Class Primitive

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class Primitive : public mindspore::Named

Primitive defines a operator primitive of MindSpore.

Subclassed by mindspore::ops::PrimitiveC, mindspore::prim::DoSignaturePrimitive

Public Functions

explicit Primitive(const std::string &name, const bool is_base = true, const PrimType prim_type = kPrimTypeBuiltIn)

The constructor of Primitive.

Parameters
  • name[in] The name of primitive.

  • is_base[in] True means the basic Primitive without BProp function inside.

  • prim_type[in] The type of primitive.

Primitive(const Primitive &prim)

The constructor for Primitive, create a primitive for another primitive.

Parameters

prim[in] The input primitive.

inline virtual std::string ToString() const override

Get name for Named.

Returns

The restored name of Named.

inline void BeginRecordAddAttr()

Ready to recording the attribute if the attribute needs to be added when deducing shape and type. This attributes has been recorded needs to add in infer cache.

inline void EndRecordAddAttr()

End recording attribute.

inline Primitive &AddAttr(const std::string &name, const ValuePtr &attr)

Add attribute to primitive attribute map and record the new attribute to evaluate_added_attrs_, if record_evaluate_add_attr_ is true.

Parameters
  • name[in] The name of attribute.

  • attr[in] The value of attribute.

Returns

The primitive to which attribute has been added.

inline Primitive &DelAttr(const std::string &name)

Delete the attribute.

Parameters

name[in] The name of attribute to be delete.

Returns

The primitive to which attribute has been added.

inline Primitive &SetAttrs(const mindspore::HashMap<std::string, ValuePtr> &attrs)

Use add attribute by using a map,all elements of the map will be added in the primitive’s attribute map.

Parameters

attrs[in] The attribute map needs to be added in the primitive attribute.

Returns

The primitive to which attribute has been added.

inline void set_attr(const std::string &attrName, const ValuePtr &attr)

Set attribute to the primitive attribute map.

inline void EraseAttr(const std::string &attrName)

Erase attribute to the primitive attribute map.

inline virtual BaseRef RunComputeFunction(const VectorRef&) const

Run Primitive’s compute function if the compute function has been implemented.

Parameters

args[in] The arguments of primitive need to compute.

Returns

The primitive’s calculation result.

inline ValuePtr GetAttr(const std::string &attrName) const

Get Primitive’s attribute.

Parameters

attrName[in] Primitive attribute name.

Returns

The value of attribute in primitive attribute map, if the map is not

inline const mindspore::HashMap<std::string, ValuePtr> &attrs() const

Get Primitive’s all attributes.

Returns

The Primitive’s all attribute.

inline const mindspore::HashMap<std::string, ValuePtr> &evaluate_added_attrs() const

Get the attributes added in MindSpore renormalize stage.

Returns

Attributes which have been added in MindSpore renormalize stage.

inline void set_evaluate_added_attrs(const mindspore::HashMap<std::string, ValuePtr> &attrs)

Use add attribute using a map,all elements of the map will be added in the primitive’s attribute map.

Parameters

attrs[in] The attribute map needs to be added in the primitive attribute.

inline bool HasAttr() const

Check if Primitive has any attribute. for example Primitives like scalar_add, return, etc, don’t have any attribute.

Returns

Return ture, If Primitive has attributes, else return false.

inline bool HasAttr(const std::string &attrName) const

Check If Primitive has an attribute named attrName.

Parameters

attrName[in] The name of attribute.

Returns

Return true if Primitive has an attribute named attrName,else return false.

inline void set_prim_type(const PrimType t)

Set the name of primitive.

Parameters

t – The primitive type that needs to be set.

inline virtual PrimitivePtr Clone()

Clone a Primitive.

Returns

A Primitive which cloned by current primitive.

inline void set_instance_name(const std::string &s)

Set primitive instance_name.

Parameters

s[in] The primitive instance name to be set.

inline bool HasPyEvaluator() const

Check whether the primitive type if has the Python infer function,.

Returns

Return true if Primitive’s type is kPrimTypePyInfer or kPrimTypeUserCustom, else return false.

inline bool IsCustomPrim() const

Check whether the primitive type if has the python infer function,.

Returns

Return true if Primitive’s type is kPrimTypeUserCustom, else return false.

inline PrimType prim_type() const

Get Primitive type.

Returns

The type of Primitive.

inline std::string instance_name() const

Get primitive instance name.

Returns

The instance name of primitive.

std::string GetAttrsText() const

Get primitive attribute debug string. If the attribute name of primitive is a,the value is b The return value of GetAttrsText function is [a=b].

Returns

Get attribute debug string of primitive.

~Primitive() override = default

Destructor of Primitive.

inline void set_has_signature(bool has_signature)

The flag to be set in primitive.

Parameters

has_signature[in] Set the flag whether there is a signature for the primitive.

inline bool has_signature() const

Check whether the primitive has signature.

Returns

Return true if primitive has signature flag , else return false.

inline bool is_base() const

Check whether the primitive is a basic primitive.

Returns

Return true if the primitive is basic, else return false.

inline void set_const_prim(bool is_const_prim)

Set primitive const flag. If the is_const_prim_ of primitive is true means the primitive will be eliminated in constant folding.

Parameters

is_const_prim – The flag of primitive to be set.

inline bool is_const_prim() const

Check whether the primitive is const primitive.

Returns

Return true if primitive is a const primitive, else return false.

inline void set_const_input_indexes(const std::vector<size_t> &const_input_indexes)

Set const input index for primitive.

Parameters

const_input_indexes – The const input index of the primitive to be set.

inline const std::vector<size_t> &get_const_input_indexes() const

Get const input index of the primitive.

Returns

Const input indexes of the primitive.

inline uint64_t id() const

Get Primitive’s id.

Returns

primitive’s Id.