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

aclgrphParseCaffe

Parses a Caffe model into a graph.

aclgrphParseONNX

Parses an ONNX model into a graph.

aclgrphParseONNXFromMem

Parses an ONNX model that has been loaded to memory into a graph.

aclgrphParseTensorFlow

Parses a TensorFlow model into a graph.

aclgrphBuildInitialize

Initializes model build, for allocating resources.

aclgrphBuildFinalize

Destroys allocations after model building.

aclgrphBuildModel

Builds an input graph into an offline model adapted to the AI processor and saves it to the memory buffer.

aclgrphBundleBuildModel

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.

aclgrphBundleSaveModel

Serializes an offline model to a file.

aclgrphConvertToWeightRefreshableGraphs

Converts the original graph into a group of graphs whose weights can be updated by passing the const node name array.

aclgrphDumpGraph

Dumps the input graph to a text file.

aclgrphGetIRVersion

Obtains the version number of the API related to model build.

aclgrphGenerateForOp

Builds a graph based on the single-operator information or JSON file of a single-operator.

aclgrphSaveModel

Serializes an offline model to a file.

aclgrphSetOpAttr

Sets node attributes to modify a graph.

aclgrphCalibration

Quantized a graph. For details about the application scenarios, see Quantization.

aclgrphProfCreateConfig

Creates a profiling configuration.

aclgrphProfDestroyConfig

Destroys a profiling configuration.

aclgrphProfFinalize

Finalizes profiling.

aclgrphProfInit

Initializes profiling and sets profiling parameters. (Currently, you can specify the path for saving profile data files.)

aclgrphProfStart

Starts profiling.

aclgrphProfStop

Stops profiling.

