From 137a2be01897e2af6af991cbd84a73217ef32183 Mon Sep 17 00:00:00 2001 From: chenfei Date: Thu, 9 Feb 2023 19:29:33 +0800 Subject: [PATCH] clean static code --- .../operator/composite/pybind_composite.cc | 2 +- .../include/common/pybind_api/api_register.h | 34 +++++++++---------- mindspore/ccsrc/pipeline/jit/init.cc | 4 +-- mindspore/ccsrc/pybind_api/ir/anf_py.cc | 2 +- mindspore/ccsrc/pybind_api/ir/cell_py.cc | 2 +- .../ccsrc/pybind_api/ir/func_graph_py.cc | 4 +-- .../ccsrc/pybind_api/ir/map_tensor_py.cc | 2 +- .../ccsrc/pybind_api/ir/param_info_py.cc | 2 +- mindspore/ccsrc/pybind_api/ir/primitive_py.cc | 2 +- mindspore/ccsrc/pybind_api/ir/signature_py.cc | 2 +- mindspore/ccsrc/pybind_api/ir/tensor_py.cc | 8 ++--- mindspore/ccsrc/pybind_api/ir/value_py.cc | 3 +- .../ccsrc/pybind_api/utils/ms_context_py.cc | 2 +- 13 files changed, 34 insertions(+), 35 deletions(-) diff --git a/mindspore/ccsrc/frontend/operator/composite/pybind_composite.cc b/mindspore/ccsrc/frontend/operator/composite/pybind_composite.cc index eb82b3e2cca..82b88e294ba 100644 --- a/mindspore/ccsrc/frontend/operator/composite/pybind_composite.cc +++ b/mindspore/ccsrc/frontend/operator/composite/pybind_composite.cc @@ -26,7 +26,7 @@ #include "frontend/operator/composite/zip_operation.h" namespace mindspore { namespace prim { -void RegCompositeOpsGroup(py::module *m) { +void RegCompositeOpsGroup(const py::module *m) { // Reg HyperMap (void)py::class_>(*m, "HyperMap_") .def(py::init>(), py::arg("reverse"), py::arg("ops")) diff --git a/mindspore/ccsrc/include/common/pybind_api/api_register.h b/mindspore/ccsrc/include/common/pybind_api/api_register.h index 645f0b452e4..774cfda63ad 100644 --- a/mindspore/ccsrc/include/common/pybind_api/api_register.h +++ b/mindspore/ccsrc/include/common/pybind_api/api_register.h @@ -24,16 +24,16 @@ namespace py = pybind11; namespace mindspore { void RegTyping(py::module *m); -void RegCNode(py::module *m); -void RegCell(py::module *m); -void RegMetaFuncGraph(py::module *m); -void RegFuncGraph(py::module *m); +void RegCNode(const py::module *m); +void RegCell(const py::module *m); +void RegMetaFuncGraph(const py::module *m); +void RegFuncGraph(const py::module *m); void RegUpdateFuncGraphHyperParams(py::module *m); -void RegParamInfo(py::module *m); -void RegPrimitive(py::module *m); -void RegSignatureEnumRW(py::module *m); -void RegValues(py::module *m); -void RegMsContext(py::module *m); +void RegParamInfo(const py::module *m); +void RegPrimitive(const py::module *m); +void RegSignatureEnumRW(const py::module *m); +void RegValues(const py::module *m); +void RegMsContext(const py::module *m); void RegSecurity(py::module *m); namespace initializer { @@ -45,22 +45,22 @@ void RegPyNativeExecutor(const py::module *m); } namespace tensor { -void RegMetaTensor(py::module *m); -void RegCSRTensor(py::module *m); -void RegCOOTensor(py::module *m); -void RegRowTensor(py::module *m); -void RegMapTensor(py::module *m); +void RegMetaTensor(const py::module *m); +void RegCSRTensor(const py::module *m); +void RegCOOTensor(const py::module *m); +void RegRowTensor(const py::module *m); +void RegMapTensor(const py::module *m); } // namespace tensor #ifndef ENABLE_SECURITY namespace profiler { -void RegProfilerManager(py::module *m); -void RegProfiler(py::module *m); +void RegProfilerManager(const py::module *m); +void RegProfiler(const py::module *m); } // namespace profiler #endif namespace prim { -void RegCompositeOpsGroup(py::module *m); +void RegCompositeOpsGroup(const py::module *m); } #ifdef _MSC_VER namespace abstract { diff --git a/mindspore/ccsrc/pipeline/jit/init.cc b/mindspore/ccsrc/pipeline/jit/init.cc index 567dd10c78d..600005265d5 100644 --- a/mindspore/ccsrc/pipeline/jit/init.cc +++ b/mindspore/ccsrc/pipeline/jit/init.cc @@ -73,7 +73,7 @@ using RecoveryContext = mindspore::distributed::recovery::RecoveryContext; #ifndef ENABLE_SECURITY namespace mindspore { namespace profiler { -void RegProfiler(py::module *m) { +void RegProfiler(const py::module *m) { (void)py::class_>(*m, "Profiler") .def_static("get_instance", &Profiler::GetInstance, py::arg("device_name"), "Profiler get_instance.") .def("init", &Profiler::Init, py::arg("profiling_path"), py::arg("device_id") = py::int_(0), @@ -86,7 +86,7 @@ void RegProfiler(py::module *m) { .def("step_profiling_enable", &Profiler::StepProfilingEnable, py::arg("enable_flag"), "enable or disable step profiling"); } -void RegProfilerManager(py::module *m) { +void RegProfilerManager(const py::module *m) { (void)py::class_>(*m, "ProfilerManager") .def_static("get_instance", &ProfilerManager::GetInstance, "ProfilerManager get_instance.") .def("dynamic_status", &ProfilerManager::GetNetDynamicShapeStatus, "dynamic_status"); diff --git a/mindspore/ccsrc/pybind_api/ir/anf_py.cc b/mindspore/ccsrc/pybind_api/ir/anf_py.cc index e48d91b65c3..1bbe20cfc7b 100644 --- a/mindspore/ccsrc/pybind_api/ir/anf_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/anf_py.cc @@ -20,7 +20,7 @@ namespace mindspore { // Define python 'CNode' class. -void RegCNode(py::module *m) { +void RegCNode(const py::module *m) { (void)py::class_(*m, "CNode") .def("expanded_str", (std::string(CNode::*)(int32_t) const) & CNode::DebugString, "Get CNode string representation with specified expansion level."); diff --git a/mindspore/ccsrc/pybind_api/ir/cell_py.cc b/mindspore/ccsrc/pybind_api/ir/cell_py.cc index 6e9c9d4a493..b39f3e2d23c 100644 --- a/mindspore/ccsrc/pybind_api/ir/cell_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/cell_py.cc @@ -39,7 +39,7 @@ void CellPy::AddAttr(CellPtr cell, const std::string &name, const py::object &ob } } // Define python 'Cell' class. -void RegCell(py::module *m) { +void RegCell(const py::module *m) { (void)py::enum_(*m, "MixedPrecisionType", py::arithmetic()) .value("NOTSET", MixedPrecisionType::kNotSet) .value("FP16", MixedPrecisionType::kFP16) diff --git a/mindspore/ccsrc/pybind_api/ir/func_graph_py.cc b/mindspore/ccsrc/pybind_api/ir/func_graph_py.cc index 2c5687d0c8b..30de7f6fdae 100644 --- a/mindspore/ccsrc/pybind_api/ir/func_graph_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/func_graph_py.cc @@ -60,7 +60,7 @@ py::dict UpdateFuncGraphHyperParams(const FuncGraphPtr &func_graph, const py::di return hyper_params; } -void RegFuncGraph(py::module *m) { +void RegFuncGraph(const py::module *m) { // Define python "FuncGraph" class (void)py::class_(*m, "FuncGraph") .def(py::init()) @@ -68,7 +68,7 @@ void RegFuncGraph(py::module *m) { .def("get_return", &FuncGraph::get_return, "Get return node of FuncGraph"); } -void RegMetaFuncGraph(py::module *m) { +void RegMetaFuncGraph(const py::module *m) { // Define python "MetaFuncGraph_" class (void)py::class_>(*m, "MetaFuncGraph_") .def("set_signatures", &MetaFuncGraph::set_signatures, "Set primitive inputs signature."); diff --git a/mindspore/ccsrc/pybind_api/ir/map_tensor_py.cc b/mindspore/ccsrc/pybind_api/ir/map_tensor_py.cc index 2ab5cbc5784..099bcd3ffc9 100644 --- a/mindspore/ccsrc/pybind_api/ir/map_tensor_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/map_tensor_py.cc @@ -94,7 +94,7 @@ static std::pair PyMapTensorGetData(const } namespace tensor { -void RegMapTensor(py::module *m) { +void RegMapTensor(const py::module *m) { // Define python MapTensor class. (void)py::class_(*m, "MapTensor_") .def(py::init([](const TypePtr &key_dtype, const TypePtr &value_dtype, const ShapeVector &value_shape, diff --git a/mindspore/ccsrc/pybind_api/ir/param_info_py.cc b/mindspore/ccsrc/pybind_api/ir/param_info_py.cc index ad82af12db9..31bbb11a079 100644 --- a/mindspore/ccsrc/pybind_api/ir/param_info_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/param_info_py.cc @@ -20,7 +20,7 @@ namespace mindspore { namespace py = pybind11; -void RegParamInfo(py::module *m) { +void RegParamInfo(const py::module *m) { (void)py::class_(*m, "ParamInfo", py::dynamic_attr()) .def(py::init()) .def(py::init([](const ParamInfo ¶m_info) { return std::make_shared(param_info); }), diff --git a/mindspore/ccsrc/pybind_api/ir/primitive_py.cc b/mindspore/ccsrc/pybind_api/ir/primitive_py.cc index 0bebd038a46..e489cf53416 100644 --- a/mindspore/ccsrc/pybind_api/ir/primitive_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/primitive_py.cc @@ -698,7 +698,7 @@ void PrimitivePyAdapter::set_attached_primitive(const PrimitivePyPtr &prim) { attached_primitive_ = prim; } -void RegPrimitive(py::module *m) { +void RegPrimitive(const py::module *m) { (void)py::enum_(*m, "prim_type", py::arithmetic()) .value("unknown", PrimType::kPrimTypeUnknown) .value("builtin", PrimType::kPrimTypeBuiltIn) diff --git a/mindspore/ccsrc/pybind_api/ir/signature_py.cc b/mindspore/ccsrc/pybind_api/ir/signature_py.cc index 3d170f204a2..38c8d82e414 100644 --- a/mindspore/ccsrc/pybind_api/ir/signature_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/signature_py.cc @@ -30,7 +30,7 @@ static ValuePtr PyArgToValue(const py::object &arg) { return parse::data_converter::PyDataToValue(arg); } // Bind SignatureEnumRW as a python class. -void RegSignatureEnumRW(py::module *m) { +void RegSignatureEnumRW(const py::module *m) { (void)py::class_(*m, "Signature") .def(py::init([](const std::string &name, SignatureEnumRW rw, SignatureEnumKind kind, const py::object arg_default, SignatureEnumDType dtype) { diff --git a/mindspore/ccsrc/pybind_api/ir/tensor_py.cc b/mindspore/ccsrc/pybind_api/ir/tensor_py.cc index cbb5ab20c3a..e9a9f97fec8 100644 --- a/mindspore/ccsrc/pybind_api/ir/tensor_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/tensor_py.cc @@ -488,7 +488,7 @@ static ShapeVector GetShapeFromTuple(const py::tuple &tuple) { } return shape; } -void RegMetaTensor(py::module *m) { +void RegMetaTensor(const py::module *m) { // Define python MetaTensor class. (void)py::class_>(*m, "MetaTensor") .def(py::init(), py::arg("dtype"), py::arg("shape")) @@ -788,7 +788,7 @@ py::tuple GetSparseTensorShape(const T &sparse_tensor) { py::tuple CSRTensorPy::GetPyTupleShape(const CSRTensor &csr_tensor) { return GetSparseTensorShape(csr_tensor); } -void RegCSRTensor(py::module *m) { +void RegCSRTensor(const py::module *m) { // Define python CSRTensor class. (void)py::class_>(*m, "CSRTensor") .def(py::init([](const Tensor &indptr, const Tensor &indices, const Tensor &values, const py::tuple &shape) { @@ -809,7 +809,7 @@ void RegCSRTensor(py::module *m) { py::tuple COOTensorPy::GetPyTupleShape(const COOTensor &coo_tensor) { return GetSparseTensorShape(coo_tensor); } -void RegCOOTensor(py::module *m) { +void RegCOOTensor(const py::module *m) { // Define python COOTensor class. (void)py::class_>(*m, "COOTensor") .def(py::init([](const Tensor &indices, const Tensor &values, const py::tuple &shape) { @@ -829,7 +829,7 @@ void RegCOOTensor(py::module *m) { py::tuple RowTensorPy::GetPyTupleShape(const RowTensor &row_tensor) { return GetSparseTensorShape(row_tensor); } -void RegRowTensor(py::module *m) { +void RegRowTensor(const py::module *m) { // Define python RowTensor class. (void)py::class_>(*m, "RowTensor") .def(py::init([](const Tensor &indices, const Tensor &values, const py::tuple &shape) { diff --git a/mindspore/ccsrc/pybind_api/ir/value_py.cc b/mindspore/ccsrc/pybind_api/ir/value_py.cc index cabb146b7fa..33bd8ed9c2a 100644 --- a/mindspore/ccsrc/pybind_api/ir/value_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/value_py.cc @@ -15,14 +15,13 @@ */ #include "ir/value.h" -#include #include "include/common/pybind_api/api_register.h" #include "abstract/abstract_value.h" namespace mindspore { // Define python class for values. -void RegValues(py::module *m) { +void RegValues(const py::module *m) { (void)py::class_>(*m, "UMonad").def(py::init()); (void)py::class_>(*m, "IOMonad").def(py::init()); } diff --git a/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc b/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc index 0655ee1692a..9b766969ba4 100644 --- a/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc +++ b/mindspore/ccsrc/pybind_api/utils/ms_context_py.cc @@ -72,7 +72,7 @@ py::object MsCtxGetParameter(const std::shared_ptr &ctx, MsCtxParam p } // namespace // Note: exported python enum variables beginning with '_' are for internal use -void RegMsContext(py::module *m) { +void RegMsContext(const py::module *m) { (void)py::enum_(*m, "ms_ctx_param", py::arithmetic()) .value("check_bprop", MsCtxParam::MS_CTX_CHECK_BPROP_FLAG) .value("enable_dump", MsCtxParam::MS_CTX_ENABLE_DUMP)