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
28002287
Commit
28002287
authored
Nov 12, 2018
by
Pruthvi
Committed by
Scott Cyphers
Nov 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cse for convert layout (#1983)
* cse for convert layout * addressed PR comments * Addressed PR comments
parent
296ee2cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
cpu_cse.cpp
src/ngraph/runtime/cpu/cpu_cse.cpp
+20
-1
cpu_test.cpp
test/cpu_test.cpp
+36
-0
No files found.
src/ngraph/runtime/cpu/cpu_cse.cpp
View file @
28002287
...
...
@@ -29,7 +29,26 @@ using namespace std;
static
bool
cse_convertlayout
(
std
::
shared_ptr
<
Node
>
a
,
std
::
shared_ptr
<
Node
>
b
)
{
return
false
;
NGRAPH_DEBUG
<<
"In cse_convertlayout for "
<<
a
->
get_name
()
<<
" and "
<<
b
->
get_name
();
auto
ar_a
=
std
::
static_pointer_cast
<
runtime
::
cpu
::
op
::
ConvertLayout
>
(
a
);
auto
ar_b
=
std
::
static_pointer_cast
<
runtime
::
cpu
::
op
::
ConvertLayout
>
(
b
);
// gets the tensor layout from the given node
auto
get_tensor_layout
=
[](
std
::
shared_ptr
<
Node
>
node
)
{
auto
tensor
=
node
->
get_output_tensor_ptr
();
auto
cpu_tl
=
static_cast
<
ngraph
::
runtime
::
cpu
::
LayoutDescriptor
*>
(
tensor
->
get_tensor_layout
().
get
());
return
cpu_tl
;
};
auto
a_layout_desc
=
get_tensor_layout
(
a
);
auto
b_layout_desc
=
get_tensor_layout
(
b
);
bool
is_args_same
=
(
ar_a
->
get_argument
(
0
)
==
ar_b
->
get_argument
(
0
));
bool
is_output_mem_desc_same
=
runtime
::
cpu
::
mkldnn_utils
::
compare_mkldnn_mds
(
a_layout_desc
->
get_mkldnn_md
(),
b_layout_desc
->
get_mkldnn_md
());
return
is_args_same
&&
is_output_mem_desc_same
;
}
namespace
ngraph
...
...
test/cpu_test.cpp
View file @
28002287
...
...
@@ -542,3 +542,39 @@ TEST(cpu_test, collapse_dims2)
EXPECT_TRUE
(
test
::
all_close
(
cpu_results
.
at
(
i
),
int_results
.
at
(
i
)));
}
}
TEST
(
cpu_test
,
convert_layout
)
{
auto
make_function
=
[]()
->
std
::
shared_ptr
<
Function
>
{
auto
W
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
10
,
400
});
auto
X
=
std
::
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
400
,
10
});
auto
W_reshape
=
std
::
make_shared
<
op
::
Reshape
>
(
W
,
AxisVector
{
1
,
0
},
Shape
{
400
,
10
});
auto
add1
=
std
::
make_shared
<
op
::
Add
>
(
X
,
W_reshape
);
auto
sub1
=
std
::
make_shared
<
op
::
Subtract
>
(
X
,
W_reshape
);
auto
mul1
=
std
::
make_shared
<
op
::
Multiply
>
(
X
,
W_reshape
);
return
make_shared
<
Function
>
(
NodeVector
{
add1
,
sub1
,
mul1
},
op
::
ParameterVector
{
W
,
X
});
};
auto
backend
=
runtime
::
Backend
::
create
(
"CPU"
);
auto
cpu_f
=
make_function
();
auto
int_f
=
make_function
();
test
::
Uniform
<
float
>
rng
(
-
100.0
f
,
100.0
f
);
vector
<
vector
<
float
>>
args
;
for
(
shared_ptr
<
op
::
Parameter
>
param
:
cpu_f
->
get_parameters
())
{
vector
<
float
>
tensor_val
(
shape_size
(
param
->
get_shape
()));
rng
.
initialize
(
tensor_val
);
args
.
push_back
(
tensor_val
);
}
auto
int_results
=
execute
(
int_f
,
args
,
"INTERPRETER"
);
auto
cpu_results
=
execute
(
cpu_f
,
args
,
"CPU"
);
size_t
count
=
count_ops_of_type
<
runtime
::
cpu
::
op
::
ConvertLayout
>
(
cpu_f
);
ASSERT_EQ
(
count
,
1
);
for
(
size_t
i
=
0
;
i
<
cpu_results
.
size
();
i
++
)
{
EXPECT_TRUE
(
test
::
all_close
(
cpu_results
.
at
(
i
),
int_results
.
at
(
i
)));
}
}
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