init v0.23.0

Signed-off-by: Sun Ruoxi <sunruoxi@4paradigm.com>
This commit is contained in:
2026-08-27 15:11:51 +08:00
parent b582a8e7d1
commit 7f8a1b1f7a
2849 changed files with 712887 additions and 22001 deletions

View File

@@ -0,0 +1,18 @@
# -----------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
if(BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG)
file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
foreach(SUB_DIR ${CURRENT_DIRS})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
add_subdirectory(${SUB_DIR})
endif()
endforeach()
endif()

View File

@@ -0,0 +1,140 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file stub_ops.h
* \brief
*/
#ifndef MATH_COMMON_STUB_OPS_H
#define MATH_COMMON_STUB_OPS_H
#include "graph/operator_reg.h"
#include "graph/operator.h"
namespace ge {
/**
*@brief Input data for other operators. \n
*@par Inputs:
*x: A tensor. \n
*@par Attributes:
*index: Index of the input tensor.The data type must be int32 or int64.
Assume that net has three data nodes, one should be set 0, another should
be set 1, and the left should be set 2. \n
*@par Outputs:
*y: A tensor. \n
*@par Third-party framework compatibility
*Compatible with the Caffe operator Data.
*/
REG_OP(Data)
.INPUT(x, TensorType::ALL())
.OUTPUT(y, TensorType::ALL())
.ATTR(index, Int, 0)
.OP_END_FACTORY_REG(Data)
/**
*@brief Creates a constant tensor from a tensor-like object. This operator is used for inference.
Operator Const has the same definition as operator Constant. \n
*@par Attributes:
*value: Required. The value and type of the resulting tensor, and no restrictions on type. \n
*@par Outputs:
*y: A constant tensor. \n
*@par Third-party framework compatibility
*Compatible with the TensorFlow operator Const.
*/
REG_OP(Const)
.OUTPUT(y, TensorType::ALL())
.ATTR(value, Tensor, Tensor())
.OP_END_FACTORY_REG(Const)
/**
*@brief Cast a tensor from src data type to dst data type.
*@par Inputs:
*One input:
* x:An ND or 5HD tensor. Support 1D~8D. Must be one of the following types: bool, float16, float, int8, int32, uint32, uint8, bfloat16, uint1,
int64, uint64, int16, uint16, double, complex32, complex64, complex128, qint8, quint8, qint16, quint16, qint32,
hifloat8, float8_e5m2, float8_e4m3fn, float4_e1m2, float4_e2m1.
*@par Attributes:
*dst_type: A required attribute of type int32, specifying the dst data type.
*@par Outputs:
*y:An ND Tensor with same shape as x, and data type is specified by dst_type.
*@attention Constraints:
* @li In the scenario where the data type is converted from float16 to int16: \n
* If the input data contains inf, inf is converted into the maximum value of int16. \n
* If the input data contains -inf, -inf is converted into the minimum value of int16. \n
* @li In the scenarios where the data type is converted from INT32 to INT8: \n
* It can only guarantee that the input data has no precision errors within the range of (-2048, 1920).
* @li Atlas Inference Series Product in the scenarios where the data type is converted from FLOAT32 to INT8: \n
* It can only guarantee that the input data has no precision errors within the range of (-2048, 1920).
* @li Atlas Inference Series Product in the scenarios where the data type is converted from FLOAT32 to INT64 and from FLOAT32 to UINT8: \n
* It can only guarantee that the input data has no precision errors within the range of (-2147483648, 2147483583).
* @li Atlas Inference Series Product in the scenarios where the data type is converted from INT64 to FLOAT32: \n
* It can only guarantee that the input data has no precision errors within the range of (-2147483648, 2147483647).
*/
REG_OP(Cast)
.INPUT(x, TensorType({DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_INT8, DT_INT32, DT_UINT32, DT_UINT8,
DT_INT64, DT_UINT64, DT_INT16, DT_UINT16, DT_DOUBLE, DT_COMPLEX64,
DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32, DT_BF16, DT_UINT1,
DT_COMPLEX32, DT_HIFLOAT8, DT_FLOAT8_E5M2, DT_FLOAT8_E4M3FN,
DT_FLOAT4_E1M2, DT_FLOAT4_E2M1}))
.OUTPUT(y, TensorType({DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_INT8, DT_INT32, DT_UINT32, DT_UINT8,
DT_INT64, DT_UINT64, DT_INT16, DT_UINT16, DT_DOUBLE, DT_COMPLEX64,
DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32,
DT_BF16, DT_COMPLEX32, DT_HIFLOAT8, DT_FLOAT8_E5M2, DT_FLOAT8_E4M3FN,
DT_FLOAT4_E1M2, DT_FLOAT4_E2M1}))
.REQUIRED_ATTR(dst_type, Int)
.OP_END_FACTORY_REG(Cast)
/**
* @brief Creates a tensor filled with a scalar value.
* This operation creates a tensor of shape "dims" and fills it with "value".
*
* @par Inputs:
* @li dims: A 1D tensor of types int32 or int64. Represents the shape of the output tensor .
The size of each dimension must be less than or equal to 8. \n
* @li value: A 0D scalar. Specifies the value to fill the returned tensor.
* Must be one of the following types:
* bfloat16, float16, float32, double, int32, uint8, int16, int8, complex64, int64, bool,
* qint8, quint8, qint32, qint16, quint16, uint16, complex128, uint32, uint64, string.
*
* @par Outputs:
* y: A tensor. Has the same type as "value".
*
* @par Third-party framework compatibility
* @li Compatible with the TensorFlow operator Fill.
* @li Compatible with the Caffe operator Filler.
*
*/
REG_OP(Fill)
.INPUT(dims, TensorType::IndexNumberType())
.INPUT(value, "T")
.OUTPUT(y, "T")
.DATATYPE(T, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16,
DT_INT8, DT_COMPLEX64, DT_INT64, DT_BOOL, DT_QINT8,
DT_QUINT8, DT_QINT32, DT_QINT16, DT_QUINT16, DT_UINT16,
DT_COMPLEX128, DT_FLOAT16, DT_BF16, DT_UINT32, DT_UINT64, DT_STRING}))
.OP_END_FACTORY_REG(Fill)
} // namespace ge
#endif // MATH_COMMON_STUB_OPS_H

View File

@@ -0,0 +1,40 @@
# -----------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
file(GLOB_RECURSE OP_API_FILES "*.cpp")
add_library(opapi_math SHARED ${OP_API_FILES})
target_compile_definitions(opapi_math PRIVATE
_GLIBCXX_USE_CXX11_ABI=0
LOG_CPP
)
target_include_directories(opapi_math PRIVATE
${OPAPI_INCLUDE}
${ASCEND_CANN_PACKAGE_PATH}/pkg_inc
)
if(ENABLE_TEST)
add_library(opapi_stub SHARED ${OP_API_FILES})
target_compile_definitions(opapi_stub PRIVATE
_GLIBCXX_USE_CXX11_ABI=0
LOG_CPP
)
target_include_directories(opapi_stub PRIVATE
${OPAPI_INCLUDE}
${ASCEND_CANN_PACKAGE_PATH}/pkg_inc
${ASCEND_CANN_PACKAGE_PATH}/include/ascendc/basic_api
)
endif()

View File

@@ -0,0 +1,24 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_CAST_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_CAST_H
#include "opdev/op_executor.h"
#include "opdev/make_op_executor.h"
namespace l0op {
const aclTensor* Cast(const aclTensor* self, op::DataType dstDtype, aclOpExecutor* executor);
// 专攻卷积反向定制
const aclTensor* CastOnlyForConvBackward(const aclTensor* self, op::DataType dstDtype, aclOpExecutor* executor);
} // namespace l0op
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_CAST_H

View File

