Skip to content
Open
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
13 changes: 9 additions & 4 deletions fbgemm_gpu/experimental/gen_ai/src/quantize/quantize.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1955,12 +1955,15 @@ __global__ void compute_amax_and_quantize_kernel(
const auto warp_id = threadIdx.y;
const int64_t idx = (block_idx + warp_id) * blocksize + thread_id;

if (idx >= n)
return;
// Do NOT early-return for out-of-range threads: compute_max() below uses a
// block-wide cub::BlockReduce + __syncthreads() that every thread must reach,
// otherwise the block deadlocks on ROCm/AMD. Mask the work with `active`.
const bool active = idx < n;

float scale = 1.f, unscale = 1.f;

float thread_val = x[idx];
// Inactive lanes feed 0 into the fabsf-max reduction (neutral).
float thread_val = active ? static_cast<float>(x[idx]) : 0.0f;
float block_amax = compute_max<THREAD_X, THREAD_Y>(thread_val, blocksize);

if (global_amax) {
Expand All @@ -1970,7 +1973,9 @@ __global__ void compute_amax_and_quantize_kernel(
compute_scale(scale, unscale, block_amax);
}

y[idx] = quantize(thread_val, scale, unscale);
if (active) {
y[idx] = quantize(thread_val, scale, unscale);
}
}

int ceil_div(const int a, const int b) {
Expand Down
Loading