Ascend C APIs

Ascend C provides a group of class library APIs. You can use the standard C++ syntax and class library APIs for programming. Ascend C programming class library APIs are classified into the following types:
  • Basic data structures: basic data structures used in kernel APIs, such as GlobalTensor and LocalTensor.
  • C APIs at the language extension layer: Open the complete programming capabilities of chips, support memory allocation for arrays, and generally use pointer-based programming, providing a consistent C language programming experience with the industry.
  • Basic APIs: implement abstract hardware capabilities and open chip capabilities to ensure completeness and compatibility. The APIs marked as Instruction Set Architecture Special Interface (ISASI, hardware architecture-related APIs) do not guarantee compatibility across hardware versions.
  • High-level APIs: implement common compute algorithms to improve programming and development efficiency based on basic APIs. High-level APIs include math library, Matmul, Softmax, and others, and ensure compatibility.
  • Single Instruction Multiple Thread (SIMT) APIs: implement parallel computation by executing a single instruction across multiple threads. SIMT programming is mainly used for vector computing and is particularly well-suited for handling discrete memory access and complex control logic.
  • Utils APIs (common auxiliary functions): provide various common utility classes, covering functions such as standard library, platform information acquisition, runtime compilation, and log output. These APIs empower you to efficiently develop operators and optimize performance.

Basic Data Structure

Table 1 Basic data structure list

API

Function

LocalTensor

LocalTensor is used to store data in the local memory of the AI Core. It supports the logical positions (TPosition) VECIN, VECOUT, VECCALC, A2, B1, B2, CO1, and CO2.

GlobalTensor

Stores the global data of the global memory (external storage).

Coordinate

Coordinate is essentially a tuple, and is used to indicate location information of a tensor in different dimensions, that is, a coordinate value.

Layout

The Layout<Shape, Stride> data structure is a basic template class that describes the memory layout of multi-dimensional tensors. It implements the mapping from the logical coordinate space to the one-dimensional memory address space based on the shape and stride information at compile time, providing fundamental support for complex tensor operations and hardware optimization.

TensorTrait

The TensorTrait data structure is a basic template class that describes tensor-related information, including the tensor data type, logical position, and layout memory layout.

Basic APIs

Table 2 Memory data movement APIs

API

Function

DataCopy

Performs data movement, including common data movement, enhanced data movement, tiled data movement, and real-time format conversion.

Copy

Performs the movement instruction between VECIN, VECCALC, and VECOUT, and supports the mask operation and Data Block interval operation.

Table 3 Memory vector computation APIs

Category

API

Function

Basic Arithmetic

Exp

Computes the natural exponent based on elements.

Ln

Computes the natural logarithm based on elements.

Abs

Computes the absolute value based on elements.

Reciprocal

Computes the reciprocal based on elements.

Sqrt

Extracts the square root based on elements.

Rsqrt

Computes the reciprocal after square root extraction based on elements.

Relu

Performs a ReLU operation based on elements.

Add

Performs addition based on elements.

Sub

Performs subtraction based on elements.

Mul

Performs multiplication based on elements.

Div

Performs division based on elements.

Max

Computes the maximum value based on elements.

Min

Computes the minimum value based on elements.

Adds

Performs addition between a scalar and a vector element-wise.

Muls

Performs multiplication between a scalar and a vector element-wise.

Maxs

Compares each element of a vector with a scalar and returns the larger one.

Mins

Compares each element of a vector with a scalar and returns the smaller one.

LeakyRelu

Computes Leaky ReLU on the source operand element-wise.

Basic Arithmetic

Subs

Performs subtraction between a scalar and each element of a vector. The scalar can be before or after the vector. The scalar input can be a single element from a LocalTensor.

Divs

Performs division between a scalar and each element of a vector. The scalar can be before or after the vector. The scalar input can be a single element from a LocalTensor.

Logical Computation

Not

Performs bitwise Not based on elements.

And

Performs a bitwise AND operation based on elements.

Or

Performs a bitwise OR operation based on elements.

ShiftLeft

Performs left shift on the source operand element-wise. The shift distance is determined by scalarValue.

ShiftRight

Performs right shift on the source operand element-wise. The shift distance is determined by scalarValue.

Logical Computation

Ands

Performs bitwise AND between a scalar and each element of a vector. The scalar can be before or after the vector. The scalar input can be a single element from a LocalTensor.

Ors

Performs bitwise OR between a scalar and each element of a vector. The scalar can be before or after the vector. The scalar input can be a single element from a LocalTensor.

Compound Computation

Axpy

Adds the product of each element in the source operand and a scalar to the corresponding element in the destination operand.

CastDequant

Quantizes the input and converts the precision.

AddRelu

Adds inputs element-wise, compares the result with 0, and selects the larger value.

AddReluCast

Adds inputs element-wise, compares the result with 0, selects the larger value, and converts precision based on the data types of the source and destination operand tensors.

AddDeqRelu

Adds inputs element-wise, performs Deq quantization on the result, and then performs ReLU calculation on the result (compares the result with 0 and selects the larger value).

SubRelu

Computes the difference element-wise, compares the result with 0, and selects the larger value.

SubReluCast

Computes the difference element-wise, compares the result with 0, selects the larger value, and converts precision based on the data types of the source and destination operand tensors.

MulAddDst

Multiplies src0Local and src1Local element-wise, adds them to dstLocal, and saves the final result to dstLocal.

MulCast

Performs element-wise manipulation and converts the precision based on the data types of the source and destination operand tensors.

FusedMulAdd

Multiplies src0Local and dstLocal element-wise, adds src1Local, and saves the result to dstLocal.

MulAddRelu

Multiplies src0Local and dstLocal element-wise, adds them to src1Local, compares the result with 0, selects the larger value, and saves the final result to dstLocal.

Comparison and Selection

Compare

Compares the sizes of two tensors element by element. If the comparison result is true, the corresponding bit of the output result is 1. Otherwise, the bit is 0.

Compare (Result Stored in a Register)

Compares the sizes of two tensors element by element. If the comparison result is true, the corresponding bit of the output result is 1. Otherwise, the bit is 0. This interface can be used when the mask parameter is required. The result is stored in a register.

Compares

Compares the sizes of an element in a tensor with that of a scalar element by element. If the comparison result is true, the corresponding bit of the output result is 1. Otherwise, the bit is 0.

Select

Selects the source operand src0 or src1 based on the bit value of selMask (mask used for selection) to obtain the destination operand dst. When the bit value of selMask is 1, src0 is selected. When the bit value of selMask is 0, src1 is selected.

GatherMask

Selects elements from the source operand and writes them to the destination operand based on a gather mask (for data collection) that corresponds to either the binary of the built-in fixed mode or the binary of the user-defined input tensor values.

Precision Conversion Instructions

Cast

Converts precision based on the data types of the source and destination operand tensors.

Reduction Computation

ReduceMax

Obtains the maximum value and its corresponding index position among the input data.

ReduceMin

Obtains the minimum value and its corresponding index position among the input data.

ReduceSum

Sums up all input data.

WholeReduceMax

Computes the maximum value and index of all data in each repeat.

WholeReduceMin

Computes the minimum value and index of all data in each repeat.

WholeReduceSum

Sums all data in each repeat.

BlockReduceMax

Computes the maximum of all elements in each repeat.

BlockReduceMin

Computes the minimum of all elements in each repeat.

BlockReduceSum

Sums all elements in each repeat. Source operands are added in binary tree mode.

PairReduceSum

Sums two adjacent (odd and even) elements.

RepeatReduceSum

Sums all data in each repeat. Compared with WholeReduceSum, it does not support the bitwise mask mode. You are advised to use WholeReduceSum with more comprehensive functions.

Data Conversion

Transpose

Performs transpose on data blocks of a 16 × 16 2D matrix, and conversion between [N,C,H,W] and [N,H,W,C].

TransDataTo5HD

Converts the NCHW format to the NC1HWC0 format. It can also be used for transposing a two-dimensional matrix data block.

Data Padding

Duplicate

Copies a variable or an immediate value multiple times and fills the result into a vector.

Brcb

Extracts eight elements from a given input tensor each time and fills them in eight data blocks (32 bytes) in the result tensor. Each element corresponds to a data block.

CreateVecIndex

Creates the vector index with firstValue as the start value.

Data Scatter/Data Gather

Gather

Gathers given input tensors by element to the result tensor based on the offset address tensor provided.

Mask Operations

SetMaskCount

Sets mask to counter mode. In this mode, you do not need to perceive the number of iterations or process unaligned tail blocks. You can directly pass in the amount of data to be computed. The actual number of iterations is automatically inferred by the Vector Unit.

SetMaskNorm

Sets mask to normal mode. This mode is the default mode. You can configure the number of iterations.

SetVectorMask

Sets mask during Vector computation.

ResetMask

Restores the mask value to the default (all 1s), indicating that all elements in each iteration participate in the Vector computation.

Quantization Settings

SetDeqScale

Sets the value of the DEQSCALE register.

Table 4 Scalar computation APIs

API

Function

GetBitCount

Obtains the number of 0s or 1s in a binary number of the uint64_t type.

CountLeadingZero

Computes the number of leading 0s of a uint64_t number (number of 0s from the most significant bit to the first 1 in the binary number).

Cast (float to half/int32_t)

Converts the type of a scalar to a specified type.

CountBitsCntSameAsSignBit

Computes the number of consecutive bits that are the same as the sign bit from the most significant bit in the binary number of the uint64_t type.

GetSFFValue

Obtains the location where the first 0 or 1 appears in a binary number of the uint64_t type.

Cast (float to bfloat16_t)

Converts scalar data of the float type to scalar data of the bfloat16_t type.

Cast (multiple types to float)

Converts scalar data of the bfloat16_t type to scalar data of the float type.

Table 5 Resource management APIs

API

Function

TPipe

Manages resources such as the global memory. It allocates and manages resources such as memory.

GetTPipePtr

Obtains the TPipe pointer for the Global Memory managed by the framework. After obtaining the pointer, you can perform TPipe-related operations.

TBufPool

Manually manages or reuses the Unified Buffer/L1 Buffer physical memory. It is mainly used when the Unified Buffer/L1 Buffer physical memory is insufficient in multi-stage computing.

TQue

Performs EnQue and DeQue operations, and implements inter-task synchronization through queues.

TQueBind

Binds the source and destination logical locations to determine the memory allocation location and insert the corresponding synchronization event, solving problems such as memory allocation, management, and synchronization.

TBuf

Manages the memory occupied by some temporary variables used during Ascend C programming. The memory occupied by these temporary variables can be managed using the TBuf data structure.

InitSpmBuffer

Initializes the SPM buffer.

WriteSpmBuffer

Copies the data that needs to be temporarily stored due to overflow into the SPM Buffer.

ReadSpmBuffer

Reads data from the SPM buffer back to the local data.

GetUserWorkspace

Obtains the workspace pointer used by the user.

SetSysWorkSpace

Sets the pointer to the system workspace, as the system workspace is used by the framework communication mechanism during fused operator programming.

