From 5edf2b3d9210fc0648439e6356b5d2df8a557f9d Mon Sep 17 00:00:00 2001 From: dayschan Date: Fri, 23 Apr 2021 19:24:49 +0800 Subject: [PATCH] Bugfix of GetValue when the attr is a list that mixed with Int32Imm and Int64Imm (unreasonable, but it occured), it will crash whether we use GetValue> or GetValue>. so we need to traverse the list and pick the numbers manually. --- .../akg/akg_kernel_json_generator.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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;