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
2f8b19a8
Commit
2f8b19a8
authored
Mar 11, 2018
by
Jayaram Bobba
Committed by
Robert Kimball
Mar 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix to matmul bias column broadcast and modified unit tests (#627)
parent
8520e846
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
27 deletions
+12
-27
cpu_emitter.cpp
src/ngraph/runtime/cpu/cpu_emitter.cpp
+4
-11
cpu_fusion.cpp
test/cpu_fusion.cpp
+8
-16
No files found.
src/ngraph/runtime/cpu/cpu_emitter.cpp
View file @
2f8b19a8
...
@@ -231,10 +231,6 @@ namespace ngraph
...
@@ -231,10 +231,6 @@ namespace ngraph
}
}
#endif
#endif
//TODO: This could be further optimized to reduce the impact of memcpy by either
//a) emitting customized code for initializing output/bias
//b) emitting two cblas calls (one for gemm on W and x and the second for gemm on Bias and E^T + the result of the first gemm)
//@jbobba suggests b) is more efficient but we should benchmark both
template
<>
template
<>
void
CPU_Emitter
::
EMITTER_DECL
(
ngraph
::
op
::
MatmulBias
)
void
CPU_Emitter
::
EMITTER_DECL
(
ngraph
::
op
::
MatmulBias
)
{
{
...
@@ -323,13 +319,10 @@ namespace ngraph
...
@@ -323,13 +319,10 @@ namespace ngraph
writer
<<
"};
\n
"
;
writer
<<
"};
\n
"
;
writer
<<
"cblas::cblas_sgemm("
writer
<<
"cblas::cblas_sgemm("
<<
"cblas::Layout::RowMajor, "
<<
cnotranspose
<<
ctranspose
<<
"cblas::Layout::RowMajor, "
<<
cnotranspose
<<
cnotranspose
<<
arg2_shape
[
0
]
<<
", "
<<
arg2_shape
[
1
]
<<
", 1"
<<
arg2_shape
[
0
]
<<
", "
<<
arg2_shape
[
1
]
<<
", 1,
\n
"
<<
",
\n
"
<<
"1.0f, "
<<
args
[
2
].
get_name
()
<<
", 1, "
<<
" 1.0f, ones_col,"
<<
max
(
1UL
,
arg2_shape
[
1
])
<<
", "
<<
"ones_col, "
<<
max
(
1UL
,
arg2_shape
[
1
])
<<
", "
<<
args
[
2
].
get_name
()
<<
", "
<<
"1"
<<
", "
<<
"1.0f"
<<
"1.0f"
<<
",
\n
"
<<
",
\n
"
<<
" "
<<
out
[
0
].
get_name
()
<<
", "
<<
" "
<<
out
[
0
].
get_name
()
<<
", "
...
...
test/cpu_fusion.cpp
View file @
2f8b19a8
...
@@ -109,14 +109,10 @@ TEST(cpu_fusion, gemm_cpu_broadcast_row)
...
@@ -109,14 +109,10 @@ TEST(cpu_fusion, gemm_cpu_broadcast_row)
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeA
);
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeA
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeB
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeB
);
auto
reshape_w
=
make_shared
<
op
::
Reshape
>
(
A
,
AxisVector
{
1
,
0
},
Shape
{
2
,
3
});
auto
bias
=
op
::
Constant
::
create
<
float
>
(
element
::
f32
,
Shape
{
2
},
std
::
vector
<
float
>
{
2.0
f
,
3.0
f
});
auto
reshape_x
=
make_shared
<
op
::
Reshape
>
(
B
,
AxisVector
{
1
,
0
},
Shape
{
3
,
2
});
auto
one
=
op
::
Constant
::
create
<
float
>
(
element
::
f32
,
Shape
{
2
},
std
::
vector
<
float
>
{
1.0
f
,
1.0
f
});
auto
broadcast
=
make_shared
<
op
::
Broadcast
>
(
one
,
shapeC
,
AxisSet
{
0
});
auto
cg
=
make_shared
<
op
::
MatmulBias
>
(
auto
cg
=
make_shared
<
op
::
MatmulBias
>
(
A
,
B
,
one
,
A
->
get_shape
(),
B
->
get_shape
(),
true
,
true
,
AxisSet
{
0
});
A
,
B
,
bias
,
A
->
get_shape
(),
B
->
get_shape
(),
true
,
true
,
AxisSet
{
0
});
auto
f
=
make_shared
<
Function
>
(
cg
,
op
::
ParameterVector
{
A
,
B
});
auto
f
=
make_shared
<
Function
>
(
cg
,
op
::
ParameterVector
{
A
,
B
});
...
@@ -136,8 +132,8 @@ TEST(cpu_fusion, gemm_cpu_broadcast_row)
...
@@ -136,8 +132,8 @@ TEST(cpu_fusion, gemm_cpu_broadcast_row)
copy_data
(
b
,
dataB
);
copy_data
(
b
,
dataB
);
cf
->
call
({
a
,
b
},
{
result
});
cf
->
call
({
a
,
b
},
{
result
});
vector
<
float
>
expected
{
1
0
,
28
,
37
,
109
};
vector
<
float
>
expected
{
1
1
,
30
,
38
,
111
};
ASSERT_TRUE
(
read_vector
<
float
>
(
result
)
==
expected
);
EXPECT_EQ
(
read_vector
<
float
>
(
result
),
expected
);
}
}
TEST
(
cpu_fusion
,
gemm_cpu_broadcast_column
)
TEST
(
cpu_fusion
,
gemm_cpu_broadcast_column
)
...
@@ -148,14 +144,10 @@ TEST(cpu_fusion, gemm_cpu_broadcast_column)
...
@@ -148,14 +144,10 @@ TEST(cpu_fusion, gemm_cpu_broadcast_column)
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeA
);
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeA
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeB
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
shapeB
);
auto
reshape_w
=
make_shared
<
op
::
Reshape
>
(
A
,
AxisVector
{
1
,
0
},
Shape
{
2
,
3
});
auto
bias
=
op
::
Constant
::
create
<
float
>
(
element
::
f32
,
Shape
{
2
},
std
::
vector
<
float
>
{
2.0
f
,
3.0
f
});
auto
reshape_x
=
make_shared
<
op
::
Reshape
>
(
B
,
AxisVector
{
1
,
0
},
Shape
{
3
,
2
});
auto
one
=
op
::
Constant
::
create
<
float
>
(
element
::
f32
,
Shape
{
2
},
std
::
vector
<
float
>
{
1.0
f
,
1.0
f
});
auto
broadcast
=
make_shared
<
op
::
Broadcast
>
(
one
,
shapeC
,
AxisSet
{
1
});
auto
cg
=
make_shared
<
op
::
MatmulBias
>
(
auto
cg
=
make_shared
<
op
::
MatmulBias
>
(
A
,
B
,
one
,
A
->
get_shape
(),
B
->
get_shape
(),
true
,
true
,
AxisSet
{
1
});
A
,
B
,
bias
,
A
->
get_shape
(),
B
->
get_shape
(),
true
,
true
,
AxisSet
{
1
});
auto
f
=
make_shared
<
Function
>
(
cg
,
op
::
ParameterVector
{
A
,
B
});
auto
f
=
make_shared
<
Function
>
(
cg
,
op
::
ParameterVector
{
A
,
B
});
...
@@ -175,8 +167,8 @@ TEST(cpu_fusion, gemm_cpu_broadcast_column)
...
@@ -175,8 +167,8 @@ TEST(cpu_fusion, gemm_cpu_broadcast_column)
copy_data
(
b
,
dataB
);
copy_data
(
b
,
dataB
);
cf
->
call
({
a
,
b
},
{
result
});
cf
->
call
({
a
,
b
},
{
result
});
vector
<
float
>
expected
{
1
0
,
28
,
37
,
109
};
vector
<
float
>
expected
{
1
1
,
29
,
39
,
111
};
ASSERT_TRUE
(
read_vector
<
float
>
(
result
)
==
expected
);
EXPECT_EQ
(
read_vector
<
float
>
(
result
),
expected
);
}
}
TEST
(
cpu_fusion
,
gemm_cpu_broadcast_matrix
)
TEST
(
cpu_fusion
,
gemm_cpu_broadcast_matrix
)
...
...
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