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
9fc184e5
Commit
9fc184e5
authored
Jun 25, 2019
by
Shucai Xiao
Browse files
generalize the reduce operation implementation.
parent
42b24bd1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
src/targets/gpu/include/migraphx/gpu/device/reduce_opers.hpp
src/targets/gpu/include/migraphx/gpu/device/reduce_opers.hpp
+9
-9
No files found.
src/targets/gpu/include/migraphx/gpu/device/reduce_opers.hpp
View file @
9fc184e5
...
...
@@ -13,17 +13,17 @@ namespace device {
template
<
class
T
>
inline
__device__
void
reduce_max
(
T
*
data_ptr
,
size_t
block_size
,
size_t
thr_idx
,
size_t
item_num
)
{
auto
stride
=
(
item_num
+
1
)
/
2
;
while
(
true
)
{
if
(
thr_idx
+
stride
<
item_num
)
auto
stride
=
(
item_num
+
1
)
/
2
;
auto
size
=
item_num
/
2
;
for
(
size_t
i
=
thr_idx
;
i
<
size
;
i
+=
block_size
)
{
data_ptr
[
thr_idx
]
=
::
max
(
to_hip_type
(
data_ptr
[
thr_idx
]),
to_hip_type
(
data_ptr
[
thr_idx
+
stride
]));
data_ptr
[
i
]
=
::
max
(
to_hip_type
(
data_ptr
[
i
]),
to_hip_type
(
data_ptr
[
i
+
stride
]));
}
__syncthreads
();
item_num
=
stride
;
stride
=
(
stride
+
1
)
/
2
;
if
(
item_num
==
1
)
break
;
...
...
@@ -41,16 +41,16 @@ inline __device__ void reduce_max(T* data_ptr, size_t block_size, size_t thr_idx
template
<
class
T
>
inline
__device__
void
reduce_sum
(
T
*
data_ptr
,
size_t
block_size
,
size_t
thr_idx
,
size_t
item_num
)
{
auto
stride
=
(
item_num
+
1
)
/
2
;
while
(
true
)
{
if
(
thr_idx
+
stride
<
item_num
)
auto
stride
=
(
item_num
+
1
)
/
2
;
auto
size
=
item_num
/
2
;
for
(
size_t
i
=
thr_idx
;
i
<
size
;
i
+=
block_size
)
{
data_ptr
[
thr_idx
]
+=
data_ptr
[
thr_idx
+
stride
];
data_ptr
[
i
]
+=
data_ptr
[
i
+
stride
];
}
__syncthreads
();
item_num
=
stride
;
stride
=
(
stride
+
1
)
/
2
;
if
(
item_num
==
1
)
break
;
...
...
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