Commit 22500e6c authored by Shucai Xiao's avatar Shucai Xiao
Browse files

clang format

parent ea932b63
...@@ -533,7 +533,7 @@ struct cpu_softmax ...@@ -533,7 +533,7 @@ struct cpu_softmax
{ {
argument result{output_shape}; argument result{output_shape};
auto batch_lens = output_shape.lens(); auto batch_lens = output_shape.lens();
std::size_t n_dims = batch_lens[op.axis]; std::size_t n_dims = batch_lens[op.axis];
batch_lens[op.axis] = 1; batch_lens[op.axis] = 1;
shape batch_shape{shape::int32_type, batch_lens}; shape batch_shape{shape::int32_type, batch_lens};
...@@ -552,9 +552,9 @@ struct cpu_softmax ...@@ -552,9 +552,9 @@ struct cpu_softmax
for(std::size_t j = 0; j < n_dims; ++j) for(std::size_t j = 0; j < n_dims; ++j)
{ {
idx[op.axis] = j; idx[op.axis] = j;
std::size_t index = output_shape.index(idx); std::size_t index = output_shape.index(idx);
output[index] = std::exp(input[index] - batch_max[i]); output[index] = std::exp(input[index] - batch_max[i]);
} }
for(std::size_t j = 0; j < n_dims; ++j) for(std::size_t j = 0; j < n_dims; ++j)
...@@ -591,7 +591,7 @@ struct cpu_logsoftmax ...@@ -591,7 +591,7 @@ struct cpu_logsoftmax
{ {
argument result{output_shape}; argument result{output_shape};
auto batch_lens = output_shape.lens(); auto batch_lens = output_shape.lens();
std::size_t n_dims = batch_lens[op.axis]; std::size_t n_dims = batch_lens[op.axis];
batch_lens[op.axis] = 1; batch_lens[op.axis] = 1;
shape batch_shape{shape::int32_type, batch_lens}; shape batch_shape{shape::int32_type, batch_lens};
...@@ -613,9 +613,9 @@ struct cpu_logsoftmax ...@@ -613,9 +613,9 @@ struct cpu_logsoftmax
for(std::size_t j = 0; j < n_dims; ++j) for(std::size_t j = 0; j < n_dims; ++j)
{ {
idx[op.axis] = j; idx[op.axis] = j;
std::size_t index = output_shape.index(idx); std::size_t index = output_shape.index(idx);
output[index] = input[index] - batch_max[i]; output[index] = input[index] - batch_max[i];
} }
for(std::size_t j = 0; j < n_dims; ++j) for(std::size_t j = 0; j < n_dims; ++j)
......
...@@ -33,15 +33,16 @@ void logsoftmax(hipStream_t stream, const argument& result, const argument& arg, ...@@ -33,15 +33,16 @@ void logsoftmax(hipStream_t stream, const argument& result, const argument& arg,
launch(stream, batch_shape.elements() * block_size, block_size)([=](auto idx) __device__ { launch(stream, batch_shape.elements() * block_size, block_size)([=](auto idx) __device__ {
std::size_t thr_idx = idx.local; std::size_t thr_idx = idx.local;
std::size_t blk_idx = idx.group; std::size_t blk_idx = idx.group;
using type = device_type<std::remove_cv_t<typename decltype(output)::value_type>>; using type = device_type<std::remove_cv_t<typename decltype(output)::value_type>>;
MIGRAPHX_DEVICE_SHARED type lds_data[max_block_size + 1]; MIGRAPHX_DEVICE_SHARED type lds_data[max_block_size + 1];
auto batch_idx = batch.multi(blk_idx); auto batch_idx = 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
std::size_t remaining_item_num = batch_item_num; std::size_t remaining_item_num = batch_item_num;
std::size_t round_item_num = (batch_item_num + block_size - 1) / block_size * block_size; std::size_t round_item_num =
lds_data[max_block_size] = input[0]; (batch_item_num + block_size - 1) / block_size * block_size;
lds_data[max_block_size] = input[0];
for(std::size_t i = thr_idx; i < round_item_num; i += block_size) for(std::size_t i = thr_idx; i < round_item_num; i += block_size)
{ {
if(i < batch_item_num) if(i < batch_item_num)
......
...@@ -15,10 +15,10 @@ namespace device { ...@@ -15,10 +15,10 @@ namespace device {
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;
std::size_t batch_item_num = lens[axis]; std::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};
hip_visit_all(result, arg, batch_shape)([&](auto output, auto input, auto batch) { hip_visit_all(result, arg, batch_shape)([&](auto output, auto input, auto batch) {
...@@ -33,15 +33,16 @@ void softmax(hipStream_t stream, const argument& result, const argument& arg, in ...@@ -33,15 +33,16 @@ void softmax(hipStream_t stream, const argument& result, const argument& arg, in
launch(stream, batch_shape.elements() * block_size, block_size)([=](auto idx) __device__ { launch(stream, batch_shape.elements() * block_size, block_size)([=](auto idx) __device__ {
std::size_t thr_idx = idx.local; std::size_t thr_idx = idx.local;
std::size_t blk_idx = idx.group; std::size_t blk_idx = idx.group;
using type = device_type<std::remove_cv_t<typename decltype(output)::value_type>>; using type = device_type<std::remove_cv_t<typename decltype(output)::value_type>>;
MIGRAPHX_DEVICE_SHARED type lds_data[max_block_size + 1]; MIGRAPHX_DEVICE_SHARED type lds_data[max_block_size + 1];
auto batch_idx = batch.multi(blk_idx); auto batch_idx = 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
std::size_t remaining_item_num = batch_item_num; std::size_t remaining_item_num = batch_item_num;
std::size_t round_item_num = (batch_item_num + block_size - 1) / block_size * block_size; std::size_t round_item_num =
lds_data[max_block_size] = input[0]; (batch_item_num + block_size - 1) / block_size * block_size;
lds_data[max_block_size] = input[0];
for(std::size_t i = thr_idx; i < round_item_num; i += block_size) for(std::size_t i = thr_idx; i < round_item_num; i += block_size)
{ {
if(i < batch_item_num) if(i < batch_item_num)
......
...@@ -11,8 +11,11 @@ namespace gpu { ...@@ -11,8 +11,11 @@ namespace gpu {
namespace device { namespace device {
template <class T> template <class T>
inline __device__ void inline __device__ void reduce_max(T* data_ptr,
reduce_max(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t item_num, std::size_t max_index) std::size_t block_size,
std::size_t thr_idx,
std::size_t item_num,
std::size_t max_index)
{ {
while(true) while(true)
{ {
...@@ -39,8 +42,11 @@ reduce_max(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t ...@@ -39,8 +42,11 @@ reduce_max(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t
} }
template <class T> template <class T>
inline __device__ void inline __device__ void reduce_min(T* data_ptr,
reduce_min(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t item_num, std::size_t min_index) std::size_t block_size,
std::size_t thr_idx,
std::size_t item_num,
std::size_t min_index)
{ {
while(true) while(true)
{ {
...@@ -67,8 +73,11 @@ reduce_min(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t ...@@ -67,8 +73,11 @@ reduce_min(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t
} }
template <class T> template <class T>
inline __device__ void inline __device__ void reduce_sum(T* data_ptr,
reduce_sum(T* data_ptr, std::size_t block_size, std::size_t thr_idx, std::size_t item_num, std::size_t sum_index) std::size_t block_size,
std::size_t thr_idx,
std::size_t item_num,
std::size_t sum_index)
{ {
while(true) while(true)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment