已合并
legacy日落-给一些算子增加InferDataTpye和Tiling日志 #4712
pan xiong创建于 16 天前
legacy日落-给一些算子增加InferDataTpye和Tiling日志 #4712
已合并
pan xiong创建于 16 天前
28 个文件变更+970-568
@@ -247,6 +247,16 @@ ge::graphStatus BatchToSpaceTiling::SetTilingData()
247 tilingData->cropLeft = crops_[2];247 tilingData->cropLeft = crops_[2];
248 tilingData->cropRight = crops_[3];248 tilingData->cropRight = crops_[3];
249 249 
250+ OP_LOGI(context_,
251+ "TilingData: inShape=[%ld,%ld,%ld,%ld] outShape=[%ld,%ld,%ld,%ld] totalCount=%lu "
252+ "perCoreCount=%lu ubFactor=%u bufferSize=%u blockSize=%ld cropTop=%ld cropBottom=%ld "
253+ "cropLeft=%ld cropRight=%ld",
254+ tilingData->inShape[0], tilingData->inShape[1], tilingData->inShape[2], tilingData->inShape[3],
255+ tilingData->outShape[0], tilingData->outShape[1], tilingData->outShape[2], tilingData->outShape[3],
256+ tilingData->totalCount, tilingData->perCoreCount, tilingData->ubFactor, tilingData->bufferSize,
257+ tilingData->blockSize, tilingData->cropTop, tilingData->cropBottom, tilingData->cropLeft,
258+ tilingData->cropRight);
259+ 
250 const uint64_t tilingKey = GET_TPL_TILING_KEY(ubAxis_);260 const uint64_t tilingKey = GET_TPL_TILING_KEY(ubAxis_);
251 OP_LOGI(context_, "tilingKey is %lu, ubAxis %u", tilingKey, ubAxis_);261 OP_LOGI(context_, "tilingKey is %lu, ubAxis %u", tilingKey, ubAxis_);
252 context_->SetTilingKey(tilingKey);262 context_->SetTilingKey(tilingKey);
@@ -285,6 +295,7 @@ ge::graphStatus BatchToSpaceTiling::DoTiling()
285 295 
286static ge::graphStatus BatchToSpaceTilingFunc(gert::TilingContext* context)296static ge::graphStatus BatchToSpaceTilingFunc(gert::TilingContext* context)
287{297{
298+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
288 BatchToSpaceTiling tiling(context);299 BatchToSpaceTiling tiling(context);
289 return tiling.DoTiling();300 return tiling.DoTiling();
290}301}
@@ -119,8 +119,24 @@ ge::graphStatus BatchToSpaceInferShapeHelper::Inference()
119static ge::graphStatus Infershape4BatchToSpace(gert::InferShapeContext* context)119static ge::graphStatus Infershape4BatchToSpace(gert::InferShapeContext* context)
120{120{
121 BatchToSpaceInferShapeHelper helper(context);121 BatchToSpaceInferShapeHelper helper(context);
122- return helper.Inference();122+ const ge::graphStatus ret = helper.Inference();
123+ if (ret != ge::GRAPH_SUCCESS) {
124+ return ret;
125+ }
126+ const gert::Shape* yShape = context->GetOutputShape(OUTPUT_IDX_Y);
127+ OP_CHECK_NULL_WITH_CONTEXT(context, yShape);
128+ OP_LOGI(context->GetNodeName(), "BatchToSpace output shape: %s.", Ops::Base::ToString(*yShape).c_str());
129+ return ge::GRAPH_SUCCESS;
123}130}
124 131 
125-IMPL_OP_INFERSHAPE(BatchToSpace).InferShape(Infershape4BatchToSpace).InputsDataDependency({INPUT_IDX_CROPS});132+static ge::graphStatus InferDataType4BatchToSpace(gert::InferDataTypeContext* context)
133+{
134+ context->SetOutputDataType(OUTPUT_IDX_Y, context->GetInputDataType(INPUT_IDX_X));
135+ return ge::GRAPH_SUCCESS;
136+}
137+ 
138+IMPL_OP_INFERSHAPE(BatchToSpace)
139+ .InferShape(Infershape4BatchToSpace)
140+ .InferDataType(InferDataType4BatchToSpace)
141+ .InputsDataDependency({INPUT_IDX_CROPS});
126} // namespace ops142} // namespace ops
@@ -21,6 +21,7 @@ struct CircularPadGradCompileInfo {};
21 21 
22static ge::graphStatus CircularPadGradTiling(gert::TilingContext* context)22static ge::graphStatus CircularPadGradTiling(gert::TilingContext* context)
23{23{
24+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
24 OP_LOGD(context->GetNodeName(), "CircularPadGradTiling running begin");25 OP_LOGD(context->GetNodeName(), "CircularPadGradTiling running begin");
25 PadV3GradACTiling tilingObject(context);26 PadV3GradACTiling tilingObject(context);
26 tilingObject.isCircularPadGrad_ = true;27 tilingObject.isCircularPadGrad_ = true;
@@ -0,0 +1,76 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#include "log/log.h"
12+#include "op_host/util/const_util.h"
13+#include "op_host/util/shape_util.h"
14+#include "register/op_impl_registry.h"
15+ 
16+using namespace ge;
17+ 
18+namespace ops {
19+static constexpr size_t INPUT_IDX_X = 0;
20+static constexpr size_t INPUT_IDX_PADDINGS = 1;
21+static constexpr size_t OUTPUT_IDX_Y = 0;
22+static constexpr size_t PADDING_PAIR_SIZE = 2;
23+static constexpr int64_t UNKNOWN_DIM = -1;
24+ 
25+static ge::graphStatus InferShape4CircularPadGrad(gert::InferShapeContext* context)
26+{
27+ const gert::Shape* xShape = context->GetInputShape(INPUT_IDX_X);
28+ OP_CHECK_NULL_WITH_CONTEXT(context, xShape);
29+ gert::Shape* yShape = context->GetOutputShape(OUTPUT_IDX_Y);
30+ OP_CHECK_NULL_WITH_CONTEXT(context, yShape);
31+ 
32+ if (Ops::Base::IsUnknownRank(*xShape)) {
33+ Ops::Base::SetUnknownRank(*yShape);
34+ OP_LOGI(context->GetNodeName(), "CircularPadGrad output shape: %s.", Ops::Base::ToString(*yShape).c_str());
35+ return ge::GRAPH_SUCCESS;
36+ }
37+ 
38+ gert::Shape paddings;
39+ if (!Ops::Base::GetConstIntToShape<gert::InferShapeContext>(context, INPUT_IDX_PADDINGS, paddings)) {
40+ yShape->SetDimNum(xShape->GetDimNum());
41+ for (size_t i = 0; i < xShape->GetDimNum(); ++i) {
42+ yShape->SetDim(i, UNKNOWN_DIM);
43+ }
44+ OP_LOGI(context->GetNodeName(), "CircularPadGrad output shape: %s.", Ops::Base::ToString(*yShape).c_str());
45+ return ge::GRAPH_SUCCESS;
46+ }
47+ 
48+ OP_CHECK_IF(paddings.GetDimNum() != xShape->GetDimNum() * PADDING_PAIR_SIZE,
49+ OP_LOGE(context->GetNodeName(), "The paddings element count must be twice the x rank."),
50+ return ge::GRAPH_FAILED);
51+ *yShape = *xShape;
52+ for (size_t i = 0; i < xShape->GetDimNum(); ++i) {
53+ const int64_t xDim = xShape->GetDim(i);
54+ if (xDim != UNKNOWN_DIM) {
55+ const int64_t yDim = xDim - paddings.GetDim(PADDING_PAIR_SIZE * i) -
56+ paddings.GetDim(PADDING_PAIR_SIZE * i + 1);
57+ OP_CHECK_IF(yDim < 0, OP_LOGE(context->GetNodeName(), "The output dimension must not be negative."),
58+ return ge::GRAPH_FAILED);
59+ yShape->SetDim(i, yDim);
60+ }
61+ }
62+ OP_LOGI(context->GetNodeName(), "CircularPadGrad output shape: %s.", Ops::Base::ToString(*yShape).c_str());
63+ return ge::GRAPH_SUCCESS;
64+}
65+ 
66+static ge::graphStatus InferDataType4CircularPadGrad(gert::InferDataTypeContext* context)
67+{
68+ context->SetOutputDataType(OUTPUT_IDX_Y, context->GetInputDataType(INPUT_IDX_X));
69+ return ge::GRAPH_SUCCESS;
70+}
71+ 
72+IMPL_OP_INFERSHAPE(CircularPadGrad)
73+ .InferShape(InferShape4CircularPadGrad)
74+ .InferDataType(InferDataType4CircularPadGrad)
75+ .InputsDataDependency({INPUT_IDX_PADDINGS});
76+} // namespace ops
@@ -40,18 +40,15 @@ constexpr int64_t SIMT_DCACHE_SIZE = 64 * 1024;
40// ============================================================================40// ============================================================================
41// Helper: Get platform info (ubSize, coreNum)41// Helper: Get platform info (ubSize, coreNum)
42// ============================================================================42// ============================================================================
43-static ge::graphStatus GetPlatformInfo(gert::TilingContext* context,43+static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t* ubSize, int64_t* coreNum)
44- uint64_t* ubSize, int64_t* coreNum)
45{44{
46 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();45 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
47 OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);46 OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);
48 auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);47 auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);
49 *coreNum = ascendcPlatform.GetCoreNumAiv();48 *coreNum = ascendcPlatform.GetCoreNumAiv();
50- OP_CHECK_IF(*coreNum == 0, OP_LOGE(context, "coreNum is 0"),49+ OP_CHECK_IF(*coreNum == 0, OP_LOGE(context, "coreNum is 0"), return ge::GRAPH_FAILED);
51- return ge::GRAPH_FAILED);
52 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, *ubSize);50 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, *ubSize);
53- OP_CHECK_IF(*ubSize == 0, OP_LOGE(context, "ubSize is 0"),51+ OP_CHECK_IF(*ubSize == 0, OP_LOGE(context, "ubSize is 0"), return ge::GRAPH_FAILED);
54- return ge::GRAPH_FAILED);
55 return ge::GRAPH_SUCCESS;52 return ge::GRAPH_SUCCESS;
56}53}
57 54 
@@ -61,15 +58,22 @@ static ge::graphStatus GetPlatformInfo(gert::TilingContext* context,
61static int64_t GetDtypeSize(ge::DataType dataType)58static int64_t GetDtypeSize(ge::DataType dataType)
62{59{
63 switch (dataType) {60 switch (dataType) {
64- case ge::DT_FLOAT16: case ge::DT_BF16:61+ case ge::DT_FLOAT16:
65- case ge::DT_INT16: case ge::DT_UINT16:62+ case ge::DT_BF16:
63+ case ge::DT_INT16:
64+ case ge::DT_UINT16:
66 return 2;65 return 2;
67- case ge::DT_FLOAT: case ge::DT_INT32: case ge::DT_UINT32:66+ case ge::DT_FLOAT:
67+ case ge::DT_INT32:
68+ case ge::DT_UINT32:
68 return 4;69 return 4;
69- case ge::DT_DOUBLE: case ge::DT_INT64: case ge::DT_UINT64:70+ case ge::DT_DOUBLE:
71+ case ge::DT_INT64:
72+ case ge::DT_UINT64:
70 case ge::DT_COMPLEX64:73 case ge::DT_COMPLEX64:
71 return 8;74 return 8;
72- case ge::DT_INT8: case ge::DT_UINT8:75+ case ge::DT_INT8:
76+ case ge::DT_UINT8:
73 return 1;77 return 1;
74 default:78 default:
75 return 4;79 return 4;
@@ -84,10 +88,8 @@ ge::graphStatus TilingDiagFlatArch35(gert::TilingContext* context, DiagFlatTilin
84 // 1. Get platform info88 // 1. Get platform info
85 uint64_t ubSize;89 uint64_t ubSize;
86 int64_t hwCoreNum;90 int64_t hwCoreNum;
87- OP_CHECK_IF(91+ OP_CHECK_IF(GetPlatformInfo(context, &ubSize, &hwCoreNum) != ge::GRAPH_SUCCESS,
88- GetPlatformInfo(context, &ubSize, &hwCoreNum) != ge::GRAPH_SUCCESS,92+ OP_LOGE(context, "GetPlatformInfo error"), return ge::GRAPH_FAILED);
89- OP_LOGE(context, "GetPlatformInfo error"),
90- return ge::GRAPH_FAILED);
91 93 
92 // 2. Get input shape and numInput94 // 2. Get input shape and numInput
93 auto inputX = context->GetInputShape(0);95 auto inputX = context->GetInputShape(0);
@@ -112,8 +114,7 @@ ge::graphStatus TilingDiagFlatArch35(gert::TilingContext* context, DiagFlatTilin
112 int64_t outTotal = outWidth * outWidth;114 int64_t outTotal = outWidth * outWidth;
113 115 
114 // 6. Multi-core split116 // 6. Multi-core split
115- int64_t realCoreNum = std::min(hwCoreNum,117+ int64_t realCoreNum = std::min(hwCoreNum, std::max<int64_t>(1, (numInput + outTotal) / MIN_WORK_PER_CORE / 2));
116- std::max<int64_t>(1, (numInput + outTotal) / MIN_WORK_PER_CORE / 2));
117 118 
118 // 7. outPerCore119 // 7. outPerCore
119 int64_t outPerCore = 0;120 int64_t outPerCore = 0;
@@ -122,25 +123,23 @@ ge::graphStatus TilingDiagFlatArch35(gert::TilingContext* context, DiagFlatTilin
122 }123 }
123 124 
124 // 8. tileLength125 // 8. tileLength
125- OP_CHECK_IF(dtypeSize <= 0, OP_LOGE(context, "invalid dtypeSize %ld", dtypeSize),126+ OP_CHECK_IF(dtypeSize <= 0, OP_LOGE(context, "invalid dtypeSize %ld", dtypeSize), return ge::GRAPH_FAILED);
126- return ge::GRAPH_FAILED);
127 int64_t ubPerBuf = (ubSize - SIMT_DCACHE_SIZE) / DIAG_FLAT_BUFFER_NUM;127 int64_t ubPerBuf = (ubSize - SIMT_DCACHE_SIZE) / DIAG_FLAT_BUFFER_NUM;
128 int64_t tileLength = std::min<int64_t>({ubPerBuf / dtypeSize, outPerCore});128 int64_t tileLength = std::min<int64_t>({ubPerBuf / dtypeSize, outPerCore});
129 129 
130 // 9. Fill output struct130 // 9. Fill output struct
131- out->numInput = numInput;131+ out->numInput = numInput;
132- out->diagonal = diagonal;132+ out->diagonal = diagonal;
133- out->outWidth = outWidth;133+ out->outWidth = outWidth;
134- out->outTotal = outTotal;134+ out->outTotal = outTotal;
135- out->outPerCore = outPerCore;135+ out->outPerCore = outPerCore;
136- out->tileLength = tileLength;136+ out->tileLength = tileLength;
137 out->realCoreNum = realCoreNum;137 out->realCoreNum = realCoreNum;
138 out->localMemSize = static_cast<uint32_t>(ubSize - SIMT_DCACHE_SIZE);138 out->localMemSize = static_cast<uint32_t>(ubSize - SIMT_DCACHE_SIZE);
139 139 
140 // 10. Set context-level params (common to both callers)140 // 10. Set context-level params (common to both callers)
141 auto ret = context->SetLocalMemorySize(out->localMemSize);141 auto ret = context->SetLocalMemorySize(out->localMemSize);
142- OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,142+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS, OP_LOGE(context, "set local memory size failed."), return ret);
143- OP_LOGE(context, "set local memory size failed."), return ret);
144 143 
145 context->SetBlockDim(realCoreNum);144 context->SetBlockDim(realCoreNum);
146 145 
@@ -156,28 +155,31 @@ ge::graphStatus TilingDiagFlatArch35(gert::TilingContext* context, DiagFlatTilin
156// ============================================================================155// ============================================================================
157static ge::graphStatus DiagFlatTilingFunc(gert::TilingContext* context)156static ge::graphStatus DiagFlatTilingFunc(gert::TilingContext* context)
158{157{
158+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
159 DiagFlatTilingOutput out;159 DiagFlatTilingOutput out;
160- OP_CHECK_IF(160+ OP_CHECK_IF(TilingDiagFlatArch35(context, &out) != ge::GRAPH_SUCCESS,
161- TilingDiagFlatArch35(context, &out) != ge::GRAPH_SUCCESS,161+ OP_LOGE(context, "TilingDiagFlatArch35 error"), return ge::GRAPH_FAILED);
162- OP_LOGE(context, "TilingDiagFlatArch35 error"),
163- return ge::GRAPH_FAILED);
164 162 
165 // Fill DiagFlat's own TilingData163 // Fill DiagFlat's own TilingData
166 DiagFlatArch35TilingData* tiling = context->GetTilingData<DiagFlatArch35TilingData>();164 DiagFlatArch35TilingData* tiling = context->GetTilingData<DiagFlatArch35TilingData>();
167 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);165 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);
168- OP_CHECK_IF(166+ OP_CHECK_IF(memset_s(tiling, sizeof(DiagFlatArch35TilingData), 0, sizeof(DiagFlatArch35TilingData)) != EOK,
169- memset_s(tiling, sizeof(DiagFlatArch35TilingData), 0, sizeof(DiagFlatArch35TilingData)) != EOK,167+ OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
170- OP_LOGE(context, "set tiling data error"),
171- return ge::GRAPH_FAILED);
172 168 
173- tiling->numInput = out.numInput;169+ tiling->numInput = out.numInput;
174- tiling->diagonal = out.diagonal;170+ tiling->diagonal = out.diagonal;
175- tiling->outWidth = out.outWidth;171+ tiling->outWidth = out.outWidth;
176- tiling->outTotal = out.outTotal;172+ tiling->outTotal = out.outTotal;
177- tiling->outPerCore = out.outPerCore;173+ tiling->outPerCore = out.outPerCore;
178- tiling->tileLength = out.tileLength;174+ tiling->tileLength = out.tileLength;
179 tiling->realCoreNum = out.realCoreNum;175 tiling->realCoreNum = out.realCoreNum;
180 176 
177+ OP_LOGI(context->GetNodeName(),
178+ "DiagFlat TilingData: numInput=%ld diagonal=%ld outWidth=%ld outTotal=%ld outPerCore=%ld "
179+ "tileLength=%ld realCoreNum=%ld",
180+ tiling->numInput, tiling->diagonal, tiling->outWidth, tiling->outTotal, tiling->outPerCore,
181+ tiling->tileLength, tiling->realCoreNum);
182+ 
181 // DiagFlat's own TilingKey183 // DiagFlat's own TilingKey
182 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(3501));184 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(3501));
183 185 
@@ -197,8 +199,6 @@ struct DiagFlatCompileInfo {};
197// ============================================================================199// ============================================================================
198// Tiling registration200// Tiling registration
199// ============================================================================201// ============================================================================
200-IMPL_OP_OPTILING(DiagFlat)202+IMPL_OP_OPTILING(DiagFlat).Tiling(DiagFlatTilingFunc).TilingParse<DiagFlatCompileInfo>(TilingParseForDiagFlat);
201- .Tiling(DiagFlatTilingFunc)
202- .TilingParse<DiagFlatCompileInfo>(TilingParseForDiagFlat);
203 203 
204} // namespace optiling204} // namespace optiling
@@ -66,7 +66,13 @@ static ge::graphStatus InfershapeForDiagFlat(gert::InferShapeContext* context)
66 return ge::GRAPH_SUCCESS;66 return ge::GRAPH_SUCCESS;
67}67}
68 68 
69-IMPL_OP_INFERSHAPE(DiagFlat).InferShape(InfershapeForDiagFlat);69+static ge::graphStatus InferDataTypeForDiagFlat(gert::InferDataTypeContext* context)
70+{
71+ context->SetOutputDataType(DIAGFLAT_OUT_Y_IDX, context->GetInputDataType(DIAGFLAT_IN_X_IDX));
72+ return ge::GRAPH_SUCCESS;
73+}
74+ 
75+IMPL_OP_INFERSHAPE(DiagFlat).InferShape(InfershapeForDiagFlat).InferDataType(InferDataTypeForDiagFlat);
70// -------------------DiagFlat Ops END---------------------76// -------------------DiagFlat Ops END---------------------
71 77 
72} // namespace ops78} // namespace ops
@@ -43,28 +43,22 @@ constexpr uint32_t WS_SYS_SIZE = 0U;
43// ============================================================================43// ============================================================================
44// Helper: Get platform info (ubSize, coreNum)44// Helper: Get platform info (ubSize, coreNum)
45// ============================================================================45// ============================================================================
46-static ge::graphStatus GetPlatformInfo(gert::TilingContext* context,46+static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t* ubSize, int64_t* coreNum)
47- uint64_t* ubSize, int64_t* coreNum)
48{47{
49 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();48 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
50 OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);49 OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);
51 auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);50 auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);
52 *coreNum = ascendcPlatform.GetCoreNumAiv();51 *coreNum = ascendcPlatform.GetCoreNumAiv();
53- OP_CHECK_IF(*coreNum == 0, OP_LOGE(context, "coreNum is 0"),52+ OP_CHECK_IF(*coreNum == 0, OP_LOGE(context, "coreNum is 0"), return ge::GRAPH_FAILED);
54- return ge::GRAPH_FAILED);
55 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, *ubSize);53 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, *ubSize);
56- OP_CHECK_IF(*ubSize == 0, OP_LOGE(context, "ubSize is 0"),54+ OP_CHECK_IF(*ubSize == 0, OP_LOGE(context, "ubSize is 0"), return ge::GRAPH_FAILED);
57- return ge::GRAPH_FAILED);
58 return ge::GRAPH_SUCCESS;55 return ge::GRAPH_SUCCESS;
59}56}
60 57 
61// ============================================================================58// ============================================================================
62// Helper: 32B alignment59// Helper: 32B alignment
63// ============================================================================60// ============================================================================
64-static int64_t AlignUp(int64_t n, int64_t align)61+static int64_t AlignUp(int64_t n, int64_t align) { return ((n + align - 1) / align) * align; }
65-{
66- return ((n + align - 1) / align) * align;
67-}
68 62 
69// ============================================================================63// ============================================================================
70// Helper: Get dtype size64// Helper: Get dtype size
@@ -72,15 +66,23 @@ static int64_t AlignUp(int64_t n, int64_t align)
72static int64_t GetDtypeSize(ge::DataType dataType)66static int64_t GetDtypeSize(ge::DataType dataType)
73{67{
74 switch (dataType) {68 switch (dataType) {
75- case ge::DT_FLOAT16: case ge::DT_BF16:69+ case ge::DT_FLOAT16:
76- case ge::DT_INT16: case ge::DT_UINT16:70+ case ge::DT_BF16:
71+ case ge::DT_INT16:
72+ case ge::DT_UINT16:
77 return 2;73 return 2;
78- case ge::DT_FLOAT: case ge::DT_INT32: case ge::DT_UINT32:74+ case ge::DT_FLOAT:
75+ case ge::DT_INT32:
76+ case ge::DT_UINT32:
79 return 4;77 return 4;
80- case ge::DT_DOUBLE: case ge::DT_INT64: case ge::DT_UINT64:78+ case ge::DT_DOUBLE:
79+ case ge::DT_INT64:
80+ case ge::DT_UINT64:
81 case ge::DT_COMPLEX64:81 case ge::DT_COMPLEX64:
82 return 8;82 return 8;
83- case ge::DT_INT8: case ge::DT_UINT8: case ge::DT_BOOL:83+ case ge::DT_INT8:
84+ case ge::DT_UINT8:
85+ case ge::DT_BOOL:
84 return 1;86 return 1;
85 default:87 default:
86 return 4;88 return 4;
@@ -90,29 +92,37 @@ static int64_t GetDtypeSize(ge::DataType dataType)
90// ============================================================================92// ============================================================================
91// 1D→2D via diag_flat (one-way: diag_v2 → diag_flat)93// 1D→2D via diag_flat (one-way: diag_v2 → diag_flat)
92// ============================================================================94// ============================================================================
95+static void LogTilingData(gert::TilingContext* context, const DiagV2Arch35TilingData* tiling)
96+{
97+ OP_LOGI(context->GetNodeName(),
98+ "DiagV2 TilingData: diagonal=%ld realCoreNum=%ld tileLength=%ld xWidth=%ld xHeight=%ld gmOffset=%ld "
99+ "numOut=%ld numPerCore=%ld tailNum=%ld threadNum=%ld numInput=%ld outWidth=%ld outTotal=%ld "
100+ "outPerCore=%ld",
101+ tiling->diagonal, tiling->realCoreNum, tiling->tileLength, tiling->xWidth, tiling->xHeight,
102+ tiling->gmOffset, tiling->numOut, tiling->numPerCore, tiling->tailNum, tiling->threadNum, tiling->numInput,
103+ tiling->outWidth, tiling->outTotal, tiling->outPerCore);
104+}
105+ 
93static inline ge::graphStatus ProcessDiagFlat(gert::TilingContext* context)106static inline ge::graphStatus ProcessDiagFlat(gert::TilingContext* context)
94{107{
95 DiagFlatTilingOutput out;108 DiagFlatTilingOutput out;
96- OP_CHECK_IF(109+ OP_CHECK_IF(TilingDiagFlatArch35(context, &out) != ge::GRAPH_SUCCESS,
97- TilingDiagFlatArch35(context, &out) != ge::GRAPH_SUCCESS,110+ OP_LOGE(context, "TilingDiagFlatArch35 error"), return ge::GRAPH_FAILED);
98- OP_LOGE(context, "TilingDiagFlatArch35 error"),
99- return ge::GRAPH_FAILED);
100 111 
101 // Fill diag_v2's own TilingData from diag_flat's output112 // Fill diag_v2's own TilingData from diag_flat's output
102 DiagV2Arch35TilingData* tiling = context->GetTilingData<DiagV2Arch35TilingData>();113 DiagV2Arch35TilingData* tiling = context->GetTilingData<DiagV2Arch35TilingData>();
103 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);114 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);
104- OP_CHECK_IF(115+ OP_CHECK_IF(memset_s(tiling, sizeof(DiagV2Arch35TilingData), 0, sizeof(DiagV2Arch35TilingData)) != EOK,
105- memset_s(tiling, sizeof(DiagV2Arch35TilingData), 0, sizeof(DiagV2Arch35TilingData)) != EOK,116+ OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
106- OP_LOGE(context, "set tiling data error"),
107- return ge::GRAPH_FAILED);
108 117 
109- tiling->diagonal = out.diagonal;118+ tiling->diagonal = out.diagonal;
110 tiling->realCoreNum = out.realCoreNum;119 tiling->realCoreNum = out.realCoreNum;
111- tiling->tileLength = out.tileLength;120+ tiling->tileLength = out.tileLength;
112- tiling->numInput = out.numInput;121+ tiling->numInput = out.numInput;
113- tiling->outWidth = out.outWidth;122+ tiling->outWidth = out.outWidth;
114- tiling->outTotal = out.outTotal;123+ tiling->outTotal = out.outTotal;
115- tiling->outPerCore = out.outPerCore;124+ tiling->outPerCore = out.outPerCore;
125+ LogTilingData(context, tiling);
116 126 
117 // Select diag_v2's own TilingKey: IS_1D_INPUT=1 → DiagFlatSimd kernel127 // Select diag_v2's own TilingKey: IS_1D_INPUT=1 → DiagFlatSimd kernel
118 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(1));128 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(1));
@@ -127,15 +137,13 @@ static inline ge::graphStatus ProcessDiagFlat(gert::TilingContext* context)
127// ============================================================================137// ============================================================================
128// 2D→1D tiling (IS_1D_INPUT=0)138// 2D→1D tiling (IS_1D_INPUT=0)
129// ============================================================================139// ============================================================================
130-static ge::graphStatus Tiling2Dto1D(gert::TilingContext* context,140+static ge::graphStatus Tiling2Dto1D(gert::TilingContext* context, int64_t hwCoreNum, int64_t dtypeSize, uint64_t ubSize)
131- int64_t hwCoreNum, int64_t dtypeSize,
132- uint64_t ubSize)
133{141{
134 auto inputX = context->GetInputShape(0);142 auto inputX = context->GetInputShape(0);
135 OP_CHECK_NULL_WITH_CONTEXT(context, inputX);143 OP_CHECK_NULL_WITH_CONTEXT(context, inputX);
136 auto inputShape = inputX->GetStorageShape();144 auto inputShape = inputX->GetStorageShape();
137 int64_t xHeight = inputShape.GetDim(0);145 int64_t xHeight = inputShape.GetDim(0);
138- int64_t xWidth = inputShape.GetDim(1);146+ int64_t xWidth = inputShape.GetDim(1);
139 147 
140 auto attrs = context->GetAttrs();148 auto attrs = context->GetAttrs();
141 OP_CHECK_NULL_WITH_CONTEXT(context, attrs);149 OP_CHECK_NULL_WITH_CONTEXT(context, attrs);
@@ -177,21 +185,20 @@ static ge::graphStatus Tiling2Dto1D(gert::TilingContext* context,
177 185 
178 DiagV2Arch35TilingData* tiling = context->GetTilingData<DiagV2Arch35TilingData>();186 DiagV2Arch35TilingData* tiling = context->GetTilingData<DiagV2Arch35TilingData>();
179 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);187 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);
180- OP_CHECK_IF(188+ OP_CHECK_IF(memset_s(tiling, sizeof(DiagV2Arch35TilingData), 0, sizeof(DiagV2Arch35TilingData)) != EOK,
181- memset_s(tiling, sizeof(DiagV2Arch35TilingData), 0, sizeof(DiagV2Arch35TilingData)) != EOK,189+ OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
182- OP_LOGE(context, "set tiling data error"),
183- return ge::GRAPH_FAILED);
184 190 
185- tiling->xWidth = xWidth;191+ tiling->xWidth = xWidth;
186- tiling->xHeight = xHeight;192+ tiling->xHeight = xHeight;
187- tiling->gmOffset = gmOffset;193+ tiling->gmOffset = gmOffset;
188- tiling->numOut = numOut;194+ tiling->numOut = numOut;
189 tiling->realCoreNum = realCoreNum;195 tiling->realCoreNum = realCoreNum;
190- tiling->numPerCore = numPerCore;196+ tiling->numPerCore = numPerCore;
191- tiling->tailNum = tailNum;197+ tiling->tailNum = tailNum;
192- tiling->diagonal = diagonal;198+ tiling->diagonal = diagonal;
193- tiling->tileLength = tileLength;199+ tiling->tileLength = tileLength;
194- tiling->threadNum = threadNum;200+ tiling->threadNum = threadNum;
201+ LogTilingData(context, tiling);
195 202 
196 context->SetLocalMemorySize(ubSize - 64 * 1024);203 context->SetLocalMemorySize(ubSize - 64 * 1024);
197 204 
@@ -204,6 +211,7 @@ static ge::graphStatus Tiling2Dto1D(gert::TilingContext* context,
204// ============================================================================211// ============================================================================
205static ge::graphStatus DiagV2TilingFunc(gert::TilingContext* context)212static ge::graphStatus DiagV2TilingFunc(gert::TilingContext* context)
206{213{
214+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
207 auto inputX = context->GetInputShape(0);215 auto inputX = context->GetInputShape(0);
208 OP_CHECK_NULL_WITH_CONTEXT(context, inputX);216 OP_CHECK_NULL_WITH_CONTEXT(context, inputX);
209 auto inputShape = inputX->GetStorageShape();217 auto inputShape = inputX->GetStorageShape();
@@ -217,10 +225,8 @@ static ge::graphStatus DiagV2TilingFunc(gert::TilingContext* context)
217 // 2D→1D path225 // 2D→1D path
218 uint64_t ubSize;226 uint64_t ubSize;
219 int64_t hwCoreNum;227 int64_t hwCoreNum;
220- OP_CHECK_IF(228+ OP_CHECK_IF(GetPlatformInfo(context, &ubSize, &hwCoreNum) != ge::GRAPH_SUCCESS,
221- GetPlatformInfo(context, &ubSize, &hwCoreNum) != ge::GRAPH_SUCCESS,229+ OP_LOGE(context, "GetPlatformInfo error"), return ge::GRAPH_FAILED);
222- OP_LOGE(context, "GetPlatformInfo error"),
223- return ge::GRAPH_FAILED);
224 230 
225 auto inputDesc = context->GetInputDesc(0);231 auto inputDesc = context->GetInputDesc(0);
226 OP_CHECK_NULL_WITH_CONTEXT(context, inputDesc);232 OP_CHECK_NULL_WITH_CONTEXT(context, inputDesc);
@@ -233,7 +239,7 @@ static ge::graphStatus DiagV2TilingFunc(gert::TilingContext* context)
233 OP_CHECK_NULL_WITH_CONTEXT(context, currentWorkspace);239 OP_CHECK_NULL_WITH_CONTEXT(context, currentWorkspace);
234 currentWorkspace[0] = WS_SYS_SIZE;240 currentWorkspace[0] = WS_SYS_SIZE;
235 241 
236- ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(0)); // IS_1D_INPUT=0242+ ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(0)); // IS_1D_INPUT=0
237 243 
238 return ge::GRAPH_SUCCESS;244 return ge::GRAPH_SUCCESS;
239}245}
@@ -249,8 +255,6 @@ static ge::graphStatus TilingParseForDiagV2([[maybe_unused]] gert::TilingParseCo
249// ============================================================================255// ============================================================================
250// Tiling registration256// Tiling registration
251// ============================================================================257// ============================================================================
252-IMPL_OP_OPTILING(DiagV2)258+IMPL_OP_OPTILING(DiagV2).Tiling(DiagV2TilingFunc).TilingParse<DiagV2CompileInfo>(TilingParseForDiagV2);
253- .Tiling(DiagV2TilingFunc)
254- .TilingParse<DiagV2CompileInfo>(TilingParseForDiagV2);
255 259 
256} // namespace optiling260} // namespace optiling
@@ -89,11 +89,18 @@ static ge::graphStatus Infershape4DiagV2(gert::InferShapeContext* context)
89 }89 }
90 90 
91 OP_LOGD(context, "output_y_shape = %s.", Ops::Base::ToString(*output_y_shape).c_str());91 OP_LOGD(context, "output_y_shape = %s.", Ops::Base::ToString(*output_y_shape).c_str());
92+ OP_LOGI(context, "DiagV2 output shape: %s.", Ops::Base::ToString(*output_y_shape).c_str());
92 OP_LOGD(context, "End to do DiagV2Infershape.");93 OP_LOGD(context, "End to do DiagV2Infershape.");
93 94 
94 return ge::GRAPH_SUCCESS;95 return ge::GRAPH_SUCCESS;
95}96}
96 97 
97-IMPL_OP_INFERSHAPE(DiagV2).InferShape(Infershape4DiagV2);98+static ge::graphStatus InferDataType4DiagV2(gert::InferDataTypeContext* context)
99+{
100+ context->SetOutputDataType(DiagV2_OUT_Y_IDX, context->GetInputDataType(DiagV2_IN_X_IDX));
101+ return ge::GRAPH_SUCCESS;
102+}
103+ 
104+IMPL_OP_INFERSHAPE(DiagV2).InferShape(Infershape4DiagV2).InferDataType(InferDataType4DiagV2);
98// -------------------DiagV2 Ops END---------------------105// -------------------DiagV2 Ops END---------------------
99-} // namespace ops106+} // namespace ops
@@ -489,6 +489,13 @@ void PadV3GradReplicationTiling::FillTilingData(PadV3GradReplicationTilingData*
489 tilingData->rightPad[i] = rightPad_[i];489 tilingData->rightPad[i] = rightPad_[i];
490 }490 }
491 491 
492+ OP_LOGI(context_->GetNodeName(),
493+ "PadV3GradReplication TilingData: dimNum=%u splitAxis=%u splitCount=%u splitSize=%u "
494+ "usedCoreNum=%u tilesPerCore=%u inputShape=%s outputShape=%s strideAligned=%s leftPad=%s rightPad=%s",
495+ tilingData->dimNum, tilingData->splitAxis, tilingData->splitCount, tilingData->splitSize,
496+ tilingData->usedCoreNum, tilingData->tilesPerCore, ToString(inputShape_, dimNum_).c_str(),
497+ ToString(outputShape_, dimNum_).c_str(), ToString(strideAligned_, dimNum_).c_str(),
498+ ToString(leftPad_, dimNum_).c_str(), ToString(rightPad_, dimNum_).c_str());
492 OP_LOGI(context_->GetNodeName(), "FillTilingData done.");499 OP_LOGI(context_->GetNodeName(), "FillTilingData done.");
493}500}
494 501 
@@ -567,6 +574,7 @@ static ge::graphStatus TilingPrepare4PadV3GradReplication(gert::TilingParseConte
567 574 
568IMPL_OP_OPTILING(PadV3GradReplication)575IMPL_OP_OPTILING(PadV3GradReplication)
569 .Tiling([](gert::TilingContext* context) -> ge::graphStatus {576 .Tiling([](gert::TilingContext* context) -> ge::graphStatus {
577+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
570 PadV3GradReplicationTiling tiling(context);578 PadV3GradReplicationTiling tiling(context);
571 return tiling.DoTiling();579 return tiling.DoTiling();
572 })580 })
@@ -0,0 +1,76 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#include "log/log.h"
12+#include "op_host/util/const_util.h"
13+#include "op_host/util/shape_util.h"
14+#include "register/op_impl_registry.h"
15+ 
16+using namespace ge;
17+ 
18+namespace ops {
19+static constexpr size_t INPUT_IDX_X = 0;
20+static constexpr size_t INPUT_IDX_PADDINGS = 1;
21+static constexpr size_t OUTPUT_IDX_Z = 0;
22+static constexpr size_t PADDING_PAIR_SIZE = 2;
23+static constexpr int64_t UNKNOWN_DIM = -1;
24+ 
25+static ge::graphStatus InferShape4PadV3GradReplication(gert::InferShapeContext* context)
26+{
27+ const gert::Shape* xShape = context->GetInputShape(INPUT_IDX_X);
28+ OP_CHECK_NULL_WITH_CONTEXT(context, xShape);
29+ gert::Shape* zShape = context->GetOutputShape(OUTPUT_IDX_Z);
30+ OP_CHECK_NULL_WITH_CONTEXT(context, zShape);
31+ 
32+ if (Ops::Base::IsUnknownRank(*xShape)) {
33+ Ops::Base::SetUnknownRank(*zShape);
34+ OP_LOGI(context->GetNodeName(), "PadV3GradReplication output shape: %s.", Ops::Base::ToString(*zShape).c_str());
35+ return ge::GRAPH_SUCCESS;
36+ }
37+ 
38+ gert::Shape paddings;
39+ if (!Ops::Base::GetConstIntToShape<gert::InferShapeContext>(context, INPUT_IDX_PADDINGS, paddings)) {
40+ zShape->SetDimNum(xShape->GetDimNum());
41+ for (size_t i = 0; i < xShape->GetDimNum(); ++i) {
42+ zShape->SetDim(i, UNKNOWN_DIM);
43+ }
44+ OP_LOGI(context->GetNodeName(), "PadV3GradReplication output shape: %s.", Ops::Base::ToString(*zShape).c_str());
45+ return ge::GRAPH_SUCCESS;
46+ }
47+ 
48+ OP_CHECK_IF(paddings.GetDimNum() != xShape->GetDimNum() * PADDING_PAIR_SIZE,
49+ OP_LOGE(context->GetNodeName(), "The paddings element count must be twice the x rank."),
50+ return ge::GRAPH_FAILED);
51+ *zShape = *xShape;
52+ for (size_t i = 0; i < xShape->GetDimNum(); ++i) {
53+ const int64_t xDim = xShape->GetDim(i);
54+ if (xDim != UNKNOWN_DIM) {
55+ const int64_t zDim = xDim - paddings.GetDim(PADDING_PAIR_SIZE * i) -
56+ paddings.GetDim(PADDING_PAIR_SIZE * i + 1);
57+ OP_CHECK_IF(zDim < 0, OP_LOGE(context->GetNodeName(), "The output dimension must not be negative."),
58+ return ge::GRAPH_FAILED);
59+ zShape->SetDim(i, zDim);
60+ }
61+ }
62+ OP_LOGI(context->GetNodeName(), "PadV3GradReplication output shape: %s.", Ops::Base::ToString(*zShape).c_str());
63+ return ge::GRAPH_SUCCESS;
64+}
65+ 
66+static ge::graphStatus InferDataType4PadV3GradReplication(gert::InferDataTypeContext* context)
67+{
68+ context->SetOutputDataType(OUTPUT_IDX_Z, context->GetInputDataType(INPUT_IDX_X));
69+ return ge::GRAPH_SUCCESS;
70+}
71+ 
72+IMPL_OP_INFERSHAPE(PadV3GradReplication)
73+ .InferShape(InferShape4PadV3GradReplication)
74+ .InferDataType(InferDataType4PadV3GradReplication)
75+ .InputsDataDependency({INPUT_IDX_PADDINGS});
76+} // namespace ops
@@ -25,8 +25,7 @@ static constexpr double MIN_CORE_UTIL_RATIO = 0.8;
25 25 
26class SliceLastDimTiling {26class SliceLastDimTiling {
27public:27public:
28- explicit SliceLastDimTiling(gert::TilingContext* context) : context_(context)28+ explicit SliceLastDimTiling(gert::TilingContext* context) : context_(context) {}
29- {}
30 ge::graphStatus DoTiling();29 ge::graphStatus DoTiling();
31 30 
32private:31private:
@@ -35,10 +34,10 @@ private:
35 ge::graphStatus ComputeAndSetTiling();34 ge::graphStatus ComputeAndSetTiling();
36 35 
37 void InitElementSizes();36 void InitElementSizes();
38- void DoCacheLineTiling(37+ void DoCacheLineTiling(int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct, int64_t& minUbFactor,
39- int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct, int64_t& minUbFactor, int64_t& outerProduct);38+ int64_t& outerProduct);
40- void DoTilingSearch(39+ void DoTilingSearch(int64_t alignedLast, int32_t startAxis, int64_t minUbFactor, int64_t clInnerProduct,
41- int64_t alignedLast, int32_t startAxis, int64_t minUbFactor, int64_t clInnerProduct, int64_t outerProduct);40+ int64_t outerProduct);
42 ge::graphStatus SetTilingData();41 ge::graphStatus SetTilingData();
43 42 
44 gert::TilingContext* context_;43 gert::TilingContext* context_;
@@ -78,32 +77,28 @@ ge::graphStatus SliceLastDimTiling::GetSocInfo()
78 coreNum_ = ascendcPlatform.GetCoreNumAiv();77 coreNum_ = ascendcPlatform.GetCoreNumAiv();
79 OP_CHECK_IF(78 OP_CHECK_IF(
80 (coreNum_ == 0U),79 (coreNum_ == 0U),
81- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(80+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "coreNum", std::to_string(coreNum_).c_str(),
82- context_->GetNodeName(), "coreNum", std::to_string(coreNum_).c_str(), "The core num must be positive."),81+ "The core num must be positive."),
83 return ge::GRAPH_FAILED);82 return ge::GRAPH_FAILED);
84 uint64_t ubSize = 0;83 uint64_t ubSize = 0;
85 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);84 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);
86- OP_CHECK_IF(85+ OP_CHECK_IF((ubSize == 0U),
87- (ubSize == 0U),86+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(),
88- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(87+ "Failed to get ub size, ub size must be positive."),
89- context_->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(),88+ return ge::GRAPH_FAILED);
90- "Failed to get ub size, ub size must be positive."),
91- return ge::GRAPH_FAILED);
92 ubSize_ = static_cast<uint32_t>(ubSize);89 ubSize_ = static_cast<uint32_t>(ubSize);
93 cacheLineSize_ = Ops::Base::GetCacheLineSize(context_);90 cacheLineSize_ = Ops::Base::GetCacheLineSize(context_);
94- OP_CHECK_IF(91+ OP_CHECK_IF((cacheLineSize_ == 0U),
95- (cacheLineSize_ == 0U),92+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
96- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(93+ context_->GetNodeName(), "cacheLineSize", std::to_string(cacheLineSize_).c_str(),
97- context_->GetNodeName(), "cacheLineSize", std::to_string(cacheLineSize_).c_str(),94+ "Failed to get cache line size, cache line size must be positive."),
98- "Failed to get cache line size, cache line size must be positive."),95+ return ge::GRAPH_FAILED);
99- return ge::GRAPH_FAILED);
100 ubBlockSize_ = Ops::Base::GetUbBlockSize(context_);96 ubBlockSize_ = Ops::Base::GetUbBlockSize(context_);
101- OP_CHECK_IF(97+ OP_CHECK_IF((ubBlockSize_ == 0U),
102- (ubBlockSize_ == 0U),98+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ubBlockSize",
103- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(99+ std::to_string(ubBlockSize_).c_str(),
104- context_->GetNodeName(), "ubBlockSize", std::to_string(ubBlockSize_).c_str(),100+ "Failed to get block size, block size must be positive."),
105- "Failed to get block size, block size must be positive."),101+ return ge::GRAPH_FAILED);
106- return ge::GRAPH_FAILED);
107 return ge::GRAPH_SUCCESS;102 return ge::GRAPH_SUCCESS;
108}103}
109 104 
@@ -113,21 +108,19 @@ ge::graphStatus SliceLastDimTiling::GetParams()
113 OP_CHECK_NULL_WITH_CONTEXT(context_, inputValueDesc);108 OP_CHECK_NULL_WITH_CONTEXT(context_, inputValueDesc);
114 auto inputDataType = inputValueDesc->GetDataType();109 auto inputDataType = inputValueDesc->GetDataType();
115 dSize_ = ge::GetSizeByDataType(inputDataType);110 dSize_ = ge::GetSizeByDataType(inputDataType);
116- OP_CHECK_IF(111+ OP_CHECK_IF(dSize_ <= 0,
117- dSize_ <= 0,112+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "dSize", std::to_string(dSize_).c_str(),
118- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(113+ "The data type size must be positive."),
119- context_->GetNodeName(), "dSize", std::to_string(dSize_).c_str(), "The data type size must be positive."),114+ return ge::GRAPH_FAILED);
120- return ge::GRAPH_FAILED);
121 115 
122 auto xInputShape = context_->GetInputShape(INPUT_IDX_X);116 auto xInputShape = context_->GetInputShape(INPUT_IDX_X);
123 OP_CHECK_NULL_WITH_CONTEXT(context_, xInputShape);117 OP_CHECK_NULL_WITH_CONTEXT(context_, xInputShape);
124 auto xShape = xInputShape->GetStorageShape();118 auto xShape = xInputShape->GetStorageShape();
125 rank_ = static_cast<int64_t>(xShape.GetDimNum());119 rank_ = static_cast<int64_t>(xShape.GetDimNum());
126- OP_CHECK_IF(120+ OP_CHECK_IF(rank_ < 1 || rank_ > static_cast<int64_t>(MAX_RANK),
127- rank_ < 1 || rank_ > static_cast<int64_t>(MAX_RANK),121+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context_->GetNodeName(), "x", std::to_string(rank_).c_str(),
128- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(122+ "The shape dim of x must be in [1, 8]."),
129- context_->GetNodeName(), "x", std::to_string(rank_).c_str(), "The shape dim of x must be in [1, 8]."),123+ return ge::GRAPH_FAILED);
130- return ge::GRAPH_FAILED);
131 for (int64_t i = 0; i < rank_; ++i) {124 for (int64_t i = 0; i < rank_; ++i) {
132 inShape_[i] = xShape.GetDim(i);125 inShape_[i] = xShape.GetDim(i);
133 }126 }
@@ -151,8 +144,8 @@ ge::graphStatus SliceLastDimTiling::GetParams()
151 }144 }
152 OP_CHECK_IF(145 OP_CHECK_IF(
153 stride_ < 1,146 stride_ < 1,
154- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(147+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "stride", std::to_string(stride_).c_str(),
155- context_->GetNodeName(), "stride", std::to_string(stride_).c_str(), "The value of stride must be >= 1."),148+ "The value of stride must be >= 1."),
156 return ge::GRAPH_FAILED);149 return ge::GRAPH_FAILED);
157 150 
158 lastDimIn_ = inShape_[rank_ - 1];151 lastDimIn_ = inShape_[rank_ - 1];
@@ -192,8 +185,8 @@ void SliceLastDimTiling::InitElementSizes()
192 cacheLineElements_ = cacheLineSize_ / static_cast<uint32_t>(dSize_);185 cacheLineElements_ = cacheLineSize_ / static_cast<uint32_t>(dSize_);
193}186}
194 187 
195-void SliceLastDimTiling::DoCacheLineTiling(188+void SliceLastDimTiling::DoCacheLineTiling(int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct,
196- int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct, int64_t& minUbFactor, int64_t& outerProduct)189+ int64_t& minUbFactor, int64_t& outerProduct)
197{190{
198 int64_t outShape[2];191 int64_t outShape[2];
199 outShape[0] = outerSize_;192 outShape[0] = outerSize_;
@@ -220,8 +213,8 @@ void SliceLastDimTiling::DoCacheLineTiling(
220 }213 }
221}214}
222 215 
223-void SliceLastDimTiling::DoTilingSearch(216+void SliceLastDimTiling::DoTilingSearch(int64_t alignedLast, int32_t startAxis, int64_t minUbFactor,
224- int64_t alignedLast, int32_t startAxis, int64_t minUbFactor, int64_t clInnerProduct, int64_t outerProduct)217+ int64_t clInnerProduct, int64_t outerProduct)
225{218{
226 int64_t outShape[2];219 int64_t outShape[2];
227 outShape[0] = outerSize_;220 outShape[0] = outerSize_;
@@ -273,10 +266,9 @@ ge::graphStatus SliceLastDimTiling::SetTilingData()
273 perCoreCount_ = Ops::Base::CeilDiv(totalCount_, static_cast<uint64_t>(coreNum_));266 perCoreCount_ = Ops::Base::CeilDiv(totalCount_, static_cast<uint64_t>(coreNum_));
274 uint64_t realCoreNum = Ops::Base::CeilDiv(totalCount_, perCoreCount_);267 uint64_t realCoreNum = Ops::Base::CeilDiv(totalCount_, perCoreCount_);
275 268 
276- OP_LOGI(269+ OP_LOGI(context_,
277- context_,270+ "SliceLastDim tiling: copyMode=%u ubAxis=%u ubFactor=%u totalCount=%lu perCoreCount=%lu realCoreNum=%lu",
278- "SliceLastDim tiling: copyMode=%u ubAxis=%u ubFactor=%u totalCount=%lu perCoreCount=%lu realCoreNum=%lu",271+ copyMode_, ubAxis_, ubFactor_, totalCount_, perCoreCount_, realCoreNum);
279- copyMode_, ubAxis_, ubFactor_, totalCount_, perCoreCount_, realCoreNum);
280 272 
281 auto tilingData = context_->GetTilingData<SliceLastDimTilingData>();273 auto tilingData = context_->GetTilingData<SliceLastDimTilingData>();
282 OP_CHECK_NULL_WITH_CONTEXT(context_, tilingData);274 OP_CHECK_NULL_WITH_CONTEXT(context_, tilingData);
@@ -293,12 +285,11 @@ ge::graphStatus SliceLastDimTiling::SetTilingData()
293 context_->SetTilingKey(GET_TPL_TILING_KEY(copyMode_, ubAxis_));285 context_->SetTilingKey(GET_TPL_TILING_KEY(copyMode_, ubAxis_));
294 context_->SetBlockDim(realCoreNum);286 context_->SetBlockDim(realCoreNum);
295 287 
296- OP_LOGI(288+ OP_LOGI(context_,
297- context_,289+ "SliceLastDim tilingData: outerSize=%ld lastDimIn=%ld lastDimOut=%ld start=%ld stride=%ld "
298- "SliceLastDim tilingData: outerSize=%ld lastDimIn=%ld lastDimOut=%ld start=%ld stride=%ld "290+ "totalCount=%lu perCoreCount=%lu ubFactor=%u bufferSize=%u",
299- "totalCount=%lu perCoreCount=%lu ubFactor=%u bufferSize=%u",291+ tilingData->outerSize, tilingData->lastDimIn, tilingData->lastDimOut, tilingData->start, tilingData->stride,
300- tilingData->outerSize, tilingData->lastDimIn, tilingData->lastDimOut, tilingData->start, tilingData->stride,292+ tilingData->totalCount, tilingData->perCoreCount, tilingData->ubFactor, tilingData->bufferSize);
301- tilingData->totalCount, tilingData->perCoreCount, tilingData->ubFactor, tilingData->bufferSize);
302 293 
303 return ge::GRAPH_SUCCESS;294 return ge::GRAPH_SUCCESS;
304}295}
@@ -319,18 +310,15 @@ ge::graphStatus SliceLastDimTiling::ComputeAndSetTiling()
319ge::graphStatus SliceLastDimTiling::DoTiling()310ge::graphStatus SliceLastDimTiling::DoTiling()
320{311{
321 auto ret = GetSocInfo();312 auto ret = GetSocInfo();
322- OP_CHECK_IF(313+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,
323- ret != ge::GRAPH_SUCCESS,314+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetSocInfo", "failed", ""), return ret);
324- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetSocInfo", "failed", ""), return ret);
325 ret = GetParams();315 ret = GetParams();
326- OP_CHECK_IF(316+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,
327- ret != ge::GRAPH_SUCCESS,317+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetParams", "failed", ""), return ret);
328- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetParams", "failed", ""), return ret);
329 ret = ComputeAndSetTiling();318 ret = ComputeAndSetTiling();
330- OP_CHECK_IF(319+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,
331- ret != ge::GRAPH_SUCCESS,320+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ComputeAndSetTiling", "failed", ""),
332- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ComputeAndSetTiling", "failed", ""),321+ return ret);
333- return ret);
334 322 
335 size_t* workSpaceSize = context_->GetWorkspaceSizes(1);323 size_t* workSpaceSize = context_->GetWorkspaceSizes(1);
336 OP_CHECK_NULL_WITH_CONTEXT(context_, workSpaceSize);324 OP_CHECK_NULL_WITH_CONTEXT(context_, workSpaceSize);
@@ -340,6 +328,7 @@ ge::graphStatus SliceLastDimTiling::DoTiling()
340 328 
341static ge::graphStatus SliceLastDimTilingFunc(gert::TilingContext* context)329static ge::graphStatus SliceLastDimTilingFunc(gert::TilingContext* context)
342{330{
331+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
343 SliceLastDimTiling tiling(context);332 SliceLastDimTiling tiling(context);
344 return tiling.DoTiling();333 return tiling.DoTiling();
345}334}
@@ -10,6 +10,7 @@
10 10 
11#include "register/op_impl_registry.h"11#include "register/op_impl_registry.h"
12#include "log/log.h"12#include "log/log.h"
13+#include "util/shape_util.h"
13 14 
14using namespace ge;15using namespace ge;
15namespace ops {16namespace ops {
@@ -66,8 +67,15 @@ static ge::graphStatus Infershape4SliceLastDim(gert::InferShapeContext* context)
66 yShape->AppendDim(length);67 yShape->AppendDim(length);
67 }68 }
68 69 
70+ OP_LOGI(context->GetNodeName(), "SliceLastDim output shape: %s.", Ops::Base::ToString(*yShape).c_str());
69 return ge::GRAPH_SUCCESS;71 return ge::GRAPH_SUCCESS;
70}72}
71 73 
72-IMPL_OP_INFERSHAPE(SliceLastDim).InferShape(Infershape4SliceLastDim);74+static ge::graphStatus InferDataType4SliceLastDim(gert::InferDataTypeContext* context)
75+{
76+ context->SetOutputDataType(OUTPUT_IDX_Y, context->GetInputDataType(INPUT_IDX_X));
77+ return ge::GRAPH_SUCCESS;
78+}
79+ 
80+IMPL_OP_INFERSHAPE(SliceLastDim).InferShape(Infershape4SliceLastDim).InferDataType(InferDataType4SliceLastDim);
73} // namespace ops81} // namespace ops
@@ -27,8 +27,7 @@ static constexpr double MIN_CORE_UTIL_RATIO = 0.8;
27 27 
28class SliceWithAxesTiling {28class SliceWithAxesTiling {
29public:29public:
30- explicit SliceWithAxesTiling(gert::TilingContext* context) : context_(context)30+ explicit SliceWithAxesTiling(gert::TilingContext* context) : context_(context) {}
31- {}
32 ge::graphStatus DoTiling();31 ge::graphStatus DoTiling();
33 32 
34private:33private:
@@ -37,10 +36,10 @@ private:
37 ge::graphStatus ComputeAndSetTiling();36 ge::graphStatus ComputeAndSetTiling();
38 37 
39 void InitElementSizes();38 void InitElementSizes();
40- void DoCacheLineTiling(39+ void DoCacheLineTiling(int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct, int64_t& minUbFactor,
41- int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct, int64_t& minUbFactor, int64_t& outerProduct);40+ int64_t& outerProduct);
42- void DoTilingSearch(41+ void DoTilingSearch(int64_t alignedLast, int32_t startAxis, int64_t minUbFactor, int64_t clInnerProduct,
43- int64_t alignedLast, int32_t startAxis, int64_t minUbFactor, int64_t clInnerProduct, int64_t outerProduct);42+ int64_t outerProduct);
44 ge::graphStatus SetTilingData();43 ge::graphStatus SetTilingData();
45 44 
46 gert::TilingContext* context_;45 gert::TilingContext* context_;
@@ -74,32 +73,28 @@ ge::graphStatus SliceWithAxesTiling::GetSocInfo()
74 coreNum_ = ascendcPlatform.GetCoreNumAiv();73 coreNum_ = ascendcPlatform.GetCoreNumAiv();
75 OP_CHECK_IF(74 OP_CHECK_IF(
76 (coreNum_ == 0U),75 (coreNum_ == 0U),
77- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(76+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "coreNum", std::to_string(coreNum_).c_str(),
78- context_->GetNodeName(), "coreNum", std::to_string(coreNum_).c_str(), "The core num must be positive."),77+ "The core num must be positive."),
79 return ge::GRAPH_FAILED);78 return ge::GRAPH_FAILED);
80 uint64_t ubSize = 0;79 uint64_t ubSize = 0;
81 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);80 ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);
82- OP_CHECK_IF(81+ OP_CHECK_IF((ubSize == 0U),
83- (ubSize == 0U),82+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(),
84- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(83+ "Failed to get ub size, ub size must be positive."),
85- context_->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(),84+ return ge::GRAPH_FAILED);
86- "Failed to get ub size, ub size must be positive."),
87- return ge::GRAPH_FAILED);
88 ubSize_ = static_cast<uint32_t>(ubSize);85 ubSize_ = static_cast<uint32_t>(ubSize);
89 cacheLineSize_ = Ops::Base::GetCacheLineSize(context_);86 cacheLineSize_ = Ops::Base::GetCacheLineSize(context_);
90- OP_CHECK_IF(87+ OP_CHECK_IF((cacheLineSize_ == 0U),
91- (cacheLineSize_ == 0U),88+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
92- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(89+ context_->GetNodeName(), "cacheLineSize", std::to_string(cacheLineSize_).c_str(),
93- context_->GetNodeName(), "cacheLineSize", std::to_string(cacheLineSize_).c_str(),90+ "Failed to get cache line size, cache line size must be positive."),
94- "Failed to get cache line size, cache line size must be positive."),91+ return ge::GRAPH_FAILED);
95- return ge::GRAPH_FAILED);
96 ubBlockSize_ = Ops::Base::GetUbBlockSize(context_);92 ubBlockSize_ = Ops::Base::GetUbBlockSize(context_);
97- OP_CHECK_IF(93+ OP_CHECK_IF((ubBlockSize_ == 0U),
98- (ubBlockSize_ == 0U),94+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ubBlockSize",
99- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(95+ std::to_string(ubBlockSize_).c_str(),
100- context_->GetNodeName(), "ubBlockSize", std::to_string(ubBlockSize_).c_str(),96+ "Failed to get block size, block size must be positive."),
101- "Failed to get block size, block size must be positive."),97+ return ge::GRAPH_FAILED);
102- return ge::GRAPH_FAILED);
103 return ge::GRAPH_SUCCESS;98 return ge::GRAPH_SUCCESS;
104}99}
105 100 
@@ -109,21 +104,19 @@ ge::graphStatus SliceWithAxesTiling::GetParams()
109 OP_CHECK_NULL_WITH_CONTEXT(context_, inputValueDesc);104 OP_CHECK_NULL_WITH_CONTEXT(context_, inputValueDesc);
110 auto inputDataType = inputValueDesc->GetDataType();105 auto inputDataType = inputValueDesc->GetDataType();
111 dSize_ = ge::GetSizeByDataType(inputDataType);106 dSize_ = ge::GetSizeByDataType(inputDataType);
112- OP_CHECK_IF(107+ OP_CHECK_IF(dSize_ <= 0,
113- dSize_ <= 0,108+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "dSize", std::to_string(dSize_).c_str(),
114- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(109+ "The data type size must be positive."),
115- context_->GetNodeName(), "dSize", std::to_string(dSize_).c_str(), "The data type size must be positive."),110+ return ge::GRAPH_FAILED);
116- return ge::GRAPH_FAILED);
117 111 
118 auto xInputShape = context_->GetInputShape(INPUT_IDX_X);112 auto xInputShape = context_->GetInputShape(INPUT_IDX_X);
119 OP_CHECK_NULL_WITH_CONTEXT(context_, xInputShape);113 OP_CHECK_NULL_WITH_CONTEXT(context_, xInputShape);
120 auto xShape = xInputShape->GetStorageShape();114 auto xShape = xInputShape->GetStorageShape();
121 rank_ = static_cast<uint8_t>(xShape.GetDimNum());115 rank_ = static_cast<uint8_t>(xShape.GetDimNum());
122- OP_CHECK_IF(116+ OP_CHECK_IF(rank_ == 0 || rank_ > MAX_AXIS_COUNT,
123- rank_ == 0 || rank_ > MAX_AXIS_COUNT,117+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context_->GetNodeName(), "x", std::to_string(rank_).c_str(),
124- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(118+ "The shape dim of x must be in [1, 8]."),
125- context_->GetNodeName(), "x", std::to_string(rank_).c_str(), "The shape dim of x must be in [1, 8]."),119+ return ge::GRAPH_FAILED);
126- return ge::GRAPH_FAILED);
127 for (uint8_t i = 0; i < rank_; ++i) {120 for (uint8_t i = 0; i < rank_; ++i) {
128 inShape_[i] = xShape.GetDim(i);121 inShape_[i] = xShape.GetDim(i);
129 }122 }
@@ -150,9 +143,8 @@ ge::graphStatus SliceWithAxesTiling::GetParams()
150 int64_t ax = axesData[k];143 int64_t ax = axesData[k];
151 OP_CHECK_IF(144 OP_CHECK_IF(
152 ax < 0 || ax >= rank_,145 ax < 0 || ax >= rank_,
153- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(146+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "axis", std::to_string(ax).c_str(),
154- context_->GetNodeName(), "axis", std::to_string(ax).c_str(),147+ "The value of axis must be in [0, rank)."),
155- "The value of axis must be in [0, rank)."),
156 return ge::GRAPH_FAILED);148 return ge::GRAPH_FAILED);
157 fullOffsets_[ax] = offsetsShape[k];149 fullOffsets_[ax] = offsetsShape[k];
158 int64_t sz = sizeShape[k];150 int64_t sz = sizeShape[k];
@@ -167,8 +159,8 @@ ge::graphStatus SliceWithAxesTiling::GetParams()
167 for (uint8_t i = 0; i < rank_; ++i) {159 for (uint8_t i = 0; i < rank_; ++i) {
168 OP_CHECK_IF(160 OP_CHECK_IF(
169 outShape_[i] <= 0,161 outShape_[i] <= 0,
170- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(162+ OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context_->GetNodeName(), "y", std::to_string(outShape_[i]).c_str(),
171- context_->GetNodeName(), "y", std::to_string(outShape_[i]).c_str(), "The shape dim of y must be >= 0."),163+ "The shape dim of y must be >= 0."),
172 return ge::GRAPH_FAILED);164 return ge::GRAPH_FAILED);
173 }165 }
174 166 
@@ -183,8 +175,8 @@ void SliceWithAxesTiling::InitElementSizes()
183 cacheLineElements_ = cacheLineSize_ / static_cast<uint32_t>(dSize_);175 cacheLineElements_ = cacheLineSize_ / static_cast<uint32_t>(dSize_);
184}176}
185 177 
186-void SliceWithAxesTiling::DoCacheLineTiling(178+void SliceWithAxesTiling::DoCacheLineTiling(int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct,
187- int64_t alignedLast, int32_t& startAxis, int64_t& clInnerProduct, int64_t& minUbFactor, int64_t& outerProduct)179+ int64_t& minUbFactor, int64_t& outerProduct)
188{180{
189 int32_t last = static_cast<int32_t>(rank_) - 1;181 int32_t last = static_cast<int32_t>(rank_) - 1;
190 startAxis = last;182 startAxis = last;
@@ -208,8 +200,8 @@ void SliceWithAxesTiling::DoCacheLineTiling(
208 }200 }
209}201}
210 202 
211-void SliceWithAxesTiling::DoTilingSearch(203+void SliceWithAxesTiling::DoTilingSearch(int64_t alignedLast, int32_t startAxis, int64_t minUbFactor,
212- int64_t alignedLast, int32_t startAxis, int64_t minUbFactor, int64_t clInnerProduct, int64_t outerProduct)204+ int64_t clInnerProduct, int64_t outerProduct)
213{205{
214 int32_t last = static_cast<int32_t>(rank_) - 1;206 int32_t last = static_cast<int32_t>(rank_) - 1;
215 uint8_t bestAxis = 0;207 uint8_t bestAxis = 0;
@@ -258,9 +250,9 @@ ge::graphStatus SliceWithAxesTiling::SetTilingData()
258 perCoreCount_ = Ops::Base::CeilDiv(totalCount_, static_cast<uint64_t>(coreNum_));250 perCoreCount_ = Ops::Base::CeilDiv(totalCount_, static_cast<uint64_t>(coreNum_));
259 uint64_t realCoreNum = Ops::Base::CeilDiv(totalCount_, perCoreCount_);251 uint64_t realCoreNum = Ops::Base::CeilDiv(totalCount_, perCoreCount_);
260 252 
261- OP_LOGI(253+ OP_LOGI(context_,
262- context_, "SliceWithAxes tiling: rank=%u ubAxis=%u ubFactor=%u totalCount=%lu perCoreCount=%lu realCoreNum=%lu",254+ "SliceWithAxes tiling: rank=%u ubAxis=%u ubFactor=%u totalCount=%lu perCoreCount=%lu realCoreNum=%lu",
263- rank_, ubAxis_, ubFactor_, totalCount_, perCoreCount_, realCoreNum);255+ rank_, ubAxis_, ubFactor_, totalCount_, perCoreCount_, realCoreNum);
264 256 
265 auto tilingData = context_->GetTilingData<SliceWithAxesTilingData>();257 auto tilingData = context_->GetTilingData<SliceWithAxesTilingData>();
266 OP_CHECK_NULL_WITH_CONTEXT(context_, tilingData);258 OP_CHECK_NULL_WITH_CONTEXT(context_, tilingData);
@@ -281,19 +273,18 @@ ge::graphStatus SliceWithAxesTiling::SetTilingData()
281 context_->SetTilingKey(tilingKey);273 context_->SetTilingKey(tilingKey);
282 context_->SetBlockDim(realCoreNum);274 context_->SetBlockDim(realCoreNum);
283 275 
284- OP_LOGI(276+ OP_LOGI(context_,
285- context_,277+ "SliceWithAxes tilingData: rank=%u ubAxis=%u ubFactor=%u bufferSize=%u totalCount=%lu perCoreCount=%lu "
286- "SliceWithAxes tilingData: rank=%u ubAxis=%u ubFactor=%u bufferSize=%u totalCount=%lu perCoreCount=%lu "278+ "inShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld] outShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld] "
287- "inShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld] outShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld] "279+ "offsets=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld]",
288- "offsets=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld]",280+ tilingData->rank, tilingData->ubAxis, tilingData->ubFactor, tilingData->bufferSize, tilingData->totalCount,
289- tilingData->rank, tilingData->ubAxis, tilingData->ubFactor, tilingData->bufferSize, tilingData->totalCount,281+ tilingData->perCoreCount, tilingData->inShape[0], tilingData->inShape[1], tilingData->inShape[2],
290- tilingData->perCoreCount, tilingData->inShape[0], tilingData->inShape[1], tilingData->inShape[2],282+ tilingData->inShape[3], tilingData->inShape[4], tilingData->inShape[5], tilingData->inShape[6],
291- tilingData->inShape[3], tilingData->inShape[4], tilingData->inShape[5], tilingData->inShape[6],283+ tilingData->inShape[7], tilingData->outShape[0], tilingData->outShape[1], tilingData->outShape[2],
292- tilingData->inShape[7], tilingData->outShape[0], tilingData->outShape[1], tilingData->outShape[2],284+ tilingData->outShape[3], tilingData->outShape[4], tilingData->outShape[5], tilingData->outShape[6],
293- tilingData->outShape[3], tilingData->outShape[4], tilingData->outShape[5], tilingData->outShape[6],285+ tilingData->outShape[7], tilingData->fullOffsets[0], tilingData->fullOffsets[1], tilingData->fullOffsets[2],
294- tilingData->outShape[7], tilingData->fullOffsets[0], tilingData->fullOffsets[1], tilingData->fullOffsets[2],286+ tilingData->fullOffsets[3], tilingData->fullOffsets[4], tilingData->fullOffsets[5],
295- tilingData->fullOffsets[3], tilingData->fullOffsets[4], tilingData->fullOffsets[5], tilingData->fullOffsets[6],287+ tilingData->fullOffsets[6], tilingData->fullOffsets[7]);
296- tilingData->fullOffsets[7]);
297 288 
298 return ge::GRAPH_SUCCESS;289 return ge::GRAPH_SUCCESS;
299}290}
@@ -315,18 +306,15 @@ ge::graphStatus SliceWithAxesTiling::ComputeAndSetTiling()
315ge::graphStatus SliceWithAxesTiling::DoTiling()306ge::graphStatus SliceWithAxesTiling::DoTiling()
316{307{
317 auto ret = GetSocInfo();308 auto ret = GetSocInfo();
318- OP_CHECK_IF(309+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,
319- ret != ge::GRAPH_SUCCESS,310+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetSocInfo", "failed", ""), return ret);
320- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetSocInfo", "failed", ""), return ret);
321 ret = GetParams();311 ret = GetParams();
322- OP_CHECK_IF(312+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,
323- ret != ge::GRAPH_SUCCESS,313+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetParams", "failed", ""), return ret);
324- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "GetParams", "failed", ""), return ret);
325 ret = ComputeAndSetTiling();314 ret = ComputeAndSetTiling();
326- OP_CHECK_IF(315+ OP_CHECK_IF(ret != ge::GRAPH_SUCCESS,
327- ret != ge::GRAPH_SUCCESS,316+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ComputeAndSetTiling", "failed", ""),
328- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ComputeAndSetTiling", "failed", ""),317+ return ret);
329- return ret);
330 318 
331 size_t* workSpaceSize = context_->GetWorkspaceSizes(1);319 size_t* workSpaceSize = context_->GetWorkspaceSizes(1);
332 OP_CHECK_NULL_WITH_CONTEXT(context_, workSpaceSize);320 OP_CHECK_NULL_WITH_CONTEXT(context_, workSpaceSize);
@@ -336,6 +324,7 @@ ge::graphStatus SliceWithAxesTiling::DoTiling()
336 324 
337static ge::graphStatus SliceWithAxesTilingFunc(gert::TilingContext* context)325static ge::graphStatus SliceWithAxesTilingFunc(gert::TilingContext* context)
338{326{
327+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
339 SliceWithAxesTiling tiling(context);328 SliceWithAxesTiling tiling(context);
340 return tiling.DoTiling();329 return tiling.DoTiling();
341}330}
@@ -10,6 +10,7 @@
10 10 
11#include "register/op_impl_registry.h"11#include "register/op_impl_registry.h"
12#include "log/log.h"12#include "log/log.h"
13+#include "util/shape_util.h"
13 14 
14using namespace ge;15using namespace ge;
15namespace ops {16namespace ops {
@@ -78,10 +79,18 @@ static ge::graphStatus Infershape4SliceWithAxes(gert::InferShapeContext* context
78 yShape->SetDim(axis, sliceSize);79 yShape->SetDim(axis, sliceSize);
79 }80 }
80 81 
82+ OP_LOGI(context->GetNodeName(), "SliceWithAxes output shape: %s.", Ops::Base::ToString(*yShape).c_str());
83+ return ge::GRAPH_SUCCESS;
84+}
85+ 
86+static ge::graphStatus InferDataType4SliceWithAxes(gert::InferDataTypeContext* context)
87+{
88+ context->SetOutputDataType(OUTPUT_IDX_Y, context->GetInputDataType(INPUT_IDX_X));
81 return ge::GRAPH_SUCCESS;89 return ge::GRAPH_SUCCESS;
82}90}
83 91 
84IMPL_OP_INFERSHAPE(SliceWithAxes)92IMPL_OP_INFERSHAPE(SliceWithAxes)
85 .InferShape(Infershape4SliceWithAxes)93 .InferShape(Infershape4SliceWithAxes)
94+ .InferDataType(InferDataType4SliceWithAxes)
86 .InputsDataDependency({INPUT_IDX_OFFSETS, INPUT_IDX_SIZE});95 .InputsDataDependency({INPUT_IDX_OFFSETS, INPUT_IDX_SIZE});
87} // namespace ops96} // namespace ops
@@ -30,7 +30,7 @@ static constexpr uint32_t MAX_BUFFER_SIZE = 64 * 1024U;
30 30 
31class SpaceToBatchTiling {31class SpaceToBatchTiling {
32public:32public:
33- explicit SpaceToBatchTiling(gert::TilingContext* context) : context_(context){};33+ explicit SpaceToBatchTiling(gert::TilingContext* context) : context_(context) {};
34 ~SpaceToBatchTiling() = default;34 ~SpaceToBatchTiling() = default;
35 35 
36 ge::graphStatus DoTiling();36 ge::graphStatus DoTiling();
@@ -299,6 +299,12 @@ ge::graphStatus SpaceToBatchTiling::DoTiling()
299 OP_LOGI(context_, "inShape=%s, outShape=%s, blockSize=%ld, paddings=[%ld,%ld,%ld,%ld]",299 OP_LOGI(context_, "inShape=%s, outShape=%s, blockSize=%ld, paddings=[%ld,%ld,%ld,%ld]",
300 ArrToStr(inShape_, STB_AXIS_COUNT).c_str(), ArrToStr(outShape_, STB_AXIS_COUNT).c_str(), blockSize_,300 ArrToStr(inShape_, STB_AXIS_COUNT).c_str(), ArrToStr(outShape_, STB_AXIS_COUNT).c_str(), blockSize_,
301 paddings_[0][0], paddings_[0][1], paddings_[1][0], paddings_[1][1]);301 paddings_[0][0], paddings_[0][1], paddings_[1][0], paddings_[1][1]);
302+ OP_LOGI(context_->GetNodeName(),
303+ "SpaceToBatch TilingData: inShape=%s outShape=%s blockSize=%ld paddings=[%ld,%ld,%ld,%ld] "
304+ "totalCount=%lu perCoreCount=%lu ubAxis=%u ubFactor=%u bufferSize=%u",
305+ ArrToStr(inShape_, STB_AXIS_COUNT).c_str(), ArrToStr(outShape_, STB_AXIS_COUNT).c_str(), blockSize_,
306+ paddings_[0][0], paddings_[0][1], paddings_[1][0], paddings_[1][1], tilingData->totalCount,
307+ tilingData->perCoreCount, tilingData->ubAxis, tilingData->ubFactor, tilingData->bufferSize);
302 308 
303 context_->SetTilingKey(tilingKey);309 context_->SetTilingKey(tilingKey);
304 context_->SetBlockDim(realCoreNum_);310 context_->SetBlockDim(realCoreNum_);
@@ -312,6 +318,7 @@ ge::graphStatus SpaceToBatchTiling::DoTiling()
312 318 
313static ge::graphStatus Tiling4SpaceToBatch(gert::TilingContext* context)319static ge::graphStatus Tiling4SpaceToBatch(gert::TilingContext* context)
314{320{
321+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
315 SpaceToBatchTiling tiling{context};322 SpaceToBatchTiling tiling{context};
316 return tiling.DoTiling();323 return tiling.DoTiling();
317}324}
@@ -80,6 +80,7 @@ ge::graphStatus SpaceToBatchInferShapeHelper::Inference()
80 80 
81 if (Ops::Base::IsUnknownRank(*xShape_)) {81 if (Ops::Base::IsUnknownRank(*xShape_)) {
82 Ops::Base::SetUnknownRank(*yShape_);82 Ops::Base::SetUnknownRank(*yShape_);
83+ OP_LOGI(context_->GetNodeName(), "SpaceToBatch output shape: %s.", Ops::Base::ToString(*yShape_).c_str());
83 return ge::GRAPH_SUCCESS;84 return ge::GRAPH_SUCCESS;
84 }85 }
85 86 
@@ -119,6 +120,7 @@ ge::graphStatus SpaceToBatchInferShapeHelper::Inference()
119 120 
120 yShape_->AppendDim(xShape_->GetDim(3));121 yShape_->AppendDim(xShape_->GetDim(3));
121 122 
123+ OP_LOGI(context_->GetNodeName(), "SpaceToBatch output shape: %s.", Ops::Base::ToString(*yShape_).c_str());
122 return ge::GRAPH_SUCCESS;124 return ge::GRAPH_SUCCESS;
123}125}
124 126 
@@ -128,5 +130,14 @@ static ge::graphStatus Infershape4SpaceToBatch(gert::InferShapeContext* context)
128 return helper.Inference();130 return helper.Inference();
129}131}
130 132 
131-IMPL_OP_INFERSHAPE(SpaceToBatch).InferShape(Infershape4SpaceToBatch).InputsDataDependency({INPUT_IDX_PADDINGS});133+static ge::graphStatus InferDataType4SpaceToBatch(gert::InferDataTypeContext* context)
134+{
135+ context->SetOutputDataType(OUTPUT_IDX_Y, context->GetInputDataType(INPUT_IDX_X));
136+ return ge::GRAPH_SUCCESS;
137+}
138+ 
139+IMPL_OP_INFERSHAPE(SpaceToBatch)
140+ .InferShape(Infershape4SpaceToBatch)
141+ .InferDataType(InferDataType4SpaceToBatch)
142+ .InputsDataDependency({INPUT_IDX_PADDINGS});
132} // namespace ops143} // namespace ops
@@ -282,6 +282,24 @@ ge::graphStatus SpaceToBatchNDTiling::SetTilingData()
282 tilingData->padBottom[i] = padBottom_[i];282 tilingData->padBottom[i] = padBottom_[i];
283 }283 }
284 284 
285+ OP_LOGI(context_,
286+ "SpaceToBatchND TilingData: rank=%ld inShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld] "
287+ "outShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld] totalCount=%ld perCoreCount=%ld ubAxis=%ld "
288+ "ubFactor=%ld bufferSize=%ld numSpatialDims=%ld blockShape=[%ld,%ld,%ld,%ld,%ld,%ld,%ld] "
289+ "padTop=[%ld,%ld,%ld,%ld,%ld,%ld,%ld] padBottom=[%ld,%ld,%ld,%ld,%ld,%ld,%ld]",
290+ tilingData->rank, tilingData->inShape[0], tilingData->inShape[1], tilingData->inShape[2],
291+ tilingData->inShape[3], tilingData->inShape[4], tilingData->inShape[5], tilingData->inShape[6],
292+ tilingData->inShape[7], tilingData->inShape[8], tilingData->outShape[0], tilingData->outShape[1],
293+ tilingData->outShape[2], tilingData->outShape[3], tilingData->outShape[4], tilingData->outShape[5],
294+ tilingData->outShape[6], tilingData->outShape[7], tilingData->outShape[8], tilingData->totalCount,
295+ tilingData->perCoreCount, tilingData->ubAxis, tilingData->ubFactor, tilingData->bufferSize,
296+ tilingData->numSpatialDims, tilingData->blockShape[0], tilingData->blockShape[1], tilingData->blockShape[2],
297+ tilingData->blockShape[3], tilingData->blockShape[4], tilingData->blockShape[5], tilingData->blockShape[6],
298+ tilingData->padTop[0], tilingData->padTop[1], tilingData->padTop[2], tilingData->padTop[3],
299+ tilingData->padTop[4], tilingData->padTop[5], tilingData->padTop[6], tilingData->padBottom[0],
300+ tilingData->padBottom[1], tilingData->padBottom[2], tilingData->padBottom[3], tilingData->padBottom[4],
301+ tilingData->padBottom[5], tilingData->padBottom[6]);
302+ 
285 uint64_t tilingKey = GET_TPL_TILING_KEY(static_cast<uint64_t>(rank_) - static_cast<uint64_t>(ubAxis_));303 uint64_t tilingKey = GET_TPL_TILING_KEY(static_cast<uint64_t>(rank_) - static_cast<uint64_t>(ubAxis_));
286 304 
287 OP_LOGI(context_, "tilingKey is %lu, ubAxis %u", tilingKey, ubAxis_);305 OP_LOGI(context_, "tilingKey is %lu, ubAxis %u", tilingKey, ubAxis_);
@@ -323,6 +341,7 @@ ge::graphStatus SpaceToBatchNDTiling::DoTiling()
323 341 
324static ge::graphStatus SpaceToBatchNDTilingFunc(gert::TilingContext* context)342static ge::graphStatus SpaceToBatchNDTilingFunc(gert::TilingContext* context)
325{343{
344+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
326 SpaceToBatchNDTiling tiling(context);345 SpaceToBatchNDTiling tiling(context);
327 return tiling.DoTiling();346 return tiling.DoTiling();
328}347}
@@ -111,10 +111,12 @@ ge::graphStatus SpaceToBatchNDInferShapeHelper::Inference()
111 111 
112 if (Ops::Base::IsUnknownRank(*xShape_)) {112 if (Ops::Base::IsUnknownRank(*xShape_)) {
113 Ops::Base::SetUnknownRank(*yShape_);113 Ops::Base::SetUnknownRank(*yShape_);
114+ OP_LOGI(context_->GetNodeName(), "SpaceToBatchND output shape: %s.", Ops::Base::ToString(*yShape_).c_str());
114 return ge::GRAPH_SUCCESS;115 return ge::GRAPH_SUCCESS;
115 }116 }
116 117 
117 OP_CHECK_IF(CheckAndInfer() != ge::GRAPH_SUCCESS, OP_LOGE(context_, "infer failed"), return ge::GRAPH_FAILED);118 OP_CHECK_IF(CheckAndInfer() != ge::GRAPH_SUCCESS, OP_LOGE(context_, "infer failed"), return ge::GRAPH_FAILED);
119+ OP_LOGI(context_->GetNodeName(), "SpaceToBatchND output shape: %s.", Ops::Base::ToString(*yShape_).c_str());
118 return ge::GRAPH_SUCCESS;120 return ge::GRAPH_SUCCESS;
119}121}
120 122 
@@ -124,7 +126,14 @@ static ge::graphStatus Infershape4SpaceToBatchND(gert::InferShapeContext* contex
124 return helper.Inference();126 return helper.Inference();
125}127}
126 128 
129+static ge::graphStatus InferDataType4SpaceToBatchND(gert::InferDataTypeContext* context)
130+{
131+ context->SetOutputDataType(OUTPUT_IDX_Y, context->GetInputDataType(INPUT_IDX_X));
132+ return ge::GRAPH_SUCCESS;
133+}
134+ 
127IMPL_OP_INFERSHAPE(SpaceToBatchND)135IMPL_OP_INFERSHAPE(SpaceToBatchND)
128 .InferShape(Infershape4SpaceToBatchND)136 .InferShape(Infershape4SpaceToBatchND)
137+ .InferDataType(InferDataType4SpaceToBatchND)
129 .InputsDataDependency({INPUT_IDX_BS, INPUT_IDX_PADS});138 .InputsDataDependency({INPUT_IDX_BS, INPUT_IDX_PADS});
130} // namespace ops139} // namespace ops
@@ -72,16 +72,28 @@ static ge::graphStatus GetWorkspaceSize(gert::TilingContext* context)
72// ============================================================================72// ============================================================================
73// Helper: Handle scalar (rank=0) input73// Helper: Handle scalar (rank=0) input
74// ============================================================================74// ============================================================================
75-static ge::graphStatus HandleScalarInput(gert::TilingContext* context, int64_t tiles,75+static void LogTilingData(gert::TilingContext* context, const TileWithAxisTilingData* tiling)
76- uint64_t ubSize)76+{
77+ OP_LOGI(context->GetNodeName(),
78+ "TileWithAxis TilingData: inShape=[%ld,%ld,%ld] outShape=[%ld,%ld,%ld] totalCount=%lu "
79+ "perCoreCount=%lu ubAxis=%u ubFactor=%u bufferSize=%u tiles=%ld rowLength=%ld",
80+ tiling->inShape[0], tiling->inShape[1], tiling->inShape[2], tiling->outShape[0], tiling->outShape[1],
81+ tiling->outShape[2], tiling->totalCount, tiling->perCoreCount, tiling->ubAxis, tiling->ubFactor,
82+ tiling->bufferSize, tiling->tiles, tiling->rowLength);
83+}
84+ 
85+static ge::graphStatus HandleScalarInput(gert::TilingContext* context, int64_t tiles, uint64_t ubSize)
77{86{
78 TileWithAxisTilingData* tiling = context->GetTilingData<TileWithAxisTilingData>();87 TileWithAxisTilingData* tiling = context->GetTilingData<TileWithAxisTilingData>();
79 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);88 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);
80- OP_CHECK_IF(89+ OP_CHECK_IF(memset_s(tiling, sizeof(TileWithAxisTilingData), 0, sizeof(TileWithAxisTilingData)) != EOK,
81- memset_s(tiling, sizeof(TileWithAxisTilingData), 0, sizeof(TileWithAxisTilingData)) != EOK,90+ OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
82- OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);91+ tiling->inShape[0] = 1;
83- tiling->inShape[0] = 1; tiling->inShape[1] = 1; tiling->inShape[2] = 1;92+ tiling->inShape[1] = 1;
84- tiling->outShape[0] = 1; tiling->outShape[1] = tiles; tiling->outShape[2] = 1;93+ tiling->inShape[2] = 1;
94+ tiling->outShape[0] = 1;
95+ tiling->outShape[1] = tiles;
96+ tiling->outShape[2] = 1;
85 tiling->totalCount = 1;97 tiling->totalCount = 1;
86 tiling->perCoreCount = 1;98 tiling->perCoreCount = 1;
87 tiling->ubAxis = 0;99 tiling->ubAxis = 0;
@@ -89,10 +101,11 @@ static ge::graphStatus HandleScalarInput(gert::TilingContext* context, int64_t t
89 tiling->bufferSize = ubSize / 2;101 tiling->bufferSize = ubSize / 2;
90 tiling->tiles = tiles;102 tiling->tiles = tiles;
91 tiling->rowLength = 1;103 tiling->rowLength = 1;
104+ LogTilingData(context, tiling);
92 context->SetBlockDim(1);105 context->SetBlockDim(1);
93 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(0));106 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(0));
94- OP_CHECK_IF(GetWorkspaceSize(context) != ge::GRAPH_SUCCESS,107+ OP_CHECK_IF(GetWorkspaceSize(context) != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetWorkspaceSize error"),
95- OP_LOGE(context, "GetWorkspaceSize error"), return ge::GRAPH_FAILED);108+ return ge::GRAPH_FAILED);
96 return ge::GRAPH_SUCCESS;109 return ge::GRAPH_SUCCESS;
97}110}
98 111 
@@ -116,16 +129,17 @@ static ge::graphStatus NormalizeAxis(gert::TilingContext* context, int64_t& axis
116// ============================================================================129// ============================================================================
117static int64_t MaxBlocksOnAxis(uint8_t ax, int64_t outerDim, int64_t tiles, int64_t rowLength)130static int64_t MaxBlocksOnAxis(uint8_t ax, int64_t outerDim, int64_t tiles, int64_t rowLength)
118{131{
119- if (ax == 0) return outerDim;132+ if (ax == 0)
120- if (ax == 1) return outerDim * tiles;133+ return outerDim;
134+ if (ax == 1)
135+ return outerDim * tiles;
121 return outerDim * tiles * rowLength;136 return outerDim * tiles * rowLength;
122}137}
123 138 
124// ============================================================================139// ============================================================================
125// Helper: Compute ubFactor from axis + target block count140// Helper: Compute ubFactor from axis + target block count
126// ============================================================================141// ============================================================================
127-static uint32_t ComputeUbFactor(uint8_t ax, int64_t target,142+static uint32_t ComputeUbFactor(uint8_t ax, int64_t target, int64_t outerDim, int64_t tiles, int64_t rowLength)
128- int64_t outerDim, int64_t tiles, int64_t rowLength)
129{143{
130 if (ax == 0) {144 if (ax == 0) {
131 return static_cast<uint32_t>(std::max(static_cast<int64_t>(1), CeilDiv(outerDim, target)));145 return static_cast<uint32_t>(std::max(static_cast<int64_t>(1), CeilDiv(outerDim, target)));
@@ -141,20 +155,21 @@ static uint32_t ComputeUbFactor(uint8_t ax, int64_t target,
141// ============================================================================155// ============================================================================
142// Helper: Compute totalCount from axis + ubFactor156// Helper: Compute totalCount from axis + ubFactor
143// ============================================================================157// ============================================================================
144-static uint64_t ComputeTotalCount(uint8_t ax, int64_t uf,158+static uint64_t ComputeTotalCount(uint8_t ax, int64_t uf, int64_t outerDim, int64_t tiles, int64_t rowLength)
145- int64_t outerDim, int64_t tiles, int64_t rowLength)
146{159{
147- if (ax == 0) return static_cast<uint64_t>(CeilDiv(outerDim, uf));160+ if (ax == 0)
148- if (ax == 1) return static_cast<uint64_t>(outerDim * CeilDiv(tiles, uf));161+ return static_cast<uint64_t>(CeilDiv(outerDim, uf));
162+ if (ax == 1)
163+ return static_cast<uint64_t>(outerDim * CeilDiv(tiles, uf));
149 return static_cast<uint64_t>(outerDim * tiles * CeilDiv(rowLength, uf));164 return static_cast<uint64_t>(outerDim * tiles * CeilDiv(rowLength, uf));
150}165}
151 166 
152// ============================================================================167// ============================================================================
153// Step 2: Select initial UB axis by priority (0 > 1 > 2)168// Step 2: Select initial UB axis by priority (0 > 1 > 2)
154// ============================================================================169// ============================================================================
155-static void SelectInitialUbAxis(int64_t ubFactor0, int64_t ubFactor1, int64_t ubFactor2,170+static void SelectInitialUbAxis(int64_t ubFactor0, int64_t ubFactor1, int64_t ubFactor2, int64_t outerDim,
156- int64_t outerDim, int64_t tiles, int64_t rowLength,171+ int64_t tiles, int64_t rowLength, uint8_t& ubAxis, uint32_t& ubFactor,
157- uint8_t& ubAxis, uint32_t& ubFactor, uint64_t& totalCount)172+ uint64_t& totalCount)
158{173{
159 if (ubFactor0 >= 1) {174 if (ubFactor0 >= 1) {
160 ubAxis = 0;175 ubAxis = 0;
@@ -174,10 +189,9 @@ static void SelectInitialUbAxis(int64_t ubFactor0, int64_t ubFactor1, int64_t ub
174// ============================================================================189// ============================================================================
175// Step 2.5: Core-aware ubFactor adjustment + cross-axis fallback190// Step 2.5: Core-aware ubFactor adjustment + cross-axis fallback
176// ============================================================================191// ============================================================================
177-static void AdjustForCoreUtilization(uint8_t& ubAxis, uint32_t& ubFactor, uint64_t& totalCount,192+static void AdjustForCoreUtilization(uint8_t& ubAxis, uint32_t& ubFactor, uint64_t& totalCount, int64_t ubFactor0,
178- int64_t ubFactor0, int64_t ubFactor1, int64_t ubFactor2,193+ int64_t ubFactor1, int64_t ubFactor2, int64_t outerDim, int64_t tiles,
179- int64_t outerDim, int64_t tiles, int64_t rowLength,194+ int64_t rowLength, int64_t coreNum)
180- int64_t coreNum)
181{195{
182 int64_t totalOutElements = outerDim * tiles * rowLength;196 int64_t totalOutElements = outerDim * tiles * rowLength;
183 int64_t thresholdBlocks = static_cast<int64_t>(static_cast<double>(coreNum) * TARGET_CORE_RATIO);197 int64_t thresholdBlocks = static_cast<int64_t>(static_cast<double>(coreNum) * TARGET_CORE_RATIO);
@@ -202,31 +216,33 @@ static void AdjustForCoreUtilization(uint8_t& ubAxis, uint32_t& ubFactor, uint64
202 return;216 return;
203 }217 }
204 218 
205- uint8_t bestAxis = ubAxis;219+ uint8_t bestAxis = ubAxis;
206 uint64_t bestCount = totalCount;220 uint64_t bestCount = totalCount;
207- uint32_t bestUf = ubFactor;221+ uint32_t bestUf = ubFactor;
208 222 
209 const int64_t origUbFactors[] = {ubFactor0, ubFactor1, ubFactor2};223 const int64_t origUbFactors[] = {ubFactor0, ubFactor1, ubFactor2};
210 for (uint8_t cand = 0; cand < 3; cand++) {224 for (uint8_t cand = 0; cand < 3; cand++) {
211- if (cand == ubAxis || origUbFactors[cand] < 1) continue;225+ if (cand == ubAxis || origUbFactors[cand] < 1)
226+ continue;
212 227 
213 int64_t maxOnCand = MaxBlocksOnAxis(cand, outerDim, tiles, rowLength);228 int64_t maxOnCand = MaxBlocksOnAxis(cand, outerDim, tiles, rowLength);
214 int64_t candTarget = std::min({thresholdBlocks, maxBlocksByData, maxOnCand, coreNum});229 int64_t candTarget = std::min({thresholdBlocks, maxBlocksByData, maxOnCand, coreNum});
215- uint32_t candUf = ComputeUbFactor(cand, candTarget, outerDim, tiles, rowLength);230+ uint32_t candUf = ComputeUbFactor(cand, candTarget, outerDim, tiles, rowLength);
216 uint64_t candCount = ComputeTotalCount(cand, static_cast<int64_t>(candUf), outerDim, tiles, rowLength);231 uint64_t candCount = ComputeTotalCount(cand, static_cast<int64_t>(candUf), outerDim, tiles, rowLength);
217 232 
218- if (candCount > static_cast<uint64_t>(coreNum)) continue;233+ if (candCount > static_cast<uint64_t>(coreNum))
234+ continue;
219 235 
220 if (candCount > bestCount) {236 if (candCount > bestCount) {
221- bestAxis = cand;237+ bestAxis = cand;
222 bestCount = candCount;238 bestCount = candCount;
223- bestUf = candUf;239+ bestUf = candUf;
224 }240 }
225 }241 }
226 242 
227 if (bestAxis != ubAxis) {243 if (bestAxis != ubAxis) {
228- ubAxis = bestAxis;244+ ubAxis = bestAxis;
229- ubFactor = bestUf;245+ ubFactor = bestUf;
230 totalCount = bestCount;246 totalCount = bestCount;
231 }247 }
232}248}
@@ -236,13 +252,12 @@ static void AdjustForCoreUtilization(uint8_t& ubAxis, uint32_t& ubFactor, uint64
236// ============================================================================252// ============================================================================
237static ge::graphStatus TileWithAxisTilingFunc(gert::TilingContext* context)253static ge::graphStatus TileWithAxisTilingFunc(gert::TilingContext* context)
238{254{
255+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
239 // 1. 获取平台运行信息256 // 1. 获取平台运行信息
240 uint64_t ubSize;257 uint64_t ubSize;
241 int64_t coreNum;258 int64_t coreNum;
242- OP_CHECK_IF(259+ OP_CHECK_IF(GetPlatformInfo(context, &ubSize, &coreNum) != ge::GRAPH_SUCCESS,
243- GetPlatformInfo(context, &ubSize, &coreNum) != ge::GRAPH_SUCCESS,260+ OP_LOGE(context, "GetPlatformInfo error"), return ge::GRAPH_FAILED);
244- OP_LOGE(context, "GetPlatformInfo error"),
245- return ge::GRAPH_FAILED);
246 261 
247 // 2. 获取输入信息262 // 2. 获取输入信息
248 auto inputX = context->GetInputShape(0);263 auto inputX = context->GetInputShape(0);
@@ -272,8 +287,8 @@ static ge::graphStatus TileWithAxisTilingFunc(gert::TilingContext* context)
272 }287 }
273 288 
274 // 4. 校验并归一化 axis289 // 4. 校验并归一化 axis
275- OP_CHECK_IF(NormalizeAxis(context, axis, rank) != ge::GRAPH_SUCCESS,290+ OP_CHECK_IF(NormalizeAxis(context, axis, rank) != ge::GRAPH_SUCCESS, OP_LOGE(context, "NormalizeAxis failed"),
276- OP_LOGE(context, "NormalizeAxis failed"), return ge::GRAPH_FAILED);291+ return ge::GRAPH_FAILED);
277 292 
278 // 5. 计算展平参数 (v1.6 折叠 axisDim 进 rowLength)293 // 5. 计算展平参数 (v1.6 折叠 axisDim 进 rowLength)
279 int64_t outerDim = 1;294 int64_t outerDim = 1;
@@ -290,13 +305,13 @@ static ge::graphStatus TileWithAxisTilingFunc(gert::TilingContext* context)
290 // 6. TilingData 空间分配305 // 6. TilingData 空间分配
291 TileWithAxisTilingData* tiling = context->GetTilingData<TileWithAxisTilingData>();306 TileWithAxisTilingData* tiling = context->GetTilingData<TileWithAxisTilingData>();
292 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);307 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);
293- OP_CHECK_IF(308+ OP_CHECK_IF(memset_s(tiling, sizeof(TileWithAxisTilingData), 0, sizeof(TileWithAxisTilingData)) != EOK,
294- memset_s(tiling, sizeof(TileWithAxisTilingData), 0, sizeof(TileWithAxisTilingData)) != EOK,309+ OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
295- OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
296 310 
297 // 7. UB 切分311 // 7. UB 切分
298 int64_t dtypeSize = static_cast<int64_t>(ge::GetSizeByDataType(dataType));312 int64_t dtypeSize = static_cast<int64_t>(ge::GetSizeByDataType(dataType));
299- OP_CHECK_IF(dtypeSize <= 0, OP_LOGE(context, "unsupported dtype, GetSizeByDataType returned %ld", dtypeSize), return ge::GRAPH_FAILED);313+ OP_CHECK_IF(dtypeSize <= 0, OP_LOGE(context, "unsupported dtype, GetSizeByDataType returned %ld", dtypeSize),
314+ return ge::GRAPH_FAILED);
300 int64_t bufferSizeElements = (static_cast<int64_t>(ubSize) / 2) / dtypeSize;315 int64_t bufferSizeElements = (static_cast<int64_t>(ubSize) / 2) / dtypeSize;
301 int64_t rowOutElements = tiles * rowLength;316 int64_t rowOutElements = tiles * rowLength;
302 317 
@@ -304,16 +319,14 @@ static ge::graphStatus TileWithAxisTilingFunc(gert::TilingContext* context)
304 int64_t ubFactor1 = (rowLength > 0) ? std::min(tiles, bufferSizeElements / rowLength) : 0;319 int64_t ubFactor1 = (rowLength > 0) ? std::min(tiles, bufferSizeElements / rowLength) : 0;
305 int64_t ubFactor2 = std::min(rowLength, bufferSizeElements);320 int64_t ubFactor2 = std::min(rowLength, bufferSizeElements);
306 321 
307- uint8_t ubAxis = 0;322+ uint8_t ubAxis = 0;
308 uint32_t ubFactor = 1;323 uint32_t ubFactor = 1;
309 uint64_t totalCount = 0;324 uint64_t totalCount = 0;
310 325 
311- SelectInitialUbAxis(ubFactor0, ubFactor1, ubFactor2, outerDim, tiles, rowLength,326+ SelectInitialUbAxis(ubFactor0, ubFactor1, ubFactor2, outerDim, tiles, rowLength, ubAxis, ubFactor, totalCount);
312- ubAxis, ubFactor, totalCount);
313 327 
314- AdjustForCoreUtilization(ubAxis, ubFactor, totalCount,328+ AdjustForCoreUtilization(ubAxis, ubFactor, totalCount, ubFactor0, ubFactor1, ubFactor2, outerDim, tiles, rowLength,
315- ubFactor0, ubFactor1, ubFactor2,329+ coreNum);
316- outerDim, tiles, rowLength, coreNum);
317 330 
318 // 8. 多核切分331 // 8. 多核切分
319 uint64_t perCoreCount = static_cast<uint64_t>(CeilDiv(static_cast<int64_t>(totalCount), coreNum));332 uint64_t perCoreCount = static_cast<uint64_t>(CeilDiv(static_cast<int64_t>(totalCount), coreNum));
@@ -333,14 +346,13 @@ static ge::graphStatus TileWithAxisTilingFunc(gert::TilingContext* context)
333 tiling->bufferSize = static_cast<uint32_t>(ubSize) / 2;346 tiling->bufferSize = static_cast<uint32_t>(ubSize) / 2;
334 tiling->tiles = tiles;347 tiling->tiles = tiles;
335 tiling->rowLength = rowLength;348 tiling->rowLength = rowLength;
349+ LogTilingData(context, tiling);
336 350 
337 // 10. 设置 BlockDim + workspace + TilingKey351 // 10. 设置 BlockDim + workspace + TilingKey
338 context->SetBlockDim(realCoreNum);352 context->SetBlockDim(realCoreNum);
339 353 
340- OP_CHECK_IF(354+ OP_CHECK_IF(GetWorkspaceSize(context) != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetWorkspaceSize error"),
341- GetWorkspaceSize(context) != ge::GRAPH_SUCCESS,355+ return ge::GRAPH_FAILED);
342- OP_LOGE(context, "GetWorkspaceSize error"),
343- return ge::GRAPH_FAILED);
344 356 
345 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(ubAxis));357 ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(ubAxis));
346 358 
@@ -360,6 +372,8 @@ struct TileWithAxisCompileInfo {};
360// ============================================================================372// ============================================================================
361// Tiling 注册入口373// Tiling 注册入口
362// ============================================================================374// ============================================================================
363-IMPL_OP_OPTILING(TileWithAxis).Tiling(TileWithAxisTilingFunc).TilingParse<TileWithAxisCompileInfo>(TilingParseForTileWithAxis);375+IMPL_OP_OPTILING(TileWithAxis)
376+ .Tiling(TileWithAxisTilingFunc)
377+ .TilingParse<TileWithAxisCompileInfo>(TilingParseForTileWithAxis);
364 378 
365} // namespace optiling379} // namespace optiling
@@ -49,6 +49,7 @@ static ge::graphStatus InferShape4TileWithAxis(gert::InferShapeContext* context)
49 // unknown rank 处理: input rank 未知时 output 也设未知49 // unknown rank 处理: input rank 未知时 output 也设未知
50 if (Ops::Base::IsUnknownRank(*input_shape)) {50 if (Ops::Base::IsUnknownRank(*input_shape)) {
51 Ops::Base::SetUnknownRank(*output_shape);51 Ops::Base::SetUnknownRank(*output_shape);
52+ OP_LOGI(context->GetNodeName(), "TileWithAxis output shape: %s.", Ops::Base::ToString(*output_shape).c_str());
52 return ge::GRAPH_SUCCESS;53 return ge::GRAPH_SUCCESS;
53 }54 }
54 55 
@@ -57,6 +58,7 @@ static ge::graphStatus InferShape4TileWithAxis(gert::InferShapeContext* context)
57 // 标量输入: 输出 shape = [tiles]58 // 标量输入: 输出 shape = [tiles]
58 output_shape->SetDimNum(1);59 output_shape->SetDimNum(1);
59 output_shape->SetDim(0, tiles);60 output_shape->SetDim(0, tiles);
61+ OP_LOGI(context->GetNodeName(), "TileWithAxis output shape: %s.", Ops::Base::ToString(*output_shape).c_str());
60 return ge::GRAPH_SUCCESS;62 return ge::GRAPH_SUCCESS;
61 }63 }
62 64 
@@ -75,9 +77,16 @@ static ge::graphStatus InferShape4TileWithAxis(gert::InferShapeContext* context)
75 }77 }
76 }78 }
77 79 
80+ OP_LOGI(context->GetNodeName(), "TileWithAxis output shape: %s.", Ops::Base::ToString(*output_shape).c_str());
78 return ge::GRAPH_SUCCESS;81 return ge::GRAPH_SUCCESS;
79}82}
80 83 
81-IMPL_OP_INFERSHAPE(TileWithAxis).InferShape(InferShape4TileWithAxis);84+static ge::graphStatus InferDataType4TileWithAxis(gert::InferDataTypeContext* context)
85+{
86+ context->SetOutputDataType(0, context->GetInputDataType(0));
87+ return ge::GRAPH_SUCCESS;
88+}
89+ 
90+IMPL_OP_INFERSHAPE(TileWithAxis).InferShape(InferShape4TileWithAxis).InferDataType(InferDataType4TileWithAxis);
82 91 
83} // namespace ops92} // namespace ops
@@ -36,8 +36,8 @@ using Ops::Base::FloorDiv;
36constexpr size_t WORKSPACE_NUM = 1;36constexpr size_t WORKSPACE_NUM = 1;
37constexpr int64_t CACHE_BUF_SIZE = 16 * 1024; // 16 KB37constexpr int64_t CACHE_BUF_SIZE = 16 * 1024; // 16 KB
38 38 
39-static ge::graphStatus GetPlatformInfo(39+static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t* ubSize, int64_t* coreNum,
40- gert::TilingContext* context, uint64_t* ubSize, int64_t* coreNum, uint64_t* blockSize, uint64_t* cacheLineSize)40+ uint64_t* blockSize, uint64_t* cacheLineSize)
41{41{
42 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();42 fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
43 OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);43 OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);
@@ -78,13 +78,13 @@ static ge::graphStatus GetShapeAttrsInfo(gert::TilingContext* context, ShapeAttr
78 78 
79 int64_t x1Rank = static_cast<int64_t>(x1Shape.GetDimNum());79 int64_t x1Rank = static_cast<int64_t>(x1Shape.GetDimNum());
80 int64_t x2Rank = static_cast<int64_t>(x2Shape.GetDimNum());80 int64_t x2Rank = static_cast<int64_t>(x2Shape.GetDimNum());
81- OP_CHECK_IF(81+ OP_CHECK_IF(x1Rank != x2Rank, OP_LOGE(context, "x1 rank %ld != x2 rank %ld", x1Rank, x2Rank),
82- x1Rank != x2Rank, OP_LOGE(context, "x1 rank %ld != x2 rank %ld", x1Rank, x2Rank), return ge::GRAPH_FAILED);82+ return ge::GRAPH_FAILED);
83 for (int64_t i = 0; i < x1Rank; ++i) {83 for (int64_t i = 0; i < x1Rank; ++i) {
84 int64_t d1 = x1Shape.GetDim(static_cast<size_t>(i));84 int64_t d1 = x1Shape.GetDim(static_cast<size_t>(i));
85 int64_t d2 = x2Shape.GetDim(static_cast<size_t>(i));85 int64_t d2 = x2Shape.GetDim(static_cast<size_t>(i));
86- OP_CHECK_IF(86+ OP_CHECK_IF(d1 != d2, OP_LOGE(context, "x1 dim[%ld]=%ld != x2 dim[%ld]=%ld", i, d1, i, d2),
87- d1 != d2, OP_LOGE(context, "x1 dim[%ld]=%ld != x2 dim[%ld]=%ld", i, d1, i, d2), return ge::GRAPH_FAILED);87+ return ge::GRAPH_FAILED);
88 }88 }
89 89 
90 auto inputDesc = context->GetInputDesc(0);90 auto inputDesc = context->GetInputDesc(0);
@@ -137,8 +137,26 @@ static ge::graphStatus GetShapeAttrsInfo(gert::TilingContext* context, ShapeAttr
137 return ge::GRAPH_SUCCESS;137 return ge::GRAPH_SUCCESS;
138}138}
139 139 
140-static ge::graphStatus HandleEmptyTensor(140+static void LogTilingData(gert::TilingContext* context, const DataCompareTilingData* tiling)
141- gert::TilingContext* context, DataCompareTilingData* tiling, const ShapeAttrsInfo* info)141+{
142+ OP_LOGI(context->GetNodeName(),
143+ "TilingData: axisNum=%d axisShape=[%ld,%ld] axisStride=[%ld,%ld] aLoopCntTotal=%ld "
144+ "aSplitChunkCnt=%ld aBigCoreLoopCnt=%ld aSmallCoreLoopCnt=%ld aBigCoreCnt=%d usedCoreNum=%d "
145+ "aSplitAxisIdx=%d rSplitAxisIdx=%d aUbFactor=%ld aUbFactorAlign=%ld rUbFactor=%ld "
146+ "rUbFactorAlign=%ld innerAProd=%ld innerAProdAlign=%ld innerRProd=%ld innerRProdAlign=%ld "
147+ "rLoopCntTotal=%ld preReduceUbSize=%ld postReduceUbSize=%ld tmpBufUbSize=%ld cacheBufUbSize=%ld "
148+ "rGroupCnt=%ld atol=%f rtol=%f",
149+ tiling->axisNum, tiling->axisShape[0], tiling->axisShape[1], tiling->axisStride[0], tiling->axisStride[1],
150+ tiling->aLoopCntTotal, tiling->aSplitChunkCnt, tiling->aBigCoreLoopCnt, tiling->aSmallCoreLoopCnt,
151+ tiling->aBigCoreCnt, tiling->usedCoreNum, tiling->aSplitAxisIdx, tiling->rSplitAxisIdx, tiling->aUbFactor,
152+ tiling->aUbFactorAlign, tiling->rUbFactor, tiling->rUbFactorAlign, tiling->innerAProd,
153+ tiling->innerAProdAlign, tiling->innerRProd, tiling->innerRProdAlign, tiling->rLoopCntTotal,
154+ tiling->preReduceUbSize, tiling->postReduceUbSize, tiling->tmpBufUbSize, tiling->cacheBufUbSize,
155+ tiling->rGroupCnt, tiling->atol, tiling->rtol);
156+}
157+ 
158+static ge::graphStatus HandleEmptyTensor(gert::TilingContext* context, DataCompareTilingData* tiling,
159+ const ShapeAttrsInfo* info)
142{160{
143 tiling->usedCoreNum = 0;161 tiling->usedCoreNum = 0;
144 tiling->axisShape[0] = info->totalElements;162 tiling->axisShape[0] = info->totalElements;
@@ -154,6 +172,7 @@ static ge::graphStatus HandleEmptyTensor(
154 wsSizes[0] = sysWsSize;172 wsSizes[0] = sysWsSize;
155 173 
156 OP_LOGI(context->GetNodeName(), "EMPTY tensor path, totalElements=0");174 OP_LOGI(context->GetNodeName(), "EMPTY tensor path, totalElements=0");
175+ LogTilingData(context, tiling);
157 return ge::GRAPH_SUCCESS;176 return ge::GRAPH_SUCCESS;
158}177}
159 178 
@@ -168,9 +187,9 @@ static void FuseAxis(DataCompareTilingData* tiling, int64_t totalElements)
168 tiling->axisStride[1] = 1;187 tiling->axisStride[1] = 1;
169}188}
170 189 
171-static ge::graphStatus ComputeUbFactorTailR(190+static ge::graphStatus ComputeUbFactorTailR(gert::TilingContext* context, DataCompareTilingData* tiling,
172- gert::TilingContext* context, DataCompareTilingData* tiling, uint64_t ubSize, uint64_t blockSize, int64_t typeSize,191+ uint64_t ubSize, uint64_t blockSize, int64_t typeSize,
173- int64_t totalElements)192+ int64_t totalElements)
174{193{
175 // All Reduce 恒为 tail-R194 // All Reduce 恒为 tail-R
176 tiling->aUbFactor = 1;195 tiling->aUbFactor = 1;
@@ -249,9 +268,8 @@ static bool ShouldUseGroup(int64_t aLoopCntTotal, int64_t rLoopCntTotal, int64_t
249 return (aLoopCntTotal <= coreNum / 2 && rLoopCntTotal > 1);268 return (aLoopCntTotal <= coreNum / 2 && rLoopCntTotal > 1);
250}269}
251 270 
252-static ge::graphStatus ComputeGroupSplit(271+static ge::graphStatus ComputeGroupSplit(gert::TilingContext* context, DataCompareTilingData* tiling, int64_t coreNum,
253- gert::TilingContext* context, DataCompareTilingData* tiling, int64_t coreNum, int64_t rLoopCntTotal,272+ int64_t rLoopCntTotal, int32_t* usedCoreNum)
254- int32_t* usedCoreNum)
255{273{
256 int64_t aOuter = tiling->aLoopCntTotal;274 int64_t aOuter = tiling->aLoopCntTotal;
257 int64_t rOuter = rLoopCntTotal;275 int64_t rOuter = rLoopCntTotal;
@@ -275,9 +293,8 @@ static ge::graphStatus ComputeGroupSplit(
275 int64_t rGroupCnt = numBlocks / aOuter;293 int64_t rGroupCnt = numBlocks / aOuter;
276 tiling->rGroupCnt = rGroupCnt;294 tiling->rGroupCnt = rGroupCnt;
277 295 
278- OP_CHECK_IF(296+ OP_CHECK_IF(context->SetScheduleMode(1) != ge::GRAPH_SUCCESS, OP_LOGE(context, "Failed to set ScheduleMode"),
279- context->SetScheduleMode(1) != ge::GRAPH_SUCCESS, OP_LOGE(context, "Failed to set ScheduleMode"),297+ return ge::GRAPH_FAILED);
280- return ge::GRAPH_FAILED);
281 298 
282 return ge::GRAPH_SUCCESS;299 return ge::GRAPH_SUCCESS;
283}300}
@@ -300,26 +317,24 @@ static void SetWorkspaceSize(gert::TilingContext* context, const DataCompareTili
300 317 
301static ge::graphStatus DataCompareTilingFunc(gert::TilingContext* context)318static ge::graphStatus DataCompareTilingFunc(gert::TilingContext* context)
302{319{
320+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
303 OP_LOGD(context->GetNodeName(), "Begin DataCompareTilingFunc");321 OP_LOGD(context->GetNodeName(), "Begin DataCompareTilingFunc");
304 322 
305 uint64_t ubSize = 0;323 uint64_t ubSize = 0;
306 int64_t coreNum = 0;324 int64_t coreNum = 0;
307 uint64_t blockSize = 0;325 uint64_t blockSize = 0;
308 uint64_t cacheLineSize = 0;326 uint64_t cacheLineSize = 0;
309- OP_CHECK_IF(327+ OP_CHECK_IF(GetPlatformInfo(context, &ubSize, &coreNum, &blockSize, &cacheLineSize) != ge::GRAPH_SUCCESS,
310- GetPlatformInfo(context, &ubSize, &coreNum, &blockSize, &cacheLineSize) != ge::GRAPH_SUCCESS,328+ OP_LOGE(context, "GetPlatformInfo failed"), return ge::GRAPH_FAILED);
311- OP_LOGE(context, "GetPlatformInfo failed"), return ge::GRAPH_FAILED);
312 329 
313 ShapeAttrsInfo info;330 ShapeAttrsInfo info;
314- OP_CHECK_IF(331+ OP_CHECK_IF(GetShapeAttrsInfo(context, &info) != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetShapeAttrsInfo failed"),
315- GetShapeAttrsInfo(context, &info) != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetShapeAttrsInfo failed"),332+ return ge::GRAPH_FAILED);
316- return ge::GRAPH_FAILED);
317 333 
318 DataCompareTilingData* tiling = context->GetTilingData<DataCompareTilingData>();334 DataCompareTilingData* tiling = context->GetTilingData<DataCompareTilingData>();
319 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);335 OP_CHECK_NULL_WITH_CONTEXT(context, tiling);
320- OP_CHECK_IF(336+ OP_CHECK_IF(memset_s(tiling, sizeof(DataCompareTilingData), 0, sizeof(DataCompareTilingData)) != EOK,
321- memset_s(tiling, sizeof(DataCompareTilingData), 0, sizeof(DataCompareTilingData)) != EOK,337+ OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
322- OP_LOGE(context, "set tiling data error"), return ge::GRAPH_FAILED);
323 338 
324 if (info.isEmptyTensor) {339 if (info.isEmptyTensor) {
325 return HandleEmptyTensor(context, tiling, &info);340 return HandleEmptyTensor(context, tiling, &info);
@@ -331,10 +346,9 @@ static ge::graphStatus DataCompareTilingFunc(gert::TilingContext* context)
331 tiling->aSplitAxisIdx = 0;346 tiling->aSplitAxisIdx = 0;
332 tiling->rSplitAxisIdx = 1;347 tiling->rSplitAxisIdx = 1;
333 348 
334- OP_CHECK_IF(349+ OP_CHECK_IF(ComputeUbFactorTailR(context, tiling, ubSize, blockSize, info.typeSize, info.totalElements) !=
335- ComputeUbFactorTailR(context, tiling, ubSize, blockSize, info.typeSize, info.totalElements) !=350+ ge::GRAPH_SUCCESS,
336- ge::GRAPH_SUCCESS,351+ OP_LOGE(context, "ComputeUbFactorTailR failed"), return ge::GRAPH_FAILED);
337- OP_LOGE(context, "ComputeUbFactorTailR failed"), return ge::GRAPH_FAILED);
338 352 
339 ComputeUbSizes(tiling, info.typeSize, blockSize);353 ComputeUbSizes(tiling, info.typeSize, blockSize);
340 354 
@@ -348,9 +362,8 @@ static ge::graphStatus DataCompareTilingFunc(gert::TilingContext* context)
348 int32_t usedCoreNum = tiling->usedCoreNum;362 int32_t usedCoreNum = tiling->usedCoreNum;
349 if (ShouldUseGroup(tiling->aLoopCntTotal, rLoopCntTotal, coreNum)) {363 if (ShouldUseGroup(tiling->aLoopCntTotal, rLoopCntTotal, coreNum)) {
350 templateType = 1;364 templateType = 1;
351- OP_CHECK_IF(365+ OP_CHECK_IF(ComputeGroupSplit(context, tiling, coreNum, rLoopCntTotal, &usedCoreNum) != ge::GRAPH_SUCCESS,
352- ComputeGroupSplit(context, tiling, coreNum, rLoopCntTotal, &usedCoreNum) != ge::GRAPH_SUCCESS,366+ OP_LOGE(context, "ComputeGroupSplit failed"), return ge::GRAPH_FAILED);
353- OP_LOGE(context, "ComputeGroupSplit failed"), return ge::GRAPH_FAILED);
354 }367 }
355 368 
356 tiling->atol = info.atol;369 tiling->atol = info.atol;
@@ -361,12 +374,12 @@ static ge::graphStatus DataCompareTilingFunc(gert::TilingContext* context)
361 374 
362 bool isGroup = (templateType == 1);375 bool isGroup = (templateType == 1);
363 SetWorkspaceSize(context, tiling, isGroup);376 SetWorkspaceSize(context, tiling, isGroup);
377+ LogTilingData(context, tiling);
364 378 
365- OP_LOGI(379+ OP_LOGI(context->GetNodeName(),
366- context->GetNodeName(),380+ "Tiling done: totalElements=%ld, rUbFactor=%ld, rLoopCntTotal=%ld, "
367- "Tiling done: totalElements=%ld, rUbFactor=%ld, rLoopCntTotal=%ld, "381+ "usedCoreNum=%d, isGroup=%d, templateType=%d",
368- "usedCoreNum=%d, isGroup=%d, templateType=%d",382+ info.totalElements, tiling->rUbFactor, rLoopCntTotal, usedCoreNum, static_cast<int>(isGroup), templateType);
369- info.totalElements, tiling->rUbFactor, rLoopCntTotal, usedCoreNum, static_cast<int>(isGroup), templateType);
370 383 
371 return ge::GRAPH_SUCCESS;384 return ge::GRAPH_SUCCESS;
372}385}
@@ -17,6 +17,7 @@
17 */17 */
18#include "register/op_impl_registry.h"18#include "register/op_impl_registry.h"
19#include "op_common/log/log.h"19#include "op_common/log/log.h"
20+#include "util/shape_util.h"
20 21 
21using namespace ge;22using namespace ge;
22 23 
@@ -45,29 +46,25 @@ static ge::graphStatus InferShape4DataCompare(gert::InferShapeContext* context)
45 const int64_t x2Rank = static_cast<int64_t>(x2Shape->GetDimNum());46 const int64_t x2Rank = static_cast<int64_t>(x2Shape->GetDimNum());
46 47 
47 // rank 校验 ≤ 848 // rank 校验 ≤ 8
48- OP_CHECK_IF(49+ OP_CHECK_IF(x1Rank > static_cast<int64_t>(kMaxRank),
49- x1Rank > static_cast<int64_t>(kMaxRank),50+ OP_LOGE(context->GetNodeName(), "x1 rank %ld exceeds max %zu", x1Rank, kMaxRank), return GRAPH_FAILED);
50- OP_LOGE(context->GetNodeName(), "x1 rank %ld exceeds max %zu", x1Rank, kMaxRank), return GRAPH_FAILED);51+ OP_CHECK_IF(x2Rank > static_cast<int64_t>(kMaxRank),
51- OP_CHECK_IF(52+ OP_LOGE(context->GetNodeName(), "x2 rank %ld exceeds max %zu", x2Rank, kMaxRank), return GRAPH_FAILED);
52- x2Rank > static_cast<int64_t>(kMaxRank),
53- OP_LOGE(context->GetNodeName(), "x2 rank %ld exceeds max %zu", x2Rank, kMaxRank), return GRAPH_FAILED);
54 53 
55 // shape 一致性校验54 // shape 一致性校验
56- OP_CHECK_IF(55+ OP_CHECK_IF(x1Rank != x2Rank, OP_LOGE(context->GetNodeName(), "x1 rank %ld != x2 rank %ld", x1Rank, x2Rank),
57- x1Rank != x2Rank, OP_LOGE(context->GetNodeName(), "x1 rank %ld != x2 rank %ld", x1Rank, x2Rank),56+ return GRAPH_FAILED);
58- return GRAPH_FAILED);
59 for (int64_t i = 0; i < x1Rank; ++i) {57 for (int64_t i = 0; i < x1Rank; ++i) {
60- OP_CHECK_IF(58+ OP_CHECK_IF(x1Shape->GetDim(static_cast<size_t>(i)) != x2Shape->GetDim(static_cast<size_t>(i)),
61- x1Shape->GetDim(static_cast<size_t>(i)) != x2Shape->GetDim(static_cast<size_t>(i)),59+ OP_LOGE(context->GetNodeName(), "x1 dim[%ld]=%ld != x2 dim[%ld]=%ld", i,
62- OP_LOGE(60+ x1Shape->GetDim(static_cast<size_t>(i)), i, x2Shape->GetDim(static_cast<size_t>(i))),
63- context->GetNodeName(), "x1 dim[%ld]=%ld != x2 dim[%ld]=%ld", i,61+ return GRAPH_FAILED);
64- x1Shape->GetDim(static_cast<size_t>(i)), i, x2Shape->GetDim(static_cast<size_t>(i))),
65- return GRAPH_FAILED);
66 }62 }
67 63 
68 // 输出固定为标量(0 维)64 // 输出固定为标量(0 维)
69 *numShape = gert::Shape();65 *numShape = gert::Shape();
70 66 
67+ OP_LOGI(context->GetNodeName(), "DataCompare output shape: %s.", Ops::Base::ToString(*numShape).c_str());
71 OP_LOGD(context->GetNodeName(), "End InferShape: x1Rank=%ld, output=scalar", x1Rank);68 OP_LOGD(context->GetNodeName(), "End InferShape: x1Rank=%ld, output=scalar", x1Rank);
72 return GRAPH_SUCCESS;69 return GRAPH_SUCCESS;
73}70}
@@ -30,20 +30,18 @@ using namespace ge;
30namespace xdivy {30namespace xdivy {
31 31 
32// === 算子特定常量 — 新算子必须修改 ===32// === 算子特定常量 — 新算子必须修改 ===
33-constexpr int64_t kPhysNodesFp32 = 3; // 物理存活节点 P (FP32 路径, 无 Cast)33+constexpr int64_t kPhysNodesFp32 = 3; // 物理存活节点 P (FP32 路径, 无 Cast)
34-constexpr int64_t kPhysNodesFp16 = 4; // 物理存活节点 P (FP16/BF16 路径, 有 Cast)34+constexpr int64_t kPhysNodesFp16 = 4; // 物理存活节点 P (FP16/BF16 路径, 有 Cast)
35-constexpr int64_t kBufDtypeSize = 4; // per_buf_elems 永远除 sizeof(float32) (cast.md §Tile)35+constexpr int64_t kBufDtypeSize = 4; // per_buf_elems 永远除 sizeof(float32) (cast.md §Tile)
36 36 
37// 5.1 PadAndSqueeze37// 5.1 PadAndSqueeze
38 38 
39-bool PadAndSqueeze(39+bool PadAndSqueeze(const std::vector<std::vector<int64_t>>& input_shapes,
40- const std::vector<std::vector<int64_t>>& input_shapes,40+ const std::vector<std::vector<int64_t>>& output_shapes, std::vector<int64_t>& maximum_bro_shape,
41- const std::vector<std::vector<int64_t>>& output_shapes,41+ std::vector<std::vector<int64_t>>& normal_input_shapes,
42- std::vector<int64_t>& maximum_bro_shape,42+ std::vector<std::vector<int64_t>>& normal_output_shapes)
43- std::vector<std::vector<int64_t>>& normal_input_shapes,
44- std::vector<std::vector<int64_t>>& normal_output_shapes)
45{43{
46- int64_t num_inputs = (int64_t)input_shapes.size();44+ int64_t num_inputs = (int64_t)input_shapes.size();
47 int64_t num_outputs = (int64_t)output_shapes.size();45 int64_t num_outputs = (int64_t)output_shapes.size();
48 int64_t max_rank = 0;46 int64_t max_rank = 0;
49 for (auto& s : input_shapes)47 for (auto& s : input_shapes)
@@ -57,8 +55,10 @@ bool PadAndSqueeze(
57 return p;55 return p;
58 };56 };
59 std::vector<std::vector<int64_t>> padded_in(num_inputs), padded_out(num_outputs);57 std::vector<std::vector<int64_t>> padded_in(num_inputs), padded_out(num_outputs);
60- for (int64_t i = 0; i < num_inputs; i++) padded_in[i] = pad(input_shapes[i]);58+ for (int64_t i = 0; i < num_inputs; i++)
61- for (int64_t i = 0; i < num_outputs; i++) padded_out[i] = pad(output_shapes[i]);59+ padded_in[i] = pad(input_shapes[i]);
60+ for (int64_t i = 0; i < num_outputs; i++)
61+ padded_out[i] = pad(output_shapes[i]);
62 maximum_bro_shape.clear();62 maximum_bro_shape.clear();
63 normal_input_shapes.assign(num_inputs, std::vector<int64_t>());63 normal_input_shapes.assign(num_inputs, std::vector<int64_t>());
64 normal_output_shapes.assign(num_outputs, std::vector<int64_t>());64 normal_output_shapes.assign(num_outputs, std::vector<int64_t>());
@@ -66,31 +66,37 @@ bool PadAndSqueeze(
66 bool all_one = true;66 bool all_one = true;
67 int64_t max_dim = 0;67 int64_t max_dim = 0;
68 for (int64_t i = 0; i < num_inputs; i++) {68 for (int64_t i = 0; i < num_inputs; i++) {
69- if (padded_in[i][d] != 1) all_one = false;69+ if (padded_in[i][d] != 1)
70+ all_one = false;
70 max_dim = std::max(max_dim, padded_in[i][d]);71 max_dim = std::max(max_dim, padded_in[i][d]);
71 }72 }
72 for (int64_t i = 0; i < num_outputs; i++) {73 for (int64_t i = 0; i < num_outputs; i++) {
73- if (padded_out[i][d] != 1) all_one = false;74+ if (padded_out[i][d] != 1)
75+ all_one = false;
74 max_dim = std::max(max_dim, padded_out[i][d]);76 max_dim = std::max(max_dim, padded_out[i][d]);
75 }77 }
76 if (!all_one) {78 if (!all_one) {
77 maximum_bro_shape.push_back(max_dim);79 maximum_bro_shape.push_back(max_dim);
78- for (int64_t i = 0; i < num_inputs; i++) normal_input_shapes[i].push_back(padded_in[i][d]);80+ for (int64_t i = 0; i < num_inputs; i++)
79- for (int64_t i = 0; i < num_outputs; i++) normal_output_shapes[i].push_back(padded_out[i][d]);81+ normal_input_shapes[i].push_back(padded_in[i][d]);
82+ for (int64_t i = 0; i < num_outputs; i++)
83+ normal_output_shapes[i].push_back(padded_out[i][d]);
80 }84 }
81 }85 }
82 if (maximum_bro_shape.empty()) {86 if (maximum_bro_shape.empty()) {
83 maximum_bro_shape.push_back(1);87 maximum_bro_shape.push_back(1);
84- for (int64_t i = 0; i < num_inputs; i++) normal_input_shapes[i].push_back(1);88+ for (int64_t i = 0; i < num_inputs; i++)
85- for (int64_t i = 0; i < num_outputs; i++) normal_output_shapes[i].push_back(1);89+ normal_input_shapes[i].push_back(1);
90+ for (int64_t i = 0; i < num_outputs; i++)
91+ normal_output_shapes[i].push_back(1);
86 }92 }
87 return true;93 return true;
88}94}
89 95 
90// 5.2 FindSplitAxis — 从最内轴向外扫描,d_k × inner > per_buf_elems 时切分96// 5.2 FindSplitAxis — 从最内轴向外扫描,d_k × inner > per_buf_elems 时切分
91 97 
92-bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,98+bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape, int64_t dtype_size, int64_t ub_per_core,
93- int64_t dtype_size, int64_t ub_per_core, int64_t phys_nodes, SplitResult& out)99+ int64_t phys_nodes, SplitResult& out)
94{100{
95 int64_t per_buf_bytes = (ub_per_core / phys_nodes) & ~31LL;101 int64_t per_buf_bytes = (ub_per_core / phys_nodes) & ~31LL;
96 int64_t per_buf_elems = per_buf_bytes / dtype_size;102 int64_t per_buf_elems = per_buf_bytes / dtype_size;
@@ -119,39 +125,50 @@ bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,
119 125 
120// 5.3 MultiCoreSplit126// 5.3 MultiCoreSplit
121 127 
122-bool MultiCoreSplit(const std::vector<int64_t>& max_bro_shape,128+bool MultiCoreSplit(const std::vector<int64_t>& max_bro_shape, const SplitResult& ub_split, int64_t max_cores,
123- const SplitResult& ub_split, int64_t max_cores, MultiCoreResult& out)129+ MultiCoreResult& out)
124{130{
125 int64_t k = ub_split.axis, outer_prod = 1;131 int64_t k = ub_split.axis, outer_prod = 1;
126- for (int64_t j = 0; j < k; j++) outer_prod *= max_bro_shape[j];132+ for (int64_t j = 0; j < k; j++)
133+ outer_prod *= max_bro_shape[j];
127 out.total_tiles = outer_prod * ub_split.a_o;134 out.total_tiles = outer_prod * ub_split.a_o;
128- out.num_cores = (out.total_tiles < max_cores) ? out.total_tiles : max_cores;135+ out.num_cores = (out.total_tiles < max_cores) ? out.total_tiles : max_cores;
129- out.tiles_main = out.total_tiles / out.num_cores;136+ out.tiles_main = out.total_tiles / out.num_cores;
130- out.cores_tail = out.total_tiles % out.num_cores;137+ out.cores_tail = out.total_tiles % out.num_cores;
131 return true;138 return true;
132}139}
133 140 
134// 5.5 地址偏移141// 5.5 地址偏移
135 142 
136-bool PrecomputeInputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides) {143+bool PrecomputeInputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides)
144+{
137 int64_t rank = (int64_t)s.size();145 int64_t rank = (int64_t)s.size();
138 strides.assign(rank, 0);146 strides.assign(rank, 0);
139 for (int64_t d = rank - 1; d >= 0; d--) {147 for (int64_t d = rank - 1; d >= 0; d--) {
140- if (s[d] == 1) { strides[d] = 0; continue; }148+ if (s[d] == 1) {
149+ strides[d] = 0;
150+ continue;
151+ }
141 int64_t prod = 1;152 int64_t prod = 1;
142- for (int64_t j = d + 1; j < rank; j++) prod *= s[j];153+ for (int64_t j = d + 1; j < rank; j++)
154+ prod *= s[j];
143 strides[d] = prod;155 strides[d] = prod;
144 }156 }
145 return true;157 return true;
146}158}
147 159 
148-bool PrecomputeOutputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides) {160+bool PrecomputeOutputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides)
161+{
149 int64_t rank = (int64_t)s.size();162 int64_t rank = (int64_t)s.size();
150 strides.assign(rank, 0);163 strides.assign(rank, 0);
151 for (int64_t d = rank - 1; d >= 0; d--) {164 for (int64_t d = rank - 1; d >= 0; d--) {
152- if (s[d] == 1) { strides[d] = 0; continue; }165+ if (s[d] == 1) {
166+ strides[d] = 0;
167+ continue;
168+ }
153 int64_t prod = 1;169 int64_t prod = 1;
154- for (int64_t j = d + 1; j < rank; j++) prod *= s[j];170+ for (int64_t j = d + 1; j < rank; j++)
171+ prod *= s[j];
155 strides[d] = prod;172 strides[d] = prod;
156 }173 }
157 return true;174 return true;
@@ -172,7 +189,8 @@ static std::string Arr2String(const int64_t* arr, int64_t n)
172 std::ostringstream oss;189 std::ostringstream oss;
173 oss << "[";190 oss << "[";
174 if (n > 0) {191 if (n > 0) {
175- for (int64_t i = 0; i < n - 1; ++i) oss << arr[i] << ",";192+ for (int64_t i = 0; i < n - 1; ++i)
193+ oss << arr[i] << ",";
176 oss << arr[n - 1];194 oss << arr[n - 1];
177 }195 }
178 oss << "]";196 oss << "]";
@@ -188,23 +206,28 @@ ge::graphStatus XdivyTiling::GetShapeInfo()
188 206 
189 // 读输入 shape207 // 读输入 shape
190 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetInputsNum(); ++i) {208 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetInputsNum(); ++i) {
191- auto shape = ctx_->GetInputShape(i); OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);209+ auto shape = ctx_->GetInputShape(i);
210+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);
192 std::vector<int64_t> dims;211 std::vector<int64_t> dims;
193 gert::Shape s = shape->GetStorageShape();212 gert::Shape s = shape->GetStorageShape();
194- for (size_t d = 0; d < s.GetDimNum(); ++d) dims.push_back(s.GetDim(d));213+ for (size_t d = 0; d < s.GetDimNum(); ++d)
214+ dims.push_back(s.GetDim(d));
195 raw_input_shapes_.push_back(dims);215 raw_input_shapes_.push_back(dims);
196 }216 }
197 217 
198 // 读输出 shape218 // 读输出 shape
199 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetOutputsNum(); ++i) {219 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetOutputsNum(); ++i) {
200- auto shape = ctx_->GetOutputShape(i); OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);220+ auto shape = ctx_->GetOutputShape(i);
221+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);
201 std::vector<int64_t> dims;222 std::vector<int64_t> dims;
202 gert::Shape s = shape->GetStorageShape();223 gert::Shape s = shape->GetStorageShape();
203- for (size_t d = 0; d < s.GetDimNum(); ++d) dims.push_back(s.GetDim(d));224+ for (size_t d = 0; d < s.GetDimNum(); ++d)
225+ dims.push_back(s.GetDim(d));
204 raw_output_shapes_.push_back(dims);226 raw_output_shapes_.push_back(dims);
205 }227 }
206 228 
207- auto inputDesc = ctx_->GetInputDesc(0); OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);229+ auto inputDesc = ctx_->GetInputDesc(0);
230+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);
208 ge::DataType dtype = inputDesc->GetDataType();231 ge::DataType dtype = inputDesc->GetDataType();
209 if (dtype == ge::DT_FLOAT) {232 if (dtype == ge::DT_FLOAT) {
210 dtype_size_ = 4;233 dtype_size_ = 4;
@@ -217,17 +240,16 @@ ge::graphStatus XdivyTiling::GetShapeInfo()
217 return GRAPH_FAILED;240 return GRAPH_FAILED;
218 }241 }
219 242 
220- PadAndSqueeze(raw_input_shapes_, raw_output_shapes_,243+ PadAndSqueeze(raw_input_shapes_, raw_output_shapes_, max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
221- max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
222 rank_ = (int64_t)max_bro_shape_.size();244 rank_ = (int64_t)max_bro_shape_.size();
223 245 
224- OP_LOGI(ctx_->GetNodeName(), "Xdivy GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu",246+ OP_LOGI(ctx_->GetNodeName(), "Xdivy GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu", rank_, phys_nodes_,
225- rank_, phys_nodes_, compileInfo->ubSize, compileInfo->coreNum);247+ compileInfo->ubSize, compileInfo->coreNum);
226 248 
227 return GRAPH_SUCCESS;249 return GRAPH_SUCCESS;
228}250}
229 251 
230-template<int64_t R>252+template <int64_t R>
231ge::graphStatus XdivyTiling::DoTilingAndSet()253ge::graphStatus XdivyTiling::DoTilingAndSet()
232{254{
233 auto* tiling = ctx_->GetTilingData<XdivyTilingData<R>>();255 auto* tiling = ctx_->GetTilingData<XdivyTilingData<R>>();
@@ -243,81 +265,81 @@ ge::graphStatus XdivyTiling::DoTilingAndSet()
243 FindSplitAxis(max_bro_shape_, kBufDtypeSize, ub_per_core, phys_nodes_, tiling->split);265 FindSplitAxis(max_bro_shape_, kBufDtypeSize, ub_per_core, phys_nodes_, tiling->split);
244 MultiCoreSplit(max_bro_shape_, tiling->split, (int64_t)compileInfo->coreNum, tiling->multicore);266 MultiCoreSplit(max_bro_shape_, tiling->split, (int64_t)compileInfo->coreNum, tiling->multicore);
245 267 
246- int64_t num_in = (int64_t)normal_input_shapes_.size();268+ int64_t num_in = (int64_t)normal_input_shapes_.size();
247 int64_t num_out = (int64_t)normal_output_shapes_.size();269 int64_t num_out = (int64_t)normal_output_shapes_.size();
248 std::vector<std::vector<int64_t>> in_strides(num_in), out_strides(num_out);270 std::vector<std::vector<int64_t>> in_strides(num_in), out_strides(num_out);
249- for (int64_t i = 0; i < num_in; i++) PrecomputeInputStrides(normal_input_shapes_[i], in_strides[i]);271+ for (int64_t i = 0; i < num_in; i++)
250- for (int64_t i = 0; i < num_out; i++) PrecomputeOutputStrides(normal_output_shapes_[i], out_strides[i]);272+ PrecomputeInputStrides(normal_input_shapes_[i], in_strides[i]);
273+ for (int64_t i = 0; i < num_out; i++)
274+ PrecomputeOutputStrides(normal_output_shapes_[i], out_strides[i]);
251 275 
252 tiling->rank = rank_;276 tiling->rank = rank_;
253 int64_t delta = R - rank_;277 int64_t delta = R - rank_;
254 278 
255 // max_bro_shape: 前补 1279 // max_bro_shape: 前补 1
256- for (int64_t d = 0; d < delta; d++) tiling->max_bro_shape[d] = 1;280+ for (int64_t d = 0; d < delta; d++)
257- for (int64_t d = 0; d < rank_; d++) tiling->max_bro_shape[d + delta] = max_bro_shape_[d];281+ tiling->max_bro_shape[d] = 1;
282+ for (int64_t d = 0; d < rank_; d++)
283+ tiling->max_bro_shape[d + delta] = max_bro_shape_[d];
258 284 
259 tiling->split.axis += delta;285 tiling->split.axis += delta;
260 286 
261- tiling->num_inputs = num_in;287+ tiling->num_inputs = num_in;
262 tiling->num_outputs = num_out;288 tiling->num_outputs = num_out;
263 289 
264 // input: 前补 shape=1 stride=0290 // input: 前补 shape=1 stride=0
265 for (int64_t i = 0; i < num_in; i++) {291 for (int64_t i = 0; i < num_in; i++) {
266 for (int64_t d = 0; d < delta; d++) {292 for (int64_t d = 0; d < delta; d++) {
267- tiling->input_shapes[i][d] = 1;293+ tiling->input_shapes[i][d] = 1;
268 tiling->input_strides[i][d] = 0;294 tiling->input_strides[i][d] = 0;
269 }295 }
270 for (int64_t d = 0; d < rank_; d++) {296 for (int64_t d = 0; d < rank_; d++) {
271- tiling->input_shapes[i][d + delta] = normal_input_shapes_[i][d];297+ tiling->input_shapes[i][d + delta] = normal_input_shapes_[i][d];
272 tiling->input_strides[i][d + delta] = in_strides[i][d];298 tiling->input_strides[i][d + delta] = in_strides[i][d];
273 }299 }
274 }300 }
275 // 未使用 input slot: 全填 1/0301 // 未使用 input slot: 全填 1/0
276 for (int64_t i = num_in; i < kMaxInputSlots; i++)302 for (int64_t i = num_in; i < kMaxInputSlots; i++)
277 for (int64_t d = 0; d < R; d++) {303 for (int64_t d = 0; d < R; d++) {
278- tiling->input_shapes[i][d] = 1;304+ tiling->input_shapes[i][d] = 1;
279 tiling->input_strides[i][d] = 0;305 tiling->input_strides[i][d] = 0;
280 }306 }
281 307 
282 // output: 前补 shape=1 stride=0308 // output: 前补 shape=1 stride=0
283 for (int64_t i = 0; i < num_out; i++) {309 for (int64_t i = 0; i < num_out; i++) {
284 for (int64_t d = 0; d < delta; d++) {310 for (int64_t d = 0; d < delta; d++) {
285- tiling->output_shapes[i][d] = 1;311+ tiling->output_shapes[i][d] = 1;
286 tiling->output_strides[i][d] = 0;312 tiling->output_strides[i][d] = 0;
287 }313 }
288 for (int64_t d = 0; d < rank_; d++) {314 for (int64_t d = 0; d < rank_; d++) {
289- tiling->output_shapes[i][d + delta] = normal_output_shapes_[i][d];315+ tiling->output_shapes[i][d + delta] = normal_output_shapes_[i][d];
290 tiling->output_strides[i][d + delta] = out_strides[i][d];316 tiling->output_strides[i][d + delta] = out_strides[i][d];
291 }317 }
292 }318 }
293 for (int64_t i = num_out; i < kMaxOutputSlots; i++)319 for (int64_t i = num_out; i < kMaxOutputSlots; i++)
294 for (int64_t d = 0; d < R; d++) {320 for (int64_t d = 0; d < R; d++) {
295- tiling->output_shapes[i][d] = 1;321+ tiling->output_shapes[i][d] = 1;
296 tiling->output_strides[i][d] = 0;322 tiling->output_strides[i][d] = 0;
297 }323 }
298 324 
299 ctx_->SetBlockDim(tiling->multicore.num_cores);325 ctx_->SetBlockDim(tiling->multicore.num_cores);
300 326 
301 // 维测: TilingData 全部字段327 // 维测: TilingData 全部字段
302- OP_LOGI(ctx_->GetNodeName(), "Xdivy TilingData: per_buf_bytes=%ld rank=%ld->R=%d "328+ OP_LOGI(ctx_->GetNodeName(),
329+ "Xdivy TilingData: per_buf_bytes=%ld rank=%ld->R=%d "
303 "max_bro_shape=%s "330 "max_bro_shape=%s "
304 "split(axis=%ld a_i=%ld a_o=%ld a_i_tail=%ld) "331 "split(axis=%ld a_i=%ld a_o=%ld a_i_tail=%ld) "
305 "multi(cores=%ld tiles=%ld main=%ld core_tail=%ld) num_in=%ld num_out=%ld",332 "multi(cores=%ld tiles=%ld main=%ld core_tail=%ld) num_in=%ld num_out=%ld",
306- tiling->per_buf_bytes, rank_, (int)R,333+ tiling->per_buf_bytes, rank_, (int)R, Arr2String(tiling->max_bro_shape, R).c_str(), tiling->split.axis,
307- Arr2String(tiling->max_bro_shape, R).c_str(),334+ tiling->split.a_i, tiling->split.a_o, tiling->split.a_i_tail, tiling->multicore.num_cores,
308- tiling->split.axis, tiling->split.a_i, tiling->split.a_o, tiling->split.a_i_tail,335+ tiling->multicore.total_tiles, tiling->multicore.tiles_main, tiling->multicore.cores_tail, num_in, num_out);
309- tiling->multicore.num_cores, tiling->multicore.total_tiles,
310- tiling->multicore.tiles_main, tiling->multicore.cores_tail,
311- num_in, num_out);
312 336 
313 for (int64_t i = 0; i < num_in; i++)337 for (int64_t i = 0; i < num_in; i++)
314- OP_LOGI(ctx_->GetNodeName(), "Xdivy TilingData input[%ld]: shape=%s stride=%s",338+ OP_LOGI(ctx_->GetNodeName(), "Xdivy TilingData input[%ld]: shape=%s stride=%s", i,
315- i, Arr2String(tiling->input_shapes[i], R).c_str(),339+ Arr2String(tiling->input_shapes[i], R).c_str(), Arr2String(tiling->input_strides[i], R).c_str());
316- Arr2String(tiling->input_strides[i], R).c_str());
317 for (int64_t i = 0; i < num_out; i++)340 for (int64_t i = 0; i < num_out; i++)
318- OP_LOGI(ctx_->GetNodeName(), "Xdivy TilingData output[%ld]: shape=%s stride=%s",341+ OP_LOGI(ctx_->GetNodeName(), "Xdivy TilingData output[%ld]: shape=%s stride=%s", i,
319- i, Arr2String(tiling->output_shapes[i], R).c_str(),342+ Arr2String(tiling->output_shapes[i], R).c_str(), Arr2String(tiling->output_strides[i], R).c_str());
320- Arr2String(tiling->output_strides[i], R).c_str());
321 343 
322 return GRAPH_SUCCESS;344 return GRAPH_SUCCESS;
323}345}
@@ -325,7 +347,8 @@ ge::graphStatus XdivyTiling::DoTilingAndSet()
325ge::graphStatus XdivyTiling::RunTiling()347ge::graphStatus XdivyTiling::RunTiling()
326{348{
327 ge::graphStatus ret = GetShapeInfo();349 ge::graphStatus ret = GetShapeInfo();
328- if (ret != GRAPH_SUCCESS) return ret;350+ if (ret != GRAPH_SUCCESS)
351+ return ret;
329 352 
330 int64_t mapped = (rank_ <= 4) ? 4 : 8;353 int64_t mapped = (rank_ <= 4) ? 4 : 8;
331 if (mapped == 4) {354 if (mapped == 4) {
@@ -340,11 +363,13 @@ ge::graphStatus XdivyTiling::RunTiling()
340 363 
341static ge::graphStatus TilingFuncXdivy(gert::TilingContext* context)364static ge::graphStatus TilingFuncXdivy(gert::TilingContext* context)
342{365{
366+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
343 XdivyTiling xdivyTiling(context);367 XdivyTiling xdivyTiling(context);
344 auto ret = xdivyTiling.RunTiling();368 auto ret = xdivyTiling.RunTiling();
345- if (ret != GRAPH_SUCCESS) return ret;369+ if (ret != GRAPH_SUCCESS)
370+ return ret;
346 size_t* workspaces = context->GetWorkspaceSizes(1);371 size_t* workspaces = context->GetWorkspaceSizes(1);
347- workspaces[0] = 16 * 1024 * 1024; // 16MB372+ workspaces[0] = 16 * 1024 * 1024; // 16MB
348 return GRAPH_SUCCESS;373 return GRAPH_SUCCESS;
349}374}
350 375 
@@ -14,6 +14,7 @@
14#include "register/op_impl_registry.h"14#include "register/op_impl_registry.h"
15#include "infershape_broadcast_util.h"15#include "infershape_broadcast_util.h"
16#include "log/log.h"16#include "log/log.h"
17+#include "util/shape_util.h"
17 18 
18using namespace ge;19using namespace ge;
19 20 
@@ -21,9 +22,21 @@ namespace ops {
21 22 
22static ge::graphStatus InferShapeForXdivy(gert::InferShapeContext* context)23static ge::graphStatus InferShapeForXdivy(gert::InferShapeContext* context)
23{24{
24- return Ops::Base::InferShape4Broadcast(context);25+ const ge::graphStatus status = Ops::Base::InferShape4Broadcast(context);
26+ if (status == ge::GRAPH_SUCCESS) {
27+ const gert::Shape* outputShape = context->GetOutputShape(0);
28+ OP_CHECK_NULL_WITH_CONTEXT(context, outputShape);
29+ OP_LOGI(context->GetNodeName(), "Xdivy output shape: %s.", Ops::Base::ToString(*outputShape).c_str());
30+ }
31+ return status;
25}32}
26 33 
27-IMPL_OP_INFERSHAPE(Xdivy).InferShape(InferShapeForXdivy);34+static ge::graphStatus InferDataTypeForXdivy(gert::InferDataTypeContext* context)
35+{
36+ context->SetOutputDataType(0, context->GetInputDataType(0));
37+ return ge::GRAPH_SUCCESS;
38+}
39+ 
40+IMPL_OP_INFERSHAPE(Xdivy).InferShape(InferShapeForXdivy).InferDataType(InferDataTypeForXdivy);
28 41 
29} // namespace ops42} // namespace ops
@@ -8,7 +8,6 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10 10 
11- 
12// Xlog1py Tiling — arch35 实现11// Xlog1py Tiling — arch35 实现
13#include "xlog1py_tiling_arch35.h"12#include "xlog1py_tiling_arch35.h"
14#include "../../op_kernel/arch35/xlog1py_struct.h"13#include "../../op_kernel/arch35/xlog1py_struct.h"
@@ -26,20 +25,20 @@ namespace xlog1py {
26 25 
27constexpr int64_t kPhysNodesFp32 = 3;26constexpr int64_t kPhysNodesFp32 = 3;
28constexpr int64_t kPhysNodesFp16 = 4;27constexpr int64_t kPhysNodesFp16 = 4;
29-constexpr int64_t kBufDtypeSize = 4;28+constexpr int64_t kBufDtypeSize = 4;
30 29 
31-bool PadAndSqueeze(30+bool PadAndSqueeze(const std::vector<std::vector<int64_t>>& input_shapes,
32- const std::vector<std::vector<int64_t>>& input_shapes,31+ const std::vector<std::vector<int64_t>>& output_shapes, std::vector<int64_t>& maximum_bro_shape,
33- const std::vector<std::vector<int64_t>>& output_shapes,32+ std::vector<std::vector<int64_t>>& normal_input_shapes,
34- std::vector<int64_t>& maximum_bro_shape,33+ std::vector<std::vector<int64_t>>& normal_output_shapes)
35- std::vector<std::vector<int64_t>>& normal_input_shapes,
36- std::vector<std::vector<int64_t>>& normal_output_shapes)
37{34{
38- int64_t num_inputs = (int64_t)input_shapes.size();35+ int64_t num_inputs = (int64_t)input_shapes.size();
39 int64_t num_outputs = (int64_t)output_shapes.size();36 int64_t num_outputs = (int64_t)output_shapes.size();
40 int64_t max_rank = 0;37 int64_t max_rank = 0;
41- for (auto& s : input_shapes) max_rank = std::max(max_rank, (int64_t)s.size());38+ for (auto& s : input_shapes)
42- for (auto& s : output_shapes) max_rank = std::max(max_rank, (int64_t)s.size());39+ max_rank = std::max(max_rank, (int64_t)s.size());
40+ for (auto& s : output_shapes)
41+ max_rank = std::max(max_rank, (int64_t)s.size());
43 auto pad = [&](const std::vector<int64_t>& s) {42 auto pad = [&](const std::vector<int64_t>& s) {
44 std::vector<int64_t> p;43 std::vector<int64_t> p;
45 p.assign(max_rank - (int64_t)s.size(), 1);44 p.assign(max_rank - (int64_t)s.size(), 1);
@@ -47,8 +46,10 @@ bool PadAndSqueeze(
47 return p;46 return p;
48 };47 };
49 std::vector<std::vector<int64_t>> padded_in(num_inputs), padded_out(num_outputs);48 std::vector<std::vector<int64_t>> padded_in(num_inputs), padded_out(num_outputs);
50- for (int64_t i = 0; i < num_inputs; i++) padded_in[i] = pad(input_shapes[i]);49+ for (int64_t i = 0; i < num_inputs; i++)
51- for (int64_t i = 0; i < num_outputs; i++) padded_out[i] = pad(output_shapes[i]);50+ padded_in[i] = pad(input_shapes[i]);
51+ for (int64_t i = 0; i < num_outputs; i++)
52+ padded_out[i] = pad(output_shapes[i]);
52 maximum_bro_shape.clear();53 maximum_bro_shape.clear();
53 normal_input_shapes.assign(num_inputs, std::vector<int64_t>());54 normal_input_shapes.assign(num_inputs, std::vector<int64_t>());
54 normal_output_shapes.assign(num_outputs, std::vector<int64_t>());55 normal_output_shapes.assign(num_outputs, std::vector<int64_t>());
@@ -56,29 +57,35 @@ bool PadAndSqueeze(
56 bool all_one = true;57 bool all_one = true;
57 int64_t max_dim = 0;58 int64_t max_dim = 0;
58 for (int64_t i = 0; i < num_inputs; i++) {59 for (int64_t i = 0; i < num_inputs; i++) {
59- if (padded_in[i][d] != 1) all_one = false;60+ if (padded_in[i][d] != 1)
61+ all_one = false;
60 max_dim = std::max(max_dim, padded_in[i][d]);62 max_dim = std::max(max_dim, padded_in[i][d]);
61 }63 }
62 for (int64_t i = 0; i < num_outputs; i++) {64 for (int64_t i = 0; i < num_outputs; i++) {
63- if (padded_out[i][d] != 1) all_one = false;65+ if (padded_out[i][d] != 1)
66+ all_one = false;
64 max_dim = std::max(max_dim, padded_out[i][d]);67 max_dim = std::max(max_dim, padded_out[i][d]);
65 }68 }
66 if (!all_one) {69 if (!all_one) {
67 maximum_bro_shape.push_back(max_dim);70 maximum_bro_shape.push_back(max_dim);
68- for (int64_t i = 0; i < num_inputs; i++) normal_input_shapes[i].push_back(padded_in[i][d]);71+ for (int64_t i = 0; i < num_inputs; i++)
69- for (int64_t i = 0; i < num_outputs; i++) normal_output_shapes[i].push_back(padded_out[i][d]);72+ normal_input_shapes[i].push_back(padded_in[i][d]);
73+ for (int64_t i = 0; i < num_outputs; i++)
74+ normal_output_shapes[i].push_back(padded_out[i][d]);
70 }75 }
71 }76 }
72 if (maximum_bro_shape.empty()) {77 if (maximum_bro_shape.empty()) {
73 maximum_bro_shape.push_back(1);78 maximum_bro_shape.push_back(1);
74- for (int64_t i = 0; i < num_inputs; i++) normal_input_shapes[i].push_back(1);79+ for (int64_t i = 0; i < num_inputs; i++)
75- for (int64_t i = 0; i < num_outputs; i++) normal_output_shapes[i].push_back(1);80+ normal_input_shapes[i].push_back(1);
81+ for (int64_t i = 0; i < num_outputs; i++)
82+ normal_output_shapes[i].push_back(1);
76 }83 }
77 return true;84 return true;
78}85}
79 86 
80-bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,87+bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape, int64_t dtype_size, int64_t ub_per_core,
81- int64_t dtype_size, int64_t ub_per_core, int64_t phys_nodes, SplitResult& out)88+ int64_t phys_nodes, SplitResult& out)
82{89{
83 int64_t per_buf_bytes = (ub_per_core / phys_nodes) & ~31LL;90 int64_t per_buf_bytes = (ub_per_core / phys_nodes) & ~31LL;
84 int64_t per_buf_elems = per_buf_bytes / dtype_size;91 int64_t per_buf_elems = per_buf_bytes / dtype_size;
@@ -94,8 +101,10 @@ bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,
94 return true;101 return true;
95 }102 }
96 if (k == 0) {103 if (k == 0) {
97- out.axis = 0; out.a_i = max_bro_shape[0];104+ out.axis = 0;
98- out.a_o = 1; out.a_i_tail = max_bro_shape[0];105+ out.a_i = max_bro_shape[0];
106+ out.a_o = 1;
107+ out.a_i_tail = max_bro_shape[0];
99 return true;108 return true;
100 }109 }
101 inner *= max_bro_shape[k];110 inner *= max_bro_shape[k];
@@ -103,37 +112,48 @@ bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,
103 return true;112 return true;
104}113}
105 114 
106-bool MultiCoreSplit(const std::vector<int64_t>& max_bro_shape,115+bool MultiCoreSplit(const std::vector<int64_t>& max_bro_shape, const SplitResult& ub_split, int64_t max_cores,
107- const SplitResult& ub_split, int64_t max_cores, MultiCoreResult& out)116+ MultiCoreResult& out)
108{117{
109 int64_t k = ub_split.axis, outer_prod = 1;118 int64_t k = ub_split.axis, outer_prod = 1;
110- for (int64_t j = 0; j < k; j++) outer_prod *= max_bro_shape[j];119+ for (int64_t j = 0; j < k; j++)
120+ outer_prod *= max_bro_shape[j];
111 out.total_tiles = outer_prod * ub_split.a_o;121 out.total_tiles = outer_prod * ub_split.a_o;
112- out.num_cores = (out.total_tiles < max_cores) ? out.total_tiles : max_cores;122+ out.num_cores = (out.total_tiles < max_cores) ? out.total_tiles : max_cores;
113- out.tiles_main = out.total_tiles / out.num_cores;123+ out.tiles_main = out.total_tiles / out.num_cores;
114- out.cores_tail = out.total_tiles % out.num_cores;124+ out.cores_tail = out.total_tiles % out.num_cores;
115 return true;125 return true;
116}126}
117 127 
118-bool PrecomputeInputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides) {128+bool PrecomputeInputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides)
129+{
119 int64_t rank = (int64_t)s.size();130 int64_t rank = (int64_t)s.size();
120 strides.assign(rank, 0);131 strides.assign(rank, 0);
121 for (int64_t d = rank - 1; d >= 0; d--) {132 for (int64_t d = rank - 1; d >= 0; d--) {
122- if (s[d] == 1) { strides[d] = 0; continue; }133+ if (s[d] == 1) {
134+ strides[d] = 0;
135+ continue;
136+ }
123 int64_t prod = 1;137 int64_t prod = 1;
124- for (int64_t j = d + 1; j < rank; j++) prod *= s[j];138+ for (int64_t j = d + 1; j < rank; j++)
139+ prod *= s[j];
125 strides[d] = prod;140 strides[d] = prod;
126 }141 }
127 return true;142 return true;
128}143}
129 144 
130-bool PrecomputeOutputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides) {145+bool PrecomputeOutputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides)
146+{
131 int64_t rank = (int64_t)s.size();147 int64_t rank = (int64_t)s.size();
132 strides.assign(rank, 0);148 strides.assign(rank, 0);
133 for (int64_t d = rank - 1; d >= 0; d--) {149 for (int64_t d = rank - 1; d >= 0; d--) {
134- if (s[d] == 1) { strides[d] = 0; continue; }150+ if (s[d] == 1) {
151+ strides[d] = 0;
152+ continue;
153+ }
135 int64_t prod = 1;154 int64_t prod = 1;
136- for (int64_t j = d + 1; j < rank; j++) prod *= s[j];155+ for (int64_t j = d + 1; j < rank; j++)
156+ prod *= s[j];
137 strides[d] = prod;157 strides[d] = prod;
138 }158 }
139 return true;159 return true;
@@ -150,7 +170,8 @@ static std::string Arr2String(const int64_t* arr, int64_t n)
150 std::ostringstream oss;170 std::ostringstream oss;
151 oss << "[";171 oss << "[";
152 if (n > 0) {172 if (n > 0) {
153- for (int64_t i = 0; i < n - 1; ++i) oss << arr[i] << ",";173+ for (int64_t i = 0; i < n - 1; ++i)
174+ oss << arr[i] << ",";
154 oss << arr[n - 1];175 oss << arr[n - 1];
155 }176 }
156 oss << "]";177 oss << "]";
@@ -165,42 +186,48 @@ ge::graphStatus Xlog1pyTiling::GetShapeInfo()
165 OP_CHECK_NULL_WITH_CONTEXT(ctx_, compileInfo);186 OP_CHECK_NULL_WITH_CONTEXT(ctx_, compileInfo);
166 187 
167 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetInputsNum(); ++i) {188 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetInputsNum(); ++i) {
168- auto shape = ctx_->GetInputShape(i); OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);189+ auto shape = ctx_->GetInputShape(i);
190+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);
169 std::vector<int64_t> dims;191 std::vector<int64_t> dims;
170 gert::Shape s = shape->GetStorageShape();192 gert::Shape s = shape->GetStorageShape();
171- for (size_t d = 0; d < s.GetDimNum(); ++d) dims.push_back(s.GetDim(d));193+ for (size_t d = 0; d < s.GetDimNum(); ++d)
194+ dims.push_back(s.GetDim(d));
172 raw_input_shapes_.push_back(dims);195 raw_input_shapes_.push_back(dims);
173 }196 }
174 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetOutputsNum(); ++i) {197 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetOutputsNum(); ++i) {
175- auto shape = ctx_->GetOutputShape(i); OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);198+ auto shape = ctx_->GetOutputShape(i);
199+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);
176 std::vector<int64_t> dims;200 std::vector<int64_t> dims;
177 gert::Shape s = shape->GetStorageShape();201 gert::Shape s = shape->GetStorageShape();
178- for (size_t d = 0; d < s.GetDimNum(); ++d) dims.push_back(s.GetDim(d));202+ for (size_t d = 0; d < s.GetDimNum(); ++d)
203+ dims.push_back(s.GetDim(d));
179 raw_output_shapes_.push_back(dims);204 raw_output_shapes_.push_back(dims);
180 }205 }
181 206 
182- auto inputDesc = ctx_->GetInputDesc(0); OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);207+ auto inputDesc = ctx_->GetInputDesc(0);
208+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);
183 ge::DataType dtype = inputDesc->GetDataType();209 ge::DataType dtype = inputDesc->GetDataType();
184 if (dtype == ge::DT_FLOAT) {210 if (dtype == ge::DT_FLOAT) {
185- dtype_size_ = 4; phys_nodes_ = kPhysNodesFp32;211+ dtype_size_ = 4;
212+ phys_nodes_ = kPhysNodesFp32;
186 } else if (dtype == ge::DT_FLOAT16 || dtype == ge::DT_BF16) {213 } else if (dtype == ge::DT_FLOAT16 || dtype == ge::DT_BF16) {
187- dtype_size_ = 2; phys_nodes_ = kPhysNodesFp16;214+ dtype_size_ = 2;
215+ phys_nodes_ = kPhysNodesFp16;
188 } else {216 } else {
189 OP_LOGE(ctx_->GetNodeName(), "Xlog1py unsupported dtype");217 OP_LOGE(ctx_->GetNodeName(), "Xlog1py unsupported dtype");
190 return GRAPH_FAILED;218 return GRAPH_FAILED;
191 }219 }
192 220 
193- PadAndSqueeze(raw_input_shapes_, raw_output_shapes_,221+ PadAndSqueeze(raw_input_shapes_, raw_output_shapes_, max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
194- max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
195 rank_ = (int64_t)max_bro_shape_.size();222 rank_ = (int64_t)max_bro_shape_.size();
196 223 
197- OP_LOGI(ctx_->GetNodeName(), "Xlog1py GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu",224+ OP_LOGI(ctx_->GetNodeName(), "Xlog1py GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu", rank_,
198- rank_, phys_nodes_, compileInfo->ubSize, compileInfo->coreNum);225+ phys_nodes_, compileInfo->ubSize, compileInfo->coreNum);
199 226 
200 return GRAPH_SUCCESS;227 return GRAPH_SUCCESS;
201}228}
202 229 
203-template<int64_t R>230+template <int64_t R>
204ge::graphStatus Xlog1pyTiling::DoTilingAndSet()231ge::graphStatus Xlog1pyTiling::DoTilingAndSet()
205{232{
206 auto* tiling = ctx_->GetTilingData<Xlog1pyTilingData<R>>();233 auto* tiling = ctx_->GetTilingData<Xlog1pyTilingData<R>>();
@@ -215,69 +242,74 @@ ge::graphStatus Xlog1pyTiling::DoTilingAndSet()
215 FindSplitAxis(max_bro_shape_, kBufDtypeSize, ub_per_core, phys_nodes_, tiling->split);242 FindSplitAxis(max_bro_shape_, kBufDtypeSize, ub_per_core, phys_nodes_, tiling->split);
216 MultiCoreSplit(max_bro_shape_, tiling->split, (int64_t)compileInfo->coreNum, tiling->multicore);243 MultiCoreSplit(max_bro_shape_, tiling->split, (int64_t)compileInfo->coreNum, tiling->multicore);
217 244 
218- int64_t num_in = (int64_t)normal_input_shapes_.size();245+ int64_t num_in = (int64_t)normal_input_shapes_.size();
219 int64_t num_out = (int64_t)normal_output_shapes_.size();246 int64_t num_out = (int64_t)normal_output_shapes_.size();
220 std::vector<std::vector<int64_t>> in_strides(num_in), out_strides(num_out);247 std::vector<std::vector<int64_t>> in_strides(num_in), out_strides(num_out);
221- for (int64_t i = 0; i < num_in; i++) PrecomputeInputStrides(normal_input_shapes_[i], in_strides[i]);248+ for (int64_t i = 0; i < num_in; i++)
222- for (int64_t i = 0; i < num_out; i++) PrecomputeOutputStrides(normal_output_shapes_[i], out_strides[i]);249+ PrecomputeInputStrides(normal_input_shapes_[i], in_strides[i]);
250+ for (int64_t i = 0; i < num_out; i++)
251+ PrecomputeOutputStrides(normal_output_shapes_[i], out_strides[i]);
223 252 
224 tiling->rank = rank_;253 tiling->rank = rank_;
225 int64_t delta = R - rank_;254 int64_t delta = R - rank_;
226 255 
227- for (int64_t d = 0; d < delta; d++) tiling->max_bro_shape[d] = 1;256+ for (int64_t d = 0; d < delta; d++)
228- for (int64_t d = 0; d < rank_; d++) tiling->max_bro_shape[d + delta] = max_bro_shape_[d];257+ tiling->max_bro_shape[d] = 1;
258+ for (int64_t d = 0; d < rank_; d++)
259+ tiling->max_bro_shape[d + delta] = max_bro_shape_[d];
229 260 
230 tiling->split.axis += delta;261 tiling->split.axis += delta;
231- tiling->num_inputs = num_in;262+ tiling->num_inputs = num_in;
232 tiling->num_outputs = num_out;263 tiling->num_outputs = num_out;
233 264 
234 for (int64_t i = 0; i < num_in; i++) {265 for (int64_t i = 0; i < num_in; i++) {
235 for (int64_t d = 0; d < delta; d++) {266 for (int64_t d = 0; d < delta; d++) {
236- tiling->input_shapes[i][d] = 1;267+ tiling->input_shapes[i][d] = 1;
237 tiling->input_strides[i][d] = 0;268 tiling->input_strides[i][d] = 0;
238 }269 }
239 for (int64_t d = 0; d < rank_; d++) {270 for (int64_t d = 0; d < rank_; d++) {
240- tiling->input_shapes[i][d + delta] = normal_input_shapes_[i][d];271+ tiling->input_shapes[i][d + delta] = normal_input_shapes_[i][d];
241 tiling->input_strides[i][d + delta] = in_strides[i][d];272 tiling->input_strides[i][d + delta] = in_strides[i][d];
242 }273 }
243 }274 }
244 for (int64_t i = num_in; i < kMaxInputSlots; i++)275 for (int64_t i = num_in; i < kMaxInputSlots; i++)
245 for (int64_t d = 0; d < R; d++) {276 for (int64_t d = 0; d < R; d++) {
246- tiling->input_shapes[i][d] = 1;277+ tiling->input_shapes[i][d] = 1;
247 tiling->input_strides[i][d] = 0;278 tiling->input_strides[i][d] = 0;
248 }279 }
249 280 
250 for (int64_t i = 0; i < num_out; i++) {281 for (int64_t i = 0; i < num_out; i++) {
251 for (int64_t d = 0; d < delta; d++) {282 for (int64_t d = 0; d < delta; d++) {
252- tiling->output_shapes[i][d] = 1;283+ tiling->output_shapes[i][d] = 1;
253 tiling->output_strides[i][d] = 0;284 tiling->output_strides[i][d] = 0;
254 }285 }
255 for (int64_t d = 0; d < rank_; d++) {286 for (int64_t d = 0; d < rank_; d++) {
256- tiling->output_shapes[i][d + delta] = normal_output_shapes_[i][d];287+ tiling->output_shapes[i][d + delta] = normal_output_shapes_[i][d];
257 tiling->output_strides[i][d + delta] = out_strides[i][d];288 tiling->output_strides[i][d + delta] = out_strides[i][d];
258 }289 }
259 }290 }
260 for (int64_t i = num_out; i < kMaxOutputSlots; i++)291 for (int64_t i = num_out; i < kMaxOutputSlots; i++)
261 for (int64_t d = 0; d < R; d++) {292 for (int64_t d = 0; d < R; d++) {
262- tiling->output_shapes[i][d] = 1;293+ tiling->output_shapes[i][d] = 1;
263 tiling->output_strides[i][d] = 0;294 tiling->output_strides[i][d] = 0;
264 }295 }
265 296 
266 ctx_->SetBlockDim(tiling->multicore.num_cores);297 ctx_->SetBlockDim(tiling->multicore.num_cores);
267 298 
268- OP_LOGI(ctx_->GetNodeName(), "Xlog1py TilingData: per_buf_bytes=%ld rank=%ld->R=%d "299+ OP_LOGI(ctx_->GetNodeName(),
300+ "Xlog1py TilingData: per_buf_bytes=%ld rank=%ld->R=%d "
269 "max_bro_shape=%s split(axis=%ld a_i=%ld a_o=%ld a_i_tail=%ld) "301 "max_bro_shape=%s split(axis=%ld a_i=%ld a_o=%ld a_i_tail=%ld) "
270- "multi(cores=%ld tiles=%ld main=%ld core_tail=%ld)",302+ "multi(cores=%ld tiles=%ld main=%ld core_tail=%ld) num_in=%ld num_out=%ld",
271- tiling->per_buf_bytes, rank_, (int)R,303+ tiling->per_buf_bytes, rank_, (int)R, Arr2String(tiling->max_bro_shape, R).c_str(), tiling->split.axis,
272- Arr2String(tiling->max_bro_shape, R).c_str(),304+ tiling->split.a_i, tiling->split.a_o, tiling->split.a_i_tail, tiling->multicore.num_cores,
273- tiling->split.axis, tiling->split.a_i, tiling->split.a_o, tiling->split.a_i_tail,305+ tiling->multicore.total_tiles, tiling->multicore.tiles_main, tiling->multicore.cores_tail, num_in, num_out);
274- tiling->multicore.num_cores, tiling->multicore.total_tiles,
275- tiling->multicore.tiles_main, tiling->multicore.cores_tail);
276 306 
277 for (int64_t i = 0; i < num_in; i++)307 for (int64_t i = 0; i < num_in; i++)
278- OP_LOGI(ctx_->GetNodeName(), "Xlog1py TilingData input[%ld]: shape=%s stride=%s",308+ OP_LOGI(ctx_->GetNodeName(), "Xlog1py TilingData input[%ld]: shape=%s stride=%s", i,
279- i, Arr2String(tiling->input_shapes[i], R).c_str(),309+ Arr2String(tiling->input_shapes[i], R).c_str(), Arr2String(tiling->input_strides[i], R).c_str());
280- Arr2String(tiling->input_strides[i], R).c_str());310+ for (int64_t i = 0; i < num_out; i++)
311+ OP_LOGI(ctx_->GetNodeName(), "Xlog1py TilingData output[%ld]: shape=%s stride=%s", i,
312+ Arr2String(tiling->output_shapes[i], R).c_str(), Arr2String(tiling->output_strides[i], R).c_str());
281 313 
282 return GRAPH_SUCCESS;314 return GRAPH_SUCCESS;
283}315}
@@ -285,7 +317,8 @@ ge::graphStatus Xlog1pyTiling::DoTilingAndSet()
285ge::graphStatus Xlog1pyTiling::RunTiling()317ge::graphStatus Xlog1pyTiling::RunTiling()
286{318{
287 ge::graphStatus ret = GetShapeInfo();319 ge::graphStatus ret = GetShapeInfo();
288- if (ret != GRAPH_SUCCESS) return ret;320+ if (ret != GRAPH_SUCCESS)
321+ return ret;
289 322 
290 int64_t mapped = (rank_ <= 4) ? 4 : 8;323 int64_t mapped = (rank_ <= 4) ? 4 : 8;
291 if (mapped == 4) {324 if (mapped == 4) {
@@ -300,9 +333,11 @@ ge::graphStatus Xlog1pyTiling::RunTiling()
300 333 
301static ge::graphStatus TilingFuncXlog1py(gert::TilingContext* context)334static ge::graphStatus TilingFuncXlog1py(gert::TilingContext* context)
302{335{
336+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
303 Xlog1pyTiling xlog1pyTiling(context);337 Xlog1pyTiling xlog1pyTiling(context);
304 auto ret = xlog1pyTiling.RunTiling();338 auto ret = xlog1pyTiling.RunTiling();
305- if (ret != GRAPH_SUCCESS) return ret;339+ if (ret != GRAPH_SUCCESS)
340+ return ret;
306 size_t* workspaces = context->GetWorkspaceSizes(1);341 size_t* workspaces = context->GetWorkspaceSizes(1);
307 workspaces[0] = 16 * 1024 * 1024;342 workspaces[0] = 16 * 1024 * 1024;
308 return GRAPH_SUCCESS;343 return GRAPH_SUCCESS;
@@ -8,18 +8,30 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10 10 
11- 
12// Xlog1py InferShape — output = broadcast_max(x, y)11// Xlog1py InferShape — output = broadcast_max(x, y)
13#include "infershape_broadcast_util.h"12#include "infershape_broadcast_util.h"
14#include "log/log.h"13#include "log/log.h"
15#include "register/op_impl_registry.h"14#include "register/op_impl_registry.h"
15+#include "util/shape_util.h"
16 16 
17using namespace ge;17using namespace ge;
18namespace ops {18namespace ops {
19static ge::graphStatus InferShapeForXlog1py(gert::InferShapeContext* context)19static ge::graphStatus InferShapeForXlog1py(gert::InferShapeContext* context)
20{20{
21- return Ops::Base::InferShape4Broadcast(context);21+ const ge::graphStatus status = Ops::Base::InferShape4Broadcast(context);
22+ if (status == ge::GRAPH_SUCCESS) {
23+ const gert::Shape* outputShape = context->GetOutputShape(0);
24+ OP_CHECK_NULL_WITH_CONTEXT(context, outputShape);
25+ OP_LOGI(context->GetNodeName(), "Xlog1py output shape: %s.", Ops::Base::ToString(*outputShape).c_str());
26+ }
27+ return status;
22}28}
23 29 
24-IMPL_OP_INFERSHAPE(Xlog1py).InferShape(InferShapeForXlog1py);30+static ge::graphStatus InferDataTypeForXlog1py(gert::InferDataTypeContext* context)
31+{
32+ context->SetOutputDataType(0, context->GetInputDataType(0));
33+ return ge::GRAPH_SUCCESS;
34+}
35+ 
36+IMPL_OP_INFERSHAPE(Xlog1py).InferShape(InferShapeForXlog1py).InferDataType(InferDataTypeForXlog1py);
25} // namespace ops37} // namespace ops
@@ -31,20 +31,18 @@ using namespace ge;
31namespace xlogy {31namespace xlogy {
32 32 
33// === 算子特定常量 — 新算子必须修改 ===33// === 算子特定常量 — 新算子必须修改 ===
34-constexpr int64_t kPhysNodesFp32 = 3; // 物理存活节点 P (FP32 路径, 无 Cast)34+constexpr int64_t kPhysNodesFp32 = 3; // 物理存活节点 P (FP32 路径, 无 Cast)
35-constexpr int64_t kPhysNodesFp16 = 4; // 物理存活节点 P (FP16/BF16 路径, 有 Cast)35+constexpr int64_t kPhysNodesFp16 = 4; // 物理存活节点 P (FP16/BF16 路径, 有 Cast)
36-constexpr int64_t kBufDtypeSize = 4; // per_buf_elems 永远除 sizeof(float32) (cast.md §Tile)36+constexpr int64_t kBufDtypeSize = 4; // per_buf_elems 永远除 sizeof(float32) (cast.md §Tile)
37 37 
38// 5.1 PadAndSqueeze38// 5.1 PadAndSqueeze
39 39 
40-bool PadAndSqueeze(40+bool PadAndSqueeze(const std::vector<std::vector<int64_t>>& input_shapes,
41- const std::vector<std::vector<int64_t>>& input_shapes,41+ const std::vector<std::vector<int64_t>>& output_shapes, std::vector<int64_t>& maximum_bro_shape,
42- const std::vector<std::vector<int64_t>>& output_shapes,42+ std::vector<std::vector<int64_t>>& normal_input_shapes,
43- std::vector<int64_t>& maximum_bro_shape,43+ std::vector<std::vector<int64_t>>& normal_output_shapes)
44- std::vector<std::vector<int64_t>>& normal_input_shapes,
45- std::vector<std::vector<int64_t>>& normal_output_shapes)
46{44{
47- int64_t num_inputs = (int64_t)input_shapes.size();45+ int64_t num_inputs = (int64_t)input_shapes.size();
48 int64_t num_outputs = (int64_t)output_shapes.size();46 int64_t num_outputs = (int64_t)output_shapes.size();
49 int64_t max_rank = 0;47 int64_t max_rank = 0;
50 for (auto& s : input_shapes)48 for (auto& s : input_shapes)
@@ -58,8 +56,10 @@ bool PadAndSqueeze(
58 return p;56 return p;
59 };57 };
60 std::vector<std::vector<int64_t>> padded_in(num_inputs), padded_out(num_outputs);58 std::vector<std::vector<int64_t>> padded_in(num_inputs), padded_out(num_outputs);
61- for (int64_t i = 0; i < num_inputs; i++) padded_in[i] = pad(input_shapes[i]);59+ for (int64_t i = 0; i < num_inputs; i++)
62- for (int64_t i = 0; i < num_outputs; i++) padded_out[i] = pad(output_shapes[i]);60+ padded_in[i] = pad(input_shapes[i]);
61+ for (int64_t i = 0; i < num_outputs; i++)
62+ padded_out[i] = pad(output_shapes[i]);
63 maximum_bro_shape.clear();63 maximum_bro_shape.clear();
64 normal_input_shapes.assign(num_inputs, std::vector<int64_t>());64 normal_input_shapes.assign(num_inputs, std::vector<int64_t>());
65 normal_output_shapes.assign(num_outputs, std::vector<int64_t>());65 normal_output_shapes.assign(num_outputs, std::vector<int64_t>());
@@ -67,31 +67,37 @@ bool PadAndSqueeze(
67 bool all_one = true;67 bool all_one = true;
68 int64_t max_dim = 0;68 int64_t max_dim = 0;
69 for (int64_t i = 0; i < num_inputs; i++) {69 for (int64_t i = 0; i < num_inputs; i++) {
70- if (padded_in[i][d] != 1) all_one = false;70+ if (padded_in[i][d] != 1)
71+ all_one = false;
71 max_dim = std::max(max_dim, padded_in[i][d]);72 max_dim = std::max(max_dim, padded_in[i][d]);
72 }73 }
73 for (int64_t i = 0; i < num_outputs; i++) {74 for (int64_t i = 0; i < num_outputs; i++) {
74- if (padded_out[i][d] != 1) all_one = false;75+ if (padded_out[i][d] != 1)
76+ all_one = false;
75 max_dim = std::max(max_dim, padded_out[i][d]);77 max_dim = std::max(max_dim, padded_out[i][d]);
76 }78 }
77 if (!all_one) {79 if (!all_one) {
78 maximum_bro_shape.push_back(max_dim);80 maximum_bro_shape.push_back(max_dim);
79- for (int64_t i = 0; i < num_inputs; i++) normal_input_shapes[i].push_back(padded_in[i][d]);81+ for (int64_t i = 0; i < num_inputs; i++)
80- for (int64_t i = 0; i < num_outputs; i++) normal_output_shapes[i].push_back(padded_out[i][d]);82+ normal_input_shapes[i].push_back(padded_in[i][d]);
83+ for (int64_t i = 0; i < num_outputs; i++)
84+ normal_output_shapes[i].push_back(padded_out[i][d]);
81 }85 }
82 }86 }
83 if (maximum_bro_shape.empty()) {87 if (maximum_bro_shape.empty()) {
84 maximum_bro_shape.push_back(1);88 maximum_bro_shape.push_back(1);
85- for (int64_t i = 0; i < num_inputs; i++) normal_input_shapes[i].push_back(1);89+ for (int64_t i = 0; i < num_inputs; i++)
86- for (int64_t i = 0; i < num_outputs; i++) normal_output_shapes[i].push_back(1);90+ normal_input_shapes[i].push_back(1);
91+ for (int64_t i = 0; i < num_outputs; i++)
92+ normal_output_shapes[i].push_back(1);
87 }93 }
88 return true;94 return true;
89}95}
90 96 
91// 5.2 FindSplitAxis — 从最内轴向外扫描,d_k × inner > per_buf_elems 时切分97// 5.2 FindSplitAxis — 从最内轴向外扫描,d_k × inner > per_buf_elems 时切分
92 98 
93-bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,99+bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape, int64_t dtype_size, int64_t ub_per_core,
94- int64_t dtype_size, int64_t ub_per_core, int64_t phys_nodes, SplitResult& out)100+ int64_t phys_nodes, SplitResult& out)
95{101{
96 int64_t per_buf_bytes = (ub_per_core / phys_nodes) & ~31LL;102 int64_t per_buf_bytes = (ub_per_core / phys_nodes) & ~31LL;
97 int64_t per_buf_elems = per_buf_bytes / dtype_size;103 int64_t per_buf_elems = per_buf_bytes / dtype_size;
@@ -120,39 +126,50 @@ bool FindSplitAxis(const std::vector<int64_t>& max_bro_shape,
120 126 
121// 5.3 MultiCoreSplit127// 5.3 MultiCoreSplit
122 128 
123-bool MultiCoreSplit(const std::vector<int64_t>& max_bro_shape,129+bool MultiCoreSplit(const std::vector<int64_t>& max_bro_shape, const SplitResult& ub_split, int64_t max_cores,
124- const SplitResult& ub_split, int64_t max_cores, MultiCoreResult& out)130+ MultiCoreResult& out)
125{131{
126 int64_t k = ub_split.axis, outer_prod = 1;132 int64_t k = ub_split.axis, outer_prod = 1;
127- for (int64_t j = 0; j < k; j++) outer_prod *= max_bro_shape[j];133+ for (int64_t j = 0; j < k; j++)
134+ outer_prod *= max_bro_shape[j];
128 out.total_tiles = outer_prod * ub_split.a_o;135 out.total_tiles = outer_prod * ub_split.a_o;
129- out.num_cores = (out.total_tiles < max_cores) ? out.total_tiles : max_cores;136+ out.num_cores = (out.total_tiles < max_cores) ? out.total_tiles : max_cores;
130- out.tiles_main = out.total_tiles / out.num_cores;137+ out.tiles_main = out.total_tiles / out.num_cores;
131- out.cores_tail = out.total_tiles % out.num_cores;138+ out.cores_tail = out.total_tiles % out.num_cores;
132 return true;139 return true;
133}140}
134 141 
135// 5.5 地址偏移142// 5.5 地址偏移
136 143 
137-bool PrecomputeInputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides) {144+bool PrecomputeInputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides)
145+{
138 int64_t rank = (int64_t)s.size();146 int64_t rank = (int64_t)s.size();
139 strides.assign(rank, 0);147 strides.assign(rank, 0);
140 for (int64_t d = rank - 1; d >= 0; d--) {148 for (int64_t d = rank - 1; d >= 0; d--) {
141- if (s[d] == 1) { strides[d] = 0; continue; }149+ if (s[d] == 1) {
150+ strides[d] = 0;
151+ continue;
152+ }
142 int64_t prod = 1;153 int64_t prod = 1;
143- for (int64_t j = d + 1; j < rank; j++) prod *= s[j];154+ for (int64_t j = d + 1; j < rank; j++)
155+ prod *= s[j];
144 strides[d] = prod;156 strides[d] = prod;
145 }157 }
146 return true;158 return true;
147}159}
148 160 
149-bool PrecomputeOutputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides) {161+bool PrecomputeOutputStrides(const std::vector<int64_t>& s, std::vector<int64_t>& strides)
162+{
150 int64_t rank = (int64_t)s.size();163 int64_t rank = (int64_t)s.size();
151 strides.assign(rank, 0);164 strides.assign(rank, 0);
152 for (int64_t d = rank - 1; d >= 0; d--) {165 for (int64_t d = rank - 1; d >= 0; d--) {
153- if (s[d] == 1) { strides[d] = 0; continue; }166+ if (s[d] == 1) {
167+ strides[d] = 0;
168+ continue;
169+ }
154 int64_t prod = 1;170 int64_t prod = 1;
155- for (int64_t j = d + 1; j < rank; j++) prod *= s[j];171+ for (int64_t j = d + 1; j < rank; j++)
172+ prod *= s[j];
156 strides[d] = prod;173 strides[d] = prod;
157 }174 }
158 return true;175 return true;
@@ -173,7 +190,8 @@ static std::string Arr2String(const int64_t* arr, int64_t n)
173 std::ostringstream oss;190 std::ostringstream oss;
174 oss << "[";191 oss << "[";
175 if (n > 0) {192 if (n > 0) {
176- for (int64_t i = 0; i < n - 1; ++i) oss << arr[i] << ",";193+ for (int64_t i = 0; i < n - 1; ++i)
194+ oss << arr[i] << ",";
177 oss << arr[n - 1];195 oss << arr[n - 1];
178 }196 }
179 oss << "]";197 oss << "]";
@@ -189,23 +207,28 @@ ge::graphStatus XlogyTiling::GetShapeInfo()
189 207 
190 // 读输入 shape208 // 读输入 shape
191 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetInputsNum(); ++i) {209 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetInputsNum(); ++i) {
192- auto shape = ctx_->GetInputShape(i); OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);210+ auto shape = ctx_->GetInputShape(i);
211+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);
193 std::vector<int64_t> dims;212 std::vector<int64_t> dims;
194 gert::Shape s = shape->GetStorageShape();213 gert::Shape s = shape->GetStorageShape();
195- for (size_t d = 0; d < s.GetDimNum(); ++d) dims.push_back(s.GetDim(d));214+ for (size_t d = 0; d < s.GetDimNum(); ++d)
215+ dims.push_back(s.GetDim(d));
196 raw_input_shapes_.push_back(dims);216 raw_input_shapes_.push_back(dims);
197 }217 }
198 218 
199 // 读输出 shape219 // 读输出 shape
200 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetOutputsNum(); ++i) {220 for (size_t i = 0; i < ctx_->GetComputeNodeInfo()->GetOutputsNum(); ++i) {
201- auto shape = ctx_->GetOutputShape(i); OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);221+ auto shape = ctx_->GetOutputShape(i);
222+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, shape);
202 std::vector<int64_t> dims;223 std::vector<int64_t> dims;
203 gert::Shape s = shape->GetStorageShape();224 gert::Shape s = shape->GetStorageShape();
204- for (size_t d = 0; d < s.GetDimNum(); ++d) dims.push_back(s.GetDim(d));225+ for (size_t d = 0; d < s.GetDimNum(); ++d)
226+ dims.push_back(s.GetDim(d));
205 raw_output_shapes_.push_back(dims);227 raw_output_shapes_.push_back(dims);
206 }228 }
207 229 
208- auto inputDesc = ctx_->GetInputDesc(0); OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);230+ auto inputDesc = ctx_->GetInputDesc(0);
231+ OP_CHECK_NULL_WITH_CONTEXT(ctx_, inputDesc);
209 ge::DataType dtype = inputDesc->GetDataType();232 ge::DataType dtype = inputDesc->GetDataType();
210 if (dtype == ge::DT_FLOAT) {233 if (dtype == ge::DT_FLOAT) {
211 dtype_size_ = 4;234 dtype_size_ = 4;
@@ -218,17 +241,16 @@ ge::graphStatus XlogyTiling::GetShapeInfo()
218 return GRAPH_FAILED;241 return GRAPH_FAILED;
219 }242 }
220 243 
221- PadAndSqueeze(raw_input_shapes_, raw_output_shapes_,244+ PadAndSqueeze(raw_input_shapes_, raw_output_shapes_, max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
222- max_bro_shape_, normal_input_shapes_, normal_output_shapes_);
223 rank_ = (int64_t)max_bro_shape_.size();245 rank_ = (int64_t)max_bro_shape_.size();
224 246 
225- OP_LOGI(ctx_->GetNodeName(), "Xlogy GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu",247+ OP_LOGI(ctx_->GetNodeName(), "Xlogy GetShapeInfo done rank %ld phys_nodes %ld ub %lu core %lu", rank_, phys_nodes_,
226- rank_, phys_nodes_, compileInfo->ubSize, compileInfo->coreNum);248+ compileInfo->ubSize, compileInfo->coreNum);
227 249 
228 return GRAPH_SUCCESS;250 return GRAPH_SUCCESS;
229}251}
230 252 
231-template<int64_t R>253+template <int64_t R>
232ge::graphStatus XlogyTiling::DoTilingAndSet()254ge::graphStatus XlogyTiling::DoTilingAndSet()
233{255{
234 auto* tiling = ctx_->GetTilingData<XlogyTilingData<R>>();256 auto* tiling = ctx_->GetTilingData<XlogyTilingData<R>>();
@@ -244,81 +266,81 @@ ge::graphStatus XlogyTiling::DoTilingAndSet()
244 FindSplitAxis(max_bro_shape_, kBufDtypeSize, ub_per_core, phys_nodes_, tiling->split);266 FindSplitAxis(max_bro_shape_, kBufDtypeSize, ub_per_core, phys_nodes_, tiling->split);
245 MultiCoreSplit(max_bro_shape_, tiling->split, (int64_t)compileInfo->coreNum, tiling->multicore);267 MultiCoreSplit(max_bro_shape_, tiling->split, (int64_t)compileInfo->coreNum, tiling->multicore);
246 268 
247- int64_t num_in = (int64_t)normal_input_shapes_.size();269+ int64_t num_in = (int64_t)normal_input_shapes_.size();
248 int64_t num_out = (int64_t)normal_output_shapes_.size();270 int64_t num_out = (int64_t)normal_output_shapes_.size();
249 std::vector<std::vector<int64_t>> in_strides(num_in), out_strides(num_out);271 std::vector<std::vector<int64_t>> in_strides(num_in), out_strides(num_out);
250- for (int64_t i = 0; i < num_in; i++) PrecomputeInputStrides(normal_input_shapes_[i], in_strides[i]);272+ for (int64_t i = 0; i < num_in; i++)
251- for (int64_t i = 0; i < num_out; i++) PrecomputeOutputStrides(normal_output_shapes_[i], out_strides[i]);273+ PrecomputeInputStrides(normal_input_shapes_[i], in_strides[i]);
274+ for (int64_t i = 0; i < num_out; i++)
275+ PrecomputeOutputStrides(normal_output_shapes_[i], out_strides[i]);
252 276 
253 tiling->rank = rank_;277 tiling->rank = rank_;
254 int64_t delta = R - rank_;278 int64_t delta = R - rank_;
255 279 
256 // max_bro_shape: 前补 1280 // max_bro_shape: 前补 1
257- for (int64_t d = 0; d < delta; d++) tiling->max_bro_shape[d] = 1;281+ for (int64_t d = 0; d < delta; d++)
258- for (int64_t d = 0; d < rank_; d++) tiling->max_bro_shape[d + delta] = max_bro_shape_[d];282+ tiling->max_bro_shape[d] = 1;
283+ for (int64_t d = 0; d < rank_; d++)
284+ tiling->max_bro_shape[d + delta] = max_bro_shape_[d];
259 285 
260 tiling->split.axis += delta;286 tiling->split.axis += delta;
261 287 
262- tiling->num_inputs = num_in;288+ tiling->num_inputs = num_in;
263 tiling->num_outputs = num_out;289 tiling->num_outputs = num_out;
264 290 
265 // input: 前补 shape=1 stride=0291 // input: 前补 shape=1 stride=0
266 for (int64_t i = 0; i < num_in; i++) {292 for (int64_t i = 0; i < num_in; i++) {
267 for (int64_t d = 0; d < delta; d++) {293 for (int64_t d = 0; d < delta; d++) {
268- tiling->input_shapes[i][d] = 1;294+ tiling->input_shapes[i][d] = 1;
269 tiling->input_strides[i][d] = 0;295 tiling->input_strides[i][d] = 0;
270 }296 }
271 for (int64_t d = 0; d < rank_; d++) {297 for (int64_t d = 0; d < rank_; d++) {
272- tiling->input_shapes[i][d + delta] = normal_input_shapes_[i][d];298+ tiling->input_shapes[i][d + delta] = normal_input_shapes_[i][d];
273 tiling->input_strides[i][d + delta] = in_strides[i][d];299 tiling->input_strides[i][d + delta] = in_strides[i][d];
274 }300 }
275 }301 }
276 // 未使用 input slot: 全填 1/0302 // 未使用 input slot: 全填 1/0
277 for (int64_t i = num_in; i < kMaxInputSlots; i++)303 for (int64_t i = num_in; i < kMaxInputSlots; i++)
278 for (int64_t d = 0; d < R; d++) {304 for (int64_t d = 0; d < R; d++) {
279- tiling->input_shapes[i][d] = 1;305+ tiling->input_shapes[i][d] = 1;
280 tiling->input_strides[i][d] = 0;306 tiling->input_strides[i][d] = 0;
281 }307 }
282 308 
283 // output: 前补 shape=1 stride=0309 // output: 前补 shape=1 stride=0
284 for (int64_t i = 0; i < num_out; i++) {310 for (int64_t i = 0; i < num_out; i++) {
285 for (int64_t d = 0; d < delta; d++) {311 for (int64_t d = 0; d < delta; d++) {
286- tiling->output_shapes[i][d] = 1;312+ tiling->output_shapes[i][d] = 1;
287 tiling->output_strides[i][d] = 0;313 tiling->output_strides[i][d] = 0;
288 }314 }
289 for (int64_t d = 0; d < rank_; d++) {315 for (int64_t d = 0; d < rank_; d++) {
290- tiling->output_shapes[i][d + delta] = normal_output_shapes_[i][d];316+ tiling->output_shapes[i][d + delta] = normal_output_shapes_[i][d];
291 tiling->output_strides[i][d + delta] = out_strides[i][d];317 tiling->output_strides[i][d + delta] = out_strides[i][d];
292 }318 }
293 }319 }
294 for (int64_t i = num_out; i < kMaxOutputSlots; i++)320 for (int64_t i = num_out; i < kMaxOutputSlots; i++)
295 for (int64_t d = 0; d < R; d++) {321 for (int64_t d = 0; d < R; d++) {
296- tiling->output_shapes[i][d] = 1;322+ tiling->output_shapes[i][d] = 1;
297 tiling->output_strides[i][d] = 0;323 tiling->output_strides[i][d] = 0;
298 }324 }
299 325 
300 ctx_->SetBlockDim(tiling->multicore.num_cores);326 ctx_->SetBlockDim(tiling->multicore.num_cores);
301 327 
302 // 维测: TilingData 全部字段328 // 维测: TilingData 全部字段
303- OP_LOGI(ctx_->GetNodeName(), "Xlogy TilingData: per_buf_bytes=%ld rank=%ld->R=%d "329+ OP_LOGI(ctx_->GetNodeName(),
330+ "Xlogy TilingData: per_buf_bytes=%ld rank=%ld->R=%d "
304 "max_bro_shape=%s "331 "max_bro_shape=%s "
305 "split(axis=%ld a_i=%ld a_o=%ld a_i_tail=%ld) "332 "split(axis=%ld a_i=%ld a_o=%ld a_i_tail=%ld) "
306 "multi(cores=%ld tiles=%ld main=%ld core_tail=%ld) num_in=%ld num_out=%ld",333 "multi(cores=%ld tiles=%ld main=%ld core_tail=%ld) num_in=%ld num_out=%ld",
307- tiling->per_buf_bytes, rank_, (int)R,334+ tiling->per_buf_bytes, rank_, (int)R, Arr2String(tiling->max_bro_shape, R).c_str(), tiling->split.axis,
308- Arr2String(tiling->max_bro_shape, R).c_str(),335+ tiling->split.a_i, tiling->split.a_o, tiling->split.a_i_tail, tiling->multicore.num_cores,
309- tiling->split.axis, tiling->split.a_i, tiling->split.a_o, tiling->split.a_i_tail,336+ tiling->multicore.total_tiles, tiling->multicore.tiles_main, tiling->multicore.cores_tail, num_in, num_out);
310- tiling->multicore.num_cores, tiling->multicore.total_tiles,
311- tiling->multicore.tiles_main, tiling->multicore.cores_tail,
312- num_in, num_out);
313 337 
314 for (int64_t i = 0; i < num_in; i++)338 for (int64_t i = 0; i < num_in; i++)
315- OP_LOGI(ctx_->GetNodeName(), "Xlogy TilingData input[%ld]: shape=%s stride=%s",339+ OP_LOGI(ctx_->GetNodeName(), "Xlogy TilingData input[%ld]: shape=%s stride=%s", i,
316- i, Arr2String(tiling->input_shapes[i], R).c_str(),340+ Arr2String(tiling->input_shapes[i], R).c_str(), Arr2String(tiling->input_strides[i], R).c_str());
317- Arr2String(tiling->input_strides[i], R).c_str());
318 for (int64_t i = 0; i < num_out; i++)341 for (int64_t i = 0; i < num_out; i++)
319- OP_LOGI(ctx_->GetNodeName(), "Xlogy TilingData output[%ld]: shape=%s stride=%s",342+ OP_LOGI(ctx_->GetNodeName(), "Xlogy TilingData output[%ld]: shape=%s stride=%s", i,
320- i, Arr2String(tiling->output_shapes[i], R).c_str(),343+ Arr2String(tiling->output_shapes[i], R).c_str(), Arr2String(tiling->output_strides[i], R).c_str());
321- Arr2String(tiling->output_strides[i], R).c_str());
322 344 
323 return GRAPH_SUCCESS;345 return GRAPH_SUCCESS;
324}346}
@@ -326,7 +348,8 @@ ge::graphStatus XlogyTiling::DoTilingAndSet()
326ge::graphStatus XlogyTiling::RunTiling()348ge::graphStatus XlogyTiling::RunTiling()
327{349{
328 ge::graphStatus ret = GetShapeInfo();350 ge::graphStatus ret = GetShapeInfo();
329- if (ret != GRAPH_SUCCESS) return ret;351+ if (ret != GRAPH_SUCCESS)
352+ return ret;
330 353 
331 int64_t mapped = (rank_ <= 4) ? 4 : 8;354 int64_t mapped = (rank_ <= 4) ? 4 : 8;
332 if (mapped == 4) {355 if (mapped == 4) {
@@ -341,11 +364,13 @@ ge::graphStatus XlogyTiling::RunTiling()
341 364 
342static ge::graphStatus TilingFuncXlogy(gert::TilingContext* context)365static ge::graphStatus TilingFuncXlogy(gert::TilingContext* context)
343{366{
367+ OP_LOGD(context->GetNodeName(), "Begin the tiling process for Arch35 architecture");
344 XlogyTiling xlogyTiling(context);368 XlogyTiling xlogyTiling(context);
345 auto ret = xlogyTiling.RunTiling();369 auto ret = xlogyTiling.RunTiling();
346- if (ret != GRAPH_SUCCESS) return ret;370+ if (ret != GRAPH_SUCCESS)
371+ return ret;
347 size_t* workspaces = context->GetWorkspaceSizes(1);372 size_t* workspaces = context->GetWorkspaceSizes(1);
348- workspaces[0] = 16 * 1024 * 1024; // 16MB373+ workspaces[0] = 16 * 1024 * 1024; // 16MB
349 return GRAPH_SUCCESS;374 return GRAPH_SUCCESS;
350}375}
351 376 
@@ -15,13 +15,26 @@
15#include "infershape_broadcast_util.h"15#include "infershape_broadcast_util.h"
16#include "log/log.h"16#include "log/log.h"
17#include "register/op_impl_registry.h"17#include "register/op_impl_registry.h"
18+#include "util/shape_util.h"
18 19 
19using namespace ge;20using namespace ge;
20namespace ops {21namespace ops {
21static ge::graphStatus InferShapeForXlogy(gert::InferShapeContext* context)22static ge::graphStatus InferShapeForXlogy(gert::InferShapeContext* context)
22{23{
23- return Ops::Base::InferShape4Broadcast(context);24+ const ge::graphStatus status = Ops::Base::InferShape4Broadcast(context);
25+ if (status == ge::GRAPH_SUCCESS) {
26+ const gert::Shape* outputShape = context->GetOutputShape(0);
27+ OP_CHECK_NULL_WITH_CONTEXT(context, outputShape);
28+ OP_LOGI(context->GetNodeName(), "Xlogy output shape: %s.", Ops::Base::ToString(*outputShape).c_str());
29+ }
30+ return status;
24}31}
25 32 
26-IMPL_OP_INFERSHAPE(Xlogy).InferShape(InferShapeForXlogy);33+static ge::graphStatus InferDataTypeForXlogy(gert::InferDataTypeContext* context)
34+{
35+ context->SetOutputDataType(0, context->GetInputDataType(0));
36+ return ge::GRAPH_SUCCESS;
37+}
38+ 
39+IMPL_OP_INFERSHAPE(Xlogy).InferShape(InferShapeForXlogy).InferDataType(InferDataTypeForXlogy);
27} // namespace ops40} // namespace ops