From 58f3ea002d05ad690f5365de7970a8580ac0e26e Mon Sep 17 00:00:00 2001 From: caifubi Date: Wed, 31 Mar 2021 11:18:59 +0800 Subject: [PATCH] clean codex --- .../kernel_compiler/hccl/hccl_context.cc | 24 ++++------ .../device/ascend/ascend_kernel_runtime.cc | 1 - .../ascend/executor/ai_cpu_dynamic_kernel.cc | 1 - .../ascend/executor/aicpu_ext_info_handle.cc | 5 +- .../device/executor/executor_callback.cc | 39 --------------- .../device/executor/executor_callback.h | 47 ------------------- mindspore/ops/operations/nn_ops.py | 2 + .../stub/dynamic_shape/dynamic_shape_stub.cc | 8 ---- 8 files changed, 16 insertions(+), 111 deletions(-) delete mode 100644 mindspore/ccsrc/runtime/device/executor/executor_callback.cc delete mode 100644 mindspore/ccsrc/runtime/device/executor/executor_callback.h diff --git a/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_context.cc b/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_context.cc index abf501ba0f1..aa4070db0ed 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_context.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_context.cc @@ -23,13 +23,16 @@ constexpr auto kHcclConfigFileOld = "RANK_TABLE_FILE"; namespace mindspore { namespace kernel { -std::string GetRankId() { - std::string rank_id_str; - rank_id_str = std::getenv("RANK_ID"); - if (rank_id_str.empty()) { - MS_LOG(ERROR) << "Get hccl rankid failed, please set env RANK_ID"; +int GetRankId() { + auto rank_id_env = std::getenv("RANK_ID"); + if (rank_id_env == nullptr) { + MS_LOG(EXCEPTION) << "No RANK_ID, please export RANK_ID"; + } + try { + return std::stoi(rank_id_env); + } catch (std::invalid_argument &e) { + MS_LOG(EXCEPTION) << "Invalid rankd id env:" << rank_id_env; } - return rank_id_str; } bool HcclContext::InitHccl() { @@ -45,14 +48,7 @@ bool HcclContext::InitHccl() { } } - auto rank_id = GetRankId(); - try { - rank_id_ = std::stoi(rank_id); - } catch (std::invalid_argument &e) { - MS_LOG(ERROR) << "Invalid rankd id env:" << rank_id; - return false; - } - + rank_id_ = GetRankId(); if (rank_id_ < 0 || rank_id_ > 7) { MS_LOG(ERROR) << "rank_id needs to be between 0-7"; return false; diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc b/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc index 4fc0db50dfc..653989f19c6 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc @@ -46,7 +46,6 @@ #include "backend/optimizer/mem_reuse/mem_reuse_checker.h" #endif #include "runtime/device/ascend/executor/tiling/op_tiling_calculater.h" -#include "runtime/device/executor/executor_callback.h" #include "runtime/device/ascend/executor/hccl_dynamic_kernel.h" #include "utils/config_manager.h" #include "runtime/device/ascend/profiling/reporter/op_name_task_stream_reporter.h" diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/ai_cpu_dynamic_kernel.cc b/mindspore/ccsrc/runtime/device/ascend/executor/ai_cpu_dynamic_kernel.cc index 4bce9f5e15c..fb1f0f00a51 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/ai_cpu_dynamic_kernel.cc +++ b/mindspore/ccsrc/runtime/device/ascend/executor/ai_cpu_dynamic_kernel.cc @@ -24,7 +24,6 @@ #include "utils/utils.h" #include "backend/session/anf_runtime_algorithm.h" #include "backend/kernel_compiler/aicpu/aicpu_util.h" -#include "runtime/device/executor/executor_callback.h" namespace mindspore { namespace device { diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/aicpu_ext_info_handle.cc b/mindspore/ccsrc/runtime/device/ascend/executor/aicpu_ext_info_handle.cc index 181161a7e8c..ae48ea620a9 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/aicpu_ext_info_handle.cc +++ b/mindspore/ccsrc/runtime/device/ascend/executor/aicpu_ext_info_handle.cc @@ -37,7 +37,10 @@ bool AicpuExtInfoHandler::Parse(const std::string &ext_info) { ext_info_.reset(new (std::nothrow) uint8_t[ext_info_len_]); MS_EXCEPTION_IF_NULL(ext_info_); - (void)memcpy_s(ext_info_.get(), ext_info_len_, ext_info.c_str(), ext_info.size()); + auto ret = memcpy_s(ext_info_.get(), ext_info_len_, ext_info.c_str(), ext_info.size()); + if (ret != 0) { + MS_LOG(EXCEPTION) << "The memcpy_s failed, errorno(" << ret << ")"; + } input_shape_and_type_.clear(); output_shape_and_type_.clear(); diff --git a/mindspore/ccsrc/runtime/device/executor/executor_callback.cc b/mindspore/ccsrc/runtime/device/executor/executor_callback.cc deleted file mode 100644 index fb7dbc51686..00000000000 --- a/mindspore/ccsrc/runtime/device/executor/executor_callback.cc +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2020 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "runtime/device/executor/executor_callback.h" -#include "utils/log_adapter.h" - -namespace mindspore { -namespace device { -void ExecutorCallback::RegistCallback(const std::function &callback) { - std::lock_guard guard(lock_); - callback_queue_.push(callback); -} - -void ExecutorCallback::Consume() { - std::lock_guard guard(lock_); - while (!callback_queue_.empty()) { - auto callback_func = callback_queue_.front(); - callback_queue_.pop(); - if (!callback_func) { - MS_LOG(EXCEPTION) << "callback_func is empty"; - } - callback_func(); - } -} -} // namespace device -} // namespace mindspore diff --git a/mindspore/ccsrc/runtime/device/executor/executor_callback.h b/mindspore/ccsrc/runtime/device/executor/executor_callback.h deleted file mode 100644 index 01c6793b47e..00000000000 --- a/mindspore/ccsrc/runtime/device/executor/executor_callback.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2020 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_EXECUTOR_EXECUTOR_CALLBACK_H_ -#define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_EXECUTOR_EXECUTOR_CALLBACK_H_ - -#include -#include -#include -#include "utils/ms_utils.h" - -namespace mindspore { -namespace device { -class ExecutorCallback { - public: - static ExecutorCallback &GetInstance() { - static ExecutorCallback instance; - return instance; - } - - void RegistCallback(const std::function &callback); - void Consume(); - - private: - ExecutorCallback() = default; - ~ExecutorCallback() = default; - DISABLE_COPY_AND_ASSIGN(ExecutorCallback); - - std::queue> callback_queue_; - std::mutex lock_; -}; -} // namespace device -} // namespace mindspore -#endif // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_EXECUTOR_EXECUTOR_CALLBACK_H_ diff --git a/mindspore/ops/operations/nn_ops.py b/mindspore/ops/operations/nn_ops.py index aa6141780a4..a02beecace9 100644 --- a/mindspore/ops/operations/nn_ops.py +++ b/mindspore/ops/operations/nn_ops.py @@ -1124,6 +1124,7 @@ class BatchNorm(PrimitiveWithInfer): Inputs: If `is_training` is False, inputs are Tensors. + - **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type. - **scale** (Tensor) - Tensor of shape :math:`(C,)`, with float16 or float32 data type. - **bias** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`. @@ -1131,6 +1132,7 @@ class BatchNorm(PrimitiveWithInfer): - **variance** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `mean`. If `is_training` is True, `scale`, `bias`, `mean` and `variance` are Parameters. + - **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type. - **scale** (Parameter) - Parameter of shape :math:`(C,)`, with float16 or float32 data type. - **bias** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`. diff --git a/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc b/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc index 19f869baaf4..2f0a0031f00 100644 --- a/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc +++ b/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc @@ -19,19 +19,11 @@ #include "runtime/device/ascend/executor/rts/profiling_rts_dynamic_kernel.h" #include "runtime/device/ascend/executor/ai_core_dynamic_kernel.h" #include "profiler/device/ascend/rt_callback_manager.h" -#include "runtime/device/executor/executor_callback.h" #include "profiler/device/ascend/ascend_profiling.h" #include "runtime/device/ascend/executor/tiling/op_tiling_calculater.h" #include "backend/kernel_compiler/host/host_kernel_metadata.h" #include "backend/kernel_compiler/host/host_kernel_build.h" -namespace mindspore { -namespace device { -void ExecutorCallback::RegistCallback(const std::function &callback) {} -void ExecutorCallback::Consume() {} -} // namespace device -} // namespace mindspore - namespace mindspore { namespace device { namespace ascend {