OpAttrDef

Function Usage

Defines operator attributes.

Prototype

class OpAttrDef {
public:
  explicit OpAttrDef(const char *name);
  OpAttrDef(const OpAttrDef &attr_def);
  ~OpAttrDef();
  OpAttrDef &operator=(const OpAttrDef &attr_def);
  OpAttrDef &AttrType(Option attr_type);
  OpAttrDef &Bool(void);
  OpAttrDef &Bool(bool value);
  OpAttrDef &Float(void);
  OpAttrDef &Float(float value);
  OpAttrDef &Int(void);
  OpAttrDef &Int(int64_t value);
  OpAttrDef &String(void);
  OpAttrDef &String(const char *value);
  OpAttrDef &ListBool(void);
  OpAttrDef &ListBool(std::vector<bool> value);
  OpAttrDef &ListFloat(void);
  OpAttrDef &ListFloat(std::vector<float> value);
  OpAttrDef &ListInt(void);
  OpAttrDef &ListInt(std::vector<int64_t> value);
  OpAttrDef &ListListInt(void);
  OpAttrDef &ListListInt(std::vector<std::vector<int64_t>> value);
  OpAttrDef &Version(uint32_t version);
  ge::AscendString &GetName(void) const;
  bool IsRequired(void);
private:
  ...
};

Function Usage

Table 1 Member functions of the OpAttrDef class

Function Name

Input Parameter Description

Function Description

AttrType

attr_type: attribute type.

Sets the operator attribute type. The value can be OPTIONAL or REQUIRED.

Bool

None

Sets the operator attribute data type to Bool.

Bool

value

Sets the operator attribute type to Bool and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

Float

None

Sets the operator attribute data type to Float.

Float

value

Sets the operator attribute type to Float and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

Int

None

Sets the operator attribute data type to Int.

Int

value

Sets the operator attribute type to Int and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

String

None

Sets the operator attribute data type to String.

String

value

Sets the operator attribute type to String and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

ListBool

None

Sets the operator attribute data type to ListBool.

ListBool

value

Sets the operator attribute type to ListBool and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

ListFloat

None

Sets the operator attribute data type to ListFloat.

ListFloat

value

Sets the operator attribute type to ListFloat and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

ListInt

None

Sets the operator attribute data type to ListInt.

ListInt

value

Sets the operator attribute type to ListInt and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

ListListInt

None

Sets the operator attribute data type to ListListInt.

ListListInt

value

Sets the operator attribute type to ListListInt and the default attribute value to value. If the attribute type is set to OPTIONAL, this API class must be called to set the default value.

Version

version: configured version number.

When adding optional attributes, in order to maintain compatibility of the original single-operator API (aclnnxxx), use the Version API to configure its version number. The version number should start from 1 and be configured continuously (and uniformly numbered with the optional inputs). After the configuration, the automatically generated aclnn API will carry the version number. The API of a later version contains all parameters of the API of an earlier version.

GetName

None

Obtains the attribute name.

IsRequired

None

Determines whether an operator attribute is required. If it is, true is returned. If not, false is returned.