Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
0df035a0
Commit
0df035a0
authored
Jul 25, 2018
by
Aditya Atluri
Browse files
formatted source for previous commit
parent
c8b86e03
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
src/targets/cpu/cpu_lowering.cpp
src/targets/cpu/cpu_lowering.cpp
+22
-15
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+2
-1
No files found.
src/targets/cpu/cpu_lowering.cpp
View file @
0df035a0
...
...
@@ -56,16 +56,23 @@ struct cpu_batch_norm_inference
auto
image_height
=
output_shape
.
lens
()[
2
];
auto
image_width
=
output_shape
.
lens
()[
3
];
visit_all
(
output
,
input
,
mini_batch_mean
,
mini_batch_variance
,
gamma
,
bias
)([
&
](
auto
result
,
auto
buffer
,
auto
_mean
,
auto
_variance
,
auto
_gamma
,
auto
_bias
)
{
for
(
size_t
n
=
0
;
n
<
num_batch
;
n
++
)
{
visit_all
(
output
,
input
,
mini_batch_mean
,
mini_batch_variance
,
gamma
,
bias
)(
[
&
](
auto
result
,
auto
buffer
,
auto
_mean
,
auto
_variance
,
auto
_gamma
,
auto
_bias
)
{
for
(
size_t
n
=
0
;
n
<
num_batch
;
n
++
)
{
size_t
stride_n
=
n
*
num_channels
*
image_height
*
image_width
;
for
(
size_t
c
=
0
;
c
<
num_channels
;
c
++
)
{
for
(
size_t
c
=
0
;
c
<
num_channels
;
c
++
)
{
size_t
stride_c
=
c
*
image_height
*
image_width
;
for
(
size_t
h
=
0
;
h
<
image_height
;
h
++
)
{
for
(
size_t
h
=
0
;
h
<
image_height
;
h
++
)
{
size_t
stride_h
=
h
*
image_width
;
for
(
size_t
w
=
0
;
w
<
image_width
;
w
++
)
{
for
(
size_t
w
=
0
;
w
<
image_width
;
w
++
)
{
size_t
index
=
w
+
stride_h
+
stride_c
+
stride_n
;
result
[
index
]
=
_gamma
[
c
]
*
(
buffer
[
index
]
-
_mean
[
c
])
/
std
::
sqrt
(
_variance
[
c
]
+
epsilon
)
+
_bias
[
c
];
result
[
index
]
=
_gamma
[
c
]
*
(
buffer
[
index
]
-
_mean
[
c
])
/
std
::
sqrt
(
_variance
[
c
]
+
epsilon
)
+
_bias
[
c
];
}
}
}
...
...
test/cpu_ops_test.cpp
View file @
0df035a0
...
...
@@ -10,7 +10,8 @@ void batch_norm_inference_test()
{
migraph
::
program
p
;
const
size_t
width
=
2
,
height
=
2
,
channels
=
4
,
batches
=
2
;
const
float
x_val
=
8.0
f
,
mean_val
=
2.0
f
,
variance_val
=
4.0
f
,
scale_val
=
2.0
f
,
bias_val
=
1.0
f
;
const
float
x_val
=
8.0
f
,
mean_val
=
2.0
f
,
variance_val
=
4.0
f
,
scale_val
=
2.0
f
,
bias_val
=
1.0
f
;
const
float
output_val
=
scale_val
*
(
x_val
-
mean_val
)
/
(
std
::
sqrt
(
variance_val
))
+
bias_val
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
batches
,
channels
,
height
,
width
}};
...
...
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