@@ -0,0 +1,251 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_ERROR_CHECK_H__
#define OP_ERROR_CHECK_H__
#include "opdev/op_log.h"
#include "opdev/common_types.h"
#include "opdev/data_type_utils.h"
#include "opdev/shape_utils.h"
const int32_t NCHW_N_DIM = 0;
const int32_t NCHW_C_DIM = 1;
const int32_t NHWC_N_DIM = 0;
const int32_t NHWC_C_DIM = 3;
static inline bool IsNullptr(const aclTensor *tensor, const char *name) {
if (tensor == nullptr) {
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a proper Tensor but got null for argument %s.", name);
return true;
}
return false;
}
static inline bool IsNullptr(const aclTensorList *tensorList, const char *name) {
if (tensorList == nullptr) {
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a proper TensorList but got null for argument %s.", name);
return true;
}
return false;
}
static inline bool IsNullptr(const aclScalar *scalar, const char *name) {
if (scalar == nullptr) {
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a value of type number for argument %s but instead found type null.",
name);
return true;
}
return false;
}
static inline bool IsNullptr(const aclIntArray *intArr, const char *name) {
if (intArr == nullptr) {
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a value of type List[int] for argument %s but instead found type null.",
name);
return true;
}
return false;
}
static inline bool IsNullptr(const aclBoolArray *boolArr, const char *name) {
if (boolArr == nullptr) {
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a value of type List[bool] for argument %s but instead found type null.",
name);
return true;
}
return false;
}
static inline bool IsNullptr(const aclFloatArray *floatArr, const char *name) {
if (floatArr == nullptr) {
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Expected a value of type List[float] for argument %s but instead found type \
null.", name);
return true;
}
return false;
}
static inline bool CheckDims(const aclTensor *tensor) {
const auto& xShape = tensor->GetViewShape();
for(size_t i = 0; i < xShape.GetDimNum(); i++) {
if (xShape.GetDim(i) > INT32_MAX) {
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The tensor's shape cannot be larger than %d.", INT32_MAX);
return false;
}
}
return true;
}
static inline bool CheckReduceOutShape(const aclTensor *inferOut, const aclTensor *out)
{
auto const &xShape = inferOut->GetViewShape();
auto const &yShape = out->GetViewShape();
if (xShape != yShape) {
if (!(xShape.GetShapeSize() == 1 && yShape.GetShapeSize() == 1)) {
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The out tensor's shape[%s] is not equal with inferOut shape[%s].",
op::ToString(out->GetViewShape()).GetString(), op::ToString(inferOut->GetViewShape()).GetString());
return false;
}
}
return true;
}
static inline bool CheckNCDimValid(const aclTensor *self, const aclTensor *out) {
auto format = self->GetStorageFormat();
int64_t selfDimN = 0;
int64_t selfDimC = 0;
int64_t outDimN = 0;
int64_t outDimC = 0;
if (format == op::Format::FORMAT_NCHW) {
selfDimN = self->GetViewShape().GetDim(NCHW_N_DIM);
selfDimC = self->GetViewShape().GetDim(NCHW_C_DIM);
outDimN = out->GetViewShape().GetDim(NCHW_N_DIM);
outDimC = out->GetViewShape().GetDim(NCHW_C_DIM);
} else if (format == op::Format::FORMAT_NHWC) {
selfDimN = self->GetViewShape().GetDim(NHWC_N_DIM);
selfDimC = self->GetViewShape().GetDim(NHWC_C_DIM);
outDimN = out->GetViewShape().GetDim(NHWC_N_DIM);
outDimC = out->GetViewShape().GetDim(NHWC_C_DIM);
} else {
OP_LOGE(ACLNN_ERR_PARAM_INVALID,
"Input and output format only support [NCHW, NHWC] format .");
return false;
}
if ((selfDimN != outDimN) || (selfDimC != outDimC)) {
OP_LOGE(ACLNN_ERR_PARAM_INVALID,
"The selfDimN[%ld]/outDimN[%ld] or selfDimC[%ld]/outDimC[%ld] not equal .",
selfDimN, outDimN, selfDimC, outDimC);
return false;
}
return true;
}
#define OP_CHECK_NULL(param, retExpr) \
if (IsNullptr(param, #param)) { \
retExpr; \
}
#define OP_CHECK_DTYPE_NOT_SUPPORT(tensor, supportList, retExpr) \
if (!CheckType(tensor->GetDataType(), supportList)) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Tensor %s not implemented for %s, should be in dtype support list %s.", \
#tensor, op::ToString(tensor->GetDataType()).GetString(), op::ToString(supportList).GetString()); \
retExpr; \
}
#define OP_CHECK_DTYPE_NOT_MATCH(tensor, expectedDtype, retExpr) \
if (tensor->GetDataType() != expectedDtype) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Tensor %s expected dtype is %s but found %s.", \
#tensor, op::ToString(expectedDtype).GetString(), op::ToString(tensor->GetDataType()).GetString()); \
retExpr; \
}
#define OP_CHECK_DTYPE_NOT_SAME(tensor1, tensor2, retExpr) \
if (tensor1->GetDataType() != tensor2->GetDataType()) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected both tensors to have same dtype, but found %s %s and %s %s.", \
#tensor1, op::ToString(tensor1->GetDataType()).GetString(), \
#tensor2, op::ToString(tensor2->GetDataType()).GetString()); \
retExpr; \
}
#define OP_CHECK_RESULT_DTYPE_CAST_FAILED(dtype, desiredDtype, retExpr); \
if (!CanCast(dtype, desiredDtype)) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Result type %s can't be cast to the desired output type %s.", \
op::ToString(dtype).GetString(), op::ToString(desiredDtype).GetString()); \
retExpr; \
}
#define OP_CHECK_BROADCAST(tensor1, tensor2, retExpr) \
if (!CheckBroadcastShape(tensor1->GetViewShape(), tensor2->GetViewShape())) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size of tensor %s %s.", \
#tensor1, op::ToString(tensor1->GetViewShape()).GetString(), \
#tensor2, op::ToString(tensor2->GetViewShape()).GetString()); \
retExpr; \
}
#define OP_CHECK_BROADCAST_WITH_SHAPE(tensor, shape, retExpr) \
if (!CheckBroadcastShape(tensor->GetViewShape(), shape)) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size %s.", \
#tensor, op::ToString(tensor->GetViewShape()).GetString(), op::ToString(shape).GetString()); \
retExpr; \
}
#define OP_CHECK_BROADCAST_AND_INFER_SHAPE(tensor1, tensor2, retShape, retExpr) \
if (!BroadcastInferShape(tensor1->GetViewShape(), tensor2->GetViewShape(), retShape)) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The size of tensor %s %s must match the size of tensor %s %s.", \
#tensor1, op::ToString(tensor1->GetViewShape()).GetString(), \
#tensor2, op::ToString(tensor2->GetViewShape()).GetString()); \
retExpr; \
}
#define OP_CHECK_SHAPE_NOT_EQUAL(tensor1, tensor2, retExpr) \
if (tensor1->GetViewShape() != tensor2->GetViewShape()) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected tensor for %s to have same size as tensor for %s, but %s does not " \
"equal %s.", #tensor1, #tensor2, op::ToString(tensor1->GetViewShape()).GetString(), \
op::ToString(tensor2->GetViewShape()).GetString()); \
retExpr; \
}
#define OP_CHECK_SHAPE_NOT_EQUAL_WITH_EXPECTED_SIZE(tensor, shape, retExpr) \
if (tensor->GetViewShape() != shape) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected tensor for %s to have same size as %s, but got %s.", \
#tensor, op::ToString(shape).GetString(), op::ToString(tensor->GetViewShape()).GetString()); \
retExpr; \
}
#define OP_CHECK_WRONG_DIMENSION(tensor, expectedDimNum, retExpr) \
if (tensor->GetViewShape().GetDimNum() != expectedDimNum) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Expected %zu dimension input, but got %s with sizes %s.", \
static_cast<size_t>(expectedDimNum), #tensor, op::ToString(tensor->GetViewShape()).GetString()); \
retExpr; \
}
#define OP_CHECK_MAX_DIM(tensor, maxDim, retExpr) \
if (tensor->GetViewShape().GetDimNum() > static_cast<size_t>(maxDim)) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The %s tensor cannot be larger than %zu dimensions.", \
#tensor, static_cast<size_t>(maxDim)); \
retExpr; \
}
#define OP_CHECK_MIN_DIM(tensor, minDim, retExpr) \
if (tensor->GetViewShape().GetDimNum() < static_cast<size_t>(minDim)) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The %s tensor must have at least %zu dimensions.", \
#tensor, static_cast<size_t>(minDim)); \
retExpr; \
}
#define OP_CHECK_COMM_INPUT(workspaceSize, executor) \
if (workspaceSize == nullptr || executor == nullptr) { \
OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "The workspaceSize or executor is nullptr."); \
return ACLNN_ERR_PARAM_NULLPTR; \
}
#define OP_CHECK_ADD_TO_LAUNCHER_LIST_AICORE(cond, retExpr, errMsg, ...) \
if (cond) { \
OP_LOGE(ACLNN_ERR_INNER_STATIC_WORKSPACE_INVALID, errMsg, ##__VA_ARGS__); \
retExpr; \
}
#define OP_CHECK_INFERSHAPE(cond, retExpr, errMsg, ...) \
if (cond) { \
OP_LOGE(ACLNN_ERR_INNER_INFERSHAPE_ERROR, errMsg, ##__VA_ARGS__); \
retExpr; \
}
#define OP_CHECK_TENSORLIST_SIZE_EQUAL(tensorlist1, tensorlist2, retExpr) \
if ((tensorlist1)->Size() != (tensorlist2)->Size()) { \
OP_LOGE(ACLNN_ERR_PARAM_INVALID, \
"The %s tensorlist and %s tensorlist must have the same number of tensors, but got %ld and %ld.", \
#tensorlist1, #tensorlist2, (tensorlist1)->Size(), (tensorlist2)->Size()); \
retExpr; \
}
#endif

View File

@@ -0,0 +1,89 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_CONTIGUOUS_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_CONTIGUOUS_H
#include "opdev/op_def.h"
#include "opdev/common_types.h"
namespace l0op {
typedef struct {
// 每个op::Shape 18ns
int64_t viewOffset;
// Transpose
op::Shape transposeSrcShape;
op::Shape transposeDstShape;
op::FVector<int64_t, op::MAX_DIM_NUM> perm;
// broadcast to
op::Shape broadcastSrcShape;
op::Shape broadcastDstShape;
op::FVector<int64_t, op::MAX_DIM_NUM> shape;
// slice
op::Shape sliceSrcShape;
op::Shape sliceDstShape;
op::FVector<int64_t, op::MAX_DIM_NUM> offset;
op::FVector<int64_t, op::MAX_DIM_NUM> size;
// strided slice
op::Shape stridedsliceSrcShape;
op::Shape stridedsliceDstShape;
op::FVector<int64_t, op::MAX_DIM_NUM> begin;
op::FVector<int64_t, op::MAX_DIM_NUM> end;
op::FVector<int64_t, op::MAX_DIM_NUM> strides;
// optimizer
bool mayBroadcast;
bool mayTranspose;
bool maySlice;
bool mayStridedslice;
} ContiguousParam;
/**
* @brief 将非连续Tensor转换为连续Tensor
* @param x
* @param executor
* @return aclTensor 转换后的tensor
*/
const aclTensor* Contiguous(const aclTensor* x, aclOpExecutor* executor);
/**
* @brief 将连续tensor拷贝到非连续的tensor上
* @param x
* @param y
* @param executor
* @return aclTensor 转换后的tensor
*/
const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor);
/**
* @brief 对Tensor创建一个View要求Tensor满足PickView的条件
* @param x 输入Tensor可以是一整块的非连续Tensor
* @param executor
* @return 输出Shape是一个连续Tensor
*/
const aclTensor* PickViewAsContiguous(const aclTensor* x, aclOpExecutor* executor);
const aclTensor* ReViewToOut(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor);
// ============内部接口=============
bool CanOptimizeContiguous(
const op::Shape& viewShape, const op::Strides& strides, int64_t offset, int64_t storageSize,
ContiguousParam& param);
bool CanOptimizeView(const op::Shape& viewShape, const op::Strides& strides, int64_t offset, ContiguousParam& param);
// ============内部接口=============
} // namespace l0op
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_CONTIGUOUS_H

View File

@@ -0,0 +1,20 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_PAD_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_PAD_H
#include "opdev/op_executor.h"
#include "opdev/make_op_executor.h"
namespace l0op {
const aclTensor* Pad(const aclTensor* self, const aclTensor* paddings, aclOpExecutor* executor);
}
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_PAD_H

View File

@@ -0,0 +1,37 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_RESHAPE_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_RESHAPE_H
#include "opdev/shape_utils.h"
#include "opdev/op_def.h"
namespace l0op {
/**
* @brief Modify input tensor's shape.
* @param x Input Tensor. Should be contiguous.
* @param shape Target Shape. Only one dimension can be -1.
* @param executor aclOpExecutor.ldd
* @return *aclTensor Output tensor.
*/
const aclTensor* Reshape(const aclTensor* x, const op::Shape& shape, aclOpExecutor* executor);
/**
* @brief Modify input tensor's shape.
* @param x Input Tensor. Should be contiguous.
* @param shape Target Shape. Only one dimension can be -1.
* @param executor aclOpExecutor.
* @return *aclTensor Output tensor.
*/
const aclTensor* Reshape(const aclTensor* x, const aclIntArray* shape, aclOpExecutor* executor);
} // namespace l0op
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_RESHAPE_H

View File

@@ -0,0 +1,25 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_SLICE_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_SLICE_H
#include "opdev/op_def.h"
namespace l0op {
const aclTensor* Slice(
const aclTensor* x, const aclTensor* y, const aclTensor* offset, const aclTensor* size, aclOpExecutor* executor);
const aclTensor* Slice(
const aclTensor* x, const aclIntArray* offsets, const aclIntArray* size, aclOpExecutor* executor);
} // namespace l0op
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_SLICE_H

View File

@@ -0,0 +1,56 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_TRANSDATA_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_TRANSDATA_H
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* ReFormat(const aclTensor* x, const op::Format& format, aclOpExecutor* executor = nullptr);
/**
* TransData
* Formal Transdata. Set the c0 size strictly based on the data type and chip block size.
* support data type as follows: fp16,fp32,int32,uint32,int8,uint8
* fp16: block_size/2
* fp32/int32/uint32: block_size/4 (this is different from `TransDataSpecial`)
* int8/uint8: block_size/1
*
* @param x : aclTensor need to transpose
* @param dstPrimaryFormat: dstPrimaryFormat like NC1HWC0
* @param groups: groups
* @param executor: executor should not be null
* @return trans format tensor
*/
const aclTensor* TransData(const aclTensor* x, op::Format dstPrimaryFormat, int64_t groups, aclOpExecutor* executor);
/**
* Special Transdata. Set the c0 size strictly based on the data type and chip block size.
* this transdata c0 size rule:
* fp16: block_size/2
* fp32/int32/uint32: block_size/2
* int8/uint8: block_size/1
* bool not supported, should do:
* (NCHW, bool)-> cast -> (NCHW, fp16) -> TransDataSpecial -> (5HD, fp16) -> cast -> (5HD, bool)
* (5HD, bool)-> cast -> (5HD, fp16) -> TransDataSpecial -> (NCHW, fp16) -> cast -> (NCHW, bool)
*
* @param x : aclTensor need to transpose
* @param dstPrimaryFormat: dstPrimaryFormat like NC1HWC0
* @param groups: groups
* @param executor: executor should not be null
* @return trans format tensor
*/
const aclTensor* TransDataSpecial(
const aclTensor* x, op::Format dstPrimaryFormat, int64_t groups, aclOpExecutor* executor);
} // namespace l0op
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_TRANSDATA_H

View File

@@ -0,0 +1,22 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_TRANSPOSE_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_TRANSPOSE_H
#include "opdev/op_def.h"
namespace l0op {
const aclTensor* Transpose(const aclTensor* x, const aclTensor* y, const aclTensor* perm, aclOpExecutor* executor);
const aclTensor* Transpose(const aclTensor* x, const aclIntArray* perm, aclOpExecutor* executor);
} // namespace l0op
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_TRANSPOSE_H

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file add.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_ADD_OP_H_
#define OP_API_INC_LEVEL0_OP_ADD_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* Add(const aclTensor* self, const aclTensor* other, aclOpExecutor* executor);
}
#endif // OP_API_INC_LEVEL0_OP_ADD_OP_H_

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file arange.h
* \brief
*/
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_ARANGE_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_ARANGE_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* Arange(const aclScalar* start, const aclScalar* end, const aclScalar* step, const aclTensor* out,
const bool isClosed, aclOpExecutor* executor);
}
#endif

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file axpy.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_AXPY_OP_H_
#define OP_API_INC_LEVEL0_OP_AXPY_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* Axpy(const aclTensor* self, const aclTensor* other, float alpha, aclOpExecutor* executor);
}
#endif // OP_API_INC_LEVEL0_OP_AXPY_OP_H_

