Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix l2norm block_size #7044

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion oneflow/core/ep/cuda/cuda_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class CudaStream : public Stream {
explicit CudaStream(CudaDevice* device);
~CudaStream() override;

static constexpr uint32_t kDefaultBlockSize = 256;

DeviceType device_type() const override;
Device* device() const override;
Maybe<void> Sync() override;
Expand Down Expand Up @@ -106,7 +108,7 @@ class CudaStream : public Stream {

template<typename... Params, typename... Args>
void LaunchKernel(void (*kernel)(Params...), size_t elem_cnt, size_t max_waves, Args... args) {
constexpr uint32_t block_size = 256;
constexpr uint32_t block_size = kDefaultBlockSize;
CudaLaunchConfig config{};
InitLaunchConfigWithWaves(&config, elem_cnt, block_size, max_waves);
LaunchKernel(kernel, config, args...);
Expand Down
4 changes: 2 additions & 2 deletions oneflow/user/kernels/l2_normalize_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {
template<typename T>
__global__ void L2NormalizeForward(const int32_t n, const int32_t c, const int32_t d,
const T epsilon, const T* in, T* square_x_sum, T* out) {
using BlockReduce = cub::BlockReduce<T, kCudaThreadsNumPerBlock>;
using BlockReduce = cub::BlockReduce<T, ep::CudaStream::kDefaultBlockSize>;
__shared__ typename BlockReduce::TempStorage temp_storage;

for (int32_t i = blockIdx.x; i < n; i += gridDim.x) {
Expand Down Expand Up @@ -54,7 +54,7 @@ __global__ void L2NormalizeBackward(const int32_t n, const int32_t c, const int3
const T inv_norm = rsqrt(fmaxf(square_x_sum[i], epsilon));
const int32_t offset = (i / d) * d * c + (i % d);
if (square_x_sum[i] >= epsilon) {
using BlockReduce = cub::BlockReduce<T, kCudaThreadsNumPerBlock>;
using BlockReduce = cub::BlockReduce<T, ep::CudaStream::kDefaultBlockSize>;
__shared__ typename BlockReduce::TempStorage temp_storage_prod_sum;

T y_dy_prod_sum = GetZeroVal<T>();
Expand Down