Session APIs (C++)

  • Session

    API

    Description

    Session Constructor and Destructor

    Constructs or destroys an object of class Session.

    AddGraph

    Adds a graph to a Session, in which a unique graph ID is generated.

    AddGraphWithCopy

    Adds a graph to a Session, in which a unique graph ID is generated.

    BuildGraph

    Synchronously builds the graph of a specified ID to generate an executable model.

    CompileGraph

    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.

    ExecuteGraphWithStreamAsync

    Asynchronously runs the graph of a specified ID and returns the execution result.

    GEInitialize

    Initializes GE.

    GetCompiledGraphSummary

    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.

    GEFinalize

    Finalizes GE and destroys associated allocations.

    GEGetErrorMsg

    Obtains and clears the error messages returned by other failed API calls in the same process or thread.

    GEGetErrorMsgV2

    Obtains and clears the error messages returned by other failed API calls in the same process or thread.

    GEGetWarningMsg

    Obtains and clears the warning messages returned by other failed API calls in the same process or thread.

    GEGetWarningMsgV2

    Obtains and clears the warning messages returned by other failed API calls in the same process or thread.

    GetSessionId

    Obtains the session ID.

    GetVariables

    Queries variables and obtains the tensors of all variable operators or tensor a specified variable operator in a Session.

    IsGraphNeedRebuild

    Determines whether a graph needs to be rebuilt.

    LoadGraph

    Binds a graph with a specified ID to a stream in asynchronous graph execution scenarios.

    PaRemapped

    Determines whether the memory can be quickly recovered when an uncorrectable error (UCE) occurs in the memory.

    RegisterCallBackFunc

    Registers a callback function.

    RegisterExternalAllocator

    Registers an external allocator to the GE. This applies to the scenario where the user's memory pool is used.

    RemoveGraph

    Removes a graph with a specified ID from the current Session.

    RunGraph

    Synchronously runs the graph of a specified ID and returns the execution result.

    RunGraphAsync

    Asynchronously runs the graph of a specified ID and returns the execution result.

    RunGraphDistribute

    Runs the graph corresponding to a specified ID synchronously after the input refdata node is partitioned, and outputs the execution result.

    RunGraphWithStreamAsync

    Asynchronously runs the graph of a specified ID and returns the execution result. This API is used to compile, load, and run graphs.

    SaveGraphsToPb

    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.

    SetGraphConstMemoryBase

    Sets the const memory base address of a graph.

    SetGraphFixedFeatureMemoryBase

    Sets the memory base address of the fixed feature of a graph.

    SetGraphFixedFeatureMemoryBaseWithType

    Sets the base address of the fixed feature memory of different memory types in a graph.

    ShardGraphs

    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.

    ShardGraphsToFile

    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.

    UpdateGraphFeatureMemoryBase

    Updates the feature memory base address of a graph.

    UpdateGraphRefreshableFeatureMemoryBase

    Updates the base address of the feature memory that can be updated except fixed memory.

    UnregisterExternalAllocator

    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

    GeSession Constructor and Destructor

    Constructs and destructs an object of class GeSession.

    AddGraph

    Adds a graph to a GeSession, in which a unique graph ID is generated.

    AddGraphClone

    Adds a graph to a GeSession, in which a unique graph ID is generated.

    CompileGraph

    Synchronously compiles the graph corresponding to the specified ID.

    GEFinalizeV2

    Finalizes GE and destroys associated allocations.

    GEGetErrorMsgV3

    Obtains and clears the error messages returned by other failed API calls in the same process or thread.

    GEGetWarningMsgV3

    Obtains and clears the warning messages returned by other failed API calls in the same process or thread.

    GEInitializeV2

    Initializes GE.

    GetCompiledGraphSummary

    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.

    GetCompiledModel

    Obtains the serialized model after graph compilation.

    GetSessionId

    Obtains the session ID.

    IsGraphNeedRebuild

    Determines whether a graph needs to be rebuilt.

    LoadGraph

    Loads a graph and prepares for its execution, including allocating and managing resources such as memory and computational streams required for graph execution.

    RegisterCallBackFunc

    Registers a callback function.

    RegisterExternalAllocator

    Registers an external allocator to the GE. This applies to the scenario where the user's memory pool is used.

    RemoveGraph

    Removes a graph with a specified ID from the current GeSession.

    RunGraph

    Synchronously runs the graph of a specified ID and returns the execution result.

    RunGraphAsync

    Asynchronously runs the graph of a specified ID and returns the execution result.

    RunGraphWithStreamAsync

    Asynchronously runs the graph of a specified ID and returns the execution result.

    SetGraphConstMemoryBase

    Sets the const memory base address of a graph.

    SetGraphFixedFeatureMemoryBaseWithType

    Sets the base address of the fixed feature memory of different memory types in a graph.

    UpdateGraphFeatureMemoryBase

    Updates the feature memory base address of a graph.

    UpdateGraphRefreshableFeatureMemoryBase

    Updates the base address of the feature memory that can be updated except fixed memory.

    UnregisterExternalAllocator

    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

    CompliantNodeBuilder

    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.

    EsCGraphBuilder

    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.

    EsCTensorHolder

    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.

    EsGraphBuilder

    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.

    EsTensorHolder

    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.

    EsTensorLike

    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

    EsCreateGraphBuilder

    Creates a graph builder instance.

    EsDestroyGraphBuilder

    Releases graph builder resources.

    EsCreateGraphInputWithDetails

    Creates an input on a graph.

    EsCreateGraphInput

    Creates a data input on a graph.

    EsSetDataType

    Sets the data type of a tensor. If no data type is specified, the default value float is used.

    EsSetFormat

    Sets the memory format of a tensor. If no format is set, the default value ND is used.

    EsSetShape

    Sets the shape of a tensor. If no shape is set, the default value [] is used, indicating a scalar.

    EsSetOriginSymbolShape

    Sets the symbolic expression of the tensor shape. If it is not set, there is no symbolic information by default.

    EsCreateConstInt64

    Creates a Const node of the int64 type.

    EsCreateConstInt32

    Creates a Const node of the int32 type.

    EsCreateConstUInt64

    Creates a Const node of the uint64 type.

    EsCreateConstUInt32

    Creates a Const node of the uint32 type.

    EsCreateConstFloat

    Creates a Const node of the float type.

    EsCreateVectorInt64

    Creates a vector constant of the int64 type.

    EsCreateVectorInt32

    Creates a vector constant of the int32 type.

    EsCreateVectorUInt64

    Creates a vector constant of the uint64 type.

    EsCreateVectorUInt32

    Creates a vector constant of the uint32 type.

    EsCreateVectorFloat

    Creates a vector constant of the float type.

    EsCreateScalarInt64

    Creates a scalar constant of the int64 type.

    EsCreateScalarInt32

    Creates a scalar constant of the int32 type.

    EsCreateScalarUInt64

    Creates a scalar constant of the uint64 type.

    EsCreateScalarUInt32

    Creates a scalar constant of the uint32 type.

    EsCreateScalarFloat

    Creates a scalar constant of the float type.

    EsCreateVariable

    Creates a variable node.

    EsSetGraphOutput

    Sets the output of a graph.

    EsBuildGraphAndReset

    Returns the pointer to the ge::Graph instance. The ownership is transferred to the caller.

    EsGetOwnerBuilder

    Returns the snapshot of the EsCGraphBuilder instance. The ownership is not transferred.

    EsGetProducer

    Returns the snapshot of the ge::GNode instance.

    EsAddControlEdge

    Connects control edges.

    EsCreateEsCTensor

    Used by a C user to create an EsCTensor.

    EsCreateEsCTensorFromFile

    Used by a C user to create an EsCTensor using a binary file.

    EsSetInt64AttrForGraph

    Sets the int64 attribute of a graph.

    EsSetStringAttrForGraph

    Sets the string attribute of a graph.

    EsSetBoolAttrForGraph

    Sets the Boolean attribute of a graph.

    EsSetInt64AttrForTensor

    Sets the int64 attribute of a tensor.

    EsSetStringAttrForTensor

    Sets the string attribute of a tensor.

    EsSetBoolAttrForTensor

    Sets the Boolean attribute of a tensor.

    EsSetInt64AttrForNode

    Sets the int64 attribute of a node.

    EsSetStringAttrForNode

    Sets the string attribute of a node.

    EsSetBoolAttrForNode

    Sets the Boolean attribute of a node.

