CANN/metadef属性转换追加函数
AppendConvertedAttrVal【免费下载链接】metadefAscend Metadata Definition项目地址: https://gitcode.com/cann/metadef函数功能将RuntimeAttrs内存中的第index个属性从src_type数据类型转成dst_type数据类型后追加在当前的tilingdata后面。函数原型ge::graphStatus AppendConvertedAttrVal(const RuntimeAttrs *attrs, const size_t attr_index, const AttrDataType src_type, const AttrDataType dst_type)参数说明表 1参数列表参数输入/输出说明attrs输入图执行时的属性。attr_index输入属性的序号。src_type输入属性的原始dtype。AttrDataType类型具体定义如下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 };src_type和dst_type支持的取值范围和对应关系见表2。dst_type输入属性的目标dtype。src_type和dst_type支持的取值范围和对应关系见表2。表 2src_type和dst_type支持的取值范围和对应关系src_typedst_typekInt64kInt32、kUint32kListInt64kListInt32、kListUint32kInt32kInt32kListInt32kListInt32kFloat32kFloat32、kFloat16、kBfloat16、kInt64、kInt32、kInt16、kInt8kListFloat32kListFloat32、kListFloat16、kListInt64、kListInt32、kListInt16、kListInt8kBoolkBoolkStringkString返回值说明成功返回ge::GRAPH_SUCCESS。失败返回ge::GRAPH_FAILED。约束说明无。调用示例auto td_buf TilingData::CreateCap(100U); auto td reinterpret_castTilingData *(td_buf.get()); auto holder BuildTestContext(); auto context holder.GetContextTilingContext(); 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::CreateFromint64_t(0x7fffffffUL)}, {str, ge::AnyValue::CreateFromstd::string(Hello!)}, {bool, ge::AnyValue::CreateFrombool(true)}, {float, ge::AnyValue::CreateFromfloat(10.101)}, {list_int, ge::AnyValue::CreateFromstd::vectorint64_t({1, 2, 3})}, {list_int2, ge::AnyValue::CreateFromstd::vectorint64_t({4, 5, 6})}, {list_float, ge::AnyValue::CreateFromstd::vectorfloat({1.2, 3.4, 4.5})}}) .Build(); return holder; }【免费下载链接】metadefAscend Metadata Definition项目地址: https://gitcode.com/cann/metadef创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考