From 9acbfeba0962370ea7299770c28e2d5f009b9dea Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Tue, 16 Nov 2021 10:24:46 -0800 Subject: [PATCH] Address some code scan issues. (#9752) --- include/onnxruntime/core/common/status.h | 16 ++++++++-------- .../training_ops/cuda/optimizer/lamb.cu | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/onnxruntime/core/common/status.h b/include/onnxruntime/core/common/status.h index 2f8e75186b..f348e7e653 100644 --- a/include/onnxruntime/core/common/status.h +++ b/include/onnxruntime/core/common/status.h @@ -47,7 +47,7 @@ enum StatusCode { EP_FAIL = 11 }; -inline const char* StatusCodeToString(StatusCode status) noexcept { +constexpr const char* StatusCodeToString(StatusCode status) noexcept { switch (status) { case StatusCode::OK: return "SUCCESS"; @@ -79,7 +79,7 @@ inline const char* StatusCodeToString(StatusCode status) noexcept { } #ifdef _WIN32 -inline HRESULT StatusCodeToHRESULT(StatusCode status) noexcept { +constexpr HRESULT StatusCodeToHRESULT(StatusCode status) noexcept { switch (status) { case StatusCode::OK: @@ -89,23 +89,23 @@ inline HRESULT StatusCodeToHRESULT(StatusCode status) noexcept { case StatusCode::INVALID_ARGUMENT: return E_INVALIDARG; case StatusCode::NO_SUCHFILE: - return __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); + return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); case StatusCode::NO_MODEL: - return __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); + return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); case StatusCode::ENGINE_ERROR: return E_FAIL; case StatusCode::RUNTIME_EXCEPTION: return E_FAIL; case StatusCode::INVALID_PROTOBUF: - return __HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT); + return HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT); case StatusCode::MODEL_LOADED: - return __HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR); + return HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR); case StatusCode::NOT_IMPLEMENTED: return E_NOTIMPL; case StatusCode::INVALID_GRAPH: - return __HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT); + return HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT); case StatusCode::EP_FAIL: - return __HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR); + return HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR); default: return E_FAIL; } diff --git a/orttraining/orttraining/training_ops/cuda/optimizer/lamb.cu b/orttraining/orttraining/training_ops/cuda/optimizer/lamb.cu index 269b4c7b15..ed289497f5 100644 --- a/orttraining/orttraining/training_ops/cuda/optimizer/lamb.cu +++ b/orttraining/orttraining/training_ops/cuda/optimizer/lamb.cu @@ -630,8 +630,8 @@ void LambMultiTensorReductionFunctor::operator() const int shared_memory_size = thread_count / GPU_WARP_SIZE * 2 * sizeof(TBuf); // Enforce assumptions used inside this reduction CUDA kernel. - ORT_ENFORCE(thread_count % GPU_WARP_SIZE == 0); - ORT_ENFORCE((thread_count & (thread_count - 1)) == 0); + static_assert(thread_count % GPU_WARP_SIZE == 0, "thread_count must be a multiple of GPU_WARP_SIZE"); + static_assert((thread_count & (thread_count - 1)) == 0, "thread_count must be a power of two"); const int num_blocks = chunk_group.chunk_count; const size_t w_buffer_size = num_blocks * sizeof(TOut1);