SetAttr

Description

Sets attribute values of a node.

A node may have multiple attributes. After an attribute value is set for the first time, the data type of the attribute is fixed. The following data types are supported:

  • Integer: int64_t, uint32_t, and int32_t

    Use SetAttr(const AscendString& name, int64_t attrValue) to set the attribute value, and use GetAttr(const AscendString& name, int32_t& attrValue) or GetAttr(const AscendString& name, uint32_t& attrValue) to obtain the value. Ensure that the integer data is not truncated. It is the same for the types int32_t and uint32_t.

  • List of integers: std::vector<int64_t>, std::vector<int32_t>, and std::vector<uint32_t>
  • Floating-point number: float
  • List of floating-point numbers: std::vector<float>
  • String: AscendString
  • List of strings: std::vector<AscendString>
  • Bool: bool
  • List of bools: std::vector<bool>
  • Tensor: Tensor
  • List of Tensors: std::vector<Tensor>
  • OpBytes: vector<uint8_t>
  • AttrValue type: AttrValue
  • 2D list of integers: std::vector<std::vector<int64_t>
  • List of DataTypes: std::vector<ge::DataType>
  • DataType: ge::DataType

Prototype

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;

Parameters

Parameter

Input/Output

Description

name

Input

Attribute name.

attr_value

Input

Attribute value of type int64_t.

attr_value

Input

Attribute value of type int32_t.

attr_value

Input

Attribute value of type uint32_t.

attr_value

Input

Attribute value of type float.

attr_value

Input

Attribute value of type AscendString.

attr_value

Input

Attribute value of type bool.

attr_value

Input

Attribute value of type Tensor.

attr_value

Input

Attribute value of type std::vector<int64_t>.

attr_value

Input

Attribute value of type std::vector<int32_t>.

attr_value

Input

Attribute value of type std::vector<uint32_t>.

attr_value

Input

Attribute value of type std::vector<float>.

attr_value

Input

Attribute value of type std::vector<ge::AscendString>.

attr_value

Input

Attribute value of type std::vector<bool>.

attr_value

Input

Attribute value of type std::vector<Tensor>.

attr_value

Input

Attribute value of type OpBytes, or std::vector<uint8_t>.

attr_value

Input

Attribute value of type std::vector<std::vector<int64_t>>.

attr_value

Input

Attribute value of type std::vector<ge::DataType>.

attr_value

Input

Attribute value of type ge::DataType.

attr_value

Input

Attribute value of type AttrValue.

Returns

Parameter

Type

Description

-

graphStatus

GRAPH_SUCCESS(0) on success;

else, failure.

Restrictions

None