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

REQUIRED_ATTR

Function Prototype

REQUIRED_ATTR (x, type)

Function Description

Registers an operator attribute. The default value must be specified.

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.

For example, register the attribute mode of the int64_t type by calling the REQUIRED_ATTR (mode, Int) API. After the operator attribute is successfully registered, the following APIs are automatically generated:

static const string name_attr_mode(); // Returns the attribute name, that is, mode.
OpInt get_attr_mode() const; // Returns the value of the mode attribute. OpInt indicates int64_t.
_THIS_TYPE& set_attr_mode(const OpInt& v); // Sets the value of the mode attribute. A this object is returned.

Parameter Description

Parameter

Input/Output

Type

Description

x

Input

-

Macro parameter, attribute name of the operator

type

Input

-

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.