From 22ec976ef7435f4ca7cd0632ea406c3d2c4dba90 Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Fri, 21 Aug 2020 09:07:17 +0800 Subject: [PATCH] fix compilation warnings Signed-off-by: zhoufeng --- CMakeLists.txt | 2 +- mindspore/ccsrc/debug/anf_ir_utils.cc | 2 +- .../ccsrc/frontend/operator/composite/multitype_funcgraph.cc | 5 +++-- mindspore/ccsrc/frontend/optimizer/ad/kprim.cc | 2 +- .../ccsrc/minddata/dataset/engine/datasetops/batch_op.cc | 2 +- mindspore/ccsrc/pipeline/jit/parse/parse.cc | 4 ++-- mindspore/ccsrc/pipeline/jit/pipeline_ge.cc | 2 +- mindspore/ccsrc/pybind_api/ir/primitive_py.cc | 2 +- mindspore/ccsrc/pybind_api/ir/primitive_py.h | 2 +- mindspore/ccsrc/utils/base_ref_extends.cc | 2 +- tests/ut/cpp/transform/transform_base_test.cc | 2 +- 11 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98b43c46080..1c52375cf5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ endif() set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -Wl,--allow-shlib-undefined -D_LIBCPP_INLINE_VISIBILITY='' -D_LIBCPP_DISABLE_EXTERN_TEMPLATE=1 -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2 -Wno-cpp") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -std=c++17 -Werror -Wall -Wno-deprecated-declarations -fPIC") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -std=c++17 -Werror -Wall -fPIC") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(PYBIND11_CPP_STANDARD -std=c++17) diff --git a/mindspore/ccsrc/debug/anf_ir_utils.cc b/mindspore/ccsrc/debug/anf_ir_utils.cc index d2049b1afec..42bf1824b75 100644 --- a/mindspore/ccsrc/debug/anf_ir_utils.cc +++ b/mindspore/ccsrc/debug/anf_ir_utils.cc @@ -1818,7 +1818,7 @@ class IrParser { py::object tensor_obj = LoadObject(lexer_.GetTokenText()); py::array tensor_data = py::cast(tensor_obj); - if (tensor_data == nullptr) { + if (!tensor_data) { return TOK_ERROR; } *val_ptr = TensorPy::MakeTensor(tensor_data, TypeIdToType(type)); diff --git a/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc b/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc index d7b7e18d4ee..5b59854d647 100644 --- a/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc +++ b/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc @@ -49,7 +49,8 @@ void MultitypeFuncGraph::Register(const TypePtrList &types, specialize_fn s_fn) } void MultitypeFuncGraph::Register(const TypePtrList &types, const py::function &py_fn) { - MS_LOG(DEBUG) << "Register type (" << ::mindspore::ToString(types) << ", " << std::string(py_fn.str()) << ")."; + MS_LOG(DEBUG) << "Register type (" << ::mindspore::ToString(types) << ", " << py::str(py_fn.cast()) + << ")."; auto fn = fn_cache_.find(types); if (fn != fn_cache_.end()) { MS_LOG(EXCEPTION) << "Cannot register as (" << ::mindspore::ToString(types) << ", already registered."; @@ -116,7 +117,7 @@ FuncGraphPtr MultitypeFuncGraph::GenerateFromTypes(const TypePtrList &types) { auto py_fn = SignMatch(types); std::ostringstream buffer; buffer << types; - if (py_fn != py::none()) { + if (!py_fn.is_none()) { FuncGraphPtr func_graph = parse::ParsePythonCode(py_fn); if (func_graph == nullptr) { MS_LOG(EXCEPTION) << "Fail to parse overload function " << buffer.str(); diff --git a/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc b/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc index 1b669865806..3b296b5880f 100644 --- a/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc +++ b/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc @@ -50,7 +50,7 @@ FuncGraphPtr KPrim::GetBprop(const PrimitivePtr &prim) { grad_op_child_scope_prefix + prim->name()); ScopeGuard scope_guard(scope); py::function fn = prim->is_base() ? GetBpropFunction(prim->name()) : prim->cast()->GetBpropFunction(); - if (fn == nullptr || py::isinstance(fn)) { + if (!fn || py::isinstance(fn)) { MS_LOG(DEBUG) << "Fail to find bprop function for " << prim->name() << "."; return nullptr; } diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/batch_op.cc b/mindspore/ccsrc/minddata/dataset/engine/datasetops/batch_op.cc index e907d2cac50..34488266ba6 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/batch_op.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/batch_op.cc @@ -285,7 +285,7 @@ Status BatchOp::MapColumns(std::pair, CBatchInfo> Status BatchOp::GetBatchSize(int32_t *batch_size, CBatchInfo info) { #ifdef ENABLE_PYTHON - if (batch_size_func_ != nullptr) { + if (batch_size_func_) { RETURN_IF_NOT_OK(InvokeBatchSizeFunc(batch_size, info)); } else { (*batch_size) = start_batch_size_; diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index f525c9fccf9..486f8181ce7 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -36,7 +36,7 @@ namespace parse { FuncGraphPtr ParsePythonCode(const py::object &obj, const std::string &python_mod_get_parse_method) { (void)python_adapter::set_python_scoped(); - if (obj == nullptr || py::isinstance(obj)) { + if (!obj || py::isinstance(obj)) { MS_LOG(ERROR) << "Parse the python code failed, obj is nullptr or none"; return nullptr; } @@ -265,7 +265,7 @@ FunctionBlockPtr Parser::ParseFunction(const py::object &node, const FunctionBlo } bool set_flag = UpdateFuncGraphFlags(ast_->function(), current_fg); - if (ast_->obj() != ast_->function()) { + if (!ast_->obj().is(ast_->function())) { set_flag = set_flag && UpdateFuncGraphFlags(ast_->obj(), current_fg); } diff --git a/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc b/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc index dade1ada386..a4254ea152d 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc @@ -190,7 +190,7 @@ bool AddDFGraph(const std::map &info, const py::di ConvertObjectToTensors(init_params, &init_tensors); (void)convertor.ConvertAllNode().InitParam(init_tensors).BuildGraph(); - if (broadcast_params != py::none()) { + if (!broadcast_params.is_none()) { if (!py::isinstance(broadcast_params)) { MS_LOG(ERROR) << "Invalid broadcast params, it must be py::dict type"; return false; diff --git a/mindspore/ccsrc/pybind_api/ir/primitive_py.cc b/mindspore/ccsrc/pybind_api/ir/primitive_py.cc index b5f76b1d240..7920c3ada4c 100644 --- a/mindspore/ccsrc/pybind_api/ir/primitive_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/primitive_py.cc @@ -103,7 +103,7 @@ py::tuple check_bprop_out(const py::object &grads_obj, const py::tuple &py_args) py::object grad_dtype = grads[i].attr("dtype"); py::tuple arg_shape = py_args[i].attr("shape"); py::object arg_dtype = py_args[i].attr("dtype"); - if (!grad_shape.equal(arg_shape) || grad_dtype != arg_dtype) { + if (!grad_shape.equal(arg_shape) || !grad_dtype.is(arg_dtype)) { MS_EXCEPTION(ValueError) << "For user define net bprop, the gradient of the " << i << "th arg should have the same shape and dtype as the " << i << "th arg, but the " << i << "th arg shape: " << py::cast(arg_shape) diff --git a/mindspore/ccsrc/pybind_api/ir/primitive_py.h b/mindspore/ccsrc/pybind_api/ir/primitive_py.h index f519b1a0806..761db9142e4 100644 --- a/mindspore/ccsrc/pybind_api/ir/primitive_py.h +++ b/mindspore/ccsrc/pybind_api/ir/primitive_py.h @@ -63,7 +63,7 @@ class PrimitivePy : public Primitive { const py::object &GetPyObj() const { return python_obj_; } py::dict RunInfer(const py::tuple &args); bool ObjHasAttr(const char *attr_name) { return py::hasattr(python_obj_, attr_name); } - bool HasPyObj() { return python_obj_ != nullptr; } + bool HasPyObj() { return python_obj_.operator bool(); } PrimitivePtr Clone() override; bool is_tuple_input_ = false; diff --git a/mindspore/ccsrc/utils/base_ref_extends.cc b/mindspore/ccsrc/utils/base_ref_extends.cc index e720b150b86..8463de994e2 100644 --- a/mindspore/ccsrc/utils/base_ref_extends.cc +++ b/mindspore/ccsrc/utils/base_ref_extends.cc @@ -24,5 +24,5 @@ bool PyObjectRef::operator==(const BaseRef &other) const { return *this == utils::cast(other); } -bool PyObjectRef::operator==(const PyObjectRef &other) const { return object_ == other.object_; } +bool PyObjectRef::operator==(const PyObjectRef &other) const { return object_.is(other.object_); } } // namespace mindspore diff --git a/tests/ut/cpp/transform/transform_base_test.cc b/tests/ut/cpp/transform/transform_base_test.cc index a0322867502..9cf26cb6b82 100644 --- a/tests/ut/cpp/transform/transform_base_test.cc +++ b/tests/ut/cpp/transform/transform_base_test.cc @@ -61,7 +61,7 @@ void PrintMeTensor(MeTensor* tensor) { py::array tensor_data = TensorPy::AsNumpy(*tensor); std::cout << std::string(py::str(tensor_data)) << std::endl; - std::cout << "tensor dtype is: " << std::string(tensor_data.dtype().str()) << std::endl; + std::cout << "tensor dtype is: " << py::str(tensor_data.dtype()) << std::endl; } FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, unsigned int nparam) {