GetSysWorkSpacePtr

Obtains the pointer to the system workspace.

Table 6 Synchronization control APIs

API

Function

TQueSync

Provides synchronization control. You can use these types of APIs to implement synchronization control.

IBSet

When different AI Cores operate the same global memory block, this function can be called to synchronize the AI Cores to avoid data dependency problems such as write-after-read, read-after-write, and write-after-write. IBSet is called to set the flag bit of a core. IBSet and IBWait are used in pairs to indicate the synchronization waiting instruction between cores, waiting for the completion of a core operation.

IBWait

When different AI Cores operate the same global memory block, this function can be called to synchronize the AI Cores to avoid data dependency problems such as write-after-read, read-after-write, and write-after-write. IBWait and IBSet are used in pairs to indicate the synchronization waiting instruction between cores, waiting for the completion of a core operation.

SyncAll

When different AI Cores operate the same global memory block, this function can be called to synchronize the AI Cores to avoid data dependency problems such as write-after-read, read-after-write, and write-after-write. Currently, multi-core synchronization is classified into hardware synchronization and software synchronization. Hardware synchronization uses hardware-provided all-core synchronization instructions to ensure multi-core synchronization. Software synchronization is implemented through software algorithms.

InitDetermineComputeWorkspace

Initializes the value of the GM shared memory. WaitPreBlock and NotifyNextBlock can be called only after the initialization is complete.

WaitPreBlock

Reads the value in the GM address to determine whether to continue to wait. When the GM value meets the waiting condition of the current core, the core can proceed to the next operation.

NotifyNextBlock

Writes the GM address to notify the next core that the operation of the current core is completed and the next core can perform the operation.

SetNextTaskStart

Is called in the subkernels of SuperKernel. After the call, the instructions can be executed in parallel with subsequent subkernels, improving the overall performance.

WaitPreTaskEnd

Is called in the subkernels of SuperKernel. Before the call, the instructions can be executed in parallel with earlier subkernels, improving the overall performance.

Table 7 Cache processing APIs

API

Function

DataCachePreload

Preloads data from the specific DDR address where the source address is located to the data cache.

DataCacheCleanAndInvalid

Refreshes the cache to ensure cache consistency.

Table 8 System variable access API

API

Function

GetBlockNum

Obtains the number of blocks configured for the current task, which is used for multi-core logic control in the code.

GetBlockIdx

Obtains the index of the current core, which is used for multi-core logic control and multi-core offset computation in the code.

GetDataBlockSizeInBytes

Obtains the size (in bytes) of a data block of the current chip version. You can compute the values of parameters, such as repeatTime, Data Block Stride, and Repeat Stride, to be passed in the API command based on the data block size.

GetArchVersion

Obtains the version number of the current AI processor architecture.

InitSocState

Initializes the AI Core state. The AI Core has some global states, such as the atomic accumulation state and mask mode. During actual running, these values can be modified by previously executed operators, resulting in unexpected computation behavior. In static tensor programming scenarios, you must call this API at the kernel entry point.

Table 9 Atomic operation APIs

API

Function

SetAtomicAdd

Sets whether to perform atomic addition for data transfer from VECOUT to GM, from L0C to GM, or from L1 to GM. The addition data type can be set based on different parameters.

SetAtomicType

Sets different atomic operation data types using template parameters.

DisableDmaAtomic

Clears the status of an atomic operation.

AtomicAdd

Performs atomic addition on the specified global memory address.

AtomicMin

Performs atomic minimization on the specified global memory address.

AtomicMax

Performs atomic maximization on the specified global memory address.

AtomicCas

Performs an atomic comparison on the specified global memory address. If the current value at that address equals value1, it is replaced with value2. Otherwise, the value at the global memory address remains unchanged.

AtomicExch

Performs an atomic exchange operation in the global memory. Specifically, it reads data from the specified global memory address, stores the new value back to the same address, and returns the old value.

Table 10 Debugging APIs

API

Function

DumpTensor

Dumps the content of specified tensors for operators developed based on operator projects.

printf

Implements the formatted output function in CPU- or NPU-side debugging for operators developed based on operator projects.

ascendc_assert

Provides an API for implementing the assert function in both the CPU domain and NPU domain. When the assert condition is not met, the system outputs the assert information and prints it in a formatted manner on the screen.

assert

Implements the assert function in CPU/NPU for operators developed based on operator projects.

DumpAccChkPoint

Dumps the content of specified tensors for operators developed based on operator projects. This API can be used to print tensors at a specified offset position.

PrintTimeStamp

Provides the timestamp logging function to mark key execution points in the operator kernel code.

Trap

Stops the kernel when a software exception occurs.

GmAlloc

Creates shared memory during verification of the CPU-side operation of the kernel function. That is, creates a shared file in the /tmp directory and returns the mapping pointer to the file.

ICPU_RUN_KF

Functions as the CPU commissioning entry and completes calls to CPU operator programs during verification of the CPU-side operation of the kernel function.

ICPU_SET_TILING_KEY

Specifies tilingKey used for the current CPU debugging. During debugging, only the branch to which tilingKey corresponds in the operator kernel function is executed.

GmFree

Frees the shared memory allocated by GmAlloc during verification of the CPU-side operation of the kernel function.

SetKernelMode

Sets the kernel mode to the single AIV mode, single AIC mode, or MIX mode to enable CPU commissioning of single AIV (vector) operators, single AIC (cube) operators, or MIX operators, respectively.

TRACE_START

Performs dotting in any running phase of the operator when the CAModel is used for operator performance simulation, to analyze the pipeline diagrams of different instructions for further performance tuning.

Indicates dotting from the start point. This API is used together with TRACE_STOP.

TRACE_STOP

Performs dotting in any running phase of the operator when the CAModel is used for operator performance simulation, to analyze the pipeline diagrams of different instructions for further performance tuning.

Indicates dotting from the end point. This API is used together with TRACE_START.

MetricsProfStart

Starts the profile data collection. This API is used together with MetricsProfStop. When using Operator Tuning (msProf) for on-board operator tuning, you can call MetricsProfStart and MetricsProfStop before and after the code segment on the kernel to specify the scope of the code segment to be optimized.

MetricsProfStop

Stops the profile data collection. This API is used together with MetricsProfStart. When using Operator Tuning (msProf) for on-board operator tuning, you can call MetricsProfStart and MetricsProfStop before and after the code segment on the kernel to specify the scope of the code segment to be optimized.

Table 11 Tool function APIs

API

Function

Async

Provides a unified API for executing specific functions in different modes (AIC or AIV), thereby avoiding direct hardware condition judgment in code (such as using ASCEND_IS_AIV or ASCEND_IS_AIC).

NumericLimits

NumericLimits is a tool class used to query attributes such as the maximum and minimum values of a specified data type.

GetTaskRatio

Applies to the separated Cube/Vector mode and obtains the Cube/Vector ratio.

GetUBSizeInBytes

Obtains the UB size, in bytes.

GetRuntimeUBSize

Obtains the runtime UB size, in bytes. You can calculate the number of cycles based on the UB size.

Table 12 Kernel tiling APIs

API

Function

GET_TILING_DATA

Obtains the tiling information input by the kernel entry point function of the operator and fills the information in the registered tiling structure. This function is compiled in macro expansion mode. If a user has registered multiple TilingData structures, this API is used to return the default registered structure.

GET_TILING_DATA_WITH_STRUCT

Specifies a structure name to obtain the specified tiling information and fills the information in the corresponding tiling structure. This function is compiled in macro expansion mode.

GET_TILING_DATA_MEMBER

Obtains the member variables of a tiling structure.

TILING_KEY_IS

Checks whether the tiling_key in the current kernel function execution is equal to a specific key, so as to identify a kernel branch with tiling_key==key.

REGISTER_TILING_DEFAULT

Registers the default TilingData structure defined by the user using the standard C++ syntax on the kernel.

REGISTER_TILING_FOR_TILINGKEY

Registers a custom TilingData structure that matches the TilingKey on the kernel. This API requires a logical expression that uses the string TILING_KEY_VAR to represent the actual TilingKey and the range that the TilingKey satisfies.

REGISTER_NONE_TILING

When using a custom TilingData structure defined with the standard C++ syntax in the kernel, if you are unsure which structures need to be registered, you can use this API to inform the framework that you need to use the unregistered standard C++ syntax to define the TilingData. This API works in conjunction with GET_TILING_DATA_WITH_STRUCT, GET_TILING_DATA_MEMBER, and GET_TILING_DATA_PTR_WITH_STRUCT to obtain the corresponding TilingData.

KERNEL_TASK_TYPE_DEFAULT

Sets the global default kernel type, which applies to all tiling keys.

KERNEL_TASK_TYPE

Sets the kernel type corresponding to a specific tiling key.

Table 13 ISASI APIs

Category

API

Function

Scalar Computation

WriteGmByPassDCache

Writes data to the global memory address without passing through the DCache.

ReadGmByPassDCache

Reads data from the global memory address without passing through the DCache.

Vector Computation

VectorPadding

Performs the padding operation on the source operand by the data block based on padMode and padSide.

BilinearInterpolation

Performs bilinear interpolation operations, including vertical iteration and horizontal iteration.

GetCmpMask

Obtains the comparison result of the Compare (Result Stored in a Register) instruction.

SetCmpMask

Sets the comparison register for the APIs where Select does not specify the mask parameter.

GetReduceRepeatSumSpr

Obtains the computation result of ReduceSum (based on the first n data elements of a tensor).

GetReduceRepeatMaxMinSpr

Obtains the maximum/minimum values and the corresponding index values in the scenario where ReduceMax and ReduceMin are consecutive.

ProposalConcat

Inserts consecutive elements into the corresponding positions in Region Proposals. In each iteration, 16 consecutive elements are inserted into the corresponding positions in 16 Region Proposals.

ProposalExtract

Extracts elements from corresponding positions in Region Proposals and rearranges them. In each iteration, 16 elements are extracted from 16 Region Proposals and arranged consecutively. The functionality of this API is the opposite of that of ProposalConcat.

RpSort16

Sorts the Region Proposals based on their score fields in descending order. 16 Region Proposals are sorted in each iteration.

MrgSort4

Merges up to four sorted Region Proposal lists into one. The results are sorted in descending order of the score fields.

Sort32

Serves as a sorting function that can sort up to 32 elements in each iteration.

MrgSort

Merges up to four sorted lists into one. The results are sorted in descending order of the score fields.

GetMrgSortResult

Obtains the number of region proposals in the queue processed by MrgSort or MrgSort4 and stores the number in the four List input parameters in sequence.

Gatherb

Gathers a given input tensor to the result tensor based on the offset address tensor provided.

Scatter

With a given contiguous input tensor and a destination address offset tensor, generates a new result tensor based on the offset address and distributes the input tensor to the result tensor.

Vector Computation

Prelu

Writes src0 to dst directly if src0 is greater than 0. Otherwise, writes the result of src0 × src1 to dst.

Mull

