Internal Associated APIs

During operator prototype registration, tiling implementation, and shape inference, some auxiliary data structures and APIs are called in the external open APIs, which are referred to as internal associated APIs. Developers will not directly call internal associated APIs, so this section is only for brief introduction.

KernelContext Class

This class encapsulates the underlying data structure KernelRunContext, including the numbers of operator inputs and outputs, input and output data information, compute_node_info, and kernel_extend_info required for kernel execution.

Table 1 Member functions of the KernelContext class

API

Function

GetInput

Obtains the input chain pointer. Chain is a class that can be used to store any type of data.

GetInputNum

Obtains the number of kernel inputs.

GetInputPointer

Obtains the pointer to input data. This function first obtains the input chain and then obtains the pointer from the input chain.

GetInputStrPointer

Obtains the pointer to the input string. This function first obtains the input chain and then obtains the pointer from the input chain.

GetInputValue

Obtains the value of input data. This function first obtains the input chain and then obtains the value from the input chain.

GetOutput

Obtains the output chain pointer.

GetOutput2

Obtains the output chain pointer.

GetOutputNum

Obtains the number of kernel outputs.

GetOutputPointer

Obtains the pointer to output data. This function first obtains the output chain and then obtains the pointer from the output chain.

GetContext

Obtains the lower-layer context structure.

GetKernelExtend

Obtains the pointer to the kernel extension information.

GetComputeNodeExtend

Obtains the pointer to the compute node information.

MutableInput

Obtains the input chain pointer.

MutableInputPointer

Obtains the pointer to input data. This function first obtains the input chain and then obtains the pointer from the input chain.

IsInlineSize

Determines whether a piece of data is stored in inline mode based on the data length. Inline storage indicates that data is saved in the context without the need for separate memory allocation.

TilingParseContext Class

The information required for TilingParse is stored in this class. This class provides context information for writing the TilingParse function of an operator. The required information can be obtained from this class during TilingParse.

Table 2 Member functions of the TilingParseContext class

API

Description

GetCompiledJson

Obtains the JSON string generated during operator build.

GetCompiledInfo

Obtains the CompiledInfo instance.

GetPlatformInfo

Obtains the fe::PlatFormInfos pointer.

Chain Class

Chain is a class that can be used to store any type of data. You can use the Set API to save data, and the GetPointer or GetValue method to obtain the saved data.

Table 3 Member functions of the Chain class

API

Function

GetPointer

Obtains the pointer that points to the data stored in the chain.

GetValue

Obtains the value of the data stored in the chain.

Set

Sets the data to the chain. During setting of the data pointer, the deleter is called to delete the data stored in the chain.

SetWithDefaultDeleter

Sets the data to the chain. During setting of the data pointer, the deleter is called to delete the data stored in the chain.

HasDeleter

Checks whether data stored in the current chain contains the deleter.

ContinuousBuffer Class

The ContinuousBuffer class is used to continuously store data of any type. Each piece of data is converted into a uint8_t array for storage, and each memory unit is called a buffer. ContinuousBuffer uses two attributes to describe the stored data, namely the number of storage buffers and the memory offset offsets_ of each buffer. Every buffer is continuous in the memory.

Table 4 Member functions of the ContinuousBuffer class

API

Function

GetNum

Obtains the number of buffers.

GetTotalLength

Obtains the total length of the current instance.

Get

Obtains the buffer pointer and length information.

KernelExtendInfo Class

This class is used to store additional information for kernel running, including the kernel name, type, index of the kernel types used for profiling registration, and index of the compute node names.

Table 5 Member functions of the KernelExtendInfo class

API

Function

GetKernelName

Obtains the kernel name.

SetKernelName

Sets the kernel name.

GetKernelType

Obtains the kernel type. An operator can correspond to multiple kernels, so it can correspond to multiple kernel types.

SetKernelType

Sets the kernel type.

SetKernelTypeIdx

Sets kernel_type_idx_ for profiling. It indicates the idx of the kernel type character string set during profiling. Use idx to replace the kernel type character string as the identifier to improve the speed.

SetNodeNameIdx

Sets compute_node_name_idx_ for profiling. During profiling, use idx to replace the node name string as the identifier to improve the speed.

GetNodeNameIdx

Obtains compute_node_name_idx_ for profiling.

GetKernelTypeIdx

Obtains kernel_type_idx_ for profiling.

TensorOperateType

enum TensorOperateType {
  kGetTensorAddress,  ///< Obtain the tensor address.
  kFreeTensor,        ///< Free the tensor.
  kPlusShareCount,    ///< Share the tensor.
  kTensorOperateType
};

StructSizeInfoBase Class

The StructSizeInfoBase class is used to store and obtain sizes of tiling structures defined by Ascend C high-level APIs and users. It uses a singleton to implement a structure information library.

Table 6 Member functions of the StructSizeInfoBase class

Function

Meaning

GetInstance

Obtains the singleton of the StructSizeInfoBase class.

SetStructSize

Sets the sizes of tiling structures defined by high-level APIs and users.

GetStructSize

Obtains the sizes of tiling structures defined by high-level APIs and users.

TilingDataStructBase Class

The TilingDataStructBase class is used to record the information about the tiling structure construction process. The following APIs are provided:

Table 7 Member functions of the TilingDataStructBase class

Function

Meaning

GetInstance

Obtains the singleton of the TilingDataStructBase class.

RecordTilingStruct

Used by the framework to check whether different operators register different tiling structures with the same name. If yes, a warning is printed.

Value Computation Verification APIs

The following table lists APIs used to verify value computation in the framework.

Table 8 APIs

Function

Meaning

MulOverflow

Checks whether overflow occurs in value multiplication. The condition for determining overflow is that the product value is greater than the maximum value that can be represented by TRet of the ret type.

AddOverflow

Checks whether overflow occurs in value addition. The condition for determining overflow is that the sum of values is greater than the maximum value that can be represented by TRet of the ret type.

Compat

Checks whether the value of an input parameter is beyond the value range that can be represented by the specified type T.

OpExecuteContext Class

This class is used to save the contexts when single-operator execution APIs are called in graph mode.

Table 9 Member functions of the OpExecuteContext class

Function Name

Meaning

GetInputTensor

Obtains the input tensor of a specified index.

GetOptionalInputTensor

Obtains the optional input tensor of a specified index.

GetDynamicInputTensor

Obtains the tensor with a dynamic number of inputs at a specified index.

GetRequiredInputTensor

Obtains the required input tensor of a specified index.

GetOutputTensor

Obtains the output tensor of a specified index.

GetDynamicOutputTensor

Obtains the tensor with a dynamic number of outputs at a specified index.

GetRequiredOutputTensor

Obtains the required output tensor of a specified index.

GetStream

Obtains the stream information of a delivered operator.

GetOpExecuteFunc

Obtains the execution callback function of a multi-kernel operator.

MallocWorkspace

Allocates workspaces.

FreeWorkspace

Frees workspaces.

GetDeterministic

Obtains configuration items for deterministic computing.

GetAllowHf32

Obtains the allow_hf32 configuration item.

GetPrecisionMode

Obtains configuration items of a precision mode.