Basic Data Structures and APIs of Graphs (C++)

  • Class and structure

    API

    Description

    ArgDescInfo

    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.

    ArgsFormatSerializer

    ArgsFormat serialization information.

    AttrValue

    Stores attribute values.

    BaseCustomOp

    A base class for custom operators.

    CompiledGraphSummary

    Provides a brief summary of the graph compilation result.

    CtInferShapeContext

    Inherited from InferShapeContext, CtInferShapeContext is used for shape inference during compilation and provides APIs for compilation.

    CtInferShapeRangeContext

    Inherited from InferShapeRangeContext, CtInferShapeRangeContext is used for ShapeRange inference during compilation and provides APIs for compilation.

    CustomPassContext

    Obtains the custom pass context object.

    CustomOpCreatorRegister

    Registers custom operators.

    DecomposePass

    Decomposition pass class.

    EagerExecuteOp

    A base class for custom operators.

    EagerOpExecutionContext

    Operator execution context.

    ExternalWeightDesc

    Obtains details of the external weights persisted to a disk.

    FeatureMemory

    Stores feature memory information.

    FusionBasePass

    Fusion pass.

    FusionPassRegistrationData

    Fusion pass registration class.

    GeUtils

    Provides utilities for GE graph modification, such as shape inference, node support verification, and graph optimization.

    Graph

    Constructs graph-related classes.

    GraphBuffer

    Stores the cached data of graphs.

    GNode

    Constructs the node data of a graph.

    InferenceContext

    Obtains the inference context object and sets the shape and data type of the object. It is mainly used for resource operators.

    InferFormatFuncRegister

    Registers the operator InferFormat function. This API is referenced by other header files and is not directly called by operator developers.

    InferShapeFuncRegister

    Registers the operator infershape function. This API is referenced by other header files and is not directly called by operator developers.

    InferValueRangeFuncRegister

    Registers the operator InferValueRangeFuncRegister function. This API is referenced by other header files and is not directly called by operator developers.

    InputTensorInfo

    Inputs tensor information.

    KernelLaunchInfo

    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.

    LogicalStreamAllocationInfo

    Obtains logical stream allocation information.

    MatchResult

    A matched graph structure obtained on PatternMatcher. The results contain the matched nodes.

    ModelBufferData

    Serialized model data in the memory buffer.

    Operator

    Operator class.

    OperatorCreatorRegister

    Registers an operator prototype. This API is referenced by other header files. Therefore, it is not directly called by operator developers.

    OperatorFactory

    An internal associated API, which is referenced by other header files and is not directly called by operator developers.

    OpLibRegister

    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.

    OutputTensorInfo

    Outputs tensor information.

    PassReceiver

    Receives and processes pass registration information.

    PassRegistrar

    Receives the fusion pass registration information and registers it with the global singleton.

    PassRegistrationData

    A class for registering and managing custom passes (in the processing phase).

    Pattern

    Defines a template for graph topology matching. It takes a graph as input and specifies the graph structure to match.

    PatternFusionPass

    Pattern fusion class.

    PatternMatcher

    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.

    PatternMatcherConfig

    A class used to configure the PatternMatcher behavior.

    PatternMatcherConfigBuilder

    An auxiliary class used to construct PatternMatcherConfig.

    ShapeAndType

    Sets and obtains the shape and data type of an object.

    StreamAllocationSummary

    Stream allocation summary.

    StreamPassContext

    Context object for the logical stream allocation pass.

    SubgraphRewriter

    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.

    SubgraphInput

    Describes an input tensor of a subgraph.

    SubgraphOutput

    Describes an output tensor of a subgraph.

    SubgraphBoundary

    Defines a subgraph boundary.

    VerifyFuncRegister

    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

    ConvertToAscendString

    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.

    ConvertToListAscendString

    Defines a template function ConvertToListAscendString to convert strings of different types to those of the AscendString type.

  • Macro

    Macro Definition

    Description

    BROADCAST_INFER

    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.

    COMMON_INFER_FUNC_REG

    Registers the InferShape function of an operator.

    ELMTWISE_INFER_SHAPEANDTYPE

    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.

    IMPLEMT_COMMON_INFERFUNC

    Encapsulates the Common_InferShape function of an operator.

    IMPLEMT_INFERFORMAT_FUNC

    Encapsulates the inferFormat function of an operator.

    IMPLEMT_INFERFUNC

    Encapsulates the InferShape function of an operator.

    IMPLEMT_VERIFIER

    Encapsulates the Verify function of an operator.

    INFER_FORMAT_FUNC_REG

    Registers the InferFormat function of an operator.

    INFER_FUNC_REG

    Registers the InferShape function of an operator.

    REG_AUTO_MAPPING_OP

    Registers custom operators.

    REG_FUSION_PASS

    Registers the custom fusion pass.

    REG_DECOMPOSE_PASS

    Registers the graph modification function in the 1-to-N scenario

    REGISTER_CUSTOM_PASS

    Registers the custom pass.

    VERIFY_FUNC_REG

    Registers the Verify function of an operator.

    Prototype Definition (REG_OP)

    Defines the operator prototype.

    Prototype Definition Derivative APIs

    Registers an operator type.

  • Enum

    Enum Type

    Description

    ArgDescType

    Args address type.

    CustomPassStage

    Custom pass execution phase.

    HiddenInputSubType

    Hidden input address type of ArgDescInfo.

    DumpFormat

    Dump file format.

    MemoryType

    -

    ProfDataTypeConfig

    Configuration file of the profiling data type.

    ProfilingAicoreMetrics

    Profiling AI Core metrics.

