Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
3609cc74
Commit
3609cc74
authored
6 years ago
by
shssf
Committed by
Robert Kimball
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IntelGPU backend: Reshape operation optimization (#1566)
parent
e6267708
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
19 deletions
+45
-19
intelgpu_backend.cpp
src/ngraph/runtime/intelgpu/intelgpu_backend.cpp
+26
-19
backend_test.in.cpp
test/backend_test.in.cpp
+19
-0
No files found.
src/ngraph/runtime/intelgpu/intelgpu_backend.cpp
View file @
3609cc74
...
...
@@ -594,27 +594,34 @@ bool runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function> func)
{
arguments_check
(
op
,
1
,
1
);
const
shared_ptr
<
op
::
Reshape
>
op_broadcast
=
static_pointer_cast
<
op
::
Reshape
>
(
op
);
const
AxisVector
&
broadcast_axes
=
op_broadcast
->
get_input_order
();
vector
<
uint16_t
>
permute_order
({
0
,
1
,
2
,
3
});
// No action by default
const
size_t
max_dim
=
4
;
const
size_t
scale
=
broadcast_axes
.
size
()
<
max_dim
?
max_dim
-
broadcast_axes
.
size
()
:
0
;
// Need to scale indexes up according on array rank.
// For example, in 2D array, indexes are 0,1 but in 4D array it should be 2,3
// because cldnn::tensor is always 4D assuming cldnn::bfyx model
size_t
rindex
=
max_dim
;
for
(
auto
i
=
broadcast_axes
.
crbegin
();
i
!=
broadcast_axes
.
crend
()
&&
rindex
>
0
;
++
i
,
--
rindex
)
const
shared_ptr
<
op
::
Reshape
>
op_reshape
=
static_pointer_cast
<
op
::
Reshape
>
(
op
);
if
(
op_reshape
->
get_is_transpose
())
{
permute_order
.
at
(
rindex
-
1
)
=
*
i
+
scale
;
}
vector
<
uint16_t
>
permute_order
({
0
,
1
,
2
,
3
});
// No action by default
const
AxisVector
&
reshape_axes
=
op_reshape
->
get_input_order
();
const
size_t
max_dim
=
4
;
const
size_t
scale
=
reshape_axes
.
size
()
<
max_dim
?
max_dim
-
reshape_axes
.
size
()
:
0
;
// Need to scale indexes up according on array rank.
// For example, in 2D array, indexes are 0,1 but in 4D array it should be 2,3
// because cldnn::tensor is always 4D assuming cldnn::bfyx model
size_t
rindex
=
max_dim
;
for
(
auto
i
=
reshape_axes
.
crbegin
();
i
!=
reshape_axes
.
crend
()
&&
rindex
>
0
;
++
i
,
--
rindex
)
{
permute_order
.
at
(
rindex
-
1
)
=
*
i
+
scale
;
}
const
cldnn
::
permute
cldnn_permute
(
get_output_name
(
op
),
get_input_name
(
op
),
permute_order
);
topology
.
add
(
cldnn_permute
);
const
cldnn
::
permute
cldnn_permute
(
get_output_name
(
op
),
get_input_name
(
op
),
permute_order
);
topology
.
add
(
cldnn_permute
);
}
else
{
do_equal_propagation
(
topology
,
get_input_name
(
op
),
get_output_name
(
op
));
}
}
else
if
(
"Negative"
==
op
->
description
())
{
...
...
This diff is collapsed.
Click to expand it.
test/backend_test.in.cpp
View file @
3609cc74
...
...
@@ -2691,6 +2691,25 @@ NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t)
EXPECT_EQ
((
vector
<
float
>
{
42
}),
read_vector
<
float
>
(
result
));
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
reshape_s2t1
)
{
Shape
shape_a
{};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
boolean
,
shape_a
);
Shape
shape_r
{
1
};
auto
r
=
make_shared
<
op
::
Reshape
>
(
A
,
AxisVector
{},
shape_r
);
auto
f
=
make_shared
<
Function
>
(
r
,
op
::
ParameterVector
{
A
});
auto
backend
=
runtime
::
Backend
::
create
(
"${BACKEND_NAME}"
);
// Create some tensors for input/output
auto
a
=
backend
->
create_tensor
(
element
::
boolean
,
shape_a
);
copy_data
(
a
,
vector
<
char
>
{
42
});
auto
result
=
backend
->
create_tensor
(
element
::
boolean
,
shape_r
);
backend
->
call_with_validate
(
f
,
{
result
},
{
a
});
EXPECT_EQ
((
vector
<
char
>
{
42
}),
read_vector
<
char
>
(
result
));
}
NGRAPH_TEST
(
$
{
BACKEND_NAME
},
reshape_v2m_col
)
{
Shape
shape_a
{
3
};
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment