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
e47c0140
"src/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "fed23ec79685ed0f5051d72bd98a959116c27641"
Commit
e47c0140
authored
May 02, 2022
by
turneram
Browse files
Formatting
parent
fe7562cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
34 deletions
+33
-34
src/include/migraphx/op/layernorm.hpp
src/include/migraphx/op/layernorm.hpp
+30
-31
src/onnx/parse_layernorm.cpp
src/onnx/parse_layernorm.cpp
+2
-2
src/targets/gpu/layernorm.cpp
src/targets/gpu/layernorm.cpp
+1
-1
No files found.
src/include/migraphx/op/layernorm.hpp
View file @
e47c0140
...
...
@@ -72,37 +72,10 @@ struct layernorm
mean_inv_std_dev_dim.at(i) = 1;
} */
if
(
args
.
size
()
==
3
)
if
(
args
.
size
()
==
3
)
{
visit_all
(
result
,
args
[
0
],
args
[
1
],
args
[
2
])(
[
&
](
auto
output
,
auto
data
,
auto
weights
,
auto
bias
)
{
par_for
(
norm_count
,
[
&
](
auto
idx
)
{
auto
offset
=
idx
*
norm_size
;
double
mean
=
0
;
double
mean_square
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
norm_size
;
++
i
)
{
mean
+=
data
[
offset
+
i
];
mean_square
+=
data
[
offset
+
i
]
*
data
[
offset
+
i
];
}
mean
/=
norm_size
;
mean_square
=
sqrt
(
mean_square
/
norm_size
-
mean
*
mean
+
epsilon
);
for
(
std
::
size_t
i
=
0
;
i
<
norm_size
;
++
i
)
{
if
(
args
.
size
()
==
3
)
output
[
offset
+
i
]
=
(
data
[
offset
+
i
]
-
mean
)
/
mean_square
*
weights
[
i
]
+
bias
[
i
];
else
output
[
offset
+
i
]
=
(
data
[
offset
+
i
]
-
mean
)
/
mean_square
*
weights
[
i
];
}
});
});
}
else
{
visit_all
(
result
,
args
[
0
])(
[
&
](
auto
output
,
auto
data
)
{
[
&
](
auto
output
,
auto
data
,
auto
weights
,
auto
bias
)
{
par_for
(
norm_count
,
[
&
](
auto
idx
)
{
auto
offset
=
idx
*
norm_size
;
double
mean
=
0
;
...
...
@@ -116,12 +89,38 @@ struct layernorm
mean_square
=
sqrt
(
mean_square
/
norm_size
-
mean
*
mean
+
epsilon
);
for
(
std
::
size_t
i
=
0
;
i
<
norm_size
;
++
i
)
{
output
[
offset
+
i
]
=
(
data
[
offset
+
i
]
-
mean
)
/
mean_square
;
// scale and bias handled by onnx parser
if
(
args
.
size
()
==
3
)
output
[
offset
+
i
]
=
(
data
[
offset
+
i
]
-
mean
)
/
mean_square
*
weights
[
i
]
+
bias
[
i
];
else
output
[
offset
+
i
]
=
(
data
[
offset
+
i
]
-
mean
)
/
mean_square
*
weights
[
i
];
}
});
});
}
else
{
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
data
)
{
par_for
(
norm_count
,
[
&
](
auto
idx
)
{
auto
offset
=
idx
*
norm_size
;
double
mean
=
0
;
double
mean_square
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
norm_size
;
++
i
)
{
mean
+=
data
[
offset
+
i
];
mean_square
+=
data
[
offset
+
i
]
*
data
[
offset
+
i
];
}
mean
/=
norm_size
;
mean_square
=
sqrt
(
mean_square
/
norm_size
-
mean
*
mean
+
epsilon
);
for
(
std
::
size_t
i
=
0
;
i
<
norm_size
;
++
i
)
{
output
[
offset
+
i
]
=
(
data
[
offset
+
i
]
-
mean
)
/
mean_square
;
// scale and bias handled by onnx parser
}
});
});
}
return
result
;
}
...
...
src/onnx/parse_layernorm.cpp
View file @
e47c0140
...
...
@@ -32,9 +32,9 @@ struct parse_layernorm : op_parser<parse_layernorm>
if
(
args
.
size
()
>=
2
)
layernorm
=
info
.
add_instruction
(
make_op
(
"mul"
),
layernorm
,
args
.
at
(
1
));
if
(
args
.
size
()
==
3
)
if
(
args
.
size
()
==
3
)
layernorm
=
info
.
add_instruction
(
make_op
(
"add"
),
layernorm
,
args
.
at
(
2
));
return
layernorm
;
}
};
...
...
src/targets/gpu/layernorm.cpp
View file @
e47c0140
...
...
@@ -15,7 +15,7 @@ shape hip_layernorm::compute_shape(std::vector<shape> inputs) const
argument
hip_layernorm
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
layernorm
(
ctx
.
get_stream
().
get
(),
args
.
back
(),
args
[
0
]);
return
args
.
back
();
}
...
...
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