Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
c9b32c9c
"ts/webui/src/static/style/App.scss" did not exist on "3ec26b40afd88b8255ebc74b46f475b77aa4d19b"
Commit
c9b32c9c
authored
Jul 16, 2018
by
Aditya Atluri
Browse files
added batch norm inference and its test - not working
parent
a47f8e4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
src/targets/cpu/cpu_lowering.cpp
src/targets/cpu/cpu_lowering.cpp
+47
-0
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+12
-0
No files found.
src/targets/cpu/cpu_lowering.cpp
View file @
c9b32c9c
...
...
@@ -16,6 +16,53 @@ T zero(const T&)
return
T
(
0
);
}
//
// cpu implemenataion of batch norm for inference
//
// inputs are:
// mini-batch mean, mini-batch variance,
// input data, output data,
// total number of elements in input,
// epsilon for denominator to normalize,
// gamma and beta
//
// the input data format should be nchw
//
struct
cpu_batch_norm_inference
{
std
::
string
name
()
const
{
return
"cpu::batch_norm_inference"
;
}
argument
compute
(
context
&
,
std
::
vector
<
argument
>
args
)
const
{
// args[0] is output (y),
// args[1] is input (x),
// args[2] is number of input elements (m),
// args[3] is mini-batch mean (u),
// args[4] is mini-batch variance (s),
// args[5] is epsilon (e)
// args[6] is gamma (g)
// args[7] is beta (b)
auto
output
=
args
[
0
];
auto
input
=
args
[
1
];
auto
num_input_elements
=
args
[
2
];
auto
mini_batch_mean
=
args
[
3
];
auto
mini_batch_variance
=
args
[
4
];
auto
epsilon
=
args
[
5
];
auto
gamma
=
args
[
6
];
auto
beta
=
args
[
7
];
for
(
size_t
i
=
0
;
i
<
num_input_elements
;
i
++
)
{
output
[
i
]
=
gamma
*
\
((
input
[
i
]
-
mini_batch_mean
)
/
(
std
::
sqrt
(
mini_batch_variance
+
epsilon
)))
+
\
beta
;
}
return
output
;
}
};
struct
cpu_convolution
{
convolution
op
;
...
...
test/cpu_ops_test.cpp
View file @
c9b32c9c
...
...
@@ -6,6 +6,17 @@
#include "test.hpp"
#include "verify.hpp"
void
batch_norm_inference_test
()
{
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
4
}};
auto
x
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
1
,
2
,
3
,
4
}};
auto
y
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
0
,
0
,
0
,
0
}};
p
.
add_instruction
(
migraph
::
cpu_batch_norm_inference
,
y
,
x
,
4
,
0
,
0.5
,
0.5
,
1
,
0
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
}
void
exp_test
()
{
migraph
::
program
p
;
...
...
@@ -625,4 +636,5 @@ int main()
conv2d_test
();
conv2d_padding_test
();
conv2d_padding_stride_test
();
batch_norm_inference_test
();
}
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