Full APIs
This section mainly describes secure, easy-to-use graph construction APIs for application users or high-level frameworks to build models and set model graphs, operators in the graphs, and operator attributes (inputs, outputs, and other attributes).
aclgrph APIs (C++)
|
API |
Description |
|---|---|
|
Parses a Caffe model into a graph. |
|
|
Parses an ONNX model into a graph. |
|
|
Parses an ONNX model that has been loaded to memory into a graph. |
|
|
Parses a TensorFlow model into a graph. |
|
|
Initializes model build, for allocating resources. |
|
|
Destroys allocations after model building. |
|
|
Builds an input graph into an offline model adapted to the AI processor and saves it to the memory buffer. |
|
|
The difference between this API and aclgrphBuildModel is that this API applies to the weight update scenario. After the offline model cache is generated using the aclgrphBundleBuildModel API, aclgrphBundleSaveModel needs to be called to flush the cache to disks. |
|
|
Serializes an offline model to a file. |
|
|
Converts the original graph into a group of graphs whose weights can be updated by passing the const node name array. |
|
|
Dumps the input graph to a text file. |
|
|
Obtains the version number of the API related to model build. |
|
|
Builds a graph based on the single-operator information or JSON file of a single-operator. |
|
|
Serializes an offline model to a file. |
|
|
Sets node attributes to modify a graph. |
|
|
Quantized a graph. For details about the application scenarios, see Quantization. |
|
|
Creates a profiling configuration. |
|
|
Destroys a profiling configuration. |
|
|
Finalizes profiling. |
|
|
Initializes profiling and sets profiling parameters. (Currently, you can specify the path for saving profile data files.) |
|
|
Starts profiling. |
|
|
Stops profiling. |
Session APIs (C++)
- Session
API
Description
Constructs or destroys an object of class Session.
Adds a graph to a Session, in which a unique graph ID is generated.
Adds a graph to a Session, in which a unique graph ID is generated.
Synchronously builds the graph of a specified ID to generate an executable model.
Synchronously compiles the graph corresponding to the specified ID. Compared with BuildGraph, this API provides only the graph compilation function and does not generate executable models. BuildGraph contains the graph build process, initializes the memory resources required by the model after the process, and generates an executable model.
Asynchronously runs the graph of a specified ID and returns the execution result.
Initializes GE.
Queries the summary about the compiled graph. The summary includes the feature memory size, const memory size, numbers of streams and events, and whether the memory can be updated.
Finalizes GE and destroys associated allocations.
Obtains and clears the error messages returned by other failed API calls in the same process or thread.
Obtains and clears the error messages returned by other failed API calls in the same process or thread.
Obtains and clears the warning messages returned by other failed API calls in the same process or thread.
Obtains and clears the warning messages returned by other failed API calls in the same process or thread.
Obtains the session ID.
Queries variables and obtains the tensors of all variable operators or tensor a specified variable operator in a Session.
Determines whether a graph needs to be rebuilt.
Binds a graph with a specified ID to a stream in asynchronous graph execution scenarios.
Determines whether the memory can be quickly recovered when an uncorrectable error (UCE) occurs in the memory.
Registers a callback function.
Registers an external allocator to the GE. This applies to the scenario where the user's memory pool is used.
Removes a graph with a specified ID from the current Session.
Synchronously runs the graph of a specified ID and returns the execution result.
Asynchronously runs the graph of a specified ID and returns the execution result.
Runs the graph corresponding to a specified ID synchronously after the input refdata node is partitioned, and outputs the execution result.
Asynchronously runs the graph of a specified ID and returns the execution result. This API is used to compile, load, and run graphs.
This API is deprecated. Avoid using it.
Saves graphs in a session as a .pb file. Weight sharing in a session is supported. That is, if two graphs in a session have the same weight, only one weight is saved.
Sets the const memory base address of a graph.
Sets the memory base address of the fixed feature of a graph.
Sets the base address of the fixed feature memory of different memory types in a graph.
This API is deprecated. Avoid using it.
This API shards graphs in a session based on the AddGraph sequence. Sharded graphs are saved in the memory.
This API is deprecated. Avoid using it.
Shard a graph in a session based on the AddGraph sequence. Sharded graphs are saved as .pb files.
Updates the feature memory base address of a graph.
Updates the base address of the feature memory that can be updated except fixed memory.
Destroys the allocator registered by the user based on the stream. This applies to the scenario where the user's memory pool is used.
- GESession
API
Description
Constructs and destructs an object of class GeSession.
Adds a graph to a GeSession, in which a unique graph ID is generated.
Adds a graph to a GeSession, in which a unique graph ID is generated.
Synchronously compiles the graph corresponding to the specified ID.
Finalizes GE and destroys associated allocations.
Obtains and clears the error messages returned by other failed API calls in the same process or thread.
Obtains and clears the warning messages returned by other failed API calls in the same process or thread.
Initializes GE.
Queries the summary about the compiled graph. The summary includes the feature memory size, const memory size, numbers of streams and events, and whether the memory can be updated.
Obtains the serialized model after graph compilation.
Obtains the session ID.
Determines whether a graph needs to be rebuilt.
Loads a graph and prepares for its execution, including allocating and managing resources such as memory and computational streams required for graph execution.
Registers a callback function.
Registers an external allocator to the GE. This applies to the scenario where the user's memory pool is used.
Removes a graph with a specified ID from the current GeSession.
Synchronously runs the graph of a specified ID and returns the execution result.
Asynchronously runs the graph of a specified ID and returns the execution result.
Asynchronously runs the graph of a specified ID and returns the execution result.
Sets the const memory base address of a graph.
Sets the base address of the fixed feature memory of different memory types in a graph.
Updates the feature memory base address of a graph.
Updates the base address of the feature memory that can be updated except fixed memory.
Destroys the allocator registered by the user based on the stream. This applies to the scenario where the user's memory pool is used.
ES APIs (C++)
- Class and structure
API
Description
Node builder class. This class builds graph nodes that conform to IR specifications. It provides chain APIs to define a node's inputs, outputs, and attributes, ensuring compliance with IR requirements. The class is called internally by ES-generated APIs. If you build graphs directly using ES-generated APIs, you do not need to interact with this class. However, when customizing ES APIs, you can use the capabilities of this class to create nodes.
C-style graph builder structure, which is an internal implementation class for both C and C++. C users can call esb_funcs.h to build graphs, while C++ users can call external APIs provided by the EsGraphBuilder class.
C-style output type for ES APIs. C users can call esb_funcs.h to build graphs, while C++ users can call external APIs provided by the EsTensorHolder class.
Graph builder class. This class enables C++ users to build computational graphs. It provides methods for creating graph elements such as inputs, setting private attributes, building final graphs, and calling the conversion logic of the ES-generated C API through the inline functions of the ES-generated C++ API.
Node output expression class. This class is used for C++ graph building. It provides the tensor operation APIs of C and supports various operations on node outputs, including setting the data type, format, and shape, setting private attributes, and performing arithmetic operations.
Generic EsTensorHolder class. This class is used to convert scalar and vector values into EsTensorHolder objects so that the C++ graph building APIs can directly transfer values for graph building.
- Function
API
Description
Creates a graph builder instance.
Releases graph builder resources.
Creates an input on a graph.
Creates a data input on a graph.
Sets the data type of a tensor. If no data type is specified, the default value float is used.
Sets the memory format of a tensor. If no format is set, the default value ND is used.
Sets the shape of a tensor. If no shape is set, the default value [] is used, indicating a scalar.
Sets the symbolic expression of the tensor shape. If it is not set, there is no symbolic information by default.
Creates a Const node of the int64 type.
Creates a Const node of the int32 type.
Creates a Const node of the uint64 type.
Creates a Const node of the uint32 type.
Creates a Const node of the float type.
Creates a vector constant of the int64 type.
Creates a vector constant of the int32 type.
Creates a vector constant of the uint64 type.
Creates a vector constant of the uint32 type.
Creates a vector constant of the float type.
Creates a scalar constant of the int64 type.
Creates a scalar constant of the int32 type.
Creates a scalar constant of the uint64 type.
Creates a scalar constant of the uint32 type.
Creates a scalar constant of the float type.
Creates a variable node.
Sets the output of a graph.
Returns the pointer to the ge::Graph instance. The ownership is transferred to the caller.
Returns the snapshot of the EsCGraphBuilder instance. The ownership is not transferred.
Returns the snapshot of the ge::GNode instance.
Connects control edges.
Used by a C user to create an EsCTensor.
Used by a C user to create an EsCTensor using a binary file.
Sets the int64 attribute of a graph.
Sets the string attribute of a graph.
Sets the Boolean attribute of a graph.
Sets the int64 attribute of a tensor.
Sets the string attribute of a tensor.
Sets the Boolean attribute of a tensor.
Sets the int64 attribute of a node.
Sets the string attribute of a node.
Sets the Boolean attribute of a node.
Basic Data Structures and APIs of Graphs (C++)
- Class and structure
API
Description
ArgDescInfo class. This class describes the address information specified by Args, a kernel input parameter. It semantically expresses Args-specified addresses and specifies the usage and related information about each address.
ArgsFormat serialization information.
Stores attribute values.
A base class for custom operators.
Provides a brief summary of the graph compilation result.
Inherited from InferShapeContext, CtInferShapeContext is used for shape inference during compilation and provides APIs for compilation.
Inherited from InferShapeRangeContext, CtInferShapeRangeContext is used for ShapeRange inference during compilation and provides APIs for compilation.
Obtains the custom pass context object.
Registers custom operators.
Decomposition pass class.
A base class for custom operators.
Operator execution context.
Obtains details of the external weights persisted to a disk.
Stores feature memory information.
Fusion pass.
Fusion pass registration class.
Provides utilities for GE graph modification, such as shape inference, node support verification, and graph optimization.
Constructs graph-related classes.
Stores the cached data of graphs.
Constructs the node data of a graph.
Obtains the inference context object and sets the shape and data type of the object. It is mainly used for resource operators.
Registers the operator InferFormat function. This API is referenced by other header files and is not directly called by operator developers.
Registers the operator infershape function. This API is referenced by other header files and is not directly called by operator developers.
Registers the operator InferValueRangeFuncRegister function. This API is referenced by other header files and is not directly called by operator developers.
Inputs tensor information.
Provides APIs for creating and managing tasks delivered to devices. The APIs allow developers to set or obtain the launch information about the tasks to be delivered to devices.
Obtains logical stream allocation information.
A matched graph structure obtained on PatternMatcher. The results contain the matched nodes.
Serialized model data in the memory buffer.
Operator class.
Registers an operator prototype. This API is referenced by other header files. Therefore, it is not directly called by operator developers.
An internal associated API, which is referenced by other header files and is not directly called by operator developers.
The APIs provided by the OpLibRegister class are internal associated APIs. Currently, the class provides the registration function for custom operator dynamic libraries so that the custom operator project framework can register specified initialization functions. You do not need to pay attention to these APIs.
Outputs tensor information.
Receives and processes pass registration information.
Receives the fusion pass registration information and registers it with the global singleton.
A class for registering and managing custom passes (in the processing phase).
Defines a template for graph topology matching. It takes a graph as input and specifies the graph structure to match.
Pattern fusion class.
A tool class for subgraph matching. It takes a pattern definition and a graph to be matched. It uses the pattern to perform graph matching and provides the MatchNext API to return match results sequentially.
A class used to configure the PatternMatcher behavior.
An auxiliary class used to construct PatternMatcherConfig.
Sets and obtains the shape and data type of an object.
Stream allocation summary.
Context object for the logical stream allocation pass.
A tool class for graph modification. It takes a range in a graph and a replacement graph, and uses the replacement graph to replace the nodes in the given range.
Describes an input tensor of a subgraph.
Describes an output tensor of a subgraph.
Defines a subgraph boundary.
Registers the operator verifyFunc function. This API is referenced by other header files and is not directly called by the operator developer.
- Function
API
Description
A template function. It takes a template parameter T and converts it to the AscendString type. It is mainly used to convert strings of different types to those of the AscendString type.
Defines a template function ConvertToListAscendString to convert strings of different types to those of the AscendString type.
- Macro
Macro Definition
Description
Encapsulated macro of common functions, facilitating the development of the InferShape function. This function sets the output shape based on the shapes of two inputs. This macro sets the shape only, and does not set the data type.
Registers the InferShape function of an operator.
Encapsulated macro of common functions, facilitating the development of the InferShape function. This API sets the output shape and data type based on the input shape and data type.
Encapsulates the Common_InferShape function of an operator.
Encapsulates the inferFormat function of an operator.
Encapsulates the InferShape function of an operator.
Encapsulates the Verify function of an operator.
Registers the InferFormat function of an operator.
Registers the InferShape function of an operator.
Registers custom operators.
Registers the custom fusion pass.
Registers the graph modification function in the 1-to-N scenario
Registers the custom pass.
Registers the Verify function of an operator.
Defines the operator prototype.
Registers an operator type.
- Enum
Enum Type
Description
Args address type.
Custom pass execution phase.
Hidden input address type of ArgDescInfo.
Dump file format.
-
Configuration file of the profiling data type.
Profiling AI Core metrics.
Session APIs (Python)
|
API |
Description |
|---|---|
|
Initializes a session. |
|
|
Adds a graph to a session. |
|
|
Initializes GE for execution. |
|
|
Terminates GE and releases all resources. |
|
|
Runs a graph. |
ES APIs (Python)
- Class and structure
API
Description
GraphBuilder class, which is used to build computational graphs in Eager Style mode.
TensorHolder class, which is used to represent tensor operations in Eager Style graph construction.
- Global function
API
Description
Attribute scope context manager.
Controls the dependency scope context manager.
Obtains the plug-in module with the specified name.
Lists the names of all loaded plug-ins.
Basic Data Structures and APIs of Graphs (Python)
- Class and structure
- Enum
Enum
Description
Enumerates attribute value types.
Enumerates data types and defines all supported data types.
Enumerates the graph export formats.
Enumerates input types.
Enumerates data formats and defines all supported data formats.
Basic Data Structures and APIs of Graphs (C)
|
API |
Description |
|---|---|
|
Obtains the path of the custom operator library. |
|
|
Applies only to the scenario where the graph is executed asynchronously. The specified session is used to bind the graph with the specified value of graph ID to the corresponding stream. |
|
|
Runs the graph of a specified ID using the specified session instance and returns the execution result. This API is asynchronous. |
|
|
Obtains all nodes of the root graph and subgraphs. |
|
|
Obtains the IDs of the auxiliary secondary logical streams of the root graph and subgraphs. |
|
|
Obtains the actual number of physical streams of the communication secondary stream corresponding to the root graph and subgraphs. |
|
|
Obtains the logical stream IDs of the root graph and subgraphs. |
|
|
Obtains the actual number of physical streams of the root graph and subgraphs. |
|
|
Obtains the logical stream information strings of the root graph and subgraphs. |
|
|
Obtains the stream graphs of the root graph and subgraphs. |
|
|
Obtains the user stream labels of the root graph and subgraphs. |
|
|
Checks whether the root graph and subgraph are allocated by the stream allocation pass registered by the user. |
|
|
Obtains the definition of the registered IR operator prototype. |
|
|
Queries the IR expression capability. |