Multiplies the first count data elements of src0 and src1 element-wise, and writes the result to dst0Local. If the result overflows, the overflow part is written to dst1Local.

AbsSub

Subtracts src1 from src0Local, takes the absolute value, and stores the result to dst.

ExpSub

Subtracts src1 from src0, uses the difference as the exponent to compute the power of the natural constant e, and stores the result to dst.

MulsCast

Multiplies the first count elements of the vector source operand by a scalar, converts the result to half type in CAST_ROUND mode, and stores the final result to dst. The scalar can be before or after the tensor.

Truncate

Truncates floating-point elements of the source operand to their integer part, while retaining the data type of the source operand.

Interleave

Interleaves the elements from given source operands src0 and src1 and stores them in the result operands dst0 and dst1.

DeInterleave

Deinterleaves the elements from given source operands src0 and src1 and stores them in the result operands dst0 and dst1.

Data Movement

DataCopyPad

Enables data non-aligned movement.

SetPadValue

Sets the value filled by DataCopyPad.

Cube Computation

Mmad

Performs matrix multiplication and addition.

MmadWithSparse

Performs matrix multiplication and addition operations. The input left matrix A is a sparse matrix, and the input right matrix B is a dense matrix.

SetHF32Mode

Sets register values. This API is similar to SetHF32TransMode, SetMMRowMajor, and SetMMColumnMajor. SetHF32Mode is used to set the HF32 mode of the MMAD.

SetHF32TransMode

Sets register values. This API is similar to SetHF32Mode, SetMMRowMajor, and SetMMColumnMajor. SetHF32TransMode is used to set the HF32 rounding mode of the MMAD. It is valid only when the HF32 mode of the MMAD takes effect.

SetMMRowMajor

Sets register values. This API is similar to SetHF32Mode and SetHF32TransMode. This API sets MMAD computation to traverse preferentially along the N dimension.

SetMMColumnMajor

Sets register values. This API is similar to SetHF32Mode and SetHF32TransMode. This API sets MMAD computation to traverse preferentially along the M dimension.

Conv2D

Performs 2D convolution on a given input tensor and a weight tensor and outputs a result tensor. The Conv2d convolution layer is mostly used for image recognition, and a filter is used to extract features in an image.

Gemm

Multiplies two tensors and outputs a result tensor. Multiply matrix A and matrix B to obtain matrix C, and output matrix C.

SetFixPipeConfig

Sets the tensor quantization parameters for the real-time quantization during DataCopy (CO1 -> GM or CO1 -> A1).

SetFixpipeNz2ndFlag

Sets the NZ2ND configuration for the real-time format conversion (NZ2ND) during DataCopy (CO1 -> GM or CO1 -> A1).

SetFixpipePreQuantFlag

Sets the scalar quantization parameters for the real-time quantization process during DataCopy (CO1 -> GM or CO1 -> A1).

SetFixPipeClipRelu

Sets the maximum value of the ClipReLU operation after real-time quantization during DataCopy (CO1 -> GM).

SetFixPipeAddr

Sets the address of the LocalTensor for the element-wise operation after real-time quantization during DataCopy (CO1->GM).

Fill

Initializes LocalTensor (TPosition: A1, A2, B1, or B2) to a specific value.

LoadData

Provides the Load2D and Load3D data loading functions.

LoadDataWithTranspose

Loads 2D data with transposing from A1/B1 to A2/B2.

SetAippFunctions

Sets AI preprocessing (AIPP) parameters for images.

LoadImageToLocal

Transfers image data from the GM to A1/B1. During the transfer, you can preprocess images, including image flipping, image resizing (clipping, cropping, scaling, and stretching), color space conversion (CSC), and type conversion.

LoadUnZipIndex

Loads the compression index table on the GM to the internal register.

LoadDataUnzip

Decompress the data on the GM and transfer the data to A1, B1, and B2.

LoadDataWithSparse

Moves the 512-byte dense weight matrix stored in B1 to B2, and reads the 128-byte index matrix for sparseness of the dense matrix.

SetFmatrix

Sets the attribute description of the feature map when Load3Dv1/Load3Dv2 is called.

SetLoadDataBoundary

Sets A1/B1 boundary value when Load3D is called.

SetLoadDataRepeat

Sets the repeat parameter of the Load3Dv2 API. After the repeat parameter is set, the Load3Dv2 API can be called once to complete the data movement for multiple iterations.

SetLoadDataPaddingValue

Sets padValue for Load3Dv1/Load3Dv2.

Fixpipe

Processes the result after the matrix computation is complete. For example, the computation result is quantized and the data is moved from CO1 to the Global Memory.

Synchronization Control

SetFlag/WaitFlag

Synchronizes different pipelines in the same core. This synchronization operation needs to be inserted between different pipeline instructions with data dependency.

PipeBarrier

Blocks a pipeline. This synchronization operation needs to be inserted between the same pipelines with data dependency.

DataSyncBarrier

Blocks the execution of subsequent instructions until all previous memory access instructions (the memory location to be waited for can be controlled by parameters) are executed.

CrossCoreSetFlag

Sets the synchronization between the Cube Core (AIC) and Vector Core (AIV) on the AI Core for the separated mode.

CrossCoreWaitFlag

Waits for the synchronization between the Cube Core (AIC) and Vector Core (AIV) on the AI Core for the separated mode.

Synchronization Control

Mutex

Mutex is used for synchronization between asynchronous pipeline instructions in a core. Its function is similar to the lock mechanism in traditional CPUs. The synchronization dependency between pipelines is implemented by locking specified pipelines and then releasing them. Each lock has a fixed mutex ID, which can be custom (ranging from 0 to 27) or released using AllocMutexID/ReleaseMutexID.

AllocMutexID

Obtains and occupies a MutexID from the framework. This API is used together with ReleaseMutexID to manage the obtaining and release of MutexIDs.

ReleaseMutexID

Releases a MutexID from the framework. It is used together with AllocMutexID.

Cache Processing

ICachePreLoad

Preloads instructions to the iCache from the DDR address where the instructions are located.

GetICachePreloadStatus

Obtains the PreLoad status of the iCache.

System Variable Access

GetProgramCounter

Obtains the pointer to the program counter, which is used to record the current program execution position.

GetSubBlockNum

Obtains the number of Vector Cores on the AI Core.

GetSubBlockIdx

Obtains the ID of the Vector Core on the AI Core.

GetSystemCycle

Obtains the number of cycles in the current system. If the number of cycles is converted to time (unit: μs), the frequency must be 50 MHz. The conversion formula is as follows: Time = (Number of cycles/50) μs.

System Variable Access

SetCtrlSpr

Sets specific bits of the CTRL register (control register).

GetCtrlSpr

Reads the value of a specific bit in the CTRL register (control register).

ResetCtrlSpr

Resets specific bits of the CTRL register (control register).

Atomic Operations

SetAtomicMax

Sets whether to perform atomic comparison for subsequent data transferred from VECOUT to GM, which compares the content to be copied with the existing content in GM and writes the maximum value to GM.

SetAtomicMin

Sets whether to perform atomic comparison for subsequent data transferred from VECOUT to GM, which compares the content to be copied with the existing content in GM and writes the minimum value to GM.

SetStoreAtomicConfig

Sets the atomic operation enabling flag and type.

GetStoreAtomicConfig

Obtains the value of the enabling flag and type of the atomic operation.

Debugging APIs

CheckLocalMemoryIA

Monitors the UB read and write operations within the specified range. If the UB read and write operations within the specified range are monitored, an EXCEPTION error is reported. If the UB read and write operations within the specified range are not monitored, no error is reported.

Cube Group Management

CubeResGroupHandle

Controls communication between the AIC and the AIV through soft synchronization in the separated mode, to implement AI Core compute resource grouping.

GroupBarrier

When two AIV tasks in the same CubeResGroupHandle object depend on each other, control synchronization by calling GroupBarrier.

KfcWorkspace

KfcWorkspace is the communication workspace descriptor, which is used to manage the message communication area division of different CubeResGroupHandle objects. It is used together with CubeResGroupHandle. The KfcWorkspace constructor is used to create a KfcWorkspace object.

High-Level APIs

Table 14 Mathematical computation APIs

API

Function

Acos

Computes arc cosine element-wise.

Acosh

Computes inverse hyperbolic cosine element-wise.

Asin

Computes arcsine element-wise.

Asinh

Computes the hyperbolic arcsine element-wise.

Atan

Computes the arc tangent of a trigonometric function element-wise.

Atanh

Computes the inverse hyperbolic tangent element-wise.

Axpy

Adds the product of each element of the source operand and a scalar to the corresponding element in the destination operand.

Ceil

Obtains the minimum integer value greater than or equal to x, that is, rounding towards positive infinity.

ClampMax

Replaces the number greater than scalar with scalar in srcTensor and retains the number less than or equal to scalar as the dstTensor output.

ClampMin

Replaces the number less than scalar with scalar in srcTensor and retains the number greater than or equal to scalar as the dstTensor output.

Cos

Computes the cosine function element-wise.

Cosh

Computes hyperbolic cosine element-wise.

CumSum

Accumulates data by row or column.

Digamma

Computes the logarithmic derivative of the gamma function of x element-wise.

Erf

Computes error function or Gaussian error function element-wise.

Erfc

Returns the complementary error function computing result of input x. The integral ranges from x to infinity.

Exp

Computes the natural exponent element-wise.

Floor

Obtains the minimum integer value less than or equal to x, that is, rounding towards negative infinity.

Fmod

Computes the remainder of two floating-point numbers element-wise.

Frac

Returns decimals element-wise.

Hypot

Computes the square root of the sum of squares of two floating-point numbers element-wise.

IsFinite

Performs element-wise checks to determine whether the input floating-point numbers are neither NaN nor ±INF.

Lgamma

Computes the absolute value and natural logarithm of the gamma function of x element-wise.

Log

Computes logarithm of bases e, 2, and 10 element-wise.

Power

Computes exponentiation element-wise.

Round

Rounds the input element to the nearest integer.

Sign

Performs the Sign operation element-wise. Sign refers to the symbol that returns the input data.

Sin

Computes sine element-wise.

Sinh

Computes hyperbolic sine element-wise.

Tan

Computes tangent element-wise.

Tanh

Performs element-wise logistic regression using the Tanh function.

Trunc

Truncates floating point numbers element-wise, that is, rounding towards zero.

Xor

Performs the XOR operation element-wise.

Fma

Computes the result of multiplying two inputs and then adding a third input element-wise.

IsNan

Performs element-wise checks to determine whether the input floating-point numbers are NaN.

IsInf

Performs element-wise checks to determine whether the input floating-point numbers are ±INF.

Rint

Obtains the integer closest to the input data.

SinCos

Performs sine and cosine computation element-wise to obtain the sine and cosine results.

LogicalNot

Applies a logical NOT operation element-wise.

LogicalAnd

Performs the AND operation by element.

LogicalAnds

Performs a logical AND operation between each element in an input vector and a scalar.

LogicalOr

Performs the OR operation by element.

LogicalOrs

