Internal APIs
This section describes the internal data structure and APIs required for operator execution, registration, and Infershape. These APIs are not directly called by users.
These APIs are declared in operator_factory.h and inference_context.h files.
Class OperatorFactory
CreateOperator
Function
Obtains the operator object instance based on the operator name and operator type.
Prototype
static Operator CreateOperator(const std::string &operator_name, const std::string &operator_type)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
operator_name |
Input |
Operator name. |
operator_type |
Input |
Operator type. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
string |
Operator object instance. |
Restriction
None
GetOpsTypeList
Function
Obtains the list of all supported operator types.
Prototype
static graphStatus GetOpsTypeList(std::vector<std::string> &all_ops)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
all_ops |
Output |
List of operator types. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
|
Restrictions
None
IsExistOp
Function
Queries whether a specified operator type is supported.
Prototype
static bool IsExistOp(const string &operator_type)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
operator_type |
Input |
Operator type. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
bool |
|
Restrictions
None
Class OperatorCreatorRegister
Constructor and Destructor
Function
OperatorCreatorRegister constructor and destructor.
Prototype
OperatorCreatorRegister (const string &operatorType, OpCreator const &opCreator);
~ OperatorCreatorRegister()
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
operatorType |
Input |
Operator type. |
opCreator |
Input |
Operator constructor. |
Returns
The OperatorCreatorRegister constructor returns an object of the OperatorCreatorRegister type.
Restrictions
This API registers an operator prototype and is referenced by other header files. Therefore, it is not directly called by the operator developer.
Class InferShapeFuncRegister
Constructor and Destructor
Function
InferShapeFuncRegister constructor and destructor.
Prototype
InferShapeFuncRegister (const std::string &operatorType, InferShapeFunc inferShapeFunc);
~ InferShapeFuncRegister()
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
operatorType |
Input |
Operator type. |
inferShapeFunc |
Input |
Infershape function of the operator. |
Returns
The InferShapeFuncRegister constructor returns an object of the InferShapeFuncRegister type.
Restrictions
This API registers the operator infershape function and is referenced by other header files. Therefore, it is not directly called by the operator developer.
Class InferFormatFuncRegister
Constructor and Destructor
Function
InferFormatFuncRegister constructor and destructor.
Prototype
InferFormatFuncRegister(const std::string &operatorType, InferFormatFunc inferFormatFunc);
~InferFormatFuncRegister()
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
operatorType |
Input |
Operator type. |
InferFormatFunc |
Input |
InferFormat function of the operator. |
Returns
The InferFormatFuncRegister constructor returns an object of the InferFormatFuncRegister type.
Restrictions
This API registers the InferFormat function of the operator and is referenced by other header files. Therefore, it is not directly called by the operator developer.
Class VerifyFuncRegister
Constructor and Destructor
Function
VerifyFuncRegister constructor and destructor.
Prototype
VerifyFuncRegister (const std::string &operatorType, VerifyFunc verifyFunc);
~ VerifyFuncRegister()
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
operatorType |
Input |
Operator type. |
verifyFunc |
Input |
Operator Verify function. |
Returns
The VerifyFuncRegister constructor returns an object of the VerifyFuncRegister type.
Restrictions
This API registers the verify function of an operator. This API is referenced by other header files and does not need to be directly called by the operator developer.
Class InferenceContext
InferenceContext Constructor and Destructor
Description
Constructs or destructs a InferenceContext object.
Prototype
~InferenceContext() = default;
InferenceContext(const InferenceContext &context) = delete;
InferenceContext(const InferenceContext &&context) = delete;
InferenceContext &operator=(const InferenceContext &context) = delete;
InferenceContext &operator=(const InferenceContext &&context) = delete
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
context |
Input |
InferenceContext content for initialization. |
Returns
The InferenceContext constructor returns an object of the InferenceContext type.
Exception Handling
None
Restrictions
None
SetInputHandleShapesAndTypes
Function
In the inference context, set the ShapeAndType of the operator input handle.
Syntax
void SetInputHandleShapesAndTypes(std::vector<std::vector<ShapeAndType>> &&shapes_and_types)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
shapes_and_types |
Input |
ShapeAndType of the operator input handle. |
Return Value
None
Exception Handling
None
Restriction
None
SetOutputHandleShapesAndTypes
Function
In the inference context, set the ShapeAndType of the operator output handle.
Syntax
void SetOutputHandleShapesAndTypes(const std::vector<std::vector<ShapeAndType>> &shapes_and_types);
void SetOutputHandleShapesAndTypes(std::vector<std::vector<ShapeAndType>> &&shapes_and_types)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
shapes_and_types |
Input |
ShapeAndType of the operator output handle. |
Return Value
None
Exception Handling
None
Restriction
None
GetInputHandleShapesAndTypes
Function
In the inference context, obtain the ShapeAndType of the operator input handle.
Syntax
const std::vector<std::vector<ShapeAndType>> &GetInputHandleShapesAndTypes() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
const std::vector<std::vector<ShapeAndType>>& |
ShapeAndType of the operator input handle. |
Exception Handling
None
Restriction
None
GetOutputHandleShapesAndTypes
Function
In the inference context, obtain the ShapeAndType of the operator output handle.
Syntax
const std::vector<std::vector<ShapeAndType>> &GetOutputHandleShapesAndTypes() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
const std::vector<std::vector<ShapeAndType>>& |
ShapeAndType of the operator output handle. |
Exception Handling
None
Restriction
None
SetMarks
Description
Sets a mark for a resource operator pair in the inference context with resource operators.
Prototype
void SetMarks(const std::vector<std::string> &marks)
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
marks |
Input |
Marks of resource operators |
Returns
None
Exception Handling
None
Restrictions
None
GetMarks
Description
Gets a mark for a resource operator pair in the inference context with resource operators.
Prototype
const std::vector<std::string> &GetMarks() const
Parameters
None
Returns
Parameter |
Type |
Description |
---|---|---|
- |
const std::vector<std::vector<ShapeAndType>>& |
Marks of resource operators |
Exception Handling
None
Restrictions
None
Create
Description
Creates a context object for a resource operator in the inference context with resource operators.
Prototype
static std::unique_ptr<InferenceContext> Create()
Parameters
None
Returns
Parameter |
Type |
Description |
---|---|---|
- |
std::unique_ptr<InferenceContext>ShapeAndType>>& |
Context object transferred between resource operators |
Exception Handling
None
Restrictions
None
Class ShapeAndType
Constructor and Destructor
Function
ShapeAndType constructor and destructor.
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
shape |
Input |
Shape to be set. |
dataType |
Input |
Data type to be set. |
Returns
The ShapeAndType constructor returns an object of the ShapeAndType type.
Exception Handling
None
Restrictions
None
SetShape
Function
Sets the shape of class ShapeAndType.
Prototype
void SetShape(const Shape &shape)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
shape |
Input |
Target shape. |
Returns
None
Exception Handling
None
Restrictions
None
SetType
Function
Sets the data type of class ShapeAndType.
Prototype
void SetType(DataType dataType)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
dataType |
Input |
Target data type. |
Returns
None
Exception Handling
None
Restrictions
None