Fix prefast warnings in CUDA ops (#14814)

Fix some prefast warnings in CUDA ops.
This commit is contained in:
Tianlei Wu 2023-02-24 21:23:08 -08:00 committed by GitHub
parent 3bcdb0a83a
commit 6603be26c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 7 deletions

View file

@ -113,7 +113,7 @@ Status LongformerAttention<T>::ComputeInternal(OpKernelContext* context) const {
CUDA_RETURN_IF_ERROR(cudaEventCreateWithFlags(&is_copy_done, cudaEventDisableTiming));
CUDA_RETURN_IF_ERROR(cudaEventRecord(is_copy_done, stream));
size_t qkv_size = batch_size * sequence_length * 3 * hidden_size * element_size;
size_t qkv_size = static_cast<size_t>(batch_size) * sequence_length * 3 * hidden_size * element_size;
// Buffer for GEMM outputs of q, k, v, global_q, global_k and global_v
// TODO(tianleiwu): compact global_q only need batch_size * window * hidden_size * element_size buffer size.
auto gemm_buffer = GetScratchBuffer<void>(qkv_size + qkv_size, context->GetComputeStream());

View file

@ -190,7 +190,7 @@ static Fused_multihead_attention_params_mhca getMHCAParams(
// Set the pointers.
params.o_ptr = o_packed_d;
params.o_stride_in_bytes = h * d * sizeof(half);
params.o_stride_in_bytes = static_cast<int64_t>(h) * d * sizeof(half);
// Set the dimensions.
params.b = b;

View file

@ -49,7 +49,7 @@ class TSharedCubinKernel {
if (kernelMeta.mSM == smVersion &&
kernelMeta.mDataType == mDataType &&
mFunctions.find(kernelKey) == mFunctions.end()) {
int32_t const DEFAULT_SMEM_SIZE{48 * 1024};
constexpr int32_t DEFAULT_SMEM_SIZE = 48 * 1024;
if (kernelMeta.mSharedMemBytes >= DEFAULT_SMEM_SIZE) {
int32_t deviceID{0};
cudaGetDevice(&deviceID);

View file

@ -3104,7 +3104,7 @@ class FusedMultiHeadAttentionXMMAKernelV2 : public TFusedMultiHeadAttentionXMMAK
bool flash_attention = false,
bool causal_mask = false) const {
s = flash_attention ? 0 : s;
return (uint64_t)s << 32 | d << 8 | (with_relative_position_bias ? 16ull : 0ull) | (flash_attention ? 8ull : 0ull) | (causal_mask ? 4ull : 0ull) | (interleaved ? 2ull : 0ull) | (unroll ? 1ull : 0ull);
return (uint64_t)s << 32 | (uint64_t)d << 8 | (with_relative_position_bias ? 16ull : 0ull) | (flash_attention ? 8ull : 0ull) | (causal_mask ? 4ull : 0ull) | (interleaved ? 2ull : 0ull) | (unroll ? 1ull : 0ull);
}
virtual uint64_t hashID(const KernelMeta& kernelMeta) const {

View file

@ -244,7 +244,7 @@ void InitGreedyState(transformers::IGreedySearchState<T>* greedy_state,
initStateRange.Begin();
#endif
cudaStream_t cuda_stream = ort_stream ? reinterpret_cast<cudaStream_t>(ort_stream->GetHandle()) : nullptr;
cudaStream_t cuda_stream = ort_stream ? reinterpret_cast<cudaStream_t>(ort_stream->GetHandle()) : nullptr;
CUDA_CALL_THROW(cudaMemsetAsync(greedy_state->next_token_scores.data(), 0, greedy_state->next_token_scores.size_bytes(), cuda_stream));
CUDA_CALL_THROW(cudaMemsetAsync(greedy_state->next_positions.data(), 0, greedy_state->next_positions.size_bytes(), cuda_stream));
@ -449,7 +449,7 @@ Status ProcessLogits(const OrtValue& logits, //
// Apply top-k selection like the following:
// next_token_scores = next_token_scores.view(batch_size, num_beams * vocab_size)
// next_token_scores, next_tokens = torch.topk(next_token_scores, 2 * num_beams, dim=1, largest=True, sorted=True)
int64_t next_token_scores_dims[] = {batch_size, num_beams * vocab_size};
int64_t next_token_scores_dims[] = {batch_size, static_cast<int64_t>(num_beams) * static_cast<int64_t>(vocab_size)};
TensorShape next_token_scores_shape(&next_token_scores_dims[0], 2);
auto element_type = DataTypeImpl::GetType<float>();

View file

@ -146,7 +146,7 @@ Status Transpose::DoTranspose(const cudaDeviceProp& prop,
for (auto i = new_rank - 1; i > 0; i--) {
auto curr = new_permutations[i];
auto prev = new_permutations[i - 1];
auto prev = new_permutations[static_cast<ptrdiff_t>(i) - 1];
if (prev + 1 == curr) {
// all dims bigger than curr need to be reduced by 1 due to the merging.
for (auto j = 0; j < new_rank; j++) {