Performs a logical OR operation between each element in an input vector and a scalar.

LogicalXor

Performs the logical exclusive OR operation by element.

BitwiseNot

Performs a bitwise NOT operation on the input.

BitwiseAnd

Performs a bitwise AND operation on two inputs.

BitwiseOr

Performs a bitwise OR operation on two inputs.

BitwiseXor

Performs a bitwise XOR operation on two inputs.

Where

Selects elements from two source operands based on specified conditions to generate a target operand.

Table 15 Quantization operation APIs

API

Function

AntiQuantize

Performs element-wise fake quantization. For example, apply fake quantization to quantize int8_t to half.

AscendAntiQuant

Performs element-wise fake quantization. For example, apply fake quantization to quantize int8_t to half.

Dequantize

Performs element-wise dequantization. For example, it can dequantize int32_t to half or float.

AscendDequant

Performs dequantization by element. For example, dequantize the int32_t data type to the half/float data type.

Quantize

Performs element-wise quantization. For example, it can quantize half or float into int8_t.

AscendQuant

Performs quantization by element. For example, quantize the half/float data type to the int8_t data type.

Table 16 Normalization operation APIs

API

Function

BatchNorm

Normalizes each input feature of samples in each batch along the batch dimension.

DeepNorm

Serves as a replacement for LayerNorm normalization during the training process of a deep neural network.

GroupNorm

Divides the input C dimension into groups (groupNum) and standardizes each group of data.

LayerNorm

Normalizes the input data of network layers to the [0, 1] range to standardize the distributions of both input and output data across network layers.

LayerNormGrad

Computes the backpropagation gradient of LayerNorm.

LayerNormGradBeta

Obtains the reverse beta/gmma value and outputs pdx, gmma, and beta when used in conjunction with LayerNormGrad.

Normalize

Computes the reciprocal rstd of the standard deviation of the input data with shape [A, R] and the normalized output y based on the known mean value and variance in LayerNorm.

RmsNorm

Normalizes input data whose shape is [B, S, H] using RmsNorm.

WelfordUpdate

Implements preprocessing of the Welford algorithm.

WelfordFinalize

Implements postprocessing of the Welford algorithm.

Table 17 Activation function APIs

API

Function

AdjustSoftMaxRes

Performs postprocessing on SoftMax compute results and adjusts SoftMax compute results to specified values.

FasterGelu

Implements an activation function of the simplified FastGelu version.

FasterGeluV2

Implements an activation function of the FastGeluV2 version.

GeGLU

Serves as a GLU variant that uses GeLU as the activation function.

Gelu

Serves as an important activation function that is inspired by ReLU and dropout. The idea of random regularization is introduced in activation.

LogSoftMax

Performs LogSoftmax computation on the input tensor.

ReGlu

Serves as a GLU variant that uses ReLU as the activation function.

Sigmoid

Performs logistic regression with Sigmoid element-wise.

Silu

Computes Silu element-wise.

SimpleSoftMax

Uses the computed sum and max data to perform softmax computation on the input tensor.

SoftMax

Performs softmax computation on input tensors by row.

SoftmaxFlash

Serves as the enhanced version of SoftMax. It not only performs softmaxflash computation on the input tensor but also updates the result of the current softmax computation based on the sum and max values obtained in the previous softmax computation.

SoftmaxFlashV2

Serves as the enhanced version of SoftmaxFlash, corresponding to the FlashAttention-2 algorithm.

SoftmaxFlashV3

Serves as the enhanced version of SoftmaxFlash, corresponding to the Softmax PASA algorithm.

SoftmaxGrad

Performs gradient backpropagation on input tensors.

SoftmaxGradFront

Performs gradient backpropagation on input tensors.

SwiGLU

Serves as a GLU variant that uses Swish as the activation function.

Swish

Serves as a Swish activation function in neural networks.

Table 18 Reduction APIs

API

Function

Sum

Obtains the sum of elements in the last dimension.

Mean

Computes the mean of elements according to the direction of the last axis.

ReduceXorSum

Performs the XOR (bitwise XOR) operation by element and computes the sum of the results using ReduceSum.

ReduceSum

Accumulates data of a multi-dimensional vector based on a specified dimension.

ReduceMean

Computes the mean of a multi-dimensional vector along a specified dimension.

ReduceMax

Returns the maximum value of a multi-dimensional vector along a specified dimension.

ReduceMin

Returns the minimum value of a multi-dimensional vector along a specified dimension.

ReduceAny

Computes the logical OR of a multi-dimensional vector along a specified dimension.

ReduceAll

Computes the logical AND of a multi-dimensional vector along a specified dimension.

ReduceProd

Computes the product of a multi-dimensional vector along a specified dimension.

Table 19 Sorting operation APIs

API

Function

TopK

Obtains the first k maximum or minimum values of the last dimension and their corresponding indexes.

Concat

Preprocesses the data and merges the source operand srcLocal to be sorted into the target data concatLocal. After the data is preprocessed, you can sort the data.

Extract

Processes the sorting result data and outputs the sorted values and indexes.

Sort

Sorts data in descending order by value.

MrgSort

Merges up to four sorted lists into one. The results are sorted in descending order of the score fields.

Table 20 Data filtering APIs

API

Function

Select

Given two source operands src0 and src1, selects elements based on the values (non-bit) of corresponding positions of maskTensor to obtain the destination operand dst.

DropOut

Provides the function of filtering the source operand based on the mask tensor to obtain the destination operand.

Table 21 Tensor transformation APIs

API

Function

Transpose

Performs data format and reshape operations on the input data.

TransData

Converts the format of the input data to the target format.

Broadcast

Broadcasts the input based on the output shape.

Pad

Pads the two-dimensional tensor (height × width) to 32-bytes alignment in the width direction.

UnPad

Unpads the two-dimensional tensor (height × width) in the width direction.

Fill

Initializes data in the global memory to a specified value.

Table 22 Index computation API

API

Function

Arange

Returns an arithmetic sequence given the start value, difference, and length.

Table 23 Matrix computation API

API

Function

Matmul

Performs matrix multiplications.

Table 24 HCCL communication API

API

Function

HCCL Communication

Orchestrates collective communication tasks on the AI Core.

Table 25 Convolution computation APIs

API

Function

Conv3D

Performs 3D convolution forward matrix computation.

Conv3DBackpropInput

Computes the backpropagation of a 3D convolution to obtain the backpropagated error of the feature map.

Conv3DBackpropFilter

Computes the backpropagation of a 3D convolution to obtain the backpropagated error of the weight.

Table 26 Random function API

API

Function

PhiloxRandom

Generates several random numbers based on the Philox random number generation algorithm after a random number seed is given.

SIMT API

Table 27 Kernel definition API

API

Function

asc_vf_call

Starts a SIMT Vector Function (VF) subtask to launch a specified number of threads for executing the specified SIMT kernel function.

Table 28 Synchronization functions

API

Function

asc_syncthreads

Waits until all threads in the current thread block have reached this function.

asc_threadfence

Ensures the time sequence of write operations when different cores access the same global or shared memory.

asc_threadfence_block

Coordinates the memory operation sequence of threads in the same thread block to ensure that all memory read and write operations before a thread calls asc_threadfence_block () are visible to other threads in the same thread block.

Table 29 Mathematical functions

API

Function

tanf

Obtains the tangent of the input data.

tanhf

Obtains the hyperbolic tangent of the input data.

htanh

Obtains the hyperbolic tangent of the input data.

h2tanh

Obtains the hyperbolic tangent of each element in the input data.

tanpif

Obtains the tangent of the input data multiplied by π.

atanf

Obtains the arc tangent of the input data.

atan2f

Obtains the arc tangent of y/x of the input data.

atanhf

Obtains the inverse hyperbolic tangent of the input data.

expf

Obtains the value of e raised to the power of x.

hexp

Obtains the value of e raised to the power of x.

h2exp

Obtains the value of e raised to the power of each element of x with a given x.

exp2f

Obtains the value of 2 raised to the power of x.

hexp2

Obtains the value of 2 raised to the power of x.

h2exp2

Obtains the value of 2 raised to the power of each element of x with a given x.

exp10f

Obtains the value of 10 raised to the power of x.

hexp10

Obtains the value of 10 raised to the power of x.

h2exp10

Obtains the value of 10 raised to the power of each element of x with a given x.

expm1f

Obtains the value of e raised to the power of x minus 1.

logf

Obtains the logarithm of the input data with base e.

hlog

Obtains the logarithm of the input data with base e.

h2log

Obtains the logarithm of each element in the input data with base e.

log2f

Obtains the logarithm of the input data with base 2.

hlog2

Obtains the logarithm of the input data with base 2.

h2log2

Obtains the logarithm of each element in the input data with base 2.

log10f

Obtains the logarithm of the input data with base 10.

hlog10

Obtains the logarithm of the input data with base 10.

h2log10

Obtains the logarithm of each element in the input data with base 10.

log1pf

Obtains the logarithm of the input data plus 1 with base e.

logbf

Computes the logarithm of the input data with base 2, rounds down the result, and returns it as a floating-point value.

ilogbf

Computes the logarithm of the input data with base 2, rounds down the result, and returns an integer.

cosf

Obtains the cosine of the input data.

hcos

Obtains the cosine of the input data.

h2cos

Obtains the cosine of each element in the input data.

coshf

Obtains the hyperbolic cosine of the input data.

cospif

Obtains the cosine of the input data multiplied by π.

acosf

Obtains the arc cosine of the input data.

acoshf

Obtains the inverse hyperbolic cosine of the input data.

sinf

Obtains the sine of the input data.

hsin

Obtains the sine of the input data.

h2sin

Obtains the sine of each element in the input data.

sinhf

Obtains the hyperbolic sine of the input data.

sinpif

Obtains the sine of the input data multiplied by π.

asinf

Obtains the inverse sine of the input data.

asinhf

Obtains the inverse hyperbolic sine of the input data.

sincosf

Obtains the sine and cosine of the input data.

sincospif

Obtains the sine and cosine of the input data multiplied by π.

frexpf

Converts x to a normalized signed number in the range [1/2, 1) multiplied by an integral power of 2.

ldexpf

Obtains the result of multiplying the input x by 2 raised to the power of exp.

sqrtf

Obtains the square root of the input data x.

hsqrt

Obtains the square root of the input data x.

h2sqrt

Obtains the square root of each element in the input data x.

rsqrtf

Obtains the reciprocal of the square root of the input data x.

hrsqrt

Obtains the reciprocal of the square root of the input data x.

h2rsqrt

Obtains the reciprocal of the square root of each element in the input data x.

hrcp

Obtains the reciprocal of the input data x.

h2rcp

Obtains the reciprocal of each element in the input data x.

hypotf

Obtains the square root of the sum of squares of the input data x and y (x2 + y2).

rhypotf

Obtains the reciprocal of the square root of the sum of squares of the input data x and y (x2 + y2).

powf

Obtains the input data x raised to the power of y.

norm3df

Obtains the square root of the sum of squares of the input data a, b, and c (a2 + b2 + c2).