View File

@@ -0,0 +1,45 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_BATCH_NORM_GRAD_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_BATCH_NORM_GRAD_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const std::array<aclTensor*, 2> BNTrainingUpdateGrad(const aclTensor* gradOut, const aclTensor* x,
const aclTensor* saveMean, const aclTensor* saveInvstd, float eps,
aclOpExecutor* executor);
const std::array<aclTensor*, 2> BN3DTrainingUpdateGrad(const aclTensor* gradOut, const aclTensor* x,
const aclTensor* saveMean, const aclTensor* saveInvstd,
float eps, aclOpExecutor* executor);
const aclTensor* BNTrainingReduceGrad(const aclTensor* gradOut, const aclTensor* x, const aclTensor* gradWeight,
const aclTensor* gradBias, const aclTensor* weight, const aclTensor* saveMean,
const aclTensor* saveInvstd, float eps, aclOpExecutor* executor);
const aclTensor* BN3DTrainingReduceGrad(const aclTensor* gradOut, const aclTensor* x, const aclTensor* gradWeight,
const aclTensor* gradBias, const aclTensor* weight, const aclTensor* saveMean,
const aclTensor* saveInvstd, float eps, aclOpExecutor* executor);
const aclTensor* BNInferGrad(const aclTensor* gradOut, const aclTensor* weight, const aclTensor* runningVar, float eps,
aclOpExecutor* executor);
constexpr size_t BN_GRAD_V3_OUTPUT_NUM = 3;
const std::array<aclTensor*, BN_GRAD_V3_OUTPUT_NUM> BatchNormGradV3(const aclTensor* gradOut,
const aclTensor* input,
const aclTensor* weight,
const aclTensor* runningMean,
const aclTensor* runningVar,
const aclTensor* saveMean,
const aclTensor* saveInvstd,
bool training, float eps,
aclOpExecutor* executor);
} // namespace l0op
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_BATCH_NORM_GRAD_OP_H_

View File

@@ -0,0 +1,28 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file broadcast_to.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_BROADCAST_TO_H
#define OP_API_INC_LEVEL0_BROADCAST_TO_H
# include "opdev/op_def.h"
namespace l0op {
const aclTensor *BroadcastTo(const aclTensor *x, const aclTensor *y, const aclTensor *shape, aclOpExecutor *executor);
const aclTensor *BroadcastTo(const aclTensor *x, const aclIntArray *shape, aclOpExecutor *executor);
} // l0op
#endif // OP_API_INC_LEVEL0_BROADCAST_TO_H

View File

@@ -0,0 +1,21 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_API_OP_API_COMMON_INC_LEVEL0_OP_DILATION_OP_H_
#define OP_API_OP_API_COMMON_INC_LEVEL0_OP_DILATION_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
// Dilation
const aclTensor *Dilation(const aclTensor *x, const aclIntArray *dilations, const aclIntArray *pads,
float paddingValue, aclOpExecutor *executor);
} // namespace l0op
#endif // OP_API_OP_API_COMMON_INC_LEVEL0_OP_DILATION_OP_H_

View File

@@ -0,0 +1,20 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_DIV_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_DIV_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *Div(const aclTensor *self, const aclTensor *other, aclOpExecutor *executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_ADD_OP_H_

View File

@@ -0,0 +1,27 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file dot.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_DOT_H_
#define OP_API_INC_LEVEL0_DOT_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *Dot(const aclTensor *self, const aclTensor *tensor, aclOpExecutor *executor);
}
#endif // OP_API_INC_LEVEL0_DOT_H_

View File

@@ -0,0 +1,25 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file expand.h
* \brief
*/
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_EXPAND_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_EXPAND_OP_H_
#include "opdev/op_executor.h"
#include "opdev/make_op_executor.h"
namespace l0op {
const aclTensor *Expand(const aclTensor *self, const aclIntArray *shape, aclOpExecutor *executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_EXPAND_OP_H_

View File

@@ -0,0 +1,20 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_API_INC_LEVEL0_FAULT_INJECTION_H_
#define OP_API_INC_LEVEL0_FAULT_INJECTION_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* FaultInjection(const aclTensor *injectObj, const aclTensor *injectPara, aclTensor *out, aclOpExecutor *executor);
} // namespace l0op
#endif // OP_API_INC_LEVEL0_FAULT_INJECTION_H_

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file fill.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_FILL_OP_H_
#define OP_API_INC_LEVEL0_OP_FILL_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *Fill(const aclTensor *dims, const aclTensor *value, const aclIntArray *outShape,
aclOpExecutor *executor);
}
#endif

View File

@@ -0,0 +1,27 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file gather_elements.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_GATHER_ELEMENTS_H_
#define OP_API_INC_LEVEL0_OP_GATHER_ELEMENTS_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *GatherElements(const aclTensor *self,
const int64_t dim,
const aclTensor *index,
aclOpExecutor *executor);
} // l0op
#endif // OP_API_INC_LEVEL0_OP_GATHER_ELEMENTS_H_

View File

@@ -0,0 +1,25 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_API_INC_LEVEL0_OP_GATHER_V2_H_
#define OP_API_INC_LEVEL0_OP_GATHER_V2_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *GatherV2(const aclTensor *self, int64_t axis, const aclTensor *indices, aclOpExecutor *executor,
int batchDims = 0, bool negativeIndexSupport = false);
const aclTensor *GatherV2WithImplMode(const aclTensor *self, int64_t axis, const aclTensor *indices, int64_t implMode,
aclOpExecutor *executor, int batchDims = 0, bool negativeIndexSupport = false);
}
#endif // OP_API_INC_LEVEL0_OP_GATHER_V2_H_

View File

@@ -0,0 +1,23 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef COMMON_INC_EXTERNAL_ACLNN_KERNELS_GATHER_V3_H
#define COMMON_INC_EXTERNAL_ACLNN_KERNELS_GATHER_V3_H
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *GatherV3(const aclTensor *self, int64_t axis, const aclTensor *indices, aclOpExecutor *executor,
int batchDims = 0, bool negativeIndexSupport = false);
}
#endif // COMMON_INC_EXTERNAL_ACLNN_KERNELS_GATHER_V3_H

