Skip to content

Use cudaMemset/hipMemset to setup IndexShuffling kernel. #4016

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 16 additions & 1 deletion fbgemm_gpu/experimental/gen_ai/src/moe/index_shuffling.cu
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,23 @@ std::tuple<at::Tensor, at::Tensor, at::Tensor> index_shuffling_torch(
at::Tensor shuffled_expert_indices = allocate_index_tensor(num_tokens);
at::Tensor shuffled_token_indices = allocate_index_tensor(num_tokens);

#ifdef USE_ROCM
counts.zero_();
// TODO(shikaili): hipMetsetAsync is more expensive than ATen set zero.
/*
hipMemsetAsync(
counts.data_ptr(),
0,
counts.numel() * counts.dtype().itemsize(),
at::cuda::getCurrentCUDAStream());
*/
#else
cudaMemsetAsync(
counts.data_ptr(),
0,
counts.numel() * counts.dtype().itemsize(),
at::cuda::getCurrentCUDAStream());
#endif

// Avoid expensive `cudaGetDeviceProperties` call.
if (num_sms < 0) {
Expand All @@ -298,7 +314,6 @@ std::tuple<at::Tensor, at::Tensor, at::Tensor> index_shuffling_torch(
kernel = (void*)index_shuffling_kernel<DataType, IndexType, E, B>; \
smem_size = sizeof(SharedStorage<DataType, IndexType, E, B>);

int num_tokens_per_tile;
if (num_experts == 16) {
DISPATCH(16, kNumTokensPerTile);
} else {
Expand Down
Loading