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 249a8b3ef01..819da97a120 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 @@ -111,8 +111,8 @@ class OpInfoExtractor { op_attr->set_type("bool"); } else if (v->isa()) { op_attr->set_type("str"); - } else if (v->isa() || v->isa()) { - auto vec = v->isa() ? v->cast()->value() : v->cast()->value(); + } else if (v->isa()) { + const auto &vec = v->cast()->value(); if (vec.empty()) { op_attr->set_type("listInt"); } else if (vec[0]->isa() || vec[0]->isa()) { @@ -262,10 +262,14 @@ void AkgKernelJsonGenerator::GetAttrJson(const AnfNodePtr &anf_node, const std:: MS_EXCEPTION_IF_NULL(anf_node); MS_EXCEPTION_IF_NULL(op_attr); MS_EXCEPTION_IF_NULL(attr_json); + + auto get_int_value = [](const ValuePtr &value) -> int { + return value->isa() ? static_cast(GetValue(value)) : GetValue(value); + }; std::string type = op_attr->type(); (*attr_json)[kJsonKeyDataType] = type; if (type == "int") { - (*attr_json)[kJsonKeyValue] = static_cast(GetValue(attr_value)); + (*attr_json)[kJsonKeyValue] = get_int_value(attr_value); } else if (type == "str") { (*attr_json)[kJsonKeyValue] = GetValue(attr_value); } else if (type == "bool") { @@ -274,9 +278,8 @@ void AkgKernelJsonGenerator::GetAttrJson(const AnfNodePtr &anf_node, const std:: (*attr_json)[kJsonKeyValue] = GetValue(attr_value); } else if (type == "listInt") { 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); }); + const auto &vals = attr_value->cast()->value(); + (void)std::transform(vals.begin(), vals.end(), std::back_inserter(list_int), get_int_value); (*attr_json)[kJsonKeyValue] = list_int; } else if (type == "listStr") { std::vector data_format;