rnorm3df

Obtains the reciprocal of the square root of the sum of squares of the input data a, b, and c (a2 + b2 + c2).

norm4df

Obtains the square root of the sum of squares of the input data a, b, c, and d (a2 + b2 + c2 + d2).

rnorm4df

Obtains the reciprocal of the square root of the sum of squares of the input data a, b, c, and d (a2 + b2 + c2 + d2).

normf

Obtains the square root of the sum of squares of the first n elements in the input data a (a[0]2 + a[1]2 + ... + a[n-1]2).

rnormf

Obtains the reciprocal of the square root of the sum of squares of the first n elements in the input data a (a[0]2 + a[1]2 + ... + a[n-1]2).

cbrtf

Obtains the cube root of the input data x.

rcbrtf

Obtains the reciprocal of the cube root of the input data x.

erff

Obtains the error function value of the input data.

erfcf

Obtains the complementary error function value of the input data.

erfinvf

Obtains the inverse error function value of the input data.

erfcinvf

Obtains the inverse complementary error function value of the input data.

erfcxf

Obtains the scaled complementary error function value of the input data.

tgammaf

Obtains the gamma function value of the input data x.

lgammaf

Obtains the absolute value of the gamma value of the input data x and calculates the natural logarithm.

cyl_bessel_i0f

Obtains the value of the zeroth-order regular modified cylindrical Bessel function of the input data x.

cyl_bessel_i1f

Obtains the value of the first-order regular modified cylindrical Bessel function of the input data x.

normcdff

Obtains the cumulative distribution function value of the standard normal distribution of the input data x.

normcdfinvf

Obtains the inverse function of the standard normal cumulative distribution of the input data x.

j0f

Obtains the value of the zeroth-order first-type Bessel function j0 of the input data x.

j1f

Obtains the value of the first-order first-type Bessel function j1 of the input data x.

jnf

Obtains the value of the nth-order first-type Bessel function jn of the input data x.

y0f

Obtains the value of the zeroth-order second-type Bessel function y0 of the input data x.

y1f

Obtains the value of the first-order second-type Bessel function y1 of the input data x.

ynf

Obtains the value of the nth-order second-type Bessel function yn of the input data x.

fabsf

Obtains the absolute value of the input data.

__habs

Obtains the absolute value of the input data.

fmaf

Computes the result of x multiplied by y plus z for the input data x, y, and z.

__hfma

Computes the result of x multiplied by y plus z for the input data x, y, and z.

fmaxf

Obtains the maximum value between two inputs.

__hmax

Obtains the maximum value between two inputs.

fminf

Obtains the minimum value between two inputs.

__hmin

Obtains the minimum value between two inputs.

fdimf

Obtains the difference between two inputs. If the difference is less than 0, 0 is returned.

remquof

Obtains the remainder of input x divided by y. The quotient is rounded to the nearest integer. If the floating-point result of x divided by y is exactly halfway between two integers, the quotient is rounded to the even integer. The quotient is then stored in the variable pointed to by the pointer quo.

fmodf

Obtains the remainder of input x divided by y. The quotient is the integer part of the floating-point result of x divided by y.

remainderf

Obtains the remainder of input x divided by y. The quotient is rounded to the nearest integer. If the floating-point result of x divided by y is exactly halfway between two integers, the quotient is rounded to the even integer.

copysignf

Obtains a floating-point number composed of the magnitude of the first input x and the sign of the second input y.

nearbyIntf

Obtains the integer closest to the input floating-point number. If the input floating-point number is exactly halfway between two integers, the even integer is returned.

nextafterf

If y is greater than x, the function returns the next representable floating-point value larger than x, that is, incrementing the least significant bit of the floating-point number's binary representation by one.

If y is less than x, the function returns the next representable floating-point value less than x, that is, decrementing the least significant bit of the floating-point number's binary representation by one.

If y is equal to x, x is returned.

scalbnf

Obtains the product of the input data x and 2 raised to the power of n.

scalblnf

Obtains the product of the input data x and 2 raised to the power of n.

modff

Decomposes the input data into the fractional part and the integer part.

labs

Obtains the absolute value of the input data.

llabs

Obtains the absolute value of the input data.

llmax

Obtains the maximum value between two inputs.

ullmax

Obtains the maximum value between two inputs.

umax

Obtains the maximum value between two inputs.

llmin

Obtains the minimum value between two inputs.

ullmin

Obtains the minimum value between two inputs.

umin

Obtains the minimum value between two inputs.

fdivdef

Obtains the result of dividing two inputs.

signbit

Obtains the sign bit of the input data.

__mulhi

Obtains the upper 32 bits of the product of two int32 inputs, x and y.

__umulhi

Obtains the upper 32 bits of the product of two uint32 inputs, x and y.

__mul64hi

Obtains the upper 64 bits of the product of two int64 inputs, x and y.

__umul64hi

Obtains the upper 64 bits of the product of two uint64 inputs, x and y.

__mul_i32toi64

Computes the product of two 32-bit integer inputs, x and y, and returns a 64-bit result.

__brev

Reverses the bit order of the input data and returns the reversed value.

__clz

Counts the number of consecutive leading zeros in the binary representation of the input data, starting from the most significant bit (MSB).

__ffs

Scans the binary representation of the input data starting from the least significant bit (LSB) and returns the index (1-based) of the first bit set to 1. If no bits are set to 1, it returns 0.

__popc

Counts the number of bits set to 1 in the binary representation of the input data, starting from the MSB to the LSB.

__byte_perm

Combines two 4-byte uint32_t inputs into an 8-byte 64-bit integer. The selector s specifies which 4 bytes to select, and these 4 bytes are concatenated into a uint32_t integer from LSB to MSB.

Table 30 Precision conversion

API

Function

rintf

Returns the integer closest to the input data. If there are two equally close integers, the even one will be returned.

hrint

Returns the integer closest to the input data. If there are two equally close integers, the even one will be returned.

h2rint

Returns the integer closest to each element of the input data. If there are two equally close integers, the even one will be returned.

lrintf

Returns the integer closest to the input data. If there are two equally close integers, the even one will be returned.

llrintf

Returns the integer closest to the input data. If there are two equally close integers, the even one will be returned.

roundf

Rounds off the input data to the nearest integer.

lroundf

Rounds off the input data to the nearest integer.

llroundf

Rounds off the input data to the nearest integer.

floorf

Obtains the largest integer less than or equal to the input data.

hfloor

Obtains the largest integer less than or equal to the input data.

h2floor

Obtains the largest integer less than or equal to each element of the input data.

ceilf

Obtains the smallest integer greater than or equal to the input data.

hceil

Obtains the smallest integer greater than or equal to the input data.

h2ceil

Obtains the smallest integer greater than or equal to each element of the input data.

truncf

Obtains the integer truncated from the floating-point number of the input data.

htrunc

Obtains the integer truncated from the floating-point number of the input data.

h2trunc

Obtains the integer truncated from the floating-point number of each element in the input data.

Table 31 Comparison functions

API

Function

isfinite

Checks whether a floating-point number is finite (not inf or nan).

isnan

Checks whether a floating-point number is nan.

__hisnan

Checks whether a floating-point number is nan.

isinf

Checks whether a floating-point number is infinite.

__hisinf

Checks whether a floating-point number is infinite.

Table 32 Atomic functions

API

Function

asc_atomic_add

Performs an atomic add operation on the data in the Unified Buffer or Global Memory and the specified data, accumulating the specified data into the data in the Unified Buffer or Global Memory.

asc_atomic_sub

Performs an atomic subtract operation on the data in the Unified Buffer or Global Memory and the specified data, subtracting the specified data from the data in the Unified Buffer or Global Memory.

asc_atomic_exch

Performs an atomic assignment operation on the address in the Unified Buffer or Global Memory, assigning the specified data to the address in the Unified Buffer or Global Memory.

asc_atomic_max

Performs an atomic maximum operation on the data in Unified Buffer or Global Memory, assigning the maximum value between the data in Unified Buffer or Global Memory and the specified data to the address in Unified Buffer or Global Memory.

asc_atomic_min

Performs an atomic minimum operation on the data in Unified Buffer or Global Memory, assigning the minimum value between the data in Unified Buffer or Global Memory and the specified data to the address in Unified Buffer or Global Memory.

asc_atomic_inc

Performs an atomic increment operation on the address value in the Unified Buffer or Global Memory. If the address value is greater than or equal to the specified value val, the address value is set to 0. Otherwise, the address value is incremented by 1.

asc_atomic_dec

Performs an atomic decrement operation on the address value in the Unified Buffer or Global Memory. If the address value is 0 or greater than the specified value val, the address value is set to val. Otherwise, the address value is decremented by 1.

asc_atomic_cas

Performs an atomic compare-and-swap operation on the address value in the Unified Buffer or Global Memory. If the address value is equal to the specified value compare, the address value is set to the specified value val. Otherwise, the address value remains unchanged.

asc_atomic_and

Performs an atomic AND (&) operation on the address value in the Unified Buffer or Global Memory and the specified value val, assigning the result to the Unified Buffer or Global Memory.

asc_atomic_or

Performs an atomic OR (|) operation on the address value in the Unified Buffer or Global Memory and the specified value val, assigning the result to the Unified Buffer or Global Memory.

asc_atomic_xor

Performs an atomic XOR (^) operation on the address value in the Unified Buffer or Global Memory and the specified value val, assigning the result to the Unified Buffer or Global Memory.

Table 33 Warp functions

API

Function

asc_all

Checks whether the inputs of all active threads are not 0.

asc_any

Checks whether the input of any active thread is not 0.

asc_ballot

Checks whether the input of each active thread in a warp is not 0.

asc_activemask

Checks whether all threads in a warp are active.

asc_shfl

Obtains the var value input by the specified thread srcLane in a warp for swapping.

asc_shfl_up

Obtains the var value input by the thread that is delta lanes forward from the current thread in the warp (current LaneId – delta) for swapping.

asc_shfl_down

Obtains the var value input by the thread that is delta lanes backward from the current thread in a warp (current LaneId + delta) for swapping.

asc_shfl_xor

Obtains the var value input by the thread corresponding to dstLaneId (obtained by performing an XOR operation on the current LaneId and the input laneMask: LaneId^laneMask) for swapping.

asc_reduce_add

Sums up the val values input by all active threads in a warp.

asc_reduce_max

Computes the maximum value of val input by all active threads in a warp.

asc_reduce_min

Computes the minimum value of val input by all active threads in a warp.

Table 34 Type conversion

API

Function

__float2float_rn

Returns the floating-point number of the input, rounded according to the CAST_RINT mode.

__float2float_rz

Returns the floating-point number of the input, rounded according to the CAST_TRUNC mode.

__float2float_rd

Returns the floating-point number of the input, rounded according to the CAST_FLOOR mode.

__float2float_ru

Returns the floating-point number of the input, rounded according to the CAST_CEIL mode.

__float2float_rna

Returns the floating-point number of the input, rounded according to the CAST_ROUND mode.

__float2half