View File

@@ -0,0 +1,34 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file inplace_index_add.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_INDEX_ADD_H_
#define OP_API_INC_LEVEL0_OP_INDEX_ADD_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *InplaceIndexAddAiCore(const aclTensor *self, const int64_t dim, const aclTensor *index,
const aclTensor *source, const aclTensor *alphaTensor,
aclOpExecutor *executor);
const aclTensor *InplaceIndexAddAiCpu(const aclTensor *self, const int64_t dim, const aclTensor *index,
const aclTensor *source, const aclTensor *alphaTensor,
aclOpExecutor *executor);
const aclTensor *InplaceIndexAddWithSorted(const aclTensor *self, const int64_t dim, const aclTensor *sortedIndices,
const aclTensor *pos, const aclTensor *value, const aclTensor *alphaTensor,
aclOpExecutor *executor);
}
#endif

View File

@@ -0,0 +1,25 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file masked_scatter.h
* \brief
*/
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_MASKED_SCATTER_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_MASKED_SCATTER_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* MaskedScatter(const aclTensor* self, const aclTensor* mask, const aclTensor* source,
aclOpExecutor* executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_MASKED_SCATTER_OP_H_

View File

@@ -0,0 +1,22 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_MATMUL_V2TOV3_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_MATMUL_V2TOV3_H_
#include "opdev/op_executor.h"
namespace l0op {
bool MmCheckHitV3Shape(const aclTensor* x1, const aclTensor* x2, const aclTensor* bias,
const bool transposeX1, const bool transposeX2, op::Format mat2_format, bool supportSplitK);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_MATMUL_V2TOV3_H_

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file maximum.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_MAXIMUM_OP_H_
#define OP_API_INC_LEVEL0_OP_MAXIMUM_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* Maximum(const aclTensor* self, const aclTensor* other, aclOpExecutor* executor);
}
#endif // OP_API_INC_LEVEL0_OP_MAXIMUM_OP_H_

View File

@@ -0,0 +1,25 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file minimum.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_OP_MINIMUM_OP_H_
#define OP_API_INC_LEVEL0_OP_MINIMUM_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* Minimum(const aclTensor* self, const aclTensor* other, aclOpExecutor* executor);
}
#endif // OP_API_INC_LEVEL0_OP_MINIMUM_OP_H_

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file mul.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_MUL_H_
#define OP_API_INC_LEVEL0_MUL_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *Mul(const aclTensor *self, const aclTensor *other, aclOpExecutor *executor);
}
#endif // OP_API_INC_LEVEL0_MUL_H_

View File

@@ -0,0 +1,28 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file muls.h
* \brief
*/
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_MULS_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_MULS_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *Muls(const aclTensor *self,
float alpha,
aclOpExecutor *executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_MULS_OP_H_

View File

@@ -0,0 +1,27 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_ONES_LIKE_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_ONES_LIKE_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
static const std::initializer_list<op::DataType> AICPU_DTYPE_SUPPORT_LIST = {
op::DataType::DT_BOOL, op::DataType::DT_FLOAT, op::DataType::DT_FLOAT16, op::DataType::DT_INT8,
op::DataType::DT_INT16, op::DataType::DT_UINT16, op::DataType::DT_UINT8, op::DataType::DT_INT32,
op::DataType::DT_INT64, op::DataType::DT_DOUBLE, op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128,
op::DataType::DT_BF16};
const aclTensor *OnesLike(const aclTensor *self, aclOpExecutor *executor);
inline static bool IsAiCpuSupport(const aclTensor *self) {
return op::CheckType(self->GetDataType(), AICPU_DTYPE_SUPPORT_LIST);
}
} // namespace l0op
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_ONES_LIKE_OP_H_

View File

