IR Construction APIs
Class Graph
Graph Constructor and Destructor
Description
Constructs or destructs a graph.
Prototype
explicit Graph(const std::string& name);
Graph();
~Graph()
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Graph name |
Returns
The graph constructor returns a Graph object.
Exception Handling
None
Restrictions
None
SetOutputs
Description
Sets the output operators of a graph.
Prototype
Graph& SetOutputs(const std::vector<Operator>& outputs);
Graph& SetOutputs(const std::vector<std::pair<Operator, std::vector<size_t>>> &output_indexs);
Graph& SetOutputs(const std::vector<std::pair<ge::Operator, std::string> > &outputs)
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
outputs |
Input |
A list of output operators that return results in sequence. |
output_indexs |
Input |
A size_t for the result return sequence. |
outputs |
Input |
A list of strings for the output operators that return results in sequence. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
Caller itself |
Exception Handling
None
Restrictions
None
SetTargets
Description
Sets the end operators of a graph.
The results of the end operators are not returned to the user.
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
targets |
Input |
A list of end operators |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
Caller itself |
Exception Handling
None
Restrictions
None
IsValid
Description
Checks if a Graph object is valid, or executable.
Prototype
bool IsValid() const
Parameter Description
None
Returns
Parameter |
Type |
Description |
---|---|---|
- |
bool |
|
Restrictions
None
SetNeedIteration
Description
Enables iterative execution of a graph.
Prototype
void SetNeedIteration(bool need_iteration)
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
need_iteration |
Input |
Iterative execution enable
|
Returns
None
Exception Handling
None
Restrictions
This API must be used in conjunction with npu_runconfig/iterations_per_loop, npu_runconfig/loop_cond, npu_runconfig/one, and npu_runconfig/zero, you need to construct variable operators named after npu_runconfig/iterations_per_loop, npu_runconfig/loop_cond, npu_runconfig/one, or npu_runconfig/zero.
AddOp
Description
Registers an unconnected operator with a graph for query and object obtaining.
Prototype
graphStatus AddOp(ge::Operator& op)
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
op |
Input |
Operator to be added |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
SUCCESS on success FAILED on failure |
Restrictions
This API is optional. For switchover between functions, an operator object may be a local variable and cannot be obtained by functions. In this case, the operator can be registered with the graph to obtain the previously created operator object. After the operator object is registered in the graph, the operator object exists unless the graph is destroyed.
FindOpByName
Description
Obtains an operator object registered with a graph based on the operator name.
Prototype
graphStatus FindOpByName(const string& name, ge::Operator& op) const
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
name |
Input |
Operator name |
op |
Output |
The operator object |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
SUCCESS if the operator instance is successfully obtained. FAILED if the operator object is not registered in the graph. |
Restrictions
This API is optional and is used in conjunction with AddOp.
GetAllOpName
Description
Obtain the names of all operators registered with a graph.
Function Prototype
graphStatus GetAllOpName(std::vector<string>& op_name) const
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
opName |
Output |
Returns the names of all operators in a graph. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
SUCCESS on success FAILED on failure |
Exception Handling
None
Restrictions
This API is optional and is used in conjunction with AddOp.
SaveToFile
Description
Serializes a graph to a file.
Prototype
graphStatus SaveToFile(const string& file_name) const
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
file_name |
Input |
File path and file name |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
SUCCESS on success FAILED on failure |
Restrictions
None
LoadFromFile
Description
Reads a graph from a file.
Prototype
graphStatus LoadFromFile(const string& file_name)
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
file_name |
Input |
File path and file name |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
SUCCESS on success FAILED on failure |
Exception Handling
None
Restrictions
None
FindOpByType
Description
Obtains all operator objects of a specified type registered with a graph.
Prototype
graphStatus FindOpByType(const string &type, std::vector<ge::Operator> &ops) const
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
type |
Input |
Operator type |
ops |
Output |
The operator objects |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
SUCCESS if the operator instances are successfully obtained. |
Class Model Build
aclgrphBuildInitialize
Description
Initializes model building, which is used to allocates resources.
Prototype
graphStatus aclgrphBuildInitialize(std::map<std::string, std::string> global_options)
Restrictions
aclgrphBuildInitialize can be called only once per process.
After aclgrphBuildInitialize is called, aclgrphBuildModel can be called repeatedly per process.
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
global_options |
Input |
Parameter map describing the initial configuration of offline model building. key indicates the parameter type, and value indicates the value. For details about the parameters in the map, see aclgrphBuildInitialize Configuration Parameters. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
GRAPH_SUCCESS on success; else, failure |
aclgrphBuildModel
Description
Builds a graph into an offline model adapted to the Ascend AI Processor.
Prototype
graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map<std::string, std::string> &build_options, ModelBufferData& model);
Restrictions
None
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
graph |
Input |
Graph to be built |
build_options |
Input |
Parameter map describing the initial configuration of offline model building. key indicates the parameter type, and value indicates the value. For details about the parameters in the map, see aclgrphBuildModel Configuration Parameters. |
model |
Output |
Buffer of the generated offline model struct ModelBufferData { std::shared_ptr<uint8_t> data = nullptr; uint64_t length; }; data points to the generated model data, and length indicates the actual model size. |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
GRAPH_SUCCESS on success; else, failure |
aclgrphSaveModel
Description
Serializes an offline model to a file.
Prototype
graphStatus aclgrphSaveModel(const string &output_file, const ModelBufferData& model)
Restrictions
None
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
model |
Input |
Buffer of the offline model struct ModelBufferData { std::shared_ptr<uint8_t> data = nullptr; uint64_t length; }; data points to the generated model data, and length indicates the actual model size. |
output_file |
Input |
File name |
Returns
Parameter |
Type |
Description |
---|---|---|
- |
graphStatus |
GRAPH_SUCCESS on success; else, failure |