* Copyright (c) 2026 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_example_pypto_tiling.cpp
* \brief AddExamplePypto算子的tiling实现
*
* 注意:本文件不显式include PyPTO生成的头文件。enable_pypto_kernel(add_example_pypto)在configure阶段
* 生成 AddExamplePyptoTilingKey_tilingkey.h 与 AddExamplePyptoTiling_tiling.h,并由cmake以
* -include 的方式强制包含到本文件(顺序:tilingkey在前,tiling在后)。因此下面可以直接使用
* AddExamplePyptoTiling —— 它就是op_kernel/add_example_pypto.py中的同名dataclass,host与kernel
* 共享同一份tiling布局,无需手写副本。
*/
#include "exe_graph/runtime/tiling_context.h"
#include "tiling/platform/platform_ascendc.h"
#include "register/op_def_registry.h"
#include "register/tilingdata_base.h"
#include "log/log.h"
namespace optiling {
BEGIN_TILING_DATA_DEF(AddExamplePyptoTilingData)
TILING_DATA_FIELD_DEF(int64_t, rows)
TILING_DATA_FIELD_DEF(int64_t, columns)
END_TILING_DATA_DEF
REGISTER_TILING_DATA_CLASS(AddExamplePypto, AddExamplePyptoTilingData)
struct AddExamplePyptoCompileInfo {};
constexpr int64_t TILE_ROWS = 16;
constexpr int64_t TILE_COLUMNS = 16;
constexpr size_t DIMS_LIMIT = 2;
constexpr uint64_t OPERATION_ADD = 0;
* \brief AddExamplePypto算子的tiling入口
*/
static ge::graphStatus AddExamplePyptoTilingFunc(gert::TilingContext* context)
{
fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);
auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);
int64_t coreNum = ascendcPlatform.GetCoreNumAiv();
OP_CHECK_IF(coreNum == 0, OP_LOGE(context, "coreNum is 0"), return ge::GRAPH_FAILED);
auto inputX1 = context->GetInputShape(0);
OP_CHECK_NULL_WITH_CONTEXT(context, inputX1);
const auto& shapeX1 = inputX1->GetStorageShape();
OP_CHECK_IF(shapeX1.GetDimNum() != DIMS_LIMIT,
OP_LOGE(context, "AddExamplePypto: input dim = %zu, should be equal 2", shapeX1.GetDimNum()),
return ge::GRAPH_FAILED);
auto inputX2 = context->GetInputShape(1);
OP_CHECK_NULL_WITH_CONTEXT(context, inputX2);
const auto& shapeX2 = inputX2->GetStorageShape();
OP_CHECK_IF(shapeX2.GetDimNum() != shapeX1.GetDimNum(),
OP_LOGE(context, "AddExamplePypto: x2 dim = %zu, should equal x1 dim = %zu", shapeX2.GetDimNum(),
shapeX1.GetDimNum()),
return ge::GRAPH_FAILED);
for (size_t i = 0; i < shapeX1.GetDimNum(); i++) {
OP_CHECK_IF(shapeX2.GetDim(i) != shapeX1.GetDim(i),
OP_LOGE(context, "AddExamplePypto: x2 shape[%zu] = %ld, should equal x1 shape[%zu] = %ld", i,
shapeX2.GetDim(i), i, shapeX1.GetDim(i)),
return ge::GRAPH_FAILED);
}
int64_t rows = shapeX1.GetDim(0);
int64_t columns = shapeX1.GetDim(1);
OP_CHECK_IF(rows % TILE_ROWS != 0 || columns % TILE_COLUMNS != 0,
OP_LOGE(context, "AddExamplePypto: shape [%ld, %ld] should be aligned to [%ld, %ld]", rows, columns,
TILE_ROWS, TILE_COLUMNS),
return ge::GRAPH_FAILED);
size_t* currentWorkspace = context->GetWorkspaceSizes(1);
OP_CHECK_NULL_WITH_CONTEXT(context, currentWorkspace);
currentWorkspace[0] = 0U;
AddExamplePyptoTiling* tilingData = context->GetTilingData<AddExamplePyptoTiling>();
OP_CHECK_NULL_WITH_CONTEXT(context, tilingData);
tilingData->rows = rows;
tilingData->columns = columns;
context->SetBlockDim(1);
context->SetTilingKey(OPERATION_ADD);
return ge::GRAPH_SUCCESS;
}
* \brief 解析AddExamplePypto算子的编译信息,本算子无静态tiling信息
*/
static ge::graphStatus TilingParseForAddExamplePypto([[maybe_unused]] gert::TilingParseContext* context)
{
return ge::GRAPH_SUCCESS;
}
IMPL_OP_OPTILING(AddExamplePypto)
.Tiling(AddExamplePyptoTilingFunc)
.TilingParse<AddExamplePyptoCompileInfo>(TilingParseForAddExamplePypto);
}