SetAttr

Applicability

Product

Supported or Not

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference products

Atlas training products

Header File/Library File

  • Header file: #include <graph/operator.h>
  • Library file: libgraph.so

Function Usage

Sets the value of an operator attribute.

An operator may have multiple attributes. Once the value of an attribute is set, 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 string& name, int64_t attrValue) to set an attribute value, and use GetAttr(const string& name, int32_t& attrValue) or GetAttr(const string& name, uint32_t& attrValue) to obtain the value. Ensure that the integer data is not clipped. It is the same for the types int32_t and uint32_t.

  • Integer list: std::vector<int64_t>, std::vector<int32_t>, std::vector<uint32_t>, or std::initializer_list<int64_t>&&
  • Floating-point number: float
  • Floating-point number list: std::vector<float>
  • String: string
  • String list: std::vector<std::string>
  • Bool: bool
  • Bool list: std::vector<bool>
  • Tensor: Tensor
  • Tensor list: std::vector<Tensor>
  • Arrays of bytes: OpBytes (that it, vector<uint8_t>) or (const uint8_t* data, size_t size)
  • AttrValue: AttrValue
  • 2D integer list: std::vector<std::vector<int64_t>>
  • DataType list: std::vector<ge::DataType>
  • DataType: ge::DataType
  • NamedAttrs: ge::NamedAttrs
  • NamedAttrs list: std::vector<ge::NamedAttrs>

Prototype

APIs taking string arguments will be deprecated in future releases. Use APIs taking non-string arguments instead.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Operator &SetAttr(const std::string &name, int64_t attr_value)
Operator &SetAttr(const std::string &name, int32_t attr_value)
Operator &SetAttr(const std::string &name, uint32_t attr_value)
Operator &SetAttr(const std::string &name, const std::vector<int64_t> &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<int32_t> &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<uint32_t> &attr_value)
Operator &SetAttr(const std::string &name, std::initializer_list<int64_t> &&attr_value)
Operator &SetAttr(const std::string &name, float32_t attr_value)
Operator &SetAttr(const std::string &name, const std::vector<float32_t> &attr_value)
Operator &SetAttr(const std::string &name, AttrValue &&attr_value)
Operator &SetAttr(const std::string &name, const std::string &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<std::string> &attr_value)
Operator &SetAttr(const std::string &name, bool attr_value)
Operator &SetAttr(const std::string &name, const std::vector<bool> &attr_value)
Operator &SetAttr(const std::string &name, const Tensor &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<Tensor> &attr_value)
Operator &SetAttr(const std::string &name, const OpBytes &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<std::vector<int64_t>> &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<ge::DataType> &attr_value)
Operator &SetAttr(const std::string &name, const ge::DataType &attr_value)
Operator &SetAttr(const std::string &name, const ge::NamedAttrs &attr_value)
Operator &SetAttr(const std::string &name, const std::vector<ge::NamedAttrs> &attr_value)
Operator &SetAttr(const char_t *name, int64_t attr_value)
Operator &SetAttr(const char_t *name, int32_t attr_value)
Operator &SetAttr(const char_t *name, uint32_t attr_value)
Operator &SetAttr(const char_t *name, const std::vector<int64_t> &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<int32_t> &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<uint32_t> &attr_value)
Operator &SetAttr(const char_t *name, std::initializer_list<int64_t> &&attr_value)
Operator &SetAttr(const char_t *name, float32_t attr_value)
Operator &SetAttr(const char_t *name, const std::vector<float32_t> &attr_value)
Operator &SetAttr(const char_t *name, AttrValue &&attr_value)
Operator &SetAttr(const char_t *name, const char_t *attr_value)
Operator &SetAttr(const char_t *name, const AscendString &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<AscendString> &attr_values)
Operator &SetAttr(const char_t *name, bool attr_value)
Operator &SetAttr(const char_t *name, const std::vector<bool> &attr_value)
Operator &SetAttr(const char_t *name, const Tensor &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<Tensor> &attr_value)
Operator &SetAttr(const char_t *name, const OpBytes &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<std::vector<int64_t>> &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<ge::DataType> &attr_value)
Operator &SetAttr(const char_t *name, const ge::DataType &attr_value)
Operator &SetAttr(const char_t *name, const ge::NamedAttrs &attr_value)
Operator &SetAttr(const char_t *name, const std::vector<ge::NamedAttrs> &attr_value)

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 vector<int64_t>.

attr_value

Input

Attribute value of type vector<int32_t>.

attr_value

Input

Attribute value of type vector<uint32_t>.

attr_value

Input

Attribute value of type std::initializer_list<int64_t>&&.

attr_value

Input

Attribute value of the floating-point type.

attr_value

Input

Attribute value of the floating-point list type.

attr_value

Input

Attribute value of the bool type.

attr_value

Input

Attribute value of the bool list type.

attr_value

Input

Attribute value of type AttrValue.

attr_value

Input

Attribute value of the string type.

attr_value

Input

Attribute value of the string list type.

attr_value

Input

Attribute value of type Tensor.

attr_value

Input

Attribute value of the tensor list type.

attr_value

Input

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

data

Input

Attribute value of type Bytes, specifying the start address of a byte stream.

size

Input

Attribute value of type Bytes, specifying the length of a byte stream.

attr_value

Input

Attribute value of the quantized data type.

attr_value

Input

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

attr_value

Input

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

attr_value

Input

Attribute value of type DataType.

attr_value

Input

Attribute value of type NamedAttrs

attr_value

Input

Attribute value of type vector<ge::NamedAttrs>

Returns

Object of class Operator.

Exception Handling

None

Constraints

None