From 5a64cde29f2d8a048675ed2ad2e8c9e4bfc66fde Mon Sep 17 00:00:00 2001 From: lizhenyu Date: Thu, 2 Feb 2023 14:55:59 +0800 Subject: [PATCH] fix code check warnings --- .../ccsrc/plugin/device/cpu/hal/device/cpu_common.h | 4 ++-- .../ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h | 10 +++++++--- .../gpu/optimizer/trt_pass/trt_converter_context.h | 5 ++++- .../embedding_cache/embedding_cache_prefetch_actor.cc | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mindspore/ccsrc/plugin/device/cpu/hal/device/cpu_common.h b/mindspore/ccsrc/plugin/device/cpu/hal/device/cpu_common.h index 1091dbecd10..a977dee8436 100644 --- a/mindspore/ccsrc/plugin/device/cpu/hal/device/cpu_common.h +++ b/mindspore/ccsrc/plugin/device/cpu/hal/device/cpu_common.h @@ -23,12 +23,12 @@ namespace mindspore { namespace device { namespace cpu { #define CHECK_RET_WITH_EXCEPT(expression, status, message) \ - { \ + do { \ auto ret = (expression); \ if (ret != (status)) { \ MS_LOG(EXCEPTION) << (message); \ } \ - } + } while (0); } // namespace cpu } // namespace device } // namespace mindspore diff --git a/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h b/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h index 24689c6bd0d..06c440d7a44 100644 --- a/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h +++ b/mindspore/ccsrc/plugin/device/gpu/kernel/trt/trt_utils.h @@ -133,6 +133,10 @@ class TrtLogger : public nvinfer1::ILogger { {Severity::kERROR, {MsLogLevel::kError, google::GLOG_ERROR, "ERROR"}}, {Severity::kINTERNAL_ERROR, {MsLogLevel::kError, google::GLOG_ERROR, "INTERNAL ERROR"}}}; + static const size_t kMsLogLevelIndex = 0; + static const size_t kGoogleLogLevelIndex = 1; + static const size_t kLogLevelDescriptionIndex = 2; + auto iter = logger_map.find(severity); if (iter == logger_map.end()) { google::LogMessage("", 0, google::GLOG_WARNING).stream() << "Unrecognized severity type: " << msg << std::endl; @@ -141,12 +145,12 @@ class TrtLogger : public nvinfer1::ILogger { auto level = iter->second; // discard log - if (std::get<0>(level) < log_level_) { + if (std::get(level) < log_level_) { return; } - google::LogMessage("", 0, std::get<1>(level)).stream() - << "[TensorRT " << std::get<2>(level) << "] " << msg << std::endl; + google::LogMessage("", 0, std::get(level)).stream() + << "[TensorRT " << std::get(level) << "] " << msg << std::endl; #undef google #endif // USE_GLOG } diff --git a/mindspore/ccsrc/plugin/device/gpu/optimizer/trt_pass/trt_converter_context.h b/mindspore/ccsrc/plugin/device/gpu/optimizer/trt_pass/trt_converter_context.h index 77e0dc1d6c4..118695f8443 100644 --- a/mindspore/ccsrc/plugin/device/gpu/optimizer/trt_pass/trt_converter_context.h +++ b/mindspore/ccsrc/plugin/device/gpu/optimizer/trt_pass/trt_converter_context.h @@ -32,6 +32,9 @@ namespace mindspore { namespace opt { +// The const number 4GB in bytes. +constexpr size_t kFourGBytes = 4UL << 30; + // Class transform ANF graph to Tensor-RT network. // It converts the operators in ANF graph to Tensor-RT layer according to the topological order. // During the conversion, the cache keep the map between ANF node outputs and Tensor-RT layer outputs. @@ -43,7 +46,7 @@ class TrtConverterContext : public std::enable_shared_from_this= 0 && index < SizeToInt(first_dim_size)) { - size_t pos = index * embedding_size; + size_t pos = IntToSize(index) * embedding_size; auto ret = memcpy_s(output_addr, (indices_num - i) * lens, input_addr + pos, lens); if (ret != EOK) { MS_LOG(ERROR) << "Memcpy failed, errno[" << ret << "]";