Operator APIs
- Class Operator
- Constructor and Destructor
- GetName
- GetOpType
- SetInput
- AddControlInput
- IsEmpty
- GetInputDesc
- GetOutputDesc
- TryGetInputDesc
- GetInputConstData
- GetDynamicInputNum
- GetDynamicOutputNum
- GetDynamicInputDesc
- GetDynamicOutputDesc
- UpdateInputDesc
- UpdateOutputDesc
- UpdateDynamicInputDesc
- UpdateDynamicOutputDesc
- InferShapeAndType
- SetInferenceContext
- GetInferenceContext
- VerifyAllAttr
- GetInputsSize
- GetOutputsSize
- GetAllAttrNamesAndTypes
- SetAttr
- GetAttr
- BreakConnect
- GetSubgraphNamesCount
- GetSubgraphNames
- GetSubgraphBuilder
- GetSubgraph
- GetDynamicSubgraphBuilder
- GetDynamicSubgraph
- Class Tensor
- Class TensorDesc
- Class Shape
- Class AttrValue
Class Operator
Constructor and Destructor
Function
Operator constructor and destructor
Syntax
Operator();
explicit Operator(const string& type);
explicit Operator(const string& name, const string& type);
virtual ~Operator()
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
type |
Input |
Operator type. |
name |
Input |
Operator name. |
Return Value
The Operator constructor returns an object of the Operator type.
Exception Handling
None
Restriction
None
GetName
Function
Obtains the name of an operator.
Syntax
string GetName() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
string |
Operator name. |
Exception Handling
None
Restriction
None
GetOpType
Function
Obtains the operator type.
Syntax
string GetOpType() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
string |
Operator type. If this parameter is not set, the return value is "". |
Exception Handling
None
Restriction
None
SetInput
Function
Specifies the input source of the operator, that is, which operator's output is used as the input of the current operator.
There are two SetInput methods:
If output 0 of srcOprt is specified as the input of the current operator, use the first syntax to set the input of the current operator, and the output name of srcOprt does not need to be specified. If another output of srcOprt is specified as the input of the current operator, use the second syntax to set the input of the current operator, and the output name of srcOprt needs to be specified.
Syntax
Operator& SetInput(const string& dst_name, const Operator& src_oprt);
Operator& SetInput(const string& dst_name, const Operator& src_oprt, const string &name)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
dst_name |
Input |
Input name of the operator. |
src_oprt |
Input |
Input operator object whose input name is dstName. |
name |
Input |
Output name of srcOprt. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
Operator& |
Scheduler itself. |
Exception Handling
None
Restriction
Operator& srcOprt can have only one output.
AddControlInput
Function
Adds a control edge of the operator. Currently, the control edge controls only the execution sequence of the operator.
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
src_oprt |
Input |
Source operator corresponding to the control edge. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
Operator object itself. |
Exception Handling
None
Restriction
None
IsEmpty
Function
Checks whether the operator object is empty. If yes, the object is unavailable.
Syntax
bool IsEmpty() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
const |
|
Exception Handling
None
Restriction
None
GetInputDesc
Function
Obtains the input TensorDesc of the operator based on its input name or input index.
Syntax
TensorDesc GetInputDesc(const string& name) const;
TensorDesc GetInputDesc(uint32_t index) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Input name of the operator. If no operator input name is available, the default object constructed by TensorDesc is returned. Set DataType to DT_FLOAT (indicating the float type) and set Format to FORMAT_NCHW (indicating the NCHW format). |
index |
Input |
Input index of the operator. If no operator input index is available, the default object constructed by TensorDesc is returned. Set DataType to DT_FLOAT (indicating the float type) and set Format to FORMAT_NCHW (indicating the NCHW format). |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
TensorDesc of the operator input. |
Exception Handling
None
Restriction
None
GetOutputDesc
Function
Obtains the output TensorDesc of the operator based on the operator output name or output index.
Syntax
TensorDesc GetOutputDesc(const string& name) const;
TensorDesc GetOutputDesc(uint32_t index) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Output name of the operator. If no operator output name is available, the default object constructed by TensorDesc is returned. Set DataType to DT_FLOAT (indicating the float type) and set Format to FORMAT_NCHW (indicating the NCHW format). |
index |
Input |
Output index of the operator. If no operator output index is available, the default object constructed by TensorDesc is returned. Set DataType to DT_FLOAT (indicating the float type) and set Format to FORMAT_NCHW (indicating the NCHW format). |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
TensorDesc of the operator output. |
Exception Handling
None
Restriction
None
TryGetInputDesc
Function
Obtains the input TensorDesc of the operator based on its input name or input index.
Syntax
graphStatus TryGetInputDesc(const string& name, TensorDesc& tensor_desc) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Input name of the operator. |
tensor_desc |
Output |
Returns the current format of the operator port, which is a TensorDesc object. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
True: The port is available, and TensorDesc is successfully obtained. False: The port is unavailable, the output parameter is empty, TensorDesc fails to be obtained. |
Exception Handling
Exception Scenario |
Description |
---|---|
No input of the corresponding name. |
False is returned. |
Restriction
None
GetInputConstData
Function
Obtains the data of the Const node if it corresponds to the input of the specified operator.
Syntax
graphStatus GetInputConstData(const string& dst_name, Tensor& data) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
dst_name |
Input |
Input name. |
data |
Output |
Returns the data Tensor of the Const node. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the node corresponding to the input of the specified operator is a Const node and data is obtained successfully, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
GetDynamicInputNum
Function
Obtains the actual number of dynamic inputs of an operator.
Syntax
int GetDynamicInputNum(const string& name) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Name of the dynamic inputs of an operator. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
int |
Actual number of dynamic inputs. If name is invalid or the operator has no dynamic input, –1 is returned. |
Restriction
None
GetDynamicOutputNum
Function
Obtains the actual number of dynamic outputs of an operator.
Syntax
int GetDynamicOutputNum(const string& name) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Name of the dynamic outputs of an operator. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
int |
Actual number of dynamic outputs. If name is invalid or the operator has no dynamic output, 0 is returned. |
Restriction
None
GetDynamicInputDesc
Function
Obtains the dynamic input TensorDesc of an operator based on the combination of its input name and index.
Syntax
TensorDesc GetDynamicInputDesc(const string& name,uint32_t index) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Dynamic input name of the operator. |
index |
Input |
Dynamic input index of the operator, which starts from 1. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
If TensorDesc is obtained successfully, the required TensorDesc object is returned. Otherwise, the default TensorDesc object is returned. Set DataType to DT_FLOAT (indicating the float type) and Format to FORMAT_NCHW (indicating the NCHW format). |
Exception Handling
None
Restriction
None
GetDynamicOutputDesc
Function
Obtains the dynamic output TensorDesc of an operator based on the combination of its input name and index.
Syntax
TensorDesc GetDynamicOutputDesc (const string& name, uint32_t index) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Dynamic output name of the operator. |
index |
Input |
Dynamic output index of the operator, which starts from 1. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
If TensorDesc is obtained successfully, the required TensorDesc object is returned. Otherwise, the default TensorDesc object is returned. Set DataType to DT_FLOAT (indicating the float type) and Format to FORMAT_NCHW (indicating the NCHW format). |
Exception Handling
None
Restriction
None
UpdateInputDesc
Function
Updates the input TensorDesc of an operator based on its input name.
Syntax
graphStatus UpdateInputDesc(const string& name, const TensorDesc& tensor_desc)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Operator input name. |
tensor_desc |
Input |
TensorDesc object. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If TensorDesc is updated successfully, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
Exception |
Description |
---|---|
No input corresponding to the name. |
The function ends in advance, and GRAPH_FAILED is returned. |
Restriction
None
UpdateOutputDesc
Function
Updates the output TensorDesc of an operator based on its output name.
Syntax
graphStatus UpdateOutputDesc (const string& name, const TensorDesc& tensor_desc)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Output name of the operator. |
tensor_desc |
Input |
TensorDesc object. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If TensorDesc is updated successfully, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
UpdateDynamicInputDesc
Function
Updates the dynamic input TensorDesc of an operator based on the combination of its output name and index.
Syntax
graphStatus UpdateDynamicInputDesc(const string& name, uint32_t index, const TensorDesc& tensor_desc)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Dynamic input name of the operator. |
index |
Input |
Dynamic input index of the operator, which starts from 1. |
tensor_desc |
Input |
TensorDesc object. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the dynamic input TensorDesc is updated successfully, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
UpdateDynamicOutputDesc
Function
Updates the dynamic output TensorDesc of an operator based on the combination of its output name and index.
Syntax
graphStatus UpdateDynamicOutputDesc (const string& name, uint32_t index, const TensorDesc& tensor_desc)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Dynamic output name of the operator. |
index |
Input |
Dynamic output index of the operator. |
tensor_desc |
Input |
TensorDesc object. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the dynamic output TensorDesc is updated successfully, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
InferShapeAndType
Function
Infers the shape and data type of the output of the operator.
For details about the definition of data types, see DataType.
Syntax
graphStatus InferShapeAndType()
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the inference is successful, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
SetInferenceContext
Function
Sets the shape and data type of the predecessor operator of the unknowShape operator.
Syntax
void SetInferenceContext(const InferenceContextPtr &inference_context)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
inference_context |
Input |
Inference context of the current operator. InferenceContextPtr is the alias of the pointer to class InferenceContext. using InferenceContextPtr = std::shared_ptr<InferenceContext>; |
Return Value
None
Exception Handling
None
Restriction
None
GetInferenceContext
Function
Obtains the shape and data type of the predecessor operator of operator unknowShape.
Syntax
InferenceContextPtr GetInferenceContext() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
InferenceContextPtr |
Returns the inference context of the current operator. InferenceContextPtr is the alias of the pointer to class InferenceContext. using InferenceContextPtr = std::shared_ptr<InferenceContext>; |
Exception Handling
None
Restriction
None
VerifyAllAttr
Function
Verifies whether the attributes, inputs, and outputs of an operator are valid based on the value of disableCommonVerifier.
Syntax
graphStatus VerifyAllAttr(bool disable_common_verifier = false)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
disable_common_verifier |
Input |
false: only the attribute validity is verified. true: validity of the attribute, input, and output of the operator is verified. The default value is false. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the inference is successful, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
GetInputsSize
Function
Obtains the number of inputs of the current operator.
Syntax
size_t GetInputsSize() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
size_t |
Returns the number of inputs of the current operator. |
Exception Handling
None
Restriction
None
GetOutputsSize
Function
Obtains the number of all outputs of an operator.
Syntax
size_t GetOutputsSize() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
size_t |
Returns the number of outputs of the current operator. |
Restriction
None
GetAllAttrNamesAndTypes
Function
Obtains the names and types of all attributes of the operator.
Syntax
const std::map<std::string, std::string> GetAllAttrNamesAndTypes() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
map |
All attribute names and types. |
Exception Handling
None
Restriction
None
SetAttr
Description
Sets the attribute values of an operator.
An operator may have multiple attributes. After an attribute value is set for the first time, the data type of the attribute is fixed. Must be one of the following data types:
- Integer: int64_t, uint32_t, and int32_t
Use SetAttr(const string& name, int64_t attrValue) to set the attribute value, and use GetAttr(const string& name, int32_t& attrValue) or GetAttr(const string& name, uint32_t& attrValue) to obtain the value. Ensure that the integer data is not truncated. It is the same for the types int32_t and uint32_t.
- List of integers: std::vector<int64_t>, std::vector<int32_t>, std::vector<uint32_t>, and std::initializer_list<int64_t>&&
- Floating-point number: float
- List of floating-point numbers: std::vector<float>
- String: string
- List of strings: std::vector<string>
- Bool: bool
- List of bools: std::vector<bool>
- Tensor: Tensor
- List of Tensors: std::vector<Tensor>
- Bytes: byte arrays represented by OpBytes (vector<uint8_t>) and const uint8_t* data, size_t size
- Quantized data: UsrQuantizeFactorParams
- AttrValue type: AttrValue
- 2D list of integers: std::vector<std::vector<int64_t>
- List of DataTypes: vector<ge::DataType>
- Data type: DataType
- NamedAttrs type: NamedAttrs
- List of NamedAttrs: vector<<NamedAttrs>>
Prototype
Operator& SetAttr(const string& name, int64_t attrValue);
Operator& SetAttr(const string& name, int32_t attrValue);
Operator& SetAttr(const string& name, uint32_t attrValue);
Operator& SetAttr(const string& name, const std::vector<int64_t>& attrValue);
Operator& SetAttr(const string& name, const std::vector<int32_t>& attrValue);
Operator& SetAttr(const string& name, const std::vector<uint32_t>& attrValue);
Operator& SetAttr(const string& name, std::initializer_list<int64_t>&& attrValue);
Operator& SetAttr(const string& name, float attrValue);
Operator& SetAttr(const string& name, const std::vector<float>& attrValue);
Operator& SetAttr(const string& name, AttrValue&& attr_value);
Operator& SetAttr(const string& name, const string& attrValue);
Operator& SetAttr(const string& name, const std::vector<string>& attrValue);
Operator& SetAttr(const string& name, bool attrValue);
Operator& SetAttr(const string& name, const std::vector<bool>& attrValue);
Operator& SetAttr(const string& name, const Tensor& attrValue);
Operator& SetAttr(const string& name, const std::vector<Tensor>& attrValue);
Operator& SetAttr(const string& name, const OpBytes& attrValue);
Operator& SetAttr(const string& name, const std::vector<std::vector<int64_t>>& attr_value);
Operator& SetAttr(const string& name, const std::vector<ge::DataType>& attr_value);
Operator& SetAttr(const string& name, const ge::DataType& attr_value)
Operator &SetAttr(const string &name, const ge::NamedAttrs &attr_value);
Operator &SetAttr(const string &name, const std::vector<ge::NamedAttrs> &attr_value);
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Attribute name |
attrValue |
Input |
Attribute value of type int64_t |
attrValue |
Input |
Attribute value of type int32_t |
attrValue |
Input |
Attribute value of type uint32_t |
attrValue |
Input |
Attribute value of type vector<int64_t> |
attrValue |
Input |
Attribute value of type vector<int32_t> |
attrValue |
Input |
Attribute value of type vector<uint32_t> |
attrValue |
Input |
Attribute value of type std::initializer_list<int64_t>&& |
attrValue |
Input |
Attribute value of type float |
attrValue |
Input |
Attribute value of type std::vector<float> |
attrValue |
Input |
Attribute value of type bool |
attrValue |
Input |
Attribute value of type std::vector<bool> |
attrValue |
Input |
Attribute value of type AttrValue |
attrValue |
Input |
Attribute value of type string |
attrValue |
Input |
Attribute value of type std::vector<string> |
attrValue |
Input |
Attribute value of type Tensor |
attrValue |
Input |
Attribute value of type std::vector<Tensor> |
attrValue |
Input |
Attribute value of type Bytes. OpBytes indicates vector<uint_8>. |
data |
Input |
Attribute value of type Bytes, specifying the start address of a byte stream |
size |
Input |
Attribute value of type Bytes, specifying the length of a byte stream |
attrValue |
Input |
Attribute value of type UsrQuantizeFactorParams |
attrValue |
Input |
Attribute value of type vector<vector<int64_t>> |
attrValue |
Input |
Attribute value of type vector<ge::DataType> |
attrValue |
Input |
Attribute value of type DataType |
attrValue |
Input |
Attribute value of type NamedAttrs |
attrValue |
Input |
Attribute value of type vector<ge::NamedAttrs> |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
Object itself |
Exception Handling
None
Restrictions
None
GetAttr
Description
Obtains the attribute value based on the attribute name.
Prototype
graphStatus GetAttr(const string& name, int64_t& attrValue) const;
graphStatus GetAttr(const string& name, int32_t& attrValue) const;
graphStatus GetAttr(const string& name, uint32_t& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<int64_t>& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<int32_t>& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<uint32_t>& attrValue) const;
graphStatus GetAttr(const string& name, float& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<float>& attrValue) const;
graphStatus GetAttr(const string& name, AttrValue& attr_value) const;
graphStatus GetAttr(const string& name, string& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<string>& attrValue) const;
graphStatus GetAttr(const string& name, bool& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<bool>& attrValue) const;
graphStatus GetAttr(const string& name, Tensor& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<Tensor>& attrValue) const;
graphStatus GetAttr(const string& name, OpBytes& attrValue) const;
graphStatus GetAttr(const string& name, std::vector<std::vector<int64_t>>& attr_value) const;
graphStatus GetAttr(const string& name, std::vector<ge::DataType>& attr_value) const;
graphStatus GetAttr(const string& name, ge::DataType& attr_value) const
graphStatus GetAttr(const string& name, std::vector<ge::NamedAttrs>& attr_value) const;
graphStatus GetAttr(const string& name, ge::NamedAttrs& attr_value) const
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
name |
Output |
Attribute name. |
attrValue |
Output |
Returned attribute value of type int64_t. |
attrValue |
Output |
Returned attribute value of type int32_t. |
attrValue |
Output |
Returned attribute value of type uint32_t. |
attrValue |
Output |
Returned attribute value of type vector<int64_t>, which is an integer list. |
attrValue |
Output |
Returned attribute value of type vector<int32_t>, which is an integer list. |
attrValue |
Output |
Returned attribute value of type vector<uint32_t>, which is an integer list. |
attrValue |
Output |
Returned attribute value of the floating point type. |
attrValue |
Output |
Returned attribute value of the floating point list type. |
attrValue |
Output |
Returned attribute value of type AttrValue. |
attrValue |
Output |
Returned attribute value of type bool. |
attrValue |
Output |
Returned attribute value of the bool list type. |
attrValue |
Output |
Returned attribute value of type string. |
attrValue |
Output |
Returned attribute value of the string list type. |
attrValue |
Output |
Returned attribute value of type Tensor. |
attrValue |
Output |
Returned attribute value of the tensor list type. |
attrValue |
Output |
Returned attribute value of type Bytes. OpBytes indicates vector<uint_8>. |
attrValue |
Output |
Returned attribute value of the quantized data type. |
attrValue |
Output |
Returned attribute value of type vector<vector<int64_t>>, which is an integer two-dimensional list type. |
attrValue |
Output |
Returned attribute value of type vector<ge::DataType>, which is a DataType list type. |
attrValue |
Output |
Returned attribute value of type DataType. |
attrValue |
Output |
Returned attribute value of type vector<ge::NamedAttrs>. |
attrValue |
Output |
Returned attribute value of type NamedAttrs. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
GRAPH_SUCCESS if the corresponding name is found; else, GRAPH_FAILED |
Exception Handling
None
Restrictions
None
BreakConnect
Function
Deletes all connections between the current operator and the previous operator and between the current operator and the next operator.
Syntax
void BreakConnect() const
Parameter Description
None
Return Value
None
Exception Handling
None
Restriction
None
GetSubgraphNamesCount
Description
Obtains the number of subgraphs of an operator.
Prototype
size_t Operator::GetSubgraphNamesCount() const
Parameters
None
Returns
Parameter |
Type |
Description |
---|---|---|
- |
size_t |
Number of subgraphs of the operator |
Exception Handling
None
Restrictions
None
GetSubgraphNames
Description
Obtains the subgraph names of an operator.
Prototype
std::vector<std::string> GetSubgraphNames() const
Parameters
None
Returns
std::vector<std::string>
Exception Handling
None
Restrictions
None
GetSubgraphBuilder
Description
Obtains the SubgraphBuilder object of an operator subgraph.
Prototype
SubgraphBuilder GetSubgraphBuilder(const string &name) const
Parameters
Parameter |
Type |
Description |
---|---|---|
name |
string |
Subgraph name |
Returns
The SubgraphBuilder object
Exception Handling
None
Restrictions
None
GetSubgraph
Description
Obtains the subgraph of an operator.
Prototype
Graph GetSubgraph(const string &name) const
Parameters
Parameter |
Type |
Description |
---|---|---|
name |
string |
Subgraph name |
Returns
The Graph object
Exception Handling
None
Restrictions
None
GetDynamicSubgraphBuilder
Description
Obtains the SubgraphBuilder object of a dynamic-input operator subgraph.
Prototype
SubgraphBuilder GetDynamicSubgraphBuilder(const string &name, uint32_t index) const
Parameters
Parameter |
Type |
Description |
---|---|---|
name |
string |
Subgraph name |
index |
uint32_t |
Subgraph index |
Returns
The SubgraphBuilder object
Exception Handling
None
Restrictions
None
GetDynamicSubgraph
Description
Obtains a dynamic-input operator subgraph.
Prototype
Graph GetDynamicSubgraph(const string &name, uint32_t index) const
Parameters
Parameter |
Type |
Description |
---|---|---|
name |
string |
Subgraph name |
index |
uint32_t |
Subgraph index |
Returns
The Graph object
Exception Handling
None
Restrictions
None
Class Tensor
The copy constructor and assignment operations of class Tensor share the tensor information. The Clone method is used to copy tensors.
Constructor and Destructor
Description
Constructs or destructs a Tensor.
Prototype
Tensor();
explicit Tensor(const TensorDesc &tensorDesc);
Tensor(const TensorDesc &tensorDesc, const std::vector<uint8_t> &data);
Tensor(const TensorDesc &tensorDesc, const uint8_t *data, size_t size);
Tensor(TensorDesc &&tensorDesc, std::vector<uint8_t> &&data);
~Tensor();
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
tensorDesc |
Input |
TensorDesc object |
data |
Input |
Data to be set |
size |
Input |
Data length, in bytes |
Returns
The Tensor object
Exception Handling
None
Restrictions
None
SetTensorDesc
Function
Sets the descriptor of a tensor: TensorDesc.
Syntax
graphStatus SetTensorDesc(const TensorDesc &tensorDesc)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
tensorDesc |
Input |
Tensor descriptor to be set. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the operation is successful, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
GetTensorDesc
Function
Obtains the descriptor of a tensor: TensorDesc.
Syntax
TensorDesc GetTensorDesc() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
Tensor descriptor. |
Exception Handling
None
Restriction
This API modifies the returned TensorDesc, which does not affect the existing TensorDesc information in the Tensor object.
SetData
Function
Sets data to a tensor.
Syntax
graphStatus SetData(std::vector<uint8_t> &&data);
graphStatus SetData(const std::vector<uint8_t> &data);
graphStatus SetData(const uint8_t *data, size_t size)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
data |
Input |
Data to be set. |
size |
Input |
Data length, in bytes. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the operation is successful, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
GetData
Function
Obtains the data of a tensor.
Data returned by const uint8_t* GetData() const cannot be modified, while data returned by uint8_t* GetData() can be modified.
Syntax
const uint8_t* GetData() const;
uint8_t* GetData()
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
const Buffer |
Tensor data. |
Exception Handling
None
Restriction
None
GetSize
Function
Obtains the size of data in a tensor.
Syntax
size_t GetSize() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
size_t |
Size of data stored in a tensor, in bytes. |
Exception Handling
None
Restriction
None
IsValid
Function
Checks whether a Tensor object is valid.
If the actual size of the tensor data is the same as that of the tensor data described by TensorDesc, the object is valid.
Syntax
graphStatus IsValid()
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the Tensor object is valid, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
Clone
Function
Clones a tensor.
Syntax
Tensor Clone() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
Tensor |
Cloned tensor object. |
Exception Handling
None
Restriction
None
Class TensorDesc
The copy constructor and assignment operations of class Tensor are value copy (deep copy) and do not share TensorDesc information.
When the Move constructor and Move assignment of class TensorDesc will move the original TensorDesc information to the new TensorDesc object.
Constructor and Destructor
Function
TensorDesc constructor and destructor
Syntax
TensorDesc();
explicit TensorDesc(Shape shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);
TensorDesc(const TensorDesc& desc);
TensorDesc(TensorDesc&& desc);
~TensorDesc()
Parameter Description
Return Value
The TensorDesc constructor returns an object of the TensorDesc type.
Exception Handling
None
Restriction
None
Update
Function
Updates the shape, format, and data type of a TensorDesc object.
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
shape |
Input |
Shape object to be updated. |
format |
Input |
Format object to be updated. The default value is FORMAT_ND. |
dt |
Input |
DataType object to be updated. The default value is DT_FLOAT. |
Return Value
None
Exception Handling
None
Restriction
None
SetShape
Function
Sets the shape of a tensor into TensorDesc.
It refers to the shape of the model adapted to the Ascend AI Processor.
Syntax
void SetShape(Shape shape)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
shape |
Input |
shape object to be set into TensorDesc. |
Return Value
None
Exception Handling
None
Restriction
None
GetShape
Function
Obtains the shape of a tensor from TensorDesc.
Syntax
Shape GetShape() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
shape described by TensorDesc |
Exception Handling
None
Restriction
The returned shape is obtained through value copy (deep copy). This API modifies the returned shape, which does not affect the existing shape in TensorDesc.
SetUnknownDimNumShape
Description
Sets the shape of a tensor to {-2} to indicate that it is an unknown tensor.
Prototype
graphStatus SetUnknownDimNumShape()
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
NA |
- |
- |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
Execution result: GRAPH_SUCCESS (0) on success; else, failure |
Exception Handling
None
Restrictions
None
SetShapeRange
Description
Sets the shape range.
Prototype
graphStatus SetShapeRange(const std::vector<std::pair<int64_t,int64_t>> &range)
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
range |
Input |
Shape range. Each element in a vector is a pair. The first value in each pair specifies the minimum dimension size, and the second value specifies the maximum dimension size. For example: If the shape of the tensor is {1, 1, –1, 2}, and the maximum size of the third axis is 100, range can be set to {{1,1},{1,1},{1,100},{2,2}} |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
Execution result: GRAPH_SUCCESS (0) on success; else, failure |
Exception Handling
None
Restrictions
None
GetShapeRange
Description
Obtains the shape range.
Prototype
graphStatus GetShapeRange(std::vector<std::pair<int64_t,int64_t>> &range) const
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
range |
Output |
Shape range |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
Execution result: GRAPH_SUCCESS (0) on success; else, failure |
Exception Handling
None
Restrictions
None
SetFormat
Function
Sets the tensor format into TensorDesc.
The format refers to the format of the model adapted to the Ascend AI Processor.
Syntax
void SetFormat(Format format)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
format |
Input |
format information to be set. For details about the format type, see Format. |
Return Value
None
Exception Handling
None
Restriction
None
GetFormat
Function
Obtains the format information of a tensor described by TensorDesc.
Syntax
Format GetFormat() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
format information of the tensor described by TensorDesc. |
Exception Handling
None
Restriction
The returned format is obtained through value copy (deep copy). This API is used to modify the returned format, which does not affect the existing format information in TensorDesc.
SetDataType
Function
Sets the data type of a tensor into TensorDesc.
The data type refers to that of the model adapted to the Ascend AI Processor.
Syntax
void SetDataType(DataType dt)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
dt |
Input |
Data type of the tensor to be set described by TensorDesc. For details about data types, see DataType. |
Return Value
None
Exception Handling
None
Restriction
None
GetDataType
Function
Obtains the data type of a tensor described by TensorDesc.
Syntax
DataType GetDataType() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
Data type of the tensor described by TensorDesc. |
Exception Handling
None
Restriction
The returned data type is obtained through value copy (deep copy). This API is used to modify the returned data type, which does not affect the existing data type information in TensorDesc.
SetSize
Function
Sets the data size of a tensor into TensorDesc.
Syntax
void SetSize(int64_t size)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
size |
Input |
Data size of the tensor to be set. |
Return Value
None
Exception Handling
None
Restriction
None
GetSize
Function
Obtains the data size of a tensor from TensorDesc.
Syntax
int64_t GetSize() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
int64_t |
Data size of the tensor described by TensorDesc. |
Exception Handling
None
Restriction
None
SetName
Function
Sets the name of a tensor into TensorDesc.
Syntax
void SetName(const std::string &name)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Tensor name to be set. |
Return Value
None
Exception Handling
None
Restriction
None
GetName
Function
Obtains the name of a tensor from TensorDesc.
Syntax
std::string GetName() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
string |
Tensor name. |
Exception Handling
None
Restriction
None
SetRealDimCnt
Function
Sets the actual number of dimensions of a tensor into TensorDesc.
The number of shape dimensions returned by the GetShape API may be 1 more than the actual number due to padding. This API is used to set the actual number of shape dimensions.
Syntax
void SetRealDimCnt(const int64_t realDimCnt)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
realDimCnt |
Input |
Actual number of data dimensions of TensorDesc to be set. |
Return Value
None
Exception Handling
None
Restriction
None
GetRealDimCnt
Function
Obtains the actual number of dimensions of a tensor described by TensorDesc.
Syntax
int64_t GetRealDimCnt() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
int64_t |
Number of actual dimensions described by TensorDesc. |
Exception Handling
None
Restriction
None
SetOriginShape
Function
Sets the original shape of a tensor into TensorDesc.
The shape refers to that of the original network model.
Syntax
void SetOriginShape(Shape originShape)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
originShape |
Input |
Original shape set into TensorDesc. |
Return Value
None
Exception Handling
None
Restriction
None
SetOriginFormat
Function
Sets the original format of a tensor into TensorDesc.
The format refers to that of the original network model.
Syntax
void SetOriginFormat(Format originFormat)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
originFormat |
Input |
Original format to be set. For the definition of the format data type, see Format. |
Return Value
None
Exception Handling
None
Restriction
None
GetOriginFormat
Function
Obtains the original format of a tensor described by TensorDesc.
Syntax
Format GetOriginFormat() const
Parameter Description
None
Return Value
Exception Handling
None
Restriction
None
Class Shape
Constructor and Destructor
Function
Shape constructor and destructor
Syntax
Shape();
~Shape();
explicit Shape(const std::vector<int64_t>& dims)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
dims |
Input |
Value of Shape. Shape indicates the dimensions of a tensor. std::vector<int64_t> indicates each dimension. |
Return Value
The Shape constructor returns an object of the Shape type.
Exception Handling
None
Restriction
None
GetDimNum
Function
Obtains the dimension count of Shape.
Syntax
size_t GetDimNum() const
Parameter Description
None
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
size_t |
Shape dimension count of the tensor |
Exception Handling
None
Restriction
None
SetDim
Function
Sets dimension idx in Shape to value.
Syntax
graphStatus SetDim(size_t idx, int64_t value)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
idx |
Input |
Dimension index of Shape, which starts from 0. |
value |
Input |
Value to be set. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the operation is successful, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
GetDim
Function
Obtains the size of dimension idx of Shape.
Syntax
int64_t GetDim(size_t idx) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
idx |
Input |
Dimension index, which starts from 0. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
int64_t |
Size of dimension idx. |
Exception Handling
None
Restriction
None
Class AttrValue
Constructor and Destructor
Function
AttrValue constructor and destructor.
Syntax
AttrValue();
~AttrValue()
Parameter Description
None
Return Value
The AttrValue constructor returns an object of the AttrValue type.
Exception Handling
None
Restriction
None
GetValue
Function
Obtains the value of value in the key-value pair and converts the obtained value from the T type to the DT type.
- converting INT to int64_t
- converting FLOAT to float
- converting STR to std::string
Syntax
template<typename T, typename DT>
graphStatus GetValue(DT& val) const
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
val |
Output |
Parameter of the DT type. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
If the data type conversion succeeds, GRAPH_SUCCESS is returned. Otherwise, GRAPH_FAILED is returned. |
Exception Handling
None
Restriction
None
CreateFrom
Function
Converts DT-type data types (int64_t, float, and std::string) to T-type data types (INT, FLOAT, and STR).
- converting int64_t type to INT
- converting float to FLOAT
- converting std::string type to STR
Syntax
template<typename T, typename DT>
static T CreateFrom(DT&& val)
Parameter Description
Parameter |
Input/Output |
Description |
---|---|---|
val |
Input |
Parameter of the DT type. |
Return Value
Parameter |
Type |
Description |
---|---|---|
- |
|
Parameter of the T type. |
Exception Handling
None
Restriction
None
- Class Operator
- Constructor and Destructor
- GetName
- GetOpType
- SetInput
- AddControlInput
- IsEmpty
- GetInputDesc
- GetOutputDesc
- TryGetInputDesc
- GetInputConstData
- GetDynamicInputNum
- GetDynamicOutputNum
- GetDynamicInputDesc
- GetDynamicOutputDesc
- UpdateInputDesc
- UpdateOutputDesc
- UpdateDynamicInputDesc
- UpdateDynamicOutputDesc
- InferShapeAndType
- SetInferenceContext
- GetInferenceContext
- VerifyAllAttr
- GetInputsSize
- GetOutputsSize
- GetAllAttrNamesAndTypes
- SetAttr
- GetAttr
- BreakConnect
- GetSubgraphNamesCount
- GetSubgraphNames
- GetSubgraphBuilder
- GetSubgraph
- GetDynamicSubgraphBuilder
- GetDynamicSubgraph
- Class Tensor
- Class TensorDesc
- Class Shape
- Class AttrValue