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
2651f738
Unverified
Commit
2651f738
authored
Jan 29, 2020
by
Amy Zhuang
Committed by
GitHub
Jan 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MLIR] Use enum class for broadcast hint. (#4238)
Co-authored-by:
Scott Cyphers
<
diyessi@users.noreply.github.com
>
parent
d3a8e62a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
14 deletions
+27
-14
affine_lowerer.cpp
src/contrib/mlir/backend/pass/affine_lowerer.cpp
+9
-9
callback_utils.hpp
src/contrib/mlir/runtime/cpu/callback_utils.hpp
+10
-1
cpu_callbacks.cpp
src/contrib/mlir/runtime/cpu/cpu_callbacks.cpp
+8
-4
No files found.
src/contrib/mlir/backend/pass/affine_lowerer.cpp
View file @
2651f738
...
...
@@ -1324,39 +1324,39 @@ namespace
}
attrs
.
gemmAttrs2d
.
ldc
=
attrs
.
gemmAttrs2d
.
n
;
int
broadcastHint
=
-
2
;
BroadcastType
broadcastHint
=
BroadcastType
::
ERROR
;
if
(
vBias
.
rank
()
==
0
)
{
// Scalar
broadcastHint
=
2
;
broadcastHint
=
BroadcastType
::
ROWCOLUMN
;
}
else
if
(
vBias
.
rank
()
==
2
)
{
if
(
biasShape
[
0
]
==
attrs
.
gemmAttrs2d
.
m
&&
biasShape
[
1
]
==
1
)
{
broadcastHint
=
1
;
broadcastHint
=
BroadcastType
::
COLUMN
;
}
else
if
(
biasShape
[
0
]
==
1
&&
biasShape
[
1
]
==
attrs
.
gemmAttrs2d
.
n
)
{
broadcastHint
=
0
;
broadcastHint
=
BroadcastType
::
ROW
;
}
else
else
if
(
biasShape
[
0
]
==
attrs
.
gemmAttrs2d
.
m
&&
biasShape
[
1
]
==
attrs
.
gemmAttrs2d
.
n
)
{
broadcastHint
=
-
1
;
broadcastHint
=
BroadcastType
::
NONE
;
}
}
else
{
if
(
biasShape
[
0
]
==
attrs
.
gemmAttrs2d
.
m
)
{
broadcastHint
=
1
;
broadcastHint
=
BroadcastType
::
COLUMN
;
}
else
if
(
biasShape
[
0
]
==
attrs
.
gemmAttrs2d
.
n
)
{
broadcastHint
=
0
;
broadcastHint
=
BroadcastType
::
ROW
;
}
}
NGRAPH_CHECK
(
broadcastHint
!=
-
2
,
"Unhandled broadcast"
);
NGRAPH_CHECK
(
broadcastHint
!=
BroadcastType
::
ERROR
,
"Unhandled broadcast"
);
attrs
.
gemmAttrs2d
.
broadcastHint
=
broadcastHint
;
auto
int64Ty
=
rewriter
.
getIntegerType
(
64
);
...
...
src/contrib/mlir/runtime/cpu/callback_utils.hpp
View file @
2651f738
...
...
@@ -84,6 +84,15 @@ namespace ngraph
SOFTMAX
};
enum
class
BroadcastType
{
NONE
,
ROW
,
COLUMN
,
ROWCOLUMN
,
ERROR
};
// These structs and union are used to pass attributes to callbacks.
template
<
int
N
>
struct
poolAttrs
...
...
@@ -107,7 +116,7 @@ namespace ngraph
int64_t
ldc
;
float
alpha
;
float
beta
;
int64_t
broadcastHint
;
BroadcastType
broadcastHint
;
};
union
opAttrs
{
...
...
src/contrib/mlir/runtime/cpu/cpu_callbacks.cpp
View file @
2651f738
...
...
@@ -636,7 +636,7 @@ static void __mlir_cblas_sgemm_with_bias(StaticMemRef* memRefmatA,
matOut
,
std
::
max
<
size_t
>
(
1
,
ldc
));
if
(
broadcastHint
==
0
)
if
(
broadcastHint
==
BroadcastType
::
ROW
)
{
std
::
vector
<
float
>
ones
(
m
,
1.0
f
);
cblas
::
cblas_sgemm
(
cblas
::
Layout
::
RowMajor
,
...
...
@@ -654,7 +654,7 @@ static void __mlir_cblas_sgemm_with_bias(StaticMemRef* memRefmatA,
matOut
,
std
::
max
<
size_t
>
(
1
,
ldc
));
}
else
if
(
broadcastHint
==
1
)
else
if
(
broadcastHint
==
BroadcastType
::
COLUMN
)
{
std
::
vector
<
float
>
ones
(
n
,
1.0
f
);
cblas
::
cblas_sgemm
(
cblas
::
Layout
::
RowMajor
,
...
...
@@ -672,7 +672,7 @@ static void __mlir_cblas_sgemm_with_bias(StaticMemRef* memRefmatA,
matOut
,
std
::
max
<
size_t
>
(
1
,
ldc
));
}
else
if
(
broadcastHint
==
2
)
else
if
(
broadcastHint
==
BroadcastType
::
ROWCOLUMN
)
{
std
::
vector
<
float
>
ones
(
m
,
1.0
f
);
std
::
vector
<
float
>
bias
(
n
,
*
matC
);
...
...
@@ -691,7 +691,7 @@ static void __mlir_cblas_sgemm_with_bias(StaticMemRef* memRefmatA,
matOut
,
std
::
max
<
size_t
>
(
1
,
ldc
));
}
else
else
if
(
broadcastHint
==
BroadcastType
::
NONE
)
{
std
::
vector
<
float
>
identity
(
n
*
n
,
0.0
f
);
for
(
auto
i
=
0
;
i
<
n
*
n
;
i
+=
n
+
1
)
...
...
@@ -713,6 +713,10 @@ static void __mlir_cblas_sgemm_with_bias(StaticMemRef* memRefmatA,
matOut
,
std
::
max
<
size_t
>
(
1
,
ldc
));
}
else
{
NGRAPH_UNREACHABLE
(
"Unsupported broadcast"
);
}
}
extern
"C"
void
__mlir_callback_1_input
(
void
*
input
,
void
*
output
,
size_t
index
,
OpType
type
)
...
...
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