AppendConvertedAttrVal

Description

Casts the data type of the indexth attribute in RuntimeAttrs memory from src_type to dst_type and appends the attribute to the current tiling data.

Prototype

ge::graphStatus AppendConvertedAttrVal(const RuntimeAttrs *attrs, const size_t attr_index, const AttrDataType src_type, const AttrDataType dst_type)

Parameters

Table 1 Parameter list

Parameter

Input/Output

Description

attrs

Input

Attribute during graph execution: IR attribute and private attribute.

attr_index

Input

Index of an attribute.

src_type

Input

Original dtype of an attribute, which is of the AttrDataType type. The specific definition is as follows:

enum class AttrDataType : int32_t {
  kBool = 0,
  kString,
  kInt32,
  kInt64,
  kUint32,
  kFloat32,
  kFloat16,
  kListBool,
  kListString,
  kListInt32,
  kListInt64,
  kListUint32,
  kListFloat32,
  kListFloat16,
  kListListInt32,
  kListListInt64,
  kBfloat16,
  kInt8,
  kInt16,
  kListInt8,
  kListInt16,
  kTypeEnd
};

For details about the value ranges and mappings between src_type and dst_type, see Table 2.

dst_type

Input

Target dtype of an attribute.

For details about the value ranges and mappings between src_type and dst_type, see Table 2.

Table 2 Value ranges and mappings between src_type and dst_type

src_type

dst_type

kInt64

kInt32 and kUint32

kListInt64

kListInt32 and kListUint32

kInt32

kInt32

kListInt32

kListInt32

kFloat32

kFloat32, kFloat16, kBfloat16, kInt64, kInt32, kInt16, and kInt8

kListFloat32

kListFloat32, kListFloat16, kListInt64, kListInt32, kListInt16, and kListInt8

kBool

kBool

kString

kString

Returns

  • ge::GRAPH_SUCCESS on success.
  • ge::GRAPH_FAILED on failure.

Restrictions

None

Example

auto td_buf = TilingData::CreateCap(100U);
auto td = reinterpret_cast<TilingData *>(td_buf.get());

auto holder = BuildTestContext();
auto context = holder.GetContext<TilingContext>();
auto ret = td->AppendConvertedAttrVal(context->GetAttrs(), 1, AttrDataType::kString, AttrDataType::kString)


FakeKernelContextHolder BuildTestContext() {
  auto holder = gert::KernelRunContextFaker()
                    .NodeIoNum(1, 1)
                    .IrInputNum(1)
                    .NodeInputTd(0, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND)
                    .NodeOutputTd(0, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ)
                    .NodeAttrs({{"int", ge::AnyValue::CreateFrom<int64_t>(0x7fffffffUL)},
                                {"str", ge::AnyValue::CreateFrom<std::string>("Hello!")},
                                {"bool", ge::AnyValue::CreateFrom<bool>(true)},
                                {"float", ge::AnyValue::CreateFrom<float>(10.101)},
                                {"list_int", ge::AnyValue::CreateFrom<std::vector<int64_t>>({1, 2, 3})},
                                {"list_int2", ge::AnyValue::CreateFrom<std::vector<int64_t>>({4, 5, 6})},
                                {"list_float", ge::AnyValue::CreateFrom<std::vector<float>>({1.2, 3.4, 4.5})}})
                    .Build();
  return holder;
}