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
17a269a4
Commit
17a269a4
authored
Jun 24, 2019
by
Shucai Xiao
Browse files
clang format
parent
63773ec0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
src/targets/gpu/device/softmax.cpp
src/targets/gpu/device/softmax.cpp
+12
-15
No files found.
src/targets/gpu/device/softmax.cpp
View file @
17a269a4
...
@@ -13,8 +13,7 @@ namespace gpu {
...
@@ -13,8 +13,7 @@ namespace gpu {
namespace
device
{
namespace
device
{
template
<
class
T
>
template
<
class
T
>
__device__
void
__device__
void
reduce_max
(
T
*
data_ptr
,
size_t
block_size
,
size_t
thr_idx
,
size_t
item_num
)
reduce_max
(
T
*
data_ptr
,
size_t
block_size
,
size_t
thr_idx
,
size_t
item_num
)
{
{
auto
stride
=
(
item_num
+
1
)
/
2
;
auto
stride
=
(
item_num
+
1
)
/
2
;
while
(
true
)
while
(
true
)
...
@@ -42,8 +41,7 @@ reduce_max(T* data_ptr, size_t block_size, size_t thr_idx, size_t item_num)
...
@@ -42,8 +41,7 @@ reduce_max(T* data_ptr, size_t block_size, size_t thr_idx, size_t item_num)
}
}
template
<
class
T
>
template
<
class
T
>
__device__
void
__device__
void
reduce_sum
(
T
*
data_ptr
,
size_t
block_size
,
size_t
thr_idx
,
size_t
item_num
)
reduce_sum
(
T
*
data_ptr
,
size_t
block_size
,
size_t
thr_idx
,
size_t
item_num
)
{
{
auto
stride
=
(
item_num
+
1
)
/
2
;
auto
stride
=
(
item_num
+
1
)
/
2
;
while
(
true
)
while
(
true
)
...
@@ -70,10 +68,10 @@ reduce_sum(T* data_ptr, size_t block_size, size_t thr_idx, size_t item_num)
...
@@ -70,10 +68,10 @@ reduce_sum(T* data_ptr, size_t block_size, size_t thr_idx, size_t item_num)
void
softmax
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
int
axis
)
void
softmax
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
int
axis
)
{
{
auto
lens
=
result
.
get_shape
().
lens
();
auto
lens
=
result
.
get_shape
().
lens
();
auto
batch_lens
=
lens
;
auto
batch_lens
=
lens
;
size_t
batch_item_num
=
lens
[
axis
];
size_t
batch_item_num
=
lens
[
axis
];
batch_lens
[
axis
]
=
1
;
batch_lens
[
axis
]
=
1
;
migraphx
::
shape
batch_shape
{
result
.
get_shape
().
type
(),
batch_lens
};
migraphx
::
shape
batch_shape
{
result
.
get_shape
().
type
(),
batch_lens
};
visit_all
(
result
,
arg
)([
&
](
auto
output
,
auto
input
)
{
visit_all
(
result
,
arg
)([
&
](
auto
output
,
auto
input
)
{
...
@@ -101,9 +99,9 @@ void softmax(hipStream_t stream, const argument& result, const argument& arg, in
...
@@ -101,9 +99,9 @@ void softmax(hipStream_t stream, const argument& result, const argument& arg, in
auto
batch_idx
=
desc_batch
.
multi
(
blk_idx
);
auto
batch_idx
=
desc_batch
.
multi
(
blk_idx
);
auto
data_idx
=
batch_idx
;
auto
data_idx
=
batch_idx
;
// load data to lds and compute the batch max
// load data to lds and compute the batch max
size_t
remaining_item_num
=
batch_item_num
;
size_t
remaining_item_num
=
batch_item_num
;
size_t
round_item_num
=
(
batch_item_num
+
block_size
-
1
)
/
block_size
*
block_size
;
size_t
round_item_num
=
(
batch_item_num
+
block_size
-
1
)
/
block_size
*
block_size
;
lds_data
[
block_size
]
=
input_ptr
[
0
];
lds_data
[
block_size
]
=
input_ptr
[
0
];
for
(
size_t
i
=
thr_idx
;
i
<
round_item_num
;
i
+=
block_size
)
for
(
size_t
i
=
thr_idx
;
i
<
round_item_num
;
i
+=
block_size
)
{
{
if
(
i
<
batch_item_num
)
if
(
i
<
batch_item_num
)
...
@@ -124,14 +122,13 @@ void softmax(hipStream_t stream, const argument& result, const argument& arg, in
...
@@ -124,14 +122,13 @@ void softmax(hipStream_t stream, const argument& result, const argument& arg, in
__syncthreads
();
__syncthreads
();
lds_data
[
block_size
]
=
0
;
lds_data
[
block_size
]
=
0
;
remaining_item_num
=
batch_item_num
;
remaining_item_num
=
batch_item_num
;
for
(
size_t
i
=
thr_idx
;
i
<
round_item_num
;
i
+=
block_size
)
for
(
size_t
i
=
thr_idx
;
i
<
round_item_num
;
i
+=
block_size
)
{
{
if
(
i
<
batch_item_num
)
if
(
i
<
batch_item_num
)
{
{
data_idx
[
axis
]
=
i
;
data_idx
[
axis
]
=
i
;
lds_data
[
thr_idx
]
=
lds_data
[
thr_idx
]
=
input_ptr
[
desc_data
.
linear
(
data_idx
)]
-
batch_max
;
input_ptr
[
desc_data
.
linear
(
data_idx
)]
-
batch_max
;
lds_data
[
thr_idx
]
=
::
exp
(
to_hip_type
(
lds_data
[
thr_idx
]));
lds_data
[
thr_idx
]
=
::
exp
(
to_hip_type
(
lds_data
[
thr_idx
]));
}
}
...
...
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