Returns the half-precision floating-point number converted from the input in line with the CAST_RINT mode.

__float2half_rn

Returns the half-precision floating-point number converted from the input in line with the CAST_RINT mode.

__float2half_rn_sat

In saturation mode, returns the half-precision floating-point number converted from the input in line with the CAST_RINT mode.

__float2half_rz

Returns the half-precision floating-point number converted from the input in line with the CAST_TRUNC mode.

__float2half_rz_sat

In saturation mode, returns the half-precision floating-point number converted from the input in line with the CAST_TRUNC mode.

__float2half_rd

Returns the half-precision floating-point number converted from the input in line with the CAST_FLOOR mode.

__float2half_rd_sat

In saturation mode, returns the half-precision floating-point number converted from the input in line with the CAST_FLOOR mode.

__float2half_ru

Returns the half-precision floating-point number converted from the input in line with the CAST_CEIL mode.

__float2half_ru_sat

In saturation mode, returns the half-precision floating-point number converted from the input in line with the CAST_CEIL mode.

__float2half_rna

Returns the half-precision floating-point number converted from the input in line with the CAST_ROUND mode.

__float2half_rna_sat

In saturation mode, returns the half-precision floating-point number converted from the input in line with the CAST_ROUND mode.

__float2half_ro

Returns the half-precision floating-point number converted from the input in line with the CAST_ODD mode.

__float2half_ro_sat

In saturation mode, returns the half-precision floating-point number converted from the input in line with the CAST_ODD mode.

__float2bfloat16

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__float2bfloat16_rn

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__float2bfloat16_rn_sat

In saturation mode, returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__float2bfloat16_rz

Returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__float2bfloat16_rz_sat

In saturation mode, returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__float2bfloat16_rd

Returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__float2bfloat16_rd_sat

In saturation mode, returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__float2bfloat16_ru

Returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__float2bfloat16_ru_sat

In saturation mode, returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__float2bfloat16_rna

Returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__float2bfloat16_rna_sat

In saturation mode, returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__float2uint_rn

Returns the unsigned integer converted from the input in line with the CAST_RINT mode.

__float2uint_rz

Returns the unsigned integer converted from the input in line with the CAST_TRUNC mode.

__float2uint_rd

Returns the unsigned integer converted from the input in line with the CAST_FLOOR mode.

__float2uint_ru

Returns the unsigned integer converted from the input in line with the CAST_CEIL mode.

__float2uint_rna

Returns the unsigned integer converted from the input in line with the CAST_ROUND mode.

__float2int_rn

Returns the signed integer converted from the input in line with the CAST_RINT mode.

__float2int_rz

Returns the signed integer converted from the input in line with the CAST_TRUNC mode.

__float2int_rd

Returns the signed integer converted from the input in line with the CAST_FLOOR mode.

__float2int_ru

Returns the signed integer converted from the input in line with the CAST_CEIL mode.

__float2int_rna

Returns the signed integer converted from the input in line with the CAST_ROUND mode.

__float2ull_rn

Returns the 64-bit unsigned integer converted from the input in line with the CAST_RINT mode.

__float2ull_rz

Returns the 64-bit unsigned integer converted from the input in line with the CAST_TRUNC mode.

__float2ull_rd

Returns the 64-bit unsigned integer converted from the input in line with the CAST_FLOOR mode.

__float2ull_ru

Returns the 64-bit unsigned integer converted from the input in line with the CAST_CEIL mode.

__float2ull_rna

Returns the 64-bit unsigned integer converted from the input in line with the CAST_ROUND mode.

__float2ll_rn

Returns the 64-bit signed integer converted from the input in line with the CAST_RINT mode.

__float2ll_rz

Returns the 64-bit signed integer converted from the input in line with the CAST_TRUNC mode.

__float2ll_rd

Returns the 64-bit signed integer converted from the input in line with the CAST_FLOOR mode.

__float2ll_ru

Returns the 64-bit signed integer converted from the input in line with the CAST_CEIL mode.

__float2ll_rna

Returns the 64-bit signed integer converted from the input in line with the CAST_ROUND mode.

__float22half2_rn_sat

In saturation mode, returns the half2 data converted from the two input components in line with the CAST_RINT mode.

__float22half2_rz

Returns the half2 data converted from the two input components in line with the CAST_TRUNC mode.

__float22half2_rz_sat

In saturation mode, returns the half2 data converted from the two input components in line with the CAST_TRUNC mode.

__float22half2_rd

Returns the half2 data converted from the two input components in line with the CAST_FLOOR mode.

__float22half2_rd_sat

In saturation mode, returns the half2 data converted from the two input components in line with the CAST_FLOOR mode.

__float22half2_ru

Returns the half2 data converted from the two input components in line with the CAST_CEIL mode.

__float22half2_ru_sat

In saturation mode, returns the half2 data converted from the two input components in line with the CAST_CEIL mode.

__float22half2_rna

Returns the half2 data converted from the two input components in line with the CAST_ROUND mode.

__float22half2_rna_sat

In saturation mode, returns the half2 data converted from the two input components in line with the CAST_ROUND mode.

__float22half2_ro

Returns the half2 data converted from the two input components in line with the CAST_ODD mode.

__float22half2_ro_sat

In saturation mode, returns the half2 data converted from the two input components in line with the CAST_ODD mode.

__float22bfloat162_rn_sat

In saturation mode, returns the bfloat16x2_t data converted from the two input components in line with the CAST_RINT mode.

__float22bfloat162_rz

Returns the bfloat16x2_t data converted from the two input components in line with the CAST_TRUNC mode.

__float22bfloat162_rz_sat

In saturation mode, returns the bfloat16x2_t data converted from the two input components in line with the CAST_TRUNC mode.

__float22bfloat162_rd

Returns the bfloat16x2_t data converted from the two input components in line with the CAST_FLOOR mode.

__float22bfloat162_rd_sat

In saturation mode, returns the bfloat16x2_t data converted from the two input components in line with the CAST_FLOOR mode.

__float22bfloat162_ru

Returns the bfloat16x2_t data converted from the two input components in line with the CAST_CEIL mode.

__float22bfloat162_ru_sat

In saturation mode, returns the bfloat16x2_t data converted from the two input components in line with the CAST_CEIL mode.

__float22bfloat162_rna

Returns the bfloat16x2_t data converted from the two input components in line with the CAST_ROUND mode.

__float22bfloat162_rna_sat

In saturation mode, returns the bfloat16x2_t data converted from the two input components in line with the CAST_ROUND mode.

__float22hif82_rna

Returns the hifloat8x2_t data converted from the two input components in line with the CAST_ROUND mode.

__float22hif82_rna_sat

In saturation mode, returns the hifloat8x2_t data converted from the two input components in line with the CAST_ROUND mode.

__float22hif82_rh

Returns the hifloat8x2_t data converted from the two input components in line with the CAST_HYBRID mode.

__float22hif82_rh_sat

In saturation mode, returns the hifloat8x2_t data converted from the two input components in line with the CAST_HYBRID mode.

__asc_cvt_float2_to_fp8x2

In saturation mode, returns the __asc_fp8x2_storage_t data converted from the two input components based on the specified 8-bit floating-point number type and in line with the CAST_RINT mode.

__half2float

Returns the floating-point number converted from the input.

__half2half_rn

Returns the half data rounded from the input in line with the CAST_RINT mode.

__half2half_rz

Returns the half data rounded from the input in line with the CAST_TRUNC mode.

__half2half_rd

Returns the half data rounded from the input in line with the CAST_FLOOR mode.

__half2half_ru

Returns the half data rounded from the input in line with the CAST_CEIL mode.

__half2half_rna

Returns the half data rounded from the input in line with the CAST_ROUND mode.

__half2bfloat16_rn

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__half2bfloat16_rz

Returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__half2bfloat16_rd

Returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__half2bfloat16_ru

Returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__half2bfloat16_rna

Returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__half2uint_rn

Returns the unsigned integer converted from the input in line with the CAST_RINT mode.

__half2uint_rz

Returns the unsigned integer converted from the input in line with the CAST_TRUNC mode.

__half2uint_rd

Returns the unsigned integer converted from the input in line with the CAST_FLOOR mode.

__half2uint_ru

Returns the unsigned integer converted from the input in line with the CAST_CEIL mode.

__half2uint_rna

Returns the unsigned integer converted from the input in line with the CAST_ROUND mode.

__half2int_rn

Returns the signed integer converted from the input in line with the CAST_RINT mode.

__half2int_rz

Returns the signed integer converted from the input in line with the CAST_TRUNC mode.

__half2int_rd

Returns the signed integer converted from the input in line with the CAST_FLOOR mode.

__half2int_ru

Returns the signed integer converted from the input in line with the CAST_CEIL mode.

__half2int_rna

Returns the signed integer converted from the input in line with the CAST_ROUND mode.

__half2ull_rn

Returns the 64-bit unsigned integer converted from the input in line with the CAST_RINT mode.

__half2ull_rz

Returns the 64-bit unsigned integer converted from the input in line with the CAST_TRUNC mode.

__half2ull_rd

Returns the 64-bit unsigned integer converted from the input in line with the CAST_FLOOR mode.

__half2ull_ru

Returns the 64-bit unsigned integer converted from the input in line with the CAST_CEIL mode.

__half2ull_rna

Returns the 64-bit unsigned integer converted from the input in line with the CAST_ROUND mode.

__half2ll_rn

Returns the 64-bit signed integer converted from the input in line with the CAST_RINT mode.

__half2ll_rz

Returns the 64-bit signed integer converted from the input in line with the CAST_TRUNC mode.

__half2ll_rd

Returns the 64-bit signed integer converted from the input in line with the CAST_FLOOR mode.

__half2ll_ru

Returns the 64-bit signed integer converted from the input in line with the CAST_CEIL mode.

__half2ll_rna

Returns the 64-bit signed integer converted from the input in line with the CAST_ROUND mode.

__half22hif82_rna

Returns the hifloat8x2_t data converted from the two input components in line with the CAST_ROUND mode.

__half22hif82_rna_sat

In saturation mode, returns the hifloat8x2_t data converted from the two input components in line with the CAST_ROUND mode.

__half22hif82_rh

Returns the hifloat8x2_t data converted from the two input components in line with the CAST_HYBRID mode.

__half22hif82_rh_sat

In saturation mode, returns the hifloat8x2_t data converted from the two input components in line with the CAST_HYBRID mode.

__bfloat162half_rn

Returns the half data converted from the input in line with the CAST_RINT mode.

__bfloat162half_rn_sat

In saturation mode, returns the half data converted from the input in line with the CAST_RINT mode.

__bfloat162half_rz

Returns the half data converted from the input in line with the CAST_TRUNC mode.

__bfloat162half_rz_sat

In saturation mode, returns the half data converted from the input in line with the CAST_TRUNC mode.

__bfloat162half_rd

Returns the half data converted from the input in line with the CAST_FLOOR mode.

__bfloat162half_rd_sat

In saturation mode, returns the half data converted from the input in line with the CAST_FLOOR mode.

