diff --git a/mindspore/ccsrc/backend/kernel_compiler/aicpu/aicpu_kernel_build.cc b/mindspore/ccsrc/backend/kernel_compiler/aicpu/aicpu_kernel_build.cc index 9e1af320268..8d2e16c4f70 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/aicpu/aicpu_kernel_build.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/aicpu/aicpu_kernel_build.cc @@ -116,7 +116,7 @@ void ParseAttrValue(const std::string &type, const std::string &attr_name, const MS_EXCEPTION_IF_NULL(node_attr); MS_EXCEPTION_IF_NULL(value); if (type == "int") { - auto attr_value = GetValue(value); + auto attr_value = static_cast(GetValue(value)); (*node_attr)[attr_name].set_i(attr_value); } else if (type == "str") { auto attr_value = GetValue(value); @@ -128,15 +128,15 @@ void ParseAttrValue(const std::string &type, const std::string &attr_name, const auto attr_value = GetValue(value); (*node_attr)[attr_name].set_f(attr_value); } else if (type == "listInt") { - std::vector attr_value; + std::vector attr_value; auto value_type = value->type(); MS_EXCEPTION_IF_NULL(value_type); auto value_type_str = value_type->ToString(); - if (value_type_str == "Int32") { - int data = GetValue(value); + if (value_type_str == "Int64") { + int64_t data = GetValue(value); attr_value.push_back(data); } else { - attr_value = GetValue>(value); + attr_value = GetValue>(value); } mindspore::AttrValue input_shape_attr; mindspore::AttrValue_ArrayValue *input_shape_attr_list = input_shape_attr.mutable_array(); diff --git a/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_decoder.cc b/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_decoder.cc index 8790795c832..3a89759485d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_decoder.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_decoder.cc @@ -168,7 +168,7 @@ class CNodeDecoder { output_formats_.push_back(output_desc[kJsonKeyFormat]); output_types_.push_back(DtypeToTypeId(output_desc[kJsonKeyDataType])); auto get_item = - func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), cnode_, NewValueNode(SizeToInt(j))}); + func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), cnode_, NewValueNode(SizeToLong(j))}); func_graph->AddNode(get_item); nodes_map_[output_desc[kJsonKeyTensorName]] = get_item; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_generator.cc b/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_generator.cc index 15296e29272..17cfedc989a 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_generator.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_json_generator.cc @@ -35,7 +35,10 @@ std::vector GetDynInputSize(const AnfNodePtr &anf_node) { auto primitive = AnfAlgo::GetCNodePrimitive(anf_node); MS_EXCEPTION_IF_NULL(primitive); if (primitive->HasAttr(kAttrDynInputSizes)) { - dyn_input_sizes = GetValue>(primitive->GetAttr(kAttrDynInputSizes)); + std::vector dyn_input_sizes_me = + GetValue>(primitive->GetAttr(kAttrDynInputSizes)); + (void)std::transform(dyn_input_sizes_me.begin(), dyn_input_sizes_me.end(), std::back_inserter(dyn_input_sizes), + [](const int64_t &value) { return static_cast(value); }); } return dyn_input_sizes; } @@ -256,7 +259,7 @@ void AkgKernelJsonGenerator::GetAttrJson(const AnfNodePtr &anf_node, const std:: std::string type = op_attr->type(); (*attr_json)[kJsonKeyDataType] = type; if (type == "int") { - (*attr_json)[kJsonKeyValue] = GetValue(attr_value); + (*attr_json)[kJsonKeyValue] = static_cast(GetValue(attr_value)); } else if (type == "str") { (*attr_json)[kJsonKeyValue] = GetValue(attr_value); } else if (type == "bool") { @@ -264,7 +267,11 @@ void AkgKernelJsonGenerator::GetAttrJson(const AnfNodePtr &anf_node, const std:: } else if (type == "float") { (*attr_json)[kJsonKeyValue] = GetValue(attr_value); } else if (type == "listInt") { - (*attr_json)[kJsonKeyValue] = GetValue>(attr_value); + std::vector list_int; + std::vector list_int_me = GetValue>(attr_value); + (void)std::transform(list_int_me.begin(), list_int_me.end(), std::back_inserter(list_int), + [](const int64_t &value) { return static_cast(value); }); + (*attr_json)[kJsonKeyValue] = list_int; } else if (type == "listStr") { std::vector data_format; if (op_attr->name() == kArgDataformat) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/common_utils.cc b/mindspore/ccsrc/backend/kernel_compiler/common_utils.cc index 2c1cf5dcc91..ec85eb367af 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/common_utils.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/common_utils.cc @@ -235,7 +235,7 @@ size_t GetDtypeNbyte(const std::string &dtypes) { } bool SetInputKernelBuilderInfo(const std::vector> &inputs, size_t real_input_num, - size_t builder_idex, const std::vector &dyn_input_sizes, + size_t builder_idex, const std::vector &dyn_input_sizes, const std::shared_ptr &builder) { MS_EXCEPTION_IF_NULL(builder); @@ -262,7 +262,7 @@ bool SetInputKernelBuilderInfo(const std::vector> &inp return false; } - for (int t = 0; t < dyn_input_sizes[dyn_input_idx]; t++) { + for (int64_t t = 0; t < dyn_input_sizes[dyn_input_idx]; t++) { kernel_info_index++; auto type_id = DtypeToTypeId(dtypes[builder_idex]); inputs_device_type.push_back(type_id); @@ -376,11 +376,11 @@ bool ParseMetadata(const CNodePtr &kernel_node, const std::shared_ptr> inputs = op_info_ptr->inputs_ptr(); std::vector> outputs = op_info_ptr->outputs_ptr(); - std::vector dyn_input_sizes; + std::vector dyn_input_sizes; auto primitive = AnfAlgo::GetCNodePrimitive(kernel_node); MS_EXCEPTION_IF_NULL(primitive); if (primitive->GetAttr("dyn_input_sizes") != nullptr) { - dyn_input_sizes = GetValue>(primitive->GetAttr("dyn_input_sizes")); + dyn_input_sizes = GetValue>(primitive->GetAttr("dyn_input_sizes")); } if (inputs.size() > 0) { MS_EXCEPTION_IF_NULL(inputs[0]); @@ -552,11 +552,11 @@ std::vector>> GetInputIndex(cons continue; } - std::vector dyn_input_sizes; + std::vector dyn_input_sizes; auto prim = AnfAlgo::GetCNodePrimitive(anf_node); MS_EXCEPTION_IF_NULL(prim); if (prim->GetAttr(kAttrDynInputSizes) != nullptr) { - dyn_input_sizes = GetValue>(prim->GetAttr(kAttrDynInputSizes)); + dyn_input_sizes = GetValue>(prim->GetAttr(kAttrDynInputSizes)); } if (dyn_input_sizes.empty()) { @@ -764,28 +764,26 @@ bool IsWeightBoundary(const AnfNodePtr &node) { return false; } -std::vector GetReduceAttrAxis(const CNodePtr &cnode) { +std::vector GetReduceAttrAxis(const CNodePtr &cnode) { if (AnfAlgo::GetInputTensorNum(cnode) != AnfAlgo::GetOutputTensorNum(cnode) && AnfAlgo::GetInputTensorNum(cnode) != 1) { MS_LOG(EXCEPTION) << "the kind of reduce node [" << cnode->DebugString() << "] is not single input or single output "; } - std::vector axis; + std::vector axis; auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(cnode, 0); auto primitive = AnfAlgo::GetCNodePrimitive(cnode); MS_EXCEPTION_IF_NULL(primitive); auto axis_attr = primitive->GetAttr(kAxis); if (axis_attr == nullptr) { MS_LOG(ERROR) << "This node does't have axie attr."; - return std::vector(); + return std::vector(); } - auto type = axis_attr->type(); - MS_EXCEPTION_IF_NULL(type); - std::vector axis_list; - if (type->ToString() == kTypeInt32) { - axis_list.emplace_back(GetValue(axis_attr)); + std::vector axis_list; + if (axis_attr->isa()) { + axis_list.emplace_back(GetValue(axis_attr)); } else { - axis_list = GetValue>(axis_attr); + axis_list = GetValue>(axis_attr); } for (const auto &elem : axis_list) { if (elem < 0) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/common_utils.h b/mindspore/ccsrc/backend/kernel_compiler/common_utils.h index fc0a6bd7544..b23c7334b5c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/common_utils.h +++ b/mindspore/ccsrc/backend/kernel_compiler/common_utils.h @@ -100,7 +100,7 @@ void GetFuncGraphOutputNodes(const FuncGraphPtr &func_graph, std::vector> *node_list); bool IsWeightBoundary(const AnfNodePtr &node); -std::vector GetReduceAttrAxis(const CNodePtr &cnode); +std::vector GetReduceAttrAxis(const CNodePtr &cnode); std::string GetProcessorStr(const AnfNodePtr &anf_node); template diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/argmax_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/argmax_cpu_kernel.cc index d67c4d47ff9..513464f14ba 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/argmax_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/argmax_cpu_kernel.cc @@ -27,7 +27,7 @@ void ArgmaxCPUKernel::InitKernel(const CNodePtr &kernel_node) { batch_size_ = shape[0]; class_num_ = shape[1]; - int axis = AnfAlgo::GetNodeAttr(kernel_node, AXIS); + int64_t axis = AnfAlgo::GetNodeAttr(kernel_node, AXIS); if (axis != -1 && axis != 1) { MS_LOG(EXCEPTION) << "argmax kernel not support axis " << axis; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.cc index 6776c0f154e..bf7179b551a 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.cc @@ -22,12 +22,12 @@ namespace kernel { void ConcatCPUKernel::InitKernel(const CNodePtr &kernel_node) { CheckParam(kernel_node); - axis_ = AnfAlgo::GetNodeAttr(kernel_node, AXIS); + axis_ = AnfAlgo::GetNodeAttr(kernel_node, AXIS); auto input_1_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); if (axis_ < 0) { - axis_ = axis_ + SizeToInt(input_1_shape.size()); + axis_ = axis_ + SizeToLong(input_1_shape.size()); } - axis_ += 4 - input_1_shape.size(); + axis_ += 4 - SizeToLong(input_1_shape.size()); auto input_num = AnfAlgo::GetInputTensorNum(kernel_node); for (size_t i = 0; i < input_num; i++) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.h index 207e04b7ead..90f712295fb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/concat_cpu_kernel.h @@ -36,7 +36,7 @@ class ConcatCPUKernel : public CPUKernel { void CheckParam(const CNodePtr &kernel_node); void CopyDataToOutput(const std::vector &inputs, size_t dim0, size_t dim1, size_t dim2, float **output_addr, size_t *buff_size); - int axis_; + int64_t axis_; std::vector> input_shape_list_; std::vector output_shape_; }; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc index b28dce775c3..11da103ea87 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc @@ -22,7 +22,7 @@ namespace mindspore { namespace kernel { void EmbeddingLookUpCommGradCPUKernel::InitKernel(const CNodePtr &kernel_node) { CheckParam(kernel_node); - split_num_ = AnfAlgo::GetNodeAttr(kernel_node, "split_num"); + split_num_ = AnfAlgo::GetNodeAttr(kernel_node, "split_num"); MS_LOG(INFO) << "split_num: " << split_num_; auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); if (input_shape[0] % split_num_ != 0) { @@ -47,9 +47,9 @@ bool EmbeddingLookUpCommGradCPUKernel::Launch(const std::vector &rank_group = {0, 1, 2, 3, 4, 5, 6, 7}; - size_t input_split_lens = input_size / split_num_ / sizeof(float_t); - size_t output_split_lens = output_size / split_num_ / sizeof(float_t); - for (int i = 0; i < split_num_; i++) { + size_t input_split_lens = input_size / LongToSize(split_num_) / sizeof(float_t); + size_t output_split_lens = output_size / LongToSize(split_num_) / sizeof(float_t); + for (int64_t i = 0; i < split_num_; i++) { MPIAllGather(input_addr + i * input_split_lens, output_addr + i * output_split_lens, rank_group, input_split_lens); } #if defined(_WIN32) || defined(_WIN64) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.h index e97a96780a2..e23b58918a4 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.h @@ -34,7 +34,7 @@ class EmbeddingLookUpCommGradCPUKernel : public CPUKernel { private: void CheckParam(const CNodePtr &kernel_node); - int split_num_; + int64_t split_num_; }; MS_REG_CPU_KERNEL(EmbeddingLookupCommGrad, diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc index 25f85046140..1428082e748 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc @@ -61,7 +61,7 @@ void EmbeddingLookUpCPUKernel::InitKernel(const CNodePtr &kernel_node) { indices_lens_ *= shape; } if (AnfAlgo::HasNodeAttr(kAttrOffset, kernel_node)) { - offset_ = AnfAlgo::GetNodeAttr(kernel_node, kAttrOffset); + offset_ = AnfAlgo::GetNodeAttr(kernel_node, kAttrOffset); } indices_data_type_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 1); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.h index 23481242f8c..b73fbf4829e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.h @@ -37,7 +37,7 @@ class EmbeddingLookUpCPUKernel : public CPUKernel { protected: void CheckParam(const CNodePtr &kernel_node); - int offset_{0}; + int64_t offset_{0}; size_t indices_lens_{1}; size_t first_dim_size_{1}; size_t outer_dim_size_{1}; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.cc index 73b11f1c01f..220a90f75ac 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.cc @@ -23,9 +23,9 @@ void GatherV2CPUKernel::InitKernel(const CNodePtr &kernel_node) { input_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); indices_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); output_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - axis_ = AnfAlgo::GetNodeAttr(kernel_node, AXIS); + axis_ = AnfAlgo::GetNodeAttr(kernel_node, AXIS); if (axis_ < 0) { - axis_ = axis_ + SizeToInt(input_shape_.size()); + axis_ = axis_ + SizeToLong(input_shape_.size()); } axis_ += 4 - input_shape_.size(); CPUKernelUtils::ExpandDimsTo4(&input_shape_); @@ -75,7 +75,7 @@ void GatherV2CPUKernel::CopyDataToOutput(const std::vector & MS_LOG(EXCEPTION) << "The indices value is less than 0."; } size_t index = IntToSize(indices_addr[i]); - if (index >= input_shape_[IntToSize(axis_)]) { + if (index >= input_shape_[LongToSize(axis_)]) { auto ret = memset_s(*output_addr, *buff_size, 0., num * sizeof(float)); if (ret != EOK) { MS_LOG(EXCEPTION) << "memset failed."; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.h index 9d6ec0de68b..43864356aee 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/gather_cpu_kernel.h @@ -39,7 +39,7 @@ class GatherV2CPUKernel : public CPUKernel { std::vector input_shape_; std::vector indices_shape_; std::vector output_shape_; - int axis_; + int64_t axis_; }; MS_REG_CPU_KERNEL( diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_cpu_kernel.cc index 06a83bdad0d..6d3de6337b0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_cpu_kernel.cc @@ -15,6 +15,7 @@ */ #include "backend/kernel_compiler/cpu/mkldnn/conv2d_cpu_kernel.h" #include +#include #include "utils/ms_utils.h" #include "backend/kernel_compiler/cpu/mkldnn/mkl_kernel_engine.h" #include "runtime/device/cpu/cpu_device_address.h" @@ -30,7 +31,7 @@ void Conv2dCPUKernel::InitKernel(const CNodePtr &kernel_node) { MS_LOG(EXCEPTION) << "conv2d only support nchw input!"; } std::vector kernel_size({weight_shape[2], weight_shape[3]}); - size_t group = IntToSize(AnfAlgo::GetNodeAttr(kernel_node, GROUP)); + size_t group = LongToSize(AnfAlgo::GetNodeAttr(kernel_node, GROUP)); if (group != 1) { if (src_shape[1] % group != 0) { MS_LOG(EXCEPTION) << "conv2d channels should be divided by group!"; @@ -41,8 +42,14 @@ void Conv2dCPUKernel::InitKernel(const CNodePtr &kernel_node) { dnnl::memory::desc src_desc = GetDefaultMemDesc(src_shape); dnnl::memory::desc weights_desc = GetDefaultMemDesc(weight_shape); dnnl::memory::desc dst_desc = GetDefaultMemDesc(dst_shape); - auto stride_ori = AnfAlgo::GetNodeAttr>(kernel_node, STRIDE); - auto dilation_ori = AnfAlgo::GetNodeAttr>(kernel_node, DILATION); + std::vector stride_ori; + std::vector dilation_ori; + auto stride_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDE); + auto dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, DILATION); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_ori), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_ori), + [](const int64_t &value) { return static_cast(value); }); if (stride_ori.size() != 4 || stride_ori[2] != stride_ori[3]) { MS_LOG(EXCEPTION) << "conv2d only support equal stride, and stride must be 4d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_filter_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_filter_cpu_kernel.cc index 96f2dcdd3cd..b4c35083e7a 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_filter_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_filter_cpu_kernel.cc @@ -15,6 +15,7 @@ */ #include "backend/kernel_compiler/cpu/mkldnn/conv2d_grad_filter_cpu_kernel.h" #include +#include #include "utils/ms_utils.h" #include "backend/kernel_compiler/cpu/mkldnn/mkl_kernel_engine.h" #include "runtime/device/cpu/cpu_device_address.h" @@ -30,7 +31,7 @@ void Conv2dGradFilterCPUKernel::InitKernel(const CNodePtr &kernel_node) { MS_LOG(EXCEPTION) << ("conv2d grad filter only support nchw input!"); } std::vector kernel_size({weight_shape[2], weight_shape[3]}); - size_t group = IntToSize(AnfAlgo::GetNodeAttr(kernel_node, GROUP)); + size_t group = LongToSize(AnfAlgo::GetNodeAttr(kernel_node, GROUP)); if (group != 1) { if (src_shape[1] % group != 0) { MS_LOG(EXCEPTION) << "conv2d channels should be divided by group!"; @@ -41,8 +42,14 @@ void Conv2dGradFilterCPUKernel::InitKernel(const CNodePtr &kernel_node) { dnnl::memory::desc src_desc = GetDefaultMemDesc(src_shape); dnnl::memory::desc weights_desc = GetDefaultMemDesc(weight_shape); dnnl::memory::desc dst_desc = GetDefaultMemDesc(dst_shape); - auto stride_ori = AnfAlgo::GetNodeAttr>(kernel_node, STRIDE); - auto dilation_ori = AnfAlgo::GetNodeAttr>(kernel_node, DILATION); + std::vector stride_ori; + std::vector dilation_ori; + auto stride_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDE); + auto dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, DILATION); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_ori), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_ori), + [](const int64_t &value) { return static_cast(value); }); if (stride_ori.size() != 2 || stride_ori[0] != stride_ori[1]) { MS_LOG(EXCEPTION) << "Conv2dGradFilterCPUKernel only support equal stride, and stride must be 2d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_input_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_input_cpu_kernel.cc index a211ea82481..5c746fafeaf 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_input_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/conv2d_grad_input_cpu_kernel.cc @@ -15,6 +15,7 @@ */ #include "backend/kernel_compiler/cpu/mkldnn/conv2d_grad_input_cpu_kernel.h" #include +#include #include "backend/kernel_compiler/cpu/mkldnn/mkl_kernel_engine.h" #include "runtime/device/cpu/cpu_device_address.h" #include "utils/ms_utils.h" @@ -30,7 +31,7 @@ void Conv2dGradInputCPUKernel::InitKernel(const CNodePtr &kernel_node) { MS_LOG(EXCEPTION) << "conv2d grad filter only support nchw input!"; } std::vector kernel_size({weight_shape[2], weight_shape[3]}); - size_t group = IntToSize(AnfAlgo::GetNodeAttr(kernel_node, GROUP)); + size_t group = LongToSize(AnfAlgo::GetNodeAttr(kernel_node, GROUP)); if (group != 1) { if (src_shape[1] % group != 0) { MS_LOG(EXCEPTION) << "conv2d channels should be divided by group!"; @@ -42,8 +43,14 @@ void Conv2dGradInputCPUKernel::InitKernel(const CNodePtr &kernel_node) { dnnl::memory::desc weights_desc = GetDefaultMemDesc(weight_shape); dnnl::memory::desc dst_desc = GetDefaultMemDesc(dst_shape); - auto stride_ori = AnfAlgo::GetNodeAttr>(kernel_node, STRIDE); - auto dilation_ori = AnfAlgo::GetNodeAttr>(kernel_node, DILATION); + std::vector stride_ori; + std::vector dilation_ori; + auto stride_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDE); + auto dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, DILATION); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_ori), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_ori), + [](const int64_t &value) { return static_cast(value); }); if (stride_ori.size() != 2 || stride_ori[0] != stride_ori[1]) { MS_LOG(EXCEPTION) << "Conv2dGradInputCPUKernel only support equal stride, and stride must be 2d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_cpu_kernel.cc index 68b36657583..91b7eb0a97a 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_cpu_kernel.cc @@ -76,9 +76,9 @@ void LstmCPUKernel::CheckParam(const CNodePtr &kernel_node) { std::vector src_h_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 1); std::vector src_c_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 2); bidirectional_ = AnfAlgo::GetNodeAttr(kernel_node, "bidirectional"); - input_size_ = AnfAlgo::GetNodeAttr(kernel_node, "input_size"); - hidden_size_ = AnfAlgo::GetNodeAttr(kernel_node, "hidden_size"); - num_layers_ = AnfAlgo::GetNodeAttr(kernel_node, "num_layers"); + input_size_ = static_cast(AnfAlgo::GetNodeAttr(kernel_node, "input_size")); + hidden_size_ = static_cast(AnfAlgo::GetNodeAttr(kernel_node, "hidden_size")); + num_layers_ = static_cast(AnfAlgo::GetNodeAttr(kernel_node, "num_layers")); has_bias_ = AnfAlgo::GetNodeAttr(kernel_node, "has_bias"); batch_size_ = SizeToInt(src_shape[1]); seq_len_ = SizeToInt(src_shape[0]); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.cc index e609dcb0316..cfcc3ab9d10 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.cc @@ -94,9 +94,9 @@ void LSTMGradCPUKernel::CheckParam(const CNodePtr &kernel_node) { std::vector src_h_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 1); std::vector src_c_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 2); bidirectional_ = AnfAlgo::GetNodeAttr(kernel_node, "bidirectional"); - input_size_ = AnfAlgo::GetNodeAttr(kernel_node, "input_size"); - hidden_size_ = AnfAlgo::GetNodeAttr(kernel_node, "hidden_size"); - num_layers_ = AnfAlgo::GetNodeAttr(kernel_node, "num_layers"); + input_size_ = AnfAlgo::GetNodeAttr(kernel_node, "input_size"); + hidden_size_ = AnfAlgo::GetNodeAttr(kernel_node, "hidden_size"); + num_layers_ = AnfAlgo::GetNodeAttr(kernel_node, "num_layers"); has_bias_ = AnfAlgo::GetNodeAttr(kernel_node, "has_bias"); batch_size_ = SizeToInt(src_shape[1]); seq_len_ = SizeToInt(src_shape[0]); @@ -104,20 +104,20 @@ void LSTMGradCPUKernel::CheckParam(const CNodePtr &kernel_node) { if (bidirectional_) { num_directions_ = 2; } - const int gate_size = 4 * hidden_size_; + const int64_t gate_size = 4 * hidden_size_; if (num_layers_ <= 0) { MS_LOG(EXCEPTION) << "layers must be greater than zero!"; } if (num_layers_ > kMaxLSTMLayer) { MS_LOG(EXCEPTION) << "layers must be lower than 100!"; } - for (int i = 0; i < num_layers_; ++i) { + for (int64_t i = 0; i < num_layers_; ++i) { weight_size_ += gate_size * (i == 0 ? input_size_ : hidden_size_ * num_directions_); weight_h_size_ += gate_size * hidden_size_; } weight_size_ = weight_size_ * num_directions_; weight_h_size_ = weight_h_size_ * num_directions_; - if (num_directions_ * num_layers_ != SizeToInt(src_h_shape[0])) { + if (num_directions_ * num_layers_ != SizeToLong(src_h_shape[0])) { MS_LOG(EXCEPTION) << "error iteration shape!"; } if (src_shape.size() != 3 || src_h_shape.size() != 3 || src_c_shape.size() != 3) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.h index b2368fc5518..f7e6db3e907 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/lstm_grad_cpu_kernel.h @@ -44,13 +44,13 @@ class LSTMGradCPUKernel : public MKLCPUKernel { const dnnl::memory &diff_bias_memory); void ResetMemory(const dnnl::memory &mem, string name); void CheckParam(const CNodePtr &kernel_node); - int weight_size_ = 0; - int weight_h_size_ = 0; - int input_size_; - int hidden_size_; - int num_layers_; - int batch_size_; - int seq_len_; + int64_t weight_size_ = 0; + int64_t weight_h_size_ = 0; + int64_t input_size_; + int64_t hidden_size_; + int64_t num_layers_; + int64_t batch_size_; + int64_t seq_len_; int num_directions_; bool bidirectional_; bool has_bias_; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/mkl_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/mkl_cpu_kernel.cc index 6e9a4a18efc..0771f82d45b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/mkl_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/mkl_cpu_kernel.cc @@ -56,7 +56,10 @@ void MKLCPUKernel::GetPadding(const CNodePtr &kernel_node, const std::string &pa padding_r->emplace_back(0); padding_r->emplace_back(0); } else { - std::vector pad = AnfAlgo::GetNodeAttr>(kernel_node, PAD_LIST); + std::vector pad; + std::vector pad_me = AnfAlgo::GetNodeAttr>(kernel_node, PAD_LIST); + (void)std::transform(pad_me.begin(), pad_me.end(), std::back_inserter(pad), + [](const int64_t &value) { return static_cast(value); }); padding_l->emplace_back(pad[0]); padding_l->emplace_back(pad[1]); padding_r->emplace_back(pad[2]); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_cpu_kernel.cc index ad0ff274c1b..e475f656125 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_cpu_kernel.cc @@ -28,8 +28,14 @@ void PoolingCPUKernel::InitKernel(const CNodePtr &kernel_node) { std::vector dst_shape = AnfAlgo::GetOutputDeviceShape(kernel_node, 0); dnnl::memory::desc src_desc = GetDefaultMemDesc(src_shape); dnnl::memory::desc dst_desc = GetDefaultMemDesc(dst_shape); - std::vector origin_kernel_sizes = AnfAlgo::GetNodeAttr>(kernel_node, KSIZE); - std::vector strides = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); + std::vector origin_kernel_sizes; + std::vector strides; + std::vector kernel_sizes_me = AnfAlgo::GetNodeAttr>(kernel_node, KSIZE); + std::vector strides_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); + (void)std::transform(kernel_sizes_me.begin(), kernel_sizes_me.end(), std::back_inserter(origin_kernel_sizes), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides), + [](const int64_t &value) { return static_cast(value); }); if (origin_kernel_sizes.size() != 4 || strides.size() != 4) { MS_LOG(EXCEPTION) << "invalid kernel size " << origin_kernel_sizes.size() << " or stride size " << strides.size(); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_grad_cpu_kernel.cc index bd9bbe7b11a..37c0cc272a2 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/pooling_grad_cpu_kernel.cc @@ -27,8 +27,14 @@ void PoolingGradCPUKernel::InitKernel(const CNodePtr &kernel_node) { MS_EXCEPTION_IF_NULL(kernel_node); src_shape_ = AnfAlgo::GetInputDeviceShape(kernel_node, 0); dst_shape_ = AnfAlgo::GetInputDeviceShape(kernel_node, 1); - std::vector kernel_sizes = AnfAlgo::GetNodeAttr>(kernel_node, KSIZE); - std::vector strides = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); + std::vector kernel_sizes; + std::vector strides; + auto kernel_sizes_me = AnfAlgo::GetNodeAttr>(kernel_node, KSIZE); + auto strides_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); + (void)std::transform(kernel_sizes_me.begin(), kernel_sizes_me.end(), std::back_inserter(kernel_sizes), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides), + [](const int64_t &value) { return static_cast(value); }); if (kernel_sizes.size() != 4 || strides.size() != 4 || src_shape_.size() != 4 || dst_shape_.size() != 4) { MS_LOG(EXCEPTION) << "pooling grad invalid input size"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/softmax_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/softmax_cpu_kernel.cc index d1f68038b55..6356008f686 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/softmax_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/mkldnn/softmax_cpu_kernel.cc @@ -14,6 +14,7 @@ * limitations under the License. */ #include "backend/kernel_compiler/cpu/mkldnn/softmax_cpu_kernel.h" +#include #include "backend/kernel_compiler/cpu/mkldnn/mkl_kernel_engine.h" #include "runtime/device/cpu/cpu_device_address.h" #include "utils/ms_utils.h" @@ -23,7 +24,10 @@ namespace kernel { void SoftmaxCPUKernel::InitKernel(const CNodePtr &kernel_node) { MS_EXCEPTION_IF_NULL(kernel_node); std::vector src_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 0); - std::vector axis_list = AnfAlgo::GetNodeAttr>(kernel_node, AXIS); + std::vector axis_list; + std::vector axis_list_me = AnfAlgo::GetNodeAttr>(kernel_node, AXIS); + (void)std::transform(axis_list_me.begin(), axis_list_me.end(), std::back_inserter(axis_list), + [](const int64_t &value) { return static_cast(value); }); if (axis_list.size() != 1) { MS_LOG(EXCEPTION) << "cpu softmax only support input axis size 1"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/one_hot_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/one_hot_cpu_kernel.cc index 5bbc9f49a24..922c23557ce 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/one_hot_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/one_hot_cpu_kernel.cc @@ -24,14 +24,14 @@ void OneHotCPUKernel::InitKernel(const CNodePtr &kernel_node) { if (output_shape.size() < 2) { MS_LOG(EXCEPTION) << "invalid output shape size: " << output_shape.size(); } - int axis = AnfAlgo::GetNodeAttr(kernel_node, AXIS); - if (axis != -1 && IntToSize(axis) >= output_shape.size()) { + int64_t axis = AnfAlgo::GetNodeAttr(kernel_node, AXIS); + if (axis != -1 && LongToSize(axis) >= output_shape.size()) { MS_LOG(EXCEPTION) << "invalid axis: " << axis; } if (axis == -1) { axis_ = output_shape.size() - 1; } else { - axis_ = IntToSize(axis); + axis_ = LongToSize(axis); } depth_ = output_shape[axis_]; stride_ = 1; diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.cc index a6c8b7f3149..5c5f80e2a77 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.cc @@ -44,7 +44,8 @@ void EmbeddingLookUpProxyKernel::InitKernel(const CNodePtr &kernel_node) { values.insert(values.end(), output_shape.begin(), output_shape.end()); MS_LOG(INFO) << "Init embedding lookup proxy kernel, input shape:" << input_shape << ", indices_shape:" << indices_shape << ", output_shape:" << output_shape; - std::vector lens{SizeToInt(input_shape.size()), SizeToInt(indices_shape.size()), SizeToInt(output_shape.size())}; + std::vector lens{SizeToLong(input_shape.size()), SizeToLong(indices_shape.size()), + SizeToLong(output_shape.size())}; if (mindspore::ps::Util::IsRoleOfWorker()) { mindspore::ps::worker.AddEmbeddingTable(key_, input_shape[axis]); mindspore::ps::worker.InitPSEmbeddingTable(keys, values, lens); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/push_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/push_kernel.h index 42145a3da96..fa60043d2a4 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/push_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/ps/push_kernel.h @@ -39,11 +39,11 @@ class PushKernel : public CPUKernel { } std::vector keys; std::vector addrs; - std::vector sizes; + std::vector sizes; for (auto input : inputs) { keys.push_back(key_); addrs.push_back(reinterpret_cast(input->addr)); - sizes.push_back(SizeToInt(input->size) / sizeof(T)); + sizes.push_back(SizeToLong(input->size) / sizeof(T)); } mindspore::ps::worker.Push(keys, addrs, sizes); auto ret = memcpy_s(outputs[0]->addr, outputs[0]->size, &key_, sizeof(size_t)); @@ -56,8 +56,9 @@ class PushKernel : public CPUKernel { void Init(const CNodePtr &kernel_node) { key_ = AnfAlgo::GetNodeAttr(kernel_node, kAttrPsKey); - auto optim_input_shapes = AnfAlgo::GetNodeAttr>>(kernel_node, "optim_input_shapes"); - std::vector only_shape_indices = AnfAlgo::GetNodeAttr>(kernel_node, "only_shape_indices"); + auto optim_input_shapes = + AnfAlgo::GetNodeAttr>>(kernel_node, "optim_input_shapes"); + auto only_shape_indices = AnfAlgo::GetNodeAttr>(kernel_node, "only_shape_indices"); MS_LOG(INFO) << "Key " << key_ << " optimizer input shapes are:" << optim_input_shapes; MS_LOG(INFO) << "Only init shape indices are " << only_shape_indices; for (size_t i = 0; i < optim_input_shapes.size(); i++) { @@ -66,7 +67,7 @@ class PushKernel : public CPUKernel { if (std::count(only_shape_indices.begin(), only_shape_indices.end(), i) == 0) { size_t size = sizeof(T); for (size_t j = 0; j < shape.size(); j++) { - size *= shape[j]; + size *= LongToSize(shape[j]); } input_size_list_.push_back(size); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc index 68f41b55699..2c7393f456e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_cpu_kernel.cc @@ -16,6 +16,7 @@ #include #include +#include #include "backend/kernel_compiler/cpu/reduce_cpu_kernel.h" #include "runtime/device/cpu/cpu_device_address.h" @@ -87,7 +88,10 @@ bool ReduceCPUKernel::Launch(const std::vector &inputs, void ReduceCPUKernel::CheckAxis(const CNodePtr &kernel_node) { auto axis_addr = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr(AXIS); if (axis_addr->isa()) { - auto attr_axis = AnfAlgo::GetNodeAttr>(kernel_node, AXIS); + std::vector attr_axis; + std::vector attr_axis_me = AnfAlgo::GetNodeAttr>(kernel_node, AXIS); + (void)std::transform(attr_axis_me.begin(), attr_axis_me.end(), std::back_inserter(attr_axis), + [](const int64_t &value) { return static_cast(value); }); if (attr_axis.size() > shape_.size()) { MS_LOG(EXCEPTION) << "invalid axis size: " << axis_.size(); } else if (attr_axis.empty()) { @@ -105,8 +109,8 @@ void ReduceCPUKernel::CheckAxis(const CNodePtr &kernel_node) { axis_.push_back(IntToSize(axis)); } } - } else if (axis_addr->isa()) { - int axis = AnfAlgo::GetNodeAttr(kernel_node, AXIS); + } else if (axis_addr->isa()) { + int axis = static_cast(AnfAlgo::GetNodeAttr(kernel_node, AXIS)); while (axis < 0) { axis += SizeToInt(shape_.size()); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc index 2354a7e76f1..cbc0d42a25b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "backend/kernel_compiler/cpu/slice_cpu_kernel.h" #include "runtime/device/cpu/cpu_device_address.h" @@ -21,17 +22,26 @@ namespace kernel { void SliceCPUKernel::InitKernel(const CNodePtr &kernel_node) { CheckParam(kernel_node); input_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); - begin_ = AnfAlgo::GetNodeAttr>(kernel_node, BEGIN); + std::vector begin_me = AnfAlgo::GetNodeAttr>(kernel_node, BEGIN); + (void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_), + [](const int64_t &value) { return static_cast(value); }); auto prim = AnfAlgo::GetCNodePrimitive(kernel_node); MS_EXCEPTION_IF_NULL(prim); auto strides = prim->GetAttr(STRIDES); if (strides != nullptr) { - strides_ = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); - end_ = AnfAlgo::GetNodeAttr>(kernel_node, END); + std::vector strides_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); + std::vector end_me = AnfAlgo::GetNodeAttr>(kernel_node, END); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(end_me.begin(), end_me.end(), std::back_inserter(end_), + [](const int64_t &value) { return static_cast(value); }); TransArg(); ClipBegin(); } else { - auto sizes = AnfAlgo::GetNodeAttr>(kernel_node, SIZE); + std::vector sizes; + std::vector sizes_me = AnfAlgo::GetNodeAttr>(kernel_node, SIZE); + (void)std::transform(sizes_me.begin(), sizes_me.end(), std::back_inserter(sizes), + [](const int64_t &value) { return static_cast(value); }); if (sizes.size() != input_shape_.size() || begin_.size() != input_shape_.size()) { MS_LOG(EXCEPTION) << "begin|size|input size must be equal"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_grad_cpu_kernel.cc index 80d8bba998f..d168ea34852 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_grad_cpu_kernel.cc @@ -14,6 +14,7 @@ * limitations under the License. */ #include "backend/kernel_compiler/cpu/slice_grad_cpu_kernel.h" +#include #include "runtime/device/cpu/cpu_device_address.h" #include "ir/primitive.h" @@ -22,19 +23,27 @@ namespace kernel { void SliceGradCPUKernel::InitKernel(const CNodePtr &kernel_node) { CheckParam(kernel_node); output_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - begin_ = AnfAlgo::GetNodeAttr>(kernel_node, BEGIN); + std::vector begin_me = AnfAlgo::GetNodeAttr>(kernel_node, BEGIN); + (void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_), + [](const int64_t &value) { return static_cast(value); }); auto prim = AnfAlgo::GetCNodePrimitive(kernel_node); MS_EXCEPTION_IF_NULL(prim); auto strides = prim->GetAttr(STRIDES); if (strides != nullptr) { - strides_ = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); - end_ = AnfAlgo::GetNodeAttr>(kernel_node, END); + std::vector strides_me = AnfAlgo::GetNodeAttr>(kernel_node, STRIDES); + std::vector end_me = AnfAlgo::GetNodeAttr>(kernel_node, END); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(end_me.begin(), end_me.end(), std::back_inserter(end_), + [](const int64_t &value) { return static_cast(value); }); if (strides_.size() != end_.size() || strides_.size() != output_shape_.size()) { MS_LOG(EXCEPTION) << "stride|end|input size must be equal"; } FormatArgs(true); } else { - size_ = AnfAlgo::GetNodeAttr>(kernel_node, SIZE); + std::vector size_me = AnfAlgo::GetNodeAttr>(kernel_node, SIZE); + (void)std::transform(size_me.begin(), size_me.end(), std::back_inserter(size_), + [](const int64_t &value) { return static_cast(value); }); if (size_.size() != output_shape_.size() || begin_.size() != output_shape_.size()) { MS_LOG(EXCEPTION) << "begin|size|input size must be equal"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.cc index 8d0f7f6bc3d..1cf9d4835b8 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.cc @@ -15,6 +15,7 @@ */ #include "backend/kernel_compiler/cpu/tile_cpu_kernel.h" +#include #include "runtime/device/cpu/cpu_device_address.h" namespace mindspore { @@ -23,7 +24,9 @@ void TileCPUKernel::InitKernel(const CNodePtr &kernel_node) { CheckParam(kernel_node); x_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); y_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - multiples_ = AnfAlgo::GetNodeAttr>(kernel_node, "multiples"); + std::vector multiples_me = AnfAlgo::GetNodeAttr>(kernel_node, "multiples"); + (void)std::transform(multiples_me.begin(), multiples_me.end(), std::back_inserter(multiples_), + [](const int64_t &value) { return static_cast(value); }); dtype_ = AnfAlgo::GetPrevNodeOutputInferDataType(kernel_node, 0); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.cc index 8ec3698cf6b..b756397a4f7 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.cc @@ -15,6 +15,7 @@ */ #include "backend/kernel_compiler/cpu/transpose_cpu_kernel.h" +#include #include "runtime/device/cpu/cpu_device_address.h" namespace mindspore { namespace kernel { @@ -22,7 +23,9 @@ const size_t kMaxDim = 100; void TransposeCPUFwdKernel::InitKernel(const CNodePtr &kernel_node) { MS_EXCEPTION_IF_NULL(kernel_node); shape_ = AnfAlgo::GetInputDeviceShape(kernel_node, 0); - axis_ = AnfAlgo::GetNodeAttr>(kernel_node, "perm"); + std::vector axis_me = AnfAlgo::GetNodeAttr>(kernel_node, "perm"); + (void)std::transform(axis_me.begin(), axis_me.end(), std::back_inserter(axis_), + [](const int64_t &value) { return static_cast(value); }); if (shape_.size() != axis_.size()) { MS_LOG(EXCEPTION) << "The size of input shape and transpose axis shape must be equal."; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.cc index e9950b52984..05e90f6a92e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.cc @@ -43,9 +43,9 @@ template void UniqueCPUKernel::LaunchKernel(const std::vector &inputs, const std::vector &outputs) { auto x_addr = reinterpret_cast(inputs[0]->addr); auto y_addr = reinterpret_cast(outputs[0]->addr); - auto idx_addr = reinterpret_cast(outputs[1]->addr); + auto idx_addr = reinterpret_cast(outputs[1]->addr); - std::unordered_map uniq; + std::unordered_map uniq; int n = SizeToInt(n_); uniq.reserve(n * 2); for (int i = 0, j = 0; i < n; ++i) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmax_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmax_gpu_kernel.h index 13a7d4380b3..cbcf0c8f48d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmax_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmax_gpu_kernel.h @@ -64,7 +64,7 @@ class ArgmaxGpuKernel : public GpuKernel { << "-D inputs."; } - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); if (axis_ < 0) { axis_ += SizeToInt(input_shape.size()); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmaxwithvalue_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmaxwithvalue_gpu_kernel.h index 6ba4cef6f2f..7511a3afb5b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmaxwithvalue_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/argmaxwithvalue_gpu_kernel.h @@ -47,7 +47,7 @@ class ArgmaxWithValueGpuKernel : public GpuKernel { std::vector shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 1); int dims = shape.size(); - int axis = GetAttr(kernel_node, "axis"); + int axis = static_cast(GetAttr(kernel_node, "axis")); if (axis < 0) { axis += dims; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h index 16307cfa419..e615b2b049c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/kernel_constants.h" @@ -97,7 +98,10 @@ class ArrayReduceGpuKernel : public GpuKernel { if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("axis")->isa() || AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("axis")->isa()) { - auto attr_axis = GetAttr>(kernel_node, "axis"); + std::vector attr_axis; + std::vector attr_axis_me = GetAttr>(kernel_node, "axis"); + (void)std::transform(attr_axis_me.begin(), attr_axis_me.end(), std::back_inserter(attr_axis), + [](const int64_t &value) { return static_cast(value); }); if (attr_axis.empty()) { axis_.push_back(-1); } else { @@ -105,8 +109,8 @@ class ArrayReduceGpuKernel : public GpuKernel { axis < 0 ? axis_.push_back(axis + input_dim_length) : axis_.push_back(axis); } } - } else if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("axis")->isa()) { - int axis = GetAttr(kernel_node, "axis"); + } else if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("axis")->isa()) { + int axis = static_cast(GetAttr(kernel_node, "axis")); axis < 0 ? axis_.push_back(axis + input_dim_length) : axis_.push_back(axis); } else { MS_LOG(EXCEPTION) << "Attribute axis type is invalid."; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/concatv2_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/concatv2_gpu_kernel.h index 08b8abc2f85..14b900351b1 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/concatv2_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/concatv2_gpu_kernel.h @@ -63,7 +63,7 @@ class ConcatV2GpuFwdKernel : public GpuKernel { if (!CheckParam(kernel_node)) { return false; } - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); if (axis_ < 0) { auto input_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 0); axis_ += SizeToInt(input_shape.size()); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_gpu_kernel.h index 870f33eb559..2c191f93ed5 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_gpu_kernel.h @@ -55,7 +55,7 @@ class GatherGpuFwdKernel : public GpuKernel { index_shapes_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); output_shapes_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - axis_ = GetAttr(kernel_node, "dim"); + axis_ = static_cast(GetAttr(kernel_node, "dim")); if (axis_ < 0) { axis_ = axis_ + SizeToInt(input_shapes_.size()); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_grad_gpu_kernel.h index 221ca8459d4..ba389d5a5c9 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gather_grad_gpu_kernel.h @@ -55,7 +55,7 @@ class GatherGradGpuKernel : public GpuKernel { grad_shapes_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); output_shapes_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - axis_ = GetAttr(kernel_node, "dim"); + axis_ = static_cast(GetAttr(kernel_node, "dim")); if (axis_ < 0) { axis_ = axis_ + SizeToInt(index_shapes_.size()); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gatherv2_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gatherv2_gpu_kernel.h index 50cb53d55e4..d5649bb0d4c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gatherv2_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/gatherv2_gpu_kernel.h @@ -56,7 +56,7 @@ class GatherV2GpuFwdKernel : public GpuKernel { indices_shapes_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); output_shapes_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); if (axis_ < 0) { axis_ = axis_ + SizeToInt(input_shapes_.size()); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/one_hot_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/one_hot_gpu_kernel.h index 13d2eb32f2f..10c922d30ed 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/one_hot_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/one_hot_gpu_kernel.h @@ -45,7 +45,7 @@ class OneHotGpuFwdKernel : public GpuKernel { return true; } bool Init(const CNodePtr &kernel_node) override { - int axis = GetAttr(kernel_node, "axis"); + int axis = static_cast(GetAttr(kernel_node, "axis")); auto input = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); auto output = AnfAlgo::GetOutputInferShape(kernel_node, 0); int input_size = SizeToInt(input.size()); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_gpu_kernel.h index 1716f60686f..e8ca831b0ed 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_gpu_kernel.h @@ -114,12 +114,12 @@ class RepeatElementsGpuKernel : public GpuKernel { } std::reverse(input_shape_cumulative_product_.begin(), input_shape_cumulative_product_.end()); - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); if (axis_ < 0) { axis_ += input_dim_; } - rep_ = GetAttr(kernel_node, "rep"); + rep_ = static_cast(GetAttr(kernel_node, "rep")); output_size_ = input_size_ * rep_; output_shape_ = input_shape_; output_shape_[axis_] *= rep_; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_grad_gpu_kernel.h index ee51fbf8982..27f5b2cceb4 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/repeat_elements_grad_gpu_kernel.h @@ -60,11 +60,11 @@ class RepeatElementsGradGpuKernel : public GpuKernel { std::vector dy_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); int dy_dim = dy_shape.size(); - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); if (axis_ < 0) { axis_ += dy_dim; } - rep_ = GetAttr(kernel_node, "rep"); + rep_ = static_cast(GetAttr(kernel_node, "rep")); if (axis_ >= dy_dim) { axis_ = dy_dim - 1; rep_ = 1; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h index 9bd4d1f1865..eb50372a43f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_KERNEL_GPU_SCATTER_ND_GPU_KERNEL_H #include +#include #include "backend/kernel_compiler/gpu/cuda_impl/scatter_nd.cuh" #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" @@ -98,7 +99,9 @@ class ScatterNdGpuFwdKernel : public GpuKernel { indices_shapes_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); output_shapes_ = AnfAlgo::GetOutputInferShape(kernel_node, 0); - vec_work_shape_ = GetAttr>(kernel_node, "shape"); + std::vector shape_me = GetAttr>(kernel_node, "shape"); + (void)std::transform(shape_me.begin(), shape_me.end(), std::back_inserter(vec_work_shape_), + [](const int64_t &value) { return static_cast(value); }); GetSize(); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.h index ea385ab1eb4..510c647b065 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_gpu_kernel.h @@ -19,6 +19,7 @@ #include #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/cuda_impl/slice_impl.cuh" @@ -106,8 +107,12 @@ class SliceGpuFwdKernel : public GpuKernel { MS_LOG(ERROR) << "Input dims is " << input_shape.size() << ", scalar is not supported."; return false; } - size_ = GetAttr>(kernel_node, "size"); - begin_ = GetAttr>(kernel_node, "begin"); + std::vector size_me = GetAttr>(kernel_node, "size"); + std::vector begin_me = GetAttr>(kernel_node, "begin"); + (void)std::transform(size_me.begin(), size_me.end(), std::back_inserter(size_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_), + [](const int64_t &value) { return static_cast(value); }); for (size_t i = 0; i < input_shape.size(); i++) { if (input_shape[i] <= 0 || size_[i] <= 0) { MS_LOG(WARNING) << "Slice output is null."; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.h index c1827b44b7f..e1990a6d2e1 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/slice_grad_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_SLICE_GRAD_GPU_KERNEL_H #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/cuda_impl/slice_impl.cuh" @@ -50,27 +51,38 @@ class SliceGradGpuKernel : public GpuKernel { auto kernel_name = AnfAlgo::GetCNodeName(kernel_node); if (kernel_name == "StridedSliceGrad") { is_strided_slice_ = true; - auto shapex = GetAttr>(kernel_node, "shapex"); + std::vector shapex; + std::vector shapex_me = GetAttr>(kernel_node, "shapex"); + (void)std::transform(shapex_me.begin(), shapex_me.end(), std::back_inserter(shapex), + [](const int64_t &value) { return static_cast(value); }); for (auto x : shapex) { input_shape_.push_back(IntToSize(x)); } for (auto i = input_shape_.size(); i < 4; i++) { (void)input_shape_.insert(input_shape_.begin(), 1); } - strides_ = GetAttr>(kernel_node, "strides"); + std::vector strides_me = GetAttr>(kernel_node, "strides"); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides_), + [](const int64_t &value) { return static_cast(value); }); for (auto i = strides_.size(); i < 4; i++) { (void)strides_.insert(strides_.begin(), 1); } - size_ = GetAttr>(kernel_node, "end"); + std::vector size_me = GetAttr>(kernel_node, "end"); + (void)std::transform(size_me.begin(), size_me.end(), std::back_inserter(size_), + [](const int64_t &value) { return static_cast(value); }); } else { auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); ShapeNdTo4d(input_shape, &input_shape_); - size_ = GetAttr>(kernel_node, "size"); + std::vector size_me = GetAttr>(kernel_node, "size"); + (void)std::transform(size_me.begin(), size_me.end(), std::back_inserter(size_), + [](const int64_t &value) { return static_cast(value); }); } auto dy_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); ShapeNdTo4d(dy_shape, &dy_shape_); - begin_ = GetAttr>(kernel_node, "begin"); + std::vector begin_me = GetAttr>(kernel_node, "begin"); + (void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_), + [](const int64_t &value) { return static_cast(value); }); DealParam(); input_size_ = input_shape_[0] * input_shape_[1] * input_shape_[2] * input_shape_[3] * sizeof(T); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/split_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/split_gpu_kernel.h index 2a7cb6c5dc2..124a7734a2c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/split_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/split_gpu_kernel.h @@ -57,12 +57,12 @@ class SplitGpuFwdKernel : public GpuKernel { } bool Init(const CNodePtr &kernel_node) override { - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); if (axis_ < 0) { auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); axis_ += SizeToInt(input_shape.size()); } - output_num_ = GetAttr(kernel_node, "output_num"); + output_num_ = static_cast(GetAttr(kernel_node, "output_num")); if (!CheckParam(kernel_node)) { return false; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_kernel.h index 3587f7e4e80..e9a6a137134 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_gpu_kernel.h @@ -81,9 +81,15 @@ class StridedSliceGpuKernel : public GpuKernel { private: void FillEmptyDims(const CNodePtr &kernel_node) { - begin_ = GetAttr>(kernel_node, "begin"); - end_ = GetAttr>(kernel_node, "end"); - strides_ = GetAttr>(kernel_node, "strides"); + std::vector begin_me = GetAttr>(kernel_node, "begin"); + std::vector end_me = GetAttr>(kernel_node, "end"); + std::vector strides_me = GetAttr>(kernel_node, "strides"); + (void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(end_me.begin(), end_me.end(), std::back_inserter(end_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides_), + [](const int64_t &value) { return static_cast(value); }); for (size_t i = 0; i < MAX_DIMS; i++) { if (i < begin_.size()) { @@ -111,7 +117,7 @@ class StridedSliceGpuKernel : public GpuKernel { } void ParseMasks(const CNodePtr &kernel_node) { - auto begin_mask_int = GetAttr(kernel_node, "begin_mask"); + auto begin_mask_int = static_cast(GetAttr(kernel_node, "begin_mask")); auto begin_mask = Dec2Bin(begin_mask_int); for (size_t i = 0; i < begin_mask.size(); i++) { if (begin_mask[i]) { @@ -119,7 +125,7 @@ class StridedSliceGpuKernel : public GpuKernel { } } - auto end_mask_int = GetAttr(kernel_node, "end_mask"); + auto end_mask_int = static_cast(GetAttr(kernel_node, "end_mask")); auto end_mask = Dec2Bin(end_mask_int); for (size_t j = 0; j < end_mask.size(); j++) { if (end_mask[j]) { @@ -127,7 +133,7 @@ class StridedSliceGpuKernel : public GpuKernel { } } - auto ellipsis_mask_int = GetAttr(kernel_node, "ellipsis_mask"); + auto ellipsis_mask_int = static_cast(GetAttr(kernel_node, "ellipsis_mask")); auto ellipsis_mask = Dec2Bin(ellipsis_mask_int); for (size_t k = 0; k < ellipsis_mask.size(); k++) { if (ellipsis_mask[k]) { @@ -137,7 +143,7 @@ class StridedSliceGpuKernel : public GpuKernel { } } - auto shrink_axis_mask_str = GetAttr(kernel_node, "shrink_axis_mask"); + auto shrink_axis_mask_str = static_cast(GetAttr(kernel_node, "shrink_axis_mask")); auto shrink_axis_mask = Dec2Bin(shrink_axis_mask_str); for (size_t l = 0; l < shrink_axis_mask.size(); l++) { if (shrink_axis_mask[l]) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_grad_gpu_kernel.h index 6d092d18f5a..984702d50de 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/strided_slice_grad_gpu_kernel.h @@ -50,7 +50,10 @@ class StridedSliceGradGpuKernel : public GpuKernel { return true; } bool Init(const CNodePtr &kernel_node) override { - auto shapex = GetAttr>(kernel_node, "shapex"); + std::vector shapex; + std::vector shapex_me = GetAttr>(kernel_node, "shapex"); + (void)std::transform(shapex_me.begin(), shapex_me.end(), std::back_inserter(shapex), + [](const int64_t &value) { return static_cast(value); }); for (auto x : shapex) { input_shape_.push_back(IntToSize(x)); } @@ -84,9 +87,15 @@ class StridedSliceGradGpuKernel : public GpuKernel { private: void FillEmptyDims(const CNodePtr &kernel_node) { - begin_ = GetAttr>(kernel_node, "begin"); - end_ = GetAttr>(kernel_node, "end"); - strides_ = GetAttr>(kernel_node, "strides"); + std::vector begin_me = GetAttr>(kernel_node, "begin"); + std::vector end_me = GetAttr>(kernel_node, "end"); + std::vector strides_me = GetAttr>(kernel_node, "strides"); + (void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(end_me.begin(), end_me.end(), std::back_inserter(end_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides_), + [](const int64_t &value) { return static_cast(value); }); for (size_t i = 0; i < MAX_DIMS; i++) { if (i < begin_.size()) { @@ -114,7 +123,7 @@ class StridedSliceGradGpuKernel : public GpuKernel { } void ParseMasks(const CNodePtr &kernel_node) { - auto begin_mask_int = GetAttr(kernel_node, "begin_mask"); + auto begin_mask_int = static_cast(GetAttr(kernel_node, "begin_mask")); auto begin_mask = Dec2Bin(begin_mask_int); for (size_t i = 0; i < begin_mask.size(); i++) { if (begin_mask[i]) { @@ -122,7 +131,7 @@ class StridedSliceGradGpuKernel : public GpuKernel { } } - auto end_mask_int = GetAttr(kernel_node, "end_mask"); + auto end_mask_int = static_cast(GetAttr(kernel_node, "end_mask")); auto end_mask = Dec2Bin(end_mask_int); for (size_t j = 0; j < end_mask.size(); j++) { if (end_mask[j]) { @@ -130,7 +139,7 @@ class StridedSliceGradGpuKernel : public GpuKernel { } } - auto ellipsis_mask_int = GetAttr(kernel_node, "ellipsis_mask"); + auto ellipsis_mask_int = static_cast(GetAttr(kernel_node, "ellipsis_mask")); auto ellipsis_mask = Dec2Bin(ellipsis_mask_int); for (size_t k = 0; k < ellipsis_mask.size(); k++) { if (ellipsis_mask[k]) { @@ -140,7 +149,7 @@ class StridedSliceGradGpuKernel : public GpuKernel { } } - auto shrink_axis_mask_str = GetAttr(kernel_node, "shrink_axis_mask"); + auto shrink_axis_mask_str = static_cast(GetAttr(kernel_node, "shrink_axis_mask")); auto shrink_axis_mask = Dec2Bin(shrink_axis_mask_str); for (size_t l = 0; l < shrink_axis_mask.size(); l++) { if (shrink_axis_mask[l]) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/transpose_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/transpose_gpu_kernel.h index bf40bb64756..7bb0a6b77af 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/transpose_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/transpose_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_TRANSPOSE_H_ #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/cuda_impl/transpose_impl.cuh" @@ -75,7 +76,10 @@ class TransposeGpuFwdKernel : public GpuKernel { } input_size_ *= sizeof(T); output_size_ = input_size_; - auto perm = GetAttr>(kernel_node, "perm"); + std::vector perm; + std::vector perm_me = GetAttr>(kernel_node, "perm"); + (void)std::transform(perm_me.begin(), perm_me.end(), std::back_inserter(perm), + [](const int64_t &value) { return static_cast(value); }); for (size_t j = 0; j < perm.size(); j++) { input_axis_.push_back(perm[j]); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_init_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_init_kernel.cc index 3c88b88c747..66ea2d68685 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_init_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_init_kernel.cc @@ -15,6 +15,7 @@ */ #include "backend/kernel_compiler/gpu/data/dataset_init_kernel.h" +#include #include "backend/kernel_compiler/gpu/data/dataset_utils.h" #include "runtime/device/gpu/gpu_buffer_mgr.h" #include "runtime/device/gpu/gpu_memory_allocator.h" @@ -34,7 +35,15 @@ const std::vector &DatasetInitKernel::GetWorkspaceSizeList() const { ret bool DatasetInitKernel::Init(const CNodePtr &kernel_node) { queue_name_ = GetAttr(kernel_node, "queue_name"); - auto shapes = GetAttr>>(kernel_node, "shapes"); + std::vector> shapes; + std::vector> shapes_me = GetAttr>>(kernel_node, "shapes"); + (void)std::transform(shapes_me.begin(), shapes_me.end(), std::back_inserter(shapes), + [](const std::vector &values) { + std::vector shape; + (void)std::transform(values.begin(), values.end(), std::back_inserter(shape), + [](const int64_t &value) { return static_cast(value); }); + return shape; + }); auto types = GetAttr>(kernel_node, "types"); if (shapes.size() != types.size()) { MS_LOG(EXCEPTION) << "Invalid shapes: " << shapes << ", types: " << types; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_iterator_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_iterator_kernel.cc index 562f0b21019..4b9749a86a1 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_iterator_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_iterator_kernel.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include "backend/kernel_compiler/gpu/data/dataset_utils.h" #include "profiler/device/gpu/gpu_profiling.h" #include "runtime/device/gpu/gpu_buffer_mgr.h" @@ -44,7 +45,15 @@ const std::vector &DatasetIteratorKernel::GetWorkspaceSizeList() const { bool DatasetIteratorKernel::Init(const CNodePtr &kernel_node) { queue_name_ = GetAttr(kernel_node, "shared_name"); - auto shapes = GetAttr>>(kernel_node, "shapes"); + std::vector> shapes; + std::vector> shapes_me = GetAttr>>(kernel_node, "shapes"); + (void)std::transform(shapes_me.begin(), shapes_me.end(), std::back_inserter(shapes), + [](const std::vector &values) { + std::vector shape; + (void)std::transform(values.begin(), values.end(), std::back_inserter(shape), + [](const int64_t &value) { return static_cast(value); }); + return shape; + }); auto types = GetAttr>(kernel_node, "types"); if (shapes.size() != types.size()) { MS_LOG(EXCEPTION) << "Invalid shapes: " << shapes << ", types: " << types; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/addn_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/addn_gpu_kernel.h index 5dac339ad73..5379ed95347 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/addn_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/addn_gpu_kernel.h @@ -85,7 +85,7 @@ class AddNGpuFwdKernel : public GpuKernel { InitResource(); cudnn_data_type_ = GetCudnnDataType(TypeIdLabel(AnfAlgo::GetInputDeviceDataType(kernel_node, 0))); size_t input_num = AnfAlgo::GetInputTensorNum(kernel_node); - num_input_ = GetAttr(kernel_node, "n"); + num_input_ = static_cast(GetAttr(kernel_node, "n")); if (IntToSize(num_input_) != input_num) { MS_LOG(ERROR) << "Input number is " << num_input_ << " in attr, but got " << input_num << "input."; return false; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cholesky_trsm_solve_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cholesky_trsm_solve_gpu_kernel.h index 217a4300c10..4f100ead4bb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cholesky_trsm_solve_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cholesky_trsm_solve_gpu_kernel.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "backend/kernel_compiler/gpu/cuda_impl/identity_impl.cuh" #include "backend/kernel_compiler/gpu/cuda_impl/matrix_split_impl.cuh" #include "backend/kernel_compiler/gpu/gpu_kernel.h" @@ -105,7 +106,7 @@ class CholeskyTrsmGpuKernel : public GpuKernel { handle_ = device::gpu::GPUDeviceManager::GetInstance().GetCusolverDnHandle(); blas_handle_ = device::gpu::GPUDeviceManager::GetInstance().GetCublasHandle(); auto in_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); - split_dim = GetAttr(kernel_node, "split_dim"); + split_dim = static_cast(GetAttr(kernel_node, "split_dim")); if (split_dim == 0) { use_split_matrix = false; if (in_shape.size() == 2) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h index 92cac43ce06..904fca36fe6 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h @@ -51,7 +51,7 @@ class CumSumGpuKernel : public GpuKernel { } input_size_0_ = sizeof(T); shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); - axis_ = GetAttr(kernel_node, "axis"); + axis_ = static_cast(GetAttr(kernel_node, "axis")); exclusive_ = GetAttr(kernel_node, "exclusive"); reverse_ = GetAttr(kernel_node, "reverse"); int input_dim_length = SizeToInt(shape_.size()); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/determinant_triangle_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/determinant_triangle_gpu_kernel.h index 4b94939a44f..139941d41f9 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/determinant_triangle_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/determinant_triangle_gpu_kernel.h @@ -86,7 +86,7 @@ class DetTriangleGpuKernel : public GpuKernel { MS_LOG(ERROR) << "The maxtices should be in shape of square."; return false; } - fill_mode_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("fill_mode")); + fill_mode_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("fill_mode"))); InitSizeLists(); return true; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/multinomial_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/multinomial_gpu_kernel.h index ec12133cdc5..b3f61bc7a3e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/multinomial_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/multinomial_gpu_kernel.h @@ -92,8 +92,8 @@ class MultinomialGpuKernel : public GpuKernel { output_size_ *= output_shape[i]; } workspace_size_ = output_size_; - seed_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed")); - seed2_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed2")); + seed_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed"))); + seed2_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed2"))); InitSizeLists(); return true; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h index 43954a762c6..1f05be71a45 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h @@ -119,8 +119,8 @@ class RandomOpGpuKernel : public GpuKernel { output_size_ *= output_shape[i]; workspace_size_ *= output_shape[i]; } - seed_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed")); - seed2_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed2")); + seed_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed"))); + seed2_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("seed2"))); InitSizeLists(); return true; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/tensordot_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/tensordot_gpu_kernel.h index 3e5b022fcd1..1d1de79d0d0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/tensordot_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/tensordot_gpu_kernel.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/kernel_constants.h" @@ -135,9 +136,14 @@ class TensorDotGpuKernel : public GpuKernel { } // holding in temp values to convert to size_t vectors - auto x1_transpose_fwd_temp = GetAttr>(kernel_node, "x1_transpose_fwd"); - auto x2_transpose_fwd_temp = GetAttr>(kernel_node, "x2_transpose_fwd"); - + std::vector x1_transpose_fwd_temp; + std::vector x1_transpose_me = GetAttr>(kernel_node, "x1_transpose_fwd"); + (void)std::transform(x1_transpose_me.begin(), x1_transpose_me.end(), std::back_inserter(x1_transpose_fwd_temp), + [](const int64_t &value) { return static_cast(value); }); + std::vector x2_transpose_fwd_temp; + std::vector x2_transpose_me = GetAttr>(kernel_node, "x2_transpose_fwd"); + (void)std::transform(x2_transpose_me.begin(), x2_transpose_me.end(), std::back_inserter(x2_transpose_fwd_temp), + [](const int64_t &value) { return static_cast(value); }); for (size_t i = 0; i < x1_transpose_fwd_temp.size(); i++) { x1_transpose_fwd_.push_back(x1_transpose_fwd_temp[i]); } @@ -147,8 +153,12 @@ class TensorDotGpuKernel : public GpuKernel { } // values to decide multiplication call specifics - x1_reshape_fwd_ = GetAttr>(kernel_node, "x1_reshape_fwd"); - x2_reshape_fwd_ = GetAttr>(kernel_node, "x2_reshape_fwd"); + std::vector x1_reshape_me = GetAttr>(kernel_node, "x1_reshape_fwd"); + (void)std::transform(x1_reshape_me.begin(), x1_reshape_me.end(), std::back_inserter(x1_reshape_fwd_), + [](const int64_t &value) { return static_cast(value); }); + std::vector x2_reshape_me = GetAttr>(kernel_node, "x2_reshape_fwd"); + (void)std::transform(x2_reshape_me.begin(), x2_reshape_me.end(), std::back_inserter(x2_reshape_fwd_), + [](const int64_t &value) { return static_cast(value); }); auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 0); output_size_ = sizeof(T); for (size_t i = 0; i < output_shape.size(); i++) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/update_thor_gradient.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/update_thor_gradient.h index 92d777d8d07..ff686d3666f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/update_thor_gradient.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/update_thor_gradient.h @@ -183,7 +183,7 @@ class UpdateThorGradientGpuKernel : public GpuKernel { auto gradient_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); auto matrix_g_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 2); - split_dim = size_t(GetAttr(kernel_node, "split_dim")); + split_dim = LongToSize(GetAttr(kernel_node, "split_dim")); gradient_size.batch_h = gradient_shape[0] / split_dim; gradient_size.batch_w = gradient_shape[1] / split_dim; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nccl/nccl_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nccl/nccl_gpu_kernel.h index e4aa67b9238..384624861ff 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nccl/nccl_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nccl/nccl_gpu_kernel.h @@ -195,7 +195,7 @@ class NcclGpuKernel : public GpuKernel { auto root_rank = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr(kAttrRootRank); if (root_rank) { - root_ = GetValue(root_rank); + root_ = static_cast(GetValue(root_rank)); } return; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_gpu_kernel.h index 710c67aa3d2..0afdf7c844d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_gpu_kernel.h @@ -125,9 +125,12 @@ class Conv2dGpuFwdKernel : public GpuKernel { compute_format_ = CUDNN_TENSOR_NHWC; } Set4DDesc(in_shape, filter_shape, output_shape); - group_ = GetAttr(kernel_node, "group"); + group_ = static_cast(GetAttr(kernel_node, "group")); CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetConvolutionGroupCount(conv_desc_, group_), "cudnnSetConvGroupCount failed"); - auto pad_list = GetAttr>(kernel_node, "pad_list"); + std::vector pad_list; + std::vector pad_list_me = GetAttr>(kernel_node, "pad_list"); + (void)std::transform(pad_list_me.begin(), pad_list_me.end(), std::back_inserter(pad_list), + [](const int64_t &value) { return static_cast(value); }); pad_height_ = pad_list[0]; pad_width_ = pad_list[2]; auto symmetry_pad = (pad_height_ == pad_list[1]) && (pad_width_ == pad_list[3]); @@ -306,8 +309,12 @@ class Conv2dGpuFwdKernel : public GpuKernel { } } void SetStrideAndDilation(const CNodePtr &kernel_node) { - stride_ = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); - dilation_ = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + std::vector stride_me = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); + std::vector dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_), + [](const int64_t &value) { return static_cast(value); }); if (stride_.size() != 4) { MS_LOG(EXCEPTION) << "Conv2d's' stride must be 4d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_filter_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_filter_gpu_kernel.h index 62b2c863670..22fb7ced2c5 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_filter_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_filter_gpu_kernel.h @@ -127,10 +127,13 @@ class ConvGradFilterGpuBkwKernel : public GpuKernel { } SetNCHW(in_shape, &n_, &c_, &old_height_, &old_width_, data_format_); Set4DDesc(dy_shape, filter_shape, in_shape); - group_ = GetAttr(kernel_node, "group"); + group_ = static_cast(GetAttr(kernel_node, "group")); CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetConvolutionGroupCount(conv_desc_, group_), "cudnnSetConvGroupCount failed"); - auto pad_list = GetAttr>(kernel_node, "pad_list"); + std::vector pad_list; + std::vector pad_list_me = GetAttr>(kernel_node, "pad_list"); + (void)std::transform(pad_list_me.begin(), pad_list_me.end(), std::back_inserter(pad_list), + [](const int64_t &value) { return static_cast(value); }); pad_height_ = pad_list[0]; pad_width_ = pad_list[2]; auto symmetry_pad = (pad_height_ == pad_list[1]) && (pad_width_ == pad_list[3]); @@ -284,7 +287,7 @@ class ConvGradFilterGpuBkwKernel : public GpuKernel { void GetFilterShape(const CNodePtr &kernel_node, std::vector *filter_shape) { auto shp_tuple_x = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("filter_sizes")->cast()->value(); (void)std::transform(std::begin(shp_tuple_x), std::end(shp_tuple_x), std::back_inserter(*filter_shape), - [](const ValuePtr &e) -> size_t { return e->cast()->value(); }); + [](const ValuePtr &e) -> size_t { return static_cast(e->cast()->value()); }); } void Set4DDesc(const std::vector &dy_shape, const std::vector &filter_shape, const std::vector &in_shape) { @@ -309,8 +312,12 @@ class ConvGradFilterGpuBkwKernel : public GpuKernel { "cudnnSetTensorNdDescriptor failed"); } void SetStrideAndDilation(const CNodePtr &kernel_node) { - stride_ = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); - dilation_ = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + std::vector stride_me = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); + std::vector dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_), + [](const int64_t &value) { return static_cast(value); }); if (stride_.size() != 2) { MS_LOG(EXCEPTION) << "ConvGradFilterGpuBkwKernel's stride must be 2d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_input_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_input_gpu_kernel.h index f13f9df8626..965d67b8463 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_input_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/conv2d_grad_input_gpu_kernel.h @@ -130,10 +130,13 @@ class ConvGradInputGpuBkwKernel : public GpuKernel { SetNCHW(input_shape, &n_, &c_, &old_height_, &old_width_, data_format_); Set4DDesc(dy_shape, input_shape, filter_shape); - group_ = GetAttr(kernel_node, "group"); + group_ = static_cast(GetAttr(kernel_node, "group")); CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetConvolutionGroupCount(conv_desc_, group_), "cudnnSetConvGroupCount failed"); - auto pad_list = GetAttr>(kernel_node, "pad_list"); + std::vector pad_list; + std::vector pad_list_me = GetAttr>(kernel_node, "pad_list"); + (void)std::transform(pad_list_me.begin(), pad_list_me.end(), std::back_inserter(pad_list), + [](const int64_t &value) { return static_cast(value); }); pad_height_ = pad_list[0]; pad_width_ = pad_list[2]; auto symmetry_pad = (pad_height_ == pad_list[1]) && (pad_width_ == pad_list[3]); @@ -263,7 +266,10 @@ class ConvGradInputGpuBkwKernel : public GpuKernel { return true; } void SetPad(const std::vector &input_shape, const CNodePtr &kernel_node) { - auto pad_list = GetAttr>(kernel_node, "pad_list"); + std::vector pad_list; + std::vector pad_list_me = GetAttr>(kernel_node, "pad_list"); + (void)std::transform(pad_list_me.begin(), pad_list_me.end(), std::back_inserter(pad_list), + [](const int64_t &value) { return static_cast(value); }); } void SelectAlgorithm(cudnnTensorDescriptor_t dx_desc_real) { if (group_ > 1 || CUDNN_MAJOR < 7) { @@ -288,7 +294,7 @@ class ConvGradInputGpuBkwKernel : public GpuKernel { void GetInputShape(const CNodePtr &kernel_node, std::vector *input_shape) { auto shp_tuple_x = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("input_sizes")->cast()->value(); (void)std::transform(std::begin(shp_tuple_x), std::end(shp_tuple_x), std::back_inserter(*input_shape), - [](const ValuePtr &e) -> size_t { return e->cast()->value(); }); + [](const ValuePtr &e) -> size_t { return static_cast(e->cast()->value()); }); } void Set4DDesc(const std::vector &dy_shape, const std::vector &input_shape, const std::vector &filter_shape) { @@ -313,8 +319,12 @@ class ConvGradInputGpuBkwKernel : public GpuKernel { "cudnnSetTensorNdDescriptor failed"); } void SetStrideAndDilation(const CNodePtr &kernel_node) { - stride_ = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); - dilation_ = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + std::vector stride_me = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); + std::vector dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_), + [](const int64_t &value) { return static_cast(value); }); if (stride_.size() != 2) { MS_LOG(EXCEPTION) << "ConvGradInputGpuBkwKernel's stride must be 2d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/im2col_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/im2col_gpu_kernel.h index 53a711775ab..4fd4c90154d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/im2col_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/im2col_gpu_kernel.h @@ -86,7 +86,10 @@ class Im2ColGpuFwdKernel : public GpuKernel { return false; } auto in_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); - auto filter_shape = GetAttr>(kernel_node, "kernel_size"); + std::vector filter_shape; + std::vector filter_shape_me = GetAttr>(kernel_node, "kernel_size"); + (void)std::transform(filter_shape_me.begin(), filter_shape_me.end(), std::back_inserter(filter_shape), + [](const int64_t &value) { return static_cast(value); }); auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 0); is_null_input_ = CHECK_NULL_INPUT(in_shape); if (is_null_input_) { @@ -96,7 +99,7 @@ class Im2ColGpuFwdKernel : public GpuKernel { } Set4DDesc(in_shape, filter_shape, output_shape); CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetConvolutionGroupCount(conv_desc_, 1), "cudnnSetConvGroupCount failed"); - pad_height_ = GetAttr(kernel_node, "pad"); + pad_height_ = static_cast(GetAttr(kernel_node, "pad")); pad_width_ = pad_height_; pad_mode_ = GetAttr(kernel_node, "pad_mode"); SetStrideAndDilation(kernel_node); @@ -173,7 +176,10 @@ class Im2ColGpuFwdKernel : public GpuKernel { return true; } void SetPad(const std::vector &in_shape, const CNodePtr &kernel_node) { - auto pad_list = GetAttr>(kernel_node, "pad_list"); + std::vector pad_list; + std::vector pad_list_me = GetAttr>(kernel_node, "pad_list"); + (void)std::transform(pad_list_me.begin(), pad_list_me.end(), std::back_inserter(pad_list), + [](const int64_t &value) { return static_cast(value); }); n_ = SizeToInt(in_shape[0]); c_ = SizeToInt(in_shape[1]); @@ -217,8 +223,12 @@ class Im2ColGpuFwdKernel : public GpuKernel { } void SetStrideAndDilation(const CNodePtr &kernel_node) { - stride_ = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); - dilation_ = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + std::vector stride_me = AnfAlgo::GetNodeAttr>(kernel_node, "stride"); + std::vector dilation_me = AnfAlgo::GetNodeAttr>(kernel_node, "dilation"); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(dilation_me.begin(), dilation_me.end(), std::back_inserter(dilation_), + [](const int64_t &value) { return static_cast(value); }); if (stride_.size() != 4) { MS_LOG(EXCEPTION) << "Im2Col's stride must be 4d!"; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_gpu_kernel.h index 74001f3755a..e1c3a5d325d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_gpu_kernel.h @@ -97,7 +97,7 @@ class L2NormalizeGpuKernel : public GpuKernel { } int input_dim_length = SizeToInt(AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0).size()); - int axis = GetAttr(kernel_node, "axis"); + int axis = static_cast(GetAttr(kernel_node, "axis")); axis_ = axis < 0 ? (axis + input_dim_length) : axis; epsilon_ = GetAttr(kernel_node, "epsilon"); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_grad_gpu_kernel.h index a5fcb65d02a..76253dc341a 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/l2normalize_grad_gpu_kernel.h @@ -119,7 +119,7 @@ class L2NormalizeGradGpuKernel : public GpuKernel { } int input_dim_length = SizeToInt(AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0).size()); - int axis = GetAttr(kernel_node, "axis"); + int axis = static_cast(GetAttr(kernel_node, "axis")); axis_ = axis < 0 ? (axis + input_dim_length) : axis; epsilon_ = GetAttr(kernel_node, "epsilon"); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_gpu_kernel.h index 7f65573a960..da6229382be 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_gpu_kernel.h @@ -49,8 +49,8 @@ class LayerNormGpuKernel : public GpuKernel { return true; } bool Init(const CNodePtr &kernel_node) override { - int begin_norm_axis = GetAttr(kernel_node, "begin_norm_axis"); - int begin_params_axis = GetAttr(kernel_node, "begin_params_axis"); + int begin_norm_axis = static_cast(GetAttr(kernel_node, "begin_norm_axis")); + int begin_params_axis = static_cast(GetAttr(kernel_node, "begin_params_axis")); auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); if (begin_norm_axis < 0) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_grad_gpu_kernel.h index 8e4b12af2d8..f77bf8daa77 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/layer_norm_grad_gpu_kernel.h @@ -51,8 +51,8 @@ class LayerNormGradGpuKernel : public GpuKernel { return true; } bool Init(const CNodePtr &kernel_node) override { - int begin_norm_axis = GetAttr(kernel_node, "begin_norm_axis"); - int begin_params_axis = GetAttr(kernel_node, "begin_params_axis"); + int begin_norm_axis = static_cast(GetAttr(kernel_node, "begin_norm_axis")); + int begin_params_axis = static_cast(GetAttr(kernel_node, "begin_params_axis")); auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); if (begin_norm_axis < 0) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_gpu_kernel.h index 2db0b152008..315748b7d9c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_gpu_kernel.h @@ -95,9 +95,9 @@ class LstmGpuKernel : public GpuKernel { batch_size_ = SizeToInt(input_shape[1]); input_size_ = SizeToInt(input_shape[2]); - input_size_ = GetAttr(kernel_node, "input_size"); - hidden_size_ = GetAttr(kernel_node, "hidden_size"); - num_layers_ = GetAttr(kernel_node, "num_layers"); + input_size_ = static_cast(GetAttr(kernel_node, "input_size")); + hidden_size_ = static_cast(GetAttr(kernel_node, "hidden_size")); + num_layers_ = static_cast(GetAttr(kernel_node, "num_layers")); has_bias_ = GetAttr(kernel_node, "has_bias"); bidirectional_ = GetAttr(kernel_node, "bidirectional"); dropout_ = GetAttr(kernel_node, "dropout"); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_data_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_data_gpu_kernel.h index 29d1de9a89c..10813422bda 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_data_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_data_gpu_kernel.h @@ -96,9 +96,9 @@ class LstmGradDataGpuKernel : public GpuKernel { return true; } void GetAttrs(const CNodePtr &kernel_node) { - input_size_ = GetAttr(kernel_node, "input_size"); - hidden_size_ = GetAttr(kernel_node, "hidden_size"); - num_layers_ = GetAttr(kernel_node, "num_layers"); + input_size_ = static_cast(GetAttr(kernel_node, "input_size")); + hidden_size_ = static_cast(GetAttr(kernel_node, "hidden_size")); + num_layers_ = static_cast(GetAttr(kernel_node, "num_layers")); has_bias_ = GetAttr(kernel_node, "has_bias"); bidirectional_ = GetAttr(kernel_node, "bidirectional"); dropout_ = GetAttr(kernel_node, "dropout"); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_weight_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_weight_gpu_kernel.h index 8a73de52a33..66d00f2cf15 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_weight_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/lstm_grad_weight_gpu_kernel.h @@ -89,9 +89,9 @@ class LstmGradWeightGpuKernel : public GpuKernel { seq_len_ = SizeToInt(input_shape[0]); batch_size_ = SizeToInt(input_shape[1]); - input_size_ = GetAttr(kernel_node, "input_size"); - hidden_size_ = GetAttr(kernel_node, "hidden_size"); - num_layers_ = GetAttr(kernel_node, "num_layers"); + input_size_ = static_cast(GetAttr(kernel_node, "input_size")); + hidden_size_ = static_cast(GetAttr(kernel_node, "hidden_size")); + num_layers_ = static_cast(GetAttr(kernel_node, "num_layers")); has_bias_ = GetAttr(kernel_node, "has_bias"); bidirectional_ = GetAttr(kernel_node, "bidirectional"); dropout_ = GetAttr(kernel_node, "dropout"); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_gpu_kernel.h index aef408c4033..93974a6bf9f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_gpu_kernel.h @@ -90,10 +90,18 @@ class MaxPoolWithArgmaxGpuFwdKernel : public GpuKernel { input_width_ = SizeToInt(input_shape[3]); output_height_ = SizeToInt(output_shape[2]); output_width_ = SizeToInt(output_shape[3]); - auto window = GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("ksize")); + std::vector window; + std::vector window_me = + GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("ksize")); + (void)std::transform(window_me.begin(), window_me.end(), std::back_inserter(window), + [](const int64_t &value) { return static_cast(value); }); window_height_ = window[1]; window_width_ = window[2]; - auto stride = GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("strides")); + std::vector stride; + std::vector stride_me = + GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("strides")); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride), + [](const int64_t &value) { return static_cast(value); }); stride_height_ = stride[1]; stride_width_ = stride[2]; pad_mode_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("padding")); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_grad_gpu_kernel.h index 9d90e2d9f4b..f0e68fe37a4 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/maxpool_with_argmax_grad_gpu_kernel.h @@ -95,10 +95,18 @@ class MaxPoolWithArgmaxGradGpuKernel : public GpuKernel { x_width_ = SizeToInt(x_shape[3]); dy_height_ = SizeToInt(dy_shape[2]); dy_width_ = SizeToInt(dy_shape[3]); - auto window = GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("ksize")); + std::vector window; + std::vector window_me = + GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("ksize")); + (void)std::transform(window_me.begin(), window_me.end(), std::back_inserter(window), + [](const int64_t &value) { return static_cast(value); }); window_height_ = window[1]; window_width_ = window[2]; - auto stride = GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("strides")); + std::vector stride; + std::vector stride_me = + GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("strides")); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride), + [](const int64_t &value) { return static_cast(value); }); stride_height_ = stride[1]; stride_width_ = stride[2]; pad_mode_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("padding")); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pad_gpu_kernel.h index baf341feabf..106744d2e09 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pad_gpu_kernel.h @@ -19,6 +19,7 @@ #include #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/cuda_impl/pad_impl.cuh" @@ -77,7 +78,15 @@ class PadGpuFwdKernel : public GpuKernel { input_shape.insert(it, 2, 1); // channel padding shape_size_ = 4; } - paddings = GetValue>>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("paddings")); + std::vector> paddings_me = + GetValue>>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("paddings")); + (void)std::transform(paddings_me.begin(), paddings_me.end(), std::back_inserter(paddings), + [](const std::vector &values) { + std::vector shape; + (void)std::transform(values.begin(), values.end(), std::back_inserter(shape), + [](const int64_t &value) { return static_cast(value); }); + return shape; + }); // shape adjustement -> from 2d/3d to 4d to standardize if (paddings.size() == 4) { } else if (paddings.size() == 3) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_gpu_kernel.h index 1b673e7c676..d2fd897a195 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_gpu_kernel.h @@ -157,10 +157,17 @@ class PoolingGpuFwdKernel : public GpuKernel { } void SetPad(const CNodePtr &kernel_node) { pad_mode_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("padding")); - auto window = GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("ksize")); + std::vector window; + std::vector window_me = + GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("ksize")); + (void)std::transform(window_me.begin(), window_me.end(), std::back_inserter(window), + [](const int64_t &value) { return static_cast(value); }); int window_height = window[2]; int window_width = window[3]; - stride_ = GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("strides")); + std::vector stride_me = + GetValue>(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("strides")); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_), + [](const int64_t &value) { return static_cast(value); }); int windowDimA[2] = {window_height, window_width}; int paddingA[2] = {0, 0}; int strideA[2] = {stride_[2], stride_[3]}; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_grad_gpu_kernel.h index 945e6a000ee..7772292ff6b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/pooling_grad_gpu_kernel.h @@ -174,8 +174,13 @@ class PoolingGradGpuKernel : public GpuKernel { } void SetPad(const CNodePtr &kernel_node) { pad_mode_ = GetAttr(kernel_node, "padding"); - stride_ = GetAttr>(kernel_node, "strides"); - auto window = GetAttr>(kernel_node, "ksize"); + std::vector stride_me = GetAttr>(kernel_node, "strides"); + std::vector window; + std::vector window_me = GetAttr>(kernel_node, "ksize"); + (void)std::transform(stride_me.begin(), stride_me.end(), std::back_inserter(stride_), + [](const int64_t &value) { return static_cast(value); }); + (void)std::transform(window_me.begin(), window_me.end(), std::back_inserter(window), + [](const int64_t &value) { return static_cast(value); }); int window_height = window[2]; int window_width = window[3]; int stride_h = stride_[2]; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_gpu_kernel.h index 555779dcfe1..e766870c5c0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_gpu_kernel.h @@ -85,11 +85,11 @@ class ROIAlignGpuFwdKernel : public GpuKernel { rois_shape_ = {roi_rows_, roi_cols_}; // Get primitive args - pooled_height_ = GetAttr(kernel_node, "pooled_height"); - pooled_width_ = GetAttr(kernel_node, "pooled_width"); + pooled_height_ = static_cast(GetAttr(kernel_node, "pooled_height")); + pooled_width_ = static_cast(GetAttr(kernel_node, "pooled_width")); spatial_scale_ = static_cast(GetAttr(kernel_node, "spatial_scale")); - sample_num_ = GetAttr(kernel_node, "sample_num"); - roi_end_mode_ = GetAttr(kernel_node, "roi_end_mode"); + sample_num_ = static_cast(GetAttr(kernel_node, "sample_num")); + roi_end_mode_ = static_cast(GetAttr(kernel_node, "roi_end_mode")); // Get output_shape output_shape_ = {roi_rows_, channels_, pooled_height_, pooled_width_}; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_grad_gpu_kernel.h index bed09cf9737..044095cd1f4 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/roi_align_grad_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_KERNEL_GPU_ROI_ALIGN_GRAD_GPU_KERNEL_H #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/cuda_impl/roi_align_impl.cuh" @@ -83,11 +84,13 @@ class ROIAlignGradGpuFwdKernel : public GpuKernel { rois_size_ = roi_rows_ * roi_cols_ * sizeof(T); // Get primitive args - xdiff_shape_ = GetAttr>(kernel_node, "xdiff_shape"); - pooled_height_ = GetAttr(kernel_node, "pooled_height"); - pooled_width_ = GetAttr(kernel_node, "pooled_width"); + std::vector xdiff_shape_me = GetAttr>(kernel_node, "xdiff_shape"); + (void)std::transform(xdiff_shape_me.begin(), xdiff_shape_me.end(), std::back_inserter(xdiff_shape_), + [](const int64_t &value) { return static_cast(value); }); + pooled_height_ = static_cast(GetAttr(kernel_node, "pooled_height")); + pooled_width_ = static_cast(GetAttr(kernel_node, "pooled_width")); spatial_scale_ = static_cast(GetAttr(kernel_node, "spatial_scale")); - sample_num_ = GetAttr(kernel_node, "sample_num"); + sample_num_ = static_cast(GetAttr(kernel_node, "sample_num")); roi_end_mode_ = 1; // Get channels, height & width diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_gpu_kernel.h index 20163bbd867..5ee07693041 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_NN_SOFTMAX_GPU_KERNEL_H_ #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/kernel_constants.h" @@ -117,11 +118,14 @@ class SoftmaxGpuKernel : public GpuKernel { auto kernel_name = AnfAlgo::GetCNodeName(kernel_node); if (kernel_name == "LogSoftmax") { algo_ = CUDNN_SOFTMAX_LOG; - auto axis = GetAttr(kernel_node, "axis"); + auto axis = static_cast(GetAttr(kernel_node, "axis")); InitSizeByAxis(input_shape, axis); } else { algo_ = CUDNN_SOFTMAX_ACCURATE; - auto axis = GetAttr>(kernel_node, "axis"); + std::vector axis; + std::vector axis_me = GetAttr>(kernel_node, "axis"); + (void)std::transform(axis_me.begin(), axis_me.end(), std::back_inserter(axis), + [](const int64_t &value) { return static_cast(value); }); InitSizeByAxis(input_shape, axis[0]); } CHECK_CUDNN_RET_WITH_EXCEPT( diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_grad_gpu_kernel.h index 5fc24b8ed87..c9637c213c2 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/softmax_grad_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_NN_SOFTMAX_GRAD_GPU_KERNEL_H_ #include +#include #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" #include "backend/kernel_compiler/gpu/kernel_constants.h" @@ -123,11 +124,14 @@ class SoftmaxGradGpuKernel : public GpuKernel { auto kernel_name = AnfAlgo::GetCNodeName(kernel_node); if (kernel_name == "LogSoftmaxGrad") { algo_ = CUDNN_SOFTMAX_LOG; - auto axis = GetAttr(kernel_node, "axis"); + auto axis = static_cast(GetAttr(kernel_node, "axis")); InitSizeByAxis(input_shape, axis); } else { algo_ = CUDNN_SOFTMAX_ACCURATE; - auto axis = GetAttr>(kernel_node, "axis"); + std::vector axis; + std::vector axis_me = GetAttr>(kernel_node, "axis"); + (void)std::transform(axis_me.begin(), axis_me.end(), std::back_inserter(axis), + [](const int64_t &value) { return static_cast(value); }); InitSizeByAxis(input_shape, axis[0]); } CHECK_CUDNN_RET_WITH_EXCEPT( diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/uniform_candidate_sampler_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/uniform_candidate_sampler_gpu_kernel.h index ad6e29b3dbd..51dce6fc89e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/uniform_candidate_sampler_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/uniform_candidate_sampler_gpu_kernel.h @@ -78,11 +78,11 @@ class UniformCandidateSamplerGpuKernel : public GpuKernel { return false; } // getting attrs - num_true_ = GetAttr(kernel_node, "num_true"); - num_sampled_ = GetAttr(kernel_node, "num_sampled"); + num_true_ = static_cast(GetAttr(kernel_node, "num_true")); + num_sampled_ = static_cast(GetAttr(kernel_node, "num_sampled")); unique_ = GetAttr(kernel_node, "unique"); - range_max_ = GetAttr(kernel_node, "range_max"); - int seed = GetAttr(kernel_node, "seed"); + range_max_ = static_cast(GetAttr(kernel_node, "range_max")); + int seed = static_cast(GetAttr(kernel_node, "seed")); remove_accidental_hits_ = GetAttr(kernel_node, "remove_accidental_hits"); if (seed == 0) seed = time(NULL); generator_.seed(seed); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_decode_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_decode_gpu_kernel.h index 0f1d9ac9178..a583860698e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_decode_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_decode_gpu_kernel.h @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_KERNEL_GPU_OTHER_BOUNDINGBOX_DECODE_GPU_KERNEL_H #include +#include #include "backend/kernel_compiler/gpu/cuda_impl/boundingbox_decode_impl.cuh" #include "backend/kernel_compiler/gpu/gpu_kernel.h" #include "backend/kernel_compiler/gpu/gpu_kernel_factory.h" @@ -92,7 +93,7 @@ class BoundingBoxDecodeGpuKernel : public GpuKernel { AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("means")->isa()) { means_ = GetAttr>(kernel_node, "means"); } else if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("means")->isa()) { - float mean = GetAttr(kernel_node, "means"); + float mean = GetAttr(kernel_node, "means"); for (size_t i = 0; i < coordinate_size; i++) { means_.emplace_back(mean); } @@ -104,7 +105,7 @@ class BoundingBoxDecodeGpuKernel : public GpuKernel { AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("stds")->isa()) { stds_ = GetAttr>(kernel_node, "stds"); } else if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("stds")->isa()) { - float std = GetAttr(kernel_node, "stds"); + float std = GetAttr(kernel_node, "stds"); for (size_t i = 0; i < coordinate_size; i++) { stds_.emplace_back(std); } @@ -112,7 +113,9 @@ class BoundingBoxDecodeGpuKernel : public GpuKernel { MS_LOG(EXCEPTION) << "Attribute stds type is invalid."; } - max_shape_ = GetAttr>(kernel_node, "max_shape"); + std::vector max_shape_me = GetAttr>(kernel_node, "max_shape"); + (void)std::transform(max_shape_me.begin(), max_shape_me.end(), std::back_inserter(max_shape_), + [](const int64_t &value) { return static_cast(value); }); wh_ratio_clip_ = GetAttr(kernel_node, "wh_ratio_clip"); if (means_.size() < coordinate_size || stds_.size() < coordinate_size) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_encode_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_encode_gpu_kernel.h index 564751cda41..c9685953b50 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_encode_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/boundingbox_encode_gpu_kernel.h @@ -92,7 +92,7 @@ class BoundingBoxEncodeGpuKernel : public GpuKernel { AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("means")->isa()) { means_ = GetAttr>(kernel_node, "means"); } else if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("means")->isa()) { - float mean = GetAttr(kernel_node, "means"); + float mean = GetAttr(kernel_node, "means"); for (size_t i = 0; i < coordinate_size; i++) { means_.emplace_back(mean); } @@ -104,7 +104,7 @@ class BoundingBoxEncodeGpuKernel : public GpuKernel { AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("stds")->isa()) { stds_ = GetAttr>(kernel_node, "stds"); } else if (AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("stds")->isa()) { - float std = GetAttr(kernel_node, "stds"); + float std = GetAttr(kernel_node, "stds"); for (size_t i = 0; i < coordinate_size; i++) { stds_.emplace_back(std); } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold2_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold2_gpu_kernel.h index 32d587a90d8..2899572c41d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold2_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold2_gpu_kernel.h @@ -89,7 +89,7 @@ class BatchNormFold2GpuKernel : public GpuKernel { channel_ = input_shape[1]; height_ = input_shape[2]; width_ = input_shape[3]; - freeze_bn_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("freeze_bn")); + freeze_bn_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("freeze_bn"))); InitSizeLists(); return true; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_gpu_kernel.h index 18c7e3fb917..d4a1221b398 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_gpu_kernel.h @@ -123,7 +123,7 @@ class BatchNormFoldGpuKernel : public GpuKernel { exp_avg_factor_ = 1.0 - momentum; epsilon_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("epsilon")); is_training_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("is_training")); - freeze_bn_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("freeze_bn")); + freeze_bn_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("freeze_bn"))); auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); if (input_shape.size() != 4) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_grad_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_grad_gpu_kernel.h index 45d18602dd8..8dd19ff4535 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_grad_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/batchnorm_fold_grad_gpu_kernel.h @@ -109,7 +109,7 @@ class BatchNormFoldGradGpuKernel : public GpuKernel { epsilon_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("epsilon")); is_training_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("is_training")); - freeze_bn_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("freeze_bn")); + freeze_bn_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("freeze_bn"))); auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 2); if (input_shape.size() != 4) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_gpu_kernel.cc index 8a43ce09410..261ab9ffad0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_gpu_kernel.cc @@ -55,11 +55,11 @@ bool FakeQuantPerChannelGpuKernel::Init(const CNodePtr &kernel_node) { } // get attribute - num_bits_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits")); + num_bits_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits"))); training_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("training")); symmetric_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("symmetric")); narrow_range_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("narrow_range")); - quant_delay_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay")); + quant_delay_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay"))); if (num_bits_ <= 2 || num_bits_ >= 16) { MS_LOG(EXCEPTION) << "Attr \'num_bits\' " << num_bits_ << "is out of range, expected between 2 and 16."; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_grad_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_grad_gpu_kernel.cc index 598a6a960d1..b713184224c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_grad_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perchannel_grad_gpu_kernel.cc @@ -49,12 +49,12 @@ bool FakeQuantPerChannelGradGpuKernel::Init(const CNodePtr &kernel_node) { MS_LOG(EXCEPTION) << "Output number is " << output_num << ", but FakeQuantGrad GpuKernel OP needs 1 output."; } - num_bits_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits")); + num_bits_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits"))); if (num_bits_ <= 2 || num_bits_ >= 16) { MS_LOG(EXCEPTION) << "Attr \'num_bits\' " << num_bits_ << " is out of range, expected between 2 and 16."; } - quant_delay_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay")); + quant_delay_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay"))); if (quant_delay_ < 0) { MS_LOG(EXCEPTION) << "Attr \'quant_delay_\' " << quant_delay_ << " is less then 0, require larger than 0."; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_gpu_kernel.cc index 24edec97a91..6fbf6a9895f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_gpu_kernel.cc @@ -52,8 +52,8 @@ bool FakeQuantPerLayerGpuKernel::Init(const CNodePtr &kernel_node) { MS_LOG(EXCEPTION) << "Output number is " << output_num << ", but FakeQuant GpuKernel OP needs 1 output."; } - num_bits_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits")); - quant_delay_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay")); + num_bits_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits"))); + quant_delay_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay"))); training_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("training")); symmetric_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("symmetric")); narrow_range_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("narrow_range")); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_grad_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_grad_gpu_kernel.cc index f96b6a48d22..0a81fa9c6af 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_grad_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/quant/fake_quant_perlayer_grad_gpu_kernel.cc @@ -48,12 +48,12 @@ bool FakeQuantPerLayerGradGpuKernel::Init(const CNodePtr &kernel_node) { MS_LOG(EXCEPTION) << "Output number is " << output_num << ", but FakeQuantGrad GpuKernel OP needs 1 output."; } - num_bits_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits")); + num_bits_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("num_bits"))); if (num_bits_ <= 2 || num_bits_ >= 16) { MS_LOG(EXCEPTION) << "Attr \'num_bits\' " << num_bits_ << " is out of range, expected between 2 and 16."; } - quant_delay_ = GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay")); + quant_delay_ = static_cast(GetValue(AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("quant_delay"))); if (quant_delay_ < 0) { MS_LOG(EXCEPTION) << "Attr \'quant_delay_\' " << quant_delay_ << " is less then 0, require larger than 0."; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_choice_with_mask_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_choice_with_mask_gpu_kernel.h index c4c3380723a..afbade332f0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_choice_with_mask_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_choice_with_mask_gpu_kernel.h @@ -80,8 +80,8 @@ class RandomChoiceWithMaskGpuKernel : public GpuKernel { input_shape_5D_.insert(input_shape_5D_.begin(), 1); } // init seedc_ - int seed = GetAttr(kernel_node, "seed"); - int seed2 = GetAttr(kernel_node, "seed2"); + int seed = static_cast(GetAttr(kernel_node, "seed")); + int seed2 = static_cast(GetAttr(kernel_node, "seed2")); if (seed2 != 0) seedc_ = seed2; else if (seed != 0) @@ -92,7 +92,7 @@ class RandomChoiceWithMaskGpuKernel : public GpuKernel { for (size_t i = 0; i < input_shape.size(); i++) { input_size_ *= input_shape[i]; } - count_ = GetAttr(kernel_node, "count"); + count_ = static_cast(GetAttr(kernel_node, "count")); // upper ceiling for input for ceil_power2 ceil_power2_ = RcwmRoundUpPower2(input_size_); InitSizeLists(); diff --git a/mindspore/ccsrc/backend/kernel_compiler/hccl/hcom_util.cc b/mindspore/ccsrc/backend/kernel_compiler/hccl/hcom_util.cc index 4c0bb55c80f..8d1836f3b80 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/hccl/hcom_util.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/hccl/hcom_util.cc @@ -114,16 +114,16 @@ bool HcomUtil::GetHcomCount(const AnfNodePtr &anf_node, const vectorGetAttr("rank_size") != nullptr) { - rank_size = GetValue(primitive->GetAttr("rank_size")); + rank_size = GetValue(primitive->GetAttr("rank_size")); } else { MS_LOG(ERROR) << "Get rank size failed"; return false; } - block_size = input_size / IntToSize(rank_size); + block_size = input_size / LongToSize(rank_size); total_size = total_size + block_size; } else { if (AnfAlgo::GetCNodeName(anf_node) == kAllGatherOpName) { @@ -175,7 +175,7 @@ bool HcomUtil::GetHcomRootId(const AnfNodePtr &anf_node, uint32_t *root_id) { auto primitive = AnfAlgo::GetCNodePrimitive(anf_node); MS_EXCEPTION_IF_NULL(primitive); if (primitive->GetAttr("root_rank") != nullptr) { - *root_id = (uint32_t)GetValue(primitive->GetAttr("root_rank")); + *root_id = (uint32_t)GetValue(primitive->GetAttr("root_rank")); } else { MS_LOG(ERROR) << "HcomUtil::Get HCOM_ATTR_ROOT_INDEX fail, not support!"; return false; diff --git a/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc index 30d50ae6edb..580ac9a1e5b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc @@ -27,12 +27,12 @@ void DynamicShapeKernel::Execute() { } auto prev_output_shape = AnfAlgo::GetPrevNodeOutputInferShape(cnode_ptr_, 0); - auto output_shape = std::vector(SizeToInt(prev_output_shape.size())); + auto output_shape = std::vector(SizeToLong(prev_output_shape.size())); - auto output_type = TypeId::kNumberTypeInt32; + auto output_type = TypeId::kNumberTypeInt64; auto output_tensor_for_sync = std::make_shared(output_type, output_shape); - auto data_ptr = static_cast(output_tensor_for_sync->data_c()); + auto data_ptr = static_cast(output_tensor_for_sync->data_c()); for (size_t i = 0; i < prev_output_shape.size(); ++i) { MS_LOG(INFO) << "DEBUG prev_output_shape[" << i << "]:" << prev_output_shape[i]; *(data_ptr + i) = prev_output_shape[i]; diff --git a/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.cc b/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.cc index a1508ef08e3..70cba70b663 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.cc @@ -28,9 +28,9 @@ namespace mindspore { namespace kernel { using mindspore::kernel::tbe::TbeUtils; -std::map KernelFusion(const std::vector &fusion_scopes) { +std::map KernelFusion(const std::vector &fusion_scopes) { MS_LOG(INFO) << "kernel fusion build start, scope size:" << fusion_scopes.size(); - std::map kernel_mod_ret; + std::map kernel_mod_ret; auto build_manger = std::make_shared(); MS_EXCEPTION_IF_NULL(build_manger); for (const auto &fusion_scope_iter : fusion_scopes) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.h b/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.h index 1579953e36e..22361124ead 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.h +++ b/mindspore/ccsrc/backend/kernel_compiler/kernel_fusion.h @@ -26,15 +26,15 @@ namespace kernel { * @brief fuse op and return a callable mod */ struct FusionScopeInfo { - FusionScopeInfo(int32_t id, std::vector in, std::vector comp, std::vector out) + FusionScopeInfo(int64_t id, std::vector in, std::vector comp, std::vector out) : scope_id(id), input_nodes(std::move(in)), compute_nodes(std::move(comp)), output_nodes(std::move(out)) {} - int32_t scope_id{}; + int64_t scope_id{}; std::vector input_nodes; std::vector compute_nodes; std::vector output_nodes; }; -std::map KernelFusion(const std::vector &fusion_scopes); +std::map KernelFusion(const std::vector &fusion_scopes); } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.cc index c6ec50125e9..df2ee0893e1 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.cc @@ -69,6 +69,7 @@ constexpr auto kVTypeBool = "bool"; constexpr auto kVTypeFloat = "float"; constexpr auto kVTypeListInt = "listInt"; constexpr auto kVTypeInt32 = "Int32"; +constexpr auto kVTypeInt64 = "Int64"; constexpr auto kVTypeListUInt64 = "listUInt64"; constexpr auto kVTypeListFloat = "listFloat"; constexpr auto kVTypeListListInt = "listListInt"; @@ -241,9 +242,9 @@ bool GetInputNameAndRealNum(const std::shared_ptr &anf_node, const std: MS_EXCEPTION_IF_NULL(op_input_name); auto primitive = AnfAlgo::GetCNodePrimitive(anf_node); // for dynamic input number, dyn_input_sizes has the info of dynamic input num for each input. - std::vector dyn_input_sizes; + std::vector dyn_input_sizes; if (primitive->GetAttr(kAttrDynInputSizes) != nullptr) { - dyn_input_sizes = GetValue>(primitive->GetAttr(kAttrDynInputSizes)); + dyn_input_sizes = GetValue>(primitive->GetAttr(kAttrDynInputSizes)); } if (input_ptr->param_type() == kParamDynamic) { @@ -251,7 +252,7 @@ bool GetInputNameAndRealNum(const std::shared_ptr &anf_node, const std: MS_LOG(ERROR) << "Dyn input index" << *dyn_input_index << "is over dyn input num" << dyn_input_sizes.size(); return false; } - *input_num = IntToSize(dyn_input_sizes[*dyn_input_index]); + *input_num = LongToSize(dyn_input_sizes[*dyn_input_index]); *op_input_name = input_ptr->name() + "_dynamic_"; (*dyn_input_index)++; // if optional input is exist @@ -454,7 +455,15 @@ void TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspo MS_EXCEPTION_IF_NULL(value); MS_EXCEPTION_IF_NULL(attr_obj); if (type == kVTypeInt) { - auto attr_value = GetValue(value); + if (value->isa()) { + auto attr_value = GetValue(value); + (*attr_obj)[kJValue] = attr_value; + } else { + auto attr_value = GetValue(value); + (*attr_obj)[kJValue] = attr_value; + } + } else if (type == kVTypeInt64) { + auto attr_value = GetValue(value); (*attr_obj)[kJValue] = attr_value; } else if (type == kVTypeStr) { auto attr_value = GetValue(value); @@ -469,15 +478,25 @@ void TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspo auto attr_value = GetValue(value); (*attr_obj)[kJValue] = attr_value; } else if (type == kVTypeListInt) { - std::vector attr_value; + std::vector attr_value; auto value_type = value->type(); MS_EXCEPTION_IF_NULL(value_type); auto value_type_str = value_type->ToString(); - if (value_type_str == kVTypeInt32) { - int data = GetValue(value); + if (value_type_str == kVTypeInt64) { + int64_t data = GetValue(value); attr_value.push_back(data); } else { - attr_value = GetValue>(value); + auto vec = + value->isa() ? value->cast()->value() : value->cast()->value(); + if (!vec.empty()) { + if (vec[0]->isa()) { + std::vector attr_value_me = GetValue>(value); + (void)std::transform(attr_value_me.begin(), attr_value_me.end(), std::back_inserter(attr_value), + [](const int &value) { return static_cast(value); }); + } else { + attr_value = GetValue>(value); + } + } } (*attr_obj)[kJValue] = attr_value; } else if (type == kVTypeListFloat) { @@ -496,7 +515,7 @@ void TbeKernelJsonCreator::ParseAttrValue(const std::string &type, const mindspo auto attr_value = GetValue>(value); (*attr_obj)[kJValue] = attr_value; } else if (type == kVTypeListListInt) { - auto attr_value = GetValue>>(value); + auto attr_value = GetValue>>(value); (*attr_obj)[kJValue] = attr_value; } else { MS_LOG(EXCEPTION) << "Type: " << type << "not support"; @@ -959,17 +978,17 @@ bool TbeKernelBuild::IsDynamicInput(const mindspore::CNodePtr &cnode) { MS_EXCEPTION_IF_NULL(primitive); // for dynamic input number, dyn_input_sizes has the info of dynamic input num for each input. bool ret = false; - std::vector dyn_input_sizes; + std::vector dyn_input_sizes; auto dynamic_input_attr = primitive->GetAttr(kAttrDynInputSizes); if (dynamic_input_attr != nullptr) { - dyn_input_sizes = GetValue>(dynamic_input_attr); + dyn_input_sizes = GetValue>(dynamic_input_attr); auto real_input_size = cnode->inputs().size() - 1; auto dyn_input_size = dyn_input_sizes.size(); if (dyn_input_size != 1) { MS_LOG(INFO) << "Fusion error: fusion build not support dyn_input_sizes > 1"; return ret; } - if (IntToSize(dyn_input_sizes[0]) != real_input_size) { + if (LongToSize(dyn_input_sizes[0]) != real_input_size) { MS_LOG(INFO) << "Fusion error: dyn_input_size" << dyn_input_sizes[0] << "not equal real_input_size" << real_input_size; return ret; @@ -1069,7 +1088,7 @@ bool TbeKernelBuild::GenFusionComputeInputJson(const mindspore::CNodePtr &cnode, return true; } -std::vector TbeKernelBuild::GetDescOutputIndex(const std::vector &output_used_nums) { +std::vector TbeKernelBuild::GetDescOutputIndex(const std::vector &output_used_nums) { std::vector desc_output_index = {}; for (size_t idx = 0; idx < output_used_nums.size(); ++idx) { auto output_use_num_item = output_used_nums[idx]; @@ -1087,7 +1106,7 @@ bool TbeKernelBuild::GenFusionComputeOutputJson(const mindspore::CNodePtr &cnode MS_EXCEPTION_IF_NULL(output_desc_list); auto output_size = AnfAlgo::GetOutputTensorNum(cnode); if (AnfAlgo::HasNodeAttr(kAttrOutputUsedNum, cnode)) { - auto output_used_nums = AnfAlgo::GetNodeAttr>(cnode, kAttrOutputUsedNum); + auto output_used_nums = AnfAlgo::GetNodeAttr>(cnode, kAttrOutputUsedNum); MS_LOG(INFO) << "Fusion info: this node's output has been reused, node name: " << cnode->fullname_with_scope(); if (output_used_nums.size() != output_size) { MS_LOG(INFO) << "Fusion error: output tenor num(" << output_size << ")" diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.h b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.h index c91ac7c6666..05e6c09af24 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.h +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_build.h @@ -58,7 +58,7 @@ class TbeKernelBuild { static bool GenFusionComputeInputJson(const mindspore::CNodePtr &cnode, std::vector>::iterator *layer_iter, std::vector *input_desc_list, size_t *index); - static std::vector GetDescOutputIndex(const std::vector &output_used_nums); + static std::vector GetDescOutputIndex(const std::vector &output_used_nums); static bool GenFusionComputeOutputJson(const mindspore::CNodePtr &cnode, std::vector *output_desc_list); static void GenPreDescJson(nlohmann::json *output_desc); diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_broadcast_selecter.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_broadcast_selecter.cc index c5e882949b3..7c43d3a4cc5 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_broadcast_selecter.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_broadcast_selecter.cc @@ -35,7 +35,7 @@ bool TbeKernelBroadCastSelecter::GetShapeInfo(SupportFormat *support_format) { output_shapes_.clear(); if (AnfAlgo::HasNodeAttr(kAttrDynInputSizes, cnode_ptr_)) { MS_LOG(INFO) << "This broadcast node has dynamic input."; - auto dynamic_size_vec = AnfAlgo::GetNodeAttr>(cnode_ptr_, kAttrDynInputSizes); + auto dynamic_size_vec = AnfAlgo::GetNodeAttr>(cnode_ptr_, kAttrDynInputSizes); if (dynamic_size_vec.empty() || dynamic_size_vec[0] < 2) { MS_LOG(EXCEPTION) << "dynamic attr set error, please check."; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_reduce_selecter.h b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_reduce_selecter.h index 48b3e3a3f1c..b68bfd60cab 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_reduce_selecter.h +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_reduce_selecter.h @@ -43,7 +43,7 @@ class TbeKernelReduceSelecter { CNodePtr cnode_ptr_; std::vector input_shape_{}; std::vector output_shape_{}; - std::vector axis_{}; + std::vector axis_{}; bool keep_dims_ = false; }; } // namespace kernel diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc index b2788b48104..3a36ed28e4f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.cc @@ -92,9 +92,9 @@ void TbeKernelSelect::GetCommonPatternKernelInfo(const OpInfo &op_info) { // get dynamic inputs auto primitive = AnfAlgo::GetCNodePrimitive(cnode_ptr_); MS_EXCEPTION_IF_NULL(primitive); - std::vector dyn_input_sizes; + std::vector dyn_input_sizes; if (primitive->HasAttr(kAttrDynInputSizes)) { - dyn_input_sizes = GetValue>(primitive->GetAttr(kAttrDynInputSizes)); + dyn_input_sizes = GetValue>(primitive->GetAttr(kAttrDynInputSizes)); } // get real input/output num size_t real_input_tensor_num = AnfAlgo::GetInputTensorNum(cnode_ptr_); @@ -335,7 +335,7 @@ void TbeKernelSelect::SetTbeBuildCommonInfo(const mindspore::kernel::OpInfo &op_ bool TbeKernelSelect::GenBuilderItem(bool is_input, size_t kernel_build_info_index, size_t real_io_tensor_num, const std::vector> &ios_info, - const std::vector &dyn_input_sizes, std::vector *formats, + const std::vector &dyn_input_sizes, std::vector *formats, std::vector *device_types, std::vector> *reshape_types) { MS_EXCEPTION_IF_NULL(formats); MS_EXCEPTION_IF_NULL(device_types); @@ -361,8 +361,8 @@ bool TbeKernelSelect::GenBuilderItem(bool is_input, size_t kernel_build_info_ind MS_LOG(EXCEPTION) << "dyn_input_sizes attr set error, dynamic_input_index: " << dynamic_input_index << ", dyn_input_sizes size: " << dyn_input_sizes.size(); } - int dynamic_input_size = dyn_input_sizes[dynamic_input_index]; - for (int i = 0; i < dynamic_input_size; ++i) { + int64_t dynamic_input_size = dyn_input_sizes[dynamic_input_index]; + for (int64_t i = 0; i < dynamic_input_size; ++i) { device_types->emplace_back(tbe::DtypeToTypeId(kernel_build_info_dtype)); formats->emplace_back(kernel_build_info_format); reshape_types->emplace_back(reshape_type); diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.h b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.h index 679c56379f8..95597afd23c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.h +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_select.h @@ -49,9 +49,9 @@ class TbeKernelSelect { bool TbeCheckSupported(const KernelBuildInfoIter &kernel_build_info_iter); static void SetTbeBuildCommonInfo(const OpInfo &op_info, KernelBuildInfo::KernelBuildInfoBuilder *builder); bool GenBuilderItem(bool is_input, size_t kernel_build_info_index, size_t real_io_tensor_num, - const std::vector> &ios_info, const std::vector &dyn_input_sizes, - std::vector *formats, std::vector *device_types, - std::vector> *reshape_types); + const std::vector> &ios_info, + const std::vector &dyn_input_sizes, std::vector *formats, + std::vector *device_types, std::vector> *reshape_types); static void StringToAxisVector(const std::string &reshape_type_str, std::vector *reshape_type_vec); static void CreateNewOpInfo(const OpInfo &op_info, const SupportFormat &support_format, OpInfo *op_info_new); static void CreateNewOpIOInfo(const OpIOInfo &op_io_info, diff --git a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc index bd6e114004c..5159588b3e7 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_kernel_select/tbe_property_checker.cc @@ -34,14 +34,14 @@ constexpr char kAttrShrinkAxisMask[] = "shrink_axis_mask"; static bool CheckStridedSlice(const CNodePtr &cnode) { // check stride[-1] != 1 if (AnfAlgo::HasNodeAttr(kAttrStrides, cnode)) { - auto strides = AnfAlgo::GetNodeAttr>(cnode, kAttrStrides); + auto strides = AnfAlgo::GetNodeAttr>(cnode, kAttrStrides); if (!strides.empty() && strides[strides.size() - 1] != 1) { return false; } } // check reduction on the last dimension if (AnfAlgo::HasNodeAttr(kAttrShrinkAxisMask, cnode)) { - auto shrink_axis_mask = AnfAlgo::GetNodeAttr(cnode, kAttrShrinkAxisMask); + auto shrink_axis_mask = static_cast(AnfAlgo::GetNodeAttr(cnode, kAttrShrinkAxisMask)); AnfNodePtr input = cnode->input(1); int input_dims = 0; if (input->isa()) { diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.cc index dd9462059a2..42540b40019 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.cc @@ -64,14 +64,14 @@ void BnupdateEltwiseEltwiseFusionPass::MatchBnupdateAddRelu(const CNodePtr &cnod IsDepend(kernel_graph, cnode->input(2), {relu_input, bnupdate})) { return; } - std::vector output_used_num(AnfAlgo::GetOutputTensorNum(bnupdate), 0); + std::vector output_used_num(AnfAlgo::GetOutputTensorNum(bnupdate), 0); for (auto out_getitem : manager->node_users()[bnupdate]) { MS_EXCEPTION_IF_NULL(out_getitem.first); auto out_getitem_ptr = out_getitem.first->cast(); MS_EXCEPTION_IF_NULL(out_getitem_ptr); auto input2 = out_getitem_ptr->input(2); - auto output_idx = GetValue(GetValueNode(input2)); - output_used_num[output_idx] = SizeToInt(manager->node_users()[out_getitem.first].size()); + auto output_idx = GetValue(GetValueNode(input2)); + output_used_num[output_idx] = SizeToLong(manager->node_users()[out_getitem.first].size()); } AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), bnupdate); std::unordered_set record{cnode, relu_input, bnupdate}; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc index 400f58721eb..17bffc7f11e 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc @@ -40,14 +40,14 @@ void BnupdateEltwiseFusionPass::MatchBnupdateDoubleOutputEltwise(const CNodePtr auto bnupdate = getitem->input(1); MS_EXCEPTION_IF_NULL(bnupdate); if (bnupdate->isa() && AnfAlgo::GetCNodeName(bnupdate) == kBNTrainingUpdateOpName) { - std::vector output_used_num(AnfAlgo::GetOutputTensorNum(bnupdate), 0); + std::vector output_used_num(AnfAlgo::GetOutputTensorNum(bnupdate), 0); for (auto out_getitem : manager->node_users()[bnupdate]) { MS_EXCEPTION_IF_NULL(out_getitem.first); auto out_getitem_ptr = out_getitem.first->cast(); MS_EXCEPTION_IF_NULL(out_getitem_ptr); auto input2 = out_getitem_ptr->input(2); - auto output_idx = GetValue(GetValueNode(input2)); - output_used_num[output_idx] = SizeToInt(manager->node_users()[out_getitem.first].size()); + auto output_idx = GetValue(GetValueNode(input2)); + output_used_num[output_idx] = SizeToLong(manager->node_users()[out_getitem.first].size()); } AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), bnupdate); std::unordered_set record{cnode, bnupdate}; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_bnreduce_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_bnreduce_fusion_pass.cc index 1966229ac2b..6ed7df3df1d 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_bnreduce_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_bnreduce_fusion_pass.cc @@ -37,7 +37,7 @@ void ConvBnReduceFusionPass::MatchConvBnreduce(const CNodePtr &cnode, const sess auto conv = cnode->input(1); MS_EXCEPTION_IF_NULL(conv); if (conv->isa() && AnfAlgo::GetCNodeName(conv) == prim::kPrimConv2D->name()) { - std::vector output_used_num{SizeToInt(manager->node_users()[conv].size())}; + std::vector output_used_num{SizeToLong(manager->node_users()[conv].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), conv); std::unordered_set record{cnode, conv}; candidate_fusion->push_back(record); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.cc index 8504135ece8..a5ec41525d4 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.cc @@ -40,7 +40,7 @@ void DepthwiseConvEltwiseFusionPass::MatchDepthwiseConvRelu(const CNodePtr &cnod auto depthwise_conv = cnode->input(1); MS_EXCEPTION_IF_NULL(depthwise_conv); if (cnode->isa() && IsPrimitiveCNode(depthwise_conv, prim::kPrimDepthwiseConv2dNative)) { - std::vector output_used_num{SizeToInt(manager->node_users()[depthwise_conv].size())}; + std::vector output_used_num{SizeToLong(manager->node_users()[depthwise_conv].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), depthwise_conv); std::unordered_set record{cnode, depthwise_conv}; candidate_fusion->push_back(record); @@ -51,7 +51,7 @@ void DepthwiseConvEltwiseFusionPass::MatchDepthwiseConvRelu(const CNodePtr &cnod auto relu = cnode->input(1); MS_EXCEPTION_IF_NULL(relu); if (cnode->isa() && (IsPrimitiveCNode(relu, prim::kPrimRelu) || IsPrimitiveCNode(relu, prim::kPrimReluV2))) { - std::vector output_used_num{SizeToInt(manager->node_users()[relu].size())}; + std::vector output_used_num{SizeToLong(manager->node_users()[relu].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), relu); std::unordered_set record{cnode, relu}; candidate_fusion->push_back(record); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc index d16e22118e4..abf0bb00744 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc @@ -37,7 +37,7 @@ void MatmulConfusionTranposeFusionPass::MatchMatmulConfusionTranpose(const CNode auto matmul = cnode->input(1); MS_EXCEPTION_IF_NULL(matmul); if (matmul->isa() && AnfAlgo::CheckPrimitiveType(matmul, prim::kPrimMatMul)) { - std::vector output_used_num{SizeToInt(manager->node_users()[matmul].size())}; + std::vector output_used_num{SizeToLong(manager->node_users()[matmul].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), matmul); std::unordered_set record{cnode, matmul}; candidate_fusion->push_back(record); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_eltwise_fusion_pass.cc index adfdc80535e..a64b0cf6b17 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_eltwise_fusion_pass.cc @@ -33,7 +33,7 @@ void MatmulEltwiseFusionPass::MatchMatmulEltwise(const CNodePtr &cnode, const An MS_EXCEPTION_IF_NULL(candidate_fusion); auto manager = kernel_graph.manager(); MS_EXCEPTION_IF_NULL(manager); - std::vector output_used_num{SizeToInt(manager->node_users()[relu_input].size())}; + std::vector output_used_num{SizeToLong(manager->node_users()[relu_input].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), relu_input); std::unordered_set record{cnode, relu_input}; candidate_fusion->push_back(record); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc index 05f6d773d15..f863400846c 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc @@ -36,7 +36,7 @@ void MultiOutputFusionPass::MatchMultiOutputEltwise(const CNodePtr &cnode, const auto eltwise_input = cnode->input(1); MS_EXCEPTION_IF_NULL(eltwise_input); if (CheckMultiOutputEltWiseNode(kernel_graph, eltwise_input)) { - std::vector output_used_num{SizeToInt(manager->node_users()[eltwise_input].size())}; + std::vector output_used_num{SizeToInt(manager->node_users()[eltwise_input].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), eltwise_input); (void)record.insert(eltwise_input); auto input_cnode = eltwise_input->cast(); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.cc index 476a76f9250..ce70d38ef1c 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.cc @@ -129,9 +129,9 @@ kernel::KernelBuildInfoPtr CreateFusionOpKernelInfo(const std::vectorcast(); MS_EXCEPTION_IF_NULL(tuple_getitem); outputs_format.emplace_back(AnfAlgo::GetOutputFormat( - tuple_getitem->input(1), IntToSize(GetValue(GetValueNode(tuple_getitem->input(2)))))); + tuple_getitem->input(1), LongToSize(GetValue(GetValueNode(tuple_getitem->input(2)))))); outputs_data_type.emplace_back(AnfAlgo::GetOutputDeviceDataType( - tuple_getitem->input(1), IntToSize(GetValue(GetValueNode(tuple_getitem->input(2)))))); + tuple_getitem->input(1), LongToSize(GetValue(GetValueNode(tuple_getitem->input(2)))))); } else { outputs_format.emplace_back(AnfAlgo::GetOutputFormat(output, 0)); outputs_data_type.emplace_back(AnfAlgo::GetOutputDeviceDataType(output, 0)); @@ -151,10 +151,10 @@ AnfNodePtr CreateTupleGetItem(const AnfNodePtr &buffer_fusion_kernel, session::K std::vector tuple_getitem_inputs_list; auto value = std::make_shared(prim::kPrimTupleGetItem); MS_EXCEPTION_IF_NULL(value); - auto idx = NewValueNode(SizeToInt(output_index)); + auto idx = NewValueNode(SizeToLong(output_index)); MS_EXCEPTION_IF_NULL(idx); - int temp = SizeToInt(output_index); - auto imm = std::make_shared(temp); + int64_t temp = SizeToLong(output_index); + auto imm = std::make_shared(temp); auto abstract_scalar = std::make_shared(imm); idx->set_abstract(abstract_scalar); tuple_getitem_inputs_list.push_back(value); @@ -168,10 +168,10 @@ AnfNodePtr CreateTupleGetItem(const AnfNodePtr &buffer_fusion_kernel, session::K return tuple_item; } -void ReplaceInputNodeInOtherFusionScope(std::unordered_map *buffer_fusion_infos, - int32_t fusion_id, const AnfNodePtr &output_item, +void ReplaceInputNodeInOtherFusionScope(std::unordered_map *buffer_fusion_infos, + int64_t fusion_id, const AnfNodePtr &output_item, const AnfNodePtr &replace_item) { - for (int32_t id = fusion_id + 1; id <= SizeToInt(buffer_fusion_infos->size()); ++id) { + for (int64_t id = fusion_id + 1; id <= SizeToLong(buffer_fusion_infos->size()); ++id) { auto itr = std::find((*buffer_fusion_infos)[id].inputs_list.begin(), (*buffer_fusion_infos)[id].inputs_list.end(), output_item); if (itr != (*buffer_fusion_infos)[id].inputs_list.end()) { @@ -181,7 +181,7 @@ void ReplaceInputNodeInOtherFusionScope(std::unordered_map *buffer_fusion_infos, int32_t fusion_id, +void ReplaceOldNode(std::unordered_map *buffer_fusion_infos, int64_t fusion_id, const AnfNodePtr &buffer_fusion_kernel, session::KernelGraph *kernel_graph) { MS_EXCEPTION_IF_NULL(kernel_graph); auto manager = kernel_graph->manager(); @@ -202,7 +202,7 @@ void ReplaceOldNode(std::unordered_map *buffer_fusi } void GetFusionScopeComputeNodeList(session::KernelGraph *kernel_graph, - std::unordered_map *buffer_fusion_infos) { + std::unordered_map *buffer_fusion_infos) { MS_EXCEPTION_IF_NULL(buffer_fusion_infos); MS_EXCEPTION_IF_NULL(kernel_graph); auto nodes = TopoSort(kernel_graph->get_return()); @@ -213,14 +213,14 @@ void GetFusionScopeComputeNodeList(session::KernelGraph *kernel_graph, } auto cnode = node->cast(); if (AnfAlgo::IsRealCNodeKernel(cnode) && AnfAlgo::HasNodeAttr(kOpAttrFusionId, cnode)) { - auto fusion_id = AnfAlgo::GetNodeAttr(cnode, kOpAttrFusionId); + auto fusion_id = AnfAlgo::GetNodeAttr(cnode, kOpAttrFusionId); (*buffer_fusion_infos)[fusion_id].anf_nodes.push_back(cnode); } } } void GetFusionScopeInputNodeList(const session::KernelGraph &kernel_graph, - std::unordered_map *buffer_fusion_infos) { + std::unordered_map *buffer_fusion_infos) { MS_EXCEPTION_IF_NULL(buffer_fusion_infos); auto manager = kernel_graph.manager(); MS_EXCEPTION_IF_NULL(manager); @@ -261,13 +261,13 @@ bool TupleGetitemNodeCompare(const AnfNodePtr &node1, const AnfNodePtr &node2) { MS_LOG(EXCEPTION) << "node's input size less than " << kTupleGetItemInputSize << ", getitem1[" << getitem2->DebugString() << "]"; } - auto output_idx1 = GetValue(GetValueNode(getitem1->input(2))); - auto output_idx2 = GetValue(GetValueNode(getitem2->input(2))); + auto output_idx1 = GetValue(GetValueNode(getitem1->input(2))); + auto output_idx2 = GetValue(GetValueNode(getitem2->input(2))); return output_idx1 < output_idx2; } void GetFusionScopeOutputNodeList(session::KernelGraph *kernel_graph, - std::unordered_map *buffer_fusion_infos) { + std::unordered_map *buffer_fusion_infos) { MS_EXCEPTION_IF_NULL(kernel_graph); MS_EXCEPTION_IF_NULL(buffer_fusion_infos); auto manager = kernel_graph->manager(); @@ -286,7 +286,7 @@ void GetFusionScopeOutputNodeList(session::KernelGraph *kernel_graph, } } } else { - int prev_idx = 0; + int64_t prev_idx = 0; std::vector tuple_getitem_nodes; std::transform(manager->node_users()[node].begin(), manager->node_users()[node].end(), std::back_inserter(tuple_getitem_nodes), @@ -296,9 +296,9 @@ void GetFusionScopeOutputNodeList(session::KernelGraph *kernel_graph, MS_EXCEPTION_IF_NULL(getitem); auto getitem_ptr = getitem->cast(); auto input2 = getitem_ptr->input(2); - auto output_idx = GetValue(GetValueNode(input2)); - for (int stub_idx = prev_idx; stub_idx < output_idx; ++stub_idx) { - auto stub_node = CreateTupleGetItem(node, kernel_graph, IntToSize(stub_idx)); + auto output_idx = GetValue(GetValueNode(input2)); + for (int64_t stub_idx = prev_idx; stub_idx < output_idx; ++stub_idx) { + auto stub_node = CreateTupleGetItem(node, kernel_graph, LongToSize(stub_idx)); (*buffer_fusion_infos)[fusion_id].outputs_list.push_back(stub_node); } prev_idx = output_idx + 1; @@ -328,7 +328,7 @@ void SetFusionOpRefInfos(session::KernelGraph *kernel_graph, const std::vectorcast(); MS_EXCEPTION_IF_NULL(output_cnode); auto input2 = output_cnode->input(2); - auto output_idx = GetValue(GetValueNode(input2)); + auto output_idx = GetValue(GetValueNode(input2)); session::AnfWithOutIndex out_pair(real_output.first, output_idx); if (kernel_graph->IsInRefOutputMap(out_pair)) { auto origin_pair = kernel_graph->GetRefCorrespondOutput(out_pair); @@ -348,7 +348,7 @@ void SetFusionOpRefInfos(session::KernelGraph *kernel_graph, const std::vector *buffer_fusion_infos) const { + std::unordered_map *buffer_fusion_infos) const { MS_EXCEPTION_IF_NULL(buffer_fusion_infos); GetFusionScopeComputeNodeList(kernel_graph, buffer_fusion_infos); GetFusionScopeInputNodeList(*kernel_graph, buffer_fusion_infos); @@ -362,19 +362,19 @@ void UbPatternFusion::GetBufferFusionInfo(session::KernelGraph *kernel_graph, bool UbPatternFusion::FuseBufferFusionPattern(session::KernelGraph *kernel_graph) const { MS_EXCEPTION_IF_NULL(kernel_graph); bool change = false; - std::unordered_map buffer_fusion_infos; + std::unordered_map buffer_fusion_infos; GetBufferFusionInfo(kernel_graph, &buffer_fusion_infos); std::vector fusion_scope_infos; std::transform( buffer_fusion_infos.begin(), buffer_fusion_infos.end(), std::back_inserter(fusion_scope_infos), - [](const std::pair &buffer_fusion_info) -> mindspore::kernel::FusionScopeInfo { + [](const std::pair &buffer_fusion_info) -> mindspore::kernel::FusionScopeInfo { return mindspore::kernel::FusionScopeInfo(buffer_fusion_info.first, buffer_fusion_info.second.inputs_list, buffer_fusion_info.second.anf_nodes, buffer_fusion_info.second.outputs_list); }); auto kernel_mods = mindspore::kernel::KernelFusion(fusion_scope_infos); - std::set fusion_ids; + std::set fusion_ids; for (auto &buffer_fusion_info : buffer_fusion_infos) { MS_LOG(DEBUG) << "anf node size: " << buffer_fusion_info.second.anf_nodes.size() << ", inputs_list size: " << buffer_fusion_info.second.inputs_list.size() @@ -394,8 +394,8 @@ bool UbPatternFusion::FuseBufferFusionPattern(session::KernelGraph *kernel_graph return change; } -bool UbPatternFusion::ReplaceFusionOp(std::unordered_map *buffer_fusion_infos, - int32_t fusion_id, const kernel::KernelModPtr &kernel_ptr, +bool UbPatternFusion::ReplaceFusionOp(std::unordered_map *buffer_fusion_infos, + int64_t fusion_id, const kernel::KernelModPtr &kernel_ptr, session::KernelGraph *kernel_graph) const { MS_EXCEPTION_IF_NULL(buffer_fusion_infos); auto buffer_fusion_info = (*buffer_fusion_infos)[fusion_id]; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.h b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.h index b507a527b43..77654027693 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/ub_pattern_fusion.h @@ -39,8 +39,8 @@ class UbPatternFusion : public Pass { private: void GetBufferFusionInfo(session::KernelGraph *kernel_graph, - std::unordered_map *buffer_fusion_infos) const; - bool ReplaceFusionOp(std::unordered_map *buffer_fusion_infos, int32_t fusion_id, + std::unordered_map *buffer_fusion_infos) const; + bool ReplaceFusionOp(std::unordered_map *buffer_fusion_infos, int64_t fusion_id, const kernel::KernelModPtr &kernel_ptr, session::KernelGraph *kernel_graph) const; bool FuseBufferFusionPattern(session::KernelGraph *kernel_graph) const; }; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.cc b/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.cc index 2ca18ec7e9a..2c21292e790 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace opt { namespace { -void AddOutputs(const AnfNodePtr &node, int rank_size) { +void AddOutputs(const AnfNodePtr &node, int64_t rank_size) { MS_EXCEPTION_IF_NULL(node); auto origin_abstract = node->abstract(); MS_EXCEPTION_IF_NULL(origin_abstract); @@ -31,7 +31,7 @@ void AddOutputs(const AnfNodePtr &node, int rank_size) { AbstractBasePtrList abstract_list; std::vector outputs_device_type; std::vector outputs_device_format; - for (int i = 0; i < rank_size; ++i) { + for (int64_t i = 0; i < rank_size; ++i) { for (size_t j = 0; j < origin_abstracts.size(); ++j) { abstract_list.push_back(origin_abstracts[j]); outputs_device_type.push_back(AnfAlgo::GetOutputDeviceDataType(node, j)); @@ -52,21 +52,21 @@ void AddOutputs(const AnfNodePtr &node, int rank_size) { AnfNodePtr ConcatOutputsForAllGather::InsertConcatForOutput(const FuncGraphPtr &func_graph, const AnfNodePtr &node, const std::vector &new_tuple_getitems, - int rank_size) const { + int64_t rank_size) const { MS_EXCEPTION_IF_NULL(func_graph); std::vector make_tuple_inputs; size_t inputs_size = AnfAlgo::GetInputTensorNum(node); for (size_t i = 0; i < inputs_size; ++i) { - for (size_t j = 0, idx = i; j < IntToSize(rank_size); ++j, idx += inputs_size) { + for (size_t j = 0, idx = i; j < LongToSize(rank_size); ++j, idx += inputs_size) { std::vector concat_inputs{NewValueNode(std::make_shared(prim::kPrimConcat->name()))}; concat_inputs.push_back(new_tuple_getitems[idx]); auto concat = func_graph->NewCNode(concat_inputs); MS_EXCEPTION_IF_NULL(concat); MS_EXCEPTION_IF_NULL(new_tuple_getitems[idx]); concat->set_abstract(new_tuple_getitems[idx]->abstract()); - AnfAlgo::SetNodeAttr(kAttrAxis, MakeValue(0), concat); + AnfAlgo::SetNodeAttr(kAttrAxis, MakeValue(static_cast(0)), concat); AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(rank_size), concat); - std::vector dyn_input_size{rank_size}; + std::vector dyn_input_size{rank_size}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_size), concat); kernel_select_->SelectKernel(concat); make_tuple_inputs.push_back(concat); @@ -90,11 +90,11 @@ const AnfNodePtr ConcatOutputsForAllGather::Process(const FuncGraphPtr &func_gra if (!AnfAlgo::HasNodeAttr(kAttrFusion, cnode) || !AnfAlgo::HasNodeAttr(kAttrRankSize, cnode)) { return nullptr; } - auto fusion = AnfAlgo::GetNodeAttr(cnode, kAttrFusion); + auto fusion = AnfAlgo::GetNodeAttr(cnode, kAttrFusion); if (fusion <= 0) { return nullptr; } - auto rank_size = AnfAlgo::GetNodeAttr(node, kAttrRankSize); + auto rank_size = AnfAlgo::GetNodeAttr(node, kAttrRankSize); AddOutputs(node, rank_size); std::vector new_outputs; CreateMultipleOutputsOfAnfNode(func_graph, node, AnfAlgo::GetOutputTensorNum(node), &new_outputs); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.h b/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.h index 7b4d0d5427d..adaeb83f310 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/enhancer/concat_outputs_for_all_gather.h @@ -34,7 +34,7 @@ class ConcatOutputsForAllGather : public PatternProcessPass { private: AnfNodePtr InsertConcatForOutput(const FuncGraphPtr &func_graph, const AnfNodePtr &node, - const std::vector &new_tuple_getitems, int rank_size) const; + const std::vector &new_tuple_getitems, int64_t rank_size) const; KernelSelectPtr kernel_select_; }; } // namespace opt diff --git a/mindspore/ccsrc/backend/optimizer/ascend/enhancer/insert_pad_for_nms_with_mask.cc b/mindspore/ccsrc/backend/optimizer/ascend/enhancer/insert_pad_for_nms_with_mask.cc index 301dbdc0a47..c06a394f3c8 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/enhancer/insert_pad_for_nms_with_mask.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/enhancer/insert_pad_for_nms_with_mask.cc @@ -68,7 +68,7 @@ const AnfNodePtr InsertPadForNMSWithMask::Process(const FuncGraphPtr &func_graph auto pad = InsertPadToGraph(func_graph, cur_input, origin_type, origin_shape); MS_EXCEPTION_IF_NULL(pad); pad->set_scope(cnode->scope()); - AnfAlgo::SetNodeAttr("paddings", MakeValue(std::vector>{{0, 0}, {0, 3}}), pad); + AnfAlgo::SetNodeAttr("paddings", MakeValue(std::vector>{{0, 0}, {0, 3}}), pad); new_inputs.push_back(pad); } auto kernel_graph = func_graph->cast>(); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/chang_axis_of_reduce_kernel.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/chang_axis_of_reduce_kernel.cc index 1e7cd4c710a..740285ba777 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/chang_axis_of_reduce_kernel.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/chang_axis_of_reduce_kernel.cc @@ -36,7 +36,7 @@ const size_t kAxis_6HD_H = 1; const size_t kAxis_6HD_W = 2; const std::map kReduceConvertMap = {{kOpFormat_FRAC_Z, ConvertReduceAttrFraczAnd6HD}, {kOpFormat_C1HWNCoC0, ConvertReduceAttrFraczAnd6HD}}; -void SafeCheckFunction(const CNodePtr &cnode, const std::vector &reduce_axis) { +void SafeCheckFunction(const CNodePtr &cnode, const std::vector &reduce_axis) { if (reduce_axis.empty()) { MS_LOG(EXCEPTION) << "The node " << cnode->DebugString() << "'s reduce axis got a empty vector"; } @@ -54,7 +54,7 @@ void SafeCheckFunction(const CNodePtr &cnode, const std::vector &reduce_axi void ConvertReduceAttrFraczAnd6HD(const CNodePtr &cnode) { auto axis = kernel::GetReduceAttrAxis(cnode); - std::vector convert_axis; + std::vector convert_axis; SafeCheckFunction(cnode, axis); auto format = AnfAlgo::GetInputFormat(cnode, 0); if (format != kOpFormat_FRAC_Z || format != kOpFormat_C1HWNCoC0) { diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_cast.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_cast.cc index 0029d6c56d7..f30f25d07e0 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_cast.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_cast.cc @@ -43,9 +43,9 @@ AnfNodePtr InsertCastForMultipleOutput(const FuncGraphPtr &func_graph, const CNo AnfNodePtr replace_node = nullptr; const auto origin_shape = AnfAlgo::GetOutputInferShape(cnode, output_idx); const auto infer_type = AnfAlgo::GetOutputInferDataType(cnode, output_idx); - auto idx = NewValueNode(SizeToInt(output_idx)); + auto idx = NewValueNode(SizeToLong(output_idx)); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(output_idx); + auto imm = std::make_shared(output_idx); idx->set_abstract(std::make_shared(imm)); auto getitem = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), cnode, idx}); AnfAlgo::SetOutputInferTypeAndShape({infer_type}, {origin_shape}, getitem.get()); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_transpose_for_basiclstm_op.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_transpose_for_basiclstm_op.cc index 93f6f76dcc0..1387263d859 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_transpose_for_basiclstm_op.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/insert_transpose_for_basiclstm_op.cc @@ -50,7 +50,7 @@ CNodePtr Insert(const FuncGraphPtr &func_graph, const CNodePtr &cnode, const std CNodePtr transpose = func_graph->NewCNode(transpose_inputs); MS_EXCEPTION_IF_NULL(transpose); AnfAlgo::SetOutputInferTypeAndShape({origin_type}, {dst_shape}, transpose.get()); - AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{1, 0}), transpose); + AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{1, 0}), transpose); AnfAlgo::SetNodeInput(cnode, transpose, 1); if (kernel_graph == nullptr) { new_node = std::make_shared(*cnode); @@ -70,7 +70,7 @@ CNodePtr Insert(const FuncGraphPtr &func_graph, const CNodePtr &cnode, const std CNodePtr transpose = func_graph->NewCNode(transpose_inputs); MS_EXCEPTION_IF_NULL(transpose); AnfAlgo::SetOutputInferTypeAndShape({dtype}, {dst_shape}, transpose.get()); - AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{1, 0}), transpose); + AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{1, 0}), transpose); make_tuple_inputs.push_back(transpose); } else { make_tuple_inputs.push_back(tuple_getitem); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc index 27486377618..7934a5b937a 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc @@ -200,7 +200,7 @@ bool GetPriorOp(const AnfNodePtr &x_node, CNodePtr *prior_op, bool *single_outpu MS_EXCEPTION_IF_NULL(input2); auto value_ptr = input2->cast(); MS_EXCEPTION_IF_NULL(value_ptr); - *output_idx = IntToSize(GetValue(value_ptr->value())); + *output_idx = LongToSize(GetValue(value_ptr->value())); *single_output = false; } return AnfAlgo::IsRealKernel(*prior_op); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/modify_ops_attrs.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/modify_ops_attrs.cc index b29cab31336..5086a0c7c9b 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/modify_ops_attrs.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/modify_ops_attrs.cc @@ -49,7 +49,7 @@ AnfNodePtr ModifyTileOpAttrs(const CNodePtr &cnode) { return nullptr; } - auto multiples = AnfAlgo::GetNodeAttr>(cnode, kAttrMultiples); + auto multiples = AnfAlgo::GetNodeAttr>(cnode, kAttrMultiples); if (multiples.size() == 4 && multiples[1] == 1) { multiples.push_back(1); AnfAlgo::SetNodeAttr(kAttrMultiples, MakeValue(multiples), cnode); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/remove_internal_output.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/remove_internal_output.cc index a7c7ff6a09f..932c97e5e3e 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/remove_internal_output.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/remove_internal_output.cc @@ -73,7 +73,7 @@ const AnfNodePtr RemoveInternalOutput::Process(const FuncGraphPtr &func_graph, c } else { auto tuple_getitem = input_node->cast(); MS_EXCEPTION_IF_NULL(tuple_getitem); - int idx = AnfAlgo::GetTupleGetItemOutIndex(tuple_getitem); + int64_t idx = SizeToLong(AnfAlgo::GetTupleGetItemOutIndex(tuple_getitem)); AnfNodePtr real_input_node = AnfAlgo::GetTupleGetItemRealInput(tuple_getitem); kernel_graph->ReplaceInternalOutput(node, real_input_node, 0, idx); } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/addn_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/addn_fission.cc index 860f6c397a8..f5163f5c725 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/addn_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/addn_fission.cc @@ -33,8 +33,8 @@ AnfNodePtr CreateNewAddn(const FuncGraphPtr &func_graph, const CNodePtr &origin_ MS_EXCEPTION_IF_NULL(new_addn); new_addn->set_scope(origin_addn_cnode->scope()); new_addn->set_abstract(origin_addn_cnode->abstract()); - AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToInt(offset)), new_addn); - std::vector dyn_input_sizes{SizeToInt(offset)}; + AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToLong(offset)), new_addn); + std::vector dyn_input_sizes{SizeToLong(offset)}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), new_addn); return new_addn; } @@ -72,8 +72,8 @@ const AnfNodePtr AddnFission::Process(const FuncGraphPtr &func_graph, const AnfN MS_EXCEPTION_IF_NULL(base_addn); base_addn->set_scope(new_cnode->scope()); base_addn->set_abstract(new_cnode->abstract()); - AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToInt(base_addn_inputs.size() - 1)), base_addn); - std::vector dyn_input_sizes{SizeToInt(base_addn_inputs.size() - 1)}; + AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToLong(base_addn_inputs.size() - 1)), base_addn); + std::vector dyn_input_sizes{SizeToLong(base_addn_inputs.size() - 1)}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), base_addn); new_cnode = base_addn; origin_input_size = base_addn->inputs().size() - 1; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_bert_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_bert_fission.cc index 728ced95bee..53c1df5bee2 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_bert_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_bert_fission.cc @@ -23,7 +23,7 @@ namespace mindspore { namespace opt { namespace { -const std::vector kOutputIndex{0, 3, 4, 5}; +const std::vector kOutputIndex{0, 3, 4, 5}; constexpr size_t kBatchNormRealOutputNum = 3; constexpr size_t kBatchNormRealInputNum = 3; @@ -48,7 +48,7 @@ bool GetBatchNormOutputs(const FuncGraphPtr &func_graph, const AnfNodePtr &bn, s MS_EXCEPTION_IF_NULL(index_node); auto value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + auto index = GetValue(value_node->value()); if (std::find(kOutputIndex.begin(), kOutputIndex.end(), index) == kOutputIndex.end()) { return false; } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_grad_infer_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_grad_infer_fission.cc index ffecb745b63..28997a093ae 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_grad_infer_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/batch_norm_grad_infer_fission.cc @@ -43,7 +43,7 @@ bool CheckOutputsIndex(const FuncGraphPtr &func_graph, const AnfNodePtr &node) { MS_EXCEPTION_IF_NULL(index_node); auto value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + auto index = GetValue(value_node->value()); if (index == kBatchNormGradInferOutputNum || index == kBatchNormGradInferOutputNum + 1) { MS_LOG(DEBUG) << "The output " << index << " of node " << node->DebugString() << " is not null, no need change"; return false; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/concat_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/concat_fission.cc index dba3592e635..fb5a8d623bf 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/concat_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/concat_fission.cc @@ -35,18 +35,18 @@ AnfNodePtr CreateNewConcat(const FuncGraphPtr &func_graph, const CNodePtr &origi // Set attrs AnfAlgo::CopyNodeAttr(kAttrAxis, origin_concat_cnode, new_concat); AnfAlgo::CopyNodeAttr(kAttrT, origin_concat_cnode, new_concat); - AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToInt(offset)), new_concat); - AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(SizeToInt(offset)), new_concat); - std::vector dyn_input_sizes{SizeToInt(offset)}; + AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToLong(offset)), new_concat); + AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(SizeToLong(offset)), new_concat); + std::vector dyn_input_sizes{SizeToLong(offset)}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), new_concat); // infer shape auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(origin_concat_cnode, 0); - auto axis = AnfAlgo::GetNodeAttr(origin_concat_cnode, kAttrAxis); + auto axis = AnfAlgo::GetNodeAttr(origin_concat_cnode, kAttrAxis); if (axis < 0) { axis += input_shape.size(); } auto output_shape = AnfAlgo::GetOutputInferShape(origin_concat_cnode, 0); - if (axis < 0 || axis >= SizeToInt(output_shape.size()) || axis >= SizeToInt(input_shape.size())) { + if (axis < 0 || axis >= SizeToLong(output_shape.size()) || axis >= SizeToLong(input_shape.size())) { MS_LOG(EXCEPTION) << "The concat_dim value " << axis << "is out of range"; } output_shape[axis] = input_shape[axis] * offset; @@ -95,9 +95,9 @@ const AnfNodePtr ConcatFission::Process(const FuncGraphPtr &func_graph, const An // Set attrs AnfAlgo::CopyNodeAttr(kAttrAxis, new_cnode, base_concat); AnfAlgo::CopyNodeAttr(kAttrT, new_cnode, base_concat); - AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToInt(base_concat_inputs.size() - 1)), base_concat); - AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(SizeToInt(base_concat_inputs.size() - 1)), base_concat); - std::vector dyn_input_sizes{SizeToInt(base_concat_inputs.size() - 1)}; + AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToLong(base_concat_inputs.size() - 1)), base_concat); + AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(SizeToLong(base_concat_inputs.size() - 1)), base_concat); + std::vector dyn_input_sizes{SizeToLong(base_concat_inputs.size() - 1)}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), base_concat); new_cnode = base_concat; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/layer_norm_grad_split.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/layer_norm_grad_split.cc index d79e9e78184..8753fa20aff 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/layer_norm_grad_split.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/layer_norm_grad_split.cc @@ -70,7 +70,7 @@ void LayerNormGradSplit::CreateOutputsOfLayerNormBetaGammaBackprop( // get device shape of LayerNormGrad's 5th Input, and convert it to attr std::vector shape_gamma = AnfAlgo::GetPrevNodeOutputInferShape(layer_norm_grad, 4); - AnfAlgo::SetNodeAttr(kAttrShapeGamma, MakeValue(opt::Convert2Int(shape_gamma)), layer_norm_beta_gamma_backprop); + AnfAlgo::SetNodeAttr(kAttrShapeGamma, MakeValue(opt::Convert2Long(shape_gamma)), layer_norm_beta_gamma_backprop); CreateMultipleOutputsOfAnfNode(graph, layer_norm_beta_gamma_backprop, kLayerNormBetaGammaBackpropOutputNum, layer_norm_beta_gamma_backprop_outputs); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/pack_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/pack_fission.cc index 873bec1f70f..c78ddd10f49 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/pack_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/pack_fission.cc @@ -34,13 +34,13 @@ AnfNodePtr CreateNewPack(const FuncGraphPtr &func_graph, const CNodePtr &origin_ new_pack->set_scope(origin_pack_cnode->scope()); new_pack->set_abstract(origin_pack_cnode->abstract()); AnfAlgo::CopyNodeAttr(kAttrAxis, origin_pack_cnode, new_pack); - AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToInt(offset)), new_pack); - AnfAlgo::SetNodeAttr(kAttrNum, MakeValue(SizeToInt(offset)), new_pack); - std::vector dyn_input_sizes{SizeToInt(offset)}; + AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToLong(offset)), new_pack); + AnfAlgo::SetNodeAttr(kAttrNum, MakeValue(SizeToLong(offset)), new_pack); + std::vector dyn_input_sizes{SizeToLong(offset)}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), new_pack); // infer shape auto output_shape = AnfAlgo ::GetOutputInferShape(origin_pack_cnode, 0); - auto axis = AnfAlgo::GetNodeAttr(new_pack, kAttrAxis); + auto axis = AnfAlgo::GetNodeAttr(new_pack, kAttrAxis); if (axis < 0) { axis += output_shape.size(); } @@ -49,12 +49,12 @@ AnfNodePtr CreateNewPack(const FuncGraphPtr &func_graph, const CNodePtr &origin_ } std::vector new_shape; for (size_t i = 0; i < output_shape.size() + 1; ++i) { - if (i < IntToSize(axis)) { + if (i < LongToSize(axis)) { new_shape.push_back(output_shape[i]); - } else if (i == IntToSize(axis)) { + } else if (i == LongToSize(axis)) { new_shape.push_back(offset); } else { - new_shape.push_back(output_shape[SizeToInt(i) - 1]); + new_shape.push_back(output_shape[SizeToLong(i) - 1]); } } new_shape.erase(new_shape.begin() + axis + 1); @@ -99,9 +99,9 @@ const AnfNodePtr PackFission::Process(const FuncGraphPtr &func_graph, const AnfN base_concat->set_scope(cnode->scope()); base_concat->set_abstract(cnode->abstract()); AnfAlgo::CopyNodeAttr(kAttrAxis, cnode, base_concat); - AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToInt(base_concat_inputs.size() - 1)), base_concat); - AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(SizeToInt(base_concat_inputs.size() - 1)), base_concat); - std::vector dyn_input_sizes{SizeToInt(base_concat_inputs.size() - 1)}; + AnfAlgo::SetNodeAttr(kAttrN, MakeValue(SizeToLong(base_concat_inputs.size() - 1)), base_concat); + AnfAlgo::SetNodeAttr(kAttrInputNums, MakeValue(SizeToLong(base_concat_inputs.size() - 1)), base_concat); + std::vector dyn_input_sizes{SizeToLong(base_concat_inputs.size() - 1)}; AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), base_concat); return base_concat; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/reduce_min_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/reduce_min_fission.cc index 8b237d7e735..9c3ca1d0854 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/reduce_min_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/reduce_min_fission.cc @@ -32,7 +32,7 @@ CNodePtr CreateReduceMin(const FuncGraphPtr &graph, const AnfNodePtr &input, con return reduce_min; } -bool NeedOptimize(const TypeId &dtype, const std::vector &shape, const std::vector &axis) { +bool NeedOptimize(const TypeId &dtype, const std::vector &shape, const std::vector &axis) { if (dtype != kNumberTypeFloat32) { MS_LOG(INFO) << "ReduceMin's input Dtype is not float32, no need optimize!"; return false; @@ -45,7 +45,7 @@ bool NeedOptimize(const TypeId &dtype, const std::vector &shape, const s MS_LOG(INFO) << "ReduceMin axis size is 1, no need optimize!"; return false; } - int last_dim = SizeToInt(shape.size() - 1); + int64_t last_dim = SizeToLong(shape.size() - 1); if (std::find(axis.begin(), axis.end(), -1) == axis.end() && std::find(axis.begin(), axis.end(), last_dim) == axis.end()) { MS_LOG(INFO) << "Attribute of axis does not contain the last axis, not match!"; @@ -54,15 +54,15 @@ bool NeedOptimize(const TypeId &dtype, const std::vector &shape, const s return true; } -std::vector CalFirstAxis(const std::vector &shape, const std::vector &axis) { - std::vector axis_fisrt; - int last_dim = SizeToInt(shape.size() - 1); +std::vector CalFirstAxis(const std::vector &shape, const std::vector &axis) { + std::vector axis_fisrt; + int64_t last_dim = SizeToLong(shape.size() - 1); std::copy_if(axis.begin(), axis.end(), std::back_inserter(axis_fisrt), - [&last_dim](int v) { return v != -1 && v != last_dim; }); + [&last_dim](int64_t v) { return v != -1 && v != last_dim; }); - int dim_size = SizeToInt(shape.size()); + int64_t dim_size = SizeToLong(shape.size()); if (axis_fisrt.empty()) { - for (int i = 0; i < dim_size - 1; ++i) { + for (int64_t i = 0; i < dim_size - 1; ++i) { axis_fisrt.push_back(i); } } @@ -78,7 +78,7 @@ std::vector CalFirstAxis(const std::vector &shape, const std::vecto return axis_fisrt; } -std::vector GetInferShape(const std::vector &shape, const std::vector &axis_first, +std::vector GetInferShape(const std::vector &shape, const std::vector &axis_first, bool keep_dims) { std::vector shape_first; for (size_t item = 0; item < shape.size(); ++item) { @@ -124,7 +124,7 @@ const AnfNodePtr ReduceMinFission::Process(const FuncGraphPtr &graph, const AnfN if (!axis_value->isa()) { return nullptr; } - auto axis = AnfAlgo::GetNodeAttr>(cnode, kAttrAxis); + auto axis = AnfAlgo::GetNodeAttr>(cnode, kAttrAxis); auto keep_dims = AnfAlgo::GetNodeAttr(cnode, kAttrKeepDims); if (!NeedOptimize(dtype, shape, axis)) { @@ -134,7 +134,7 @@ const AnfNodePtr ReduceMinFission::Process(const FuncGraphPtr &graph, const AnfN // Create reduce_min1 CNodePtr reduce_min1 = CreateReduceMin(graph, cnode->input(1), cnode); - std::vector axis_first = CalFirstAxis(shape, axis); + std::vector axis_first = CalFirstAxis(shape, axis); std::vector shape_first = GetInferShape(shape, axis_first, keep_dims); AnfAlgo::SetOutputInferTypeAndShape({dtype}, {shape_first}, reduce_min1.get()); AnfAlgo::SetNodeAttr(kAttrAxis, MakeValue(axis_first), reduce_min1); @@ -142,7 +142,7 @@ const AnfNodePtr ReduceMinFission::Process(const FuncGraphPtr &graph, const AnfN // Create reduce_min2 CNodePtr reduce_min2 = CreateReduceMin(graph, reduce_min1, cnode); reduce_min2->set_abstract(cnode->abstract()); - std::vector axis_last = {-1}; + std::vector axis_last = {-1}; AnfAlgo::SetNodeAttr(kAttrAxis, MakeValue(axis_last), reduce_min2); return reduce_min2; } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.cc index d1b184a72a8..47ded45024a 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.cc @@ -40,43 +40,44 @@ CNodePtr CreateBaseSplitVNode(const FuncGraphPtr &func_graph, const CNodePtr &or return CreateSplitVNode(func_graph, origin_cnode->input(1)); } -void SetAttrForSplitVNode(const AnfNodePtr &splitv, const std::vector &size_splits, int split_dim, int num_split) { +void SetAttrForSplitVNode(const AnfNodePtr &splitv, const std::vector &size_splits, int64_t split_dim, + int64_t num_split) { AnfAlgo::SetNodeAttr(kAttrSizeSplits, MakeValue(size_splits), splitv); AnfAlgo::SetNodeAttr(kAttrSplitDim, MakeValue(split_dim), splitv); AnfAlgo::SetNodeAttr(kAttrNumSplit, MakeValue(num_split), splitv); } -size_t GetSmallSplitSize(const AnfNodePtr &split_node, int split_dim, int num_split) { +size_t GetSmallSplitSize(const AnfNodePtr &split_node, int64_t split_dim, int64_t num_split) { auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(split_node, 0); if (split_dim < 0) { split_dim += input_shape.size(); } - if (IntToSize(split_dim) >= input_shape.size()) { + if (LongToSize(split_dim) >= input_shape.size()) { MS_LOG(EXCEPTION) << "The split_dim value should be less than the shape size of input 0"; } return input_shape[split_dim] / num_split; } -void AddNewOutputs(const FuncGraphPtr &func_graph, const AnfNodePtr &new_splitv, int outputs_num, +void AddNewOutputs(const FuncGraphPtr &func_graph, const AnfNodePtr &new_splitv, int64_t outputs_num, std::vector *inputs) { MS_EXCEPTION_IF_NULL(inputs); std::vector new_splitv_output; - CreateMultipleOutputsOfAnfNode(func_graph, new_splitv, outputs_num, &new_splitv_output); + CreateMultipleOutputsOfAnfNode(func_graph, new_splitv, LongToSize(outputs_num), &new_splitv_output); inputs->insert(inputs->end(), new_splitv_output.begin(), new_splitv_output.end()); } AnfNodePtr CreateTupleGetItem(const FuncGraphPtr &func_graph, const AnfNodePtr &input, size_t index) { MS_EXCEPTION_IF_NULL(func_graph); - auto idx = NewValueNode(SizeToInt(index)); + auto idx = NewValueNode(SizeToLong(index)); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(SizeToInt(index)); + auto imm = std::make_shared(SizeToLong(index)); auto abstract_scalar = std::make_shared(imm); idx->set_abstract(abstract_scalar); auto tuple_getitem = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), input, idx}); return tuple_getitem; } -void CreateOutputShapeAndTypeId(const CNodePtr &origin_cnode, int split_dim, int split_size, int num_split, +void CreateOutputShapeAndTypeId(const CNodePtr &origin_cnode, int64_t split_dim, int64_t split_size, int64_t num_split, std::vector *new_type_ids, std::vector> *new_output_shapes) { MS_EXCEPTION_IF_NULL(new_type_ids); @@ -87,7 +88,7 @@ void CreateOutputShapeAndTypeId(const CNodePtr &origin_cnode, int split_dim, int } output_shape[split_dim] = split_size; TypeId type_id = AnfAlgo::GetOutputInferDataType(origin_cnode, 0); - for (int i = 0; i < num_split; ++i) { + for (int64_t i = 0; i < num_split; ++i) { new_type_ids->emplace_back(type_id); new_output_shapes->emplace_back(output_shape); } @@ -95,7 +96,8 @@ void CreateOutputShapeAndTypeId(const CNodePtr &origin_cnode, int split_dim, int void SetAttrAndAbstractForBaseSplitv(const CNodePtr &origin_cnode, const CNodePtr &base_splitv, const std::vector &base_splitv_outputs, - const std::vector &size_splits_base, int split_dim, int num_split) { + const std::vector &size_splits_base, int64_t split_dim, + int64_t num_split) { SetAttrForSplitVNode(base_splitv, size_splits_base, split_dim, num_split); auto output_shape = AnfAlgo::GetOutputInferShape(origin_cnode, 0); TypeId type_id = AnfAlgo::GetOutputInferDataType(origin_cnode, 0); @@ -104,7 +106,7 @@ void SetAttrAndAbstractForBaseSplitv(const CNodePtr &origin_cnode, const CNodePt if (split_dim < 0) { split_dim += output_shape.size(); } - for (int i = 0; i < num_split; ++i) { + for (int64_t i = 0; i < num_split; ++i) { output_shape[split_dim] = size_splits_base[i]; base_output_shapes_base.emplace_back(output_shape); AnfAlgo::SetOutputInferTypeAndShape({type_id}, {output_shape}, base_splitv_outputs[i].get()); @@ -112,14 +114,14 @@ void SetAttrAndAbstractForBaseSplitv(const CNodePtr &origin_cnode, const CNodePt AnfAlgo::SetOutputInferTypeAndShape(base_type_ids, base_output_shapes_base, base_splitv.get()); } -AnfNodePtr DoFission(const FuncGraphPtr &func_graph, const CNodePtr &cnode, int num_split, int divisor) { +AnfNodePtr DoFission(const FuncGraphPtr &func_graph, const CNodePtr &cnode, int64_t num_split, int64_t divisor) { MS_EXCEPTION_IF_NULL(func_graph); - auto split_dim = AnfAlgo::GetNodeAttr(cnode, kAttrAxis); + auto split_dim = AnfAlgo::GetNodeAttr(cnode, kAttrAxis); CNodePtr base_splitv = CreateBaseSplitVNode(func_graph, cnode); // Create new size_splits for "size_splits" attr of each new Splitv node which has full inputs. - auto small_split_size = SizeToInt(GetSmallSplitSize(cnode, split_dim, num_split)); - std::vector size_splits_new(divisor, small_split_size); + auto small_split_size = SizeToLong(GetSmallSplitSize(cnode, split_dim, num_split)); + std::vector size_splits_new(divisor, small_split_size); // Create new output shape and new output type id for each new Splitv node which has full inputs. std::vector new_type_ids; std::vector> new_output_shapes; @@ -128,11 +130,11 @@ AnfNodePtr DoFission(const FuncGraphPtr &func_graph, const CNodePtr &cnode, int // Create make_tuple input to create a make_tuple for replacing the old Split node. std::vector make_tuple_inputs = {NewValueNode(prim::kPrimMakeTuple)}; // Start to divide the outputs of Split. - std::vector size_splits_base; + std::vector size_splits_base; std::vector base_splitv_outputs; const auto base_split_size = divisor * small_split_size; - int nodes_num = 0; - int cur_output_index = 0; + int64_t nodes_num = 0; + int64_t cur_output_index = 0; while (num_split - cur_output_index > divisor) { auto tuple_getitem = CreateTupleGetItem(func_graph, base_splitv, nodes_num); base_splitv_outputs.push_back(tuple_getitem); @@ -150,7 +152,7 @@ AnfNodePtr DoFission(const FuncGraphPtr &func_graph, const CNodePtr &cnode, int auto tuple_getitem = CreateTupleGetItem(func_graph, base_splitv, nodes_num); base_splitv_outputs.push_back(tuple_getitem); CNodePtr new_splitv = CreateSplitVNode(func_graph, tuple_getitem); - std::vector size_splits_new_last(last_node_num_split, small_split_size); + std::vector size_splits_new_last(last_node_num_split, small_split_size); SetAttrForSplitVNode(new_splitv, size_splits_new_last, split_dim, last_node_num_split); // Create new output shape and new output type id for the last Splitv node std::vector last_new_type_ids; @@ -192,7 +194,7 @@ const AnfNodePtr SplitFission::Process(const FuncGraphPtr &func_graph, const Anf if (!AnfAlgo::HasNodeAttr(kAttrOutputNum, cnode)) { return nullptr; } - auto num_split = AnfAlgo::GetNodeAttr(cnode, kAttrOutputNum); + auto num_split = AnfAlgo::GetNodeAttr(cnode, kAttrOutputNum); if (num_split <= outputs_divisor_) { return nullptr; } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.h b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.h index ce12031a944..6ea6717858c 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/split_fission.h @@ -30,7 +30,7 @@ class SplitFission : public PatternProcessPass { const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override; private: - int outputs_divisor_; + int64_t outputs_divisor_; }; } // namespace opt } // namespace mindspore diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/topk_split.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/topk_split.cc index 213b435f1c3..857dfa1c8fc 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/topk_split.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/topk_split.cc @@ -35,7 +35,7 @@ tensor::TensorPtr CreateTensor(const AnfNodePtr &node) { // 1 create tensor auto shape = AnfAlgo::GetPrevNodeOutputInferShape(node, 0); auto last_dim = shape[shape.size() - 1]; - std::vector indices_shape = {SizeToInt(last_dim * 2)}; + std::vector indices_shape = {SizeToLong(last_dim * 2)}; TensorTypePtr tensor_type = std::make_shared(kFloat16); MS_EXCEPTION_IF_NULL(tensor_type); tensor::DeviceInfo device_info{kOpFormat_DEFAULT, tensor_type}; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/transdata_split.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/transdata_split.cc index 85d0efe5ca4..7a80dfacf2b 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/transdata_split.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/transdata_split.cc @@ -75,13 +75,13 @@ bool TransDataSplit::DoSplit(const FuncGraphPtr &func_graph, const AnfNodePtr &n new_transpose_node = NewTransOpNode(func_graph, new_transdata_node, kernel_select_, false, prim::kPrimTranspose->name()); RefreshKernelBuildInfo(kOpFormat_HWCN, output_format, new_transpose_node); - AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{3, 2, 0, 1}), new_transpose_node); + AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{3, 2, 0, 1}), new_transpose_node); new_replace_node = new_transpose_node; } else { // trans default to hwcn new_transpose_node = NewTransOpNode(func_graph, AnfAlgo::GetInputNode(node->cast(), 0), kernel_select_, false, prim::kPrimTranspose->name()); - AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{2, 3, 1, 0}), new_transpose_node); + AnfAlgo::SetNodeAttr(kAttrPerm, MakeValue(std::vector{2, 3, 1, 0}), new_transpose_node); if (output_format == kOpFormat_FRACTAL_ZN_LSTM) { AnfAlgo::SetNodeAttr("nop_op", MakeValue(true), new_transpose_node); } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/unsorted_segment_sum_fission.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/unsorted_segment_sum_fission.cc index c8aaf3eeaab..150f8aa05a3 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/unsorted_segment_sum_fission.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/unsorted_segment_sum_fission.cc @@ -35,7 +35,7 @@ CNodePtr CreatePadding(const FuncGraphPtr &graph, const CNodePtr &origin_node, c shape[shape.size() - 1] = pad_dim_size; AnfAlgo::SetOutputInferTypeAndShape({AnfAlgo::GetPrevNodeOutputInferDataType(origin_node, 0)}, {shape}, padding.get()); - AnfAlgo::SetNodeAttr(kAttrPadDimSize, MakeValue(SizeToInt(pad_dim_size)), padding); + AnfAlgo::SetNodeAttr(kAttrPadDimSize, MakeValue(SizeToLong(pad_dim_size)), padding); return padding; } @@ -53,7 +53,7 @@ CNodePtr CreateUnsortedSegmentSum(const FuncGraphPtr &graph, const CNodePtr &ori shape[shape.size() - 1] = pad_dim_size; AnfAlgo::SetOutputInferTypeAndShape({AnfAlgo::GetOutputInferDataType(origin_node, 0)}, {shape}, unsorted_segment_sum.get()); - AnfAlgo::SetNodeAttr(kAttrNumSegments, MakeValue(SizeToInt(shape[0])), unsorted_segment_sum); + AnfAlgo::SetNodeAttr(kAttrNumSegments, MakeValue(SizeToLong(shape[0])), unsorted_segment_sum); return unsorted_segment_sum; } @@ -70,8 +70,8 @@ CNodePtr CreateSlice(const FuncGraphPtr &graph, const CNodePtr &unsort_segment_s slice->set_abstract(unsort_segment_sum->abstract()); auto unsort_segment_sum_shape = AnfAlgo::GetOutputInferShape(unsort_segment_sum, 0); std::vector offsets(unsort_segment_sum_shape.size(), 0); - AnfAlgo::SetNodeAttr(kAttrBegin, MakeValue(Convert2Int(offsets)), slice); - AnfAlgo::SetNodeAttr(kAttrSize, MakeValue(Convert2Int(unsort_segment_sum_shape)), slice); + AnfAlgo::SetNodeAttr(kAttrBegin, MakeValue(Convert2Long(offsets)), slice); + AnfAlgo::SetNodeAttr(kAttrSize, MakeValue(Convert2Long(unsort_segment_sum_shape)), slice); return slice; } } // namespace diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnorm_to_bninfer.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnorm_to_bninfer.cc index 2a952e79862..9e98d4ff18d 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnorm_to_bninfer.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnorm_to_bninfer.cc @@ -46,12 +46,12 @@ CNodePtr CreateBNInfer(const FuncGraphPtr &graph, const CNodePtr &batchnorm, con bool CheckIndex(const AnfNodePtr &index_node) { MS_EXCEPTION_IF_NULL(index_node); - if (!IsValueNode(index_node)) { + if (!IsValueNode(index_node)) { return false; } ValueNodePtr value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + auto index = GetValue(value_node->value()); if (index != 0) { MS_LOG(DEBUG) << "tuple_getitem must be 0th output of BatchNorm"; return false; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnormgrad_to_bninfergrad.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnormgrad_to_bninfergrad.cc index ca2913b5b9f..8ad1f5ce36d 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnormgrad_to_bninfergrad.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/batchnormgrad_to_bninfergrad.cc @@ -45,12 +45,12 @@ CNodePtr CreateBNInferGrad(const FuncGraphPtr &graph, const CNodePtr &batchnormg bool CheckIndex(const AnfNodePtr &index_node) { MS_EXCEPTION_IF_NULL(index_node); - if (!IsValueNode(index_node)) { + if (!IsValueNode(index_node)) { return false; } ValueNodePtr value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + int64_t index = GetValue(value_node->value()); if (index != 0) { MS_LOG(DEBUG) << "tuple_getitem must be 0th output of BatchNormGrad"; return false; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/fused_batch_norm_fusion.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/fused_batch_norm_fusion.cc index 06fc06535cb..8d4a5743fed 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/fused_batch_norm_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/fused_batch_norm_fusion.cc @@ -283,7 +283,7 @@ const AnfNodePtr FusedBatchNormFusion::Process(const FuncGraphPtr &func_graph, c MS_EXCEPTION_IF_NULL(index_node); auto value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + auto index = GetValue(value_node->value()); if (index == kReplaceOutputIndex0 || index == kReplaceOutputIndex1) { (void)manager->Replace(output, bn_training_update_outputs[index]); } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/reshape_transpose_fusion.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/reshape_transpose_fusion.cc index 76f2445dbbf..fd41cfe56f4 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/reshape_transpose_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/reshape_transpose_fusion.cc @@ -68,7 +68,7 @@ const AnfNodePtr ReshapeTransposeFusion::Process(const FuncGraphPtr &func_graph, AnfAlgo::CopyNodeAttr(kAttrPerm, transpose_cnode, new_node); AnfAlgo::SetNodeAttr(kAttrTransposeFirst, MakeValue(false), new_node); auto reshape_output_shape = AnfAlgo::GetOutputInferShape(reshape_cnode, 0); - AnfAlgo::SetNodeAttr(kAttrShape, MakeValue(Convert2Int(reshape_output_shape)), new_node); + AnfAlgo::SetNodeAttr(kAttrShape, MakeValue(Convert2Long(reshape_output_shape)), new_node); return new_node; } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/transpose_reshape_fusion.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/transpose_reshape_fusion.cc index 7e34b90fa02..0643537d020 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/transpose_reshape_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/transpose_reshape_fusion.cc @@ -68,7 +68,7 @@ const AnfNodePtr TransposeReshapeFusion::Process(const FuncGraphPtr &func_graph, AnfAlgo::CopyNodeAttr(kAttrPerm, transpose_cnode, new_node); AnfAlgo::SetNodeAttr(kAttrTransposeFirst, MakeValue(true), new_node); auto reshape_output_shape = AnfAlgo::GetOutputInferShape(reshape_cnode, 0); - AnfAlgo::SetNodeAttr(kAttrShape, MakeValue(Convert2Int(reshape_output_shape)), new_node); + AnfAlgo::SetNodeAttr(kAttrShape, MakeValue(Convert2Long(reshape_output_shape)), new_node); return new_node; } diff --git a/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.cc b/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.cc index d21cabe54a1..6b015d5917c 100644 --- a/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.cc +++ b/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.cc @@ -24,7 +24,7 @@ FusionIdAllocator::~FusionIdAllocator() {} void FusionIdAllocator::Init() { fusion_id = 0; } -int32_t FusionIdAllocator::AllocateFusionId() { +int64_t FusionIdAllocator::AllocateFusionId() { fusion_id++; return fusion_id; } @@ -38,14 +38,14 @@ bool FusionIdAllocator::HasFusionIdAttr(const AnfNodePtr &node) { return AnfAlgo::HasNodeAttr(kAttrFusionId, cnode); } -int32_t FusionIdAllocator::GetFusionId(const AnfNodePtr &node) { +int64_t FusionIdAllocator::GetFusionId(const AnfNodePtr &node) { if (HasFusionIdAttr(node)) { - return AnfAlgo::GetNodeAttr(node, kAttrFusionId); + return AnfAlgo::GetNodeAttr(node, kAttrFusionId); } return -1; } -void FusionIdAllocator::SetFusionId(const AnfNodePtr &node, int32_t id) { +void FusionIdAllocator::SetFusionId(const AnfNodePtr &node, int64_t id) { ValuePtr fusion_id_v = MakeValue(id); AnfAlgo::SetNodeAttr(kAttrFusionId, fusion_id_v, node); } diff --git a/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.h b/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.h index b4cc2e505e0..edce7edddbe 100644 --- a/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.h +++ b/mindspore/ccsrc/backend/optimizer/common/fusion_id_allocator.h @@ -29,13 +29,13 @@ class FusionIdAllocator { FusionIdAllocator &operator=(const FusionIdAllocator &in) = delete; void Init(); - int32_t AllocateFusionId(); + int64_t AllocateFusionId(); bool HasFusionIdAttr(const AnfNodePtr &node); - int32_t GetFusionId(const AnfNodePtr &node); - void SetFusionId(const AnfNodePtr &node, int32_t id); + int64_t GetFusionId(const AnfNodePtr &node); + void SetFusionId(const AnfNodePtr &node, int64_t id); private: - int32_t fusion_id; + int64_t fusion_id; }; using FusionIdAllocatorPtr = std::shared_ptr; } // namespace opt diff --git a/mindspore/ccsrc/backend/optimizer/common/helper.cc b/mindspore/ccsrc/backend/optimizer/common/helper.cc index 794e2071eca..35ac2489e9b 100644 --- a/mindspore/ccsrc/backend/optimizer/common/helper.cc +++ b/mindspore/ccsrc/backend/optimizer/common/helper.cc @@ -35,12 +35,18 @@ namespace mindspore { namespace opt { constexpr size_t kType32Len = 4; -std::vector Convert2Int(const std::vector &v) { - std::vector result; +std::vector Convert2Int(const std::vector &v) { + std::vector result; (void)std::transform(v.begin(), v.end(), std::back_inserter(result), SizeToInt); return result; } +std::vector Convert2Long(const std::vector &v) { + std::vector result; + (void)std::transform(v.begin(), v.end(), std::back_inserter(result), SizeToLong); + return result; +} + bool IsDepend(const FuncGraph &graph, const AnfNodePtr &node, const std::vector &nodes) { MS_EXCEPTION_IF_NULL(node); std::vector node_list = TopoSort(graph.get_return()); @@ -112,32 +118,14 @@ bool UnVisited(const BaseRef &n) { return false; } -bool CheckIfCNodeAndInputSize(const AnfNodePtr &node, int input_size, CNodePtr *cnode) { - MS_EXCEPTION_IF_NULL(node); - if (!node->isa()) { - MS_LOG(ERROR) << "The node is expected to be a cnode"; - return false; - } - *cnode = node->cast(); - if (*cnode == nullptr) { - return false; - } - if ((*cnode)->inputs().size() < IntToSize(input_size)) { - auto op_name = AnfAlgo::GetCNodeName(*cnode); - MS_LOG(ERROR) << "op[" + op_name + "] has less than " << input_size << " inputs."; - return false; - } - return true; -} - -CNodePtr CheckAnfNodeIfCNodeAndInputSize(const AnfNodePtr &node, int input_size) { +CNodePtr CheckAnfNodeIfCNodeAndInputSize(const AnfNodePtr &node, size_t input_size) { MS_EXCEPTION_IF_NULL(node); if (!node->isa()) { MS_LOG(EXCEPTION) << "The node is expected to be a cnode"; } auto cnode = node->cast(); MS_EXCEPTION_IF_NULL(cnode); - if (cnode->inputs().size() != IntToSize(input_size)) { + if (cnode->inputs().size() != input_size) { auto op_name = AnfAlgo::GetCNodeName(cnode); MS_LOG(EXCEPTION) << "op[" + op_name + "] has less than " << input_size << " inputs."; } @@ -201,122 +189,16 @@ bool Visited(const BaseRef &n) { return false; } -void CreateOutputsOfConvBn1(const FuncGraphPtr &func_graph, const CNodePtr &conv_cnode, const CNodePtr &bn_cnode, - std::vector *conv_bn1_outputs) { - auto prim = std::make_shared(kConvBN1OpName); - std::vector conv_bn1_inputs = {NewValueNode(prim)}; - MS_EXCEPTION_IF_NULL(conv_cnode); - // All the inputs of conv_bn1 are from the inputs of conv - for (size_t i = 1; i < conv_cnode->inputs().size(); i++) { - conv_bn1_inputs.push_back(conv_cnode->input(i)); - } - MS_EXCEPTION_IF_NULL(func_graph); - CNodePtr conv_bn1_cnode = func_graph->NewCNode(conv_bn1_inputs); - MS_EXCEPTION_IF_NULL(conv_bn1_cnode); - auto kernel_info = std::make_shared(); - conv_bn1_cnode->set_kernel_info(kernel_info); - // Set attr for conv_bn1 - AnfAlgo::CopyNodeAttrs(conv_cnode, conv_bn1_cnode); - // Set abstract of conv_bn1 - MS_EXCEPTION_IF_NULL(bn_cnode); - auto bn_abstract_tuple = dyn_cast(bn_cnode->abstract()); - MS_EXCEPTION_IF_NULL(bn_abstract_tuple); - AbstractBasePtrList conv_bn1_abstract_list; - conv_bn1_abstract_list.push_back(conv_cnode->abstract()); - auto abstract_tensor = std::make_shared( - kFloat32, Convert2Int(AnfAlgo::GetPrevNodeOutputInferShape(bn_cnode, kVariance - 1))); - conv_bn1_abstract_list.push_back(abstract_tensor); - conv_bn1_abstract_list.push_back(bn_abstract_tuple->elements()[kSaveMean]); - auto abstract_tuple = std::make_shared(conv_bn1_abstract_list); - conv_bn1_cnode->set_abstract(abstract_tuple); - - CreateMultipleOutputsOfAnfNode(func_graph, conv_bn1_cnode, kConvBn1OutputNum, conv_bn1_outputs); -} - -void CreateOutputsOfFusedBn2(const FuncGraphPtr &graph, const std::vector &fused_bn1_outputs, - const CNodePtr &bn_node, std::vector *fused_bn2_outputs) { - MS_EXCEPTION_IF_NULL(graph); - MS_EXCEPTION_IF_NULL(bn_node); - MS_EXCEPTION_IF_NULL(fused_bn2_outputs); - if (bn_node->inputs().size() != kBnInputNum) { - MS_LOG(EXCEPTION) << "BN node has wrong input size"; - } - if (fused_bn1_outputs.size() != kBN1OutputNum) { - MS_LOG(EXCEPTION) << "BN1 outputs has wrong input size"; - } - - // the inputs of fused_bn2 are from the outputs of fused_bn1 and the inputs of bn - std::vector fused_bn2_inputs = {NewValueNode(std::make_shared(kFusedBN2OpName))}; - fused_bn2_inputs.push_back(fused_bn1_outputs[0]); - fused_bn2_inputs.push_back(fused_bn1_outputs[1]); - fused_bn2_inputs.push_back(bn_node->input(4)); - fused_bn2_inputs.push_back(bn_node->input(5)); - auto fused_bn2 = graph->NewCNode(fused_bn2_inputs); - MS_EXCEPTION_IF_NULL(fused_bn2); - auto kernel_info = std::make_shared(); - fused_bn2->set_kernel_info(kernel_info); - auto types = {AnfAlgo::GetOutputInferDataType(bn_node, 4), AnfAlgo::GetOutputInferDataType(bn_node, 1), - AnfAlgo::GetOutputInferDataType(bn_node, 2)}; - auto shapes = {AnfAlgo::GetOutputInferShape(bn_node, 4), AnfAlgo::GetOutputInferShape(bn_node, 1), - AnfAlgo::GetOutputInferShape(bn_node, 2)}; - AnfAlgo::SetOutputInferTypeAndShape(types, shapes, fused_bn2.get()); - fused_bn2->set_scope(bn_node->scope()); - AnfAlgo::CopyNodeAttr(kAttrMomentum, bn_node, fused_bn2); - - CreateMultipleOutputsOfAnfNode(graph, fused_bn2, kBN2OutputNum, fused_bn2_outputs); -} - -void CreateOutputsOfFusedBn3(const FuncGraphPtr &graph, const AnfNodePtr &data_input, - const std::vector &fused_bn1_outputs, - const std::vector &fused_bn2_outputs, const CNodePtr &bn_node, - std::vector *fused_bn3_outputs) { - MS_EXCEPTION_IF_NULL(graph); - MS_EXCEPTION_IF_NULL(data_input); - MS_EXCEPTION_IF_NULL(bn_node); - MS_EXCEPTION_IF_NULL(fused_bn3_outputs); - if (bn_node->inputs().size() != kBnInputNum) { - MS_LOG(EXCEPTION) << "BN node has wrong input size"; - } - - if (fused_bn1_outputs.size() != kBN1OutputNum) { - MS_LOG(EXCEPTION) << "BN1 outputs has wrong input size"; - } - - if (fused_bn2_outputs.size() != kBN2OutputNum) { - MS_LOG(EXCEPTION) << "BN2 outputs has wrong input size"; - } - - // the inputs of fused_bn3 are from the outputs of fused_bn1 and the inputs of bn - std::vector fused_bn3_inputs = {NewValueNode(std::make_shared(kFusedBN3OpName))}; - fused_bn3_inputs.push_back(data_input); - fused_bn3_inputs.push_back(fused_bn1_outputs[0]); - fused_bn3_inputs.push_back(fused_bn2_outputs[0]); - fused_bn3_inputs.push_back(bn_node->input(2)); - fused_bn3_inputs.push_back(bn_node->input(3)); - auto fused_bn3 = graph->NewCNode(fused_bn3_inputs); - MS_EXCEPTION_IF_NULL(fused_bn3); - auto kernel_info = std::make_shared(); - fused_bn3->set_kernel_info(kernel_info); - auto types = {AnfAlgo::GetOutputInferDataType(bn_node, 0)}; - auto shapes = {AnfAlgo::GetOutputInferShape(bn_node, 0)}; - AnfAlgo::SetOutputInferTypeAndShape(types, shapes, fused_bn3.get()); - - fused_bn3->set_scope(bn_node->scope()); - AnfAlgo::CopyNodeAttr(kAttrEpsilon, kAttrEps, bn_node, fused_bn3); - - (*fused_bn3_outputs).push_back(fused_bn3); -} - void CreateMultipleOutputsOfAnfNode(const FuncGraphPtr &func_graph, const AnfNodePtr &node, size_t output_num, std::vector *outputs) { MS_EXCEPTION_IF_NULL(func_graph); MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(outputs); for (size_t i = 0; i < output_num; i++) { - int temp = SizeToInt(i); + int64_t temp = SizeToLong(i); auto idx = NewValueNode(temp); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(temp); + auto imm = std::make_shared(temp); auto abstract_scalar = std::make_shared(imm); idx->set_abstract(abstract_scalar); auto tuple_getitem = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), node, idx}); @@ -343,7 +225,7 @@ tensor::TensorPtr CreateTensorWithValueTuple(const ValueTuplePtr &value_tuple_pt return nullptr; } } - std::vector tensor_shape = {SizeToInt(values.size())}; + std::vector tensor_shape = {SizeToLong(values.size())}; tensor::TensorPtr tensor = std::make_shared(type_ptr->type_id(), tensor_shape); MS_EXCEPTION_IF_NULL(tensor); tensor::DeviceInfo device_info{kOpFormat_DEFAULT, type_ptr}; @@ -600,9 +482,9 @@ bool IsNotRealUsedByOthers(const FuncGraphPtr &graph, const AnfNodePtr &node) { } AnfNodePtr CreatTupleGetItemNode(const FuncGraphPtr &func_graph, const AnfNodePtr &node, size_t output_idx) { - auto idx = NewValueNode(SizeToInt(output_idx)); + auto idx = NewValueNode(SizeToLong(output_idx)); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(SizeToInt(output_idx)); + auto imm = std::make_shared(SizeToLong(output_idx)); auto abstract_scalar = std::make_shared(imm); idx->set_abstract(abstract_scalar); AnfNodePtr tuple_getitem = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), node, idx}); @@ -848,7 +730,7 @@ bool CompareTupleGetitem(const AnfNodePtr &n1, const AnfNodePtr &n2) { MS_EXCEPTION_IF_NULL(index_input2); auto value_node2 = index_input2->cast(); MS_EXCEPTION_IF_NULL(value_node2); - return GetValue(value_node1->value()) < GetValue(value_node2->value()); + return GetValue(value_node1->value()) < GetValue(value_node2->value()); } bool GetBoolAttr(const AnfNodePtr &node, const std::string &attr_name) { diff --git a/mindspore/ccsrc/backend/optimizer/common/helper.h b/mindspore/ccsrc/backend/optimizer/common/helper.h index bd008f68bdb..d496bb42abc 100644 --- a/mindspore/ccsrc/backend/optimizer/common/helper.h +++ b/mindspore/ccsrc/backend/optimizer/common/helper.h @@ -117,7 +117,9 @@ enum ConvBn1Output { kMean, }; -std::vector Convert2Int(const std::vector &v); +std::vector Convert2Int(const std::vector &v); + +std::vector Convert2Long(const std::vector &v); // check whether node depends on either of nodes or not bool IsDepend(const FuncGraph &graph, const AnfNodePtr &node, const std::vector &nodes); @@ -126,12 +128,8 @@ bool UnVisited(const BaseRef &n); bool Visited(const BaseRef &n); -// check if the input node is CNode, then check it's input_size, if meet condition above, return true, otherwise return -// false. cnode can only be used when return true. -bool CheckIfCNodeAndInputSize(const AnfNodePtr &node, int input_size, CNodePtr *cnode); - // check if the input node is CNode, then check it's input_size, return CNodePtr if check success. -CNodePtr CheckAnfNodeIfCNodeAndInputSize(const AnfNodePtr &node, int input_size); +CNodePtr CheckAnfNodeIfCNodeAndInputSize(const AnfNodePtr &node, size_t input_size); void CheckCNodeInputSize(const CNodePtr &cnode, size_t input_size); diff --git a/mindspore/ccsrc/backend/optimizer/gpu/batch_norm_add_relu_grad_fusion.cc b/mindspore/ccsrc/backend/optimizer/gpu/batch_norm_add_relu_grad_fusion.cc index 7cd5ea1f49d..ae9251c5435 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/batch_norm_add_relu_grad_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/gpu/batch_norm_add_relu_grad_fusion.cc @@ -54,7 +54,7 @@ bool GetBatchNormOutputs(const FuncGraphPtr &func_graph, const AnfNodePtr &bn, s MS_EXCEPTION_IF_NULL(index_node); auto value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + int index = static_cast(GetValue(value_node->value())); if (std::find(kOutputIndex.begin(), kOutputIndex.end(), index) == kOutputIndex.end()) { return false; } diff --git a/mindspore/ccsrc/backend/optimizer/gpu/combine_cast_fusion.cc b/mindspore/ccsrc/backend/optimizer/gpu/combine_cast_fusion.cc index 89ff6e80d0d..1ebc2f8d673 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/combine_cast_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/gpu/combine_cast_fusion.cc @@ -120,8 +120,8 @@ bool CastAllFusion::Run(const FuncGraphPtr &graph) { std::vector tuple_getitem_input; tuple_getitem_input.push_back(NewValueNode(prim::kPrimTupleGetItem)); tuple_getitem_input.push_back(cast_all); - auto index = NewValueNode(SizeToInt(idx)); - auto imm = std::make_shared(idx); + auto index = NewValueNode(SizeToLong(idx)); + auto imm = std::make_shared(idx); auto abstract_scalar = std::make_shared(imm); MS_EXCEPTION_IF_NULL(abstract_scalar); index->set_abstract(abstract_scalar); diff --git a/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc b/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc index ca3858c3172..f79f0531d47 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc +++ b/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.cc @@ -28,7 +28,7 @@ namespace mindspore { namespace opt { namespace { -std::vector TransposeAxis(const std::string &src_format, const std::string &dst_format) { +std::vector TransposeAxis(const std::string &src_format, const std::string &dst_format) { if ((src_format == kOpFormat_NCHW) && (dst_format == kOpFormat_NHWC)) { return {0, 2, 3, 1}; } else if ((src_format == kOpFormat_NHWC) && (dst_format == kOpFormat_NCHW)) { @@ -42,12 +42,12 @@ std::vector TransposeAxis(const std::string &src_format, const std::string // 1. out_shape [x, 1, 1, y] // 2. out_shape [x, y, 1, 1] // 3. out_shape [x, 1, y, 1] -bool IsFakeTranspose(const std::vector &out_shape, const std::vector &transpose_perm) { +bool IsFakeTranspose(const std::vector &out_shape, const std::vector &transpose_perm) { if (out_shape.size() != 4) { MS_LOG(EXCEPTION) << "Invalid data shape, 4-D data was needed, but get " << out_shape.size() << "-D."; } - std::vector perm1 = {0, 2, 3, 1}; - std::vector perm2 = {0, 3, 1, 2}; + std::vector perm1 = {0, 2, 3, 1}; + std::vector perm2 = {0, 3, 1, 2}; auto num = std::count(out_shape.begin(), out_shape.end(), 1); if ((transpose_perm == perm1) || (transpose_perm == perm2)) { if (num >= 2) { @@ -74,7 +74,7 @@ void SetTransposeOpBuildInfo(const std::string &input_format, const std::string // Insert transpose op between node and used_node whose position is used_node_index. CNodePtr InsertTransposeOp(const FuncGraphPtr &graph, const AnfNodePtr &node, const AnfNodePtr &used_node, - int used_node_index, const std::vector &transpose_perm) { + int used_node_index, const std::vector &transpose_perm) { MS_LOG(DEBUG) << "Node: " << node->fullname_with_scope() << ", used node: " << used_node->fullname_with_scope() << ", index: " << used_node_index; MS_EXCEPTION_IF_NULL(graph); @@ -161,7 +161,7 @@ const AnfNodePtr InsertFormatTransformOp::Process(const FuncGraphPtr &graph, con } void InsertFormatTransformOp::ProcessForTupleItem(const FuncGraphPtr &graph, const AnfNodePtr &node, int node_index, - const std::vector &transpose_perm, + const std::vector &transpose_perm, const std::string &transpose_format) const { auto used_node_list = GetRealNodeUsedListByOutputIdx(graph, node, node_index); for (size_t i = 0; i < used_node_list->size(); i++) { diff --git a/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.h b/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.h index 648eda87e20..50e773ee2a5 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.h +++ b/mindspore/ccsrc/backend/optimizer/gpu/insert_format_transform_op.h @@ -32,7 +32,7 @@ class InsertFormatTransformOp : public PatternProcessPass { private: void ProcessForTupleItem(const FuncGraphPtr &graph, const AnfNodePtr &node, int node_index, - const std::vector &transpose_perm, const std::string &transpose_format) const; + const std::vector &transpose_perm, const std::string &transpose_format) const; }; } // namespace opt } // namespace mindspore diff --git a/mindspore/ccsrc/backend/optimizer/gpu/remove_redundant_format_transform.cc b/mindspore/ccsrc/backend/optimizer/gpu/remove_redundant_format_transform.cc index 57873746320..f5b61a93e09 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/remove_redundant_format_transform.cc +++ b/mindspore/ccsrc/backend/optimizer/gpu/remove_redundant_format_transform.cc @@ -48,8 +48,8 @@ const AnfNodePtr RemoveRedundantFormatTransform::Process(const FuncGraphPtr &gra break; } } - auto first_transpose_perm = AnfAlgo::GetNodeAttr>(first_transpose, "perm"); - auto node_perm = AnfAlgo::GetNodeAttr>(node, "perm"); + auto first_transpose_perm = AnfAlgo::GetNodeAttr>(first_transpose, "perm"); + auto node_perm = AnfAlgo::GetNodeAttr>(node, "perm"); if ((first_transpose != node) && (first_transpose_perm == node_perm)) { return first_transpose; } diff --git a/mindspore/ccsrc/backend/optimizer/gpu/replace_addn_fusion.cc b/mindspore/ccsrc/backend/optimizer/gpu/replace_addn_fusion.cc index 87973a8f3cc..bd250bc8f80 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/replace_addn_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/gpu/replace_addn_fusion.cc @@ -40,7 +40,7 @@ const AnfNodePtr ReplaceAddNFusion::Process(const FuncGraphPtr &graph, const Anf auto B = AnfAlgo::GetInputNode(utils::cast(node), 1); MS_EXCEPTION_IF_NULL(A); MS_EXCEPTION_IF_NULL(B); - int num_input = AnfAlgo::GetNodeAttr(node, "n"); + int64_t num_input = AnfAlgo::GetNodeAttr(node, "n"); if (num_input == 2) { auto prim = std::make_shared(prim::kPrimTensorAdd->name()); MS_EXCEPTION_IF_NULL(prim); diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/arithmetic_simplify.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/arithmetic_simplify.cc index 908d33ca6d0..dba2d66ec55 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/arithmetic_simplify.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/arithmetic_simplify.cc @@ -424,9 +424,9 @@ AnfNodePtr SimplifyDiv(const AnfNodePtr &node) { } bool TryTransposeToReshape(const AnfNodePtr &node) { - auto perm = AnfAlgo::GetNodeAttr>(node, "perm"); + auto perm = AnfAlgo::GetNodeAttr>(node, "perm"); auto ori_shape = AnfAlgo::GetPrevNodeOutputInferShape(node, 0); - std::vector remove_one_perm; + std::vector remove_one_perm; for (auto idx : perm) { if (idx < 0 || IntToSize(idx) >= ori_shape.size()) { MS_EXCEPTION(ValueError); @@ -498,23 +498,23 @@ ShapeVector TransAxisValueToVector(const ValuePtr &value) { MS_EXCEPTION_IF_NULL(value); ShapeVector axis_vector; if (value->isa()) { - axis_vector.emplace_back(GetValue(value)); + axis_vector.emplace_back(GetValue(value)); } if (value->isa() || value->isa()) { - axis_vector = GetValue>(value); + axis_vector = GetValue>(value); } return axis_vector; } ShapeVector GetNodeShape(const AnfNodePtr &node) { auto base_shape = node->Shape()->cast(); - std::vector shape; + std::vector shape; std::transform(base_shape->shape().begin(), base_shape->shape().end(), std::back_inserter(shape), IntToSize); return shape; } -std::vector> GetUnmodifiedDim(const ShapeVector &a, const ShapeVector &b) { - std::vector> unmodified; +std::vector> GetUnmodifiedDim(const ShapeVector &a, const ShapeVector &b) { + std::vector> unmodified; for (size_t i = 0, j = 0, patial_a = 1, patial_b = 1;;) { if (i >= a.size() && j >= b.size()) { break; @@ -564,11 +564,12 @@ AnfNodePtr SimplifyReduce(const AnfNodePtr &node) { } else { auto tmp_node = node->cast(); auto transpose_node = tmp_node->input(1); - auto transpose_dimensions = GetValue>(AnfAlgo::GetNodeAttr(transpose_node, "perm")); + auto transpose_dimensions = + GetValue>(AnfAlgo::GetNodeAttr(transpose_node, "perm")); ShapeVector new_dimensions; auto reduce_dimensions = TransAxisValueToVector(AnfAlgo::GetNodeAttr(tmp_node, "axis")); std::transform(reduce_dimensions.begin(), reduce_dimensions.end(), std::back_inserter(new_dimensions), - [&transpose_dimensions](const int &dim) { return transpose_dimensions[dim]; }); + [&transpose_dimensions](const int64_t &dim) { return transpose_dimensions[dim]; }); std::sort(new_dimensions.begin(), new_dimensions.end()); auto new_cnode = NewCNodeWithInfo({NewValueNode(operation), x.GetNode(node)}, node); AnfAlgo::SetNodeAttr("axis", MakeValue(new_dimensions), new_cnode); diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc index 6526bc998d5..78dd56eb9bf 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc @@ -494,7 +494,7 @@ void ReplaceNewFuseCNode(const FuncGraphPtr &func_graph, const AnfNodePtr &new_f fn_inputs.clear(); fn_inputs.push_back(NewValueNode(prim::kPrimTupleGetItem)); fn_inputs.push_back(new_fuse_cnode); - fn_inputs.push_back(NewValueNode(MakeValue(SizeToInt(out_idx)))); + fn_inputs.push_back(NewValueNode(MakeValue(SizeToLong(out_idx)))); auto new_out = func_graph->NewCNode(fn_inputs); new_out->set_abstract(outputs[out_idx]->abstract()); mng->Replace(outputs[out_idx], new_out); @@ -514,7 +514,7 @@ void ReplaceNewFuseCNode(const FuncGraphPtr &func_graph, const AnfNodePtr &new_f auto value_node = value_input->cast(); MS_EXCEPTION_IF_NULL(value_node); int item_idx = GetValue(value_node->value()); - int new_item_idx = SizeToInt(out_idx) + offset + item_idx; + int new_item_idx = SizeToLong(out_idx) + offset + item_idx; fn_inputs.clear(); fn_inputs.push_back(NewValueNode(prim::kPrimTupleGetItem)); fn_inputs.push_back(new_fuse_cnode); diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_splitter.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_splitter.cc index 913314d1614..c6aa2d60d0e 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_splitter.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_splitter.cc @@ -272,7 +272,7 @@ class AreaGraph { size_t input_area = node_area_map_[input_node]; // if the input node is in a tuple, then we need to create a GetItem fot it. if (node_index_in_returned_tuple_.count(input_node) != 0) { - int idx_val = SizeToInt(node_index_in_returned_tuple_[input_node]); + int idx_val = SizeToLong(node_index_in_returned_tuple_[input_node]); auto idx = NewValueNode(idx_val); idx->set_abstract(std::make_shared(idx_val)); AnfNodePtrList getitem_inputs = {NewValueNode(prim::kPrimTupleGetItem), main_cnodes[input_area], idx}; diff --git a/mindspore/ccsrc/backend/optimizer/pass/add_atomic_clean.cc b/mindspore/ccsrc/backend/optimizer/pass/add_atomic_clean.cc index 0c8f04a8718..c3f29cb19ff 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/add_atomic_clean.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/add_atomic_clean.cc @@ -39,9 +39,9 @@ bool HasAtomic(const AnfNodePtr &input) { return false; } -std::vector CalCleanSize(const CNodePtr &pre_node) { +std::vector CalCleanSize(const CNodePtr &pre_node) { MS_EXCEPTION_IF_NULL(pre_node); - std::vector clean_size_list; + std::vector clean_size_list; // clean output for (auto &index : g_output_idx) { TypeId output_type_id = AnfAlgo::GetOutputDeviceDataType(pre_node, index); diff --git a/mindspore/ccsrc/backend/optimizer/pass/communication_op_fusion.cc b/mindspore/ccsrc/backend/optimizer/pass/communication_op_fusion.cc index 9994b972db3..fb2ecf872a3 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/communication_op_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/communication_op_fusion.cc @@ -74,7 +74,7 @@ std::string GetFusionGroupKey(const AnfNodePtr &node) { if (attr_fusion == nullptr) { return ""; } - int fusion = GetValue(attr_fusion); + int64_t fusion = GetValue(attr_fusion); if (fusion == 0) { return ""; } @@ -226,9 +226,9 @@ bool CommunicationOpFusion::DoFusion(const FuncGraphPtr &func_graph, const Commu std::vector tuple_getitem_input; tuple_getitem_input.push_back(NewValueNode(prim::kPrimTupleGetItem)); tuple_getitem_input.push_back(new_communication_op); - auto index = NewValueNode(SizeToInt(idx - start_index)); + auto index = NewValueNode(SizeToLong(idx - start_index)); MS_EXCEPTION_IF_NULL(index); - auto imm = std::make_shared(idx - start_index); + auto imm = std::make_shared(idx - start_index); MS_EXCEPTION_IF_NULL(imm); auto abstract_scalar = std::make_shared(); MS_EXCEPTION_IF_NULL(abstract_scalar); @@ -278,10 +278,11 @@ bool CommunicationOpFusion::Run(const FuncGraphPtr &func_graph) { continue; } auto first_node = it.second.communication_op_nodes[0]; - if (AnfAlgo::HasNodeAttr(kAttrIndex, first_node) && AnfAlgo::GetNodeAttr(first_node, kAttrIndex) > 0) { + if (AnfAlgo::HasNodeAttr(kAttrIndex, first_node) && AnfAlgo::GetNodeAttr(first_node, kAttrIndex) > 0) { std::stable_sort(it.second.communication_op_nodes.begin(), it.second.communication_op_nodes.end(), [](const CNodePtr &a, const CNodePtr &b) { - return AnfAlgo::GetNodeAttr(a, kAttrIndex) < AnfAlgo::GetNodeAttr(b, kAttrIndex); + return AnfAlgo::GetNodeAttr(a, kAttrIndex) < + AnfAlgo::GetNodeAttr(b, kAttrIndex); }); } size_t segment_num = 0; diff --git a/mindspore/ccsrc/backend/optimizer/pass/const_to_attr_strided_slice_grad.cc b/mindspore/ccsrc/backend/optimizer/pass/const_to_attr_strided_slice_grad.cc index b1b25c87ff9..ce6cbe49ff7 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/const_to_attr_strided_slice_grad.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/const_to_attr_strided_slice_grad.cc @@ -66,14 +66,20 @@ bool CheckValues(const ValuePtrList &strides_values) { if (value->isa()) { auto scalar = value->cast(); MS_EXCEPTION_IF_NULL(scalar); - if (!scalar->isa()) { + if (scalar->isa()) { + if (GetValue(scalar) != 1) { + MS_LOG(DEBUG) << "StridedSliceGrad has no 1 value"; + return false; + } + } else if (scalar->isa()) { + if (GetValue(scalar) != 1) { + MS_LOG(DEBUG) << "StridedSliceGrad has no 1 value"; + return false; + } + } else { MS_LOG(DEBUG) << "strides value is not a Integer"; return false; } - if (GetValue(scalar) != 1) { - MS_LOG(DEBUG) << "StridedSliceGrad has no 1 value"; - return false; - } } else { MS_LOG(DEBUG) << "The value " << value << "of tuple is not a scalar"; return false; @@ -89,8 +95,8 @@ bool CheckAttrs(const CNodePtr &strided_slice_grad) { MS_LOG(INFO) << "new_axis_mask or shrink_axis_mask not exist in cnode[" + strided_slice_grad->DebugString() + "]"; return false; } - auto new_axis_mask = AnfAlgo::GetNodeAttr(strided_slice_grad, kAttrNewAxisMask); - auto shrink_axis_mask = AnfAlgo::GetNodeAttr(strided_slice_grad, kAttrShrinkAxisMask); + auto new_axis_mask = AnfAlgo::GetNodeAttr(strided_slice_grad, kAttrNewAxisMask); + auto shrink_axis_mask = AnfAlgo::GetNodeAttr(strided_slice_grad, kAttrShrinkAxisMask); if (new_axis_mask != 0 || shrink_axis_mask != 0) { MS_LOG(INFO) << "new_axis_mask or shrink_axis_mask not equal 0"; return false; diff --git a/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_input_to_dynamic_input.cc b/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_input_to_dynamic_input.cc index 66c77dfec3f..6aeb6711775 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_input_to_dynamic_input.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_input_to_dynamic_input.cc @@ -35,7 +35,7 @@ void ConvertMakeTupleInputToPlantInputs(const FuncGraphPtr &graph, const CNodePt return; } std::vector plant_inputs; - std::vector dyn_input_sizes; + std::vector dyn_input_sizes; plant_inputs.push_back(AnfAlgo::GetCNodePrimitiveNode(cnode_ptr)); for (size_t i = 0; i < AnfAlgo::GetInputTensorNum(cnode_ptr); ++i) { auto input_node = AnfAlgo::GetInputNode(cnode_ptr, i); @@ -64,7 +64,7 @@ void ConvertMakeTupleInputToPlantInputs(const FuncGraphPtr &graph, const CNodePt } } // If there is dynamic input, set the dyn_input_sizes as an attribute and update the inputs. - if (std::any_of(dyn_input_sizes.begin(), dyn_input_sizes.end(), [](int s) { return s >= 0; })) { + if (std::any_of(dyn_input_sizes.begin(), dyn_input_sizes.end(), [](int64_t s) { return s >= 0; })) { AnfAlgo::SetNodeAttr(kAttrDynInputSizes, MakeValue(dyn_input_sizes), cnode_ptr); cnode_ptr->set_inputs(plant_inputs); } diff --git a/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc b/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc index 325acff9f9b..75183f10ab9 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/eliminate_redundant_op.cc @@ -52,9 +52,9 @@ CNodePtr GetRealPrevCNode(const AnfNodePtr &node, size_t index, std::vectorcast(); MS_EXCEPTION_IF_NULL(value_node); - int item_idx = GetValue(value_node->value()); + auto item_idx = GetValue(value_node->value()); pass_vector->push_back(make_pair(cnode, IntToSize(1))); - return GetRealPrevCNode(cnode->input(1), IntToSize(item_idx), pass_vector); + return GetRealPrevCNode(cnode->input(1), LongToSize(item_idx), pass_vector); } else if (IsPrimitive(input0, prim::kPrimDepend) || IsPrimitive(input0, prim::kPrimControlDepend)) { pass_vector->push_back(make_pair(cnode, IntToSize(1))); return GetRealPrevCNode(cnode->input(1), 0, pass_vector); diff --git a/mindspore/ccsrc/backend/optimizer/pass/getitem_tuple.cc b/mindspore/ccsrc/backend/optimizer/pass/getitem_tuple.cc index d565c7d2c5b..2b3e2b7e27e 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/getitem_tuple.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/getitem_tuple.cc @@ -52,14 +52,14 @@ const AnfNodePtr GetitemTuple::Process(const FuncGraphPtr &, const AnfNodePtr &n MS_EXCEPTION_IF_NULL(make_tuple_anf); AnfNodePtr index_node = tuple_getitem->input(kInputNodeOutputIndexInTupleGetItem); MS_EXCEPTION_IF_NULL(index_node); - if (IsValueNode(index_node)) { + if (IsValueNode(index_node)) { ValueNodePtr value_node = index_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - int index = GetValue(value_node->value()); + auto index = GetValue(value_node->value()); CNodePtr make_tuple = make_tuple_anf->cast(); MS_EXCEPTION_IF_NULL(make_tuple); - if (make_tuple->inputs().size() > IntToSize(index + 1)) { - auto ret = make_tuple->input(IntToSize(index + 1)); + if (make_tuple->inputs().size() > LongToSize(index + 1)) { + auto ret = make_tuple->input(LongToSize(index + 1)); MS_EXCEPTION_IF_NULL(ret); return ret; } diff --git a/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc b/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc index eaca523ba0d..027e0882008 100644 --- a/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc +++ b/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc @@ -22,6 +22,7 @@ #include "ir/func_graph.h" #include "base/core_ops.h" #include "utils/utils.h" +#include "utils/shape_utils.h" #include "runtime/device/kernel_info.h" #include "runtime/device/device_address.h" #include "backend/optimizer/common/helper.h" @@ -54,12 +55,13 @@ std::vector TransShapeToSizet(const abstract::ShapePtr &shape) { std::vector shape_size_t; if (IsShapeDynamic(shape)) { if (std::all_of(shape->max_shape().begin(), shape->max_shape().end(), [](int s) { return s >= 0; })) { - std::transform(shape->max_shape().begin(), shape->max_shape().end(), std::back_inserter(shape_size_t), IntToSize); + std::transform(shape->max_shape().begin(), shape->max_shape().end(), std::back_inserter(shape_size_t), + LongToSize); } else { MS_LOG(EXCEPTION) << "Invalid Max Shape"; } } else { - std::transform(shape->shape().begin(), shape->shape().end(), std::back_inserter(shape_size_t), IntToSize); + std::transform(shape->shape().begin(), shape->shape().end(), std::back_inserter(shape_size_t), LongToSize); } return shape_size_t; } @@ -84,7 +86,7 @@ size_t AnfRuntimeAlgorithm::GetTupleGetItemOutIndex(const CNodePtr &tuple_get_it MS_EXCEPTION_IF_NULL(output_index_value_node); auto value_node = output_index_value_node->cast(); MS_EXCEPTION_IF_NULL(value_node); - return IntToSize(GetValue(value_node->value())); + return LongToSize(GetValue(value_node->value())); } KernelWithIndex AnfRuntimeAlgorithm::VisitKernel(const AnfNodePtr &anf_node, size_t index) { @@ -110,8 +112,8 @@ KernelWithIndex AnfRuntimeAlgorithm::VisitKernel(const AnfNodePtr &anf_node, siz MS_EXCEPTION_IF_NULL(input2); auto value_node = input2->cast(); MS_EXCEPTION_IF_NULL(value_node); - int item_idx = GetValue(value_node->value()); - return VisitKernel(cnode->input(kRealInputNodeIndexInTupleGetItem), IntToSize(item_idx)); + auto item_idx = GetValue(value_node->value()); + return VisitKernel(cnode->input(kRealInputNodeIndexInTupleGetItem), LongToSize(item_idx)); } else if (IsPrimitive(input0, prim::kPrimDepend) || IsPrimitive(input0, prim::kPrimControlDepend)) { return VisitKernel(cnode->input(kRealInputIndexInDepend), 0); } else { @@ -791,16 +793,16 @@ void AnfRuntimeAlgorithm::SetOutputInferTypeAndShape(const std::vector & node->set_abstract(std::make_shared()); } else if (shapes.size() == 1) { // single output handle - std::vector shape_int; - std::transform(shapes[0].begin(), shapes[0].end(), std::back_inserter(shape_int), SizeToInt); + ShapeVector shape_int; + std::transform(shapes[0].begin(), shapes[0].end(), std::back_inserter(shape_int), SizeToLong); auto abstract = std::make_shared(TypeIdToType(types[0]), shape_int); node->set_abstract(abstract); } else { // multiple output handle std::vector abstract_list; for (size_t i = 0; i < types.size(); ++i) { - std::vector shape_int; - std::transform(shapes[i].begin(), shapes[i].end(), std::back_inserter(shape_int), SizeToInt); + ShapeVector shape_int; + std::transform(shapes[i].begin(), shapes[i].end(), std::back_inserter(shape_int), SizeToLong); abstract_list.emplace_back(std::make_shared(TypeIdToType(types[i]), shape_int)); } auto abstract_tuple = std::make_shared(abstract_list); @@ -1251,7 +1253,7 @@ bool AnfRuntimeAlgorithm::IsIndependentNode(const CNodePtr &node) { return false; } - uint32_t input_nums = AnfAlgo::GetInputTensorNum(node); + size_t input_nums = AnfAlgo::GetInputTensorNum(node); if (input_nums == 0) { return true; } @@ -1295,8 +1297,8 @@ void AnfRuntimeAlgorithm::GetRealDynamicShape(const std::vector &shape, } } -std::vector GetShapeFromSequeueShape(const abstract::SequeueShapePtr &sequeue_shape_ptr, size_t index, - ShapeType type) { +std::vector GetShapeFromSequeueShape(const abstract::SequeueShapePtr &sequeue_shape_ptr, size_t index, + ShapeType type) { MS_EXCEPTION_IF_NULL(sequeue_shape_ptr); auto shape_list = sequeue_shape_ptr->shape(); if (index >= shape_list.size()) { @@ -1317,17 +1319,17 @@ std::vector GetShapeFromSequeueShape(const abstract::SequeueShapePtr &seque } } -std::vector AnfRuntimeAlgorithm::GetInputMaxShape(const AnfNodePtr &anf_node, size_t index) { +std::vector AnfRuntimeAlgorithm::GetInputMaxShape(const AnfNodePtr &anf_node, size_t index) { auto input_node_with_index = AnfAlgo::GetPrevNodeOutput(anf_node, index); return GetOutputMaxShape(input_node_with_index.first, input_node_with_index.second); } -std::vector AnfRuntimeAlgorithm::GetInputMinShape(const AnfNodePtr &anf_node, size_t index) { +std::vector AnfRuntimeAlgorithm::GetInputMinShape(const AnfNodePtr &anf_node, size_t index) { auto input_node_with_index = AnfAlgo::GetPrevNodeOutput(anf_node, index); return GetOutputMinShape(input_node_with_index.first, input_node_with_index.second); } -std::vector AnfRuntimeAlgorithm::GetOutputMaxShape(const AnfNodePtr &anf_node, size_t index) { +std::vector AnfRuntimeAlgorithm::GetOutputMaxShape(const AnfNodePtr &anf_node, size_t index) { MS_EXCEPTION_IF_NULL(anf_node); auto shape = anf_node->Shape(); MS_EXCEPTION_IF_NULL(shape); @@ -1344,7 +1346,7 @@ std::vector AnfRuntimeAlgorithm::GetOutputMaxShape(const AnfNodePtr &anf_no } } -std::vector AnfRuntimeAlgorithm::GetOutputMinShape(const AnfNodePtr &anf_node, size_t index) { +std::vector AnfRuntimeAlgorithm::GetOutputMinShape(const AnfNodePtr &anf_node, size_t index) { MS_EXCEPTION_IF_NULL(anf_node); auto shape = anf_node->Shape(); MS_EXCEPTION_IF_NULL(shape); diff --git a/mindspore/ccsrc/backend/session/anf_runtime_algorithm.h b/mindspore/ccsrc/backend/session/anf_runtime_algorithm.h index ca3cee62634..81d906f1d1e 100644 --- a/mindspore/ccsrc/backend/session/anf_runtime_algorithm.h +++ b/mindspore/ccsrc/backend/session/anf_runtime_algorithm.h @@ -225,10 +225,10 @@ class AnfRuntimeAlgorithm { static bool IsIndependentNode(const CNodePtr &node); static bool GetBooleanAttr(const AnfNodePtr &node, const std::string &attr); static void GetRealDynamicShape(const std::vector &shape, NotNull *> dynamic_shape); - static std::vector GetInputMaxShape(const AnfNodePtr &anf_node, size_t index); - static std::vector GetInputMinShape(const AnfNodePtr &anf_node, size_t index); - static std::vector GetOutputMaxShape(const AnfNodePtr &anf_node, size_t index); - static std::vector GetOutputMinShape(const AnfNodePtr &anf_node, size_t index); + static std::vector GetInputMaxShape(const AnfNodePtr &anf_node, size_t index); + static std::vector GetInputMinShape(const AnfNodePtr &anf_node, size_t index); + static std::vector GetOutputMaxShape(const AnfNodePtr &anf_node, size_t index); + static std::vector GetOutputMinShape(const AnfNodePtr &anf_node, size_t index); static bool IsNodeDynamicShape(const AnfNodePtr &node); }; } // namespace session diff --git a/mindspore/ccsrc/backend/session/ascend_control_parser.cc b/mindspore/ccsrc/backend/session/ascend_control_parser.cc index fb156ebb63a..bd2ae43052e 100644 --- a/mindspore/ccsrc/backend/session/ascend_control_parser.cc +++ b/mindspore/ccsrc/backend/session/ascend_control_parser.cc @@ -216,7 +216,7 @@ void AscendControlParser::EraseParameter(NotNull root_graph, std::set search_list(exec_order.begin(), exec_order.end()); std::set root_inputs(root_graph->inputs().begin(), root_graph->inputs().end()); auto ref_map = root_graph->GetRefMap(); - ReferenceCounter parameter_count([](int32_t read, int32_t write) -> bool { return write == 1; }); + ReferenceCounter parameter_count([](int64_t read, int64_t write) -> bool { return write == 1; }); std::multimap> ref_multimap; std::transform(ref_map.begin(), ref_map.end(), std::inserter(ref_multimap, ref_multimap.end()), [](const std::pair, std::pair> &p) @@ -831,7 +831,7 @@ bool AscendControlParser::CheckLabelIndex(uint32_t index, uint32_t label_index, } } -void AscendControlParser::ReferenceCounter::AddReadCount(const AnfNodePtr &key, int32_t num) { +void AscendControlParser::ReferenceCounter::AddReadCount(const AnfNodePtr &key, int64_t num) { auto iter = count_.find(key); if (iter != count_.end()) { iter->second.first += num; @@ -840,7 +840,7 @@ void AscendControlParser::ReferenceCounter::AddReadCount(const AnfNodePtr &key, } } -void AscendControlParser::ReferenceCounter::AddWriteCount(const AnfNodePtr &key, int32_t num) { +void AscendControlParser::ReferenceCounter::AddWriteCount(const AnfNodePtr &key, int64_t num) { auto iter = count_.find(key); if (iter != count_.end()) { iter->second.second += num; @@ -860,7 +860,7 @@ bool AscendControlParser::ReferenceCounter::HasValidElem() const { return it != count_.end(); } -std::tuple AscendControlParser::ReferenceCounter::GetOneValidElem() const { +std::tuple AscendControlParser::ReferenceCounter::GetOneValidElem() const { auto it = std::find_if(count_.begin(), count_.end(), [this](const std::pair> &p) -> bool { auto &[read, written] = p.second; diff --git a/mindspore/ccsrc/backend/session/ascend_control_parser.h b/mindspore/ccsrc/backend/session/ascend_control_parser.h index 096c9b44065..ee37a008018 100644 --- a/mindspore/ccsrc/backend/session/ascend_control_parser.h +++ b/mindspore/ccsrc/backend/session/ascend_control_parser.h @@ -82,17 +82,17 @@ class AscendControlParser { }; class AscendControlParser::ReferenceCounter { public: - explicit ReferenceCounter(std::function func) : predicate_(func), count_() {} + explicit ReferenceCounter(std::function func) : predicate_(func), count_() {} ~ReferenceCounter() = default; - void AddReadCount(const AnfNodePtr &key, int32_t num); - void AddWriteCount(const AnfNodePtr &key, int32_t num); + void AddReadCount(const AnfNodePtr &key, int64_t num); + void AddWriteCount(const AnfNodePtr &key, int64_t num); void EraseElem(const AnfNodePtr &key); bool HasValidElem() const; - std::tuple GetOneValidElem() const; + std::tuple GetOneValidElem() const; private: - std::function predicate_; - std::map> count_; + std::function predicate_; + std::map> count_; }; } // namespace session } // namespace mindspore diff --git a/mindspore/ccsrc/backend/session/ascend_inference_session.cc b/mindspore/ccsrc/backend/session/ascend_inference_session.cc index d5c9ec2acee..423825bc028 100644 --- a/mindspore/ccsrc/backend/session/ascend_inference_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_inference_session.cc @@ -147,7 +147,7 @@ bool AscendInferenceSession::CompareInput(const tensor::TensorPtr &input, const auto input_shape = input->shape(); vector trans_input; (void)std::transform(input_shape.begin(), input_shape.end(), std::back_inserter(trans_input), - [](const int dim) { return static_cast(dim); }); + [](const int64_t dim) { return static_cast(dim); }); auto is_scalar_shape = [](const vector &shape) { return shape.empty() || (shape.size() == 1 && shape[0] == 1); }; @@ -227,10 +227,10 @@ void AscendInferenceSession::GetModelInputsInfo(uint32_t graph_id, std::vectorcast(); if (!AnfAlgo::IsParameterWeight(parameter)) { - vector input_shape; + vector input_shape; auto parameter_shape = AnfAlgo::GetOutputDeviceShape(parameter, 0); (void)std::transform(parameter_shape.begin(), parameter_shape.end(), std::back_inserter(input_shape), - [](const size_t dim) { return static_cast(dim); }); + [](const size_t dim) { return SizeToLong(dim); }); auto kernel_build_info = AnfAlgo::GetSelectKernelBuildInfo(parameter); auto data_type = kernel_build_info->GetOutputDeviceType(0); auto ms_tensor = std::make_shared(data_type, input_shape); diff --git a/mindspore/ccsrc/backend/session/ascend_session.cc b/mindspore/ccsrc/backend/session/ascend_session.cc index 237f25360c9..f7e322b3486 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_session.cc @@ -367,7 +367,7 @@ bool AscendSession::GraphCacheExist(const GraphInfo &graph_info) const { void AscendSession::BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, const std::vector &input_tensors, - const std::vector &tensors_mask) { + const std::vector &tensors_mask) { MS_LOG(INFO) << "Build op " << op_run_info.op_name << " start !"; if (GraphCacheExist(graph_info)) { MS_LOG(INFO) << "Build op " << op_run_info.op_name << " graph cache has existed !"; diff --git a/mindspore/ccsrc/backend/session/ascend_session.h b/mindspore/ccsrc/backend/session/ascend_session.h index 72b8213754c..c9b222042a4 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.h +++ b/mindspore/ccsrc/backend/session/ascend_session.h @@ -74,7 +74,8 @@ class AscendSession : public SessionBasic { void RunGraphImpl(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) override; void BuildGraphImpl(GraphId) override; void BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, - const std::vector &input_tensors, const std::vector &tensors_mask) override; + const std::vector &input_tensors, + const std::vector &tensors_mask) override; void RunOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, const std::vector &input_tensors, VectorRef *outputs) override; diff --git a/mindspore/ccsrc/backend/session/executor.cc b/mindspore/ccsrc/backend/session/executor.cc index bcddb8b1225..6752c3a4ec7 100644 --- a/mindspore/ccsrc/backend/session/executor.cc +++ b/mindspore/ccsrc/backend/session/executor.cc @@ -16,8 +16,8 @@ #include "backend/session/executor.h" #include #include -#include "backend/session/executor_manager.h" #include "runtime/device/kernel_runtime_manager.h" +#include "backend/session/executor_manager.h" #include "utils/comm_manager.h" #include "utils/scoped_long_running.h" @@ -312,7 +312,7 @@ void Executor::RunGraphAsync(const SessionPtr &session, const GraphId &graph_id, } void Executor::BuildOp(const SessionPtr &session, OpRunInfo *op_run_info, const GraphInfo &graph_info, - const std::vector &input_tensors, const std::vector &tensors_mask) { + const std::vector &input_tensors, const std::vector &tensors_mask) { auto task = std::make_shared(); task->session_ = session; task->op_run_info_ = op_run_info; diff --git a/mindspore/ccsrc/backend/session/executor.h b/mindspore/ccsrc/backend/session/executor.h index b0c67993dbc..c0261775926 100644 --- a/mindspore/ccsrc/backend/session/executor.h +++ b/mindspore/ccsrc/backend/session/executor.h @@ -106,7 +106,7 @@ class BuildOpTask : public Task { OpRunInfo *op_run_info_{nullptr}; GraphInfo graph_info_; std::vector input_tensors_; - std::vector tensors_mask_; + std::vector tensors_mask_; }; class RunOpTask : public Task { @@ -159,7 +159,7 @@ class Executor { void RunGraphAsync(const SessionPtr &session, const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs); void BuildOp(const SessionPtr &session, OpRunInfo *op_run_info, const GraphInfo &graph_info, - const std::vector &input_tensors, const std::vector &tensors_mask); + const std::vector &input_tensors, const std::vector &tensors_mask); void RunOp(const SessionPtr &session, OpRunInfo *op_run_info, const GraphInfo &graph_info, const std::vector &input_tensors, VectorRef *outputs); void OnRunGraphFinished(); diff --git a/mindspore/ccsrc/backend/session/gpu_session.cc b/mindspore/ccsrc/backend/session/gpu_session.cc index 7ee81a00463..295707a2b38 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.cc +++ b/mindspore/ccsrc/backend/session/gpu_session.cc @@ -361,7 +361,7 @@ void GPUSession::RunGraphImpl(const GraphId &graph_id, const std::vector &input_tensors, - const std::vector &tensors_mask) { + const std::vector &tensors_mask) { // Check if the graph cache exists. if (run_op_graphs_.find(graph_info) != run_op_graphs_.end()) { return; diff --git a/mindspore/ccsrc/backend/session/gpu_session.h b/mindspore/ccsrc/backend/session/gpu_session.h index e4c9b5c8f48..544aa543693 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.h +++ b/mindspore/ccsrc/backend/session/gpu_session.h @@ -37,7 +37,8 @@ class GPUSession : public SessionBasic { GraphId CompileGraphImpl(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override; void RunGraphImpl(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) override; void BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, - const std::vector &input_tensors, const std::vector &tensors_mask) override; + const std::vector &input_tensors, + const std::vector &tensors_mask) override; void RunOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, const std::vector &input_tensors, VectorRef *outputs) override; diff --git a/mindspore/ccsrc/backend/session/infer_session.cc b/mindspore/ccsrc/backend/session/infer_session.cc index 0fece7abaa8..798bdc0a58b 100644 --- a/mindspore/ccsrc/backend/session/infer_session.cc +++ b/mindspore/ccsrc/backend/session/infer_session.cc @@ -124,10 +124,7 @@ Status MSInferSession::LoadModelFromFile(const std::string &file_name, uint32_t Status MSInferSession::UnloadModel(uint32_t model_id) { return SUCCESS; } Status ServingTensor2MSTensor(size_t index, const InferTensorBase &out_tensor, tensor::TensorPtr &ms_tensor) { - std::vector shape; - for (auto dim : out_tensor.shape()) { - shape.push_back(static_cast(dim)); - } + std::vector shape = out_tensor.shape(); TypeId data_type; const std::map type2id_map{ {inference::kMSI_Unknown, TypeId::kNumberTypeBegin}, {inference::kMSI_Bool, TypeId::kNumberTypeBool}, @@ -167,10 +164,7 @@ Status ServingTensor2MSTensor(size_t index, const InferTensorBase &out_tensor, t } void MSTensor2ServingTensor(tensor::TensorPtr ms_tensor, InferTensorBase &out_tensor) { - vector shape; - for (auto dim : ms_tensor->shape()) { - shape.push_back(dim); - } + vector shape = ms_tensor->shape(); out_tensor.set_shape(shape); const std::map id2type_map{ diff --git a/mindspore/ccsrc/backend/session/kernel_graph.cc b/mindspore/ccsrc/backend/session/kernel_graph.cc index 0ed79bffb70..526f15498fc 100644 --- a/mindspore/ccsrc/backend/session/kernel_graph.cc +++ b/mindspore/ccsrc/backend/session/kernel_graph.cc @@ -566,9 +566,9 @@ AnfNodePtr KernelGraph::TransParameterTuple(const AbstractBasePtr &abstract) { } AnfNodePtr KernelGraph::CreatTupleGetItemNode(const AnfNodePtr &node, size_t output_idx) { - auto idx = mindspore::NewValueNode(SizeToInt(output_idx)); + auto idx = mindspore::NewValueNode(SizeToLong(output_idx)); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(SizeToInt(output_idx)); + auto imm = std::make_shared(SizeToLong(output_idx)); auto abstract_scalar = std::make_shared(imm); idx->set_abstract(abstract_scalar); AnfNodePtr tuple_getitem = NewCNode({mindspore::NewValueNode(prim::kPrimTupleGetItem), node, idx}); @@ -788,7 +788,7 @@ void KernelGraph::UpdateControlDependRelations(const std::vector &de std::vector depend_nodes = {depend_node}; int depend_mode = 0; if (AnfAlgo::HasNodeAttr(kControlDependMode, cnode)) { - depend_mode = AnfAlgo::GetNodeAttr(cnode, kControlDependMode); + depend_mode = AnfAlgo::GetNodeAttr(cnode, kControlDependMode); } MS_LOG(DEBUG) << "Prior node[" << prior_node->DebugString() << "], depend node[" << depend_node->DebugString() << "], depend_mode :" << depend_mode << "."; @@ -1112,8 +1112,7 @@ void KernelGraph::ReplaceInternalOutput(const AnfNodePtr &node, const AnfNodePtr return; } // Move specified front node to new node mapping - int index = SizeToInt(src_output_idx); - auto front_node_iter = front_nodes.find(index); + auto front_node_iter = front_nodes.find(src_output_idx); if (front_node_iter == front_nodes.end()) { MS_LOG(INFO) << "The output " << src_output_idx << " of node " << node->DebugString() << " is not an internal node"; return; @@ -1121,7 +1120,7 @@ void KernelGraph::ReplaceInternalOutput(const AnfNodePtr &node, const AnfNodePtr auto front_node_pair = front_node_iter->second; internal_outputs_to_front_map_[new_node][dst_output_idx] = front_node_pair; front_to_internal_outputs_map_[front_node_pair.first] = new_node; - front_nodes.erase(index); + front_nodes.erase(src_output_idx); if (front_nodes.empty()) { internal_outputs_to_front_map_.erase(iter); } diff --git a/mindspore/ccsrc/backend/session/session_basic.cc b/mindspore/ccsrc/backend/session/session_basic.cc index e8645f65316..1048f152469 100644 --- a/mindspore/ccsrc/backend/session/session_basic.cc +++ b/mindspore/ccsrc/backend/session/session_basic.cc @@ -71,7 +71,7 @@ tensor::TensorPtr CreateCNodeOutputTensor(const session::KernelWithIndex &node_o type_id = AnfAlgo::GetOutputInferDataType(node, output_index); } tensor::TensorPtr tensor = nullptr; - std::vector temp_shape; + std::vector temp_shape; if (graph->IsUniqueTargetInternalOutput(node, output_index)) { temp_shape.emplace_back(1); tensor = std::make_shared(type_id, temp_shape); @@ -247,7 +247,7 @@ ValueNodePtr ConstructRunOpValueNode(const std::shared_ptr &graph, } ParameterPtr ConstructRunOpParameter(const std::shared_ptr &graph, const tensor::TensorPtr &input_tensor, - int tensor_mask) { + int64_t tensor_mask) { MS_EXCEPTION_IF_NULL(graph); auto param = graph->NewParameter(); MS_EXCEPTION_IF_NULL(param); @@ -551,12 +551,12 @@ void SessionBasic::GetNewCNodeInputs(const CNodePtr &cnode, KernelGraph *graph, } continue; } else if (optimize_control_depend) { - cnode_inputs->push_back(NewValueNode(MakeValue(SizeToInt(input_idx)))); + cnode_inputs->push_back(NewValueNode(MakeValue(SizeToLong(input_idx)))); } else { // the input node is a cnode from other graph auto parameter_from_cnode = CreateNewParameterFromCNode(anf, graph); if (parameter_from_cnode == nullptr) { - parameter_from_cnode = NewValueNode(MakeValue(SizeToInt(input_idx))); + parameter_from_cnode = NewValueNode(MakeValue(SizeToLong(input_idx))); } cnode_inputs->push_back(parameter_from_cnode); (*other_graph_cnode)[anf] = parameter_from_cnode; @@ -1092,7 +1092,7 @@ void SessionBasic::RunInfer(NotNull func_graph, const std::vector< node->set_abstract(abstract); } else { node->set_abstract( - std::make_shared(kNumberTypeFloat32, std::vector{32, 64, 218, 218})->ToAbstract()); + std::make_shared(kNumberTypeFloat32, std::vector{32, 64, 218, 218})->ToAbstract()); } } else if (node->isa()) { if (tensor_index > inputs.size()) { @@ -1159,7 +1159,7 @@ void SessionBasic::Summary(KernelGraph *graph) { auto address = AnfAlgo::GetOutputAddr(node, index); auto shape = AnfAlgo::GetOutputInferShape(node, index); TypeId type_id = AnfAlgo::GetOutputInferDataType(node, index); - std::vector temp_shape; + std::vector temp_shape; (void)std::copy(shape.begin(), shape.end(), std::back_inserter(temp_shape)); tensor::TensorPtr tensor = std::make_shared(type_id, temp_shape); MS_EXCEPTION_IF_NULL(address); @@ -1299,9 +1299,9 @@ void SessionBasic::CreateOutputNode(const CNodePtr &cnode, const std::shared_ptr MS_EXCEPTION_IF_NULL(graph); if (AnfRuntimeAlgorithm::GetOutputTensorNum(cnode) > 1) { for (size_t output_index = 0; output_index < AnfRuntimeAlgorithm::GetOutputTensorNum(cnode); output_index++) { - auto idx = NewValueNode(SizeToInt(output_index)); + auto idx = NewValueNode(SizeToLong(output_index)); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(output_index); + auto imm = std::make_shared(output_index); idx->set_abstract(std::make_shared(imm)); auto getitem = graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), cnode, idx}); std::vector types = {AnfAlgo::GetOutputInferDataType(cnode, output_index)}; @@ -1320,7 +1320,7 @@ void SessionBasic::CreateOutputNode(const CNodePtr &cnode, const std::shared_ptr std::shared_ptr SessionBasic::ConstructSingleOpGraph(const OpRunInfo &op_run_info, const std::vector &input_tensors, - const std::vector &tensors_mask) { + const std::vector &tensors_mask) { auto graph = std::make_shared(); graph->set_graph_id(run_op_graph_id_); run_op_graph_id_++; @@ -1404,7 +1404,8 @@ void SessionBasic::BuildGraph(GraphId graph_id) { } void SessionBasic::BuildOp(OpRunInfo *op_run_info, const GraphInfo &graph_info, - const std::vector &input_tensors, const std::vector &tensors_mask) { + const std::vector &input_tensors, + const std::vector &tensors_mask) { MS_EXCEPTION_IF_NULL(executor_); executor_->BuildOp(shared_from_this(), op_run_info, graph_info, input_tensors, tensors_mask); } diff --git a/mindspore/ccsrc/backend/session/session_basic.h b/mindspore/ccsrc/backend/session/session_basic.h index 14b795e6e42..3f0c2d80b12 100644 --- a/mindspore/ccsrc/backend/session/session_basic.h +++ b/mindspore/ccsrc/backend/session/session_basic.h @@ -74,7 +74,7 @@ class SessionBasic : public std::enable_shared_from_this { void RunGraph(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs); void RunGraphAsync(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs); void BuildOp(OpRunInfo *, const GraphInfo &, const std::vector &input_tensors, - const std::vector &tensors_mask); + const std::vector &tensors_mask); void RunOp(OpRunInfo *, const GraphInfo &, const std::vector &input_tensors, VectorRef *outputs); virtual void RegisterSummaryCallBackFunc(const CallBackFunc &callback); @@ -142,7 +142,8 @@ class SessionBasic : public std::enable_shared_from_this { virtual void RunGraphImpl(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) = 0; virtual void BuildOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, - const std::vector &input_tensors, const std::vector &tensors_mask) {} + const std::vector &input_tensors, + const std::vector &tensors_mask) {} virtual void RunOpImpl(const OpRunInfo &op_run_info, const GraphInfo &graph_info, const std::vector &input_tensors, VectorRef *outputs) {} void RunInfer(NotNull func_graph, const std::vector &inputs); @@ -163,7 +164,7 @@ class SessionBasic : public std::enable_shared_from_this { // create a single run op graph std::shared_ptr ConstructSingleOpGraph(const OpRunInfo &op_run_info, const std::vector &input_tensors, - const std::vector &tensors_mask); + const std::vector &tensors_mask); // create a new kernel graph and update the graph sum KernelGraphPtr NewKernelGraph(); std::vector CreateParameterFromTuple(const AnfNodePtr &node, KernelGraph *graph); diff --git a/mindspore/ccsrc/common/trans.cc b/mindspore/ccsrc/common/trans.cc index 5e739611d7f..be2772ae1a9 100644 --- a/mindspore/ccsrc/common/trans.cc +++ b/mindspore/ccsrc/common/trans.cc @@ -71,6 +71,7 @@ enum DataTypeTransMode { FROM_INT32_TO_FLOAT16, FROM_INT32_TO_UINT8, FROM_INT32_TO_INT8, + FROM_INT32_TO_INT64, FROM_INT32_TO_BOOL, FROM_UINT8_TO_FLOAT, FROM_UINT8_TO_INT32, @@ -100,6 +101,7 @@ const std::map, DataTypeTransMode> mode_map{ {std::pair(kNumberTypeInt32, kNumberTypeFloat16), FROM_INT32_TO_FLOAT16}, {std::pair(kNumberTypeInt32, kNumberTypeUInt8), FROM_INT32_TO_UINT8}, {std::pair(kNumberTypeInt32, kNumberTypeInt8), FROM_INT32_TO_INT8}, + {std::pair(kNumberTypeInt32, kNumberTypeInt64), FROM_INT32_TO_INT64}, {std::pair(kNumberTypeInt32, kNumberTypeBool), FROM_INT32_TO_BOOL}, {std::pair(kNumberTypeUInt8, kNumberTypeFloat32), FROM_UINT8_TO_FLOAT}, {std::pair(kNumberTypeUInt8, kNumberTypeInt32), FROM_UINT8_TO_INT32}, @@ -154,6 +156,7 @@ bool CastKernel(const TypeIdArgs &args, void *dst, const size_t data_size, const {FROM_FLOAT16_TO_UINT8, TransDataSrc2Dst}, {FROM_INT32_TO_FLOAT, TransDataSrc2Dst}, {FROM_INT32_TO_INT8, TransDataSrc2Dst}, + {FROM_INT32_TO_INT64, TransDataSrc2Dst}, {FROM_INT32_TO_UINT8, TransDataSrc2Dst}, {FROM_INT32_TO_BOOL, TransDataSrc2Dst}, {FROM_INT32_TO_FLOAT16, TransDataSrc2Fp16}, @@ -385,7 +388,7 @@ ShapeVector GetRuntimePaddingShape(const AnfNodePtr &node, size_t index) { MS_LOG(EXCEPTION) << " The node[ " << node->DebugString() << "]'s cannot convert "; } auto shape_temp = tensor->shape(); - (void)std::transform(shape_temp.begin(), shape_temp.end(), std::back_inserter(host_shape), IntToSize); + (void)std::transform(shape_temp.begin(), shape_temp.end(), std::back_inserter(host_shape), LongToSize); if (host_shape.empty()) { host_shape.push_back(1); } @@ -395,7 +398,7 @@ ShapeVector GetRuntimePaddingShape(const AnfNodePtr &node, size_t index) { if (trans::IsNeedPadding(AnfAlgo::GetOutputFormat(node, index), host_shape.size())) { host_shape = trans::PaddingShapeTo4d(host_shape, AnfAlgo::GetOutputReshapeType(node, index)); } - std::transform(host_shape.begin(), host_shape.end(), std::back_inserter(shape), SizeToInt); + std::transform(host_shape.begin(), host_shape.end(), std::back_inserter(shape), SizeToLong); return shape; } diff --git a/mindspore/ccsrc/debug/anf_ir_utils.cc b/mindspore/ccsrc/debug/anf_ir_utils.cc index f39b933f5ab..d2f451b7737 100644 --- a/mindspore/ccsrc/debug/anf_ir_utils.cc +++ b/mindspore/ccsrc/debug/anf_ir_utils.cc @@ -33,6 +33,7 @@ #include "utils/ordered_map.h" #include "utils/ordered_set.h" #include "utils/utils.h" +#include "utils/shape_utils.h" #include "debug/trace.h" #include "utils/label.h" #include "utils/ms_context.h" @@ -1310,7 +1311,7 @@ class IrParser { *ptr = std::make_shared(elems); } - void SetArrayType(TypePtr *const ptr, const TypePtr &elem_type, const std::vector &) { + void SetArrayType(TypePtr *const ptr, const TypePtr &elem_type, const ShapeVector &) { if (ptr == nullptr) { return; } @@ -1367,7 +1368,7 @@ class IrParser { *ptr = std::make_shared(elems); } - void SetArrayType(AbstractBasePtr *const ptr, const TypePtr &elem_type, const std::vector &shape) { + void SetArrayType(AbstractBasePtr *const ptr, const TypePtr &elem_type, const ShapeVector &shape) { if (ptr == nullptr) { return; } @@ -1449,7 +1450,7 @@ class IrParser { } // process Array element type TypePtr elem_type = nullptr; - std::vector shape; + ShapeVector shape; tok = ParseOneType(func_graph, lexer_.GetNextToken(), &elem_type); if (tok != TOK_RPARENTHESIS) { return TOK_ERROR; @@ -1794,7 +1795,7 @@ class IrParser { } // parse shape - std::vector shape; + ShapeVector shape; Token tok = lexer_.GetNextToken(); if (tok != TOK_LBRACKET) { return TOK_ERROR; diff --git a/mindspore/ccsrc/debug/debug_services.cc b/mindspore/ccsrc/debug/debug_services.cc index 313bff17bc0..22078f9813d 100644 --- a/mindspore/ccsrc/debug/debug_services.cc +++ b/mindspore/ccsrc/debug/debug_services.cc @@ -383,7 +383,7 @@ void DebugServices::CheckWatchpoints(std::vector *name, std::vector void DebugServices::ReadNodesTensors(std::vector name, std::vector *ret_name, std::vector *data_ptr, std::vector *data_size, - std::vector *dtype, std::vector> *shape) { + std::vector *dtype, std::vector> *shape) { std::vector>> result_list; tensor_loader_->SearchTensors(name, &result_list); diff --git a/mindspore/ccsrc/debug/debug_services.h b/mindspore/ccsrc/debug/debug_services.h index 02510e2c399..2f414551284 100644 --- a/mindspore/ccsrc/debug/debug_services.h +++ b/mindspore/ccsrc/debug/debug_services.h @@ -181,7 +181,7 @@ class DebugServices { void ReadNodesTensors(std::vector name, std::vector *ret_name, std::vector *data_ptr, std::vector *data_size, - std::vector *dtype, std::vector> *shape); + std::vector *dtype, std::vector> *shape); bool IsWatchPoint(std::string kernel_name, const CNodePtr &kernel = nullptr); diff --git a/mindspore/ccsrc/debug/debugger/debugger.cc b/mindspore/ccsrc/debug/debugger/debugger.cc index 09094f6caf6..4ac26b17ccb 100644 --- a/mindspore/ccsrc/debug/debugger/debugger.cc +++ b/mindspore/ccsrc/debug/debugger/debugger.cc @@ -598,7 +598,7 @@ std::list Debugger::LoadTensors(const ProtoVector &ten std::vector data_ptr; std::vector data_size; std::vector dtype; - std::vector> shape; + std::vector> shape; std::transform(tensors.begin(), tensors.end(), std::back_inserter(name), GetTensorFullName); diff --git a/mindspore/ccsrc/debug/tensor_load.h b/mindspore/ccsrc/debug/tensor_load.h index e8839eda790..ff1289751a6 100644 --- a/mindspore/ccsrc/debug/tensor_load.h +++ b/mindspore/ccsrc/debug/tensor_load.h @@ -99,7 +99,7 @@ class TensorLoader { void set_iter_num(uint32_t iter_num) { this->iter_num = iter_num; } bool DumpTensorToFile(std::string tensor_name, bool trans_flag, const std::string &filepath, - const std::string &host_fmt, const std::vector &host_shape, TypeId host_type, + const std::string &host_fmt, const std::vector &host_shape, TypeId host_type, TypeId addr_type_id, std::string addr_format, size_t slot) const { if (filepath.empty()) { MS_LOG(ERROR) << "Dump file path is null!"; diff --git a/mindspore/ccsrc/frontend/operator/cc_implementations.cc b/mindspore/ccsrc/frontend/operator/cc_implementations.cc index 0c8783b0772..7f576c91bb8 100644 --- a/mindspore/ccsrc/frontend/operator/cc_implementations.cc +++ b/mindspore/ccsrc/frontend/operator/cc_implementations.cc @@ -26,7 +26,7 @@ namespace mindspore { // namespace to support primitive operators definition namespace prim { -enum class DataType { kInt, kFloat, kDouble, kUnknown }; +enum class DataType { kInt, kInt64, kFloat, kDouble, kUnknown }; // Whether has a T type data in AnyPtrList. template @@ -40,6 +40,8 @@ DataType InferType(const AnyPtrList &list) { return DataType::kDouble; } else if (HasType(list)) { return DataType::kFloat; + } else if (HasType(list)) { + return DataType::kInt64; } else if (HasType(list)) { return DataType::kInt; } @@ -116,7 +118,7 @@ template T InnerScalarFloordiv(T x, T y) { auto ret = std::floor(InnerScalarDiv(x, y)); if (std::is_integral::value) { - return static_cast(ret); + return static_cast(ret); } return ret; } @@ -131,7 +133,7 @@ T InnerScalarMod(T x, T y) { << ", y: " << std::to_string(y) << "."; } if (std::is_integral::value) { - return static_cast(x) % static_cast(y); + return static_cast(x) % static_cast(y); } return x - y * std::floor(x / y); } @@ -173,39 +175,59 @@ bool InnerScalarGe(T x, U y) { return x >= y; } -#define SCALAR_OP(op_t) \ - ValuePtr Scalar##op_t(const ValuePtrList &list) { \ - do { \ - if (list.size() < 2) { \ - MS_LOG(EXCEPTION) << "length of input list for Scalar" << #op_t << " is less than 2."; \ - } \ - ValuePtr x = list[0]; \ - ValuePtr y = list[1]; \ - MS_EXCEPTION_IF_NULL(x); \ - MS_EXCEPTION_IF_NULL(y); \ - if (x->isa() && y->isa()) { \ - double sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - float sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - int sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - float sum = InnerScalar##op_t(IntToFloat(GetValue(x)), GetValue(y)); \ - return MakeValue(sum); \ - } \ - if (x->isa() && y->isa()) { \ - float sum = InnerScalar##op_t(GetValue(x), IntToFloat(GetValue(y))); \ - return MakeValue(sum); \ - } \ - MS_LOG(EXCEPTION) << "Unsupported Value for Scalar" << #op_t << ", x: " << x->ToString() \ - << ", y: " << y->ToString(); \ - } while (0); \ +#define SCALAR_OP(op_t) \ + ValuePtr Scalar##op_t(const ValuePtrList &list) { \ + do { \ + if (list.size() < 2) { \ + MS_LOG(EXCEPTION) << "length of input list for Scalar" << #op_t << " is less than 2."; \ + } \ + ValuePtr x = list[0]; \ + ValuePtr y = list[1]; \ + MS_EXCEPTION_IF_NULL(x); \ + MS_EXCEPTION_IF_NULL(y); \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + float sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + int sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + float sum = InnerScalar##op_t(IntToFloat(GetValue(x)), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + float sum = InnerScalar##op_t(GetValue(x), IntToFloat(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + int64_t sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(LongToDouble(GetValue(x)), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(LongToDouble(GetValue(x)), FloatToDouble(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(FloatToDouble(GetValue(x)), LongToDouble(GetValue(y))); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + double sum = InnerScalar##op_t(GetValue(x), LongToDouble(GetValue(y))); \ + return MakeValue(sum); \ + } \ + MS_LOG(EXCEPTION) << "Unsupported Value for Scalar" << #op_t << ", x: " << x->ToString() \ + << ", y: " << y->ToString(); \ + } while (0); \ } SCALAR_OP(Add) @@ -249,14 +271,38 @@ SCALAR_OP(Floordiv) bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ return MakeValue(sum); \ } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ if (x->isa() && y->isa()) { \ bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ return MakeValue(sum); \ } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ if (x->isa() && y->isa()) { \ bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ return MakeValue(sum); \ } \ + if (x->isa() && y->isa()) { \ + bool sum = InnerScalar##op_t(GetValue(x), GetValue(y)); \ + return MakeValue(sum); \ + } \ MS_LOG(EXCEPTION) << "Unsupported Value for Scalar" << #op_t << ", x: " << x->ToString() \ << ", y: " << y->ToString() << "."; \ } @@ -285,7 +331,11 @@ ValuePtr ScalarUSub(const ValuePtrList &list) { MS_EXCEPTION_IF_NULL(x); if (x->isa()) { - int32_t sum = -1 * GetValue(x); + int32_t sum = -1 * GetValue(x); + return MakeValue(sum); + } + if (x->isa()) { + int64_t sum = -1 * GetValue(x); return MakeValue(sum); } if (x->isa()) { diff --git a/mindspore/ccsrc/frontend/operator/composite/composite.cc b/mindspore/ccsrc/frontend/operator/composite/composite.cc index e89a24bea1e..832bbf1b4dd 100644 --- a/mindspore/ccsrc/frontend/operator/composite/composite.cc +++ b/mindspore/ccsrc/frontend/operator/composite/composite.cc @@ -172,7 +172,7 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr &type, const FuncGraph std::vector inputs; inputs.push_back(NewValueNode(prim::kPrimMakeList)); - for (int i = 0; i < SizeToInt(size); ++i) { + for (int64_t i = 0; i < SizeToLong(size); ++i) { std::vector inputs2; inputs2.push_back(fn_rec); if (fn_arg != nullptr) { @@ -211,7 +211,7 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr &type, const FuncGrap std::vector inputs; inputs.push_back(NewValueNode(prim::kPrimMakeTuple)); - for (int i = 0; i < SizeToInt(size); ++i) { + for (int64_t i = 0; i < SizeToLong(size); ++i) { std::vector inputs2; inputs2.push_back(fn_rec); if (fn_arg != nullptr) { @@ -248,7 +248,7 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr &type, const FuncGrap inputs2.push_back(fn_arg); } - int j = 0; + int64_t j = 0; for (auto item : arg_map) { inputs2.push_back(func_graph->NewCNode({NewValueNode(prim::kPrimGetAttr), item.first, NewValueNode(j)})); j++; @@ -284,7 +284,7 @@ AnfNodePtr HyperMap::Make(const FuncGraphPtr &func_graph, const AnfNodePtr &fn_a std::ostringstream oss; oss << "There are " << arg_map.size() << " inputs of `" << name_ << "`, corresponding type info:\n" << trace::GetDebugInfo(func_graph->debug_info()) << "\n"; - int idx = 0; + int64_t idx = 0; for (auto &item : arg_map) { oss << ++idx << ": " << item.second->ToString() << "\n"; } @@ -395,8 +395,8 @@ FuncGraphPtr Tail::GenerateTupleFuncGraph(const abstract::AbstractTuplePtr &a_tu std::vector elems; elems.push_back(NewValueNode(prim::kPrimMakeTuple)); - int tuple_size = SizeToInt(a_tuple->size()); - for (int i = 1; i < tuple_size; ++i) { + int64_t tuple_size = SizeToLong(a_tuple->size()); + for (int64_t i = 1; i < tuple_size; ++i) { elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimTupleGetItem), ptrTup, NewValueNode(i)})); } @@ -415,8 +415,8 @@ FuncGraphPtr Tail::GenerateListFuncGraph(const abstract::AbstractListPtr &a_list std::vector elems; elems.push_back(NewValueNode(prim::kPrimMakeList)); - int list_size = SizeToInt(a_list->size()); - for (int i = 1; i < list_size; ++i) { + int64_t list_size = SizeToLong(a_list->size()); + for (int64_t i = 1; i < list_size; ++i) { elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimListGetItem), ptrList, NewValueNode(i)})); } @@ -449,7 +449,7 @@ REGISTER_PYBIND_DEFINE( })); FuncGraphPtr MakeTupleGradient::GenerateFuncGraph(const AbstractBasePtrList &args_spec_list) { - int tuple_size = SizeToInt(args_spec_list.size()); + int64_t tuple_size = SizeToLong(args_spec_list.size()); std::ostringstream ss; ss << "â–¶make_tuple_" << tuple_size; @@ -458,7 +458,7 @@ FuncGraphPtr MakeTupleGradient::GenerateFuncGraph(const AbstractBasePtrList &arg std::vector params; params.push_back(NewValueNode(prim::kPrimMakeTuple)); - for (int i = 0; i < tuple_size; ++i) { + for (int64_t i = 0; i < tuple_size; ++i) { params.push_back(fg->add_parameter()); } @@ -476,7 +476,7 @@ FuncGraphPtr MakeTupleGradient::GenerateFuncGraph(const AbstractBasePtrList &arg std::vector grads; grads.push_back(NewValueNode(prim::kPrimMakeTuple)); grads.push_back(NewValueNode(newenv)); - for (int i = 0; i < tuple_size; ++i) { + for (int64_t i = 0; i < tuple_size; ++i) { grads.push_back(b->NewCNode({NewValueNode(prim::kPrimTupleGetItem), dout, NewValueNode(i)})); } @@ -490,7 +490,7 @@ FuncGraphPtr MakeTupleGradient::GenerateFuncGraph(const AbstractBasePtrList &arg } FuncGraphPtr MakeListGradient::GenerateFuncGraph(const AbstractBasePtrList &args_spec_list) { - int list_size = SizeToInt(args_spec_list.size()); + int64_t list_size = SizeToLong(args_spec_list.size()); std::ostringstream ss; ss << "â–¶make_list_" << list_size; @@ -499,7 +499,7 @@ FuncGraphPtr MakeListGradient::GenerateFuncGraph(const AbstractBasePtrList &args std::vector params; params.push_back(NewValueNode(prim::kPrimMakeList)); - for (int i = 0; i < list_size; ++i) { + for (int64_t i = 0; i < list_size; ++i) { params.push_back(fg->add_parameter()); } @@ -517,7 +517,7 @@ FuncGraphPtr MakeListGradient::GenerateFuncGraph(const AbstractBasePtrList &args std::vector grads; grads.push_back(NewValueNode(prim::kPrimMakeTuple)); grads.push_back(NewValueNode(newenv)); - for (int i = 0; i < list_size; ++i) { + for (int64_t i = 0; i < list_size; ++i) { grads.push_back(b->NewCNode({NewValueNode(prim::kPrimListGetItem), dout, NewValueNode(i)})); } @@ -574,13 +574,13 @@ FuncGraphPtr GradOperation::GetGrad(AnfNodePtr node, const AnfNodePtr &weights, inputs.clear(); inputs.push_back(opsTupleItem); inputs.push_back(cnode); - inputs.push_back(NewValueNode(0)); + inputs.push_back(NewValueNode(static_cast(0))); auto out = ret->NewCNode(inputs); inputs.clear(); inputs.push_back(opsTupleItem); inputs.push_back(cnode); - inputs.push_back(NewValueNode(1)); + inputs.push_back(NewValueNode(static_cast(1))); AnfNodePtr ptr_bprop = ret->NewCNode(inputs); doGetGrad(ret, out, ptr_bprop, weights_node, opsTupleItem); @@ -604,7 +604,8 @@ void GradOperation::doGetGrad(const FuncGraphPtr &func_graph, AnfNodePtr out, An CNodePtr fv_bprop = nullptr; if (get_by_list_) { // python code: grads = hyper_map(F.partial(env_get, env), weights) - AnfNodePtr env = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), ptr_bapp, NewValueNode(0)}); + AnfNodePtr env = + func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), ptr_bapp, NewValueNode(static_cast(0))}); AnfNodePtr partial_env_get = func_graph->NewCNode({NewValueNode(prim::kPrimPartial), NewValueNode(prim::GetPythonOps("env_get")), env}); MetaFuncGraphPtr hyper_map = std::make_shared(); @@ -636,7 +637,7 @@ void GradOperation::doGetGrad(const FuncGraphPtr &func_graph, AnfNodePtr out, An // Gradients wrt first input. // ptr_bapp returns (EnvInstance(grads wrt params), grads wrt input0, grads wrt input1, ...), so 1 is for first input - func_graph->set_output(func_graph->NewCNode({opsTupleItem, ptr_bapp, NewValueNode(1)})); + func_graph->set_output(func_graph->NewCNode({opsTupleItem, ptr_bapp, NewValueNode(static_cast(1))})); } // Generate the graph. @@ -736,7 +737,7 @@ FuncGraphPtr ListMap::GenerateFuncGraph(const AbstractBasePtrList &args_spec_lis }); (void)std::transform(nexts.begin(), nexts.end(), std::back_inserter(iters), [fg_ptr](AnfNodePtr item) { - return fg_ptr->NewCNode({NewValueNode(prim::kPrimTupleGetItem), item, NewValueNode(1)}); + return fg_ptr->NewCNode({NewValueNode(prim::kPrimTupleGetItem), item, NewValueNode(static_cast(1))}); }); (void)values.insert(values.begin(), fn); @@ -820,7 +821,7 @@ void ListMap::MakeNext(const std::vector &lists, const FuncGraphPtr iters.clear(); (void)std::transform(nexts.begin(), nexts.end(), std::back_inserter(iters), [fg_ptr](AnfNodePtr item) { - return fg_ptr->NewCNode({NewValueNode(prim::kPrimTupleGetItem), item, NewValueNode(1)}); + return fg_ptr->NewCNode({NewValueNode(prim::kPrimTupleGetItem), item, NewValueNode(static_cast(1))}); }); (void)values.insert(values.begin(), fn); @@ -867,13 +868,13 @@ FuncGraphPtr TupleAdd::GenerateFuncGraph(const AbstractBasePtrList &args_spec_li std::vector elems; elems.push_back(NewValueNode(prim::kPrimMakeTuple)); - int tuple_size = SizeToInt(a_tuple->size()); - for (int i = 0; i < tuple_size; ++i) { + int64_t tuple_size = SizeToLong(a_tuple->size()); + for (int64_t i = 0; i < tuple_size; ++i) { elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimTupleGetItem), p_tup_a, NewValueNode(i)})); } - tuple_size = SizeToInt(b_tuple->size()); - for (int i = 0; i < tuple_size; ++i) { + tuple_size = SizeToLong(b_tuple->size()); + for (int64_t i = 0; i < tuple_size; ++i) { elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimTupleGetItem), p_tup_b, NewValueNode(i)})); } @@ -881,21 +882,21 @@ FuncGraphPtr TupleAdd::GenerateFuncGraph(const AbstractBasePtrList &args_spec_li return ret; } -int GetArgScalarValue(const abstract::AbstractScalarPtr &scalar, const std::string &) { +int64_t GetArgScalarValue(const abstract::AbstractScalarPtr &scalar, const std::string &) { MS_EXCEPTION_IF_NULL(scalar); - return GetValue(scalar->BuildValue()); + return GetValue(scalar->BuildValue()); } -bool CheckIndexInRange(int index, int min, int max) { return (index >= min && index <= max); } +bool CheckIndexInRange(int64_t index, int64_t min, int64_t max) { return (index >= min && index <= max); } -int GetPositiveIndex(int index, int length) { +int64_t GetPositiveIndex(int64_t index, int64_t length) { if (index < 0) { index += length; } return index; } -int CheckSliceMember(const AbstractBasePtr &member, int default_value, const std::string &member_name) { +int64_t CheckSliceMember(const AbstractBasePtr &member, int64_t default_value, const std::string &member_name) { MS_EXCEPTION_IF_NULL(member); if (member->isa()) { @@ -909,8 +910,8 @@ int CheckSliceMember(const AbstractBasePtr &member, int default_value, const std MS_LOG(EXCEPTION) << member_name << " should be a AbstractScalar or AbstractNone, but got " << member->ToString(); } -void GenerateTupleSliceParameter(const AbstractTuplePtr &tuple, const AbstractSlicePtr &slice, int *start_index, - int *stop_index, int *step_value) { +void GenerateTupleSliceParameter(const AbstractTuplePtr &tuple, const AbstractSlicePtr &slice, int64_t *start_index, + int64_t *stop_index, int64_t *step_value) { MS_EXCEPTION_IF_NULL(tuple); MS_EXCEPTION_IF_NULL(slice); MS_EXCEPTION_IF_NULL(start_index); @@ -921,10 +922,10 @@ void GenerateTupleSliceParameter(const AbstractTuplePtr &tuple, const AbstractSl const std::string stop_name("Slice stop index"); const std::string step_name("Slice step value"); - int tuple_size = SizeToInt(tuple->size()); - int start_default = 0; - int stop_default = tuple_size; - int step_default = 1; + int64_t tuple_size = SizeToLong(tuple->size()); + int64_t start_default = 0; + int64_t stop_default = tuple_size; + int64_t step_default = 1; *step_value = CheckSliceMember(slice->step(), step_default, step_name); if (*step_value == 0) { @@ -958,9 +959,9 @@ FuncGraphPtr TupleSlice::GenerateFuncGraph(const AbstractBasePtrList &args_spec_ AbstractTuplePtr tuple = abstract::CheckArg(op_name, args_spec_list, 0); AbstractSlicePtr slice = abstract::CheckArg(op_name, args_spec_list, 1); - int start_index; - int stop_index; - int step_value; + int64_t start_index; + int64_t stop_index; + int64_t step_value; GenerateTupleSliceParameter(tuple, slice, &start_index, &stop_index, &step_value); FuncGraphPtr ret = std::make_shared(); @@ -971,11 +972,11 @@ FuncGraphPtr TupleSlice::GenerateFuncGraph(const AbstractBasePtrList &args_spec_ std::vector elems; elems.push_back(NewValueNode(prim::kPrimMakeTuple)); if (step_value > 0) { - for (int index = start_index; index < stop_index; index = index + step_value) { + for (int64_t index = start_index; index < stop_index; index = index + step_value) { elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimTupleGetItem), p_tuple, NewValueNode(index)})); } } else { - for (int index = start_index; index > stop_index; index = index + step_value) { + for (int64_t index = start_index; index > stop_index; index = index + step_value) { elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimTupleGetItem), p_tuple, NewValueNode(index)})); } } diff --git a/mindspore/ccsrc/frontend/operator/composite/do_signature.cc b/mindspore/ccsrc/frontend/operator/composite/do_signature.cc index 5e2dd2cac57..22a2ad7b9c6 100644 --- a/mindspore/ccsrc/frontend/operator/composite/do_signature.cc +++ b/mindspore/ccsrc/frontend/operator/composite/do_signature.cc @@ -203,8 +203,8 @@ void DoAutoCast(const std::string &func_name, const std::vector &sign std::vector dtypes; (void)std::transform(signature.begin(), signature.end(), std::back_inserter(dtypes), [](const Signature &sig) { return sig.dtype; }); - int empty_dtype_count = std::count(dtypes.begin(), dtypes.end(), SignatureEnumDType::kDTypeEmptyDefaultValue); - if (dtypes.empty() || static_cast(dtypes.size()) == empty_dtype_count) { + int64_t empty_dtype_count = std::count(dtypes.begin(), dtypes.end(), SignatureEnumDType::kDTypeEmptyDefaultValue); + if (dtypes.empty() || static_cast(dtypes.size()) == empty_dtype_count) { return; } // Stat the index of the arguments with the largest type in the same SignatureEnumDType. diff --git a/mindspore/ccsrc/frontend/operator/composite/list_append_operation.cc b/mindspore/ccsrc/frontend/operator/composite/list_append_operation.cc index 3dfe2e23d02..40232cb24e1 100644 --- a/mindspore/ccsrc/frontend/operator/composite/list_append_operation.cc +++ b/mindspore/ccsrc/frontend/operator/composite/list_append_operation.cc @@ -43,7 +43,7 @@ FuncGraphPtr ListAppend::GenerateFuncGraph(const abstract::AbstractBasePtrList & elems.push_back(NewValueNode(prim::kPrimMakeList)); size_t arg0_length = arg0_list->size(); for (size_t i = 0; i < arg0_length; ++i) { - elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimListGetItem), arg0_node, NewValueNode(SizeToInt(i))})); + elems.push_back(ret->NewCNode({NewValueNode(prim::kPrimListGetItem), arg0_node, NewValueNode(SizeToLong(i))})); } AnfNodePtr arg1_node = ret->add_parameter(); elems.push_back(arg1_node); diff --git a/mindspore/ccsrc/frontend/operator/composite/map.cc b/mindspore/ccsrc/frontend/operator/composite/map.cc index a402d30be6a..4a92634537f 100644 --- a/mindspore/ccsrc/frontend/operator/composite/map.cc +++ b/mindspore/ccsrc/frontend/operator/composite/map.cc @@ -84,7 +84,7 @@ AnfNodePtr Map::FullMakeList(const std::shared_ptr &type, const FuncGraphP std::vector inputs; inputs.push_back(NewValueNode(prim::kPrimMakeList)); - for (int i = 0; i < SizeToInt(size); ++i) { + for (int64_t i = 0; i < SizeToLong(size); ++i) { MS_LOG(DEBUG) << "GenerateLeafFunc for the " << i << "th arg of the target"; auto ptrGraph = GenerateLeafFunc(arg_pairs.size()); auto fn = NewValueNode(ptrGraph); @@ -125,7 +125,7 @@ AnfNodePtr Map::FullMakeTuple(const std::shared_ptr &type, const FuncGrap std::vector inputs; inputs.push_back(NewValueNode(prim::kPrimMakeTuple)); - for (int i = 0; i < SizeToInt(size); ++i) { + for (int64_t i = 0; i < SizeToLong(size); ++i) { MS_LOG(DEBUG) << "GenerateLeafFunc for the " << i << "th arg of the tuple inputs"; auto ptrGraph = GenerateLeafFunc(arg_pairs.size()); auto fn = NewValueNode(ptrGraph); @@ -168,7 +168,7 @@ AnfNodePtr Map::FullMakeClass(const std::shared_ptr &type, const FuncGrap inputs2.push_back(fn_arg); } - int j = 0; + int64_t j = 0; for (auto item : arg_pairs) { inputs2.push_back(func_graph->NewCNode({NewValueNode(prim::kPrimGetAttr), item.first, NewValueNode(j)})); j++; @@ -209,7 +209,7 @@ AnfNodePtr Map::Make(const FuncGraphPtr &func_graph, const AnfNodePtr &fn_arg, c std::ostringstream oss; oss << "There are " << arg_pairs.size() << " inputs of `" << name_ << "`, corresponding type info:\n" << trace::GetDebugInfo(func_graph->debug_info()) << "\n"; - int idx = 0; + int64_t idx = 0; for (auto &item : arg_pairs) { oss << ++idx << ": " << item.second->ToString() << "\n"; } diff --git a/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc b/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc index 7ddb47e9482..56815e40896 100644 --- a/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc +++ b/mindspore/ccsrc/frontend/operator/composite/multitype_funcgraph.cc @@ -123,7 +123,7 @@ FuncGraphPtr MultitypeFuncGraph::GenerateFromTypes(const TypePtrList &types) { std::ostringstream oss; oss << "There are " << fn_cache_py_.size() << " prototypes for overload function `" << name_ << "`, corresponding location info:\n"; - int idx = 0; + int64_t idx = 0; for (auto &item : fn_cache_py_) { FuncGraphPtr func_graph = parse::ParsePythonCode(item.second); if (func_graph == nullptr) { diff --git a/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc b/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc index 87f9cea0843..2fa4e3f780c 100644 --- a/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc +++ b/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc @@ -61,7 +61,7 @@ FuncGraphPtr UnpackCall::GenerateFuncGraph(const AbstractBasePtrList &args_spec_ AnfNodePtr para_tuple = ret_graph->add_parameter(); for (size_t i = 0; i < arg_tuple->size(); ++i) { elems.push_back( - ret_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), para_tuple, NewValueNode(SizeToInt(i))})); + ret_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), para_tuple, NewValueNode(SizeToLong(i))})); } } else if (args_spec_list[index]->isa()) { AbstractDictionaryPtr arg_dict = args_spec_list[index]->cast(); diff --git a/mindspore/ccsrc/frontend/operator/composite/zip_operation.cc b/mindspore/ccsrc/frontend/operator/composite/zip_operation.cc index 9e2b6d28b22..4c765ecc87d 100644 --- a/mindspore/ccsrc/frontend/operator/composite/zip_operation.cc +++ b/mindspore/ccsrc/frontend/operator/composite/zip_operation.cc @@ -72,7 +72,7 @@ FuncGraphPtr ZipOperation::GenerateFuncGraph(const AbstractBasePtrList &args_spe ValuePtr op = prim::GetPythonOps("getitem", module_name); for (size_t arg_idx = 0; arg_idx < args_spec_list.size(); arg_idx++) { std::vector tuple_get_item_nodes{NewValueNode(op), ret_graph->parameters()[arg_idx], - NewValueNode(SizeToInt(idx))}; + NewValueNode(SizeToLong(idx))}; auto tuple_get_item_op = ret_graph->NewCNode(tuple_get_item_nodes); make_tuple_zip_nodes.push_back(tuple_get_item_op); } diff --git a/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc index 11c3cd1d971..58fd385e3c7 100644 --- a/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc +++ b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc @@ -38,9 +38,9 @@ enum State { }; struct SlideInfo { - int start; - int step; - int stop; + int64_t start; + int64_t step; + int64_t stop; }; template @@ -56,33 +56,33 @@ AbstractBasePtr InferImplTupleOrListEqual(const std::string &op_name, const Abst } void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) { - int arg1 = 0; - int arg2 = 0; + int64_t arg1 = 0; + int64_t arg2 = 0; if (!args_spec_list.empty()) { MS_EXCEPTION_IF_NULL(args_spec_list[0]); auto arg_value = args_spec_list[0]->BuildValue(); - if (!arg_value->isa()) { - MS_LOG(EXCEPTION) << "Only supported input an int32 number."; + if (!arg_value->isa()) { + MS_LOG(EXCEPTION) << "Only supported input an int64 number."; } - arg1 = GetValue(arg_value); + arg1 = GetValue(arg_value); } if (args_spec_list.size() >= 2) { MS_EXCEPTION_IF_NULL(args_spec_list[1]); auto arg_value = args_spec_list[1]->BuildValue(); - if (!arg_value->isa()) { - MS_LOG(EXCEPTION) << "Only supported input an int32 number."; + if (!arg_value->isa()) { + MS_LOG(EXCEPTION) << "Only supported input an int64 number."; } - arg2 = GetValue(arg_value); + arg2 = GetValue(arg_value); } if (args_spec_list.size() == 3) { MS_EXCEPTION_IF_NULL(args_spec_list[2]); auto arg_value = args_spec_list[2]->BuildValue(); - if (!arg_value->isa()) { - MS_LOG(EXCEPTION) << "Only supported input an int32 number."; + if (!arg_value->isa()) { + MS_LOG(EXCEPTION) << "Only supported input an int64 number."; } - slide->step = GetValue(arg_value); + slide->step = GetValue(arg_value); slide->start = arg1; slide->stop = arg2; } @@ -97,14 +97,14 @@ void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) } } -void ComputeReduceIndex(const std::vector &reverse_x, const std::vector &reverse_y, - std::vector *grad_x_reduce_idx, std::vector *grad_y_reduce_idy) { +void ComputeReduceIndex(const std::vector &reverse_x, const std::vector &reverse_y, + std::vector *grad_x_reduce_idx, std::vector *grad_y_reduce_idy) { const size_t n = reverse_x.size(); for (size_t i = 0; i < n; ++i) { State curr; - const int32_t x_i = reverse_x[i]; - const int32_t y_i = reverse_y[i]; - const int reduce_idx = SizeToInt(n - 1 - i); + const int64_t x_i = reverse_x[i]; + const int64_t y_i = reverse_y[i]; + const int64_t reduce_idx = SizeToLong(n - 1 - i); if (x_i == y_i) { curr = SAME; } else if (x_i == 1) { @@ -128,13 +128,13 @@ void ComputeReduceIndex(const std::vector &reverse_x, const std::vector &x_shape, const std::vector &y_shape) { - std::vector reverse_x; - std::vector reverse_y; + std::vector reverse_x; + std::vector reverse_y; (void)std::transform(x_shape.rbegin(), x_shape.rend(), std::back_inserter(reverse_x), - [](const ValuePtr &v) { return v->cast()->value(); }); + [](const ValuePtr &v) { return v->cast()->value(); }); (void)std::transform(y_shape.rbegin(), y_shape.rend(), std::back_inserter(reverse_y), - [](const ValuePtr &v) { return v->cast()->value(); }); + [](const ValuePtr &v) { return v->cast()->value(); }); if (reverse_x.size() > reverse_y.size()) { reverse_y.resize(reverse_x.size(), 1); @@ -142,16 +142,16 @@ AbstractBasePtr BroadcastGradientArgsDiff(const std::vector &x_shape, reverse_x.resize(reverse_y.size(), 1); } - std::vector grad_x_reduce_idx; - std::vector grad_y_reduce_idy; + std::vector grad_x_reduce_idx; + std::vector grad_y_reduce_idy; ComputeReduceIndex(reverse_x, reverse_y, &grad_x_reduce_idx, &grad_y_reduce_idy); AbstractBasePtrList abs_list_x; AbstractBasePtrList abs_list_y; (void)std::transform(grad_x_reduce_idx.begin(), grad_x_reduce_idx.end(), std::back_inserter(abs_list_x), - [](int v) { return abstract::FromValue(v); }); + [](int64_t v) { return abstract::FromValue(v); }); (void)std::transform(grad_y_reduce_idy.begin(), grad_y_reduce_idy.end(), std::back_inserter(abs_list_y), - [](int v) { return abstract::FromValue(v); }); + [](int64_t v) { return abstract::FromValue(v); }); auto x_reduce_idx = std::make_shared(abs_list_x); auto y_reduce_idx = std::make_shared(abs_list_y); AbstractBasePtrList elem_list; @@ -199,7 +199,7 @@ bool CompareShape(const std::vector &x_shape, const std::vector(x_shape[i]) != GetValue(y_shape[i])) { + if (GetValue(x_shape[i]) != GetValue(y_shape[i])) { return false; } } @@ -210,16 +210,16 @@ bool CompareShape(const std::vector &x_shape, const std::vectorsize(); - std::set axis_set; + std::set axis_set; auto axis_data = axis_value_ptr->value(); if (axis_data.empty()) { - int size = 1; + int64_t size = 1; AbstractBasePtrList values(x_rank, std::make_shared(size)); return std::make_shared(values); } for (auto &elem : axis_data) { - int e_value = CheckAxis(primitive->name(), elem, -SizeToInt(x_rank), SizeToInt(x_rank) - 1); + int64_t e_value = CheckAxis(primitive->name(), elem, -SizeToLong(x_rank), SizeToLong(x_rank) - 1); (void)axis_set.insert(e_value); } @@ -229,11 +229,11 @@ AbstractBasePtr DoInferReduceShape(const AbstractTuplePtr &x_shape, const ValueP } AbstractBasePtrList values; for (size_t i = 0; i < x_rank; i++) { - if (axis_set.count(SizeToInt(i)) || axis_set.count(SizeToInt(i) - SizeToInt(x_rank))) { - auto axis_v = MakeValue(1); + if (axis_set.count(SizeToLong(i)) || axis_set.count(SizeToLong(i) - SizeToLong(x_rank))) { + auto axis_v = MakeValue(static_cast(1)); values.push_back(std::make_shared(axis_v, axis_v->type())); } else { - int dim_value = x_shp_data[i]->cast()->value(); + int64_t dim_value = x_shp_data[i]->cast()->value(); auto dim = MakeValue(dim_value); values.push_back(std::make_shared(dim, dim->type())); } @@ -404,20 +404,20 @@ AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr AbstractBasePtrList values; for (size_t i = 0; i < div_shp_data.size(); i++) { - if (div_shp_data[i]->cast() == nullptr) { - MS_LOG(EXCEPTION) << "div_shp_shape data should be an int32 number, but it's " << args_spec_list[1]->ToString(); + if (div_shp_data[i]->cast() == nullptr) { + MS_LOG(EXCEPTION) << "div_shp_shape data should be an int64 number, but it's " << args_spec_list[1]->ToString(); } - int shapex_value = GetValue(shpx_data[i]); - int div_value = GetValue(div_shp_data[i]); + int64_t shapex_value = GetValue(shpx_data[i]); + int64_t div_value = GetValue(div_shp_data[i]); MS_LOG(DEBUG) << "div_shp_shape data shapex_value :" << shapex_value << " div_value: " << div_value; if (div_value == 0) { MS_LOG(EXCEPTION) << "error: division value should not be 0!"; } if ((shapex_value % div_value) != 0) { - MS_LOG(EXCEPTION) << "div_shp_shape data shapex must div int:" << shapex_value << " div_value: " << div_value; + MS_LOG(EXCEPTION) << "div_shp_shape data shapex must div int64_t:" << shapex_value << " div_value: " << div_value; } - int result = shapex_value / div_value; + int64_t result = shapex_value / div_value; auto result_v = MakeValue(result); values.push_back(std::make_shared(result_v, result_v->type())); } @@ -456,9 +456,9 @@ AbstractBasePtr InferImplShapeMul(const AnalysisEnginePtr &, const PrimitivePtr auto shpx_data = shpx_value->cast()->value(); - int result = 1; + int64_t result = 1; for (size_t i = 0; i < shpx_data.size(); i++) { - int value = GetValue(shpx_data[i]); + int64_t value = GetValue(shpx_data[i]); result = IntMulWithOverflowCheck(result, value); } @@ -490,7 +490,7 @@ AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr MS_LOG(EXCEPTION) << "Error slice[" << slide.start << ", " << slide.stop << ", " << slide.step << "]"; } - for (int i = slide.start; i < slide.stop; i += slide.step) { + for (int64_t i = slide.start; i < slide.stop; i += slide.step) { args.push_back(abstract::FromValue(i)); if (i > 0 && INT_MAX - i < slide.step) { MS_EXCEPTION(ValueError) << "For make range, the required cycles number is greater than max cycles number, " @@ -502,7 +502,7 @@ AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr MS_LOG(EXCEPTION) << "Error slice[" << slide.start << ", " << slide.stop << ", " << slide.step << "]"; } - for (int i = slide.start; i > slide.stop; i += slide.step) { + for (int64_t i = slide.start; i > slide.stop; i += slide.step) { args.push_back(abstract::FromValue(i)); if (i < 0 && INT_MIN - i > slide.step) { MS_EXCEPTION(ValueError) << "For make range, the required cycles number is greater than max cycles number, " diff --git a/mindspore/ccsrc/frontend/operator/prim_to_function.cc b/mindspore/ccsrc/frontend/operator/prim_to_function.cc index f135a2c86cb..0a39409e623 100644 --- a/mindspore/ccsrc/frontend/operator/prim_to_function.cc +++ b/mindspore/ccsrc/frontend/operator/prim_to_function.cc @@ -55,7 +55,7 @@ bool PrimToFunction::GetFunction(const PrimitivePtr &prim, FunctionPtr *const fu bool result = false; if (func != nullptr) { - int args_num = GetPrimType(prim); + int64_t args_num = GetPrimType(prim); std::vector one_arg{std::make_shared()}; std::vector two_args{std::make_shared(), std::make_shared()}; TypePtr retval = std::make_shared(); @@ -76,9 +76,9 @@ bool PrimToFunction::GetFunction(const PrimitivePtr &prim, FunctionPtr *const fu return result; } -int PrimToFunction::GetPrimType(const PrimitivePtr &prim) const { +int64_t PrimToFunction::GetPrimType(const PrimitivePtr &prim) const { MS_EXCEPTION_IF_NULL(prim); - int prim_type = static_cast(kPrimTypeUnknown); + int64_t prim_type = static_cast(kPrimTypeUnknown); auto value = prim_func_type_map_.find(prim->name()); if (value != prim_func_type_map_.end()) { diff --git a/mindspore/ccsrc/frontend/operator/prim_to_function.h b/mindspore/ccsrc/frontend/operator/prim_to_function.h index fe434d01297..3e29e9d3d65 100644 --- a/mindspore/ccsrc/frontend/operator/prim_to_function.h +++ b/mindspore/ccsrc/frontend/operator/prim_to_function.h @@ -55,8 +55,8 @@ class PrimToFunction { private: PrimToFunction(); // Get the number of primitive arguments - int GetPrimType(const PrimitivePtr &prim) const; - const std::unordered_map prim_func_type_map_; + int64_t GetPrimType(const PrimitivePtr &prim) const; + const std::unordered_map prim_func_type_map_; }; } // namespace prim } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/optimizer/ad/dfunctor.cc b/mindspore/ccsrc/frontend/optimizer/ad/dfunctor.cc index 4230da26a0a..8b16556ef97 100644 --- a/mindspore/ccsrc/frontend/optimizer/ad/dfunctor.cc +++ b/mindspore/ccsrc/frontend/optimizer/ad/dfunctor.cc @@ -165,18 +165,20 @@ void DFunctor::BackPropagateSwitchLayer(const CNodePtr &cnode_morph, const CNode } void DFunctor::BackPropagate(const CNodePtr &cnode_morph, const CNodePtr &k_app, const AdjointPtr &node_adjoint) { - auto bprop = k_graph_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), k_app, NewValueNode(1)}); + auto bprop = + k_graph_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), k_app, NewValueNode(static_cast(1))}); // Call with delimited continuation dout. auto bprop_app = tape_->NewCNode({bprop, node_adjoint->dout()}); node_adjoint->RegisterDoutUser(bprop_app, 1); // Special case for switch_layer if (IsPrimitiveCNode(cnode_morph, prim::kPrimSwitchLayer)) { - auto din = tape_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), bprop_app, NewValueNode(0)}); + auto din = + tape_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), bprop_app, NewValueNode(static_cast(0))}); BackPropagateSwitchLayer(cnode_morph, din); return; } for (size_t i = 0; i < cnode_morph->size(); i++) { - auto din = tape_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), bprop_app, NewValueNode(SizeToInt(i))}); + auto din = tape_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), bprop_app, NewValueNode(SizeToLong(i))}); auto input = cnode_morph->input(i); // Backprop sens wrt fvs. if (IsValueNode(input)) { @@ -252,7 +254,8 @@ AdjointPtr DFunctor::MapMorphism(const AnfNodePtr &morph) { } // Do forward computation - auto foward_app = k_graph_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), k_app, NewValueNode(0)}); + auto foward_app = + k_graph_->NewCNode({NewValueNode(prim::kPrimTupleGetItem), k_app, NewValueNode(static_cast(0))}); // K:: cnode -> forward_app auto node_adjoint = std::make_shared(morph, foward_app, tape_); UpdateAdjoint(node_adjoint); @@ -783,8 +786,8 @@ bool DFunctor::AllReferencesStopped(const CNodePtr &node) { // To replace the primal graph with k graph void DFunctor::EliminatePrimalGraph() { auto k_vnode = NewValueNode(k_graph_); - auto idx0 = NewValueNode(SizeToInt(0)); - auto imm0 = std::make_shared(0); + auto idx0 = NewValueNode(SizeToLong(0)); + auto imm0 = std::make_shared(0); idx0->set_abstract(std::make_shared(imm0)); auto manager = primal_graph_->manager(); auto users = primal_graph_->func_graph_cnodes_index(); diff --git a/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc b/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc index a1a28bf57a8..cc47a04becd 100644 --- a/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc +++ b/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc @@ -236,7 +236,7 @@ FuncGraphPtr KPrim::BpropCut(const ValueNodePtr &value_node, const pipeline::Res auto &node_users = resources->manager()->node_users(); auto &users = node_users[value_node]; - auto cnode = std::find_if(users.begin(), users.end(), [&prim](const std::pair &user) -> bool { + auto cnode = std::find_if(users.begin(), users.end(), [&prim](const std::pair &user) -> bool { return IsPrimitiveCNode(user.first, prim); }); if (cnode == users.end()) { @@ -276,7 +276,7 @@ FuncGraphPtr KPrim::FakeBprop(const ValueNodePtr &value_node, const pipeline::Re auto &node_users = resources->manager()->node_users(); auto &users = node_users[value_node]; - auto cnode = std::find_if(users.begin(), users.end(), [&prim](const std::pair &user) -> bool { + auto cnode = std::find_if(users.begin(), users.end(), [&prim](const std::pair &user) -> bool { return IsPrimitiveCNode(user.first, prim); }); if (cnode == users.end()) { diff --git a/mindspore/ccsrc/frontend/optimizer/clean.cc b/mindspore/ccsrc/frontend/optimizer/clean.cc index 79f97fc6ea7..60f6314c502 100644 --- a/mindspore/ccsrc/frontend/optimizer/clean.cc +++ b/mindspore/ccsrc/frontend/optimizer/clean.cc @@ -116,7 +116,7 @@ AnfNodePtr ConvertGetAttrToTupleGetItem(const CNodePtr &node) { auto ct = dyn_cast(dt); const auto &cmap = ct->attributes(); - int count = 0; + int64_t count = 0; for (auto &item : cmap) { if (cons_is_str && item.first == cons_str) { break; @@ -125,7 +125,7 @@ AnfNodePtr ConvertGetAttrToTupleGetItem(const CNodePtr &node) { } auto idx_c = NewValueNode(count); - AbstractBasePtr aptr = std::make_shared(std::make_shared(count)); + AbstractBasePtr aptr = std::make_shared(std::make_shared(count)); idx_c->set_abstract(aptr); return node->func_graph()->NewCNode({NewValueNode(prim::kPrimTupleGetItem), data, idx_c}); @@ -154,7 +154,7 @@ AnfNodePtr ConvertDictGetItemToTupleGetItem(const CNodePtr &node) { auto ct = dyn_cast(dt); const auto &cmap = ct->elements(); - int count = 0; + int64_t count = 0; for (auto &item : cmap) { if (cons_is_str && item.first == cons_str) { break; @@ -163,7 +163,7 @@ AnfNodePtr ConvertDictGetItemToTupleGetItem(const CNodePtr &node) { } auto idx_c = NewValueNode(count); - AbstractBasePtr aptr = std::make_shared(std::make_shared(count)); + AbstractBasePtr aptr = std::make_shared(std::make_shared(count)); idx_c->set_abstract(aptr); return node->func_graph()->NewCNode({NewValueNode(prim::kPrimTupleGetItem), data, idx_c}); } @@ -192,21 +192,21 @@ AnfNodePtr ConvertDictSetItemToTupleSetItem(const CNodePtr &node) { auto ct = dyn_cast(dt); const auto &cmap = ct->elements(); - int count = 0; + int64_t count = 0; for (auto &item : cmap) { if (cons_is_str && item.first == cons_str) { break; } count++; } - if (IntToSize(count) >= cmap.size()) { + if (LongToSize(count) >= cmap.size()) { // for dictionary set, if the key does not exist, we should create a new item auto tuple_add_op = std::make_shared("tuple_add"); auto tuple_new_item = node->func_graph()->NewCNode({NewValueNode(prim::kPrimMakeTuple), item_value}); return node->func_graph()->NewCNode({NewValueNode(tuple_add_op), data, tuple_new_item}); } auto idx_c = NewValueNode(count); - AbstractBasePtr aptr = std::make_shared(std::make_shared(count)); + AbstractBasePtr aptr = std::make_shared(std::make_shared(count)); idx_c->set_abstract(aptr); return node->func_graph()->NewCNode({NewValueNode(prim::kPrimTupleSetItem), data, idx_c, item_value}); } @@ -327,8 +327,8 @@ AnfNodePtr EraseExtractKeywordArg(const CNodePtr &node) { return inputs[2]; } -ValueTuplePtr ConvertValueListToValueTuple(const ValueListPtr &value_list, int depth) { - const int DEPTH_MAX = 5; +ValueTuplePtr ConvertValueListToValueTuple(const ValueListPtr &value_list, int64_t depth) { + const int64_t DEPTH_MAX = 5; if (depth > DEPTH_MAX) { MS_LOG(EXCEPTION) << "List nesting is not allowed more than 5 levels."; } @@ -350,7 +350,7 @@ AnfNodePtr ConvertValueListNodeToValueTupleNode(const ValueNodePtr &node) { ValuePtr value = node->value(); auto value_list = value->cast(); MS_EXCEPTION_IF_NULL(value_list); - int depth = 0; + int64_t depth = 0; return std::make_shared(ConvertValueListToValueTuple(value_list, depth)); } @@ -424,7 +424,7 @@ AnfNodePtr ConvertMakeSparseToMakeTuple(const CNodePtr &node) { return node->func_graph()->NewCNode(inputs); } -AnfNodePtr ConvertSparseGetAttrToTupleGetItem(const CNodePtr &node, const int &index) { +AnfNodePtr ConvertSparseGetAttrToTupleGetItem(const CNodePtr &node, const int64_t &index) { MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(node->func_graph()); @@ -437,7 +437,7 @@ AnfNodePtr ConvertSparseGetAttrToTupleGetItem(const CNodePtr &node, const int &i AnfNodePtr sparse = inputs[1]; MS_EXCEPTION_IF_NULL(sparse); auto cons_node = NewValueNode(index); - AbstractBasePtr aptr = std::make_shared(std::make_shared(index)); + AbstractBasePtr aptr = std::make_shared(std::make_shared(index)); cons_node->set_abstract(aptr); return node->func_graph()->NewCNode({NewValueNode(prim::kPrimTupleGetItem), sparse, cons_node}); @@ -559,12 +559,12 @@ static std::vector ExpandTuplesC(const FuncGraphPtr &graph, const st continue; } - int idx = 0; + int64_t idx = 0; std::vector new_input; auto abs_tuple = dyn_cast(input_abs); for (auto &elem : abs_tuple->elements()) { auto c_node = graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), input, NewValueNode(idx)}); - AbstractBasePtr aptr = std::make_shared(std::make_shared(idx)); + AbstractBasePtr aptr = std::make_shared(std::make_shared(idx)); c_node->input(2)->set_abstract(aptr); c_node->set_abstract(elem); new_input.emplace_back(c_node); diff --git a/mindspore/ccsrc/frontend/optimizer/graph_kernel_reuse.h b/mindspore/ccsrc/frontend/optimizer/graph_kernel_reuse.h index fcfdcb02b0f..276927a5dcb 100644 --- a/mindspore/ccsrc/frontend/optimizer/graph_kernel_reuse.h +++ b/mindspore/ccsrc/frontend/optimizer/graph_kernel_reuse.h @@ -43,7 +43,7 @@ class GraphKernelReuse { private: std::unordered_map> graph_kernel_ops; - int count; + int64_t count; }; } // namespace opt } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/optimizer/graph_transform.cc b/mindspore/ccsrc/frontend/optimizer/graph_transform.cc index 4b1275be98f..4245ae58301 100644 --- a/mindspore/ccsrc/frontend/optimizer/graph_transform.cc +++ b/mindspore/ccsrc/frontend/optimizer/graph_transform.cc @@ -62,7 +62,7 @@ std::vector TransformTupleArgument(const FuncGraphPtr &fg, const Anf auto &elements = abs->elements(); std::vector tuple_node_expanded; for (size_t i = 0; i < elements.size(); i++) { - auto elem_node = fg->NewCNode({NewValueNode(prim::kPrimTupleGetItem), node, NewValueNode(SizeToInt(i))}); + auto elem_node = fg->NewCNode({NewValueNode(prim::kPrimTupleGetItem), node, NewValueNode(SizeToLong(i))}); elem_node->set_abstract(elements[i]); if (elements[i]->isa()) { auto nodes = TransformTupleArgument(fg, elem_node, elements[i]->cast()); diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/branch_culling.cc b/mindspore/ccsrc/frontend/optimizer/irpass/branch_culling.cc index 01f5b2f1ba8..42e1017b02b 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/branch_culling.cc +++ b/mindspore/ccsrc/frontend/optimizer/irpass/branch_culling.cc @@ -28,7 +28,7 @@ namespace opt { namespace irpass { namespace internal { AnfNodePtr GenerateSwitchNode(const FuncGraphPtr &graph, const AnfNodePtr &cond, const AnfNodePtr &data, - int switch_idx) { + int64_t switch_idx) { auto switch_node = prim::GetPythonOps("geswitch", "mindspore.ops.functional")->cast(); std::vector switch_nodes{NewValueNode(switch_node), data, cond}; auto switch_apply = graph->NewCNode(switch_nodes); @@ -186,11 +186,11 @@ struct SharedOp { inline tensor::TensorPtr GetConstData() { return MergeNetOutput.const_data; } inline void SetConstData(const tensor::TensorPtr &const_value) { MergeNetOutput.const_data = const_value; } -inline CNodePtr GetSquareOp(int switch_idx) { return MergeNetOutput.square_ops[switch_idx]; } -inline void SetSquareOp(int switch_idx, const CNodePtr &op) { MergeNetOutput.square_ops[switch_idx] = op; } +inline CNodePtr GetSquareOp(int64_t switch_idx) { return MergeNetOutput.square_ops[switch_idx]; } +inline void SetSquareOp(int64_t switch_idx, const CNodePtr &op) { MergeNetOutput.square_ops[switch_idx] = op; } -inline CNodePtr GetMergeOp(int switch_idx) { return MergeNetOutput.merge_ops[switch_idx]; } -inline void SetMergeOp(int switch_idx, const CNodePtr &op) { MergeNetOutput.merge_ops[switch_idx] = op; } +inline CNodePtr GetMergeOp(int64_t switch_idx) { return MergeNetOutput.merge_ops[switch_idx]; } +inline void SetMergeOp(int64_t switch_idx, const CNodePtr &op) { MergeNetOutput.merge_ops[switch_idx] = op; } inline void ResetSharedOp() { SetConstData(nullptr); @@ -201,14 +201,14 @@ inline void ResetSharedOp() { } tensor::TensorPtr ConstData() { - std::vector shp = {1}; - tensor::TensorPtr const_data = std::make_shared(kInt32->type_id(), shp); - auto *val = static_cast(const_data->data_c()); + std::vector shp = {1}; + tensor::TensorPtr const_data = std::make_shared(kInt64->type_id(), shp); + auto *val = static_cast(const_data->data_c()); *val = 0; return const_data; } -CNodePtr SquareOp(const FuncGraphPtr &graph, const AnfNodePtr &cond, int switch_idx, +CNodePtr SquareOp(const FuncGraphPtr &graph, const AnfNodePtr &cond, int64_t switch_idx, const tensor::TensorPtr &const_data) { auto PrimSquare = prim::GetPythonOps("square", "mindspore.ops.functional")->cast(); // for the depended node , add two const data to merge the flow ,one for depended node with same switch, @@ -222,7 +222,7 @@ CNodePtr SquareOp(const FuncGraphPtr &graph, const AnfNodePtr &cond, int switch_ return square_op; } -CNodePtr MergeNode(const FuncGraphPtr &graph, const AnfNodePtr &cond, int switch_idx, +CNodePtr MergeNode(const FuncGraphPtr &graph, const AnfNodePtr &cond, int64_t switch_idx, const tensor::TensorPtr &const_data, const CNodePtr &square_op) { // for the depended node , add two const data to merge the flow ,one for depended node with same switch, // the other use the opposite @@ -242,7 +242,7 @@ CNodePtr MergeNode(const FuncGraphPtr &graph, const AnfNodePtr &cond, int switch // construct a depend node with merge output node, merge(square_op(switch(ctrl_data)), switch(opposite_ctrl_data)) // control_depend(output_node, square_op) AnfNodePtr GenerateSwitchDependNode(const FuncGraphPtr &graph, const AnfNodePtr &cond, const AnfNodePtr &output_node, - int switch_idx) { + int64_t switch_idx) { tensor::TensorPtr const_data = GetConstData(); if (const_data == nullptr) { const_data = ConstData(); @@ -274,12 +274,12 @@ AnfNodePtr GenerateSwitchDependNode(const FuncGraphPtr &graph, const AnfNodePtr // we need to reserve the control_depend node, besides the generated merge node and control_depend node CNodePtr GenerateSwitchControlDependNode(const FuncGraphPtr &graph, const AnfNodePtr &cond, const AnfNodePtr &ctrl_dep_node, const AnfNodePtr &ctrl_depend_dst, - int switch_idx) { + int64_t switch_idx) { auto PrimMerge = prim::GetPythonOps("merge", "mindspore.ops.functional")->cast(); auto PrimSquare = prim::GetPythonOps("square", "mindspore.ops.functional")->cast(); - std::vector shp = {1}; - tensor::TensorPtr const_data = std::make_shared(kInt32->type_id(), shp); - auto *val = static_cast(const_data->data_c()); + std::vector shp = {1}; + tensor::TensorPtr const_data = std::make_shared(kInt64->type_id(), shp); + auto *val = static_cast(const_data->data_c()); *val = 0; // for the control_depend netoutput node , add two const data to merge the flow ,one for depended node with same // switch the other use the opposite @@ -542,7 +542,8 @@ AnfNodePtr GenerateMergeNodes(const AnfNodePtr &true_output_node, const AnfNodeP std::vector make_tuple_nodes{NewValueNode(prim::kPrimMakeTuple), true_output_node, false_output_node}; merge_nodes.push_back(switch_graph->NewCNode(make_tuple_nodes)); std::vector tuple_getitem_nodes{NewValueNode(prim::kPrimTupleGetItem), - switch_graph->NewCNode(merge_nodes), NewValueNode(MakeValue(0))}; + switch_graph->NewCNode(merge_nodes), + NewValueNode(MakeValue(static_cast(0)))}; return switch_graph->NewCNode(tuple_getitem_nodes); } else { abstract::AbstractTuplePtr true_branch_tuple = true_graph_output_abs->cast(); @@ -552,10 +553,10 @@ AnfNodePtr GenerateMergeNodes(const AnfNodePtr &true_output_node, const AnfNodeP make_tuple_nodes.push_back(NewValueNode(prim::kPrimMakeTuple)); for (size_t i = 0; i < true_branch_tuple->elements().size(); i++) { std::vector true_getitem_nodes{NewValueNode(prim::kPrimTupleGetItem), true_output_node, - NewValueNode(MakeValue(SizeToInt(i)))}; + NewValueNode(MakeValue(SizeToLong(i)))}; auto true_node = switch_graph->NewCNode(true_getitem_nodes); std::vector false_getitem_nodes{NewValueNode(prim::kPrimTupleGetItem), false_output_node, - NewValueNode(MakeValue(SizeToInt(i)))}; + NewValueNode(MakeValue(SizeToLong(i)))}; auto false_node = switch_graph->NewCNode(false_getitem_nodes); auto merge_node = GenerateMergeNodes(true_node, false_node, true_branch_tuple->elements()[i], diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/incorporate_getitem.h b/mindspore/ccsrc/frontend/optimizer/irpass/incorporate_getitem.h index ee62593d624..0e898c8443f 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/incorporate_getitem.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/incorporate_getitem.h @@ -41,7 +41,7 @@ class GetitemTransform { GetitemTransform() : cache_() {} ~GetitemTransform() = default; - FuncGraphPtr operator()(const FuncGraphPtr &fg, int idx) { + FuncGraphPtr operator()(const FuncGraphPtr &fg, int64_t idx) { if (cache_.find(fg) == cache_.end()) { cache_[fg] = {}; } @@ -55,7 +55,7 @@ class GetitemTransform { auto output = new_fg->output(); if (IsPrimitiveCNode(output, prim::kPrimMakeTuple)) { auto cnode = output->cast(); - auto ids = IntToSize(idx + 1); + auto ids = LongToSize(idx + 1); // Inputs should be [make_tuple, item1, item2, ...], so have to offset idx in tuple_getitem by 1. if (ids >= cnode->size()) { MS_LOG(EXCEPTION) << "index " << ids << " is out of inputs length " << cnode->size(); @@ -71,7 +71,7 @@ class GetitemTransform { } private: - std::unordered_map> cache_; + std::unordered_map> cache_; }; class GetItemTransformACrossGraph { @@ -79,7 +79,7 @@ class GetItemTransformACrossGraph { GetItemTransformACrossGraph() : cache_() {} ~GetItemTransformACrossGraph() = default; - FuncGraphPtr operator()(const FuncGraphPtr &fg, int idx) { + FuncGraphPtr operator()(const FuncGraphPtr &fg, int64_t idx) { if (cache_.find(fg) == cache_.end()) { cache_[fg] = {}; } @@ -102,7 +102,7 @@ class GetItemTransformACrossGraph { auto output = new_fg->output(); if (IsPrimitiveCNode(output, prim::kPrimMakeTuple)) { auto cnode = output->cast(); - auto ids = IntToSize(idx + 1); + auto ids = LongToSize(idx + 1); // Inputs should be [make_tuple, item1, item2, ...], so have to offset idx in tuple_getitem by 1. if (ids >= cnode->size()) { MS_LOG(EXCEPTION) << "index " << ids << " is out of inputs length " << cnode->size(); @@ -118,7 +118,7 @@ class GetItemTransformACrossGraph { } private: - std::unordered_map> cache_; + std::unordered_map> cache_; }; } // namespace internal @@ -130,7 +130,7 @@ class IncorporateGetitem : public AnfVisitor { AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { Reset(); - AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); if (node->func_graph() == nullptr || idx_ == -1 || fg_ == nullptr || fg_->has_flag(FUNC_GRAPH_FLAG_DEFER_INLINE)) { return nullptr; } @@ -142,7 +142,7 @@ class IncorporateGetitem : public AnfVisitor { if (IsPrimitiveCNode(output, prim::kPrimMakeTuple)) { auto output_cnode = output->cast(); auto outputs = output_cnode->inputs(); - int real_output_cnt = 0; + int64_t real_output_cnt = 0; for (size_t i = 1; i < outputs.size(); ++i) { if (IsCNode(outputs[i]) || IsValueNode(outputs[i]) || IsParam(outputs[i])) { real_output_cnt++; @@ -169,7 +169,7 @@ class IncorporateGetitem : public AnfVisitor { (void)std::copy(inputs.begin() + 1, inputs.end(), std::back_inserter(args_)); } - void Visit(const ValueNodePtr &vnode) override { idx_ = GetValue(vnode->value()); } + void Visit(const ValueNodePtr &vnode) override { idx_ = GetValue(vnode->value()); } void Reset() { idx_ = -1; @@ -178,7 +178,7 @@ class IncorporateGetitem : public AnfVisitor { } private: - int idx_{-1}; + int64_t idx_{-1}; FuncGraphPtr fg_{nullptr}; std::vector args_{}; internal::GetitemTransform getitem_transform_; @@ -228,8 +228,8 @@ class IncorporateGetitemFromParam : public AnfVisitor { inputs_num_[input_idx] = make_tuple_cnode->inputs().size() - 1; for (size_t output_i = 0; output_i < inputs_num_[input_idx]; ++output_i) { auto new_getitem = - func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), prev_cnode, NewValueNode(SizeToInt(output_i))}); - auto aptr = std::make_shared(std::make_shared(SizeToInt(output_i))); + func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), prev_cnode, NewValueNode(SizeToLong(output_i))}); + auto aptr = std::make_shared(std::make_shared(SizeToLong(output_i))); new_getitem->input(2)->set_abstract(aptr); new_getitem->set_abstract(make_tuple_cnode->input(output_i + 1)->abstract()); args_.push_back(new_getitem); @@ -300,14 +300,14 @@ class IncorporateGetitemFromParam : public AnfVisitor { // update users of new parameter. for (auto &user : node_users[new_fg_parameters[param_i]]) { idx_ = -1; - AnfVisitor::Match(prim::kPrimTupleGetItem, {IsParam, IsValueNode})(user.first); + AnfVisitor::Match(prim::kPrimTupleGetItem, {IsParam, IsValueNode})(user.first); if (idx_ == -1) { MS_LOG(ERROR) << "User of: " << new_fg_parameters[param_i]->DebugString() << " must be tuple getitem here, but got: " << user.first->DebugString(); return nullptr; } - if (input_i == IntToSize(idx_)) { + if (input_i == LongToSize(idx_)) { for (auto &sub_user : node_users[user.first]) { auto sub_user_cnode = sub_user.first->cast(); MS_EXCEPTION_IF_NULL(sub_user_cnode); @@ -329,7 +329,7 @@ class IncorporateGetitemFromParam : public AnfVisitor { return new_call; } - void Visit(const ValueNodePtr &vnode) override { idx_ = GetValue(vnode->value()); } + void Visit(const ValueNodePtr &vnode) override { idx_ = GetValue(vnode->value()); } void Visit(const CNodePtr &cnode) override {} @@ -346,7 +346,7 @@ class IncorporateGetitemFromParam : public AnfVisitor { std::vector args_{}; std::vector inputs_num_{}; bool need_update_{false}; - int idx_{-1}; + int64_t idx_{-1}; }; // {prim::kPrimTupleGetItem, {{prim::kPrimSwitch, X, G1, G2}, Xs}, C} @@ -358,7 +358,7 @@ class IncorporateGetitemSwitch : public AnfVisitor { AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { Reset(); is_in_get_ = true; - AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); is_in_get_ = false; auto fg = node->func_graph(); @@ -404,7 +404,7 @@ class IncorporateGetitemSwitch : public AnfVisitor { void Visit(const ValueNodePtr &vnode) override { if (is_in_get_) { - idx_ = GetValue(vnode->value()); + idx_ = GetValue(vnode->value()); } if (is_in_switch_) { @@ -446,7 +446,7 @@ class IncorporateGetitemSwitch : public AnfVisitor { return tuple_getitem_num > 1; } - int idx_{-1}; + int64_t idx_{-1}; AnfNodePtr switch_{nullptr}, x_{nullptr}; FuncGraphPtr g1_{nullptr}, g2_{nullptr}; bool is_in_get_{false}, is_in_switch_{false}; @@ -463,7 +463,7 @@ class IncorporateGetitemSwitchLayerA : public AnfVisitor { AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { Reset(); is_in_get_ = true; - AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); is_in_get_ = false; auto fg = node->func_graph(); @@ -520,7 +520,7 @@ class IncorporateGetitemSwitchLayerA : public AnfVisitor { void Visit(const ValueNodePtr &vnode) override { if (is_in_get_) { - idx_ = GetValue(vnode->value()); + idx_ = GetValue(vnode->value()); } } @@ -534,7 +534,7 @@ class IncorporateGetitemSwitchLayerA : public AnfVisitor { } private: - int idx_{-1}; + int64_t idx_{-1}; AnfNodePtr switch_layer_{nullptr}, x_{nullptr}; std::vector graphs_{}; bool is_in_get_{false}, is_in_switch_{false}; @@ -551,7 +551,7 @@ class IncorporateGetitemSwitchLayerB : public AnfVisitor { AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { Reset(); is_in_get_ = true; - AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); is_in_get_ = false; auto fg = node->func_graph(); @@ -612,7 +612,7 @@ class IncorporateGetitemSwitchLayerB : public AnfVisitor { void Visit(const ValueNodePtr &vnode) override { if (is_in_get_) { - idx_ = GetValue(vnode->value()); + idx_ = GetValue(vnode->value()); } } @@ -627,7 +627,7 @@ class IncorporateGetitemSwitchLayerB : public AnfVisitor { } private: - int idx_{-1}; + int64_t idx_{-1}; AnfNodePtr switch_layer_call_{nullptr}, x_{nullptr}; std::vector graphs_{}; bool is_in_get_{false}, is_in_switch_{false}; diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/inline.h b/mindspore/ccsrc/frontend/optimizer/irpass/inline.h index aec366ab9bd..1567ca459d1 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/inline.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/inline.h @@ -80,9 +80,9 @@ bool IsTrivial(const FuncGraphPtr &fg, AnfNodePtr) { bool IsUniqueUse(const FuncGraphPtr &fg, AnfNodePtr) { auto &cnodes = fg->func_graph_cnodes_index(); - int n_use = - std::accumulate(cnodes.begin(), cnodes.end(), 0, - [](int sum, const std::pair &item) { return sum + item.second; }); + int64_t n_use = std::accumulate( + cnodes.begin(), cnodes.end(), 0, + [](int64_t sum, const std::pair &item) { return sum + item.second; }); return n_use == 1; } @@ -211,7 +211,7 @@ class InlinerBase : public AnfVisitor { // In most cases, it may be a `Module` or other constant input. AnfNodePtr TransformBranchCall(const FuncGraphPtr &fg, const AnfNodePtr &node, const std::vector &args) { auto &fg_params = fg->parameters(); - std::vector used_param_index; + std::vector used_param_index; auto mng = fg->manager(); for (size_t i = 0; i < fg_params.size(); i++) { if (mng->node_users()[fg_params[i]].size() != 0) { diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_eliminate.h index e794671f982..d943184a134 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_eliminate.h @@ -53,12 +53,12 @@ class GetitemEliminater : public AnfVisitor { } void Visit(const ValueNodePtr &vnode) override { - if (tuple_ != nullptr && IsValueNode(vnode)) { - int idx = GetValue(vnode->value()); + if (tuple_ != nullptr && IsValueNode(vnode)) { + int64_t idx = GetValue(vnode->value()); if (idx < 0) { idx = idx + tuple_->size() - 1; } - id_ = IntToSize(idx + 1); + id_ = LongToSize(idx + 1); if (tuple_->size() > id_) { is_match_ = true; } @@ -100,8 +100,8 @@ class GetitemConstEliminater : public AnfVisitor { tuple_ = GetValueNode(vnode); has_new_value_ = vnode->has_new_value(); } - if (tuple_ != nullptr && IsValueNode(vnode)) { - id_ = IntToSize(GetValue(vnode->value())); + if (tuple_ != nullptr && IsValueNode(vnode)) { + id_ = LongToSize(GetValue(vnode->value())); if (tuple_->size() > id_) { is_match_ = true; } @@ -155,8 +155,8 @@ class SetitemEliminater : public AnfVisitor { } void Visit(const ValueNodePtr &vnode) override { - if (args_.size() > 0 && IsValueNode(vnode)) { - id_ = IntToSize(GetValue(vnode->value()) + 1); + if (args_.size() > 0 && IsValueNode(vnode)) { + id_ = LongToSize(GetValue(vnode->value()) + 1); if (id_ < args_.size()) { is_match_ = true; } @@ -211,8 +211,8 @@ class GetSetitemEliminater : public AnfVisitor { } void Visit(const ValueNodePtr &vnode) override { - if (IsValueNode(vnode)) { - auto key = GetValue(vnode->value()); + if (IsValueNode(vnode)) { + auto key = GetValue(vnode->value()); if (is_in_set_) { key1_ = key; } else { @@ -233,7 +233,7 @@ class GetSetitemEliminater : public AnfVisitor { private: bool is_in_set_{false}; - int key1_{-1}, key2_{-1}; + int64_t key1_{-1}, key2_{-1}; AnfNodePtr tuple_{nullptr}, last_{nullptr}, c2_{nullptr}; }; @@ -243,8 +243,8 @@ class GetitemDependReorder : public AnfVisitor { public: AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { Reset(); - AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); - AnfVisitor::Match(prim::kPrimListGetItem, {IsCNode, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimTupleGetItem, {IsCNode, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimListGetItem, {IsCNode, IsValueNode})(node); if (x_ == nullptr) { return nullptr; } diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/mark_interface_fusion.h b/mindspore/ccsrc/frontend/optimizer/irpass/mark_interface_fusion.h index ac635ca97b4..1f85f53c642 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/mark_interface_fusion.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/mark_interface_fusion.h @@ -32,7 +32,7 @@ namespace mindspore { namespace opt { namespace irpass { -static int count = 0; +static int64_t count = 0; std::string GetFusionNumber() { std::stringstream ss; diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/merge_addn.h b/mindspore/ccsrc/frontend/optimizer/irpass/merge_addn.h index 5e0c5985016..84ad4789e42 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/merge_addn.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/merge_addn.h @@ -256,15 +256,15 @@ class AddNEliminater : public AnfVisitor { MS_EXCEPTION(ArgumentError) << "Inputs size of AddN less than 2. " << cnode->DebugString(2); } - int valuenode_num = - std::accumulate(tuple_inputs.begin() + 1, tuple_inputs.end(), 0, [](int accumulator, const AnfNodePtr &node) { - if (IsValueNode(node)) { - return accumulator + 1; - } else { - return accumulator; - } - }); - if (IntToSize(valuenode_num) == tuple_inputs.size()) { + int64_t valuenode_num = std::accumulate(tuple_inputs.begin() + 1, tuple_inputs.end(), 0, + [](int64_t accumulator, const AnfNodePtr &node) { + if (IsValueNode(node)) { + return accumulator + 1; + } else { + return accumulator; + } + }); + if (LongToSize(valuenode_num) == tuple_inputs.size()) { // case1: all inputs is ValueNode, error MS_EXCEPTION(ArgumentError) << "All inputs of AddN is ValueNode. " << cnode->DebugString(2); } diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/minmax_grad.h b/mindspore/ccsrc/frontend/optimizer/irpass/minmax_grad.h index 079e28528d9..ecd077456fd 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/minmax_grad.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/minmax_grad.h @@ -54,7 +54,7 @@ class MinMaximumGrad : public AnfVisitor { public: AnfNodePtr operator()(const OptimizerPtr &optimizer, const AnfNodePtr &node) override { Reset(); - AnfVisitor::Match(prim::kPrimTupleGetItem, {internal::IsOriginMaxMinGrad, IsValueNode})(node); + AnfVisitor::Match(prim::kPrimTupleGetItem, {internal::IsOriginMaxMinGrad, IsValueNode})(node); if (grad_ == nullptr || idx_ < 0 || idx_ > 1 || node->func_graph() == nullptr) { return nullptr; } @@ -93,7 +93,7 @@ class MinMaximumGrad : public AnfVisitor { void Visit(const CNodePtr &cnode) override { grad_ = cnode; } - void Visit(const ValueNodePtr &vnode) override { idx_ = GetValue(vnode->value()); } + void Visit(const ValueNodePtr &vnode) override { idx_ = GetValue(vnode->value()); } void Reset() { idx_ = -1; @@ -101,7 +101,7 @@ class MinMaximumGrad : public AnfVisitor { } private: - int idx_{-1}; + int64_t idx_{-1}; CNodePtr grad_{nullptr}; }; } // namespace irpass diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/reduce_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/reduce_eliminate.h index f8e22935e02..b0ab349d561 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/reduce_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/reduce_eliminate.h @@ -75,7 +75,7 @@ class ReduceOneEliminater : public AnfVisitor { auto node_abstract = node->abstract(); // handle auto_parallel get nullptr abstract if (node_abstract != nullptr) { - auto new_base_shape = std::make_shared(GetValue>(new_shape)); + auto new_base_shape = std::make_shared(GetValue>(new_shape)); node_abstract->set_shape(new_base_shape); auto new_node = node->func_graph()->NewCNode({NewValueNode(reshape_op), x_, NewValueNode(new_shape)}); new_node->set_abstract(node_abstract); @@ -115,33 +115,33 @@ class ReduceOneEliminater : public AnfVisitor { return; } - // axis : int - if (IsValueNode(vnode)) { - auto idx = GetValue(vnode->value()); + // axis : int64_t + if (IsValueNode(vnode)) { + auto idx = GetValue(vnode->value()); // axis could be negative if (idx < 0) { - idx += SizeToInt(x_shape_.size()); + idx += SizeToLong(x_shape_.size()); } - if (SizeToInt(x_shape_.size()) > idx && x_shape_[IntToSize(idx)] == 1) { + if (SizeToLong(x_shape_.size()) > idx && x_shape_[LongToSize(idx)] == 1) { is_axis_one_ = true; axis_.push_back(idx); } return; } - // axis : tuple(int), default () + // axis : tuple(int64_t), default () if (IsValueNode(vnode)) { - auto axis = GetValue>(vnode->value()); + auto axis = GetValue>(vnode->value()); if (axis.empty()) { return; } - auto cmp = std::all_of(axis.cbegin(), axis.cend(), [this](int idx) { + auto cmp = std::all_of(axis.cbegin(), axis.cend(), [this](int64_t idx) { // axis could be negative if (idx < 0) { - idx += SizeToInt(x_shape_.size()); + idx += SizeToLong(x_shape_.size()); } - return SizeToInt(this->x_shape_.size()) > idx && this->x_shape_[IntToSize(idx)] == 1; + return SizeToLong(this->x_shape_.size()) > idx && this->x_shape_[LongToSize(idx)] == 1; }); if (cmp) { is_axis_one_ = true; @@ -160,7 +160,7 @@ class ReduceOneEliminater : public AnfVisitor { private: bool is_axis_one_{false}, is_tensor_{false}; - std::vector axis_{}, x_shape_{}; + std::vector axis_{}, x_shape_{}; AnfNodePtr x_{nullptr}; }; } // namespace irpass diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/special_op_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/special_op_eliminate.h index bcc0ae4767a..3cd09d80c35 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/special_op_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/special_op_eliminate.h @@ -172,16 +172,16 @@ class ZeroLikeFillZero : public AnfVisitor { auto fg = node->func_graph(); auto dtype = fg->NewCNode({NewValueNode(PrimDType_), y_}); auto shape = fg->NewCNode({NewValueNode(PrimShape_), y_}); - return fg->NewCNode({NewValueNode(PrimFill_), dtype, shape, NewValueNode(MakeValue(0))}); + return fg->NewCNode({NewValueNode(PrimFill_), dtype, shape, NewValueNode(MakeValue(static_cast(0)))}); } abstract::AbstractTensorPtr tensor_abstract = y_->abstract()->cast(); TypePtr tensor_type_ptr = tensor_abstract->element()->BuildType(); - std::vector tensor_shape = tensor_abstract->shape()->shape(); + std::vector tensor_shape = tensor_abstract->shape()->shape(); tensor::TensorPtr new_tensor_ptr = std::make_shared(tensor_type_ptr->type_id(), tensor_shape); - size_t mem_size = GetTypeByte(tensor_type_ptr) * IntToSize(new_tensor_ptr->ElementsNum()); + size_t mem_size = GetTypeByte(tensor_type_ptr) * LongToSize(new_tensor_ptr->ElementsNum()); char *data = reinterpret_cast(new_tensor_ptr->data_c()); (void)memset_s(data, mem_size, 0, mem_size); @@ -237,7 +237,7 @@ class PynativeEliminater : public OptimizerCaller { ValuePtr FillGetItem(const ValuePtr &value, const ValuePtr &idx) { MS_LOG(DEBUG) << "Start FillGetItem" << value->ToString() << idx->ToString(); - if (!idx->isa()) { + if (!idx->isa()) { MS_LOG(EXCEPTION) << "Getitem idx must int:" << idx->ToString(); } @@ -246,7 +246,7 @@ class PynativeEliminater : public OptimizerCaller { } auto value_tuple = value->cast(); - int idx_t = idx->cast()->value(); + int idx_t = idx->cast()->value(); MS_LOG(DEBUG) << "Fill getitem" << idx_t << (*value_tuple)[idx_t]->ToString(); return (*value_tuple)[idx_t]; } @@ -254,8 +254,8 @@ class PynativeEliminater : public OptimizerCaller { ValuePtr FillZero(const ValuePtr &value) { MS_LOG(DEBUG) << "Start FillZero"; ValuePtr out = nullptr; - if (value->isa()) { - return MakeValue(value->cast()->value()); + if (value->isa()) { + return MakeValue(value->cast()->value()); } if (value->isa()) { @@ -375,7 +375,7 @@ class AllReduceConstElim : public OptimizerCaller { auto group = primitive->GetAttr("group")->ToString(); // For sum operation, multiply constant tensor by number of devices if (reduce_op->ToString() == "sum") { - unsigned int num_of_devices; + uint32_t num_of_devices; // Get number of devices if (!CommManager::GetInstance().GetRankSize(group, &num_of_devices)) { MS_LOG(EXCEPTION) << "Failed to get num of devices for group [" + group + "]"; diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/specialize_transform.h b/mindspore/ccsrc/frontend/optimizer/irpass/specialize_transform.h index 6cb93120288..25b3ef17207 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/specialize_transform.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/specialize_transform.h @@ -251,14 +251,14 @@ class UnusedOutputEliminater : public AnfVisitor { if (node_users.count(node) == 0 || node_users[node].empty()) { return nullptr; } - std::unordered_set used_output_idx; - std::vector> all_users; + std::unordered_set used_output_idx; + std::vector> all_users; for (auto &node_user : node_users[node]) { if (!IsPrimitiveCNode(node_user.first, prim::kPrimTupleGetItem)) { return nullptr; } auto user_cnode = node_user.first->cast(); - size_t used_idx = GetValue(user_cnode->input(2)->cast()->value()); + size_t used_idx = GetValue(user_cnode->input(2)->cast()->value()); used_output_idx.insert(used_idx); all_users.push_back(std::make_pair(node_user.first, used_idx)); } @@ -281,9 +281,9 @@ class UnusedOutputEliminater : public AnfVisitor { } else { // after eliminate, create new multi output. std::vector new_output_inputs{output_cnode->input(0)}; - std::unordered_map new_idx_map; + std::unordered_map new_idx_map; for (auto idx : used_output_idx) { - new_idx_map[idx] = SizeToInt(new_output_inputs.size() - 1); + new_idx_map[idx] = SizeToLong(new_output_inputs.size() - 1); new_output_inputs.push_back(output_cnode->input(idx + 1)); } new_fg->set_output(new_fg->NewCNode(new_output_inputs)); diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/tile_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/tile_eliminate.h index 41efd252871..ae60ab02857 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/tile_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/tile_eliminate.h @@ -43,12 +43,12 @@ class TileEliminater : public AnfVisitor { } auto value = GetValueNode(tuple_); - auto elements = GetValue>(value); + auto elements = GetValue>(value); if (elements.empty()) { return x_; } - auto cmp = std::all_of(elements.cbegin(), elements.cend(), [](int i) { return i == 1; }); + auto cmp = std::all_of(elements.cbegin(), elements.cend(), [](int64_t i) { return i == 1; }); if (cmp) { return x_; } diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/transpose_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/transpose_eliminate.h index ecf8b92743d..5289ae31a42 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/transpose_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/transpose_eliminate.h @@ -42,13 +42,13 @@ class TransposeSameIOEliminater : public AnfVisitor { } auto value = GetValueNode(tuple_); - auto elements = GetValue>(value); + auto elements = GetValue>(value); if (elements.empty()) { return nullptr; } - int j = 0; - bool cmp = std::all_of(elements.cbegin(), elements.cend(), [&j](int i) { return i == j++; }); + int64_t j = 0; + bool cmp = std::all_of(elements.cbegin(), elements.cend(), [&j](int64_t i) { return i == j++; }); // same IO settings, eliminate this transpose if (cmp) { return x_; diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/value_based_eliminate.cc b/mindspore/ccsrc/frontend/optimizer/irpass/value_based_eliminate.cc index 2184d48c232..bf87c3f812b 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/value_based_eliminate.cc +++ b/mindspore/ccsrc/frontend/optimizer/irpass/value_based_eliminate.cc @@ -22,7 +22,7 @@ namespace irpass { #define UPPER_FLT_LIMIT (FLT_MAX / 2.0) #define LOWER_FLT_LIMIT (-FLT_MAX / 2.0) // Define the checking mode -enum ScalarCheckingMode : int { GREATER_EQUAL = 0, LESS }; +enum ScalarCheckingMode : int64_t { GREATER_EQUAL = 0, LESS }; bool IsNodeScalarTrueWith(const AnfNodePtr &node, const ScalarCheckingMode &checking_mode, const float &check_value) { auto value_node = node->cast(); diff --git a/mindspore/ccsrc/frontend/optimizer/opt.h b/mindspore/ccsrc/frontend/optimizer/opt.h index 32f32803a5f..eadc9db0717 100644 --- a/mindspore/ccsrc/frontend/optimizer/opt.h +++ b/mindspore/ccsrc/frontend/optimizer/opt.h @@ -33,7 +33,7 @@ namespace opt { // Define the interaction mode between an Optimize pass and Renormalize pass // FORCE_RENORM: if the pass modified the graph then the next Renormalize will be executed // CHECK_RENORM: check if the new node is un-typed to decide if the next Renormalize will be executted -enum RenormAction : int { FORCE_RENORM = 0, CHECK_RENORM }; +enum RenormAction : int64_t { FORCE_RENORM = 0, CHECK_RENORM }; class Substitution { public: diff --git a/mindspore/ccsrc/frontend/optimizer/optimizer.h b/mindspore/ccsrc/frontend/optimizer/optimizer.h index 60cd0764e8b..fbfc3e7bcec 100644 --- a/mindspore/ccsrc/frontend/optimizer/optimizer.h +++ b/mindspore/ccsrc/frontend/optimizer/optimizer.h @@ -143,7 +143,7 @@ class Optimizer : public std::enable_shared_from_this { return func_graph; } // Optimizer step counter; - int counter = 1; + int64_t counter = 1; bool changes = true; while (changes) { @@ -223,7 +223,7 @@ class Optimizer : public std::enable_shared_from_this { void set_enable(bool enable) { is_enable_ = enable; } struct { - int counter; + int64_t counter; std::string name; } CurPass_; diff --git a/mindspore/ccsrc/frontend/optimizer/pattern.cc b/mindspore/ccsrc/frontend/optimizer/pattern.cc index 5c291e811df..6d82c12d82a 100644 --- a/mindspore/ccsrc/frontend/optimizer/pattern.cc +++ b/mindspore/ccsrc/frontend/optimizer/pattern.cc @@ -19,7 +19,7 @@ namespace mindspore { namespace opt { namespace python_pass { -int Pattern::g_id_ = 0; +int64_t Pattern::g_id_ = 0; MatchResultPtr Prim::match(const AnfNodePtr &node) { if (!IsValueNode(node)) { @@ -169,7 +169,7 @@ REGISTER_PYBIND_DEFINE( .def(py::init()); (void)py::class_, Pattern>(*m, "NewParameter_") .def(py::init()); - (void)py::class_, Pattern>(*m, "Imm").def(py::init()); + (void)py::class_, Pattern>(*m, "Imm").def(py::init()); })); } // namespace python_pass } // namespace opt diff --git a/mindspore/ccsrc/frontend/optimizer/pattern.h b/mindspore/ccsrc/frontend/optimizer/pattern.h index e4282e6ccd2..cac0233a929 100644 --- a/mindspore/ccsrc/frontend/optimizer/pattern.h +++ b/mindspore/ccsrc/frontend/optimizer/pattern.h @@ -62,7 +62,7 @@ class Pattern : public Base { static void reset_gid() { g_id_ = 0; } protected: - static int g_id_; + static int64_t g_id_; // NOTE: To ensure uniqueness of the name, raise g_id_ by 1 every time a pattern got constructed string unique_name_; vector inputs_; @@ -251,7 +251,7 @@ class Imm : public Pattern { int value() { return value_; } private: - int value_; + int64_t value_; }; class MatchResult { diff --git a/mindspore/ccsrc/frontend/optimizer/py_pass.cc b/mindspore/ccsrc/frontend/optimizer/py_pass.cc index 8fc14ca885e..05cc2f7518f 100644 --- a/mindspore/ccsrc/frontend/optimizer/py_pass.cc +++ b/mindspore/ccsrc/frontend/optimizer/py_pass.cc @@ -91,7 +91,7 @@ AnfNodePtr BuildNewParameter(const PatternPtr &pattern, const MatchResultPtr &re auto new_para_pattern = pattern->cast(); MS_EXCEPTION_IF_NULL(new_para_pattern); if (!new_para_pattern->built()) { - static int parameter_id = 0; + static int64_t parameter_id = 0; auto para_name = new_para_pattern->para_name() + new_para_pattern->unique_name() + std::to_string(parameter_id++); auto para_node = std::make_shared(top_graph); MS_EXCEPTION_IF_NULL(para_node); @@ -125,7 +125,7 @@ AnfNodePtr BuildImmNode(const PatternPtr &pattern, const MatchResultPtr &res) { auto imm_pattern = pattern->cast(); MS_EXCEPTION_IF_NULL(imm_pattern); auto value = imm_pattern->value(); - auto scalar_value_ptr = std::make_shared(value); + auto scalar_value_ptr = std::make_shared(value); return std::make_shared(scalar_value_ptr); } diff --git a/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.cc b/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.cc index 927bb2e73b6..8b5e786e77c 100644 --- a/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.cc +++ b/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.cc @@ -28,7 +28,7 @@ namespace mindspore { namespace parallel { -std::unordered_set FindCNodesWithPara(const AnfNodePtr ¶, uint32_t recursive_times = 0) { +std::unordered_set FindCNodesWithPara(const AnfNodePtr ¶, uint64_t recursive_times = 0) { if (recursive_times > MAX_RECURSIVE_CALL_TIMES) { MS_LOG(EXCEPTION) << "FindCNodesWithPara exceeds max recursive call times! Max recursive call times is " << MAX_RECURSIVE_CALL_TIMES; @@ -83,7 +83,7 @@ Status AllreduceFusion::AddNodeToGraph() { return SUCCESS; } -CNodeCostMap AllreduceFusion::FindCNode(const AnfNodePtr &from, uint32_t recursive_times) const { +CNodeCostMap AllreduceFusion::FindCNode(const AnfNodePtr &from, uint64_t recursive_times) const { if (recursive_times > MAX_RECURSIVE_CALL_TIMES) { MS_LOG(EXCEPTION) << "FindCNode exceeds max recursive call times! Max recursive call times is " << MAX_RECURSIVE_CALL_TIMES; @@ -124,7 +124,7 @@ CNodeCostMap AllreduceFusion::FindCNode(const AnfNodePtr &from, uint32_t recursi return cnode_dist; } -CNodeCostMap AllreduceFusion::FindNextCNodes(const CNodePtr &from, uint32_t recursive_times) const { +CNodeCostMap AllreduceFusion::FindNextCNodes(const CNodePtr &from, uint64_t recursive_times) const { if (recursive_times > MAX_RECURSIVE_CALL_TIMES) { MS_LOG(EXCEPTION) << "FindNextCNodes exceeds max recursive call times! Max recursive call times is " << MAX_RECURSIVE_CALL_TIMES; @@ -142,7 +142,7 @@ CNodeCostMap AllreduceFusion::FindNextCNodes(const CNodePtr &from, uint32_t recu } Status AllreduceFusion::AddEdgeToGraph() { - std::unordered_map cnode_state_map; + std::unordered_map cnode_state_map; const auto &cnodes = allreduce_graph_.cnode_set(); for (auto &cnode : cnodes) { cnode_state_map[cnode] = 0; @@ -174,7 +174,7 @@ Status AllreduceFusion::AddEdgeToGraph() { return SUCCESS; } -std::vector FindMirror(const AnfNodePtr ¶, uint32_t recursive_times = 0) { +std::vector FindMirror(const AnfNodePtr ¶, uint64_t recursive_times = 0) { if (recursive_times > MAX_RECURSIVE_CALL_TIMES) { MS_LOG(EXCEPTION) << "FindMirror exceeds max recursive call times! Max recursive call times is " << MAX_RECURSIVE_CALL_TIMES; @@ -211,24 +211,24 @@ std::vector FindMirror(const AnfNodePtr ¶, uint32_t recursive_time return cnode_list; } -void SetMirrorFusion(const CNodePtr &mirror_cnode, int32_t fusion, const std::string ¶meter_name) { +void SetMirrorFusion(const CNodePtr &mirror_cnode, int64_t fusion, const std::string ¶meter_name) { MS_EXCEPTION_IF_NULL(mirror_cnode); MS_LOG(DEBUG) << "Set Mirror " << mirror_cnode->DebugString() << " fusion " << fusion; auto node_prim = GetValueNode(mirror_cnode->input(0)); auto old_value_ptr = node_prim->GetAttr(FUSION); if (old_value_ptr != nullptr) { - if (old_value_ptr->isa()) { - int32_t old_value = old_value_ptr->cast()->value(); + if (old_value_ptr->isa()) { + int64_t old_value = old_value_ptr->cast()->value(); if (old_value < fusion) { return; } } } - (void)node_prim->AddAttr(FUSION, MakeValue(std::make_shared(fusion))); + (void)node_prim->AddAttr(FUSION, MakeValue(std::make_shared(fusion))); (void)node_prim->AddAttr(PARAMETER, MakeValue(std::make_shared(parameter_name))); } -Status FindMirrorAndSetFusion(const AnfNodePtr ¶, int32_t fusion) { +Status FindMirrorAndSetFusion(const AnfNodePtr ¶, int64_t fusion) { auto mirror_cnodes = FindMirror(para); if (mirror_cnodes.empty()) { MS_LOG(WARNING) << para->ToString() << " 0 Mirror CNode found."; @@ -251,7 +251,7 @@ Status FindMirrorAndSetFusion(const AnfNodePtr ¶, int32_t fusion) { return SUCCESS; } -Status FindMirrorAndSetFusion(const std::vector ¶s, int32_t fusion) { +Status FindMirrorAndSetFusion(const std::vector ¶s, int64_t fusion) { for (auto ¶m_node : paras) { if (FindMirrorAndSetFusion(param_node, fusion) != SUCCESS) { MS_LOG(ERROR) << "FindMirrorAndSetFusion failed"; @@ -266,7 +266,7 @@ Status AllreduceFusion::SetFusion(const std::vector &cost_map) { MS_LOG(ERROR) << "cost_map must has at least 2 items, cost_map size is " << cost_map.size(); return FAILED; } - int32_t fusion = 1; + int64_t fusion = 1; for (auto cost_iter = cost_map.end() - 1; cost_iter != cost_map.begin(); --cost_iter) { auto paras = allreduce_graph_.GetParaByCost(*(cost_iter - 1), *cost_iter); if (FindMirrorAndSetFusion(paras, fusion) != SUCCESS) { @@ -278,7 +278,7 @@ Status AllreduceFusion::SetFusion(const std::vector &cost_map) { return SUCCESS; } -std::vector AllreduceFusion::GenerateCostMap(int32_t fusion_times, double tail_percent) const { +std::vector AllreduceFusion::GenerateCostMap(int64_t fusion_times, double tail_percent) const { double offset = allreduce_graph_.max() * (1 - tail_percent) / (fusion_times - 1); MS_LOG(DEBUG) << "max = " << allreduce_graph_.max() << ", offset = " << offset; std::vector cost_map; @@ -361,7 +361,7 @@ Status AllreduceFusion::SetFusionByBackwardCompAndAllreduceTime() { } double para_size = (tail_time_ - allreduce_inherent_time_) / allreduce_bandwidth_; double to_cost = allreduce_graph_.max(); - int32_t fusion = 1; + int64_t fusion = 1; while (to_cost != 0) { MS_LOG(INFO) << "to_cost: " << to_cost << " para_size: " << para_size; auto node_cost_pair = allreduce_graph_.GetParaByParaSize(to_cost, para_size); @@ -380,7 +380,7 @@ Status AllreduceFusion::SetFusionByBackwardCompAndAllreduceTime() { return SUCCESS; } -Status AllreduceFusion::SetFusionByAlgorithm(int32_t algorithm) { +Status AllreduceFusion::SetFusionByAlgorithm(int64_t algorithm) { if (algorithm == 1) { return SetFusionByBackwardCompTime(); } diff --git a/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.h b/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.h index 83bc46c9213..a1cb6fe15ca 100644 --- a/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.h +++ b/mindspore/ccsrc/frontend/parallel/allreduce_fusion/allreduce_fusion.h @@ -28,8 +28,8 @@ namespace mindspore { namespace parallel { using CNodeCostMap = std::unordered_map; -constexpr int32_t DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALGORITHM = 0; -constexpr int32_t DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TIMES = 0; +constexpr int64_t DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALGORITHM = 0; +constexpr int64_t DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TIMES = 0; constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TAIL_PERCENT = 0.1; constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_TAIL_TIME = 0.1; constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALLREDUCE_INHERENT_TIME = 0.1; @@ -37,7 +37,7 @@ constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_ALLREDUCE_BANDWIDTH = 0.1; constexpr double DEFAULT_COST_MODEL_ALLREDUCE_FUSION_COMPUTATION_TIME_PARAMETER = 0.1; constexpr char PARAMETER[] = "parameter"; -const uint32_t MAX_RECURSIVE_CALL_TIMES = 100; +const uint64_t MAX_RECURSIVE_CALL_TIMES = 100; class AllreduceFusion { public: AllreduceFusion() @@ -54,12 +54,12 @@ class AllreduceFusion { private: Status AddNodeToGraph(); - CNodeCostMap FindCNode(const AnfNodePtr &from, uint32_t recursive_times = 0) const; - CNodeCostMap FindNextCNodes(const CNodePtr &from, uint32_t recursive_times = 0) const; + CNodeCostMap FindCNode(const AnfNodePtr &from, uint64_t recursive_times = 0) const; + CNodeCostMap FindNextCNodes(const CNodePtr &from, uint64_t recursive_times = 0) const; Status AddEdgeToGraph(); - std::vector GenerateCostMap(int32_t fusion_times, double tail_percent) const; + std::vector GenerateCostMap(int64_t fusion_times, double tail_percent) const; Status SetFusion(const std::vector &cost_map); - Status SetFusionByAlgorithm(int32_t algorithm); + Status SetFusionByAlgorithm(int64_t algorithm); Status SetFusionByBackwardCompTime(); Status SetFusionByBackwardCompAndAllreduceTime(); Status GetSetFusionByBackwardCompAndAllreduceTimeParams(); diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/costmodel.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/costmodel.h index ea0b3a73e1e..14aaa265a22 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/costmodel.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/costmodel.h @@ -30,12 +30,12 @@ namespace parallel { struct Decision; using OperatorName = std::string; using Attr = std::pair; -using Param = std::pair, int32_t>; +using Param = std::pair, int64_t>; using OperatorParams = std::vector; using OperatorAttrs = std::vector; // OutPutInfo.fist: true if the operator's output is a tuple // OutPutInfo.second: elements number of the tuple output. Only meaningful if OutPutInfo.fist is true. -using OutPutInfo = std::pair; +using OutPutInfo = std::pair; using OutPutInfoVector = std::vector; using OperatorArgs = std::pair; using Operator = std::pair; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/edge_costmodel.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/edge_costmodel.h index 0a4e2967ecc..e70d23e065e 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/edge_costmodel.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/edge_costmodel.h @@ -132,7 +132,7 @@ class Edge { void set_selected_cost(const CostPtr &cost) { selected_cost_ = cost; } const CostPtr &selected_cost() const { return selected_cost_; } - void set_parameter_involve(int para_invol) { is_output_parameter_involve_ = para_invol; } + void set_parameter_involve(int64_t para_invol) { is_output_parameter_involve_ = para_invol; } // In the training phase, when the input of a operator contains WEIGHT or a output from other operators involving // WEIGHT, then these input should stay in memory until it is used in the backward phase, which is kept in memory // at the end of forward phase. @@ -166,9 +166,9 @@ class Edge { CostPtr selected_cost_; // In the training phase, 'is_output_parameter_involve_' is used to mark whether the output of the previous operator // is parameter-involved - int is_output_parameter_involve_ = -1; // -1: unset; 0: not parameter_involved; 1: parameter_involved + int64_t is_output_parameter_involve_ = -1; // -1: unset; 0: not parameter_involved; 1: parameter_involved // In the inference phase, this is used to mark whether the output of the previous operator is critical. - int is_output_critical_ = 0; + int64_t is_output_critical_ = 0; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.cc b/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.cc index 66b50e3a4b3..e3b9d7f9c17 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.cc +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.cc @@ -39,7 +39,7 @@ size_t TENSOR_SLICE_ALIGNMENT_SIZE = DEFAULT_TENSOR_SLICE_ALIGNMENT_SIZE; bool FULLY_USE_DEVICES = DEFAULT_FULLY_USE_DEVICES; bool ELEMENTWISE_OP_STRA_FOLLOW = DEFAULT_ELEMENTWISE_OP_STRA_FOLLOW; bool MULTI_SUBGRAPHS = DEFAULT_IS_MULTI_SUBGRAPHS; -int32_t RUN_PHASE = DEFAULT_RUN_PHASE; +int64_t RUN_PHASE = DEFAULT_RUN_PHASE; bool TRIANGLE_STAR_STRATEGY_OVERWRITE = DEFAULT_TRIANGLE_STAR_STRATEGY_OVERWRITE; bool DP_ALGO_ENABLE_APPROX = DEFAULT_DP_ALGO_ENABLE_APPROX; double DP_ALGO_APPROX_EPSILON = DEFAULT_DP_ALGO_APPROX_EPSILON; @@ -761,7 +761,7 @@ std::vector> CostGraph::CheckEdgeElimination() const { for (auto &op : ops_) { MS_EXCEPTION_IF_NULL(op); if (!op->is_alive()) continue; - std::map count; + std::map count; for (auto &edge : op->GetAliveSuccEdges()) { MS_EXCEPTION_IF_NULL(edge); auto v = edge->next_operator(); @@ -769,7 +769,7 @@ std::vector> CostGraph::CheckEdgeElimination() const { } for (auto &pair : count) { auto *op_ptr = pair.first; - int op_count = pair.second; + int64_t op_count = pair.second; if (op_count > 1) { std::vector> ret; for (auto &edge : op->GetAliveSuccEdges()) { @@ -1608,7 +1608,7 @@ Status CostGraph::InitReshapeStrategy() { } if (pre_iter != in_edges.end() || reshape_is_first_op) { MS_LOG(DEBUG) << "Set reshape input layout by " << reshape_info->pre_operator_name(); - int32_t pre_index = reshape_info->pre_operator_index(); + int64_t pre_index = reshape_info->pre_operator_index(); TensorInfo pre_info; std::shared_ptr pre_op_info; if (reshape_is_first_op) { @@ -1632,7 +1632,7 @@ Status CostGraph::InitReshapeStrategy() { } if (next_iter != out_edges.end()) { MS_LOG(DEBUG) << "Set reshape output layout by " << reshape_info->next_operator_name(); - int32_t next_index = reshape_info->next_operator_index(); + int64_t next_index = reshape_info->next_operator_index(); reshape_info->SetOutputLayout((*next_iter)->next_operator()->inputs_tensor_info()[next_index].tensor_layout()); } if (reshape_info->Init(nullptr) != SUCCESS) { @@ -1698,7 +1698,7 @@ void CostGraph::TopologyOrder(std::vector *topo_order) { } } } -void CostGraph::MarkCriticalOpsAndEdges(const std::map &candidate_ops) { +void CostGraph::MarkCriticalOpsAndEdges(const std::map &candidate_ops) { for (auto &op : ops_) { auto search = candidate_ops.find(op); if (search != candidate_ops.end()) { @@ -1728,9 +1728,9 @@ Status CostGraph::DetermineCriticalOps(const std::vector &topo_ } // The 'curr_memory_state' records , where remaining_output_cnt is the number // of the output of OperatorInfo that currently has not been used - std::map curr_memory_state; - (void)curr_memory_state.emplace(std::make_pair(first_op, SizeToInt(first_op->succ_edges().size()))); - std::map max_memory_state = curr_memory_state; + std::map curr_memory_state; + (void)curr_memory_state.emplace(std::make_pair(first_op, SizeToLong(first_op->succ_edges().size()))); + std::map max_memory_state = curr_memory_state; // The 'curr_memory_size' records the current total memory size, which is the sum of outputs of operators that has // not been used double curr_memory_size = first_op->GetOutputsTotalSize(); @@ -1739,7 +1739,7 @@ Status CostGraph::DetermineCriticalOps(const std::vector &topo_ for (size_t finished = 1; finished < topo_order.size(); ++finished) { // Produce (void)curr_memory_state.emplace( - std::make_pair(topo_order[finished], SizeToInt(topo_order[finished]->succ_edges().size()))); + std::make_pair(topo_order[finished], SizeToLong(topo_order[finished]->succ_edges().size()))); curr_memory_size += topo_order[finished]->GetOutputsTotalSize(); // Consume for (const auto &prev_edge : topo_order[finished]->prev_edges()) { @@ -1849,7 +1849,7 @@ Status CostGraph::CorrectOpsMemoryCost() { if ((one_op->name().find(IDENTITY_INFO) != std::string::npos) && (one_op->is_output_parameter_involve() == 1)) { if (one_op->GetAliveSuccEdges().size() > 1) { // Filter out the case when the TmpIdentity being used by multiple operators - std::map output_count; + std::map output_count; for (size_t i = 0; i < one_op->GetAliveSuccEdges().size(); ++i) { auto output_index = one_op->GetAliveSuccEdges()[i]->prev_op_output_index(); output_count[output_index]++; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h index de95a3ae92f..4547ab290ea 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h @@ -47,7 +47,7 @@ extern bool ELEMENTWISE_OP_STRA_FOLLOW; extern bool MULTI_SUBGRAPHS; extern bool DP_ALGO_ENABLE_APPROX; extern double DP_ALGO_APPROX_EPSILON; -extern int32_t RUN_PHASE; +extern int64_t RUN_PHASE; extern bool TRIANGLE_STAR_STRATEGY_OVERWRITE; class CostGraph { @@ -218,7 +218,7 @@ class CostGraph { void TopologyOrder(std::vector *); void DFSForTopoOrder(const OperatorInfoPtr &, std::map *, std::vector *); Status DetermineCriticalOps(const std::vector &); - void MarkCriticalOpsAndEdges(const std::map &); + void MarkCriticalOpsAndEdges(const std::map &); // Needed by rec_parser std::vector> inputs_tensor_name_list_; std::map tuple_getitem_list_; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.cc b/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.cc index 74b3c5aeb6d..a3d22e27f7c 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.cc +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.cc @@ -29,7 +29,7 @@ void OperatorCost::set_is_parameter_involve(const std::vector &is_paramete is_parameter_involve_ = is_parameter_inv; } -void OperatorCost::set_output_parameter_involve(int output_para) { output_parameter_involve_ = output_para; } +void OperatorCost::set_output_parameter_involve(int64_t output_para) { output_parameter_involve_ = output_para; } void OperatorCost::SetInputAndOutputTypeLength(const std::vector &input_lengths, const std::vector &output_lengths) { @@ -37,7 +37,7 @@ void OperatorCost::SetInputAndOutputTypeLength(const std::vector &input_ outputs_type_lengths_ = output_lengths; } -void OperatorCost::set_output_critical(int critical) { is_outputs_critical_ = critical; } +void OperatorCost::set_output_critical(int64_t critical) { is_outputs_critical_ = critical; } double OperatorCost::GetMemoryCost(const std::vector &inputs, const std::vector &outputs) const { @@ -81,7 +81,7 @@ double OperatorCost::GetMemoryCostForInference(const std::vector &, // return the per device communication cost in the forward phase. double MatMulCost::GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t) const { + int64_t) const { TensorInfo input0 = inputs[0]; TensorInfo output0 = outputs[0]; Shape input0_shape = input0.shape(); @@ -97,7 +97,7 @@ double MatMulCost::GetForwardCommCost(const std::vector &inputs, con // return the per device communication cost in the forward phase. double MatMulCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { // In backward phase, the communication cost is incurred only when tensor B is a Parameter and tensor B does not // fully utilize all devices double result = 0.0; @@ -109,12 +109,12 @@ double MatMulCost::GetBackwardCommCost(const std::vector &inputs, co Shape input1_shape = input1.shape(); Shape input1_slice_shape = input1.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input1_shape.size(); ++i) { used_device_num *= input1_shape[i] / input1_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } @@ -124,7 +124,7 @@ double MatMulCost::GetBackwardCommCost(const std::vector &inputs, co // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double MatMulCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t) const { + const std::vector &outputs, int64_t) const { // In forward phase, the compuatation cost = slice(A) + slice(B) + (0 or 1) allreduce(slice(C)) double result = 0.0; TensorInfo output0 = outputs[0]; @@ -143,7 +143,7 @@ double MatMulCost::GetForwardComputationCost(const std::vector &inpu // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double MatMulCost::GetBackwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { // In backward phase, the computation cost = (0 or 1) allreduce(slice(B)) double result = 0.0; if (is_parameter_[1]) { @@ -154,12 +154,12 @@ double MatMulCost::GetBackwardComputationCost(const std::vector &inp Shape input1_shape = input1.shape(); Shape input1_slice_shape = input1.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input1_shape.size(); ++i) { used_device_num *= input1_shape[i] / input1_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } @@ -168,14 +168,14 @@ double MatMulCost::GetBackwardComputationCost(const std::vector &inp // Return the per device communication cost in the forward phase. double ActivationCost::GetForwardCommCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { // ReLU is the element-wise operator, thus it does not need communication in the forward phase return 0.0; } // Return the per device communication cost in the backward phase. double ActivationCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_[0]) { TensorInfo input1 = inputs[0]; @@ -183,11 +183,11 @@ double ActivationCost::GetBackwardCommCost(const std::vector &inputs auto total_device_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); Shape input1_shape = input1.shape(); Shape input1_slice_shape = input1.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input1_shape.size(); ++i) { used_device_num *= input1_shape[i] / input1_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result = ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } } @@ -197,7 +197,7 @@ double ActivationCost::GetBackwardCommCost(const std::vector &inputs // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double ActivationCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { TensorInfo input0 = inputs[0]; Shape input0_slice_shape = input0.slice_shape(); return ListProduct(input0_slice_shape) * static_cast(inputs_type_lengths_[0]); @@ -206,20 +206,20 @@ double ActivationCost::GetForwardComputationCost(const std::vector & // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double ActivationCost::GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { return 0.0; } // Return the per device communication cost in the forward phase. double SoftmaxCost::GetForwardCommCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { // In the forward phase, the communication cost = 0 return 0.0; } // Return the per device communication cost in the backward phase. double SoftmaxCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_[0]) { TensorInfo input1 = inputs[0]; @@ -227,11 +227,11 @@ double SoftmaxCost::GetBackwardCommCost(const std::vector &inputs, c auto total_device_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); Shape input1_shape = input1.shape(); Shape input1_slice_shape = input1.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input1_shape.size(); ++i) { used_device_num *= input1_shape[i] / input1_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result = ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } } @@ -241,7 +241,7 @@ double SoftmaxCost::GetBackwardCommCost(const std::vector &inputs, c // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double SoftmaxCost::GetForwardComputationCost(const std::vector &, const std::vector &outputs, - int32_t) const { + int64_t) const { if (outputs.empty() || outputs_type_lengths_.empty()) { MS_LOG(EXCEPTION) << "The outputs or outputs_type_length is empty"; } @@ -255,20 +255,20 @@ double SoftmaxCost::GetForwardComputationCost(const std::vector &, c // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double SoftmaxCost::GetBackwardComputationCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { return 0.0; } // return the per device communication cost in the forward phase. double TmpIdentityCost::GetForwardCommCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { // Identity is the element-wise operator, thus it does not need communication in the forward phase return 0.0; } // return the per device communication cost in the backward phase. double TmpIdentityCost::GetBackwardCommCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { // Identity is the element-wise operator, thus it does not need communication in the backward phase return 0.0; } @@ -276,7 +276,7 @@ double TmpIdentityCost::GetBackwardCommCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { return 0.0; } @@ -284,7 +284,7 @@ double TmpIdentityCost::GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { return 0.0; } @@ -295,7 +295,7 @@ double TmpIdentityCost::GetMemoryCost(const std::vector &, const std double BatchParallelCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { double cost = 0.0; for (size_t i = 0; i < inputs.size(); ++i) { cost += ListProduct(inputs[i].slice_shape()) * static_cast(inputs_type_lengths_[i]); @@ -305,12 +305,12 @@ double BatchParallelCost::GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { return 0.0; } double BatchParallelCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); @@ -323,11 +323,11 @@ double BatchParallelCost::GetBackwardCommCost(const std::vector &inp TensorInfo input_a_tensor_info = inputs[j]; Shape input_a_shape = input_a_tensor_info.shape(); Shape input_a_slice_shape = input_a_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_a_shape.size(); ++i) { used_device_num *= input_a_shape[i] / input_a_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result += ListProduct(input_a_slice_shape) * static_cast(inputs_type_lengths_[0]); } } @@ -335,14 +335,14 @@ double BatchParallelCost::GetBackwardCommCost(const std::vector &inp return result; } // return the per device communication cost in the forward phase. -double PReLUCost::GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const { +double PReLUCost::GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const { // prelu does not need communication in the forward phase return 0.0; } // return the per device communication cost in the backward phase. double PReLUCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_[1]) { TensorInfo input1 = inputs[1]; @@ -351,11 +351,11 @@ double PReLUCost::GetBackwardCommCost(const std::vector &inputs, con auto total_device_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); Shape input1_shape = input1.shape(); Shape input1_slice_shape = input1.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input1_shape.size(); ++i) { used_device_num *= input1_shape[i] / input1_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result = ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } } @@ -365,7 +365,7 @@ double PReLUCost::GetBackwardCommCost(const std::vector &inputs, con // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double PReLUCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { // In forward phase, the computation cost = slice(A) + slice(B) Shape input0_slice_shape = inputs[0].slice_shape(); Shape input1_slice_shape = inputs[1].slice_shape(); @@ -378,7 +378,7 @@ double PReLUCost::GetForwardComputationCost(const std::vector &input // this operator uses double PReLUCost::GetBackwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { // In backward phase, the computation cost = (0 or 1) allreduce(slice(B)) double result = 0.0; if (is_parameter_[1]) { @@ -389,12 +389,12 @@ double PReLUCost::GetBackwardComputationCost(const std::vector(inputs_type_lengths_[1]); } } @@ -402,14 +402,14 @@ double PReLUCost::GetBackwardComputationCost(const std::vector &, const std::vector &, int32_t) const { +double OneHotCost::GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const { // onehot does not need communication in the forward phase return 0.0; } // return the per device communication cost in the backward phase. double OneHotCost::GetBackwardCommCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { // onehot does not need communication in the backward phase return 0.0; } @@ -417,7 +417,7 @@ double OneHotCost::GetBackwardCommCost(const std::vector &, const st // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double OneHotCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { // In onehot's forward phase, the computation cost = slice(A) Shape input0_slice_shape = inputs[0].slice_shape(); return ListProduct(input0_slice_shape) * static_cast(inputs_type_lengths_[0]); @@ -426,20 +426,20 @@ double OneHotCost::GetForwardComputationCost(const std::vector &inpu // Return the per device computation cost in the backward phase. The cost is calculated according to the bytes // this operator uses double OneHotCost::GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { return 0.0; } // return the per device communication cost in the forward phase. double SoftmaxCrossEntropyWithLogitsCost::GetForwardCommCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { // SoftmaxCrossEntropyWithLogitsCost does not need communication in the forward phase return 0.0; } // return the per device communication cost in the backward phase. double SoftmaxCrossEntropyWithLogitsCost::GetBackwardCommCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { // SoftmaxCrossEntropyWithLogitsCost does not need communication in the backward phase return 0.0; } @@ -447,7 +447,7 @@ double SoftmaxCrossEntropyWithLogitsCost::GetBackwardCommCost(const std::vector< // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double SoftmaxCrossEntropyWithLogitsCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { // In forward phase, the computation cost = slice(A) + slice(B) Shape input0_slice_shape = inputs[0].slice_shape(); Shape input1_slice_shape = inputs[1].slice_shape(); @@ -459,13 +459,13 @@ double SoftmaxCrossEntropyWithLogitsCost::GetForwardComputationCost(const std::v // Return the per device computation cost in the backward phase. The cost is calculated according to the bytes // this operator uses double SoftmaxCrossEntropyWithLogitsCost::GetBackwardComputationCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { return 0.0; } // return the per device communication cost in the forward phase. double ReshapeCost::GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const { + int64_t stage_id) const { CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); RankList dev_list = g_device_manager->GetDeviceListByStageId(stage_id); @@ -481,7 +481,7 @@ double ReshapeCost::GetForwardCommCost(const std::vector &inputs, co // return the per device communication cost in the backward phase. double ReshapeCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_[0]) { TensorInfo input1 = inputs[0]; @@ -489,11 +489,11 @@ double ReshapeCost::GetBackwardCommCost(const std::vector &inputs, c auto total_device_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); Shape input1_shape = input1.shape(); Shape input1_slice_shape = input1.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input1_shape.size(); ++i) { used_device_num *= input1_shape[i] / input1_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result = ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } } @@ -503,7 +503,7 @@ double ReshapeCost::GetBackwardCommCost(const std::vector &inputs, c // Return the per device computation cost in the forward phase. The cost is calculated according to the bytes // this operator uses double ReshapeCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); RankList dev_list = g_device_manager->GetDeviceListByStageId(stage_id); @@ -520,12 +520,12 @@ double ReshapeCost::GetForwardComputationCost(const std::vector &inp // Return the per device computation cost in the backward phase. The cost is calculated according to the bytes // this operator uses double ReshapeCost::GetBackwardComputationCost(const std::vector &, - const std::vector &, int32_t) const { + const std::vector &, int64_t) const { return 0.0; } double ArithmeticCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { double result; result = ListProduct(inputs[0].slice_shape()) * static_cast(inputs_type_lengths_[0]) + ListProduct(inputs[1].slice_shape()) * static_cast(inputs_type_lengths_[1]); @@ -533,7 +533,7 @@ double ArithmeticCost::GetForwardComputationCost(const std::vector & } double ArithmeticCost::GetBackwardComputationCost(const std::vector &inputs, - const std::vector &, int32_t stage_id) const { + const std::vector &, int64_t stage_id) const { double result = 0.0; CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); @@ -543,12 +543,12 @@ double ArithmeticCost::GetBackwardComputationCost(const std::vector TensorInfo input_a_tensor_info = inputs[0]; Shape input_a_shape = input_a_tensor_info.shape(); Shape input_a_slice_shape = input_a_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_a_shape.size(); ++i) { used_device_num *= input_a_shape[i] / input_a_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input_a_slice_shape) * static_cast(inputs_type_lengths_[0]); } @@ -556,19 +556,19 @@ double ArithmeticCost::GetBackwardComputationCost(const std::vector TensorInfo input_b_tensor_info = inputs[1]; Shape input_b_shape = input_b_tensor_info.shape(); Shape input_b_slice_shape = input_b_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_b_shape.size(); ++i) { used_device_num *= input_b_shape[i] / input_b_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input_b_slice_shape) * static_cast(inputs_type_lengths_[1]); } return result; } double ArithmeticCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); @@ -578,12 +578,12 @@ double ArithmeticCost::GetBackwardCommCost(const std::vector &inputs TensorInfo input_a_tensor_info = inputs[0]; Shape input_a_shape = input_a_tensor_info.shape(); Shape input_a_slice_shape = input_a_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_a_shape.size(); ++i) { used_device_num *= input_a_shape[i] / input_a_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input_a_slice_shape) * static_cast(inputs_type_lengths_[0]); } @@ -591,29 +591,29 @@ double ArithmeticCost::GetBackwardCommCost(const std::vector &inputs TensorInfo input_b_tensor_info = inputs[1]; Shape input_b_shape = input_b_tensor_info.shape(); Shape input_b_slice_shape = input_b_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_b_shape.size(); ++i) { used_device_num *= input_b_shape[i] / input_b_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input_b_slice_shape) * static_cast(inputs_type_lengths_[1]); } return result; } -bool IsDataParallel(const Shape &shape, const Shape &slice_shape, int32_t stage_id) { +bool IsDataParallel(const Shape &shape, const Shape &slice_shape, int64_t stage_id) { CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); auto total_device_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); auto strategy0 = shape[0] / slice_shape[0]; - return (total_device_num == IntToSize(strategy0)); + return (total_device_num == LongToSize(strategy0)); } double ReduceMethodCost::GetForwardCommCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { double result = 0.0; TensorInfo input0 = inputs[0]; TensorInfo output0 = outputs[0]; @@ -622,10 +622,10 @@ double ReduceMethodCost::GetForwardCommCost(const std::vector &input if (cross_batch_ && IsDataParallel(input0_shape, input0_slice_shape, stage_id)) { return result; } - std::vector dim_list = input0.reduce_dim(); - std::vector::iterator pos; - pos = std::find_if(dim_list.begin(), dim_list.end(), [input0_shape, input0_slice_shape](int32_t index) { - return input0_shape[IntToSize(index)] != input0_slice_shape[IntToSize(index)]; + std::vector dim_list = input0.reduce_dim(); + std::vector::iterator pos; + pos = std::find_if(dim_list.begin(), dim_list.end(), [input0_shape, input0_slice_shape](int64_t index) { + return input0_shape[LongToSize(index)] != input0_slice_shape[LongToSize(index)]; }); if (pos != dim_list.end()) { result += ListProduct(output0.slice_shape()) * static_cast(outputs_type_lengths_[0]); @@ -635,7 +635,7 @@ double ReduceMethodCost::GetForwardCommCost(const std::vector &input } double ReduceMethodCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_[0]) { TensorInfo input_tensor_info = inputs[0]; @@ -645,12 +645,12 @@ double ReduceMethodCost::GetBackwardCommCost(const std::vector &inpu Shape input_shape = input_tensor_info.shape(); Shape input_slice_shape = input_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_shape.size(); ++i) { used_device_num *= input_shape[i] / input_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) + if (total_device_num != LongToSize(used_device_num)) result += ListProduct(input_slice_shape) * static_cast(inputs_type_lengths_[0]); } @@ -658,17 +658,17 @@ double ReduceMethodCost::GetBackwardCommCost(const std::vector &inpu } double ReduceMethodCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { double result = 0.0; TensorInfo input0 = inputs[0]; TensorInfo output0 = outputs[0]; - std::vector dim_list = input0.reduce_dim(); + std::vector dim_list = input0.reduce_dim(); Shape input0_slice_shape = input0.slice_shape(); Shape input0_shape = input0.shape(); if (!cross_batch_ || !IsDataParallel(input0_shape, input0_slice_shape, stage_id)) { - std::vector::iterator pos; - pos = std::find_if(dim_list.begin(), dim_list.end(), [input0_shape, input0_slice_shape](int32_t index) { - return input0_shape[IntToSize(index)] != input0_slice_shape[IntToSize(index)]; + std::vector::iterator pos; + pos = std::find_if(dim_list.begin(), dim_list.end(), [input0_shape, input0_slice_shape](int64_t index) { + return input0_shape[LongToSize(index)] != input0_slice_shape[LongToSize(index)]; }); if (pos != dim_list.end()) { result += ListProduct(output0.slice_shape()) * static_cast(outputs_type_lengths_[0]); @@ -680,17 +680,17 @@ double ReduceMethodCost::GetForwardComputationCost(const std::vector } double ReduceMeanCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { double result = 0.0; TensorInfo input0 = inputs[0]; TensorInfo output0 = outputs[0]; - std::vector dim_list = input0.reduce_dim(); + std::vector dim_list = input0.reduce_dim(); Shape input0_slice_shape = input0.slice_shape(); Shape input0_shape = input0.shape(); if (!cross_batch_ || !IsDataParallel(input0_shape, input0_slice_shape, stage_id)) { - std::vector::iterator pos; - pos = std::find_if(dim_list.begin(), dim_list.end(), [input0_shape, input0_slice_shape](int32_t index) { - return input0_shape[IntToSize(index)] != input0_slice_shape[IntToSize(index)]; + std::vector::iterator pos; + pos = std::find_if(dim_list.begin(), dim_list.end(), [input0_shape, input0_slice_shape](int64_t index) { + return input0_shape[LongToSize(index)] != input0_slice_shape[LongToSize(index)]; }); if (pos != dim_list.end()) { result += ListProduct(output0.slice_shape()) * static_cast(outputs_type_lengths_[0]) * 2.0; @@ -702,7 +702,7 @@ double ReduceMeanCost::GetForwardComputationCost(const std::vector & } double DropOutCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { if (inputs.empty()) { return 0.0; } @@ -713,14 +713,14 @@ double DropOutCost::GetForwardComputationCost(const std::vector &inp // return the per device communication cost in the forward phase. double GatherV2Cost::GetForwardCommCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { // GatherV2Cost does not need communication in the forward phase return 0.0; } // return the per device communication cost in the backward phase. double GatherV2Cost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); @@ -733,11 +733,11 @@ double GatherV2Cost::GetBackwardCommCost(const std::vector &inputs, TensorInfo input_a_tensor_info = inputs[j]; Shape input_a_shape = input_a_tensor_info.shape(); Shape input_a_slice_shape = input_a_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_a_shape.size(); ++i) { used_device_num *= input_a_shape[i] / input_a_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result += ListProduct(input_a_slice_shape) * static_cast(inputs_type_lengths_[0]); } } @@ -746,7 +746,7 @@ double GatherV2Cost::GetBackwardCommCost(const std::vector &inputs, } double GatherV2Cost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { // In forward phase, the computation cost = slice(A) + slice(B) Shape input0_slice_shape = inputs[0].slice_shape(); Shape input1_slice_shape = inputs[1].slice_shape(); @@ -756,12 +756,12 @@ double GatherV2Cost::GetForwardComputationCost(const std::vector &in } double GatherV2Cost::GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const { + int64_t) const { return 0.0; } double LayerNormCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_.size() != inputs.size()) { MS_LOG(EXCEPTION) << "Invalid parameter size " << is_parameter_.size() << " for layer norm cost"; @@ -778,14 +778,14 @@ double LayerNormCost::GetBackwardCommCost(const std::vector &inputs, TensorInfo tensor_info = inputs[index]; Shape shape = tensor_info.shape(); Shape slice_shape = tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < shape.size(); ++i) { if (slice_shape[i] == 0) { MS_LOG(EXCEPTION) << "Invalid slice shape " << ShapeToString(slice_shape); } used_device_num *= shape[i] / slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result += ListProduct(slice_shape) * static_cast(inputs_type_lengths_[index]); } } @@ -794,7 +794,7 @@ double LayerNormCost::GetBackwardCommCost(const std::vector &inputs, } double LayerNormCost::GetForwardComputationCost(const std::vector &inputs, const std::vector &, - int32_t) const { + int64_t) const { double result = 0.0; if (inputs_type_lengths_.size() != inputs.size()) { MS_LOG(EXCEPTION) << "Invalid inputs type size " << inputs_type_lengths_.size() << " for layer norm cost"; @@ -809,11 +809,11 @@ double LayerNormCost::GetForwardComputationCost(const std::vector &i } double UniqueCost::GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const { + int64_t stage_id) const { return 0.0; } double UniqueCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (is_parameter_[0]) { TensorInfo input = inputs[0]; @@ -822,25 +822,25 @@ double UniqueCost::GetBackwardCommCost(const std::vector &inputs, co auto total_device_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); Shape input_shape = input.shape(); Shape input_slice_shape = input.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_shape.size(); ++i) { used_device_num *= input_shape[i] / input_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result = ListProduct(input_slice_shape) * static_cast(inputs_type_lengths_[0]); } } return result; } double UniqueCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { // In forward phase, the computation cost = slice(A) + slice(B) Shape input_slice_shape = inputs[0].slice_shape(); double result = ListProduct(input_slice_shape) * static_cast(inputs_type_lengths_[0]); return result; } double UniqueCost::GetBackwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { // In backward phase, the computation cost = (0 or 1) allreduce(slice(B)) double result = 0.0; if (is_parameter_[0]) { @@ -851,12 +851,12 @@ double UniqueCost::GetBackwardComputationCost(const std::vector &inp Shape input_shape = input.shape(); Shape input_slice_shape = input.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_shape.size(); ++i) { used_device_num *= input_shape[i] / input_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result += ListProduct(input_slice_shape) * static_cast(inputs_type_lengths_[0]); } } @@ -864,13 +864,13 @@ double UniqueCost::GetBackwardComputationCost(const std::vector &inp } double GatherV2PCost::GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; if (outputs_type_lengths_.size() != outputs.size()) { MS_LOG(EXCEPTION) << "Invalid inputs type size " << inputs_type_lengths_.size() << " for gatherv2 cost"; } // don't split axis - if (strategy_.at(IntToSize(axis_)) == 1) { + if (strategy_.at(LongToSize(axis_)) == 1) { return result; } @@ -886,7 +886,7 @@ double GatherV2PCost::GetForwardCommCost(const std::vector &inputs, } double GatherV2PCost::GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const { + int64_t stage_id) const { double result = 0.0; CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); @@ -899,11 +899,11 @@ double GatherV2PCost::GetBackwardCommCost(const std::vector &inputs, TensorInfo input_a_tensor_info = inputs[j]; Shape input_a_shape = input_a_tensor_info.shape(); Shape input_a_slice_shape = input_a_tensor_info.slice_shape(); - int32_t used_device_num = 1; + int64_t used_device_num = 1; for (size_t i = 0; i < input_a_shape.size(); ++i) { used_device_num *= input_a_shape[i] / input_a_slice_shape[i]; } - if (total_device_num != IntToSize(used_device_num)) { + if (total_device_num != LongToSize(used_device_num)) { result += ListProduct(input_a_slice_shape) * static_cast(inputs_type_lengths_[0]); } } @@ -911,7 +911,7 @@ double GatherV2PCost::GetBackwardCommCost(const std::vector &inputs, } double GatherV2PCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { double result = 0.0; Shape input0_slice_shape = inputs[0].slice_shape(); Shape input1_slice_shape = inputs[1].slice_shape(); @@ -919,7 +919,7 @@ double GatherV2PCost::GetForwardComputationCost(const std::vector &i MS_LOG(EXCEPTION) << "Invalid inputs type size " << inputs_type_lengths_.size() << " for gatherv2 cost"; } // don't split axis - if (strategy_.at(IntToSize(axis_)) == 1) { + if (strategy_.at(LongToSize(axis_)) == 1) { result += ListProduct(input0_slice_shape) * static_cast(inputs_type_lengths_[0]) + ListProduct(input1_slice_shape) * static_cast(inputs_type_lengths_[1]); } else { @@ -932,12 +932,12 @@ double GatherV2PCost::GetForwardComputationCost(const std::vector &i } double GatherV2PCost::GetBackwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t) const { + const std::vector &outputs, int64_t) const { double result = 0.0; Shape input1_slice_shape = inputs[1].slice_shape(); Shape output0_slice_shape = outputs[0].slice_shape(); // don't split axis - if (strategy_.at(IntToSize(axis_)) == 1) { + if (strategy_.at(LongToSize(axis_)) == 1) { result += ListProduct(output0_slice_shape) * static_cast(inputs_type_lengths_[0]); } else { // split axis @@ -951,7 +951,7 @@ double GatherV2PCost::GetBackwardComputationCost(const std::vector & // The forward communication is determined by whether the slice is column split or row split // The number of segments is actually the shape[0] of the output, which is the cost of the AllReduce double UnsortedSegmentSumCost::GetForwardCommCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { TensorInfo input0 = inputs[0]; TensorInfo input1 = inputs[1]; TensorInfo output0 = outputs[0]; @@ -972,7 +972,7 @@ double UnsortedSegmentSumCost::GetForwardCommCost(const std::vector } double UnsortedSegmentSumCost::GetBackwardCommCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { TensorInfo input0 = inputs[0]; TensorInfo input1 = inputs[1]; TensorInfo output0 = outputs[0]; @@ -994,7 +994,7 @@ double UnsortedSegmentSumCost::GetBackwardCommCost(const std::vector return result; } double UnsortedSegmentSumCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t) const { + const std::vector &outputs, int64_t) const { // In forward phase, the computation cost = slice(A) + slice(B) Shape input0_slice_shape = inputs[0].slice_shape(); Shape input1_slice_shape = inputs[1].slice_shape(); @@ -1006,7 +1006,7 @@ double UnsortedSegmentSumCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { TensorInfo input0 = inputs[0]; TensorInfo input1 = inputs[1]; TensorInfo output0 = outputs[0]; @@ -1029,7 +1029,7 @@ double UnsortedSegmentMinCost::GetForwardCommCost(const std::vector } double UnsortedSegmentMinCost::GetBackwardCommCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const { + const std::vector &outputs, int64_t stage_id) const { TensorInfo input0 = inputs[0]; TensorInfo input1 = inputs[1]; TensorInfo output0 = outputs[0]; @@ -1052,7 +1052,7 @@ double UnsortedSegmentMinCost::GetBackwardCommCost(const std::vector return result; } double UnsortedSegmentMinCost::GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t) const { + const std::vector &outputs, int64_t) const { // In forward phase, the computation cost = slice(A) + slice(B) Shape input0_slice_shape = inputs[0].slice_shape(); Shape input1_slice_shape = inputs[1].slice_shape(); diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h index 0b73b077c6f..c517d52ef4d 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h @@ -69,26 +69,26 @@ class OperatorCost { void set_is_parameter(const std::vector &is_parameter); void set_is_parameter_involve(const std::vector &); - void set_output_parameter_involve(int); - void set_output_critical(int); + void set_output_parameter_involve(int64_t); + void set_output_critical(int64_t); void SetInputAndOutputTypeLength(const std::vector &input_lengths, const std::vector &output_lengths); std::vector inputs_type_lengths() const { return inputs_type_lengths_; } std::vector outputs_type_lengths() const { return outputs_type_lengths_; } // per device communication cost virtual double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const = 0; + int64_t stage_id) const = 0; virtual double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const = 0; + int64_t stage_id) const = 0; virtual double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const = 0; + int64_t stage_id) const = 0; // per device computation cost virtual double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const = 0; + int64_t stage_id) const = 0; virtual double GetForwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const = 0; + const std::vector &outputs, int64_t stage_id) const = 0; virtual double GetBackwardComputationCost(const std::vector &inputs, - const std::vector &outputs, int32_t stage_id) const = 0; + const std::vector &outputs, int64_t stage_id) const = 0; // per device PEAK memory cost in a training iteration // Typically, the PEAK memory cost contributed by an operator is its output (if the output is parameter-invovled), // plus necessary inputs. @@ -100,7 +100,7 @@ class OperatorCost { // For each input in 'inputs_', a bool variable is true if the corresponding one is a parameter or a output of // pre-operator that has parameters as input. std::vector is_parameter_involve_; - int output_parameter_involve_ = -1; // -1: unset; 0: not parameter_involved; 1: parameter_involved + int64_t output_parameter_involve_ = -1; // -1: unset; 0: not parameter_involved; 1: parameter_involved // Whether the inputs are related or not? For example, TensorAdd's two inputs are independent (not related), while // Mul's two inputs are dependent (related). bool inputs_related_; @@ -111,7 +111,7 @@ class OperatorCost { std::vector outputs_type_lengths_; // Whether the output is critical, which means that this output is included in calculating peak memory cost // in the inference phase. - int is_outputs_critical_ = -1; + int64_t is_outputs_critical_ = -1; }; using OperatorCostPtr = std::shared_ptr; @@ -124,23 +124,23 @@ class MatMulCost : public OperatorCost { // per device communication cost double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; // per device computation cost double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using MatMulCostPtr = std::shared_ptr; @@ -151,21 +151,21 @@ class ActivationCost : public OperatorCost { ~ActivationCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using ActivationCostPtr = std::shared_ptr; using TransposeCost = ActivationCost; @@ -182,21 +182,21 @@ class SoftmaxCost : public OperatorCost { ~SoftmaxCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t) const override; + int64_t) const override; }; using SoftmaxCostPtr = std::shared_ptr; using TileCost = SoftmaxCost; @@ -215,21 +215,21 @@ class TmpIdentityCost : public OperatorCost { ~TmpIdentityCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; // per device PEAK memory cost in a training iteration double GetMemoryCost(const std::vector &inputs, const std::vector &outputs) const override; }; @@ -242,21 +242,21 @@ class BatchParallelCost : public OperatorCost { ~BatchParallelCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override; + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using BatchParallelCostPtr = std::shared_ptr; @@ -267,25 +267,25 @@ class VirtualDatasetCost : public OperatorCost { ~VirtualDatasetCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } // per device PEAK memory cost in a training iteration @@ -302,27 +302,27 @@ class GeneratorBaseCost : public OperatorCost { ~GeneratorBaseCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } // Inputs vector is empty for generator ops. double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } // Generator ops don't have backward steps. double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } }; @@ -336,23 +336,23 @@ class PReLUCost : public OperatorCost { // per device communication cost double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; // per device computation cost double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using PReLUCostPtr = std::shared_ptr; @@ -364,23 +364,23 @@ class OneHotCost : public OperatorCost { // per device communication cost double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; // per device computation cost double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using OneHotCostPtr = std::shared_ptr; @@ -392,23 +392,23 @@ class SoftmaxCrossEntropyWithLogitsCost : public OperatorCost { // per device communication cost double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; // per device computation cost double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using SoftmaxCrossEntropyWithLogitsCostPtr = std::shared_ptr; @@ -421,27 +421,27 @@ class ReshapeCost : public OperatorCost { // per device communication cost double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; // per device computation cost double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using ReshapeCostPtr = std::shared_ptr; @@ -452,22 +452,22 @@ class ArithmeticCost : public OperatorCost { ~ArithmeticCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override; + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using ArithmeticCostPtr = std::shared_ptr; using BiasAddCost = ArithmeticCost; @@ -480,21 +480,21 @@ class ReduceMethodCost : public OperatorCost { ~ReduceMethodCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &, const std::vector &, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } void set_cross_batch(bool cb) { cross_batch_ = cb; } @@ -511,7 +511,7 @@ class ReduceMeanCost : public ReduceMethodCost { ~ReduceMeanCost() override = default; double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; }; using ReduceMeanCostPtr = std::shared_ptr; @@ -522,27 +522,27 @@ class GetNextCost : public OperatorCost { ~GetNextCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } // Inputs vector is empty for generator ops. double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } // Generator ops don't have backward steps. double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } }; @@ -555,23 +555,23 @@ class DropOutCost : public OperatorCost { ~DropOutCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override; + int64_t) const override; double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } }; @@ -585,19 +585,19 @@ class UnsortedSegmentSumCost : public OperatorCost { ~UnsortedSegmentSumCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override; - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override; + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override; + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override; + int64_t) const override; double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } }; @@ -611,19 +611,19 @@ class UnsortedSegmentMinCost : public OperatorCost { ~UnsortedSegmentMinCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override; - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override; + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override; + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override; + int64_t) const override; double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } }; @@ -637,21 +637,21 @@ class LayerNormCost : public OperatorCost { ~LayerNormCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } - double GetForwardCommCost(const std::vector &, const std::vector &, int32_t) const override { + double GetForwardCommCost(const std::vector &, const std::vector &, int64_t) const override { return 0.0; } - double GetBackwardCommCost(const std::vector &, const std::vector &, int32_t) const override; + double GetBackwardCommCost(const std::vector &, const std::vector &, int64_t) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override; + int64_t) const override; double GetBackwardComputationCost(const std::vector &, const std::vector &, - int32_t) const override { + int64_t) const override { return 0.0; } }; @@ -665,21 +665,21 @@ class UniqueCost : public OperatorCost { ~UniqueCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t) const override; + int64_t) const override; }; using UniqueCostPtr = std::shared_ptr; @@ -691,21 +691,21 @@ class GatherV2Cost : public OperatorCost { ~GatherV2Cost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t) const override; + int64_t) const override; }; using GatherV2CostPtr = std::shared_ptr; @@ -717,26 +717,26 @@ class GatherV2PCost : public OperatorCost { ~GatherV2PCost() override = default; double GetCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardCommCost(inputs, outputs, stage_id) + GetBackwardCommCost(inputs, outputs, stage_id); } double GetForwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardCommCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override { + int64_t stage_id) const override { return GetForwardComputationCost(inputs, outputs, stage_id) + GetBackwardComputationCost(inputs, outputs, stage_id); } double GetForwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t stage_id) const override; + int64_t stage_id) const override; double GetBackwardComputationCost(const std::vector &inputs, const std::vector &outputs, - int32_t) const override; - void set_axis(int32_t axis) { axis_ = axis; } + int64_t) const override; + void set_axis(int64_t axis) { axis_ = axis; } void set_strategy(const Shape &strategy) { strategy_ = strategy; } protected: - int32_t axis_; + int64_t axis_; Shape strategy_; }; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.cc b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.cc index db1c1a025d1..ae6bcfaefba 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.cc +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.cc @@ -79,40 +79,40 @@ double CostRedisWithAdjacentNode(const std::vector> &mode, size_t i_strategy, size_t i_node, double tensor_size, bool search_forward) { double new_redis_cost = 0; - int counter = 0; + int64_t counter = 0; if (search_forward) { - if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_n) != - static_cast(1 / mode[i_node][0])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_n) != + static_cast(1 / mode[i_node][0])) { counter += 1; } - if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_c) != - static_cast(1 / mode[i_node][1])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_c) != + static_cast(1 / mode[i_node][1])) { counter += 1; } - if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_h) != - static_cast(1 / mode[i_node][2])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_h) != + static_cast(1 / mode[i_node][2])) { counter += 1; } - if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_w) != - static_cast(1 / mode[i_node][3])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.outputTensor.str_w) != + static_cast(1 / mode[i_node][3])) { counter += 1; } } else { - if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_n) != - static_cast(1 / mode[2][0])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_n) != + static_cast(1 / mode[2][0])) { counter += 1; } - if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_c) != - static_cast(1 / mode[2][1])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_c) != + static_cast(1 / mode[2][1])) { counter += 1; } - if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_h) != - static_cast(1 / mode[2][2])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_h) != + static_cast(1 / mode[2][2])) { counter += 1; } - if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_w) != - static_cast(1 / mode[2][3])) { + if (static_cast(1 / node_name_to_strategy[i_strategy].second.inputTensor[0].str_w) != + static_cast(1 / mode[2][3])) { counter += 1; } } @@ -132,12 +132,12 @@ double CostRedisWithAdjacentNode(const std::vector> &node_name_to_strategy, const Graph &graph) { - int edge_i = - static_cast(node.apply.arguments[0].tensor_shape.shape_h * node.apply.arguments[0].tensor_str.str_h); - int edge_j = - static_cast(node.apply.arguments[1].tensor_shape.shape_w * node.apply.arguments[1].tensor_str.str_w); - int edge_k = - static_cast(node.apply.arguments[0].tensor_shape.shape_w * node.apply.arguments[0].tensor_str.str_w); + int64_t edge_i = + static_cast(node.apply.arguments[0].tensor_shape.shape_h * node.apply.arguments[0].tensor_str.str_h); + int64_t edge_j = + static_cast(node.apply.arguments[1].tensor_shape.shape_w * node.apply.arguments[1].tensor_str.str_w); + int64_t edge_k = + static_cast(node.apply.arguments[0].tensor_shape.shape_w * node.apply.arguments[0].tensor_str.str_w); std::vector cost_op; std::vector> mode; @@ -171,9 +171,9 @@ StrategyRec CostMatMul::GetOptimalStr(const Graph::NodeType &node, // Get weight for MatMul double CostMatMul::GetMinCostIn(const OperatorRec &op) { - int edge_i = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); - int edge_j = static_cast(op.arguments[1].tensor_shape.shape_w * op.arguments[1].tensor_str.str_w); - int edge_k = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); + int64_t edge_i = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); + int64_t edge_j = static_cast(op.arguments[1].tensor_shape.shape_w * op.arguments[1].tensor_str.str_w); + int64_t edge_k = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); std::vector cost_in; cost_in.push_back(StrConcatDimI(edge_j, edge_k)); @@ -225,26 +225,38 @@ StrategyRec CostConvolution::GetOptimalStr( const Graph &graph, bool channel_partition) { const OperatorRec &op = node.apply; - int input_tensor_h = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); - int input_tensor_w = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); - int input_tensor_n = static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n); - int input_tensor_c = static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); + int64_t input_tensor_h = + static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); + int64_t input_tensor_w = + static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); + int64_t input_tensor_n = + static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n); + int64_t input_tensor_c = + static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); - int tensor_in = input_tensor_h * input_tensor_w * input_tensor_n * input_tensor_c; + int64_t tensor_in = input_tensor_h * input_tensor_w * input_tensor_n * input_tensor_c; - int tensor_filter_h = static_cast(op.arguments[1].tensor_shape.shape_h * op.arguments[1].tensor_str.str_h); - int tensor_filter_w = static_cast(op.arguments[1].tensor_shape.shape_w * op.arguments[1].tensor_str.str_w); - int tensor_filter_n = static_cast(op.arguments[1].tensor_shape.shape_n * op.arguments[1].tensor_str.str_n); - int tensor_filter_c = static_cast(op.arguments[1].tensor_shape.shape_c * op.arguments[1].tensor_str.str_c); + int64_t tensor_filter_h = + static_cast(op.arguments[1].tensor_shape.shape_h * op.arguments[1].tensor_str.str_h); + int64_t tensor_filter_w = + static_cast(op.arguments[1].tensor_shape.shape_w * op.arguments[1].tensor_str.str_w); + int64_t tensor_filter_n = + static_cast(op.arguments[1].tensor_shape.shape_n * op.arguments[1].tensor_str.str_n); + int64_t tensor_filter_c = + static_cast(op.arguments[1].tensor_shape.shape_c * op.arguments[1].tensor_str.str_c); - int tensor_filter = tensor_filter_h * tensor_filter_w * tensor_filter_n * tensor_filter_c; + int64_t tensor_filter = tensor_filter_h * tensor_filter_w * tensor_filter_n * tensor_filter_c; - int output_tensor_h = static_cast(node.tensor_parm.tensor_shape.shape_h * node.tensor_parm.tensor_str.str_h); - int output_tensor_w = static_cast(node.tensor_parm.tensor_shape.shape_w * node.tensor_parm.tensor_str.str_w); - int output_tensor_n = static_cast(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n); - int output_tensor_c = static_cast(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c); + int64_t output_tensor_h = + static_cast(node.tensor_parm.tensor_shape.shape_h * node.tensor_parm.tensor_str.str_h); + int64_t output_tensor_w = + static_cast(node.tensor_parm.tensor_shape.shape_w * node.tensor_parm.tensor_str.str_w); + int64_t output_tensor_n = + static_cast(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n); + int64_t output_tensor_c = + static_cast(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c); - int tensor_out = output_tensor_h * output_tensor_w * output_tensor_n * output_tensor_c; + int64_t tensor_out = output_tensor_h * output_tensor_w * output_tensor_n * output_tensor_c; std::vector cost_op; cost_op.reserve(7); @@ -284,18 +296,19 @@ StrategyRec CostConvolution::GetOptimalStr( double CostConvolution::GetMinCostIn(const Graph::NodeType &node) { const OperatorRec &op = node.apply; - int tensor_in = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h) * - static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n) * - static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w) * - static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); - int tensor_filter = static_cast(op.arguments[1].tensor_shape.shape_h * op.arguments[1].tensor_str.str_h) * - static_cast(op.arguments[1].tensor_shape.shape_n * op.arguments[1].tensor_str.str_n) * - static_cast(op.arguments[1].tensor_shape.shape_w * op.arguments[1].tensor_str.str_w) * - static_cast(op.arguments[1].tensor_shape.shape_c * op.arguments[1].tensor_str.str_c); - int tensor_out = static_cast(node.tensor_parm.tensor_shape.shape_h * node.tensor_parm.tensor_str.str_h) * - static_cast(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n) * - static_cast(node.tensor_parm.tensor_shape.shape_w * node.tensor_parm.tensor_str.str_w) * - static_cast(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c); + int64_t tensor_in = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h) * + static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n) * + static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w) * + static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); + int64_t tensor_filter = + static_cast(op.arguments[1].tensor_shape.shape_h * op.arguments[1].tensor_str.str_h) * + static_cast(op.arguments[1].tensor_shape.shape_n * op.arguments[1].tensor_str.str_n) * + static_cast(op.arguments[1].tensor_shape.shape_w * op.arguments[1].tensor_str.str_w) * + static_cast(op.arguments[1].tensor_shape.shape_c * op.arguments[1].tensor_str.str_c); + int64_t tensor_out = static_cast(node.tensor_parm.tensor_shape.shape_h * node.tensor_parm.tensor_str.str_h) * + static_cast(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n) * + static_cast(node.tensor_parm.tensor_shape.shape_w * node.tensor_parm.tensor_str.str_w) * + static_cast(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c); std::vector cost_in; cost_in.push_back(StrDimB(tensor_filter)); @@ -374,8 +387,8 @@ StrategyRec CostConvolution::ChoseStr(const std::vector &cost_op, Strate StrategyRec CostPooling::GetOptimalStr(const Graph::NodeType &node, const std::vector> &node_name_to_strategy, const Graph &graph) { - int tensor_n = static_cast(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n); - int tensor_c = static_cast(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c); + int64_t tensor_n = static_cast(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n); + int64_t tensor_c = static_cast(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c); std::vector cost_op; std::vector> mode; @@ -541,10 +554,10 @@ StrategyRec CostCommon::GetOptimalStr(const Graph::NodeType &node, const std::vector> &node_name_to_strategy, const Graph &graph) { const OperatorRec &op = node.apply; - int tensor_n = static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n); - int tensor_c = static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); - int tensor_h = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); - int tensor_w = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); + int64_t tensor_n = static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n); + int64_t tensor_c = static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); + int64_t tensor_h = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); + int64_t tensor_w = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); std::vector cost_op; std::vector> mode; @@ -625,10 +638,10 @@ StrategyRec CostCommon::ChoseStr(const std::vector &cost_op, StrategyRec // Get optimal strategy for BatchParallel OPs StrategyRec CostBatchParallel::GetOptimalStr(const Graph::NodeType &node) { const OperatorRec &op = node.apply; - int tensor_n = static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n); - int tensor_c = static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); - int tensor_h = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); - int tensor_w = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); + int64_t tensor_n = static_cast(op.arguments[0].tensor_shape.shape_n * op.arguments[0].tensor_str.str_n); + int64_t tensor_c = static_cast(op.arguments[0].tensor_shape.shape_c * op.arguments[0].tensor_str.str_c); + int64_t tensor_h = static_cast(op.arguments[0].tensor_shape.shape_h * op.arguments[0].tensor_str.str_h); + int64_t tensor_w = static_cast(op.arguments[0].tensor_shape.shape_w * op.arguments[0].tensor_str.str_w); std::vector cost_op; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.h index 563bf4598ae..7e9b20dec98 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_cost.h @@ -48,19 +48,19 @@ class CostMatMul { double GetMinCostIn(const OperatorRec &op); private: - double StrConcatDimI(int32_t a, int32_t b) { + double StrConcatDimI(int64_t a, int64_t b) { cost_in_i_ = (static_cast(a) * static_cast(b)) / 2.0; return cost_in_i_; } - double StrConcatDimJ(int32_t a, int32_t b) { + double StrConcatDimJ(int64_t a, int64_t b) { cost_in_j_ = (static_cast(a) * static_cast(b)) / 2.0; return cost_in_j_; } - double StrReduceDimK(int32_t a, int32_t b) { + double StrReduceDimK(int64_t a, int64_t b) { cost_in_k_ = (static_cast(a) * static_cast(b)) / 2.0; return cost_in_k_; @@ -85,43 +85,43 @@ class CostConvolution { double GetMinCostIn(const Graph::NodeType &node); private: - double StrDimB(int32_t TensorFilter) { + double StrDimB(int64_t TensorFilter) { cost_in_b_ = static_cast((TensorFilter) / 2.0); return cost_in_b_; } - double StrDimI(int32_t TensorIn, int32_t TensorFilter) { + double StrDimI(int64_t TensorIn, int64_t TensorFilter) { cost_in_i_ = static_cast((TensorIn + TensorFilter) / 2.0); return cost_in_i_; } - double StrDimJ(int32_t TensorIn, int32_t TensorFilter) { + double StrDimJ(int64_t TensorIn, int64_t TensorFilter) { cost_in_j_ = static_cast((TensorIn + TensorFilter) / 2.0); return cost_in_j_; } - double StrDimK(int32_t TensorIn) { + double StrDimK(int64_t TensorIn) { cost_in_k_ = static_cast((TensorIn) / 2.0); return cost_in_k_; } - double StrDimDI(int32_t TensorIn, int32_t TensorOut) { + double StrDimDI(int64_t TensorIn, int64_t TensorOut) { cost_in_di_ = static_cast((TensorIn + TensorOut) / 2.0); return cost_in_di_; } - double StrDimDJ(int32_t TensorIn, int32_t TensorOut) { + double StrDimDJ(int64_t TensorIn, int64_t TensorOut) { cost_in_dj_ = static_cast((TensorIn + TensorOut) / 2.0); return cost_in_dj_; } - double StrDimQ(int32_t TensorOut) { + double StrDimQ(int64_t TensorOut) { cost_in_q_ = static_cast((TensorOut) / 2.0); return cost_in_q_; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.cc b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.cc index 2c8469d7d88..85a5813b5b1 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.cc +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.cc @@ -139,14 +139,14 @@ Strategys PrepareOneHot(const std::shared_ptr &graph, const std::vectorattrs().find(AXIS); if (iter != ops[iter_ops]->attrs().end()) { MS_EXCEPTION_IF_NULL(iter->second); - if (iter->second->isa()) { - axis = iter->second->cast()->value(); + if (iter->second->isa()) { + axis = iter->second->cast()->value(); } else { - MS_LOG(EXCEPTION) << ops[iter_ops]->name() << ": The value of axis is not int."; + MS_LOG(EXCEPTION) << ops[iter_ops]->name() << ": The value of axis is not int64_t."; } } if (axis == -1) { @@ -165,12 +165,12 @@ Strategys PrepareOneHot(const std::shared_ptr &graph, const std::vector> &ops, const size_t iter_ops, Dimensions s) { Strategys strategies; - auto axis_input = GetValue(ops[iter_ops]->input_value().at(2)); + auto axis_input = GetValue(ops[iter_ops]->input_value().at(2)); if (axis_input < 0) { - axis_input += SizeToInt(ops[iter_ops]->inputs_tensor_info()[0].shape().size()); + axis_input += SizeToLong(ops[iter_ops]->inputs_tensor_info()[0].shape().size()); } - int32_t axis = axis_input; - if (axis >= SizeToInt(s.size())) { + int64_t axis = axis_input; + if (axis >= SizeToLong(s.size())) { MS_LOG(EXCEPTION) << "Failure: GatherV2' axis out of range."; } s[axis] = 1; @@ -187,9 +187,10 @@ Strategys PrepareGatherV2P(const std::vector> &ops for (size_t i = 0; i < index.size(); i++) { index[i] = i; } - std::sort(index.begin(), index.end(), - [&output_shape](const int &a, const int &b) { return (output_shape[a + 1] > output_shape[b + 1]); }); - std::transform(std::begin(index), std::end(index), std::begin(index), [](int x) { return x + 1; }); + std::sort(index.begin(), index.end(), [&output_shape](const int64_t &a, const int64_t &b) { + return (output_shape[a + 1] > output_shape[b + 1]); + }); + std::transform(std::begin(index), std::end(index), std::begin(index), [](int64_t x) { return x + 1; }); index.insert(index.begin(), 0); Dimensions strategie(output_shape.size(), 1); @@ -206,12 +207,12 @@ Strategys PrepareGatherV2P(const std::vector> &ops } } - auto axis_input = GetValue(ops[iter_ops]->input_value().at(2)); + auto axis_input = GetValue(ops[iter_ops]->input_value().at(2)); if (axis_input < 0) { - axis_input += SizeToInt(ops[iter_ops]->inputs_tensor_info()[0].shape().size()); + axis_input += SizeToLong(ops[iter_ops]->inputs_tensor_info()[0].shape().size()); } - int32_t axis = axis_input; - if (axis >= SizeToInt(s.size())) { + int64_t axis = axis_input; + if (axis >= SizeToLong(s.size())) { MS_LOG(EXCEPTION) << "Failure: GatherV2' axis out of range."; } if (axis == 0) { @@ -250,9 +251,10 @@ Dimensions PrepareGatherV2POutputStrategy(const std::vector output_shape[b + 1]); }); - std::transform(std::begin(index), std::end(index), std::begin(index), [](int x) { return x + 1; }); + std::sort(index.begin(), index.end(), [&output_shape](const int64_t &a, const int64_t &b) { + return (output_shape[a + 1] > output_shape[b + 1]); + }); + std::transform(std::begin(index), std::end(index), std::begin(index), [](int64_t x) { return x + 1; }); index.insert(index.begin(), 0); Dimensions strategie(output_shape.size(), 1); @@ -274,24 +276,24 @@ Dimensions PrepareGatherV2POutputStrategy(const std::vector> &ops, const size_t iter_ops, Dimensions s) { - int32_t axis = 0; + int64_t axis = 0; auto iter = ops[iter_ops]->attrs().find(AXIS); if (iter != ops[iter_ops]->attrs().end()) { MS_EXCEPTION_IF_NULL(iter->second); - if (iter->second->isa()) { - axis = iter->second->cast()->value(); + if (iter->second->isa()) { + axis = iter->second->cast()->value(); } else { - MS_LOG(EXCEPTION) << ops[iter_ops]->name() << " : The value of axis is not int."; + MS_LOG(EXCEPTION) << ops[iter_ops]->name() << " : The value of axis is not int64_t."; } } - int32_t axis_index = axis; + int64_t axis_index = axis; if (axis < 0) { size_t input_dim = ops[iter_ops]->inputs_tensor_info()[0].shape().size(); - axis_index = static_cast(input_dim) + axis; + axis_index = static_cast(input_dim) + axis; } - s[IntToSize(axis_index)] = 1; + s[LongToSize(axis_index)] = 1; Strategys strategies; strategies.push_back(s); @@ -543,7 +545,7 @@ Dimensions PrepareIncomingOperatorInputStrategy(const std::vector> &ops, const int iter_ops) { +Dimensions GetAxisList(const std::vector> &ops, const int64_t iter_ops) { Dimensions axis_list; auto axis_param = ops[iter_ops]->attrs().find(AXIS)->second; std::vector elements; @@ -556,10 +558,10 @@ Dimensions GetAxisList(const std::vector> &ops, co } for (auto &element : elements) { - if (!element->isa()) { + if (!element->isa()) { MS_LOG(EXCEPTION) << "Failure: Dimension indexes is not Int32." << std::endl; } - auto axis = element->cast()->value(); + auto axis = element->cast()->value(); axis_list.push_back(axis); } return axis_list; @@ -614,19 +616,19 @@ Dimensions GetDimList(const std::vector> &ops, con auto input_value = ops[iter_ops]->input_value(); auto input_dim = ops[iter_ops]->inputs_tensor_info()[0].shape().size(); if (input_value.back()->isa()) { - auto attr_axis = GetValue>(input_value.back()); + auto attr_axis = GetValue>(input_value.back()); if (attr_axis.empty()) { for (size_t i = 0; i < input_dim; i++) { - dim_list.push_back(SizeToInt(i)); + dim_list.push_back(SizeToLong(i)); } } else { for (auto &axis : attr_axis) { - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } } - } else if (input_value.back()->isa()) { - int axis = GetValue(input_value.back()); - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + } else if (input_value.back()->isa()) { + int64_t axis = GetValue(input_value.back()); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } else { MS_LOG(EXCEPTION) << "Failure: Axis type is invalid." << std::endl; } @@ -665,19 +667,19 @@ Dimensions GetDimListFromAttrs(const std::vector> auto input_dim = ops[iter_ops]->inputs_tensor_info()[0].shape().size(); MS_EXCEPTION_IF_NULL(iter->second); if (iter->second->isa()) { - auto attr_axis = GetValue>(iter->second); + auto attr_axis = GetValue>(iter->second); if (attr_axis.empty()) { for (size_t i = 0; i < input_dim; ++i) { - dim_list.push_back(SizeToInt(i)); + dim_list.push_back(SizeToLong(i)); } } else { for (auto &axis : attr_axis) { - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } } - } else if (iter->second->isa()) { - int axis = GetValue(iter->second); - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + } else if (iter->second->isa()) { + int64_t axis = GetValue(iter->second); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } else { MS_LOG(EXCEPTION) << "Axis type is invalid."; } @@ -811,8 +813,8 @@ Dimensions ApplyBroadcast(const std::vector> &ops, size_t first_tensor_dim, size_t second_tensor_dim, bool broadcast_first_tensor) { Dimensions s_empty = {}; Dimensions s_broadcast; - int target_tensor_index = 0; - int refer_tensor_index = 0; + int64_t target_tensor_index = 0; + int64_t refer_tensor_index = 0; size_t target_tensor_dim; size_t refer_tensor_dim; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.h index 0c034edd84f..97bb83dec8e 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_generate_strategy.h @@ -64,7 +64,7 @@ Dimensions CopyIncomingOperatorOutputStrategy(const std::shared_ptr &grap const size_t iter_ops, const size_t iter_graph); Dimensions PrepareIncomingOperatorInputStrategy(const std::vector> &ops, const size_t incoming_op_index); -Dimensions GetAxisList(const std::vector> &ops, const int iter_ops); +Dimensions GetAxisList(const std::vector> &ops, const int64_t iter_ops); Dimensions ModifyStrategyIfSqueezeIncoming(const std::vector> &ops, const size_t incoming_op_index, Dimensions s); bool GetKeepDims(const std::vector> &ops, const size_t iter_ops); diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.cc b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.cc index 106a589ea85..3528529ff92 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.cc +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.cc @@ -28,7 +28,7 @@ namespace mindspore { namespace parallel { -const TensorParam MakeTensor(int n, int c, int h, int w) { +const TensorParam MakeTensor(int64_t n, int64_t c, int64_t h, int64_t w) { TensorParam new_tensor; new_tensor.tensor_type = kFloat32; new_tensor.tensor_shape.shape_n = n; diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.h index d2cb26b6ab0..fd66258fdb9 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_parse_graph.h @@ -141,7 +141,7 @@ const std::map DictOpType{ {ASSIGN_SUB, OperatorType::kRecElmWiseOp}, {"AssignAdd", OperatorType::kRecElmWiseOp}}; -const TensorParam MakeTensor(int n, int c, int h, int w); +const TensorParam MakeTensor(int64_t n, int64_t c, int64_t h, int64_t w); Graph::NodeType MakeNewOperator(const std::vector> &ops, size_t iter_ops); diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_partition.cc b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_partition.cc index ae520470712..0e81c03d918 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_partition.cc +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_partition.cc @@ -203,12 +203,12 @@ Status PartitionForAllDevices(const size_t num_device, const double device_memor MS_EXCEPTION_IF_NULL(graph); // Comopute iter times - int iter_times = static_cast(log2(num_device)); + int64_t iter_times = static_cast(log2(num_device)); if (iter_times > 10) { MS_LOG(EXCEPTION) << "ERROR: Number of iter_times can't be larger than 10."; } // N-cuts loop - for (int loop = 0; loop < iter_times; loop++) { + for (int64_t loop = 0; loop < iter_times; loop++) { // Sort by weights std::vector reorder_node_list = SortByWeight(graph); @@ -254,7 +254,7 @@ Graph::NodeType ApplyStrToTensor(Graph::NodeType Node) { Node.tensor_parm.tensor_str.str_w = Node.apply.str.outputTensor.str_w; // Set input tensors' tersor_parm - for (int i = 0; i < 2; i++) { + for (int64_t i = 0; i < 2; i++) { Node.apply.arguments[i].tensor_str.str_n = Node.apply.str.inputTensor[i].str_n; Node.apply.arguments[i].tensor_str.str_c = Node.apply.str.inputTensor[i].str_c; Node.apply.arguments[i].tensor_str.str_h = Node.apply.str.inputTensor[i].str_h; @@ -275,7 +275,7 @@ Status DevicesMemoryControl(const size_t num_device, const double device_memory, for (uint64_t i_node = 0; i_node < iter_nodes; i_node++) { if (graph->nodes[i_node].info == 0) { Graph::NodeType &Node = graph->nodes[i_node]; - for (int index = 0; index < 2; index++) { + for (int64_t index = 0; index < 2; index++) { used_memory += Node.apply.arguments[index].tensor_str.str_n * Node.apply.arguments[index].tensor_shape.shape_n * Node.apply.arguments[index].tensor_str.str_c * Node.apply.arguments[index].tensor_shape.shape_c * Node.apply.arguments[index].tensor_str.str_h * Node.apply.arguments[index].tensor_shape.shape_h * @@ -296,7 +296,7 @@ Status DevicesMemoryControl(const size_t num_device, const double device_memory, size_t GetDataTypeSize(const TensorType &type) { switch (type) { case kInt8: - return sizeof(int); + return sizeof(int64_t); case kFloat16: return sizeof(float) / 2; case kFloat32: diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_strategy.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_strategy.h index 4d8ef9c8bdb..268b0ea06ba 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_strategy.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_strategy.h @@ -31,7 +31,7 @@ struct TensorStr4D { struct StrategyRec { TensorStr4D inputTensor[MAX_INPUT_NUM]; TensorStr4D outputTensor; - int32_t cut_counter = 0; + int64_t cut_counter = 0; double cost = 0; }; } // namespace parallel diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_tensor.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_tensor.h index 315c52c867b..29ff32214c3 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_tensor.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/rec_core/rec_tensor.h @@ -24,10 +24,10 @@ namespace parallel { enum TensorType { kInt8, kFloat16, kFloat32, kDouble64 }; struct Shape4D { - int32_t shape_n = 1; - int32_t shape_c = 1; - int32_t shape_h = 1; - int32_t shape_w = 1; + int64_t shape_n = 1; + int64_t shape_c = 1; + int64_t shape_h = 1; + int64_t shape_w = 1; }; struct TensorParam { diff --git a/mindspore/ccsrc/frontend/parallel/context.cc b/mindspore/ccsrc/frontend/parallel/context.cc index 57b1f96305b..a9c2b3efffb 100644 --- a/mindspore/ccsrc/frontend/parallel/context.cc +++ b/mindspore/ccsrc/frontend/parallel/context.cc @@ -67,12 +67,12 @@ void ParallelContext::Reset() { pipeline_stage_split_num_ = 0; } -void ParallelContext::set_device_num(int32_t device_num) { +void ParallelContext::set_device_num(int64_t device_num) { device_num_ = device_num; device_num_is_set_ = true; } -void ParallelContext::set_global_rank(int32_t global_rank) { +void ParallelContext::set_global_rank(int64_t global_rank) { global_rank_ = global_rank; global_rank_is_set_ = true; } @@ -85,9 +85,9 @@ void ParallelContext::set_gradient_fp32_sync(bool gradient_fp32_sync) { gradient void ParallelContext::set_loss_repeated_mean(bool loss_repeated_mean) { loss_repeated_mean_ = loss_repeated_mean; } -void ParallelContext::set_pipeline_stage_split_num(const int32_t stage_num) { pipeline_stage_split_num_ = stage_num; } +void ParallelContext::set_pipeline_stage_split_num(const int64_t stage_num) { pipeline_stage_split_num_ = stage_num; } -void ParallelContext::set_stage(const std::vector &stages) { stages_ = stages; } +void ParallelContext::set_stage(const std::vector &stages) { stages_ = stages; } bool ParallelContext::set_parallel_mode(const std::string ¶llel_mode) { auto iter = std::find(PARALLEL_MODE_LIST.begin(), PARALLEL_MODE_LIST.end(), parallel_mode); @@ -187,10 +187,7 @@ void ParallelParameterContextCkptInTraining(const FuncGraphPtr &func_graph, cons return; } - std::vector shape_int = dyn_cast(ptr->GetShapeTrack())->shape(); - Shape shape; - (void)std::transform(shape_int.begin(), shape_int.end(), std::back_inserter(shape), - [](const int &value) { return static_cast(value); }); + std::vector shape = dyn_cast(ptr->GetShapeTrack())->shape(); auto ret = param_shapes.try_emplace(param_node->name(), shape); if (!ret.second) { MS_LOG(EXCEPTION) << "The shape for parameter name " << param_node->name() << " is existed"; diff --git a/mindspore/ccsrc/frontend/parallel/context.h b/mindspore/ccsrc/frontend/parallel/context.h index 4e71b0d0947..3d74d370a89 100644 --- a/mindspore/ccsrc/frontend/parallel/context.h +++ b/mindspore/ccsrc/frontend/parallel/context.h @@ -64,17 +64,17 @@ class ParallelContext { void set_loss_repeated_mean(bool loss_repeated_mean); bool loss_repeated_mean() const { return loss_repeated_mean_; } - void set_device_num(int32_t device_num); - int32_t device_num() const { return device_num_; } + void set_device_num(int64_t device_num); + int64_t device_num() const { return device_num_; } - void set_pipeline_stage_split_num(const int32_t stages); - int32_t pipeline_stage_split_num() const { return pipeline_stage_split_num_; } + void set_pipeline_stage_split_num(const int64_t stages); + int64_t pipeline_stage_split_num() const { return pipeline_stage_split_num_; } - void set_stage(const std::vector &stages); - std::vector stage() const { return stages_; } + void set_stage(const std::vector &stages); + std::vector stage() const { return stages_; } - void set_global_rank(int32_t global_rank); - int32_t global_rank() const { return global_rank_; } + void set_global_rank(int64_t global_rank); + int64_t global_rank() const { return global_rank_; } bool set_parallel_mode(const std::string ¶llel_mode); std::string parallel_mode() const { return parallel_mode_; } @@ -117,11 +117,11 @@ class ParallelContext { bool full_batch_; bool gradient_fp32_sync_; bool loss_repeated_mean_; - int32_t device_num_; - int32_t global_rank_; + int64_t device_num_; + int64_t global_rank_; std::string parallel_mode_; std::string strategy_search_mode_; - std::vector stages_; + std::vector stages_; int32_t pipeline_stage_split_num_; bool parameter_broadcast_; bool device_num_is_set_; diff --git a/mindspore/ccsrc/frontend/parallel/costmodel_context.cc b/mindspore/ccsrc/frontend/parallel/costmodel_context.cc index 3f23ac424ad..e769d13decb 100644 --- a/mindspore/ccsrc/frontend/parallel/costmodel_context.cc +++ b/mindspore/ccsrc/frontend/parallel/costmodel_context.cc @@ -100,11 +100,11 @@ void CostModelContext::set_costmodel_communi_const(double cm_communi_const) { void CostModelContext::set_costmodel_communi_bias(double cm_communi_bias) { costmodel_communi_bias_ = cm_communi_bias; } void CostModelContext::set_multi_subgraphs(bool multi_graphs) { is_multi_subgraphs_ = multi_graphs; } -void CostModelContext::set_costmodel_allreduce_fusion_algorithm(int32_t algorithm) { +void CostModelContext::set_costmodel_allreduce_fusion_algorithm(int64_t algorithm) { costmodel_allreduce_fusion_algorithm_ = algorithm; } -void CostModelContext::set_costmodel_allreduce_fusion_times(int32_t allreduce_fusion_times) { +void CostModelContext::set_costmodel_allreduce_fusion_times(int64_t allreduce_fusion_times) { costmodel_allreduce_fusion_times_ = allreduce_fusion_times; } @@ -144,7 +144,7 @@ void CostModelContext::set_triangle_star_strategy_overwrite(bool overwrite) { triangle_star_strategy_overwrite_ = overwrite; } -void CostModelContext::set_run_phase(int32_t phase) { run_phase_ = phase; } +void CostModelContext::set_run_phase(int64_t phase) { run_phase_ = phase; } struct CostRegister { CostRegister() { diff --git a/mindspore/ccsrc/frontend/parallel/costmodel_context.h b/mindspore/ccsrc/frontend/parallel/costmodel_context.h index 04efe224e12..92f961bf51a 100644 --- a/mindspore/ccsrc/frontend/parallel/costmodel_context.h +++ b/mindspore/ccsrc/frontend/parallel/costmodel_context.h @@ -94,11 +94,11 @@ class CostModelContext { void set_multi_subgraphs(bool); bool is_multi_subgraphs() const { return is_multi_subgraphs_; } - void set_costmodel_allreduce_fusion_algorithm(int32_t); - int32_t costmodel_allreduce_fusion_algorithm() const { return costmodel_allreduce_fusion_algorithm_; } + void set_costmodel_allreduce_fusion_algorithm(int64_t); + int64_t costmodel_allreduce_fusion_algorithm() const { return costmodel_allreduce_fusion_algorithm_; } - void set_costmodel_allreduce_fusion_times(int32_t); - int32_t costmodel_allreduce_fusion_times() const { return costmodel_allreduce_fusion_times_; } + void set_costmodel_allreduce_fusion_times(int64_t); + int64_t costmodel_allreduce_fusion_times() const { return costmodel_allreduce_fusion_times_; } void set_costmodel_allreduce_fusion_tail_percent(double); double costmodel_allreduce_fusion_tail_percent() const { return costmodel_allreduce_fusion_tail_percent_; } @@ -140,8 +140,8 @@ class CostModelContext { void set_triangle_star_strategy_overwrite(bool); bool triangle_star_strategy_overwrite() const { return triangle_star_strategy_overwrite_; } - void set_run_phase(int32_t); - int32_t run_phase() const { return run_phase_; } + void set_run_phase(int64_t); + int64_t run_phase() const { return run_phase_; } void set_dp_algo_approxi_epsilon(double); double dp_algo_approxi_epsilon() const { return dp_algo_approxi_epsilon_; } @@ -190,11 +190,11 @@ class CostModelContext { // When APPROXIMATION is enabled in the DP algorithm, the 'epsilon' value used in the APPROXIMATION. double dp_algo_approxi_epsilon_; - int32_t run_phase_; // 0: 'training', 1: 'inference' + int64_t run_phase_; // 0: 'training', 1: 'inference' - int32_t costmodel_allreduce_fusion_algorithm_; + int64_t costmodel_allreduce_fusion_algorithm_; - int32_t costmodel_allreduce_fusion_times_; + int64_t costmodel_allreduce_fusion_times_; double costmodel_allreduce_fusion_tail_percent_; diff --git a/mindspore/ccsrc/frontend/parallel/device.h b/mindspore/ccsrc/frontend/parallel/device.h index c69438b23ef..852d8b16882 100644 --- a/mindspore/ccsrc/frontend/parallel/device.h +++ b/mindspore/ccsrc/frontend/parallel/device.h @@ -29,15 +29,15 @@ class Device { // This class abstract the 'device' information, used in Parallel module. public: Device() : rank_(0) { name_.clear(); } - explicit Device(int32_t rank) : rank_(rank) { name_.clear(); } - Device(std::string name, int32_t rank) : name_(std::move(name)), rank_(rank) {} + explicit Device(int64_t rank) : rank_(rank) { name_.clear(); } + Device(std::string name, int64_t rank) : name_(std::move(name)), rank_(rank) {} ~Device() = default; std::string name() const { return name_; } - int32_t rank() const { return rank_; } + int64_t rank() const { return rank_; } private: std::string name_; - int32_t rank_; + int64_t rank_; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/device_manager.cc b/mindspore/ccsrc/frontend/parallel/device_manager.cc index 5202e038c8c..649ca42efbe 100644 --- a/mindspore/ccsrc/frontend/parallel/device_manager.cc +++ b/mindspore/ccsrc/frontend/parallel/device_manager.cc @@ -28,16 +28,16 @@ namespace mindspore { namespace parallel { DeviceManagerPtr g_device_manager = nullptr; -Stage::Stage(const std::vector &devices, int num, int rank) +Stage::Stage(const std::vector &devices, int64_t num, int64_t rank) : devices_(devices), number_(num), rank_(rank) { gm_ = GroupManager(); } // NOTE: '-1' indicates ERROR -int Stage::global_rank(Group *g) const { return ((g == nullptr) ? rank_ : -1); } +int64_t Stage::global_rank(Group *g) const { return ((g == nullptr) ? rank_ : -1); } -bool InitDevice(int32_t device_num, int32_t global_rank, const std::string &backend, - const std::vector &stage) { +bool InitDevice(int64_t device_num, int64_t global_rank, const std::string &backend, + const std::vector &stage) { if (device_num <= 0) { MS_LOG(ERROR) << "'device_num' must be positive."; return false; @@ -51,7 +51,7 @@ bool InitDevice(int32_t device_num, int32_t global_rank, const std::string &back return false; } // 'device_num_converted' must be the power of 2 - if ((IntToUint(device_num) & IntToUint(device_num - 1)) != 0) { + if ((LongToUlong(device_num) & LongToUlong(device_num - 1)) != 0) { MS_LOG(ERROR) << "'device_num' must be the power of 2."; return false; } @@ -65,12 +65,12 @@ bool InitDevice(int32_t device_num, int32_t global_rank, const std::string &back } RankList devices, stage_map; - for (int i = 0; i < device_num; ++i) { + for (int64_t i = 0; i < device_num; ++i) { devices.push_back(i); } if (stage.size()) { - int32_t summed_value = 0; + int64_t summed_value = 0; for (auto begin = stage.begin(); begin != stage.end(); ++begin) { if (*begin <= 0) { MS_LOG(ERROR) << "The value in the pipeline stages should be positive value"; @@ -109,9 +109,9 @@ void CheckGlobalDeviceManager() { } } -int32_t GetListMemberByIndex(size_t index, const RankList &devices) { +int64_t GetListMemberByIndex(size_t index, const RankList &devices) { size_t i = 0; - int32_t result = 0; + int64_t result = 0; if ((devices.empty()) || (index >= devices.size())) { MS_LOG(EXCEPTION) << "Index is out of the list scope"; } @@ -145,11 +145,11 @@ std::shared_ptr GetListMemberByIndex(size_t index, const std::vector MAX_DEVICE_NUM) { MS_LOG(ERROR) << "The number of 'devices' in a stage must not be greater than " << MAX_DEVICE_NUM; return Status::FAILED; @@ -182,7 +182,7 @@ Status DeviceManager::Init(const RankList &devices, int32_t global_device_rank, return Status::FAILED; } RankList curr_dev_list; - for (int i = 0; i < num_device; ++i) { + for (int64_t i = 0; i < num_device; ++i) { curr_dev_list.push_back(GetListMemberByIndex(global_index, devices)); global_index++; } @@ -191,7 +191,7 @@ Status DeviceManager::Init(const RankList &devices, int32_t global_device_rank, global_index = 0; for (stage_it = stage_map.begin(); stage_it != stage_map.end(); ++stage_it) { - int num_device = *stage_it; + int64_t num_device = *stage_it; if (num_device > MAX_DEVICE_NUM) { MS_LOG(ERROR) << "The number of 'devices' in a stage must be less than " << MAX_DEVICE_NUM; return Status::FAILED; @@ -201,7 +201,7 @@ Status DeviceManager::Init(const RankList &devices, int32_t global_device_rank, return Status::FAILED; } std::vector curr_dev_list; - for (int i = 0; i < num_device; ++i) { + for (int64_t i = 0; i < num_device; ++i) { curr_dev_list.push_back(*GetListMemberByIndex(global_index, devices_)); global_index++; } @@ -226,13 +226,13 @@ Status DeviceManager::Init(const RankList &devices, int32_t global_device_rank, return Status::SUCCESS; } -std::shared_ptr DeviceManager::GetStageById(int32_t stage_id) { +std::shared_ptr DeviceManager::GetStageById(int64_t stage_id) { std::shared_ptr res; - if (IntToSize(stage_id) >= stages_.size()) { + if (LongToSize(stage_id) >= stages_.size()) { MS_LOG(ERROR) << "the 'stage_id': " << stage_id << ", is out of the scope of 'stage_devices_': " << stages_.size(); return res; } - int32_t index = 0; + int64_t index = 0; for (auto &stage : stages_) { if (index == stage_id) return stage; index++; @@ -240,12 +240,12 @@ std::shared_ptr DeviceManager::GetStageById(int32_t stage_id) { return res; } -RankList DeviceManager::GetDeviceListByStageId(int32_t stage_id) const { - if (IntToSize(stage_id) >= stage_devices_.size()) +RankList DeviceManager::GetDeviceListByStageId(int64_t stage_id) const { + if (LongToSize(stage_id) >= stage_devices_.size()) MS_LOG(ERROR) << "the 'stage_id': " << stage_id << ", is out of the scope of 'stage_devices_': " << stage_devices_.size(); RankList res; - int32_t index = 0; + int64_t index = 0; for (auto &stage : stage_devices_) { if (index == stage_id) { return stage; @@ -255,31 +255,31 @@ RankList DeviceManager::GetDeviceListByStageId(int32_t stage_id) const { return res; } -RankList DeviceManager::global_device_list(int32_t stage_id, int32_t rank, int32_t split_num) const { +RankList DeviceManager::global_device_list(int64_t stage_id, int64_t rank, int64_t split_num) const { RankList res; if (split_num <= 0) { return res; } - if (IntToSize(stage_id) >= stage_devices_.size()) { + if (LongToSize(stage_id) >= stage_devices_.size()) { MS_LOG(ERROR) << "the 'stage_id': " << stage_id << ", is out of the scope of 'stage_devices_': " << stage_devices_.size(); return res; } RankList global_list = GetDeviceListByStageId(stage_id); - if (global_list.size() % IntToSize(split_num)) { + if (global_list.size() % LongToSize(split_num)) { MS_LOG(ERROR) << "dev list size(" << global_list.size() << ") can not be divisible by split num: " << stage_id; return res; } - std::vector dev_list; + std::vector dev_list; (void)std::copy(global_list.begin(), global_list.end(), std::back_inserter(dev_list)); size_t index = 0; - size_t slice_size = dev_list.size() / IntToSize(split_num); - for (int32_t i = 0; i < split_num; ++i) { + size_t slice_size = dev_list.size() / LongToSize(split_num); + for (int64_t i = 0; i < split_num; ++i) { bool found = false; - index = slice_size * IntToSize(i); + index = slice_size * LongToSize(i); for (size_t j = 0; j < slice_size; ++j) { if (dev_list[index + j] == rank) { found = true; @@ -298,7 +298,7 @@ RankList DeviceManager::global_device_list(int32_t stage_id, int32_t rank, int32 return res; } -Device DeviceManager::CreateNewDeviceByRank(int32_t rank) const { return Device(rank); } +Device DeviceManager::CreateNewDeviceByRank(int64_t rank) const { return Device(rank); } std::vector DeviceManager::CreateDeviceListByRankList(RankList ranks) { std::vector dev_list; @@ -334,7 +334,7 @@ std::string HashName(const std::string &origin_name) { return std::to_string(std // is '0-1-3-5-7'. std::string DeviceManager::GenerateGroupNameByRanks(RankList ranks) { std::string rank_list_name; - std::vector::iterator it; + std::vector::iterator it; std::sort(ranks.begin(), ranks.end()); // sorted in increasing order for (it = ranks.begin(); it != ranks.end(); ++it) { if (it == ranks.begin()) { @@ -374,7 +374,7 @@ Group DeviceManager::CreateGroup(const std::string &group_name, // Create the group with only the given devices' ranks. Group DeviceManager::CreateGroup(const RankList &dev_ranks) { - std::unordered_set rank_set(dev_ranks.begin(), dev_ranks.end()); + std::unordered_set rank_set(dev_ranks.begin(), dev_ranks.end()); if (dev_ranks.size() != rank_set.size()) { MS_LOG(EXCEPTION) << "Invalid dev ranks(" << dev_ranks << "), it has the Duplicate elements in list"; } diff --git a/mindspore/ccsrc/frontend/parallel/device_manager.h b/mindspore/ccsrc/frontend/parallel/device_manager.h index 09c7d003a6e..504ecb4594f 100644 --- a/mindspore/ccsrc/frontend/parallel/device_manager.h +++ b/mindspore/ccsrc/frontend/parallel/device_manager.h @@ -53,24 +53,24 @@ class Stage { explicit Stage(std::vector devices) : devices_(std::move(devices)), number_(0), rank_(0) { gm_ = GroupManager(); } - Stage(const std::vector &devices, int num, int rank); + Stage(const std::vector &devices, int64_t num, int64_t rank); ~Stage() = default; - int GetStageNum() const { return number_; } + int64_t GetStageNum() const { return number_; } size_t GetDevicesNum() const { return devices_.size(); } std::vector GetDevicesList() { return devices_; } - int global_rank(Group *g) const; + int64_t global_rank(Group *g) const; private: std::vector devices_; - int number_; - int32_t rank_; + int64_t number_; + int64_t rank_; GroupManager gm_; }; // This method is used for initializing the global DeviceManager 'g_device_manager', // arguments including 'device_num' and 'global_rank' -bool InitDevice(int32_t device_num, int32_t global_rank, const std::string &backend, const std::vector &stage); +bool InitDevice(int64_t device_num, int64_t global_rank, const std::string &backend, const std::vector &stage); void CheckGlobalDeviceManager(); @@ -82,27 +82,27 @@ class DeviceManager { DeviceManager() : local_rank_(0), global_rank_(0), stage_num_(0) { gm_ = GroupManager(); } ~DeviceManager() = default; - Status Init(const RankList &devices, int32_t local_device, const RankList &stage_map, const std::string &backend); + Status Init(const RankList &devices, int64_t local_device, const RankList &stage_map, const std::string &backend); static DeviceManager &GetInstance(); - RankList GetDeviceListByStageId(int32_t stage_id) const; - RankList global_device_list(int32_t stage_id, int32_t rank, int32_t split_num) const; + RankList GetDeviceListByStageId(int64_t stage_id) const; + RankList global_device_list(int64_t stage_id, int64_t rank, int64_t split_num) const; - Device CreateNewDeviceByRank(int32_t rank) const; + Device CreateNewDeviceByRank(int64_t rank) const; std::vector CreateDeviceListByRankList(RankList ranks); std::string GenerateGroupNameByRanks(RankList dev_ranks); Group CreateGroup(const std::string &group_name, const std::vector &devices); Group CreateGroup(const RankList &dev_ranks); - std::shared_ptr GetStageById(int32_t stage_id); + std::shared_ptr GetStageById(int64_t stage_id); size_t DeviceNum() const { return devices_.size(); } - int32_t GetStageNum() const { return static_cast(stage_devices_.size()); } + int64_t GetStageNum() const { return static_cast(stage_devices_.size()); } - int32_t global_rank() const { return global_rank_; } + int64_t global_rank() const { return global_rank_; } std::string backend() const { return backend_; } - void set_global_rank(int32_t global_rank) { global_rank_ = global_rank; } + void set_global_rank(int64_t global_rank) { global_rank_ = global_rank; } void Clear(); std::string world_group() const { return gm_.world_group(); } std::string FindRankListNameByHashName(const std::string &hash_name); @@ -110,7 +110,7 @@ class DeviceManager { private: std::vector> devices_; // each stage has a list of devices - std::vector> stage_devices_; + std::vector> stage_devices_; std::shared_ptr device_; std::vector> stages_; GroupManager gm_; @@ -120,9 +120,9 @@ class DeviceManager { std::map rank_to_group_; // the key is rank list, value is hash name std::map group_to_rank_; // the key is hash name, value is rank list - int32_t local_rank_; - int32_t global_rank_; - int32_t stage_num_; + int64_t local_rank_; + int64_t global_rank_; + int64_t stage_num_; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/device_matrix.cc b/mindspore/ccsrc/frontend/parallel/device_matrix.cc index 8533b866700..c403a4ffa19 100644 --- a/mindspore/ccsrc/frontend/parallel/device_matrix.cc +++ b/mindspore/ccsrc/frontend/parallel/device_matrix.cc @@ -29,13 +29,13 @@ namespace mindspore { namespace parallel { -DeviceMatrix::DeviceMatrix(int32_t rank, RankList dev_list, Shape dev_shape) +DeviceMatrix::DeviceMatrix(int64_t rank, RankList dev_list, Shape dev_shape) : rank_(rank), dev_list_(std::move(dev_list)), dev_shape_(std::move(dev_shape)) { - if (!std::any_of(dev_list_.begin(), dev_list_.end(), [rank](int32_t a) { return a == rank; })) { + if (!std::any_of(dev_list_.begin(), dev_list_.end(), [rank](int64_t a) { return a == rank; })) { MS_LOG(EXCEPTION) << "Rank " << rank << " is not in the current stage!"; } - int32_t total = std::accumulate(dev_shape_.begin(), dev_shape_.end(), 1, std::multiplies()); - if (IntToSize(total) != dev_list_.size()) { + int64_t total = std::accumulate(dev_shape_.begin(), dev_shape_.end(), 1, std::multiplies()); + if (LongToSize(total) != dev_list_.size()) { MS_LOG(EXCEPTION) << "Device shape does not match the size of the device list!"; } } @@ -44,7 +44,7 @@ Status DeviceMatrix::CreateGroupList() { size_t size = dev_shape_.size(); RankList group; for (size_t i = 0; i < size; i++) { - Status status = GetDevicesAlongDim(SizeToUint(i), &group); + Status status = GetDevicesAlongDim(SizeToUlong(i), &group); group_list_.push_back(group); if (status == Status::FAILED) { return Status::FAILED; @@ -53,7 +53,7 @@ Status DeviceMatrix::CreateGroupList() { return Status::SUCCESS; } -Status DeviceMatrix::GetDevicesAlongDim(const uint32_t &dim, RankList *devices) { +Status DeviceMatrix::GetDevicesAlongDim(const uint64_t &dim, RankList *devices) { if (dim >= dev_shape_.size()) { MS_LOG(EXCEPTION) << "The dimension " << dim << " is out of the size of the device shape!"; } @@ -66,48 +66,48 @@ Status DeviceMatrix::GetDevicesAlongDim(const uint32_t &dim, RankList *devices) std::vector local_group_list; // lower than dim - int32_t step = 1; - for (uint32_t i = dim + 1; i < dev_shape_.size(); i++) { + int64_t step = 1; + for (uint64_t i = dim + 1; i < dev_shape_.size(); i++) { step = step * dev_shape_[i]; } - int32_t num = *dev_list_.begin(); - for (int32_t i = 0; i < dev_shape_[dim]; i++) { + int64_t num = *dev_list_.begin(); + for (int64_t i = 0; i < dev_shape_[dim]; i++) { group.push_back(num); num += step; } - for (int32_t i = 0; i < step; i++) { + for (int64_t i = 0; i < step; i++) { local_group_list.push_back(group); - (void)std::for_each(group.begin(), group.end(), [](int32_t &a) { a++; }); + (void)std::for_each(group.begin(), group.end(), [](int64_t &a) { a++; }); } // higher than dim step = step * dev_shape_[dim]; - int32_t len = SizeToInt(dev_list_.size()) / step; + int64_t len = SizeToLong(dev_list_.size()) / step; // search rank - int32_t target = rank_; - for (int32_t i = 0; i < len; i++) { + int64_t target = rank_; + for (int64_t i = 0; i < len; i++) { for (RankList &temp : local_group_list) { - if (std::any_of(temp.begin(), temp.end(), [target](int32_t a) { return a == target; })) { + if (std::any_of(temp.begin(), temp.end(), [target](int64_t a) { return a == target; })) { *devices = temp; return Status::SUCCESS; } - (void)std::for_each(temp.begin(), temp.end(), [step](int32_t &a) { a = a + step; }); + (void)std::for_each(temp.begin(), temp.end(), [step](int64_t &a) { a = a + step; }); } } MS_LOG(ERROR) << "Can't find groups for rank" << rank_ << " in device list!"; return Status::FAILED; } -Shape ConvertRankToCoordinate(int32_t rank, const Shape &dev_shape) { +Shape ConvertRankToCoordinate(int64_t rank, const Shape &dev_shape) { Shape dev_coordinate; for (size_t i = 0; i < dev_shape.size(); ++i) { - int32_t size = dev_shape[dev_shape.size() - i - 1]; + int64_t size = dev_shape[dev_shape.size() - i - 1]; if (size == 0) { MS_LOG(EXCEPTION) << "Invalid dev shape: " << ShapeToString(dev_shape); } else { - int32_t index = rank % size; + int64_t index = rank % size; (void)dev_coordinate.insert(dev_coordinate.begin(), index); rank = rank / size; } @@ -120,7 +120,7 @@ Status DeviceMatrix::GetDevicesByTensorMap(const Shape &tensor_map, RankList *ra // -1 means the corresponding dimension is not split. if (element == MAP_NONE) { continue; - } else if ((element < 0) || (IntToSize(element) >= dev_shape_.size())) { + } else if ((element < 0) || (LongToSize(element) >= dev_shape_.size())) { MS_LOG(ERROR) << "create group by tensor map: the tensor map is invalid"; return FAILED; } @@ -147,7 +147,7 @@ Status DeviceMatrix::GetDevicesByTensorMap(const Shape &tensor_map, RankList *ra if (map == MAP_NONE) { continue; } - size_t index = dev_shape_.size() - IntToSize(map) - 1; + size_t index = dev_shape_.size() - LongToSize(map) - 1; if (current_rank_coordinate[index] != tmp_rank_coordinate[index]) { matched = false; break; diff --git a/mindspore/ccsrc/frontend/parallel/device_matrix.h b/mindspore/ccsrc/frontend/parallel/device_matrix.h index bf3bea1f234..9f2648de810 100644 --- a/mindspore/ccsrc/frontend/parallel/device_matrix.h +++ b/mindspore/ccsrc/frontend/parallel/device_matrix.h @@ -26,21 +26,21 @@ namespace mindspore { namespace parallel { -using RankList = std::vector; +using RankList = std::vector; using Shape = std::vector; class DeviceMatrix { public: - DeviceMatrix(int32_t rank, RankList devices, Shape dev_shape); + DeviceMatrix(int64_t rank, RankList devices, Shape dev_shape); DeviceMatrix() = default; ~DeviceMatrix() = default; std::vector group_list() const { return group_list_; } Status CreateGroupList(); Status GetDevicesByTensorMap(const Shape &tensor_map, RankList *rank_list); - Status GetDevicesAlongDim(const uint32_t &dim, RankList *devices); + Status GetDevicesAlongDim(const uint64_t &dim, RankList *devices); private: - int32_t rank_ = -1; + int64_t rank_ = -1; RankList dev_list_; // From low dim to high dim. eg: [D0 D1 D2 D3] Shape dev_shape_; diff --git a/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.cc b/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.cc index b4841a19913..48e3187c3da 100644 --- a/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.cc +++ b/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.cc @@ -69,8 +69,8 @@ AnfNodePtr ValuePtrToAnfNodePtr(const ValuePtr &value_ptr) { return value_node->cast(); } -static std::unordered_map int_tensor_map = {}; -AnfNodePtr CreateInt32Tensor(int32_t value) { +static std::unordered_map int_tensor_map = {}; +AnfNodePtr CreateInt32Tensor(int64_t value) { auto it = int_tensor_map.find(value); if (it != int_tensor_map.end()) { return it->second; @@ -82,13 +82,13 @@ AnfNodePtr CreateInt32Tensor(int32_t value) { return anf_node_ptr; } -AnfNodePtr CreatTypeInt(int32_t value) { +AnfNodePtr CreatTypeInt(int64_t value) { ValuePtr value_ptr = MakeValue(std::make_shared(value)); return ValuePtrToAnfNodePtr(value_ptr); } -AnfNodePtr CreatInt32Imm(int32_t value) { - ValuePtr value_ptr = MakeValue(std::make_shared(value)); +AnfNodePtr CreatInt64Imm(int64_t value) { + ValuePtr value_ptr = MakeValue(std::make_shared(value)); return ValuePtrToAnfNodePtr(value_ptr); } diff --git a/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.h b/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.h index 9309cea2cdb..13ab343f92e 100644 --- a/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.h +++ b/mindspore/ccsrc/frontend/parallel/graph_util/generate_graph.h @@ -37,9 +37,9 @@ std::string GetOpPythonPath(const OperatorName &op_name); // Init python operator Instance ValuePtr CreatOpInstance(const OperatorAttrs &attrs, const OperatorName &op_name, const std::string &instance_name); -AnfNodePtr CreatTypeInt(int32_t value); -AnfNodePtr CreatInt32Imm(int32_t value); -AnfNodePtr CreateInt32Tensor(int32_t value); +AnfNodePtr CreatTypeInt(int64_t value); +AnfNodePtr CreatInt64Imm(int64_t value); +AnfNodePtr CreateInt32Tensor(int64_t value); AnfNodePtr ValuePtrToAnfNodePtr(const ValuePtr &value_ptr); std::string HashInstanceName(const std::string &name); diff --git a/mindspore/ccsrc/frontend/parallel/graph_util/get_parallel_info.cc b/mindspore/ccsrc/frontend/parallel/graph_util/get_parallel_info.cc index 0e626127e95..fcac6abaf77 100644 --- a/mindspore/ccsrc/frontend/parallel/graph_util/get_parallel_info.cc +++ b/mindspore/ccsrc/frontend/parallel/graph_util/get_parallel_info.cc @@ -71,10 +71,10 @@ py::dict GetAllreduceFusion(const FuncGraphPtr &graph) { MS_LOG(EXCEPTION) << "name is not StringImm"; } auto name = name_ptr->cast()->value(); - if (!fusion_ptr->isa()) { - MS_LOG(EXCEPTION) << "fusion is not Int32Imm"; + if (!fusion_ptr->isa()) { + MS_LOG(EXCEPTION) << "fusion is not Int64Imm"; } - int32_t fusion = fusion_ptr->cast()->value(); + int64_t fusion = fusion_ptr->cast()->value(); dict[py::str(name)] = fusion; } return dict; diff --git a/mindspore/ccsrc/frontend/parallel/group_manager.cc b/mindspore/ccsrc/frontend/parallel/group_manager.cc index 5bd019fede9..a57cb3b72ef 100644 --- a/mindspore/ccsrc/frontend/parallel/group_manager.cc +++ b/mindspore/ccsrc/frontend/parallel/group_manager.cc @@ -37,7 +37,7 @@ Status Group::Init(const std::string &name, const std::vector &devices) std::vector Group::GetDevicesList() const { return devices_; } -bool Group::IsInThisGroup(int32_t device_rank) { +bool Group::IsInThisGroup(int64_t device_rank) { for (auto &device : devices_) { if (device.rank() == device_rank) { return true; @@ -50,7 +50,7 @@ bool Group::IsInThisGroup(int32_t device_rank) { Status Group::GetIndex(size_t *index) { size_t pos = 0; CheckGlobalDeviceManager(); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); for (auto &device : devices_) { if (device.rank() == rank) { *index = pos; @@ -151,7 +151,7 @@ Status GroupManager::DestroyAllGroups() { return Status::SUCCESS; } -Status GroupManager::GetRankID(const std::string &name, unsigned int *const rank_id) { +Status GroupManager::GetRankID(const std::string &name, uint32_t *const rank_id) { auto it = groups_.find(name); if (it == groups_.end()) { MS_LOG(ERROR) << "Could not find group name :" << name; @@ -164,7 +164,7 @@ Status GroupManager::GetRankID(const std::string &name, unsigned int *const rank return Status::SUCCESS; } -Status GroupManager::GetRankSize(const std::string &name, unsigned int *const rank_size) { +Status GroupManager::GetRankSize(const std::string &name, uint32_t *const rank_size) { auto it = groups_.find(name); if (it == groups_.end()) { MS_LOG(ERROR) << "Could not find group name :" << name; diff --git a/mindspore/ccsrc/frontend/parallel/group_manager.h b/mindspore/ccsrc/frontend/parallel/group_manager.h index 2ef6e40f15b..eeb99a67516 100644 --- a/mindspore/ccsrc/frontend/parallel/group_manager.h +++ b/mindspore/ccsrc/frontend/parallel/group_manager.h @@ -40,7 +40,7 @@ class Group { Status Init(const std::string &name, const std::vector &devices); std::vector GetDevicesList() const; std::string name() const { return name_; } - bool IsInThisGroup(int32_t device_rank); + bool IsInThisGroup(int64_t device_rank); Status GetIndex(size_t *index); size_t GetDevNum() const { return devices_.size(); } @@ -57,8 +57,8 @@ class GroupManager { Status CreateGroup(const std::string &name, const std::vector &devices, Group *group); Status DestroyGroup(Group *group); Status DestroyAllGroups(); - Status GetRankID(const std::string &name, unsigned int *rank_id); - Status GetRankSize(const std::string &name, unsigned int *rank_size); + Status GetRankID(const std::string &name, uint32_t *rank_id); + Status GetRankSize(const std::string &name, uint32_t *rank_size); Status FindGroup(const std::string &name, Group **group); std::string world_group() const { return world_group_; } void set_world_group(const std::string &name) { world_group_ = name; } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.cc index e4da62f6660..79ade08268c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.cc @@ -44,7 +44,7 @@ Status DropoutInfo::CheckStrategy(const StrategyPtr &strategy) { CheckGlobalDeviceManager(); auto input_strategy = strategy->GetInputDim().at(0); size_t dev_num = g_device_manager->GetDeviceListByStageId(stage_id_).size(); - auto product_p = std::accumulate(input_strategy.begin(), input_strategy.end(), 1, std::multiplies()); + auto product_p = std::accumulate(input_strategy.begin(), input_strategy.end(), 1, std::multiplies()); if (IntToSize(product_p) != dev_num) { MS_LOG(ERROR) << name_ << ": Invalid strategy. Don't support repeated calc."; return FAILED; @@ -92,7 +92,7 @@ Status ActivationOther::GetAttrs() { return SUCCESS; } -Status Activation::GenerateStrategies(int32_t stage_id) { +Status Activation::GenerateStrategies(int64_t stage_id) { if ((inputs_shape_.size() != ACTIVATION_INPUTS_SIZE) || (outputs_shape_.size() != ACTIVATION_OUTPUTS_SIZE)) { MS_LOG(ERROR) << name_ << " : Inputs shape size(" << inputs_shape_.size() << ") or outputs shape size(" << outputs_shape_.size() << "is wrong."; @@ -118,7 +118,7 @@ Status Activation::GenerateStrategies(int32_t stage_id) { return SUCCESS; } -Status DropoutInfo::GenerateStrategies(int32_t stage_id) { +Status DropoutInfo::GenerateStrategies(int64_t stage_id) { Shape input0_split(inputs_shape_[0].size(), 1); Shapes splittable_inputs = {input0_split}; @@ -148,13 +148,13 @@ Status Softmax::CheckStrategy(const StrategyPtr &strategy) { Dimensions input_strategy = stra.at(0); for (auto &element : axis_) { - int32_t axis_index = element; + int64_t axis_index = element; if (element < 0) { size_t input_dim = inputs_shape_.at(0).size(); - axis_index = static_cast(input_dim) + element; + axis_index = static_cast(input_dim) + element; } - int32_t axis_strategy = input_strategy.at(IntToSize(axis_index)); + int64_t axis_strategy = input_strategy.at(LongToSize(axis_index)); // Dimension corresponding to axis is un-splittable if (axis_strategy != MIN_SLICE_NUM) { MS_LOG(ERROR) << name_ << " : The strategy corresponding to axis dimension(" << axis_strategy << ") is not 1"; @@ -174,10 +174,10 @@ Status Softmax::GetAttrs() { auto iter = attrs_.find(AXIS); if (iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(iter->second); - if (iter->second->isa()) { // the axis is a number - int32_t axis_element = iter->second->cast()->value(); + if (iter->second->isa()) { // the axis is a number + int64_t axis_element = iter->second->cast()->value(); axis_.push_back(axis_element); - MS_LOG(INFO) << name_ << " : The axis is int, value is " << axis_element; + MS_LOG(INFO) << name_ << " : The axis is int64_t, value is " << axis_element; } else if (iter->second->isa()) { // the axis is a tuple ValueTuplePtr value_tuple = iter->second->cast(); if (value_tuple == nullptr) { @@ -186,14 +186,14 @@ Status Softmax::GetAttrs() { } std::vector value_vector = value_tuple->value(); (void)std::transform(value_vector.begin(), value_vector.end(), std::back_inserter(axis_), - [](const ValuePtr &value) { return static_cast(GetValue(value)); }); + [](const ValuePtr &value) { return static_cast(GetValue(value)); }); if (axis_.empty()) { MS_LOG(ERROR) << name_ << " : The axis tuple is empty."; return FAILED; } MS_LOG(INFO) << name_ << " : The axis is tuple, value is " << ListToString(axis_); } else { - MS_LOG(ERROR) << name_ << " : The value of axis is not int or tuple int."; + MS_LOG(ERROR) << name_ << " : The value of axis is not int64_t or tuple int64_t."; return FAILED; } } @@ -204,9 +204,9 @@ Status Softmax::GetAttrs() { } // for example: tensor dimension is 4, then axis range [-4, 3] - int32_t dim = SizeToInt(inputs_shape_.at(0).size()); + int64_t dim = SizeToLong(inputs_shape_.at(0).size()); auto it = - std::find_if(axis_.begin(), axis_.end(), [dim](int32_t element) { return ((element >= dim) || (element < -dim)); }); + std::find_if(axis_.begin(), axis_.end(), [dim](int64_t element) { return ((element >= dim) || (element < -dim)); }); if (it != axis_.end()) { MS_LOG(ERROR) << name_ << " : The axis(" << *it << ") is out of range[" << -dim << ", " << dim - 1 << "]."; return FAILED; @@ -217,7 +217,7 @@ Status Softmax::GetAttrs() { Status Softmax::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status Softmax::GenerateStrategies(int32_t stage_id) { +Status Softmax::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << " : GetAttrs failed."; return FAILED; @@ -230,12 +230,12 @@ Status Softmax::GenerateStrategies(int32_t stage_id) { Shape input0_split; (void)input0_split.insert(input0_split.begin(), inputs_shape_[0].size(), 1); for (auto &element : axis_) { - int32_t axis_index = element; + int64_t axis_index = element; if (element < 0) { size_t input_dim = inputs_shape_.at(0).size(); - axis_index = static_cast(input_dim) + element; + axis_index = static_cast(input_dim) + element; } - input0_split[IntToSize(axis_index)] = 0; + input0_split[LongToSize(axis_index)] = 0; } Shapes splittable_inputs = {input0_split}; @@ -410,19 +410,19 @@ Status ExpandDimsInfo::GetAttrs() { return FAILED; } - if (!input_value_.back()->isa()) { - MS_LOG(ERROR) << name_ << ": The type of axis is not int"; + if (!input_value_.back()->isa()) { + MS_LOG(ERROR) << name_ << ": The type of axis is not int64_t"; return FAILED; } - int32_t axis = GetValue(input_value_.back()); + int64_t axis = GetValue(input_value_.back()); if (inputs_shape_.empty()) { MS_LOG(ERROR) << name_ << ": The inputs shape is empty"; return FAILED; } - int32_t dim = SizeToInt(inputs_shape_[0].size()); + int64_t dim = SizeToLong(inputs_shape_[0].size()); if ((axis > dim) || (axis < -dim - 1)) { MS_LOG(ERROR) << name_ << ": The axis(" << axis << ") is out of range[" << -dim - 1 << ", " << dim << "]"; return FAILED; @@ -448,13 +448,13 @@ Status ExpandDimsInfo::InferTensorMap() { Shape input_tensor_map, output_tensor_map; size_t size = inputs_shape_[0].size(); for (size_t i = 0; i < size; ++i) { - input_tensor_map.push_back(SizeToInt(size - i - 1)); + input_tensor_map.push_back(SizeToLong(size - i - 1)); } inputs_tensor_map_.push_back(input_tensor_map); output_tensor_map = input_tensor_map; - if ((positive_axis_ < 0) || (positive_axis_ > SizeToInt(size))) { + if ((positive_axis_ < 0) || (positive_axis_ > SizeToLong(size))) { MS_LOG(ERROR) << name_ << ": Invalid positive axis " << positive_axis_; return FAILED; } @@ -479,7 +479,7 @@ Status ExpandDimsInfo::InferTensorStrategy() { } Shape output_strategy = inputs_strategy_[0]; - if ((positive_axis_ < 0) || (positive_axis_ > SizeToInt(output_strategy.size()))) { + if ((positive_axis_ < 0) || (positive_axis_ > SizeToLong(output_strategy.size()))) { MS_LOG(ERROR) << name_ << ": Invalid positive axis " << positive_axis_; return FAILED; } @@ -568,7 +568,7 @@ Status ExpandDimsInfo::InferMirrorOps() { } Status SqueezeInfo::InferAxis(const ValueTuplePtr &value_tuple) { - std::vector axis; + std::vector axis; auto axis_list = value_tuple->value(); if (inputs_shape_.empty()) { MS_LOG(ERROR) << name_ << ": The inputs shape is empty"; @@ -589,12 +589,12 @@ Status SqueezeInfo::InferAxis(const ValueTuplePtr &value_tuple) { // convert negative axis to positive. for (auto &dim : axis_list) { - if (!dim->isa()) { - MS_LOG(ERROR) << name_ << ": The type of axis is not int"; + if (!dim->isa()) { + MS_LOG(ERROR) << name_ << ": The type of axis is not int64_t"; return FAILED; } - int32_t dim_value = GetValue(dim); - int32_t positive_value = (dim_value < 0) ? (dim_value + SizeToInt(input_size)) : dim_value; + int64_t dim_value = GetValue(dim); + int64_t positive_value = (dim_value < 0) ? (dim_value + SizeToLong(input_size)) : dim_value; axis.push_back(positive_value); } axis_ = MakeValue(axis)->cast(); @@ -633,14 +633,14 @@ Status SqueezeInfo::InferTensorMap() { return FAILED; } size_t size = inputs_shape_[0].size(); - std::vector axis = GetValue>(axis_); + std::vector axis = GetValue>(axis_); for (size_t i = 0; i < size; ++i) { size_t index = size - i - 1; - auto iter = std::find(axis.begin(), axis.end(), SizeToInt(i)); + auto iter = std::find(axis.begin(), axis.end(), SizeToLong(i)); if (iter == axis.end()) { - output_tensor_map.push_back(SizeToInt(index)); + output_tensor_map.push_back(SizeToLong(index)); } - input_tensor_map.push_back(SizeToInt(index)); + input_tensor_map.push_back(SizeToLong(index)); } inputs_tensor_map_.push_back(input_tensor_map); outputs_tensor_map_.push_back(output_tensor_map); @@ -668,9 +668,9 @@ Status SqueezeInfo::InferTensorInfo() { Shapes inputs_slice_shape, outputs_slice_shape; Strategys inputs_strategy = strategy_->GetInputDim(); Dimensions output_strategy; - std::vector axis = GetValue>(axis_); + std::vector axis = GetValue>(axis_); for (size_t i = 0; i < inputs_shape_[0].size(); ++i) { - auto iter = std::find(axis.begin(), axis.end(), SizeToInt(i)); + auto iter = std::find(axis.begin(), axis.end(), SizeToLong(i)); if (iter == axis.end()) { output_strategy.push_back(inputs_strategy[0].at(i)); } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.h index a2978bfcfd3..c7e4ccb6472 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/activation_info.h @@ -53,7 +53,7 @@ class Activation : public ActivationBase { const PrimitiveAttrs &attrs) : ActivationBase(name, inputs_shape, outputs_shape, attrs, std::make_shared(false)) {} ~Activation() override = default; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: @@ -104,7 +104,7 @@ class Softmax : public ActivationBase { const PrimitiveAttrs &attrs) : ActivationBase(name, inputs_shape, outputs_shape, attrs, std::make_shared(false)) {} ~Softmax() override = default; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: @@ -112,7 +112,7 @@ class Softmax : public ActivationBase { Status GetAttrs() override; private: - std::vector axis_; + std::vector axis_; }; class SoftmaxInfo : public Softmax { @@ -211,7 +211,7 @@ class ExpandDimsInfo : public ActivationOther { Status InferTensorStrategy(); private: - int32_t positive_axis_ = -1; + int64_t positive_axis_ = -1; Strategys inputs_strategy_; Strategys outputs_strategy_; }; @@ -257,7 +257,7 @@ class DropoutInfo : public ActivationOther { const PrimitiveAttrs &attrs) : ActivationOther(name, inputs_shape, outputs_shape, attrs) {} ~DropoutInfo() override = default; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; protected: Status CheckStrategy(const StrategyPtr &strategy) override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.cc index ba5f991261b..2a9ccb88a94 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.cc @@ -292,7 +292,7 @@ Status ArithmeticBase::InferTensorInfo() { Status ArithmeticBase::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status ArithmeticBase::GenerateStrategies(int32_t stage_id) { +Status ArithmeticBase::GenerateStrategies(int64_t stage_id) { Shape input0_split(inputs_shape_[0].size(), 1); Shape input1_split(inputs_shape_[1].size(), 1); Shapes splittable_inputs = {input0_split, input1_split}; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.h index 2478f0f5fb5..9d9d08af6b2 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/arithmetic_info.h @@ -37,7 +37,7 @@ class ArithmeticBase : public OperatorInfo { ~ArithmeticBase() override = default; Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; void ReComputeBatchSplitFlagList() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.cc index 16cb93270cf..d0d88f65df3 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.cc @@ -32,9 +32,9 @@ Status BatchParallelInfo::CheckStrategy(const StrategyPtr &strategy) { return FAILED; } - int32_t stage = strategy->GetInputStage(); + int64_t stage = strategy->GetInputStage(); CheckGlobalDeviceManager(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(stage).size()); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(stage).size()); dev_num_ = dev_num; size_t strategy_size = strategy->GetInputNumber(); @@ -175,7 +175,7 @@ Status BatchParallelInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status BatchParallelInfo::GenerateStrategies(int32_t stage_id) { +Status BatchParallelInfo::GenerateStrategies(int64_t stage_id) { CheckGlobalDeviceManager(); size_t total_dev_num = g_device_manager->GetDeviceListByStageId(stage_id).size(); StrategyPtr sp; @@ -183,7 +183,7 @@ Status BatchParallelInfo::GenerateStrategies(int32_t stage_id) { for (size_t i = 0; i < inputs_shape_.size(); i++) { Shape temp(inputs_shape_[i].size(), 1); if (split_flag_list_[i]) { - temp[0] = SizeToInt(total_dev_num); + temp[0] = SizeToLong(total_dev_num); } strategy.push_back(temp); } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.h index 3d47b53b543..1c73298c412 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/batch_parallel_info.h @@ -40,7 +40,7 @@ class BatchParallelInfo : public OperatorInfo { ~BatchParallelInfo() override = default; Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: @@ -55,7 +55,7 @@ class BatchParallelInfo : public OperatorInfo { Status InferAsLossDivisor() override; private: - int32_t dev_num_; + int64_t dev_num_; }; class SparseSoftmaxCrossEntropyWithLogitsInfo : public BatchParallelInfo { diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.cc index 2b1b7a19b2b..c3e12cf4217 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.cc @@ -62,9 +62,9 @@ Status BiasAddInfo::InferTensorMap() { Dimensions sub_a_strategy = stra.at(0); size_t sub_a_strategy_size = sub_a_strategy.size(); for (size_t i = 0; i < sub_a_strategy_size; ++i) { - sub_a_tensor_map.push_back((int32_t)(LAST_INDEX(sub_a_strategy_size) - i)); + sub_a_tensor_map.push_back((int64_t)(LAST_INDEX(sub_a_strategy_size) - i)); } - sub_b_tensor_map.push_back((int32_t)(LAST_INDEX(sub_a_strategy_size) - 1)); + sub_b_tensor_map.push_back((int64_t)(LAST_INDEX(sub_a_strategy_size) - 1)); inputs_tensor_map_.push_back(sub_a_tensor_map); inputs_tensor_map_.push_back(sub_b_tensor_map); @@ -178,7 +178,7 @@ Status BiasAddInfo::InferTensorInfo() { Status BiasAddInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status BiasAddInfo::GenerateStrategies(int32_t stage_id) { +Status BiasAddInfo::GenerateStrategies(int64_t stage_id) { Shape input0_split(inputs_shape_[0].size(), 1); Shapes splittable_inputs = {input0_split, input0_split}; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.h index 62045e0dcc7..7e2b68a1a0d 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/bias_add_info.h @@ -39,7 +39,7 @@ class BiasAddInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; void ReComputeBatchSplitFlagList() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.cc index 4e999d01cc2..f478f9f3d5b 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.cc @@ -40,11 +40,11 @@ Status BroadcastToInfo::GetAttrs() { return FAILED; } for (auto &ele : var->value()) { - if (!ele->isa()) { + if (!ele->isa()) { MS_LOG(ERROR) << name_ << ": The element of shape must be int"; return FAILED; } - out_shape_.push_back(static_cast(GetValue(ele))); + out_shape_.push_back(static_cast(GetValue(ele))); } } else { MS_LOG(ERROR) << name_ << ": Can not find the shape attr"; @@ -164,7 +164,7 @@ Status BroadcastToInfo::InferTensorInfo() { Status BroadcastToInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status BroadcastToInfo::GenerateStrategies(int32_t stage_id) { +Status BroadcastToInfo::GenerateStrategies(int64_t stage_id) { if (InferAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": Infer attrs failed"; return FAILED; @@ -229,8 +229,8 @@ Status BroadcastToInfo::ComputeReplaceGraph(const CNodePtr &cnode) { Attr attr_shape = std::make_pair(SHAPE, MakeValue(to_shape)); OperatorAttrs attrs = {attr_shape}; auto new_broadcast_to = gen_g.PushBack({gen_g.NewOpInst(BROADCAST_TO, attrs), gen_g.virtual_input_node()}); - std::vector> input_nodes = {std::make_pair(new_broadcast_to, 1)}; - replace_graph_ = std::make_shared>, AnfNodePtr>>( + std::vector> input_nodes = {std::make_pair(new_broadcast_to, 1)}; + replace_graph_ = std::make_shared>, AnfNodePtr>>( std::make_pair(input_nodes, new_broadcast_to)); return SUCCESS; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.h index c60b0e593dd..212f3844df4 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/broadcast_to_info.h @@ -41,7 +41,7 @@ class BroadcastToInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; ReplaceGraphPtr replace_graph(const CNodePtr &cnode) override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc index 89cae3d181a..bd4166bbbfd 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc @@ -29,14 +29,14 @@ namespace mindspore { namespace parallel { Status ConcatInfo::GetAttrs() { - int axis = 0; + int64_t axis = 0; auto axis_iter = attrs_.find(AXIS); if (axis_iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(axis_iter->second); - if (axis_iter->second->isa()) { - axis = axis_iter->second->cast()->value(); + if (axis_iter->second->isa()) { + axis = axis_iter->second->cast()->value(); } else { - MS_LOG(ERROR) << name_ << ": The value of axis is not int"; + MS_LOG(ERROR) << name_ << ": The value of axis is not int64_t"; return FAILED; } } else { @@ -48,13 +48,13 @@ Status ConcatInfo::GetAttrs() { MS_LOG(ERROR) << name_ << ": The inputs shape is empty"; return FAILED; } - int dim = SizeToInt(inputs_shape_[0].size()); + int64_t dim = SizeToLong(inputs_shape_[0].size()); if (axis < 0) { axis = axis + dim; } - axis_ = SizeToInt(axis); + axis_ = SizeToLong(axis); return SUCCESS; } @@ -125,8 +125,8 @@ Status ConcatInfo::InferTensorMap() { } // cannot use dev_matrix_shape_ replace inputs_shape_[0], because it may not be fully split in all devices. - int32_t size = SizeToInt(inputs_shape_[0].size()); - for (int i = 0; i < size; ++i) { + int64_t size = SizeToLong(inputs_shape_[0].size()); + for (int64_t i = 0; i < size; ++i) { tensor_map.push_back(size - i - 1); } @@ -199,7 +199,7 @@ void ConcatInfo::ReComputeBatchSplitFlagList() { Status ConcatInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status ConcatInfo::GenerateStrategies(int32_t stage_id) { +Status ConcatInfo::GenerateStrategies(int64_t stage_id) { if (InferAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": Infer attrs failed"; return FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h index 183a2166600..151ef7eb456 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h @@ -38,7 +38,7 @@ class ConcatInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; void ReComputeBatchSplitFlagList() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.cc index eb09bd6ca04..04a9f241a84 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.cc @@ -29,7 +29,7 @@ namespace mindspore { namespace parallel { -static int32_t SEED_NUM = 1; +static int64_t SEED_NUM = 1; Status DropoutDoMaskInfo::CheckStrategy(const StrategyPtr &strategy) { if (strategy == nullptr) { @@ -79,7 +79,7 @@ Status DropoutDoMaskInfo::InferTensorMap() { size_t size = inputs_shape_[0].size(); // if the dimension of input is 4, and tensor_map_index is [3, 2, 1, 0] for (size_t i = 0; i < size; ++i) { - tensor_map_index.push_back(SizeToInt(size - i - 1)); + tensor_map_index.push_back(SizeToLong(size - i - 1)); } // the input[1] do not need tensor map @@ -124,7 +124,7 @@ Status DropoutDoMaskInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status DropoutDoMaskInfo::GenerateStrategies(int32_t stage_id) { +Status DropoutDoMaskInfo::GenerateStrategies(int64_t stage_id) { if (inputs_shape_.empty()) { MS_LOG(ERROR) << name_ << ": The inputs shape is empty"; return FAILED; @@ -154,7 +154,7 @@ std::shared_ptr DropoutDoMaskInfo::GenerateBatchStrategies() { CheckGlobalDeviceManager(); size_t dev_num = g_device_manager->GetDeviceListByStageId(0).size(); Dimensions strategy(inputs_shape_[0].size() - 1, 1); - (void)strategy.insert(strategy.begin(), SizeToInt(dev_num)); + (void)strategy.insert(strategy.begin(), SizeToLong(dev_num)); Strategys strategy_v = {strategy}; return std::make_shared(strategy_v); } @@ -236,10 +236,7 @@ void SetGenMaskShape(const CNodePtr &cnode, const Shape &input_slice_shape) { if (manager == nullptr) { MS_LOG(EXCEPTION) << "Failure: AddNode error since manager is nullptr."; } - std::vector input_slice_shape_int; - (void)std::transform(input_slice_shape.begin(), input_slice_shape.end(), std::back_inserter(input_slice_shape_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr new_shape = MakeValue(input_slice_shape_int); + ValuePtr new_shape = MakeValue(input_slice_shape); AnfNodePtr val = NewValueNode(new_shape); (void)manager->Replace(dropout_gen_mask_cnode->input(1), val); } @@ -274,8 +271,8 @@ std::vector DropoutDoMaskInfo::GetDropoutGenMaskReplaceOp(const CNodeP } Shape input_slice_shape = inputs_tensor_info_[0].slice_shape(); - int32_t seed_0 = GetValue(attr[SEED0]); - int32_t seed_1 = GetValue(attr[SEED1]); + int64_t seed_0 = GetValue(attr[SEED0]); + int64_t seed_1 = GetValue(attr[SEED1]); if ((seed_0 == 0) && (seed_1 == 0) && (repeated_calc_num_ > 1)) { seed_0 = SEED_NUM; seed_1 = SEED_NUM; @@ -285,10 +282,7 @@ std::vector DropoutDoMaskInfo::GetDropoutGenMaskReplaceOp(const CNodeP MS_LOG(DEBUG) << "The input slice shape droupout is " << ShapeToString(input_slice_shape); return replace_ops; } - std::vector input_slice_shape_int; - (void)std::transform(input_slice_shape.begin(), input_slice_shape.end(), std::back_inserter(input_slice_shape_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr new_shape = MakeValue(input_slice_shape_int); + ValuePtr new_shape = MakeValue(input_slice_shape); Attr attr_0 = std::make_pair(SEED0, MakeValue(seed_0)); Attr attr_1 = std::make_pair(SEED1, MakeValue(seed_1)); OperatorAttrs attrs = {attr_0, attr_1}; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.h index 53f8d3e52fd..4f514c2354e 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/dropout_do_mask_info.h @@ -37,7 +37,7 @@ class DropoutDoMaskInfo : public OperatorInfo { ~DropoutDoMaskInfo() override = default; Status Init(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; std::shared_ptr GenerateBatchStrategies() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.cc index 2b3b9cef45e..cf3d37eb01e 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.cc @@ -55,13 +55,13 @@ Status GatherV2Info::GetAttrs() { MS_LOG(ERROR) << name_ << ": input can not be a scalar!"; return FAILED; } - int axis = GetValue(input_value_.at(2)); - if (axis >= SizeToInt(inputs_shape_.at(0).size()) || axis < 0 - SizeToInt(inputs_shape_.at(0).size())) { + int64_t axis = GetValue(input_value_.at(2)); + if (axis >= SizeToLong(inputs_shape_.at(0).size()) || axis < 0 - SizeToLong(inputs_shape_.at(0).size())) { MS_LOG(ERROR) << "Axis is " << axis << ", not in [-" << inputs_shape_.at(0).size() << ", " << inputs_shape_.at(0).size() << ")."; } if (axis < 0) { - axis += SizeToInt(inputs_shape_[0].size()); + axis += SizeToLong(inputs_shape_[0].size()); } axis_ = axis; @@ -130,8 +130,8 @@ Status GatherV2Info::InferTensorMap() { size_t size = inputs_shape_.at(0).size(); // such as 4: tensor_map_index [3,2,1,0] for (size_t i = 0; i < size; ++i) { - tensor_map_in.push_back(SizeToInt(size - i - 1)); - tensor_map_out.push_back(SizeToInt(size - i - 1)); + tensor_map_in.push_back(SizeToLong(size - i - 1)); + tensor_map_out.push_back(SizeToLong(size - i - 1)); } if (index_size_ == 0) { @@ -147,7 +147,7 @@ Status GatherV2Info::InferTensorMap() { Shape tensor_map_in_index; if (index_size_ >= 1) { - tensor_map_in_index.push_back(SizeToInt(size - axis_ - 1)); + tensor_map_in_index.push_back(SizeToLong(size - axis_ - 1)); } for (size_t i = 1; i < index_size_; ++i) { tensor_map_in_index.push_back(-1); @@ -201,7 +201,7 @@ Status GatherV2Info::InferTensorInfo() { return SUCCESS; } -OperatorVector CreateSubOp(int32_t sub_value) { +OperatorVector CreateSubOp(int64_t sub_value) { OperatorVector ops; OperatorName operator_name = SUB; OperatorAttrs operator_attrs; @@ -224,26 +224,26 @@ Status GatherV2Info::InferTensorSubOps() { if ((index_size_ == 0) || (axis_strategy_ == 1)) { return SUCCESS; } - int32_t mod_n = 1; - for (size_t i = IntToSize(axis_) + 1; i < dev_matrix_shape_.size(); i++) { + int64_t mod_n = 1; + for (size_t i = LongToSize(axis_) + 1; i < dev_matrix_shape_.size(); i++) { mod_n *= dev_matrix_shape_.at(i); } - if ((axis_ >= SizeToInt(dev_matrix_shape_.size())) || axis_ < 0) { + if ((axis_ >= SizeToLong(dev_matrix_shape_.size())) || axis_ < 0) { MS_LOG(ERROR) << "Axis is " << axis_ << ", not in [0, " << dev_matrix_shape_.size() << ")."; } - int32_t mod_p = mod_n * dev_matrix_shape_.at(axis_); - int32_t rank = g_device_manager->global_rank(); - int32_t mod_rank = rank % mod_p; - mod_rank = static_cast(mod_rank / mod_n); + int64_t mod_p = mod_n * dev_matrix_shape_.at(axis_); + int64_t rank = g_device_manager->global_rank(); + int64_t mod_rank = rank % mod_p; + mod_rank = static_cast(mod_rank / mod_n); if (inputs_shape_.size() != GATHER_V2_INPUTS_SIZE) { MS_LOG(ERROR) << name_ << ": inputs shape size must be " << GATHER_V2_INPUTS_SIZE << ", but is " << inputs_shape_.size(); return FAILED; } - if ((axis_ >= SizeToInt(inputs_shape_.at(0).size())) || axis_ < 0) { + if ((axis_ >= SizeToLong(inputs_shape_.at(0).size())) || axis_ < 0) { MS_LOG(ERROR) << "Axis is " << axis_ << ", not in [0, " << inputs_shape_.at(0).size() << ")."; } - int32_t sub_value = static_cast(inputs_shape_.at(0).at(axis_) / dev_matrix_shape_.at(axis_)) * mod_rank; + int64_t sub_value = static_cast(inputs_shape_.at(0).at(axis_) / dev_matrix_shape_.at(axis_)) * mod_rank; OperatorVector sub_op; sub_ops_.emplace_back(std::move(sub_op)); @@ -275,7 +275,7 @@ Status GatherV2Info::InitForCostModel(const StrategyPtr &strategy) { return SUCCESS; } -Status GatherV2Info::GenerateStrategies(int32_t stage_id) { +Status GatherV2Info::GenerateStrategies(int64_t stage_id) { if ((inputs_shape_.size() != GATHER_V2_INPUTS_SIZE) || (outputs_shape_.size() != GATHER_V2_OUTPUTS_SIZE)) { MS_LOG(ERROR) << name_ << " : Inputs shape size(" << inputs_shape_.size() << ") or outputs shape size(" << outputs_shape_.size() << "is wrong."; @@ -318,7 +318,7 @@ std::shared_ptr GatherV2Info::GenerateBatchStrategies() { if (index_size_ != 1) { strategy.push_back(1); } else { - strategy.push_back(SizeToInt(dev_num)); + strategy.push_back(SizeToLong(dev_num)); } for (size_t i = 1; i < inputs_shape_[0].size(); i++) { strategy.push_back(1); diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.h index d7ceeda2e19..e6ad33edc9b 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_info.h @@ -48,7 +48,7 @@ class GatherV2Info : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; std::shared_ptr GenerateBatchStrategies() override; @@ -64,9 +64,9 @@ class GatherV2Info : public OperatorInfo { private: Status InferTensorSubOps(); - int32_t axis_; + int64_t axis_; size_t index_size_; - int32_t axis_strategy_; + int64_t axis_strategy_; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.cc index 4ba40a71d9b..a7ef6dd7c10 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.cc @@ -42,11 +42,11 @@ Status GatherV2PInfo::GetManualSplitWithoutOffsetAttr() { int64_t offset = 0; for (auto &ele : value_vector) { index_offsets_.push_back(offset); - if (!ele->isa()) { - MS_LOG(ERROR) << name_ << ": The element of manual split must be int"; + if (!ele->isa()) { + MS_LOG(ERROR) << name_ << ": The element of manual split must be int64_t"; return FAILED; } - int64_t param_split_shape = static_cast(GetValue(ele)); + int64_t param_split_shape = static_cast(GetValue(ele)); if (param_split_shape <= 0) { MS_LOG(ERROR) << name_ << ": The value of manual split must be positive, but got " << param_split_shape; return FAILED; @@ -84,8 +84,8 @@ Status GatherV2PInfo::GetManualSplitAttr() { MS_LOG(ERROR) << name_ << ": Size of manual split with offset's element must be 2"; return FAILED; } - int64_t param_split_row = static_cast(GetValue(value_vector[0])); - int64_t offset = static_cast(GetValue(value_vector[1])); + int64_t param_split_row = (GetValue(value_vector[0])); + int64_t offset = (GetValue(value_vector[1])); if ((param_split_row <= 0) || (offset < 0)) { MS_LOG(ERROR) << name_ << ": The value of param split shape must be positive, and the offset must larger or equal to 0"; @@ -120,7 +120,7 @@ Status GatherV2PInfo::GetAttrs() { MS_LOG(ERROR) << name_ << ": the third input value is nullptr, is not a ValueNode!"; return FAILED; } - auto axis = GetValue(input_value_.at(2)); + auto axis = GetValue(input_value_.at(2)); // if axis is negative then convert it to positive auto params_shape = inputs_shape_.at(0); if (params_shape.size() == 0) { @@ -128,7 +128,7 @@ Status GatherV2PInfo::GetAttrs() { return FAILED; } if (axis < 0) { - axis += SizeToInt(inputs_shape_[0].size()); + axis += SizeToLong(inputs_shape_[0].size()); } axis_ = axis; } @@ -180,7 +180,7 @@ Status GatherV2PInfo::CheckManualSplit(const Strategys &strategy) { return FAILED; } - if (indices_strategy[1] != SizeToInt(param_split_shapes_.size())) { + if (indices_strategy[1] != SizeToLong(param_split_shapes_.size())) { MS_LOG(ERROR) << name_ << ": The indices_strategy[1] must be equal to manual split size"; return FAILED; } @@ -201,7 +201,7 @@ Status GatherV2PInfo::CheckManualSplit(const Strategys &strategy) { // Don't support repeated calc CheckGlobalDeviceManager(); size_t dev_num = g_device_manager->GetDeviceListByStageId(stage_id_).size(); - auto product_p = std::accumulate(param_strategy.begin(), param_strategy.end(), 1, std::multiplies()); + auto product_p = std::accumulate(param_strategy.begin(), param_strategy.end(), 1, std::multiplies()); if (IntToSize(product_p) < dev_num) { MS_LOG(ERROR) << name_ << ": Manual split doesn't support repeated calc"; return FAILED; @@ -258,15 +258,15 @@ Status GatherV2PInfo::CheckStrategy(const StrategyPtr &strategy) { } // axis != 0, param_shape(0)%(param_strategy(0)*param_strategy(axis)) must be 0 - if (axis_ != 0 && param_shape.at(0) % (param_strategy.at(0) * param_strategy.at(IntToSize(axis_))) != 0) { + if (axis_ != 0 && param_shape.at(0) % (param_strategy.at(0) * param_strategy.at(LongToSize(axis_))) != 0) { MS_LOG(DEBUG) << name_ << ": index_shape(0) can't be divided by (param_strategy(0)*param_strategy(axis))."; return FAILED; } // param_strategy(axis) != 1, index can't be splited auto index_strategy = strategy->GetInputDim().at(1); - auto product_i = std::accumulate(index_strategy.begin(), index_strategy.end(), 1, std::multiplies()); - if ((param_strategy.at(IntToSize(axis_)) != 1) && (product_i != 1)) { + auto product_i = std::accumulate(index_strategy.begin(), index_strategy.end(), 1, std::multiplies()); + if ((param_strategy.at(LongToSize(axis_)) != 1) && (product_i != 1)) { MS_LOG(DEBUG) << name_ << ": param is splited at dim (axis)" << axis_ << " ,index can't be splited."; return FAILED; } @@ -274,7 +274,7 @@ Status GatherV2PInfo::CheckStrategy(const StrategyPtr &strategy) { // param_strategy(axis) != 1, Don't support repeated calc CheckGlobalDeviceManager(); size_t dev_num = g_device_manager->GetDeviceListByStageId(stage_id_).size(); - auto product_p = std::accumulate(param_strategy.begin(), param_strategy.end(), 1, std::multiplies()); + auto product_p = std::accumulate(param_strategy.begin(), param_strategy.end(), 1, std::multiplies()); if (IntToSize(product_p) != dev_num && param_strategy.at(IntToSize(axis_)) != 1) { MS_LOG(DEBUG) << name_ << ": Invalid strategy. Don't support repeated calc."; return FAILED; @@ -329,7 +329,7 @@ Status GatherV2PInfo::InferDevMatrixShape() { dev_matrix_shape_ = param_strategy; // param_strategy(axis)!=1, - if (param_strategy.at(IntToSize(axis_)) != 1) { + if (param_strategy.at(LongToSize(axis_)) != 1) { std::reverse(dev_matrix_shape_.begin(), dev_matrix_shape_.end()); } else { dev_matrix_shape_.insert(dev_matrix_shape_.end(), index_strategy.begin(), index_strategy.end()); @@ -337,10 +337,10 @@ Status GatherV2PInfo::InferDevMatrixShape() { // infer out dev_matrix_shape // axis!=0, split axis - if (axis_ != 0 && param_strategy.at(IntToSize(axis_)) != 1) { - out_dev_matrix_shape_.push_back(param_strategy.at(0) * param_strategy.at(IntToSize(axis_))); + if (axis_ != 0 && param_strategy.at(LongToSize(axis_)) != 1) { + out_dev_matrix_shape_.push_back(param_strategy.at(0) * param_strategy.at(LongToSize(axis_))); for (size_t i = 1; i < param_strategy.size(); ++i) { - if (i == IntToSize(axis_)) { + if (i == LongToSize(axis_)) { out_dev_matrix_shape_.push_back(1); } else { out_dev_matrix_shape_.push_back(param_strategy.at(i)); @@ -351,8 +351,8 @@ Status GatherV2PInfo::InferDevMatrixShape() { } CheckGlobalDeviceManager(); size_t dev_num = g_device_manager->GetDeviceListByStageId(stage_id_).size(); - auto param_product = std::accumulate(param_strategy.begin(), param_strategy.end(), 1, std::multiplies()); - auto index_product = std::accumulate(index_strategy.begin(), index_strategy.end(), 1, std::multiplies()); + auto param_product = std::accumulate(param_strategy.begin(), param_strategy.end(), 1, std::multiplies()); + auto index_product = std::accumulate(index_strategy.begin(), index_strategy.end(), 1, std::multiplies()); if (param_product * index_product < SizeToInt(dev_num)) { // add the repeated calculation num to the last dimension of dev matrix out_dev_matrix_shape_.push_back(SizeToInt(dev_num / (param_product * index_product))); @@ -370,18 +370,18 @@ void GatherV2PInfo::InferInputsTensorMap() { Shape tensor_map_index; Shape tensor_map_params; auto param_strategy = strategy_->GetInputDim().at(0); - if (param_strategy.at(IntToSize(axis_)) != 1) { + if (param_strategy.at(LongToSize(axis_)) != 1) { tensor_map_index.insert(tensor_map_index.begin(), index_size, MAP_NONE); for (size_t i = 0; i < param_size; ++i) { - tensor_map_params.push_back(SizeToInt(i)); + tensor_map_params.push_back(SizeToLong(i)); } } else { // param_strategy(axis) == 1 for (size_t i = 0; i < param_size; ++i) { - tensor_map_params.push_back(SizeToInt(total_size - i - 1)); + tensor_map_params.push_back(SizeToLong(total_size - i - 1)); } for (size_t i = 0; i < index_size; ++i) { - tensor_map_index.push_back(SizeToInt(index_size - i - 1)); + tensor_map_index.push_back(SizeToLong(index_size - i - 1)); } } inputs_tensor_map_.emplace_back(std::move(tensor_map_params)); @@ -395,15 +395,15 @@ void GatherV2PInfo::InferOutputsTensorMap() { size_t total_size = param_size + index_size; Shape tensor_map_out; auto param_strategy = strategy_->GetInputDim().at(0); - if (param_strategy.at(IntToSize(axis_)) == 1) { + if (param_strategy.at(LongToSize(axis_)) == 1) { // param_strategy(axis) == 1 for (size_t i = 0; i < param_size; ++i) { - if (i == IntToSize(axis_)) { + if (i == LongToSize(axis_)) { for (size_t j = 0; j < index_size; ++j) { - tensor_map_out.push_back(SizeToInt(index_size - j - 1)); + tensor_map_out.push_back(SizeToLong(index_size - j - 1)); } } else { - tensor_map_out.push_back(SizeToInt(total_size - i - 1)); + tensor_map_out.push_back(SizeToLong(total_size - i - 1)); } } } else { @@ -420,13 +420,13 @@ void GatherV2PInfo::InferOutputsTensorMap() { } } else { for (size_t i = 0; i < param_size; ++i) { - if (i == IntToSize(axis_)) { + if (i == LongToSize(axis_)) { tensor_map_out.insert(tensor_map_out.end(), index_size, MAP_NONE); } else { if (i == 0 && dynamic_shape_indices_ && target_ != CPU) { tensor_map_out.push_back(MAP_NONE); } - tensor_map_out.push_back(SizeToInt(param_size - i - 1)); + tensor_map_out.push_back(SizeToLong(param_size - i - 1)); } } } @@ -451,7 +451,7 @@ Status GatherV2PInfo::InferTensorInfo() { Shape input_shape = inputs_shape_.at(0); Shape input_index_shape = inputs_shape_.at(1); Shape output_shape = outputs_shape_.at(0); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); // infer tensor layout TensorLayout input_tensor_layout, input_index_layout, output_tensor_layout; if (manual_split_) { @@ -481,7 +481,7 @@ Status GatherV2PInfo::InferTensorInfo() { Status GatherV2PInfo::InferBias() { CheckGlobalDeviceManager(); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); auto input_shape = inputs_shape_.at(0); auto params_strategy = strategy_->GetInputDim().at(0); // axis don't split @@ -534,18 +534,18 @@ Status GatherV2PInfo::InferOffset() { Status GatherV2PInfo::InferGroup() { auto param_strategy = strategy_->GetInputDim().at(0); - size_t dim = IntToSize(axis_); - if (param_strategy.at(IntToSize(axis_)) != 1 && inputs_shape_.at(0).size() == 2) { + size_t dim = LongToSize(axis_); + if (param_strategy.at(LongToSize(axis_)) != 1 && inputs_shape_.at(0).size() == 2) { dim = (axis_ + 1) % 2; } CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); RankList dev_list = g_device_manager->GetDeviceListByStageId(stage_id_); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); DeviceMatrix dev_matrix(rank, dev_list, dev_matrix_shape_); RankList group_devices; - if (dev_matrix.GetDevicesAlongDim(SizeToUint(dim), &group_devices) != SUCCESS) { + if (dev_matrix.GetDevicesAlongDim(SizeToUlong(dim), &group_devices) != SUCCESS) { MS_LOG(ERROR) << name_ << ": Create group failed."; return FAILED; } @@ -575,7 +575,7 @@ Status GatherV2PInfo::InferForwardCommunication() { forward_op_.clear(); auto param_strategy = strategy_->GetInputDim().at(0); // don't split axis or target is not CPU, no need forward communication - if (target_ != CPU || param_strategy.at(IntToSize(axis_)) == 1) { + if (target_ != CPU || param_strategy.at(LongToSize(axis_)) == 1) { return SUCCESS; } // split axis @@ -617,9 +617,9 @@ Status GatherV2PInfo::ComputeReplaceGraph(const CNodePtr &cnode) { } auto sub = gen_g.PushBack({gen_g.NewOpInst(SUB), gen_g.virtual_input_node(), CreateInt32Tensor(index_offset_)}); auto gather_v2 = - gen_g.PushBack({gen_g.NewOpInst(replace_op_name_), gen_g.virtual_input_node(), sub, CreatInt32Imm(axis_)}); - std::vector> input_nodes = {std::make_pair(sub, 2), std::make_pair(gather_v2, 1)}; - replace_graph_ = std::make_shared>, AnfNodePtr>>( + gen_g.PushBack({gen_g.NewOpInst(replace_op_name_), gen_g.virtual_input_node(), sub, CreatInt64Imm(axis_)}); + std::vector> input_nodes = {std::make_pair(sub, 2), std::make_pair(gather_v2, 1)}; + replace_graph_ = std::make_shared>, AnfNodePtr>>( std::make_pair(input_nodes, gather_v2)); return SUCCESS; } @@ -632,10 +632,10 @@ Status GatherV2PInfo::ComputeReplaceGraph(const CNodePtr &cnode) { auto minimum = gen_g.PushBack({gen_g.NewOpInst(MINIMUM), relu, CreateInt32Tensor(slice_size_ - 1)}); auto equal = gen_g.PushBack({gen_g.NewOpInst(EQUAL), sub, minimum}); auto gather_v2 = - gen_g.PushBack({gen_g.NewOpInst(replace_op_name_), gen_g.virtual_input_node(), minimum, CreatInt32Imm(axis_)}); + gen_g.PushBack({gen_g.NewOpInst(replace_op_name_), gen_g.virtual_input_node(), minimum, CreatInt64Imm(axis_)}); auto dtype = gen_g.PushBack({gen_g.NewOpInst(DTYPE), gather_v2}); auto cast = gen_g.PushBack({gen_g.NewOpInst(CAST), equal, dtype}); - auto expand_dims = gen_g.PushBack({gen_g.NewOpInst(EXPAND_DIMS), cast, CreatInt32Imm(axis_ - 1)}); + auto expand_dims = gen_g.PushBack({gen_g.NewOpInst(EXPAND_DIMS), cast, CreatInt64Imm(axis_ - 1)}); auto mul = gen_g.PushBack({gen_g.NewOpInst(MUL), gather_v2, expand_dims}); // don't need expandim,if param_size = 1, if (inputs_shape_.at(0).size() == 1) { @@ -654,8 +654,8 @@ Status GatherV2PInfo::ComputeReplaceGraph(const CNodePtr &cnode) { } else { reduce_op = gen_g.PushBack({gen_g.NewOpInst(REDUCE_SCATTER, attrs), mul}); } - std::vector> input_nodes = {std::make_pair(sub, 2), std::make_pair(gather_v2, 1)}; - replace_graph_ = std::make_shared>, AnfNodePtr>>( + std::vector> input_nodes = {std::make_pair(sub, 2), std::make_pair(gather_v2, 1)}; + replace_graph_ = std::make_shared>, AnfNodePtr>>( std::make_pair(input_nodes, reduce_op)); return SUCCESS; @@ -674,7 +674,7 @@ ReplaceGraphPtr GatherV2PInfo::replace_graph(const CNodePtr &cnode) { if (target_ == CPU) { return nullptr; } - if (param_strategy.at(IntToSize(axis_)) != 1 && ComputeReplaceGraph(cnode) != SUCCESS) { + if (param_strategy.at(LongToSize(axis_)) != 1 && ComputeReplaceGraph(cnode) != SUCCESS) { MS_LOG(EXCEPTION) << name_ << ": ComputeReplaceGraph failed."; } return replace_graph_; @@ -698,7 +698,7 @@ Status GatherV2PInfo::ComputeReplaceOp() { OperatorName op_name = EMBEDDING_LOOKUP; OperatorAttrs attrs; - int32_t bias_int = static_cast(bias); + int64_t bias_int = static_cast(bias); Attr param_offset = std::make_pair("offset", MakeValue(bias_int)); OperatorParams params = {std::make_pair(param_offset, 3)}; OperatorArgs args = std::make_pair(attrs, params); @@ -741,7 +741,7 @@ Status GatherV2PInfo::InitForCostModel(const StrategyPtr &strategy) { Status GatherV2PInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status GatherV2PInfo::GenerateStrategies(int32_t stage_id) { +Status GatherV2PInfo::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { return FAILED; } @@ -781,7 +781,7 @@ std::shared_ptr GatherV2PInfo::GenerateBatchStrategies() { size_t dev_num = g_device_manager->GetDeviceListByStageId(0).size(); Dimensions param_strategy(inputs_shape_[0].size(), 1); Dimensions index_strategy; - index_strategy.push_back(SizeToInt(dev_num)); + index_strategy.push_back(SizeToLong(dev_num)); for (size_t i = 1; i < inputs_shape_[1].size(); i++) { index_strategy.push_back(1); } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.h index ba516dca063..1f09170df5a 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/gather_v2_p_info.h @@ -43,7 +43,7 @@ class GatherV2PInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; ReplaceGraphPtr replace_graph(const CNodePtr &cnode) override; std::shared_ptr GenerateBatchStrategies() override; @@ -70,7 +70,7 @@ class GatherV2PInfo : public OperatorInfo { Status InferOffset(); Status InferGroup(); - int32_t axis_; + int64_t axis_; std::string target_ = DEVICE; int64_t bias_; int64_t index_offset_; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.cc index 5e4d5fa2fd7..a49824f18b8 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.cc @@ -39,7 +39,7 @@ Status GetNextInfo::InferTensorMap() { if (full_batch) { out_tensor_map.push_back(MAP_NONE); } else { - out_tensor_map.push_back(SizeToInt(dev_matrix_shape_.size() - i - 1)); + out_tensor_map.push_back(SizeToLong(dev_matrix_shape_.size() - i - 1)); } } outputs_tensor_map_.push_back(out_tensor_map); @@ -125,8 +125,8 @@ Status GetNextInfo::CheckStrategy(const StrategyPtr &strategy) { return FAILED; } } - int32_t stage = strategy->GetInputStage(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(stage).size()); + int64_t stage = strategy->GetInputStage(); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(stage).size()); dev_num_ = dev_num; return SUCCESS; } @@ -172,10 +172,10 @@ Status GetNextInfo::GetAttrOutPutNum() { auto iter = attrs_.find(GETNEXT_NUM); if (iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(iter->second); - if (iter->second->isa()) { - output_num_ = iter->second->cast()->value(); + if (iter->second->isa()) { + output_num_ = iter->second->cast()->value(); } else { - MS_LOG(ERROR) << name_ << " : The value of output_num is not int."; + MS_LOG(ERROR) << name_ << " : The value of output_num is not int64_t."; return FAILED; } } @@ -186,7 +186,7 @@ Status GetNextInfo::GetAttrs() { if (GetAttrTypes() == FAILED || GetAttrShapes() == FAILED || GetAttrOutPutNum() == FAILED) { return FAILED; } - if (types_.size() != IntToSize(output_num_) || shapes_.size() != IntToSize(output_num_) || output_num_ == 0) { + if (types_.size() != LongToSize(output_num_) || shapes_.size() != LongToSize(output_num_) || output_num_ == 0) { MS_LOG(ERROR) << name_ << " : The output_num is not equal to shapes size."; return FAILED; } @@ -211,15 +211,7 @@ Status GetNextInfo::InferReplaceOps(const StrategyPtr &) { out_shapes[i][0] = out_shapes[i][0] / dev_num_; } } - std::vector> out_shapes_int; - (void)std::transform(out_shapes.begin(), out_shapes.end(), std::back_inserter(out_shapes_int), - [](const std::vector &shape) { - std::vector shape_int; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_int), - [](const int64_t &v) { return static_cast(v); }); - return shape_int; - }); - ValuePtr new_shapes = MakeValue(out_shapes_int); + ValuePtr new_shapes = MakeValue(out_shapes); Attr attr_types = std::make_pair(TYPES, attrs_[TYPES]); Attr attr_shapes = std::make_pair(SHAPES, new_shapes); Attr attr_num = std::make_pair(GETNEXT_NUM, attrs_[GETNEXT_NUM]); @@ -242,7 +234,7 @@ Status GetNextInfo::InitForCostModel(const StrategyPtr &strategy) { Status GetNextInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status GetNextInfo::GenerateStrategies(int32_t stage_id) { +Status GetNextInfo::GenerateStrategies(int64_t stage_id) { Strategys stra; StrategyPtr sp = std::make_shared(stage_id, stra); if (SetCostUnderStrategy(sp) == SUCCESS) { diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.h index bf30529aaf9..111fd9ff43f 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/get_next_info.h @@ -38,7 +38,7 @@ class GetNextInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; protected: Status CheckStrategy(const StrategyPtr &strategy) override; @@ -57,10 +57,10 @@ class GetNextInfo : public OperatorInfo { Status InferAsLossDivisor() override { return SUCCESS; } private: - int32_t dev_num_ = 1; + int64_t dev_num_ = 1; std::vector types_; Shapes shapes_; - int32_t output_num_ = 0; + int64_t output_num_ = 0; std::string shared_name_; }; } // namespace parallel diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.cc index f6326b39e82..d4561c345f8 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.cc @@ -33,13 +33,13 @@ Status L2NormalizeInfo::CheckStrategy(const StrategyPtr &strategy) { Strategys stra = strategy->GetInputDim(); Dimensions input_strategy = stra.at(0); - int32_t axis_index = axis_; + int64_t axis_index = axis_; if (axis_ < 0) { size_t input_dim = inputs_shape_.at(0).size(); - axis_index = static_cast(input_dim) + axis_; + axis_index = static_cast(input_dim) + axis_; } - if (input_strategy[IntToSize(axis_index)] != 1) { + if (input_strategy[LongToSize(axis_index)] != 1) { MS_LOG(ERROR) << name_ << " : The dim " << axis_index << " of input strategy must be 1."; return FAILED; } @@ -51,10 +51,10 @@ Status L2NormalizeInfo::GetAttrs() { auto iter = attrs_.find(AXIS); if (iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(iter->second); - if (iter->second->isa()) { - axis_ = iter->second->cast()->value(); + if (iter->second->isa()) { + axis_ = iter->second->cast()->value(); } else { - MS_LOG(ERROR) << name_ << " : The value of axis is not int."; + MS_LOG(ERROR) << name_ << " : The value of axis is not int64_t."; return FAILED; } } @@ -84,16 +84,16 @@ Status L2NormalizeInfo::InferMirrorOps() { return SUCCESS; } -Status L2NormalizeInfo::GenerateStrategies(int32_t stage_id) { +Status L2NormalizeInfo::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << " : GetAttrs failed."; return FAILED; } Shape input0_split(inputs_shape_[0].size() - 1, 1); - int32_t axis_index = axis_; + int64_t axis_index = axis_; if (axis_ < 0) { size_t input_dim = inputs_shape_.at(0).size(); - axis_index = static_cast(input_dim) + axis_; + axis_index = static_cast(input_dim) + axis_; } (void)input0_split.insert(input0_split.begin() + axis_index, 0); Shapes splittable_inputs = {input0_split}; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.h index 1e3442e9e37..06c61f8b157 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/l2_normalize_info.h @@ -35,7 +35,7 @@ class L2NormalizeInfo : public Activation { const PrimitiveAttrs &attrs) : Activation(name, inputs_shape, outputs_shape, attrs) {} ~L2NormalizeInfo() override = default; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; protected: Status GetAttrs() override; @@ -43,7 +43,7 @@ class L2NormalizeInfo : public Activation { Status CheckStrategy(const StrategyPtr &strategy) override; private: - int32_t axis_ = 0; // Default value = 0 + int64_t axis_ = 0; // Default value = 0 }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/layer_norm_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/layer_norm_info.cc index 8fbe857f819..625748ca3e7 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/layer_norm_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/layer_norm_info.cc @@ -28,13 +28,13 @@ Status LayerNormInfo::GetAttrs() { MS_LOG(ERROR) << name_ << ": Can not find the attr of begin norm axis"; return FAILED; } - if ((iter->second == nullptr) || !iter->second->isa()) { - MS_LOG(ERROR) << name_ << ": The axis type is not int"; + if ((iter->second == nullptr) || !iter->second->isa()) { + MS_LOG(ERROR) << name_ << ": The axis type is not int64_t"; return FAILED; } - int32_t dim = SizeToInt(input_shape_.size()); - auto axis = GetValue(iter->second); + int64_t dim = SizeToLong(input_shape_.size()); + auto axis = GetValue(iter->second); if ((axis >= dim) || (axis < -dim)) { MS_LOG(ERROR) << name_ << ": The axis(" << axis << ") is out of range[" << -dim << ", " << dim - 1 << "]"; return FAILED; @@ -43,7 +43,7 @@ Status LayerNormInfo::GetAttrs() { if (axis < 0) { axis = axis + dim; } - begin_norm_axis_ = IntToSize(axis); + begin_norm_axis_ = LongToSize(axis); return SUCCESS; } @@ -121,7 +121,7 @@ Status LayerNormInfo::CreateTensorMap(size_t input_index) { Shape shape = inputs_shape_[input_index]; Shape tensor_map; for (size_t i = 0; i < shape.size(); ++i) { - tensor_map.push_back(SizeToInt(shape.size() - i - 1)); + tensor_map.push_back(SizeToLong(shape.size() - i - 1)); } inputs_tensor_map_.push_back(tensor_map); outputs_tensor_map_.push_back(tensor_map); @@ -239,7 +239,7 @@ Status LayerNormInfo::GenerateGammaAndBetaStrategies(const std::vector(input_dim) + axis_; + axis_index = static_cast(input_dim) + axis_; } - int64_t input_axis_strategy = input_strategy.at(IntToSize(axis_index)); - int64_t label_axis_strategy = label_strategy.at(IntToSize(axis_index)); + int64_t input_axis_strategy = input_strategy.at(LongToSize(axis_index)); + int64_t label_axis_strategy = label_strategy.at(LongToSize(axis_index)); // Dimension corresponding to axis is un-splittable if ((input_axis_strategy != MIN_SLICE_NUM) && (label_axis_strategy != MIN_SLICE_NUM)) { MS_LOG(ERROR) << name_ << " : The strategy corresponding to axis dimension is not 1, input: " << input_axis_strategy @@ -166,20 +166,20 @@ void SoftmaxCrossEntropyWithLogitsInfo::ReComputeBatchSplitFlagList() { } } -Status SoftmaxCrossEntropyWithLogitsInfo::GenerateStrategies(int32_t stage_id) { +Status SoftmaxCrossEntropyWithLogitsInfo::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << " : GetAttrs failed."; return FAILED; } - int32_t axis_index = axis_; + int64_t axis_index = axis_; if (axis_ < 0) { size_t input_dim = inputs_shape_[0].size(); - axis_index = static_cast(input_dim) + axis_; + axis_index = static_cast(input_dim) + axis_; } Shape input0_split; (void)input0_split.insert(input0_split.begin(), inputs_shape_[0].size(), 1); - input0_split[IntToSize(axis_index)] = 0; + input0_split[LongToSize(axis_index)] = 0; Shapes splittable_inputs = {input0_split, input0_split}; std::vector sp_vector; if (GenerateStrategiesWithBroadcast(stage_id, inputs_shape_, splittable_inputs, &sp_vector) != SUCCESS) { diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/loss_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/loss_info.h index 99d5c23e214..e30864e6633 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/loss_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/loss_info.h @@ -42,7 +42,7 @@ class SoftmaxCrossEntropyWithLogitsInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; void ReComputeBatchSplitFlagList() override; @@ -59,7 +59,7 @@ class SoftmaxCrossEntropyWithLogitsInfo : public OperatorInfo { Status InferAsLossDivisor() override; private: - int32_t axis_ = -1; // default -1 + int64_t axis_ = -1; // default -1 }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.cc index 4b9d9c34458..3516222a655 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.cc @@ -109,10 +109,10 @@ Status MatMulBase::GetAttrs() { auto field_size_iter = attrs_.find(FIELD_SIZE); if (field_size_iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(field_size_iter->second); - if (field_size_iter->second->isa()) { - field_size_ = field_size_iter->second->cast()->value(); + if (field_size_iter->second->isa()) { + field_size_ = field_size_iter->second->cast()->value(); } else { - MS_LOG(ERROR) << name_ << " : The value of field_size is not int."; + MS_LOG(ERROR) << name_ << " : The value of field_size is not int64_t."; return FAILED; } } @@ -421,7 +421,7 @@ Status MatMulBase::SwapLastTwoElements(mindspore::parallel::Shape *const input) return SUCCESS; } -Status MatMulBase::GenerateStrategies(int32_t stage_id) { +Status MatMulBase::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << " : GetAttrs failed."; return FAILED; @@ -456,9 +456,9 @@ Status MatMulBase::GenerateStrategies(int32_t stage_id) { combined_shape = input1_shape; combined_shape.push_back(input0_shape[input0_shape.size() - 2]); } - std::function recursive = [&stage_id, &dev_num, &combined_partitions, &combined_shape, + std::function recursive = [&stage_id, &dev_num, &combined_partitions, &combined_shape, &input1_shape_size, &recursive, &input0_shape_size, - this](uint32_t current_index, size_t n) { + this](uint64_t current_index, size_t n) { // Finishing the recursive steps, if the strategy is valid, then calculate the cost // for this operator under the strategy. if (current_index == combined_shape.size()) { @@ -474,8 +474,8 @@ Status MatMulBase::GenerateStrategies(int32_t stage_id) { } else { MS_LOG(DEBUG) << name_ << " : The value input0_shape_size: " << input0_shape_size << ", input1_shape_size: " << input1_shape_size; - for (uint32_t i = 1; i <= n; i *= 2) { - if (n % i == 0 && IntToSize(combined_shape[current_index]) % i == 0) { + for (uint64_t i = 1; i <= n; i *= 2) { + if (n % i == 0 && LongToSize(combined_shape[current_index]) % i == 0) { combined_partitions.push_back(i); recursive(current_index + 1, n / i); combined_partitions.pop_back(); @@ -490,7 +490,7 @@ Status MatMulBase::GenerateStrategies(int32_t stage_id) { return Status::SUCCESS; } -Status MatMulBase::PrepareStrategy(int32_t stage_id, size_t dev_num, +Status MatMulBase::PrepareStrategy(int64_t stage_id, size_t dev_num, mindspore::parallel::Dimensions combined_partitions, size_t input0_shape_size, size_t input1_shape_size, mindspore::parallel::StrategyPtr *const sp) { int64_t product = @@ -592,8 +592,8 @@ Status MatMulBase::CheckForTensorSliceValid() const { } for (auto &one_input_tensor : inputs_tensor_info_) { auto slice_shape = one_input_tensor.slice_shape(); - if ((IntToSize(slice_shape[LAST_INDEX(slice_shape.size())]) % TENSOR_SLICE_ALIGNMENT_SIZE != 0) || - (IntToSize(slice_shape[SECOND_FROM_END(slice_shape.size())]) % TENSOR_SLICE_ALIGNMENT_SIZE != 0)) { + if ((LongToSize(slice_shape[LAST_INDEX(slice_shape.size())]) % TENSOR_SLICE_ALIGNMENT_SIZE != 0) || + (LongToSize(slice_shape[SECOND_FROM_END(slice_shape.size())]) % TENSOR_SLICE_ALIGNMENT_SIZE != 0)) { return FAILED; } } @@ -624,7 +624,7 @@ Status MatMulBase::SetCostUnderStrategy(const mindspore::parallel::StrategyPtr & std::vector relica_inputs_tensor_vector; InitTensorInfoForCost(&relica_inputs_tensor_vector); - int32_t stage_id = strategy->GetInputStage(); + int64_t stage_id = strategy->GetInputStage(); // Here, we use the origin outputs_, because we only use the slice size of the output tensor. // It does not matter whether the output tensor is transposed or not. double computation_cost = diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.h index e83ae3493d0..26afaaae69c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/matmul_info.h @@ -41,9 +41,9 @@ class MatMulBase : public OperatorInfo { Status InitForCostModel(const StrategyPtr &strategy) override; // Generate all strategies and the corresponding cost for this MatMul operator - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; - Status PrepareStrategy(int32_t stage_id, size_t dev_num, Dimensions combined_partitions, size_t input0_shape_size, + Status PrepareStrategy(int64_t stage_id, size_t dev_num, Dimensions combined_partitions, size_t input0_shape_size, size_t input1_shape_size, StrategyPtr *sp); Status SwapLastTwoElements(Shape *shape); @@ -62,7 +62,7 @@ class MatMulBase : public OperatorInfo { bool transpose_a_ = false; bool transpose_b_ = false; bool forward_reduce_scatter_ = false; - int32_t field_size_ = 0; + int64_t field_size_ = 0; size_t mat_a_dimension_ = 0; size_t mat_b_dimension_ = 0; Shape origin_dev_matrix_shape_; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.cc index 617f34b0590..935b0650e33 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.cc @@ -33,11 +33,11 @@ Status OneHotInfo::GetAttrs() { auto iter = attrs_.find(AXIS); if (iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(iter->second); - if (iter->second->isa()) { + if (iter->second->isa()) { axis_value_ptr_ = iter->second; - axis_ = iter->second->cast()->value(); + axis_ = iter->second->cast()->value(); } else { - MS_LOG(ERROR) << name_ << ": The value of axis is not int."; + MS_LOG(ERROR) << name_ << ": The value of axis is not int64_t."; return FAILED; } } @@ -157,10 +157,10 @@ Status OneHotInfo::ExtractInputInfo() { return FAILED; } - if (value_ptr->isa()) { - total_class_number_ = value_ptr->cast()->value(); + if (value_ptr->isa()) { + total_class_number_ = value_ptr->cast()->value(); } else { - MS_LOG(ERROR) << "OneHot Primitive depth type must be int"; + MS_LOG(ERROR) << "OneHot Primitive depth type must be int64_t"; return FAILED; } classes_each_device_ = total_class_number_ / old_dev_matrix_back_; @@ -196,10 +196,10 @@ Status OneHotInfo::ComputeReplaceGraph(const CNodePtr &cnode) { auto sub2 = gen_g.PushBack({gen_g.NewOpInst(SUB), mul3, CreateInt32Tensor(1)}); Attr attr_onehot_axis = std::make_pair(AXIS, axis_value_ptr_); OperatorAttrs attrs_onehot = {attr_onehot_axis}; - auto onehot = gen_g.PushBack({gen_g.NewOpInst(ONEHOT, attrs_onehot), sub2, CreatInt32Imm(classes_each_device_), + auto onehot = gen_g.PushBack({gen_g.NewOpInst(ONEHOT, attrs_onehot), sub2, CreatInt64Imm(classes_each_device_), cnode->input(3), cnode->input(4)}); - std::vector> input_nodes = {std::make_pair(floor_div, 1), std::make_pair(sub1, 1)}; - replace_graph_ = std::make_shared>, AnfNodePtr>>( + std::vector> input_nodes = {std::make_pair(floor_div, 1), std::make_pair(sub1, 1)}; + replace_graph_ = std::make_shared>, AnfNodePtr>>( std::make_pair(input_nodes, onehot)); return SUCCESS; @@ -236,7 +236,7 @@ Status OneHotInfo::InitForCostModel(const StrategyPtr &strategy) { return SUCCESS; } -Status OneHotInfo::GenerateStrategies(int32_t stage_id) { +Status OneHotInfo::GenerateStrategies(int64_t stage_id) { Shapes splittable_inputs = {{1, 1}, {}, {}}; std::vector sp_vector; if (inputs_shape_.size() != 3) { @@ -270,7 +270,7 @@ Status OneHotInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return Se std::shared_ptr OneHotInfo::GenerateBatchStrategies() { CheckGlobalDeviceManager(); size_t dev_num = g_device_manager->GetDeviceListByStageId(0).size(); - Dimensions strategy = {SizeToInt(dev_num), 1}; + Dimensions strategy = {SizeToLong(dev_num), 1}; Dimensions empty_strategy; Strategys strategy_v = {strategy, empty_strategy, empty_strategy}; return std::make_shared(strategy_v); diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.h index 5d65ff0f634..1b3624fb1ce 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/onehot_info.h @@ -38,7 +38,7 @@ class OneHotInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; ReplaceGraphPtr replace_graph(const CNodePtr &cnode) override; std::shared_ptr GenerateBatchStrategies() override; @@ -57,12 +57,12 @@ class OneHotInfo : public OperatorInfo { Status ComputeReplaceGraph(const CNodePtr &cnode); int axis_ = -1; - int32_t rank_ = 0; - int32_t total_class_number_ = 1; - int32_t classes_each_device_ = 1; - int32_t old_dev_matrix_back_ = 1; + int64_t rank_ = 0; + int64_t total_class_number_ = 1; + int64_t classes_each_device_ = 1; + int64_t old_dev_matrix_back_ = 1; ValuePtr axis_value_ptr_; - int32_t mod_rank_ = 0; + int64_t mod_rank_ = 0; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.cc index b519b413146..36c831bf9ef 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.cc @@ -80,7 +80,7 @@ Status OperatorInfo::CheckStrategyValue(const StrategyPtr &strategy, const Shape return FAILED; } - if ((IntToUint(strategy_value) & IntToUint(strategy_value - 1)) != 0) { + if ((LongToUlong(strategy_value) & LongToUlong(strategy_value - 1)) != 0) { if (is_auto_parallel_) { MS_LOG(DEBUG) << name_ << ": Invalid Strategy value it is not the power of 2, " << strategy_value; } else { @@ -132,7 +132,7 @@ Status OperatorInfo::InferAttrs() { } void OperatorInfo::SetDeviceListByStrategy() { - int32_t stage = strategy_->GetInputStage(); + int64_t stage = strategy_->GetInputStage(); CheckGlobalDeviceManager(); global_device_list_ = g_device_manager->GetDeviceListByStageId(stage); } @@ -149,7 +149,7 @@ Status OperatorInfo::InferRepeatedCalcInfo() { if (g_dev_list_size == dev_matrix_size) { repeated_calc_num_ = 1; } else if (g_dev_list_size % dev_matrix_size == 0) { - repeated_calc_num_ = ((int32_t)(g_dev_list_size / dev_matrix_size)); + repeated_calc_num_ = ((int64_t)(g_dev_list_size / dev_matrix_size)); } else { MS_LOG(ERROR) << name_ << ": Dev list size " << g_dev_list_size << " can not be divisible by dev matrix size " << dev_matrix_size; @@ -157,8 +157,8 @@ Status OperatorInfo::InferRepeatedCalcInfo() { } CheckGlobalDeviceManager(); - int32_t rank = g_device_manager->global_rank(); - int32_t stage = strategy_->GetInputStage(); + int64_t rank = g_device_manager->global_rank(); + int64_t stage = strategy_->GetInputStage(); local_device_list_ = g_device_manager->global_device_list(stage, rank, repeated_calc_num_); return SUCCESS; @@ -206,7 +206,7 @@ void OperatorInfo::ResetTensorMapIfRepeatedCalc() { } // use for loss repeated calculation -Operator CreateVirtualDivOp(int32_t div_num) { +Operator CreateVirtualDivOp(int64_t div_num) { OperatorName operator_name = VIRTUAL_DIV; ValuePtr attr0_value = MakeValue(div_num); Attr attr0 = std::make_pair(DIVISOR, attr0_value); @@ -301,7 +301,7 @@ OperatorVector CreateMirrorOps(const std::string &group_name, size_t dev_num) { OperatorName operator_name = MIRROR_OPERATOR; ValuePtr attr0_value = MakeValue(group_name); - ValuePtr attr1_value = MakeValue(SizeToInt(dev_num)); + ValuePtr attr1_value = MakeValue(SizeToLong(dev_num)); ValuePtr attr2_value = MakeValue(mean_flag); Attr attr0 = std::make_pair(GROUP, attr0_value); @@ -330,7 +330,7 @@ Status OperatorInfo::CreateGroupByTensorMap(const Shape &tensor_map, std::vector return FAILED; } CheckGlobalDeviceManager(); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); DeviceMatrix dev_matrix(rank, global_device_list_, dev_matrix_shape_); RankList group_devices; if (dev_matrix.GetDevicesByTensorMap(tensor_map, &group_devices) != SUCCESS) { @@ -353,10 +353,10 @@ Status OperatorInfo::CreateGroupByDim(size_t axis, std::vector *group) { return FAILED; } CheckGlobalDeviceManager(); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); DeviceMatrix dev_matrix(rank, global_device_list_, dev_matrix_shape_); RankList group_devices; - if (dev_matrix.GetDevicesAlongDim(SizeToUint(axis), &group_devices) != SUCCESS) { + if (dev_matrix.GetDevicesAlongDim(SizeToUlong(axis), &group_devices) != SUCCESS) { return FAILED; } @@ -477,7 +477,7 @@ Status OperatorInfo::InitForCostModelWithAutoRepeatCalc(const StrategyPtr &strat } used_devices_ = - ((int32_t)(std::accumulate(dev_matrix_shape_.begin(), dev_matrix_shape_.end(), 1, std::multiplies()))); + ((int64_t)(std::accumulate(dev_matrix_shape_.begin(), dev_matrix_shape_.end(), 1, std::multiplies()))); // must be after InferDevMatrixShape if (InferRepeatedCalcInfo() != SUCCESS) { @@ -703,7 +703,7 @@ std::shared_ptr GenerateBatchStrategiesBySplitFlag(const Shapes &shap return nullptr; } CheckGlobalDeviceManager(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(0).size()); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(0).size()); Strategys strategy_v; for (size_t i = 0; i != shapes.size(); i++) { if (shapes[i].empty()) { @@ -736,7 +736,7 @@ void OperatorInfo::ComputeBatchSplitFlagList() { } // This is a common method for checking whether the generated stragegy has the correct number of devuces. -Status PrepareStrategyBase(int32_t stage_id, size_t dev_num, const Shapes &inputs_partitions, StrategyPtr *const sp) { +Status PrepareStrategyBase(int64_t stage_id, size_t dev_num, const Shapes &inputs_partitions, StrategyPtr *const sp) { if (sp == nullptr) { MS_LOG(ERROR) << "The strategy is null."; return FAILED; @@ -787,7 +787,7 @@ void PrintStrategy(const StrategyPtr &strategy) { } // generate strategies for that each dimension of input0 and input1 is relevant, such as: ([a, b, c, d], [a, b, c, d]) -Status GenerateStrategiesForTwoEqualInputs(int32_t stage_id, const Shapes &inputs_shape, +Status GenerateStrategiesForTwoEqualInputs(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *const sp_vector) { if (sp_vector == nullptr) { MS_LOG(ERROR) << "The sp_vector is null."; @@ -820,7 +820,7 @@ Status GenerateStrategiesForTwoEqualInputs(int32_t stage_id, const Shapes &input // generate strategies for that input0 and input1 have relevant dimensions, and input0 needs to broadcast // such as: ([b, c, d], [a, b, c, d]) or ([1, c, d], [a, b, c, d]) -Status GenerateStrategiesForBroadcastLeft(int32_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, +Status GenerateStrategiesForBroadcastLeft(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *const sp_vector) { if (sp_vector == nullptr) { MS_LOG(ERROR) << "The sp_vector is null."; @@ -869,7 +869,7 @@ Status GenerateStrategiesForBroadcastLeft(int32_t stage_id, const Shapes &inputs // generate strategies for that input0 and input1 have relevant dimensions, and input1 needs to broadcast // such as: ([a, b, c, d], [b, c, d]) or ([a, b, c, d], [1, c, d]) -Status GenerateStrategiesForBroadcastRight(int32_t stage_id, const Shapes &inputs_shape, +Status GenerateStrategiesForBroadcastRight(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *const sp_vector) { if (sp_vector == nullptr) { MS_LOG(ERROR) << "The sp_vector is null."; @@ -919,7 +919,7 @@ Status GenerateStrategiesForBroadcastRight(int32_t stage_id, const Shapes &input // generate strategies for that input0 and input1 have same size, and input0 or input1 needs to broadcast // such as: ([a, 1], [1, b]) or ([a, b, c, d], [1, b, c, d]) or ([a, b, c, 1], [1, b, c, d]) -Status GenerateStrategiesForBroadcastBoth(int32_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, +Status GenerateStrategiesForBroadcastBoth(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *const sp_vector) { if (sp_vector == nullptr) { MS_LOG(ERROR) << "The sp_vector is null."; @@ -975,7 +975,7 @@ Status GenerateStrategiesForBroadcastBoth(int32_t stage_id, const Shapes &inputs // dimension is splittable. 'inputs_partitions' is the result of partitions. // NOTE: This implementation would partition all splittable dimensions in all inputs. Some operators requiring // specific dimensions in inputs have the identical partition should have individual implementation. -Status GenerateStrategiesForIndependentInputs(int32_t stage_id, const Shapes &inputs_shape, +Status GenerateStrategiesForIndependentInputs(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *const sp_vector) { if (sp_vector == nullptr) { @@ -996,9 +996,9 @@ Status GenerateStrategiesForIndependentInputs(int32_t stage_id, const Shapes &in (void)combined_splittable_inputs.insert(combined_splittable_inputs.end(), splittable_inputs[j].begin(), splittable_inputs[j].end()); } - std::function recursive = [&stage_id, &dev_num, &sp_vector, &combined_inputs_shape, + std::function recursive = [&stage_id, &dev_num, &sp_vector, &combined_inputs_shape, &combined_splittable_inputs, &combined_partitions, &recursive, - &inputs_shape](uint32_t current_index, size_t n) { + &inputs_shape](uint64_t current_index, size_t n) { if (current_index == combined_inputs_shape.size()) { MS_LOG(DEBUG) << "The value of combined_splittable_inputs.size is: " << combined_splittable_inputs.size(); Shapes inputs_partitions; @@ -1023,8 +1023,8 @@ Status GenerateStrategiesForIndependentInputs(int32_t stage_id, const Shapes &in recursive(current_index + 1, n / MIN_SLICE_NUM); combined_partitions.pop_back(); } else if (combined_splittable_inputs[current_index] == 1) { - for (uint32_t i = 1; i <= n; i *= 2) { - if (n % i == 0 && IntToSize(combined_inputs_shape[current_index]) % i == 0) { + for (uint64_t i = 1; i <= n; i *= 2) { + if (n % i == 0 && LongToSize(combined_inputs_shape[current_index]) % i == 0) { combined_partitions.push_back(i); recursive(current_index + 1, n / i); combined_partitions.pop_back(); @@ -1045,7 +1045,7 @@ Status GenerateStrategiesForIndependentInputs(int32_t stage_id, const Shapes &in // such as: ([a, b, c, d], [a, b, c, d]) or ([b, c, d], [a, b, c, d]) or ([1, c, d], [a, b, c, d]) // or ([a, b, c, d], [b, c, d]) or ([a, b, c, d], [1, c, d]) // or ([a, 1], [1, b]) or ([a, b, c, d], [1, b, c, d]) or ([a, b, c, 1], [1, b, c, d]) -Status GenerateStrategiesWithBroadcast(int32_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, +Status GenerateStrategiesWithBroadcast(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *const sp_vector) { if (sp_vector == nullptr) { MS_LOG(ERROR) << "The sp_vector is null."; @@ -1105,7 +1105,7 @@ Status OperatorInfo::SetCostUnderStrategyBase(const StrategyPtr &strategy) { } return FAILED; } - int32_t stage_id = strategy->GetInputStage(); + int64_t stage_id = strategy->GetInputStage(); double computation_cost = operator_cost()->GetForwardComputationCost(inputs_tensor_info_, outputs_tensor_info_, stage_id); double communication_cost = operator_cost()->GetCommCost(inputs_tensor_info_, outputs_tensor_info_, stage_id); @@ -1191,7 +1191,7 @@ void OperatorInfo::ExactStrategiesAndRelatedEdges() { } } -int OperatorInfo::ComputeOpAndPrevEdgeParameterInvolved() { +int64_t OperatorInfo::ComputeOpAndPrevEdgeParameterInvolved() { if (is_output_parameter_involve_ != -1) { return is_output_parameter_involve_; } @@ -1280,8 +1280,8 @@ Status OperatorInfo::CorrectMemoryCost(size_t input_index) { return SUCCESS; } -int32_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const Shape &tensor_map) { - int32_t ret = -1; +int64_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const Shape &tensor_map) { + int64_t ret = -1; // The number of repetitions is equal to the number of all devices divided by the number of devices use for // tensor map. @@ -1290,12 +1290,12 @@ int32_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const S // -1 means the corresponding dimension is not split. if (element == MAP_NONE) { continue; - } else if ((element < 0) || (IntToSize(element) >= dev_matrix_shape.size())) { + } else if ((element < 0) || (LongToSize(element) >= dev_matrix_shape.size())) { MS_LOG(ERROR) << "Invalid tensor map: " << ShapeToString(tensor_map) << ", the dev matrix shape is " << ShapeToString(dev_matrix_shape); return ret; } else { - size_t index = dev_matrix_shape.size() - IntToSize(element) - 1; + size_t index = dev_matrix_shape.size() - LongToSize(element) - 1; if (dev_matrix_shape[index] <= 0) { MS_LOG(ERROR) << "Invalid dev matrix shape: " << ShapeToString(dev_matrix_shape); return ret; @@ -1304,7 +1304,7 @@ int32_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const S } } - return (int32_t)device_num; + return (int64_t)device_num; } Status OperatorInfo::InferAsLossDivisor() { @@ -1325,7 +1325,7 @@ Status OperatorInfo::InferAsLossDivisor() { } if (outputs_tensor_map_[0].empty()) { - as_loss_divisor_ = SizeToInt(global_device_list_.size()); + as_loss_divisor_ = SizeToLong(global_device_list_.size()); MS_LOG(INFO) << name_ << ": The output is a scalar, use the dev size " << as_loss_divisor_ << ", loss divisor."; return SUCCESS; } @@ -1410,7 +1410,7 @@ void OperatorInfo::BreakingTiesForPerferringDataParallel(const StrategyPtr &stra if (!stra->GetInputDim().empty() && !stra->GetInputDim()[0].empty()) { CheckGlobalDeviceManager(); auto total_device_num = g_device_manager->GetDeviceListByStageId(stra->GetInputStage()).size(); - if (IntToSize(stra->GetInputDim()[0][0]) == total_device_num) { + if (LongToSize(stra->GetInputDim()[0][0]) == total_device_num) { if (cost->computation_cost_ > 1.0) { cost->computation_cost_ -= 1.0; } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.h index bec113b493a..f5b78075a6c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/operator_info.h @@ -45,9 +45,9 @@ using Ops = std::vector; using VirtualDivOp = OperatorVector; using TensorMaps = std::vector; using TensorLayouts = std::vector; -using different_type = std::vector::difference_type; +using different_type = std::vector::difference_type; using PrimitiveAttrs = std::unordered_map; -using ReplaceGraphPtr = std::shared_ptr>, AnfNodePtr>>; +using ReplaceGraphPtr = std::shared_ptr>, AnfNodePtr>>; class Edge; @@ -82,7 +82,7 @@ class OperatorInfo { // Given the stage_id (which indicates the number of devices), // generate all strategies for this operator - virtual Status GenerateStrategies(int32_t stage_id) = 0; + virtual Status GenerateStrategies(int64_t stage_id) = 0; const OperatorCostPtr &operator_cost() const { return operator_cost_; } void set_cost(const OperatorCostPtr &cost) { operator_cost_ = cost; } virtual Status SetCostUnderStrategy(const StrategyPtr &strategy) = 0; @@ -104,7 +104,7 @@ class OperatorInfo { // In the inference phase, the memory cost is incurred only when the operator is critical. The size is calculated // by the output Status CalculateMemoryCostForInference(); - int ComputeOpAndPrevEdgeParameterInvolved(); + int64_t ComputeOpAndPrevEdgeParameterInvolved(); ForwardOp forward_op() const { return forward_op_; } ForwardOp replace_op() const { return replace_op_; } @@ -160,11 +160,11 @@ class OperatorInfo { // When the output of a Parameter (require_grad) being used by multiple operators, the Parameter's cost is calculated // multiple times. This method is to correct this, and makes the cost is calulated only once. Status CorrectMemoryCost(size_t input_index); - int is_output_parameter_involve() const { return is_output_parameter_involve_; } - int is_output_critical() const { return is_output_critical_; } + int64_t is_output_parameter_involve() const { return is_output_parameter_involve_; } + int64_t is_output_critical() const { return is_output_critical_; } void mark_output_critical() { is_output_critical_ = 1; } void mark_output_not_critical() { is_output_critical_ = 0; } - int used_devices() const { return used_devices_; } + int64_t used_devices() const { return used_devices_; } // needed by rec_parser void set_type(const std::string &type) { type_ = type; } const std::string &type() const { return type_; } @@ -220,8 +220,8 @@ class OperatorInfo { std::vector inputs_tensor_info_; std::vector outputs_tensor_info_; Shape dev_matrix_shape_; // if repeated calculation, it contains the repeated_calc_num_ - int32_t repeated_calc_num_ = 1; - int32_t as_loss_divisor_ = 1; + int64_t repeated_calc_num_ = 1; + int64_t as_loss_divisor_ = 1; TensorMaps inputs_tensor_map_; TensorMaps outputs_tensor_map_; ForwardOp forward_op_; @@ -248,11 +248,11 @@ class OperatorInfo { // If any input is parameter-involved, the output is parameter-involved. This variable is used in calculating // peak memory cost in the training phase. // -1: unset; 0: not parameter_involved; 1: parameter_involved - int is_output_parameter_involve_ = -1; + int64_t is_output_parameter_involve_ = -1; // Whether this output is critical, which means that this output is included in calculating peak memory cost // in the inference phase. // -1 : unset; 0: not critical; 1: critical - int is_output_critical_ = -1; + int64_t is_output_critical_ = -1; double outputs_total_size_ = 0.0; bool is_calculated_outputs_size_ = false; // for each input and output, the followings record the number of bytes of each element @@ -267,7 +267,7 @@ class OperatorInfo { std::vector split_flag_list_; std::string refkey_parameter_name_; CNodePtr cnode_; - int32_t used_devices_ = -1; + int64_t used_devices_ = -1; // the repeated_calc_num_ will be inserted to the last dimension of dev matrix in default bool repeated_num_in_dev_matrix_right_ = true; // Whether the list of available strategies is exact or approximate @@ -280,26 +280,26 @@ class OperatorInfo { Shape GetSliceShape(const Shape &tensor_shape, const Dimensions &strategy); Status CheckStrategyValue(const StrategyPtr &strategy, const Shapes &inputs_shape, bool); -Operator CreateVirtualDivOp(int32_t div_num); +Operator CreateVirtualDivOp(int64_t div_num); Operator CreateAllReduceOp(const std::string &reduce_op, const std::string &group); Operator CreateReduceScatterOp(const std::string &reduce_op, const std::string &group); Operator CreateAllGatherOp(const std::string &group); Operator CreateGetTensorSliceOp(const TensorLayout &tensor_layout); OperatorVector CreateMirrorOps(const std::string &group_name, size_t dev_num); -int32_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const Shape &tensor_map); +int64_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const Shape &tensor_map); std::shared_ptr GenerateBatchStrategiesBySplitFlag(const Shapes &shapes, const std::vector &split_flag_list); void PrintStrategy(const StrategyPtr &strategy); // generate strategies for that all inputs' dimensions are independent, such as: ([a, b, c, d]) -Status GenerateStrategiesForIndependentInputs(int32_t stage_id, const Shapes &inputs_shape, +Status GenerateStrategiesForIndependentInputs(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *sp_vector); // generate strategies for that have two inputs, and input0 or input1 maybe broadcast, // and the corresponding dimensions that are not broadcast are all relevant dimensions // such as: ([a, b, c, d], [a, b, c, d]) or ([b, c, d], [a, b, c, d]) or ([1, c, d], [a, b, c, d]) // or ([a, b, c, d], [b, c, d]) or ([a, b, c, d], [1, c, d]) // or ([a, 1], [1, b]) or ([a, b, c, d], [1, b, c, d]) or ([a, b, c, 1], [1, b, c, d]) -Status GenerateStrategiesWithBroadcast(int32_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, +Status GenerateStrategiesWithBroadcast(int64_t stage_id, const Shapes &inputs_shape, const Shapes &splittable_inputs, std::vector *sp_vector); Shapes GetRefKeyNodeShape(const AnfNodePtr &node, const FuncGraphPtr &func_graph); diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h b/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h index d57f2bb7e27..4ff6c5b2bc7 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/ops_utils.h @@ -22,12 +22,12 @@ namespace parallel { constexpr size_t PRELU_INPUTS_SIZE = 2; constexpr size_t PRELU_OUTPUTS_SIZE = 1; constexpr size_t PRELU_SECOND_INPUT_SIZE = 1; -constexpr int32_t PRELU_CHANNEL_INDEX = 1; -constexpr int32_t PRELU_CHANNEL_STRATEGY = 1; -constexpr int32_t NO_SPLIT_MAP = -1; -constexpr int32_t NO_SPLIT_STRATEGY = 1; -constexpr int32_t SPLIT_FLAG = 1; -constexpr int32_t NO_SPLIT_FLAG = 0; +constexpr int64_t PRELU_CHANNEL_INDEX = 1; +constexpr int64_t PRELU_CHANNEL_STRATEGY = 1; +constexpr int64_t NO_SPLIT_MAP = -1; +constexpr int64_t NO_SPLIT_STRATEGY = 1; +constexpr int64_t SPLIT_FLAG = 1; +constexpr int64_t NO_SPLIT_FLAG = 0; constexpr size_t MATMUL_ATTRS_SIZE = 2; constexpr size_t STRIDED_SLICE_ATTRS_SIZE = 5; constexpr size_t STRIDED_SLICE_INPUTS_SIZE = 4; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.cc index 19db3b7bf0e..8171fde0518 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.cc @@ -33,8 +33,8 @@ Status PackInfo::GetAttrs() { auto axis_iter = attrs_.find(AXIS); if (axis_iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(axis_iter->second); - if (axis_iter->second->isa()) { - axis = axis_iter->second->cast()->value(); + if (axis_iter->second->isa()) { + axis = axis_iter->second->cast()->value(); } else { MS_LOG(ERROR) << name_ << ": The value of axis is not int"; return FAILED; @@ -181,7 +181,7 @@ void PackInfo::ReComputeBatchSplitFlagList() { Status PackInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status PackInfo::GenerateStrategies(int32_t stage_id) { +Status PackInfo::GenerateStrategies(int64_t stage_id) { if (InferAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": Infer attrs failed"; return FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.h index a1807764303..87de6811662 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/pack_info.h @@ -38,7 +38,7 @@ class PackInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; void ReComputeBatchSplitFlagList() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.cc index 53c08716e95..0a484d340ee 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.cc @@ -191,7 +191,7 @@ Status PReLUInfo::InitForCostModel(const StrategyPtr &strategy) { return SUCCESS; } -Status PReLUInfo::GenerateStrategies(int32_t stage_id) { +Status PReLUInfo::GenerateStrategies(int64_t stage_id) { if (inputs_shape_.size() != PRELU_INPUTS_SIZE) { return FAILED; } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.h index 49d298e73b7..2d5b44d0018 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/prelu_info.h @@ -40,7 +40,7 @@ class PReLUInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.cc index 236536baec0..af357b07697 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.cc @@ -40,8 +40,8 @@ Status ReduceMethod::InferDevMatrixShape() { return SUCCESS; } -std::vector ReduceMethod::reduce_dim() { - std::vector dim_list; +std::vector ReduceMethod::reduce_dim() { + std::vector dim_list; if (input_value_.size() < 2) { MS_LOG(EXCEPTION) << name_ << ": Input value size is smaller than 2."; } @@ -51,20 +51,20 @@ std::vector ReduceMethod::reduce_dim() { MS_ASSERT(inputs_shape_.size() == 1); auto input_dim = inputs_shape_.at(0).size(); if (input_value_.back()->isa()) { - auto attr_axis = GetValue>(input_value_.back()); + auto attr_axis = GetValue>(input_value_.back()); // axis is (), reduce all dim if (attr_axis.empty()) { for (size_t i = 0; i < input_dim; ++i) { - dim_list.push_back(SizeToInt(i)); + dim_list.push_back(SizeToLong(i)); } } else { for (auto &axis : attr_axis) { - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } } - } else if (input_value_.back()->isa()) { - int axis = GetValue(input_value_.back()); - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + } else if (input_value_.back()->isa()) { + int64_t axis = GetValue(input_value_.back()); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } else { MS_LOG(EXCEPTION) << "Axis type is invalid."; } @@ -109,7 +109,7 @@ Status ReduceMethod::GetAttrs() { Status ReduceMethod::InferTensorMap() { Shape tensor_map_index, output_tensor_map; - std::vector dim_list; + std::vector dim_list; size_t size = inputs_shape_.at(0).size(); // such as 4: tensor_map_index [3,2,1,0] for (size_t i = 0; i < size; ++i) { @@ -117,7 +117,7 @@ Status ReduceMethod::InferTensorMap() { } dim_list = reduce_dim(); for (size_t i = 0; i < size; ++i) { - if (find(dim_list.begin(), dim_list.end(), SizeToInt(i)) != dim_list.end()) { + if (find(dim_list.begin(), dim_list.end(), SizeToLong(i)) != dim_list.end()) { if (keepdims_) { output_tensor_map.push_back(-1); } else { @@ -140,7 +140,7 @@ bool IsDataParallelStrategy(const Dimensions &strategy, int32_t stage_id) { MS_LOG(EXCEPTION) << "IsDataParallelStrategy: strategy is empty"; } - return (IntToSize(strategy[0]) == total_dev_num); + return (LongToSize(strategy[0]) == total_dev_num); } Status ReduceMethod::InferForwardCommunication() { @@ -154,7 +154,7 @@ Status ReduceMethod::InferForwardCommunication() { return SUCCESS; } forward_op_.clear(); - std::vector dim_list = reduce_dim(); + std::vector dim_list = reduce_dim(); size_t size = stra.size(); // judge if the reduce dim is partitioned. Shape group_creat_map; @@ -166,11 +166,11 @@ Status ReduceMethod::InferForwardCommunication() { } for (size_t index = 0; index < size; ++index) { auto pos = - std::find_if(dim_list.begin(), dim_list.end(), [index](const int32_t &dim) { return SizeToInt(index) == dim; }); + std::find_if(dim_list.begin(), dim_list.end(), [index](const int64_t &dim) { return SizeToLong(index) == dim; }); if (pos != dim_list.end() && stra[index] != 1) { continue; } - group_creat_map.push_back(SizeToInt(size) - SizeToInt(index) - 1); + group_creat_map.push_back(SizeToLong(size) - SizeToLong(index) - 1); } // if repeated calculation and the repeated_calc_num_ insert to the last dimension of dev matrix, @@ -231,7 +231,7 @@ Status ReduceMeanInfo::InferForwardCommunication() { return SUCCESS; } forward_op_.clear(); - std::vector dim_list = reduce_dim(); + std::vector dim_list = reduce_dim(); size_t size = stra.size(); // judge if the reduce dim is partitioned. Shape group_creat_map; @@ -244,11 +244,11 @@ Status ReduceMeanInfo::InferForwardCommunication() { for (size_t index = 0; index < size; ++index) { auto pos = - std::find_if(dim_list.begin(), dim_list.end(), [index](const int32_t &dim) { return SizeToInt(index) == dim; }); + std::find_if(dim_list.begin(), dim_list.end(), [index](const int64_t &dim) { return SizeToLong(index) == dim; }); if (pos != dim_list.end() && stra[index] != 1) { continue; } - group_creat_map.push_back(SizeToInt(size) - SizeToInt(index) - 1); + group_creat_map.push_back(SizeToLong(size) - SizeToLong(index) - 1); } // if repeated calculation and the repeated_calc_num_ insert to the last dimension of dev matrix, @@ -329,12 +329,12 @@ Status ArgMaxWithValueInfo::InferMirrorOps() { } Dimensions ReduceMethod::InferOutputStrategy() { - std::vector dim_list = reduce_dim(); + std::vector dim_list = reduce_dim(); Dimensions output_strategy; Dimensions stra = strategy_->GetInputDim().at(0); // if keepdims_ is true,then output strategy is same with input. for (size_t i = 0; i < stra.size(); ++i) { - if (find(dim_list.begin(), dim_list.end(), SizeToInt(i)) != dim_list.end()) { + if (find(dim_list.begin(), dim_list.end(), SizeToLong(i)) != dim_list.end()) { if (keepdims_) { output_strategy.push_back(1); } @@ -368,7 +368,7 @@ Status ReduceMethod::InferTensorInfo() { return FAILED; } - std::vector dim_list = reduce_dim(); + std::vector dim_list = reduce_dim(); TensorInfo input_tensor_info(input_tensor_layout, input_shape, input_slice_shape); TensorInfo output_tensor_info(output_tensor_layout, output_shape, output_slice_shape); input_tensor_info.set_reduce_dim(dim_list); @@ -381,7 +381,7 @@ Status ReduceMethod::InferTensorInfo() { Status ReduceMethod::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status ReduceMethod::GenerateStrategies(int32_t stage_id) { +Status ReduceMethod::GenerateStrategies(int64_t stage_id) { if ((inputs_shape_.size() != 1) || (outputs_shape_.size() != 1)) { MS_LOG(ERROR) << name_ << ": Inputs shape size or outputs shape size is wrong, " << inputs_shape_.size() << ", " << outputs_shape_.size(); @@ -425,8 +425,8 @@ Status ReduceMethod::InitForCostModel(const StrategyPtr &strategy) { return SUCCESS; } -std::vector ArgMaxWithValueInfo::reduce_dim() { - std::vector dim_list; +std::vector ArgMaxWithValueInfo::reduce_dim() { + std::vector dim_list; auto iter = attrs_.find(AXIS); if (iter == attrs_.end()) { MS_LOG(EXCEPTION) << name_ << ": Don't have attr axis."; @@ -436,19 +436,19 @@ std::vector ArgMaxWithValueInfo::reduce_dim() { auto input_dim = inputs_shape_.at(0).size(); MS_EXCEPTION_IF_NULL(iter->second); if (iter->second->isa()) { - auto attr_axis = GetValue>(iter->second); + auto attr_axis = GetValue>(iter->second); if (attr_axis.empty()) { for (size_t i = 0; i < input_dim; ++i) { - dim_list.push_back(SizeToInt(i)); + dim_list.push_back(SizeToLong(i)); } } else { for (auto &axis : attr_axis) { - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } } - } else if (iter->second->isa()) { - int axis = GetValue(iter->second); - axis < 0 ? dim_list.push_back(axis + SizeToInt(input_dim)) : dim_list.push_back(axis); + } else if (iter->second->isa()) { + int64_t axis = GetValue(iter->second); + axis < 0 ? dim_list.push_back(axis + SizeToLong(input_dim)) : dim_list.push_back(axis); } else { MS_LOG(EXCEPTION) << "Axis type is invalid."; } @@ -461,19 +461,19 @@ Status ArgMaxWithValueInfo::CheckStrategy(const StrategyPtr &strategy) { MS_LOG(ERROR) << name_ << ": CheckStrategy for parent class ReduceMethod failed"; return FAILED; } - std::vector dim_list = reduce_dim(); + std::vector dim_list = reduce_dim(); MS_ASSERT(dim_list.size() == 1); Strategys stra = strategy->GetInputDim(); MS_ASSERT(stra.size() == 1); Shape input_strategy = stra.at(0); MS_ASSERT(dim_list.at(0) < input_strategy.size()); - if (input_strategy.at(IntToSize(dim_list.at(0))) != 1) { + if (input_strategy.at(LongToSize(dim_list.at(0))) != 1) { MS_LOG(WARNING) << name_ << " CheckStrategy for ArgMaxWithValueInfo, the strategy corresponding to axis is not one, real strategy " "is " - << input_strategy.at(IntToSize(dim_list.at(0))) + << input_strategy.at(LongToSize(dim_list.at(0))) << ", the output index may be not compatible with the stand alone Primitive"; } return SUCCESS; @@ -512,7 +512,7 @@ Status ArgMaxWithValueInfo::InferTensorInfo() { return FAILED; } - std::vector dim_list = reduce_dim(); + std::vector dim_list = reduce_dim(); TensorInfo input_tensor_info(input_tensor_layout, input_shape, input_slice_shape); TensorInfo output_tensor_info(output_tensor_layout, output_shape, output_slice_shape); input_tensor_info.set_reduce_dim(dim_list); @@ -531,7 +531,7 @@ Status ArgMaxWithValueInfo::InferAsLossDivisor() { MS_LOG(INFO) << name_ << " has two outputs, use output[0] to infer"; if (outputs_tensor_map_[0].empty()) { - as_loss_divisor_ = SizeToInt(global_device_list_.size()); + as_loss_divisor_ = SizeToLong(global_device_list_.size()); MS_LOG(INFO) << name_ << ": The output is a scalar, use the dev size" << as_loss_divisor_ << " as loss divisor."; return SUCCESS; } @@ -545,7 +545,7 @@ Status ArgMaxWithValueInfo::InferAsLossDivisor() { return SUCCESS; } -Status ArgMaxWithValueInfo::GenerateStrategies(int32_t stage_id) { +Status ArgMaxWithValueInfo::GenerateStrategies(int64_t stage_id) { if ((inputs_shape_.size() != 1) || (outputs_shape_.size() != 2)) { MS_LOG(ERROR) << name_ << ": Inputs shape size or outputs shape size is wrong, " << inputs_shape_.size() << ", " << outputs_shape_.size(); diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.h index 56a83d61d59..9f2f3eeae1d 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/reduce_method_info.h @@ -40,7 +40,7 @@ class ReduceMethod : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: @@ -53,7 +53,7 @@ class ReduceMethod : public OperatorInfo { Status InferTensorMap() override; Status InferTensorInfo() override; Status InferMirrorOps() override; - virtual std::vector reduce_dim(); + virtual std::vector reduce_dim(); Status InferForwardCommunication() override; Status InferDevMatrixShape() override; }; @@ -79,10 +79,10 @@ class ArgMaxWithValueInfo : public ReduceMethod { ~ArgMaxWithValueInfo() override = default; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; protected: - std::vector reduce_dim() override; + std::vector reduce_dim() override; Status CheckStrategy(const StrategyPtr &strategy) override; Status InferMirrorOps() override; Status InferTensorMap() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.cc index 8243f821540..5ae43f2e1fc 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.cc @@ -50,7 +50,7 @@ Status ReLUV2Info::CheckStrategy(const StrategyPtr &strategy) { Status ReLUV2Info::GetAttrs() { return SUCCESS; } -Status ReLUV2Info::GenerateStrategies(int32_t stage_id) { +Status ReLUV2Info::GenerateStrategies(int64_t stage_id) { Shape input0_split(inputs_shape_[0].size(), 1); // the second dimension is not splitable input0_split[1] = 0; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.h index 20423bf4b58..e30ecf267f5 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/reluv2_info.h @@ -42,7 +42,7 @@ class ReLUV2Info : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.cc index e74665d4a8f..1ab418903c9 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.cc @@ -101,8 +101,8 @@ Status ReshapeInfo::GetParameterInput() { for (auto &element : elements) { MS_EXCEPTION_IF_NULL(element); - if (element->isa()) { - int32_t axis = element->cast()->value(); + if (element->isa()) { + int64_t axis = element->cast()->value(); parameter_input_v_.push_back(axis); } else { MS_LOG(ERROR) << name_ << ": The value of axis must be int32."; @@ -289,13 +289,13 @@ void ReshapeInfo::InferTensorInfoByLayout() { Status ReshapeInfo::GetAttrs() { return GetParameterInput(); } void ReshapeInfo::device_number(const StrategyPtr &strategy) { - int32_t stage = 0; + int64_t stage = 0; if (strategy != nullptr) { stage = strategy->GetInputStage(); } CheckGlobalDeviceManager(); global_device_list_ = g_device_manager->GetDeviceListByStageId(stage); - dev_num_ = SizeToInt(global_device_list_.size()); + dev_num_ = SizeToLong(global_device_list_.size()); MS_ASSERT(dev_num_ > 0); } @@ -398,7 +398,7 @@ void ReshapeInfo::SetCostForReshapeWithParameter() { void ReshapeInfo::SetCostForReshape(const mindspore::parallel::StrategyPtr &strategy) { MS_EXCEPTION_IF_NULL(strategy); - int32_t stage_id = strategy->GetInputStage(); + int64_t stage_id = strategy->GetInputStage(); double computation_cost = operator_cost()->GetForwardComputationCost(inputs_tensor_info_, outputs_tensor_info_, stage_id); double communication_cost = operator_cost()->GetCommCost(inputs_tensor_info_, outputs_tensor_info_, stage_id); @@ -420,7 +420,7 @@ void ReshapeInfo::SetCostForReshape(const mindspore::parallel::StrategyPtr &stra strategy_cost_.emplace_back(swc); } -Status ReshapeInfo::GenerateStrategies(int32_t stage_id) { +Status ReshapeInfo::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": GetAttrs failed."; return FAILED; @@ -444,7 +444,7 @@ Status ReshapeInfo::GenerateStrategies(int32_t stage_id) { Status ReshapeInfo::GenetateStrategyCosts(const std::vector> &pre_stra_costs, const std::vector> &next_stra_costs, - int32_t out_index, int32_t in_index, bool is_prev_param) { + int64_t out_index, int64_t in_index, bool is_prev_param) { is_generating_costs_ = true; for (auto pre_stra_cost : pre_stra_costs) { std::vector pre_out_tensor_infos; @@ -453,7 +453,7 @@ Status ReshapeInfo::GenetateStrategyCosts(const std::vectoroutputs_ptr; } - if (pre_out_tensor_infos.size() <= IntToSize(out_index)) { + if (pre_out_tensor_infos.size() <= LongToSize(out_index)) { MS_LOG(ERROR) << "out_index is out of range of the tensor_infos in setting reshape's input_layout"; return FAILED; } @@ -477,7 +477,7 @@ Status ReshapeInfo::GenetateStrategyCosts(const std::vector next_in_tensor_infos = next_stra_cost->inputs_ptr; - if (next_in_tensor_infos.size() <= IntToSize(in_index)) { + if (next_in_tensor_infos.size() <= LongToSize(in_index)) { MS_LOG(ERROR) << "in_index is out of range of the tensor_infos in setting reshape's output_layout"; return FAILED; } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.h index 91e43827260..21dfdce485c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/reshape_info.h @@ -56,18 +56,18 @@ class ReshapeInfo : public OperatorInfo { void SetCostForReshapeWithParameter(); void set_pre_operator_name(const std::string &pre_name) { pre_operator_name_ = pre_name; } void set_next_operator_name(const std::string &next_name) { next_operator_name_ = next_name; } - void set_pre_operator_index(int32_t pre_index) { pre_operator_index_ = pre_index; } - void set_next_operator_index(int32_t next_index) { next_operator_index_ = next_index; } + void set_pre_operator_index(int64_t pre_index) { pre_operator_index_ = pre_index; } + void set_next_operator_index(int64_t next_index) { next_operator_index_ = next_index; } Status GenetateStrategyCosts(const std::vector> &pre_stra_costs, - const std::vector> &next_stra_costs, int32_t out_index, - int32_t in_index, bool is_prev_param); + const std::vector> &next_stra_costs, int64_t out_index, + int64_t in_index, bool is_prev_param); Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; std::string pre_operator_name() const { return pre_operator_name_; } std::string next_operator_name() const { return next_operator_name_; } - int32_t pre_operator_index() const { return pre_operator_index_; } - int32_t next_operator_index() const { return next_operator_index_; } + int64_t pre_operator_index() const { return pre_operator_index_; } + int64_t next_operator_index() const { return next_operator_index_; } protected: Status CheckStrategy(const StrategyPtr &strategy) override; @@ -87,10 +87,10 @@ class ReshapeInfo : public OperatorInfo { void device_number(const StrategyPtr &strategy); Status InferDefaultLayout(const Shape &shape, TensorLayout *const layout); - int32_t dev_num_; - int32_t pre_operator_index_; - int32_t next_operator_index_; - std::vector parameter_input_v_; + int64_t dev_num_; + int64_t pre_operator_index_; + int64_t next_operator_index_; + std::vector parameter_input_v_; std::vector sp_vector_; Dimensions input_strategy_; TensorLayout input_layout_; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/split_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/split_info.cc index 3a9ff4b909d..a442ef6877c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/split_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/split_info.cc @@ -35,8 +35,8 @@ Status SplitInfo::GetAttrs() { auto axis_iter = attrs_.find(AXIS); if (axis_iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(axis_iter->second); - if (axis_iter->second->isa()) { - axis = axis_iter->second->cast()->value(); + if (axis_iter->second->isa()) { + axis = axis_iter->second->cast()->value(); } else { MS_LOG(ERROR) << name_ << ": The value of axis is not int"; return FAILED; @@ -59,8 +59,8 @@ Status SplitInfo::GetAttrs() { auto output_num_iter = attrs_.find(OUTPUT_NUM); if (output_num_iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(output_num_iter->second); - if (output_num_iter->second->isa()) { - output_num = output_num_iter->second->cast()->value(); + if (output_num_iter->second->isa()) { + output_num = output_num_iter->second->cast()->value(); } else { MS_LOG(ERROR) << name_ << ": The value of output_num is not int"; return FAILED; @@ -190,7 +190,7 @@ Status SplitInfo::InferTensorInfo() { Status SplitInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status SplitInfo::GenerateStrategies(int32_t stage_id) { +Status SplitInfo::GenerateStrategies(int64_t stage_id) { if (InferAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": Infer attrs failed"; return FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/split_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/split_info.h index 4e747bad4ff..d1cb9f13519 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/split_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/split_info.h @@ -36,7 +36,7 @@ class SplitInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; std::shared_ptr GenerateBatchStrategies() override; Status SetCostUnderStrategy(const StrategyPtr &) override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.cc index 31be2a09b86..2ec4dbcaf9a 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.cc @@ -28,24 +28,24 @@ namespace mindspore { namespace parallel { -Status StridedSliceInfo::GetMask(const std::string &mask_name, int32_t *mask_value) { +Status StridedSliceInfo::GetMask(const std::string &mask_name, int64_t *mask_value) { if (mask_value == nullptr) { return FAILED; } auto mask_iter = attrs_.find(mask_name); if (mask_iter != attrs_.end()) { MS_EXCEPTION_IF_NULL(mask_iter->second); - if (mask_iter->second->isa()) { - *mask_value = mask_iter->second->cast()->value(); + if (mask_iter->second->isa()) { + *mask_value = mask_iter->second->cast()->value(); } else { - MS_LOG(ERROR) << name_ << ": The value of " << mask_name << " is not int"; + MS_LOG(ERROR) << name_ << ": The value of " << mask_name << " is not int64_t"; return FAILED; } } return SUCCESS; } -Status GetInput(const ValuePtr &input_value, std::vector *input) { +Status GetInput(const ValuePtr &input_value, std::vector *input) { MS_EXCEPTION_IF_NULL(input_value); ValueTuplePtr value_tuple = input_value->cast(); if (value_tuple == nullptr) { @@ -55,8 +55,8 @@ Status GetInput(const ValuePtr &input_value, std::vector *input) { for (auto &element : value_tuple->value()) { MS_EXCEPTION_IF_NULL(element); - if (element->isa()) { - int32_t value = element->cast()->value(); + if (element->isa()) { + int64_t value = element->cast()->value(); input->push_back(value); } else { MS_LOG(ERROR) << "The value must be int32"; @@ -110,7 +110,7 @@ Status StridedSliceInfo::CheckStrategy(const StrategyPtr &strategy) { } Dimensions strategy_value = stra[0]; - bool has_split = std::any_of(strategy_value.begin(), strategy_value.end(), [](int32_t v) { return v > 1; }); + bool has_split = std::any_of(strategy_value.begin(), strategy_value.end(), [](int64_t v) { return v > 1; }); if (has_split && has_mask_) { MS_LOG(ERROR) << name_ << ": When there is a mask, the input is not supported to be split"; return FAILED; @@ -164,8 +164,8 @@ Status StridedSliceInfo::InferTensorMap() { } // cannot use dev_matrix_shape_ replace inputs_shape_[0], because it may not be fully split in all devices. - int32_t size = SizeToInt(inputs_shape_[0].size()); - for (int i = 0; i < size; ++i) { + int64_t size = SizeToLong(inputs_shape_[0].size()); + for (int64_t i = 0; i < size; ++i) { tensor_map.push_back(size - i - 1); } @@ -235,7 +235,7 @@ Status StridedSliceInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status StridedSliceInfo::GenerateStrategies(int32_t stage_id) { +Status StridedSliceInfo::GenerateStrategies(int64_t stage_id) { if (InferAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": Infer attrs failed"; return FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.h index 3225308bf24..0d55557d40f 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/strided_slice_info.h @@ -39,7 +39,7 @@ class StridedSliceInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; std::shared_ptr GenerateBatchStrategies() override; @@ -51,17 +51,17 @@ class StridedSliceInfo : public OperatorInfo { Status InferTensorInfo() override; Status InferDevMatrixShape() override; Status InferTensorMap() override; - Status GetMask(const std::string &mask_name, int32_t *mask_value); + Status GetMask(const std::string &mask_name, int64_t *mask_value); private: - std::vector begin_; - std::vector end_; - std::vector strides_; - int32_t begin_mask_ = 0; - int32_t end_mask_ = 0; - int32_t ellipsis_mask_ = 0; - int32_t new_axis_mask_ = 0; - int32_t shrink_axis_mask_ = 0; + std::vector begin_; + std::vector end_; + std::vector strides_; + int64_t begin_mask_ = 0; + int64_t end_mask_ = 0; + int64_t ellipsis_mask_ = 0; + int64_t new_axis_mask_ = 0; + int64_t shrink_axis_mask_ = 0; bool has_mask_ = false; }; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.cc index d8ec6e587c0..9ef8d6eaac2 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.cc @@ -53,8 +53,8 @@ Status TileInfo::GetAttrs() { for (auto &element : elements) { MS_EXCEPTION_IF_NULL(element); - if (element->isa()) { - int64_t axis = static_cast(element->cast()->value()); + if (element->isa()) { + int64_t axis = static_cast(element->cast()->value()); full_multiples_.push_back(axis); } else { MS_LOG(ERROR) << name_ << ": The value of axis must be int32."; @@ -105,8 +105,8 @@ Status TileInfo::InferTensorMap() { } // cannot use dev_matrix_shape_ replace outputs_shape_[0], because it may not be fully split in all devices. - int32_t size = SizeToInt(outputs_shape_[0].size()); - for (int i = 0; i < size; ++i) { + int64_t size = SizeToLong(outputs_shape_[0].size()); + for (int64_t i = 0; i < size; ++i) { output_tensor_map.push_back(size - i - 1); } @@ -175,10 +175,7 @@ void TileInfo::UpdateMultiples(const CNodePtr &cnode) { auto manager = func_graph->manager(); MS_EXCEPTION_IF_NULL(manager); - std::vector slice_multiples_int; - (void)std::transform(slice_multiples_.begin(), slice_multiples_.end(), std::back_inserter(slice_multiples_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr new_multiples = MakeValue(slice_multiples_int); + ValuePtr new_multiples = MakeValue(slice_multiples_); AnfNodePtr val = NewValueNode(new_multiples); (void)manager->Replace(cnode->input(2), val); } @@ -194,7 +191,7 @@ std::shared_ptr TileInfo::GenerateBatchStrategies() { Status TileInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status TileInfo::GenerateStrategies(int32_t stage_id) { +Status TileInfo::GenerateStrategies(int64_t stage_id) { if (InferAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": Infer attrs failed"; return FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.h index 5ff576e3086..952b4918907 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/tile_info.h @@ -39,7 +39,7 @@ class TileInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t) override; + Status GenerateStrategies(int64_t) override; Status SetCostUnderStrategy(const StrategyPtr &) override; std::shared_ptr GenerateBatchStrategies() override; void UpdateMultiples(const CNodePtr &cnode); diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.cc index 3425e95f4c0..112c64c2ca5 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.cc @@ -96,7 +96,7 @@ Status TmpIdentityInfo::InitForCostModel(const StrategyPtr &strategy) { Status TmpIdentityInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status TmpIdentityInfo::GenerateStrategies(int32_t stage_id) { +Status TmpIdentityInfo::GenerateStrategies(int64_t stage_id) { if ((inputs_shape_.size() != 1) || (outputs_shape_.size() != 1)) { MS_LOG(ERROR) << name_ << ": Inputs shape size or outputs shape size is wrong, " << inputs_shape_.size() << ", " << outputs_shape_.size(); diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.h index 474e18db20f..690823d30f7 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/tmp_identity_info.h @@ -40,7 +40,7 @@ class TmpIdentityInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.cc index 99cc0dfd986..1bfe775ab8c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.cc @@ -68,8 +68,8 @@ Status TransposeInfo::ComputeAxis() { axis_v_.clear(); for (auto &element : elements) { MS_EXCEPTION_IF_NULL(element); - if (element->isa()) { - int32_t axis = element->cast()->value(); + if (element->isa()) { + int64_t axis = element->cast()->value(); axis_v_.push_back(axis); } else { MS_LOG(ERROR) << name_ << ": The value of axis must be int32."; @@ -77,7 +77,7 @@ Status TransposeInfo::ComputeAxis() { } } - for (int32_t i = 0; i < SizeToInt(axis_v_.size()); i++) { + for (int64_t i = 0; i < SizeToLong(axis_v_.size()); i++) { auto iter = std::find(axis_v_.begin(), axis_v_.end(), i); if (iter == axis_v_.end()) { MS_LOG(ERROR) << name_ << ": axis_v_ must be a permutation."; @@ -96,13 +96,13 @@ Status TransposeInfo::InferTensorMap() { Shape tensor_map_index_input; for (size_t j = 0; j < inputs_shape_[0].size(); ++j) { - tensor_map_index_input.push_back(SizeToInt(inputs_shape_[0].size() - j - 1)); + tensor_map_index_input.push_back(SizeToLong(inputs_shape_[0].size() - j - 1)); } inputs_tensor_map_.push_back(tensor_map_index_input); Shape tensor_map_index_output = tensor_map_index_input; - for (uint32_t i = 0; i < tensor_map_index_output.size(); i++) { - tensor_map_index_output[i] = tensor_map_index_input[IntToUint(axis_v_[i])]; + for (uint64_t i = 0; i < tensor_map_index_output.size(); i++) { + tensor_map_index_output[i] = tensor_map_index_input[LongToUlong(axis_v_[i])]; } outputs_tensor_map_.push_back(tensor_map_index_output); return SUCCESS; @@ -112,8 +112,8 @@ Status TransposeInfo::InferTensorMap() { Strategys TransposeInfo::GetOutputsStrategy() { Strategys outputs_strategy; Dimensions strategy = input_strategy_; - for (uint32_t i = 0; i < strategy.size(); i++) { - strategy[i] = input_strategy_[IntToUint(axis_v_[i])]; + for (uint64_t i = 0; i < strategy.size(); i++) { + strategy[i] = input_strategy_[LongToUlong(axis_v_[i])]; } outputs_strategy.push_back(strategy); return outputs_strategy; @@ -191,7 +191,7 @@ Status TransposeInfo::SetCostUnderStrategy(const mindspore::parallel::StrategyPt return SetCostUnderStrategyBase(strategy); } -Status TransposeInfo::GenerateStrategies(int32_t stage_id) { +Status TransposeInfo::GenerateStrategies(int64_t stage_id) { if (GetAttrs() != SUCCESS) { MS_LOG(ERROR) << name_ << ": GetAttrs failed."; return FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.h index 0d017c18214..babd5cb9bbc 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/transpose_info.h @@ -39,7 +39,7 @@ class TransposeInfo : public OperatorInfo { ~TransposeInfo() override = default; Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; protected: @@ -55,7 +55,7 @@ class TransposeInfo : public OperatorInfo { private: Status ComputeAxis(); - std::vector axis_v_; + std::vector axis_v_; Dimensions input_strategy_; }; } // namespace parallel diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.cc index 46b1c3aefe2..118584759f0 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.cc @@ -110,8 +110,8 @@ Status UniqueInfo::CheckStrategy(const StrategyPtr &strategy) { return FAILED; } } - int32_t stage = strategy->GetInputStage(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(stage).size()); + int64_t stage = strategy->GetInputStage(); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(stage).size()); dev_num_ = dev_num; if (stras[0][0] != 1) { MS_LOG(ERROR) << "Currently, unique only support repeat calculate in all devices"; @@ -163,7 +163,7 @@ Status UniqueInfo::InitForCostModel(const StrategyPtr &strategy) { Status UniqueInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status UniqueInfo::GenerateStrategies(int32_t stage_id) { +Status UniqueInfo::GenerateStrategies(int64_t stage_id) { if (inputs_shape_.size() != UNIQUE_INPUTS_SIZE) { return FAILED; } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.h index 1a7d2851d64..0ecf6f6f43c 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/unique_info.h @@ -38,7 +38,7 @@ class UniqueInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; protected: Status CheckStrategy(const StrategyPtr &strategy) override; @@ -52,7 +52,7 @@ class UniqueInfo : public OperatorInfo { Status InferAsLossDivisor() override { return SUCCESS; } private: - int32_t dev_num_ = 1; + int64_t dev_num_ = 1; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.cc index 91a1456e368..93e2c050f55 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.cc @@ -54,7 +54,7 @@ Status UnsortedSegmentOpInfo::GetAttrs() { MS_LOG(ERROR) << name_ << ": input can not be a scalar!"; return FAILED; } - int num_segments = GetValue(input_value_.at(2)); + auto num_segments = GetValue(input_value_.at(2)); if (num_segments < 0) { MS_LOG(ERROR) << name_ << ": the number of segments should be non negative value."; return FAILED; @@ -180,7 +180,7 @@ Status UnsortedSegmentOpInfo::InitForCostModel(const StrategyPtr &strategy) { } // Set the default strategy -Status UnsortedSegmentOpInfo::GenerateStrategies(int32_t stage_id) { +Status UnsortedSegmentOpInfo::GenerateStrategies(int64_t stage_id) { Shape input0_split(inputs_shape_[0].size(), 1); Shapes splittable_inputs = {input0_split}; @@ -278,7 +278,7 @@ std::shared_ptr UnsortedSegmentOpInfo::GenerateBatchStrategies() { ReplaceGraphPtr UnsortedSegmentMinInfo::replace_graph(const CNodePtr &cnode) { auto input_id_strategy = strategy_->GetInputDim().at(1); // 1. the two input shapes are same, and the strategy is not all ones - if (std::any_of(input_id_strategy.begin(), input_id_strategy.end(), [](const int32_t &shard) { return shard > 1; })) { + if (std::any_of(input_id_strategy.begin(), input_id_strategy.end(), [](const int64_t &shard) { return shard > 1; })) { if (ComputeReplaceGraph(cnode) != SUCCESS) { MS_LOG(EXCEPTION) << name_ << ": ComputeReplaceGraph failed."; } @@ -293,17 +293,17 @@ Status UnsortedSegmentMinInfo::ComputeReplaceGraph(const CNodePtr &cnode) { return FAILED; } // Get the attributes of the UnsortedSegmentMin - auto num_segments = GetValue(input_value_.at(2)); + auto num_segments = GetValue(input_value_.at(2)); // Step1: Output branch auto segment_min = gen_g.PushBack({gen_g.NewOpInst(UNSORTED_SEGMENT_MIN), gen_g.virtual_input_node(), - gen_g.virtual_input_node(), CreatInt32Imm(num_segments)}); - auto expandim_output = gen_g.PushBack({gen_g.NewOpInst(EXPAND_DIMS), segment_min, CreatInt32Imm(0)}); + gen_g.virtual_input_node(), CreatInt64Imm(num_segments)}); + auto expandim_output = gen_g.PushBack({gen_g.NewOpInst(EXPAND_DIMS), segment_min, CreatInt64Imm(0)}); auto all_gather_output = gen_g.PushBack({gen_g.NewOpInst(ALL_GATHER), expandim_output}); - auto final_output = gen_g.PushBack({gen_g.NewOpInst(REDUCE_MIN), all_gather_output, CreatInt32Imm(0)}); + auto final_output = gen_g.PushBack({gen_g.NewOpInst(REDUCE_MIN), all_gather_output, CreatInt64Imm(0)}); - std::vector> input_nodes = {std::make_pair(segment_min, 1), - std::make_pair(segment_min, 2)}; - replace_graph_ = std::make_shared>, AnfNodePtr>>( + std::vector> input_nodes = {std::make_pair(segment_min, 1), + std::make_pair(segment_min, 2)}; + replace_graph_ = std::make_shared>, AnfNodePtr>>( std::make_pair(input_nodes, final_output)); return SUCCESS; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.h index 8e684b294b2..1337d4cfa57 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/unsorted_segment_op_info.h @@ -40,7 +40,7 @@ class UnsortedSegmentOpInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; std::shared_ptr GenerateBatchStrategies() override; diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.cc index 308a6642405..871758409f6 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.cc @@ -66,10 +66,10 @@ Status VirtualDatasetInfo::CheckStrategy(const StrategyPtr &strategy) { Status VirtualDatasetInfo::InferDevMatrixShape() { Strategys stra = strategy_->GetInputDim(); Dimensions strategy_first = stra.at(0); - int32_t stage = strategy_->GetInputStage(); + int64_t stage = strategy_->GetInputStage(); CheckGlobalDeviceManager(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(stage).size()); - int32_t batch_split_num = ((int32_t)(strategy_first.at(0))); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(stage).size()); + int64_t batch_split_num = ((int64_t)(strategy_first.at(0))); dev_matrix_shape_.push_back(batch_split_num); if (dev_num > batch_split_num) { dev_matrix_shape_.push_back(dev_num / batch_split_num); @@ -146,7 +146,7 @@ Status VirtualDatasetInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { return SetCostUnderStrategyBase(strategy); } -Status VirtualDatasetInfo::GenerateStrategies(int32_t stage_id) { +Status VirtualDatasetInfo::GenerateStrategies(int64_t stage_id) { MS_EXCEPTION_IF_NULL(ParallelContext::GetInstance()); bool full_batch = ParallelContext::GetInstance()->full_batch(); size_t total_dev_num; @@ -166,7 +166,7 @@ Status VirtualDatasetInfo::GenerateStrategies(int32_t stage_id) { Strategys strategy; for (auto &shape : inputs_shape_) { Shape temp; - temp.emplace_back(SizeToInt(total_dev_num)); + temp.emplace_back(SizeToLong(total_dev_num)); (void)temp.insert(temp.end(), shape.size() - 1, 1); strategy.push_back(temp); } diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.h index fe54954be0b..7088a5267ee 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/virtual_dataset_info.h @@ -37,7 +37,7 @@ class VirtualDatasetInfo : public OperatorInfo { Status Init(const StrategyPtr &strategy) override; Status InitForCostModel(const StrategyPtr &strategy) override; - Status GenerateStrategies(int32_t stage_id) override; + Status GenerateStrategies(int64_t stage_id) override; Status SetCostUnderStrategy(const StrategyPtr &strategy) override; void ReComputeBatchSplitFlagList() override; diff --git a/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc b/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc index e4a4ebc586f..82f11dbc207 100644 --- a/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc +++ b/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc @@ -173,9 +173,9 @@ size_t GetLengthOfDataType(const TypePtr &type) { case kNumberTypeFloat64: return sizeof(double); case kNumberTypeInt: - return sizeof(int); + return sizeof(int64_t); case kNumberTypeUInt: - return sizeof(unsigned int); + return sizeof(unsigned int64_t); case kNumberTypeFloat: return sizeof(float); default: @@ -431,7 +431,7 @@ OperatorInfoPtr CreateTheOperatorInfo(const PrimitivePtr &prim, const CNodePtr & MS_LOG(EXCEPTION) << "Failure: operator " << prim->name() << " SetCostUnderStrategy failed"; } else if (FULLY_USE_DEVICES) { // If configured to fully use devices, then checking for the user-specified strategy - int32_t used_devices = operator_info->used_devices(); + int64_t used_devices = operator_info->used_devices(); MS_EXCEPTION_IF_NULL(g_device_manager); auto total_device_num = g_device_manager->GetDeviceListByStageId(0).size(); // 'used_devices == 1' means that ALL-1 strategy, which is valid in auto-parallel @@ -439,7 +439,7 @@ OperatorInfoPtr CreateTheOperatorInfo(const PrimitivePtr &prim, const CNodePtr & return operator_info; } // 'used_devices == -1' means that 'used_devices_' is not set - if ((used_devices == -1) || IntToSize(used_devices) != total_device_num) { + if ((used_devices == -1) || LongToSize(used_devices) != total_device_num) { MS_LOG(EXCEPTION) << "In configuration 'FULLY_USE_DEVICES' = True, " << "but the specified strategy uses device: " << used_devices << ", total devices: " << total_device_num; @@ -666,7 +666,7 @@ void ConstructCostGraphEdges(const std::vector &all_nodes) { // In this case, 'prev_anf_node' is 'tuple_getitem', the actual precursor node is node before // this 'tuple_getitem' MS_LOG(INFO) << "Jumping the 'tuple_getitem' operator."; - output_index = IntToSize(GetValue(GetValueNode(prev_cnode->input(2)))); + output_index = LongToSize(GetValue(GetValueNode(prev_cnode->input(2)))); prev_cnode = prev_cnode->input(1)->cast(); bool bool_result_tuple = (prev_cnode == nullptr) || (!IsValueNode(prev_cnode->input(0))); if (bool_result_tuple) { @@ -756,10 +756,7 @@ void AugmentCostGraph(const std::vector &all_nodes) { if (input_shape == nullptr) { MS_LOG(EXCEPTION) << "Failure: input_shape is nullptr"; } - std::vector shape_int = input_shape->shape(); - Shape shape; - (void)std::transform(shape_int.begin(), shape_int.end(), std::back_inserter(shape), - [](int sub_shape) { return static_cast(sub_shape); }); + Shape shape = input_shape->shape(); Shapes inputs_shape = {shape}; Shapes outputs_shape = {shape}; // 2) init the attr @@ -806,7 +803,7 @@ void AugmentCostGraph(const std::vector &all_nodes) { std::string edge_name = std::string(IDENTITY_INFO) + OPERATOR_TO_OPERATOR_CONNECTOR + target_op_info->name(); // If the edge between these two operators already has been added, then the edge will not be added again. - if (entire_costgraph->IsEdgeInCostGraph(edge_name, 0, IntToSize(input_index - 1))) { + if (entire_costgraph->IsEdgeInCostGraph(edge_name, 0, LongToSize(input_index - 1))) { continue; } std::shared_ptr edge_ptr = @@ -857,7 +854,7 @@ bool FindReshape(const CNodePtr &cnode, std::unordered_set *op_cach } // find previous node, then obtain its strategy_cost_ vector to get its layout vector. -bool FindPreNodeStraCosts(const AnfNodePtr &node, OperatorInfoPtr *pre_operator_info, int32_t *out_index) { +bool FindPreNodeStraCosts(const AnfNodePtr &node, OperatorInfoPtr *pre_operator_info, int64_t *out_index) { // if previous node is a parameter, handle it in the outsize. if (node->isa()) { return false; @@ -907,7 +904,7 @@ bool FindPreNodeStraCosts(const AnfNodePtr &node, OperatorInfoPtr *pre_operator_ // find next node, then obtain its strategy_cost_ vector to get its layout vector. // if reshape's output connect to several primitive, return the first layout found -bool FindNextNodeStraCosts(const CNodePtr &cnode, OperatorInfoPtr *next_operator_info, int32_t *in_index) { +bool FindNextNodeStraCosts(const CNodePtr &cnode, OperatorInfoPtr *next_operator_info, int64_t *in_index) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(cnode->func_graph()); FuncGraphManagerPtr manager = cnode->func_graph()->manager(); @@ -953,7 +950,7 @@ void ReshapeCostCompute(const std::vector &all_nodes) { MS_ASSERT(cnode->inputs().size() == 3); // get previous node's strategy_cost_ auto pre_node = cnode->input(1); - int32_t out_index = 0; + int64_t out_index = 0; OperatorInfoPtr pre_operator_info; std::vector> pre_stra_costs; auto operator_info = cnode->user_data(); @@ -969,7 +966,7 @@ void ReshapeCostCompute(const std::vector &all_nodes) { pre_stra_costs = pre_operator_info->strategy_cost(); } // get next node's strategy_cost_ - int32_t in_index = 0; + int64_t in_index = 0; OperatorInfoPtr next_operator_info; std::vector> next_stra_costs; bool find_next_node = FindNextNodeStraCosts(cnode, &next_operator_info, &in_index); diff --git a/mindspore/ccsrc/frontend/parallel/step_parallel.cc b/mindspore/ccsrc/frontend/parallel/step_parallel.cc index 6a5dec9d526..f07c332818e 100644 --- a/mindspore/ccsrc/frontend/parallel/step_parallel.cc +++ b/mindspore/ccsrc/frontend/parallel/step_parallel.cc @@ -53,7 +53,7 @@ static const std::set COMMUNICATION_OPS = {ALL_REDUCE, ALL_GATHER, static const std::set INVALID_LOSS_OPS = {GET_NEXT, VIRTUALLOSS}; // g_RefMap, for CNode B input i is a RefKey[Parameter C], // it will be one item in map with key: C, and value: (B, i) -static std::map> g_RefMap; +static std::map> g_RefMap; static void HandleNoUsedParameter(const FuncGraphPtr &root); void SetCommunicationOpGroupLabel(std::vector new_node_input) { @@ -91,7 +91,7 @@ std::vector CreateInput(const Operator &op, const AnfNodePtr &node, for (auto ¶m : params) { AnfNodePtr val = NewValueNode(param.first.second); MS_EXCEPTION_IF_NULL(val); - int32_t position = param.second; + int64_t position = param.second; (void)new_node_input.insert(new_node_input.begin() + position, val); } } @@ -121,7 +121,7 @@ void InsertNode(const Operator &op, const CNodePtr &node, size_t index, const An new_node_prim->set_attr("keep_value_node_input", MakeValue(true)); new_node->set_scope(scope); node_input[0]->set_scope(scope); - manager->SetEdge(node, SizeToInt(index), new_node); + manager->SetEdge(node, SizeToLong(index), new_node); MS_LOG(INFO) << "Insert " << instance_name << " success"; } @@ -179,14 +179,14 @@ void ForwardCommunication(OperatorVector forward_op, const CNodePtr &node) { } } -CNodePtr InsertMakeTuple(const AnfNodePtr &prev, uint32_t num, const FuncGraphPtr &func_graph) { +CNodePtr InsertMakeTuple(const AnfNodePtr &prev, uint64_t num, const FuncGraphPtr &func_graph) { MS_EXCEPTION_IF_NULL(prev); MS_EXCEPTION_IF_NULL(func_graph); std::vector make_tuple_inputs; make_tuple_inputs.push_back(NewValueNode(prim::kPrimMakeTuple)); - for (uint32_t i = 0; i < num; i++) { + for (uint64_t i = 0; i < num; i++) { std::vector tuple_get_item_inputs{NewValueNode(prim::kPrimTupleGetItem), prev, - CreatInt32Imm(UintToInt(i))}; + CreatInt64Imm(UlongToLong(i))}; auto tuple_get_item = func_graph->NewCNode(tuple_get_item_inputs); MS_EXCEPTION_IF_NULL(tuple_get_item); make_tuple_inputs.push_back(tuple_get_item); @@ -200,7 +200,7 @@ CNodePtr InsertMakeTuple(const AnfNodePtr &prev, uint32_t num, const FuncGraphPt } void InsertRedistribution(const RedistributionOpListPtr &redistribution_oplist_ptr, const CNodePtr &node, - const FuncGraphPtr &func_graph, int pos, const CNodePtr &pre_node) { + const FuncGraphPtr &func_graph, int64_t pos, const CNodePtr &pre_node) { MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(pre_node); MS_EXCEPTION_IF_NULL(func_graph); @@ -210,27 +210,27 @@ void InsertRedistribution(const RedistributionOpListPtr &redistribution_oplist_p MS_LOG(EXCEPTION) << "size of OperatorVector and OutPutInfoVector must be the same!"; } for (size_t index = 0; index < (redistribution_oplist_ptr->first).size(); ++index) { - if (pos >= SizeToInt(node->inputs().size())) { + if (pos >= SizeToLong(node->inputs().size())) { MS_LOG(EXCEPTION) << "InsertRedistribution:pos can't be larger than node's inputs'size"; } // Creat new node - AnfNodePtr target_node = node->input(IntToSize(pos)); + AnfNodePtr target_node = node->input(LongToSize(pos)); MS_EXCEPTION_IF_NULL(target_node); // Creat instance_name auto op = (redistribution_oplist_ptr->first)[index]; std::string op_name = (redistribution_oplist_ptr->first)[index].first; std::string instance_name_base = REDISTRIBUTION_OP; std::string instance_name = instance_name_base + "_" + CreateInstanceName(pre_node, index) + op_name; - InsertNode(op, node, IntToSize(pos), target_node, func_graph, instance_name); + InsertNode(op, node, LongToSize(pos), target_node, func_graph, instance_name); if ((redistribution_oplist_ptr->second)[index].first) { - target_node = node->input(IntToSize(pos)); + target_node = node->input(LongToSize(pos)); MS_EXCEPTION_IF_NULL(target_node); (void)InsertMakeTuple(target_node, (redistribution_oplist_ptr->second)[index].second, func_graph); } } } -void InsertGetTensorSliceOp(const Operator &op, const CNodePtr &node, const FuncGraphPtr &func_graph, int pos, +void InsertGetTensorSliceOp(const Operator &op, const CNodePtr &node, const FuncGraphPtr &func_graph, int64_t pos, const std::string &instance_name) { if (func_graph == nullptr) { MS_LOG(EXCEPTION) << "InsertGetTensorSliceOp: the graph is null, the instance name is " << instance_name; @@ -238,14 +238,14 @@ void InsertGetTensorSliceOp(const Operator &op, const CNodePtr &node, const Func FuncGraphManagerPtr manager = func_graph->manager(); MS_EXCEPTION_IF_NULL(manager); - if (pos >= SizeToInt(node->inputs().size())) { + if (pos >= SizeToLong(node->inputs().size())) { MS_LOG(EXCEPTION) << "InsertGetTensorSliceOp: pos can't be larger than node's inputs'size, the instance name is " << instance_name; } // Creat new node - AnfNodePtr pre_node = node->input(IntToSize(pos)); + AnfNodePtr pre_node = node->input(LongToSize(pos)); MS_EXCEPTION_IF_NULL(pre_node); - InsertNode(op, node, IntToSize(pos), pre_node, func_graph, instance_name); + InsertNode(op, node, LongToSize(pos), pre_node, func_graph, instance_name); } TensorLayout GetTensorInLayout(const CNodePtr &middle_node, const PrimitivePtr &middle_prim, @@ -254,7 +254,7 @@ TensorLayout GetTensorInLayout(const CNodePtr &middle_node, const PrimitivePtr & if (middle_prim->name() == TUPLE_GETITEM) { auto value_node = middle_node->input(2)->cast(); MS_EXCEPTION_IF_NULL(value_node); - size_t index_s = IntToSize(GetValue(value_node->value())); + size_t index_s = LongToSize(GetValue(value_node->value())); if (index_s >= distribute_operator->outputs_tensor_info().size()) { MS_LOG(EXCEPTION) << "The index out of range, index: " << index_s << ", vector size: " << distribute_operator->outputs_tensor_info().size(); @@ -308,8 +308,8 @@ OperatorInfoPtr GetDistributeOperator(const CNodePtr &node) { return distribute_operator; } -void Redistribution(const std::pair &node_pair, const OperatorInfoPtr &distribute_operator, - const CNodePtr &middle_node, int index, TensorRedistribution tensor_redistribution, +void Redistribution(const std::pair &node_pair, const OperatorInfoPtr &distribute_operator, + const CNodePtr &middle_node, int64_t index, TensorRedistribution tensor_redistribution, const CNodePtr &pre_node) { FuncGraphPtr func_graph = middle_node->func_graph(); if (func_graph == nullptr) { @@ -335,13 +335,13 @@ void Redistribution(const std::pair &node_pair, const OperatorI return; } - if (IntToSize(index - 1) >= next_distribute_operator->inputs_tensor_info().size()) { + if (LongToSize(index - 1) >= next_distribute_operator->inputs_tensor_info().size()) { MS_LOG(WARNING) << "The index is out of range, the index is " << index - 1 << ", the vector size is " << next_distribute_operator->inputs_tensor_info().size() << "next operator name is " << next_distribute_operator->name(); return; } - TensorInfo tensorinfo_out = next_distribute_operator->inputs_tensor_info()[IntToSize(index - 1)]; + TensorInfo tensorinfo_out = next_distribute_operator->inputs_tensor_info()[LongToSize(index - 1)]; TensorLayout tensorlayout_out = tensorinfo_out.tensor_layout(); TensorLayout tensorlayout_in = GetTensorInLayout(middle_node, middle_prim, distribute_operator); if (tensor_redistribution.Init(tensorlayout_in, tensorlayout_out, dev_list) == FAILED) { @@ -489,7 +489,7 @@ void StepRedistribution(const CNodePtr &node, const OperatorInfoPtr &distribute_ } } -void SplitTensor(const AnfNodePtr &node, const CNodePtr &next_node, int index) { +void SplitTensor(const AnfNodePtr &node, const CNodePtr &next_node, int64_t index) { MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(next_node); OperatorInfoPtr op_info = next_node->user_data(); @@ -512,11 +512,11 @@ void SplitTensor(const AnfNodePtr &node, const CNodePtr &next_node, int index) { MS_LOG(INFO) << "Split tensor for " << op_info->name() << ": The shape of tensor is " << shape_str; // extract tensor layout - if (IntToSize(index - 1) >= op_info->inputs_tensor_info().size()) { + if (LongToSize(index - 1) >= op_info->inputs_tensor_info().size()) { MS_LOG(EXCEPTION) << "The index is out of range, index is " << index - 1 << ", vector size is " << op_info->inputs_tensor_info().size(); } - TensorInfo tensor_info = op_info->inputs_tensor_info()[IntToSize(index - 1)]; + TensorInfo tensor_info = op_info->inputs_tensor_info()[LongToSize(index - 1)]; TensorLayout tensor_layout = tensor_info.tensor_layout(); // Use _GetTensorSlice operator to split the tensor @@ -633,7 +633,7 @@ std::vector ReplaceOpInput(const Operator &replace_op, const std::st } if (!params.empty()) { Param param_first = *(params.begin()); - int32_t first_position = param_first.second; + int64_t first_position = param_first.second; if (first_position == 1) { replace_input.pop_back(); } @@ -642,7 +642,7 @@ std::vector ReplaceOpInput(const Operator &replace_op, const std::st if (val == nullptr) { MS_LOG(EXCEPTION) << "Failure:val is nullptr"; } - int32_t position = param.second; + int64_t position = param.second; (void)replace_input.insert(replace_input.begin() + position, val); } } @@ -750,7 +750,7 @@ void StepReplaceGraph(const ReplaceGraphPtr &replace_graph, const CNodePtr &node static std::unordered_map input_map = {}; static int appear_count = 0; for (auto &replace_input : replace_graph->first) { - auto pre_node = node->input(IntToSize(replace_input.second)); + auto pre_node = node->input(LongToSize(replace_input.second)); auto it = input_map.find(replace_input.first); if (it != input_map.end()) { @@ -767,7 +767,7 @@ void StepReplaceGraph(const ReplaceGraphPtr &replace_graph, const CNodePtr &node (void)manager->Replace(node, replace_output); } -int32_t GetTupleGetItemIndex(const CNodePtr &cnode) { +int64_t GetTupleGetItemIndex(const CNodePtr &cnode) { MS_EXCEPTION_IF_NULL(cnode); if (cnode->inputs().size() != 3) { MS_LOG(EXCEPTION) << cnode->ToString() << " size( " << cnode->inputs().size() << " ) is not 3"; @@ -779,10 +779,10 @@ int32_t GetTupleGetItemIndex(const CNodePtr &cnode) { ValuePtr tuple_index_value = GetValueNode(cnode->input(2)); MS_EXCEPTION_IF_NULL(tuple_index_value); - if (!tuple_index_value->isa()) { + if (!tuple_index_value->isa()) { MS_LOG(EXCEPTION) << "The index of tuple getitem is not int32"; } - return tuple_index_value->cast()->value(); + return tuple_index_value->cast()->value(); } void InsertVirtualDivOp(const VirtualDivOp &virtual_div_op, const CNodePtr &node) { @@ -975,7 +975,7 @@ void InsertMirrorOps(const MirrorOps &mirror_ops, const CNodePtr &node) { continue; } } - manager->SetEdge(node, SizeToInt(index), next_cnode.second); + manager->SetEdge(node, SizeToLong(index), next_cnode.second); continue; } } @@ -1097,11 +1097,11 @@ OperatorInfoPtr NewOperatorInstance(const PrimitivePtr &prim, const PrimitiveAtt StrategyPtr ExtractStrategy(std::unordered_map attrs) { ValueTuplePtr var = attrs[STRATEGY]->cast(); StrategyPtr strategyPtr; - std::vector stages = ParallelContext::GetInstance()->stage(); + std::vector stages = ParallelContext::GetInstance()->stage(); auto res = attrs.find(STAGE_ATTR); - int32_t stage_id = 0; + int64_t stage_id = 0; if (res != attrs.end()) { - stage_id = GetValue(res->second); + stage_id = GetValue(res->second); } if (stage_id && stages.empty()) { MS_LOG(ERROR) << "Find stage id:" << stage_id << " but the pipeline_stages is 0."; @@ -1115,15 +1115,13 @@ StrategyPtr ExtractStrategy(std::unordered_map attrs) { if (var->size() > 0) { std::vector elements = var->value(); Strategys strategy; - for (uint32_t index = 0; index < elements.size(); ++index) { + for (uint64_t index = 0; index < elements.size(); ++index) { Dimensions dim; if (elements[index]->isa()) { ValueTuplePtr value_tuple = elements[index]->cast(); std::vector value_vector = value_tuple->value(); - (void)std::transform( - value_vector.begin(), value_vector.end(), std::back_inserter(dim), [](const ValuePtr &value) { - return value->isa() ? GetValue(value) : static_cast(GetValue(value)); - }); + (void)std::transform(value_vector.begin(), value_vector.end(), std::back_inserter(dim), + [](const ValuePtr &value) { return static_cast(GetValue(value)); }); strategy.push_back(dim); } else { MS_LOG(EXCEPTION) << "Failure:Strategy's format is wrong! Need ValueSequence"; @@ -1152,10 +1150,7 @@ Shapes GetValueListShape(const AnfNodePtr &node) { auto tensor = ele->cast(); MS_EXCEPTION_IF_NULL(tensor); auto one_shape = tensor->shape(); - Shape shape_64; - (void)std::transform(one_shape.begin(), one_shape.end(), std::back_inserter(shape_64), - [](const int &value) { return static_cast(value); }); - shapes.push_back(shape_64); + shapes.push_back(one_shape); } return shapes; } @@ -1197,20 +1192,12 @@ Shapes GetNodeShape(const AnfNodePtr &node) { for (auto &shape : tuple_shape) { auto each_shape = dyn_cast(shape); MS_EXCEPTION_IF_NULL(each_shape); - std::vector shape_int = each_shape->shape(); - Shape new_shape; - (void)std::transform(shape_int.begin(), shape_int.end(), std::back_inserter(new_shape), - [](const int &value) { return static_cast(value); }); - shapes.push_back(new_shape); + shapes.push_back(each_shape->shape()); } } else { auto shape_ptr = dyn_cast(base_shape_ptr); MS_EXCEPTION_IF_NULL(shape_ptr); - std::vector shape_int = shape_ptr->shape(); - Shape new_shape; - (void)std::transform(shape_int.begin(), shape_int.end(), std::back_inserter(new_shape), - [](const int &value) { return static_cast(value); }); - shapes.push_back(new_shape); + shapes.push_back(shape_ptr->shape()); } return shapes; } @@ -1288,7 +1275,7 @@ std::vector ExtractShape(const CNodePtr &node) { if (parameters.size() != 1) { MS_LOG(EXCEPTION) << "Find parameter by ref key node failed"; } - std::pair node_pair = std::make_pair(node, SizeToInt(i)); + std::pair node_pair = std::make_pair(node, SizeToLong(i)); g_RefMap[parameters[0]] = node_pair; input_shapes = GetRefKeyNodeShape(input, func_graph); } else if (IsValueNode(input) || input->isa() || input->isa() || @@ -1314,7 +1301,7 @@ std::vector ExtractShape(const CNodePtr &node) { return shape_all; } -std::pair FindParallelCareNode(const AnfNodePtr &node, int32_t recursion_num) { +std::pair FindParallelCareNode(const AnfNodePtr &node, int32_t recursion_num) { if (recursion_num >= RECURSION_LIMIT) { return std::make_pair(nullptr, 0); } @@ -1350,12 +1337,12 @@ std::pair FindParallelCareNode(const AnfNodePtr &node, int32_t return std::make_pair(nullptr, 0); } -std::pair FindSubGraph(const FuncGraphPtr &graph, const AnfNodePtr ¶meter) { +std::pair FindSubGraph(const FuncGraphPtr &graph, const AnfNodePtr ¶meter) { MS_EXCEPTION_IF_NULL(graph); MS_EXCEPTION_IF_NULL(parameter); FuncGraphManagerPtr manager = graph->manager(); MS_EXCEPTION_IF_NULL(manager); - std::pair prim_anf_node_pair = FindParallelCareNode(parameter, 0); + std::pair prim_anf_node_pair = FindParallelCareNode(parameter, 0); if (prim_anf_node_pair.first != nullptr) { return prim_anf_node_pair; } else { @@ -1373,11 +1360,11 @@ std::pair FindSubGraph(const FuncGraphPtr &graph, const AnfNode } FuncGraphPtr graph_sub = GetValueNode(graph_value_node); auto parameters = graph_sub->parameters(); - if (IntToSize(param_pair.second - 1) >= parameters.size()) { + if (LongToSize(param_pair.second - 1) >= parameters.size()) { MS_LOG(EXCEPTION) << "The index is out of range, index is " << param_pair.second - 1 << ", vector size is " << parameters.size(); } - std::pair res = FindSubGraph(graph_sub, parameters[IntToSize(param_pair.second - 1)]); + std::pair res = FindSubGraph(graph_sub, parameters[LongToSize(param_pair.second - 1)]); if (res.first != nullptr) { return res; } @@ -1430,7 +1417,7 @@ void ApplyParallelOptOnParam(const FuncGraphPtr &root, const AnfNodePtr ¶met } // When this function returns non-empty string, that means parallel optimizer is applied on this parameter. -std::string SetParallelShape(const AnfNodePtr ¶meter, const std::pair &res) { +std::string SetParallelShape(const AnfNodePtr ¶meter, const std::pair &res) { MS_EXCEPTION_IF_NULL(parameter); AbstractBasePtr abstract = parameter->abstract(); MS_EXCEPTION_IF_NULL(abstract); @@ -1441,11 +1428,11 @@ std::string SetParallelShape(const AnfNodePtr ¶meter, const std::pairToString() << " 's OperatorInfoPtr is nullptr"; } - if (IntToSize(res.second - 1) >= distribute_operator->inputs_tensor_info().size()) { + if (LongToSize(res.second - 1) >= distribute_operator->inputs_tensor_info().size()) { MS_LOG(EXCEPTION) << "The index is out of range, index is " << res.second - 1 << ", vector size is " << distribute_operator->inputs_tensor_info().size(); } - TensorInfo tensorinfo_in = distribute_operator->inputs_tensor_info()[IntToSize(res.second - 1)]; + TensorInfo tensorinfo_in = distribute_operator->inputs_tensor_info()[LongToSize(res.second - 1)]; TensorLayout tensor_layout = tensorinfo_in.tensor_layout(); Shape slice_shape = tensor_layout.slice_shape().array(); std::string opt_shard_group; @@ -1504,7 +1491,7 @@ void CoverSliceShape(const FuncGraphPtr &root) { ApplyParallelOptOnParam(root, parameter, group); continue; } - std::pair res = FindSubGraph(root, parameter); + std::pair res = FindSubGraph(root, parameter); if (res.first == nullptr) { MS_LOG(INFO) << "Parameter " << parameter->ToString() << " don't need to set parallel shape"; } else { @@ -1554,7 +1541,7 @@ void SetClonedTensorShapeForOptimizer(const FuncGraphPtr &root) { continue; } // get the cloned index - int32_t cloned_index = param_value->cloned_index(); + int64_t cloned_index = param_value->cloned_index(); // find the be cloned parameter bool found_be_cloned_parameter = false; @@ -1613,11 +1600,11 @@ void SetVirtualDatasetStrategy(const CNodePtr &node) { MS_EXCEPTION_IF_NULL(prim); if (prim->name() == VIRTUAL_DATA_SET) { CheckGlobalDeviceManager(); - int32_t dev_num; + int64_t dev_num; if (full_batch) { dev_num = 1; } else { - dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(0).size()); + dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(0).size()); } auto attrs_temp = prim->attrs(); std::vector shape_list = ExtractShape(node); @@ -1654,7 +1641,7 @@ Status ValidRankCheck(int32_t global_rank, int32_t strategy_stage) { return Status::FAILED; } -Status ValidStageCheck(const std::vector &stages, int32_t strategy_stage) { +Status ValidStageCheck(const std::vector &stages, int32_t strategy_stage) { if (stages.size() > 0) { if (strategy_stage >= 0 && strategy_stage < (int32_t)stages.size()) { return Status::SUCCESS; @@ -1759,8 +1746,8 @@ void ExtractInformation(const std::vector &all_nodes, bool is_traini MS_LOG(INFO) << "there are " << last_forward_node_ids.size() << " output nodes in eval/predict"; } // Get global rank after the checkpoint? - int32_t global_rank = ParallelContext::GetInstance()->global_rank(); - std::vector stages = ParallelContext::GetInstance()->stage(); + int64_t global_rank = ParallelContext::GetInstance()->global_rank(); + std::vector stages = ParallelContext::GetInstance()->stage(); for (auto &node : all_nodes) { auto cnode = node->cast(); if ((cnode == nullptr) || !IsValueNode(cnode->input(0))) { @@ -1847,17 +1834,17 @@ void ExtractInformation(const std::vector &all_nodes, bool is_traini } } -TensorLayout GetInputLayoutFromCNode(const std::pair &node_pair) { +TensorLayout GetInputLayoutFromCNode(const std::pair &node_pair) { CNodePtr cnode = node_pair.first->cast(); MS_EXCEPTION_IF_NULL(cnode); OperatorInfoPtr distribute_operator = GetDistributeOperator(cnode); MS_EXCEPTION_IF_NULL(distribute_operator); - int index = node_pair.second; - if (index > SizeToInt(distribute_operator->inputs_tensor_info().size())) { + int64_t index = node_pair.second; + if (index > SizeToLong(distribute_operator->inputs_tensor_info().size())) { MS_LOG(EXCEPTION) << "The index is out of range, the node_pair.second is " << index - 1 << ", the vector size is " << distribute_operator->inputs_tensor_info().size(); } - TensorInfo tensorinfo_in = distribute_operator->inputs_tensor_info()[IntToSize(index - 1)]; + TensorInfo tensorinfo_in = distribute_operator->inputs_tensor_info()[LongToSize(index - 1)]; TensorLayout tensorlayout_in = tensorinfo_in.tensor_layout(); return tensorlayout_in; } @@ -1961,7 +1948,7 @@ std::shared_ptr CreateParameterLayout(const AnfNodePtr &node) { return next_layout; } CheckGlobalDeviceManager(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(0).size()); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(0).size()); TensorLayout input_tensor_layout; // create input_shape Shapes inputs_shape = GetNodeShape(node); @@ -1971,7 +1958,7 @@ std::shared_ptr CreateParameterLayout(const AnfNodePtr &node) { } // create tensor_map size_t shape_size = input_shape_array.size(); - TensorMap input_tensor_map_array(SizeToInt(shape_size) - 1, -1); + TensorMap input_tensor_map_array(SizeToLong(shape_size) - 1, -1); input_tensor_map_array.insert(input_tensor_map_array.begin(), 0); // create dev_matrix Shape dev_matrix_array = {dev_num}; @@ -1986,7 +1973,7 @@ RedistributionOpListPtr InferSensRedistribution(const AnfNodePtr &node, const Te TensorRedistribution tensor_redistribution; // create stand alone layout:TensorMap:[all -1],dev_matrix:[dev_num]. CheckGlobalDeviceManager(); - int32_t dev_num = SizeToInt(g_device_manager->GetDeviceListByStageId(0).size()); + int64_t dev_num = SizeToLong(g_device_manager->GetDeviceListByStageId(0).size()); TensorLayout stand_alone_layout; Shapes inputs_shape = GetNodeShape(node); if (inputs_shape.empty()) { @@ -1998,7 +1985,7 @@ RedistributionOpListPtr InferSensRedistribution(const AnfNodePtr &node, const Te return nullptr; } // TensorMap - TensorMap stand_alone_tensor_map_array(SizeToInt(input_shape_array.size()), -1); + TensorMap stand_alone_tensor_map_array(SizeToLong(input_shape_array.size()), -1); // Dev_matrix Shape dev_matrix_array = {dev_num}; if (stand_alone_layout.InitFromVector(dev_matrix_array, stand_alone_tensor_map_array, input_shape_array) == FAILED) { @@ -2038,7 +2025,7 @@ std::shared_ptr FindPrevLayout(const AnfNodePtr &node) { PrimitivePtr prim = prim_anf_node->value()->cast(); if (prim->name() == TUPLE_GETITEM) { auto tuple_index = GetTupleGetItemIndex(cnode); - auto layout_ptr = FindPrevParallelCareNodeLayout(cnode->input(1), IntToSize(tuple_index)); + auto layout_ptr = FindPrevParallelCareNodeLayout(cnode->input(1), LongToSize(tuple_index)); if (!layout_ptr) { MS_LOG(EXCEPTION) << " Failure:FindPrevLayout failed, tuple_getitem before reshape, but there does not exit a parallel care node " @@ -2199,7 +2186,7 @@ TensorLayouts GetLossNodeGradOutputLayout(const LossNodeInfo &node_info) { << node_info.has_tuple_getitem << ", the output size is " << op_output_size << ", the dout_index is " << node_info.dout_index; - if ((op_output_size == 0) || (op_output_size <= IntToSize(node_info.dout_index))) { + if ((op_output_size == 0) || (op_output_size <= LongToSize(node_info.dout_index))) { MS_LOG(EXCEPTION) << "The index is " << node_info.dout_index << ", but the size of outputs is " << op_output_size; } @@ -2207,7 +2194,7 @@ TensorLayouts GetLossNodeGradOutputLayout(const LossNodeInfo &node_info) { MS_LOG(EXCEPTION) << "Currently, it is not supported that the sens is a tuple."; } - loss_grad_tensor_info = operator_info->outputs_tensor_info()[IntToSize(node_info.dout_index)]; + loss_grad_tensor_info = operator_info->outputs_tensor_info()[LongToSize(node_info.dout_index)]; ret.push_back(loss_grad_tensor_info.tensor_layout()); return ret; } @@ -2543,10 +2530,10 @@ void HandleSymbolicKeyInstance(const FuncGraphPtr &root, const std::vector> NodeParameterName(const CNodePtr &node) { +std::vector> NodeParameterName(const CNodePtr &node) { std::vector node_inputs{node->inputs()}; - std::vector> param_names; - for (int i = 0; i < UintToInt(node_inputs.size()); ++i) { + std::vector> param_names; + for (int64_t i = 0; i < UlongToLong(node_inputs.size()); ++i) { auto input = node_inputs[i]; if (input->isa()) { auto input_parameter = input->cast(); @@ -2600,7 +2587,7 @@ void CheckpointStrategy(const std::vector &all_nodes) { std::string stratey_key_name = prim->name() + "_" + param_name; stra_map[stratey_key_name] = operator_info->strategy(); for (auto param_name_pair : param_names) { - if (param_name_pair.second - 1 >= UintToInt(input_tensor_info.size())) { + if (param_name_pair.second - 1 >= UlongToLong(input_tensor_info.size())) { continue; } tensor_info_map[param_name_pair.first] = input_tensor_info[param_name_pair.second - 1]; @@ -2613,8 +2600,8 @@ void CheckpointStrategy(const std::vector &all_nodes) { if (param_split_shapes.size() != index_offsets.size()) { MS_LOG(EXCEPTION) << "In manual split, the param_split_shapes and index_offsets lenght should be same."; } - std::vector> manual_shape; - for (int i = 0; i < UintToInt(param_split_shapes.size()); ++i) { + std::vector> manual_shape; + for (int64_t i = 0; i < UlongToLong(param_split_shapes.size()); ++i) { manual_shape.push_back({param_split_shapes[i], index_offsets[i]}); } manual_shape_map[param_name] = manual_shape; @@ -2774,10 +2761,10 @@ void MarkForwardCNode(const FuncGraphPtr &root) { Status ParallelInit() { MS_EXCEPTION_IF_NULL(ParallelContext::GetInstance()); - int32_t device_num = ParallelContext::GetInstance()->device_num(); - int32_t global_rank = ParallelContext::GetInstance()->global_rank(); + int64_t device_num = ParallelContext::GetInstance()->device_num(); + int64_t global_rank = ParallelContext::GetInstance()->global_rank(); int32_t split_stage_num = ParallelContext::GetInstance()->pipeline_stage_split_num(); - std::vector stages = ParallelContext::GetInstance()->stage(); + std::vector stages = ParallelContext::GetInstance()->stage(); std::string parallel_mode = ParallelContext::GetInstance()->parallel_mode(); auto ms_context = MsContext::GetInstance(); MS_EXCEPTION_IF_NULL(ms_context); @@ -2991,7 +2978,7 @@ ParameterUsersInfo FindParameterUsers(const AnfNodePtr &node, bool (*IsCareNode) return parameter_users_info; } -Shape ParameterSliceShape(const std::pair ¶m_info) { +Shape ParameterSliceShape(const std::pair ¶m_info) { auto user_cnode = param_info.first->cast(); MS_EXCEPTION_IF_NULL(user_cnode); auto user_input_index = param_info.second; @@ -2999,7 +2986,7 @@ Shape ParameterSliceShape(const std::pair ¶m_info) { MS_EXCEPTION_IF_NULL(op_info); size_t input_tensor_info_size = op_info->inputs_tensor_info().size(); - if (SizeToInt(input_tensor_info_size) <= user_input_index - 1) { + if (SizeToLong(input_tensor_info_size) <= user_input_index - 1) { MS_LOG(EXCEPTION) << op_info->name() << ": the size of inputs tensor info is " << input_tensor_info_size << ", but the index is " << user_input_index - 1; } diff --git a/mindspore/ccsrc/frontend/parallel/step_parallel.h b/mindspore/ccsrc/frontend/parallel/step_parallel.h index 4375853608f..c78729d3806 100644 --- a/mindspore/ccsrc/frontend/parallel/step_parallel.h +++ b/mindspore/ccsrc/frontend/parallel/step_parallel.h @@ -40,7 +40,7 @@ const int32_t RECURSION_LIMIT = 3; struct LossNodeInfo { bool has_tuple_getitem = false; - int dout_index = 0; // now don't support the sens is a tuple + int64_t dout_index = 0; // now don't support the sens is a tuple CNodePtr loss_node = nullptr; }; @@ -49,15 +49,15 @@ std::string CreateInstanceName(const CNodePtr &node, size_t index); void ForwardCommunication(OperatorVector forward_op, const CNodePtr &node); void InsertRedistribution(const RedistributionOpListPtr &redistribution_oplist_ptr, const CNodePtr &node, - const FuncGraphPtr &func_graph, int pos, const CNodePtr &pre_node); + const FuncGraphPtr &func_graph, int64_t pos, const CNodePtr &pre_node); TensorLayout GetTensorInLayout(const CNodePtr &pre_node, const PrimitivePtr &pre_prim, const OperatorInfoPtr &distribute_operator_pre); OperatorInfoPtr GetDistributeOperator(const CNodePtr &node); -void Redistribution(const std::pair &node_pair, const OperatorInfoPtr &distribute_operator, - const CNodePtr &middle_node, int index, TensorRedistribution tensor_redistribution, +void Redistribution(const std::pair &node_pair, const OperatorInfoPtr &distribute_operator, + const CNodePtr &middle_node, int64_t index, TensorRedistribution tensor_redistribution, const CNodePtr &pre_node); bool StrategyFound(std::unordered_map attrs); @@ -106,10 +106,10 @@ std::vector FindParameterByRefKeyNode(const AnfNodePtr &node, const std::vector ExtractShape(const CNodePtr &node); // Find finally sub graph -std::pair FindSubGraph(const FuncGraphPtr &func_graph, const AnfNodePtr ¶meter); +std::pair FindSubGraph(const FuncGraphPtr &func_graph, const AnfNodePtr ¶meter); // Set distribute shape for parameters abstract -std::string SetParallelShape(const AnfNodePtr ¶meter, const std::pair &res); +std::string SetParallelShape(const AnfNodePtr ¶meter, const std::pair &res); // change parameters'shape in resource void CoverSliceShape(const FuncGraphPtr &root); @@ -119,7 +119,7 @@ void SetVirtualDatasetStrategy(const CNodePtr &node); // Creat parallel operator for primitive node(has strategy) void ExtractInformation(const std::vector &all_nodes, bool is_training = true); -TensorLayout GetInputLayoutFromCNode(const std::pair &node_pair); +TensorLayout GetInputLayoutFromCNode(const std::pair &node_pair); std::shared_ptr FindNextLayout(const CNodePtr &node); @@ -135,14 +135,14 @@ void ReshapeInit(const std::vector &all_nodes); void ParallelCommunication(const FuncGraphPtr &root, const std::vector &all_nodes, const FuncGraphManagerPtr &manager); -std::vector> NodeParameterName(const CNodePtr &node); +std::vector> NodeParameterName(const CNodePtr &node); void CheckpointStrategy(const std::vector &all_nodes); // main step of Parallel bool StepParallel(const FuncGraphPtr &func_graph, const opt::OptimizerPtr &optimizer); -int32_t GetTupleGetItemIndex(const CNodePtr &cnode); +int64_t GetTupleGetItemIndex(const CNodePtr &cnode); Status ParallelInit(); diff --git a/mindspore/ccsrc/frontend/parallel/strategy.h b/mindspore/ccsrc/frontend/parallel/strategy.h index 03bee638e75..854245c08c4 100644 --- a/mindspore/ccsrc/frontend/parallel/strategy.h +++ b/mindspore/ccsrc/frontend/parallel/strategy.h @@ -37,7 +37,7 @@ using StrategyPtr = std::shared_ptr; class Strategy { public: - Strategy(int32_t stage, Strategys inputs) + Strategy(int64_t stage, Strategys inputs) : stage_(stage), inputs_(std::move(inputs)), internal_size_(0), internal_stragies_() {} Strategy(const Strategy &another_stra) : stage_(another_stra.GetInputStage()) { @@ -53,7 +53,7 @@ class Strategy { ~Strategy() = default; size_t GetInputNumber() const { return inputs_.size(); } Strategys GetInputDim() const { return inputs_; } - int32_t GetInputStage() const { return stage_; } + int64_t GetInputStage() const { return stage_; } void ExpandInputDimFromOneToTwo() { if (inputs_.size() == 1) { inputs_.push_back(inputs_[0]); @@ -81,7 +81,7 @@ class Strategy { } private: - const int32_t stage_; + const int64_t stage_; // The size of Dimensions must equal to inputs_ tensor dimension. Strategys inputs_; @@ -89,7 +89,7 @@ class Strategy { std::vector internal_stragies_; }; -inline StrategyPtr NewStrategy(const int32_t stage, const Strategys &inputs) { +inline StrategyPtr NewStrategy(const int64_t stage, const Strategys &inputs) { return std::make_shared(stage, inputs); } } // namespace parallel diff --git a/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.cc b/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.cc index 5ac82218438..3074564a4e3 100644 --- a/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.cc +++ b/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.cc @@ -59,27 +59,27 @@ Status StrategyCheckpoint::Load(StrategyMap *strategy_map) { MS_LOG(ERROR) << "Load strategy file failed"; return FAILED; } - size_t node_num = IntToSize(parallel_strategy_map.parallel_strategy_item_size()); + size_t node_num = LongToSize(parallel_strategy_map.parallel_strategy_item_size()); for (size_t i = 0; i < node_num; i++) { - straspb::ParallelStrategyItem parallel_strategy_item = parallel_strategy_map.parallel_strategy_item(SizeToInt(i)); + straspb::ParallelStrategyItem parallel_strategy_item = parallel_strategy_map.parallel_strategy_item(SizeToLong(i)); std::string node_name = parallel_strategy_item.node_name(); straspb::ParallelStrategys parallel_strategys = parallel_strategy_item.parallel_strategys(); - auto stage = (int32_t)parallel_strategys.stage(); - size_t strategys_num = IntToSize(parallel_strategys.parallel_strategy_size()); + auto stage = (int64_t)parallel_strategys.stage(); + size_t strategys_num = LongToSize(parallel_strategys.parallel_strategy_size()); Strategys strategy_inputs; for (size_t j = 0; j < strategys_num; j++) { - straspb::ParallelStrategy parallel_strategy = parallel_strategys.parallel_strategy(SizeToInt(j)); + straspb::ParallelStrategy parallel_strategy = parallel_strategys.parallel_strategy(SizeToLong(j)); Dimensions dimension; - size_t dim_num = IntToSize(parallel_strategy.dim_size()); + size_t dim_num = LongToSize(parallel_strategy.dim_size()); for (size_t k = 0; k < dim_num; k++) { - dimension.push_back(parallel_strategy.dim(SizeToInt(k))); + dimension.push_back(parallel_strategy.dim(SizeToLong(k))); } strategy_inputs.push_back(dimension); } StrategyPtr strategy = NewStrategy(stage, strategy_inputs); (*strategy_map)[node_name] = strategy; - current_stage_ = (int32_t)parallel_strategy_map.current_stage(); + current_stage_ = (int64_t)parallel_strategy_map.current_stage(); } return SUCCESS; } @@ -87,7 +87,7 @@ Status StrategyCheckpoint::Load(StrategyMap *strategy_map) { Status StrategyCheckpoint::Save(const StrategyMap &strategy_map, const TensorInfoMap &tensor_info_map, ManualShapeMap *manual_shape_map) { straspb::ParallelStrategyMap parallel_strategy_map; - parallel_strategy_map.set_current_stage(IntToUint(++current_stage_)); + parallel_strategy_map.set_current_stage(LongToUlong(++current_stage_)); for (auto &node_stra : strategy_map) { straspb::ParallelStrategyItem *parallel_strategy_item = parallel_strategy_map.add_parallel_strategy_item(); MS_EXCEPTION_IF_NULL(parallel_strategy_item); @@ -95,12 +95,12 @@ Status StrategyCheckpoint::Save(const StrategyMap &strategy_map, const TensorInf straspb::ParallelStrategys *parallel_strategys = parallel_strategy_item->mutable_parallel_strategys(); MS_EXCEPTION_IF_NULL(parallel_strategys); MS_EXCEPTION_IF_NULL(node_stra.second); - parallel_strategys->set_stage(IntToUint(node_stra.second->GetInputStage())); + parallel_strategys->set_stage(LongToUlong(node_stra.second->GetInputStage())); for (auto &dims : node_stra.second->GetInputDim()) { straspb::ParallelStrategy *parallel_strategy = parallel_strategys->add_parallel_strategy(); MS_EXCEPTION_IF_NULL(parallel_strategy); for (auto dim : dims) { - parallel_strategy->add_dim(IntToUint(dim)); + parallel_strategy->add_dim(LongToUlong(dim)); } } } @@ -114,7 +114,7 @@ Status StrategyCheckpoint::Save(const StrategyMap &strategy_map, const TensorInf straspb::DevMatrix *dev_matrix = parallel_layouts->add_dev_matrix(); MS_EXCEPTION_IF_NULL(dev_matrix); for (auto dim : tensor_layout.device_arrangement().array()) { - dev_matrix->add_dim(IntToUint(dim)); + dev_matrix->add_dim(LongToUlong(dim)); } straspb::TensorMap *tensor_map = parallel_layouts->add_tensor_map(); MS_EXCEPTION_IF_NULL(tensor_map); diff --git a/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.h b/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.h index 1b1a4e17c06..9dc71cddedc 100644 --- a/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.h +++ b/mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.h @@ -31,7 +31,7 @@ namespace mindspore { namespace parallel { using StrategyMap = std::unordered_map; using TensorInfoMap = std::unordered_map; -using ManualShapeMap = std::unordered_map>>; +using ManualShapeMap = std::unordered_map>>; class StrategyCheckpoint { public: StrategyCheckpoint() { @@ -56,7 +56,7 @@ class StrategyCheckpoint { bool load_checkpoint_on_; bool save_checkpoint_on_; bool CheckPointExit(const std::string path) const; - int32_t current_stage_; + int64_t current_stage_; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/arrangement.cc b/mindspore/ccsrc/frontend/parallel/tensor_layout/arrangement.cc index eb22c631ee2..e6cf0ed732b 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/arrangement.cc +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/arrangement.cc @@ -147,7 +147,7 @@ std::shared_ptr, Arrangement>> Arrangement::G Shape expand_num_list_shape; (void)std::transform(expand_shape_list_ptr->begin(), expand_shape_list_ptr->end(), std::back_inserter(expand_num_list_shape), - [](const Arrangement &arr) { return SizeToInt(arr.GetDimSize()); }); + [](const Arrangement &arr) { return SizeToLong(arr.GetDimSize()); }); Arrangement expand_num_list; Status status = expand_num_list.Init(expand_num_list_shape); if (status != Status::SUCCESS) { @@ -222,7 +222,7 @@ std::shared_ptr Arrangement::GetUnifiedShape(const Arrangement &in2 std::vector Arrangement::GetSqueezeIdx() const { std::vector out; for (size_t i = 0; i < GetDimSize(); i++) { - if (GetDimByIdx(SizeToUint(i)) == 1) { + if (GetDimByIdx(SizeToUlong(i)) == 1) { out.push_back(i); } } diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/array.cc b/mindspore/ccsrc/frontend/parallel/tensor_layout/array.cc index 71c58f1ddb5..fb72289ac90 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/array.cc +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/array.cc @@ -58,7 +58,7 @@ bool Array::operator==(const Array &shape) const { if (GetDimSize() != shape.GetDimSize()) { return false; } - for (uint32_t i = 0; i < GetDimSize(); i++) { + for (uint64_t i = 0; i < GetDimSize(); i++) { if (GetDimByIdx(i) != shape.GetDimByIdx(i)) { return false; } diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.cc b/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.cc index 3080c8279db..aecde779327 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.cc +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.cc @@ -32,10 +32,7 @@ Status ConstructOperator::Init(const RankList &dev_list, const Shape &dev_matrix // skip redistribution for reshape operator OperatorVector ConstructOperator::SkipRedisReshapeOP(Shape shape) { OperatorAttrs attrs; - std::vector shape_int; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr param_value = MakeValue(shape_int); + ValuePtr param_value = MakeValue(shape); Attr param = std::make_pair(SHAPE, param_value); OperatorParams params = {std::make_pair(param, 2)}; OperatorArgs args = std::make_pair(attrs, params); @@ -55,10 +52,7 @@ Status ConstructOperator::ReshapeOP(Shape shape) { return Status::INVALID_ARGUMENT; } OperatorAttrs attrs; - std::vector shape_int; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr param_value = MakeValue(shape_int); + ValuePtr param_value = MakeValue(shape); Attr param = std::make_pair(SHAPE, param_value); OperatorParams params = {std::make_pair(param, 2)}; OperatorArgs args = std::make_pair(attrs, params); @@ -66,7 +60,7 @@ Status ConstructOperator::ReshapeOP(Shape shape) { return Status::SUCCESS; } -Operator CreateStridedSliceOp(int32_t value, const Shape &begin, const Shape &end, const Shape &strides) { +Operator CreateStridedSliceOp(int64_t value, const Shape &begin, const Shape &end, const Shape &strides) { ValuePtr attr_value = MakeValue(value); Attr attr_begin_mask = std::make_pair(BEGIN_MASK, attr_value); Attr attr_end_mask = std::make_pair(END_MASK, attr_value); @@ -75,21 +69,12 @@ Operator CreateStridedSliceOp(int32_t value, const Shape &begin, const Shape &en Attr attr_shrink_axis_mask = std::make_pair(SHRINK_AXIS_MASK, attr_value); OperatorAttrs attrs = {attr_begin_mask, attr_end_mask, attr_ellipsis_mask, attr_new_axis_mask, attr_shrink_axis_mask}; - std::vector begin_int; - (void)std::transform(begin.begin(), begin.end(), std::back_inserter(begin_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr param_begin_value = MakeValue(begin_int); + ValuePtr param_begin_value = MakeValue(begin); Param param_begin = std::make_pair(std::make_pair(BEGIN, param_begin_value), 2); - std::vector end_int; - (void)std::transform(end.begin(), end.end(), std::back_inserter(end_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr param_end_value = MakeValue(end_int); + ValuePtr param_end_value = MakeValue(end); Param param_end = std::make_pair(std::make_pair(END, param_end_value), 3); - std::vector strides_int; - (void)std::transform(strides.begin(), strides.end(), std::back_inserter(strides_int), - [](const int64_t &value) { return static_cast(value); }); - ValuePtr param_strides_value = MakeValue(strides_int); + ValuePtr param_strides_value = MakeValue(strides); Param param_strides = std::make_pair(std::make_pair(STRIDES, param_strides_value), 4); OperatorParams params = {param_begin, param_end, param_strides}; OperatorArgs op_args = std::make_pair(attrs, params); @@ -152,13 +137,13 @@ Status ConstructOperator::StridedSliceOP(Args args) { } Status ConstructOperator::AllGatherOP(int64_t dev_dim) { - if ((IntToSize(dev_dim) >= dev_size_) || (dev_dim < 0)) { + if ((LongToSize(dev_dim) >= dev_size_) || (dev_dim < 0)) { MS_LOG(ERROR) << "Invalid device dimension " << dev_dim << " when construct AllGather operator!"; return Status::INVALID_ARGUMENT; } std::vector group_list; - if (CreateGroupByDim(dev_size_ - IntToSize(dev_dim) - 1, &group_list) != SUCCESS) { + if (CreateGroupByDim(dev_size_ - LongToSize(dev_dim) - 1, &group_list) != SUCCESS) { MS_LOG(ERROR) << "AllGather op: create group failed"; return FAILED; } else if (group_list.empty()) { // this group only has one device, don't need do allgather @@ -177,7 +162,7 @@ Status ConstructOperator::AllGatherOP(int64_t dev_dim) { } Status ConstructOperator::ConcatOP(int64_t concat_dim) { - if (IntToSize(concat_dim) >= tensor_shape_.size()) { + if (LongToSize(concat_dim) >= tensor_shape_.size()) { MS_LOG(ERROR) << "Invalid tensor dimension " << concat_dim << " when construct Concat operator!"; return Status::INVALID_ARGUMENT; } @@ -263,10 +248,10 @@ Status ConstructOperator::CreateGroupByDim(size_t axis, std::vector *grou MS_EXCEPTION_IF_NULL(group); CheckGlobalDeviceManager(); MS_EXCEPTION_IF_NULL(g_device_manager); - int32_t rank = g_device_manager->global_rank(); + int64_t rank = g_device_manager->global_rank(); DeviceMatrix dev_matrix(rank, dev_list_, dev_matrix_shape_); RankList group_devices; - if (dev_matrix.GetDevicesAlongDim(SizeToUint(axis), &group_devices) != SUCCESS) { + if (dev_matrix.GetDevicesAlongDim(SizeToUlong(axis), &group_devices) != SUCCESS) { return FAILED; } // this group only has one device, don't need create the group diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.h b/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.h index 8a3c780e6db..fc63e33f905 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.h +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/construct_operator.h @@ -31,7 +31,7 @@ using Args = std::vector; class ConstructOperator { public: - const int32_t DEFAULT = 0; + const int64_t DEFAULT = 0; ConstructOperator() : dev_size_(0) {} ~ConstructOperator() = default; Status Init(const RankList &dev_list, const Shape &dev_matrix_shape); diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/map.cc b/mindspore/ccsrc/frontend/parallel/tensor_layout/map.cc index d8d5e475122..728944f1964 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/map.cc +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/map.cc @@ -44,7 +44,7 @@ bool Map::IsValidMap() { // check that all none -1 value in array_ is different Shape sorted_array = array_; std::sort(sorted_array.begin(), sorted_array.end()); - int32_t value = MAP_NONE; + int64_t value = MAP_NONE; for (auto &element : sorted_array) { if (element == MAP_NONE) { continue; @@ -65,10 +65,10 @@ int64_t Map::GetMaxItem() const { } } -int32_t Map::GetIndexByValue(int64_t value) const { +int64_t Map::GetIndexByValue(int64_t value) const { auto iter = find(array_.begin(), array_.end(), value); if (iter != array_.end()) { - return static_cast(std::distance(array_.begin(), iter)); + return static_cast(std::distance(array_.begin(), iter)); } else { return MAP_NONE; } @@ -115,7 +115,7 @@ std::shared_ptr Map::ExpandMapByDecreaseNumber(const Arrangement &expand_nu } else { int64_t start_map = expand_num_list.ComputeReverseAccumulateSumInReverseOrder()[static_cast(GetDimByIdx(i))]; - for (int32_t k = expand_num_list.GetDimByReverseIdx(static_cast(GetDimByIdx(i))) - 1; k >= 0; k--) { + for (int64_t k = expand_num_list.GetDimByReverseIdx(static_cast(GetDimByIdx(i))) - 1; k >= 0; k--) { new_shape.push_back(k + start_map); } } diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/map.h b/mindspore/ccsrc/frontend/parallel/tensor_layout/map.h index 3a18bab028e..1cbb9e586dc 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/map.h +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/map.h @@ -28,7 +28,7 @@ namespace mindspore { namespace parallel { -constexpr int32_t MAP_NONE = -1; +constexpr int64_t MAP_NONE = -1; class Map : public Array { public: @@ -36,7 +36,7 @@ class Map : public Array { ~Map() override = default; Status Init(const Shape &array) override; int64_t GetMaxItem() const; - int32_t GetIndexByValue(int64_t value) const; + int64_t GetIndexByValue(int64_t value) const; std::shared_ptr ExpandMapByNone(const Arrangement &expand_num_list) const; std::shared_ptr ExpandMapByDecreaseNumber(const Arrangement &expand_num_list) const; std::shared_ptr> ReMapVector(const std::vector &input_vector) const; diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.cc b/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.cc index 56912f1c7c1..a86bd716499 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.cc +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.cc @@ -85,7 +85,7 @@ Status RedistributionOperatorInfer::InferRedistributionOperator() { size_t index = map_.begin()->first; int64_t in_dim = map_[index]; map_[index] = NONE; - Args args = {SizeToInt(index), in_dim, dev_mat_.GetDimByReverseIdx(LongToSize(in_dim))}; + Args args = {SizeToLong(index), in_dim, dev_mat_.GetDimByReverseIdx(LongToSize(in_dim))}; if (InsertOperator(CONCAT_BY_AXIS, args) == Status::FAILED) { return Status::FAILED; } @@ -96,7 +96,7 @@ Status RedistributionOperatorInfer::InferRedistributionOperator() { Status RedistributionOperatorInfer::InferSplitByAxis() { for (auto iter = map_.begin(); iter != map_.end();) { - uint32_t index = iter->first; + uint64_t index = iter->first; int64_t in_dim = iter->second; int64_t out_dim = out_tensor_map_.GetDimByIdx(index); if (in_dim == out_dim) { @@ -106,7 +106,7 @@ Status RedistributionOperatorInfer::InferSplitByAxis() { if (in_dim == NONE && !std::any_of(map_.begin(), map_.end(), [out_dim](const RedistributionOperatorMap::value_type &a) { return a.second == out_dim; })) { - Args args = {dev_mat_.GetDimByReverseIdx(IntToUint(out_dim)), UintToInt(index), out_dim}; + Args args = {dev_mat_.GetDimByReverseIdx(LongToUlong(out_dim)), UlongToLong(index), out_dim}; if (InsertOperator(SPLIT_BY_AXIS, args) == Status::FAILED) { MS_LOG(ERROR) << "Insert SplitByAxis Error!"; return Status::FAILED; @@ -121,7 +121,7 @@ Status RedistributionOperatorInfer::InferSplitByAxis() { Status RedistributionOperatorInfer::InferPermuteByAxis() { for (auto iter = map_.begin(); iter != map_.end();) { - uint32_t index = iter->first; + uint64_t index = iter->first; int64_t in_dim = map_[index]; int64_t out_dim = out_tensor_map_.GetDimByIdx(index); if (in_dim == out_dim) { @@ -131,11 +131,11 @@ Status RedistributionOperatorInfer::InferPermuteByAxis() { if (in_dim == NONE && std::any_of(map_.begin(), map_.end(), [out_dim](const RedistributionOperatorMap::value_type &a) { return a.second == out_dim; })) { - int32_t cat_dim = in_tensor_map_.GetIndexByValue(out_dim); + int64_t cat_dim = in_tensor_map_.GetIndexByValue(out_dim); int64_t dev_num = dev_mat_.GetDimByReverseIdx(LongToSize(out_dim)); if (is_cost_model_) { - int64_t dev_dim = in_tensor_map_.GetDimByIdx(IntToUint(cat_dim)); - Args args_alltoall = {dev_mat_.GetDimByReverseIdx(IntToUint(dev_dim)), UintToInt(index), cat_dim, dev_dim, + int64_t dev_dim = in_tensor_map_.GetDimByIdx(LongToUlong(cat_dim)); + Args args_alltoall = {dev_mat_.GetDimByReverseIdx(LongToUlong(dev_dim)), UlongToLong(index), cat_dim, dev_dim, dev_num}; if (InsertOperator(PERMUTE_BY_AXIS, args_alltoall) == Status::FAILED) { MS_LOG(ERROR) << "Insert PermuteByAxis Error!"; @@ -143,7 +143,7 @@ Status RedistributionOperatorInfer::InferPermuteByAxis() { } } else { Args args_allconcat = {cat_dim, out_dim, dev_num}; - Args args_allsplit = {dev_num, UintToInt(index), out_dim}; + Args args_allsplit = {dev_num, UlongToLong(index), out_dim}; if (InsertOperator(CONCAT_BY_AXIS, args_allconcat) == Status::FAILED) { MS_LOG(ERROR) << "Insert ConcatByAxis Error!"; return Status::FAILED; @@ -154,7 +154,7 @@ Status RedistributionOperatorInfer::InferPermuteByAxis() { } } (void)map_.erase(iter++); - map_[IntToSize(cat_dim)] = NONE; + map_[LongToSize(cat_dim)] = NONE; } else { (void)++iter; } @@ -164,11 +164,11 @@ Status RedistributionOperatorInfer::InferPermuteByAxis() { Status RedistributionOperatorInfer::InferConcatByAxis() { for (auto iter = map_.begin(); iter != map_.end();) { - uint32_t index = iter->first; + uint64_t index = iter->first; int64_t in_dim = map_[index]; int64_t out_dim = out_tensor_map_.GetDimByIdx(index); if (in_dim != NONE && out_tensor_map_.GetIndexByValue(in_dim) == NONE) { - Args args = {SizeToInt(index), in_dim, dev_mat_.GetDimByReverseIdx(LongToSize(in_dim))}; + Args args = {SizeToLong(index), in_dim, dev_mat_.GetDimByReverseIdx(LongToSize(in_dim))}; if (InsertOperator(CONCAT_BY_AXIS, args) == Status::FAILED) { MS_LOG(ERROR) << "Insert ConcatByAxis Error!"; return Status::FAILED; diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.h b/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.h index 56e98a24b68..341fc198cf0 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.h +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/redistribution_operator_infer.h @@ -31,14 +31,14 @@ namespace parallel { using DeviceArrangement = Shape; using TensorMap = Shape; using TensorShape = Shape; -using RedistributionOperatorMap = std::unordered_map; +using RedistributionOperatorMap = std::unordered_map; using OperatorR = std::pair; using OperatorC = std::pair; using OperatorList = std::vector; class RedistributionOperatorInfer { public: - const int NONE = -1; + const int64_t NONE = -1; explicit RedistributionOperatorInfer(bool construct_op_flag = true) : construct_op_flag_(construct_op_flag), is_cost_model_(false) {} Status Init(const TensorLayout &tensor_layout, const Map &out_tensor_map, RankList dev_list, diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_info.h b/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_info.h index 042851b0df0..30d41997780 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_info.h +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_info.h @@ -44,15 +44,15 @@ class TensorInfo { TensorLayout tensor_layout() const { return tensor_layout_; } Shape slice_shape() const { return slice_shape_; } Shape shape() const { return shape_; } - void set_reduce_dim(const std::vector &dim) { reduce_dim_ = dim; } - std::vector reduce_dim() const { return reduce_dim_; } + void set_reduce_dim(const std::vector &dim) { reduce_dim_ = dim; } + std::vector reduce_dim() const { return reduce_dim_; } Dimensions InferStrategy() const { Dimensions stra; for (size_t i = 0; i < shape_.size(); ++i) { if ((slice_shape_[i] == 0) || (shape_[i] % slice_shape_[i] != 0)) { return stra; } - int32_t dim = (int32_t)(shape_[i] / slice_shape_[i]); + int64_t dim = (int64_t)(shape_[i] / slice_shape_[i]); stra.push_back(dim); } return stra; @@ -63,7 +63,7 @@ class TensorInfo { Shape shape_; Shape slice_shape_; // reduce method's reduce dim - std::vector reduce_dim_; + std::vector reduce_dim_; }; } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.cc b/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.cc index 2549fa53391..4b3393d7cc1 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.cc +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.cc @@ -105,9 +105,9 @@ bool TensorLayout::IsValidTensorLayout() const { } bool TensorLayout::TensorShapeDimensionIsDividedBySplitDeviceDimension() const { - for (uint32_t i = 0; i < tensor_map_.GetDimSize(); i++) { + for (uint64_t i = 0; i < tensor_map_.GetDimSize(); i++) { if (tensor_map_.GetDimByIdx(i) != -1) { - int32_t divisor = GetSliceNumByTensorDimensionIndex(i); + int64_t divisor = GetSliceNumByTensorDimensionIndex(i); if (divisor == 0) { MS_LOG(ERROR) << "GetSliceNumByTensorDimensionIndex is 0"; return false; @@ -127,9 +127,9 @@ void TensorLayout::RemoveElementEqualToOneInDeviceArrangement() { size_t dev_num_left = device_arrangement_origin_.GetDimSize(); for (size_t i = 0; i < dev_num; i++) { if (device_arrangement_origin_.GetDimByIdx(i) == 1) { - int32_t idx = GetTensorDimensionIndexByDeviceDimensionIndex(static_cast(dev_num - 1 - i)); + int64_t idx = GetTensorDimensionIndexByDeviceDimensionIndex(static_cast(dev_num - 1 - i)); if (idx != -1) { - tensor_map_shape[static_cast(idx)] = -1; + tensor_map_shape[static_cast(idx)] = -1; } for (auto &value : tensor_map_shape) { if (value >= SizeToLong(dev_num_left) - 1 - static_cast(i)) { @@ -146,18 +146,18 @@ void TensorLayout::RemoveElementEqualToOneInDeviceArrangement() { } // if idx is not in tensor_map, return -1 -int32_t TensorLayout::GetTensorDimensionIndexByDeviceDimensionIndex(int64_t idx) const { +int64_t TensorLayout::GetTensorDimensionIndexByDeviceDimensionIndex(int64_t idx) const { return tensor_map_.GetIndexByValue(idx); } // tensor_map_.GetDimByIdx(idx) should not be -1 -int32_t TensorLayout::GetSliceDeviceDimensionByTensorDimensionIndex(uint32_t idx) const { - return static_cast(device_arrangement_.GetDimSize()) - 1 - tensor_map_.GetDimByIdx(idx); +int64_t TensorLayout::GetSliceDeviceDimensionByTensorDimensionIndex(uint64_t idx) const { + return static_cast(device_arrangement_.GetDimSize()) - 1 - tensor_map_.GetDimByIdx(idx); } // tensor_map_.GetDimByIdx(idx) should not be -1 -int32_t TensorLayout::GetSliceNumByTensorDimensionIndex(uint32_t idx) const { - return device_arrangement_.GetDimByIdx(static_cast(GetSliceDeviceDimensionByTensorDimensionIndex(idx))); +int64_t TensorLayout::GetSliceNumByTensorDimensionIndex(uint64_t idx) const { + return device_arrangement_.GetDimByIdx(static_cast(GetSliceDeviceDimensionByTensorDimensionIndex(idx))); } std::shared_ptr TensorLayout::ExpandTensorShape(const Arrangement &expanded_shape) const { @@ -188,11 +188,11 @@ std::shared_ptr TensorLayout::ComputeArrangementByExpandedShape(con } std::vector re_map_expand_list; Arrangement empty_arrangement; - for (int32_t i = static_cast(device_arrangement_.GetDimSize()) - 1; i >= 0; i--) { + for (int64_t i = static_cast(device_arrangement_.GetDimSize()) - 1; i >= 0; i--) { if (tensor_map_.GetIndexByValue(i) < 0) { re_map_expand_list.push_back(empty_arrangement); } else { - re_map_expand_list.push_back((*expand_list_ptr)[IntToUint(tensor_map_.GetIndexByValue(i))]); + re_map_expand_list.push_back((*expand_list_ptr)[LongToUlong(tensor_map_.GetIndexByValue(i))]); } } std::shared_ptr new_arrangement_ptr = @@ -326,7 +326,7 @@ Arrangement TensorLayout::slice_shape() const { if (dim == -1) { shape.push_back(num); } else { - int64_t divisor = device_arrangement_.GetDimByReverseIdx(IntToUint(dim)); + int64_t divisor = device_arrangement_.GetDimByReverseIdx(LongToUlong(dim)); shape.push_back(num / divisor); } } diff --git a/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.h b/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.h index 22a00ef4ae3..1d04ff74f99 100644 --- a/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.h +++ b/mindspore/ccsrc/frontend/parallel/tensor_layout/tensor_layout.h @@ -50,9 +50,9 @@ class TensorLayout { void set_layout_transfer(bool flag) { layout_transfer_ = flag; } - int32_t get_field_size() const { return field_size_; } + int64_t get_field_size() const { return field_size_; } - void set_field_size(int32_t field_size) { field_size_ = field_size; } + void set_field_size(int64_t field_size) { field_size_ = field_size; } bool uniform_split() const { return uniform_split_; } @@ -113,10 +113,10 @@ class TensorLayout { std::shared_ptr ComputeArrangementByExpandedShape(const Arrangement &tensor_shape) const; bool IsValidTensorLayout() const; void RemoveElementEqualToOneInDeviceArrangement(); - int32_t GetSliceDeviceDimensionByTensorDimensionIndex(uint32_t idx) const; - int32_t GetSliceNumByTensorDimensionIndex(uint32_t idx) const; + int64_t GetSliceDeviceDimensionByTensorDimensionIndex(uint64_t idx) const; + int64_t GetSliceNumByTensorDimensionIndex(uint64_t idx) const; bool TensorShapeDimensionIsDividedBySplitDeviceDimension() const; - int32_t GetTensorDimensionIndexByDeviceDimensionIndex(int64_t idx) const; + int64_t GetTensorDimensionIndexByDeviceDimensionIndex(int64_t idx) const; Arrangement device_arrangement_origin_; Arrangement tensor_shape_origin_; diff --git a/mindspore/ccsrc/pipeline/jit/action.cc b/mindspore/ccsrc/pipeline/jit/action.cc index d4079c428b1..1f414d7d73b 100644 --- a/mindspore/ccsrc/pipeline/jit/action.cc +++ b/mindspore/ccsrc/pipeline/jit/action.cc @@ -444,7 +444,7 @@ bool KeepValueNodeDuplication(const AnfNodePtr &value_node, const ResourcePtr &r auto &node_users = res->manager()->node_users(); auto &users = node_users[value_node]; auto used_by_keep_value_prim = - std::any_of(users.begin(), users.end(), [](const std::pair &user) -> bool { + std::any_of(users.begin(), users.end(), [](const std::pair &user) -> bool { MS_EXCEPTION_IF_NULL(user.first); auto cnode = user.first->cast(); if (cnode == nullptr) { diff --git a/mindspore/ccsrc/pipeline/jit/parse/data_converter.cc b/mindspore/ccsrc/pipeline/jit/parse/data_converter.cc index ca8469b6c4c..645c68d50fd 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/data_converter.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/data_converter.cc @@ -52,7 +52,7 @@ FuncGraphPtr ConvertToBpropCut(const py::object &obj) { outputs.push_back(NewValueNode(fake_bprop)); py::object code_obj = py::getattr(bprop_func, "__code__"); - size_t inputs_num = py::cast(py::getattr(code_obj, "co_argcount")) - 3; + size_t inputs_num = py::cast(py::getattr(code_obj, "co_argcount")) - 3; for (size_t i = 0; i < inputs_num; ++i) { auto param = bprop_graph->add_parameter(); outputs.push_back(param); @@ -211,10 +211,10 @@ bool ConvertSlice(const py::object &obj, ValuePtr *const data) { if (py::isinstance(py_attr)) { return kNone; } else if (py::isinstance(py_attr)) { - int value = py::cast(py_attr); + int64_t value = py::cast(py_attr); return MakeValue(value); } else { - MS_LOG(EXCEPTION) << "Slice should contain only int or none"; + MS_LOG(EXCEPTION) << "Slice should contain only int64_t or none"; } }; ValuePtr start = convert_func("start"); @@ -300,7 +300,7 @@ bool ConvertNumberWithType(const T &obj, ValuePtr *const data, TypePtr dtype) { *data = std::make_shared(obj); break; default: - *data = std::make_shared(obj); + *data = std::make_shared(obj); } return true; } @@ -344,13 +344,13 @@ bool ConvertNumberWithType(const T &obj, ValuePtr *const data, TypePtr dtype) { return false; } -bool ConvertIntegerWithType(const int &obj, ValuePtr *const data, TypePtr dtype = nullptr) { +bool ConvertIntegerWithType(const int64_t &obj, ValuePtr *const data, TypePtr dtype = nullptr) { if (dtype == nullptr) { - *data = std::make_shared(obj); + *data = std::make_shared(obj); return true; } - return ConvertNumberWithType(obj, data, dtype); + return ConvertNumberWithType(obj, data, dtype); } bool ConvertFloatWithType(const float &obj, ValuePtr *const data, TypePtr dtype = nullptr) { @@ -377,7 +377,7 @@ bool ConvertData(const py::object &obj, ValuePtr *const data, bool use_signature } else if (py::isinstance(obj)) { converted = std::make_shared(py::cast(obj)); } else if (py::isinstance(obj)) { - ret = ConvertIntegerWithType(py::cast(obj), &converted, dtype); + ret = ConvertIntegerWithType(py::cast(obj), &converted, dtype); } else if (py::isinstance(obj)) { ret = ConvertFloatWithType(py::cast(obj), &converted, dtype); } else if (py::isinstance(obj)) { diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index fcb9be0b157..511f1b07a3d 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -227,7 +227,7 @@ void Parser::GenerateArgsNodeForFunction(const FunctionBlockPtr &block, const py block->func_graph()->set_has_kwarg(!py::isinstance(kw_arg_node)); py::list kwonly_args = python_adapter::GetPyObjAttr(func_args, "kwonlyargs"); - block->func_graph()->set_kwonlyargs_count(SizeToInt(kwonly_args.size())); + block->func_graph()->set_kwonlyargs_count(SizeToLong(kwonly_args.size())); MS_EXCEPTION_IF_NULL(ast_); py::list args = ast_->GetArgs(fn_node); @@ -342,7 +342,7 @@ FunctionBlockPtr Parser::ParseFunction(const py::object &node, const FunctionBlo FunctionBlockPtr Parser::ParseStatements(FunctionBlockPtr fn_block, const py::object &nodes) { py::int_ pcount = python_adapter::CallPyObjMethod(nodes, "__len__"); - size_t count = IntToSize(pcount); + size_t count = LongToSize(pcount); MS_LOG(DEBUG) << "The nodes count is " << count; for (size_t i = 0; i < count; i++) { auto node = py::cast(nodes)[i]; @@ -383,7 +383,7 @@ FunctionBlockPtr Parser::ParseStatement(const FunctionBlockPtr &block, const py: MS_LOG(EXCEPTION) << "List size should not be less than 2."; } auto filename = location[0].cast(); - auto line_no = location[1].cast(); + auto line_no = location[1].cast(); auto fn_loc = block->func_graph()->debug_info()->location(); py::str desc = python_adapter::CallPyModFn(ast_->module(), PYTHON_MOD_GET_OBJECT_DESCRIPTION, ast_->function(), fn_loc->file_name(), fn_loc->line()); @@ -414,7 +414,7 @@ AnfNodePtr Parser::ParseExprNode(const FunctionBlockPtr &block, const py::object errcode_ = PARSE_NODE_METHOD_UNSUPPORTED; py::list ret = ast_->CallParserObjMethod(PYTHON_PARSE_GET_LOCATION, node); auto filename = ret[0].cast(); - auto line_no = ret[1].cast(); + auto line_no = ret[1].cast(); auto fn_loc = block->func_graph()->debug_info()->location(); py::str desc = python_adapter::CallPyModFn(ast_->module(), PYTHON_MOD_GET_OBJECT_DESCRIPTION, ast_->function(), fn_loc->file_name(), fn_loc->line()); @@ -460,8 +460,8 @@ LocationPtr Parser::GetLocation(const py::object &node) const { MS_LOG(EXCEPTION) << "List size should not be less than 5."; } // refer to Location::Location() for each member of ret: line, column, line_end, column_end. - auto location = std::make_shared(ret[0].cast(), ret[1].cast(), ret[2].cast(), - ret[3].cast(), ret[4].cast()); + auto location = std::make_shared(ret[0].cast(), ret[1].cast(), ret[2].cast(), + ret[3].cast(), ret[4].cast()); return location; } @@ -540,8 +540,8 @@ AnfNodePtr Parser::ParseNum(const FunctionBlockPtr &, const py::object &node) { py::object obj = python_adapter::GetPyObjAttr(node, "n"); TraceGuard trace_guard(GetLocation(node)); if (py::isinstance(obj)) { - MS_LOG(INFO) << "The Num is int:" << (std::string)py::str(obj); - auto data = py::cast(obj); + MS_LOG(INFO) << "The Num is int64_t:" << (std::string)py::str(obj); + auto data = py::cast(obj); return NewValueNode(data); } else if (py::isinstance(obj)) { MS_LOG(INFO) << "The Num is float:" << (std::string)py::str(obj); @@ -1251,10 +1251,10 @@ FunctionBlockPtr Parser::ParseForIter(const FunctionBlockPtr &block, const py::o // generate the iterator next apply // process as following: `app = next(it); target = app[0]; it = app[1];` CNodePtr app = body_block->func_graph()->NewCNode({op_next, iter_param}); - CNodePtr target_app = body_block->func_graph()->NewCNode({op_getitem, app, NewValueNode(0)}); + CNodePtr target_app = body_block->func_graph()->NewCNode({op_getitem, app, NewValueNode(static_cast(0))}); py::object target_node = python_adapter::GetPyObjAttr(node, "target"); - CNodePtr iter2_app = body_block->func_graph()->NewCNode({op_getitem, app, NewValueNode(1)}); + CNodePtr iter2_app = body_block->func_graph()->NewCNode({op_getitem, app, NewValueNode(static_cast(1))}); WriteAssignVars(body_block, target_node, target_app); // link the variable name with the target @@ -1341,8 +1341,8 @@ FunctionBlockPtr Parser::ParseForLoop(const FunctionBlockPtr &block, const py::o CNodePtr target_var = body_block->func_graph()->NewCNode({op_getitem, iter_node, loop_var}); WriteAssignVars(body_block, target_node, target_var); // create 'i = i + 1' - CNodePtr loop_var_inc = - body_block->func_graph()->NewCNode({NewValueNode(prim::kPrimScalarAdd), loop_var, NewValueNode(1)}); + CNodePtr loop_var_inc = body_block->func_graph()->NewCNode( + {NewValueNode(prim::kPrimScalarAdd), loop_var, NewValueNode(static_cast(1))}); body_block->WriteVariable(loop_var->name(), loop_var_inc); // link the variable name with the target @@ -1356,7 +1356,7 @@ FunctionBlockPtr Parser::ParseForLoop(const FunctionBlockPtr &block, const py::o TraceManager::EndTrace(); after_block->AddPrevBlock(header_block); - block->Jump(header_block, NewValueNode(0)); + block->Jump(header_block, NewValueNode(static_cast(0))); body_block->Mature(); header_block->ConditionalJump(cond_node, body_block, after_block, false); @@ -1447,7 +1447,8 @@ void Parser::HandleAssignTuple(const FunctionBlockPtr &block, const py::object & for (size_t i = 0; i < items.size(); i++) { // Use the Primitive replace the operation resolve node (getitem) // because the getitem will eventually be converted to Primitive node - CNodePtr item_apply = block->func_graph()->NewCNode({op_getitem, assigned_node, NewValueNode(static_cast(i))}); + CNodePtr item_apply = + block->func_graph()->NewCNode({op_getitem, assigned_node, NewValueNode(static_cast(i))}); py::object elt = items[i]; WriteAssignVars(block, elt, item_apply); @@ -1471,7 +1472,7 @@ void Parser::HandleAssignClassMember(const FunctionBlockPtr &block, const py::ob MS_LOG(EXCEPTION) << "List size should not be less than 2."; } auto filename = location[0].cast(); - auto line_no = location[1].cast(); + auto line_no = location[1].cast(); // Now only support the self.xxx = yyy, where self.xxx must be a defined Parameter type if (!py::hasattr(ast()->obj(), common::SafeCStr(attr_name))) { MS_EXCEPTION(TypeError) << "'" << var_name << "' should be a Parameter, but not defined, at " << filename << ":" @@ -1546,7 +1547,7 @@ FunctionBlockPtr Parser::ParseAssign(const FunctionBlockPtr &block, const py::ob AnfNodePtr value_node = ParseExprNode(block, value_object); py::object targets_object = python_adapter::GetPyObjAttr(node, "targets"); py::int_ pcount = python_adapter::CallPyObjMethod(targets_object, "__len__"); - size_t count = IntToSize(pcount); + size_t count = LongToSize(pcount); MS_LOG(DEBUG) << "The nodes count is " << count; for (size_t i = 0; i < count; i++) { auto target_node = py::cast(targets_object)[i]; @@ -1564,7 +1565,7 @@ FunctionBlockPtr Parser::ParseBreak(const FunctionBlockPtr &block, const py::obj MS_LOG(EXCEPTION) << "List size should not be less than 2."; } auto filename = location[0].cast(); - auto line_no = location[1].cast(); + auto line_no = location[1].cast(); MS_LOG(EXCEPTION) << "Unexpected 'break' at " << filename << ":" << line_no; } // Get current loop. @@ -1588,7 +1589,7 @@ FunctionBlockPtr Parser::ParseContinue(const FunctionBlockPtr &block, const py:: MS_LOG(EXCEPTION) << "List size should not be less than 2."; } auto filename = location[0].cast(); - auto line_no = location[1].cast(); + auto line_no = location[1].cast(); MS_LOG(EXCEPTION) << "Unexpected 'continue' at " << filename << ":" << line_no; } // Jump to the header of the loop with iterator called. @@ -1628,8 +1629,8 @@ void Parser::RemoveUnnecessaryPhis() { auto mng = Manage(func_graph_, false); // replace the nodes // remove from inside to outside - for (int idx = SizeToInt(phis.size() - 1); idx >= 0; idx--) { - auto phi = phis[IntToSize(idx)]; + for (int64_t idx = SizeToLong(phis.size() - 1); idx >= 0; idx--) { + auto phi = phis[LongToSize(idx)]; auto new_node = FindPhis(removable_phis, phi); MS_LOG(DEBUG) << "phi " << phi->DebugString() << " to " << new_node->DebugString(); mng->Replace(phi, new_node); @@ -1710,7 +1711,7 @@ bool ParseAst::InitParseAstInfo(const std::string &python_mod_get_parse_method) function_module_ = py::cast(python_adapter::GetPyObjAttr(parser_, "function_module")); function_name_ = py::cast(python_adapter::GetPyObjAttr(parser_, "function_name")); function_filename_ = py::cast(python_adapter::GetPyObjAttr(parser_, "filename")); - function_line_offset_ = py::cast(python_adapter::GetPyObjAttr(parser_, "line_offset")); + function_line_offset_ = py::cast(python_adapter::GetPyObjAttr(parser_, "line_offset")); return true; } diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.h b/mindspore/ccsrc/pipeline/jit/parse/parse.h index efc5d9a9620..4f349efa307 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.h +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.h @@ -36,7 +36,7 @@ namespace mindspore { namespace parse { // Parse status define -enum ParseStatusCode : int { +enum ParseStatusCode : int64_t { PARSE_SUCCESS = 0, PARSE_FUNCTION_IS_NULL, // python function is null PARSE_PARAMETER_INVALID, // parameter is invalid @@ -52,10 +52,10 @@ enum ParseStatusCode : int { // max loop count of for statement, when loop count is less then this value, the for loop will be unrolled, otherwise it // will be sunk(i.e. not unrolled) // NOTE: Since when the for loop was unrolled, it depends backend operators `tuple_getitem` and `scalar_add` which were -// not implemented, so here set MAX_FOR_LOOP_COUNT to int max limit to override default value `600`. This will make +// not implemented, so here set MAX_FOR_LOOP_COUNT to int64_t max limit to override default value `600`. This will make // the for loop will always be unrolled, but don't worry about the memory were exhausted, an exception will be raised // when function call depth execeeds the limit `context.get_context('max_call_depth')`. -const int MAX_FOR_LOOP_COUNT = std::numeric_limits::max(); +const int64_t MAX_FOR_LOOP_COUNT = std::numeric_limits::max(); class AstNodeType; class ParseAst; @@ -324,7 +324,7 @@ class ParseAst { const std::string &function_filename() const { return function_filename_; } - int function_line_offset() const { return function_line_offset_; } + int64_t function_line_offset() const { return function_line_offset_; } py::function function() { return function_; } @@ -357,7 +357,7 @@ class ParseAst { std::string function_name_; std::string function_module_; std::string function_filename_; - int function_line_offset_; + int64_t function_line_offset_; }; // update the graph flags diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse_base.h b/mindspore/ccsrc/pipeline/jit/parse/parse_base.h index 89e91240ab2..167165754d1 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse_base.h +++ b/mindspore/ccsrc/pipeline/jit/parse/parse_base.h @@ -28,14 +28,14 @@ namespace py = pybind11; namespace mindspore { namespace parse { // define the node type -enum AstMainType : int { +enum AstMainType : int64_t { AST_MAIN_TYPE_STMT = 0, // ast.Stmt AST_MAIN_TYPE_EXPR = 1, // ast.Expr AST_MAIN_TYPE_SLICE = 2, // ast.Slice AST_MAIN_TYPE_UNKNOWN = 0xFF // Error }; -enum AstSubType : int { +enum AstSubType : int64_t { AST_SUB_TYPE_AND = 3, // ast.And AST_SUB_TYPE_OR = 4, // ast.Or AST_SUB_TYPE_NAME = 5, // ast.Name @@ -111,7 +111,7 @@ const char PYTHON_EXTERN_PARSE_METHOD[] = "__parse_method__"; const char PYTHON_EXTERN_MINDSPORE_FLAG[] = "_mindspore_flags"; // define the parse constant -const int MAX_COMPARISON_OPS_SUPPORTED = 1; +const int64_t MAX_COMPARISON_OPS_SUPPORTED = 1; const char CUSTOM_BPROP_NAME[] = "bprop"; // define the Namespace name @@ -122,7 +122,7 @@ const char RESOLVE_NAMESPACE_NAME_COMMON_OPS[] = "CommonOPS"; // for common const char RESOLVE_NAMESPACE_NAME_MODULE[] = "Module"; // fro Module namespace // define Resolve type -enum ResolveTypeDef : int { +enum ResolveTypeDef : int64_t { RESOLVE_TYPE_NONE = 0, // resolve None RESOLVE_TYPE_FUNCTION = 1, // reslove function RESOLVE_TYPE_METHOD = 2, // resolve class method diff --git a/mindspore/ccsrc/pipeline/jit/pass.cc b/mindspore/ccsrc/pipeline/jit/pass.cc index 39d6d84bdef..5c6fcbc4f34 100644 --- a/mindspore/ccsrc/pipeline/jit/pass.cc +++ b/mindspore/ccsrc/pipeline/jit/pass.cc @@ -321,7 +321,7 @@ void ReclaimOptimizer() { bool OptPassGroup(const ResourcePtr &res, const std::string &name) { if (res->func_graph() == nullptr) { - MS_LOG(ERROR) << "Opt passes int error"; + MS_LOG(ERROR) << "Opt passes int64_t error"; return false; } diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.cc b/mindspore/ccsrc/pipeline/jit/pipeline.cc index 118ac4016c6..5d65a2ff579 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline.cc @@ -79,12 +79,12 @@ ExecutorPyPtr ExecutorPy::executor_ = nullptr; std::mutex ExecutorPy::instance_lock_; bool ExecutorPy::debugger_terminate_ = false; -std::unordered_map g_args_cache; namespace { -std::string GetBaseNameForIR(int stage_idx, const std::string &action_name) { +std::string GetBaseNameForIR(int64_t stage_idx, const std::string &action_name) { std::ostringstream oss; oss << std::setfill('0') << std::setw(2) << stage_idx << "_" << action_name; return oss.str(); @@ -117,7 +117,7 @@ py::tuple GenerateKey(const std::string &name, const std::unordered_map> ExecutorPy::FetchI } auto weight_name = weight_node->cast()->name(); // find the fakequant from input - int count = 0; - const int max_depth = 5; + int64_t count = 0; + const int64_t max_depth = 5; while (!is_quant_cnode(x)) { if (count >= max_depth) { break; @@ -632,7 +632,7 @@ void Pipeline::Run() { FuncGraphPtr user_graph = nullptr; WITH(MsProfile::GetProfile())[&user_graph, this]() { - int i = 0; + int64_t i = 0; for (auto &action : actions_) { #ifdef ENABLE_TIMELINE DumpTime &dump_time = DumpTime::GetInstance(); @@ -886,19 +886,19 @@ bool InitExecDatasetVm(const std::string &queue_name, int64_t size, int64_t batc MS_LOG(INFO) << "Start InitDataSet Entry"; ShapeVector int_input_indexes; (void)std::transform(input_indexes.begin(), input_indexes.end(), std::back_inserter(int_input_indexes), - [](int64_t item) { return static_cast(item); }); + [](int64_t item) { return static_cast(item); }); std::vector int_shapes; (void)std::transform(shapes.begin(), shapes.end(), std::back_inserter(int_shapes), [](const std::vector &item) { ShapeVector vector_item; (void)std::transform(item.begin(), item.end(), std::back_inserter(vector_item), - [](int64_t inner_item) { return static_cast(inner_item); }); + [](int64_t inner_item) { return static_cast(inner_item); }); return vector_item; }); auto p_init = std::make_shared("InitDataSetQueue"); p_init->set_attr("queue_name", MakeValue(queue_name)); - p_init->set_attr("size", MakeValue(static_cast(size))); - p_init->set_attr("batch_size", MakeValue(static_cast(batch_size))); + p_init->set_attr("size", MakeValue(static_cast(size))); + p_init->set_attr("batch_size", MakeValue(static_cast(batch_size))); p_init->set_attr("types", MakeValue(types)); p_init->set_attr("shapes", MakeValue(int_shapes)); p_init->set_attr("input_indexes", MakeValue(int_input_indexes)); diff --git a/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc b/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc index ba7c7c8bb3d..1e0ed1e5b26 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline_ge.cc @@ -156,11 +156,11 @@ void ConvertObjectToTensors(const py::dict &dict, TensorOrderMap *const tensors) std::string name = py::cast(item.first); if (py::isinstance(item.second.attr("data"))) { // convert float to tensor with shape([1]) - tensor = std::make_shared(kNumberTypeFloat32, std::vector({1})); + tensor = std::make_shared(kNumberTypeFloat32, std::vector({1})); *(static_cast(tensor->data_c())) = py::cast(item.second.attr("data")); } else if (py::isinstance(item.second.attr("data"))) { - // convert int to tensor with shape([1]) - tensor = std::make_shared(kNumberTypeInt32, std::vector({1})); + // convert int64_t to tensor with shape([1]) + tensor = std::make_shared(kNumberTypeInt32, std::vector({1})); *(static_cast(tensor->data_c())) = py::cast(item.second.attr("data")); } else if (py::isinstance(item.second.attr("data"))) { // cast tensor diff --git a/mindspore/ccsrc/pipeline/jit/resource.cc b/mindspore/ccsrc/pipeline/jit/resource.cc index 7f8d7325314..d3a1526877c 100644 --- a/mindspore/ccsrc/pipeline/jit/resource.cc +++ b/mindspore/ccsrc/pipeline/jit/resource.cc @@ -234,7 +234,7 @@ Resource::~Resource() { } Any GetMethodOrAttr(const string &name, const TypeId &type_id, const BuiltInTypeMap &method_map) { - auto type_method_map = method_map.find(static_cast(type_id)); + auto type_method_map = method_map.find(static_cast(type_id)); if (type_method_map == method_map.end()) { return Any(); } @@ -248,10 +248,10 @@ Any GetMethodOrAttr(const string &name, const TypeId &type_id, const BuiltInType bool Resource::IsTypeInBuiltInMap(const TypeId &type) { TypeId type_id = NormalizeTypeId(type); const BuiltInTypeMap &method_map = GetMethodMap(); - auto iter = method_map.find(static_cast(type_id)); + auto iter = method_map.find(static_cast(type_id)); if (iter == method_map.end()) { const BuiltInTypeMap &attr_map = GetAttrMap(); - iter = attr_map.find(static_cast(type_id)); + iter = attr_map.find(static_cast(type_id)); if (iter == attr_map.end()) { return false; } diff --git a/mindspore/ccsrc/pipeline/jit/resource.h b/mindspore/ccsrc/pipeline/jit/resource.h index 4a207588028..71957e4d058 100644 --- a/mindspore/ccsrc/pipeline/jit/resource.h +++ b/mindspore/ccsrc/pipeline/jit/resource.h @@ -46,7 +46,7 @@ const char kPynativeGraphId[] = "graph_id"; class InferenceResource; -using BuiltInTypeMap = std::unordered_map>; +using BuiltInTypeMap = std::unordered_map>; BuiltInTypeMap &GetMethodMap(); diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc index 855104dccd0..6a883bc7ab5 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc @@ -195,7 +195,7 @@ AnfNodePtr MixedPrecisionCastHelper(const AnfNodePtr &source_node, const Abstrac auto &items = x->elements(); std::vector nodes; nodes.emplace_back(NewValueNode(prim::kPrimMakeTuple)); - int idx = 0; + int64_t idx = 0; for (const auto &item : items) { AnfNodePtr tuple_node = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), source_node, NewValueNode(idx)}); @@ -419,12 +419,12 @@ AbstractBasePtr PyInferRes2Abstract(const PrimitivePyPtr &prim_py, const py::dic } if (prim_py->IsCustomPrim()) { // Raise error if output_num is not match the infer result. - int output_num = GetValue(prim_py->GetAttr("output_num")); + int64_t output_num = GetValue(prim_py->GetAttr("output_num")); if (res_spec->isa() && output_num != 1) { MS_LOG(EXCEPTION) << "Custom primitive " << prim_py->ToString() << " output_num " << output_num << " not matches the infer result."; } else if (res_spec->isa() && - (res_spec->cast()->size() != IntToSize(output_num))) { + (res_spec->cast()->size() != LongToSize(output_num))) { MS_LOG(EXCEPTION) << "Custom primitive " << prim_py->ToString() << " output_num " << output_num << " not matches the infer result."; } @@ -607,10 +607,10 @@ EvaluatorPtr InitUniformPrimEvaluator(const PrimitivePtr &primitive, PrimitiveIm return uniform_primitive_evaluator; } -const int kResolveCaseUserDefineClass = 1; -const int kResolveCaseBuiltInType = 2; -const int kResolveCaseFunction = 3; -int GetResolveCase(const TypePtr &data_type) { +const int64_t kResolveCaseUserDefineClass = 1; +const int64_t kResolveCaseBuiltInType = 2; +const int64_t kResolveCaseFunction = 3; +int64_t GetResolveCase(const TypePtr &data_type) { MS_EXCEPTION_IF_NULL(data_type); if (data_type->type_id() == kObjectTypeClass) { return kResolveCaseUserDefineClass; @@ -814,7 +814,7 @@ EvalResultPtr StaticGetter(const AnalysisEnginePtr &engine, const AbstractBasePt MS_LOG(EXCEPTION) << "The value of the attribute could not be inferred: " << item_value->ToString(); } - int case_v = GetResolveCase(data_type); + int64_t case_v = GetResolveCase(data_type); if (case_v == kResolveCaseUserDefineClass) { return GetEvaluatedValueForClassAttrOrMethod(engine, args_spec_list, item_value, data_conf, out_conf); } else if (case_v == kResolveCaseBuiltInType) { diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc index 91d865d7190..ba5ad124b6d 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc @@ -87,7 +87,7 @@ std::shared_ptr ProgramSpecializer::GetFuncGraphSpecialize } std::string GetNextCounter() { - static int g_CloneCounter = 1; + static int64_t g_CloneCounter = 1; std::string str_count = std::to_string(g_CloneCounter); g_CloneCounter++; return str_count; @@ -571,7 +571,7 @@ void FuncGraphSpecializer::ProcessCNode(const CNodePtr &new_node) { namespace { void DumpEvaluatorCache(const EvaluatorCacheMap &evaluator_cache_map, const AbstractBasePtrList &argvals) { MS_LOG(DEBUG) << "Find unique argvals failed: " << argvals.size() << ", " << argvals << ". Check cache all items."; - int i = 0; + int64_t i = 0; for (const auto &item : evaluator_cache_map) { MS_LOG(DEBUG) << "evaluator_cache_map[" << i++ << "]: " << item.first; } diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h index 5912b2f3aae..bba403bcfdf 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h @@ -244,7 +244,7 @@ class AnalysisEngine : public std::enable_shared_from_this { function_call_depth_--; } - unsigned int function_call_depth() { return function_call_depth_; } + uint64_t function_call_depth() { return function_call_depth_; } private: void SetUndeterminedFlag(const EvaluatorPtr &evaluator); @@ -273,7 +273,7 @@ class AnalysisEngine : public std::enable_shared_from_this { EvalResultPtr ExecuteMultipleEvaluators(const std::vector &evaluators, const AnfNodeConfigPtr &out_conf, const ConfigPtrList &args_conf_list); // record current depth of function call statck - unsigned int function_call_depth_; + uint64_t function_call_depth_; #ifdef DEBUG std::vector compute_conf_stack_; diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc index 5f789c52ce0..fe0ed330c1d 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc @@ -74,7 +74,7 @@ namespace pynative { static std::shared_ptr session = nullptr; PynativeExecutorPtr PynativeExecutor::executor_ = nullptr; std::mutex PynativeExecutor::instance_lock_; -int PynativeExecutor::graph_id_ = 0; +int64_t PynativeExecutor::graph_id_ = 0; template void PynativeExecutorTry(PynativeExecutor *const executor, void (PynativeExecutor::*method)(Args...), Args &&... args) { @@ -211,7 +211,7 @@ std::map GetDstType(const py::tuple &py_args, } if (max_type == TypeId::kNumberTypeBool) { if (has_int) { - max_type = TypeId::kNumberTypeInt32; + max_type = TypeId::kNumberTypeInt64; } if (has_float) { max_type = TypeId::kNumberTypeFloat32; @@ -273,10 +273,10 @@ py::object DoParamMixPrecisionCast(bool *is_cast, const py::object obj) { py::object DoParamMixPrecisionCastTuple(bool *is_cast, const py::tuple tuple) { MS_EXCEPTION_IF_NULL(is_cast); - auto tuple_size = static_cast(tuple.size()); + auto tuple_size = static_cast(tuple.size()); py::tuple result(tuple_size); - for (int i = 0; i < tuple_size; i++) { + for (int64_t i = 0; i < tuple_size; i++) { if (py::isinstance(tuple[i])) { MS_LOG(DEBUG) << "Call cast for item " << i; result[i] = DoParamMixPrecisionCast(is_cast, tuple[i]); @@ -497,7 +497,7 @@ void PlantTensorTupleToVector(const py::tuple &tuple_inputs, const PrimitivePtr MS_EXCEPTION_IF_NULL(tensor); input_tensors->emplace_back(tensor); } - op_prim->set_attr(kAttrDynInputSizes, MakeValue(std::vector{SizeToInt(tuple_inputs.size())})); + op_prim->set_attr(kAttrDynInputSizes, MakeValue(std::vector{SizeToLong(tuple_inputs.size())})); } void ConvertValueTupleToTensor(const py::object &input_object, std::vector *input_tensors) { @@ -515,7 +515,7 @@ void ConvertValueTupleToTensor(const py::object &input_object, std::vector *input_tensors, int *tensor_mask) { + std::vector *input_tensors, int64_t *tensor_mask) { MS_EXCEPTION_IF_NULL(op_prim); MS_EXCEPTION_IF_NULL(input_tensors); MS_EXCEPTION_IF_NULL(tensor_mask); @@ -537,7 +537,7 @@ void ConvertMultiPyObjectToTensor(const py::object &input_object, const Primitiv } void ConvertPyObjectToTensor(const py::object &input_object, const PrimitivePtr &op_prim, - std::vector *input_tensors, int *tensor_mask) { + std::vector *input_tensors, int64_t *tensor_mask) { MS_EXCEPTION_IF_NULL(op_prim); MS_EXCEPTION_IF_NULL(input_tensors); MS_EXCEPTION_IF_NULL(tensor_mask); @@ -549,7 +549,7 @@ void ConvertPyObjectToTensor(const py::object &input_object, const PrimitivePtr tensor_ptr = std::make_shared(input_value, kFloat32); *tensor_mask = kValueNodeTensorMask; } else if (py::isinstance(input_object)) { - tensor_ptr = std::make_shared(py::cast(input_object), kInt32); + tensor_ptr = std::make_shared(py::cast(input_object), kInt64); *tensor_mask = kValueNodeTensorMask; } else if (py::isinstance(input_object)) { tensor_ptr = TensorPy::MakeTensor(py::cast(input_object), nullptr); @@ -573,7 +573,7 @@ void ConvertPyObjectToTensor(const py::object &input_object, const PrimitivePtr input_tensors->emplace_back(tensor_ptr); } -void ConstructInputTensor(const OpExecInfoPtr &op_run_info, std::vector *tensors_mask, +void ConstructInputTensor(const OpExecInfoPtr &op_run_info, std::vector *tensors_mask, std::vector *input_tensors) { MS_EXCEPTION_IF_NULL(op_run_info); MS_EXCEPTION_IF_NULL(tensors_mask); @@ -603,16 +603,16 @@ void ConstructInputTensor(const OpExecInfoPtr &op_run_info, std::vector *te continue; } // convert const and tuple input to tensor - int tensor_mask = static_cast(op_run_info->inputs_mask[index]); + int64_t tensor_mask = static_cast(op_run_info->inputs_mask[index]); ConvertPyObjectToTensor(op_run_info->op_inputs[index], op_prim, input_tensors, &tensor_mask); // mark tensors, data : 0, weight : 1, valuenode: 2 - std::vector new_mask(input_tensors->size() - tensors_mask->size(), tensor_mask); + std::vector new_mask(input_tensors->size() - tensors_mask->size(), tensor_mask); tensors_mask->insert(tensors_mask->end(), new_mask.begin(), new_mask.end()); } op_prim->EndRecordAddAttr(); } -void EraseValueNodeTensor(const std::vector &tensors_mask, std::vector *input_tensors) { +void EraseValueNodeTensor(const std::vector &tensors_mask, std::vector *input_tensors) { MS_EXCEPTION_IF_NULL(input_tensors); if (input_tensors->size() != tensors_mask.size()) { MS_LOG(EXCEPTION) << "Input tensors size " << input_tensors->size() << " should be equal to tensors mask size " @@ -1056,7 +1056,7 @@ AnfNodePtr PynativeExecutor::MakeValueNode(const py::object &obj, const std::str ValuePtr PynativeExecutor::GetForwardValue(const OpExecInfoPtr &op_exec_info) { auto id = GetOpId(op_exec_info); - int graph_id = resource_->results()[pipeline::kPynativeGraphId].cast(); + int64_t graph_id = resource_->results()[pipeline::kPynativeGraphId].cast(); auto op = std::to_string(graph_id) + id; op.append(std::to_string(op_id_map_[id])); auto iter = op_forward_map_.find(op); @@ -1081,9 +1081,9 @@ void PynativeExecutor::SaveOutputNodeMap(const std::string &obj_id, const py::ob if (py::isinstance(out_real)) { auto value = py::cast(out_real); - auto size = static_cast(value.size()); + auto size = static_cast(value.size()); if (size > 1) { - for (int i = 0; i < size; ++i) { + for (int64_t i = 0; i < size; ++i) { auto value_id = GetId(value[i]); set_node_map(curr_g_, value_id, cnode, i); } @@ -1114,7 +1114,7 @@ void PynativeExecutor::SaveAllResult(const OpExecInfoPtr &op_exec_info, const CN } } std::string id = GetOpId(op_exec_info); - int graph_id = resource_->results()[pipeline::kPynativeGraphId].cast(); + int64_t graph_id = resource_->results()[pipeline::kPynativeGraphId].cast(); auto op_id = std::to_string(graph_id) + id; op_id.append(std::to_string(op_id_map_[id])); cnode->set_forward(value, op_id); @@ -1303,7 +1303,7 @@ py::object PynativeExecutor::RunOpInMs(const OpExecInfoPtr &op_exec_info, Pynati } std::vector input_tensors; - std::vector tensors_mask; + std::vector tensors_mask; ConstructInputTensor(op_exec_info, &tensors_mask, &input_tensors); // get graph info for checking it whether existing in the cache std::string graph_info = GetSingleOpGraphInfo(op_exec_info, input_tensors); @@ -1419,26 +1419,26 @@ void PynativeExecutor::set_node_map(const FuncGraphPtr &g, const py::object &nod return; } auto tuple = node.cast(); - auto tuple_size = static_cast(tuple.size()); - for (int i = 0; i < tuple_size; ++i) { + auto tuple_size = static_cast(tuple.size()); + for (int64_t i = 0; i < tuple_size; ++i) { auto id = GetId(tuple[i]); if (is_param) { graph_info_map_[g].params.emplace(id); } set_node_map(g, id, cnode, i); - set_tuple_node_map(g, tuple[i], cnode, std::vector{i}, is_param); + set_tuple_node_map(g, tuple[i], cnode, std::vector{i}, is_param); } } void PynativeExecutor::set_tuple_node_map(const FuncGraphPtr &g, const py::object &node, const AnfNodePtr &cnode, - const std::vector &idx, bool is_param) { + const std::vector &idx, bool is_param) { if (!py::isinstance(node)) { return; } auto tuple = node.cast(); - auto tuple_size = static_cast(tuple.size()); - for (int i = 0; i < tuple_size; ++i) { - std::vector tmp = idx; + auto tuple_size = static_cast(tuple.size()); + for (int64_t i = 0; i < tuple_size; ++i) { + std::vector tmp = idx; tmp.emplace_back(i); auto id = GetId(tuple[i]); if (is_param) { @@ -1463,11 +1463,11 @@ void PynativeExecutor::EndGraphInner(const py::object &cell, const py::object &o if (graph_info_map_[curr_g_].node_map.find(out_id) == graph_info_map_[curr_g_].node_map.end()) { if (py::isinstance(out)) { auto tuple = out.cast(); - auto tuple_size = static_cast(tuple.size()); + auto tuple_size = static_cast(tuple.size()); std::vector inputs; inputs.emplace_back(NewValueNode(prim::kPrimMakeTuple)); - for (int i = 0; i < tuple_size; i++) { + for (int64_t i = 0; i < tuple_size; i++) { inputs.emplace_back(GetInput(tuple[i], false)); } auto cnode = curr_g_->NewCNode(inputs); diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h index 54fa41cca46..0b8bc1be881 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h @@ -60,7 +60,7 @@ void ClearPyNativeSession(); struct GraphInfo { std::unordered_set params; // hold input parameters and cell weigths - std::unordered_map>> node_map; + std::unordered_map>> node_map; AnfNodePtr output; std::vector objects; }; @@ -144,20 +144,20 @@ class PynativeExecutor : public std::enable_shared_from_this { void set_pyobj(FuncGraphPtr g, const std::string obj) { graph_info_map_[g].objects.push_back(obj); } void set_node_map(const FuncGraphPtr &g, const py::object &node, const AnfNodePtr &cnode, bool is_param = false); void set_node_map(const FuncGraphPtr &g, const std::string &obj, AnfNodePtr node) { - graph_info_map_[g].node_map[obj] = std::make_pair(node, std::vector{-1}); + graph_info_map_[g].node_map[obj] = std::make_pair(node, std::vector{-1}); } void set_node_map(const FuncGraphPtr &g, const std::string &obj, AnfNodePtr node, int index) { - graph_info_map_[g].node_map[obj] = std::make_pair(node, std::vector{index}); + graph_info_map_[g].node_map[obj] = std::make_pair(node, std::vector{index}); } - void set_node_map(const FuncGraphPtr &g, const std::string &obj, AnfNodePtr node, std::vector index) { + void set_node_map(const FuncGraphPtr &g, const std::string &obj, AnfNodePtr node, std::vector index) { graph_info_map_[g].node_map[obj] = std::make_pair(node, index); } void set_tuple_node_map(const FuncGraphPtr &g, const py::object &node, const AnfNodePtr &cnode, - const std::vector &idx, bool is_param = false); + const std::vector &idx, bool is_param = false); static std::shared_ptr executor_; static std::mutex instance_lock_; - static int graph_id_; + static int64_t graph_id_; bool grad_flag_{false}; bool first_grad_step_{false}; bool grad_is_running{false}; diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute_ge.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute_ge.cc index 0eb8b202062..2fe53eb5d81 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute_ge.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute_ge.cc @@ -86,7 +86,7 @@ bool SetInputsForSingleOpGraph(const OpExecInfoPtr &op_exec_info, const std::vec return false; } - int op_input_idx = 1; + int64_t op_input_idx = 1; size_t size = inputs.size(); for (size_t i = 0; i < size; i++) { if (inputs[i] == nullptr) { @@ -225,7 +225,7 @@ std::vector ConvertOutputTensors(const OpExecInfoPtr &op_exec_info, const std::vector &ge_tensors) { std::vector outputs; AbstractBasePtr abs_base = op_exec_info->abstract; - std::vector> shapes; + std::vector> shapes; if (abs_base != nullptr && abs_base->isa()) { auto arg_tensor = dyn_cast(abs_base); shapes.emplace_back(arg_tensor->shape()->shape()); diff --git a/mindspore/ccsrc/ps/common.h b/mindspore/ccsrc/ps/common.h index 625ad1f9e8a..4b854020bcd 100644 --- a/mindspore/ccsrc/ps/common.h +++ b/mindspore/ccsrc/ps/common.h @@ -59,18 +59,18 @@ constexpr char kSparseAdamOp[] = "Adam"; constexpr char kSparseLazyAdamOp[] = "LazyAdam"; constexpr char kSparseFtrlOp[] = "FTRL"; -constexpr int kInitWeightsCmd = 10; -constexpr int kInitWeightToOptimIdCmd = 11; -constexpr int kInitOptimInputsShapeCmd = 12; -constexpr int kInitKeyToPushNodeIdCmd = 13; -constexpr int kInitEmbeddingsCmd = 20; -constexpr int kCheckReadyForPushCmd = 25; -constexpr int kCheckReadyForPullCmd = 26; -constexpr int kEmbeddingLookupCmd = 30; -constexpr int kFinalizeCmd = 40; +constexpr int64_t kInitWeightsCmd = 10; +constexpr int64_t kInitWeightToOptimIdCmd = 11; +constexpr int64_t kInitOptimInputsShapeCmd = 12; +constexpr int64_t kInitKeyToPushNodeIdCmd = 13; +constexpr int64_t kInitEmbeddingsCmd = 20; +constexpr int64_t kCheckReadyForPushCmd = 25; +constexpr int64_t kCheckReadyForPullCmd = 26; +constexpr int64_t kEmbeddingLookupCmd = 30; +constexpr int64_t kFinalizeCmd = 40; constexpr size_t kInvalidKey = UINT64_MAX; -constexpr int kInvalidID = -1; +constexpr int64_t kInvalidID = -1; using Key = ::ps::Key; using Keys = ::ps::SArray; diff --git a/mindspore/ccsrc/ps/optimizer_info.cc b/mindspore/ccsrc/ps/optimizer_info.cc index 8bfbc4a1a88..a999f81eff9 100644 --- a/mindspore/ccsrc/ps/optimizer_info.cc +++ b/mindspore/ccsrc/ps/optimizer_info.cc @@ -67,7 +67,7 @@ void OptimizerInfo::UpdateOptimInputValue(const std::string &optim_type, const s T *src_data = reinterpret_cast(data) + offset; MS_EXCEPTION_IF_NULL(dst_data); MS_EXCEPTION_IF_NULL(src_data); - int ret = memcpy_s(optim_input->addr, optim_input->size, src_data, size); + int64_t ret = memcpy_s(optim_input->addr, optim_input->size, src_data, size); if (ret != 0) { MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; return; @@ -104,7 +104,7 @@ void DenseOptimInfo::ComputeMean(const std::vector> &, size_ void DenseOptimInfo::Reset() { MS_EXCEPTION_IF_NULL(gradient()->addr); - int ret = memset_s(gradient()->addr, gradient()->size, 0x00, gradient()->size); + int64_t ret = memset_s(gradient()->addr, gradient()->size, 0x00, gradient()->size); if (ret != 0) { MS_LOG(EXCEPTION) << "memset_s error, errorno(" << ret << ")"; return; @@ -131,7 +131,7 @@ void SparseOptimInfo::Accumulate(const Values &values, const Lengths &lengths) { void *src_data = incr_grad_data; MS_EXCEPTION_IF_NULL(dst_data); MS_EXCEPTION_IF_NULL(src_data); - auto ret = memcpy_s(dst_data, dst_size, src_data, src_size); + int64_t ret = memcpy_s(dst_data, dst_size, src_data, src_size); if (ret != 0) { MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; return; @@ -172,7 +172,7 @@ void SparseOptimInfo::ComputeMean(const std::vector> &shapes MS_EXCEPTION_IF_NULL(gradient()); MS_EXCEPTION_IF_NULL(indices()); size_t indices_size = static_cast(indices()->size / sizeof(int)); - int segment_size = gradient()->size / indices()->size; + size_t segment_size = gradient()->size / indices()->size; std::vector new_grad(indices_size * segment_size); std::vector new_indices(indices_size); @@ -185,8 +185,8 @@ void SparseOptimInfo::ComputeMean(const std::vector> &shapes if (input_shapes.size() == 0) { MS_LOG(EXCEPTION) << "Invalid input shapes"; } - int first_dim_size = input_shapes.front(); - int outer_dim_size = segment_size; + size_t first_dim_size = input_shapes.front(); + size_t outer_dim_size = segment_size; if (first_dim_size == 0 || outer_dim_size == 0) { MS_LOG(ERROR) << "Invalid first dim size"; @@ -200,7 +200,7 @@ void SparseOptimInfo::ComputeMean(const std::vector> &shapes size_t original_row_count = input_shapes.front(); if (original_row_count > 0) { size_t offset = 0; - std::map rank_dims = Util::AllRankLocalShard(original_row_count, rank_id, server_num); + std::map rank_dims = Util::AllRankLocalShard(original_row_count, rank_id, server_num); for (size_t i = 0; i < rank_id; i++) { if (rank_dims.count(i) == 0) { MS_LOG(EXCEPTION) << "No local shard number for rank " << i; @@ -215,20 +215,15 @@ void SparseOptimInfo::ComputeMean(const std::vector> &shapes Util::ReduceSparseGradient(grad_data, indices_data, indices_size, segment_size, first_dim_size, outer_dim_size, &unique_sparse_grad); - int reduced_grad_size = unique_sparse_grad.indices_size_ * segment_size * sizeof(float); + int64_t reduced_grad_size = unique_sparse_grad.indices_size_ * segment_size * sizeof(float); MS_EXCEPTION_IF_NULL(unique_sparse_grad.value_); - auto ret = memcpy_s(gradient()->addr, gradient()->size, unique_sparse_grad.value_, reduced_grad_size); + int64_t ret = memcpy_s(gradient()->addr, gradient()->size, unique_sparse_grad.value_, reduced_grad_size); if (ret != 0) { MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; return; } - int reduced_indice_size = unique_sparse_grad.indices_size_ * sizeof(int); + int64_t reduced_indice_size = unique_sparse_grad.indices_size_ * sizeof(int); MS_EXCEPTION_IF_NULL(unique_sparse_grad.indices_); - ret = memcpy_s(indices()->addr, indices()->size, unique_sparse_grad.indices_, reduced_indice_size); - if (ret != 0) { - MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; - return; - } gradient()->size = reduced_grad_size; indices()->size = reduced_indice_size; @@ -295,7 +290,7 @@ SparseAdamOptimInfo::SparseAdamOptimInfo(const AddressPtr &weight, const Address inputs_.push_back(grad); inputs_.push_back(indices); grads_offset_ = grad->size / sizeof(float); - indices_offset_ = indices->size / sizeof(int); + indices_offset_ = indices->size / sizeof(int64_t); } void SparseAdamOptimInfo::Update(const Values &values, const Lengths &lens) { @@ -339,7 +334,7 @@ SparseFtrlOptimInfo::SparseFtrlOptimInfo(const AddressPtr &weight, const Address inputs_.push_back(grad); inputs_.push_back(indices); grads_offset_ = grad->size / sizeof(float); - indices_offset_ = indices->size / sizeof(int); + indices_offset_ = indices->size / sizeof(int64_t); } const AddressPtr &SparseFtrlOptimInfo::gradient() { diff --git a/mindspore/ccsrc/ps/optimizer_info_builder.cc b/mindspore/ccsrc/ps/optimizer_info_builder.cc index 0213505db73..a3f9f67fc73 100644 --- a/mindspore/ccsrc/ps/optimizer_info_builder.cc +++ b/mindspore/ccsrc/ps/optimizer_info_builder.cc @@ -96,7 +96,7 @@ AddressPtr OptimizerInfoBuilder::GenInputAddrPtr(const std::string &optim_type, void *src_data = reinterpret_cast(ps_data) + addr_data_offset; MS_EXCEPTION_IF_NULL(dst_data); MS_EXCEPTION_IF_NULL(src_data); - int ret = memcpy_s(dst_data, dst_size, src_data, src_size); + int64_t ret = memcpy_s(dst_data, dst_size, src_data, src_size); if (ret != 0) { MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; delete[] buffer; @@ -119,7 +119,7 @@ OptimizerInfo *MomentumOptimInfoBuilder::BuildInputs(const WeightPtr &weight, co accumulate->addr = new float[weight->size()]; MS_EXCEPTION_IF_NULL(accumulate->addr); accumulate->size = weight->size() * sizeof(float); - int ret = memset_s(accumulate->addr, accumulate->size, 0x00, accumulate->size); + int64_t ret = memset_s(accumulate->addr, accumulate->size, 0x00, accumulate->size); if (ret != 0) { MS_LOG(EXCEPTION) << "memset_s error, errorno(" << ret << ")"; delete[] reinterpret_cast(accumulate->addr); @@ -146,7 +146,7 @@ OptimizerInfo *SparseAdamOptimInfoBuilder::BuildInputs(const WeightPtr &weight, m->addr = new float[weight->size()]; MS_EXCEPTION_IF_NULL(m->addr); m->size = weight->size() * sizeof(float); - int ret = memset_s(m->addr, m->size, 0x00, m->size); + int64_t ret = memset_s(m->addr, m->size, 0x00, m->size); if (ret != 0) { MS_LOG(EXCEPTION) << "memset_s error, errorno(" << ret << ")"; delete[] reinterpret_cast(m->addr); @@ -205,7 +205,7 @@ OptimizerInfo *SparseFtrlOptimInfoBuilder::BuildInputs(const WeightPtr &weight, MS_EXCEPTION_IF_NULL(linear); linear->addr = new float[weight->size()]; MS_EXCEPTION_IF_NULL(linear->addr); - int ret = memset_s(linear->addr, weight->size() * sizeof(float), 0x00, weight->size() * sizeof(float)); + int64_t ret = memset_s(linear->addr, weight->size() * sizeof(float), 0x00, weight->size() * sizeof(float)); if (ret != 0) { MS_LOG(EXCEPTION) << "memset_s error, errorno(" << ret << ")"; delete[] reinterpret_cast(linear->addr); diff --git a/mindspore/ccsrc/ps/parameter_server.h b/mindspore/ccsrc/ps/parameter_server.h index 86318a1875a..cbb7e5be6a8 100644 --- a/mindspore/ccsrc/ps/parameter_server.h +++ b/mindspore/ccsrc/ps/parameter_server.h @@ -105,7 +105,7 @@ class ParameterServer { ParameterServer *ps_; typedef void (ServerHandler::*RequestHandler)(const ::ps::KVMeta &req_meta, const ::ps::KVPairs &req_data, ::ps::KVPairs *res); - std::unordered_map handlers_; + std::unordered_map handlers_; std::unordered_map init_weights_; std::unordered_map init_weight_to_optim_; std::unordered_map init_optim_info_; @@ -113,7 +113,7 @@ class ParameterServer { bool Init(const FuncGraphPtr &func_graph); void InitOptimInfoBuilders(); - void InitWeightKeyToOptims(const Key &key, const int &optim_id); + void InitWeightKeyToOptims(const Key &key, const int64_t &optim_id); void InitOptimInputsShape(const Keys &keys, const Values &values, const Lengths &lengths); void InitWeight(const Key &key, const WeightPtr &weight); void InitGrad(const Key &key, const GradPtr &grad); @@ -293,13 +293,13 @@ void ParameterServer::ServerHandler::HandleInitEmbeddings(const ::ps::KVMeta const Lengths &lens = req_data.lens; size_t index = 0; - for (int i = 0; i < lens[0]; i++) { + for (int64_t i = 0; i < lens[0]; i++) { input_shape->push_back(static_cast(req_data.vals[index++])); } - for (int j = 0; j < lens[1]; j++) { + for (int64_t j = 0; j < lens[1]; j++) { indices_shape->push_back(static_cast(req_data.vals[index++])); } - for (int k = 0; k < lens[2]; k++) { + for (int64_t k = 0; k < lens[2]; k++) { output_shape->push_back(static_cast(req_data.vals[index++])); } ps_->InitEmbeddingTable(key, shapes); @@ -374,7 +374,7 @@ void ParameterServer::InitOptimInfoBuilders() { } template -void ParameterServer::InitWeightKeyToOptims(const Key &key, const int &optim_id) { +void ParameterServer::InitWeightKeyToOptims(const Key &key, const int64_t &optim_id) { if (weight_key_to_optims_.count(key) > 0 || Util::optimizer_name(optim_id) == "") { return; } @@ -390,7 +390,7 @@ void ParameterServer::InitOptimInputsShape(const Keys &keys, const Values &va MS_EXCEPTION_IF_NULL(inputs_shape); InputsShapePtr original_inputs_shape = std::make_shared(); MS_EXCEPTION_IF_NULL(original_inputs_shape); - int val_idx = 0; + int64_t val_idx = 0; const Key &key = keys[0]; MS_LOG(INFO) << "Initializing optimizer inputs shape for key:" << key; if (optim_inputs_shape_.count(key) == 0) { @@ -405,7 +405,7 @@ void ParameterServer::InitOptimInputsShape(const Keys &keys, const Values &va inputs_shape->push_back(shape); original_inputs_shape->push_back(original_shape); - for (int j = 0; j < lengths[i]; j++) { + for (int64_t j = 0; j < lengths[i]; j++) { shape->push_back(values[val_idx]); original_shape->push_back(values[val_idx++]); } @@ -738,7 +738,7 @@ void ParameterServer::SyncEmbeddingTables() { } auto lookup = embedding_lookup_ops_[key]; const std::vector &input_shapes = lookup->input_sizes(); - std::vector new_tensor_shape(input_shapes.begin(), input_shapes.end()); + std::vector new_tensor_shape(input_shapes.begin(), input_shapes.end()); tensor::TensorPtr new_tensor = std::make_shared(kNumberTypeFloat32, new_tensor_shape); MS_EXCEPTION_IF_NULL(new_tensor); @@ -751,7 +751,7 @@ void ParameterServer::SyncEmbeddingTables() { } MS_EXCEPTION_IF_NULL(new_tensor_data_ptr); MS_EXCEPTION_IF_NULL(weights_[key]->data()); - int ret = memcpy_s(new_tensor_data_ptr, new_tensor_size, weights_[key]->data(), embedding_table_size); + int64_t ret = memcpy_s(new_tensor_data_ptr, new_tensor_size, weights_[key]->data(), embedding_table_size); if (ret != 0) { MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; return; diff --git a/mindspore/ccsrc/ps/util.cc b/mindspore/ccsrc/ps/util.cc index a069e597845..82719a44156 100644 --- a/mindspore/ccsrc/ps/util.cc +++ b/mindspore/ccsrc/ps/util.cc @@ -23,23 +23,23 @@ namespace mindspore { namespace ps { -int Util::rank_id_ = -1; +int64_t Util::rank_id_ = -1; -std::unordered_map Util::optimizer_to_ids{ +std::unordered_map Util::optimizer_to_ids{ {kApplyMomentum, 0}, {kSparseAdam, 1}, {kSparseLazyAdam, 2}, {kSparseFtrl, 3}, }; -std::unordered_map Util::id_to_optimizers{ +std::unordered_map Util::id_to_optimizers{ {0, kApplyMomentum}, {1, kSparseAdam}, {2, kSparseLazyAdam}, {3, kSparseFtrl}, }; -std::unordered_map Util::id_to_optimizer_nodes{ +std::unordered_map Util::id_to_optimizer_nodes{ {0, kApplyMomentumOp}, {1, kSparseAdamOp}, {2, kSparseLazyAdamOp}, @@ -90,21 +90,21 @@ void Util::SetInternalEnvVar() { } } -int Util::optimizer_id(std::string name) { +int64_t Util::optimizer_id(std::string name) { if (optimizer_to_ids.count(name) > 0) { return optimizer_to_ids[name]; } return -1; } -std::string Util::optimizer_name(int id) { +std::string Util::optimizer_name(int64_t id) { if (id_to_optimizers.count(id) > 0) { return id_to_optimizers[id]; } return ""; } -std::string Util::optimizer_node_name(int id) { +std::string Util::optimizer_node_name(int64_t id) { if (id_to_optimizer_nodes.count(id) > 0) { return id_to_optimizer_nodes[id]; } @@ -113,30 +113,30 @@ std::string Util::optimizer_node_name(int id) { bool Util::is_optimizer(std::string name) { return optimizer_to_ids.count(name) > 0; } -int Util::LocalShard(int first_dim, int rank_id, int server_num) { - std::map shard_dims = AllRankLocalShard(first_dim, rank_id, server_num); +int64_t Util::LocalShard(int64_t first_dim, int64_t rank_id, int64_t server_num) { + std::map shard_dims = AllRankLocalShard(first_dim, rank_id, server_num); if (shard_dims.count(rank_id) == 0) { MS_LOG(EXCEPTION) << "Invalid rank id " << rank_id; } return shard_dims[rank_id]; } -std::map Util::AllRankLocalShard(int first_dim, int rank_id, int server_num) { +std::map Util::AllRankLocalShard(int64_t first_dim, int64_t rank_id, int64_t server_num) { if (first_dim <= 0 || server_num <= 0 || rank_id < 0) { MS_LOG(EXCEPTION) << "Input values are invalid."; } if (rank_id >= server_num) { MS_LOG(EXCEPTION) << "The rank ID " << rank_id << " should be less than the number of servers " << server_num; } - std::map shard_dims; - for (int i = 0; i < server_num; i++) { + std::map shard_dims; + for (int64_t i = 0; i < server_num; i++) { shard_dims[i] = 0; } - if (server_num != static_cast(shard_dims.size())) { + if (server_num != static_cast(shard_dims.size())) { MS_LOG(EXCEPTION) << "Inconsistent server num " << server_num << " shard dims counter size " << shard_dims.size(); } - int server_index = -1; - for (int i = 0; i < first_dim; i++) { + int64_t server_index = -1; + for (int64_t i = 0; i < first_dim; i++) { server_index = (server_index + 1) % server_num; shard_dims[server_index] = shard_dims[server_index] + 1; } diff --git a/mindspore/ccsrc/ps/util.h b/mindspore/ccsrc/ps/util.h index 4fc7ece89bd..eda5bc1bd99 100644 --- a/mindspore/ccsrc/ps/util.h +++ b/mindspore/ccsrc/ps/util.h @@ -33,21 +33,21 @@ class Util { static bool IsRoleOfPServer(); static bool IsRoleOfScheduler(); static void SetInternalEnvVar(); - static int optimizer_id(std::string name); - static std::string optimizer_name(int id); - static std::string optimizer_node_name(int id); + static int64_t optimizer_id(std::string name); + static std::string optimizer_name(int64_t id); + static std::string optimizer_node_name(int64_t id); static bool is_optimizer(std::string name); - static int LocalShard(int first_dim, int rank_id, int server_num); - static std::map AllRankLocalShard(int first_dim, int rank_id, int server_num); + static int64_t LocalShard(int64_t first_dim, int64_t rank_id, int64_t server_num); + static std::map AllRankLocalShard(int64_t first_dim, int64_t rank_id, int64_t server_num); static void ReduceSparseGradient(float *gradients, int *indices, const size_t indices_size, size_t segment_size, const size_t first_dim_size, const size_t outer_dim_size, mindspore::kernel::SparseGradient *unique_sparse_grad); private: - static std::unordered_map optimizer_to_ids; - static std::unordered_map id_to_optimizers; - static std::unordered_map id_to_optimizer_nodes; - static int rank_id_; + static std::unordered_map optimizer_to_ids; + static std::unordered_map id_to_optimizers; + static std::unordered_map id_to_optimizer_nodes; + static int64_t rank_id_; }; } // namespace ps } // namespace mindspore diff --git a/mindspore/ccsrc/ps/worker.h b/mindspore/ccsrc/ps/worker.h index 8c8b3922f6b..f4dacabe689 100644 --- a/mindspore/ccsrc/ps/worker.h +++ b/mindspore/ccsrc/ps/worker.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "ps/ps.h" #include "utils/log_adapter.h" @@ -54,7 +55,7 @@ class Worker { void InitPSEmbeddingTable(const std::vector &keys, std::vector shapes, const ShapeVector &sizes); void InitPSParamAndOptim(const AnfNodePtr &input_node, const tensor::TensorPtr &tensor); void DoPSEmbeddingLookup(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, - const ::ps::SArray &lens, ::ps::SArray *lookup_result, int cmd); + const ::ps::SArray &lens, ::ps::SArray *lookup_result, int64_t cmd); void Finalize(); private: @@ -76,7 +77,7 @@ class Worker { size_t key_cnt_; std::map param_to_key_; std::map init_keys_; - std::map key_to_optimId_; + std::map key_to_optimId_; std::map> key_to_optim_shapes_; std::map param_to_init_in_server_; }; @@ -106,13 +107,13 @@ void Worker::Push(const std::vector &keys, std::vector add MS_LOG(EXCEPTION) << "no optim id found for key" << keys[0]; } Key key = keys[0]; - int optim_id = key_to_optimId_[key]; + int64_t optim_id = key_to_optimId_[key]; bool is_sparse = false; if (optim_id == 1 || optim_id == 2 || optim_id == 3) { is_sparse = true; } - int grad_index = -1; - int indice_index = -1; + int64_t grad_index = -1; + int64_t indice_index = -1; // Sparse adam gradient if (optim_id == 1 || optim_id == 2) { @@ -125,7 +126,7 @@ void Worker::Push(const std::vector &keys, std::vector add indice_index = 1; } - size_t total_size = std::accumulate(sizes.begin(), sizes.end(), 0, std::plus()); + size_t total_size = std::accumulate(sizes.begin(), sizes.end(), 0, std::plus()); ::ps::SArray total_buffer(total_size, 0); size_t offset = 0; size_t dst_size = 0; @@ -148,13 +149,16 @@ void Worker::Push(const std::vector &keys, std::vector add while (!kv_worker_->IsReadyForPush(keys[0])) { continue; } + std::vector sizes_int; + (void)std::transform(sizes.begin(), sizes.end(), std::back_inserter(sizes_int), + [](const int64_t &value) { return static_cast(value); }); if (!is_sparse) { - kv_worker_->PushData(::ps::SArray<::ps::Key>(keys), total_buffer, ::ps::SArray(sizes)); + kv_worker_->PushData(::ps::SArray<::ps::Key>(keys), total_buffer, ::ps::SArray(sizes_int)); } else { - std::vector &var_shape = key_to_optim_shapes_[key][0]; - int first_dim_size = var_shape[0]; - int outer_dim_size = std::accumulate(var_shape.begin() + 1, var_shape.end(), 1, std::multiplies()); - kv_worker_->PushSparseData(::ps::SArray<::ps::Key>(keys), total_buffer, ::ps::SArray(sizes), grad_index, + std::vector &var_shape = key_to_optim_shapes_[key][0]; + int64_t first_dim_size = var_shape[0]; + int64_t outer_dim_size = std::accumulate(var_shape.begin() + 1, var_shape.end(), 1, std::multiplies()); + kv_worker_->PushSparseData(::ps::SArray<::ps::Key>(keys), total_buffer, ::ps::SArray(sizes_int), grad_index, indice_index, first_dim_size, outer_dim_size); } } @@ -178,7 +182,7 @@ void Worker::Pull(const size_t key, void *dev_addr, const size_t size) { template void Worker::DoPSEmbeddingLookup(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, - const ::ps::SArray &lens, ::ps::SArray *lookup_result, int cmd) { + const ::ps::SArray &lens, ::ps::SArray *lookup_result, int64_t cmd) { MS_EXCEPTION_IF_NULL(lookup_result); kv_worker_->EmbeddingLookup(keys, lookup_ids, lens, lookup_result, cmd); } @@ -226,7 +230,7 @@ void Worker::InitPSOptimInputShapes(const size_t key) { shape_len.push_back(1); all_shape.push_back(1); } else { - shape_len.push_back(SizeToInt(shape.size())); + shape_len.push_back(SizeToLong(shape.size())); for (auto dim : shape) { all_shape.push_back(static_cast(dim)); } @@ -297,7 +301,7 @@ void Worker::InitPSOptimId(const size_t param_key) { if (key_to_optimId_.count(param_key) == 0) { MS_LOG(EXCEPTION) << "Can't find optimizer id of parameter key " << param_key; } - int optim_id = key_to_optimId_[param_key]; + int64_t optim_id = key_to_optimId_[param_key]; ::ps::SArray<::ps::Key> keys = {param_key}; ::ps::SArray optim_id_vals = {static_cast(optim_id)}; @@ -317,7 +321,11 @@ void Worker::InitPSEmbeddingTable(const std::vector &keys, std::vecto for (auto dim : shapes) { shapes_val.push_back(static_cast(dim)); } - kv_worker_->Wait(kv_worker_->InitEmbeddingTable(::ps::SArray<::ps::Key>(keys), shapes_val, ::ps::SArray(sizes))); + std::vector sizes_int; + (void)std::transform(sizes.begin(), sizes.end(), std::back_inserter(sizes_int), + [](const int64_t &value) { return static_cast(value); }); + kv_worker_->Wait( + kv_worker_->InitEmbeddingTable(::ps::SArray<::ps::Key>(keys), shapes_val, ::ps::SArray(sizes_int))); } template diff --git a/mindspore/ccsrc/ps/worker_proxy.h b/mindspore/ccsrc/ps/worker_proxy.h index 9422d05d0c3..625dc5f2af5 100644 --- a/mindspore/ccsrc/ps/worker_proxy.h +++ b/mindspore/ccsrc/ps/worker_proxy.h @@ -39,10 +39,10 @@ class WorkerProxy : public ::ps::KVWorker { using Worker = ::ps::KVWorker; using Callback = std::function; using SlicedKVs = std::vector>>; - using Slicer = std::function &send, const std::vector<::ps::Range> &ranges, - SlicedKVs *sliced, const std::map &attrs)>; + using Slicer = std::function &send, const std::vector<::ps::Range> &ranges, + SlicedKVs *sliced, const std::map &attrs)>; using ::ps::SimpleApp::obj_; - explicit WorkerProxy(int app_id, int customer_id, int lookup_customer_id, int general_customer_id) + explicit WorkerProxy(int64_t app_id, int64_t customer_id, int64_t lookup_customer_id, int64_t general_customer_id) : Worker(app_id, customer_id) { server_num_ = ::ps::NumServers(); PSContext::instance()->SetPSRankId(::ps::MyRank()); @@ -66,41 +66,42 @@ class WorkerProxy : public ::ps::KVWorker { void AddEmbeddingTable(const ::ps::Key &key, const size_t &row_count); void AddKeyToServerId(const ::ps::Key &key); void EmbeddingLookup(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, - const ::ps::SArray &lens, ::ps::SArray *outs, int cmd = 0, const Callback &cb = nullptr, - int priority = 0); - int InitEmbeddingTable(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, - const ::ps::SArray &lens = {}, const Callback &cb = nullptr, int priority = 0); + const ::ps::SArray &lens, ::ps::SArray *outs, int64_t cmd = 0, + const Callback &cb = nullptr, int64_t priority = 0); + int64_t InitEmbeddingTable(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, + const ::ps::SArray &lens = {}, const Callback &cb = nullptr, int64_t priority = 0); bool IsReadyForPush(const Key &key); bool IsReadyForPull(const Key &key); void PushData(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, const ::ps::SArray &lens = {}, - int cmd = 0, int priority = 0); + int64_t cmd = 0, int64_t priority = 0); void PushSparseData(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, const ::ps::SArray &lens, size_t grad_index, size_t indice_index, size_t first_dim_size, size_t outer_dim_size); void PullData(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray *vals, ::ps::SArray *lens = nullptr, - int cmd = 0, int priority = 0); + int64_t cmd = 0, int64_t priority = 0); void Finalize(); private: template - int AddLookupCB(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, C *vals, int cmd, - const Callback &cb); - int AddGeneralRspCB(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray *vals, ::ps::SArray *lens, int cmd, + int64_t AddLookupCB(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, C *vals, int64_t cmd, const Callback &cb); - void LookupIdSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, - std::vector>> *sliced, const std::map &attrs); - void SparseSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, - std::vector>> *sliced, const std::map &attrs); - void BroadcastSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, - std::vector>> *sliced, const std::map &attrs); - void RoundRobinSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, - std::vector>> *sliced, const std::map &attrs); - void WorkerInitEmbeddingSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, + int64_t AddGeneralRspCB(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray *vals, ::ps::SArray *lens, + int64_t cmd, const Callback &cb); + void LookupIdSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, + std::vector>> *sliced, const std::map &attrs); + void SparseSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, + std::vector>> *sliced, const std::map &attrs); + void BroadcastSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, + std::vector>> *sliced, const std::map &attrs); + void RoundRobinSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, + std::vector>> *sliced, + const std::map &attrs); + void WorkerInitEmbeddingSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, std::vector>> *sliced, - const std::map &attrs); + const std::map &attrs); void ProcessLookupResult(const ::ps::Message &msg); void ProcessResponse(const ::ps::Message &msg); - void Send(::ps::Customer *customer, int timestamp, bool push, bool pull, int cmd, const ::ps::KVPairs &kvs, - const Slicer &slicer, std::map attrs = {}); + void Send(::ps::Customer *customer, int64_t timestamp, bool push, bool pull, int64_t cmd, const ::ps::KVPairs &kvs, + const Slicer &slicer, std::map attrs = {}); void AddKeyByHashMod(const ::ps::Key &key); void PrepareSparseGradient(const size_t begin, const size_t end, const std::unordered_set &distinct_ids, @@ -109,22 +110,22 @@ class WorkerProxy : public ::ps::KVWorker { void BuildSparseValue(const ::ps::SArray &lengths, const size_t grad_index, const size_t indice_index, const T *original_data, const T *grads, int *indices, ::ps::SArray *reduced_data); - int server_num_; + int64_t server_num_; std::unique_ptr<::ps::Customer> lookup_customer_; std::unique_ptr<::ps::Customer> general_customer_; std::unordered_map<::ps::Key, std::shared_ptr>> embedding_table_ranges_; - std::unordered_map>> lookup_results_; - std::unordered_map>> gathered_response_; + std::unordered_map>> lookup_results_; + std::unordered_map>> gathered_response_; std::mutex mutex_; Slicer lookup_slicer_; Slicer sparse_slicer_; Slicer broadcast_slicer_; Slicer round_robin_slicer_; Slicer worker_init_embedding_slicer_; - std::unordered_map lookup_callbacks_; - std::unordered_map general_callbacks_; - std::unordered_map expected_result_count_; - std::unordered_map<::ps::Key, int> key_to_server_id_; + std::unordered_map lookup_callbacks_; + std::unordered_map general_callbacks_; + std::unordered_map expected_result_count_; + std::unordered_map<::ps::Key, int64_t> key_to_server_id_; std::unordered_map<::ps::Key, size_t> embedding_row_cnt_; }; @@ -132,8 +133,8 @@ template void WorkerProxy::AddEmbeddingTable(const ::ps::Key &key, const size_t &row_count) { uint64_t begin = 0; uint64_t end = 0; - for (int i = 0; i < server_num_; i++) { - int local_row_cnt = Util::LocalShard(row_count, i, server_num_); + for (int64_t i = 0; i < server_num_; i++) { + int64_t local_row_cnt = Util::LocalShard(row_count, i, server_num_); if (i == 0) { end = local_row_cnt - 1; } else { @@ -155,7 +156,7 @@ void WorkerProxy::AddKeyByHashMod(const ::ps::Key &key) { if (server_num_ == 0) { MS_LOG(EXCEPTION) << "Server number is invalid:0"; } - key_to_server_id_[key] = static_cast(key % server_num_); + key_to_server_id_[key] = static_cast(key % server_num_); MS_LOG(INFO) << "The server id of key " << key << " is " << key_to_server_id_[key]; } @@ -166,26 +167,25 @@ void WorkerProxy::AddKeyToServerId(const ::ps::Key &key) { template void WorkerProxy::EmbeddingLookup(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, - const ::ps::SArray &lens, ::ps::SArray *outs, int cmd, const Callback &cb, - int priority) { - MS_EXCEPTION_IF_NULL(outs); - int ts = AddLookupCB(keys, lookup_ids, outs, cmd, cb); + const ::ps::SArray &lens, ::ps::SArray *outs, int64_t cmd, + const Callback &cb, int64_t priority) { + int64_t ts = AddLookupCB(keys, lookup_ids, outs, cmd, cb); ::ps::KVPairs kvs; kvs.keys = keys; kvs.lens = lookup_ids; kvs.priority = priority; expected_result_count_[ts] = 0; Send(lookup_customer_.get(), ts, true, true, cmd, kvs, lookup_slicer_); - int expect_rt_count = expected_result_count_[ts]; + int64_t expect_rt_count = expected_result_count_[ts]; lookup_customer_->AddResponse(ts, server_num_ - expect_rt_count); lookup_customer_->WaitRequest(ts); expected_result_count_.erase(ts); } template -int WorkerProxy::InitEmbeddingTable(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, - const ::ps::SArray &lens, const Callback &cb, int priority) { - int ts = obj_->NewRequest(::ps::kServerGroup); +int64_t WorkerProxy::InitEmbeddingTable(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, + const ::ps::SArray &lens, const Callback &cb, int64_t priority) { + int64_t ts = obj_->NewRequest(::ps::kServerGroup); ::ps::KVPairs kvs; kvs.keys = keys; kvs.vals = vals; @@ -219,8 +219,8 @@ bool WorkerProxy::IsReadyForPull(const Key &key) { template void WorkerProxy::PushData(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, - const ::ps::SArray &lens, int cmd, int priority) { - int ts = AddGeneralRspCB(keys, nullptr, nullptr, cmd, nullptr); + const ::ps::SArray &lens, int64_t cmd, int64_t priority) { + int64_t ts = AddGeneralRspCB(keys, nullptr, nullptr, cmd, nullptr); ::ps::KVPairs kvs; kvs.keys = keys; kvs.vals = vals; @@ -245,14 +245,14 @@ template void WorkerProxy::PushSparseData(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &vals, const ::ps::SArray &lens, size_t grad_index, size_t indice_index, size_t first_dim_size, size_t outer_dim_size) { - int ts = AddGeneralRspCB(keys, nullptr, nullptr, 0, nullptr); + int64_t ts = AddGeneralRspCB(keys, nullptr, nullptr, 0, nullptr); ::ps::KVPairs kvs; kvs.keys = keys; kvs.vals = vals; kvs.lens = lens; - const int cmd = 0; + const int64_t cmd = 0; if (embedding_table_ranges_.count(keys[0])) { - std::map attrs{{0, grad_index}, {1, indice_index}, {2, first_dim_size}, {3, outer_dim_size}}; + std::map attrs{{0, grad_index}, {1, indice_index}, {2, first_dim_size}, {3, outer_dim_size}}; Send(general_customer_.get(), ts, true, false, cmd, kvs, sparse_slicer_, attrs); } else { Send(general_customer_.get(), ts, true, false, cmd, kvs, round_robin_slicer_); @@ -265,9 +265,9 @@ void WorkerProxy::PushSparseData(const ::ps::SArray<::ps::Key> &keys, const : template void WorkerProxy::PullData(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray *vals, ::ps::SArray *lens, - int cmd, int priority) { + int64_t cmd, int64_t priority) { MS_EXCEPTION_IF_NULL(vals); - int ts = AddGeneralRspCB(keys, vals, lens, cmd, nullptr); + int64_t ts = AddGeneralRspCB(keys, vals, lens, cmd, nullptr); ::ps::KVPairs kvs; kvs.keys = keys; kvs.priority = priority; @@ -284,7 +284,7 @@ void WorkerProxy::PullData(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray< template void WorkerProxy::Finalize() { - int ts = obj_->NewRequest(::ps::kServerGroup); + int64_t ts = obj_->NewRequest(::ps::kServerGroup); ::ps::KVPairs kvs; kvs.keys.push_back(0); kvs.vals.push_back(0.0f); @@ -295,38 +295,38 @@ void WorkerProxy::Finalize() { template template -int WorkerProxy::AddLookupCB(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, - C *lookup_result, int cmd, const Callback &cb) { +int64_t WorkerProxy::AddLookupCB(const ::ps::SArray<::ps::Key> &keys, const ::ps::SArray &lookup_ids, + C *lookup_result, int64_t cmd, const Callback &cb) { MS_EXCEPTION_IF_NULL(lookup_result); - int ts = lookup_customer_->NewRequest(::ps::kServerGroup); + int64_t ts = lookup_customer_->NewRequest(::ps::kServerGroup); const auto &callback = [this, ts, keys, lookup_ids, lookup_result, cb]() mutable { mutex_.lock(); auto &kvs = lookup_results_[ts]; mutex_.unlock(); - std::unordered_map>> id_addr_map; + std::unordered_map>> id_addr_map; for (const auto &s : kvs) { - int offset = 0; - int len = s.vals.size() / s.keys.size(); + int64_t offset = 0; + int64_t len = s.vals.size() / s.keys.size(); for (size_t i = 0; i < s.keys.size(); i++) { const Key &key = s.keys[i]; T *addr = s.vals.data() + offset; offset += len; - id_addr_map[key] = std::make_shared>(std::make_pair(addr, len)); + id_addr_map[key] = std::make_shared>(std::make_pair(addr, len)); MS_EXCEPTION_IF_NULL(id_addr_map[key]); } } T *result_addr = lookup_result->data(); MS_EXCEPTION_IF_NULL(result_addr); - int offset = 0; + int64_t offset = 0; size_t dst_size = 0; size_t src_size = 0; void *dst_data = nullptr; void *src_data = nullptr; for (size_t i = 0; i < lookup_ids.size(); i++) { auto &pair = id_addr_map[static_cast(lookup_ids[i])]; - int size = pair->second * sizeof(T); + int64_t size = pair->second * sizeof(T); dst_size = size; src_size = size; dst_data = result_addr + offset; @@ -351,12 +351,12 @@ int WorkerProxy::AddLookupCB(const ::ps::SArray<::ps::Key> &keys, const ::ps: } template -int WorkerProxy::AddGeneralRspCB(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray *vals, ::ps::SArray *lens, - int cmd, const Callback &cb) { - int ts = general_customer_->NewRequest(::ps::kServerGroup); +int64_t WorkerProxy::AddGeneralRspCB(const ::ps::SArray<::ps::Key> &keys, ::ps::SArray *vals, + ::ps::SArray *lens, int64_t cmd, const Callback &cb) { + int64_t ts = general_customer_->NewRequest(::ps::kServerGroup); const auto &callback = [this, ts, keys, vals, lens, cb]() mutable { mutex_.lock(); - std::map> server_kvs = gathered_response_[ts]; + std::map> server_kvs = gathered_response_[ts]; mutex_.unlock(); vals->clear(); @@ -383,11 +383,11 @@ int WorkerProxy::AddGeneralRspCB(const ::ps::SArray<::ps::Key> &keys, ::ps::S } template -void WorkerProxy::LookupIdSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, +void WorkerProxy::LookupIdSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, std::vector>> *sliced, - const std::map &attrs) { + const std::map &attrs) { MS_EXCEPTION_IF_NULL(sliced); - int *lookup_ids = send.lens.data(); + int32_t *lookup_ids = send.lens.data(); size_t id_size = send.lens.size(); const Key &key = send.keys[0]; @@ -398,7 +398,7 @@ void WorkerProxy::LookupIdSlicer(int timestamp, const ::ps::KVPairs &send, const ::ps::Range &range = ranges[i]; const auto &begin = range.begin(); const auto &end = range.end(); - std::unordered_set unique_ids; + std::unordered_set unique_ids; auto &kvs = sliced->at(i).second; kvs.keys.push_back(key); @@ -425,9 +425,9 @@ void WorkerProxy::LookupIdSlicer(int timestamp, const ::ps::KVPairs &send, } template -void WorkerProxy::SparseSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, +void WorkerProxy::SparseSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, std::vector>> *sliced, - const std::map &attrs) { + const std::map &attrs) { MS_EXCEPTION_IF_NULL(sliced); // Init variables T *data = send.vals.data(); @@ -448,8 +448,8 @@ void WorkerProxy::SparseSlicer(int timestamp, const ::ps::KVPairs &send, c int indice_size = send.lens[indice_index]; int segment_size = grad_size / indice_size; - int grad_offset = 0; - int indice_offset = 0; + int64_t grad_offset = 0; + int64_t indice_offset = 0; for (size_t i = 0; i < grad_index; i++) { grad_offset += send.lens[i]; } @@ -545,8 +545,8 @@ void WorkerProxy::PrepareSparseGradient(const size_t begin, const size_t end, MS_EXCEPTION_IF_NULL(all_indice); MS_EXCEPTION_IF_NULL(gradient); MS_EXCEPTION_IF_NULL(indices); - int offset = 0; - int index = 0; + int64_t offset = 0; + int64_t index = 0; size_t segment_data_size = segment_size * sizeof(T); size_t dst_size; size_t src_size; @@ -581,7 +581,7 @@ void WorkerProxy::BuildSparseValue(const ::ps::SArray &lengths, const si MS_EXCEPTION_IF_NULL(grads); MS_EXCEPTION_IF_NULL(indices); MS_EXCEPTION_IF_NULL(reduced_data); - int offset = 0; + int64_t offset = 0; size_t dst_size = 0; size_t src_size = 0; void *dst_data = nullptr; @@ -605,11 +605,11 @@ void WorkerProxy::BuildSparseValue(const ::ps::SArray &lengths, const si } // Fill the reduced gradient - int grad_offset = 0; + int64_t grad_offset = 0; for (size_t i = 0; i < grad_index; i++) { grad_offset += lengths[i]; } - int data_size = lengths[grad_index] * sizeof(T); + int64_t data_size = lengths[grad_index] * sizeof(T); dst_size = data_size; src_size = data_size; dst_data = reduced_data->data() + grad_offset; @@ -623,7 +623,7 @@ void WorkerProxy::BuildSparseValue(const ::ps::SArray &lengths, const si } // Fill the reduced indice - int indice_offset = grad_offset + lengths[grad_index]; + int64_t indice_offset = grad_offset + lengths[grad_index]; data_size = lengths[indice_index] * sizeof(T); T *indice_data = reduced_data->data() + indice_offset; dst_size = data_size; @@ -640,12 +640,12 @@ void WorkerProxy::BuildSparseValue(const ::ps::SArray &lengths, const si } template -void WorkerProxy::BroadcastSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, +void WorkerProxy::BroadcastSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, std::vector>> *sliced, - const std::map &attr) { + const std::map &attr) { MS_EXCEPTION_IF_NULL(sliced); sliced->resize(server_num_); - for (int i = 0; i < server_num_; i++) { + for (int64_t i = 0; i < server_num_; i++) { sliced->at(i).first = true; sliced->at(i).second = send; expected_result_count_[timestamp] += 1; @@ -653,16 +653,16 @@ void WorkerProxy::BroadcastSlicer(int timestamp, const ::ps::KVPairs &send } template -void WorkerProxy::RoundRobinSlicer(int timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, +void WorkerProxy::RoundRobinSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, std::vector>> *sliced, - const std::map &attr) { + const std::map &attr) { MS_EXCEPTION_IF_NULL(sliced); sliced->resize(server_num_); auto keys = send.keys; auto vals = send.vals; auto lens = send.lens; - int server_id, len; + int64_t server_id, len; ::ps::Key param_key; for (size_t i = 0; i < keys.size(); i++) { param_key = keys[i]; @@ -679,7 +679,7 @@ void WorkerProxy::RoundRobinSlicer(int timestamp, const ::ps::KVPairs &sen } len = lens[i]; - int offset = std::accumulate(lens.begin(), lens.begin() + i, 0); + int64_t offset = std::accumulate(lens.begin(), lens.begin() + i, 0); auto val_begin = vals.begin() + offset; auto val_end = val_begin + len; @@ -691,10 +691,10 @@ void WorkerProxy::RoundRobinSlicer(int timestamp, const ::ps::KVPairs &sen } template -void WorkerProxy::WorkerInitEmbeddingSlicer(int timestamp, const ::ps::KVPairs &send, +void WorkerProxy::WorkerInitEmbeddingSlicer(int64_t timestamp, const ::ps::KVPairs &send, const std::vector<::ps::Range> &, std::vector>> *sliced, - const std::map &attrs) { + const std::map &attrs) { MS_EXCEPTION_IF_NULL(sliced); sliced->resize(server_num_); auto keys = send.keys; @@ -717,7 +717,7 @@ void WorkerProxy::WorkerInitEmbeddingSlicer(int timestamp, const ::ps::KVPair template void WorkerProxy::ProcessLookupResult(const ::ps::Message &msg) { - int ts = msg.meta.timestamp; + int64_t ts = msg.meta.timestamp; if (msg.meta.pull) { CHECK_GE(msg.data.size(), (size_t)2); ::ps::KVPairs kvs; @@ -739,7 +739,7 @@ void WorkerProxy::ProcessLookupResult(const ::ps::Message &msg) { template void WorkerProxy::ProcessResponse(const ::ps::Message &msg) { - int ts = msg.meta.timestamp; + int64_t ts = msg.meta.timestamp; if (msg.meta.pull) { CHECK_GE(msg.data.size(), (size_t)2); @@ -762,8 +762,8 @@ void WorkerProxy::ProcessResponse(const ::ps::Message &msg) { } template -void WorkerProxy::Send(::ps::Customer *customer, int timestamp, bool push, bool pull, int cmd, - const ::ps::KVPairs &kvs, const Slicer &slicer, std::map attrs) { +void WorkerProxy::Send(::ps::Customer *customer, int64_t timestamp, bool push, bool pull, int64_t cmd, + const ::ps::KVPairs &kvs, const Slicer &slicer, std::map attrs) { MS_EXCEPTION_IF_NULL(customer); SlicedKVs sliced; slicer(timestamp, kvs, ::ps::Postoffice::Get()->GetServerKeyRanges(), &sliced, attrs); diff --git a/mindspore/ccsrc/pybind_api/ir/anf_py.cc b/mindspore/ccsrc/pybind_api/ir/anf_py.cc index d033dfff5ae..6311b3e717e 100644 --- a/mindspore/ccsrc/pybind_api/ir/anf_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/anf_py.cc @@ -22,7 +22,7 @@ namespace mindspore { // Define python 'RefKey' class. REGISTER_PYBIND_DEFINE(CNode, ([](const pybind11::module *m) { (void)py::class_(*m, "CNode") - .def("expanded_str", (std::string(CNode::*)(int) const) & CNode::DebugString, + .def("expanded_str", (std::string(CNode::*)(int32_t) const) & CNode::DebugString, "Get CNode string representation with specified expansion level."); })); } // namespace mindspore diff --git a/mindspore/ccsrc/pybind_api/ir/tensor_py.cc b/mindspore/ccsrc/pybind_api/ir/tensor_py.cc index 2d22a4424f7..e2f3ea834b4 100644 --- a/mindspore/ccsrc/pybind_api/ir/tensor_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/tensor_py.cc @@ -23,6 +23,7 @@ #include "pybind_api/api_register.h" #include "abstract/abstract_value.h" +#include "utils/shape_utils.h" namespace mindspore { namespace tensor { diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_device_address.cc b/mindspore/ccsrc/runtime/device/ascend/ascend_device_address.cc index a44265755a1..6e32793b81d 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_device_address.cc +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_device_address.cc @@ -287,7 +287,7 @@ bool AscendDeviceAddress::SyncDeviceToHost(const ShapeVector &shape, size_t size SyncStream(); bool sync_ok = false; std::vector host_shape; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), IntToSize); + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), LongToSize); if (host_shape.empty()) { host_shape.emplace_back(1); } @@ -301,7 +301,7 @@ bool AscendDeviceAddress::SyncDeviceToHost(const ShapeVector &shape, size_t size auto shape_size = trans::ShapeSize(host_shape); auto host = std::vector(size_); SyncMemory(host.data(), ptr_, size_, RT_MEMCPY_DEVICE_TO_HOST); - const trans::TypeIdArgs type_args{host.data(), shape_size, type_id_, type, size}; + const trans::TypeIdArgs type_args{host.data(), shape_size, type_id_, type, size_}; sync_ok = trans::TransDataType(type_args, host_ptr); if (!sync_ok) { MS_LOG(ERROR) << "trans data type failed."; @@ -460,7 +460,7 @@ std::vector AscendDeviceAddress::GetDeviceShape(std::vector *hos *host_shape = trans::PaddingShapeTo4d(*host_shape); } else { host_shape->clear(); - (void)std::transform(host_shape_.begin(), host_shape_.end(), std::back_inserter(*host_shape), IntToSize); + (void)std::transform(host_shape_.begin(), host_shape_.end(), std::back_inserter(*host_shape), LongToSize); } device_shape = trans::TransShapeToDevice(*host_shape, format_); } @@ -473,7 +473,7 @@ bool AscendDeviceAddress::SyncDeviceToHostAndConvertFormat(const ShapeVector &sh << ", size:" << size_ << "), Host(type_id:" << TypeIdLabel(type) << ", size:" << size << ")"; bool sync_ok = false; std::vector host_shape; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), IntToSize); + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), LongToSize); if (host_shape.empty()) { host_shape.emplace_back(1); } @@ -526,7 +526,7 @@ bool AscendDeviceAddress::SyncHostToDevice(const ShapeVector &shape, size_t size SyncStream(); bool sync_ok = false; std::vector host_shape; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), IntToSize); + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), LongToSize); if (host_shape.empty()) { host_shape.emplace_back(1); } @@ -569,7 +569,7 @@ bool AscendDeviceAddress::ConvertFormatAndSyncHostToDevice(const ShapeVector &sh MS_LOG(INFO) << "ConvertFormatAndSyncHostToDevice, Device(format:" << format_ << ", type_id:" << TypeIdLabel(type_id_) << ", size:" << size_ << "), Host(type_id:" << TypeIdLabel(type) << ", size:" << size << ")"; std::vector host_shape; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), IntToSize); + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(host_shape), LongToSize); if (host_shape.empty()) { host_shape.emplace_back(1); } diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc b/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc index d04d6fce58a..9019abd4513 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc +++ b/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "backend/session/anf_runtime_algorithm.h" #include "runtime/device/ascend/ge_types_convert.h" #include "utils/utils.h" @@ -103,7 +104,10 @@ void FeedTeOpConstTensor(const NotNull &cnode, const std::map>(cnode.get(), kDynamicShapeDepends); + std::vector depends_list; + std::vector depends_list_me = AnfAlgo::GetNodeAttr>(cnode.get(), kDynamicShapeDepends); + (void)std::transform(depends_list_me.begin(), depends_list_me.end(), std::back_inserter(depends_list), + [](const int64_t &value) { return static_cast(value); }); for (auto index : depends_list) { auto iter = depend_tensor_map.find(IntToSize(index)); if (iter == depend_tensor_map.end()) { diff --git a/mindspore/ccsrc/runtime/device/ascend/kernel_select_graph_kernel.cc b/mindspore/ccsrc/runtime/device/ascend/kernel_select_graph_kernel.cc index c76f96728f4..c9b3cab1c66 100644 --- a/mindspore/ccsrc/runtime/device/ascend/kernel_select_graph_kernel.cc +++ b/mindspore/ccsrc/runtime/device/ascend/kernel_select_graph_kernel.cc @@ -114,8 +114,8 @@ bool CanConvertDefaultShapeToNZ(const std::vector &shape) { return true; } -std::vector DefaultToFracNZAxis(const std::vector &ori_shape, const std::vector &axis) { - std::vector frac_nz_axis = axis; +std::vector DefaultToFracNZAxis(const std::vector &ori_shape, const std::vector &axis) { + std::vector frac_nz_axis = axis; auto shape_len = ori_shape.size(); for (size_t i = 0; i < axis.size(); ++i) { auto axis_idx = (frac_nz_axis[i] + shape_len) % shape_len; @@ -132,7 +132,7 @@ std::vector DefaultToFracNZAxis(const std::vector &ori_shape, const return frac_nz_axis; } -std::vector GetReducedFracNZShape(const std::vector &ori_shape, const std::vector &axis, +std::vector GetReducedFracNZShape(const std::vector &ori_shape, const std::vector &axis, bool keep_dims) { std::vector result; std::set positive_idx; @@ -160,27 +160,31 @@ void UpdateFracNZReduceOp(const CNodePtr &cnode) { cnode->set_input(0, new_prim_node); auto axis_value = new_prim->GetAttr(kAttrAxis); - std::vector default_axis; + std::vector default_axis; if (axis_value->isa()) { auto value_list = dyn_cast(axis_value); for (const auto &item : value_list->value()) { - if (item->isa()) { - default_axis.push_back(GetValue(item)); + if (item->isa()) { + default_axis.push_back(GetValue(item)); + } else { + MS_LOG(EXCEPTION) << "GetValue type should be int64"; } } } else if (axis_value->isa()) { auto value_tuple = dyn_cast(axis_value); for (const auto &item : value_tuple->value()) { - if (item->isa()) { - default_axis.push_back(GetValue(item)); + if (item->isa()) { + default_axis.push_back(GetValue(item)); + } else { + MS_LOG(EXCEPTION) << "GetValue type should be int64"; } } } else { MS_LOG(ERROR) << "Axis attr type is not correct!"; } auto infer_shape = AnfAlgo::GetPrevNodeOutputInferShape(cnode, 0); - std::vector frac_nz_axis = DefaultToFracNZAxis(infer_shape, default_axis); - AnfAlgo::SetNodeAttr(kAttrAxis, MakeValue>(frac_nz_axis), cnode); + std::vector frac_nz_axis = DefaultToFracNZAxis(infer_shape, default_axis); + AnfAlgo::SetNodeAttr(kAttrAxis, MakeValue>(frac_nz_axis), cnode); auto output_shape = AnfAlgo::GetOutputInferShape(cnode, 0); if (output_shape.size() == 1) { AnfAlgo::SetNodeAttr(kAttrOutputDefault, MakeValue(true), cnode); diff --git a/mindspore/ccsrc/runtime/device/executor/dynamic_kernel.cc b/mindspore/ccsrc/runtime/device/executor/dynamic_kernel.cc index a12805abbab..9f002a1c6c1 100644 --- a/mindspore/ccsrc/runtime/device/executor/dynamic_kernel.cc +++ b/mindspore/ccsrc/runtime/device/executor/dynamic_kernel.cc @@ -16,6 +16,7 @@ #include "runtime/device/executor/dynamic_kernel.h" #include +#include #include "backend/session/anf_runtime_algorithm.h" #include "common/trans.h" #include "pipeline/jit/static_analysis/static_analysis.h" @@ -41,12 +42,15 @@ void DynamicKernel::Initialize() { return; } MS_LOG(INFO) << "Have depends"; - auto depends_list = AnfAlgo::GetNodeAttr>(cnode_ptr_, kDynamicShapeDepends); + std::vector depends_list; + std::vector depends_list_me = AnfAlgo::GetNodeAttr>(cnode_ptr_, kDynamicShapeDepends); + (void)std::transform(depends_list_me.begin(), depends_list_me.end(), std::back_inserter(depends_list), + [](const int64_t &value) { return static_cast(value); }); // Save depend input tensor. Sync data in InferShape. for (auto depend : depends_list) { auto pre_node_with_index = AnfAlgo::GetPrevNodeOutput(cnode_ptr_, depend); auto output_addr = AnfAlgo::GetPrevNodeMutableOutputAddr(cnode_ptr_, depend); - std::vector shapes = trans::GetRuntimePaddingShape(pre_node_with_index.first, pre_node_with_index.second); + std::vector shapes = trans::GetRuntimePaddingShape(pre_node_with_index.first, pre_node_with_index.second); auto host_type = AnfAlgo::GetOutputInferDataType(pre_node_with_index.first, pre_node_with_index.second); auto out_tensor = std::make_shared(host_type, shapes); out_tensor->set_device_address(output_addr); diff --git a/mindspore/ccsrc/runtime/device/kernel_adjust.cc b/mindspore/ccsrc/runtime/device/kernel_adjust.cc index 64bc1842523..088c42be374 100644 --- a/mindspore/ccsrc/runtime/device/kernel_adjust.cc +++ b/mindspore/ccsrc/runtime/device/kernel_adjust.cc @@ -437,9 +437,9 @@ CNodePtr KernelAdjust::CreateStreamActiveOp(const std::shared_ptr &kernel_graph_ptr, const CNodePtr &node, size_t output_idx) { - auto idx = NewValueNode(SizeToInt(output_idx)); + auto idx = NewValueNode(SizeToLong(output_idx)); MS_EXCEPTION_IF_NULL(idx); - auto imm = std::make_shared(SizeToInt(output_idx)); + auto imm = std::make_shared(SizeToInt(output_idx)); auto abstract_scalar = std::make_shared(imm); idx->set_abstract(abstract_scalar); CNodePtr tuple_getitem = kernel_graph_ptr->NewCNode({NewValueNode(prim::kPrimTupleGetItem), node, idx}); diff --git a/mindspore/ccsrc/runtime/device/kernel_runtime.cc b/mindspore/ccsrc/runtime/device/kernel_runtime.cc index 61f9682e386..6b4d29d098b 100644 --- a/mindspore/ccsrc/runtime/device/kernel_runtime.cc +++ b/mindspore/ccsrc/runtime/device/kernel_runtime.cc @@ -650,7 +650,7 @@ void KernelRuntime::AssignStaticMemoryValueNode(session::KernelGraph *graph) { MS_LOG(EXCEPTION) << "Cannot alloc address when flag is: " << kStaticMem << ", tensor size is: " << tensor_size; } AnfAlgo::SetOutputAddr(address, 0, value_node.get()); - ShapeVector shape = {1, SizeToInt(tensor_size)}; + ShapeVector shape = {1, SizeToLong(tensor_size)}; if (!address->SyncHostToDevice(shape, tensor_size, kNumberTypeUInt8, value.data())) { MS_LOG(EXCEPTION) << "kValueNode SyncHostToDevice fail!"; } diff --git a/mindspore/ccsrc/transform/graph_ir/convert.cc b/mindspore/ccsrc/transform/graph_ir/convert.cc index 06135c4877b..17cf578c2c8 100644 --- a/mindspore/ccsrc/transform/graph_ir/convert.cc +++ b/mindspore/ccsrc/transform/graph_ir/convert.cc @@ -899,7 +899,7 @@ void DfGraphConvertor::UpdateDataOpDesc(const AnfNodePtr &it, const OperatorPtr return; } auto normal_shape_ptr = dyn_cast(node->Shape()); - vector shape; + std::vector shape; if (normal_shape_ptr == nullptr) { MS_LOG(INFO) << "Invalid shape to update data op descriptor."; return; @@ -1150,7 +1150,7 @@ void DfGraphConvertor::ConvertMakeTuple(const CNodePtr node) { tuple_out_handle_cache_[node.get()] = tuple_items; } -AnfNodePtr DfGraphConvertor::TraceTupleGetItem(const CNodePtr &node, unsigned int *index) { +AnfNodePtr DfGraphConvertor::TraceTupleGetItem(const CNodePtr &node, uint64_t *index) { const int TUPLE_GET_ITEM_INDEX = 2; if (node->inputs().size() < 3) { // "tuple_getitem" primitive must have 3 inputs MS_LOG(EXCEPTION) << "length of inputs of TupleGetItem is less than 3"; @@ -1160,7 +1160,7 @@ AnfNodePtr DfGraphConvertor::TraceTupleGetItem(const CNodePtr &node, unsigned in error_ = INVALID_ARGUMENT; MS_LOG(EXCEPTION) << "can't convert get item with non-constant index"; } - *index = IntToUint(GetValue(GetValueNode(index_node))); + *index = LongToUlong(GetValue(GetValueNode(index_node))); return node->inputs()[1]; } @@ -1172,14 +1172,14 @@ AnfNodePtr DfGraphConvertor::TraceDepend(const CNodePtr &node) { return cnode->inputs()[1]; } -AnfNodePtr DfGraphConvertor::TraceMakeTuple(const CNodePtr &node, unsigned int index) { +AnfNodePtr DfGraphConvertor::TraceMakeTuple(const CNodePtr &node, uint64_t index) { if (index + 1 >= node->inputs().size()) { MS_LOG(EXCEPTION) << "length of make_tuple is less than index: " << index; } return node->inputs()[index + 1]; } -OutHandler DfGraphConvertor::GetHandler(const AnfNodePtr &node, const std::stack &index_stack, +OutHandler DfGraphConvertor::GetHandler(const AnfNodePtr &node, const std::stack &index_stack, AnfNode *const draw_index) { if (node == nullptr) { MS_LOG(ERROR) << "Get nullptr while trace real op"; @@ -1212,12 +1212,12 @@ OutHandler DfGraphConvertor::GetHandler(const AnfNodePtr &node, const std::stack OutHandler DfGraphConvertor::TraceRealOp(AnfNodePtr node) { bool flag = IsPrimitiveCNode(node, prim::kPrimTupleGetItem) || IsPrimitiveCNode(node, prim::kPrimMakeTuple) || IsPrimitiveCNode(node, prim::kPrimDepend); - std::stack index_stack; + std::stack index_stack; auto draw_index = node.get(); while (flag) { flag = false; if (IsPrimitiveCNode(node, prim::kPrimTupleGetItem)) { - unsigned int index; + uint64_t index; node = TraceTupleGetItem(node->cast(), &index); index_stack.push(index); flag = true; @@ -1268,7 +1268,7 @@ AnfNodePtr DfGraphConvertor::GetRealOpNode(AnfNodePtr node) { error_ = FAILED; return node; } - int index = value_ptr->value(); + int64_t index = value_ptr->value(); // make_tuple apply inputs:make_tuple, [tuple_items,] if (IsPrimitiveCNode(node_inputs[1], prim::kPrimMakeTuple)) { diff --git a/mindspore/ccsrc/transform/graph_ir/convert.h b/mindspore/ccsrc/transform/graph_ir/convert.h index 24dceb3a50b..ec46edd15ac 100644 --- a/mindspore/ccsrc/transform/graph_ir/convert.h +++ b/mindspore/ccsrc/transform/graph_ir/convert.h @@ -135,11 +135,11 @@ class DfGraphConvertor { std::ostringstream restore_checkpoint_sout_; std::unordered_map op_draw_name_; - AnfNodePtr TraceTupleGetItem(const CNodePtr &node, unsigned int *index); - AnfNodePtr TraceMakeTuple(const CNodePtr &node, unsigned int index); + AnfNodePtr TraceTupleGetItem(const CNodePtr &node, uint64_t *index); + AnfNodePtr TraceMakeTuple(const CNodePtr &node, uint64_t index); AnfNodePtr TraceDepend(const CNodePtr &node); OutHandler TraceRealOp(AnfNodePtr node); - OutHandler GetHandler(const AnfNodePtr &node, const std::stack &index_stack, AnfNode *const draw_index); + OutHandler GetHandler(const AnfNodePtr &node, const std::stack &index_stack, AnfNode *const draw_index); OperatorPtr Convert(AnfNodePtr node); OperatorPtr ConvertCNode(CNodePtr node); std::vector ConvertDependNode(AnfNodePtr node); diff --git a/mindspore/ccsrc/transform/graph_ir/op_adapter.cc b/mindspore/ccsrc/transform/graph_ir/op_adapter.cc index 0bb0995be63..fc643881114 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_adapter.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_adapter.cc @@ -392,7 +392,7 @@ std::shared_ptr OpAdapterImpl::CreateNodeDesc(const AnfNodePtr &no return nullptr; } - std::vector shape; + std::vector shape; auto shape_ptr = dyn_cast(node->Shape()); if (nullptr != shape_ptr) { shape = shape_ptr->shape(); @@ -524,7 +524,7 @@ int OpAdapterImpl::SetCustomOpAttr(const CusOperatorPtr &op, const PrimitivePtr ValueType value_type = SINGLE_VALUE; for (auto item : prim->attrs()) { if (item.second->isa()) { - (void)op->SetAttr(item.first, GetValue(item.second)); + (void)op->SetAttr(item.first, GetValue(item.second)); } else if (item.second->isa()) { (void)op->SetAttr(item.first, GetValue(item.second)); } else if (item.second->isa()) { @@ -538,8 +538,8 @@ int OpAdapterImpl::SetCustomOpAttr(const CusOperatorPtr &op, const PrimitivePtr (void)op->SetAttr(item.first, GetValue>(item.second)); } else if ((*val_seq)[0]->isa()) { (void)op->SetAttr(item.first, GetValue>(item.second)); - } else if ((*val_seq)[0]->isa()) { - (void)op->SetAttr(item.first, GetValue>(item.second)); + } else if ((*val_seq)[0]->isa()) { + (void)op->SetAttr(item.first, GetValue>(item.second)); } else if ((*val_seq)[0]->isa()) { (void)op->SetAttr(item.first, GetValue>(item.second)); } else { diff --git a/mindspore/ccsrc/transform/graph_ir/op_adapter.h b/mindspore/ccsrc/transform/graph_ir/op_adapter.h index 37595523b3c..3fd3371d1fa 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_adapter.h +++ b/mindspore/ccsrc/transform/graph_ir/op_adapter.h @@ -302,7 +302,7 @@ class OpAdapter : public BaseOpAdapter { // specialization for int static int64_t ConvertAny(const ValuePtr &value, const AnyTraits) { - return static_cast(GetValue(value)); + return static_cast(GetValue(value)); } // specialization for int or tuple broadcast to Vector @@ -329,7 +329,7 @@ class OpAdapter : public BaseOpAdapter { auto sub_vector = it->cast(); std::vector sublist; for (auto &item : sub_vector->value()) { - sublist.push_back(static_cast(GetValue(item))); + sublist.push_back(static_cast(GetValue(item))); } list.push_back(sublist); } @@ -352,7 +352,7 @@ class OpAdapter : public BaseOpAdapter { } auto sub_vector = it->cast(); for (auto &item : sub_vector->value()) { - list.push_back(static_cast(GetValue(item))); + list.push_back(static_cast(GetValue(item))); } } return list; @@ -367,12 +367,12 @@ class OpAdapter : public BaseOpAdapter { auto vec = value->cast(); MS_EXCEPTION_IF_NULL(vec); for (auto &it : vec->value()) { - list.push_back(static_cast(GetValue(it))); + list.push_back(static_cast(GetValue(it))); } return list; } if (value->isa()) { - list.push_back(static_cast(GetValue(value))); + list.push_back(static_cast(GetValue(value))); return list; } MS_LOG(EXCEPTION) << "Value should be ValueTuple or Scalar, but got " << value->type_name(); diff --git a/mindspore/ccsrc/transform/graph_ir/op_adapter_util.cc b/mindspore/ccsrc/transform/graph_ir/op_adapter_util.cc index bc6e2bfbd07..03ff8804998 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_adapter_util.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_adapter_util.cc @@ -46,9 +46,9 @@ std::vector ConvertAnyUtil(const ValuePtr &value, const std::string &na list[0] = 1; list[1] = 1; (void)std::transform(vec->value().begin(), vec->value().end(), list.begin() + 2, - [](const ValuePtr &val) { return static_cast(GetValue(val)); }); + [](const ValuePtr &val) { return static_cast(GetValue(val)); }); } else { - int64_t data = GetValue(value); + int64_t data = GetValue(value); int size = 2; // 2 int in list list = TransformUtil::ConvertIntToList(data, size); } @@ -68,7 +68,7 @@ std::string ConvertAnyUtil(const ValuePtr &value, const AnyTraits(it); + buffer << GetValue(it); i++; } return buffer.str(); @@ -97,7 +97,7 @@ std::vector ConvertAnyUtil(const ValuePtr &value, const std::string &fo std::vector list; list.resize(vec->value().size()); (void)std::transform(vec->value().begin(), vec->value().end(), list.begin(), - [](const ValuePtr &val) { return static_cast(GetValue(val)); }); + [](const ValuePtr &val) { return static_cast(GetValue(val)); }); if (format == kOpFormat_NHWC) { if (list.size() < 4) { MS_LOG(EXCEPTION) << "The size of list is less than 4"; @@ -143,6 +143,14 @@ GeTensor VectorToTensorUtil(const ValuePtr &value) { MS_LOG(EXCEPTION) << "Update conversion descriptor failed!"; } return GeTensor(*desc, reinterpret_cast(data.data()), data.size() * sizeof(int32_t)); + } else if (vec[0]->isa()) { + MS_LOG(INFO) << "convert value to tensor with data type = Int64"; + auto data = ConvertAnyUtil(value, AnyTraits(), AnyTraits>()); + auto desc = TransformUtil::GetGeTensorDesc({static_cast(vec.size())}, kNumberTypeInt64, kOpFormat_NCHW); + if (desc == nullptr) { + MS_LOG(EXCEPTION) << "Update conversion descriptor failed!"; + } + return GeTensor(*desc, reinterpret_cast(data.data()), data.size() * sizeof(int64_t)); } else if (vec[0]->isa()) { MS_LOG(INFO) << "convert value to tensor with data type = Float32"; auto data = ConvertAnyUtil(value, AnyTraits(), AnyTraits>()); diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc index d5c581c406e..6dcbe0a38f6 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc @@ -30,8 +30,9 @@ INPUT_MAP(Add) = {{1, INPUT_DESC(x1)}, {2, INPUT_DESC(x2)}}; ATTR_MAP(Add) = EMPTY_ATTR_MAP; OUTPUT_MAP(Add) = {{0, OUTPUT_DESC(y)}}; REG_ADPT_DESC(Add, prim::kPrimTensorAdd->name(), - std::make_shared(std::make_shared>(ExtraAttr({{"mode", MakeValue(1)}})), - std::make_shared>(ExtraAttr({{"mode", MakeValue(1)}})))) + std::make_shared( + std::make_shared>(ExtraAttr({{"mode", MakeValue(static_cast(1))}})), + std::make_shared>(ExtraAttr({{"mode", MakeValue(static_cast(1))}})))) // GreaterEqual INPUT_MAP(GreaterEqual) = {{1, INPUT_DESC(x1)}, {2, INPUT_DESC(x2)}}; diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/nn_calculation_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/nn_calculation_ops_declare.cc index 28410f6f6bc..42b2e99d0cb 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/nn_calculation_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/nn_calculation_ops_declare.cc @@ -31,7 +31,7 @@ ATTR_MAP(Conv2D) = { {"pad_list", ATTR_DESC(pads, AnyTraits>(), AnyTraits>())}, {"dilation", ATTR_DESC(dilations, AnyTraits>(), AnyTraits>())}, {"data_format", ATTR_DESC(data_format, AnyTraits())}, - {"group", ATTR_DESC(groups, AnyTraits())}, + {"group", ATTR_DESC(groups, AnyTraits())}, }; OUTPUT_MAP(Conv2D) = {{0, OUTPUT_DESC(y)}}; REG_ADPT_DESC(Conv2D, prim::kPrimConv2D->name(), ADPT_DESC(Conv2D)) @@ -45,7 +45,7 @@ ATTR_MAP(Conv2DBackpropInputD) = { {"stride", ATTR_DESC(strides, "pad", AnyTraits>())}, {"dilation", ATTR_DESC(dilations, AnyTraits>(), AnyTraits>())}, {"data_format", ATTR_DESC(data_format, AnyTraits())}, - {"group", ATTR_DESC(groups, AnyTraits())}, + {"group", ATTR_DESC(groups, AnyTraits())}, }; OUTPUT_MAP(Conv2DBackpropInputD) = {{0, OUTPUT_DESC(y)}}; REG_ADPT_DESC(Conv2DBackpropInputD, prim::kPrimConv2DBackpropInput->name(), ADPT_DESC(Conv2DBackpropInputD)) @@ -59,7 +59,7 @@ ATTR_MAP(Conv2DBackpropFilterD) = { {"stride", ATTR_DESC(strides, "pad", AnyTraits>())}, {"dilation", ATTR_DESC(dilations, AnyTraits>(), AnyTraits>())}, {"data_format", ATTR_DESC(data_format, AnyTraits())}, - {"group", ATTR_DESC(groups, AnyTraits())}, + {"group", ATTR_DESC(groups, AnyTraits())}, }; OUTPUT_MAP(Conv2DBackpropFilterD) = {{0, OUTPUT_DESC(y)}}; REG_ADPT_DESC(Conv2DBackpropFilterD, prim::kPrimConv2DBackpropFilter->name(), ADPT_DESC(Conv2DBackpropFilterD)) diff --git a/mindspore/ccsrc/transform/graph_ir/util.cc b/mindspore/ccsrc/transform/graph_ir/util.cc index 9ae96de3965..f9986a4e813 100644 --- a/mindspore/ccsrc/transform/graph_ir/util.cc +++ b/mindspore/ccsrc/transform/graph_ir/util.cc @@ -323,7 +323,7 @@ ShapeVector TransformUtil::ConvertGeShape(const GeShape &ge_shape) { } ShapeVector TransformUtil::ConvertGeShape(const GeShape &ge_shape, const ShapeVector &request_dims) { - vector ret; + vector ret; if (ge_shape.GetDimNum() == 0) { MS_LOG(DEBUG) << "GeTensor's shape is scalar"; return ret; @@ -370,7 +370,7 @@ MeTensorPtr TransformUtil::GenerateMeTensor(const GeTensorPtr &ge_tensor, const MeTensorPtr TransformUtil::ConvertGeTensor(const GeTensorPtr &ge_tensor) { MS_EXCEPTION_IF_NULL(ge_tensor); GeShape ge_shape = ge_tensor->GetTensorDesc().GetShape(); - vector me_dims = ConvertGeShape(ge_shape); + vector me_dims = ConvertGeShape(ge_shape); TypeId type_id = ConvertGeDataType(ge_tensor->GetTensorDesc().GetDataType()); if (type_id == MeDataType::kTypeUnknown) { @@ -385,7 +385,7 @@ MeTensorPtr TransformUtil::ConvertGeTensor(const GeTensorPtr &ge_tensor) { MeTensorPtr TransformUtil::ConvertGeTensor(const GeTensorPtr ge_tensor, const ShapeVector &request_dims) { MS_EXCEPTION_IF_NULL(ge_tensor); GeShape ge_shape = ge_tensor->GetTensorDesc().GetShape(); - vector me_dims = ConvertGeShape(ge_shape, request_dims); + vector me_dims = ConvertGeShape(ge_shape, request_dims); MS_LOG(INFO) << "GE tensor type is " << static_cast(ge_tensor->GetTensorDesc().GetDataType()); // Create a tensor with wanted data type and shape TypeId type_id = ConvertGeDataType(ge_tensor->GetTensorDesc().GetDataType()); diff --git a/mindspore/ccsrc/transform/onnx/onnx_exporter.cc b/mindspore/ccsrc/transform/onnx/onnx_exporter.cc index 1d1d75573a7..ba6bf13bc09 100644 --- a/mindspore/ccsrc/transform/onnx/onnx_exporter.cc +++ b/mindspore/ccsrc/transform/onnx/onnx_exporter.cc @@ -85,7 +85,7 @@ void SetAttrTupleValueToProto(const ValuePtr &value, onnx::AttributeProto_Attrib switch (attr_type) { case onnx::AttributeProto_AttributeType_INTS: for (size_t i = beg_idx; i < tuple_ptr->size(); ++i) { - attr_proto->add_ints(GetValue((*tuple_ptr)[i])); + attr_proto->add_ints(GetValue((*tuple_ptr)[i])); } break; case onnx::AttributeProto_AttributeType_FLOATS: @@ -180,7 +180,7 @@ OPERATOR_ONNX_CONVERT_DEFINE( Conv2D, Conv, OpNameInfo() .Attr("dilation", "dilations", onnx::AttributeProto_AttributeType_INTS, SetAttrTupleValueToProto<2>) - .Attr("group", "group", onnx::AttributeProto_AttributeType_INT, SetAttrValueToProto) + .Attr("group", "group", onnx::AttributeProto_AttributeType_INT, SetAttrValueToProto) .Attr("kernel_size", "kernel_shape", onnx::AttributeProto_AttributeType_INTS, SetAttrTupleValueToProto<0>) .Attr("pad_mode", "auto_pad", onnx::AttributeProto_AttributeType_STRING, [](ValuePtr value, onnx::AttributeProto_AttributeType, onnx::AttributeProto *const attr_proto, @@ -217,7 +217,7 @@ OPERATOR_ONNX_CONVERT_DEFINE(PReLU, PRelu, OpNameInfo()) OPERATOR_ONNX_CONVERT_DEFINE(Argmax, ArgMax, OpNameInfo() .Attr("axis", "axis", onnx::AttributeProto_AttributeType_INT, - SetAttrValueToProto) + SetAttrValueToProto) .Attr("", "keepdims", onnx::AttributeProto_AttributeType_INT, [](ValuePtr, onnx::AttributeProto_AttributeType, onnx::AttributeProto *const attr_proto, const PrimitivePtr &) { @@ -374,10 +374,10 @@ class OnnxExporter { void ResetNodeIndex() { onnx_node_index_ = 0; } - static int GetInt32Value(const AnfNodePtr &node) { + static int64_t GetInt64Value(const AnfNodePtr &node) { auto value_node_ptr = dyn_cast(node); MS_EXCEPTION_IF_NULL(value_node_ptr); - return GetValue(value_node_ptr->value()); + return GetValue(value_node_ptr->value()); } onnx::ModelProto model_; @@ -546,13 +546,13 @@ void OnnxExporter::MatchAndMark(const FuncGraphPtr &func_graph, const std::vecto op_merged_infos[cnode->input(1)].referred_count -= 1; } else if (cnode->IsApply(prim::kPrimTupleGetItem) && IsPrimitiveCNode(cnode->input(1), std::make_shared("BatchNorm")) && - GetInt32Value(cnode->input(2)) == 0) { + GetInt64Value(cnode->input(2)) == 0) { op_merged_infos[cnode].mode = OP_MERGE_BATCH_NORM; op_merged_infos[cnode->input(1)].mode = OP_MERGE_IGNORE; op_merged_infos[cnode->input(1)].referred_count -= 1; } else if (cnode->IsApply(prim::kPrimTupleGetItem) && IsPrimitiveCNode(cnode->input(1), std::make_shared("MaxPoolWithArgmax")) && - GetInt32Value(cnode->input(2)) == 0) { + GetInt64Value(cnode->input(2)) == 0) { op_merged_infos[cnode].mode = OP_MERGE_MAXPOOL_WITH_ARGMAX; op_merged_infos[cnode->input(1)].mode = OP_MERGE_IGNORE; op_merged_infos[cnode->input(1)].referred_count -= 1; @@ -671,7 +671,7 @@ void OnnxExporter::ExportPrimReduce(const FuncGraphPtr & /*func_graph*/, const C auto tuple_ptr = dyn_cast(axis_value); MS_EXCEPTION_IF_NULL(tuple_ptr); for (size_t i = 0; i < tuple_ptr->size(); ++i) { - attr_proto->add_ints(GetValue((*tuple_ptr)[i])); + attr_proto->add_ints(GetValue((*tuple_ptr)[i])); } } else { attr_proto->add_ints(int_ptr->value()); @@ -925,7 +925,7 @@ void OnnxExporter::ExportPrimGatherV2(const FuncGraphPtr &func_graph, const CNod node_proto->add_input(name_indices); onnx::AttributeProto *attr_proto = node_proto->add_attribute(); attr_proto->set_type(onnx::AttributeProto_AttributeType_INT); - attr_proto->set_i(static_cast<::google::protobuf::int64>(dyn_cast(axis)->value())); + attr_proto->set_i(static_cast<::google::protobuf::int64>(dyn_cast(axis)->value())); } void OnnxExporter::ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node, diff --git a/mindspore/ccsrc/utils/convert_utils.cc b/mindspore/ccsrc/utils/convert_utils.cc index c6ff17ad184..8b37f53148a 100644 --- a/mindspore/ccsrc/utils/convert_utils.cc +++ b/mindspore/ccsrc/utils/convert_utils.cc @@ -59,14 +59,22 @@ bool ValueToBool(const ValuePtr &v, bool *value) { return true; } -bool BaseRefToInt(const ValuePtr &v, int *value) { +bool BaseRefToInt(const ValuePtr &v, int64_t *value) { MS_EXCEPTION_IF_NULL(v); if (v->isa()) { auto tensor = v->cast(); (void)tensor->data_sync(); - int *tensor_data = static_cast(tensor->data_c()); - auto vb = tensor_data[0]; - *value = vb; + if (tensor->Dtype()->ToString() == "Int32") { + int32_t *tensor_data = static_cast(tensor->data_c()); + auto vb = tensor_data[0]; + *value = static_cast(vb); + } else if (tensor->Dtype()->ToString() == "Int64") { + int64_t *tensor_data = static_cast(tensor->data_c()); + auto vb = tensor_data[0]; + *value = vb; + } else { + MS_LOG(ERROR) << "Index must be Int type."; + } return true; } MS_LOG(ERROR) << "Index must be tensor type."; diff --git a/mindspore/ccsrc/utils/convert_utils.h b/mindspore/ccsrc/utils/convert_utils.h index 1628d78a4cf..8c14d757878 100644 --- a/mindspore/ccsrc/utils/convert_utils.h +++ b/mindspore/ccsrc/utils/convert_utils.h @@ -39,7 +39,7 @@ using TensorPtr = std::shared_ptr; } // namespace tensor bool BaseRefToBool(const BaseRef &in, bool *out); -bool BaseRefToInt(const ValuePtr &v, int *value); +bool BaseRefToInt(const ValuePtr &v, int64_t *value); bool ValueToBool(const ValuePtr &in, bool *out); // Isomorphism diff --git a/mindspore/ccsrc/utils/load_onnx/anf_model_parser.cc b/mindspore/ccsrc/utils/load_onnx/anf_model_parser.cc index 1828cc21739..22892a7580c 100644 --- a/mindspore/ccsrc/utils/load_onnx/anf_model_parser.cc +++ b/mindspore/ccsrc/utils/load_onnx/anf_model_parser.cc @@ -370,14 +370,14 @@ bool MSANFModelParser::ObtainValueNodeInScalarForm(const std::string &value_node ValuePtr value_ptr = nullptr; switch (attr_tensor_type) { case onnx::TensorProto_DataType_INT32: { - std::vector add_data; + std::vector add_data; for (int i = 0; i < attr_tensor.int32_data_size(); ++i) { add_data.push_back(attr_tensor.int32_data(i)); } if (add_data.size() == 1) { value_ptr = MakeValue(add_data[0]); } else if (!add_data.empty()) { - value_ptr = MakeValue>(add_data); + value_ptr = MakeValue>(add_data); } break; } diff --git a/mindspore/ccsrc/vm/backend.cc b/mindspore/ccsrc/vm/backend.cc index 66ad928cec3..4dd15394b41 100644 --- a/mindspore/ccsrc/vm/backend.cc +++ b/mindspore/ccsrc/vm/backend.cc @@ -32,7 +32,7 @@ namespace mindspore { namespace compile { bool Backend::GetCond(const BaseRef &c, bool *const value) { return BaseRefToBool(c, value); } -bool Backend::GetIndex(const BaseRef &c, int *const value) { return BaseRefToInt(utils::cast(c), value); } +bool Backend::GetIndex(const BaseRef &c, int64_t *const value) { return BaseRefToInt(utils::cast(c), value); } LinConvertResult MsBackend::MsConvert(const AnfNodePtrList &lst, const std::string &target) { MS_LOG(DEBUG) << "MsConvert"; diff --git a/mindspore/ccsrc/vm/backend.h b/mindspore/ccsrc/vm/backend.h index 1bb7c2e406a..2ed9ff36adb 100644 --- a/mindspore/ccsrc/vm/backend.h +++ b/mindspore/ccsrc/vm/backend.h @@ -44,7 +44,7 @@ class Backend { LinkFuncType convert_fn() { return convert_fn_; } std::string name() { return name_; } virtual bool GetCond(const BaseRef &c, bool *value); - virtual bool GetIndex(const BaseRef &c, int *value); + virtual bool GetIndex(const BaseRef &c, int64_t *value); virtual GraphId CompileGraph(NotNull fg) { return kInvalidGraphId; } virtual void Link(GraphId) {} virtual void SetDebugger() {} diff --git a/mindspore/ccsrc/vm/segment_runner.cc b/mindspore/ccsrc/vm/segment_runner.cc index c27e3e56739..a6b13e196d8 100644 --- a/mindspore/ccsrc/vm/segment_runner.cc +++ b/mindspore/ccsrc/vm/segment_runner.cc @@ -58,7 +58,7 @@ AnfNodePtrList GetOutput(const AnfNodePtrList &lst, const NodeUsersMap &users, c std::begin(lst), std::end(lst), std::back_inserter(output), [&users, &seen](AnfNodePtr n) -> AnfNodePtr { auto usersn = users.find(n); bool is_referred_out_of_segment = std::any_of( - std::begin(usersn->second), std::end(usersn->second), [&seen](const std::pair &u) -> bool { + std::begin(usersn->second), std::end(usersn->second), [&seen](const std::pair &u) -> bool { return std::find(std::begin(seen), std::end(seen), u.first) == std::end(seen); }); if (n->isa() && is_referred_out_of_segment) { diff --git a/mindspore/ccsrc/vm/transform.cc b/mindspore/ccsrc/vm/transform.cc index 048077d39db..3b1906d22c9 100644 --- a/mindspore/ccsrc/vm/transform.cc +++ b/mindspore/ccsrc/vm/transform.cc @@ -119,9 +119,9 @@ void AddControlEdge(const FuncGraphPtr &graph, const AnfNodePtr &node, PrimitivePtr prim_ptr = GetValueNode(input_cnode->input(0)); MS_EXCEPTION_IF_NULL(prim_ptr); ValuePtr mode_ptr = prim_ptr->GetAttr("depend_mode"); - int depend_mode = 0; + int64_t depend_mode = 0; if (mode_ptr != nullptr) { - depend_mode = GetValue(mode_ptr); + depend_mode = GetValue(mode_ptr); } if ((prior_node->isa() || depend_node->isa()) && depend_mode == 0) { return; @@ -448,7 +448,7 @@ void CompileGraph::Push(const AnfNodePtr &node) { set_height(height_ + 1); } -void CompileGraph::AddInst(const Instruction &inst, const int &arg) { +void CompileGraph::AddInst(const Instruction &inst, const int64_t &arg) { VectorRef args; args.push_back(arg); AddInst(inst, args); @@ -466,7 +466,7 @@ void CompileGraph::AddInst(const Instruction &inst, const VectorRef &args) { // Gets the stack reference for the node value. If the node is a constant, // it may actually cause the push in to not be mentioned before. -int CompileGraph::Ref(const AnfNodePtr &node) { +int64_t CompileGraph::Ref(const AnfNodePtr &node) { MS_EXCEPTION_IF_NULL(node); MS_LOG(DEBUG) << "Start Ref node " << node->DebugString(true) << " height_: " << height_; if (slots_.count(node) == 0 && node->isa()) { @@ -501,7 +501,7 @@ void CompileGraph::AddInput(const AnfNodePtr &node) { } // Call back effect in stack -void CompileGraph::Ret(int nargs) { set_height(height_ - nargs); } +void CompileGraph::Ret(int64_t nargs) { set_height(height_ - nargs); } void CompileGraph::PushParameters(const FuncGraphPtr &graph) { MS_EXCEPTION_IF_NULL(graph); @@ -512,7 +512,8 @@ void CompileGraph::PushParameters(const FuncGraphPtr &graph) { } } -int CompileGraph::LinConvert(const FuncGraphPtr &graph, const AnfNodePtrList &node_list, const std::string &target) { +int64_t CompileGraph::LinConvert(const FuncGraphPtr &graph, const AnfNodePtrList &node_list, + const std::string &target) { MS_LOG(DEBUG) << "LinConvert start"; LinConvertResult result; @@ -543,7 +544,7 @@ int CompileGraph::LinConvert(const FuncGraphPtr &graph, const AnfNodePtrList &no return RET_SUCCESS; } -int CompileGraph::InterpretNode(const FuncGraphPtr &graph, const CNodePtr &node) { +int64_t CompileGraph::InterpretNode(const FuncGraphPtr &graph, const CNodePtr &node) { MS_EXCEPTION_IF_NULL(node); MS_LOG(DEBUG) << "Interpret node: " << node->DebugString(true); std::vector node_inputs = node->inputs(); @@ -573,7 +574,7 @@ int CompileGraph::InterpretNode(const FuncGraphPtr &graph, const CNodePtr &node) AddPrimitive(node, value); } } else { - int ret = AddCall(graph, node); + int64_t ret = AddCall(graph, node); if (ret == RET_BREAK) { return ret; } @@ -589,7 +590,7 @@ bool CompileGraph::SplitGraph(const FuncGraphPtr &graph) { MS_LOG(DEBUG) << "Split nodes size:" << splits.size(); for (auto &split : splits) { - int ret = RET_SUCCESS; + int64_t ret = RET_SUCCESS; if (utils::isa(split)) { MS_LOG(DEBUG) << "Start a extern LinConvert"; std::vector args; @@ -631,7 +632,7 @@ InstSet CompileGraph::Run(const FuncGraphPtr &graph) { Reset(); PushParameters(graph); - int param_height = height_; + int64_t param_height = height_; MS_LOG(DEBUG) << "'param_height': " << height_ << " to split graph: " << graph->get_return()->DebugString(true); if (!SplitGraph(graph)) { @@ -644,8 +645,8 @@ InstSet CompileGraph::Run(const FuncGraphPtr &graph) { return ret; } -void CompileGraph::AddPadStack(int param_height) { - int stack_sizes = max_height_ - param_height; +void CompileGraph::AddPadStack(int64_t param_height) { + int64_t stack_sizes = max_height_ - param_height; MS_LOG(DEBUG) << "Pad stack max_height_:" << max_height_ << " param:" << param_height << " need_stack:" << stack_sizes; if (stack_sizes > 0) { @@ -658,7 +659,7 @@ void CompileGraph::AddTailCall(const AnfNodePtr &fn, size_t size) { VectorRef args; args.emplace_back(Ref(fn)); args.emplace_back(height_); - args.emplace_back(static_cast(size - 1)); + args.emplace_back(static_cast(size - 1)); MS_LOG(DEBUG) << "Tail call:" << Ref(fn) << ", " << height_ << ", " << size - 1; AddInst(Instruction::kTailCall, args); } @@ -725,7 +726,7 @@ void CompileGraph::AddPrimitive(const CNodePtr &node, const PrimitivePtr &prim) AddInst(Instruction::kPrim, args); } -int CompileGraph::AddCall(const FuncGraphPtr &graph, const CNodePtr &node) { +int64_t CompileGraph::AddCall(const FuncGraphPtr &graph, const CNodePtr &node) { auto inputs = node->inputs(); AnfNodePtr fn = inputs[0]; (void)Ref(fn); @@ -739,7 +740,7 @@ int CompileGraph::AddCall(const FuncGraphPtr &graph, const CNodePtr &node) { } MS_LOG(DEBUG) << "Call:" << Ref(fn) << ", " << height_ << ", " << size - 1; AddInst(Instruction::kCall, Ref(fn)); - Ret(static_cast(size - 1)); + Ret(static_cast(size - 1)); return RET_SUCCESS; } @@ -770,7 +771,7 @@ void TraverseGraphMap( if (node->func_graph() != fg) { continue; } - int key = use.second; + int64_t key = use.second; if (key != 0) { MS_EXCEPTION_IF_NULL(node->input(0)); bool key_is_const = node->input(0)->isa(); @@ -842,7 +843,7 @@ CompileGraphs::CompileGraphs(const BackendPtr &backend, const std::vector(insts_.size()); + mapping_[graph] = static_cast(insts_.size()); if (transform_ != nullptr) { InstSet insts = transform_->Run(graph); if (!insts.empty()) { diff --git a/mindspore/ccsrc/vm/transform.h b/mindspore/ccsrc/vm/transform.h index 819ee07eb71..89e36c6ff49 100644 --- a/mindspore/ccsrc/vm/transform.h +++ b/mindspore/ccsrc/vm/transform.h @@ -57,11 +57,11 @@ class CompileGraph { bool IsCut(const AnfNodePtr &node); void Push(const AnfNodePtr &node); void Tie(const AnfNodePtr &n1, const AnfNodePtr &n2) { slots_[n2] = slots_[n1]; } - void Ret(int nargs); - int Ref(const AnfNodePtr &node); + void Ret(int64_t nargs); + int64_t Ref(const AnfNodePtr &node); VectorRef SplitNodes(const FuncGraphPtr &func_graph); - void set_height(int h) { + void set_height(int64_t h) { height_ = h; if (height_ > max_height_) { max_height_ = height_; @@ -79,10 +79,10 @@ class CompileGraph { VectorRef SplitNodesWithTarget(const std::vector &input_nodes, const FuncGraphPtr &graph); void PushParameters(const FuncGraphPtr &func_graph); bool SplitGraph(const FuncGraphPtr &func_graph); - int LinConvert(const FuncGraphPtr &func_graph, const AnfNodePtrList &node_list, const std::string &target = ""); - int InterpretNode(const FuncGraphPtr &func_graph, const CNodePtr &node); - int AddCall(const FuncGraphPtr &graph, const CNodePtr &node); - void AddPadStack(int param_height); + int64_t LinConvert(const FuncGraphPtr &func_graph, const AnfNodePtrList &node_list, const std::string &target = ""); + int64_t InterpretNode(const FuncGraphPtr &func_graph, const CNodePtr &node); + int64_t AddCall(const FuncGraphPtr &graph, const CNodePtr &node); + void AddPadStack(int64_t param_height); void AddTailCall(const AnfNodePtr &fn, size_t size); void AddPartial(const CNodePtr &node); void AddMakeTuple(const CNodePtr &node); @@ -92,17 +92,17 @@ class CompileGraph { void AddPrimitive(const CNodePtr &node, const PrimitivePtr &prim); void AddInput(const AnfNodePtr &node); void AddExternal(const LinConvertResult &result); - void AddInst(const Instruction &inst, const int &arg); + void AddInst(const Instruction &inst, const int64_t &arg); void AddInst(const Instruction &inst, const ValuePtr &arg); void AddInst(const Instruction &inst, const VectorRef &args); BackendPtr backend_; LinkFuncType lin_convert_; bool is_gevm_convert_; - int height_{0}; - int max_height_{0}; + int64_t height_{0}; + int64_t max_height_{0}; std::vector cut_list_; - std::unordered_map slots_; + std::unordered_map slots_; InstSet inst_; }; @@ -127,7 +127,7 @@ class CompileGraphs { private: InstSet insts_; - std::unordered_map mapping_; + std::unordered_map mapping_; CompileGraphPtr transform_; BackendPtr backend_; }; diff --git a/mindspore/ccsrc/vm/vm.cc b/mindspore/ccsrc/vm/vm.cc index 56d0713085b..f7e62b0b9f2 100644 --- a/mindspore/ccsrc/vm/vm.cc +++ b/mindspore/ccsrc/vm/vm.cc @@ -31,7 +31,8 @@ namespace compile { // fn_: Callable function. // args_: Sequence of function args. // fg_: Graph of function. -StructPartial::StructPartial(int fn, const VectorRef &args, const FuncGraphPtr &fg) : fn_(fn), args_(args), fg_(fg) {} +StructPartial::StructPartial(int64_t fn, const VectorRef &args, const FuncGraphPtr &fg) + : fn_(fn), args_(args), fg_(fg) {} std::ostream &operator<<(std::ostream &os, const StructPartial &other) { os << "partial(" << other.fn_ << ", " << other.args_.ToString() << ")"; @@ -54,7 +55,7 @@ bool operator==(const StructSimuSwitch &lhs, const StructSimuSwitch &rhs) { } std::ostream &operator<<(std::ostream &os, const SwitchCondStatus &other) { - os << "SwitchCondStatus(" << static_cast(other) << ")"; + os << "SwitchCondStatus(" << static_cast(other) << ")"; return os; } @@ -76,32 +77,32 @@ void FinalVM::Push(const BaseRef &v) { insts_stack_[IntToSize(sp_++)] = v; } -void FinalVM::Pop(int n) { +void FinalVM::Pop(int64_t n) { if (n > sp_) { MS_LOG(EXCEPTION) << "Invalid value of n " << n << ", it should be not more than " << sp_ - 1; } - for (int i = 0; i < n; i++) { + for (int64_t i = 0; i < n; i++) { insts_stack_[IntToSize(sp_ - i - 1)] = BaseRef(); } sp_ -= n; } -void FinalVM::MoveStack(int nitems, int height) { +void FinalVM::MoveStack(int64_t nitems, int64_t height) { if (nitems > height || height > sp_) { MS_LOG(EXCEPTION) << "MoveStack arg error: nitems=" << nitems << " height=" << height; } - int n = height - nitems; - int src = sp_ - height; - int dst = sp_ - nitems; - for (int i = 0; i < nitems; i++) { + int64_t n = height - nitems; + int64_t src = sp_ - height; + int64_t dst = sp_ - nitems; + for (int64_t i = 0; i < nitems; i++) { insts_stack_[IntToSize(src + i)] = insts_stack_[IntToSize(dst + i)]; } Pop(n); } -BaseRef FinalVM::Ref(int i) { +BaseRef FinalVM::Ref(int64_t i) { MS_LOG(DEBUG) << "Ref i:" << i << " sp_:" << sp_; - size_t sp_next = IntToSize(sp_ + i); + size_t sp_next = LongToSize(sp_ + i); if (sp_next < insts_stack_.size()) { if (utils::isa(insts_stack_[sp_next])) { py::object value = utils::cast(insts_stack_[sp_next]).object_; @@ -129,7 +130,7 @@ void FinalVM::Popp() { void FinalVM::Pushsp() { retsp_.push(sp_); } void FinalVM::Popsp() { - int sp = retsp_.top(); + int64_t sp = retsp_.top(); MS_LOG(DEBUG) << "Current sp:" << sp_ << ", before sp:" << sp << ", " << sp_ - sp; if (sp_ >= sp) { Pop(sp_ - sp + 1); @@ -147,7 +148,7 @@ void FinalVM::DoJmp(const BaseRef &jmp_orig) { MS_LOG(DEBUG) << "Start jump StructPartial"; auto new_jmp = utils::cast>(jmp); auto args = new_jmp->args_; - InstPadStack(VectorRef(std::vector{static_cast(args.size())})); + InstPadStack(VectorRef(std::vector{static_cast(args.size())})); auto iter = args.rbegin(); for (; iter != args.rend(); ++iter) { Push(*iter); @@ -156,10 +157,10 @@ void FinalVM::DoJmp(const BaseRef &jmp_orig) { return; } - if (!utils::isa(jmp)) { - MS_LOG(EXCEPTION) << "Jmp inst should be a int"; + if (!utils::isa(jmp)) { + MS_LOG(EXCEPTION) << "Jmp inst should be a int64_t"; } - pc_ = utils::cast(jmp); + pc_ = utils::cast(jmp); MS_LOG(DEBUG) << "End do jump pc_:" << pc_; } @@ -167,7 +168,7 @@ BaseRef FinalVM::Eval(const VectorRef &args) { MS_LOG(DEBUG) << "Start: " << args.size(); insts_stack_.clear(); insts_stack_.resize(args.size()); - std::stack().swap(retp_); + std::stack().swap(retp_); retp_.push(-1); pc_ = 0; sp_ = 0; @@ -179,7 +180,7 @@ BaseRef FinalVM::Eval(const VectorRef &args) { py::object value = py_ref.object_; if (py::isinstance(value)) { auto a = py::cast(value); - Push(static_cast(a)); + Push(static_cast(a)); continue; } } @@ -211,7 +212,7 @@ void FinalVM::InstCall(const VectorRef &args) { return; } - int jmp = utils::cast(args[0]); + int64_t jmp = utils::cast(args[0]); MS_LOG(DEBUG) << "Call pushp:" << pc_ << ", jmp:" << jmp << ", sp:" << sp_; Pushp(); DoJmp(Ref(jmp)); @@ -227,9 +228,9 @@ void FinalVM::InstTailCall(const VectorRef &args) { return; } - int jmp = utils::cast(args[0]); - int height = utils::cast(args[1]); - int nargs = utils::cast(args[2]); + int64_t jmp = utils::cast(args[0]); + int64_t height = utils::cast(args[1]); + int64_t nargs = utils::cast(args[2]); auto new_jmp = Ref(jmp); MoveStack(nargs, height); @@ -257,8 +258,8 @@ void FinalVM::InstReturn(const VectorRef &args) { return; } - int rpos = utils::cast(args[0]); - int height = utils::cast(args[1]); + int64_t rpos = utils::cast(args[0]); + int64_t height = utils::cast(args[1]); auto rv = Ref(rpos); Pop(height); @@ -275,12 +276,12 @@ void FinalVM::InstRealPartial(const VectorRef &args) { return; } - int fn_ = utils::cast(args[0]); - auto fn = utils::cast(Ref(fn_)); + int64_t fn_ = utils::cast(args[0]); + auto fn = utils::cast(Ref(fn_)); MS_LOG(DEBUG) << "Partial argssize:" << args.size(); std::vector outs(args.size() - 1); (void)std::transform(args.begin() + 1, args.end(), outs.begin(), - [&, this](const BaseRef &a) { return Ref(utils::cast(a)); }); + [&, this](const BaseRef &a) { return Ref(utils::cast(a)); }); Push(std::make_shared(fn, VectorRef(outs))); } @@ -298,9 +299,9 @@ void FinalVM::InstRealSwitch(const VectorRef &args) { return; } - int cond = utils::cast(args[0]); - int vtrue = utils::cast(args[1]); - int vfalse = utils::cast(args[2]); + int64_t cond = utils::cast(args[0]); + int64_t vtrue = utils::cast(args[1]); + int64_t vfalse = utils::cast(args[2]); BaseRef c = Ref(cond); MS_LOG(DEBUG) << vtrue << " false:" << vfalse << " InstSwitch: " << c.ToString(); @@ -332,14 +333,14 @@ void FinalVM::InstSwitchLayer(const VectorRef &args) { return; } - int idx = utils::cast(args[0]); - VectorRef branches = utils::cast(Ref(utils::cast(args[1]))); - int size = static_cast(branches.size()); + int64_t idx = utils::cast(args[0]); + VectorRef branches = utils::cast(Ref(utils::cast(args[1]))); + int64_t size = static_cast(branches.size()); BaseRef index = Ref(idx); - int idx_value = 0; + int64_t idx_value = 0; if (!backend_->GetIndex(index, &idx_value)) { - MS_LOG(EXCEPTION) << "Not supported type to be casted to int."; + MS_LOG(EXCEPTION) << "Not supported type to be casted to int64_t."; } auto ori_value = idx_value; if (idx_value < 0) { @@ -360,7 +361,7 @@ void FinalVM::InstTuple(const VectorRef &args) { VectorRef tuple; auto iter = args.begin(); for (; iter != args.end(); ++iter) { - auto a = utils::cast(*iter); + auto a = utils::cast(*iter); tuple.push_back(Ref(a)); } Push(tuple); @@ -390,7 +391,7 @@ void FinalVM::InstInput(const VectorRef &args) { return; } - int rpos = utils::cast(args[0]); + int64_t rpos = utils::cast(args[0]); Push(Ref(rpos)); MS_LOG(DEBUG) << "End"; } @@ -404,10 +405,10 @@ void FinalVM::InstPadStack(const VectorRef &args) { return; } - int sz = utils::cast(args[0]); + int64_t sz = utils::cast(args[0]); MS_LOG(DEBUG) << insts_stack_.size() << " need padstack " << sz << " sp_ " << sp_; size_t stack_size = insts_stack_.size(); - int need = sz - (static_cast(stack_size) - sp_); + int64_t need = sz - (static_cast(stack_size) - sp_); if (need > 0) { MS_LOG(DEBUG) << "InstPadStack resize: size:" << insts_stack_.size() << " need pad:" << need; insts_stack_.resize(stack_size + IntToSize(need)); @@ -426,7 +427,7 @@ void FinalVM::InstExternal(const VectorRef &args) { RunFunctionRef run_ref = utils::cast(args[0]); compile::RunFuncPtr fn = run_ref.func_; for (size_t i = 2; i < args.size(); ++i) { - auto index = utils::cast(args[i]); + auto index = utils::cast(args[i]); tuple.push_back(Ref(index)); } @@ -455,7 +456,7 @@ void FinalVM::InstPushPrim(const VectorRef &args) { auto prim = utils::cast(args[0]); VectorRef tuple; for (size_t i = 1; i < args.size(); ++i) { - auto index = utils::cast(args[i]); + auto index = utils::cast(args[i]); tuple.push_back(Ref(index)); } diff --git a/mindspore/ccsrc/vm/vm.h b/mindspore/ccsrc/vm/vm.h index 751c0405cdb..79163c6b9ef 100644 --- a/mindspore/ccsrc/vm/vm.h +++ b/mindspore/ccsrc/vm/vm.h @@ -69,12 +69,12 @@ const std::vector inst_str{"call", "tail_call", "return", class StructPartial : public Base { public: // Initialize StructPartial. - StructPartial(int fn, const VectorRef &args, const FuncGraphPtr &fg = nullptr); + StructPartial(int64_t fn, const VectorRef &args, const FuncGraphPtr &fg = nullptr); virtual ~StructPartial() = default; MS_DECLARE_PARENT(StructPartial, Base) - int fn_; + int64_t fn_; VectorRef args_; FuncGraphPtr fg_; }; @@ -122,10 +122,10 @@ class FinalVM { BaseRef RunHook(const PrimitivePtr &prim, const VectorRef &arg); protected: - BaseRef Ref(int i); + BaseRef Ref(int64_t i); void Push(const BaseRef &v); - void Pop(int n = 1); - void MoveStack(int nitems, int height); + void Pop(int64_t n = 1); + void MoveStack(int64_t nitems, int64_t height); void Pushp(); void Popp(); void Pushsp(); @@ -136,10 +136,10 @@ class FinalVM { private: InstSet insts_; std::deque insts_stack_; - std::stack retp_; - std::stack retsp_; - int pc_; - int sp_; + std::stack retp_; + std::stack retsp_; + int64_t pc_; + int64_t sp_; BackendPtr backend_; const InstFunctionMap inst_function_map = { {Instruction::kCall, [this](const VectorRef &args) { InstCall(args); }}, diff --git a/mindspore/core/abstract/abstract_function.cc b/mindspore/core/abstract/abstract_function.cc index 2d46862af1d..1e9218870c2 100644 --- a/mindspore/core/abstract/abstract_function.cc +++ b/mindspore/core/abstract/abstract_function.cc @@ -65,7 +65,7 @@ AbstractFuncUnion::AbstractFuncUnion(const AbstractFunctionPtr &first, const Abs std::string AbstractFuncUnion::ToString() const { std::ostringstream buffer; buffer << "AbstractFuncUnion({"; - int i = 0; + int64_t i = 0; for (const auto &func : func_list_) { MS_EXCEPTION_IF_NULL(func); buffer << "[" << i << "]: " << func->ToString() << ", "; @@ -278,7 +278,7 @@ std::size_t VirtualAbstractClosure::hash() const { std::string VirtualAbstractClosure::ToString() const { std::ostringstream buffer; buffer << "VirtualAbstractClosure(args: {"; - int i = 0; + int64_t i = 0; for (const auto &arg : args_spec_list_) { MS_EXCEPTION_IF_NULL(arg); buffer << "[" << i << "]: " << arg->ToString() << ", "; @@ -317,7 +317,7 @@ std::size_t TypedPrimitiveAbstractClosure::hash() const { std::string TypedPrimitiveAbstractClosure::ToString() const { std::ostringstream buffer; buffer << "TypedPrimitiveAbstractClosure: primitive: " << prim_->name() << "(args: {"; - int i = 0; + int64_t i = 0; for (const auto &arg : args_spec_list_) { MS_EXCEPTION_IF_NULL(arg); buffer << "[" << i << "]: " << arg->ToString() << ", "; diff --git a/mindspore/core/abstract/abstract_value.cc b/mindspore/core/abstract/abstract_value.cc index c296c892431..329180bac29 100644 --- a/mindspore/core/abstract/abstract_value.cc +++ b/mindspore/core/abstract/abstract_value.cc @@ -192,7 +192,7 @@ const AbstractBasePtr AbstractSequeue::operator[](const std::size_t &dim) const std::string AbstractSequeue::ToString() const { std::ostringstream buffer; - int i = 0; + int64_t i = 0; for (const auto &ele : elements_) { MS_EXCEPTION_IF_NULL(ele); buffer << "element[" << i << "]: " << ele->ToString() << ","; diff --git a/mindspore/core/abstract/abstract_value.h b/mindspore/core/abstract/abstract_value.h index b66e5a9c3f9..126398b70a5 100644 --- a/mindspore/core/abstract/abstract_value.h +++ b/mindspore/core/abstract/abstract_value.h @@ -102,6 +102,7 @@ class AbstractScalar : public AbstractBase { explicit AbstractScalar(const ValuePtr &value, const TypePtr &type) : AbstractBase(value, type) {} explicit AbstractScalar(const ValuePtr &value) : AbstractBase(value, value->type()) {} explicit AbstractScalar(int value) : AbstractBase(MakeValue(value), kInt32) {} + explicit AbstractScalar(int64_t value) : AbstractBase(MakeValue(value), kInt64) {} explicit AbstractScalar(float value) : AbstractBase(MakeValue(value), kFloat32) {} explicit AbstractScalar(double value) : AbstractBase(MakeValue(value), kFloat64) {} explicit AbstractScalar(bool value) : AbstractBase(MakeValue(value), kBool) {} @@ -294,7 +295,7 @@ class AbstractTensor : public AbstractUndetermined { if (value != nullptr) { auto tensor = value->cast(); if (tensor != nullptr) { - hash_sum = hash_combine(hash_sum, IntToSize(tensor->DataSize())); + hash_sum = hash_combine(hash_sum, LongToSize(tensor->DataSize())); } } return hash_sum; diff --git a/mindspore/core/abstract/analysis_context.cc b/mindspore/core/abstract/analysis_context.cc index 2270f3c1b03..9795673fa28 100644 --- a/mindspore/core/abstract/analysis_context.cc +++ b/mindspore/core/abstract/analysis_context.cc @@ -199,7 +199,7 @@ std::string AnalysisContext::ToString() const { buffer << "Func Graph: " << func_graph_->ToString(); } buffer << " Args: "; - int i = 0; + int64_t i = 0; for (const auto &arg : args_spec_list_) { buffer << "[" << i << "]: " << arg->ToString() << ", "; i++; diff --git a/mindspore/core/abstract/dshape.cc b/mindspore/core/abstract/dshape.cc index a2cbe0fe62d..6695fa7f0ff 100644 --- a/mindspore/core/abstract/dshape.cc +++ b/mindspore/core/abstract/dshape.cc @@ -82,7 +82,7 @@ bool Shape::operator==(const BaseShape &other) const { return shape_ == static_cast(other).shape_; } -const int Shape::SHP_ANY; +const int64_t Shape::SHP_ANY; void Shape::Broaden() { for (size_t i = 0; i < shape_.size(); i++) { shape_[i] = SHP_ANY; @@ -122,7 +122,7 @@ bool SequeueShape::SequeueEqual(const BaseShape &other) const { if (other_shapes.size() != p_shapes_.size()) { return false; } - for (unsigned int i = 0; i < p_shapes_.size(); ++i) { + for (uint64_t i = 0; i < p_shapes_.size(); ++i) { if (!(*p_shapes_[i] == *other_shapes[i])) { return false; } diff --git a/mindspore/core/abstract/dshape.h b/mindspore/core/abstract/dshape.h index 01aa314e222..1f2f7836aca 100644 --- a/mindspore/core/abstract/dshape.h +++ b/mindspore/core/abstract/dshape.h @@ -62,19 +62,10 @@ extern const std::shared_ptr kNoShape; class Shape : public BaseShape { public: - static const int SHP_ANY = -1; + static const int64_t SHP_ANY = -1; Shape() : shape_() {} - Shape(const std::initializer_list &list) : shape_(list) {} - Shape(const std::initializer_list &list) { - std::vector list_in(list); - (void)std::transform(list_in.begin(), list_in.end(), std::back_inserter(shape_), - [](const int64_t &value) { return static_cast(value); }); - } + Shape(const std::initializer_list &list) : shape_(list) {} explicit Shape(const ShapeVector &list) : shape_(list) {} - explicit Shape(const std::vector &list) { - (void)std::transform(list.begin(), list.end(), std::back_inserter(shape_), - [](const int64_t &value) { return static_cast(value); }); - } Shape(const ShapeVector &list, const ShapeVector &min_shape, const ShapeVector &max_shape) : shape_(list), min_shape_(min_shape), max_shape_(max_shape) {} ~Shape() override = default; diff --git a/mindspore/core/abstract/infer_functions.h b/mindspore/core/abstract/infer_functions.h index c37194ab2ee..7bf40dbd33f 100644 --- a/mindspore/core/abstract/infer_functions.h +++ b/mindspore/core/abstract/infer_functions.h @@ -229,7 +229,7 @@ AbstractBasePtr InferTupleOrListOrDictLen(const std::string &op_name, const Abst // Inputs: a tuple or list or dict. CheckArgsSize(op_name, args_spec_list, 1); auto arg = CheckArg(op_name, args_spec_list, 0); - return std::make_shared(SizeToInt(arg->size())); + return std::make_shared(SizeToLong(arg->size())); } } // namespace abstract } // namespace mindspore diff --git a/mindspore/core/abstract/param_validator.cc b/mindspore/core/abstract/param_validator.cc index 69fe88b4a3d..69f30b6ea9b 100644 --- a/mindspore/core/abstract/param_validator.cc +++ b/mindspore/core/abstract/param_validator.cc @@ -119,14 +119,14 @@ TypePtr CheckDtypeSame(const std::string &op, const AbstractTensorPtr &tensor_ba return type_base; } -int CheckAxis(const std::string &op, const ValuePtr &axis, int minimum, int max) { +int64_t CheckAxis(const std::string &op, const ValuePtr &axis, int64_t minimum, int64_t max) { if (axis == nullptr) { MS_LOG(EXCEPTION) << op << " evaluator axis is null"; } - if (!axis->isa()) { - MS_LOG(EXCEPTION) << op << " evaluator axis should be int, but got " << axis->type_name(); + if (!axis->isa()) { + MS_LOG(EXCEPTION) << op << " evaluator axis should be int64_t, but got " << axis->type_name(); } - int axis_value = GetValue(axis); + int64_t axis_value = GetValue(axis); if (axis_value > max || axis_value < minimum) { MS_LOG(EXCEPTION) << op << " evaluator axis value should be in the range [" << minimum << ", " << max << "], but get " << axis_value; diff --git a/mindspore/core/abstract/param_validator.h b/mindspore/core/abstract/param_validator.h index 0b49a7c30fb..49b7b93aa91 100644 --- a/mindspore/core/abstract/param_validator.h +++ b/mindspore/core/abstract/param_validator.h @@ -44,7 +44,7 @@ ShapePtr CheckShapeSame(const std::string &op, const AbstractTensorPtr &tensor_b TypePtr CheckDtypeSame(const std::string &op, const AbstractTensorPtr &tensor_base, const AbstractTensorPtr &tensor); -int CheckAxis(const std::string &op, const ValuePtr &axis, int min, int max); +int64_t CheckAxis(const std::string &op, const ValuePtr &axis, int64_t min, int64_t max); void CheckArgsSize(const std::string &op, const AbstractBasePtrList &args_spec_list, size_t size_expect); diff --git a/mindspore/core/abstract/prim_arrays.cc b/mindspore/core/abstract/prim_arrays.cc index abf3ede6890..7d7a011b458 100644 --- a/mindspore/core/abstract/prim_arrays.cc +++ b/mindspore/core/abstract/prim_arrays.cc @@ -58,14 +58,14 @@ AbstractBasePtr InferImplBroadCastShape(const AnalysisEnginePtr &, const Primiti auto shp_tuple_x = value_tuple_x->value(); ShapeVector shp_x; (void)std::transform(std::begin(shp_tuple_x), std::end(shp_tuple_x), std::back_inserter(shp_x), - [](const ValuePtr &e) -> int { return GetValue(e); }); + [](const ValuePtr &e) -> int64_t { return GetValue(e); }); auto value_tuple_y = ys->BuildValue()->cast(); MS_EXCEPTION_IF_NULL(value_tuple_y); auto shp_tuple_y = value_tuple_y->value(); ShapeVector shp_y; (void)std::transform(std::begin(shp_tuple_y), std::end(shp_tuple_y), std::back_inserter(shp_y), - [](const ValuePtr &e) -> int { return GetValue(e); }); + [](const ValuePtr &e) -> int64_t { return GetValue(e); }); ShapeVector res = BroadcastShape(shp_x, shp_y); if (res.empty()) { @@ -74,8 +74,8 @@ AbstractBasePtr InferImplBroadCastShape(const AnalysisEnginePtr &, const Primiti } AbstractBasePtrList elems; - (void)std::transform(res.begin(), res.end(), std::back_inserter(elems), [](int n) -> AbstractBasePtr { - return std::make_shared(std::make_shared(n), kInt32); + (void)std::transform(res.begin(), res.end(), std::back_inserter(elems), [](int64_t n) -> AbstractBasePtr { + return std::make_shared(std::make_shared(n), kInt64); }); return std::make_shared(elems); @@ -101,7 +101,7 @@ AbstractBasePtr InferImplTile(const AnalysisEnginePtr &, const PrimitivePtr &pri auto value_tuple_mul = mul_shp_value->cast(); auto mul_shp_data = value_tuple_mul->value(); (void)std::transform(std::begin(mul_shp_data), std::end(mul_shp_data), std::back_inserter(mul_shp), - [](const ValuePtr &e) -> int { return GetValue(e); }); + [](const ValuePtr &e) -> int64_t { return GetValue(e); }); if (input_shape->shape().size() != mul_shp_data.size()) { MS_LOG(EXCEPTION) << "Tile requires input and multiples size equal, while the input size is " << input_shape->shape().size() << ", value size is: " << mul_shp_data.size() << "."; @@ -126,13 +126,13 @@ AbstractBasePtr InferImplPack(const AnalysisEnginePtr &, const PrimitivePtr &pri size_t tuple_len = arg->elements().size(); AbstractTensorPtr tensor_base = CheckArg(op_name, arg->elements(), 0); - int rank_base = SizeToInt(tensor_base->shape()->shape().size()); + int64_t rank_base = SizeToLong(tensor_base->shape()->shape().size()); ValuePtr axis = primitive->GetAttr("axis"); // Axis value should be in [-(rank_base + 1), rank_base). - int axis_value = CheckAxis(op_name, axis, -(rank_base + 1), rank_base); + int64_t axis_value = CheckAxis(op_name, axis, -(rank_base + 1), rank_base); // If axis is negative, add offset(rank_base + 1) to turn it to positive. - axis_value = GetPositiveAxis(axis_value, IntToSize(rank_base + 1)); + axis_value = GetPositiveAxis(axis_value, LongToSize(rank_base + 1)); for (size_t i = 1; i < tuple_len; ++i) { AbstractTensorPtr tensor = CheckArg(op_name, arg->elements(), i); @@ -140,7 +140,7 @@ AbstractBasePtr InferImplPack(const AnalysisEnginePtr &, const PrimitivePtr &pri (void)CheckShapeSame(op_name, tensor_base, tensor); } - primitive->set_attr("N", MakeValue(SizeToInt(tuple_len))); + primitive->set_attr("N", MakeValue(SizeToLong(tuple_len))); primitive->set_attr("T", tensor_base->element()->BuildType()); AbstractTensorPtr ret = dyn_cast(tensor_base->Broaden()); @@ -213,7 +213,7 @@ AbstractBasePtr InferImplUnsortedSegmentSum(const AnalysisEnginePtr &, const Pri auto segment_ids_shape = segment_ids->shape()->shape(); auto num_segments = CheckArg(op_name, args_spec_list, 2); - std::vector shape; + ShapeVector shape; auto num_segments_value = num_segments->BuildValue(); MS_EXCEPTION_IF_NULL(num_segments_value); if (!num_segments_value->isa()) { @@ -222,7 +222,7 @@ AbstractBasePtr InferImplUnsortedSegmentSum(const AnalysisEnginePtr &, const Pri shape.emplace_back(-1); } else { auto num_segments_tensor = num_segments_value->cast(); - int value = *(static_cast(num_segments_tensor->data_c())); + int64_t value = *(static_cast(num_segments_tensor->data_c())); MS_LOG(INFO) << "Infer UnsortedSegmentSum output shape:" << value; shape.emplace_back(value); } @@ -263,9 +263,9 @@ AbstractBasePtr InferImplDiv(const AnalysisEnginePtr &, const PrimitivePtr &prim MS_EXCEPTION_IF_NULL(x->shape()); MS_EXCEPTION_IF_NULL(y); MS_EXCEPTION_IF_NULL(y->shape()); - std::vector x_shape = x->shape()->shape(); - std::vector y_shape = y->shape()->shape(); - std::vector out_shape = BroadcastShape(x_shape, y_shape); + ShapeVector x_shape = x->shape()->shape(); + ShapeVector y_shape = y->shape()->shape(); + ShapeVector out_shape = BroadcastShape(x_shape, y_shape); return std::make_shared(x->element(), std::make_shared(out_shape)); } @@ -279,9 +279,9 @@ AbstractBasePtr InferImplRealDiv(const AnalysisEnginePtr &, const PrimitivePtr & MS_EXCEPTION_IF_NULL(x->shape()); MS_EXCEPTION_IF_NULL(y); MS_EXCEPTION_IF_NULL(y->shape()); - std::vector x_shape = x->shape()->shape(); - std::vector y_shape = y->shape()->shape(); - std::vector out_shape = BroadcastShape(x_shape, y_shape); + ShapeVector x_shape = x->shape()->shape(); + ShapeVector y_shape = y->shape()->shape(); + ShapeVector out_shape = BroadcastShape(x_shape, y_shape); if (out_shape.empty()) { MS_LOG(EXCEPTION) << "BroadcastShape fail: " << args_spec_list[0]->ToString() << "," << args_spec_list[1]->ToString(); @@ -296,7 +296,7 @@ AbstractBasePtr InferImplGatherV2(const AnalysisEnginePtr &, const PrimitivePtr AbstractTensorPtr params = CheckArg(op_name, args_spec_list, 0); AbstractTensorPtr indices = CheckArg(op_name, args_spec_list, 1); - int axis_val = 0; + int64_t axis_val = 0; // 3rd input is a Tensor when GatherV2 is a dynamic shape operator if (args_spec_list[2]->isa()) { auto axis = args_spec_list[2]->cast(); @@ -305,10 +305,10 @@ AbstractBasePtr InferImplGatherV2(const AnalysisEnginePtr &, const PrimitivePtr MS_EXCEPTION_IF_NULL(axis_value_ptr); auto axis_tensor = axis_value_ptr->cast(); MS_EXCEPTION_IF_NULL(axis_tensor); - axis_val = *static_cast(axis_tensor->data_c()); + axis_val = *static_cast(axis_tensor->data_c()); } else if (args_spec_list[2]->isa()) { auto axis = args_spec_list[2]->cast(); - axis_val = GetValue(axis->BuildValue()); + axis_val = GetValue(axis->BuildValue()); } else { MS_LOG(EXCEPTION) << "Invalid abstract type:" << args_spec_list[2]->type_name(); } @@ -316,7 +316,7 @@ AbstractBasePtr InferImplGatherV2(const AnalysisEnginePtr &, const PrimitivePtr auto params_shp = params->shape()->shape(); auto indices_shp = indices->shape()->shape(); - auto params_rank = static_cast(params_shp.size()); + auto params_rank = static_cast(params_shp.size()); if (axis_val < 0) { axis_val += params_rank; } @@ -350,7 +350,7 @@ AbstractBasePtr InferImplShape(const AnalysisEnginePtr &, const PrimitivePtr &pr AbstractBasePtrList elements; for (const auto &dim : shape) { if (dim == Shape::SHP_ANY) { - elements.push_back(std::make_shared(std::make_shared(), std::make_shared(32))); + elements.push_back(std::make_shared(std::make_shared(), std::make_shared(64))); } else { elements.push_back(std::make_shared(dim)); } @@ -366,14 +366,14 @@ AbstractBasePtr InferImplDynamicShape(const AnalysisEnginePtr &, const Primitive AbstractTensorPtr input = CheckArg(op_name, args_spec_list, 0); auto shape = input->shape()->shape(); - bool has_dyn_shape = std::any_of(shape.begin(), shape.end(), [](int dim) { return dim == Shape::SHP_ANY; }); - std::vector tensor_shp({static_cast(shape.size())}); + bool has_dyn_shape = std::any_of(shape.begin(), shape.end(), [](int64_t dim) { return dim == Shape::SHP_ANY; }); + ShapeVector tensor_shp({static_cast(shape.size())}); if (has_dyn_shape) { - auto elem = std::make_shared(std::make_shared(), std::make_shared(32)); + auto elem = std::make_shared(std::make_shared(), std::make_shared(64)); return std::make_shared(elem, std::make_shared(tensor_shp)); } - auto shp_buf_size = sizeof(int) * shape.size(); - auto tensor = std::make_shared(kNumberTypeInt32, tensor_shp, shape.data(), shp_buf_size); + auto shp_buf_size = sizeof(int64_t) * shape.size(); + auto tensor = std::make_shared(kNumberTypeInt64, tensor_shp, shape.data(), shp_buf_size); return tensor->ToAbstract(); } diff --git a/mindspore/core/abstract/prim_debug.cc b/mindspore/core/abstract/prim_debug.cc index 4b8cde34d8a..a8d705f2e9b 100644 --- a/mindspore/core/abstract/prim_debug.cc +++ b/mindspore/core/abstract/prim_debug.cc @@ -29,7 +29,7 @@ AbstractBasePtr InferImplDebug(const AnalysisEnginePtr &, const PrimitivePtr &pr CheckArgsSize(op_name, args_spec_list, 1); auto tensor_value = CheckArg(op_name, args_spec_list, 0); - int tensor_rank = SizeToInt(tensor_value->shape()->shape().size()); + int64_t tensor_rank = SizeToLong(tensor_value->shape()->shape().size()); if (tensor_rank == 0) { MS_LOG(EXCEPTION) << op_name << " summary evaluator second arg should be an tensor, but got a scalar, rank is 0"; } diff --git a/mindspore/core/abstract/prim_maths.cc b/mindspore/core/abstract/prim_maths.cc index 230486216a5..e2082245449 100644 --- a/mindspore/core/abstract/prim_maths.cc +++ b/mindspore/core/abstract/prim_maths.cc @@ -54,10 +54,10 @@ AbstractBasePtr InferImplMul(const AnalysisEnginePtr &, const PrimitivePtr &prim CheckArgsSize(op_name, args_spec_list, 2); ShapePtr shape_x = dyn_cast(args_spec_list[0]->GetShapeTrack()); MS_EXCEPTION_IF_NULL(shape_x); - std::vector x_dims = shape_x->shape(); + std::vector x_dims = shape_x->shape(); ShapePtr shape_y = dyn_cast(args_spec_list[1]->GetShapeTrack()); MS_EXCEPTION_IF_NULL(shape_y); - std::vector y_dims = shape_y->shape(); + std::vector y_dims = shape_y->shape(); auto broadcast_shape = BroadcastShape(x_dims, y_dims); if (broadcast_shape.empty()) { MS_LOG(EXCEPTION) << "BroadcastShape fail: " << args_spec_list[0]->ToString() << "," @@ -75,10 +75,10 @@ AbstractBasePtr InferImplTensorAdd(const AnalysisEnginePtr &, const PrimitivePtr CheckArgsSize(op_name, args_spec_list, 2); ShapePtr shape_x = dyn_cast(args_spec_list[0]->GetShapeTrack()); MS_EXCEPTION_IF_NULL(shape_x); - std::vector x_dims = shape_x->shape(); + std::vector x_dims = shape_x->shape(); ShapePtr shape_y = dyn_cast(args_spec_list[1]->GetShapeTrack()); MS_EXCEPTION_IF_NULL(shape_y); - std::vector y_dims = shape_y->shape(); + std::vector y_dims = shape_y->shape(); auto broadcast_shape = BroadcastShape(x_dims, y_dims); if (broadcast_shape.empty()) { MS_LOG(EXCEPTION) << "BroadcastShape fail: " << args_spec_list[0]->ToString() << "," diff --git a/mindspore/core/abstract/prim_nn.cc b/mindspore/core/abstract/prim_nn.cc index b41d40594c7..62ce8c69d4f 100644 --- a/mindspore/core/abstract/prim_nn.cc +++ b/mindspore/core/abstract/prim_nn.cc @@ -35,15 +35,15 @@ AbstractBasePtr InferImplPooling(const AnalysisEnginePtr &, const PrimitivePtr & if (input_shape->shape().size() != 4) { MS_LOG(EXCEPTION) << "Pooling input should be a 4-D tensor."; } - int h_input = input_shape->shape()[2]; - int w_input = input_shape->shape()[3]; + int64_t h_input = input_shape->shape()[2]; + int64_t w_input = input_shape->shape()[3]; - int window = primitive->GetAttr("window")->cast()->value(); - int stride = primitive->GetAttr("stride")->cast()->value(); - int padding = primitive->GetAttr("pad")->cast()->value(); - int nan_opt = primitive->GetAttr("nan_opt")->cast()->value(); - int data_mode = primitive->GetAttr("data_mode")->cast()->value(); - int ceil_mode = primitive->GetAttr("ceil_mode")->cast()->value(); + int64_t window = primitive->GetAttr("window")->cast()->value(); + int64_t stride = primitive->GetAttr("stride")->cast()->value(); + int64_t padding = primitive->GetAttr("pad")->cast()->value(); + int64_t nan_opt = primitive->GetAttr("nan_opt")->cast()->value(); + int64_t data_mode = primitive->GetAttr("data_mode")->cast()->value(); + int64_t ceil_mode = primitive->GetAttr("ceil_mode")->cast()->value(); if (stride <= 0) { MS_LOG(EXCEPTION) << "Invalid stride value: " << stride << ", should greater then 0"; @@ -81,8 +81,8 @@ AbstractBasePtr InferImplPooling(const AnalysisEnginePtr &, const PrimitivePtr & } } - int h_out = ((h_input + 2 * padding - (window - 1) - 1) / stride) + 1; - int w_out = ((w_input + 2 * padding - (window - 1) - 1) / stride) + 1; + int64_t h_out = ((h_input + 2 * padding - (window - 1) - 1) / stride) + 1; + int64_t w_out = ((w_input + 2 * padding - (window - 1) - 1) / stride) + 1; ShapeVector shape_out = {input_shape->shape()[0], input_shape->shape()[1], h_out, w_out}; AbstractBasePtr ret = input_tensor->Broaden(); ret->set_shape(std::make_shared(shape_out)); @@ -329,10 +329,10 @@ AbstractBasePtr InferImplLayerNorm(const AnalysisEnginePtr &, const PrimitivePtr // begin_norm_axis and begin_params_axis should be smaller than the size of input_x and >= -1 ValuePtr bna_ptr = primitive->GetAttr("begin_norm_axis"); - int begin_norm_axis = CheckAxis(op_name, bna_ptr, -1, SizeToInt(input_rank) - 1); + int64_t begin_norm_axis = CheckAxis(op_name, bna_ptr, -1, SizeToLong(input_rank) - 1); ValuePtr bpa_ptr = primitive->GetAttr("begin_params_axis"); - int begin_params_axis = CheckAxis(op_name, bpa_ptr, -1, SizeToInt(input_rank) - 1); + int64_t begin_params_axis = CheckAxis(op_name, bpa_ptr, -1, SizeToLong(input_rank) - 1); begin_params_axis = GetPositiveAxis(begin_params_axis, input_rank); // the beta and gama shape should be x_shape[begin_params_axis:] @@ -353,7 +353,7 @@ AbstractBasePtr InferImplLayerNorm(const AnalysisEnginePtr &, const PrimitivePtr MS_LOG(EXCEPTION) << "LayerNorm evaluator gamma or beta is a AbstractScalar that is not support."; } - size_t begin_params_axis_u = IntToSize(begin_params_axis); + size_t begin_params_axis_u = LongToSize(begin_params_axis); if ((begin_params_axis_u > input_shape_list.size()) || (gamma_shape_list.size() + begin_params_axis_u < input_shape_list.size()) || (beta_shape_list.size() + begin_params_axis_u < input_shape_list.size())) { @@ -423,8 +423,6 @@ AbstractBasePtr InferImplDropoutGenMask(const AnalysisEnginePtr &, const Primiti int64_t e_value = 0; if (value_track->isa()) { e_value = GetValue(value_track); - } else if (value_track->isa()) { - e_value = static_cast(GetValue(value_track)); } else { MS_LOG(EXCEPTION) << "DropOutGenMask input x_shape elements is not int64 or int32, but " << value_track->ToString() << "."; diff --git a/mindspore/core/abstract/prim_others.cc b/mindspore/core/abstract/prim_others.cc index 12fd113b571..549c6085a34 100644 --- a/mindspore/core/abstract/prim_others.cc +++ b/mindspore/core/abstract/prim_others.cc @@ -222,8 +222,8 @@ AbstractBasePtr InferImplMakeRowTensor(const AnalysisEnginePtr &, const Primitiv auto shp = dense_shape_value->value(); ShapeVector dense_shape_vec; (void)std::transform(std::begin(shp), std::end(shp), std::back_inserter(dense_shape_vec), - [](const ValuePtr &e) -> int { - auto elem = GetValue(e); + [](const ValuePtr &e) -> int64_t { + auto elem = GetValue(e); return elem; }); if (dense_shape_vec.size() != values_shp.size()) { @@ -316,11 +316,11 @@ AbstractBasePtr InferImplMakeSparseTensor(const AnalysisEnginePtr &, const Primi auto shp = dense_shape_value->value(); ShapeVector dense_shape_vec; (void)std::transform(std::begin(shp), std::end(shp), std::back_inserter(dense_shape_vec), - [](const ValuePtr &e) -> int { - auto elem = GetValue(e); + [](const ValuePtr &e) -> int64_t { + auto elem = GetValue(e); return elem; }); - if (IntToSize(indices_shp[1]) != dense_shape_vec.size()) { + if (LongToSize(indices_shp[1]) != dense_shape_vec.size()) { MS_EXCEPTION(TypeError) << "The size of dense_shape must be equal with the second dimension of indices " << indices_shp[1] << ", but got " << dense_shape_vec.size(); } diff --git a/mindspore/core/abstract/prim_structures.cc b/mindspore/core/abstract/prim_structures.cc index 0388c4ab492..7e6633a73f7 100644 --- a/mindspore/core/abstract/prim_structures.cc +++ b/mindspore/core/abstract/prim_structures.cc @@ -108,9 +108,9 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr MS_EXCEPTION(TypeError) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone."; } if (args_spec_list[index]->isa() && - !dyn_cast(args_spec_list[index])->BuildValue()->isa()) { + !dyn_cast(args_spec_list[index])->BuildValue()->isa()) { MS_EXCEPTION(TypeError) << "MakeSlice eval " << index - << " parameter is an AbstractScalar, but is not an int32 number."; + << " parameter is an AbstractScalar, but is not an int64 number."; } } // Slice: start, end, step @@ -125,50 +125,50 @@ AbstractBasePtr InferTupleOrListGetItem(const std::string &op_name, const Abstra AbstractScalarPtr index = CheckArg(op_name, args_spec_list, 1); ValuePtr index_value = index->BuildValue(); - if (!index_value->isa()) { + if (!index_value->isa()) { // when index_value is an AnyValue and args_spec_list[0] is a scalar, try to return the type of the first element // and continue if (dyn_cast(queue->elements()[0]) != nullptr) { return std::make_shared(queue->elements()[0]->BuildType()); } - MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int32 number, but got " + MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int64 number, but got " << index_value->ToString(); } - int idx_v = GetValue(index_value); + int64_t idx_v = GetValue(index_value); std::size_t nelems = queue->elements().size(); - if (idx_v >= SizeToInt(nelems) || idx_v < -SizeToInt(nelems)) { - MS_EXCEPTION(IndexError) << op_name << " evaluator index should be in range[-" << SizeToInt(nelems) << ", " - << SizeToInt(nelems) << "), but got " << idx_v << "."; + if (idx_v >= SizeToLong(nelems) || idx_v < -SizeToLong(nelems)) { + MS_EXCEPTION(IndexError) << op_name << " evaluator index should be in range[-" << SizeToLong(nelems) << ", " + << SizeToLong(nelems) << "), but got " << idx_v << "."; } std::size_t uidx_v = 0; if (idx_v >= 0) { - uidx_v = IntToSize(idx_v); + uidx_v = LongToSize(idx_v); } else { - uidx_v = IntToSize(idx_v + SizeToInt(nelems)); + uidx_v = LongToSize(idx_v + SizeToLong(nelems)); } return queue->elements()[uidx_v]; } template AbstractBasePtr InferTupleOrListSetItem(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { - // Inputs: a tuple or list, a scalar whose value is an int32 number and an object of a subclass of AbstractBase. + // Inputs: a tuple or list, a scalar whose value is an int64 number and an object of a subclass of AbstractBase. CheckArgsSize(op_name, args_spec_list, 3); auto queue = CheckArg(op_name, args_spec_list, 0); AbstractScalarPtr index = CheckArg(op_name, args_spec_list, 1); ValuePtr index_value = index->BuildValue(); - if (!index_value->isa()) { - MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int32 number, but got " + if (!index_value->isa()) { + MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int64 number, but got " << index_value->ToString(); } - int idx_v = GetValue(index_value); + int64_t idx_v = GetValue(index_value); if (idx_v < 0) { MS_EXCEPTION(IndexError) << "The index of " << typeid(T).name() << " should be positive number, but got " << idx_v << "."; } - size_t uidx_v = IntToSize(idx_v); + size_t uidx_v = LongToSize(idx_v); AbstractBasePtrList elements = queue->elements(); std::size_t nelems = elements.size(); if (uidx_v >= nelems) { @@ -241,8 +241,8 @@ AbstractBasePtr InferImplDictSetItem(const AnalysisEnginePtr &, const PrimitiveP MS_EXCEPTION_IF_NULL(args_spec_list[2]); auto new_ele = std::make_pair(key_str, args_spec_list[2]); if (it != dict_elems.end()) { - int index = it - dict_elems.begin(); - dict_elems[IntToSize(index)] = new_ele; + int64_t index = it - dict_elems.begin(); + dict_elems[LongToSize(index)] = new_ele; } else { dict_elems.push_back(new_ele); } diff --git a/mindspore/core/abstract/utils.cc b/mindspore/core/abstract/utils.cc index 2262ed1aded..b250a0b2d31 100644 --- a/mindspore/core/abstract/utils.cc +++ b/mindspore/core/abstract/utils.cc @@ -23,7 +23,6 @@ #include #include "utils/symbolic.h" #include "abstract/param_validator.h" -#include "utils/shape_utils.h" namespace mindspore { namespace abstract { @@ -200,9 +199,9 @@ TypePtr CheckTypeList(const TypePtr &predicate, const TypePtrList &args_type_lis return TypeJoin(args_type_list); } -int GetPositiveAxis(int axis_value, size_t increment) { +int64_t GetPositiveAxis(int64_t axis_value, size_t increment) { if (axis_value < 0) { - axis_value = axis_value + SizeToInt(increment); + axis_value = axis_value + SizeToLong(increment); } if (axis_value < 0) { @@ -224,9 +223,9 @@ ShapeVector RealBroadcast(const std::string &op, ShapeVector x_shape, ShapeVecto ShapeVector broadcast_shape; for (size_t i = 0; i < std_len; i++) { - int x_i = x_shape[i]; // i-th dimension of x - int y_i = y_shape[i]; // i-th dimension of y - int output_i = 0; // i-th dimension of the output + int64_t x_i = x_shape[i]; // i-th dimension of x + int64_t y_i = y_shape[i]; // i-th dimension of y + int64_t output_i = 0; // i-th dimension of the output if (x_i == y_i) { output_i = x_i; } else if (x_i == 1) { diff --git a/mindspore/core/abstract/utils.h b/mindspore/core/abstract/utils.h index 413ff799401..3287e15184a 100644 --- a/mindspore/core/abstract/utils.h +++ b/mindspore/core/abstract/utils.h @@ -26,6 +26,7 @@ #include "abstract/abstract_value.h" #include "utils/any.h" #include "utils/misc.h" +#include "utils/shape_utils.h" namespace mindspore { namespace abstract { @@ -46,9 +47,9 @@ TypePtr CheckTypeList(const TypePtr &predicate, const TypePtrList &args_type_lis bool CheckType(const TypePtr &expected_type, const TypePtr &x); -int GetPositiveAxis(int axis_value, size_t increment); +int64_t GetPositiveAxis(int64_t axis_value, size_t increment); -std::vector BroadcastShape(std::vector shpx, std::vector shpy); +ShapeVector BroadcastShape(ShapeVector shpx, ShapeVector shpy); // Get broadcasted shape for binary element-wise operation ShapePtr GetBroadcastShape(const std::string &op, const AbstractTensorPtr &tensor_x, const AbstractTensorPtr &tensor_y); diff --git a/mindspore/core/base/base_ref.h b/mindspore/core/base/base_ref.h index 05157a40209..54781e56b2b 100644 --- a/mindspore/core/base/base_ref.h +++ b/mindspore/core/base/base_ref.h @@ -65,13 +65,13 @@ inline std::shared_ptr MakeNode(std::initializer_list elemen // Anfnode, Funcgraph and some not value node class template >::value && is_base::value, - int>::type = 0> + int64_t>::type = static_cast(0)> inline BasePtr MakeNode(const T &v) { return v; } -template >::value && !is_base_ref::value, int>::type = 0> +template >::value && !is_base_ref::value, + int64_t>::type = static_cast(0)> inline BasePtr MakeNode(const T &v) { return MakeValue(v); } @@ -145,7 +145,8 @@ struct BaseRefLess { namespace utils { // judge isa relation // examples: isa(handle), isa(handle) -template ::value && !is_base_ref::value, int>::type = 0> +template ::value && !is_base_ref::value, int64_t>::type = static_cast(0)> bool isa(const BaseRef &handle) { if (!handle.m_ptr) { return false; @@ -155,7 +156,7 @@ bool isa(const BaseRef &handle) { // noderef isa ptr isa(x) or isa() template ::value, typename T::element_type>::type, - typename std::enable_if::value || is_base_ref::value, int>::type = 0> + typename std::enable_if::value || is_base_ref::value, int64_t>::type = static_cast(0)> bool isa(const BaseRef &handle) { if (handle.m_ptr == nullptr) { return typeid(handle.m_ptr) == typeid(T); @@ -179,15 +180,16 @@ bool isa(const BaseRef &handle) { } // isa(handle), judge reference or ptr -template ::value, int>::type = 0> +template ::value, int64_t>::type = static_cast(0)> bool isa(const BaseRef &handle) { static const uint32_t tid = Base::GetTypeId(typeid(T).name()); return handle.IsFromTypeId(tid) || (handle.m_ptr && handle.m_ptr->isa()); } // valueref -> C++ type -// cast(handle) -template ::value && !is_shared_ptr::value, int>::type = 0> +// cast(handle) +template ::value && !is_shared_ptr::value, int64_t>::type = + static_cast(0)> T cast(const BaseRef &handle) { T ret = GetValue(std::static_pointer_cast(handle.m_ptr)); return std::move(ret); @@ -195,7 +197,7 @@ T cast(const BaseRef &handle) { // valueref -> valueref type // cast(handle) -template ::value, int>::type = 0> +template ::value, int64_t>::type = static_cast(0)> const T &cast(const BaseRef &handle) { if (handle.m_ptr) { return static_cast(*handle.m_ptr); @@ -208,7 +210,7 @@ const T &cast(const BaseRef &handle) { // cast(handle) template ::value, typename T::element_type>::type, typename std::enable_if::value && std::is_base_of::value, - int>::type = 0> + int64_t>::type = static_cast(0)> T cast(const BaseRef &handle) { if (!handle.m_ptr) { MS_LOG(EXCEPTION) << "Can not cast to " << typeid(T).name() << ", pointer is null"; diff --git a/mindspore/core/c_ops/avg_pool.cc b/mindspore/core/c_ops/avg_pool.cc index 414776b2e68..d29df4198c0 100644 --- a/mindspore/core/c_ops/avg_pool.cc +++ b/mindspore/core/c_ops/avg_pool.cc @@ -30,20 +30,23 @@ std::string AvgPool::get_padding() const { auto value_ptr = GetAttr("padding"); return GetValue(value_ptr); } -void AvgPool::set_kernel_size(const std::vector &kernel_size) { this->AddAttr("k_size", MakeValue(kernel_size)); } +void AvgPool::set_kernel_size(const std::vector &kernel_size) { + this->AddAttr("k_size", MakeValue(kernel_size)); +} -std::vector AvgPool::get_kernel_size() const { +std::vector AvgPool::get_kernel_size() const { auto value_ptr = GetAttr("k_size"); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -void AvgPool::set_strides(const std::vector &strides) { this->AddAttr("strides", MakeValue(strides)); } +void AvgPool::set_strides(const std::vector &strides) { this->AddAttr("strides", MakeValue(strides)); } -std::vector AvgPool::get_strides() const { +std::vector AvgPool::get_strides() const { auto value_ptr = GetAttr("strides"); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -void AvgPool::Init(const std::vector &kernel_size, const std::vector &stride, const std::string &padding) { +void AvgPool::Init(const std::vector &kernel_size, const std::vector &stride, + const std::string &padding) { auto prim_name = this->name(); this->AddAttr("data_format", MakeValue("NCHW")); this->set_padding(CheckAndConvertUtils::CheckString("padding", padding, {"valid", "same"}, prim_name)); @@ -70,8 +73,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector out_shape = {batch, channel, out_h, out_w}; + std::vector out_shape = {batch, channel, out_h, out_w}; if (std::any_of(out_shape.begin(), out_shape.end(), [](int a) { return a <= 0; })) { MS_LOG(EXCEPTION) << "Kernel size is not valid."; } diff --git a/mindspore/core/c_ops/avg_pool.h b/mindspore/core/c_ops/avg_pool.h index 6ae01b239af..372c2037f4e 100644 --- a/mindspore/core/c_ops/avg_pool.h +++ b/mindspore/core/c_ops/avg_pool.h @@ -32,13 +32,13 @@ class AvgPool : public PrimitiveC { AvgPool() : PrimitiveC(kNameAvgPool) { InitIOName({"x"}, {"output"}); } ~AvgPool() = default; MS_DECLARE_PARENT(AvgPool, PrimitiveC); - void Init(const std::vector &kernel_size = {1}, const std::vector &stride = {1}, + void Init(const std::vector &kernel_size = {1}, const std::vector &stride = {1}, const std::string &padding = "valid"); void set_padding(const std::string &pad); - void set_kernel_size(const std::vector &kernel_size); - void set_strides(const std::vector &strides); - std::vector get_kernel_size() const; - std::vector get_strides() const; + void set_kernel_size(const std::vector &kernel_size); + void set_strides(const std::vector &strides); + std::vector get_kernel_size() const; + std::vector get_strides() const; std::string get_padding() const; }; diff --git a/mindspore/core/c_ops/conv2d.cc b/mindspore/core/c_ops/conv2d.cc index a38285f9292..4ab9992bfc5 100644 --- a/mindspore/core/c_ops/conv2d.cc +++ b/mindspore/core/c_ops/conv2d.cc @@ -40,7 +40,7 @@ abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::ve w_shape[1], conv_prim->name()); auto out_channel = conv_prim->get_output_channel(); CheckAndConvertUtils::Check("out_channel", out_channel, kEqual, "w_shape[0]", w_shape[0], conv_prim->name()); - std::vector temp_w; + std::vector temp_w; std::copy(w_shape.begin() + 2, w_shape.end(), std::back_inserter(temp_w)); CheckAndConvertUtils::Check("kernel_size", conv_prim->get_kernel_size(), kEqual, "w_shape[2:4]", temp_w, conv_prim->name()); @@ -53,9 +53,9 @@ abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::ve auto stride_w = stride[3]; auto dilation_h = dilation[2]; auto dilation_w = dilation[3]; - int h_out = -1; - int w_out = -1; - std::vector pad_list(4, 0); + int64_t h_out = -1; + int64_t w_out = -1; + std::vector pad_list(4, 0); auto pad_mode = conv_prim->get_pad_mode(); if (pad_mode == "valid") { h_out = ceil((x_shape[2] - dilation_h * (kernel_size_h - 1)) / stride_h); @@ -64,10 +64,12 @@ abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::ve h_out = ceil(x_shape[2] / stride_h); w_out = ceil(x_shape[3] / stride_w); - auto pad_needed_h = std::max(0, (h_out - 1) * stride_h + dilation_h * (kernel_size_h - 1) + 1 - x_shape[2]); + auto pad_needed_h = + std::max(static_cast(0), (h_out - 1) * stride_h + dilation_h * (kernel_size_h - 1) + 1 - x_shape[2]); pad_list.emplace_back(floor(pad_needed_h / 2)); pad_list.emplace_back(pad_needed_h / 2); - auto pad_needed_w = std::max(0, (w_out - 1) * stride_w + dilation_w * (kernel_size_w - 1) + 1 - x_shape[3]); + auto pad_needed_w = + std::max(static_cast(0), (w_out - 1) * stride_w + dilation_w * (kernel_size_w - 1) + 1 - x_shape[3]); auto pad_left = floor(pad_needed_w / 2); pad_list.emplace_back(pad_left); pad_list.emplace_back(pad_needed_h - pad_left); @@ -84,7 +86,7 @@ abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::ve w_out = floor(w_out); } conv_prim->set_pad_list(pad_list); - std::vector out_shape = {x_shape[0], out_channel, h_out, w_out}; + std::vector out_shape = {x_shape[0], out_channel, h_out, w_out}; return std::make_shared(out_shape); } @@ -93,7 +95,8 @@ TypePtr Conv2dInferType(const PrimitivePtr &prim, const std::vector valid_types = {kNumberTypeInt8, kNumberTypeInt32, kNumberTypeFloat16, kNumberTypeFloat32}; + const std::set valid_types = {kNumberTypeInt8, kNumberTypeInt32, kNumberTypeInt64, kNumberTypeFloat16, + kNumberTypeFloat32}; std::map types; types.emplace("x", input_args[0]->BuildType()); types.emplace("w", input_args[1]->BuildType()); @@ -106,12 +109,12 @@ TypePtr Conv2dInferType(const PrimitivePtr &prim, const std::vector &kernel_size, int mode, const std::string &pad_mode, - const std::vector &pad, const std::vector &stride, const std::vector &dilation, - int group) { +void Conv2D::Init(int64_t out_channel, const std::vector &kernel_size, int64_t mode, + const std::string &pad_mode, const std::vector &pad, const std::vector &stride, + const std::vector &dilation, int64_t group) { auto prim_name = this->name(); this->AddAttr("data_format", MakeValue("NCHW")); - this->AddAttr("offset_a", MakeValue(0)); + this->AddAttr("offset_a", MakeValue(static_cast(0))); this->set_kernel_size(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, prim_name)); this->set_stride(CheckAndConvertUtils::CheckPositiveVector(kStride, stride, this->name(), true, true)); this->set_dilation(CheckAndConvertUtils::CheckPositiveVector(kDilation, dilation, this->name(), true, true)); @@ -130,55 +133,59 @@ void Conv2D::Init(int out_channel, const std::vector &kernel_size, int mode this->set_group(CheckAndConvertUtils::CheckInteger("group", group, kGreaterThan, 0, prim_name)); } -std::vector Conv2D::get_kernel_size() const { +std::vector Conv2D::get_kernel_size() const { auto value_ptr = GetAttr(kKernelSize); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -std::vector Conv2D::get_stride() const { + +std::vector Conv2D::get_stride() const { auto value_ptr = GetAttr(kStride); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -std::vector Conv2D::get_dilation() const { + +std::vector Conv2D::get_dilation() const { auto value_ptr = GetAttr(kDilation); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } + std::string Conv2D::get_pad_mode() const { auto value_ptr = this->GetAttr(kPadMode); return GetValue(value_ptr); } -std::vector Conv2D::get_pad() const { + +std::vector Conv2D::get_pad() const { auto value_ptr = this->GetAttr(kPad); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -std::vector Conv2D::get_pad_list() const { +std::vector Conv2D::get_pad_list() const { auto value_ptr = this->GetAttr(kPadList); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -int Conv2D::get_mode() const { +int64_t Conv2D::get_mode() const { auto value_ptr = this->GetAttr(kMode); - return GetValue(value_ptr); + return GetValue(value_ptr); } -int Conv2D::get_group() const { +int64_t Conv2D::get_group() const { auto value_ptr = this->GetAttr(kGroup); - return GetValue(value_ptr); + return GetValue(value_ptr); } -int Conv2D::get_output_channel() const { +int64_t Conv2D::get_output_channel() const { auto value_ptr = this->GetAttr(kOutputChannel); - return GetValue(value_ptr); + return GetValue(value_ptr); } -void Conv2D::set_kernel_size(const std::vector &kernel_size) { +void Conv2D::set_kernel_size(const std::vector &kernel_size) { this->AddAttr(kKernelSize, MakeValue(kernel_size)); } -void Conv2D::set_stride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } -void Conv2D::set_dilation(const std::vector &dilation) { this->AddAttr(kDilation, MakeValue(dilation)); } +void Conv2D::set_stride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } +void Conv2D::set_dilation(const std::vector &dilation) { this->AddAttr(kDilation, MakeValue(dilation)); } void Conv2D::set_pad_mode(const std::string &pad_mode) { this->AddAttr(kPadMode, MakeValue(pad_mode)); } -void Conv2D::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } -void Conv2D::set_mode(int mode) { this->AddAttr(kMode, MakeValue(mode)); } -void Conv2D::set_group(int group) { this->AddAttr(kGroup, MakeValue(group)); } -void Conv2D::set_out_channel(int output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } -void Conv2D::set_pad_list(const std::vector &pad_list) { this->AddAttr(kPadList, MakeValue(pad_list)); } +void Conv2D::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } +void Conv2D::set_mode(int64_t mode) { this->AddAttr(kMode, MakeValue(mode)); } +void Conv2D::set_group(int64_t group) { this->AddAttr(kGroup, MakeValue(group)); } +void Conv2D::set_out_channel(int64_t output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } +void Conv2D::set_pad_list(const std::vector &pad_list) { this->AddAttr(kPadList, MakeValue(pad_list)); } AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { diff --git a/mindspore/core/c_ops/conv2d.h b/mindspore/core/c_ops/conv2d.h index e899697e64a..62c2b75f93a 100644 --- a/mindspore/core/c_ops/conv2d.h +++ b/mindspore/core/c_ops/conv2d.h @@ -32,27 +32,28 @@ class Conv2D : public PrimitiveC { Conv2D(); ~Conv2D() = default; MS_DECLARE_PARENT(Conv2D, PrimitiveC); - void Init(int out_channel, const std::vector &kernel_size, int mode = 1, const std::string &pad_mode = "valid", - const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1, 1, 1}, - const std::vector &dilation = {1, 1, 1, 1}, int group = 1); - std::vector get_kernel_size() const; - std::vector get_stride() const; - std::vector get_dilation() const; + void Init(int64_t out_channel, const std::vector &kernel_size, int64_t mode = 1, + const std::string &pad_mode = "valid", const std::vector &pad = {0, 0, 0, 0}, + const std::vector &stride = {1, 1, 1, 1}, const std::vector &dilation = {1, 1, 1, 1}, + int64_t group = 1); + std::vector get_kernel_size() const; + std::vector get_stride() const; + std::vector get_dilation() const; std::string get_pad_mode() const; - std::vector get_pad() const; - std::vector get_pad_list() const; - int get_mode() const; - int get_group() const; - int get_output_channel() const; - void set_kernel_size(const std::vector &kernel_size); - void set_stride(const std::vector &stride); - void set_dilation(const std::vector &dilation); + std::vector get_pad() const; + std::vector get_pad_list() const; + int64_t get_mode() const; + int64_t get_group() const; + int64_t get_output_channel() const; + void set_kernel_size(const std::vector &kernel_size); + void set_stride(const std::vector &stride); + void set_dilation(const std::vector &dilation); void set_pad_mode(const std::string &pad_mode); - void set_pad(const std::vector &pad); - void set_mode(int mode); - void set_group(int group); - void set_out_channel(int output_channel); - void set_pad_list(const std::vector &pad_list); + void set_pad(const std::vector &pad); + void set_mode(int64_t mode); + void set_group(int64_t group); + void set_out_channel(int64_t output_channel); + void set_pad_list(const std::vector &pad_list); }; AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args); diff --git a/mindspore/core/c_ops/depthwise_conv2d.cc b/mindspore/core/c_ops/depthwise_conv2d.cc index 4e1e057240e..c88749c0424 100644 --- a/mindspore/core/c_ops/depthwise_conv2d.cc +++ b/mindspore/core/c_ops/depthwise_conv2d.cc @@ -24,9 +24,9 @@ #include "abstract/primitive_infer_map.h" namespace mindspore { -void DepthWiseConv2D::Init(int channel_multiplier, const std::vector &kernel_size, int mode, - const std::string &pad_mode, const std::vector &pad, const std::vector &stride, - const std::vector &dilation, int group) { +void DepthWiseConv2D::Init(int channel_multiplier, const std::vector &kernel_size, int mode, + const std::string &pad_mode, const std::vector &pad, + const std::vector &stride, const std::vector &dilation, int group) { auto prim_name = this->name(); this->AddAttr("data_format", MakeValue("NCHW")); this->AddAttr("offset_a", MakeValue(0)); @@ -62,30 +62,30 @@ void DepthWiseConv2D::Init(int channel_multiplier, const std::vector &kerne this->set_group(CheckAndConvertUtils::CheckInteger("group", group, kGreaterThan, 0, prim_name)); } -std::vector DepthWiseConv2D::get_kernel_size() const { +std::vector DepthWiseConv2D::get_kernel_size() const { auto value_ptr = GetAttr(kKernelSize); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -std::vector DepthWiseConv2D::get_stride() const { +std::vector DepthWiseConv2D::get_stride() const { auto value_ptr = GetAttr(kStride); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -std::vector DepthWiseConv2D::get_dilation() const { +std::vector DepthWiseConv2D::get_dilation() const { auto value_ptr = GetAttr(kDilation); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } std::string DepthWiseConv2D::get_pad_mode() const { auto value_ptr = this->GetAttr(kPadMode); return GetValue(value_ptr); } -std::vector DepthWiseConv2D::get_pad() const { +std::vector DepthWiseConv2D::get_pad() const { auto value_ptr = this->GetAttr(kPad); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -std::vector DepthWiseConv2D::get_pads() const { +std::vector DepthWiseConv2D::get_pads() const { auto value_ptr = this->GetAttr(kPads); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } int DepthWiseConv2D::get_mode() const { @@ -102,18 +102,20 @@ int DepthWiseConv2D::get_output_channel() const { return GetValue(value_ptr); } -void DepthWiseConv2D::set_kernel_size(const std::vector &kernel_size) { +void DepthWiseConv2D::set_kernel_size(const std::vector &kernel_size) { this->AddAttr(kKernelSize, MakeValue(kernel_size)); } -void DepthWiseConv2D::set_stride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } -void DepthWiseConv2D::set_dilation(const std::vector &dilation) { this->AddAttr(kDilation, MakeValue(dilation)); } +void DepthWiseConv2D::set_stride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } +void DepthWiseConv2D::set_dilation(const std::vector &dilation) { + this->AddAttr(kDilation, MakeValue(dilation)); +} void DepthWiseConv2D::set_pad_mode(const std::string &pad_mode) { this->AddAttr(kPadMode, MakeValue(pad_mode)); } -void DepthWiseConv2D::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } +void DepthWiseConv2D::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } void DepthWiseConv2D::set_mode(int mode) { this->AddAttr(kMode, MakeValue(mode)); } void DepthWiseConv2D::set_group(int group) { this->AddAttr(kGroup, MakeValue(group)); } void DepthWiseConv2D::set_out_channel(int output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } -void DepthWiseConv2D::set_pads(const std::vector &pad_list) { this->AddAttr(kPads, MakeValue(pad_list)); } +void DepthWiseConv2D::set_pads(const std::vector &pad_list) { this->AddAttr(kPads, MakeValue(pad_list)); } abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); @@ -129,7 +131,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorname()); auto out_channel = conv_prim->get_output_channel(); - std::vector temp_w; + std::vector temp_w; std::copy(w_shape.begin() + 2, w_shape.end(), std::back_inserter(temp_w)); CheckAndConvertUtils::Check("kernel_size", conv_prim->get_kernel_size(), kEqual, "w_shape[2:4]", temp_w, conv_prim->name()); @@ -148,7 +150,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector pad_list(4, 0); + std::vector pad_list(4, 0); auto pad_mode = conv_prim->get_pad_mode(); if (pad_mode == "valid") { h_out = ceil((x_shape[2] - dilation_h * (kernel_size_h - 1)) / stride_h); @@ -157,10 +159,12 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(0), (h_out - 1) * stride_h + dilation_h * (kernel_size_h - 1) + 1 - x_shape[2]); pad_list.emplace_back(floor(pad_needed_h / 2)); pad_list.emplace_back(pad_needed_h / 2); - auto pad_needed_w = std::max(0, (w_out - 1) * stride_w + dilation_w * (kernel_size_w - 1) + 1 - x_shape[3]); + auto pad_needed_w = + std::max(static_cast(0), (w_out - 1) * stride_w + dilation_w * (kernel_size_w - 1) + 1 - x_shape[3]); auto pad_left = floor(pad_needed_w / 2); pad_list.emplace_back(pad_left); pad_list.emplace_back(pad_needed_h - pad_left); @@ -177,7 +181,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorset_pads(pad_list); - std::vector out_shape = {x_shape[0], out_channel * x_shape[1], h_out, w_out}; + std::vector out_shape = {x_shape[0], out_channel * x_shape[1], h_out, w_out}; return std::make_shared(out_shape); } diff --git a/mindspore/core/c_ops/depthwise_conv2d.h b/mindspore/core/c_ops/depthwise_conv2d.h index 9c19e819996..42e165c360a 100644 --- a/mindspore/core/c_ops/depthwise_conv2d.h +++ b/mindspore/core/c_ops/depthwise_conv2d.h @@ -31,27 +31,28 @@ class DepthWiseConv2D : public PrimitiveC { DepthWiseConv2D() : PrimitiveC(kNameDepthWiseConv2D) { InitIOName({"x", "w"}, {"output"}); } ~DepthWiseConv2D() = default; MS_DECLARE_PARENT(DepthWiseConv2D, PrimitiveC); - void Init(int out_channel, const std::vector &kernel_size, int mode = 1, const std::string &pad_mode = "valid", - const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1, 1, 1}, - const std::vector &dilation = {1, 1, 1, 1}, int group = 1); - std::vector get_kernel_size() const; - std::vector get_stride() const; - std::vector get_dilation() const; + void Init(int out_channel, const std::vector &kernel_size, int mode = 1, + const std::string &pad_mode = "valid", const std::vector &pad = {0, 0, 0, 0}, + const std::vector &stride = {1, 1, 1, 1}, const std::vector &dilation = {1, 1, 1, 1}, + int group = 1); + std::vector get_kernel_size() const; + std::vector get_stride() const; + std::vector get_dilation() const; std::string get_pad_mode() const; - std::vector get_pad() const; - std::vector get_pads() const; + std::vector get_pad() const; + std::vector get_pads() const; int get_mode() const; int get_group() const; int get_output_channel() const; - void set_kernel_size(const std::vector &kernel_size); - void set_stride(const std::vector &stride); - void set_dilation(const std::vector &dilation); + void set_kernel_size(const std::vector &kernel_size); + void set_stride(const std::vector &stride); + void set_dilation(const std::vector &dilation); void set_pad_mode(const std::string &pad_mode); - void set_pad(const std::vector &pad); + void set_pad(const std::vector &pad); void set_mode(int mode); void set_group(int group); void set_out_channel(int output_channel); - void set_pads(const std::vector &pad_list); + void set_pads(const std::vector &pad_list); }; AbstractBasePtr DepthWiseConv2DInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args); diff --git a/mindspore/core/c_ops/op_utils.cc b/mindspore/core/c_ops/op_utils.cc index e8d40048c54..d0466c00a64 100644 --- a/mindspore/core/c_ops/op_utils.cc +++ b/mindspore/core/c_ops/op_utils.cc @@ -35,7 +35,7 @@ abstract::ShapePtr BroadCastInferShape(const std::string &op_name, const std::ve auto x_length = x_shape.size(); auto y_length = y_shape.size(); auto length = x_length < y_length ? x_length : y_length; - std::vector broadcast_shape; + std::vector broadcast_shape; if (x_length == length) { std::copy(y_shape.begin(), y_shape.end() - length, std::back_inserter(broadcast_shape)); } else { diff --git a/mindspore/core/c_ops/squeeze.cc b/mindspore/core/c_ops/squeeze.cc index 117352baa4a..bc8808c8c0e 100644 --- a/mindspore/core/c_ops/squeeze.cc +++ b/mindspore/core/c_ops/squeeze.cc @@ -36,7 +36,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorname(); auto axis = squeeze_prim->get_axis(); - std::vector infer_shape; + std::vector infer_shape; auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShape("input_shape", input_args[0]->GetShapeTrack(), op_name); auto len = in_shape.size(); diff --git a/mindspore/core/ir/pattern_matcher.h b/mindspore/core/ir/pattern_matcher.h index c5d3e2ee428..db89fecb98f 100644 --- a/mindspore/core/ir/pattern_matcher.h +++ b/mindspore/core/ir/pattern_matcher.h @@ -464,7 +464,7 @@ class PPrimitive : public PBase > { template class PConstant : public PBase > { public: - explicit PConstant(const AnfNodePtr &as_node, const bool any_value = true, const int check_value = 0, + explicit PConstant(const AnfNodePtr &as_node, const bool any_value = true, const int64_t check_value = 0, const bool is_scalar = false) : as_node_(as_node), captured_node_(as_node), @@ -957,7 +957,7 @@ class PConstant : public PBase > { mutable AnfNodePtr as_node_; mutable AnfNodePtr captured_node_; bool any_value_{true}; - int check_value_{0}; + int64_t check_value_{0}; bool is_scalar_{false}; mutable bool is_new_value_node_{false}; mutable bool captured_{false}; diff --git a/mindspore/core/ir/tensor.h b/mindspore/core/ir/tensor.h index e00878a0830..5d45b280af3 100644 --- a/mindspore/core/ir/tensor.h +++ b/mindspore/core/ir/tensor.h @@ -160,7 +160,7 @@ class Tensor : public MetaTensor { // param data_type [TypeId] data type explicit Tensor(const std::vector &input, const TypePtr &data_type = nullptr); - // brief Create 0 dimension tensor from an int scalar. + // brief Create 0 dimension tensor from an int64_t scalar. // // param input [int64] the data for tensor // param data_type [TypeId] data type diff --git a/mindspore/core/utils/check_convert_utils.cc b/mindspore/core/utils/check_convert_utils.cc index 5b7dd6faf17..a4de577607e 100644 --- a/mindspore/core/utils/check_convert_utils.cc +++ b/mindspore/core/utils/check_convert_utils.cc @@ -48,7 +48,7 @@ const std::map> kCompareRangeT {kIncludeRight, {"in (", "]"}}, {kIncludeBoth, {"in [", "]"}}}; } // namespace -bool CheckAndConvertUtils::IsEqualVector(const std::vector &vec_1, const std::vector &vec_2) { +bool CheckAndConvertUtils::IsEqualVector(const std::vector &vec_1, const std::vector &vec_2) { if (vec_1.size() != vec_2.size()) { return false; } @@ -60,10 +60,10 @@ bool CheckAndConvertUtils::IsEqualVector(const std::vector &vec_1, const st return true; } -std::vector CheckAndConvertUtils::CheckPositiveVector(const std::string &arg_name, - const std::vector &arg_value, - const std::string &prim_name, bool allow_four, - bool ret_four) { +std::vector CheckAndConvertUtils::CheckPositiveVector(const std::string &arg_name, + const std::vector &arg_value, + const std::string &prim_name, bool allow_four, + bool ret_four) { auto raise_message = [allow_four, prim_name, arg_value, arg_name]() -> void { std::ostringstream buffer; buffer << "For " << prim_name << " attr " << arg_name << " should be a positive vector of size two "; @@ -83,12 +83,13 @@ std::vector CheckAndConvertUtils::CheckPositiveVector(const std::string &ar } } if (arg_value.size() == 1) { - return ret_four ? std::vector{1, 1, arg_value[0], arg_value[0]} : std::vector{arg_value[0], arg_value[0]}; + return ret_four ? std::vector{1, 1, arg_value[0], arg_value[0]} + : std::vector{arg_value[0], arg_value[0]}; } if (arg_value.size() == 2) { - return ret_four ? std::vector{1, 1, arg_value[0], arg_value[1]} : arg_value; + return ret_four ? std::vector{1, 1, arg_value[0], arg_value[1]} : arg_value; } else if (arg_value.size() == 4 && allow_four) { - return ret_four ? arg_value : std::vector{arg_value[2], arg_value[3]}; + return ret_four ? arg_value : std::vector{arg_value[2], arg_value[3]}; } raise_message(); return arg_value; @@ -167,8 +168,9 @@ void CheckAndConvertUtils::CheckInRange(const std::string &arg_name, int arg_val MS_EXCEPTION(ValueError) << buffer.str(); } -std::vector CheckAndConvertUtils::ConvertShapePtrToShape(const std::string &arg_name, const BaseShapePtr &shape, - const std::string &prim_name) { +std::vector CheckAndConvertUtils::ConvertShapePtrToShape(const std::string &arg_name, + const BaseShapePtr &shape, + const std::string &prim_name) { MS_EXCEPTION_IF_NULL(shape); if (!shape->isa()) { MS_EXCEPTION(ValueError) << "The " << arg_name << "'s shape is " << shape->ToString() @@ -202,9 +204,9 @@ void CheckAndConvertUtils::Check(const string &arg_name, int arg_value, CompareE MS_EXCEPTION(exception_type) << buffer.str() << arg_name << " should be " << iter_to_string->second << value << " but got " << arg_value; } -void CheckAndConvertUtils::Check(const string &arg_name, const std::vector &arg_value, CompareEnum compare_type, - const string &value_name, const std::vector &value, const string &prim_name, - ExceptionType exception_type) { +void CheckAndConvertUtils::Check(const string &arg_name, const std::vector &arg_value, + CompareEnum compare_type, const string &value_name, const std::vector &value, + const string &prim_name, ExceptionType exception_type) { if (compare_type != kEqual) { auto iter = kCompareToString.find(compare_type); if (iter != kCompareToString.end()) { diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index 1085c4f1358..b1ab73f8c69 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -44,27 +44,27 @@ enum CompareRange { class CheckAndConvertUtils { public: - static std::vector CheckPositiveVector(const std::string &arg_name, const std::vector &arg_value, - const std::string &prim_name, bool allow_four = false, - bool ret_four = false); + static std::vector CheckPositiveVector(const std::string &arg_name, const std::vector &arg_value, + const std::string &prim_name, bool allow_four = false, + bool ret_four = false); static std::string CheckString(const std::string &arg_name, const std::string &arg_value, const std::set &check_list, const std::string &prim_name); static int CheckInteger(const std::string &arg_name, int arg_value, CompareEnum compare_operator, int match_value, const std::string &prim_name); static void CheckInRange(const std::string &arg_name, int arg_value, CompareRange compare_operator, const std::pair &range, const std::string &prim_name); - static std::vector ConvertShapePtrToShape(const std::string &arg_name, const BaseShapePtr &shape, - const std::string &prim_name); + static std::vector ConvertShapePtrToShape(const std::string &arg_name, const BaseShapePtr &shape, + const std::string &prim_name); static void Check(const std::string &arg_name, int arg_value, CompareEnum compare_type, const std::string &value_name, int value, const std::string &prim_name = "", ExceptionType exception_type = ValueError); - static void Check(const std::string &arg_name, const std::vector &arg_value, CompareEnum compare_type, - const std::string &value_name, const std::vector &value, const std::string &prim_name = "", + static void Check(const std::string &arg_name, const std::vector &arg_value, CompareEnum compare_type, + const std::string &value_name, const std::vector &value, const std::string &prim_name = "", ExceptionType exception_type = ValueError); static TypeId CheckTensorTypeSame(const std::map &types, const std::set &check_list, const std::string &prim_name); private: - static bool IsEqualVector(const std::vector &vec_1, const std::vector &vec_2); + static bool IsEqualVector(const std::vector &vec_1, const std::vector &vec_2); }; } // namespace mindspore #endif // MINDSPORE_CORE_UTILS_CHECK_CONVERT_UTILS_H_ diff --git a/mindspore/core/utils/convert_utils_base.h b/mindspore/core/utils/convert_utils_base.h index 6aa70346fe5..d63d381d4fc 100644 --- a/mindspore/core/utils/convert_utils_base.h +++ b/mindspore/core/utils/convert_utils_base.h @@ -44,6 +44,8 @@ inline int64_t SizeToLong(size_t u) { return static_cast(u); } +inline uint64_t SizeToUlong(size_t u) { return static_cast(u); } + inline size_t IntToSize(int u) { if (u < 0) { MS_LOG(WARNING) << "The int value(" << u << ") is less than 0."; @@ -71,6 +73,10 @@ inline size_t FloatToSize(float u) { } inline float IntToFloat(int32_t v) { return static_cast(v); } +inline double LongToDouble(int64_t v) { return static_cast(v); } + +inline double FloatToDouble(float v) { return static_cast(v); } + inline uint32_t IntToUint(int32_t u) { if (u < 0) { MS_LOG(EXCEPTION) << "The int32_t value(" << u << ") is less than 0."; @@ -85,8 +91,22 @@ inline int32_t UintToInt(uint32_t u) { return static_cast(u); } -inline unsigned int UlongToUint(size_t u) { - if (u > static_cast((std::numeric_limits::max)())) { +inline uint64_t LongToUlong(int64_t u) { + if (u < 0) { + MS_LOG(EXCEPTION) << "The int64_t value(" << u << ") is less than 0."; + } + return static_cast(u); +} + +inline int64_t UlongToLong(uint64_t u) { + if (u > static_cast((std::numeric_limits::max)())) { + MS_LOG(EXCEPTION) << "The uint64_t value(" << u << ") exceeds the maximum value of int64_t."; + } + return static_cast(u); +} + +inline unsigned int UlongToUint(uint64_t u) { + if (u > static_cast((std::numeric_limits::max)())) { MS_LOG(EXCEPTION) << "The size_t value(" << u << ") exceeds the maximum value of unsigned int."; } return static_cast(u); diff --git a/mindspore/core/utils/info.cc b/mindspore/core/utils/info.cc index 06aa1e2de85..6ab3afb0127 100644 --- a/mindspore/core/utils/info.cc +++ b/mindspore/core/utils/info.cc @@ -25,11 +25,11 @@ namespace mindspore { std::string HighLightLine(const std::string &line, int col_begin, int col_end, SourceLineTip tip) { std::string temp_line = line; - if (col_begin < col_end && col_begin != -1 && col_end <= SizeToInt(temp_line.length()) && + if (col_begin < col_end && col_begin != -1 && col_end <= SizeToLong(temp_line.length()) && tip != kSourceLineTipDiscard) { - std::string start = temp_line.substr(0, IntToSize(col_begin)); - std::string trimmed = temp_line.substr(IntToSize(col_begin), IntToSize(col_end - col_begin)); - std::string end = temp_line.substr(IntToSize(col_end), IntToSize(SizeToInt(temp_line.length()) - col_end)); + std::string start = temp_line.substr(0, LongToSize(col_begin)); + std::string trimmed = temp_line.substr(LongToSize(col_begin), LongToSize(col_end - col_begin)); + std::string end = temp_line.substr(LongToSize(col_end), LongToSize(SizeToLong(temp_line.length()) - col_end)); std::stringstream oss; std::stringstream tip_ss; std::string start_spaces(start.length(), ' '); diff --git a/mindspore/core/utils/shape_utils.h b/mindspore/core/utils/shape_utils.h index a2e43a9930f..2b34dad90b4 100644 --- a/mindspore/core/utils/shape_utils.h +++ b/mindspore/core/utils/shape_utils.h @@ -18,6 +18,6 @@ #define MINDSPORE_SHAPE_UTILS_INFO_H_ #include -using ShapeVector = std::vector; +using ShapeVector = std::vector; #endif // MINDSPORE_SHAPE_UTILS_INFO_H_ diff --git a/mindspore/core/utils/tensor_construct_utils.cc b/mindspore/core/utils/tensor_construct_utils.cc index 66764bb4638..6382ec0fe16 100644 --- a/mindspore/core/utils/tensor_construct_utils.cc +++ b/mindspore/core/utils/tensor_construct_utils.cc @@ -29,7 +29,7 @@ void SetTensorData(void *data, float num, size_t data_length) { } } } // namespace -tensor::TensorPtr TensorConstructUtils::CreateZerosTensor(TypeId type, const std::vector &shape) { +tensor::TensorPtr TensorConstructUtils::CreateZerosTensor(TypeId type, const std::vector &shape) { tensor::TensorPtr tensor = std::make_shared(type, shape); size_t mem_size = GetTypeByte(tensor->type()) * IntToSize(tensor->ElementsNum()); @@ -41,7 +41,7 @@ tensor::TensorPtr TensorConstructUtils::CreateZerosTensor(TypeId type, const std return tensor; } -tensor::TensorPtr TensorConstructUtils::CreateOnesTensor(TypeId type, const std::vector &shape) { +tensor::TensorPtr TensorConstructUtils::CreateOnesTensor(TypeId type, const std::vector &shape) { tensor::TensorPtr tensor = std::make_shared(type, shape); auto mem_size = IntToSize(tensor->ElementsNum()); if (tensor->data_type() == kNumberTypeFloat32) { @@ -52,7 +52,7 @@ tensor::TensorPtr TensorConstructUtils::CreateOnesTensor(TypeId type, const std: return tensor; } -tensor::TensorPtr TensorConstructUtils::CreateTensor(TypeId type, const std::vector &shape, void *data) { +tensor::TensorPtr TensorConstructUtils::CreateTensor(TypeId type, const std::vector &shape, void *data) { tensor::TensorPtr tensor = std::make_shared(type, shape, data, type); return tensor; } diff --git a/mindspore/core/utils/tensor_construct_utils.h b/mindspore/core/utils/tensor_construct_utils.h index b4e48a2ff94..4094c67ace3 100644 --- a/mindspore/core/utils/tensor_construct_utils.h +++ b/mindspore/core/utils/tensor_construct_utils.h @@ -20,9 +20,9 @@ namespace mindspore { class TensorConstructUtils { public: - static tensor::TensorPtr CreateZerosTensor(TypeId type, const std::vector &shape); - static tensor::TensorPtr CreateOnesTensor(TypeId type, const std::vector &shape); - static tensor::TensorPtr CreateTensor(TypeId type, const std::vector &shape, void *data); + static tensor::TensorPtr CreateZerosTensor(TypeId type, const std::vector &shape); + static tensor::TensorPtr CreateOnesTensor(TypeId type, const std::vector &shape); + static tensor::TensorPtr CreateTensor(TypeId type, const std::vector &shape, void *data); }; } // namespace mindspore #endif // MINDSPORE_CORE_UTILS_TENSOR_CONSTRUCT_UTILS_H_ diff --git a/mindspore/lite/test/ut/src/runtime/kernel/common_utils_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/common_utils_test.cc index 057b4774b62..68e9973dcb3 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/common_utils_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/common_utils_test.cc @@ -34,7 +34,7 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient1) { * 0 * 3 */ - std::vector indices{0, 0, 1, 1, 0, 3}; + std::vector indices{0, 0, 1, 1, 0, 3}; /* 0 1 * 2 3 * 4 5 @@ -46,9 +46,9 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient1) { for (int i = 0; i < 6 * 2; i++) { grad.push_back(i); } - std::vector unique_indices(6); + std::vector unique_indices(6); std::vector summed_grad(12); - std::vector tmp_indices(6); + std::vector tmp_indices(6); std::vector tmp_grad(12); SparseGradient unique_grad({summed_grad.data(), unique_indices.data(), 6}); @@ -64,7 +64,7 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient1) { BucketReduceSparseGradient(param); EXPECT_EQ(unique_grad.indices_size_, 3); - std::vector expect_indices({0, 1, 3}); + std::vector expect_indices({0, 1, 3}); for (size_t i = 0; i < unique_grad.indices_size_; ++i) { EXPECT_EQ(unique_grad.indices_[i], expect_indices[i]); } @@ -72,7 +72,7 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient1) { * 10 12 * 10 11 */ - std::vector expect_value({10, 13, 10, 12, 10, 11}); + std::vector expect_value({10, 13, 10, 12, 10, 11}); for (size_t i = 0; i < unique_grad.indices_size_ * 2; ++i) { EXPECT_EQ(unique_grad.value_[i], expect_value[i]); } @@ -87,7 +87,7 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient2) { * 0 * 6 */ - std::vector indices{0, 0, 1, 1, 0, 6}; + std::vector indices{0, 0, 1, 1, 0, 6}; /* 0 1 * 2 3 * 4 5 @@ -99,9 +99,9 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient2) { for (int i = 0; i < 6 * 2; i++) { grad.push_back(i); } - std::vector unique_indices(6); + std::vector unique_indices(6); std::vector summed_grad(12); - std::vector tmp_indices(6); + std::vector tmp_indices(6); std::vector tmp_grad(12); SparseGradient unique_grad({summed_grad.data(), unique_indices.data(), 6}); SparseGradient workspace_grad({tmp_grad.data(), tmp_indices.data(), 6}); @@ -117,7 +117,7 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient2) { EXPECT_EQ(unique_grad.indices_size_, 2); - std::vector expect_indices({0, 1}); + std::vector expect_indices({0, 1}); for (size_t i = 0; i < unique_grad.indices_size_; ++i) { EXPECT_EQ(unique_grad.indices_[i], expect_indices[i]); } @@ -125,7 +125,7 @@ TEST_F(CommonUtilTest, BucketReduceSparseGradient2) { /* 10 13 * 10 12 */ - std::vector expect_value({10, 13, 10, 12}); + std::vector expect_value({10, 13, 10, 12}); for (size_t i = 0; i < unique_grad.indices_size_ * 2; ++i) { EXPECT_EQ(unique_grad.value_[i], expect_value[i]); } diff --git a/mindspore/lite/tools/anf_exporter/anf_exporter.cc b/mindspore/lite/tools/anf_exporter/anf_exporter.cc index 36ee16d2418..d28eabbc09b 100644 --- a/mindspore/lite/tools/anf_exporter/anf_exporter.cc +++ b/mindspore/lite/tools/anf_exporter/anf_exporter.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "src/ops/quant_dtype_cast.h" #include "abstract/abstract_value.h" @@ -360,7 +361,11 @@ int AnfExporter::ConvertInputParameter(const std::shared_ptr input_anod MS_LOG(ERROR) << "Shape of Abstract of parameter should be ShapePtr, " << paramNode->name(); return RET_PARAM_INVALID; } - paramTensor->dims = utils::cast(abstractTensor->BuildShape())->shape(); + auto shape_vector = utils::cast(abstractTensor->BuildShape())->shape(); + std::vector dims; + (void)std::transform(shape_vector.begin(), shape_vector.end(), std::back_inserter(dims), + [](const int64_t &value) { return static_cast(value); }); + paramTensor->dims = dims; auto paramValue = std::dynamic_pointer_cast(paramNode->default_param()); if (paramValue != nullptr) { paramTensor->data.resize(paramValue->tensor_size()); @@ -385,7 +390,11 @@ int AnfExporter::ConvertInputValueNode(std::shared_ptr input_anode, auto abstractTensor = utils::cast(valueAbstract); auto typePtr = abstractTensor->element()->GetTypeTrack(); paramTensor->dataType = typePtr->type_id(); - paramTensor->dims = utils::cast(abstractTensor->BuildShape())->shape(); + auto shape_vector = utils::cast(abstractTensor->BuildShape())->shape(); + std::vector dims; + (void)std::transform(shape_vector.begin(), shape_vector.end(), std::back_inserter(dims), + [](const int64_t &value) { return static_cast(value); }); + paramTensor->dims = dims; #ifdef SUPPORT_TRAIN if (paramTensor->dims.size() == 0) paramTensor->dims = {1}; #endif diff --git a/mindspore/lite/tools/anf_importer/import_from_meta_graphT.cc b/mindspore/lite/tools/anf_importer/import_from_meta_graphT.cc index c0576c92d5c..913567335cd 100644 --- a/mindspore/lite/tools/anf_importer/import_from_meta_graphT.cc +++ b/mindspore/lite/tools/anf_importer/import_from_meta_graphT.cc @@ -41,7 +41,10 @@ int AnfImporterFromMetaGraphT::ConverterConstTensor() { std::copy(tensor->dims.begin(), tensor->dims.end(), shape.begin()); auto type_id = static_cast(tensor->dataType); auto type_ptr = TypeIdToType(type_id); - auto abstract_tensor = std::make_shared(type_ptr, shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); parameter->set_abstract(abstract_tensor); parameter->set_name("const_" + std::to_string(i) + "_parameter"); @@ -114,7 +117,10 @@ abstract::AbstractTensorPtr AnfImporterFromMetaGraphT::ConvertTensorToAbstractTe std::copy(tensor->dims.begin(), tensor->dims.end(), shape.begin()); auto type_id = static_cast(tensor->dataType); auto type_ptr = TypeIdToType(type_id); - return std::make_shared(type_ptr, shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + return std::make_shared(type_ptr, shape_vector); } int AnfImporterFromMetaGraphT::ConvertAbstract(const std::unique_ptr &src_cnode, diff --git a/mindspore/lite/tools/anf_importer/import_from_protobuf.cc b/mindspore/lite/tools/anf_importer/import_from_protobuf.cc index aefb52b4ad6..8e984859abe 100644 --- a/mindspore/lite/tools/anf_importer/import_from_protobuf.cc +++ b/mindspore/lite/tools/anf_importer/import_from_protobuf.cc @@ -25,6 +25,8 @@ #include #include #include +#include + #include "src/ops/primitive_c.h" #include "frontend/operator/ops.h" #include "include/errorcode.h" @@ -233,7 +235,10 @@ int AnfImporterFromProtobuf::BuildParameterForFuncGraph(const ParameterPtr &node } auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[tensor_typeproto.elem_type()]); - auto abstract_tensor = std::make_shared(type_ptr, shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); node->set_abstract(abstract_tensor); if (default_para_map_.find(value_proto.name()) != default_para_map_.end()) { @@ -359,7 +364,11 @@ bool AnfImporterFromProtobuf::ObtainCNodeAttrInTensorForm(const PrimitivePtr &pr for (int i = 0; i < attr_tensor.dims_size(); ++i) { shape.push_back(attr_tensor.dims(i)); } - tensor::TensorPtr tensor_info = std::make_shared(kDefaultValueSwitchMap[attr_tensor_type], shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + tensor::TensorPtr tensor_info = + std::make_shared(kDefaultValueSwitchMap[attr_tensor_type], shape_vector); auto *tensor_data_buf = reinterpret_cast(tensor_info->data_c()); ret = memcpy_s(tensor_data_buf, tensor_info->Size(), tensor_buf.data(), tensor_buf.size()); prim->set_attr(attr_name, MakeValue(tensor_info)); @@ -442,7 +451,11 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInTensorForm(const std::string &val for (int i = 0; i < attr_tensor.dims_size(); ++i) { shape.push_back(attr_tensor.dims(i)); } - tensor::TensorPtr tensor_info = std::make_shared(kDefaultValueSwitchMap[attr_tensor_type], shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + tensor::TensorPtr tensor_info = + std::make_shared(kDefaultValueSwitchMap[attr_tensor_type], shape_vector); const std::string &tensor_buf = attr_tensor.raw_data(); auto *tensor_data_buf = reinterpret_cast(tensor_info->data_c()); auto ret = memcpy_s(tensor_data_buf, tensor_info->Size(), tensor_buf.data(), tensor_buf.size()); @@ -455,7 +468,7 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInTensorForm(const std::string &val return false; } auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]); - auto abstract_tensor = std::make_shared(type_ptr, shape); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); new_value_node->set_abstract(abstract_tensor); anfnode_build_map_[value_node_name] = new_value_node; return true; @@ -542,13 +555,16 @@ std::unordered_map AnfImporterFromProt const onnx::AttributeProto &attr_proto) { std::unordered_map kv; for (int i = 0; i < attr_proto.tensors_size(); i++) { - std::vector shape_vec; + std::vector shape; const onnx::TensorProto &attr_tensor = attr_proto.tensors(i); for (int j = 0; j < attr_tensor.dims_size(); ++j) { - shape_vec.push_back(attr_tensor.dims(j)); + shape.push_back(attr_tensor.dims(j)); } + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor.data_type()]); - auto abstract_tensor = std::make_shared(type_ptr, shape_vec); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); kv.insert(std::pair(attr_tensor.name(), abstract_tensor)); } return kv; @@ -692,8 +708,11 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph(const FuncGraphPtr &output for (int i = 0; i < output_typeproto.tensor_type().shape().dim_size(); ++i) { output_shape.push_back(output_typeproto.tensor_type().shape().dim(i).dim_value()); } + std::vector shape_vector; + (void)std::transform(output_shape.begin(), output_shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[output_type]); - auto abstract_tensor = std::make_shared(type_ptr, output_shape); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); inputs.clear(); auto primReturn = std::make_unique(); MS_ASSERT(primReturn != nullptr); diff --git a/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc b/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc index 9c045f53388..1b2cf42c7d0 100644 --- a/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc +++ b/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc @@ -1349,7 +1349,10 @@ STATUS PostTrainingQuantizer::BiasCorrection(const FuncGraphPtr &func_graph) { ParamValueLitePtr param_value = std::make_shared(); MS_ASSERT(param_value != nullptr); - param_value->set_tensor_shape(shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int64_t &value) { return static_cast(value); }); + param_value->set_tensor_shape(shape_vector); param_value->set_tensor_type(kNumberTypeFloat32); auto size = sizeof(float) * bias_diff.size(); diff --git a/mindspore/lite/tools/optimizer/common/gllo_utils.cc b/mindspore/lite/tools/optimizer/common/gllo_utils.cc index 9bcedaa5718..c87d6154c69 100644 --- a/mindspore/lite/tools/optimizer/common/gllo_utils.cc +++ b/mindspore/lite/tools/optimizer/common/gllo_utils.cc @@ -348,7 +348,11 @@ ParameterPtr AddNewBiasNode(float *bias_data, const FuncGraphPtr &func_graph, in auto bias_parameter = func_graph->add_parameter(); MS_ASSERT(bias_parameter != nullptr); std::vector shape = {kernel_num}; - auto abstract_tensor = std::make_shared(TypeIdToType(weight_tensor->tensor_type()), shape); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + auto abstract_tensor = + std::make_shared(TypeIdToType(weight_tensor->tensor_type()), shape_vector); bias_parameter->set_abstract(abstract_tensor); ParamValueLitePtr param_value = std::make_shared(); diff --git a/mindspore/lite/tools/optimizer/fusion/batchmatmul_fusion.cc b/mindspore/lite/tools/optimizer/fusion/batchmatmul_fusion.cc index bb622da4140..c5ba9ae1185 100644 --- a/mindspore/lite/tools/optimizer/fusion/batchmatmul_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/batchmatmul_fusion.cc @@ -16,6 +16,7 @@ #include "tools/optimizer/fusion/batchmatmul_fusion.h" #include #include +#include #include "src/ops/primitive_c.h" #include "src/param_value_lite.h" #include "schema/inner/model_generated.h" @@ -91,7 +92,10 @@ STATUS GetRightMatmulInputParamter(const CNodePtr &stack_node, const ParameterPt } rmatmul_input_shape.insert(rmatmul_input_shape.begin(), joint_fullconnect_size); auto type_ptr = TypeIdToType(fc_weight_param->tensor_type()); - auto abstract_tensor = std::make_shared(type_ptr, rmatmul_input_shape); + std::vector shape_vector; + (void)std::transform(rmatmul_input_shape.begin(), rmatmul_input_shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); rmatmul_input->set_abstract(abstract_tensor); rmatmul_input->set_name(stack_node->fullname_with_scope() + "right_parameter"); ParamValueLitePtr param_value = std::make_shared(); diff --git a/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc b/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc index 30068e6f5b4..16235a027ed 100644 --- a/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include "tools/optimizer/common/gllo_utils.h" #include "tools/anf_exporter/anf_exporter.h" #include "src/kernel_registry.h" @@ -77,9 +78,12 @@ std::vector GetCNodeInputTensors(const CNodePtr &CNode) { ParameterPtr CreateNewParamter(const FuncGraphPtr &func_graph, Tensor *tensor) { auto parameter = func_graph->add_parameter(); std::vector shape(tensor->shape()); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); auto type_id = static_cast(tensor->data_type()); auto type_ptr = TypeIdToType(type_id); - auto abstract_tensor = std::make_shared(type_ptr, shape); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); parameter->set_abstract(abstract_tensor); ParamValueLitePtr param_value = std::make_shared(); diff --git a/mindspore/lite/tools/optimizer/graph/weight_format_transform_pass.cc b/mindspore/lite/tools/optimizer/graph/weight_format_transform_pass.cc index 7c7b2d4c621..7454e7ec6ed 100644 --- a/mindspore/lite/tools/optimizer/graph/weight_format_transform_pass.cc +++ b/mindspore/lite/tools/optimizer/graph/weight_format_transform_pass.cc @@ -15,6 +15,7 @@ */ #include "tools/optimizer/graph/weight_format_transform_pass.h" #include +#include #include "tools/optimizer/common/gllo_utils.h" using mindspore::lite::converter::FmkType_CAFFE; @@ -75,7 +76,11 @@ lite::STATUS WeightFormatTransformPass::ConvWeightFormatTrans(const FuncGraphPtr } auto type_id = static_cast(weight_value->tensor_type()); auto type_ptr = TypeIdToType(type_id); - auto abstract_tensor = std::make_shared(type_ptr, weight_value->tensor_shape()); + auto shape = weight_value->tensor_shape(); + std::vector shape_vector; + (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), + [](const int32_t &value) { return static_cast(value); }); + auto abstract_tensor = std::make_shared(type_ptr, shape_vector); weight_node->set_abstract(abstract_tensor); } return RET_OK; diff --git a/mindspore/ops/composite/multitype_ops/_constexpr_utils.py b/mindspore/ops/composite/multitype_ops/_constexpr_utils.py index 757e6559cc2..e8be0599713 100644 --- a/mindspore/ops/composite/multitype_ops/_constexpr_utils.py +++ b/mindspore/ops/composite/multitype_ops/_constexpr_utils.py @@ -675,7 +675,7 @@ def get_pos_of_int_index(indexes_types): """Get int index positions from the mixed tensors index which contains int, tensor, slice, and ellipsis.""" int_positions = [] for i, ele_type in enumerate(indexes_types): - if ele_type == mstype.int32: + if ele_type in (mstype.int32, mstype.int64): int_positions.append(i) return int_positions @@ -695,7 +695,7 @@ def separate_mixed_tensors_index(indexes_types, op_name): ellipsis_position = i else: raise IndexError(f"For '{op_name}', the index elements only support " - f"'Tensor', 'int32', 'Slice', 'Ellipsis', but got {ele_type}.") + f"'Tensor', 'int32', 'int64', 'Slice', 'Ellipsis', but got {ele_type}.") return tensor_positions, slice_positions, ellipsis_position diff --git a/mindspore/ops/operations/array_ops.py b/mindspore/ops/operations/array_ops.py index 5ffe5310414..a6d670d1a8c 100644 --- a/mindspore/ops/operations/array_ops.py +++ b/mindspore/ops/operations/array_ops.py @@ -1576,7 +1576,8 @@ class UnsortedSegmentSum(PrimitiveWithInfer): num_segments_type = num_segments['dtype'] validator.check_subclass("num_segments", num_segments_type, [mstype.tensor, mstype.number], self.name) if isinstance(num_segments_type, type(mstype.tensor)): - validator.check_tensor_dtype_valid("num_segments", num_segments_type, [mstype.int32], self.name) + validator.check_tensor_dtype_valid("num_segments", num_segments_type, [mstype.int32, mstype.int64], + self.name) shp = [-1] else: validator.check_value_type('num_segments', num_segments_v, [int], self.name) @@ -4074,7 +4075,7 @@ class GatherD(PrimitiveWithInfer): def __infer__(self, x, dim, index): validator.check_subclass("x", x['dtype'], mstype.tensor, self.name) validator.check_tensor_dtype_valid("index", index['dtype'], [mstype.int32, mstype.int64], self.name) - validator.check_subclass("dim", dim['dtype'], mstype.int32, self.name) + validator.check_subclass("dim", dim['dtype'], [mstype.int32, mstype.int64], self.name) x_shp = x['shape'] idx_shp = index['shape'] x_rank = len(x_shp) diff --git a/mindspore/ops/operations/image_ops.py b/mindspore/ops/operations/image_ops.py index 3cdacfade11..14545dd11e9 100644 --- a/mindspore/ops/operations/image_ops.py +++ b/mindspore/ops/operations/image_ops.py @@ -121,8 +121,10 @@ class CropAndResize(PrimitiveWithInfer): validator.check("crop_height", crop_size_value[0], "minimum", 0, Rel.GT, self.name) validator.check("crop_width", crop_size_value[1], "minimum", 0, Rel.GT, self.name) # check crop_size element type - validator.check("crop_height dtype", crop_size_dtype[0], "expected", mstype.int32, Rel.EQ, self.name) - validator.check("crop_width dtype", crop_size_dtype[1], "expected", mstype.int32, Rel.EQ, self.name) + validator.check("crop_height dtype", crop_size_dtype[0], "expected", [mstype.int32, mstype.int64], Rel.IN, + self.name) + validator.check("crop_width dtype", crop_size_dtype[1], "expected", [mstype.int32, mstype.int64], Rel.IN, + self.name) num_boxes = boxes_shape[0] crop_height = crop_size_value[0] diff --git a/tests/ut/cpp/abstract/abstract_test.cc b/tests/ut/cpp/abstract/abstract_test.cc index 2e3a2a8d1ac..1c244246295 100644 --- a/tests/ut/cpp/abstract/abstract_test.cc +++ b/tests/ut/cpp/abstract/abstract_test.cc @@ -77,7 +77,7 @@ TEST_F(TestAbstract, TestParseDataClass) { ASSERT_TRUE(foo != nullptr); AbstractBasePtr abstract_x = FromValue(1.1, true); - AbstractBasePtr abstract_y = FromValue(5, true); + AbstractBasePtr abstract_y = FromValue(static_cast(5), true); auto partical_func = dyn_cast(foo); AbstractBasePtrList args_spec_list = partical_func->args(); diff --git a/tests/ut/cpp/abstract/utils_test.cc b/tests/ut/cpp/abstract/utils_test.cc index 33cada28d71..ea954c0641f 100644 --- a/tests/ut/cpp/abstract/utils_test.cc +++ b/tests/ut/cpp/abstract/utils_test.cc @@ -29,23 +29,23 @@ class TestUtils : public UT::Common { TEST_F(TestUtils, test_join) { // AbstractScalar - AbstractBasePtr abs_s1 = FromValue(1, false); - AbstractBasePtr abs_s2 = FromValue(2, false); - AbstractBasePtr abs_s_anything = FromValue(2, true); + AbstractBasePtr abs_s1 = FromValue(static_cast(1), false); + AbstractBasePtr abs_s2 = FromValue(static_cast(2), false); + AbstractBasePtr abs_s_anything = FromValue(static_cast(2), true); AbstractBasePtr res_s1 = abs_s1->Join(abs_s2); ASSERT_EQ(*res_s1, *abs_s_anything); // AbstractTuple join; - std::vector list1 = {1, 2, 3, 4, 5}; - std::vector list2 = {5, 4, 3, 2, 1}; + std::vector list1 = {1, 2, 3, 4, 5}; + std::vector list2 = {5, 4, 3, 2, 1}; AbstractBasePtr abs_t1 = FromValue(list1, true); AbstractBasePtr abs_t2 = FromValue(list2, true); AbstractBasePtr res_t1 = abs_t1->Join(abs_t2); ASSERT_EQ(res_t1, abs_t1); - abs_s1 = FromValue(1, false); + abs_s1 = FromValue(static_cast(1), false); AbstractBasePtr t1 = std::make_shared(AbstractBasePtrList({abs_s1, abs_s_anything})); AbstractBasePtr t2 = std::make_shared(AbstractBasePtrList({abs_s1, abs_s_anything})); diff --git a/tests/ut/cpp/dataset/build_vocab_test.cc b/tests/ut/cpp/dataset/build_vocab_test.cc index b742a3c616a..e3d960debec 100644 --- a/tests/ut/cpp/dataset/build_vocab_test.cc +++ b/tests/ut/cpp/dataset/build_vocab_test.cc @@ -47,7 +47,7 @@ TEST_F(MindDataTestVocab, TestVocabFromUnorderedMap) { // Look up specified words std::vector words = {"apple", "dog", "egg"}; - std::vector expected = {1, 3, -1}; + std::vector expected = {1, 3, -1}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); @@ -65,7 +65,7 @@ TEST_F(MindDataTestVocab, TestVocabFromEmptyMap) { // Look up specified words // Expect that we will return -1 when word is not in vocab std::vector words = {"apple", "dog", "egg"}; - std::vector expected = {-1, -1, -1}; + std::vector expected = {-1, -1, -1}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); @@ -96,7 +96,7 @@ TEST_F(MindDataTestVocab, TestVocabFromVectorPrependSpTokens) { // Look up specified words // Expect that we will return -1 when word is not in vocab std::vector words = {"apple", "banana", "fox"}; - std::vector expected = {1, 2, -1}; + std::vector expected = {1, 2, -1}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); @@ -113,7 +113,7 @@ TEST_F(MindDataTestVocab, TestVocabFromVectorAppendSpTokens) { // Look up specified words std::vector words = {"apple", "", "fox"}; - std::vector expected = {0, 5, -1}; + std::vector expected = {0, 5, -1}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); @@ -131,7 +131,7 @@ TEST_F(MindDataTestVocab, TestVocabFromVectorWithNoSpTokens) { // Look up specified words std::vector words = {"apple", "banana", "fox", ""}; - std::vector expected = {0, 1, -1, -1}; + std::vector expected = {0, 1, -1, -1}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); @@ -149,7 +149,7 @@ TEST_F(MindDataTestVocab, TestVocabFromEmptyVector) { // Look up specified words // Expect that we will return -1 when word is not in vocab std::vector words = {"apple", "banana", "fox"}; - std::vector expected = {-1, -1, -1}; + std::vector expected = {-1, -1, -1}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); @@ -202,7 +202,7 @@ TEST_F(MindDataTestVocab, TestVocabFromFile) { // Look up specified words std::vector words = {"not", "all"}; - std::vector expected = {2, 3}; + std::vector expected = {2, 3}; for (uint32_t i = 0; i < words.size(); ++i) { int32_t x = vocab->Lookup(words[i]); EXPECT_EQ(x, expected[i]); diff --git a/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc b/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc index 815ec6c9c5f..38f569b2e3c 100644 --- a/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc +++ b/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc @@ -145,7 +145,7 @@ TEST_F(MindDataTestPipeline, TestManifestClassIndex) { map["cat"] = 111; // forward slash is not good, but we need to add this somewhere, also in windows, its a '\' map["dog"] = 222; // forward slash is not good, but we need to add this somewhere, also in windows, its a '\' map["wrong folder name"] = 1234; // this is skipped - std::vector expected_label = {111, 222}; + std::vector expected_label = {111, 222}; // Create a Manifest Dataset std::shared_ptr ds = Manifest(file_path, "train", RandomSampler(), map, true); diff --git a/tests/ut/cpp/dataset/perf_data_test.cc b/tests/ut/cpp/dataset/perf_data_test.cc index 486209be218..71b2ab1a71f 100644 --- a/tests/ut/cpp/dataset/perf_data_test.cc +++ b/tests/ut/cpp/dataset/perf_data_test.cc @@ -28,10 +28,10 @@ class MindDataTestPerfData : public UT::Common { }; TEST_F(MindDataTestPerfData, Test1) { - PerfData> p1(2, 3); + PerfData> p1(2, 3); PerfData> p2(2, 3); EXPECT_EQ(p1.capacity(), p2.capacity()); - std::vector row = {1, 2, 3}; + std::vector row = {1, 2, 3}; p1.AddSample(row); p2.AddSample(row); EXPECT_EQ(p1.size(), 1); @@ -40,7 +40,7 @@ TEST_F(MindDataTestPerfData, Test1) { p2.AddSample(row); EXPECT_EQ(p1.size(), 2); EXPECT_EQ(p1.size(), p2.size()); - std::vector row1 = {4, 5, 6}; + std::vector row1 = {4, 5, 6}; p2.AddSample(row1); EXPECT_EQ(p2.size(), 2); auto r1 = p2.Row(static_cast(0)); diff --git a/tests/ut/cpp/ir/clone_test.cc b/tests/ut/cpp/ir/clone_test.cc index b8b32571eaa..a93dc10e279 100644 --- a/tests/ut/cpp/ir/clone_test.cc +++ b/tests/ut/cpp/ir/clone_test.cc @@ -29,9 +29,9 @@ namespace mindspore { class TestCloner : public UT::Common { public: TestCloner() : getPyFun("gtest_input.ir.clone_test", true) { - one = NewValueNode(1); - two = NewValueNode(2); - three = NewValueNode(3); + one = NewValueNode(static_cast(1)); + two = NewValueNode(static_cast(2)); + three = NewValueNode(static_cast(3)); } FuncGraphPtr GraphForInline() { return nullptr; } diff --git a/tests/ut/cpp/ir/meta_tensor_test.cc b/tests/ut/cpp/ir/meta_tensor_test.cc index 9980a446595..cd0d8e267c3 100644 --- a/tests/ut/cpp/ir/meta_tensor_test.cc +++ b/tests/ut/cpp/ir/meta_tensor_test.cc @@ -33,7 +33,7 @@ class TestMetaTensor : public UT::Common { public: TestMetaTensor() {} virtual void SetUp() { - std::vector dimensions({2, 3}); + std::vector dimensions({2, 3}); meta_tensor_ = MetaTensor(TypeId::kNumberTypeFloat64, dimensions); } @@ -42,7 +42,7 @@ class TestMetaTensor : public UT::Common { }; TEST_F(TestMetaTensor, InitTest) { - std::vector dimensions({2, 3}); + std::vector dimensions({2, 3}); MetaTensor meta_tensor(TypeId::kNumberTypeFloat64, dimensions); // Test type @@ -65,7 +65,7 @@ TEST_F(TestMetaTensor, TypeTest) { // Test shape TEST_F(TestMetaTensor, ShapeTest) { - std::vector dimensions({5, 6, 7}); + std::vector dimensions({5, 6, 7}); meta_tensor_.set_shape(dimensions); ASSERT_EQ(5, meta_tensor_.DimensionSize(0)); @@ -77,7 +77,7 @@ TEST_F(TestMetaTensor, ShapeTest) { } TEST_F(TestMetaTensor, EqualTest) { - std::vector dimensions({2, 3}); + std::vector dimensions({2, 3}); MetaTensor meta_tensor_x(TypeId::kNumberTypeFloat64, dimensions); MetaTensor meta_tensor_y(meta_tensor_x); @@ -110,7 +110,7 @@ py::array_t BuildInputTensor() { } TEST_F(TestTensor, PyArrayScalarTest) { - std::vector dimensions; + std::vector dimensions; py::array data = py::array_t(dimensions); uint8_t *data_buf = reinterpret_cast(data.request(true).ptr); @@ -123,7 +123,7 @@ TEST_F(TestTensor, PyArrayScalarTest) { } TEST_F(TestTensor, InitScalarTest) { - std::vector dimensions; + std::vector dimensions; Tensor tensor(TypeId::kNumberTypeInt64, dimensions); uint8_t *data_buf = reinterpret_cast(tensor.data_c()); @@ -142,7 +142,7 @@ TEST_F(TestTensor, InitScalarTest) { // Test shape ASSERT_EQ(0, tensor.shape().size()); - std::vector empty_shape; + std::vector empty_shape; ASSERT_EQ(empty_shape, tensor.shape()); // Test number of elements @@ -151,7 +151,7 @@ TEST_F(TestTensor, InitScalarTest) { } TEST_F(TestTensor, InitTensorPtrTest) { - std::vector dimensions; + std::vector dimensions; Tensor tensor(TypeId::kNumberTypeInt64, dimensions); std::shared_ptr tensor_ptr = std::make_shared(tensor); @@ -164,7 +164,7 @@ TEST_F(TestTensor, InitTensorPtrTest) { // Test shape ASSERT_EQ(0, tensor_ptr->shape().size()); - std::vector empty_shape; + std::vector empty_shape; ASSERT_EQ(empty_shape, tensor_ptr->shape()); // Test number of elements @@ -173,7 +173,7 @@ TEST_F(TestTensor, InitTensorPtrTest) { } TEST_F(TestTensor, InitByTupleTest) { - const std::vector shape = {2, 3, 4}; + const std::vector shape = {2, 3, 4}; TypePtr data_type = kFloat32; Tensor tuple_tensor(data_type->type_id(), shape); ASSERT_EQ(2, tuple_tensor.DimensionSize(0)); @@ -232,7 +232,7 @@ TEST_F(TestTensor, ValueEqualTest) { ASSERT_TRUE(t1->ValueEqual(*t1)); ASSERT_TRUE(t1->ValueEqual(*t2)); - std::vector shape = {6}; + std::vector shape = {6}; TensorPtr t3 = std::make_shared(kInt32->type_id(), shape); TensorPtr t4 = std::make_shared(kInt32->type_id(), shape); ASSERT_TRUE(t3->ValueEqual(*t3)); @@ -300,7 +300,7 @@ TEST_F(TestTensor, InitByFloatArrayDataTest) { std::cout << "Dim: " << tensor->DataDim() << std::endl; ASSERT_EQ(2, tensor->DataDim()); - std::vector dimensions = tensor->shape(); + std::vector dimensions = tensor->shape(); ASSERT_GT(dimensions.size(), 1); std::cout << "Dim0: " << dimensions[0] << std::endl; ASSERT_EQ(2, dimensions[0]); @@ -341,7 +341,7 @@ TEST_F(TestTensor, TensorDataTest) { float ge_tensor_data[] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6}; // Create a Tensor with wanted data type and shape - Tensor tensor(TypeId::kNumberTypeFloat32, std::vector({2, 3})); + Tensor tensor(TypeId::kNumberTypeFloat32, std::vector({2, 3})); // Get the writable data pointer from the tensor float *me_tensor_data = reinterpret_cast(tensor.data_c()); @@ -363,7 +363,7 @@ TEST_F(TestTensor, TensorDataTest) { } TEST_F(TestTensor, TensorPyCast) { - std::vector shape{2, 3, 4, 5}; + std::vector shape{2, 3, 4, 5}; py::tuple py_tuple = py::make_tuple(std::make_shared(kNumberTypeFloat32, shape)); auto shape1 = py::cast(py_tuple[0]).shape(); const py::tuple &t = py_tuple; diff --git a/tests/ut/cpp/ir/value_test.cc b/tests/ut/cpp/ir/value_test.cc index b4ed5f438ef..37966f4a6d7 100644 --- a/tests/ut/cpp/ir/value_test.cc +++ b/tests/ut/cpp/ir/value_test.cc @@ -34,9 +34,9 @@ class TestValue : public UT::Common { TestValue() {} }; -TEST_F(TestValue, test_int32) { - auto i32a = std::make_shared(2); - ASSERT_TRUE(i32a != nullptr); +TEST_F(TestValue, test_int64) { + auto i64a = std::make_shared(2); + ASSERT_TRUE(i64a != nullptr); } TEST_F(TestValue, testToAbstract) { @@ -46,13 +46,13 @@ TEST_F(TestValue, testToAbstract) { ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(boola)); ASSERT_FALSE(*(ret) == *(std::make_shared(false))); - ASSERT_FALSE(*(ret) == *(std::make_shared(2))); + ASSERT_FALSE(*(ret) == *(std::make_shared(static_cast(2)))); - ValuePtr i32v = std::make_shared(2); - AbstractBasePtr i32a = std::make_shared(2); - ret = i32v->ToAbstract(); + ValuePtr i64v = std::make_shared(2); + AbstractBasePtr i64a = std::make_shared(static_cast(2)); + ret = i64v->ToAbstract(); ASSERT_TRUE(ret); - ASSERT_EQ(*(ret), *(i32a)); + ASSERT_EQ(*(ret), *(i64a)); ValuePtr f32v = std::make_shared(1.0); AbstractBasePtr f32a = std::make_shared(1.0f); @@ -72,8 +72,8 @@ TEST_F(TestValue, testToAbstract) { ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(va)); - ValuePtr tv = std::make_shared(std::vector({boolv, i32v, f32v, sv, vv})); - AbstractBasePtr ta = std::make_shared(AbstractBasePtrList({boola, i32a, f32a, sa, va})); + ValuePtr tv = std::make_shared(std::vector({boolv, i64v, f32v, sv, vv})); + AbstractBasePtr ta = std::make_shared(AbstractBasePtrList({boola, i64a, f32a, sa, va})); ret = tv->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(ta)); diff --git a/tests/ut/cpp/kernel/cpu/sparse_apply_adam_cpu_kernel_test.cc b/tests/ut/cpp/kernel/cpu/sparse_apply_adam_cpu_kernel_test.cc index e5cba862306..b3a117b12fb 100644 --- a/tests/ut/cpp/kernel/cpu/sparse_apply_adam_cpu_kernel_test.cc +++ b/tests/ut/cpp/kernel/cpu/sparse_apply_adam_cpu_kernel_test.cc @@ -44,7 +44,7 @@ class SparseApplyAdamCpuKernelTest : public UT::Common { return kernel_addr; } - void CreateInputAddress(std::vector &indices) { + void CreateInputAddress(std::vector &indices) { inputs_.push_back(CreateKernelAddress(var_.data())); inputs_.push_back(CreateKernelAddress(m_.data())); inputs_.push_back(CreateKernelAddress(v_.data())); @@ -58,8 +58,9 @@ class SparseApplyAdamCpuKernelTest : public UT::Common { inputs_.push_back(CreateKernelAddress(indices.data())); } - void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, std::vector &tmp_grad, - std::vector &tmp_indices, std::vector &m_t) { + void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, + std::vector &tmp_grad, std::vector &tmp_indices, + std::vector &m_t) { workspace_.push_back(CreateKernelAddress(new_grad.data())); workspace_.push_back(CreateKernelAddress(new_indices.data())); workspace_.push_back(CreateKernelAddress(tmp_grad.data())); @@ -93,13 +94,14 @@ TEST_F(SparseApplyAdamCpuKernelTest, dense_test) { sparse_adam_->indices_size_ = 3; sparse_adam_->var_first_dim_size_ = 3; sparse_adam_->var_outer_dim_size_ = 9; + sparse_adam_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 1, 2}; + std::vector indices{0, 1, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); std::vector m_t(3 * 3 * 3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices, m_t); sparse_adam_->Launch(inputs_, workspace_, outputs_); @@ -120,13 +122,14 @@ TEST_F(SparseApplyAdamCpuKernelTest, sparse_test1) { sparse_adam_->indices_size_ = 2; sparse_adam_->var_first_dim_size_ = 3; sparse_adam_->var_outer_dim_size_ = 9; + sparse_adam_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 2}; + std::vector indices{0, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); std::vector m_t(3 * 3 * 3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices, m_t); sparse_adam_->Launch(inputs_, workspace_, outputs_); @@ -151,13 +154,14 @@ TEST_F(SparseApplyAdamCpuKernelTest, sparse_test2) { sparse_adam_->indices_size_ = 3; sparse_adam_->var_first_dim_size_ = 3; sparse_adam_->var_outer_dim_size_ = 9; + sparse_adam_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{2, 2, 1}; + std::vector indices{2, 2, 1}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); std::vector m_t(3 * 3 * 3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices, m_t); sparse_adam_->Launch(inputs_, workspace_, outputs_); diff --git a/tests/ut/cpp/kernel/cpu/sparse_apply_ftrl_cpu_kernel_test.cc b/tests/ut/cpp/kernel/cpu/sparse_apply_ftrl_cpu_kernel_test.cc index 230c8cbf9eb..858f4e87c60 100644 --- a/tests/ut/cpp/kernel/cpu/sparse_apply_ftrl_cpu_kernel_test.cc +++ b/tests/ut/cpp/kernel/cpu/sparse_apply_ftrl_cpu_kernel_test.cc @@ -48,7 +48,7 @@ class SparseApplyFtrlCpuKernelTest : public UT::Common { return kernel_addr; } - void CreateInputAddress(std::vector &indices) { + void CreateInputAddress(std::vector &indices) { inputs_.push_back(CreateKernelAddress(var_.data())); inputs_.push_back(CreateKernelAddress(accum_.data())); inputs_.push_back(CreateKernelAddress(linear_.data())); @@ -56,8 +56,8 @@ class SparseApplyFtrlCpuKernelTest : public UT::Common { inputs_.push_back(CreateKernelAddress(indices.data())); } - void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, std::vector &tmp_grad, - std::vector &tmp_indices) { + void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, + std::vector &tmp_grad, std::vector &tmp_indices) { workspace_.push_back(CreateKernelAddress(new_grad.data())); workspace_.push_back(CreateKernelAddress(new_indices.data())); workspace_.push_back(CreateKernelAddress(tmp_grad.data())); @@ -84,13 +84,14 @@ TEST_F(SparseApplyFtrlCpuKernelTest, dense_test) { sparse_ftrl_->indices_size_ = 3; sparse_ftrl_->var_first_dim_size_ = 3; sparse_ftrl_->var_outer_dim_size_ = 9; + sparse_ftrl_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 1, 2}; + std::vector indices{0, 1, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_ftrl_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3 * 3; ++i) { @@ -110,13 +111,14 @@ TEST_F(SparseApplyFtrlCpuKernelTest, sparse_test1) { sparse_ftrl_->indices_size_ = 2; sparse_ftrl_->var_first_dim_size_ = 3; sparse_ftrl_->var_outer_dim_size_ = 9; + sparse_ftrl_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 2}; + std::vector indices{0, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_ftrl_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3; ++i) { @@ -140,13 +142,14 @@ TEST_F(SparseApplyFtrlCpuKernelTest, sparse_test2) { sparse_ftrl_->indices_size_ = 3; sparse_ftrl_->var_first_dim_size_ = 3; sparse_ftrl_->var_outer_dim_size_ = 9; + sparse_ftrl_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{2, 2, 1}; + std::vector indices{2, 2, 1}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_ftrl_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3; ++i) { diff --git a/tests/ut/cpp/kernel/cpu/sparse_apply_lazy_adam_cpu_kernel_test.cc b/tests/ut/cpp/kernel/cpu/sparse_apply_lazy_adam_cpu_kernel_test.cc index a829ead90ed..d685d05b670 100644 --- a/tests/ut/cpp/kernel/cpu/sparse_apply_lazy_adam_cpu_kernel_test.cc +++ b/tests/ut/cpp/kernel/cpu/sparse_apply_lazy_adam_cpu_kernel_test.cc @@ -44,7 +44,7 @@ class SparseApplyLazyAdamCpuKernelTest : public UT::Common { return kernel_addr; } - void CreateInputAddress(std::vector &indices) { + void CreateInputAddress(std::vector &indices) { inputs_.push_back(CreateKernelAddress(var_.data())); inputs_.push_back(CreateKernelAddress(m_.data())); inputs_.push_back(CreateKernelAddress(v_.data())); @@ -58,8 +58,8 @@ class SparseApplyLazyAdamCpuKernelTest : public UT::Common { inputs_.push_back(CreateKernelAddress(indices.data())); } - void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, std::vector &tmp_grad, - std::vector &tmp_indices) { + void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, + std::vector &tmp_grad, std::vector &tmp_indices) { workspace_.push_back(CreateKernelAddress(new_grad.data())); workspace_.push_back(CreateKernelAddress(new_indices.data())); workspace_.push_back(CreateKernelAddress(tmp_grad.data())); @@ -92,13 +92,14 @@ TEST_F(SparseApplyLazyAdamCpuKernelTest, dense_test) { sparse_lazy_adam_->indices_size_ = 3; sparse_lazy_adam_->var_first_dim_size_ = 3; sparse_lazy_adam_->var_outer_dim_size_ = 9; + sparse_lazy_adam_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 1, 2}; + std::vector indices{0, 1, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_lazy_adam_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3 * 3; ++i) { @@ -118,13 +119,14 @@ TEST_F(SparseApplyLazyAdamCpuKernelTest, sparse_test1) { sparse_lazy_adam_->indices_size_ = 2; sparse_lazy_adam_->var_first_dim_size_ = 3; sparse_lazy_adam_->var_outer_dim_size_ = 9; + sparse_lazy_adam_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 2}; + std::vector indices{0, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_lazy_adam_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3; ++i) { @@ -148,13 +150,14 @@ TEST_F(SparseApplyLazyAdamCpuKernelTest, sparse_test2) { sparse_lazy_adam_->indices_size_ = 3; sparse_lazy_adam_->var_first_dim_size_ = 3; sparse_lazy_adam_->var_outer_dim_size_ = 9; + sparse_lazy_adam_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{2, 2, 1}; + std::vector indices{2, 2, 1}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_lazy_adam_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3; ++i) { diff --git a/tests/ut/cpp/kernel/cpu/sparse_apply_proximal_adagrad_cpu_kernel_test.cc b/tests/ut/cpp/kernel/cpu/sparse_apply_proximal_adagrad_cpu_kernel_test.cc index 64bd5d3ef31..32453efe411 100644 --- a/tests/ut/cpp/kernel/cpu/sparse_apply_proximal_adagrad_cpu_kernel_test.cc +++ b/tests/ut/cpp/kernel/cpu/sparse_apply_proximal_adagrad_cpu_kernel_test.cc @@ -44,7 +44,7 @@ class SparseApplyProximalAdagradCpuKernelTest : public UT::Common { return kernel_addr; } - void CreateInputAddress(std::vector &indices) { + void CreateInputAddress(std::vector &indices) { inputs_.push_back(CreateKernelAddress(var_.data())); inputs_.push_back(CreateKernelAddress(accum_.data())); inputs_.push_back(CreateKernelAddress(&lr_)); @@ -54,8 +54,8 @@ class SparseApplyProximalAdagradCpuKernelTest : public UT::Common { inputs_.push_back(CreateKernelAddress(indices.data())); } - void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, std::vector &tmp_grad, - std::vector &tmp_indices) { + void CreateWorkspaceAddress(std::vector &new_grad, std::vector &new_indices, + std::vector &tmp_grad, std::vector &tmp_indices) { workspace_.push_back(CreateKernelAddress(new_grad.data())); workspace_.push_back(CreateKernelAddress(new_indices.data())); workspace_.push_back(CreateKernelAddress(tmp_grad.data())); @@ -83,13 +83,14 @@ TEST_F(SparseApplyProximalAdagradCpuKernelTest, dense_test) { sparse_proximal_adagrad_->indices_size_ = 3; sparse_proximal_adagrad_->var_first_dim_size_ = 3; sparse_proximal_adagrad_->var_outer_dim_size_ = 9; + sparse_proximal_adagrad_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 1, 2}; + std::vector indices{0, 1, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_proximal_adagrad_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3 * 3; ++i) { @@ -108,13 +109,14 @@ TEST_F(SparseApplyProximalAdagradCpuKernelTest, sparse_test1) { sparse_proximal_adagrad_->indices_size_ = 2; sparse_proximal_adagrad_->var_first_dim_size_ = 3; sparse_proximal_adagrad_->var_outer_dim_size_ = 9; + sparse_proximal_adagrad_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{0, 2}; + std::vector indices{0, 2}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_proximal_adagrad_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3; ++i) { @@ -137,13 +139,14 @@ TEST_F(SparseApplyProximalAdagradCpuKernelTest, sparse_test2) { sparse_proximal_adagrad_->indices_size_ = 3; sparse_proximal_adagrad_->var_first_dim_size_ = 3; sparse_proximal_adagrad_->var_outer_dim_size_ = 9; + sparse_proximal_adagrad_->indices_data_type_ = kNumberTypeInt64; - std::vector indices{2, 2, 1}; + std::vector indices{2, 2, 1}; CreateInputAddress(indices); std::vector new_grad(3 * 3 * 3); - std::vector new_indices(3); + std::vector new_indices(3); std::vector tmp_grad(3 * 3 * 3); - std::vector tmp_indices(3); + std::vector tmp_indices(3); CreateWorkspaceAddress(new_grad, new_indices, tmp_grad, tmp_indices); sparse_proximal_adagrad_->Launch(inputs_, workspace_, outputs_); for (size_t i = 0; i < 3 * 3; ++i) { diff --git a/tests/ut/cpp/kernel/cpu/unique_cpu_kernel_test.cc b/tests/ut/cpp/kernel/cpu/unique_cpu_kernel_test.cc index 7dfd3c22787..943a1ace96b 100644 --- a/tests/ut/cpp/kernel/cpu/unique_cpu_kernel_test.cc +++ b/tests/ut/cpp/kernel/cpu/unique_cpu_kernel_test.cc @@ -51,7 +51,7 @@ class UniqueCpuKernelTest : public UT::Common { std::vector x_; std::vector y_; - std::vector idx_; + std::vector idx_; std::vector inputs_; std::vector workspace_; std::vector outputs_; @@ -68,7 +68,7 @@ TEST_F(UniqueCpuKernelTest, compute_test) { // check compute result std::vector expect_y{1, 2, 4, 7, 8}; - std::vector expect_idx{0, 0, 1, 2, 2, 2, 3, 4, 4}; + std::vector expect_idx{0, 0, 1, 2, 2, 2, 3, 4, 4}; EXPECT_TRUE(y_ == expect_y); EXPECT_TRUE(idx_ == expect_idx); } diff --git a/tests/ut/cpp/kernel/cpu/unique_with_pad_cpu_kernel_test.cc b/tests/ut/cpp/kernel/cpu/unique_with_pad_cpu_kernel_test.cc index d7be8e94e4f..c9d1177f576 100644 --- a/tests/ut/cpp/kernel/cpu/unique_with_pad_cpu_kernel_test.cc +++ b/tests/ut/cpp/kernel/cpu/unique_with_pad_cpu_kernel_test.cc @@ -30,7 +30,7 @@ class UniqueWithPadCpuKernelTest : public UT::Common { void SetUp() override { unique_with_pad_->n_ = 10; - unique_with_pad_->dtype_ = kNumberTypeInt32; + unique_with_pad_->dtype_ = kNumberTypeInt64; inputs_.clear(); workspace_.clear(); outputs_.clear(); @@ -53,10 +53,10 @@ class UniqueWithPadCpuKernelTest : public UT::Common { outputs_.push_back(CreateKernelAddress(idx_.data())); } - std::vector x_; - int pad_dim_; - std::vector out_; - std::vector idx_; + std::vector x_; + int64_t pad_dim_; + std::vector out_; + std::vector idx_; std::vector inputs_; std::vector workspace_; std::vector outputs_; @@ -73,8 +73,8 @@ TEST_F(UniqueWithPadCpuKernelTest, compute_test) { unique_with_pad_->Launch(inputs_, workspace_, outputs_); // check compute result - std::vector expect_out{1, 5, 4, 3, 2, 8, 8, 8, 8, 8}; - std::vector expect_idx{0, 0, 1, 1, 2, 2, 3, 3, 4, 4}; + std::vector expect_out{1, 5, 4, 3, 2, 8, 8, 8, 8, 8}; + std::vector expect_idx{0, 0, 1, 1, 2, 2, 3, 3, 4, 4}; EXPECT_TRUE(out_ == expect_out); EXPECT_TRUE(idx_ == expect_idx); } diff --git a/tests/ut/cpp/operator/cc_implementations_test.cc b/tests/ut/cpp/operator/cc_implementations_test.cc index 4bc5aea964b..a84ae3c533f 100644 --- a/tests/ut/cpp/operator/cc_implementations_test.cc +++ b/tests/ut/cpp/operator/cc_implementations_test.cc @@ -31,9 +31,9 @@ class TestImplementations : public UT::Common { TEST_F(TestImplementations, ScalarAddTest) { ValuePtrList list; - list.push_back(MakeValue(1)); - list.push_back(MakeValue(2)); - ASSERT_EQ(ScalarAdd(list)->cast()->value(), 3); + list.push_back(MakeValue(static_cast(1))); + list.push_back(MakeValue(static_cast(2))); + ASSERT_EQ(ScalarAdd(list)->cast()->value(), 3); list.clear(); list.push_back(MakeValue(1.0f)); @@ -46,8 +46,8 @@ TEST_F(TestImplementations, ScalarAddTest) { ASSERT_EQ(ScalarAdd(list)->cast()->value(), 3.5); list.clear(); - list.push_back(MakeValue(INT32_MAX)); - list.push_back(MakeValue(2)); + list.push_back(MakeValue(INT64_MAX)); + list.push_back(MakeValue(static_cast(2))); try { ScalarAdd(list); FAIL(); @@ -56,8 +56,8 @@ TEST_F(TestImplementations, ScalarAddTest) { } list.clear(); - list.push_back(MakeValue(INT32_MIN)); - list.push_back(MakeValue(-1)); + list.push_back(MakeValue(INT64_MIN)); + list.push_back(MakeValue(static_cast(-1))); try { ScalarAdd(list); FAIL(); @@ -69,9 +69,9 @@ TEST_F(TestImplementations, ScalarAddTest) { TEST_F(TestImplementations, ScalarSubTest) { ValuePtrList list; - list.push_back(MakeValue(1)); - list.push_back(MakeValue(3)); - ASSERT_EQ(ScalarSub(list)->cast()->value(), -2); + list.push_back(MakeValue(static_cast(1))); + list.push_back(MakeValue(static_cast(3))); + ASSERT_EQ(ScalarSub(list)->cast()->value(), -2); list.clear(); list.push_back(MakeValue(1.0f)); @@ -84,8 +84,8 @@ TEST_F(TestImplementations, ScalarSubTest) { ASSERT_EQ(ScalarSub(list)->cast()->value(), 2.5); list.clear(); - list.push_back(MakeValue(INT32_MAX)); - list.push_back(MakeValue(-1)); + list.push_back(MakeValue(INT64_MAX)); + list.push_back(MakeValue(static_cast(-1))); try { ScalarSub(list); FAIL(); @@ -94,8 +94,8 @@ TEST_F(TestImplementations, ScalarSubTest) { } list.clear(); - list.push_back(MakeValue(INT32_MIN)); - list.push_back(MakeValue(1)); + list.push_back(MakeValue(INT64_MIN)); + list.push_back(MakeValue(static_cast(1))); try { ScalarSub(list); FAIL(); @@ -107,9 +107,9 @@ TEST_F(TestImplementations, ScalarSubTest) { TEST_F(TestImplementations, ScalarMulTest) { ValuePtrList list; - list.push_back(MakeValue(2)); - list.push_back(MakeValue(3)); - ASSERT_EQ(ScalarMul(list)->cast()->value(), 6); + list.push_back(MakeValue(static_cast(2))); + list.push_back(MakeValue(static_cast(3))); + ASSERT_EQ(ScalarMul(list)->cast()->value(), 6); list.clear(); list.push_back(MakeValue(2.0f)); @@ -122,8 +122,8 @@ TEST_F(TestImplementations, ScalarMulTest) { ASSERT_EQ(ScalarMul(list)->cast()->value(), 8.0); list.clear(); - list.push_back(MakeValue(10)); - list.push_back(MakeValue(INT32_MAX)); + list.push_back(MakeValue(static_cast(10))); + list.push_back(MakeValue(INT64_MAX)); try { ScalarMul(list); FAIL(); @@ -132,8 +132,8 @@ TEST_F(TestImplementations, ScalarMulTest) { } list.clear(); - list.push_back(MakeValue(INT32_MIN)); - list.push_back(MakeValue(-1)); + list.push_back(MakeValue(INT64_MIN)); + list.push_back(MakeValue(static_cast(-1))); try { ScalarMul(list); FAIL(); @@ -142,8 +142,8 @@ TEST_F(TestImplementations, ScalarMulTest) { } list.clear(); - list.push_back(MakeValue(-2)); - list.push_back(MakeValue(INT32_MAX)); + list.push_back(MakeValue(static_cast(-2))); + list.push_back(MakeValue(INT64_MAX)); try { ScalarMul(list); FAIL(); @@ -152,8 +152,8 @@ TEST_F(TestImplementations, ScalarMulTest) { } list.clear(); - list.push_back(MakeValue(2)); - list.push_back(MakeValue(INT32_MIN)); + list.push_back(MakeValue(static_cast(2))); + list.push_back(MakeValue(INT64_MIN)); try { ScalarMul(list); FAIL(); @@ -162,17 +162,17 @@ TEST_F(TestImplementations, ScalarMulTest) { } list.clear(); - list.push_back(MakeValue(0)); - list.push_back(MakeValue(INT32_MIN)); - ASSERT_EQ(ScalarDiv(list)->cast()->value(), 0); + list.push_back(MakeValue(static_cast(0))); + list.push_back(MakeValue(INT64_MIN)); + ASSERT_EQ(ScalarDiv(list)->cast()->value(), 0); list.clear(); } TEST_F(TestImplementations, ScalarDivTest) { ValuePtrList list; - list.push_back(MakeValue(6)); - list.push_back(MakeValue(3)); - ASSERT_EQ(ScalarDiv(list)->cast()->value(), 2); + list.push_back(MakeValue(static_cast(6))); + list.push_back(MakeValue(static_cast(3))); + ASSERT_EQ(ScalarDiv(list)->cast()->value(), 2); list.clear(); list.push_back(MakeValue(3.0f)); @@ -185,8 +185,8 @@ TEST_F(TestImplementations, ScalarDivTest) { ASSERT_EQ(ScalarDiv(list)->cast()->value(), -2.0); list.clear(); - list.push_back(MakeValue(INT32_MAX)); - list.push_back(MakeValue(0)); + list.push_back(MakeValue(INT64_MAX)); + list.push_back(MakeValue(static_cast(0))); try { ScalarDiv(list); FAIL(); @@ -195,8 +195,8 @@ TEST_F(TestImplementations, ScalarDivTest) { } list.clear(); - list.push_back(MakeValue(INT32_MIN)); - list.push_back(MakeValue(-1)); + list.push_back(MakeValue(INT64_MIN)); + list.push_back(MakeValue(static_cast(-1))); try { ScalarDiv(list); FAIL(); @@ -205,31 +205,31 @@ TEST_F(TestImplementations, ScalarDivTest) { } list.clear(); - list.push_back(MakeValue(-1)); - list.push_back(MakeValue(INT32_MIN)); - ASSERT_EQ(ScalarDiv(list)->cast()->value(), 0); + list.push_back(MakeValue(static_cast(-1))); + list.push_back(MakeValue(INT64_MIN)); + ASSERT_EQ(ScalarDiv(list)->cast()->value(), 0); list.clear(); } TEST_F(TestImplementations, ScalarModTest) { ValuePtrList list; - list.push_back(MakeValue(7)); - list.push_back(MakeValue(3)); - ASSERT_EQ(ScalarMod(list)->cast()->value(), 1); + list.push_back(MakeValue(static_cast(7))); + list.push_back(MakeValue(static_cast(3))); + ASSERT_EQ(ScalarMod(list)->cast()->value(), 1); list.clear(); - list.push_back(MakeValue(-8)); - list.push_back(MakeValue(3)); - ASSERT_EQ(ScalarMod(list)->cast()->value(), -2); + list.push_back(MakeValue(static_cast(-8))); + list.push_back(MakeValue(static_cast(3))); + ASSERT_EQ(ScalarMod(list)->cast()->value(), -2); list.clear(); - list.push_back(MakeValue(-9)); - list.push_back(MakeValue(2)); - ASSERT_EQ(ScalarMod(list)->cast()->value(), -1); + list.push_back(MakeValue(static_cast(-9))); + list.push_back(MakeValue(static_cast(2))); + ASSERT_EQ(ScalarMod(list)->cast()->value(), -1); list.clear(); - list.push_back(MakeValue(INT32_MIN)); - list.push_back(MakeValue(0)); + list.push_back(MakeValue(INT64_MIN)); + list.push_back(MakeValue(static_cast(0))); try { ScalarMod(list); FAIL(); @@ -238,8 +238,8 @@ TEST_F(TestImplementations, ScalarModTest) { } list.clear(); - list.push_back(MakeValue(INT32_MIN)); - list.push_back(MakeValue(-1)); + list.push_back(MakeValue(INT64_MIN)); + list.push_back(MakeValue(static_cast(-1))); try { ScalarMod(list); FAIL(); @@ -251,8 +251,8 @@ TEST_F(TestImplementations, ScalarModTest) { TEST_F(TestImplementations, ScalarUAddTest) { ValuePtrList list; - list.push_back(MakeValue((uint32_t)1)); - ASSERT_EQ(ScalarUAdd(list)->cast()->value(), 1); + list.push_back(MakeValue((uint64_t)1)); + ASSERT_EQ(ScalarUAdd(list)->cast()->value(), 1); list.clear(); } @@ -265,8 +265,8 @@ TEST_F(TestImplementations, ScalarLogTest) { TEST_F(TestImplementations, ScalarUSubTest) { ValuePtrList list; - list.push_back(MakeValue(1)); - ASSERT_EQ(ScalarUSub(list)->cast()->value(), -1); + list.push_back(MakeValue(static_cast(1))); + ASSERT_EQ(ScalarUSub(list)->cast()->value(), -1); list.clear(); } diff --git a/tests/ut/cpp/operator/composite_test.cc b/tests/ut/cpp/operator/composite_test.cc index 9912e0c4e87..499f19452f2 100644 --- a/tests/ut/cpp/operator/composite_test.cc +++ b/tests/ut/cpp/operator/composite_test.cc @@ -64,8 +64,8 @@ void TestComposite::TearDown() { class UTCompositeUtils { public: - static AbstractTensorPtr ArrayInt32Of(std::initializer_list shp) { - auto ele = std::make_shared(kAnyValue, kInt32); + static AbstractTensorPtr ArrayInt32Of(std::initializer_list shp) { + auto ele = std::make_shared(kAnyValue, kInt64); return std::make_shared(ele, std::make_shared(shp)); } static FuncGraphPtr MakeFuncGraph(const MetaFuncGraphPtr &metaFuncGraphPtr, size_t nparam) { @@ -96,8 +96,8 @@ TEST_F(TestComposite, test_TupleSlice_arg_two_numbers) { eles.push_back(tensor); } auto tuple_tensor = std::make_shared(eles); - auto start_index = std::make_shared(1); - auto stop_index = std::make_shared(5); + auto start_index = std::make_shared(static_cast(1)); + auto stop_index = std::make_shared(static_cast(5)); AbstractBasePtrList args_spec_list = {tuple_tensor, start_index, stop_index}; try { @@ -121,7 +121,7 @@ TEST_F(TestComposite, test_TupleSlice_arg_one_number) { eles.push_back(tensor); } auto tuple_tensor = std::make_shared(eles); - auto start_index = std::make_shared(1); + auto start_index = std::make_shared(static_cast(1)); AbstractBasePtrList args_spec_list = {tuple_tensor, start_index}; try { @@ -153,9 +153,9 @@ TEST_F(TestComposite, test_TupleSlice_arg_slice) { eles.push_back(tensor); } auto tuple_tensor = std::make_shared(eles); - auto start_index = std::make_shared(1); - auto stop_index = std::make_shared(6); - auto step = std::make_shared(2); + auto start_index = std::make_shared(static_cast(1)); + auto stop_index = std::make_shared(static_cast(6)); + auto step = std::make_shared(static_cast(2)); auto slice = std::make_shared(start_index, stop_index, step); AbstractBasePtrList args_spec_list = {tuple_tensor, slice}; @@ -179,8 +179,8 @@ TEST_F(TestComposite, test_TupleSlice_arg_slice_step_none) { eles.push_back(tensor); } auto tuple_tensor = std::make_shared(eles); - auto start_index = std::make_shared(1); - auto stop_index = std::make_shared(5); + auto start_index = std::make_shared(static_cast(1)); + auto stop_index = std::make_shared(static_cast(5)); auto step = std::make_shared(); auto slice = std::make_shared(start_index, stop_index, step); AbstractBasePtrList args_spec_list = {tuple_tensor, slice}; @@ -207,7 +207,7 @@ TEST_F(TestComposite, test_TupleSlice_arg_slice_step_negative) { auto tuple_tensor = std::make_shared(eles); auto start_index = std::make_shared(); auto stop_index = std::make_shared(); - auto step = std::make_shared(-1); + auto step = std::make_shared(static_cast(-1)); auto slice = std::make_shared(start_index, stop_index, step); AbstractBasePtrList args_spec_list = {tuple_tensor, slice}; @@ -231,9 +231,9 @@ TEST_F(TestComposite, test_TupleSlice_arg_slice_step_positive) { eles.push_back(tensor); } auto tuple_tensor = std::make_shared(eles); - auto start_index = std::make_shared(-2); + auto start_index = std::make_shared(static_cast(-2)); auto stop_index = std::make_shared(); - auto step = std::make_shared(-1); + auto step = std::make_shared(static_cast(-1)); auto slice = std::make_shared(start_index, stop_index, step); AbstractBasePtrList args_spec_list = {tuple_tensor, slice}; diff --git a/tests/ut/cpp/operator/ops_test.cc b/tests/ut/cpp/operator/ops_test.cc index 829d66176e7..2aa9eaf7831 100644 --- a/tests/ut/cpp/operator/ops_test.cc +++ b/tests/ut/cpp/operator/ops_test.cc @@ -374,13 +374,13 @@ TEST_F(TestOps, Conv2dTest) { TEST_F(TestOps, Conv2dAttrTest) { Primitive prim("Conv2D"); prim.SetAttrs({ - {"stride", MakeValue(3)}, - {"pad", MakeValue(1)}, + {"stride", MakeValue(static_cast(3))}, + {"pad", MakeValue(static_cast(1))}, }); ASSERT_EQ(prim.name(), kPrimConv2D->name()); - Int32Imm stride(3); - Int32Imm pad(1); + Int64Imm stride(3); + Int64Imm pad(1); ASSERT_EQ(*prim.GetAttr("stride"), stride); ASSERT_EQ(*prim.GetAttr("pad"), pad); } @@ -388,8 +388,8 @@ TEST_F(TestOps, Conv2dAttrTest) { TEST_F(TestOps, CustomOpAttrTest) { Primitive prim("CustomOp", true, kPrimTypePyInferShape); prim.SetAttrs({ - {"attr1", MakeValue(3)}, - {"attr2", MakeValue(1)}, + {"attr1", MakeValue(static_cast(3))}, + {"attr2", MakeValue(static_cast(1))}, }); ASSERT_EQ(prim.name(), std::string("CustomOp")); ASSERT_EQ(prim.prim_type(), kPrimTypePyInferShape); diff --git a/tests/ut/cpp/optimizer/clean_test.cc b/tests/ut/cpp/optimizer/clean_test.cc index 82bec1b5a8a..c944cd09ba1 100644 --- a/tests/ut/cpp/optimizer/clean_test.cc +++ b/tests/ut/cpp/optimizer/clean_test.cc @@ -52,7 +52,7 @@ void TestClean::SetUp() { // build the nodes AnfNodePtr valuenode_next = NewValueNode(std::string("ms_next")); ParameterPtr parameter = std::make_shared(me_graph); - AbstractBasePtr para_scalar = std::make_shared(0); + AbstractBasePtr para_scalar = std::make_shared(static_cast(0)); AbstractBasePtr para_list = std::make_shared( AbstractBasePtrList({std::make_shared(kFloat64), std::make_shared(kFloat64)})); AbstractBasePtrList para_elem{para_scalar, para_list}; diff --git a/tests/ut/cpp/optimizer/lib_test.cc b/tests/ut/cpp/optimizer/lib_test.cc index d0678f1ecc2..a363a056d49 100644 --- a/tests/ut/cpp/optimizer/lib_test.cc +++ b/tests/ut/cpp/optimizer/lib_test.cc @@ -111,8 +111,8 @@ TEST_F(TestOptLib, test_inline) { // add infer and renormalize std::shared_ptr res = std::make_shared(); AbstractBasePtrList args_spec_list; - AbstractBasePtr abstract_v1 = abstract::FromValue(1, true); - AbstractBasePtr abstract_v2 = abstract::FromValue(2, true); + AbstractBasePtr abstract_v1 = abstract::FromValue(static_cast(1), true); + AbstractBasePtr abstract_v2 = abstract::FromValue(static_cast(2), true); args_spec_list.push_back(abstract_v1); args_spec_list.push_back(abstract_v2); AnalysisResult result = pipeline::AbstractAnalyze(res, before1, args_spec_list); @@ -190,7 +190,7 @@ TEST_F(TestOptLib, test_elim_cast_same_dtype) { cast_py->set_attr("DstT", TypeIdToType(kNumberTypeFloat32)); auto x_node = inputs[1]; - std::vector shp = {2, 3}; + std::vector shp = {2, 3}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); x_node->set_abstract(x_abstract); @@ -220,7 +220,7 @@ TEST_F(TestOptLib, test_elim_reshape_same_shape) { auto &inputs = before->output()->cast()->inputs(); if (inputs.size() > 1) { auto x_node = inputs[1]; - std::vector shp = {2, 3}; + std::vector shp = {2, 3}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); x_node->set_abstract(x_abstract); @@ -230,7 +230,7 @@ TEST_F(TestOptLib, test_elim_reshape_same_shape) { ASSERT_TRUE(CheckOpt(before, after, patterns)); if (inputs.size() > 1) { auto x_node = inputs[1]; - std::vector shp = {3, 2}; + std::vector shp = {3, 2}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); x_node->set_abstract(x_abstract); @@ -286,7 +286,7 @@ TEST_F(TestOptLib, test_elim_reduce_mean_shape_one) { auto inputs = before->output()->cast()->inputs(); if (inputs.size() > 2) { auto x_node = inputs[1]; - std::vector shp = {1}; + std::vector shp = {1}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); x_node->set_abstract(x_abstract); @@ -308,7 +308,7 @@ TEST_F(TestOptLib, test_elim_all_shape_one) { auto inputs = before->output()->cast()->inputs(); if (inputs.size() > 2) { auto x_node = inputs[1]; - std::vector shp = {1}; + std::vector shp = {1}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); x_node->set_abstract(x_abstract); @@ -329,7 +329,7 @@ TEST_F(TestOptLib, test_elim_sum_shape_one) { auto inputs = before->output()->cast()->inputs(); if (inputs.size() > 2) { auto x_node = inputs[1]; - std::vector shp = {1}; + std::vector shp = {1}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); x_node->set_abstract(x_abstract); @@ -349,9 +349,9 @@ TEST_F(TestOptLib, test_tuple_getitem) { FuncGraphPtr after_1 = getPyFun.CallAndParseRet("test_tuple_getitem", "after_1"); FuncGraphPtr make_get_const = std::make_shared(); - auto value_node_1 = NewValueNode(1); - auto value_node_2 = NewValueNode(2); - std::vector vec{1, 2}; + auto value_node_1 = NewValueNode(static_cast(1)); + auto value_node_2 = NewValueNode(static_cast(2)); + std::vector vec{1, 2}; auto value_node_tuple = NewValueNode(MakeValue(vec)); std::vector node_list{NewValueNode(prim::kPrimTupleGetItem), value_node_tuple, value_node_1}; auto get_item = make_get_const->NewCNode(node_list); @@ -515,11 +515,11 @@ TEST_F(TestOptLib, test_reducesum_one) { FuncGraphPtr after3 = getPyFun.CallAndParseRet("test_reducesum_one", "after_3"); auto patterns = std::vector({irpass.reduce_eliminate_}); - std::vector shp = {3, 2, 2, 1}; + std::vector shp = {3, 2, 2, 1}; tensor::TensorPtr x_tensor = std::make_shared(kFloat32->type_id(), shp); auto x_abstract = x_tensor->ToAbstract(); - std::vector shp2 = {3, 2, 1, 1}; + std::vector shp2 = {3, 2, 1, 1}; tensor::TensorPtr x_tensor2 = std::make_shared(kFloat32->type_id(), shp2); auto x_abstract2 = x_tensor2->ToAbstract(); diff --git a/tests/ut/cpp/parallel/auto_parallel/rec_partition_test.cc b/tests/ut/cpp/parallel/auto_parallel/rec_partition_test.cc index 7942fa2a100..2757efa55af 100644 --- a/tests/ut/cpp/parallel/auto_parallel/rec_partition_test.cc +++ b/tests/ut/cpp/parallel/auto_parallel/rec_partition_test.cc @@ -29,7 +29,7 @@ namespace parallel { class TestPartition : public UT::Common { public: - void Create(std::shared_ptr graph, int node_num, std::vector edge_head, std::vector edge_tail); + void Create(std::shared_ptr graph, int node_num, std::vector edge_head, std::vector edge_tail); void InitEdge(std::shared_ptr graph, int vHead, int vTail); void InitNode(std::shared_ptr graph, int num_node); TensorParam *MakeTensor(int n, int c, int h, int w); @@ -37,8 +37,8 @@ class TestPartition : public UT::Common { }; // Local function to create test input graph with nodes -void TestPartition::Create(std::shared_ptr graph, int node_num, std::vector edge_head, - std::vector edge_tail) { +void TestPartition::Create(std::shared_ptr graph, int node_num, std::vector edge_head, + std::vector edge_tail) { TestPartition::InitNode(graph, node_num); unsigned int edge_num = edge_head.size(); if (edge_num != edge_tail.size()) { @@ -93,8 +93,8 @@ std::shared_ptr TestPartition::MakeMatMulData(int numNode) { edgeNum = 0; }; - std::vector edgeHead(edgeNum); // int edgeHead[8] = {0,2,4,6,1,3,5,7}; - std::vector edgeTail(edgeNum); // int edgeTail[8] = {2,4,6,8,2,4,6,8}; + std::vector edgeHead(edgeNum); // int edgeHead[8] = {0,2,4,6,1,3,5,7}; + std::vector edgeTail(edgeNum); // int edgeTail[8] = {2,4,6,8,2,4,6,8}; for (int i = 0; i < edgeNum; i++) { edgeHead[i] = i; diff --git a/tests/ut/cpp/parallel/ops_info/activation_test.cc b/tests/ut/cpp/parallel/ops_info/activation_test.cc index 4442c1d4ffd..a785d46b5d3 100644 --- a/tests/ut/cpp/parallel/ops_info/activation_test.cc +++ b/tests/ut/cpp/parallel/ops_info/activation_test.cc @@ -59,7 +59,7 @@ void TestActivation::SetUp() { ValuePtr relu = MakeValue(std::string("relu")); std::unordered_map relu_attr = {{"activation_type", relu}}; ValuePtr sm = MakeValue(std::string("softmax")); - ValuePtr axix = MakeValue(std::int32_t(2)); + ValuePtr axix = MakeValue(std::int64_t(2)); std::unordered_map softmax_attr = {{"activation_type", sm}, {"axis", axix}}; Shapes relu_inputs_shape = {{2, 4, 8, 16}}; diff --git a/tests/ut/cpp/parallel/ops_info/get_next_info_test.cc b/tests/ut/cpp/parallel/ops_info/get_next_info_test.cc index 505ab29a5ab..b9096b519e4 100644 --- a/tests/ut/cpp/parallel/ops_info/get_next_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/get_next_info_test.cc @@ -55,7 +55,7 @@ void TestGetNextInfo::SetUp() { std::unordered_map attr; std::vector types_ = {"float32", "int32"}; Shapes shapes_ = {{64, 32}, {64}}; - int32_t output_num_ = 2; + int64_t output_num_ = 2; std::string shared_name_ = "test_get_next"; attr["types"] = MakeValue(types_); attr["shapes"] = MakeValue(shapes_); diff --git a/tests/ut/cpp/parallel/ops_info/l2_normalize_info_test.cc b/tests/ut/cpp/parallel/ops_info/l2_normalize_info_test.cc index 6cbdefd123f..28823796043 100644 --- a/tests/ut/cpp/parallel/ops_info/l2_normalize_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/l2_normalize_info_test.cc @@ -54,7 +54,7 @@ void TestL2NormalizeInfo::SetUp() { g_device_manager = std::make_shared(); g_device_manager->Init(dev_list, local_dev, stage_map, "hccl"); - ValuePtr axis = MakeValue(1); + ValuePtr axis = MakeValue(static_cast(1)); std::unordered_map attr = {{AXIS, axis}}; Shapes inputs_shape = {{32, 64, 96}}; diff --git a/tests/ut/cpp/parallel/ops_info/log_softmax_info_test.cc b/tests/ut/cpp/parallel/ops_info/log_softmax_info_test.cc index 5803a4c3258..3468d921b05 100644 --- a/tests/ut/cpp/parallel/ops_info/log_softmax_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/log_softmax_info_test.cc @@ -54,7 +54,7 @@ void TestLogSoftmaxInfo::SetUp() { g_device_manager = std::make_shared(); g_device_manager->Init(dev_list, local_dev, stage_map, "hccl"); - ValuePtr axis = MakeValue(-2); + ValuePtr axis = MakeValue(static_cast(-2)); std::unordered_map attr = {{"axis", axis}}; Shapes inputs_shape = {{2, 4, 8, 16}}; diff --git a/tests/ut/cpp/parallel/ops_info/matmul_info_test.cc b/tests/ut/cpp/parallel/ops_info/matmul_info_test.cc index d5fc6f2a2ec..5eccc59a489 100644 --- a/tests/ut/cpp/parallel/ops_info/matmul_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/matmul_info_test.cc @@ -390,7 +390,7 @@ TEST_F(TestMatmulInfo, GetVirtualDivOp1) { std::string arg0_name = operator_args.first.at(0).first; ValuePtr arg0_value = operator_args.first.at(0).second; - int32_t divisor = arg0_value->cast()->value(); + int64_t divisor = arg0_value->cast()->value(); ASSERT_EQ(virtual_div_op.at(0).first, "_VirtualDiv"); ASSERT_EQ(virtual_div_op.size(), 1); diff --git a/tests/ut/cpp/parallel/ops_info/onehot_info_test.cc b/tests/ut/cpp/parallel/ops_info/onehot_info_test.cc index 6efac9598ba..fe4cc0abcb0 100644 --- a/tests/ut/cpp/parallel/ops_info/onehot_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/onehot_info_test.cc @@ -54,7 +54,7 @@ void TestOneHotInfo::SetUp() { g_device_manager = std::make_shared(); g_device_manager->Init(dev_list, local_dev, stage_map, "hccl"); - ValuePtr axis = MakeValue(std::int32_t(-1)); + ValuePtr axis = MakeValue(std::int64_t(-1)); std::unordered_map attr = {{"axis", axis}}; Shapes inputs_shape = {{64}, {}, {}}; diff --git a/tests/ut/cpp/parallel/ops_info/onehot_info_test_axis_0.cc b/tests/ut/cpp/parallel/ops_info/onehot_info_test_axis_0.cc index 239a7299cd7..756fb74e639 100644 --- a/tests/ut/cpp/parallel/ops_info/onehot_info_test_axis_0.cc +++ b/tests/ut/cpp/parallel/ops_info/onehot_info_test_axis_0.cc @@ -54,7 +54,7 @@ void TestOneHotInfo2::SetUp() { g_device_manager = std::make_shared(); g_device_manager->Init(dev_list, local_dev, stage_map, "hccl"); - ValuePtr axis = MakeValue(std::int32_t(0)); + ValuePtr axis = MakeValue(std::int64_t(0)); std::unordered_map attr = {{"axis", axis}}; Shapes inputs_shape = {{64}, {}, {}}; diff --git a/tests/ut/cpp/parallel/ops_info/reduce_method_test.cc b/tests/ut/cpp/parallel/ops_info/reduce_method_test.cc index 69d830db0f4..c89e9cabeb2 100644 --- a/tests/ut/cpp/parallel/ops_info/reduce_method_test.cc +++ b/tests/ut/cpp/parallel/ops_info/reduce_method_test.cc @@ -57,7 +57,7 @@ void TestReduceSumInfo::SetUp() { Shapes inputs_shape = {{16, 32, 64}}; Shapes outputs_shape = {{16, 32}}; - ValuePtr value = MakeValue(-1); + ValuePtr value = MakeValue(static_cast(-1)); ValuePtr value0; std::vector val = {value0, value}; ValuePtr keep_dims = MakeValue(false); diff --git a/tests/ut/cpp/parallel/ops_info/reshape_test.cc b/tests/ut/cpp/parallel/ops_info/reshape_test.cc index a15cbf2adc5..bddc5fe63e4 100644 --- a/tests/ut/cpp/parallel/ops_info/reshape_test.cc +++ b/tests/ut/cpp/parallel/ops_info/reshape_test.cc @@ -58,7 +58,7 @@ void TestReshapeInfo::SetUp() { Shapes inputs_shape = {{32, 512, 7, 7}}; Shapes outputs_shape = {{32, 25088}}; - std::vector axis = {32, 25088}; + std::vector axis = {32, 25088}; ValuePtr val0; ValuePtr val1 = MakeValue(axis); std::vector val = {val0, val1}; diff --git a/tests/ut/cpp/parallel/ops_info/softmax_entropy_loss_info_test.cc b/tests/ut/cpp/parallel/ops_info/softmax_entropy_loss_info_test.cc index 0368ae5c1de..9b5cf2f466c 100644 --- a/tests/ut/cpp/parallel/ops_info/softmax_entropy_loss_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/softmax_entropy_loss_info_test.cc @@ -166,7 +166,7 @@ TEST_F(TestSoftmaxLoss, GetVirtualDivOPs1) { std::string arg0_name = operator_args.first.at(0).first; ValuePtr arg0_value = operator_args.first.at(0).second; - int32_t divisor = arg0_value->cast()->value(); + int64_t divisor = arg0_value->cast()->value(); ASSERT_EQ(virtual_div_op.at(0).first, "_VirtualDiv"); ASSERT_EQ(virtual_div_op.size(), 1); diff --git a/tests/ut/cpp/parallel/ops_info/softmax_info_test.cc b/tests/ut/cpp/parallel/ops_info/softmax_info_test.cc index 7be44ef2b99..08b2d358087 100644 --- a/tests/ut/cpp/parallel/ops_info/softmax_info_test.cc +++ b/tests/ut/cpp/parallel/ops_info/softmax_info_test.cc @@ -54,10 +54,10 @@ void TestSoftmaxInfo::SetUp() { g_device_manager = std::make_shared(); g_device_manager->Init(dev_list, local_dev, stage_map, "hccl"); - ValuePtr axis1 = MakeValue(-2); + ValuePtr axis1 = MakeValue(static_cast(-2)); std::unordered_map attr1 = {{"axis", axis1}}; - ValuePtr axis2 = MakeValue(4); + ValuePtr axis2 = MakeValue(static_cast(4)); std::unordered_map attr2 = {{"axis", axis2}}; Shapes inputs_shape = {{2, 4, 8, 16}}; diff --git a/tests/ut/cpp/parallel/ops_info/transpose_test.cc b/tests/ut/cpp/parallel/ops_info/transpose_test.cc index 306f04c92ac..1674c0cb3ee 100644 --- a/tests/ut/cpp/parallel/ops_info/transpose_test.cc +++ b/tests/ut/cpp/parallel/ops_info/transpose_test.cc @@ -58,7 +58,7 @@ void TestTransposeInfo::SetUp() { Shapes inputs_shape = {{128, 64}}; Shapes outputs_shape = {{64, 128}}; - std::vector axis = {1, 0}; + std::vector axis = {1, 0}; ValuePtr val0; ValuePtr val1 = MakeValue(axis); std::vector val = {val0, val1}; diff --git a/tests/ut/cpp/parallel/step_auto_parallel_test.cc b/tests/ut/cpp/parallel/step_auto_parallel_test.cc index 1a93981acc4..54d60489911 100644 --- a/tests/ut/cpp/parallel/step_auto_parallel_test.cc +++ b/tests/ut/cpp/parallel/step_auto_parallel_test.cc @@ -58,9 +58,9 @@ CNodePtr Create_Node(Shape x, Shape y, Shape out) { BaseShapePtr shape1 = std::make_shared(x); BaseShapePtr shape2 = std::make_shared(y); BaseShapePtr shape3 = std::make_shared(out); - AbstractBasePtr abstract1 = abstract::FromValue(1, false); - AbstractBasePtr abstract2 = abstract::FromValue(1, false); - AbstractBasePtr abstract3 = abstract::FromValue(1, false); + AbstractBasePtr abstract1 = abstract::FromValue(static_cast(1), false); + AbstractBasePtr abstract2 = abstract::FromValue(static_cast(1), false); + AbstractBasePtr abstract3 = abstract::FromValue(static_cast(1), false); abstract1->set_shape(shape1); abstract2->set_shape(shape2); abstract3->set_shape(shape3); @@ -94,11 +94,11 @@ CNodePtr Create_two_nodes(Shape x, Shape y, Shape z, Shape w, Shape out) { BaseShapePtr shapeZ = std::make_shared(z); BaseShapePtr shapeW = std::make_shared(w); BaseShapePtr shapeOut = std::make_shared(out); - AbstractBasePtr abstractX = abstract::FromValue(1, false); - AbstractBasePtr abstractY = abstract::FromValue(1, false); - AbstractBasePtr abstractZ = abstract::FromValue(1, false); - AbstractBasePtr abstractW = abstract::FromValue(1, false); - AbstractBasePtr abstractOut = abstract::FromValue(1, false); + AbstractBasePtr abstractX = abstract::FromValue(static_cast(1), false); + AbstractBasePtr abstractY = abstract::FromValue(static_cast(1), false); + AbstractBasePtr abstractZ = abstract::FromValue(static_cast(1), false); + AbstractBasePtr abstractW = abstract::FromValue(static_cast(1), false); + AbstractBasePtr abstractOut = abstract::FromValue(static_cast(1), false); abstractX->set_shape(shapeX); abstractY->set_shape(shapeY); abstractZ->set_shape(shapeZ); diff --git a/tests/ut/cpp/parallel/step_parallel_test.cc b/tests/ut/cpp/parallel/step_parallel_test.cc index 8a3de310edb..667da48397b 100644 --- a/tests/ut/cpp/parallel/step_parallel_test.cc +++ b/tests/ut/cpp/parallel/step_parallel_test.cc @@ -52,27 +52,18 @@ void Init_Device_Manager() { g_device_manager->Init(dev_list, local_dev, stage_map, "hccl"); } -CNodePtr Make_Node(Shape x, Shape y, Shape out, int condition = 0) { - std::vector x_shape; - std::vector y_shape; - std::vector out_shape; +CNodePtr Make_Node(Shape x, Shape y, Shape out, int64_t condition = 0) { FuncGraphPtr func_graph = std::make_shared(); ParameterPtr param1 = func_graph->add_parameter(); ParameterPtr param2 = func_graph->add_parameter(); - (void)std::transform(x.begin(), x.end(), std::back_inserter(x_shape), - [](const int64_t &value) { return static_cast(value); }); - (void)std::transform(y.begin(), y.end(), std::back_inserter(y_shape), - [](const int64_t &value) { return static_cast(value); }); - (void)std::transform(out.begin(), out.end(), std::back_inserter(out_shape), - [](const int64_t &value) { return static_cast(value); }); param1->set_name("x"); param2->set_name("y"); BaseShapePtr shape1 = std::make_shared(x); BaseShapePtr shape2 = std::make_shared(y); BaseShapePtr shape3 = std::make_shared(out); - std::shared_ptr inputs_x = std::make_shared(kNumberTypeInt32, x_shape); - std::shared_ptr inputs_y = std::make_shared(kNumberTypeInt32, y_shape); - std::shared_ptr inputs_out = std::make_shared(kNumberTypeInt32, out_shape); + std::shared_ptr inputs_x = std::make_shared(kNumberTypeInt32, x); + std::shared_ptr inputs_y = std::make_shared(kNumberTypeInt32, y); + std::shared_ptr inputs_out = std::make_shared(kNumberTypeInt32, out); AbstractBasePtr abstract1 = abstract::FromValue(inputs_x, true); AbstractBasePtr abstract2 = abstract::FromValue(inputs_y, true); AbstractBasePtr abstract3 = abstract::FromValue(inputs_out, true); @@ -96,7 +87,7 @@ CNodePtr Make_Node(Shape x, Shape y, Shape out, int condition = 0) { abstract2->set_shape(shape2); param1->set_abstract(abstract1); param2->set_abstract(abstract2); - abstract3 = abstract::FromValue(1, false); + abstract3 = abstract::FromValue(static_cast(1), false); break; } case 3: { @@ -121,12 +112,12 @@ CNodePtr Make_Node(Shape x, Shape y, Shape out, int condition = 0) { return node; } -FuncGraphManagerPtr Make_Manager(int condition = 0) { - std::vector inputs_x = {64, 32}; - std::vector inputs_y = {32, 64}; - std::vector inputs_z = {64, 128}; - std::vector outputs_1 = {64, 64}; - std::vector outputs_2 = {64, 128}; +FuncGraphManagerPtr Make_Manager(int64_t condition = 0) { + std::vector inputs_x = {64, 32}; + std::vector inputs_y = {32, 64}; + std::vector inputs_z = {64, 128}; + std::vector outputs_1 = {64, 64}; + std::vector outputs_2 = {64, 128}; FuncGraphPtr func_graph = std::make_shared(); ParameterPtr param1 = func_graph->add_parameter(); ParameterPtr param2 = func_graph->add_parameter(); @@ -186,11 +177,11 @@ FuncGraphManagerPtr Make_Manager(int condition = 0) { prim2->AddAttr("strategy", var2); switch (condition) { case 1: { - prim1->set_attr("strategy", MakeValue(0)); + prim1->set_attr("strategy", MakeValue(static_cast(0))); break; } case 2: { - std::vector elements_t = {MakeValue(0)}; + std::vector elements_t = {MakeValue(static_cast(0))}; ValueTuplePtr var_t = std::make_shared(elements_t); prim1->set_attr("strategy", var_t); break; diff --git a/tests/ut/cpp/parallel/tensor_layout/construct_operator_test.cc b/tests/ut/cpp/parallel/tensor_layout/construct_operator_test.cc index 61df1a24619..71aae634d8c 100644 --- a/tests/ut/cpp/parallel/tensor_layout/construct_operator_test.cc +++ b/tests/ut/cpp/parallel/tensor_layout/construct_operator_test.cc @@ -41,7 +41,7 @@ class TestConstructOperator : public UT::Common { void TestConstructOperator::SetUp() { RankList dev_list; - for (int32_t i = 0; i < 1050; i++) { + for (int64_t i = 0; i < 1050; i++) { dev_list.push_back(i); } RankList stage_map; @@ -98,14 +98,8 @@ TEST_F(TestConstructOperator, TestStridedSliceOP) { OperatorParams params = op.second.second; ValuePtr begin_ptr = params[0].first.second; ValuePtr end_ptr = params[1].first.second; - std::vector begin_int = GetValue>(begin_ptr); - std::vector end_int = GetValue>(end_ptr); - Shape begin; - Shape end; - (void)std::transform(begin_int.begin(), begin_int.end(), std::back_inserter(begin), - [](const int32_t &value) { return static_cast(value); }); - (void)std::transform(end_int.begin(), end_int.end(), std::back_inserter(end), - [](const int32_t &value) { return static_cast(value); }); + Shape begin = GetValue>(begin_ptr); + Shape end = GetValue>(end_ptr); for (size_t i = 0; i < begin.size(); i++) { int64_t diff = end[i] - begin[i]; int64_t num = shape[i]; @@ -118,25 +112,25 @@ TEST_F(TestConstructOperator, TestStridedSliceOP) { } TEST_F(TestConstructOperator, TestAllGatherOP) { - int32_t dev_dim = 2; + int64_t dev_dim = 2; ASSERT_EQ(constructor.AllGatherOP(dev_dim), Status::SUCCESS); } TEST_F(TestConstructOperator, TestConcatOP) { - int32_t concat_dim = 0; + int64_t concat_dim = 0; ASSERT_EQ(constructor.ConcatOP(concat_dim), Status::SUCCESS); } TEST_F(TestConstructOperator, TestSplitOP) { - int32_t split_count = 2; + int64_t split_count = 2; ASSERT_EQ(constructor.SplitOP(split_count), Status::SUCCESS); } TEST_F(TestConstructOperator, TestAlltoAllOP) { - int32_t split_count = 2; - int32_t split_dim = 0; - int32_t concat_dim = 1; - int32_t dev_dim = 3; + int64_t split_count = 2; + int64_t split_dim = 0; + int64_t concat_dim = 1; + int64_t dev_dim = 3; Args args = {split_count, split_dim, concat_dim, dev_dim}; ASSERT_EQ(constructor.AlltoAllOP(args), Status::SUCCESS); } diff --git a/tests/ut/cpp/pipeline/resource_test.cc b/tests/ut/cpp/pipeline/resource_test.cc index f6fe8e52421..f2dfbb0023f 100644 --- a/tests/ut/cpp/pipeline/resource_test.cc +++ b/tests/ut/cpp/pipeline/resource_test.cc @@ -25,7 +25,7 @@ namespace mindspore { namespace pipeline { -using MethodMap = std::unordered_map>; +using MethodMap = std::unordered_map>; extern MethodMap& GetMethodMap(); diff --git a/tests/ut/cpp/pipeline/static_analysis/data_test.cc b/tests/ut/cpp/pipeline/static_analysis/data_test.cc index fb9d8b1f7ef..5264cd9e0c9 100644 --- a/tests/ut/cpp/pipeline/static_analysis/data_test.cc +++ b/tests/ut/cpp/pipeline/static_analysis/data_test.cc @@ -39,20 +39,20 @@ void TestData::TearDown() { TEST_F(TestData, test_build_value) { // assert build_value(S(1)) == 1 - AbstractScalar s1 = AbstractScalar(1); - ASSERT_EQ(1, s1.BuildValue()->cast()->value()); + AbstractScalar s1 = AbstractScalar(static_cast(1)); + ASSERT_EQ(1, s1.BuildValue()->cast()->value()); // assert build_value(S(t=ty.Int[64]), default=ANYTHING) is ANYTHING - s1 = AbstractScalar(kAnyValue, kInt32); + s1 = AbstractScalar(kAnyValue, kInt64); ASSERT_TRUE(s1.BuildValue()->isa()); ASSERT_TRUE(s1.BuildValue()->isa()); // assert build_value(T([S(1), S(2)])) == (1, 2) - AbstractBasePtr base1 = std::make_shared(1); - AbstractBasePtr base2 = std::make_shared(2); + AbstractBasePtr base1 = std::make_shared(static_cast(1)); + AbstractBasePtr base2 = std::make_shared(static_cast(2)); AbstractBasePtrList base_list = {base1, base2}; AbstractTuple t1 = AbstractTuple(base_list); - std::vector value_list = {MakeValue(1), MakeValue(2)}; + std::vector value_list = {MakeValue(static_cast(1)), MakeValue(static_cast(2))}; auto tup = t1.BuildValue()->cast()->value(); ASSERT_TRUE(tup.size() == value_list.size()); @@ -88,20 +88,20 @@ TEST_F(TestData, test_build_value) { } TEST_F(TestData, test_build_type) { - AbstractBasePtr s1 = FromValue(1, false); - AbstractBasePtr s2 = FromValue(2, false); - ASSERT_TRUE(Int(32) == *s1->BuildType()); + AbstractBasePtr s1 = FromValue(static_cast(1), false); + AbstractBasePtr s2 = FromValue(static_cast(2), false); + ASSERT_TRUE(Int(64) == *s1->BuildType()); AbstractFunctionPtr f1 = std::make_shared(nullptr, nullptr); ASSERT_TRUE(Function() == *f1->BuildType()); AbstractList l1 = AbstractList({s1, s2}); - ASSERT_TRUE(List({std::make_shared(32), std::make_shared(32)}) == *l1.BuildType()); + ASSERT_TRUE(List({std::make_shared(64), std::make_shared(64)}) == *l1.BuildType()); } TEST_F(TestData, test_build_shape) { - AbstractBasePtr s1 = FromValue(1, false); - AbstractBasePtr s2 = FromValue(2, false); + AbstractBasePtr s1 = FromValue(static_cast(1), false); + AbstractBasePtr s2 = FromValue(static_cast(2), false); ASSERT_TRUE(NoShape() == *s1->BuildShape()); AbstractFunctionPtr f1 = std::make_shared(nullptr, nullptr); @@ -111,10 +111,10 @@ TEST_F(TestData, test_build_shape) { auto lshape = l1.BuildShape(); ASSERT_TRUE(lshape); - std::vector weight1_dims = {2, 20, 5, 5}; - std::vector weight2_dims = {2, 2, 5, 5}; - tensor::TensorPtr weight1 = std::make_shared(kNumberTypeInt32, weight1_dims); - tensor::TensorPtr weight2 = std::make_shared(kNumberTypeInt32, weight2_dims); + std::vector weight1_dims = {2, 20, 5, 5}; + std::vector weight2_dims = {2, 2, 5, 5}; + tensor::TensorPtr weight1 = std::make_shared(kNumberTypeInt64, weight1_dims); + tensor::TensorPtr weight2 = std::make_shared(kNumberTypeInt64, weight2_dims); AbstractBasePtr abstract_weight1 = FromValue(weight1, true); AbstractBasePtr abstract_weight2 = FromValue(weight2, true); @@ -139,7 +139,7 @@ TEST_F(TestData, test_build_shape) { } TEST_F(TestData, test_clone) { - AbstractBasePtr s1 = FromValue(1, false); + AbstractBasePtr s1 = FromValue(static_cast(1), false); AbstractBasePtr s2 = s1->Clone(); ASSERT_TRUE(*s1->GetTypeTrack() == *s2->GetTypeTrack()); ASSERT_TRUE(s1->GetValueTrack() == s2->GetValueTrack()); @@ -165,7 +165,7 @@ TEST_F(TestData, test_clone) { } TEST_F(TestData, test_join) { - int int1 = 1; + int64_t int1 = 1; AbstractBasePtr s1 = FromValue(int1, false); AbstractBasePtr s2 = s1->Broaden(); @@ -176,7 +176,7 @@ TEST_F(TestData, test_join) { } TEST_F(TestData, test_broaden) { - int int1 = 1; + int64_t int1 = 1; AbstractBasePtr s1 = FromValue(int1, false); AbstractBasePtr s2 = s1->Broaden(); ASSERT_TRUE(*s1->GetTypeTrack() == *s2->GetTypeTrack()); diff --git a/tests/ut/cpp/pipeline/static_analysis/evaluator_test.cc b/tests/ut/cpp/pipeline/static_analysis/evaluator_test.cc index 664f353faae..1b94a766ae1 100644 --- a/tests/ut/cpp/pipeline/static_analysis/evaluator_test.cc +++ b/tests/ut/cpp/pipeline/static_analysis/evaluator_test.cc @@ -37,26 +37,26 @@ class TestEvaluatorCacheMap : public UT::Common { TEST_F(TestEvaluatorCacheMap, test_evaluator_cache_map) { EvaluatorCacheMap cache; - AbstractBasePtr abstract_v1 = FromValue(1, false); - AbstractBasePtr abstract_v2 = FromValue(2, false); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), false); + AbstractBasePtr abstract_v2 = FromValue(static_cast(2), false); AbstractBasePtrList args_spec_list = {abstract_v1, abstract_v2}; - AbstractBasePtr abstract_val = FromValue(10, false); + AbstractBasePtr abstract_val = FromValue(static_cast(10), false); cache[args_spec_list] = std::make_shared(abstract_val, std::make_shared()); auto iter = cache.find(args_spec_list); ASSERT_TRUE(iter != cache.end()); ASSERT_TRUE(iter->second->abstract() == abstract_val); - AbstractBasePtr abstract_v1_variant1 = FromValue(1, false); - AbstractBasePtr abstract_v2_variant1 = FromValue(2, false); + AbstractBasePtr abstract_v1_variant1 = FromValue(static_cast(1), false); + AbstractBasePtr abstract_v2_variant1 = FromValue(static_cast(2), false); AbstractBasePtrList args_spec_list_variant1 = {abstract_v1_variant1, abstract_v2_variant1}; iter = cache.find(args_spec_list_variant1); ASSERT_TRUE(iter != cache.end()); ASSERT_TRUE(iter->second->abstract() == abstract_val); - AbstractBasePtr abstract_v1_variant2 = FromValue(1, false); - AbstractBasePtr abstract_v2_variant2 = FromValue(3, false); + AbstractBasePtr abstract_v1_variant2 = FromValue(static_cast(1), false); + AbstractBasePtr abstract_v2_variant2 = FromValue(static_cast(3), false); AbstractBasePtrList args_spec_list_variant2 = {abstract_v1_variant2, abstract_v2_variant2}; iter = cache.find(args_spec_list_variant2); @@ -85,9 +85,9 @@ TEST_F(TestStandardEvaluator, test_multiple_conv2d) { FuncGraphPtr func_graph = getPyFun.CallAndParseRet("test_multiple_conv2d"); // NCHW - std::vector inputs_dims = {2, 20, 32, 32}; - std::vector weight1_dims = {2, 20, 5, 5}; - std::vector weight2_dims = {2, 2, 5, 5}; + std::vector inputs_dims = {2, 20, 32, 32}; + std::vector weight1_dims = {2, 20, 5, 5}; + std::vector weight2_dims = {2, 2, 5, 5}; tensor::TensorPtr inputs = std::make_shared(); inputs->set_data_type(kNumberTypeInt32); @@ -108,7 +108,7 @@ TEST_F(TestStandardEvaluator, test_multiple_conv2d) { AbstractBasePtr expected = abstract_inputs->Clone(); // NCHW - std::vector shape = {2, 2, 6, 6}; + std::vector shape = {2, 2, 6, 6}; expected->set_shape(std::make_shared(shape)); AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); diff --git a/tests/ut/cpp/pipeline/static_analysis/prim_test.cc b/tests/ut/cpp/pipeline/static_analysis/prim_test.cc index f3b61a70eb3..1e64a69be55 100644 --- a/tests/ut/cpp/pipeline/static_analysis/prim_test.cc +++ b/tests/ut/cpp/pipeline/static_analysis/prim_test.cc @@ -45,22 +45,22 @@ class UTPrimUtils { static std::shared_ptr TypeToAbstract(TypePtr t) { return std::make_shared(t); } - static AbstractTensorPtr ArrayFloat64Of(std::initializer_list shp) { + static AbstractTensorPtr ArrayFloat64Of(std::initializer_list shp) { auto ele = std::make_shared(kAnyValue, kFloat64); return std::make_shared(ele, std::make_shared(shp)); } - static AbstractTensorPtr ArrayFloat32Of(std::initializer_list shp) { + static AbstractTensorPtr ArrayFloat32Of(std::initializer_list shp) { auto ele = std::make_shared(kAnyValue, kFloat32); return std::make_shared(ele, std::make_shared(shp)); } - static AbstractTensorPtr ArrayInt32Of(std::initializer_list shp) { - auto ele = std::make_shared(kAnyValue, kInt32); + static AbstractTensorPtr ArrayInt32Of(std::initializer_list shp) { + auto ele = std::make_shared(kAnyValue, kInt64); return std::make_shared(ele, std::make_shared(shp)); } - static AbstractTuplePtr ShapeOf(std::initializer_list vals) { + static AbstractTuplePtr ShapeOf(std::initializer_list vals) { AbstractBasePtrList te; for (auto v : vals) { te.push_back(std::make_shared(v)); @@ -68,7 +68,7 @@ class UTPrimUtils { return std::make_shared(te); } - static AbstractListPtr ListShapeOf(std::initializer_list vals) { + static AbstractListPtr ListShapeOf(std::initializer_list vals) { AbstractBasePtrList te; for (auto v : vals) { te.push_back(std::make_shared(v)); @@ -83,8 +83,8 @@ const std::shared_ptr UTPrimUtils::kI64 = std::make_shared(64); const std::shared_ptr UTPrimUtils::kU64 = std::make_shared(64); namespace { /* skip ut test cases temporarily -AbstractBasePtr ArrayOfTensor(const TypePtr &t, std::initializer_list shp) { - auto shape = std::vector(shp); +AbstractBasePtr ArrayOfTensor(const TypePtr &t, std::initializer_list shp) { + auto shape = std::vector(shp); auto tensor = std::make_shared(t->type_id(), shape); return ToAbstract(tensor); } @@ -106,7 +106,7 @@ void TestPrim::TearDown() { // destroy resource } -static FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, unsigned int nparam) { +static FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, uint64_t nparam) { // build the func_graph manually, eg: // MakeFuncGraph(std::make_shared("scalar_add"), 2) means: /* python source code: @@ -117,7 +117,7 @@ static FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, unsigned int nparam) FuncGraphPtr func_graph = std::make_shared(); std::vector inputs; inputs.push_back(NewValueNode(prim)); - for (unsigned int i = 0; i < nparam; i++) { + for (uint64_t i = 0; i < nparam; i++) { inputs.push_back(func_graph->add_parameter()); } CNodePtr cnode_prim = func_graph->NewCNode(inputs); @@ -131,7 +131,7 @@ static FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, unsigned int nparam) TEST_F(TestPrim, test_typeof) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr abstract_v1 = FromValue(v1, false); args_spec_list.push_back(abstract_v1); @@ -142,17 +142,17 @@ TEST_F(TestPrim, test_typeof) { res->dump(); TypePtr res_value = res->GetValueTrack()->cast(); res_value->dump(); - ASSERT_TRUE(*res_value == Int(32)); + ASSERT_TRUE(*res_value == Int(64)); } TEST_F(TestPrim, test_list_map) { AbstractBasePtrList args_spec_list; - AbstractBasePtr abstract_v1 = FromValue(1, false); - AbstractBasePtr abstract_u1 = FromValue(1, false); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), false); + AbstractBasePtr abstract_u1 = FromValue(static_cast(1), false); auto abstract_list1 = std::make_shared(AbstractBasePtrList({abstract_v1, abstract_u1})); - AbstractBasePtr abstract_v2 = FromValue(2, false); - AbstractBasePtr abstract_u2 = FromValue(2, false); + AbstractBasePtr abstract_v2 = FromValue(static_cast(2), false); + AbstractBasePtr abstract_u2 = FromValue(static_cast(2), false); auto abstract_list2 = std::make_shared(AbstractBasePtrList({abstract_v2, abstract_u2})); auto prim_scalar_add = std::make_shared("scalar_add"); AbstractBasePtr abstract_func = ToAbstract(prim_scalar_add); @@ -164,7 +164,8 @@ TEST_F(TestPrim, test_list_map) { auto prim_list_map = std::make_shared("list_map"); FuncGraphPtr func_graph = MakeFuncGraph(prim_list_map, 3); AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); - auto expected = std::make_shared(AbstractBasePtrList({FromValue(3, false), FromValue(3, false)})); + auto expected = std::make_shared( + AbstractBasePtrList({FromValue(static_cast(3), false), FromValue(static_cast(3), false)})); res->dump(); MS_LOG(INFO) << "result res: " << res->ToString(); MS_LOG(INFO) << "result expected: " << expected->ToString(); @@ -173,7 +174,7 @@ TEST_F(TestPrim, test_list_map) { TEST_F(TestPrim, test_list_reduce) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr abstract_v1 = FromValue(v1, false); AbstractBasePtr abstract_v2 = FromValue(v1, false); @@ -191,12 +192,12 @@ TEST_F(TestPrim, test_list_reduce) { res->dump(); TypePtr res_type = res->GetTypeTrack(); res_type->dump(); - ASSERT_TRUE(*res_type == Int(32)); + ASSERT_TRUE(*res_type == Int(64)); } TEST_F(TestPrim, test_scalar_to_array) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr abstract_v1 = FromValue(v1, false); @@ -208,12 +209,12 @@ TEST_F(TestPrim, test_scalar_to_array) { res->dump(); TypePtr res_type = res->BuildType(); res_type->dump(); - ASSERT_TRUE(*res_type == TensorType(std::make_shared(32))); + ASSERT_TRUE(*res_type == TensorType(std::make_shared(64))); } TEST_F(TestPrim, test_array_to_scalar) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr abstract_v1 = FromValue(v1, false); auto abstract_a1 = std::make_shared(abstract_v1, std::make_shared()); @@ -226,12 +227,12 @@ TEST_F(TestPrim, test_array_to_scalar) { res->dump(); TypePtr res_type = res->BuildType(); res_type->dump(); - ASSERT_TRUE(*res_type == Int(32)); + ASSERT_TRUE(*res_type == Int(64)); } TEST_F(TestPrim, test_J_1) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr abstract_v1 = FromValue(v1, false); args_spec_list.push_back(abstract_v1); @@ -276,7 +277,7 @@ TEST_F(TestPrim, test_J_2) { func_graph->set_return(cnode_return); draw::Draw("test_J_2.dot", func_graph); - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr abstract_v1 = FromValue(v1, false); AbstractBasePtrList args_spec_list = {abstract_v1}; AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -285,7 +286,7 @@ TEST_F(TestPrim, test_J_2) { ASSERT_TRUE(res_J != nullptr); auto res_J_0 = res_J->elements()[0]; ASSERT_TRUE(res_J_0 != nullptr); - ASSERT_TRUE(*res_J_0 == *(FromValue(2, false))); + ASSERT_TRUE(*res_J_0 == *(FromValue(static_cast(2), false))); AbstractFunctionPtr res_J_1 = dyn_cast(res_J->elements()[1]); ASSERT_TRUE(res_J_1 != nullptr); } @@ -296,7 +297,7 @@ TEST_F(TestPrim, test_dot) { auto a1 = UTPrimUtils::ArrayFloat64Of({2, 3}); auto a2 = UTPrimUtils::ArrayFloat64Of({3, 4}); - std::vector expectedA = {2, 4}; + std::vector expectedA = {2, 4}; auto expected = UTPrimUtils::ArrayFloat64Of({2, 4}); AbstractBasePtrList args_spec_list = {a1, a2}; @@ -312,8 +313,8 @@ TEST_F(TestPrim, test_switch1) { FuncGraphPtr func_graph = MakeFuncGraph(switch_, 3); AbstractBasePtr arg0 = FromValue(true, false); - AbstractBasePtr arg1 = FromValue(1, false); - AbstractBasePtr arg2 = FromValue(2, false); + AbstractBasePtr arg1 = FromValue(static_cast(1), false); + AbstractBasePtr arg2 = FromValue(static_cast(2), false); AbstractBasePtrList args_spec_list = {arg0, arg1, arg2}; AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -325,8 +326,8 @@ TEST_F(TestPrim, test_switch2) { FuncGraphPtr func_graph = MakeFuncGraph(switch_, 3); AbstractBasePtr arg0 = FromValue(false, false); - AbstractBasePtr arg1 = FromValue(1, false); - AbstractBasePtr arg2 = FromValue(2, false); + AbstractBasePtr arg1 = FromValue(static_cast(1), false); + AbstractBasePtr arg2 = FromValue(static_cast(2), false); AbstractBasePtrList args_spec_list = {arg0, arg1, arg2}; AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -339,7 +340,7 @@ TEST_F(TestPrim, test_identity) { PrimitivePtr identity = std::make_shared("identity"); FuncGraphPtr func_graph = MakeFuncGraph(identity, 1); - AbstractBasePtr abstract_v1 = FromValue(1, false); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), false); AbstractBasePtrList args_spec_list = {abstract_v1}; AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -361,7 +362,7 @@ TEST_F(TestPrim, test_broadcast_shape) { auto ret = res->BuildValue()->cast()->value(); std::vector element_list = {MakeValue(Shape::SHP_ANY), MakeValue(Shape::SHP_ANY)}; ASSERT_TRUE(ret.size() == element_list.size()); - for (int i = 0; i < element_list.size(); i++) { + for (int64_t i = 0; i < element_list.size(); i++) { ASSERT_TRUE(*ret[i] == *element_list[i]); } } @@ -372,8 +373,8 @@ TEST_F(TestPrim, test_partial) { PrimitivePtr add = prim::kPrimScalarAdd; AbstractBasePtr abstract_add = ToAbstract(add); - AbstractBasePtr abstract_v1 = FromValue(1, false); - AbstractBasePtr abstract_v2 = FromValue(1, false); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), false); + AbstractBasePtr abstract_v2 = FromValue(static_cast(1), false); AbstractBasePtrList args_spec_list = {abstract_add, abstract_v1, abstract_v2}; AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -389,14 +390,14 @@ TEST_F(TestPrim, test_partial) { // return env_setitem(newenv, embed(x), y) TEST_F(TestPrim, test_env_setitem) { FuncGraphPtr graph_embed = MakeFuncGraph(prim::kPrimEmbed, 1); - AbstractBasePtr abstract_x = FromValue(1, false); + AbstractBasePtr abstract_x = FromValue(static_cast(1), false); AbstractBasePtrList args_spec_list = {abstract_x}; AbstractBasePtr embed_x = engine_->Run(graph_embed, args_spec_list).inferred->abstract(); FuncGraphPtr func_graph = MakeFuncGraph(prim::kPrimEnvSetItem, 3); AbstractBasePtr abstract_env = ToAbstract(newenv); - AbstractBasePtr abstract_y = FromValue(2, false); + AbstractBasePtr abstract_y = FromValue(static_cast(2), false); args_spec_list = {abstract_env, embed_x, abstract_y}; AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -409,14 +410,14 @@ TEST_F(TestPrim, test_env_setitem) { // return env_getitem(e, embed(x), z) TEST_F(TestPrim, test_env_getitem) { FuncGraphPtr graph_embed = MakeFuncGraph(prim::kPrimEmbed, 1); - AbstractBasePtr abstract_x = FromValue(1, false); + AbstractBasePtr abstract_x = FromValue(static_cast(1), false); AbstractBasePtrList args_spec_list = {abstract_x}; AbstractBasePtr embed_x = engine_->Run(graph_embed, args_spec_list).inferred->abstract(); FuncGraphPtr graph_setitem = MakeFuncGraph(prim::kPrimEnvSetItem, 3); AbstractBasePtr abstract_env = ToAbstract(newenv); - AbstractBasePtr abstract_y = FromValue(2, false); + AbstractBasePtr abstract_y = FromValue(static_cast(2), false); args_spec_list = {abstract_env, embed_x, abstract_y}; AbstractBasePtr res = engine_->Run(graph_setitem, args_spec_list).inferred->abstract(); @@ -425,7 +426,7 @@ TEST_F(TestPrim, test_env_getitem) { FuncGraphPtr graph_getitem = MakeFuncGraph(prim::kPrimEnvGetItem, 3); - AbstractBasePtr abstract_z = FromValue(3, false); + AbstractBasePtr abstract_z = FromValue(static_cast(3), false); args_spec_list = {res, embed_x, abstract_z}; res = engine_->Run(graph_getitem, args_spec_list).inferred->abstract(); @@ -439,21 +440,21 @@ TEST_F(TestPrim, test_env_getitem) { // return env_add(e1, e2) TEST_F(TestPrim, test_env_add) { FuncGraphPtr graph_embed = MakeFuncGraph(prim::kPrimEmbed, 1); - AbstractBasePtr abstract_x = FromValue(1, false); + AbstractBasePtr abstract_x = FromValue(static_cast(1), false); AbstractBasePtrList args_spec_list = {abstract_x}; AbstractBasePtr embed_x = engine_->Run(graph_embed, args_spec_list).inferred->abstract(); FuncGraphPtr graph_setitem = MakeFuncGraph(prim::kPrimEnvSetItem, 3); AbstractBasePtr abstract_env = ToAbstract(newenv); - AbstractBasePtr abstract_y = FromValue(2, false); + AbstractBasePtr abstract_y = FromValue(static_cast(2), false); args_spec_list = {abstract_env, embed_x, abstract_y}; AbstractBasePtr abstract_e1 = engine_->Run(graph_setitem, args_spec_list).inferred->abstract(); AbstractBasePtr exp = std::make_shared(kAnyValue, std::make_shared()); ASSERT_TRUE(*abstract_e1 == *exp); - AbstractBasePtr abstract_z = FromValue(3, false); + AbstractBasePtr abstract_z = FromValue(static_cast(3), false); args_spec_list = {abstract_env, embed_x, abstract_z}; AbstractBasePtr abstract_e2 = engine_->Run(graph_setitem, args_spec_list).inferred->abstract(); @@ -468,7 +469,7 @@ TEST_F(TestPrim, test_env_add) { TEST_F(TestPrim, test_relu) { PrimitivePtr relu = prim::kPrimRelu; - relu->AddAttr("T", MakeValue(static_cast(kNumberTypeFloat64))); + relu->AddAttr("T", MakeValue(static_cast(kNumberTypeFloat64))); FuncGraphPtr func_graph = MakeFuncGraph(relu, 1); AbstractBasePtr expected = UTPrimUtils::ArrayFloat64Of({2, 2, 2, 3}); // NCHW @@ -501,8 +502,8 @@ TEST_F(TestPrim, test_conv2d1) { std::shared_ptr func_graph = getPyFun.CallAndParseRet("test_conv2d", 64, kernel_size, 0, 2, 1); // NCHW - std::vector inputs_dims = {2, 20, 32, 32}; - std::vector weight_dims = {64, 20, 5, 5}; + std::vector inputs_dims = {2, 20, 32, 32}; + std::vector weight_dims = {64, 20, 5, 5}; tensor::TensorPtr inputs = std::make_shared(); inputs->set_data_type(kNumberTypeInt32); @@ -518,7 +519,7 @@ TEST_F(TestPrim, test_conv2d1) { AbstractBasePtr expected = abstract_inputs->Clone(); // NCHW - std::vector shape = {2, 64, 14, 14}; + std::vector shape = {2, 64, 14, 14}; expected->set_shape(std::make_shared(shape)); AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -634,11 +635,11 @@ TEST_F(TestPrim, test_fused_batch_norm) { FuncGraphPtr func_graph = MakeFuncGraph(fused_batch_norm, 5); // NCHW - std::vector inputs_dims = {128, 64, 32, 64}; - std::vector scale_dims = {64}; - std::vector offset_dims = {64}; - std::vector mean_dims = {64}; - std::vector variance_dims = {64}; + std::vector inputs_dims = {128, 64, 32, 64}; + std::vector scale_dims = {64}; + std::vector offset_dims = {64}; + std::vector mean_dims = {64}; + std::vector variance_dims = {64}; tensor::TensorPtr inputs = std::make_shared(); inputs->set_data_type(kNumberTypeFloat32); @@ -697,7 +698,7 @@ TEST_F(TestPrim, test_pooling) { pooling->AddAttr("ceil_mode", MakeValue(0)); FuncGraphPtr func_graph = MakeFuncGraph(pooling, 1); - std::vector inputs_dims = {8, 64, 3, 3}; + std::vector inputs_dims = {8, 64, 3, 3}; auto inputs = std::make_shared(); inputs->set_data_type(kNumberTypeFloat32); inputs->set_shape(inputs_dims); @@ -706,7 +707,7 @@ TEST_F(TestPrim, test_pooling) { AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); AbstractBasePtr expected = abstract_input->Clone()->Broaden(); - std::vector expected_dims = {8, 64, 2, 2}; + std::vector expected_dims = {8, 64, 2, 2}; expected->set_shape(std::make_shared(expected_dims)); MS_LOG(INFO) << "result: " << res->ToString(); MS_LOG(INFO) << "expected: " << expected->ToString(); @@ -715,7 +716,7 @@ TEST_F(TestPrim, test_pooling) { TEST_F(TestPrim, test_hastype) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; TypePtr v2 = std::make_shared(); AbstractBasePtr abstract_v1 = FromValue(v1, false); @@ -791,8 +792,8 @@ TEST_F(TestPrim, test_tuple_reversed) { TEST_F(TestPrim, test_list_getitem) { AbstractBasePtrList args_spec_list; - int v1 = 2; - int v2 = 1; + int64_t v1 = 2; + int64_t v2 = 1; AbstractBasePtr elem = FromValue(v1, false); AbstractBasePtr elem2 = FromValue(v2, false); @@ -811,8 +812,8 @@ TEST_F(TestPrim, test_list_getitem) { } TEST_F(TestPrim, test_list_setitem) { - int v1 = 1; - int v2 = 2; + int64_t v1 = 1; + int64_t v2 = 2; AbstractBasePtr elem1 = FromValue(v1, false); AbstractBasePtr elem2 = FromValue(v2, false); @@ -836,7 +837,7 @@ TEST_F(TestPrim, test_list_setitem) { } TEST_F(TestPrim, test_list_append) { - int v1 = 1; + int64_t v1 = 1; AbstractBasePtr elem1 = FromValue(v1, false); AbstractBasePtr elem2 = FromValue(v1, false); @@ -857,8 +858,8 @@ TEST_F(TestPrim, test_list_append) { } TEST_F(TestPrim, test_tuple_setitem) { - int v1 = 1; - int v2 = 2; + int64_t v1 = 1; + int64_t v2 = 2; AbstractBasePtr elem1 = FromValue(v1, false); AbstractBasePtr elem2 = FromValue(v2, false); @@ -883,8 +884,8 @@ TEST_F(TestPrim, test_tuple_setitem) { TEST_F(TestPrim, test_make_list) { AbstractBasePtrList args_spec_list; - int v1 = 2; - int v2 = 2; + int64_t v1 = 2; + int64_t v2 = 2; AbstractBasePtr abstract_v1 = FromValue(v1, false); AbstractBasePtr abstract_v2 = FromValue(v2, false); @@ -903,8 +904,8 @@ TEST_F(TestPrim, test_make_list) { TEST_F(TestPrim, test_make_range) { AbstractBasePtrList args_spec_list; - int v1 = 1; - int v2 = 4; + int64_t v1 = 1; + int64_t v2 = 4; AbstractBasePtr abstract_v1 = FromValue(v1); AbstractBasePtr abstract_v2 = FromValue(v2); @@ -933,9 +934,9 @@ TEST_F(TestPrim, test_layernorm) { std::shared_ptr func_graph = MakeFuncGraph(layerNorm, 3); - std::vector inputs_dims = {128, 64, 32, 64}; - std::vector mean_var_dims = {128, 64, 32, 1}; - std::vector params_dims = {64, 32, 64}; + std::vector inputs_dims = {128, 64, 32, 64}; + std::vector mean_var_dims = {128, 64, 32, 1}; + std::vector params_dims = {64, 32, 64}; tensor::TensorPtr inputs = std::make_shared(); inputs->set_data_type(kNumberTypeFloat32); @@ -993,7 +994,7 @@ TEST_F(TestPrim, test_DropoutGenMask) { auto arg0 = UTPrimUtils::ShapeOf({5, 5, 5, 5}); - std::vector keep_prob_shape = {}; + std::vector keep_prob_shape = {}; tensor::TensorPtr keep_prob = std::make_shared(0.5f); keep_prob->set_data_type(kNumberTypeFloat32); keep_prob->set_shape(keep_prob_shape); @@ -1007,7 +1008,7 @@ TEST_F(TestPrim, test_DropoutGenMask) { // should return a tensor with on dimension of 79 elements AbstractBasePtr expected = std::make_shared(std::make_shared(kAnyValue, kUInt8), - std::make_shared(std::vector{79})); + std::make_shared(std::vector{79})); AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); MS_LOG(INFO) << "res=" << res->ToString(); @@ -1019,14 +1020,14 @@ TEST_F(TestPrim, test_dropout) { std::shared_ptr env = python_adapter::set_python_scoped(); std::shared_ptr func_graph = getPyFun.CallAndParseRet("test_dropout"); - std::vector inputs_dims = {2, 20, 32, 32}; + std::vector inputs_dims = {2, 20, 32, 32}; tensor::TensorPtr inputs = std::make_shared(); inputs->set_data_type(kNumberTypeFloat32); inputs->set_shape(inputs_dims); AbstractBasePtr abstract_inputs = FromValue(inputs, true); - std::vector keep_prob_shape = {}; + std::vector keep_prob_shape = {}; tensor::TensorPtr keep_prob = std::make_shared(0.5f); keep_prob->set_data_type(kNumberTypeFloat32); keep_prob->set_shape(keep_prob_shape); @@ -1036,7 +1037,7 @@ TEST_F(TestPrim, test_dropout) { AbstractBasePtr expected = abstract_inputs->Clone(); // NCHW - std::vector shape = {2, 20, 32, 32}; + std::vector shape = {2, 20, 32, 32}; expected->set_shape(std::make_shared(shape)); AbstractBasePtr res = engine_->Run(func_graph, args_spec_list).inferred->abstract(); @@ -1102,8 +1103,8 @@ TEST_F(TestPrim, test_DictGetItem) { std::shared_ptr func_graph = MakeFuncGraph(dictGetItem, 2); std::vector> tensor_map = { - {"x", std::make_shared(kNumberTypeInt32, std::vector{2, 3, 4})}, - {"y", std::make_shared(kNumberTypeInt32, std::vector{2, 1, 4})}}; + {"x", std::make_shared(kNumberTypeInt32, std::vector{2, 3, 4})}, + {"y", std::make_shared(kNumberTypeInt32, std::vector{2, 1, 4})}}; ValueDictionary value_dict(tensor_map); AbstractBasePtr array_dict = value_dict.ToAbstract(); AbstractBasePtr key = abstract::FromValue("x"); diff --git a/tests/ut/cpp/pipeline/static_analysis/specialize_test.cc b/tests/ut/cpp/pipeline/static_analysis/specialize_test.cc index 1a320d72ed5..52e22d5d321 100644 --- a/tests/ut/cpp/pipeline/static_analysis/specialize_test.cc +++ b/tests/ut/cpp/pipeline/static_analysis/specialize_test.cc @@ -124,7 +124,7 @@ TEST_F(TestSpecializeGraph, test_specialize) { AbstractBasePtrList args_spec_list; MS_LOG(INFO) << "Begin TestSpecializeGraph call other graph."; MS_LOG(INFO) << "" << graph_f_->get_return()->ToString(); - AbstractBasePtr abstract_v1 = FromValue(1, false); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), false); args_spec_list.push_back(abstract_v1); AnalysisResult result = engine_->Run(graph_f_, args_spec_list); @@ -133,8 +133,8 @@ TEST_F(TestSpecializeGraph, test_specialize) { TEST_F(TestSpecializeGraph, test_specialize1) { AbstractBasePtrList args_spec_list; - AbstractBasePtr abstract_v1 = FromValue(1, true); - AbstractBasePtr abstract_v2 = FromValue(2, true); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), true); + AbstractBasePtr abstract_v2 = FromValue(static_cast(2), true); args_spec_list.push_back(abstract_v1); args_spec_list.push_back(abstract_v2); AnalysisResult result = engine_->Run(graph_alpha_, args_spec_list); @@ -214,8 +214,8 @@ void TestSpecializeMetaFuncGraph::TearDown() {} TEST_F(TestSpecializeMetaFuncGraph, test_specialize) { AbstractBasePtrList args_spec_list; std::cout << graph_->get_return()->ToString() << std::endl; - AbstractBasePtr abstract_v1 = FromValue(1, true); - AbstractBasePtr abstract_v2 = FromValue(2, true); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), true); + AbstractBasePtr abstract_v2 = FromValue(static_cast(2), true); args_spec_list.push_back(abstract_v1); args_spec_list.push_back(abstract_v2); AnalysisResult result = engine_->Run(graph_, args_spec_list); diff --git a/tests/ut/cpp/pipeline/static_analysis/static_analysis_test.cc b/tests/ut/cpp/pipeline/static_analysis/static_analysis_test.cc index 78d3a7083a6..fa86d5549a2 100644 --- a/tests/ut/cpp/pipeline/static_analysis/static_analysis_test.cc +++ b/tests/ut/cpp/pipeline/static_analysis/static_analysis_test.cc @@ -129,7 +129,7 @@ static FuncGraphPtr MakeFuncGraph(PrimitivePtr prim) { * @mindspore * def f(x, y): * return x + y - * print(f(1,2)) + * print64_t(f(1,2)) */ FuncGraphPtr func_graph = std::make_shared(); ParameterPtr x = func_graph->add_parameter(); @@ -153,8 +153,8 @@ void TestInfer::TearDown() { TEST_F(TestInfer, test_inferred_scalar_add) { AbstractBasePtrList args_spec_list; - int v1 = 1; - int v2 = 2; + int64_t v1 = 1; + int64_t v2 = 2; AbstractBasePtr abstract_v1 = FromValue(v1, false); AbstractBasePtr abstract_v2 = FromValue(v2, false); @@ -259,7 +259,7 @@ TEST_F(TestInferGraph, test_inferred) { AbstractBasePtrList args_spec_list; MS_LOG(INFO) << "Begin TestInferGraph call other graph."; MS_LOG(INFO) << "" << graph_f_->get_return()->ToString(); - AbstractBasePtr abstract_v1 = FromValue(1, false); + AbstractBasePtr abstract_v1 = FromValue(static_cast(1), false); args_spec_list.push_back(abstract_v1); AbstractBasePtr abs_base_got = engine_->Run(graph_f_, args_spec_list).inferred->abstract(); ASSERT_TRUE(abs_base_got.get() == abstract_v1.get()); @@ -268,7 +268,7 @@ TEST_F(TestInferGraph, test_inferred) { MS_LOG(INFO) << "Begin TestInferGraph closure."; MS_LOG(INFO) << "" << graph_alpha_->get_return()->ToString(); - AbstractBasePtr abstract_v2 = FromValue(2, false); + AbstractBasePtr abstract_v2 = FromValue(static_cast(2), false); args_spec_list.clear(); args_spec_list.push_back(abstract_v1); args_spec_list.push_back(abstract_v2); @@ -351,7 +351,7 @@ void TestInferMetaGraph::TearDown() { TEST_F(TestInferMetaGraph, test_inferred) { AbstractBasePtrList args_spec_list; - int v1 = 1; + int64_t v1 = 1; std::cout << "Begin TestInferGraph." << std::endl; std::cout << func_graph_->get_return()->ToString() << std::endl; AbstractBasePtr abstract_v1 = FromValue(v1, false); @@ -380,8 +380,8 @@ void TestInferUniform::TearDown() { TEST_F(TestInferUniform, test_inferred_scalar_add) { AbstractBasePtrList args_spec; - int v1 = 1; - int v2 = 2; + int64_t v1 = 1; + int64_t v2 = 2; AbstractBasePtr abstract_v1 = FromValue(v1, false); AbstractBasePtr abstract_v2 = FromValue(v2, false); @@ -392,7 +392,7 @@ TEST_F(TestInferUniform, test_inferred_scalar_add) { FuncGraphPtr func_graph = MakeFuncGraph(prim_scalar_add); AbstractBasePtr abs_base_got = engine_->Run(func_graph, args_spec).inferred->abstract(); ASSERT_TRUE(*(abs_base_got->GetTypeTrack()) == *(abstract_v1->GetTypeTrack())); - ASSERT_TRUE(abs_base_got->GetTypeTrack()->type_id() == kNumberTypeInt32); + ASSERT_TRUE(abs_base_got->GetTypeTrack()->type_id() == kNumberTypeInt64); } @@ -427,7 +427,7 @@ TEST_F(TestEvalOnePrim, test_scalar_add) { class TestGraphEval : public UT::Common { public: - TestGraphEval() : getPyFun("gtest_input.pipeline.infer.infer_test", true){}; + TestGraphEval() : getPyFun("gtest_input.pipeline.infer.infer_test", true){}; void SetUp(); void TearDown(); AnalysisEnginePtr engine_; diff --git a/tests/ut/cpp/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc index 58b810a3e1f..24caa16577e 100644 --- a/tests/ut/cpp/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/buffer_fusion/buffer_fusion_test.cc @@ -48,7 +48,7 @@ class TestHWBufferFusion : public BackendCommon { TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_tbe_eltwise_fusion_1", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -107,8 +107,8 @@ TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_1) { TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_tbe_eltwise_fusion_2", "before"); - std::vector shp{32, 10}; - std::vector shp_bias{10}; + std::vector shp{32, 10}; + std::vector shp_bias{10}; auto x_abstract = std::make_shared(kFloat32, shp); auto y_abstract = std::make_shared(kFloat32, shp_bias); AbstractBasePtrList args_spec_list{x_abstract, y_abstract}; @@ -199,7 +199,7 @@ TEST_F(TestHWBufferFusion, test_tbe_eltwise_fusion_2) { TEST_F(TestHWBufferFusion, test_tbe_reduce_eltwise_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_tbe_reduce_eltwise_fusion", "before"); - std::vector shp{32, 10}; + std::vector shp{32, 10}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -289,8 +289,8 @@ TEST_F(TestHWBufferFusion, test_tbe_reduce_eltwise_fusion) { TEST_F(TestHWBufferFusion, test_tbe_matmul_eltwise_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_tbe_matmul_eltwise_fusion", "before"); - std::vector x_shp{2048, 768}; - std::vector y_shp{768, 768}; + std::vector x_shp{2048, 768}; + std::vector y_shp{768, 768}; auto x_abstract = std::make_shared(kFloat32, x_shp); auto y_abstract = std::make_shared(kFloat32, y_shp); AbstractBasePtrList args_spec_list{x_abstract, y_abstract}; diff --git a/tests/ut/cpp/pre_activate/ascend/enhancer/insert_memcpy_async_for_hccl_op_test.cc b/tests/ut/cpp/pre_activate/ascend/enhancer/insert_memcpy_async_for_hccl_op_test.cc index ceafdade726..dadf84c5950 100644 --- a/tests/ut/cpp/pre_activate/ascend/enhancer/insert_memcpy_async_for_hccl_op_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/enhancer/insert_memcpy_async_for_hccl_op_test.cc @@ -56,7 +56,7 @@ TEST_F(TestHWInsertMemcpyForHccl, test_cond1_no_insert) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_insert_memcpy_async_for_hccl_op_cond1", "before2"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -77,7 +77,7 @@ TEST_F(TestHWInsertMemcpyForHccl, test_cond2) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_insert_memcpy_async_for_hccl_op_cond2", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -103,7 +103,7 @@ TEST_F(TestHWInsertMemcpyForHccl, test_cond3) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_insert_memcpy_async_for_hccl_op_cond3", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -125,7 +125,7 @@ TEST_F(TestHWInsertMemcpyForHccl, test_cond4) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_insert_memcpy_async_for_hccl_op_cond4", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -152,7 +152,7 @@ TEST_F(TestHWInsertMemcpyForHccl, test_cond5) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_insert_memcpy_async_for_hccl_op_cond5", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/format_type/check_consistency_test.cc b/tests/ut/cpp/pre_activate/ascend/format_type/check_consistency_test.cc index 89d680f442b..20c431e7eab 100644 --- a/tests/ut/cpp/pre_activate/ascend/format_type/check_consistency_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/format_type/check_consistency_test.cc @@ -45,7 +45,7 @@ TEST_F(TestHWCheckConsistency, test_check_consistency_for_format) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_check_consistency", "graph"); // renormalize func_graph to infer and set shape and type information. - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); g->parameters()[0]->set_abstract(x_abstract); auto g_cast = g->get_return()->input(1); @@ -106,7 +106,7 @@ TEST_F(TestHWCheckConsistency, test_check_consistency_for_dtype) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_check_consistency", "graph"); // Renormalize func_graph to infer and set shape and type information. - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); g->parameters()[0]->set_abstract(x_abstract); auto g_cast = g->get_return()->input(1); diff --git a/tests/ut/cpp/pre_activate/ascend/format_type/insert_cast_test.cc b/tests/ut/cpp/pre_activate/ascend/format_type/insert_cast_test.cc index c8909455d32..4725133b4e9 100644 --- a/tests/ut/cpp/pre_activate/ascend/format_type/insert_cast_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/format_type/insert_cast_test.cc @@ -46,7 +46,7 @@ TEST_F(TestHWInsertCast, test_insert_cast_op_for_single_output) { * return res */ FuncGraphPtr g = getPyFun_.CallAndParseRet("test_insert_cast_op_for_single_output", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -103,7 +103,7 @@ TEST_F(TestHWInsertCast, test_insert_cast_op_for_multiple_output) { * return res */ FuncGraphPtr g = getPyFun_.CallAndParseRet("test_insert_cast_op_for_multiple_output", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/format_type/insert_trans_op_test.cc b/tests/ut/cpp/pre_activate/ascend/format_type/insert_trans_op_test.cc index 3be96b9fed7..35f0409e931 100644 --- a/tests/ut/cpp/pre_activate/ascend/format_type/insert_trans_op_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/format_type/insert_trans_op_test.cc @@ -39,7 +39,7 @@ class TestHWInsertTransOp : public BackendCommon { ~TestHWInsertTransOp() override = default; FuncGraphPtr GetSingleOutputGraph(std::string func_name, std::string sub_func_name, std::string format) { FuncGraphPtr g = getPyFun_.CallAndParseRet(func_name, sub_func_name); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto fg = GetKernelGraph(g, args_spec_list); @@ -60,7 +60,7 @@ class TestHWInsertTransOp : public BackendCommon { } FuncGraphPtr GetMutilpleOutputGraph(std::string func_name, std::string sub_func_name, std::string format) { FuncGraphPtr g = getPyFun_.CallAndParseRet(func_name, sub_func_name); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto fg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/format_type/merge_cast_to_op_test.cc b/tests/ut/cpp/pre_activate/ascend/format_type/merge_cast_to_op_test.cc index 69e7fa8b278..257d28b8bff 100644 --- a/tests/ut/cpp/pre_activate/ascend/format_type/merge_cast_to_op_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/format_type/merge_cast_to_op_test.cc @@ -69,7 +69,7 @@ TEST_F(TestHWMergeCastToOp, test_merge_cast_to_next_op) { ASSERT_NE(g, nullptr); // set abstract because four2five node cannot infer - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); g->parameters()[0]->set_abstract(x_abstract); g->get_return()->set_abstract(x_abstract); @@ -131,7 +131,7 @@ TEST_F(TestHWMergeCastToOp, test_merge_cast_to_prior_op) { ASSERT_NE(g, nullptr); // set abstract because five2four node cannot infer - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); g->parameters()[0]->set_abstract(x_abstract); g->get_return()->set_abstract(x_abstract); diff --git a/tests/ut/cpp/pre_activate/ascend/format_type/remove_internal_output_test.cc b/tests/ut/cpp/pre_activate/ascend/format_type/remove_internal_output_test.cc index 09bed0a913c..14cbb8eab08 100644 --- a/tests/ut/cpp/pre_activate/ascend/format_type/remove_internal_output_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/format_type/remove_internal_output_test.cc @@ -42,7 +42,7 @@ class TestHWRemoveInternalOutput : public BackendCommon { KernelGraphPtr GetSingleOutputGraph(const std::string &func_name, const std::string &sub_func_name) { FuncGraphPtr g = getPyFun_.CallAndParseRet(func_name, sub_func_name); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -64,7 +64,7 @@ class TestHWRemoveInternalOutput : public BackendCommon { KernelGraphPtr GetMutilpleOutputGraph(const std::string &func_name, const std::string &sub_func_name) { FuncGraphPtr g = getPyFun_.CallAndParseRet(func_name, sub_func_name); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/addn_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/addn_fission_test.cc index 8ec2b22a795..092ff9f82c7 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/addn_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/addn_fission_test.cc @@ -35,7 +35,7 @@ class TestHWAddnFission : public BackendCommon { TEST_F(TestHWAddnFission, test_addn_fission_divided_by_2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_addn_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -60,7 +60,7 @@ TEST_F(TestHWAddnFission, test_addn_fission_divided_by_2) { TEST_F(TestHWAddnFission, test_addn_fission_divided_by_3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_addn_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -85,7 +85,7 @@ TEST_F(TestHWAddnFission, test_addn_fission_divided_by_3) { TEST_F(TestHWAddnFission, test_addn_fission_divided_by_4) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_addn_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -110,7 +110,7 @@ TEST_F(TestHWAddnFission, test_addn_fission_divided_by_4) { TEST_F(TestHWAddnFission, test_addn_fission_divided_by_8) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_addn_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -135,7 +135,7 @@ TEST_F(TestHWAddnFission, test_addn_fission_divided_by_8) { TEST_F(TestHWAddnFission, test_addn_fission_divided_by_9) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_addn_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_bert_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_bert_fission_test.cc index f793e0371bf..11a016f435d 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_bert_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_bert_fission_test.cc @@ -31,9 +31,9 @@ class TestHWBatchNormBertFission : public BackendCommon { TEST_F(TestHWBatchNormBertFission, test_fused_batch_norm_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batch_norm_bert_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 4; ++i) { @@ -71,9 +71,9 @@ TEST_F(TestHWBatchNormBertFission, test_fused_batch_norm_fission) { TEST_F(TestHWBatchNormBertFission, test_fused_batch_norm_no_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batch_norm_bert_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 4; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_grad_infer_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_grad_infer_fission_test.cc index 80f30c89386..2acca557c48 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_grad_infer_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/batch_norm_grad_infer_fission_test.cc @@ -32,7 +32,7 @@ class TestHWBatchNormGradInferFission : public BackendCommon { TEST_F(TestHWBatchNormGradInferFission, test_batch_norm_grad_infer_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batch_norm_grad_infer_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 5; ++i) { @@ -53,7 +53,7 @@ TEST_F(TestHWBatchNormGradInferFission, test_batch_norm_grad_infer_fission) { TEST_F(TestHWBatchNormGradInferFission, test_batch_norm_grad_infer_no_fission1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batch_norm_grad_infer_fission", "before_is_training"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 5; ++i) { @@ -72,7 +72,7 @@ TEST_F(TestHWBatchNormGradInferFission, test_batch_norm_grad_infer_no_fission1) TEST_F(TestHWBatchNormGradInferFission, test_batch_norm_grad_infer_no_fission2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batch_norm_grad_infer_fission", "before_output3_not_null"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 5; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_grad_split_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_grad_split_test.cc index f0a5a857b94..dbce1c5f660 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_grad_split_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_grad_split_test.cc @@ -43,8 +43,8 @@ TEST_F(TestHWBnGradSplit, test_bn_grad_split_tbe) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_bn_grad_split", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; - std::vector shp_b{64}; + std::vector shp_x{1, 64, 112, 112}; + std::vector shp_b{64}; auto x_abstract = std::make_shared(kFloat32, shp_x); auto b_abstract = std::make_shared(kFloat32, shp_b); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, b_abstract, b_abstract, b_abstract}; diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_split_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_split_test.cc index 9f4f31bf827..581b53761f3 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_split_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/bn_split_test.cc @@ -52,8 +52,8 @@ TEST_F(TestHWBnSplit, test_bn_split_tbe) { */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_bn_split_tbe", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; - std::vector shp_b{64}; + std::vector shp_x{1, 64, 112, 112}; + std::vector shp_b{64}; auto x_abstract = std::make_shared(kFloat32, shp_x); auto b_abstract = std::make_shared(kFloat32, shp_b); AbstractBasePtrList args_spec_list{x_abstract, b_abstract, b_abstract, b_abstract, b_abstract}; diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/concat_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/concat_fission_test.cc index 0198a99a592..8cf6f95cc42 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/concat_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/concat_fission_test.cc @@ -35,7 +35,7 @@ class TestHWConcatFission : public BackendCommon { TEST_F(TestHWConcatFission, test_concat_fission_divided_by_2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_concat_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -60,7 +60,7 @@ TEST_F(TestHWConcatFission, test_concat_fission_divided_by_2) { TEST_F(TestHWConcatFission, test_concat_fission_divided_by_3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_concat_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -85,7 +85,7 @@ TEST_F(TestHWConcatFission, test_concat_fission_divided_by_3) { TEST_F(TestHWConcatFission, test_concat_fission_divided_by_4) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_concat_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -110,7 +110,7 @@ TEST_F(TestHWConcatFission, test_concat_fission_divided_by_4) { TEST_F(TestHWConcatFission, test_concat_fission_divided_by_8) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_concat_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -135,7 +135,7 @@ TEST_F(TestHWConcatFission, test_concat_fission_divided_by_8) { TEST_F(TestHWConcatFission, test_concat_fission_divided_by_9) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_concat_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc index c726142e999..579c23c8448 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/lars_v2_fission_test.cc @@ -33,7 +33,7 @@ TEST_F(TestHWLarsV2Fission, test_fission) { EXPECT_NE(g, nullptr); // set abstract for all nodes in g - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); g->get_return()->input(1)->set_abstract(x_abstract); for (auto &p: g->parameters()){ diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/layer_norm_grad_split_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/layer_norm_grad_split_test.cc index 4303485d854..509c2f62281 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/layer_norm_grad_split_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/layer_norm_grad_split_test.cc @@ -43,8 +43,8 @@ TEST_F(TestHWLayerNormGradSplit, test_layer_norm_grad_split) { get_py_fun_.SetDoResolve(true); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_layer_norm_grad_split", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 64, 112, 112}; - std::vector shp_b{64}; + std::vector shp_x{1, 64, 112, 112}; + std::vector shp_b{64}; auto x_abstract = std::make_shared(kFloat32, shp_x); auto b_abstract = std::make_shared(kFloat32, shp_b); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, b_abstract, b_abstract, b_abstract}; diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/pack_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/pack_fission_test.cc index d22e55c927f..2ee57434635 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/pack_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/pack_fission_test.cc @@ -35,7 +35,7 @@ class TestHWPackFission : public BackendCommon { TEST_F(TestHWPackFission, test_pack_fission_divided_by_3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_pack_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { @@ -59,7 +59,7 @@ TEST_F(TestHWPackFission, test_pack_fission_divided_by_3) { TEST_F(TestHWPackFission, test_pack_fission_divided_by_4) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_pack_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/reduce_min_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/reduce_min_fission_test.cc index e1cec41c966..6c017c4f51e 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/reduce_min_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/reduce_min_fission_test.cc @@ -36,7 +36,7 @@ class TestHWOptReduceMinFission : public BackendCommon { TEST_F(TestHWOptReduceMinFission, test_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_reduce_min_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{32, 32, 32, 32}; + std::vector shp{32, 32, 32, 32}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; args_spec_list.push_back(x_abstract); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/single_batch_norm_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/single_batch_norm_fission_test.cc index 9f84f226780..b564140e5e2 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/single_batch_norm_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/single_batch_norm_fission_test.cc @@ -32,9 +32,9 @@ class TestHWSingleBatchNormFission : public BackendCommon { TEST_F(TestHWSingleBatchNormFission, test_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_single_batch_norm_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 4; ++i) { @@ -55,9 +55,9 @@ TEST_F(TestHWSingleBatchNormFission, test_fission) { TEST_F(TestHWSingleBatchNormFission, test_no_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_single_batch_norm_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 4; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/split_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/split_fission_test.cc index 30de43be4e4..94062b00853 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/split_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/split_fission_test.cc @@ -35,7 +35,7 @@ class TestHWSplitFission : public BackendCommon { TEST_F(TestHWSplitFission, test_split_fission_divided_by_3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_split_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp{512, 3, 1}; + std::vector shp{512, 3, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; args_spec_list.push_back(x_abstract); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/tensor_scatter_update_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/tensor_scatter_update_fission_test.cc index 1c928b581d3..6b2dc15d6ed 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/tensor_scatter_update_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/tensor_scatter_update_fission_test.cc @@ -33,9 +33,9 @@ class TestHWOptTensorScatterUpdateFission : public BackendCommon { TEST_F(TestHWOptTensorScatterUpdateFission, test_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_tensor_scatter_update_fission", "before"); EXPECT_NE(g, nullptr); - std::vector shp1{2, 3}; - std::vector shp2{2, 2}; - std::vector shp3{2}; + std::vector shp1{2, 3}; + std::vector shp2{2, 2}; + std::vector shp3{2}; auto inputx = std::make_shared(kFloat32, shp1); auto indices = std::make_shared(kInt32, shp2); auto update = std::make_shared(kFloat32, shp3); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/topk_split_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/topk_split_test.cc index 2ab614d4c29..308bffc050d 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/topk_split_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/topk_split_test.cc @@ -68,7 +68,7 @@ TEST_F(TestHWTopKSplit, test_topk_split) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_topk_split", "before"); - std::vector shp{4, 4}; + std::vector shp{4, 4}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kernel_graph = GetKernelGraph(g, args_spec_list); @@ -100,7 +100,7 @@ TEST_F(TestHWTopKSplit, test_topk_no_split) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_topk_split", "before"); - std::vector shp{4, 4}; + std::vector shp{4, 4}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kernel_graph = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/transdata_split_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/transdata_split_test.cc index a199695fdce..91c2a7c1199 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/transdata_split_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/transdata_split_test.cc @@ -106,7 +106,7 @@ TEST_F(TestHWTransdataSplit, test_transdata_split_fraz_nchw) { MS_EXCEPTION_IF_NULL(ms_context); ms_context->set_param(MS_CTX_EXECUTION_MODE, kGraphMode); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_transdata_split_fraz_nchw", "before"); - std::vector shp{2, 4, 8, 16}; + std::vector shp{2, 4, 8, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -154,7 +154,7 @@ TEST_F(TestHWTransdataSplit, test_transdata_split_nchw_fraz) { * return transdata */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_transdata_split_nchw_fraz", "before"); - std::vector shp{2, 4, 8, 16}; + std::vector shp{2, 4, 8, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fission/unsorted_segment_sum_fission_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fission/unsorted_segment_sum_fission_test.cc index 02a4aa69fae..92a98338f93 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fission/unsorted_segment_sum_fission_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fission/unsorted_segment_sum_fission_test.cc @@ -32,7 +32,7 @@ class TestHWUnsortedSegmentSumFission : public BackendCommon { TEST_F(TestHWUnsortedSegmentSumFission, test_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_unsorted_segment_sum_fission", "before1"); EXPECT_NE(g, nullptr); - std::vector shp_x{16, 1}; + std::vector shp_x{16, 1}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -50,7 +50,7 @@ TEST_F(TestHWUnsortedSegmentSumFission, test_fission) { TEST_F(TestHWUnsortedSegmentSumFission, test_no_fission) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_unsorted_segment_sum_fission", "before2"); EXPECT_NE(g, nullptr); - std::vector shp_x{16, 2}; + std::vector shp_x{16, 2}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc index add4ef8e41a..112754b4207 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc @@ -48,7 +48,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_fusion) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_fusion", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -86,7 +86,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_cond1_fusion) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_fusion", "before_cond1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -124,7 +124,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_cond2_fusion) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_fusion", "before_cond2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -162,7 +162,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_cond3_fusion) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_fusion", "before_cond3"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -200,7 +200,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_cond4_fusion) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_fusion", "before_cond4"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -220,7 +220,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_cond4_fusion) { TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -240,7 +240,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_fusion) { TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond1_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -260,7 +260,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond1_fusion) { TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond2_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -280,7 +280,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond2_fusion) { TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond3_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond3"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { @@ -300,7 +300,7 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond3_fusion) { TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond4_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond4"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 10; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_with_decay_rule_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_with_decay_rule_test.cc index 8cdb03d870c..777c30f2a40 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_with_decay_rule_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_with_decay_rule_test.cc @@ -33,7 +33,7 @@ class TestHWOptimizeAdamApplyOneWithDecayRule : public BackendCommon { TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_rule_cond1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_rule", "before_cond1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -54,7 +54,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_r TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_rule_cond2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_rule", "before_cond2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -75,7 +75,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_r TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_rule_cond3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_rule", "before_cond3"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -96,7 +96,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_r TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_rule_cond4) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_rule", "before_cond4"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -117,7 +117,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_r TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_rule_cond5) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_rule", "before_cond5"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -138,7 +138,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_r TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_assign_rule_cond1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_assign_rule", "before_cond1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -159,7 +159,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_a TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_assign_rule_cond2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_assign_rule", "before_cond2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -180,7 +180,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_a TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_assign_rule_cond3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_assign_rule", "before_cond3"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -201,7 +201,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_a TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_assign_rule_cond4) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_assign_rule", "before_cond4"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { @@ -222,7 +222,7 @@ TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_a TEST_F(TestHWOptimizeAdamApplyOneWithDecayRule, test_adam_apply_one_with_decay_assign_rule_cond5) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_with_decay_assign_rule", "before_cond5"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 11; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/add_input_to_output_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/add_input_to_output_test.cc index 9a832ec21bc..cb427449b14 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/add_input_to_output_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/add_input_to_output_test.cc @@ -44,7 +44,7 @@ class MockOpFinder : public OpFinder { TEST_F(TestHWAddInputToOutput, test_add_input_to_output) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_add_input_to_output", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 5; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnorm_to_bninfer_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnorm_to_bninfer_test.cc index d9d0baf7be2..8bacb209145 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnorm_to_bninfer_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnorm_to_bninfer_test.cc @@ -32,9 +32,9 @@ class TestHWOptimizeBatchNorm2BNInfer : public BackendCommon { TEST_F(TestHWOptimizeBatchNorm2BNInfer, test_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batchnorm_to_bninfer", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract, y_abstract, y_abstract, y_abstract, y_abstract}; auto fg = GetKernelGraph(g, args_spec_list); @@ -52,9 +52,9 @@ TEST_F(TestHWOptimizeBatchNorm2BNInfer, test_fusion) { TEST_F(TestHWOptimizeBatchNorm2BNInfer, test_no_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batchnorm_to_bninfer", "no_fusion"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract, y_abstract, y_abstract, y_abstract, y_abstract}; auto fg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnormgrad_to_bninfergrad_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnormgrad_to_bninfergrad_test.cc index 1b64e5fd00e..6e8e37b487d 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnormgrad_to_bninfergrad_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/batchnormgrad_to_bninfergrad_test.cc @@ -33,9 +33,9 @@ class TestHWOptimizeBatchNormGrad2BNInferGrad : public BackendCommon { TEST_F(TestHWOptimizeBatchNormGrad2BNInferGrad, test_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batchnormgrad_to_bninfergrad", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, y_abstract, y_abstract, y_abstract}; auto fg = GetKernelGraph(g, args_spec_list); @@ -53,9 +53,9 @@ TEST_F(TestHWOptimizeBatchNormGrad2BNInferGrad, test_fusion) { TEST_F(TestHWOptimizeBatchNormGrad2BNInferGrad, test_no_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_batchnormgrad_to_bninfergrad", "no_fusion"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, y_abstract, y_abstract, y_abstract}; auto fg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_norm_no_div_square_sum_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_norm_no_div_square_sum_fusion_test.cc index aa56d79239b..39d9d00e442 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_norm_no_div_square_sum_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_norm_no_div_square_sum_fusion_test.cc @@ -33,7 +33,7 @@ class TestHWOptimizeClipByNormNodivsquaresumFusion : public BackendCommon { TEST_F(TestHWOptimizeClipByNormNodivsquaresumFusion, test_clip_by_norm_no_div_square_sum_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_clip_by_norm_no_div_square_sum_fusion", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 4; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_value_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_value_fusion_test.cc index ac01f9b1dd3..8c70079e237 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_value_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/clip_by_value_fusion_test.cc @@ -32,7 +32,7 @@ class TestHWOptimizeClipByValueFusion : public BackendCommon { TEST_F(TestHWOptimizeClipByValueFusion, test_clip_fusion_relu0) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_clip_by_value_fusion", "before1"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { @@ -53,7 +53,7 @@ TEST_F(TestHWOptimizeClipByValueFusion, test_clip_fusion_relu0) { TEST_F(TestHWOptimizeClipByValueFusion, test_clip_fusion_relu1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_clip_by_value_fusion", "before2"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc index be6bd95b02a..c433454aca4 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc @@ -32,7 +32,7 @@ class TestHWOptimizeConfusionMulGradFusion : public BackendCommon { TEST_F(TestHWOptimizeConfusionMulGradFusion, test_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_confusion_mul_grad_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shp{10, 1024}; + std::vector shp{10, 1024}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_softmax_grad_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_softmax_grad_test.cc index 068cc0d12e4..adbc5de6701 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_softmax_grad_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_softmax_grad_test.cc @@ -33,7 +33,7 @@ class TestHWOptimizeConfusionSoftmaxGradRule : public BackendCommon { TEST_F(TestHWOptimizeConfusionSoftmaxGradRule, test_confusion_softmax_grad_rule) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_confusion_softmax_grad_rule", "before"); EXPECT_NE(g, nullptr); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 2; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/derelu_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/derelu_fusion_test.cc index 663ed309ee3..f490847be1a 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/derelu_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/derelu_fusion_test.cc @@ -32,7 +32,7 @@ class TestHWOptimizeDereluFusion : public BackendCommon { TEST_F(TestHWOptimizeDereluFusion, test_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_derelu_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 2; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/fused_batch_norm_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/fused_batch_norm_fusion_test.cc index f7cbfdc6785..b2120a48482 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/fused_batch_norm_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/fused_batch_norm_fusion_test.cc @@ -31,9 +31,9 @@ class TestHWFusedBatchNormFusion : public BackendCommon { TEST_F(TestHWFusedBatchNormFusion, test_fused_batch_norm_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_fused_batch_norm_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 6; ++i) { @@ -54,9 +54,9 @@ TEST_F(TestHWFusedBatchNormFusion, test_fused_batch_norm_fusion) { TEST_F(TestHWFusedBatchNormFusion, test_fused_batch_norm_mix_precision_fusion0) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_fused_batch_norm_fusion", "before_mix_precision0"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 6; ++i) { @@ -77,9 +77,9 @@ TEST_F(TestHWFusedBatchNormFusion, test_fused_batch_norm_mix_precision_fusion0) TEST_F(TestHWFusedBatchNormFusion, test_fused_batch_norm_mix_precision_fusion1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_fused_batch_norm_fusion", "before_mix_precision1"); EXPECT_NE(g, nullptr); - std::vector shp_x{32, 64, 112, 112}; + std::vector shp_x{32, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); - std::vector shp_y{64}; + std::vector shp_y{64}; auto y_abstract = std::make_shared(kFloat32, shp_y); AbstractBasePtrList args_spec_list{x_abstract}; for (size_t i = 0; i < 6; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_rule_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_rule_test.cc index 64c004ff275..55c554c4b44 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_rule_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_rule_test.cc @@ -55,7 +55,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond4_matched) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond4", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -98,7 +98,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond4_unmatched_real_div4) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond4", "before_unmatched_real_div4"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -141,7 +141,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond4_unmatched_real_div2) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond4", "before_unmatched_real_div2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -184,7 +184,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond4_unmatched_real_div0) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond4", "before_unmatched_real_div0"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -227,7 +227,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond4_unmatched_real_div1) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond4", "before_unmatched_real_div1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -247,7 +247,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond4_unmatched_real_div1) { TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond1_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond1", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -267,7 +267,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond1_fusion) { TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond1_unmatched) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond1", "un_match"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -287,7 +287,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond1_unmatched) { TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond2_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond2", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -307,7 +307,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond2_fusion) { TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond2_unmatched) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond2", "un_match"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -327,7 +327,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond2_unmatched) { TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond3_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond3", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -347,7 +347,7 @@ TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond3_fusion) { TEST_F(TestHWLambNextMVRule, test_lamb_next_mv_rule_cond3_unmatched) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_rule_cond3", "un_match"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_rule_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_rule_test.cc index 21643bee42b..06c68ddde45 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_rule_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_rule_test.cc @@ -56,7 +56,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_decay_rule_cond4_matched * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond4", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -100,7 +100,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_decay_rule_cond4_unmatch * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond4", "before_unmatched_add3"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -145,7 +145,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_decay_rule_cond4_unmatch * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond4", "before_unmatched_mul4"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -190,7 +190,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_decay_rule_cond4_unmatch * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond4", "before_unmatched_real_div0"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -235,7 +235,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_decay_rule_cond4_unmatch * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond4", "before_unmatched_real_div1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -256,7 +256,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_decay_rule_cond4_unmatch TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond1", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -276,7 +276,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond1) { TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond1_un_match) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond1", "un_match"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -297,7 +297,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond1_un TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond2", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -317,7 +317,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond2) { TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond2_un_match) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond2", "un_match"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -338,7 +338,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond2_un TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond3", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -358,7 +358,7 @@ TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond3) { TEST_F(TestHWLambNextMVWithDecayRule, test_lamb_next_mv_with_decay_rule_cond3_un_match) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_rule_cond3", "un_match"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_v1_rule_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_v1_rule_test.cc index bf21649672d..073b047b3d4 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_v1_rule_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_mv_with_decay_v1_rule_test.cc @@ -30,7 +30,7 @@ class TestHWLambNextMVWithDecayV1Rule : public BackendCommon { TEST_F(TestHWLambNextMVWithDecayV1Rule, test_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_v1_rule", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -50,7 +50,7 @@ TEST_F(TestHWLambNextMVWithDecayV1Rule, test_fusion) { TEST_F(TestHWLambNextMVWithDecayV1Rule, test_no_match1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_v1_rule", "no_match1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -70,7 +70,7 @@ TEST_F(TestHWLambNextMVWithDecayV1Rule, test_no_match1) { TEST_F(TestHWLambNextMVWithDecayV1Rule, test_no_match2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_v1_rule", "no_match2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { @@ -90,7 +90,7 @@ TEST_F(TestHWLambNextMVWithDecayV1Rule, test_no_match2) { TEST_F(TestHWLambNextMVWithDecayV1Rule, test_no_match3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_mv_with_decay_v1_rule", "no_match3"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 13; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_right_rule_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_right_rule_test.cc index 6a7c866ab4e..c8c460c5551 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_right_rule_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_next_right_rule_test.cc @@ -42,7 +42,7 @@ TEST_F(TestHWLambNextRightRule, test_lamb_next_right_rule_matched) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_right_rule", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 6; ++i) { @@ -74,7 +74,7 @@ TEST_F(TestHWLambNextRightRule, test_lamb_next_right_rule_unmatched) { * return output */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_next_right_rule", "before_unmatched"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 6; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_rule_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_rule_fusion_test.cc index 4de2de2700f..2057982f3be 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_rule_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_rule_fusion_test.cc @@ -33,7 +33,7 @@ class TestHWOptimizeLambUpdateWithLRRuleFusion : public BackendCommon { TEST_F(TestHWOptimizeLambUpdateWithLRRuleFusion, test_lamb_update_with_lr_rule_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_update_with_lr_rule_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 9; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_v2_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_v2_test.cc index 5be6195da20..a5e00201a25 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_v2_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/lamb_update_with_lr_v2_test.cc @@ -44,7 +44,7 @@ TEST_F(TestHWLambUpdateWithLrV2, test_lamb_update_with_lr_v2) { * return sub0 */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_lamb_update_with_lr_v2", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 7; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/layer_norm_beta_gamma_backprop_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/layer_norm_beta_gamma_backprop_fusion_test.cc index 7392d05b98f..2b27f154e0c 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/layer_norm_beta_gamma_backprop_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/layer_norm_beta_gamma_backprop_fusion_test.cc @@ -63,7 +63,7 @@ TEST_F(TestHWLayerNormBetaGammaBackpropFusion, layernorm_beta_gamma_backprop_fus * return add */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_layer_norm_beta_gamma_backprop_fusion", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); auto ret = g->get_return(); EXPECT_NE(ret, nullptr); @@ -124,7 +124,7 @@ TEST_F(TestHWLayerNormBetaGammaBackpropFusion, layernorm_beta_gamma_backprop_fus */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_layer_norm_beta_gamma_backprop_fusion", "before_unmatched_inputs_size"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); auto ret = g->get_return(); EXPECT_NE(ret, nullptr); @@ -183,7 +183,7 @@ TEST_F(TestHWLayerNormBetaGammaBackpropFusion, layernorm_beta_gamma_backprop_fus * return add */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_layer_norm_beta_gamma_backprop_fusion", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); auto ret = g->get_return(); EXPECT_NE(ret, nullptr); @@ -241,7 +241,7 @@ TEST_F(TestHWLayerNormBetaGammaBackpropFusion, layernorm_beta_gamma_backprop_fus */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_layer_norm_beta_gamma_backprop_fusion", "before_unmatched_outputs_size"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); auto ret = g->get_return(); EXPECT_NE(ret, nullptr); @@ -291,7 +291,7 @@ TEST_F(TestHWLayerNormBetaGammaBackpropFusion, layernorm_beta_gamma_backprop_fus * return add */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_layer_norm_beta_gamma_backprop_fusion", "before"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); auto ret = g->get_return(); EXPECT_NE(ret, nullptr); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/matmul_biasadd_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/matmul_biasadd_fusion_test.cc index f67eda97764..a7f2a6600d0 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/matmul_biasadd_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/matmul_biasadd_fusion_test.cc @@ -31,11 +31,11 @@ class TestHWMatmulBiasaddFusion : public BackendCommon { TEST_F(TestHWMatmulBiasaddFusion, test_matmul_biasadd_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_matmul_biasadd_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shpx{1, 3}; + std::vector shpx{1, 3}; auto x_abstract = std::make_shared(kFloat32, shpx); - std::vector shpy{3, 4}; + std::vector shpy{3, 4}; auto y_abstract = std::make_shared(kFloat32, shpy); - std::vector shp_bias{4}; + std::vector shp_bias{4}; auto bias_abstract = std::make_shared(kFloat32, shp_bias); AbstractBasePtrList args_spec_list; args_spec_list.push_back(x_abstract); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/momentum_lossscale_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/momentum_lossscale_fusion_test.cc index 50dfd66f547..6068ea1348d 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/momentum_lossscale_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/momentum_lossscale_fusion_test.cc @@ -31,7 +31,7 @@ class TestHWMomentumLossscaleFusion : public BackendCommon { TEST_F(TestHWMomentumLossscaleFusion, test_momentum_lossscale_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_momentum_lossscale_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 5; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_add_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_add_fusion_test.cc index b293cdeecb8..24f981f57c7 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_add_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_add_fusion_test.cc @@ -30,7 +30,7 @@ class TestHWMulAddFusion : public BackendCommon { TEST_F(TestHWMulAddFusion, test_mul_add_fusion1) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_mul_add_fusion", "before1"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { @@ -54,7 +54,7 @@ TEST_F(TestHWMulAddFusion, test_mul_add_fusion1) { TEST_F(TestHWMulAddFusion, test_mul_add_fusion2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_mul_add_fusion", "before2"); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_addn_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_addn_fusion_test.cc index 8ac106f81c8..b62bf0842cf 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_addn_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/mul_addn_fusion_test.cc @@ -30,7 +30,7 @@ class TestHWMulAddNFusion : public BackendCommon { TEST_F(TestHWMulAddNFusion, test_mul_addn_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_mul_addn_fusion", "before"); - std::vector shp{2, 2, 2, 2}; + std::vector shp{2, 2, 2, 2}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list({x_abstract, x_abstract}); auto fg = GetKernelGraph(g, args_spec_list); @@ -47,7 +47,7 @@ TEST_F(TestHWMulAddNFusion, test_mul_addn_fusion) { TEST_F(TestHWMulAddNFusion, test_unmatch) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_mul_addn_fusion", "unmatch"); - std::vector shp{2, 2, 2, 2}; + std::vector shp{2, 2, 2, 2}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list({x_abstract, x_abstract, x_abstract}); auto fg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/reshape_transpose_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/reshape_transpose_fusion_test.cc index 6792f4720ad..512b711afc2 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/reshape_transpose_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/reshape_transpose_fusion_test.cc @@ -39,7 +39,7 @@ TEST_F(TestHWReshapeTransposeFusion, test_reshape_transpose_fusion) { * return transpose */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_reshape_transpose_fusion", "before"); - std::vector shp{2, 2, 16, 16}; + std::vector shp{2, 2, 16, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -68,7 +68,7 @@ TEST_F(TestHWReshapeTransposeFusion, test_reshape_transpose_no_fusion) { * return transpose */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_reshape_transpose_fusion", "before"); - std::vector shp{2, 4, 8, 16}; + std::vector shp{2, 4, 8, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/softmax_grad_ext_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/softmax_grad_ext_fusion_test.cc index f6e8a1194c5..9ba9730491e 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/softmax_grad_ext_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/softmax_grad_ext_fusion_test.cc @@ -32,7 +32,7 @@ class TestHWOptSoftmaxGradExtFusion : public BackendCommon { TEST_F(TestHWOptSoftmaxGradExtFusion, test_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_softmax_grad_ext_fusion", "before"); EXPECT_NE(g, nullptr); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { @@ -53,7 +53,7 @@ TEST_F(TestHWOptSoftmaxGradExtFusion, test_fusion) { TEST_F(TestHWOptSoftmaxGradExtFusion, test_fusion_v2) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_softmax_grad_ext_fusion_v2", "before"); EXPECT_NE(g, nullptr); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { @@ -74,7 +74,7 @@ TEST_F(TestHWOptSoftmaxGradExtFusion, test_fusion_v2) { TEST_F(TestHWOptSoftmaxGradExtFusion, test_fusion_v3) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_softmax_grad_ext_fusion_v3", "before"); EXPECT_NE(g, nullptr); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 3; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/square_sum_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/square_sum_fusion_test.cc index efe5433d75c..11beccafd7d 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/square_sum_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/square_sum_fusion_test.cc @@ -32,7 +32,7 @@ class TestHWOptimizeSquareSumFusion : public BackendCommon { TEST_F(TestHWOptimizeSquareSumFusion, test_square_sumv1_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_square_sum_fusion", "before1"); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 1; ++i) { @@ -52,7 +52,7 @@ TEST_F(TestHWOptimizeSquareSumFusion, test_square_sumv1_fusion) { TEST_F(TestHWOptimizeSquareSumFusion, test_square_sumv2_fusion) { FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_square_sum_fusion", "before2"); - std::vector shp{1, 1, 1, 1}; + std::vector shp{1, 1, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list; for (size_t i = 0; i < 1; ++i) { diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_reshape_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_reshape_fusion_test.cc index 6ec407d2eaf..f5d725949ef 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_reshape_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_reshape_fusion_test.cc @@ -39,7 +39,7 @@ TEST_F(TestHWTransposeReshapeFusion, test_transpose_reshape_fusion) { * return transpose */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_transpose_reshape_fusion", "before"); - std::vector shp{2, 2, 16, 16}; + std::vector shp{2, 2, 16, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -70,7 +70,7 @@ TEST_F(TestHWTransposeReshapeFusion, test_transpose_reshape_no_fusion) { * return transpose */ FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_transpose_reshape_fusion", "before"); - std::vector shp{2, 4, 8, 16}; + std::vector shp{2, 4, 8, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_transdata_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_transdata_fusion_test.cc index 614817d1ef4..2929fdfb30b 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_transdata_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/transpose_transdata_fusion_test.cc @@ -85,7 +85,7 @@ TEST_F(TestHWTransposeTransdataFusion, test_transpose_transdata_fusion) { MS_EXCEPTION_IF_NULL(ms_context); ms_context->set_param(MS_CTX_EXECUTION_MODE, kGraphMode); FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_transpose_transdata_fusion", "before"); - std::vector shp{2, 4, 8, 16}; + std::vector shp{2, 4, 8, 16}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/common/pattern_engine_test.cc b/tests/ut/cpp/pre_activate/common/pattern_engine_test.cc index e1efa3baafc..d02f45aecda 100644 --- a/tests/ut/cpp/pre_activate/common/pattern_engine_test.cc +++ b/tests/ut/cpp/pre_activate/common/pattern_engine_test.cc @@ -49,7 +49,7 @@ TEST_F(TestMatchEngine, Var) { VarPtr v3 = std::make_shared("name"); ASSERT_TRUE(!(v1 == v2)); ASSERT_TRUE(v1->matches(v2)); - ASSERT_TRUE(v1->matches(1)); + ASSERT_TRUE(v1->matches(static_cast(1))); ASSERT_EQ(v3->ToString(), "Var(name)"); ASSERT_NE(v1->tag(), v2->tag()); } @@ -61,6 +61,8 @@ TEST_F(TestMatchEngine, CondVar) { v = utils::cast(any); } else if (utils::isa(any)) { v = utils::cast(any); + } else if (utils::isa(any)) { + v = utils::cast(any); } else { return false; } @@ -74,9 +76,9 @@ TEST_F(TestMatchEngine, CondVar) { } TEST_F(TestMatchEngine, Seq) { - auto seq = Seq({1, 2, 3}); + auto seq = Seq({static_cast(1), static_cast(2), static_cast(3)}); MS_LOG(INFO) << "seq:" << seq.ToString(); - ASSERT_EQ(seq.ToString(), "vector[Int32Imm value:1, Int32Imm value:2, Int32Imm value:3]"); + ASSERT_EQ(seq.ToString(), "vector[Int64Imm value:1, Int64Imm value:2, Int64Imm value:3]"); } TEST_F(TestMatchEngine, SeqVar) { diff --git a/tests/ut/cpp/pre_activate/mem_reuse/mem_reuse_test.cc b/tests/ut/cpp/pre_activate/mem_reuse/mem_reuse_test.cc index 5bccf520779..52035b9a7c2 100644 --- a/tests/ut/cpp/pre_activate/mem_reuse/mem_reuse_test.cc +++ b/tests/ut/cpp/pre_activate/mem_reuse/mem_reuse_test.cc @@ -56,7 +56,7 @@ static KernelGraphPtr CreateKernelGraph() { */ KernelGraphPtr g = std::make_shared(); std::vector inputs; - std::vector shp = {1, 3, 3, 4}; + std::vector shp = {1, 3, 3, 4}; TensorTypePtr tensor_type = std::make_shared(kFloat32); tensor::DeviceInfo device_info{kOpFormat_NCHW, tensor_type}; @@ -152,7 +152,7 @@ static KernelGraphPtr CreateGraphWithExecOrder() { * return */ auto anf_graph = std::make_shared(); - std::vector shape = {2, 32, 224, 224}; + std::vector shape = {2, 32, 224, 224}; auto abstract = std::make_shared(kFloat32, shape); EXPECT_NE(abstract, nullptr); auto original_x_parameter = anf_graph->add_parameter(); diff --git a/tests/ut/cpp/pre_activate/pass/allreduce_fusion_test.cc b/tests/ut/cpp/pre_activate/pass/allreduce_fusion_test.cc index 35b767d4dd6..7178ee66793 100644 --- a/tests/ut/cpp/pre_activate/pass/allreduce_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/pass/allreduce_fusion_test.cc @@ -43,7 +43,7 @@ TEST_F(TestHWAllReduceFusion, test_fusion_all) { getPyFun_.SetDoResolve(true); FuncGraphPtr g = getPyFun_.CallAndParseRet("test_all_reduce_fusion_all", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -84,7 +84,7 @@ TEST_F(TestHWAllReduceFusion, test_fusion_group) { getPyFun_.SetDoResolve(true); FuncGraphPtr g = getPyFun_.CallAndParseRet("test_all_reduce_fusion_group", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -125,7 +125,7 @@ TEST_F(TestHWAllReduceFusion, test_fusion_op) { getPyFun_.SetDoResolve(true); FuncGraphPtr g = getPyFun_.CallAndParseRet("test_all_reduce_fusion_group", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -176,7 +176,7 @@ TEST_F(TestHWAllReduceFusion, test_fusion_sorted) { getPyFun_.SetDoResolve(true); FuncGraphPtr g = getPyFun_.CallAndParseRet("test_all_reduce_fusion_all", "before"); EXPECT_NE(g, nullptr); - std::vector shp_x{1, 64, 112, 112}; + std::vector shp_x{1, 64, 112, 112}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -185,7 +185,7 @@ TEST_F(TestHWAllReduceFusion, test_fusion_sorted) { auto make_tuple = ret->input(1); auto make_tuple1 = make_tuple->cast()->input(1)->cast(); for (size_t i = 1; i < make_tuple1->inputs().size(); ++i) { - AnfAlgo::SetNodeAttr(kAttrIndex, MakeValue(SizeToInt(i)), make_tuple1->input(i)); + AnfAlgo::SetNodeAttr(kAttrIndex, MakeValue(SizeToLong(i)), make_tuple1->input(i)); } // set kernel build info kernel::KernelBuildInfo::KernelBuildInfoBuilder builder; diff --git a/tests/ut/cpp/pre_activate/pass/common_subexpression_elimination_test.cc b/tests/ut/cpp/pre_activate/pass/common_subexpression_elimination_test.cc index bbe9d45d665..586cb05c934 100644 --- a/tests/ut/cpp/pre_activate/pass/common_subexpression_elimination_test.cc +++ b/tests/ut/cpp/pre_activate/pass/common_subexpression_elimination_test.cc @@ -55,7 +55,7 @@ kernel::KernelBuildInfoPtr CreateKernelBuildInfo(const std::vector TEST_F(TestHWCSE, test_func_graph_cse) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_func_graph_cse", "g1"); - std::vector shp_x{32, 3, 224, 224}; + std::vector shp_x{32, 3, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto func_graph = GetFuncGraph(g, args_spec_list); @@ -83,7 +83,7 @@ TEST_F(TestHWCSE, test_func_graph_cse) { TEST_F(TestHWCSE, test_func_graph_cse_with_null_kernel_info) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_func_graph_cse", "g1"); - std::vector shp_x{32, 3, 224, 224}; + std::vector shp_x{32, 3, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto func_graph = GetFuncGraph(g, args_spec_list); @@ -126,7 +126,7 @@ TEST_F(TestHWCSE, test_func_graph_cse_with_null_kernel_info) { TEST_F(TestHWCSE, test_func_graph_cse_with_diff_kernel_info) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_func_graph_cse", "g1"); - std::vector shp_x{32, 3, 224, 224}; + std::vector shp_x{32, 3, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto func_graph = GetFuncGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/pass/const_to_attr_strided_slice_grad_test.cc b/tests/ut/cpp/pre_activate/pass/const_to_attr_strided_slice_grad_test.cc index 59549d3c3be..4a0a4d40a8a 100644 --- a/tests/ut/cpp/pre_activate/pass/const_to_attr_strided_slice_grad_test.cc +++ b/tests/ut/cpp/pre_activate/pass/const_to_attr_strided_slice_grad_test.cc @@ -52,7 +52,7 @@ TEST_F(TestHWConstToAttrStridedSliceGrad, test_strided_slice_grad) { EXPECT_FALSE(AnfAlgo::HasNodeAttr("strides", cnode)); EXPECT_FALSE(CheckEqualGraph(g, g_after)); - std::vector shp_x{16, 1, 1024}; + std::vector shp_x{16, 1, 1024}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/pass/convert_const_input_to_attr_test.cc b/tests/ut/cpp/pre_activate/pass/convert_const_input_to_attr_test.cc index 2b595f15607..4c4ab1f15da 100644 --- a/tests/ut/cpp/pre_activate/pass/convert_const_input_to_attr_test.cc +++ b/tests/ut/cpp/pre_activate/pass/convert_const_input_to_attr_test.cc @@ -40,7 +40,7 @@ TEST_F(TestHWConstInputToAttr, test_reshape) { ASSERT_TRUE(g != nullptr); FuncGraphPtr g_after = getPyFun_.CallAndParseRet("test_convert_reshape_input_to_attr", "after"); ASSERT_TRUE(g_after != nullptr); - std::vector shp_x{2, 3}; + std::vector shp_x{2, 3}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -54,7 +54,7 @@ TEST_F(TestHWConstInputToAttr, test_cast) { ASSERT_TRUE(g != nullptr); FuncGraphPtr g_after = getPyFun_.CallAndParseRet("test_convert_cast_input_to_attr", "after"); ASSERT_TRUE(g_after != nullptr); - std::vector shp_x{2, 3}; + std::vector shp_x{2, 3}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -68,7 +68,7 @@ TEST_F(TestHWConstInputToAttr, test_transpose) { ASSERT_TRUE(g != nullptr); FuncGraphPtr g_after = getPyFun_.CallAndParseRet("test_convert_transpose_input_to_attr", "after"); ASSERT_TRUE(g_after != nullptr); - std::vector shp_x{2, 2, 3}; + std::vector shp_x{2, 2, 3}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -91,7 +91,7 @@ TEST_F(TestHWConstInputToAttr, test_onehot) { EXPECT_FALSE(AnfAlgo::HasNodeAttr("depth", cnode)); EXPECT_FALSE(CheckEqualGraph(g, g_after)); - std::vector shp_x{16}; + std::vector shp_x{16}; auto x_abstract = std::make_shared(kInt32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/pass/convert_const_input_to_tensor_input_test.cc b/tests/ut/cpp/pre_activate/pass/convert_const_input_to_tensor_input_test.cc index 5b303d15a5e..561d6b0f23e 100644 --- a/tests/ut/cpp/pre_activate/pass/convert_const_input_to_tensor_input_test.cc +++ b/tests/ut/cpp/pre_activate/pass/convert_const_input_to_tensor_input_test.cc @@ -40,7 +40,7 @@ TEST_F(TestHWConstInputToTensorInput, test_onehot_fg) { ASSERT_TRUE(g != nullptr); FuncGraphPtr g_after = getPyFun_.CallAndParseRet("test_convert_onehot_input_to_tensor1", "after_func_graph"); ASSERT_TRUE(g_after != nullptr); - std::vector shp_x{16}; + std::vector shp_x{16}; auto x_abstract = std::make_shared(kInt32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetFuncGraph(g, args_spec_list); @@ -69,7 +69,7 @@ TEST_F(TestHWConstInputToTensorInput, test_onehot_kg) { FuncGraphPtr g_after = getPyFun_.CallAndParseRet("test_convert_onehot_input_to_tensor2", "after_kernel_graph"); ASSERT_TRUE(g_after != nullptr); EXPECT_FALSE(CheckEqualGraph(g, g_after)); - std::vector shp_x{16}; + std::vector shp_x{16}; auto x_abstract = std::make_shared(kInt32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); @@ -87,7 +87,7 @@ TEST_F(TestHWConstInputToTensorInput, test_onehot_kg) { TEST_F(TestHWConstInputToTensorInput, test_value_tuple_tensor_input) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_convert_dropout_gen_mask_tuple_input_to_tensor", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1}; + std::vector shp_x{1}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto kernel_graph = GetKernelGraph(g, args_spec_list); @@ -105,7 +105,7 @@ TEST_F(TestHWConstInputToTensorInput, test_value_tuple_tensor_input) { auto tensor = input1->cast()->value()->cast(); ASSERT_TRUE(tensor != nullptr); auto data = tensor->data_c(); - EXPECT_EQ(std::vector((int *)data, (int *)data + 4), std::vector({2, 4, 2, 2})); + EXPECT_EQ(std::vector((int64_t *)data, (int64_t *)data + 4), std::vector({2, 4, 2, 2})); } } // namespace opt } // namespace mindspore diff --git a/tests/ut/cpp/pre_activate/pass/convert_tuple_input_to_dynamic_input_test.cc b/tests/ut/cpp/pre_activate/pass/convert_tuple_input_to_dynamic_input_test.cc index 2c1dfc1c6cd..4a3a5e9d5be 100644 --- a/tests/ut/cpp/pre_activate/pass/convert_tuple_input_to_dynamic_input_test.cc +++ b/tests/ut/cpp/pre_activate/pass/convert_tuple_input_to_dynamic_input_test.cc @@ -39,7 +39,7 @@ class TestHWConstTupleInputToDynamicInput : public BackendCommon { TEST_F(TestHWConstTupleInputToDynamicInput, test_convert_tuple_input_to_dynamic_input) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_convert_tuple_input_to_dynamic_input", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{1, 11, 20, 1, 2}; + std::vector shp_x{1, 11, 20, 1, 2}; auto x_abstract = std::make_shared(kFloat32, shp_x); AbstractBasePtrList args_spec_list{x_abstract}; auto func_graph = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/pre_activate/pass/convert_tuple_output_to_maketuple_test.cc b/tests/ut/cpp/pre_activate/pass/convert_tuple_output_to_maketuple_test.cc index 458c8542188..53658d00cd8 100644 --- a/tests/ut/cpp/pre_activate/pass/convert_tuple_output_to_maketuple_test.cc +++ b/tests/ut/cpp/pre_activate/pass/convert_tuple_output_to_maketuple_test.cc @@ -39,10 +39,10 @@ class TestHWTupleOutputToMakeTuple : public BackendCommon { TEST_F(TestHWTupleOutputToMakeTuple, test_convert_tuple_output_to_maketuple) { FuncGraphPtr g = getPyFun_.CallAndParseRet("test_convert_tuple_output_to_maketuple", "before"); ASSERT_TRUE(g != nullptr); - std::vector shp_x{5, 2, 10}; - std::vector shp_h{1, 2, 2}; - std::vector shp_c{1, 2, 2}; - std::vector shp_w{112, 1, 1}; + std::vector shp_x{5, 2, 10}; + std::vector shp_h{1, 2, 2}; + std::vector shp_c{1, 2, 2}; + std::vector shp_w{112, 1, 1}; auto x_abstract = std::make_shared(kFloat32, shp_x); auto h_abstract = std::make_shared(kFloat32, shp_h); auto c_abstract = std::make_shared(kFloat32, shp_c); diff --git a/tests/ut/cpp/pre_activate/pass/eliminate_redundant_op_test.cc b/tests/ut/cpp/pre_activate/pass/eliminate_redundant_op_test.cc index f22019845f1..bad43657995 100644 --- a/tests/ut/cpp/pre_activate/pass/eliminate_redundant_op_test.cc +++ b/tests/ut/cpp/pre_activate/pass/eliminate_redundant_op_test.cc @@ -79,7 +79,7 @@ TEST_F(TestHWEliminateRedundantOp, test_eliminate_5to4_4to5) { ms_context->set_param(MS_CTX_EXECUTION_MODE, kGraphMode); FuncGraphPtr g = getPyFun_.CallAndParseRet("test_eliminate_5to4_4to5", "before"); // Renormalize func_graph to infer and set shape and type information. - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -146,7 +146,7 @@ TEST_F(TestHWEliminateRedundantOp, test_eliminate_cast) { */ FuncGraphPtr g = getPyFun_.CallAndParseRet("test_eliminate_cast", "before"); // Renormalize func_graph to infer and set shape and type information. - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); @@ -212,7 +212,7 @@ TEST_F(TestHWEliminateRedundantOp, test_eliminate_cast_depend_cast) { */ FuncGraphPtr g = getPyFun_.CallAndParseRet("test_eliminate_cast_depend_cast", "before"); // Renormalize func_graph to infer and set shape and type information. - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; auto kg = GetKernelGraph(g, args_spec_list); diff --git a/tests/ut/cpp/session/anf_runtime_algorithm_test.cc b/tests/ut/cpp/session/anf_runtime_algorithm_test.cc index 8f7ecd38363..507c3f61b13 100644 --- a/tests/ut/cpp/session/anf_runtime_algorithm_test.cc +++ b/tests/ut/cpp/session/anf_runtime_algorithm_test.cc @@ -66,7 +66,7 @@ TEST_F(AnfRuntimeAlgorithmTest, VisitKernel) { std::vector make_tuple_inputs{NewValueNode(prim::kPrimMakeTuple), add, add_second}; auto make_tuple = kernel_graph->NewCNode(make_tuple_inputs); MS_EXCEPTION_IF_NULL(make_tuple); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract}; make_tuple->set_abstract(std::make_shared(args_spec_list)); @@ -79,7 +79,8 @@ TEST_F(AnfRuntimeAlgorithmTest, VisitKernel) { EXPECT_EQ((kernel_with_index.first->cast()).get(), add_second.get()); EXPECT_EQ(kernel_with_index.second, 0); // test tuple get item node as input - std::vector tuple_get_item_inputs{NewValueNode(prim::kPrimTupleGetItem), make_tuple, NewValueNode(1)}; + std::vector tuple_get_item_inputs{NewValueNode(prim::kPrimTupleGetItem), make_tuple, + NewValueNode(static_cast(1))}; auto tuple_get_item = kernel_graph->NewCNode(tuple_get_item_inputs); kernel_with_index = AnfAlgo::VisitKernel(tuple_get_item, 0); EXPECT_NE(kernel_with_index.first->cast(), nullptr); @@ -229,7 +230,7 @@ TEST_F(AnfRuntimeAlgorithmTest, GetOutputTensorNum) { inputs.push_back(NewValueNode(prim::kPrimFusedBatchNorm)); auto bn = kernel_graph->NewCNode(inputs); MS_EXCEPTION_IF_NULL(bn); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; bn->set_abstract(std::make_shared(args_spec_list)); @@ -310,7 +311,7 @@ TEST_F(AnfRuntimeAlgorithmTest, GetPrevNodeOutputFormat) { TEST_F(AnfRuntimeAlgorithmTest, GetOutputInferShape) { auto kernel_graph = std::make_shared(); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto none_abstract = std::make_shared(); auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, none_abstract, x_abstract}; @@ -345,7 +346,7 @@ TEST_F(AnfRuntimeAlgorithmTest, GetOutputInferShape) { TEST_F(AnfRuntimeAlgorithmTest, GetPrevNodeOutputInferShape) { auto kernel_graph = std::make_shared(); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); // test parameter node as input auto parameter_node = kernel_graph->NewParameter(); @@ -361,10 +362,10 @@ TEST_F(AnfRuntimeAlgorithmTest, GetPrevNodeOutputInferShape) { TEST_F(AnfRuntimeAlgorithmTest, GetOutputDeviceShape) { auto kernel_graph = std::make_shared(); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract}; - args_spec_list.emplace_back(std::make_shared(kFloat32, std::vector{1, 2, 3, 4})); + args_spec_list.emplace_back(std::make_shared(kFloat32, std::vector{1, 2, 3, 4})); auto tuple_abstract = std::make_shared(args_spec_list); // test cnode as input std::vector inputs; @@ -388,7 +389,7 @@ TEST_F(AnfRuntimeAlgorithmTest, GetOutputDeviceShape) { TEST_F(AnfRuntimeAlgorithmTest, GetInputDeviceShape) { auto kernel_graph = std::make_shared(); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); auto parameter_one = kernel_graph->NewParameter(); MS_EXCEPTION_IF_NULL(parameter_one); @@ -422,7 +423,7 @@ TEST_F(AnfRuntimeAlgorithmTest, GetOutputInferDataTypeTest) { inputs.push_back(NewValueNode(prim::kPrimFusedBatchNorm)); auto bn = kernel_graph->NewCNode(inputs); MS_EXCEPTION_IF_NULL(bn); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); AbstractBasePtrList args_spec_list{x_abstract, x_abstract, x_abstract, x_abstract, x_abstract}; bn->set_abstract(std::make_shared(args_spec_list)); @@ -437,7 +438,7 @@ TEST_F(AnfRuntimeAlgorithmTest, GetPrevNodeOutputInferDataType) { pre_node_inputs.push_back(NewValueNode(prim::kPrimTensorAdd)); auto pre_add = kernel_graph->NewCNode(pre_node_inputs); MS_EXCEPTION_IF_NULL(pre_add); - std::vector shp{2, 32, 224, 224}; + std::vector shp{2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shp); pre_add->set_abstract(x_abstract); std::vector inputs{NewValueNode(prim::kPrimTensorAdd), pre_add}; diff --git a/tests/ut/cpp/session/kernel_graph_test.cc b/tests/ut/cpp/session/kernel_graph_test.cc index 3b171f47229..5157c9587f1 100644 --- a/tests/ut/cpp/session/kernel_graph_test.cc +++ b/tests/ut/cpp/session/kernel_graph_test.cc @@ -36,9 +36,9 @@ class KernelGraphTest : public UT::Common { TEST_F(KernelGraphTest, NewValueNode) { auto kernel_graph = std::make_shared(); - auto add_value = NewValueNode(MakeValue(0)); + auto add_value = NewValueNode(MakeValue(static_cast(0))); MS_EXCEPTION_IF_NULL(add_value); - std::vector shape = {1}; + std::vector shape = {1}; auto x_abstract = std::make_shared(kFloat32, shape); add_value->set_abstract(x_abstract); add_value->set_kernel_info(std::make_shared()); @@ -66,7 +66,7 @@ TEST_F(KernelGraphTest, NewParameter) { EXPECT_EQ(AnfAlgo::GetOutputFormat(new_paramter, 0), kOpFormat_DEFAULT); EXPECT_EQ(AnfAlgo::GetOutputDeviceDataType(new_paramter, 0), kMetaTypeNone); // test non-weight parameter node as input - std::vector shape = {2, 32, 224, 224}; + std::vector shape = {2, 32, 224, 224}; auto x_abstract = std::make_shared(kFloat32, shape); auto non_weight_parameter = anf_graph->add_parameter(); MS_EXCEPTION_IF_NULL(non_weight_parameter); @@ -138,7 +138,7 @@ TEST_F(KernelGraphTest, SetExecOrderByDefault) { * return */ auto kernel_graph = std::make_shared(); - std::vector shape = {2, 32, 224, 224}; + std::vector shape = {2, 32, 224, 224}; auto abstract = std::make_shared(kFloat32, shape); auto x_parameter = kernel_graph->NewParameter(); @@ -190,4 +190,4 @@ TEST_F(KernelGraphTest, SetGraphId) { } } // namespace session -} // namespace mindspore \ No newline at end of file +} // namespace mindspore diff --git a/tests/ut/cpp/session/session_basic_test.cc b/tests/ut/cpp/session/session_basic_test.cc index c438c92b520..92bec6f227a 100644 --- a/tests/ut/cpp/session/session_basic_test.cc +++ b/tests/ut/cpp/session/session_basic_test.cc @@ -40,7 +40,7 @@ TEST_F(SessionBasicTest, ConstructKernelGraph) { * return */ auto anf_graph = std::make_shared(); - std::vector shape = {2, 32, 224, 224}; + std::vector shape = {2, 32, 224, 224}; auto abstract = std::make_shared(kFloat32, shape); EXPECT_NE(abstract, nullptr); diff --git a/tests/ut/cpp/stub/kernel/kernel_fusion_stub.cc b/tests/ut/cpp/stub/kernel/kernel_fusion_stub.cc index 0b91bbdd35d..13bd5208e4e 100755 --- a/tests/ut/cpp/stub/kernel/kernel_fusion_stub.cc +++ b/tests/ut/cpp/stub/kernel/kernel_fusion_stub.cc @@ -19,8 +19,8 @@ namespace mindspore { namespace kernel { -std::map KernelFusion(const std::vector &fusion_scopes) { - std::map kernel_mod_ret; +std::map KernelFusion(const std::vector &fusion_scopes) { + std::map kernel_mod_ret; for (const auto &fusion_scope_iter : fusion_scopes) { kernel_mod_ret[fusion_scope_iter.scope_id] = std::make_shared(nullptr); } diff --git a/tests/ut/cpp/transform/convert_test.cc b/tests/ut/cpp/transform/convert_test.cc index bcdf33c56de..bd3346ecc40 100644 --- a/tests/ut/cpp/transform/convert_test.cc +++ b/tests/ut/cpp/transform/convert_test.cc @@ -93,9 +93,9 @@ bool MakeDfGraph(PrimitivePtr prim, unsigned int nparam) { TEST_F(TestConvert, TestConvertConv2d) { PrimitivePtr conv2d = prim::kPrimConv2D; - conv2d->AddAttr("stride", MakeValue(2)); - conv2d->AddAttr("pad", MakeValue(0)); - conv2d->AddAttr("dilation", MakeValue(0)); + conv2d->AddAttr("stride", MakeValue(static_cast(2))); + conv2d->AddAttr("pad", MakeValue(static_cast(0))); + conv2d->AddAttr("dilation", MakeValue(static_cast(0))); FuncGraphPtr anf_graph = MakeFuncGraph(conv2d, 2); std::shared_ptr graph_manager = MakeManager({anf_graph}); @@ -127,7 +127,7 @@ TEST_F(TestConvert, TestConvertMaxpooling) { TEST_F(TestConvert, TestReluOps) { auto prim = prim::kPrimRelu; - prim->AddAttr("T", MakeValue(0)); + prim->AddAttr("T", MakeValue(static_cast(0))); auto func_graph = MakeFuncGraph(prim, 1); ASSERT_TRUE(nullptr != func_graph); @@ -162,7 +162,7 @@ TEST_F(TestConvert, TestConvertBatchNorm) { inputs.push_back(NewValueNode(prim::kPrimTupleGetItem)); inputs.push_back(cnode_prim); - inputs.push_back(NewValueNode(2)); + inputs.push_back(NewValueNode(static_cast(2))); CNodePtr cnode_getitem = anf_graph->NewCNode(inputs); inputs.clear(); @@ -189,14 +189,14 @@ TEST_F(TestConvert, TestConvertBatchNorm) { TEST_F(TestConvert, TestConvertConvBackpropInput) { auto prim = prim::kPrimConv2DBackpropInput; - const std::vector list{1,1}; + const std::vector list{1,1}; prim->AddAttr("stride", MakeValue(list)); - prim->AddAttr("pad", MakeValue(0)); + prim->AddAttr("pad", MakeValue(static_cast(0))); prim->AddAttr("pad_mode", MakeValue(std::string("pad"))); - prim->AddAttr("dilation", MakeValue(1)); - prim->AddAttr("group", MakeValue(1)); - prim->AddAttr("mode", MakeValue(1)); - prim->AddAttr("dilation", MakeValue(1)); + prim->AddAttr("dilation", MakeValue(static_cast(1))); + prim->AddAttr("group", MakeValue(static_cast(1))); + prim->AddAttr("mode", MakeValue(static_cast(1))); + prim->AddAttr("dilation", MakeValue(static_cast(1))); auto func_graph = MakeFuncGraph(prim, 3); ASSERT_NE(func_graph, nullptr); @@ -219,14 +219,14 @@ TEST_F(TestConvert, TestConvertConvBackpropInput) { TEST_F(TestConvert, TestConvertConvBackpropFilter) { auto prim = prim::kPrimConv2DBackpropFilter; - const std::vector list{1,1}; + const std::vector list{1,1}; prim->AddAttr("stride", MakeValue(list)); - prim->AddAttr("pad", MakeValue(0)); + prim->AddAttr("pad", MakeValue(static_cast(0))); prim->AddAttr("pad_mode", MakeValue(std::string("pad"))); - prim->AddAttr("dilation", MakeValue(1)); - prim->AddAttr("group", MakeValue(1)); - prim->AddAttr("mode", MakeValue(1)); - prim->AddAttr("dilation", MakeValue(1)); + prim->AddAttr("dilation", MakeValue(static_cast(1))); + prim->AddAttr("group", MakeValue(static_cast(1))); + prim->AddAttr("mode", MakeValue(static_cast(1))); + prim->AddAttr("dilation", MakeValue(static_cast(1))); auto func_graph = MakeFuncGraph(prim, 3); ASSERT_NE(func_graph, nullptr); @@ -251,7 +251,7 @@ TEST_F(TestConvert, TestConvertReluGrad) { auto prim = prim::kPrimReluGrad; prim->AddAttr("alpha", MakeValue(0.1f)); prim->AddAttr("beta", MakeValue(0.1f)); - prim->AddAttr("mode", MakeValue(1)); + prim->AddAttr("mode", MakeValue(static_cast(1))); auto func_graph = MakeFuncGraph(prim, 2); ASSERT_NE(func_graph, nullptr); @@ -276,7 +276,7 @@ TEST_F(TestConvert, TestConvertBiasAdd) { auto prim = std::make_shared("BiasAdd"); prim->AddAttr("alpha", MakeValue(0.0f)); prim->AddAttr("beta", MakeValue(1.0f)); - prim->AddAttr("format", MakeValue(1)); + prim->AddAttr("format", MakeValue(static_cast(1))); auto func_graph = MakeFuncGraph(prim, 2); ASSERT_NE(func_graph, nullptr); @@ -301,7 +301,7 @@ TEST_F(TestConvert, TestConvertBiasAddGrad) { auto prim = prim::kPrimBiasAddGrad; prim->AddAttr("alpha", MakeValue(0.0f)); prim->AddAttr("beta", MakeValue(1.0f)); - prim->AddAttr("format", MakeValue(1)); + prim->AddAttr("format", MakeValue(static_cast(1))); auto func_graph = MakeFuncGraph(prim, 2); ASSERT_NE(func_graph, nullptr); @@ -326,10 +326,10 @@ TEST_F(TestConvert, TestConvertMaxPoolGradWithArgmax) { auto prim = std::make_shared("MaxPoolGradWithArgmax"); prim->AddAttr("alpha", MakeValue(0.0f)); prim->AddAttr("beta", MakeValue(1.0f)); - prim->AddAttr("window", MakeValue(2)); - prim->AddAttr("stride", MakeValue(1)); - prim->AddAttr("ceil_mode", MakeValue(0)); - prim->AddAttr("data_mode", MakeValue(0)); + prim->AddAttr("window", MakeValue(static_cast(2))); + prim->AddAttr("stride", MakeValue(static_cast(1))); + prim->AddAttr("ceil_mode", MakeValue(static_cast(0))); + prim->AddAttr("data_mode", MakeValue(static_cast(0))); prim->AddAttr("alpha", MakeValue(0.1f)); prim->AddAttr("beta", MakeValue(1.0f)); @@ -516,7 +516,7 @@ TEST_F(TestConvert, TestAssignAdd) { TEST_F(TestConvert, LogSoftmax) { auto prim = prim::kPrimLogSoftmax; - prim->AddAttr("axis", MakeValue(0)); + prim->AddAttr("axis", MakeValue(static_cast(0))); std::shared_ptr anf_graph = MakeFuncGraph(prim, 1); std::shared_ptr graph_manager = MakeManager({anf_graph}); @@ -575,7 +575,7 @@ TEST_F(TestConvert, TestNegOps) { TEST_F(TestConvert, TestOneHotOps) { auto prim = prim::kPrimOneHot; - prim->AddAttr("axis", MakeValue(0)); + prim->AddAttr("axis", MakeValue(static_cast(0))); bool ret = MakeDfGraph(prim, 4); ASSERT_TRUE(ret); } @@ -701,7 +701,7 @@ TEST_F(TestConvert, TestAddOps) { TEST_F(TestConvert, TestConvertTensor) { float data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Create a tensor with wanted data type and shape - std::vector dims{2, 2, 3}; + std::vector dims{2, 2, 3}; std::vector ge_dims{2, 2, 3}; auto type_id = kNumberTypeFloat32; MeTensor me_tensor(type_id, dims); @@ -725,14 +725,14 @@ TEST_F(TestConvert, TestConvertTensor) { TEST_F(TestConvert, TestConvertTensor0Dims) { // shape with 0 dims is also valid - std::vector dims{}; + std::vector dims{}; auto type_id = kNumberTypeFloat32; auto me_tensor_ptr = std::make_shared(type_id, dims); ASSERT_NE(TransformUtil::ConvertTensor(me_tensor_ptr, kOpFormat_NCHW), nullptr); } TEST_F(TestConvert, TestConvertTensorError) { - std::vector dims2{2, 3, 4}; + std::vector dims2{2, 3, 4}; auto type_id_2 = kNumberTypeFloat32; auto me_tensor_ptr_2 = std::make_shared(type_id_2, dims2); ASSERT_NE(TransformUtil::ConvertTensor(me_tensor_ptr_2, "xyz"), nullptr); @@ -834,9 +834,12 @@ TEST_F(TestConvert, TestConvertMakeTuple) { TEST_F(TestConvert, TestConvertInputTensors) { #define DTYPE float - MeTensorPtr input_ptr1 = MakeTensor(kF32, {1, 1, 4, 4}); - MeTensorPtr input_ptr2 = MakeTensor(kF32, {2, 3, 4, 5}); - MeTensorPtr input_ptr3 = MakeTensor(kF32, {9, 9, 1, 1}); + std::initializer_list list0 = {1, 1, 4, 4}; + std::initializer_list list1 = {2, 3, 4, 5}; + std::initializer_list list2 = {9, 9, 1, 1}; + MeTensorPtr input_ptr1 = MakeTensor(kF32, list0); + MeTensorPtr input_ptr2 = MakeTensor(kF32, list1); + MeTensorPtr input_ptr3 = MakeTensor(kF32, list2); std::vector me_inputs; me_inputs.emplace_back(input_ptr1); me_inputs.emplace_back(input_ptr2); @@ -880,10 +883,10 @@ TEST_F(TestConvert, TestConvertGeTensors) { ge_tensors.emplace_back(ge_tensor_ptr2); ge_tensors.emplace_back(ge_tensor_ptr3); - std::vector> request_dims; - std::vector dims1 = {1, 1, 4, 4}; - std::vector dims2 = {2, 3, 4, 5}; - std::vector dims3 = {9, 9, 1, 1}; + std::vector> request_dims; + std::vector dims1 = {1, 1, 4, 4}; + std::vector dims2 = {2, 3, 4, 5}; + std::vector dims3 = {9, 9, 1, 1}; request_dims.emplace_back(dims1); request_dims.emplace_back(dims2); request_dims.emplace_back(dims3); @@ -901,43 +904,43 @@ TEST_F(TestConvert, TestConvertGeTensors) { TEST_F(TestConvert, TestConvertGeShape1) { GeShape ge_shape({10, 1, 1, 1}); - std::vector request_dims{10}; + std::vector request_dims{10}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == request_dims); } TEST_F(TestConvert, TestConvertGeShape2) { GeShape ge_shape({10, 15, 1, 1}); - std::vector request_dims{10, 15}; + std::vector request_dims{10, 15}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == request_dims); } TEST_F(TestConvert, TestConvertGeShape3) { GeShape ge_shape({10, 13, 18, 1}); - std::vector request_dims{10, 13, 18}; + std::vector request_dims{10, 13, 18}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == request_dims); } TEST_F(TestConvert, TestConvertGeShape4) { GeShape ge_shape({1, 10, 1, 1}); - std::vector request_dims{10}; + std::vector request_dims{10}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == request_dims); } TEST_F(TestConvert, TestConvertGeShape5) { GeShape ge_shape({10, 1, 1, 2}); - std::vector request_dims{10}; + std::vector request_dims{10}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == TransformUtil::ConvertGeShape(ge_shape)); } TEST_F(TestConvert, TestConvertGeShape6) { GeShape ge_shape({5, 2, 1, 1}); - std::vector request_dims{10}; + std::vector request_dims{10}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == TransformUtil::ConvertGeShape(ge_shape)); } TEST_F(TestConvert, TestConvertGeShape7) { GeShape ge_shape({10}); - std::vector request_dims{10, 1}; + std::vector request_dims{10, 1}; ASSERT_TRUE(TransformUtil::ConvertGeShape(ge_shape, request_dims) == TransformUtil::ConvertGeShape(ge_shape)); } } // namespace transform diff --git a/tests/ut/cpp/transform/graph_runner_test.cc b/tests/ut/cpp/transform/graph_runner_test.cc index 4b1586893ec..54ad101a53a 100644 --- a/tests/ut/cpp/transform/graph_runner_test.cc +++ b/tests/ut/cpp/transform/graph_runner_test.cc @@ -56,15 +56,15 @@ const std::shared_ptr TestGraphRunner::kF32 = std::make_shared(32) std::shared_ptr MakeGeGraph() { PrimitivePtr conv2d = prim::kPrimConv2D; - conv2d->AddAttr("stride", MakeValue(1)); - conv2d->AddAttr("pad", MakeValue(0)); + conv2d->AddAttr("stride", MakeValue(static_cast(1))); + conv2d->AddAttr("pad", MakeValue(static_cast(0))); conv2d->AddAttr("pad_mode", MakeValue(std::string("pad"))); - conv2d->AddAttr("dilation", MakeValue(1)); - conv2d->AddAttr("group", MakeValue(1)); - conv2d->AddAttr("mode", MakeValue(1)); - conv2d->AddAttr("out_channel", MakeValue(2)); - conv2d->AddAttr("kernel_size", MakeValue(std::vector({2, 2}))); - conv2d->AddAttr("dilation", MakeValue(1)); + conv2d->AddAttr("dilation", MakeValue(static_cast(1))); + conv2d->AddAttr("group", MakeValue(static_cast(1))); + conv2d->AddAttr("mode", MakeValue(static_cast(1))); + conv2d->AddAttr("out_channel", MakeValue(static_cast(2))); + conv2d->AddAttr("kernel_size", MakeValue(std::vector({2, 2}))); + conv2d->AddAttr("dilation", MakeValue(static_cast(1))); conv2d->AddAttr("data_format", MakeValue(kOpFormat_NCHW)); FuncGraphPtr anf_graph = MakeFuncGraph(conv2d, 2); @@ -89,10 +89,10 @@ std::shared_ptr> DoExecGraph(const std::vector> request_dims; - std::vector dims1 = {1, 1, 4, 4}; - std::vector dims2 = {2, 3, 4, 5}; - std::vector dims3 = {9, 9}; + std::vector> request_dims; + std::vector dims1 = {1, 1, 4, 4}; + std::vector dims2 = {2, 3, 4, 5}; + std::vector dims3 = {9, 9}; request_dims.emplace_back(dims1); request_dims.emplace_back(dims2); request_dims.emplace_back(dims3); @@ -109,7 +109,7 @@ TEST_F(TestGraphRunner, TestGeTensorConstructor) { float ge_tensor_data[] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6}; // Create a Tensor with wanted data type and shape - MeTensor tensor = MeTensor(TypeId::kNumberTypeFloat32, std::vector({1, 2, 3})); + MeTensor tensor = MeTensor(TypeId::kNumberTypeFloat32, std::vector({1, 2, 3})); // Get the writable data pointer from the tensor float *me_tensor_data = reinterpret_cast(tensor.data_c()); @@ -138,7 +138,8 @@ TEST_F(TestGraphRunner, TestRunGraphException) { graph_manager.ClearGraph(); std::map dict; - MeTensorPtr init_tensor_ptr = MakeTensor(kF32, {2, 1, 2, 2}); + std::initializer_list list0{2, 1, 2, 2}; + MeTensorPtr init_tensor_ptr = MakeTensor(kF32, list0); dict["x1"] = init_tensor_ptr; std::shared_ptr convertor = MakeGeGraph(); @@ -146,9 +147,11 @@ TEST_F(TestGraphRunner, TestRunGraphException) { auto df_graph = (*convertor).GetComputeGraph(); graph_manager.AddGraph("test_graph", df_graph); - MeTensorPtr me_tensor_ptr = MakeTensor(kF32, {1, 1, 2, 3}); + std::initializer_list list1{1, 1, 2, 3}; + MeTensorPtr me_tensor_ptr = MakeTensor(kF32, list1); - MeTensorPtr input_ptr = MakeTensor(kF32, {1, 1, 4, 4}); + std::initializer_list list2{1, 1, 4, 4}; + MeTensorPtr input_ptr = MakeTensor(kF32, list2); std::vector me_inputs; me_inputs.emplace_back(input_ptr); std::vector me_outputs; @@ -175,7 +178,8 @@ TEST_F(TestGraphRunner, TestRunGraph) { std::shared_ptr convertor = MakeGeGraph(); std::map dict; - dict.emplace("x1", MakeTensor(kF32, {2, 1, 2, 2})); + std::initializer_list list0{2, 1, 2, 2}; + dict.emplace("x1", MakeTensor(kF32, list0)); (*convertor).ConvertAllNode().InitParam(dict).BuildGraph(); graph_manager.AddGraph("test_graph", (*convertor).GetComputeGraph()); @@ -212,15 +216,19 @@ TEST_F(TestGraphRunner, TestAPI) { std::shared_ptr convertor = MakeGeGraph(); std::map dict; - dict.emplace("x1", MakeTensor(kF32, {2, 1, 2, 2})); + std::initializer_list list0{2, 1, 2, 2}; + dict.emplace("x1", MakeTensor(kF32, list0)); (*convertor).ConvertAllNode().InitParam(dict).BuildGraph(); (*convertor).DrawComputeGraph("TestGraphRunner_TestAPI_Training.dot"); graph_manager.AddGraph("fp_bp_subgraph", (*convertor).GetComputeGraph()); - MeTensorPtr input_ptr1 = MakeTensor(kF32, {1, 1, 4, 4}); - MeTensorPtr input_ptr2 = MakeTensor(kF32, {2, 3, 4, 5}); - MeTensorPtr input_ptr3 = MakeTensor(kF32, {9, 9, 1, 1}); + std::initializer_list list1{1, 1, 4, 4}; + std::initializer_list list2{2, 3, 4, 5}; + std::initializer_list list3{9, 9, 1, 1}; + MeTensorPtr input_ptr1 = MakeTensor(kF32, list1); + MeTensorPtr input_ptr2 = MakeTensor(kF32, list2); + MeTensorPtr input_ptr3 = MakeTensor(kF32, list3); std::vector me_inputs; std::vector me_outputs; me_inputs.emplace_back(input_ptr1); diff --git a/tests/ut/cpp/transform/op_adapter_test.cc b/tests/ut/cpp/transform/op_adapter_test.cc index 7c97fbb9ec1..bc79c5c79c1 100644 --- a/tests/ut/cpp/transform/op_adapter_test.cc +++ b/tests/ut/cpp/transform/op_adapter_test.cc @@ -86,8 +86,8 @@ TEST_F(TestOpAdapter, TestSetAttr_Conv2d_Primitive) { }); ASSERT_EQ(prim->name(), prim::kPrimConv2D->name()); - Int32Imm strides(3); - Int32Imm padding(1); + Int64Imm strides(3); + Int64Imm padding(1); ASSERT_EQ(*(prim->GetAttr("strides")), strides); ASSERT_EQ(*(prim->GetAttr("padding")), padding); diff --git a/tests/ut/cpp/transform/transform_base_test.cc b/tests/ut/cpp/transform/transform_base_test.cc index e5557210abe..aac4547b7f2 100644 --- a/tests/ut/cpp/transform/transform_base_test.cc +++ b/tests/ut/cpp/transform/transform_base_test.cc @@ -97,8 +97,8 @@ FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, unsigned int nparam) { return func_graph; } -MeTensorPtr MakeTensor(const TypePtr& t, std::initializer_list shp) { - auto shape = std::vector(shp); +MeTensorPtr MakeTensor(const TypePtr& t, std::initializer_list shp) { + auto shape = std::vector(shp); auto tensor = std::make_shared(t->type_id(), shape); return tensor; } diff --git a/tests/ut/cpp/transform/transform_base_test.h b/tests/ut/cpp/transform/transform_base_test.h index ede3fde9fbd..84fa05d30f9 100644 --- a/tests/ut/cpp/transform/transform_base_test.h +++ b/tests/ut/cpp/transform/transform_base_test.h @@ -38,7 +38,7 @@ namespace transform { std::vector getAnfGraph(std::string package, std::string function); void PrintMeTensor(MeTensor* tensor); FuncGraphPtr MakeFuncGraph(const PrimitivePtr prim, unsigned int nparam); -MeTensorPtr MakeTensor(const TypePtr& t, std::initializer_list shp); +MeTensorPtr MakeTensor(const TypePtr& t, std::initializer_list shp); } // namespace transform } // namespace mindspore diff --git a/tests/ut/cpp/utils/baseref_test.cc b/tests/ut/cpp/utils/baseref_test.cc index 4a5a267d9dd..beb2f4d27df 100644 --- a/tests/ut/cpp/utils/baseref_test.cc +++ b/tests/ut/cpp/utils/baseref_test.cc @@ -31,18 +31,18 @@ class TestBaseRef : public UT::Common { }; TEST_F(TestBaseRef, TestScalar) { - BaseRef a = 1; + BaseRef a = static_cast(1); BaseRef b = 1.0; - if (isa(a)) { - ASSERT_EQ(cast(a), 1); - Int32ImmPtr c = cast(a); - ASSERT_EQ(cast(c), 1); + if (isa(a)) { + ASSERT_EQ(cast(a), 1); + Int64ImmPtr c = cast(a); + ASSERT_EQ(cast(c), 1); } - ASSERT_TRUE(isa(a)); + ASSERT_TRUE(isa(a)); ASSERT_TRUE(isa(a)); ASSERT_TRUE(isa(b)); ASSERT_TRUE(isa(b)); - BaseRef c = 1; + BaseRef c = static_cast(1); ASSERT_EQ(a == c, true); } @@ -58,10 +58,10 @@ void func(const BaseRef& sexp) { } TEST_F(TestBaseRef, TestNode) { - AnfNodePtr anf = NewValueNode(1); + AnfNodePtr anf = NewValueNode(static_cast(1)); BaseRef d = anf; MS_LOG(INFO) << "anf typeid:" << dyn_cast(anf).get(); - MS_LOG(INFO) << "anf typeid:" << NewValueNode(1)->tid(); + MS_LOG(INFO) << "anf typeid:" << NewValueNode(static_cast(1))->tid(); MS_LOG(INFO) << "node reftypeid:" << d.tid(); ASSERT_EQ(isa(d), true); ASSERT_EQ(isa(d), true); @@ -71,16 +71,16 @@ TEST_F(TestBaseRef, TestNode) { } TEST_F(TestBaseRef, TestVector) { - AnfNodePtr anf = NewValueNode(1); - VectorRef a({1, 2, anf, NewValueNode(1)}); + AnfNodePtr anf = NewValueNode(static_cast(1)); + VectorRef a({static_cast(1), static_cast(2), anf, NewValueNode(static_cast(1))}); ASSERT_TRUE(isa(a)); func(a); BaseRef b; - b = 1; - ASSERT_TRUE(isa(b)); - std::vector int_t({1, 2, 3}); + b = static_cast(1); + ASSERT_TRUE(isa(b)); + std::vector int64({1, 2, 3}); VectorRef k; - k.insert(k.end(), int_t.begin(), int_t.end()); + k.insert(k.end(), int64.begin(), int64.end()); k = a; func(k); @@ -92,8 +92,8 @@ TEST_F(TestBaseRef, TestVector) { ASSERT_TRUE(isa(c)); VectorRefPtr d = cast(c); ASSERT_TRUE(isa(d)); - VectorRef e1({1, 2, anf}); - VectorRef e({1, 2, anf}); + VectorRef e1({static_cast(1), static_cast(2), anf}); + VectorRef e({static_cast(1), static_cast(2), anf}); ASSERT_EQ(e1 == e, true); } } // namespace utils diff --git a/tests/ut/cpp/utils/callback_test.cc b/tests/ut/cpp/utils/callback_test.cc index 0a4ffb81908..1823c909850 100644 --- a/tests/ut/cpp/utils/callback_test.cc +++ b/tests/ut/cpp/utils/callback_test.cc @@ -40,7 +40,7 @@ TEST_F(TestCallback, test_get_anf_tensor_shape) { py::object obj = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_class", "test_get_object_graph"); FuncGraphPtr func_graph = pipeline::ExecutorPy::GetInstance()->GetFuncGraphPy(obj); transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph); - std::shared_ptr> param_shape_ptr = std::make_shared>(); + std::shared_ptr> param_shape_ptr = std::make_shared>(); bool get_shape = callbacks::GetParameterShape(func_graph, "weight", param_shape_ptr); ASSERT_TRUE(get_shape == true); } diff --git a/tests/ut/cpp/utils/symbolic_test.cc b/tests/ut/cpp/utils/symbolic_test.cc index c0abd388d5f..c1e594ab394 100644 --- a/tests/ut/cpp/utils/symbolic_test.cc +++ b/tests/ut/cpp/utils/symbolic_test.cc @@ -28,12 +28,12 @@ class TestSymbolic : public UT::Common { }; TEST_F(TestSymbolic, test_env) { - auto sk1 = std::make_shared(NewValueNode(1), abstract::FromValue(1234)); - auto sk1b = std::make_shared(NewValueNode(1), abstract::FromValue(1234)); + auto sk1 = std::make_shared(NewValueNode(static_cast(1)), abstract::FromValue(1234)); + auto sk1b = std::make_shared(NewValueNode(static_cast(1)), abstract::FromValue(1234)); ASSERT_EQ(*sk1, *sk1b); - auto sk2 = std::make_shared(NewValueNode(2), abstract::FromValue(1234)); + auto sk2 = std::make_shared(NewValueNode(static_cast(2)), abstract::FromValue(1234)); EnvInstance e = newenv->Set(sk1, 100); ASSERT_FALSE(e == *newenv); diff --git a/tests/ut/cpp/utils/validator_test.cc b/tests/ut/cpp/utils/validator_test.cc index 93334d76641..09ab759fcbe 100644 --- a/tests/ut/cpp/utils/validator_test.cc +++ b/tests/ut/cpp/utils/validator_test.cc @@ -42,8 +42,8 @@ TEST_F(TestValidator, ValidateOperation01) { } TEST_F(TestValidator, ValidateAbstract01) { - AnfNodePtr node = NewValueNode(1); - abstract::AbstractBasePtr abstract_v1 = abstract::FromValue(1, false); + AnfNodePtr node = NewValueNode(static_cast(1)); + abstract::AbstractBasePtr abstract_v1 = abstract::FromValue(static_cast(1), false); node->set_abstract(abstract_v1); ValidateAbstract(node); // normally, the above statement should not exit, so expected the following statement execute diff --git a/tests/ut/cpp/vm/vm_test.cc b/tests/ut/cpp/vm/vm_test.cc index 9168d408c3d..a373d35cd07 100644 --- a/tests/ut/cpp/vm/vm_test.cc +++ b/tests/ut/cpp/vm/vm_test.cc @@ -45,13 +45,15 @@ TEST_F(TestCompileVM, StructPartial) { TEST_F(TestCompileVM, FinalVM) { std::vector> instr; - instr.push_back({Instruction::kCall, VectorRef({-1})}); - instr.push_back({Instruction::kTailCall, VectorRef({-2, 1, 1})}); - instr.push_back({Instruction::kReturn, VectorRef({-1, 1})}); - instr.push_back({Instruction::kPartial, VectorRef({0, "cc"})}); + instr.push_back({Instruction::kCall, VectorRef({static_cast(-1)})}); + instr.push_back( + {Instruction::kTailCall, VectorRef({static_cast(-2), static_cast(1), static_cast(1)})}); + instr.push_back({Instruction::kReturn, VectorRef({static_cast(-1), static_cast(1)})}); + instr.push_back({Instruction::kPartial, VectorRef({static_cast(0), "cc"})}); BackendPtr backend = std::make_shared("vm"); auto vm = new FinalVM(instr, backend); - vm->Eval(VectorRef({1, 2, 3, -1, "a", "b", "c"})); + vm->Eval(VectorRef({static_cast(1), static_cast(2), static_cast(3), + static_cast(-1), "a", "b", "c"})); delete vm; vm = nullptr; } diff --git a/tests/ut/python/pynative_mode/test_implicit_conversion.py b/tests/ut/python/pynative_mode/test_implicit_conversion.py index 594bc29d484..aab0961f560 100644 --- a/tests/ut/python/pynative_mode/test_implicit_conversion.py +++ b/tests/ut/python/pynative_mode/test_implicit_conversion.py @@ -47,7 +47,7 @@ def test_bool_tensor_and_int_add(): x = Tensor(np.array([[True, False], [False, True]], dtype=np.bool_)) y = 3 ret_actual = x + y - ret_expect = Tensor(np.array([[4, 3], [3, 4]], dtype=np.int32)) + ret_expect = Tensor(np.array([[4, 3], [3, 4]], dtype=np.int64)) assert ret_actual.dtype == ret_expect.dtype assert (ret_actual.asnumpy() == ret_expect.asnumpy()).all() diff --git a/tests/ut/python/pynative_mode/test_partial.py b/tests/ut/python/pynative_mode/test_partial.py index 776d9daa370..fcd5a651e20 100644 --- a/tests/ut/python/pynative_mode/test_partial.py +++ b/tests/ut/python/pynative_mode/test_partial.py @@ -45,7 +45,7 @@ def test_full_simple_add(): MULTI_ADD = C.MultitypeFuncGraph('add') -@MULTI_ADD.register("Int32", "Int32") +@MULTI_ADD.register("Int64", "Int64") def add_int(x, y): return F.scalar_add(x, y)