From bc8686d3659566f3fe2942c7afc66e654383292e Mon Sep 17 00:00:00 2001 From: Ye Wang <52801275+wangyems@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:45:48 -0800 Subject: [PATCH] Fix prefast warning 11263 (#14508) ### Description https://dev.azure.com/aiinfra/ONNX%20Runtime/_workitems/edit/11263/ ### Motivation and Context --- .../contrib_ops/cuda/transformers/sampling_cuda_helper.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/contrib_ops/cuda/transformers/sampling_cuda_helper.h b/onnxruntime/contrib_ops/cuda/transformers/sampling_cuda_helper.h index f9046ec049..d82648890f 100644 --- a/onnxruntime/contrib_ops/cuda/transformers/sampling_cuda_helper.h +++ b/onnxruntime/contrib_ops/cuda/transformers/sampling_cuda_helper.h @@ -140,8 +140,9 @@ Status Sample(AllocatorPtr& allocator, // Multinomial sampling gsl::span& d_sampled = sampling_state->d_sampled; gsl::span& h_sampled_all = sampling_state->h_sampled_all; + size_t sample_offset = (static_cast(step) - 1) * static_cast(parameters->batch_size); CUDA_RETURN_IF_ERROR(cudaMemcpyAsync(d_sampled.data(), - h_sampled_all.data() + (step - 1) * parameters->batch_size, + h_sampled_all.data() + sample_offset, sizeof(float) * parameters->batch_size, cudaMemcpyHostToDevice, cuda_stream));