diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc index d7608983d19..4a74b94dd47 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc @@ -40,8 +40,8 @@ void Compute(const ComputeParams *params, const size_t start, const size_t en } offset += index * out_strides->at(j) * params->unit_size_; } - auto ret = - memcpy_s(x + offset, params->x_mem_size_, updates + params->unit_size_ * i, params->unit_size_ * sizeof(T)); + auto ret = memcpy_s(x + offset, params->x_mem_size_ - offset, updates + params->unit_size_ * i, + params->unit_size_ * sizeof(T)); if (ret != 0) { MS_LOG(EXCEPTION) << "memcpy_s error, errorno" << ret; } diff --git a/mindspore/ccsrc/debug/draw.cc b/mindspore/ccsrc/debug/draw.cc index 45b38dd5dc9..734ae7081af 100644 --- a/mindspore/ccsrc/debug/draw.cc +++ b/mindspore/ccsrc/debug/draw.cc @@ -33,10 +33,8 @@ #include "debug/common.h" namespace mindspore { - // namespace to support debug utils namespace draw { - namespace { // Only for ValueNode std::string ValueType(const ValueNodePtr &node) { @@ -44,7 +42,7 @@ std::string ValueType(const ValueNodePtr &node) { return ""; } auto v = node->value(); - + MS_EXCEPTION_IF_NULL(v); return v->type_name(); } @@ -230,7 +228,7 @@ void DrawUserFuncGraph(const std::string &, const FuncGraphPtr &) { } #endif -std::string Graphviz::Shape(AnfNodePtr node) { +std::string Graphviz::Shape(const AnfNodePtr &node) { if (node == nullptr) { return ""; } @@ -302,7 +300,7 @@ void BaseDigraph::Tail(const FuncGraphPtr &func_graph) { buffer_ << "node" << func_graph->get_return() << "_" << 0; } -void BaseDigraph::Edge(AnfNodePtr start, FuncGraphPtr end, int id_start) { +void BaseDigraph::Edge(const AnfNodePtr &start, const FuncGraphPtr &end, int id_start) { Head(start, id_start); buffer_ << "->"; Tail(end); @@ -521,7 +519,7 @@ static void DrawCNode(Graphviz *const graph_obj, const CNodePtr &node) { graph_obj->buffer() << ">,"; } -void Digraph::Node(AnfNodePtr node, int id) { +void Digraph::Node(const AnfNodePtr &node, int id) { if (node == nullptr) { return; } @@ -558,7 +556,7 @@ void Digraph::Node(AnfNodePtr node, int id) { buffer_ << "]" << std::endl; } -void Digraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) { +void Digraph::Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int id_start) { if (start == nullptr || end == nullptr) { return; } @@ -591,7 +589,7 @@ ModelDigraph::~ModelDigraph() { } } -std::string ModelDigraph::Shape(AnfNodePtr node) { +std::string ModelDigraph::Shape(const AnfNodePtr &node) { if (node == nullptr) { return ""; } @@ -611,7 +609,7 @@ std::string ModelDigraph::Shape(AnfNodePtr node) { return "plaintext"; } -void ModelDigraph::Node(AnfNodePtr node, int id) { +void ModelDigraph::Node(const AnfNodePtr &node, int id) { if (node == nullptr) { return; } @@ -644,7 +642,7 @@ void ModelDigraph::Node(AnfNodePtr node, int id) { buffer_ << "]" << std::endl; } -void ModelDigraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) { +void ModelDigraph::Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int id_start) { if (start == nullptr || end == nullptr) { return; } diff --git a/mindspore/ccsrc/debug/draw.h b/mindspore/ccsrc/debug/draw.h index c62fb68e06e..85a6af5d1e1 100644 --- a/mindspore/ccsrc/debug/draw.h +++ b/mindspore/ccsrc/debug/draw.h @@ -37,7 +37,7 @@ class Graphviz { virtual void Start() {} virtual void End() {} - virtual std::string Shape(AnfNodePtr node); + virtual std::string Shape(const AnfNodePtr &node); std::string Color(const AnfNodePtr &node); std::ostringstream &buffer() { return buffer_; } std::ostringstream buffer_; @@ -54,12 +54,12 @@ class BaseDigraph : public Graphviz { explicit BaseDigraph(const std::string &name) : Graphviz(name) {} ~BaseDigraph() override = default; - virtual void Node(AnfNodePtr node, int id = 0) = 0; - virtual void Edge(AnfNodePtr start, AnfNodePtr end, int idx, int idx_start = 0) = 0; + virtual void Node(const AnfNodePtr &node, int id = 0) = 0; + virtual void Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int idx_start = 0) = 0; void Start() override; void End() override; - virtual void Edge(AnfNodePtr start, FuncGraphPtr end, int id_start); + virtual void Edge(const AnfNodePtr &start, const FuncGraphPtr &end, int id_start); void FuncGraphParameters(const FuncGraphPtr &key); void SubGraph(const FuncGraphPtr &key, const std::shared_ptr &gsub); @@ -77,8 +77,8 @@ class Digraph : public BaseDigraph { explicit Digraph(const std::string &name) : BaseDigraph(name) {} ~Digraph() override; - void Node(AnfNodePtr node, int id = 0) override; - void Edge(AnfNodePtr start, AnfNodePtr end, int idx, int idx_start = 0) override; + void Node(const AnfNodePtr &node, int id = 0) override; + void Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int idx_start = 0) override; }; class ModelDigraph : public BaseDigraph { @@ -87,9 +87,9 @@ class ModelDigraph : public BaseDigraph { explicit ModelDigraph(const std::string &name) : BaseDigraph(name) {} ~ModelDigraph() override; - std::string Shape(AnfNodePtr node) override; - void Node(AnfNodePtr node, int id = 0) override; - void Edge(AnfNodePtr start, AnfNodePtr end, int idx, int idx_start = 0) override; + std::string Shape(const AnfNodePtr &node) override; + void Node(const AnfNodePtr &node, int id = 0) override; + void Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int idx_start = 0) override; }; // API to draw diff --git a/mindspore/ccsrc/debug/dump_proto.cc b/mindspore/ccsrc/debug/dump_proto.cc index 6555db9f32c..180f952dfd4 100644 --- a/mindspore/ccsrc/debug/dump_proto.cc +++ b/mindspore/ccsrc/debug/dump_proto.cc @@ -106,6 +106,7 @@ static irpb::DataType GetNumberDataType(const TypePtr &type) { } void CheckIfValidType(const TypePtr &type) { + MS_EXCEPTION_IF_NULL(type); if (type->isa()) { MS_LOG(WARNING) << "The type: " << type->type_name(); } diff --git a/mindspore/ccsrc/debug/trace.cc b/mindspore/ccsrc/debug/trace.cc index bbafe7e00f2..d3a5f5f6bb7 100644 --- a/mindspore/ccsrc/debug/trace.cc +++ b/mindspore/ccsrc/debug/trace.cc @@ -64,7 +64,7 @@ std::string GetAbstractStr(const abstract::AbstractBasePtr &abs) { return oss.str(); } -std::string GetGraphParamString(const FuncGraphPtr &graph, abstract::AbstractBasePtrList args_spec_list) { +std::string GetGraphParamString(const FuncGraphPtr &graph, const abstract::AbstractBasePtrList &args_spec_list) { MS_EXCEPTION_IF_NULL(graph); std::ostringstream oss; oss << "graph:" << graph->ToString() << " with args["; @@ -219,6 +219,8 @@ AbstractBasePtr AnalyzeFailExporter::GetNodeAbstract(const AnfNodePtr &node) { } AnfNodeConfigPtr AnalyzeFailExporter::GetFordwardConfig(const AnfNodeConfigPtr &cfg) { + MS_EXCEPTION_IF_NULL(cfg); + MS_EXCEPTION_IF_NULL(engine_); AnfNodeConfigPtr cur_cfg = cfg; auto iter = engine_->anfnode_config_map().find(cur_cfg); while (iter != engine_->anfnode_config_map().end()) { @@ -421,7 +423,7 @@ void GetEvalStackInfo(std::ostringstream &oss) { std::string last_location_info = ""; for (size_t i = 0; i < stack.size(); ++i) { auto node_config = stack[i]; - + MS_EXCEPTION_IF_NULL(node_config); auto cnode = dyn_cast(node_config->node()); if (cnode == nullptr) { MS_LOG(DEBUG) << "CNode of elements[" << i << "] is nullptr.";