Updated on 2022-03-13 GMT+08:00

ATTR

Function Prototype

ATTR(x, default_value)

Function Description

Registers an operator attribute. The default value must be specified, so that the default value can be used if the attribute value of an operator object is not set.

After the operator attributes are successfully registered, three external APIs (for obtaining the attribute name, obtaining the attribute value, and setting the attribute value, respectively) are automatically generated.

The following describes the operator attribute APIs generated in int64_t and int64_t list scenarios:

  • Register the attribute mode by calling ATTR(mode, AttrValue::INT{1}). The attribute type is int64_t and the default value is 1.

    After the attribute is successfully registered, the following APIs are automatically generated:

    static const string name_attr_mode(); // Returns the attribute name, that is, mode.
    int64_t get_attr_mode() const; // Returns the value of the mode attribute.
    _THIS_TYPE& set_attr_mode(int64_t v); // Sets the value of the mode attribute. The operator object is returned.
  • Register the pad attribute by calling ATTR(pad, AttrValue::LIST_INT{0, 0, 0, 0}). The attribute type is int64_t list. The default value is {0,0,0,0}.

    After the attribute is successfully registered, the following APIs are automatically generated:

    static const string name_attr_pad(); // Returns the attribute name, that is, pad.
    vector<int64_t> get_attr_pad() const;; // Returns the value of the pad attribute.
    _THIS_TYPE& set_attr_pad(vector<int64_t> v); // Sets the value of the pad attribute. The operator object is returned.

Parameter Description

Parameter

Input/Output

Type

Description

x

Input

-

Macro parameter, attribute name of the operator

default_value

Input

-

Value of an operator attribute. The default value varies depending on the attribute type. The following attribute types are supported:

  • AttrValue::INT: The attribute type is int64_t.
  • AttrValue::FLOAT, The attribute type is float.
  • AttrValue::STR: The attribute type is string.
  • AttrValue::BOOL: The attribute type is bool.
  • AttrValue::TENSOR: The attribute type is tensor.
  • AttrValue::LIST_INT: The attribute type is vector<int64_t> (int64_t list).
  • AttrValue::LIST_FLOAT: The attribute type is vector<float> (float list).
  • AttrValue::LIST_STR: The attribute type is vector<string> (string list).
  • AttrValue::LIST_BOOL: The attribute type is vector<bool> (bool list).
  • AttrValue::LIST_TENSOR: The attribute type is vector<Tensor> (tensor list).

Return Value

None

Exception Handling

None

Restriction

For an operator, the registered attribute name must be unique.