Session APIs (Python)

API

Description

Session Constructor

Initializes a session.

add_graph

Adds a graph to a session.

ge_initialize

Initializes GE for execution.

ge_finalize

Terminates GE and releases all resources.

run_graph

Runs a graph.

ES APIs (Python)

  • Class and structure

    API

    Description

    GraphBuilder

    GraphBuilder class, which is used to build computational graphs in Eager Style mode.

    TensorHolder

    TensorHolder class, which is used to represent tensor operations in Eager Style graph construction.

  • Global function

    API

    Description

    attr_scope

    Attribute scope context manager.

    control_dependency_scope

    Controls the dependency scope context manager.

    get_plugin

    Obtains the plug-in module with the specified name.

    list_plugins

    Lists the names of all loaded plug-ins.

Basic Data Structures and APIs of Graphs (Python)

  • Class and structure

    API

    Description

    Graph

    Graph class, which is used to represent and operate computational graphs.

    Node

    Node class, which is used to represent and operate nodes in a computational graph.

    Tensor

    Tensor class, which is used to represent tensor data.

  • Enum

    Enum

    Description

    AttrValueType

    Enumerates attribute value types.

    DataType

    Enumerates data types and defines all supported data types.

    DumpFormat

    Enumerates the graph export formats.

    InputType

    Enumerates input types.

    Format

    Enumerates data formats and defines all supported data formats.

Basic Data Structures and APIs of Graphs (C)

API

Description

aclGetCustomOpLibPath

Obtains the path of the custom operator library.

GeSessionLoadGraph

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.

GeSessionExecuteGraphWithStreamAsync

Runs the graph of a specified ID using the specified session instance and returns the execution result. This API is asynchronous.

GEStreamAllocationSummaryGetAllNodes

Obtains all nodes of the root graph and subgraphs.

GEStreamAllocationSummaryGetAttachedStreamIds

Obtains the IDs of the auxiliary secondary logical streams of the root graph and subgraphs.

GEStreamAllocationSummaryGetHcclFollowedStreamNums

Obtains the actual number of physical streams of the communication secondary stream corresponding to the root graph and subgraphs.

GEStreamAllocationSummaryGetLogicalStreamIds

Obtains the logical stream IDs of the root graph and subgraphs.

GEStreamAllocationSummaryGetPhysicalStreamNums

Obtains the actual number of physical streams of the root graph and subgraphs.

GEStreamAllocationSummaryGetStringInfos

Obtains the logical stream information strings of the root graph and subgraphs.

GEStreamAllocationSummaryGetStreamGraphs

Obtains the stream graphs of the root graph and subgraphs.

GEStreamAllocationSummaryGetUsrStreamLabels

Obtains the user stream labels of the root graph and subgraphs.

GEStreamAllocationSummaryIsAssignedByStreamPass

Checks whether the root graph and subgraph are allocated by the stream allocation pass registered by the user.

GetRegisteredIrDef

Obtains the definition of the registered IR operator prototype.

IsIrRepSupport

Queries the IR expression capability.