mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
Fix prefast warnings (#13017)
Fix prefast warnings: [C26451](https://learn.microsoft.com/en-us/cpp/code-quality/C26451?view=msvc-170) [C26436](https://learn.microsoft.com/en-us/cpp/code-quality/c26436?view=msvc-170) [C26814](https://learn.microsoft.com/en-us/cpp/code-quality/C26814?view=msvc-170)
This commit is contained in:
parent
8bb16ab900
commit
6f27659ceb
12 changed files with 26 additions and 14 deletions
|
|
@ -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<size_t>(sequence_length) * all_sequence_length * sizeof(T));
|
||||
}
|
||||
|
||||
const T* k = K + input_chunk_length * i;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ void PrepareMask(const int32_t* mask_index,
|
|||
p_mask[s_i * all_sequence_length + m_i] += static_cast<T>(-10000.0f);
|
||||
}
|
||||
}
|
||||
p_mask += sequence_length * all_sequence_length;
|
||||
p_mask += static_cast<size_t>(sequence_length) * all_sequence_length;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ Status GreedySearchProcessLogits(
|
|||
const Tensor& input = next_token_scores_value.Get<Tensor>();
|
||||
|
||||
constexpr int axis = 1;
|
||||
const unsigned top_k = static_cast<unsigned>(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<size_t>(1 + num_present_tensors));
|
||||
ORT_ENFORCE(last_outputs.size() >= static_cast<size_t>(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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -225,7 +225,9 @@ Status GreedySearchGpt<T>::Execute(const FeedsFetchesManager& feeds_fetches_mana
|
|||
// Copy the sequences to output
|
||||
gsl::span<int32_t> output = output_sequences->MutableDataAsSpan<int32_t>();
|
||||
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<size_t>(batch_id) * parameters->max_length,
|
||||
parameters->max_length);
|
||||
gsl::span<const int32_t> sequence_source = greedy_state.sequences.GetSequence(batch_id);
|
||||
gsl::copy(sequence_source, batch_output);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<size_t>(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;
|
||||
|
|
|
|||
|
|
@ -123,7 +123,8 @@ Status Attention<T>::ComputeInternal(OpKernelContext* context) const {
|
|||
int m = batch_size * sequence_length;
|
||||
int n = 3 * hidden_size;
|
||||
int k = input_hidden_size;
|
||||
auto gemm_buffer = GetScratchBuffer<T>(batch_size * sequence_length * 3 * hidden_size * element_size);
|
||||
size_t gemm_buffer_size = static_cast<size_t>(batch_size) * sequence_length * 3 * hidden_size * element_size;
|
||||
auto gemm_buffer = GetScratchBuffer<T>(gemm_buffer_size);
|
||||
|
||||
typedef typename ToCudaType<T>::MappedType CudaT;
|
||||
CudaT one = ToCudaType<T>::FromFloat(1.0f);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ Status LongformerAttention<T>::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<int>(batch_size * sequence_length);
|
||||
auto global_index_buffer = GetScratchBuffer<int>(static_cast<size_t>(batch_size) * sequence_length);
|
||||
auto batch_global_num_buffer = GetScratchBuffer<int>(batch_size);
|
||||
|
||||
size_t global_scratch_bytes = GetGlobalScratchSize(sequence_length);
|
||||
|
|
|
|||
|
|
@ -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<const T> source(reinterpret_cast<const T*>(current_logits), vocab_size);
|
||||
gsl::span<T> target = next_token_logits.subspan(i * vocab_size, vocab_size);
|
||||
gsl::span<T> target = next_token_logits.subspan(static_cast<size_t>(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) {
|
||||
|
|
|
|||
|
|
@ -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<int>(ceil(1.0 * (limit - start) / delta));
|
||||
double num = (static_cast<double>(limit) - static_cast<double>(start)) / static_cast<double>(delta);
|
||||
int count = static_cast<int>(ceil(num));
|
||||
if (count <= 0)
|
||||
count = 0;
|
||||
TensorShape shape = {static_cast<int64_t>(count)};
|
||||
|
|
|
|||
Loading…
Reference in a new issue