diff --git a/onnxruntime/contrib_ops/cpu/bert/attention_cpu_base.h b/onnxruntime/contrib_ops/cpu/bert/attention_cpu_base.h index 1d08638a7c..4295bec018 100644 --- a/onnxruntime/contrib_ops/cpu/bert/attention_cpu_base.h +++ b/onnxruntime/contrib_ops/cpu/bert/attention_cpu_base.h @@ -144,7 +144,9 @@ class AttentionCPUBase : public AttentionBase { // Broadcast mask data: (Bx)SxS* -> (BxNx)SxS* if (mask_data != nullptr) { - memcpy(output, mask_data + mask_offset, sequence_length * all_sequence_length * sizeof(T)); + memcpy(output, + mask_data + mask_offset, + static_cast(sequence_length) * all_sequence_length * sizeof(T)); } const T* k = K + input_chunk_length * i; diff --git a/onnxruntime/contrib_ops/cpu/bert/attention_helper.h b/onnxruntime/contrib_ops/cpu/bert/attention_helper.h index 9b05f30ce8..7de6b07127 100644 --- a/onnxruntime/contrib_ops/cpu/bert/attention_helper.h +++ b/onnxruntime/contrib_ops/cpu/bert/attention_helper.h @@ -91,7 +91,7 @@ void PrepareMask(const int32_t* mask_index, p_mask[s_i * all_sequence_length + m_i] += static_cast(-10000.0f); } } - p_mask += sequence_length * all_sequence_length; + p_mask += static_cast(sequence_length) * all_sequence_length; } } diff --git a/onnxruntime/contrib_ops/cpu/transformers/beam_search_impl_base.h b/onnxruntime/contrib_ops/cpu/transformers/beam_search_impl_base.h index 6653df838e..847b916cf2 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/beam_search_impl_base.h +++ b/onnxruntime/contrib_ops/cpu/transformers/beam_search_impl_base.h @@ -141,11 +141,13 @@ class BeamSearchBase : public GenerateBase { parameters_->ParseFromInputs(&context); } + ~BeamSearchBase() override = default; + // Initialize by validating all the inputs, and allocating the output tensors. - Status Initialize(); + Status Initialize() override; // Validate inputs. - Status CheckInputs(const OpKernelContextInternal& context); + Status CheckInputs(const OpKernelContextInternal& context) override; protected: // Process logits and append next tokens to sequences. diff --git a/onnxruntime/contrib_ops/cpu/transformers/generate_impl_base.h b/onnxruntime/contrib_ops/cpu/transformers/generate_impl_base.h index 7889d5bd4b..3964d50c6d 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/generate_impl_base.h +++ b/onnxruntime/contrib_ops/cpu/transformers/generate_impl_base.h @@ -56,6 +56,8 @@ class GenerateBase { ->GetAllocator(0, OrtMemTypeDefault); } + virtual ~GenerateBase() = default; + // Initialize by validating all the inputs, and allocating the output tensors. virtual Status Initialize() = 0; diff --git a/onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc b/onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc index aaa3097932..eb29dea924 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc +++ b/onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc @@ -449,7 +449,7 @@ Status GreedySearchProcessLogits( const Tensor& input = next_token_scores_value.Get(); constexpr int axis = 1; - const unsigned top_k = static_cast(1); + constexpr unsigned top_k = 1; constexpr bool largest = true; constexpr bool sorted = false; @@ -771,7 +771,7 @@ Status UpdateDecoderFeeds( #endif // Update past state - ORT_ENFORCE(last_outputs.size() >= static_cast(1 + num_present_tensors)); + ORT_ENFORCE(last_outputs.size() >= static_cast(1) + num_present_tensors); // TODO(tianleiwu): remove num_beams==1 once GreedySearch operator is available. if (num_beams == 1) { // feed present_* output to past_* inputs one by one diff --git a/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_base.h b/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_base.h index ec408dc86f..eacfd124b9 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_base.h +++ b/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_base.h @@ -92,11 +92,13 @@ class GreedySearchBase : public GenerateBase { parameters_->ParseFromInputs(&context); } + ~GreedySearchBase() override = default; + // Initialize by validating all the inputs, and allocating the output tensors. - Status Initialize(); + Status Initialize() override; // Validate inputs. - Status CheckInputs(const OpKernelContextInternal& context); + Status CheckInputs(const OpKernelContextInternal& context) override; protected: // Process logits and append next tokens to sequences. diff --git a/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_gpt.h b/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_gpt.h index a98df8c7e2..845925575b 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_gpt.h +++ b/onnxruntime/contrib_ops/cpu/transformers/greedy_search_impl_gpt.h @@ -225,7 +225,9 @@ Status GreedySearchGpt::Execute(const FeedsFetchesManager& feeds_fetches_mana // Copy the sequences to output gsl::span output = output_sequences->MutableDataAsSpan(); for (int batch_id = 0; batch_id < parameters->batch_size; ++batch_id) { - auto batch_output = output.subspan(batch_id * parameters->max_length, parameters->max_length); + auto batch_output = output.subspan( + static_cast(batch_id) * parameters->max_length, + parameters->max_length); gsl::span sequence_source = greedy_state.sequences.GetSequence(batch_id); gsl::copy(sequence_source, batch_output); } diff --git a/onnxruntime/contrib_ops/cpu/transformers/subgraph_t5_decoder.cc b/onnxruntime/contrib_ops/cpu/transformers/subgraph_t5_decoder.cc index e96885cef5..d9ee9a3ba9 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/subgraph_t5_decoder.cc +++ b/onnxruntime/contrib_ops/cpu/transformers/subgraph_t5_decoder.cc @@ -161,7 +161,7 @@ Status T5DecoderSubgraph::CreateInitialFeeds( // When first_past_input_index_ == 3, the encoder_hidden_states and past states are copied from the second output // of encoder. // When first_past_input_index_ == 2, the past states are copied from the second output of encoder. - for (size_t j = 4 - first_past_input_index_; j < encoder_fetches.size(); j++) { + for (size_t j = static_cast(4) - first_past_input_index_; j < encoder_fetches.size(); j++) { if (j == 1) { ORT_RETURN_IF(has_hidden_state_ == false, "Invalid hidden_states expension: has_hidden_state_ == false"); OrtValue expanded_hidden_states; diff --git a/onnxruntime/contrib_ops/cuda/bert/attention.cc b/onnxruntime/contrib_ops/cuda/bert/attention.cc index 47d5e5eab3..a652ff41ba 100644 --- a/onnxruntime/contrib_ops/cuda/bert/attention.cc +++ b/onnxruntime/contrib_ops/cuda/bert/attention.cc @@ -123,7 +123,8 @@ Status Attention::ComputeInternal(OpKernelContext* context) const { int m = batch_size * sequence_length; int n = 3 * hidden_size; int k = input_hidden_size; - auto gemm_buffer = GetScratchBuffer(batch_size * sequence_length * 3 * hidden_size * element_size); + size_t gemm_buffer_size = static_cast(batch_size) * sequence_length * 3 * hidden_size * element_size; + auto gemm_buffer = GetScratchBuffer(gemm_buffer_size); typedef typename ToCudaType::MappedType CudaT; CudaT one = ToCudaType::FromFloat(1.0f); diff --git a/onnxruntime/contrib_ops/cuda/bert/longformer_attention.cc b/onnxruntime/contrib_ops/cuda/bert/longformer_attention.cc index 4a0155705b..4aea30d065 100644 --- a/onnxruntime/contrib_ops/cuda/bert/longformer_attention.cc +++ b/onnxruntime/contrib_ops/cuda/bert/longformer_attention.cc @@ -79,7 +79,7 @@ Status LongformerAttention::ComputeInternal(OpKernelContext* context) const { // TODO(tianleiwu): only calculate global index once per model instead of once per LongformerAttention node. // Build Global Index - auto global_index_buffer = GetScratchBuffer(batch_size * sequence_length); + auto global_index_buffer = GetScratchBuffer(static_cast(batch_size) * sequence_length); auto batch_global_num_buffer = GetScratchBuffer(batch_size); size_t global_scratch_bytes = GetGlobalScratchSize(sequence_length); diff --git a/onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc b/onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc index 3679875a8a..85c571c189 100644 --- a/onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc +++ b/onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc @@ -249,7 +249,7 @@ Status ProcessLogits(const OrtValue& logits, // const CudaT* current_logits = logits_data + (input_length - 1) * vocab_size; for (int i = 0; i < batch_beam_size; i++) { gsl::span source(reinterpret_cast(current_logits), vocab_size); - gsl::span target = next_token_logits.subspan(i * vocab_size, vocab_size); + gsl::span target = next_token_logits.subspan(static_cast(i) * vocab_size, vocab_size); CUDA_RETURN_IF_ERROR(cudaMemcpyAsync(target.data(), source.data(), sizeof(T) * vocab_size, cudaMemcpyDeviceToDevice, cuda_stream)); if (logits_batch_size == batch_beam_size) { diff --git a/onnxruntime/core/providers/cuda/generator/range.cc b/onnxruntime/core/providers/cuda/generator/range.cc index 56189875df..1fa86af025 100644 --- a/onnxruntime/core/providers/cuda/generator/range.cc +++ b/onnxruntime/core/providers/cuda/generator/range.cc @@ -64,7 +64,8 @@ static Status ComputeRange(cudaStream_t stream, OpKernelContext* ctx) { return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "delta in Range operator can not be zero!"); } - int count = static_cast(ceil(1.0 * (limit - start) / delta)); + double num = (static_cast(limit) - static_cast(start)) / static_cast(delta); + int count = static_cast(ceil(num)); if (count <= 0) count = 0; TensorShape shape = {static_cast(count)};