news 2026/9/10 4:34:01

CANN/ge图引擎GNode设置属性API

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/ge图引擎GNode设置属性API

SetAttr

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

产品支持情况

全量芯片支持。

头文件/库文件

  • 头文件:#include <graph/gnode.h>
  • 库文件:libgraph.so

功能说明

设置Node属性的属性值。

Node可以包括多个属性,初次设置值后,算子属性值的类型固定,算子属性值的类型包括:

  • 整型:接受int64_t、uint32_t、int32_t类型的整型值

    使用SetAttr(const AscendString& name, int64_t &attrValue)设置属性值,以GetAttr(const AscendString& name, int32_t &attrValue) 、GetAttr(const AscendString& name, uint32_t &attrValue)取值时,用户需保证整型数据没有截断,同理针对int32_t和uint32_t混用时需要保证不被截断。

  • 整型列表:接受std::vector<int64_t>、std::vector<int32_t>、std::vector<uint32_t>表示的整型列表数据

  • 浮点数:float

  • 浮点数列表:std::vector<float>

  • 字符串:AscendString

  • 字符串列表:std::vector<AscendString>

  • 布尔:bool

  • 布尔列表:std::vector<bool>

  • Tensor:Tensor

  • Tensor列表:std::vector<Tensor>

  • OpBytes:字节数组,vector<uint8_t>

  • AttrValue类型

  • 整型二维列表类型:std::vector<std::vector<int64_t>

  • DataType列表类型:vector<ge::DataType>

  • DataType类型:DataType

函数原型

graphStatus SetAttr(const AscendString &name, int64_t &attr_value) const graphStatus SetAttr(const AscendString &name, int32_t &attr_value) const graphStatus SetAttr(const AscendString &name, uint32_t &attr_value) const graphStatus SetAttr(const AscendString &name, float32_t &attr_value) const graphStatus SetAttr(const AscendString &name, AscendString &attr_value) const graphStatus SetAttr(const AscendString &name, bool &attr_value) const graphStatus SetAttr(const AscendString &name, Tensor &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<int64_t> &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<int32_t> &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<uint32_t> &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<float32_t> &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<AscendString> &attr_values) const graphStatus SetAttr(const AscendString &name, std::vector<bool> &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<Tensor> &attr_value) const graphStatus SetAttr(const AscendString &name, OpBytes &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<std::vector<int64_t>> &attr_value) const graphStatus SetAttr(const AscendString &name, std::vector<ge::DataType> &attr_value) const graphStatus SetAttr(const AscendString &name, ge::DataType &attr_value) const graphStatus SetAttr(const AscendString &name, AttrValue &attr_value) const

参数说明

参数名输入/输出说明
name输入属性名称。可设置的属性名请参见属性名列表。
attr_value输入需设置的int64_t表示的整型类型属性值。
attr_value输入需设置的int32_t表示的整型类型属性值。
attr_value输入需设置的uint32_t表示的整型类型属性值。
attr_value输入需设置的浮点类型float的属性值。
attr_value输入需设置的字符串类型AscendString的属性值。
attr_value输入需设置的布尔类型bool的属性值。
attr_value输入需设置的Tensor类型的属性值。
attr_value输入需设置的vector<int64_t>表示的整型列表类型属性值。
attr_value输入需设置的vector<int32_t>表示的整型列表类型属性值。
attr_value输入需设置的vector<uint32_t>表示的整型列表类型属性值。
attr_value输入需设置的浮点列表类型vector<float>的属性值。
attr_value输入需设置的字符串列表类型vector<ge::AscendString>的属性值。
attr_value输入需设置的布尔列表类型vector<bool>的属性值。
attr_value输入需设置的Tensor列表类型vector<Tensor>的属性值。
attr_value输入需设置的Bytes,即字节数组类型的属性值,OpBytes即vector<uint8_t>。
attr_value输入需设置的vector<vector<int64_t>>表示的整型二维列表类型属性值。
attr_value输入需设置的vector<ge::DataType>表示的DataType列表类型属性值。
attr_value输入需设置的DataType类型的属性值。
attr_value输入需设置的AttrValue类型的属性值。

返回值说明

参数名类型说明
-graphStatusGRAPH_SUCCESS(0):成功。
其他值:失败。

约束说明

调用示例

gNode node; node.SetAttr(_op_exec_never_timeout,true);

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/10 4:31:44

Modbus调试三层次解剖:物理层、链路层与应用层协同排障

1. 为什么MODBUS至今仍是嵌入式现场的“硬通货”——从蓝桥杯国赛真题说起你有没有在调试一个STM32F103板子时&#xff0c;明明串口波形干净、电平标准、接线无误&#xff0c;但Modbus Poll就是收不到响应&#xff1f;或者更糟——它偶尔能读到寄存器&#xff0c;但一发写命令就…

作者头像 李华
网站建设 2026/9/10 4:31:36

STM32核心寄存器实战指南:23个高频生死线详解

1. 这不是“背诵清单”&#xff0c;而是嵌入式工程师的寄存器操作地图你翻过STM32参考手册第几遍&#xff1f;是不是每次查到某个外设章节&#xff0c;光是寄存器列表就密密麻麻占满十几页&#xff0c;字段名缩写像天书&#xff0c;复位值记了又忘&#xff0c;配置顺序一错整个…

作者头像 李华