From 659118f93914b3ca7bb6e0be5e58de0201ff3449 Mon Sep 17 00:00:00 2001 From: Ryan Hill <38674843+RyanUnderhill@users.noreply.github.com> Date: Tue, 28 Mar 2023 21:36:03 -0700 Subject: [PATCH] Prefast warning fixes (#15175) ### Description transpose.cc: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). cuda_provider_factory.cc: The type 'struct onnxruntime::ProviderInfo_CUDA_Impl' with a virtual function needs either public virtual or protected non-virtual destructor (c.35). --- onnxruntime/core/providers/cuda/cuda_provider_factory.cc | 3 ++- onnxruntime/core/providers/cuda/tensor/transpose.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/cuda/cuda_provider_factory.cc b/onnxruntime/core/providers/cuda/cuda_provider_factory.cc index 647fb98455..003dc57d61 100644 --- a/onnxruntime/core/providers/cuda/cuda_provider_factory.cc +++ b/onnxruntime/core/providers/cuda/cuda_provider_factory.cc @@ -52,7 +52,8 @@ std::unique_ptr CUDAProviderFactory::CreateProvider() { return std::make_unique(info_); } -struct ProviderInfo_CUDA_Impl : ProviderInfo_CUDA { +struct ProviderInfo_CUDA_Impl final : ProviderInfo_CUDA { + OrtStatus* SetCurrentGpuDeviceId(_In_ int device_id) override { int num_devices; auto cuda_err = ::cudaGetDeviceCount(&num_devices); diff --git a/onnxruntime/core/providers/cuda/tensor/transpose.cc b/onnxruntime/core/providers/cuda/tensor/transpose.cc index 17acc991a7..d056219a89 100644 --- a/onnxruntime/core/providers/cuda/tensor/transpose.cc +++ b/onnxruntime/core/providers/cuda/tensor/transpose.cc @@ -162,7 +162,7 @@ Status Transpose::DoTranspose(const cudaDeviceProp& prop, new_input_dims[prev] *= new_input_dims[curr]; new_input_dims[curr] = 1; for (auto j = static_cast(curr + 1); j < new_rank; j++) { - new_input_dims[j - 1] = new_input_dims[j]; + new_input_dims[static_cast(j) - 1] = new_input_dims[j]; } new_input_dims[new_rank - 1] = 1;