@@ -0,0 +1,25 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file padv3.h
* \brief
*/
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_PADV3_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_PADV3_OP_H_
#include "opdev/op_executor.h"
#include "opdev/make_op_executor.h"
namespace l0op {
const aclTensor *PadV3(const aclTensor *self, const aclTensor *paddings, const aclTensor *constant_values,
const std::string& mode, const bool paddingsContiguous, aclOpExecutor *executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_PADV3_OP_H_

View File

@@ -0,0 +1,21 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_API_INC_LEVEL0_REDUCE_MEAN_H
#define OP_API_INC_LEVEL0_REDUCE_MEAN_H
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor* ReduceMean(const aclTensor* self, const aclIntArray* dim, bool keepDim, aclOpExecutor* executor);
const aclTensor* ReduceMean(
const aclTensor* self, const aclIntArray* dim, bool keepDim, bool noopWithEmptyAxes, aclOpExecutor* executor);
} // namespace l0op
#endif

View File

@@ -0,0 +1,27 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file padv3.h
* \brief
*/
#ifndef OP_API_OP_API_COMMON_INC_LEVEL0_OP_REDUCE_SUM_OP_H_
#define OP_API_OP_API_COMMON_INC_LEVEL0_OP_REDUCE_SUM_OP_H_
#include "opdev/op_executor.h"
#include "opdev/make_op_executor.h"
namespace l0op {
const aclTensor *ReduceSumOp(const aclTensor *x, const aclIntArray *axes,
bool keep_dims, aclOpExecutor *executor);
}
#endif // OP_API_OP_API_COMMON_INC_LEVEL0_OP_REDUCE_SUM_OP_H_

View File

@@ -0,0 +1,18 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_API_INC_LEVEL0_SHAPE_OP_H
#define OP_API_INC_LEVEL0_SHAPE_OP_H
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *Shape_op(const aclTensor *x, aclOpExecutor *executor);
}
#endif

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file sort.h
* \brief
*/
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_SORT_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_SORT_OP_H_
#include "opdev/op_executor.h"
#include "opdev/fast_vector.h"
namespace l0op {
const std::tuple<aclTensor*, aclTensor*> Sort(const aclTensor* self, int64_t dim, bool descending, bool stable,
op::DataType indicesType, aclOpExecutor* executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_SORT_OP_H_

View File

@@ -0,0 +1,24 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef OP_API_INC_LEVEL0_SQUEEZE_ND_H
#define OP_API_INC_LEVEL0_SQUEEZE_ND_H
# include "opdev/op_def.h"
namespace l0op {
const aclTensor *SqueezeNd(const aclTensor *x, const aclIntArray* dim, aclOpExecutor *executor);
const aclTensor *SqueezeNd(const aclTensor *x, int64_t dim, aclOpExecutor *executor);
} // l0op
#endif // OP_API_INC_LEVEL0_SQUEEZE_ND_H

View File

@@ -0,0 +1,21 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_SUB_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_SUB_OP_H_
#include "opdev/op_executor.h"
#include "opdev/make_op_executor.h"
namespace l0op {
const aclTensor *Sub(const aclTensor *self, const aclTensor *other, aclOpExecutor *executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_SUB_OP_H_

View File

@@ -0,0 +1,26 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file tensor_move.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_TENSOR_MOVE_H
#define OP_API_INC_LEVEL0_TENSOR_MOVE_H
# include "opdev/op_def.h"
namespace l0op {
const aclTensor *TensorMove(const aclTensor *x, const aclTensor *y, aclOpExecutor *executor);
} // l0op
#endif // OP_API_INC_LEVEL0_TENSOR_MOVE_H

View File

@@ -0,0 +1,29 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file unsqueeze.h
* \brief
*/
#ifndef OP_API_INC_LEVEL0_UNSQUEEZE_ND_H
#define OP_API_INC_LEVEL0_UNSQUEEZE_ND_H
# include "opdev/op_def.h"
namespace l0op {
const aclTensor *UnsqueezeNd(const aclTensor *x, const aclIntArray* dim, aclOpExecutor *executor);
const aclTensor *UnsqueezeNd(const aclTensor *x, int64_t dim, aclOpExecutor *executor);
} // l0op
#endif // OP_API_INC_LEVEL0_UNSQUEEZE_ND_H

View File

@@ -0,0 +1,20 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef PTA_NPU_OP_API_INC_LEVEL0_OP_ZERO_OP_H_
#define PTA_NPU_OP_API_INC_LEVEL0_OP_ZERO_OP_H_
#include "opdev/op_executor.h"
namespace l0op {
const aclTensor *ZerosLike(const aclTensor *self, aclOpExecutor *executor);
}
#endif // PTA_NPU_OP_API_INC_LEVEL0_OP_ZERO_OP_H_

View File

@@ -0,0 +1,303 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file op_legacy_api.cpp
* \brief
*/
#include "opdev/op_executor.h"
#include "aclnn_kernels/cast.h"
#include "aclnn_kernels/contiguous.h"
#include "aclnn_kernels/pad.h"
#include "aclnn_kernels/reshape.h"
#include "aclnn_kernels/slice.h"
#include "aclnn_kernels/transdata.h"
#include "aclnn_kernels/transpose.h"
#include "level0/add.h"
#include "level0/axpy.h"
#include "level0/broadcast_to.h"
#include "level0/dot.h"
#include "level0/fill.h"
#include "level0/mul.h"
#include "level0/muls.h"
#include "level0/reduce_mean.h"
#include "level0/padv3.h"
#include "level0/sort.h"
#include "level0/dilation.h"
#include "level0/zero_op.h"
#include "level0/squeeze.h"
#include "level0/unsqueeze.h"
namespace l0op {
const aclTensor *TensorMove(const aclTensor *x, const aclTensor * /*y*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *ZerosLike(const aclTensor *self, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Maximum(const aclTensor *self, const aclTensor * /*other*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *GatherV2(const aclTensor *self, int64_t /*axis*/, const aclTensor * /*indices*/,
aclOpExecutor * /*executor*/, int /*batchDims = 0*/, bool /*negativeIndexSupport = false*/)
{
return self;
}
const aclTensor *GatherV2WithImplMode(const aclTensor *self, int64_t /*axis*/, const aclTensor * /*indices*/,
int64_t /*implMode*/, aclOpExecutor * /*executor*/, int /*batchDims = 0*/,
bool /*negativeIndexSupport = false*/)
{
return self;
}
const aclTensor *GatherElements(const aclTensor *self, const int64_t /*dim*/, const aclTensor * /*index*/,
aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Minimum(const aclTensor *self, const aclTensor * /*other*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Cast(const aclTensor *self, op::DataType /*dstDtype*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *CastOnlyForConvBackward(const aclTensor *self, op::DataType /*dstDtype*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Contiguous(const aclTensor *x, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *ViewCopy(const aclTensor *x, const aclTensor * /*y*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *PickViewAsContiguous(const aclTensor *x, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *ReViewToOut(const aclTensor *x, const aclTensor * /*y*/, aclOpExecutor * /*executor*/)
{
return x;
}
const std::tuple<aclTensor *, aclTensor *> Sort(const aclTensor * self, int64_t /*dim*/, bool /*descending*/,
bool /*stable*/, op::DataType /*indicesType*/,
aclOpExecutor * /*executor*/)
{
return std::tuple<aclTensor *, aclTensor *>(const_cast<aclTensor *>(self), const_cast<aclTensor *>(self));
}
bool CanOptimizeContiguous(const op::Shape & /*viewShape*/, const op::Strides & /*strides*/, int64_t /*offset*/,
int64_t /*storageSize*/, ContiguousParam & /*param*/)
{
return true;
}
bool CanOptimizeView(const op::Shape & /*viewShape*/, const op::Strides & /*strides*/, int64_t /*offset*/,
ContiguousParam & /*param*/)
{
return true;
}
const aclTensor *Pad(const aclTensor *self, const aclTensor * /*paddings*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Reshape(const aclTensor *x, const op::Shape & /*shape*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Reshape(const aclTensor *x, const aclIntArray * /*shape*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Slice(const aclTensor *x, const aclTensor * /*y*/, const aclTensor * /*offset*/,
const aclTensor * /*size*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Slice(const aclTensor *x, const aclIntArray * /*offsets*/, const aclIntArray * /*size*/,
aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *ReFormat(const aclTensor *x, const op::Format & /*format*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *TransData(const aclTensor *x, op::Format /*dstPrimaryFormat*/, int64_t /*groups*/,
aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *TransDataSpecial(const aclTensor *x, op::Format /*dstPrimaryFormat*/, int64_t /*groups*/,
aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Transpose(const aclTensor *x, const aclTensor * /*y*/, const aclTensor * /*perm*/,
aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Transpose(const aclTensor *x, const aclIntArray * /*perm*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Add(const aclTensor *self, const aclTensor * /*other*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Axpy(const aclTensor *self, const aclTensor * /*other*/, float /*alpha*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *BroadcastTo(const aclTensor *x, const aclTensor * /*y*/, const aclTensor * /*shape*/,
aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *BroadcastTo(const aclTensor *x, const aclIntArray * /*shape*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Dot(const aclTensor *self, const aclTensor * /*tensor*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Fill(const aclTensor * /*dims*/, const aclTensor *value, const aclIntArray * /*outShape*/,
aclOpExecutor * /*executor*/)
{
return value;
}
const aclTensor *Mul(const aclTensor *self, const aclTensor * /*other*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Muls(const aclTensor *self, float /*alpha*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *ReduceMean(const aclTensor *self, const aclIntArray * /*dim*/, bool /*keepDim*/,
aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *ReduceMean(const aclTensor *self, const aclIntArray * /*dim*/, bool /*keepDim*/,
bool /*noopWithEmptyAxes*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *Dilation(const aclTensor *x, const aclIntArray * /*dilations*/, const aclIntArray * /*pads*/,
float /*paddingValue*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *Shape_op(const aclTensor *x, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *SqueezeNd(const aclTensor *x, const aclIntArray * /*dim*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *SqueezeNd(const aclTensor *x, int64_t /*dim*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *PadV3(const aclTensor *self, const aclTensor * /*paddings*/, const aclTensor * /*constant_values*/,
const std::string & /*mode*/, const bool /*paddingsContiguous*/, aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *UnsqueezeNd(const aclTensor *x, const aclIntArray * /*dim*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *UnsqueezeNd(const aclTensor *x, int64_t /*dim*/, aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *ReduceSumOp(const aclTensor *x, const aclIntArray * /*axes*/, bool /*keep_dims*/,
aclOpExecutor * /*executor*/)
{
return x;
}
const aclTensor *MaskedScatter(const aclTensor * self, const aclTensor * /*mask*/, const aclTensor * /*source*/,
aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *InplaceIndexAddAiCore(const aclTensor * self, const int64_t /*dim*/, const aclTensor * /*index*/,
const aclTensor * /*source*/, const aclTensor * /*alphaTensor*/,
aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *InplaceIndexAddAiCpu(const aclTensor * self, const int64_t /*dim*/, const aclTensor * /*index*/,
const aclTensor * /*source*/, const aclTensor * /*alphaTensor*/,
aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *InplaceIndexAddWithSorted(const aclTensor * self, const int64_t /*dim*/,
const aclTensor * /*sortedIndices*/, const aclTensor * /*pos*/,
const aclTensor * /*value*/, const aclTensor * /*alphaTensor*/,
aclOpExecutor * /*executor*/)
{
return self;
}
const aclTensor *GatherV3(const aclTensor *self, int64_t axis, const aclTensor *indices, aclOpExecutor *executor,
int batchDims = 0, bool negativeIndexSupport = false)
{
(void)self;
(void)axis;
(void)indices;
(void)executor;
(void)batchDims;
(void)negativeIndexSupport;
return self;
}
} // namespace l0op

View File

@@ -0,0 +1,30 @@
# -----------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
file(GLOB_RECURSE OP_TILING_FILES "*.cpp")
add_library(optiling SHARED ${OP_TILING_FILES})
add_dependencies(optiling json)
target_compile_definitions(optiling PRIVATE
_GLIBCXX_USE_CXX11_ABI=0
LOG_CPP
)
target_include_directories(optiling PRIVATE
${OP_TILING_INCLUDE}
)
target_link_libraries(optiling PRIVATE
$<BUILD_INTERFACE:dlog_headers>
)

View File

@@ -0,0 +1,198 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file op_cache_tiling.h
* \brief
*/
#ifndef OPS_BUILT_IN_OP_TILING_OP_CACHE_DEF_TILING_H
#define OPS_BUILT_IN_OP_TILING_OP_CACHE_DEF_TILING_H
#include <array>
#include "exe_graph/runtime/tiling_context.h"
namespace optiling {
struct BatchmatmulCompileParas {
bool binary_mode_flag = false;
bool bias_flag = false;
bool at_l1_flag = true;
bool split_k_flag = false;
bool pattern_flag = false;
bool zero_flag = false;
bool sparse_4to2_flag = false;
bool binary_constant_flag = false;
bool vector_pre_conv_mode = false;
float fused_double_operand_num = 0;
float aub_double_num = 0;
float bub_double_num = 0;
int64_t quant_scale = 0;
int64_t eltwise_src = 0;
int8_t enable_pad = 0;
bool enable_nz_fusion = false;
bool enable_rt_bank_cache = false;
};
struct BatchmatmulRunParas {
bool nd_flag = false;
bool use_pre_ub = false;
bool trans_a_flag = false;
bool trans_b_flag = false;
bool format_a_nd = false;
bool format_b_nd = false;
bool format_out_nd = false;
ge::Format format_a = ge::FORMAT_ND;
ge::Format format_b = ge::FORMAT_ND;
ge::Format format_out = ge::FORMAT_ND;
bool reserved_bool = false;
bool b_have_batch = false; // dim num > 2
bool is_batch_matmul_mode = false; // dynamic_mode == "dynamic_mknb"
bool is_batch_matmul_op = false; // BatchMatMulV2 or BatchMatMul
bool used_aligned_pattern = false;
bool non_factor_k = false;
bool non_factor_bmn = false;
bool bias_flag = false;
bool pattern_flag = false;
bool do_not_multi_batch = false;
bool performance_flag = false;
bool unaligned_flag = false;
bool zero_flag = false;
bool is_compress_quant = false;
bool is_bmm_fixp = false;
bool enable_nz_fusion = false;
bool weight_nz_flag = false;
int8_t enable_pad = 0;
int8_t hf32_flag = 1;
int8_t pad_flag = 0;
int8_t nz_fusion_flag = 0;
int32_t dtype_a = 0;
int32_t dtype_b = 0;
int32_t dtype_out = 0;
int32_t dtype_bias = 0;
int64_t m_mapped = 1;
int64_t k_mapped = 1;
int64_t n_mapped = 1;
int64_t batch_mapped = 1;
int64_t m = 1;
int64_t k = 1;
int64_t n = 1;
int64_t batch = 1;
int64_t ori_shape_m = 1;
int64_t ori_shape_k = 1;
int64_t ori_shape_n = 1;
int64_t m_pad = 0;
int64_t k_pad = 0;
int64_t n_pad = 0;
int64_t nl0 = 1;
int64_t kl0 = 1;
int64_t dim0_a = 0;
int64_t dim1_a = 0;
int64_t dim2_a = 0;
int64_t dim0_b = 0;
int64_t dim1_b = 0;
int64_t dim2_b = 0;
int64_t batch_a1 = 1;
int64_t batch_a2 = 1;
int64_t batch_a3 = 1;
int64_t batch_a4 = 1;
int64_t batch_b1 = 1;
int64_t batch_b2 = 1;
int64_t batch_b3 = 1;
int64_t batch_b4 = 1;
int64_t batch_c1 = 1;
int64_t batch_c2 = 1;
int64_t batch_c3 = 1;
int64_t batch_c4 = 1;
int32_t offset_x = 0;
int32_t index_size = 0;
bool m_quant_check = false;
bool n_quant_check = false;
bool is_weight_quant_bmm = false;
bool vector_pre_conv_mode = false;
bool is_quant_batch_matmul_v3 = false;
bool is_weight_quant_batch_matmul_v2 = false;
bool is_pertoken = false;
// 3 is perm_a dim
std::array<size_t, 3> perm_a = {0, 0, 0};
// 3 is perm_b dim
std::array<size_t, 3> perm_b = {0, 0, 0};
ge::DataType bias_dtype = ge::DT_FLOAT16;
};
class CacheTilingData
{
public:
uint64_t tiling_id;
int64_t n_cub = 1;
int64_t db_cub = 1;
int64_t m_l0 = 1;
int64_t k_l0 = 1;
int64_t n_l0 = 1;
int64_t batch_dim = 1;
int64_t n_dim = 1;
int64_t m_dim = 1;
int64_t k_dim = 1;
int64_t kal1_16 = 1;
int64_t kbl1_16 = 1;
int64_t kal1_factor = 1;
int64_t kbl1_factor = 1;
int64_t m_al1 = 1;
int64_t n_bl1 = 1;
int64_t db_al1 = 1;
int64_t db_bl1 = 1;
int64_t k_aub = 1;
int64_t m_aub = 1;
int64_t db_aub = 1;
int64_t k_bub = 1;
int64_t n_bub = 1;
int64_t db_bub = 1;
int64_t aub_dim = 1;
int64_t bub_dim = 1;
int64_t m1_aub = 1;
int64_t n1_bub = 1;
int64_t k1_aub = 1;
int64_t k1_bub = 1;
int64_t m_aub_dim = 1;
int64_t n_bub_dim = 1;
int64_t k_aub_dim = 1;
int64_t k_bub_dim = 1;
int64_t k_org_dim = 1;
int64_t db_l0c = 1;
int64_t batch_l0 = 1;
int64_t batch_aub = 1;
int64_t batch_bub = 1;
int64_t batch_cub = 1;
int32_t out_branch_flag = 1;
int32_t bias_flag = 0;
int32_t aub_multi_flag = 0;
int32_t bub_multi_flag = 0;
int64_t a_align_value = 1;
int64_t b_align_value = 1;
int64_t aub_align_bound = 0;
int64_t bub_align_bound = 0;
int64_t min_kl1_cmp_kl0 = 0;
int32_t al1_attach_flag = 0;
int32_t bl1_attach_flag = 0;
int32_t abkl1_attach_flag = 0;
int32_t l0c_multi_batch = 0;
int64_t m_single_core = 1;
int64_t n_single_core = 1;
bool flag_cub_solving_bank_conflict = false;
bool al1_full_load = false;
bool bl1_full_load = false;
int8_t hf32_flag = 1;
int32_t zero_flag = 0;
bool datatype_bf16 = false;
uint64_t deq_scale_var = 0x3F800000;
uint32_t l2_cache_flag = 0;
};
} // namespace optiling
#endif

View File

@@ -0,0 +1,35 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file op_cache_tiling.cpp
* \brief
*/
#include "op_cache_tiling.h"
namespace optiling {
bool TilingPrepareForOpCache(gert::TilingContext* /*context*/)
{
return true;
}
bool TilingPrepareForOpCache(gert::TilingParseContext* /*context*/)
{
return true;
}
bool GenTiling(
const std::string& /*op_type*/, const BatchmatmulCompileParas& /*compile_params*/,
BatchmatmulRunParas& /*run_params*/, CacheTilingData& /*tiling*/, gert::TilingContext* /*context*/)
{
return true;
}
} // namespace optiling

View File

@@ -0,0 +1,34 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file cop_ache_tiling.h
* \brief
*/
#ifndef OPS_BUILT_IN_OP_TILING_OP_CACHE_TILING_H
#define OPS_BUILT_IN_OP_TILING_OP_CACHE_TILING_H
#include <array>
#include "exe_graph/runtime/tiling_context.h"
#include "exe_graph/runtime/tiling_parse_context.h"
#include "op_cache_def_tiling.h"
namespace optiling {
bool TilingPrepareForOpCache(gert::TilingContext* context);
bool TilingPrepareForOpCache(gert::TilingParseContext* context);
bool GenTiling(
const std::string& op_type, const BatchmatmulCompileParas& compile_params, BatchmatmulRunParas& run_params,
CacheTilingData& tiling, gert::TilingContext* context);
} // namespace optiling
#endif

View File

@@ -0,0 +1,209 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef __INC_REGISTER_TUNING_BANK_KEY_REGISTRY_HEADER__
#define __INC_REGISTER_TUNING_BANK_KEY_REGISTRY_HEADER__
#include <memory>
#include <unordered_map>
#include <nlohmann/json.hpp>
#include <string>
#include "graph/ascend_string.h"
#include "register/register_types.h"
#include "exe_graph/runtime/tiling_context.h"
// v1 stub
#define REGISTER_OP_BANK_KEY_CONVERT_FUN(op, opfunc) REGISTER_OP_BANK_KEY_CONVERT_FUN_UNIQ_HELPER(op, (opfunc))
#define REGISTER_OP_BANK_KEY_CONVERT_FUN_UNIQ_HELPER(optype, opfunc) REGISTER_OP_BANK_KEY_UNIQ(optype, (opfunc))
#define REGISTER_OP_BANK_KEY_UNIQ(optype, opfunc) \
static tuningtiling::OpBankKeyFuncRegistry g_##optype##BankKeyRegistryInterf(#optype, (opfunc))
#define REGISTER_OP_BANK_KEY_PARSE_FUN(op, parse_func, load_func) \
REGISTER_OP_BANK_KEY_PARSE_FUN_UNIQ_HELPER(op, (parse_func), (load_func))
#define REGISTER_OP_BANK_KEY_PARSE_FUN_UNIQ_HELPER(optype, parse_func, load_func) \
REGISTER_OP_BANK_KEY_PARSE_UNIQ(optype, (parse_func), (load_func))
#define REGISTER_OP_BANK_KEY_PARSE_UNIQ(optype, parse_func, load_func) \
static tuningtiling::OpBankKeyFuncRegistry g_##optype##BankParseInterf(#optype, (parse_func), (load_func))
// v2
#define REGISTER_OP_BANK_KEY_CONVERT_FUN_V2(op, opfunc) REGISTER_OP_BANK_KEY_CONVERT_FUN_UNIQ_HELPER_V2(op, (opfunc))
#define REGISTER_OP_BANK_KEY_CONVERT_FUN_UNIQ_HELPER_V2(optype, opfunc) REGISTER_OP_BANK_KEY_UNIQ_V2(optype, (opfunc))
#define REGISTER_OP_BANK_KEY_UNIQ_V2(optype, opfunc) \
static tuningtiling::OpBankKeyFuncRegistryV2 g_##optype##BankKeyRegistryInterf(#optype, (opfunc))
#define REGISTER_OP_BANK_KEY_PARSE_FUN_V2(op, parse_func, load_func) \
REGISTER_OP_BANK_KEY_PARSE_FUN_UNIQ_HELPER_V2(op, (parse_func), (load_func))
#define REGISTER_OP_BANK_KEY_PARSE_FUN_UNIQ_HELPER_V2(optype, parse_func, load_func) \
REGISTER_OP_BANK_KEY_PARSE_UNIQ_V2(optype, (parse_func), (load_func))
#define REGISTER_OP_BANK_KEY_PARSE_UNIQ_V2(optype, parse_func, load_func) \
static tuningtiling::OpBankKeyFuncRegistryV2 g_##optype##BankParseInterf(#optype, (parse_func), (load_func))
#define TUNING_TILING_MAKE_SHARED(exec_expr0, exec_expr1) \
do { \
try { \
exec_expr0; \
} catch (...) { \
exec_expr1; \
} \
} while (0)
// v1 stub
#define DECLARE_STRUCT_RELATE_WITH_OP(op, bank_key, ...) \
do { \
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(bank_key, __VA_ARGS__); \
static bool ParseFunc##op##bank_key( \
const std::shared_ptr<void>& in_args, size_t len, ge::AscendString& bank_key_str) \
{ \
if (sizeof(bank_key_str) != len || in_args == nullptr) { \
return false; \
} \
return false; \
} \
static bool LoadFunc##op##bank_key( \
std::shared_ptr<void>& in_args, size_t& len, const ge::AscendString& bank_key_str) \
{ \
len = sizeof(bank_key_str); \
TUNING_TILING_MAKE_SHARED(in_args = std::make_shared<bank_key>(), return false); \
auto op_ky = std::static_pointer_cast<bank_key>(in_args); \
return false; \
} \
REGISTER_OP_BANK_KEY_PARSE_FUN(op, ParseFunc##op##bank_key, LoadFunc##op##bank_key) \
} while (0)
// v2
#define DECLARE_STRUCT_RELATE_WITH_OP_V2(op, bank_key, ...) \
do { \
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(bank_key, __VA_ARGS__); \
static bool ParseFuncV2##op##bank_key( \
const std::shared_ptr<void>& in_args, size_t len, ge::AscendString& bank_key_json_str) \
{ \
if (sizeof(bank_key) != len || in_args == nullptr) { \
return false; \
} \
nlohmann::json bank_key_json; \
bank_key_json = *(std::static_pointer_cast<bank_key>(in_args)); \
try { \
std::string json_dump_str = bank_key_json.dump(); \
bank_key_json_str = ge::AscendString(json_dump_str.c_str()); \
} catch (std::exception & e) { \
return false; \
} \
return true; \
} \
static bool LoadFuncV2##op##bank_key( \
std::shared_ptr<void>& in_args, size_t& len, const ge::AscendString& bank_key_json_str) \
{ \
len = sizeof(bank_key); \
TUNING_TILING_MAKE_SHARED(in_args = std::make_shared<bank_key>(), return false); \
nlohmann::json bank_key_json; \
try { \
bank_key_json = nlohmann::json::parse(bank_key_json_str.GetString()); \
auto op_ky = std::static_pointer_cast<bank_key>(in_args); \
*op_ky = bank_key_json.get<bank_key>(); \
} catch (std::exception & e) { \
return false; \
} \
return true; \
} \
REGISTER_OP_BANK_KEY_PARSE_FUN_V2(op, ParseFuncV2##op##bank_key, LoadFuncV2##op##bank_key) \
} while (0)
namespace tuningtiling {
// v1兼容老版本om
using OpBankKeyConvertFun = std::function<bool(const gert::TilingContext*, std::shared_ptr<void>&, size_t&)>;
using OpBankParseFun = std::function<bool(const std::shared_ptr<void>&, size_t, ge::AscendString&)>;
using OpBankLoadFun = std::function<bool(std::shared_ptr<void>&, size_t&, const ge::AscendString&)>;
// v2
using OpBankKeyConvertFunV2 = std::function<bool(const gert::TilingContext*, std::shared_ptr<void>&, size_t&)>;
using OpBankParseFunV2 = std::function<bool(const std::shared_ptr<void>&, size_t, ge::AscendString&)>;
using OpBankLoadFunV2 = std::function<bool(std::shared_ptr<void>&, size_t&, const ge::AscendString&)>;
// v1兼容老版本om
class FMK_FUNC_HOST_VISIBILITY OpBankKeyFuncInfo
{
public:
explicit OpBankKeyFuncInfo(const ge::AscendString& optype);
OpBankKeyFuncInfo() = default;
~OpBankKeyFuncInfo() = default;
void SetOpConvertFunc(const OpBankKeyConvertFun& convert_func);
void SetOpParseFunc(const OpBankParseFun& parse_func);
void SetOpLoadFunc(const OpBankLoadFun& load_func);
const OpBankKeyConvertFun& GetBankKeyConvertFunc() const;
const OpBankParseFun& GetBankKeyParseFunc() const;
const OpBankLoadFun& GetBankKeyLoadFunc() const;
const ge::AscendString& GetOpType() const
{
return optype_;
}
private:
ge::AscendString optype_;
OpBankKeyConvertFun convert_func_;
OpBankParseFun parse_func_;
OpBankLoadFun load_func_;
};
// v2
class FMK_FUNC_HOST_VISIBILITY OpBankKeyFuncInfoV2
{
public:
explicit OpBankKeyFuncInfoV2(const ge::AscendString& optypeV2);
OpBankKeyFuncInfoV2() = default;
~OpBankKeyFuncInfoV2() = default;
void SetOpConvertFuncV2(const OpBankKeyConvertFunV2& convert_funcV2);
void SetOpParseFuncV2(const OpBankParseFunV2& parse_funcV2);
void SetOpLoadFuncV2(const OpBankLoadFunV2& load_funcV2);
const OpBankKeyConvertFunV2& GetBankKeyConvertFuncV2() const;
const OpBankParseFunV2& GetBankKeyParseFuncV2() const;
const OpBankLoadFunV2& GetBankKeyLoadFuncV2() const;
const ge::AscendString& GetOpTypeV2() const
{
return optypeV2_;
}
private:
ge::AscendString optypeV2_;
OpBankKeyConvertFunV2 convert_funcV2_;
OpBankParseFunV2 parse_funcV2_;
OpBankLoadFunV2 load_funcV2_;
};
// v1兼容老版本om
class FMK_FUNC_HOST_VISIBILITY OpBankKeyFuncRegistry
{
public:
OpBankKeyFuncRegistry(const ge::AscendString& optype, const OpBankKeyConvertFun& convert_func);
OpBankKeyFuncRegistry(
const ge::AscendString& optype, const OpBankParseFun& parse_func, const OpBankLoadFun& load_func);
~OpBankKeyFuncRegistry() = default;
static std::unordered_map<ge::AscendString, OpBankKeyFuncInfo>& RegisteredOpFuncInfo();
};
// v2
class FMK_FUNC_HOST_VISIBILITY OpBankKeyFuncRegistryV2
{
public:
OpBankKeyFuncRegistryV2(const ge::AscendString& optype, const OpBankKeyConvertFunV2& convert_funcV2);
OpBankKeyFuncRegistryV2(
const ge::AscendString& optype, const OpBankParseFunV2& parse_funcV2, const OpBankLoadFunV2& load_funcV2);
~OpBankKeyFuncRegistryV2() = default;
static std::unordered_map<ge::AscendString, OpBankKeyFuncInfoV2>& RegisteredOpFuncInfoV2();
};
} // namespace tuningtiling
#endif

View File

@@ -0,0 +1,191 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef __INC_REGISTER_TUNING_TILING_REFLECTION_UTILS_HEADER__
#define __INC_REGISTER_TUNING_TILING_REFLECTION_UTILS_HEADER__
#include <string>
#include <type_traits>
#include <tuple>
#include <nlohmann/json.hpp>
namespace tuningtiling {
// implement for std c++11
template <class T>
using decay_t = typename std::decay<T>::type;
template <bool B, class T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
template <typename T, T... Ints>
struct integer_sequence {
using value_type = T;
static constexpr std::size_t size()
{
return sizeof...(Ints);
}
};
template <std::size_t... Ints>
using index_sequence = integer_sequence<std::size_t, Ints...>;
template <typename T, std::size_t N, T... Is>
struct make_integer_sequence : make_integer_sequence<T, N - 1U, N - 1U, Is...> {
};
template <typename T, T... Is>
struct make_integer_sequence<T, 0, Is...> : integer_sequence<T, Is...> {
};
template <std::size_t N>
using make_index_sequence = make_integer_sequence<std::size_t, N>;
template <typename T>
struct StructInfo {
static std::tuple<> Info()
{
return std::make_tuple();
}
};
#define DECLARE_SCHEMA(Struct, ...) \
template <> \
struct StructInfo<Struct> { \
static decltype(std::make_tuple(__VA_ARGS__)) Info() \
{ \
return std::make_tuple(__VA_ARGS__); \
} \
};
#define FIELD(class, FieldName) std::make_tuple(#FieldName, &class ::FieldName)
template <typename Fn, typename Tuple, typename Field, std::size_t... Is>
void ForEachTuple(Tuple&& tuple, Field&& fields, Fn&& fn, index_sequence<Is...>)
{
(void)std::initializer_list<size_t>{
(fn(std::get<0>(std::get<Is>(fields)), tuple.*std::get<1>(std::get<Is>(fields))), Is)...};
}
template <typename Fn, typename Tuple>
void ForEachTuple(Tuple&& tuple, Fn&& fn)
{
const auto fields = StructInfo<decay_t<Tuple>>::Info();
ForEachTuple(
std::forward<Tuple>(tuple), fields, std::forward<Fn>(fn),
make_index_sequence<std::tuple_size<decltype(fields)>::value>{});
}
template <typename T>
struct is_optional : std::false_type {
};
template <typename T>
struct is_optional<std::unique_ptr<T>> : std::true_type {
};
template <typename T>
bool is_optional_v()
{
return is_optional<decay_t<T>>::value;
}
template <typename T>
decltype(std::begin(T()), std::true_type{}) containable(size_t);
template <typename T>
std::false_type containable(...);
template <typename T>
using is_containable = decltype(containable<T>(0U));
template <typename T>
constexpr bool IsSerializeType()
{
return ((!std::is_class<decay_t<T>>::value) || is_containable<decay_t<T>>());
}
template <typename T, typename Fn>
void ForEachField(T&& value, Fn&& fn)
{
ForEachTuple(std::forward<T>(value), std::forward<Fn>(fn));
}
template <typename Fn>
struct DumpFunctor;
template <typename T, typename Js, enable_if_t<!IsSerializeType<T>()>* = nullptr>
void DumpObj(T&& obj, const std::string& field_name, Js& j)
{
if (field_name.empty()) {
ForEachField(std::forward<T>(obj), DumpFunctor<Js>(j));
return;
}
ForEachField(std::forward<T>(obj), DumpFunctor<Js>(j[field_name]));
}
template <typename T, typename Js, enable_if_t<IsSerializeType<T>()>* = nullptr>
void DumpObj(T&& obj, const std::string& field_name, Js& j)
{
if (field_name.empty()) {
return;
}
j[field_name] = std::forward<T>(obj);
}
template <typename T>
struct DumpFunctor {
explicit DumpFunctor(T& j) : js(j)
{}
template <typename Name, typename Field>
void operator()(Name&& name, Field&& field) const
{
DumpObj(std::forward<Field>(field), std::forward<Name>(name), js);
}
T& js;
};
template <typename Fn>
struct FromJsonFunctor;
template <typename T, typename Js, enable_if_t<!IsSerializeType<T>()>* = nullptr>
void FromJsonImpl(T&& obj, const std::string& field_name, const Js& j)
{
if (field_name.empty()) {
ForEachField(std::forward<T>(obj), FromJsonFunctor<Js>(j));
return;
}
if (j.find(field_name) == j.cend()) {
return;
}
ForEachField(std::forward<T>(obj), FromJsonFunctor<Js>(j[field_name]));
}
template <typename T, typename Js, enable_if_t<IsSerializeType<T>()>* = nullptr>
void FromJsonImpl(T&& obj, const std::string& field_name, const Js& j)
{
// ignore missing field of optional
if ((tuningtiling::is_optional_v<decltype(obj)>()) || (j.find(field_name) == j.cend())) {
return;
}
j.at(field_name).get_to(std::forward<T>(obj));
}
template <typename Js>
struct FromJsonFunctor {
explicit FromJsonFunctor(const Js& j) : js(j)
{}
template <typename Name, typename Field>
void operator()(Name&& name, Field&& field) const
{
FromJsonImpl(std::forward<Field>(field), std::forward<Name>(name), js);
}
const Js& js;
};
} // namespace tuningtiling
#endif

View File

@@ -0,0 +1,111 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef __INC_REGISTER_TUNING_TILING_REGISTRY_HEADER__
#define __INC_REGISTER_TUNING_TILING_REGISTRY_HEADER__
#include <vector>
#include <map>
#include <memory>
#include <nlohmann/json.hpp>
#include "graph/ascend_string.h"
#include "register/tuning_tiling_reflection_utils.h"
namespace tuningtiling {
struct TilingItem {
ge::AscendString dtype_;
ge::AscendString name_;
};
class TuningTilingDef
{
public:
virtual void FromJson(const nlohmann::json& j) = 0;
virtual void ToJson(nlohmann::json& j) = 0;
ge::AscendString GetClassName() const;
virtual std::vector<TilingItem> GetItemInfo() const = 0;
protected:
TuningTilingDef() = default;
virtual ~TuningTilingDef() = default;
// dtype , name
std::vector<TilingItem> field_info_;
ge::AscendString class_name_;
};
#define BEGIN_TUNING_TILING_DEF(class_name) \
class class_name : public TuningTilingDef \
{ \
public: \
virtual void FromJson(const nlohmann::json& j) \
{ \
FromJsonImpl(*this, "", j); \
} \
\
virtual void ToJson(nlohmann::json& j) \
{ \
DumpObj(*this, "", j); \
} \
\
std::vector<TilingItem> GetItemInfo() const \
{ \
return field_info_; \
} \
\
class FieldHandler \
{ \
public: \
FieldHandler(class_name* pinstance, const ge::AscendString& dtype, const ge::AscendString& name) \
{ \
pinstance->field_info_.push_back({dtype, name}); \
} \
}; \
friend class FieldHandler; \
\
public: \
class_name() \
{ \
class_name_ = #class_name; \
};
#define TUNING_TILING_DATA_FIELD_DEF(data_type, field_name) \
public: \
data_type field_name; \
FieldHandler field_name##_handler_ = FieldHandler(this, #data_type, #field_name);
#define END_TUNING_TILING_DEF \
} \
;
using TuningTilingDefConstructor = std::shared_ptr<TuningTilingDef> (*)();
class TuningTilingClassFactory
{
public:
static std::map<ge::AscendString, TuningTilingDefConstructor>& RegisterInfo();
static void RegisterTilingData(const ge::AscendString& optype, TuningTilingDefConstructor const constructor);
static std::shared_ptr<TuningTilingDef> CreateTilingDataInstance(const ge::AscendString& optype);
};
#define REGISTER_TUNING_TILING_CLASS(optype, class_name) \
class optype##Helper \
{ \
public: \
optype##Helper() \
{ \
TuningTilingClassFactory::RegisterTilingData(#optype, optype##Helper::CreateTilingDataInstance); \
} \
static std::shared_ptr<TuningTilingDef> CreateTilingDataInstance() \
{ \
return std::make_shared<class_name>(); \
} \
}; \
optype##Helper g_tuning_tiling_##optype##Helper;
using TuningTilingDefPtr = std::shared_ptr<TuningTilingDef>;
} // namespace tuningtiling
#endif

View File

@@ -0,0 +1,20 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#include "runtime_kb_api.h"
namespace RuntimeKb {
uint32_t QueryBank(
const void* /*src*/, size_t /*src_len*/, const std::string& /*op_type*/, const std::string& /*soc_version*/,
uint32_t /*core_num*/, tuningtiling::TuningTilingDefPtr& /*tiling*/)
{
return 0;
}
} // namespace RuntimeKb

View File

@@ -0,0 +1,23 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef RUNTIME_KB_RUNTIME_KB_API_H
#define RUNTIME_KB_RUNTIME_KB_API_H
#include <string>
#include "exe_graph/runtime/tiling_context.h"
#include "register/tuning_tiling_registry.h"
namespace RuntimeKb {
uint32_t QueryBank(const void *src, size_t src_len, const std::string &op_type, const std::string &soc_version,
uint32_t core_num, tuningtiling::TuningTilingDefPtr &tiling);
}
#endif

View File

@@ -0,0 +1,39 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#include "tbe_tiling_api.h"
using namespace optiling;
namespace optiling {
bool GetTbeTiling(const gert::TilingContext* context, Conv3dBpFilterV2RunInfo& runInfoForV2, Conv3dBackpropV2TBETilingData& tbeTilingForV2)
{
(void)context;
(void)runInfoForV2;
(void)tbeTilingForV2;
return true;
}
bool GetTbeTiling(gert::TilingContext* context, Conv3dBpInputV2RunInfo& runInfoV2,
Conv3dBackpropV2TBETilingData& tbeTilingForV2, const optiling::OpTypeV2 opType)
{
(void)context;
(void)runInfoV2;
(void)tbeTilingForV2;
(void)opType;
return true;
}
bool GetTbeTiling(gert::TilingContext* context, Conv3dBackpropV2TBETilingData& tbeTilingForV2, const optiling::OpTypeV2 opType)
{
(void)context;
(void)tbeTilingForV2;
(void)opType;
return true;
}
}

View File

@@ -0,0 +1,193 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
/*!
* \file tbe_tiling_api.h
* \brief
*/
#ifndef TBE_TILING_API_H
#define TBE_TILING_API_H
#include <cstdint>
#include <exe_graph/runtime/tiling_context.h>
#include <tiling/platform/platform_ascendc.h>
#include "graph/utils/type_utils.h"
#include "platform/platform_infos_def.h"
namespace optiling {
struct Conv3dBackpropV2TBETilingData {
// L0 tiling parameters
int32_t m_l0; // Base M dimension at L0
int32_t k_l0; // Base K dimension at L0
int32_t n_l0; // Base N dimension at L0
// L1 tiling parameters
int32_t m_al1; // Step M dimension at L1
int32_t n_bl1; // Step N dimension at L1
int32_t k_al1; // Step K dimension A at L1
int32_t k_bl1; // Step K dimension B at L1
// Buffer parameters
int32_t db_l0c; // L0C buffer size
int32_t db_al1; // AL1 buffer size
int32_t db_bl1; // BL1 buffer size
// Dimension parameters
int32_t batch_dim; // Batch dimension
int32_t d_dim; // Depth dimension
int32_t group_dim; // Group dimension
int32_t m_dim; // M dimension
int32_t n_dim; // N dimension
int32_t k_dim; // K dimension
};
struct Conv3dBpFilterV2RunInfo {
int32_t batch;
int32_t co; // output channels
int32_t ci; // input channels
int32_t cout1_g; // output channels per group
int32_t cin1_g; // input channels per group
int32_t dout; // output depth // codespell:ignore dout
int32_t wo; // output width
int32_t ho; // output height
int32_t wi; // input width
int32_t hi; // input height
int32_t di; // input depth
int32_t kw; // kernel width
int32_t kh; // kernel height
int32_t kd; // kernel depth
int32_t real_g; // actual groups
int32_t stride_w;
int32_t stride_h;
int32_t stride_d;
int32_t pad_l; // left padding
int32_t pad_r; // right padding
int32_t pad_u; // up padding
int32_t pad_d; // down padding
int32_t pad_f; // front padding
int32_t pad_b; // back padding
int32_t dilation_w;
int32_t dilation_h;
int32_t dilation_d;
int32_t ci1; // another input channels parameter
uint64_t bl1_bound; // buffer limit 1 bound, tiling结果的衍生参数不建议放在这里
int32_t batch_dout_single_core; // batch*dout per core, tiling结果的衍生参数不建议放在这里 // codespell:ignore dout
// Tiling parameters
uint32_t k0;
uint32_t m0;
uint32_t n0;
uint32_t hf32Flag;
ge::DataType a_dtype = ge::DT_FLOAT16;
ge::DataType b_dtype = ge::DT_FLOAT16;
ge::DataType c_dtype = ge::DT_FLOAT16;
int32_t a_dtype_bytes = 2;
int32_t b_dtype_bytes = 2;
int32_t c_dtype_bytes = 2;
uint32_t core_num;
};
struct Conv3dBpInputV2RunInfo {
// Batch and group related
int32_t batch_n; // Batch size
int32_t real_g; // Number of groups
// Input dimensions (dedx)
int32_t dedx_d; // Input depth
int32_t dedx_cin; // Input channels per group
int32_t dedx_cin1; // Input channels per group
int32_t dedx_cin1_g; // Input channels per group (grouped)
int32_t dedx_h; // Input height
int32_t dedx_w; // Input width
// Output dimensions (dedy)
int32_t dedy_d; // Output depth
int32_t dedy_cout; // Output channels per group
int32_t dedy_cout1; // Output channels per group
int32_t dedy_cout1_g; // Output channels per group (grouped)
int32_t dedy_h; // Output height
int32_t dedy_w; // Output width
// Kernel dimensions
int32_t kernel_d; // Kernel depth
int32_t kernel_h; // Kernel height
int32_t kernel_w; // Kernel width
// Strides
int32_t stride_d; // Stride depth
int32_t stride_h; // Stride height
int32_t stride_w; // Stride width
// Padding
int32_t pad_h; // Padding height
int32_t pad_t; // Padding top
int32_t pad_u; // Padding up
int32_t pad_d; // Padding down
int32_t pad_l; // Padding left
int32_t pad_r; // Padding right
// Dilation
int32_t dilation_d; // Dilation depth
int32_t dilation_h; // Dilation height
int32_t dilation_w; // Dilation width
// Backprop padding
int32_t backprop_pad_h; // Backprop padding height
int32_t backprop_pad_t; // Backprop padding top
int32_t backprop_pad_u; // Backprop padding up
int32_t backprop_pad_d; // Backprop padding down
int32_t backprop_pad_l; // Backprop padding left
int32_t backprop_pad_r; // Backprop padding right
// Other flags
int32_t hf32_flag; // Flag for FP32 handling
int32_t a_dtype_bytes = 2;
int32_t b_dtype_bytes = 2;
int32_t c_dtype_bytes = 2;
int32_t initOutputFlag = 0;
};
struct Conv3DBackpropV2CompileInfo {
std::string soc_version = "";
platform_ascendc::SocVersion shortSocVersion = platform_ascendc::SocVersion::ASCEND910B;
uint32_t core_num = 0;
uint64_t ub_size = 0;
uint64_t l1_size = 0;
uint64_t l2_size = 0;
uint64_t l0a_size = 0;
uint64_t l0b_size = 0;
uint64_t l0c_size = 0;
uint64_t bt_size = 0;
int32_t cube_freq = 0;
bool load3d_constraints = true;
bool intrinsic_data_move_l12ub = true;
bool intrinsic_matmul_ub_to_ub = false;
bool intrinsic_conv_ub_to_ub = false;
bool intrinsic_data_move_l0c2ub = true;
bool intrinsic_fix_pipe_l0c2out = false;
bool intrinsic_fix_pipe_l0c2ub = false;
bool intrinsic_data_move_out2l1_nd2nz = false;
bool intrinsic_data_move_l12bt_bf16 = false;
};
enum OpTypeV2 : size_t {
kConv3DBackpropFilterV2,
kConv3DBackpropInputV2,
kConv3DTransposeV2,
};
bool GetTbeTiling(const gert::TilingContext* context, Conv3dBpFilterV2RunInfo& runInfoForV2, Conv3dBackpropV2TBETilingData& tbeTilingForV2);
bool GetTbeTiling(gert::TilingContext* context, Conv3dBpInputV2RunInfo& runInfoV2,
Conv3dBackpropV2TBETilingData& tbeTilingForV2, const optiling::OpTypeV2 opType);
bool GetTbeTiling(gert::TilingContext* context, Conv3dBackpropV2TBETilingData& tbeTilingForV2, const optiling::OpTypeV2 opType);
}
#endif // TBE_TILING_API_H