op_common APIs

CANN operator development and calls (regardless of built-in or custom operators) depend on the common capabilities provided by the opbase library (cann/opbase), including the APIs for log obtaining, operator tiling, and InferShape.

  • Key API categories are:
    • log: APIs related to operator logs
    • math: APIs related to mathematical computation
    • platform: platform-related APIs
    • infershape: shape-related APIs
  • Description
    • Positioning: APIs with detailed parameter descriptions are formal APIs and support backward compatibility. Reserved APIs provide only prototype definitions and do not include detailed parameter descriptions. You can skip them for now.
    • Header file: When using the APIs in this section, include the dependent header files as required. The header files are stored in the ${INSTALL_DIR}/include directory. Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.
Table 1 op_common APIs

Category

API

Description

Header File

log

OP_LOGE

Prints operator ERROR logs.

op_common/log/log.h

OP_LOGD

Prints operator DEBUG logs.

OP_LOGI

Prints operator INFO logs.

OP_LOGW

Prints operator WARNING logs.

OP_CHECK_IF

Outputs a log and executes the return expression if the condition is true.

OP_CHECK_NULL_WITH_CONTEXT

Checks if an input pointer is null based on the input context.

OP_LOGE_WITH_INVALID_INPUT_SHAPE

Records and reports an operator input shape error, with error code EZ0001.

OP_LOGE_WITH_INVALID_ATTR

Records and reports an operator attribute value error, with error code EZ0002.

OP_LOGE_WITH_INVALID_ATTR_SIZE

Records and reports an operator attribute size error, with error code EZ0003.

OP_LOGE_WITH_INVALID_INPUT

Records and reports a null input parameter error, with error code EZ0004.

OP_LOGE_WITH_INVALID_INPUT_SHAPESIZE

Records and reports an operator input shape size error, with error code EZ0005.

OP_LOGE_WITH_INVALID_INPUT_FORMAT

Records and reports an input format error, with error code EZ0006.

OP_LOGE_WITH_INVALID_INPUT_DTYPE

Records and reports an input data type error, with error code EZ0007.

OP_LOGE_FOR_INVALID_SHAPE

Records and reports a parameter shape error, with error code EZ0008.

OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON

Records and reports a parameter shape error (with a cause), with error code EZ0009.

OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON

Records and reports a multi-parameter shape error (with a cause), with error code EZ0010.

OP_LOGE_FOR_INVALID_SHAPEDIM

Records and reports a parameter shape dimension error, with error code EZ0011.

OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON

Records and reports a parameter shape dimension error (with a cause), with error code EZ0012.

OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON

Records and reports a multi-parameter shape dimension error (with a cause), with error code EZ0013.

OP_LOGE_FOR_INVALID_SHAPESIZE

Records and reports a parameter shape size error, with error code EZ0014.

OP_LOGE_FOR_INVALID_SHAPESIZE_WITH_REASON

Records and reports a parameter shape size error (with a cause), with error code EZ0015.

OP_LOGE_FOR_INVALID_SHAPESIZES_WITH_REASON

Records and reports a multi-parameter shape size error (with a cause), with error code EZ0016.

OP_LOGE_FOR_INVALID_FORMAT

Records and reports a parameter format error, with error code EZ0017.

OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON

Records and reports a multi-parameter format error (with a cause), with error code EZ0018.

OP_LOGE_FOR_INVALID_DTYPE

Records and reports a parameter data type error, with error code EZ0019.

OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON

Records and reports a parameter data type error (with a cause), with error code EZ0020.

OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON

Records and reports a multi-parameter data type error (with a cause), with error code EZ0021.

OP_LOGE_FOR_INVALID_TENSORNUM

Records and reports a parameter tensor quantity error, with error code EZ0022.

OP_LOGE_FOR_INVALID_TENSORNUMS_WITH_REASON

Records and reports a multi-parameter tensor quantity error (with a cause), with error code EZ0023.

OP_LOGE_FOR_INVALID_VALUE

Records and reports a parameter value error, with error code EZ0024.

OP_LOGE_FOR_INVALID_LISTSIZE

Records and reports a parameter list size error, with error code EZ0025.