__bfloat162half_ru

Returns the half data converted from the input in line with the CAST_CEIL mode.

__bfloat162half_ru_sat

In saturation mode, returns the half data converted from the input in line with the CAST_CEIL mode.

__bfloat162half_rna

Returns the half data converted from the input in line with the CAST_ROUND mode.

__bfloat162half_rna_sat

In saturation mode, returns the half data converted from the input in line with the CAST_ROUND mode.

__bfloat162float

Returns the floating-point data converted from the input.

__bfloat162bfloat16_rn

Returns the bfloat16_t data rounded from the input in line with the CAST_RINT mode.

__bfloat162bfloat16_rz

Returns the bfloat16_t data rounded from the input in line with the CAST_TRUNC mode.

__bfloat162bfloat16_rd

Returns the bfloat16_t data rounded from the input in line with the CAST_FLOOR mode.

__bfloat162bfloat16_ru

Returns the bfloat16_t data rounded from the input in line with the CAST_CEIL mode.

__bfloat162bfloat16_rna

Returns the bfloat16_t data rounded from the input in line with the CAST_ROUND mode.

__bfloat162uint_rn

Returns the unsigned integer converted from the input in line with the CAST_RINT mode.

__bfloat162uint_rz

Returns the unsigned integer converted from the input in line with the CAST_TRUNC mode.

__bfloat162uint_rd

Returns the unsigned integer converted from the input in line with the CAST_FLOOR mode.

__bfloat162uint_ru

Returns the unsigned integer converted from the input in line with the CAST_CEIL mode.

__bfloat162uint_rna

Returns the unsigned integer converted from the input in line with the CAST_ROUND mode.

__bfloat162int_rn

Returns the signed integer converted from the input in line with the CAST_RINT mode.

__bfloat162int_rz

Returns the signed integer converted from the input in line with the CAST_TRUNC mode.

__bfloat162int_rd

Returns the signed integer converted from the input in line with the CAST_FLOOR mode.

__bfloat162int_ru

Returns the signed integer converted from the input in line with the CAST_CEIL mode.

__bfloat162int_rna

Returns the signed integer converted from the input in line with the CAST_ROUND mode.

__bfloat162ull_rn

Returns the 64-bit unsigned integer converted from the input in line with the CAST_RINT mode.

__bfloat162ull_rz

Returns the 64-bit unsigned integer converted from the input in line with the CAST_TRUNC mode.

__bfloat162ull_rd

Returns the 64-bit unsigned integer converted from the input in line with the CAST_FLOOR mode.

__bfloat162ull_ru

Returns the 64-bit unsigned integer converted from the input in line with the CAST_CEIL mode.

__bfloat162ull_rna

Returns the 64-bit unsigned integer converted from the input in line with the CAST_ROUND mode.

__bfloat162ll_rn

Returns the 64-bit signed integer converted from the input in line with the CAST_RINT mode.

__bfloat162ll_rz

Returns the 64-bit signed integer converted from the input in line with the CAST_TRUNC mode.

__bfloat162ll_rd

Returns the 64-bit signed integer converted from the input in line with the CAST_FLOOR mode.

__bfloat162ll_ru

Returns the 64-bit signed integer converted from the input in line with the CAST_CEIL mode.

__bfloat162ll_rna

Returns the 64-bit signed integer converted from the input in line with the CAST_ROUND mode.

__uint2float_rn

Returns the floating-point data converted from the input in line with the CAST_RINT mode.

__uint2float_rz

Returns the floating-point data converted from the input in line with the CAST_TRUNC mode.

__uint2float_rd

Returns the floating-point data converted from the input in line with the CAST_FLOOR mode.

__uint2float_ru

Returns the floating-point data converted from the input in line with the CAST_CEIL mode.

__uint2float_rna

Returns the floating-point data converted from the input in line with the CAST_ROUND mode.

__uint2half_rn

Returns the half data converted from the input in line with the CAST_RINT mode.

__uint2half_rn_sat

In saturation mode, returns the half data converted from the input uint32 data in line with the CAST_RINT mode.

__uint2half_rz

Returns the half data converted from the input in line with the CAST_TRUNC mode.

__uint2half_rz_sat

In saturation mode, returns the half data converted from the input uint32 data in line with the CAST_TRUNC mode.

__uint2half_rd

Returns the half data converted from the input in line with the CAST_FLOOR mode.

__uint2half_rd_sat

In saturation mode, returns the half data converted from the input uint32 data in line with the CAST_FLOOR mode.

__uint2half_ru

Returns the half data converted from the input in line with the CAST_CEIL mode.

__uint2half_ru_sat

In saturation mode, returns the half data converted from the input uint32 data in line with the CAST_CEIL mode.

__uint2half_rna

Returns the half data converted from the input in line with the CAST_ROUND mode.

__uint2half_rna_sat

In saturation mode, returns the half data converted from the input uint32 data in line with the CAST_ROUND mode.

__uint2bfloat16_rn

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__uint2bfloat16_rz

Returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__uint2bfloat16_rd

Returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__uint2bfloat16_ru

Returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__uint2bfloat16_rna

Returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__int2float_rn

Returns the floating-point data converted from the input in line with the CAST_RINT mode.

__int2float_rz

Returns the floating-point data converted from the input in line with the CAST_TRUNC mode.

__int2float_rd

Returns the floating-point data converted from the input in line with the CAST_FLOOR mode.

__int2float_ru

Returns the floating-point data converted from the input in line with the CAST_CEIL mode.

__int2float_rna

Returns the floating-point data converted from the input in line with the CAST_ROUND mode.

__int2half_rn

Returns the half data converted from the input in line with the CAST_RINT mode.

__int2half_rn_sat

In saturation mode, returns the half data converted from the input int32 data in line with the CAST_RINT mode.

__int2half_rz

Returns the half data converted from the input in line with the CAST_TRUNC mode.

__int2half_rz_sat

In saturation mode, returns the half data converted from the input int32 data in line with the CAST_TRUNC mode.

__int2half_rd

Returns the half data converted from the input in line with the CAST_FLOOR mode.

__int2half_rd_sat

In saturation mode, returns the half data converted from the input int32 data in line with the CAST_FLOOR mode.

__int2half_ru

Returns the half data converted from the input in line with the CAST_CEIL mode.

__int2half_ru_sat

In saturation mode, returns the half data converted from the input int32 data in line with the CAST_CEIL mode.

__int2half_rna

Returns the half data converted from the input in line with the CAST_ROUND mode.

__int2half_rna_sat

In saturation mode, returns the half data converted from the input int32 data in line with the CAST_ROUND mode.

__int2bfloat16_rn

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__int2bfloat16_rz

Returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__int2bfloat16_rd

Returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__int2bfloat16_ru

Returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__int2bfloat16_rna

Returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__ull2float_rn

Returns the floating-point data converted from the input in line with the CAST_RINT mode.

__ull2float_rz

Returns the floating-point data converted from the input in line with the CAST_TRUNC mode.

__ull2float_rd

Returns the floating-point data converted from the input in line with the CAST_FLOOR mode.

__ull2float_ru

Returns the floating-point data converted from the input in line with the CAST_CEIL mode.

__ull2float_rna

Returns the floating-point data converted from the input in line with the CAST_ROUND mode.

__ull2half_rn

Returns the half data converted from the input in line with the CAST_RINT mode.

__ull2half_rz

Returns the half data converted from the input in line with the CAST_TRUNC mode.

__ull2half_rd

Returns the half data converted from the input in line with the CAST_FLOOR mode.

__ull2half_ru

Returns the half data converted from the input in line with the CAST_CEIL mode.

__ull2half_rna

Returns the half data converted from the input in line with the CAST_ROUND mode.

__ull2bfloat16_rn

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__ull2bfloat16_rz

Returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__ull2bfloat16_rd

Returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__ull2bfloat16_ru

Returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__ull2bfloat16_rna

Returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__ll2float_rn

Returns the floating-point data converted from the input in line with the CAST_RINT mode.

__ll2float_rz

Returns the floating-point data converted from the input in line with the CAST_TRUNC mode.

__ll2float_rd

Returns the floating-point data converted from the input in line with the CAST_FLOOR mode.

__ll2float_ru

Returns the floating-point data converted from the input in line with the CAST_CEIL mode.

__ll2float_rna

Returns the floating-point data converted from the input in line with the CAST_ROUND mode.

__ll2half_rn

Returns the half data converted from the input in line with the CAST_RINT mode.

__ll2half_rz

Returns the half data converted from the input in line with the CAST_TRUNC mode.

__ll2half_rd

Returns the half data converted from the input in line with the CAST_FLOOR mode.

__ll2half_ru

Returns the half data converted from the input in line with the CAST_CEIL mode.

__ll2half_rna

Returns the half data converted from the input in line with the CAST_ROUND mode.

__ll2bfloat16_rn

Returns the bfloat16 data converted from the input in line with the CAST_RINT mode.

__ll2bfloat16_rz

Returns the bfloat16 data converted from the input in line with the CAST_TRUNC mode.

__ll2bfloat16_rd

Returns the bfloat16 data converted from the input in line with the CAST_FLOOR mode.

__ll2bfloat16_ru

Returns the bfloat16 data converted from the input in line with the CAST_CEIL mode.

__ll2bfloat16_rna

Returns the bfloat16 data converted from the input in line with the CAST_ROUND mode.

__hif822float2

Returns the float2 data converted from the input hifloat8x2_t data.

__hif822half2

Returns the half2 data converted from the input hifloat8x2_t data.

__e4m3x22float2

Returns the float2 data converted from the input float8_e4m3x2_t data.

__e5m2x22float2

Returns the float2 data converted from the input float8_e5m2x2_t data.

__float2bfloat162_rn

Converts the float data to the bfloat16 type in line with the CAST_RINT mode, fills both the front and back parts of bfloat16x2, and returns the filled bfloat16x2 data.

__floats2bfloat162_rn

Converts the input data x and y to the bfloat16 type in line with the CAST_RINT mode, fills both the front and back parts of bfloat16x2, and returns the converted bfloat16x2 data.

__float22bfloat162_rn

Converts float2 data to the bfloat16x2 type in line with the CAST_RINT mode and returns the converted bfloat16x2 data.

__bfloat162bfloat162

Fills the input data into the front and rear components of bfloat16x2, and returns the converted bfloat16x2 data.

__halves2bfloat162

Fills the input data into the front and rear components of bfloat16x2 and returns the filled data.

__high2bfloat16

Extracts the high 16 bits of the input bfloat16x2 and returns the result.

__high2bfloat162

Fills the high 16 bits of the input data into bfloat16x2 and returns the result.

__high2float

Converts the high 16 bits of the input data to the float type and returns the result.

__highs2bfloat162

Extracts the high 16 bits from each of the two bfloat162 inputs, fills them into bfloat162, and returns the result.

__low2bfloat16

Returns the low 16 bits of the input data.

__low2bfloat162

Fills the low 16 bits of the input data into bfloat16x2 and returns the result.

