Skip to content

Commit 4eb273e

Browse files
kilinchangeCopilot
andcommitted
fix: add output_numel bounds check in scatter kernel
Co-authored-by: Copilot <copilot@github.com>
1 parent d85350f commit 4eb273e

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

infini_train/src/kernels/cuda/scatter.cu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ std::shared_ptr<Tensor> ScatterForward(const std::shared_ptr<Tensor> &values, co
3737
const int64_t num_experts = output_dims.back();
3838
CHECK_GT(num_experts, 0);
3939
const int64_t rows = values->NumElements() / topk;
40+
const int64_t output_numel = std::accumulate(output_dims.begin(), output_dims.end(), 1, std::multiplies<int64_t>());
41+
CHECK_EQ(output_numel, static_cast<size_t>(rows * num_experts));
4042

4143
auto output = std::make_shared<Tensor>(output_dims, values->Dtype(), values->GetDevice());
4244

0 commit comments

Comments
 (0)