From d009d83dd2a1f22a66240c2c15a6b050a3fefa58 Mon Sep 17 00:00:00 2001 From: maning202007 Date: Mon, 8 Aug 2022 16:23:01 +0800 Subject: [PATCH] fix code warnings for grid_sampler_2d_grad_cpu_kernel Fix some errors for debug_services --- mindspore/ccsrc/debug/debug_services.cc | 18 +++------- mindspore/ccsrc/debug/debug_services.h | 20 +++++------ .../ascend/hal/device/dump/data_dumper.cc | 4 +-- .../kernel/grid_sampler_2d_grad_cpu_kernel.cc | 9 ++--- .../kernel/grid_sampler_2d_grad_cpu_kernel.h | 33 +++++++++++++++---- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/mindspore/ccsrc/debug/debug_services.cc b/mindspore/ccsrc/debug/debug_services.cc index 8fab30d9de5..7ed983dd6b5 100644 --- a/mindspore/ccsrc/debug/debug_services.cc +++ b/mindspore/ccsrc/debug/debug_services.cc @@ -860,7 +860,7 @@ void DebugServices::ReadTensorFromNpy(const std::string &tensor_name, const std: * Description: This function is to convert files in each directory from device format to host format and append the * converted npy file name into NPYFilePool. It's for Ascend async dump only. */ -void DebugServices::ConvertToHostFormat(const DirMap &dir_to_files_map, NPYFilePool *const result_list) { +void DebugServices::ConvertToHostFormat(const DirMap &dir_to_files_map, NPYFilePool *const result_list) const { for (auto const &d : dir_to_files_map) { std::vector files_to_convert_in_dir; std::vector files_after_convert_in_dir; @@ -910,7 +910,7 @@ void DebugServices::ConvertToHostFormat(const DirMap &dir_to_files_map, NPYFileP * append into NPYFilePool. It's for Ascend async dump only. */ void DebugServices::ProcessConvertToHostFormat(const std::vector &files_after_convert_in_dir, - const std::string &dump_key, NPYFilePool *const result_list) { + const std::string &dump_key, NPYFilePool *const result_list) const { std::string real_dump_iter_dir = RealPath(dump_key); DIR *d_handle = opendir(real_dump_iter_dir.c_str()); if (d_handle == nullptr) { @@ -1003,7 +1003,7 @@ void DebugServices::ConvertReadTensors(std::vector backend_name, st void DebugServices::ConvertWatchPointNodes(const DumpFileMap &dump_dir_mapped_files, const std::vector &proto_dump, - const std::string &specific_dump_dir, NPYFilePool *const result_list) { + const std::string &specific_dump_dir, NPYFilePool *const result_list) const { DirMap dir_to_files_map; for (const auto &node : proto_dump) { std::string dump_name = node.dump_name; @@ -1114,7 +1114,7 @@ DebugServices::NPYFilePool DebugServices::PreProcessDumpDirSync(const std::strin void DebugServices::ProcessConvertList(const DumpFileMap &dump_dir_mapped_files, const std::string &prefix_dump_file_name, const std::string &specific_dump_dir, - DirMap *dir_to_files_map, NPYFilePool *const result_list) { + DirMap *dir_to_files_map, NPYFilePool *const result_list) const { MS_EXCEPTION_IF_NULL(dir_to_files_map); auto it = dump_dir_mapped_files.find(specific_dump_dir); if (it == dump_dir_mapped_files.end()) { @@ -2158,7 +2158,7 @@ bool DebugServices::GetAttrsFromFilename(const std::string &file_name, std::stri return true; } -std::string DebugServices::RealPath(const std::string &input_path) { +std::string DebugServices::RealPath(const std::string &input_path) const { if (input_path.length() >= PATH_MAX) { MS_LOG(EXCEPTION) << "The length of path: " << input_path << " exceeds limit: " << PATH_MAX; } @@ -2195,14 +2195,6 @@ std::string DebugServices::RealPath(const std::string &input_path) { return std::string(real_path); } -uint64_t DebugServices::BytestoUInt64(const std::vector &buffer) { -#if defined(__APPLE__) - return *reinterpret_cast(buffer.data()); -#else - return le64toh(*reinterpret_cast(buffer.data())); -#endif -} - bool DebugServices::TensorExistsInCurrent(const std::string &tensor_name) { return tensor_loader_->TensorExistsInCurrent(tensor_name); } diff --git a/mindspore/ccsrc/debug/debug_services.h b/mindspore/ccsrc/debug/debug_services.h index bf882bb461c..25017171478 100644 --- a/mindspore/ccsrc/debug/debug_services.h +++ b/mindspore/ccsrc/debug/debug_services.h @@ -400,21 +400,21 @@ class DebugServices { ProcessedNPYFiles ProcessNPYFilePool(const NPYFilePool &npy_file_pool) const; - static void ConvertToHostFormat(const DirMap &dir_to_files_map, NPYFilePool *const result_list); + void ConvertToHostFormat(const DirMap &dir_to_files_map, NPYFilePool *const result_list) const; - static void ProcessConvertToHostFormat(const std::vector &files_after_convert_in_dir, - const std::string &dump_key, NPYFilePool *const result_list); + void ProcessConvertToHostFormat(const std::vector &files_after_convert_in_dir, + const std::string &dump_key, NPYFilePool *const result_list) const; void ConvertReadTensors(std::vector backend_name, std::vector slot, std::vector device_id, std::vector iteration, std::vector root_graph_id, NPYFilePool *const result_list); - static void ConvertWatchPointNodes(const DumpFileMap &dump_dir_mapped_files, const std::vector &proto_dump, - const std::string &specific_dump_dir, NPYFilePool *const result_list); + void ConvertWatchPointNodes(const DumpFileMap &dump_dir_mapped_files, const std::vector &proto_dump, + const std::string &specific_dump_dir, NPYFilePool *const result_list) const; - static void ProcessConvertList(const DumpFileMap &dump_dir_mapped_files, const std::string &prefix_dump_file_name, - const std::string &specific_dump_dir, DirMap *dir_to_files_map, - NPYFilePool *const result_list); + void ProcessConvertList(const DumpFileMap &dump_dir_mapped_files, const std::string &prefix_dump_file_name, + const std::string &specific_dump_dir, DirMap *dir_to_files_map, + NPYFilePool *const result_list) const; void GetTensorDataInfoAsync(const std::vector &proto_dump, const std::string &specific_dump_dir, uint32_t iteration, uint32_t device_id, uint32_t root_graph_id, @@ -482,9 +482,7 @@ class DebugServices { bool GetAttrsFromFilename(const std::string &file_name, std::string *const node_name, uint64_t *const task_id, uint64_t *const stream_id) const; - static std::string RealPath(const std::string &input_path); - - static uint64_t BytestoUInt64(const std::vector &buffer); + std::string RealPath(const std::string &input_path) const; bool TensorExistsInCurrent(const std::string &tensor_name); diff --git a/mindspore/ccsrc/plugin/device/ascend/hal/device/dump/data_dumper.cc b/mindspore/ccsrc/plugin/device/ascend/hal/device/dump/data_dumper.cc index 1aaa6770810..2fc2bda281c 100644 --- a/mindspore/ccsrc/plugin/device/ascend/hal/device/dump/data_dumper.cc +++ b/mindspore/ccsrc/plugin/device/ascend/hal/device/dump/data_dumper.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -339,7 +339,7 @@ void DataDumper::OpDebugRegister() { is_op_debug_ = true; int64_t value = 0; - rtError_t rt_ret = rtGetRtCapability(FEATURE_TYPE_MEMORY, MEMORY_INFO_TS_LIMITED, &value); + rtError_t rt_ret = rtGetRtCapability(FEATURE_TYPE_MEMORY, static_cast(MEMORY_INFO_TS_LIMITED), &value); if (rt_ret != RT_ERROR_NONE) { MS_LOG(EXCEPTION) << "[DataDump] Call rt api rtGetRtCapability failed, ret = " << rt_ret; } diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.cc index cc85d4c4fd2..3b0e81ac664 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.cc @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright 2021-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,12 +76,13 @@ void GridSampler2DGradCpuKernelMod::ComputeTask(const std::vector &i } else if (interpolation_mode_ == "nearest") { interp = GridSamplerInterpolation::Nearest; } - if (padding_mode_ == "zeros") + if (padding_mode_ == "zeros") { padding = GridSamplerPadding::Zeros; - else if (padding_mode_ == "border") + } else if (padding_mode_ == "border") { padding = GridSamplerPadding::Border; - else + } else { padding = GridSamplerPadding::Reflection; + } int64_t N = x_shape_[kZero]; diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.h b/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.h index 0f753ece73e..b21860da56c 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.h +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/grid_sampler_2d_grad_cpu_kernel.h @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright 2021-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -135,15 +135,26 @@ struct Vec256 { Vec256 trunc() const { return map(std::trunc); } static Vec256 LoadU(const void *ptr) { Vec256 vec; - std::memcpy(vec.values, ptr, 32); // 32 + auto cp_ret = memcpy_s(static_cast(vec.values), 32, ptr, 32); + if (cp_ret != EOK) { + MS_LOG(ERROR) << "memcpy_s failed. errorno is: " << cp_ret; + } return vec; } static Vec256 LoadU(const void *ptr, int64_t count) { Vec256 vec; - std::memcpy(vec.values, ptr, count * sizeof(T)); + auto cp_ret = memcpy_s(static_cast(vec.values), count * sizeof(T), ptr, count * sizeof(T)); + if (cp_ret != EOK) { + MS_LOG(ERROR) << "memcpy_s failed. errorno is: " << cp_ret; + } return vec; } - void store(void *ptr, int count = size()) const { std::memcpy(ptr, values, count * sizeof(T)); } + void store(void *ptr, int count = size()) const { + auto cp_ret = memcpy_s(ptr, count * sizeof(T), values, count * sizeof(T)); + if (cp_ret != EOK) { + MS_LOG(ERROR) << "memcpy_s failed. errorno is: " << cp_ret; + } + } const T &operator[](int idx) const { return values[idx]; } T &operator[](int idx) { return values[idx]; } int zero_mask() const { @@ -234,9 +245,15 @@ struct Vec256 { Vec256 vec; for (int64_t i = 0; i != size(); i++) { if (op(values[i], other.values[i])) { - std::memset(static_cast(vec.values + i), 0xFF, sizeof(T)); + auto ret = memset_s(static_cast(vec.values + i), sizeof(T), 0xFF, sizeof(T)); + if (ret != 0) { + MS_LOG(ERROR) << "memset_s error, errorno(" << ret << ")"; + } } else { - std::memset(static_cast(vec.values + i), 0, sizeof(T)); + auto ret = memset_s(static_cast(vec.values + i), sizeof(T), 0, sizeof(T)); + if (ret != 0) { + MS_LOG(ERROR) << "memset_s error, errorno(" << ret << ")"; + } } } return vec; @@ -862,6 +879,10 @@ struct ApplyGridSample2D(GGridPtr), sizeof(T) * len * hTwo, 0, sizeof(T) * len * hTwo); + if (ret != 0) { + MS_LOG(ERROR) << "memset_s error, errorno(" << ret << ")"; + } } };