__low2float

Converts the low 16 bits of the input data into floating-point data and returns the result.

__lowhigh2highlow

Exchanges the high and low 16 bits of the input data and returns the result.

__lows2bfloat162

Extracts the low 16 bits from each of the two bfloat162 inputs, fills them into bfloat162, and returns the result.

__bfloat1622float2

Converts the two components of bfloat16x2 to float values, fills them into float2, and returns the result.

__floats2half2_rn

Converts the input data x and y to the bfloat16 type in line with the CAST_RINT mode, fills both the front and back parts of half2, and returns the converted half2 data.

__float22half2_rn

Converts float2 data to the half2 type in line with the CAST_RINT mode and returns the converted half2 data.

__low2half

Returns the low 16 bits of the input data.

__low2half2

Fills the low 16 bits of the input data into half2 and returns the result.

__high2half

Extracts the high 16 bits of the input half2 and returns the result.

__high2half2

Fills the high 16 bits of the input data into half2 and returns the result.

__highs2half2

Extracts the high 16 bits from each of the two half2 inputs, fills them into half2, and returns the result.

__lows2half2

Extracts the low 16 bits from each of the two half2 inputs, fills them into half2, and returns the result.

__halves2half2

Fills the input data into the front and rear components of half2 and returns the filled data.

__half22float2

Converts the two components of half2 to float values, fills them into float2, and returns the result.

__int_as_float

Reinterprets the bits in an integer as a floating-point number.

__uint_as_float

Reinterprets the bits in an unsigned integer as a floating-point number.

__float_as_int

Reinterprets the bits in a floating-point number as a signed integer.

__float_as_uint

Reinterprets the bits in a floating-point number as an unsigned integer.

__ushort_as_half

Reinterprets the bits of an unsigned short int as a half-precision floating-point number, reading the stored bits in half format.

__ushort_as_bfloat16

Reinterprets the bits of an unsigned short int as a bfloat16 value, reading the stored bits in bfloat16 format.

Table 35 Vector type constructor functions

API

Function

make_int2

Creates a vector of the int2 type from two given int values.

make_int4

Creates a vector of the int4 type from four given int values.

make_uint2

Creates a vector of the uint2 type from two given unsigned int values.

make_uint4

Creates a vector of the uint4 type from four given unsigned int values.

make_ulonglong2

Creates a vector of the ulonglong2 type from two given unsigned long long int values.

make_ulonglong4

Creates a vector of the ulonglong4 type from four given unsigned long long int values.

make_longlong2

Creates a vector of the longlong2 type from two given long long int values.

make_longlong4

Creates a vector of the longlong4 type from four given long long int values.

make_ulong2

Creates a vector of the ulong2 type from two given unsigned long int values.

make_ulong4

Creates a vector of the ulong4 type from four given unsigned long int values.

make_long2

Creates a vector of the long2 type from two given long int values.

make_long4

Creates a vector of the long4 type from four given long int values.

make_float2

Creates a vector of the float2 type from two given float values.

make_float4

Creates a vector of the float4 type from four given float values.

make_short2

Creates a vector of the short2 type from two given short values.

make_short4

Creates a vector of the short4 type from four given short values.

make_ushort2

Creates a vector of the ushort2 type from two given unsigned short values.

make_ushort4

Creates a vector of the ushort4 type from four given unsigned short values.

make_uchar2

Creates a vector of the uchar2 type from two given unsigned char values.

make_uchar4

Creates a vector of the uchar4 type from four given unsigned char values.

make_char2

Creates a vector of the char2 type from two given signed char values.

make_char4

Creates a vector of the char4 type from four given signed char values.

make_half2

Creates a vector of the half2 type from two given half values.

make_bfloat162

Creates a vector of the bfloat16x2_t type from two given bfloat16_t values.

Table 36 Load/Store functions with cache hints enabled

API

Function

asc_ldcg

Loads cached data from the L2 cache. If the cache hit occurs, the data is returned directly. If the cache miss occurs, the data is preloaded from Global Memory into L2 Cache and then returned.

asc_ldca

First loads cached data from data cache. If cache miss occurs, it attempts to load from L2 cache. If the required data is not found in either data cache or L2 cache, it is fetched from global memory and then cached into both L2 cache and data cache.

asc_stcg

Stores specified data to the address of the global memory and caches the data to the L2 cache, but not to the data cache.

asc_stwt

Stores specified data to the address of the global memory and caches the data to the data cache and L2 cache.

Utils API

Table 37 C++ standard library APIs

API

Function

max

Compares two operands of the same data type and returns the larger value.

min

Compares two operands of the same data type and returns the smaller value.

abs

Obtains the absolute value of the input data.

sqrt

Computes the square root of the input data.

integer_sequence

Generates an integer sequence.

tuple

Stores multiple elements of different types as a container.

get

Extracts elements from the tuple container at a specified position.

make_tuple

Creates a tuple object conveniently.

is_convertible

Determines whether implicit conversion can be performed between two types during program build.

is_base_of

Determines whether a type is a base class of another type during program build.

is_same

Determines whether two types are the same during program build.

is_void

Checks whether a type is the void type during program compilation.

is_integral

Checks whether a type is the integer type during program compilation.

is_floating_point

Checks whether a type is the floating-point type during program compilation.

is_array

Checks whether a type is the array type during program compilation.

is_pointer

Checks whether a type is the pointer type during program compilation.

is_reference

Checks whether a type is the reference type during program compilation.

is_const

Checks whether a type is const-qualified during program compilation.

remove_const

Removes const qualifiers from the input template parameter type during program compilation.

remove_volatile

Removes volatile qualifiers from the input template parameter type during program compilation.

remove_cv

Removes const or volatile qualifiers or removes both simultaneously from the input template parameter type during program compilation.

remove_reference

Removes reference qualifiers from a given type during program compilation.

remove_pointer

Removes pointer qualifiers from a given type during program compilation.

add_const

Adds const qualifiers to a specified type during program compilation.

add_volatile

Adds volatile qualifiers to a specified type during program compilation.

add_cv

Adds const and volatile qualifiers to a specified type during program compilation.

add_pointer

Adds pointer qualifiers to a specified type during program compilation.

add_lvalue_reference

Adds a left-value reference qualifier to a specified type during program compilation.

add_rvalue_reference

Adds a right-value reference qualifier to a specified type during program compilation.

enable_if

Enables or disables a specific function template, class template, or template specialization based on a condition during program build.

conditional

Selects one of two types based on a Boolean condition during program build.

integral_constant

Encapsulates a compile-time constant integer value, which is the fundamental component of many type traits and compile-time computations in the standard library.

Table 38 APIs for obtaining platform information

API

Function

PlatformAscendC

Obtains hardware platform information, such as the number of cores on a hardware platform for tiling computation to implement the tiling function on the host. The PlatformAscendC class provides a function for obtaining such platform information.

PlatformAscendCManager

Obtains hardware platform information, such as the number of cores on the hardware platform, to call operators in the basic mode (kernel launch) based on the kernel launch operator project. The PlatformAscendCManager class provides the function of obtaining platform information.

Table 39 Prototype registration and management APIs

API

Function

Prototype Registration API (OP_ADD)

Registers the prototype definition of an operator.

OpDef

Defines the operator prototype.

OpParamDef

Defines operator parameters.

OpAttrDef

Defines operator attributes.

OpAICoreDef

Defines the implementation information of the AI Processor and associates the tiling implementation and shape inference functions.

OpAICoreConfig

Configures AI Core information.

OpMC2Def

Configures the communication domain name of an MC2 operator on the host. Once the domain is configured, the kernel side can retrieve the corresponding context address associated with that communication domain.

Table 40 APIs for tiling data structure registration

API

Function

TilingData Structure Definition

Defines a TilingData class and adds required member variables (TilingData fields) to store required TilingData parameters. After the TilingData class is defined, this class inherits the TilingDef class (base class for storing and processing user-defined Tiling structure member variables) to provide APIs for setting, serializing, and saving TilingData fields.

TilingData Structure Registration

Registers the defined TilingData structure and binds it with a custom operator.

Table 41 Tiling debugging APIs

API

Function

OpTilingRegistry

The OpTilingRegistry class belongs to the context_ascendc namespace. It is mainly used to load the dynamic library for tiling implementation and obtain the tiling function pointer of the operator for debugging and verification.

ContextBuilder

Provides a series of APIs for you to manually build the TilingContext class to verify the tiling functions and the KernelContext class to verify the TilingParse functions.

Table 42 Tiling template programming APIs

API

Function

Template Argument Definition

Defines the template argument declaration ASCENDC_TPL_ARGS_DECL and the template argument combination ASCENDC_TPL_ARGS_SEL (available template).

GET_TPL_TILING_KEY

Automatically generates a TilingKey during tiling template programming. This API converts the passed template arguments into binary values based on the defined bit width, combines the binary values in sequence, and then converts the values into uint64, that is, TilingKey.

ASCENDC_TPL_SEL_PARAM

Automatically generates and configures a TilingKey during tiling template programming.

Table 43 Tiling offload APIs

API

Function

DEVICE_IMPL_OP_OPTILING

Generates a registration class for tiling offload in the tiling offload scenario, and calls member functions of the registration class to register the tiling functions to be offloaded.

Table 44 RTC APIs

API

Function

aclrtcCompileProg

Compiles a specified program.

aclrtcCreateProg

Creates an instance of the compiler using the given parameters.

aclrtcDestroyProg

Destroys an instance of the compiler.

aclrtcGetBinData

Obtains the compiled binary data.

aclrtcGetBinDataSize

Obtains the size of the compiled binary data. This API is used to allocate memory space when the aclrtcGetBinData API is used to obtain the binary data.

aclrtcGetCompileLogSize

Obtains the size of the compilation log. This API is used to allocate the memory space when the aclrtcGetCompileLog API is used to obtain the log content.

aclrtcGetCompileLog

Obtains the content of the compilation log and saves it as a character string.

Table 45 Log APIs

API

Function

ASC_CPU_LOG

Provides the function of printing logs on the host. You can use the ASC_CPU_LOG_XXX API in the TilingFunc code of the operator to output related content.

Table 46 Debugging APIs

API

Function

printf

In the operator kernel implementation code, call the printf API to print related content when log information needs to be output.

assert

Provides the assert function in SIMT VF debugging scenarios. In the SIMT VF implementation code on the operator kernel side, if the internal assert condition evaluates to false, the condition is output and the input information is formatted and printed to the screen.

__trap

Calling this API in the SIMT VF implementation code will interrupt the operator execution.

clock

Provides the clock timestamp function in the SIMT VF debugging scenario. It records the number of clock cycles (Cycle Count) from program start to the moment of API invocation, enabling precise analysis of execution latency and performance bottlenecks.

AI CPU API

Table 47 AI CPU APIs

API

Function

printf

Provides the formatted output function in the AI CPU operator kernel debugging scenario. The output content is parsed and displayed on the screen by default.

assert

Implements the assert function in the AI CPU operator kernel debugging scenario.