OP_LOGE_FOR_INVALID_VALUE_WITH_REASON

Records and reports a parameter value error (with a cause), with error code EZ0026.

OP_LOGE_FOR_INVALID_VALUES_WITH_REASON

Records and reports a multi-parameter value error (with a cause), with error code EZ0027.

OP_LOGE_FOR_INVALID_STRIDE

Records and reports a stride parameter error, with error code EZ0028.

OP_LOGE_FOR_FILE_PATH

Records and reports an invalid file path error, with error code EZ0029.

OP_LOGE_FOR_FILE_OPEN

Records and reports a file opening failure, with error code EZ0030.

OP_LOGE_FOR_FILE_PARSE

Records and reports a file parsing failure, with error code EZ0031.

OP_LOGE_FOR_INVALID_CONFIG

Records and reports an invalid configuration item value error, with error code EZ0032.

OP_LOGE_FOR_INVALID_CONFIG_WITH_REASON

Records and reports an invalid configuration item value error (with a cause), with error code EZ0033.

OP_LOGE_FOR_INVALID_CONFIGS_WITH_REASON

Records and reports a multi-configuration item value error (with a cause), with error code EZ0034.

OP_LOGE_FOR_INVALID_FORMAT_WITH_REASON

Records and reports a parameter format error (with a cause), with error code EZ0035.

OP_LOGE_FOR_INVALID_GRAPH_NODE

Records and reports an invalid graph node error, with error code EZ0036.

OP_LOGE_FOR_INVALID_ARGUMENT_WITH_REASON

Records and reports an invalid parameter error (with a cause), with error code EZ0037.

OP_LOGE_FOR_INVALID_LISTSIZE_WITH_REASON

Records and reports a parameter list size error (with the cause), with error code EZ0038.

math

FloorDiv

Returns the quotient rounded downward to the nearest integer.

op_common/op_host/util/math_util.h

FloorAlign

Aligns downward to the nearest multiple of align.

CeilDiv

Returns the quotient rounded upward to the nearest integer.

CeilAlign

Aligns upward to the nearest multiple of align.

IsFloatEqual

Checks whether two float/double values are equal.

platform

GetAivCoreNum

Obtains the number of AI Vector cores.

op_common/op_host/util/platform_util.h

GetAicCoreNum

Obtains the number of AI Cube cores.

GetUbSize

Obtains the size of the Unified Buffer (UB) on the platform, in bytes.

GetUbBlockSize

Obtains the block size of the Unified Buffer (UB) on the platform, in bytes.

GetVRegSize

Obtains the size of the Vector Register on the platform, in bytes.

GetSimtMaxThreadNum

Obtains the maximum number of SIMT threads on the platform.

GetSimtMaxDCacheSize

Obtains the maximum size of the SIMT DCache on the platform, in bytes.

GetCacheLineSize

Obtains the size of the platform cache line, in bytes.

GetSectorCacheLineSize

Obtains the size of the platform sector cache line, in bytes.

GetNddmaDcacheSize

Obtains the size of the NDDMA DCache on the platform, in bytes.

GetWorkspaceSize

Obtains the size of the LibApi workspace on the platform, in bytes.

infershape

SetUnknownRank

Sets the output shape to a dynamic rank if the input shape rank is unknown.

op_common/op_host/util/shape_util.h

IsUnknownRank

Checks if the input shape rank is unknown.

SetUnknownShape

Sets the input tensor shape to a known rank and marks each dimension length as unknown.

IsUnknownShape

Checks if each dimension length of an input shape is unknown.

InferShape4Broadcast

Infers an output tensor's shape. It is the InferShape for Broadcast operators.

op_common/op_host/infershape_broadcast_util.h

BroadcastShape

Infers the output shape after broadcast based on the input tensor shape.

InferShape4Elewise

Infers an output tensor's shape. It is the InferShape for Elewise operators.

op_common/op_host/infershape_elewise_util.h

InferShape4Reduce

Infers an output tensor's shape. It is the InferShape for Reduce operators.

op_common/op_host/infershape_reduce_util.h

Reserved APIs

-

Reserved. No setup required.

  • op_common/op_host/*.h
  • op_common/op_kernel/*.h