已合并
DualLevelQuantBatchMatmul提高代码规范性 #1309
sunduiyang创建于 1月31日
DualLevelQuantBatchMatmul提高代码规范性 #1309
已合并
sunduiyang创建于 1月31日
10 个文件变更+209-263
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_adaptive_sliding_window_tiling.cpp+81-104
@@ -22,28 +22,6 @@
22using namespace platform_ascendc;22using namespace platform_ascendc;
23using namespace optiling::tool;23using namespace optiling::tool;
24 24 
25-namespace {
26-template <typename T>
27-T GetShapeWithDataType(T size, ge::DataType dtype)
28-{
29- if (dtype == ge::DT_INT4 || dtype == ge::DT_FLOAT4_E2M1 || dtype == ge::DT_FLOAT4_E1M2) {
30- return size + size;
31- } else {
32- return size / static_cast<T>(ge::GetSizeByDataType(dtype));
33- }
34-}
35- 
36-template <typename T>
37-T GetSizeWithDataType(T shape, ge::DataType dtype)
38-{
39- if (dtype == ge::DT_FLOAT4_E2M1 || dtype == ge::DT_FLOAT4_E1M2 || dtype == ge::DT_INT4) {
40- return (shape + 1) >> 1;
41- } else {
42- return shape * static_cast<T>(ge::GetSizeByDataType(dtype));
43- }
44-}
45-} // namespace
46- 
47namespace optiling {25namespace optiling {
48namespace dual_level_quant_batch_matmul {26namespace dual_level_quant_batch_matmul {
49constexpr uint64_t CUBE_BLOCK = 16;27constexpr uint64_t CUBE_BLOCK = 16;
@@ -88,24 +66,24 @@ ge::graphStatus DualLevelQuantBatchMatmulTilingASW::GetShapeAttrsInfo()
88 66 
89ge::graphStatus DualLevelQuantBatchMatmulTilingASW::GetPlatformInfo()67ge::graphStatus DualLevelQuantBatchMatmulTilingASW::GetPlatformInfo()
90{68{
91- OP_LOGE_IF(!SetPlatformInfoForTiling(), ge::GRAPH_FAILED, opName_, "GetPlatformInfo fail");69+ OP_LOGE_IF(!SetPlatformInfoForTiling(), ge::GRAPH_FAILED, context_, "GetPlatformInfo fail");
92 return ge::GRAPH_SUCCESS;70 return ge::GRAPH_SUCCESS;
93}71}
94 72 
95ge::graphStatus DualLevelQuantBatchMatmulTilingASW::DoOpTiling()73ge::graphStatus DualLevelQuantBatchMatmulTilingASW::DoOpTiling()
96{74{
97- OP_LOGD(opName_, "DoOpTiling of adaptive sliding window tiling strategy.");75+ OP_LOGD(matmulInfo_.opName, "DoOpTiling of adaptive sliding window tiling strategy.");
98 OP_TILING_CHECK(76 OP_TILING_CHECK(
99 InstantiateTilingData() == ge::GRAPH_FAILED,77 InstantiateTilingData() == ge::GRAPH_FAILED,
100- CUBE_INNER_ERR_REPORT(opName_, "unable to get pointer of tiling data"), return ge::GRAPH_FAILED);78+ CUBE_INNER_ERR_REPORT(matmulInfo_.opName, "unable to get pointer of tiling data"), return ge::GRAPH_FAILED);
101 79 
102 if (!AnalyseSlidingWinInfo()) {80 if (!AnalyseSlidingWinInfo()) {
103- OP_LOGE(opName_, "DoOpTiling fail");81+ OP_LOGE(matmulInfo_.opName, "DoOpTiling fail");
104 return ge::GRAPH_FAILED;82 return ge::GRAPH_FAILED;
105 }83 }
106 LoadBalanceDataReset();84 LoadBalanceDataReset();
107 if (!OptimizeEdgeBasicBlock()) {85 if (!OptimizeEdgeBasicBlock()) {
108- OP_LOGE(opName_, "OptimizeEdgeBasicBlock fail");86+ OP_LOGE(matmulInfo_.opName, "OptimizeEdgeBasicBlock fail");
109 return ge::GRAPH_FAILED;87 return ge::GRAPH_FAILED;
110 }88 }
111 SetTilingData();89 SetTilingData();
@@ -124,10 +102,10 @@ uint64_t DualLevelQuantBatchMatmulTilingASW::GetTilingKey() const
124 uint64_t templateCustom = DLQBMM_TEMPLATE_CUBEBOUND;102 uint64_t templateCustom = DLQBMM_TEMPLATE_CUBEBOUND;
125 uint64_t level1QuantType = DLQBMM_QUANT_TYPE_MX;103 uint64_t level1QuantType = DLQBMM_QUANT_TYPE_MX;
126 uint64_t level0QuantType = DLQBMM_QUANT_TYPE_PER_GROUP;104 uint64_t level0QuantType = DLQBMM_QUANT_TYPE_PER_GROUP;
127- bool transA = matmulInfoPtr_->transA;105+ bool transA = matmulInfo_.transA;
128- bool transB = matmulInfoPtr_->transB;106+ bool transB = matmulInfo_.transB;
129- bool hasBias = matmulInfoPtr_->hasBias;107+ bool hasBias = matmulInfo_.hasBias;
130- bool isWeightNz = matmulInfoPtr_->x2Format == ge::FORMAT_FRACTAL_NZ;108+ bool isWeightNz = matmulInfo_.x2Format == ge::FORMAT_FRACTAL_NZ;
131 uint64_t tilingKey = GET_TPL_TILING_KEY(109 uint64_t tilingKey = GET_TPL_TILING_KEY(
132 socVersionType, subSocVersionType, templateCustom, level1QuantType, level0QuantType, transA, transB, hasBias,110 socVersionType, subSocVersionType, templateCustom, level1QuantType, level0QuantType, transA, transB, hasBias,
133 isWeightNz);111 isWeightNz);
@@ -136,16 +114,15 @@ uint64_t DualLevelQuantBatchMatmulTilingASW::GetTilingKey() const
136 114 
137ge::graphStatus DualLevelQuantBatchMatmulTilingASW::GetWorkspaceSize()115ge::graphStatus DualLevelQuantBatchMatmulTilingASW::GetWorkspaceSize()
138{116{
139- workspaceSize_ = matmulInfoPtr_->libApiWorkSpaceSize;
140 return ge::GRAPH_SUCCESS;117 return ge::GRAPH_SUCCESS;
141}118}
142 119 
143ge::graphStatus DualLevelQuantBatchMatmulTilingASW::PostTiling()120ge::graphStatus DualLevelQuantBatchMatmulTilingASW::PostTiling()
144{121{
145- OP_LOGD(opName_, "final tiling data size: %zu", tilingDataSize_);122+ OP_LOGD(context_, "final tiling data size: %zu", tilingDataSize_);
146 OP_TILING_CHECK(123 OP_TILING_CHECK(
147 tilingDataSize_ % sizeof(uint64_t) != 0,124 tilingDataSize_ % sizeof(uint64_t) != 0,
148- CUBE_INNER_ERR_REPORT(opName_, "tiling data size[%zu] is not aligned to 8", tilingDataSize_),125+ CUBE_INNER_ERR_REPORT(context_, "tiling data size[%zu] is not aligned to 8", tilingDataSize_),
149 return ge::GRAPH_FAILED);126 return ge::GRAPH_FAILED);
150 errno_t ret = memcpy_s(127 errno_t ret = memcpy_s(
151 context_->GetRawTilingData()->GetData(), context_->GetRawTilingData()->GetCapacity(),128 context_->GetRawTilingData()->GetData(), context_->GetRawTilingData()->GetCapacity(),
@@ -156,7 +133,7 @@ ge::graphStatus DualLevelQuantBatchMatmulTilingASW::PostTiling()
156 }133 }
157 context_->SetBlockDim(usedCoreNum);134 context_->SetBlockDim(usedCoreNum);
158 context_->GetRawTilingData()->SetDataSize(tilingDataSize_);135 context_->GetRawTilingData()->SetDataSize(tilingDataSize_);
159- size_t* workspaces = context_->GetWorkspaceSizes(1); // set workspace136+ size_t* workspaces = context_->GetWorkspaceSizes(1);
160 OPS_CHECK_NULL_WITH_CONTEXT(context_, workspaces);137 OPS_CHECK_NULL_WITH_CONTEXT(context_, workspaces);
161 workspaces[0] = workspaceSize_;138 workspaces[0] = workspaceSize_;
162 return ge::GRAPH_SUCCESS;139 return ge::GRAPH_SUCCESS;
@@ -177,14 +154,14 @@ ge::graphStatus DualLevelQuantBatchMatmulTilingASW::InstantiateTilingData()
177 // make_unique不会返回空指针,只会返回异常,无需在后面加空指针校验154 // make_unique不会返回空指针,只会返回异常,无需在后面加空指针校验
178 tilingData_ = std::make_unique<DualLevelQuantBatchMatmulBasicTilingData>();155 tilingData_ = std::make_unique<DualLevelQuantBatchMatmulBasicTilingData>();
179 } catch (std::bad_alloc&) {156 } catch (std::bad_alloc&) {
180- OP_LOGE(opName_, "tiling data memory allocation failed");157+ OP_LOGE(matmulInfo_.opName, "tiling data memory allocation failed");
181 return ge::GRAPH_FAILED;158 return ge::GRAPH_FAILED;
182 }159 }
183 }160 }
184 OP_TILING_CHECK(161 OP_TILING_CHECK(
185 context_->GetRawTilingData()->GetCapacity() < tilingDataSize_,162 context_->GetRawTilingData()->GetCapacity() < tilingDataSize_,
186 CUBE_INNER_ERR_REPORT(163 CUBE_INNER_ERR_REPORT(
187- opName_, "tiling data capacity %zu < actual tiling data size %zu",164+ matmulInfo_.opName, "tiling data capacity %zu < actual tiling data size %zu",
188 context_->GetRawTilingData()->GetCapacity(), tilingDataSize_),165 context_->GetRawTilingData()->GetCapacity(), tilingDataSize_),
189 return ge::GRAPH_FAILED);166 return ge::GRAPH_FAILED);
190 167 
@@ -194,14 +171,14 @@ ge::graphStatus DualLevelQuantBatchMatmulTilingASW::InstantiateTilingData()
194bool DualLevelQuantBatchMatmulTilingASW::AnalyseSlidingWinInfo()171bool DualLevelQuantBatchMatmulTilingASW::AnalyseSlidingWinInfo()
195{172{
196 if (!CalcBasicBlock()) {173 if (!CalcBasicBlock()) {
197- OP_LOGE(opName_, "inappropriate basicBlock");174+ OP_LOGE(matmulInfo_.opName, "inappropriate basicBlock");
198 return false;175 return false;
199 }176 }
200- adaptiveWin_.mBlockCnt = ops::CeilDiv(matmulInfoPtr_->mSize, adaptiveWin_.baseM);177+ adaptiveWin_.mBlockCnt = ops::CeilDiv(matmulInfo_.mSize, adaptiveWin_.baseM);
201- adaptiveWin_.nBlockCnt = ops::CeilDiv(matmulInfoPtr_->nSize, adaptiveWin_.baseN);178+ adaptiveWin_.nBlockCnt = ops::CeilDiv(matmulInfo_.nSize, adaptiveWin_.baseN);
202 adaptiveWin_.totalBlockCnt = adaptiveWin_.mBlockCnt * adaptiveWin_.nBlockCnt;179 adaptiveWin_.totalBlockCnt = adaptiveWin_.mBlockCnt * adaptiveWin_.nBlockCnt;
203- adaptiveWin_.mTail = matmulInfoPtr_->mSize - (adaptiveWin_.mBlockCnt - 1) * adaptiveWin_.baseM;180+ adaptiveWin_.mTail = matmulInfo_.mSize - (adaptiveWin_.mBlockCnt - 1) * adaptiveWin_.baseM;
204- adaptiveWin_.nTail = matmulInfoPtr_->nSize - (adaptiveWin_.nBlockCnt - 1) * adaptiveWin_.baseN;181+ adaptiveWin_.nTail = matmulInfo_.nSize - (adaptiveWin_.nBlockCnt - 1) * adaptiveWin_.baseN;
205 adaptiveWin_.totalWinCnt = ops::CeilDiv(adaptiveWin_.totalBlockCnt, static_cast<uint64_t>(compileInfo_.aicNum));182 adaptiveWin_.totalWinCnt = ops::CeilDiv(adaptiveWin_.totalBlockCnt, static_cast<uint64_t>(compileInfo_.aicNum));
206 adaptiveWin_.tailWinBlockCnt = (adaptiveWin_.totalBlockCnt) % compileInfo_.aicNum;183 adaptiveWin_.tailWinBlockCnt = (adaptiveWin_.totalBlockCnt) % compileInfo_.aicNum;
207 184 
@@ -222,16 +199,16 @@ bool DualLevelQuantBatchMatmulTilingASW::AnalyseSlidingWinInfo()
222bool DualLevelQuantBatchMatmulTilingASW::CalcBasicBlock()199bool DualLevelQuantBatchMatmulTilingASW::CalcBasicBlock()
223{200{
224 // baseM=256, baseN=256, baseK=512201 // baseM=256, baseN=256, baseK=512
225- adaptiveWin_.baseM = std::min(matmulInfoPtr_->mSize, static_cast<uint64_t>(BASIC_BLOCK_SIZE_256));202+ adaptiveWin_.baseM = std::min(matmulInfo_.mSize, static_cast<uint64_t>(BASIC_BLOCK_SIZE_256));
226 adaptiveWin_.baseM =203 adaptiveWin_.baseM =
227- ops::CeilAlign(adaptiveWin_.baseM, GetShapeWithDataType(L1_ALIGN_SIZE, matmulInfoPtr_->x1Dtype));204+ ops::CeilAlign(adaptiveWin_.baseM, GetShapeWithDataType(L1_ALIGN_SIZE, matmulInfo_.x1Dtype));
228- adaptiveWin_.baseN = std::min(matmulInfoPtr_->nSize, static_cast<uint64_t>(BASIC_BLOCK_SIZE_256));205+ adaptiveWin_.baseN = std::min(matmulInfo_.nSize, static_cast<uint64_t>(BASIC_BLOCK_SIZE_256));
229 adaptiveWin_.baseN = ops::CeilAlign(adaptiveWin_.baseN, CUBE_BLOCK);206 adaptiveWin_.baseN = ops::CeilAlign(adaptiveWin_.baseN, CUBE_BLOCK);
230 adaptiveWin_.baseK =207 adaptiveWin_.baseK =
231- ops::CeilAlign(std::min(matmulInfoPtr_->kSize, static_cast<uint64_t>(BASIC_BLOCK_SIZE_512)), MXFP_DIVISOR_SIZE);208+ ops::CeilAlign(std::min(matmulInfo_.kSize, static_cast<uint64_t>(BASIC_BLOCK_SIZE_512)), MXFP_DIVISOR_SIZE);
232 209 
233- uint64_t oriBlock = ops::CeilDiv(matmulInfoPtr_->mSize, adaptiveWin_.baseM) *210+ uint64_t oriBlock = ops::CeilDiv(matmulInfo_.mSize, adaptiveWin_.baseM) *
234- ops::CeilDiv(matmulInfoPtr_->nSize, adaptiveWin_.baseN);211+ ops::CeilDiv(matmulInfo_.nSize, adaptiveWin_.baseN);
235 bool isSmallBlock = oriBlock < compileInfo_.aicNum;212 bool isSmallBlock = oriBlock < compileInfo_.aicNum;
236 if (isSmallBlock) {213 if (isSmallBlock) {
237 AdjustBasicBlock();214 AdjustBasicBlock();
@@ -254,44 +231,44 @@ void AdjustMNCoreRatio(
254void DualLevelQuantBatchMatmulTilingASW::AdjustBasicBlock()231void DualLevelQuantBatchMatmulTilingASW::AdjustBasicBlock()
255{232{
256 uint64_t baseMAlignNum =233 uint64_t baseMAlignNum =
257- matmulInfoPtr_->transA ? GetShapeWithDataType(L2_ALIGN_SIZE, matmulInfoPtr_->x1Dtype) : CUBE_BLOCK;234+ matmulInfo_.transA ? GetShapeWithDataType(L2_ALIGN_SIZE, matmulInfo_.x1Dtype) : CUBE_BLOCK;
258 uint64_t baseNAlignNum =235 uint64_t baseNAlignNum =
259- matmulInfoPtr_->transB ? CUBE_BLOCK : GetShapeWithDataType(L2_ALIGN_SIZE, matmulInfoPtr_->x1Dtype);236+ matmulInfo_.transB ? CUBE_BLOCK : GetShapeWithDataType(L2_ALIGN_SIZE, matmulInfo_.x1Dtype);
260- uint64_t baseKAlignNum = (matmulInfoPtr_->transA && !matmulInfoPtr_->transB) ?237+ uint64_t baseKAlignNum = (matmulInfo_.transA && !matmulInfo_.transB) ?
261- GetShapeWithDataType(BASIC_BLOCK_SIZE_32, matmulInfoPtr_->x1Dtype) :238+ GetShapeWithDataType(BASIC_BLOCK_SIZE_32, matmulInfo_.x1Dtype) :
262- GetShapeWithDataType(L2_ALIGN_SIZE, matmulInfoPtr_->x1Dtype);239+ GetShapeWithDataType(L2_ALIGN_SIZE, matmulInfo_.x1Dtype);
263- uint64_t mMaxtile = ops::CeilDiv(matmulInfoPtr_->mSize, baseMAlignNum);240+ uint64_t mMaxtile = ops::CeilDiv(matmulInfo_.mSize, baseMAlignNum);
264- uint64_t nMaxtile = ops::CeilDiv(matmulInfoPtr_->nSize, baseNAlignNum);241+ uint64_t nMaxtile = ops::CeilDiv(matmulInfo_.nSize, baseNAlignNum);
265 uint64_t tempBaseM = adaptiveWin_.baseM;242 uint64_t tempBaseM = adaptiveWin_.baseM;
266 uint64_t tempBaseN = adaptiveWin_.baseN;243 uint64_t tempBaseN = adaptiveWin_.baseN;
267- if (mMaxtile * nMaxtile >= compileInfo_.aicNum || (!matmulInfoPtr_->transA && matmulInfoPtr_->transB)) {244+ if (mMaxtile * nMaxtile >= compileInfo_.aicNum || (!matmulInfo_.transA && matmulInfo_.transB)) {
268- uint64_t mCore = ops::CeilDiv(matmulInfoPtr_->mSize, adaptiveWin_.baseM);245+ uint64_t mCore = ops::CeilDiv(matmulInfo_.mSize, adaptiveWin_.baseM);
269- uint64_t nCore = ops::CeilDiv(matmulInfoPtr_->nSize, adaptiveWin_.baseN);246+ uint64_t nCore = ops::CeilDiv(matmulInfo_.nSize, adaptiveWin_.baseN);
270 if (mMaxtile < nMaxtile || (mMaxtile == nMaxtile && baseNAlignNum == CUBE_BLOCK)) {247 if (mMaxtile < nMaxtile || (mMaxtile == nMaxtile && baseNAlignNum == CUBE_BLOCK)) {
271- tempBaseM = ops::CeilAlign(ops::CeilDiv(matmulInfoPtr_->mSize, mCore), baseMAlignNum);248+ tempBaseM = ops::CeilAlign(ops::CeilDiv(matmulInfo_.mSize, mCore), baseMAlignNum);
272- mCore = ops::CeilDiv(matmulInfoPtr_->mSize, tempBaseM);249+ mCore = ops::CeilDiv(matmulInfo_.mSize, tempBaseM);
273 nCore = compileInfo_.aicNum / mCore;250 nCore = compileInfo_.aicNum / mCore;
274- tempBaseN = ops::CeilAlign(ops::CeilDiv(matmulInfoPtr_->nSize, nCore), baseNAlignNum);251+ tempBaseN = ops::CeilAlign(ops::CeilDiv(matmulInfo_.nSize, nCore), baseNAlignNum);
275 } else {252 } else {
276- tempBaseN = ops::CeilAlign(ops::CeilDiv(matmulInfoPtr_->nSize, nCore), baseNAlignNum);253+ tempBaseN = ops::CeilAlign(ops::CeilDiv(matmulInfo_.nSize, nCore), baseNAlignNum);
277- nCore = ops::CeilDiv(matmulInfoPtr_->nSize, tempBaseN);254+ nCore = ops::CeilDiv(matmulInfo_.nSize, tempBaseN);
278 mCore = compileInfo_.aicNum / nCore;255 mCore = compileInfo_.aicNum / nCore;
279- tempBaseM = ops::CeilAlign(ops::CeilDiv(matmulInfoPtr_->mSize, mCore), baseMAlignNum);256+ tempBaseM = ops::CeilAlign(ops::CeilDiv(matmulInfo_.mSize, mCore), baseMAlignNum);
280 }257 }
281 258 
282 auto updateFunc = [&, this]() {259 auto updateFunc = [&, this]() {
283- tempBaseM = ops::CeilAlign(ops::CeilDiv(matmulInfoPtr_->mSize, mCore), baseMAlignNum);260+ tempBaseM = ops::CeilAlign(ops::CeilDiv(matmulInfo_.mSize, mCore), baseMAlignNum);
284- tempBaseN = ops::CeilAlign(ops::CeilDiv(matmulInfoPtr_->nSize, nCore), baseNAlignNum);261+ tempBaseN = ops::CeilAlign(ops::CeilDiv(matmulInfo_.nSize, nCore), baseNAlignNum);
285- mCore = ops::CeilDiv(matmulInfoPtr_->mSize, static_cast<uint64_t>(tempBaseM));262+ mCore = ops::CeilDiv(matmulInfo_.mSize, static_cast<uint64_t>(tempBaseM));
286- nCore = ops::CeilDiv(matmulInfoPtr_->nSize, static_cast<uint64_t>(tempBaseN));263+ nCore = ops::CeilDiv(matmulInfo_.nSize, static_cast<uint64_t>(tempBaseN));
287 };264 };
288 AdjustMNCoreRatio(265 AdjustMNCoreRatio(
289 nCore, mCore, tempBaseN, tempBaseM, baseNAlignNum, static_cast<uint64_t>(compileInfo_.aicNum), updateFunc);266 nCore, mCore, tempBaseN, tempBaseM, baseNAlignNum, static_cast<uint64_t>(compileInfo_.aicNum), updateFunc);
290 AdjustMNCoreRatio(267 AdjustMNCoreRatio(
291 mCore, nCore, tempBaseM, tempBaseN, baseMAlignNum, static_cast<uint64_t>(compileInfo_.aicNum), updateFunc);268 mCore, nCore, tempBaseM, tempBaseN, baseMAlignNum, static_cast<uint64_t>(compileInfo_.aicNum), updateFunc);
292 269 
293- uint64_t kValueAlign = ops::CeilAlign(static_cast<uint64_t>(matmulInfoPtr_->kSize), baseKAlignNum);270+ uint64_t kValueAlign = ops::CeilAlign(static_cast<uint64_t>(matmulInfo_.kSize), baseKAlignNum);
294- uint64_t kValueMax = GetShapeWithDataType(compileInfo_.l0aSize / DB_SIZE, matmulInfoPtr_->x1Dtype) /271+ uint64_t kValueMax = GetShapeWithDataType(compileInfo_.l0aSize / DB_SIZE, matmulInfo_.x1Dtype) /
295 std::max(tempBaseM, tempBaseN) / L0_SPLIT_NUM;272 std::max(tempBaseM, tempBaseN) / L0_SPLIT_NUM;
296 if (kValueMax >= baseKAlignNum) {273 if (kValueMax >= baseKAlignNum) {
297 adaptiveWin_.baseM = tempBaseM;274 adaptiveWin_.baseM = tempBaseM;
@@ -351,39 +328,39 @@ uint32_t DualLevelQuantBatchMatmulTilingASW::CalBlockDim()
351 328 
352bool DualLevelQuantBatchMatmulTilingASW::IsInvalidWeightNzTailSplit(uint64_t splitCnt, bool isPreSplit) const329bool DualLevelQuantBatchMatmulTilingASW::IsInvalidWeightNzTailSplit(uint64_t splitCnt, bool isPreSplit) const
353{330{
354- if (matmulInfoPtr_->x2Format != ge::FORMAT_FRACTAL_NZ ||331+ if (matmulInfo_.x2Format != ge::FORMAT_FRACTAL_NZ ||
355 (((isPreSplit && adaptiveWin_.mTail >= adaptiveWin_.nTail) ||332 (((isPreSplit && adaptiveWin_.mTail >= adaptiveWin_.nTail) ||
356 (!isPreSplit && adaptiveWin_.mTail < adaptiveWin_.nTail)))) {333 (!isPreSplit && adaptiveWin_.mTail < adaptiveWin_.nTail)))) {
357 return false;334 return false;
358 }335 }
359 uint64_t tailN = adaptiveWin_.baseN / splitCnt;336 uint64_t tailN = adaptiveWin_.baseN / splitCnt;
360- return tailN % GetShapeWithDataType(L1_ALIGN_SIZE, matmulInfoPtr_->x2Dtype) != 0;337+ return tailN % GetShapeWithDataType(L1_ALIGN_SIZE, matmulInfo_.x2Dtype) != 0;
361}338}
362 339 
363bool DualLevelQuantBatchMatmulTilingASW::OptimizeEdgeBasicBlock()340bool DualLevelQuantBatchMatmulTilingASW::OptimizeEdgeBasicBlock()
364{341{
365- uint64_t mCore = ops::CeilDiv(matmulInfoPtr_->mSize, adaptiveWin_.baseM);342+ uint64_t mCore = ops::CeilDiv(matmulInfo_.mSize, adaptiveWin_.baseM);
366- uint64_t nCore = ops::CeilDiv(matmulInfoPtr_->nSize, adaptiveWin_.baseN);343+ uint64_t nCore = ops::CeilDiv(matmulInfo_.nSize, adaptiveWin_.baseN);
367 if (mCore == 1UL || nCore == 1UL) {344 if (mCore == 1UL || nCore == 1UL) {
368 return true;345 return true;
369 }346 }
370 347 
371- uint64_t mBaseTail = static_cast<uint64_t>(matmulInfoPtr_->mSize % adaptiveWin_.baseM);348+ uint64_t mBaseTail = static_cast<uint64_t>(matmulInfo_.mSize % adaptiveWin_.baseM);
372- uint64_t nBaseTail = static_cast<uint64_t>(matmulInfoPtr_->nSize % adaptiveWin_.baseN);349+ uint64_t nBaseTail = static_cast<uint64_t>(matmulInfo_.nSize % adaptiveWin_.baseN);
373- bool isMxfp4 = (matmulInfoPtr_->x1Dtype == ge::DT_FLOAT4_E2M1 || matmulInfoPtr_->x1Dtype == ge::DT_FLOAT4_E1M2) &&350+ bool isMxfp4 = (matmulInfo_.x1Dtype == ge::DT_FLOAT4_E2M1 || matmulInfo_.x1Dtype == ge::DT_FLOAT4_E1M2) &&
374- matmulInfoPtr_->x1Level1ScaleDtype == ge::DT_FLOAT8_E8M0 &&351+ matmulInfo_.x1Level1ScaleDtype == ge::DT_FLOAT8_E8M0 &&
375- matmulInfoPtr_->level1GroupSize == MICROSCALE_GROUP_SIZE;352+ matmulInfo_.level1GroupSize == MICROSCALE_GROUP_SIZE;
376- bool balanceAfterFixp = matmulInfoPtr_->kSize < static_cast<uint64_t>(BASIC_BLOCK_SIZE_1024);353+ bool balanceAfterFixp = matmulInfo_.kSize < static_cast<uint64_t>(BASIC_BLOCK_SIZE_1024);
377 bool isInnerAxisAlign =354 bool isInnerAxisAlign =
378- GetSizeWithDataType(matmulInfoPtr_->kSize, matmulInfoPtr_->x1Dtype) % MTE2_CACHELINE_SIZE == 0UL;355+ GetSizeWithDataType(matmulInfo_.kSize, matmulInfo_.x1Dtype) % MTE2_CACHELINE_SIZE == 0UL;
379- if (mBaseTail > 0UL && !matmulInfoPtr_->transA &&356+ if (mBaseTail > 0UL && !matmulInfo_.transA &&
380- (isInnerAxisAlign || (matmulInfoPtr_->mSize >= LOAD_BALANCE_THRESHOLD && !isMxfp4))) {357+ (isInnerAxisAlign || (matmulInfo_.mSize >= LOAD_BALANCE_THRESHOLD && !isMxfp4))) {
381 if (!GetOuterMAxisTailCnt(adaptiveWin_.mBaseTailSplitCnt, adaptiveWin_.mTailMain)) {358 if (!GetOuterMAxisTailCnt(adaptiveWin_.mBaseTailSplitCnt, adaptiveWin_.mTailMain)) {
382 return false;359 return false;
383 };360 };
384 }361 }
385- if (nBaseTail > 0UL && matmulInfoPtr_->transB && !balanceAfterFixp &&362+ if (nBaseTail > 0UL && matmulInfo_.transB && !balanceAfterFixp &&
386- (isInnerAxisAlign || (matmulInfoPtr_->nSize >= LOAD_BALANCE_THRESHOLD))) {363+ (isInnerAxisAlign || (matmulInfo_.nSize >= LOAD_BALANCE_THRESHOLD))) {
387 if (!GetOuterNAxisTailCnt(adaptiveWin_.nBaseTailSplitCnt, adaptiveWin_.nTailMain)) {364 if (!GetOuterNAxisTailCnt(adaptiveWin_.nBaseTailSplitCnt, adaptiveWin_.nTailMain)) {
388 return false;365 return false;
389 };366 };
@@ -394,10 +371,10 @@ bool DualLevelQuantBatchMatmulTilingASW::OptimizeEdgeBasicBlock()
394bool DualLevelQuantBatchMatmulTilingASW::GetOuterMAxisTailCnt(uint64_t& baseTailSplitCnt, uint64_t& tailMain)371bool DualLevelQuantBatchMatmulTilingASW::GetOuterMAxisTailCnt(uint64_t& baseTailSplitCnt, uint64_t& tailMain)
395{372{
396 OP_TILING_CHECK(373 OP_TILING_CHECK(
397- matmulInfoPtr_->mSize == 0UL, CUBE_INNER_ERR_REPORT(opName_, "Input size of the M-axis is zero."),374+ matmulInfo_.mSize == 0UL, CUBE_INNER_ERR_REPORT(matmulInfo_.opName, "Input size of the M-axis is zero."),
398 return false);375 return false);
399- uint64_t mCnt = ops::CeilDiv(matmulInfoPtr_->mSize, adaptiveWin_.baseM);376+ uint64_t mCnt = ops::CeilDiv(matmulInfo_.mSize, adaptiveWin_.baseM);
400- uint64_t mTailSize = matmulInfoPtr_->mSize % adaptiveWin_.baseM;377+ uint64_t mTailSize = matmulInfo_.mSize % adaptiveWin_.baseM;
401 uint64_t baseTailCntMax = std::min((adaptiveWin_.baseM - mTailSize) / BASIC_BLOCK_SIZE_16, mCnt);378 uint64_t baseTailCntMax = std::min((adaptiveWin_.baseM - mTailSize) / BASIC_BLOCK_SIZE_16, mCnt);
402 uint64_t windowSize = std::min(WINDOW_LEN, mCnt);379 uint64_t windowSize = std::min(WINDOW_LEN, mCnt);
403 uint64_t mainWindowNum = mCnt / windowSize - 1UL;380 uint64_t mainWindowNum = mCnt / windowSize - 1UL;
@@ -413,7 +390,7 @@ bool DualLevelQuantBatchMatmulTilingASW::GetOuterMAxisTailCnt(uint64_t& baseTail
413 OP_TILING_CHECK(390 OP_TILING_CHECK(
414 mainWindowNum + 1UL < mergeWindowNum,391 mainWindowNum + 1UL < mergeWindowNum,
415 CUBE_INNER_ERR_REPORT(392 CUBE_INNER_ERR_REPORT(
416- opName_, "Subtraction underflow: mainWindowNum(%lu) + 1UL - mergeWindowNum(%lu).", mainWindowNum,393+ matmulInfo_.opName, "Subtraction underflow: mainWindowNum(%lu) + 1UL - mergeWindowNum(%lu).", mainWindowNum,
417 mergeWindowNum),394 mergeWindowNum),
418 return false);395 return false);
419 uint64_t curPerf = (mainWindowNum + 1UL - mergeWindowNum) * adaptiveWin_.baseM + mergeWindowNum * newTailMain;396 uint64_t curPerf = (mainWindowNum + 1UL - mergeWindowNum) * adaptiveWin_.baseM + mergeWindowNum * newTailMain;
@@ -429,15 +406,15 @@ bool DualLevelQuantBatchMatmulTilingASW::GetOuterMAxisTailCnt(uint64_t& baseTail
429bool DualLevelQuantBatchMatmulTilingASW::GetOuterNAxisTailCnt(uint64_t& baseTailSplitCnt, uint64_t& tailMain)406bool DualLevelQuantBatchMatmulTilingASW::GetOuterNAxisTailCnt(uint64_t& baseTailSplitCnt, uint64_t& tailMain)
430{407{
431 uint64_t baseN = adaptiveWin_.baseN;408 uint64_t baseN = adaptiveWin_.baseN;
432- uint64_t nCnt = ops::CeilDiv(matmulInfoPtr_->nSize, baseN);409+ uint64_t nCnt = ops::CeilDiv(matmulInfo_.nSize, baseN);
433- uint64_t mCnt = ops::CeilDiv(matmulInfoPtr_->mSize, adaptiveWin_.baseM);410+ uint64_t mCnt = ops::CeilDiv(matmulInfo_.mSize, adaptiveWin_.baseM);
434- uint64_t nTail = matmulInfoPtr_->nSize % baseN;411+ uint64_t nTail = matmulInfo_.nSize % baseN;
435 uint64_t totalWindows = ops::CeilDiv<uint64_t>(nCnt * mCnt, compileInfo_.aicNum);412 uint64_t totalWindows = ops::CeilDiv<uint64_t>(nCnt * mCnt, compileInfo_.aicNum);
436 413 
437 OP_TILING_CHECK(414 OP_TILING_CHECK(
438 nCnt == 0UL,415 nCnt == 0UL,
439 CUBE_INNER_ERR_REPORT(416 CUBE_INNER_ERR_REPORT(
440- opName_,417+ matmulInfo_.opName,
441 "Subtraction underflow: nCnt(%lu) - 1UL and \418 "Subtraction underflow: nCnt(%lu) - 1UL and \
442the divisor is zero: WINDOW_LEN %% nCnt.",419the divisor is zero: WINDOW_LEN %% nCnt.",
443 nCnt),420 nCnt),
@@ -446,7 +423,7 @@ the divisor is zero: WINDOW_LEN %% nCnt.",
446 ops::CeilDiv<uint64_t>((nCnt - 1UL) * mCnt + mCnt % compileInfo_.aicNum, compileInfo_.aicNum);423 ops::CeilDiv<uint64_t>((nCnt - 1UL) * mCnt + mCnt % compileInfo_.aicNum, compileInfo_.aicNum);
447 424 
448 OP_TILING_CHECK(425 OP_TILING_CHECK(
449- compileInfo_.aicNum == 0UL, CUBE_INNER_ERR_REPORT(opName_, "The number of enabled Cube cores is 0."),426+ compileInfo_.aicNum == 0UL, CUBE_INNER_ERR_REPORT(matmulInfo_.opName, "The number of enabled Cube cores is 0."),
450 return false);427 return false);
451 if (nCnt * mCnt <= compileInfo_.aicNum ||428 if (nCnt * mCnt <= compileInfo_.aicNum ||
452 (mCnt % compileInfo_.aicNum == 0UL && (nCnt % WINDOW_LEN == 0UL || WINDOW_LEN % nCnt == 0UL))) {429 (mCnt % compileInfo_.aicNum == 0UL && (nCnt % WINDOW_LEN == 0UL || WINDOW_LEN % nCnt == 0UL))) {
@@ -455,7 +432,7 @@ the divisor is zero: WINDOW_LEN %% nCnt.",
455 OP_TILING_CHECK(432 OP_TILING_CHECK(
456 totalWindows < mainWindows,433 totalWindows < mainWindows,
457 CUBE_INNER_ERR_REPORT(434 CUBE_INNER_ERR_REPORT(
458- opName_, "Subtraction underflow: totalWindows(%lu) - mainWindows(%lu).", totalWindows, mainWindows),435+ matmulInfo_.opName, "Subtraction underflow: totalWindows(%lu) - mainWindows(%lu).", totalWindows, mainWindows),
459 return false);436 return false);
460 uint64_t tailWindows = totalWindows - mainWindows;437 uint64_t tailWindows = totalWindows - mainWindows;
461 uint64_t perfRes = mainWindows * baseN + tailWindows * nTail;438 uint64_t perfRes = mainWindows * baseN + tailWindows * nTail;
@@ -483,7 +460,7 @@ uint64_t DualLevelQuantBatchMatmulTilingASW::CalculateCurrentPerf(
483 OP_TILING_CHECK(460 OP_TILING_CHECK(
484 adaptiveWin_.baseN < newTailMain,461 adaptiveWin_.baseN < newTailMain,
485 CUBE_INNER_ERR_REPORT(462 CUBE_INNER_ERR_REPORT(
486- opName_, "Subtraction underflow: adaptiveWin_.baseN(%lu) - newTailMain(%lu).", adaptiveWin_.baseN,463+ matmulInfo_.opName, "Subtraction underflow: adaptiveWin_.baseN(%lu) - newTailMain(%lu).", adaptiveWin_.baseN,
487 newTailMain),464 newTailMain),
488 return static_cast<uint64_t>(-1));465 return static_cast<uint64_t>(-1));
489 uint64_t newTailLast = mergeLen * (adaptiveWin_.baseN - newTailMain) + nTail;466 uint64_t newTailLast = mergeLen * (adaptiveWin_.baseN - newTailMain) + nTail;
@@ -498,7 +475,7 @@ uint64_t DualLevelQuantBatchMatmulTilingASW::CalculateCurrentPerf(
498 OP_TILING_CHECK(475 OP_TILING_CHECK(
499 totalWindows < newMainRound,476 totalWindows < newMainRound,
500 CUBE_INNER_ERR_REPORT(477 CUBE_INNER_ERR_REPORT(
501- opName_, "Subtraction underflow: totalWindows(%lu) - newMainRound(%lu).", totalWindows, newMainRound),478+ matmulInfo_.opName, "Subtraction underflow: totalWindows(%lu) - newMainRound(%lu).", totalWindows, newMainRound),
502 return static_cast<uint64_t>(-1));479 return static_cast<uint64_t>(-1));
503 newTailRound = std::min(480 newTailRound = std::min(
504 ops::CeilDiv<uint64_t>(mergeLen * mCnt + mCnt % compileInfo_.aicNum, compileInfo_.aicNum),481 ops::CeilDiv<uint64_t>(mergeLen * mCnt + mCnt % compileInfo_.aicNum, compileInfo_.aicNum),
@@ -508,7 +485,7 @@ uint64_t DualLevelQuantBatchMatmulTilingASW::CalculateCurrentPerf(
508 OP_TILING_CHECK(485 OP_TILING_CHECK(
509 totalWindows < newMainRound + newTailRound,486 totalWindows < newMainRound + newTailRound,
510 CUBE_INNER_ERR_REPORT(487 CUBE_INNER_ERR_REPORT(
511- opName_, "Subtraction underflow: totalWindows(%lu) - newMainRound(%lu) - newTailRound(%lu).", totalWindows,488+ matmulInfo_.opName, "Subtraction underflow: totalWindows(%lu) - newMainRound(%lu) - newTailRound(%lu).", totalWindows,
512 newMainRound, newTailRound),489 newMainRound, newTailRound),
513 return static_cast<uint64_t>(-1));490 return static_cast<uint64_t>(-1));
514 return newMainRound * adaptiveWin_.baseN + newTailRound * newTailMain +491 return newMainRound * adaptiveWin_.baseN + newTailRound * newTailMain +
@@ -520,16 +497,16 @@ void DualLevelQuantBatchMatmulTilingASW::SetTilingData()
520 usedCoreNum = CalBlockDim();497 usedCoreNum = CalBlockDim();
521 498 
522 tilingData_->l1BufferNum = 2;499 tilingData_->l1BufferNum = 2;
523- tilingData_->hasBias = matmulInfoPtr_->hasBias;500+ tilingData_->hasBias = matmulInfo_.hasBias;
524 tilingData_->l2CacheDisable = L2CacheMode::L2_CACHE_DEFAULT;501 tilingData_->l2CacheDisable = L2CacheMode::L2_CACHE_DEFAULT;
525 tilingData_->usedCoreNum = usedCoreNum;502 tilingData_->usedCoreNum = usedCoreNum;
526- tilingData_->mSize = matmulInfoPtr_->mSize;503+ tilingData_->mSize = matmulInfo_.mSize;
527- tilingData_->nSize = matmulInfoPtr_->nSize;504+ tilingData_->nSize = matmulInfo_.nSize;
528- tilingData_->kSize = matmulInfoPtr_->kSize;505+ tilingData_->kSize = matmulInfo_.kSize;
529 tilingData_->mL1Size = adaptiveWin_.baseM;506 tilingData_->mL1Size = adaptiveWin_.baseM;
530 tilingData_->nL1Size = adaptiveWin_.baseN;507 tilingData_->nL1Size = adaptiveWin_.baseN;
531 tilingData_->kL1Size = adaptiveWin_.baseK;508 tilingData_->kL1Size = adaptiveWin_.baseK;
532- tilingData_->level0GroupSize = matmulInfoPtr_->level0GroupSize;509+ tilingData_->level0GroupSize = matmulInfo_.level0GroupSize;
533 510 
534 tilingData_->mTailTile = adaptiveWin_.mTailTile;511 tilingData_->mTailTile = adaptiveWin_.mTailTile;
535 tilingData_->nTailTile = adaptiveWin_.nTailTile;512 tilingData_->nTailTile = adaptiveWin_.nTailTile;
@@ -538,7 +515,7 @@ void DualLevelQuantBatchMatmulTilingASW::SetTilingData()
538 tilingData_->mTailMain = static_cast<uint32_t>(adaptiveWin_.mTailMain);515 tilingData_->mTailMain = static_cast<uint32_t>(adaptiveWin_.mTailMain);
539 tilingData_->nTailMain = static_cast<uint32_t>(adaptiveWin_.nTailMain);516 tilingData_->nTailMain = static_cast<uint32_t>(adaptiveWin_.nTailMain);
540 517 
541- OP_LOGD(opName_, "coreNum: %u", usedCoreNum);518+ OP_LOGD(matmulInfo_.opName, "coreNum: %u", usedCoreNum);
542}519}
543} // namespace dual_level_quant_batch_matmul520} // namespace dual_level_quant_batch_matmul
544} // namespace optiling521} // namespace optiling
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_checker.cpp+62-37
@@ -21,13 +21,13 @@
21#include "matmul/common/op_host/op_tiling/debug_tiling.h"21#include "matmul/common/op_host/op_tiling/debug_tiling.h"
22#include "platform/platform_infos_def.h"22#include "platform/platform_infos_def.h"
23 23 
24-namespace optiling {24+using namespace optiling;
25 25 
26constexpr uint64_t MICROSCALING_GROUP_SIZE = 32UL;26constexpr uint64_t MICROSCALING_GROUP_SIZE = 32UL;
27constexpr uint64_t DEFAULT_LEVEL0_GROUP_SIZE = 512UL;27constexpr uint64_t DEFAULT_LEVEL0_GROUP_SIZE = 512UL;
28 28 
29-namespace checker {29+namespace Ops::NN::DLQBMMChecker {
30-ge::graphStatus CheckContext(gert::TilingContext* context, const char* opName, uint64_t tilingDataSize)30+ge::graphStatus CheckContext(gert::TilingContext* context, uint64_t tilingDataSize)
范其瑞
范其瑞范其瑞2月2日

namespace命名有问题: 1、NN仓要用Ops::NN的前缀,大驼峰 2、本文件里存在大量的命名比较宽泛的函数,namespace的命名也没有带上算子名信息,后续有符号冲突的可能性

likedislike
31{31{
32 auto attrs = context->GetAttrs();32 auto attrs = context->GetAttrs();
33 OP_TILING_CHECK(33 OP_TILING_CHECK(
@@ -50,7 +50,7 @@ ge::graphStatus CheckContext(gert::TilingContext* context, const char* opName, u
50 OP_TILING_CHECK(50 OP_TILING_CHECK(
51 context->GetRawTilingData()->GetCapacity() < tilingDataSize,51 context->GetRawTilingData()->GetCapacity() < tilingDataSize,
52 CUBE_INNER_ERR_REPORT(52 CUBE_INNER_ERR_REPORT(
53- opName, "context tiling data capacity %zu < actual tiling data size %zu.",53+ context, "context tiling data capacity %zu < actual tiling data size %zu.",
54 context->GetRawTilingData()->GetCapacity(), tilingDataSize),54 context->GetRawTilingData()->GetCapacity(), tilingDataSize),
55 return ge::GRAPH_FAILED);55 return ge::GRAPH_FAILED);
56 return ge::GRAPH_SUCCESS;56 return ge::GRAPH_SUCCESS;
@@ -63,7 +63,7 @@ bool CheckAttrs(
63 OP_TILING_CHECK(63 OP_TILING_CHECK(
64 inputParams.transA != false || inputParams.transB != true,64 inputParams.transA != false || inputParams.transB != true,
65 VECTOR_INNER_ERR_REPORT_TILIING(65 VECTOR_INNER_ERR_REPORT_TILIING(
66- inputParams.opName,66+ context,
67 "x1 transpose should be false and x2 transpose should be true, "67 "x1 transpose should be false and x2 transpose should be true, "
68 "but got x1 transpose: %s, x2 transpose: %s",68 "but got x1 transpose: %s, x2 transpose: %s",
69 inputParams.transA ? "true" : "false", inputParams.transB ? "true" : "false"),69 inputParams.transA ? "true" : "false", inputParams.transB ? "true" : "false"),
@@ -71,13 +71,13 @@ bool CheckAttrs(
71 OP_TILING_CHECK(71 OP_TILING_CHECK(
72 inputParams.level1GroupSize != MICROSCALING_GROUP_SIZE,72 inputParams.level1GroupSize != MICROSCALING_GROUP_SIZE,
73 VECTOR_INNER_ERR_REPORT_TILIING(73 VECTOR_INNER_ERR_REPORT_TILIING(
74- inputParams.opName, "Level1 group size only support %zu, but got %zu", MICROSCALING_GROUP_SIZE,74+ context, "Level1 group size is only supported to be %zu, but got %zu", MICROSCALING_GROUP_SIZE,
75 inputParams.level1GroupSize),75 inputParams.level1GroupSize),
76 return false);76 return false);
77 OP_TILING_CHECK(77 OP_TILING_CHECK(
78 inputParams.level0GroupSize != DEFAULT_LEVEL0_GROUP_SIZE,78 inputParams.level0GroupSize != DEFAULT_LEVEL0_GROUP_SIZE,
79 VECTOR_INNER_ERR_REPORT_TILIING(79 VECTOR_INNER_ERR_REPORT_TILIING(
80- inputParams.opName, "Level0 group size only support %zu, but got %zu", DEFAULT_LEVEL0_GROUP_SIZE,80+ context, "Level0 group size is only supported to be %zu, but got %zu", DEFAULT_LEVEL0_GROUP_SIZE,
81 inputParams.level0GroupSize),81 inputParams.level0GroupSize),
82 return false);82 return false);
83 return true;83 return true;
@@ -90,15 +90,15 @@ bool CheckDtypes(
90 OP_TILING_CHECK(90 OP_TILING_CHECK(
91 inputParams.x1Dtype != ge::DT_FLOAT4_E2M1 || inputParams.x2Dtype != ge::DT_FLOAT4_E2M1,91 inputParams.x1Dtype != ge::DT_FLOAT4_E2M1 || inputParams.x2Dtype != ge::DT_FLOAT4_E2M1,
92 VECTOR_INNER_ERR_REPORT_TILIING(92 VECTOR_INNER_ERR_REPORT_TILIING(
93- inputParams.opName, "Input x1 and x2 dtype is only support float4_e2m1, but x1Dtype: %s x2Dtype: %s",93+ context, "Input x1 and x2 dtype is only supported to be float4_e2m1, but x1Dtype: %s x2Dtype: %s",
94 ge::TypeUtils::DataTypeToSerialString(inputParams.x1Dtype).c_str(),94 ge::TypeUtils::DataTypeToSerialString(inputParams.x1Dtype).c_str(),
95 ge::TypeUtils::DataTypeToSerialString(inputParams.x2Dtype).c_str()),95 ge::TypeUtils::DataTypeToSerialString(inputParams.x2Dtype).c_str()),
96 return false);96 return false);
97 OP_TILING_CHECK(97 OP_TILING_CHECK(
98 inputParams.x1Level0ScaleDtype != ge::DT_FLOAT || inputParams.x2Level0ScaleDtype != ge::DT_FLOAT,98 inputParams.x1Level0ScaleDtype != ge::DT_FLOAT || inputParams.x2Level0ScaleDtype != ge::DT_FLOAT,
99 VECTOR_INNER_ERR_REPORT_TILIING(99 VECTOR_INNER_ERR_REPORT_TILIING(
100- inputParams.opName,100+ context,
101- "Input x1Level0Scale and x2Level0Scale dtype only support float, "101+ "Input x1Level0Scale and x2Level0Scale dtype is only supported to be float, "
102 "but x1Level0ScaleDtype: %s, x2Level0ScaleDtype: %s",102 "but x1Level0ScaleDtype: %s, x2Level0ScaleDtype: %s",
103 ge::TypeUtils::DataTypeToSerialString(inputParams.x1Level0ScaleDtype).c_str(),103 ge::TypeUtils::DataTypeToSerialString(inputParams.x1Level0ScaleDtype).c_str(),
104 ge::TypeUtils::DataTypeToSerialString(inputParams.x2Level0ScaleDtype).c_str()),104 ge::TypeUtils::DataTypeToSerialString(inputParams.x2Level0ScaleDtype).c_str()),
@@ -106,8 +106,8 @@ bool CheckDtypes(
106 OP_TILING_CHECK(106 OP_TILING_CHECK(
107 inputParams.x1Level1ScaleDtype != ge::DT_FLOAT8_E8M0 || inputParams.x2Level1ScaleDtype != ge::DT_FLOAT8_E8M0,107 inputParams.x1Level1ScaleDtype != ge::DT_FLOAT8_E8M0 || inputParams.x2Level1ScaleDtype != ge::DT_FLOAT8_E8M0,
108 VECTOR_INNER_ERR_REPORT_TILIING(108 VECTOR_INNER_ERR_REPORT_TILIING(
109- inputParams.opName,109+ context,
110- "Input x1Level1Scale and x2Level1Scale dtype only support float8_e8m0, "110+ "Input x1Level1Scale and x2Level1Scale dtype is only supported to be float8_e8m0, "
111 "but x1Level1ScaleDtype: %s, x2Level1ScaleDtype: %s",111 "but x1Level1ScaleDtype: %s, x2Level1ScaleDtype: %s",
112 ge::TypeUtils::DataTypeToSerialString(inputParams.x1Level1ScaleDtype).c_str(),112 ge::TypeUtils::DataTypeToSerialString(inputParams.x1Level1ScaleDtype).c_str(),
113 ge::TypeUtils::DataTypeToSerialString(inputParams.x2Level1ScaleDtype).c_str()),113 ge::TypeUtils::DataTypeToSerialString(inputParams.x2Level1ScaleDtype).c_str()),
@@ -116,8 +116,8 @@ bool CheckDtypes(
116 OP_TILING_CHECK(116 OP_TILING_CHECK(
117 inputParams.biasDtype != ge::DT_FLOAT,117 inputParams.biasDtype != ge::DT_FLOAT,
118 VECTOR_INNER_ERR_REPORT_TILIING(118 VECTOR_INNER_ERR_REPORT_TILIING(
119- inputParams.opName,119+ context,
120- "Input bias dtype only support float, "120+ "Input bias dtype is only supported to be float, "
121 "but got %s",121 "but got %s",
122 ge::TypeUtils::DataTypeToSerialString(inputParams.biasDtype).c_str()),122 ge::TypeUtils::DataTypeToSerialString(inputParams.biasDtype).c_str()),
123 return false);123 return false);
@@ -125,40 +125,67 @@ bool CheckDtypes(
125 OP_TILING_CHECK(125 OP_TILING_CHECK(
126 inputParams.yDtype != ge::DT_FLOAT16 && inputParams.yDtype != ge::DT_BF16,126 inputParams.yDtype != ge::DT_FLOAT16 && inputParams.yDtype != ge::DT_BF16,
127 VECTOR_INNER_ERR_REPORT_TILIING(127 VECTOR_INNER_ERR_REPORT_TILIING(
128- inputParams.opName, "Output y dtype is only support float16 or bfloat16, but got %s",128+ context, "Output y dtype is only supported to be float16 or bfloat16, but got %s",
129 ge::TypeUtils::DataTypeToSerialString(inputParams.yDtype).c_str()),129 ge::TypeUtils::DataTypeToSerialString(inputParams.yDtype).c_str()),
130 return false);130 return false);
131 return true;131 return true;
132}132}
133 133 
134+std::string ToShapeString(std::initializer_list<uint64_t> shape)
135+{
136+ std::string shapeStr("[");
137+ const char* sep = "";
138+ for (auto x : shape) {
139+ shapeStr.append(sep);
140+ shapeStr.append(std::to_string(x));
141+ sep = ", ";
142+ }
143+ return shapeStr;
144+}
145+ 
134bool CheckInputShape(146bool CheckInputShape(
135- const char* opName, const char* variableName, const gert::Shape& shape,147+ gert::TilingContext* context, const char* variableName, const gert::Shape& shape,
136 std::initializer_list<uint64_t> expectedShape)148 std::initializer_list<uint64_t> expectedShape)
137{149{
138 auto shapeLen = shape.GetDimNum();150 auto shapeLen = shape.GetDimNum();
139 OP_TILING_CHECK(151 OP_TILING_CHECK(
140 shapeLen != expectedShape.size(),152 shapeLen != expectedShape.size(),
141 CUBE_INNER_ERR_REPORT(153 CUBE_INNER_ERR_REPORT(
142- opName, "input %s deminsion should be %zu, but got %zu", variableName, expectedShape.size(), shapeLen),154+ context, "input %s deminsion should be %zu, but got %zu", variableName, expectedShape.size(), shapeLen),
143 return false);155 return false);
144 size_t i = 0;156 size_t i = 0;
145 for (auto dim : expectedShape) {157 for (auto dim : expectedShape) {
146 OP_TILING_CHECK(158 OP_TILING_CHECK(
147 dim != static_cast<uint64_t>(shape.GetDim(i++)),159 dim != static_cast<uint64_t>(shape.GetDim(i++)),
148 VECTOR_INNER_ERR_REPORT_TILIING(160 VECTOR_INNER_ERR_REPORT_TILIING(
149- opName, "Check input %s shape failed, got %s", variableName, Ops::Base::ToString(shape).c_str()),161+ context, "Check input %s shape failed, expected %s, but got %s", variableName,
162+ ToShapeString(expectedShape).c_str(), Ops::Base::ToString(shape).c_str()),
150 return false);163 return false);
151 }164 }
152 return true;165 return true;
153}166}
154 167 
168+bool IsInputsValid(gert::TilingContext* context, const DualLevelQuantBatchMatmulInfo& inputParams)
169+{
170+ OP_TILING_CHECK(
171+ inputParams.mSize == 0 || inputParams.nSize == 0 || inputParams.kSize == 0,
172+ VECTOR_INNER_ERR_REPORT_TILIING(context, "The input M, N and K axes cannot be 0"), return false);
173+ OP_TILING_CHECK(
174+ inputParams.x1Format != ge::FORMAT_ND,
175+ VECTOR_INNER_ERR_REPORT_TILIING(context, "Input x1 input format shoulde be ND"), return false);
176+ OP_TILING_CHECK(
177+ inputParams.x2Format != ge::FORMAT_FRACTAL_NZ,
178+ VECTOR_INNER_ERR_REPORT_TILIING(context, "Input x2 weight format shoulde be FRACTAL_NZ"), return false);
179+ return true;
180+}
181+ 
155bool CheckInputs(182bool CheckInputs(
156 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,183 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,
157 const DualLevelQuantBatchMatmulInfo& inputParams)184 const DualLevelQuantBatchMatmulInfo& inputParams)
158{185{
159- OP_TILING_CHECK(186+ if (!IsInputsValid(context, inputParams)) {
160- inputParams.mSize == 0 || inputParams.nSize == 0 || inputParams.kSize == 0,187+ return false;
161- VECTOR_INNER_ERR_REPORT_TILIING(inputParams.opName, "The input M, N and K axes cannot be 0"), return false);188+ }
162 189 
163 auto& x1Level0ScaleShape = context->GetInputShape(X1_LEVEL0_SCALE_INDEX)->GetOriginShape();190 auto& x1Level0ScaleShape = context->GetInputShape(X1_LEVEL0_SCALE_INDEX)->GetOriginShape();
164 auto& x1Level1ScaleShape = context->GetInputShape(X1_LEVEL1_SCALE_INDEX)->GetOriginShape();191 auto& x1Level1ScaleShape = context->GetInputShape(X1_LEVEL1_SCALE_INDEX)->GetOriginShape();
@@ -167,41 +194,39 @@ bool CheckInputs(
167 OP_TILING_CHECK(194 OP_TILING_CHECK(
168 x1Level0ScaleShape.GetShapeSize() == 0 || x1Level1ScaleShape.GetShapeSize() == 0 ||195 x1Level0ScaleShape.GetShapeSize() == 0 || x1Level1ScaleShape.GetShapeSize() == 0 ||
169 x2Level0ScaleShape.GetShapeSize() == 0 || x2Level1ScaleShape.GetShapeSize() == 0,196 x2Level0ScaleShape.GetShapeSize() == 0 || x2Level1ScaleShape.GetShapeSize() == 0,
170- VECTOR_INNER_ERR_REPORT_TILIING(inputParams.opName, "Not yet support empty tensor"), return false);197+ VECTOR_INNER_ERR_REPORT_TILIING(context, "Not yet support empty tensor"), return false);
171- OP_TILING_CHECK(
172- inputParams.x2Format != ge::FORMAT_FRACTAL_NZ,
173- VECTOR_INNER_ERR_REPORT_TILIING(inputParams.opName, "Input x2 weight format shoulde be FRACTAL_NZ"),
174- return false);
175 198 
176 // check input shape199 // check input shape
177 uint64_t level1ScaleKSize = ops::CeilDiv<uint64_t>(inputParams.kSize, MICROSCALING_GROUP_SIZE * 2UL);200 uint64_t level1ScaleKSize = ops::CeilDiv<uint64_t>(inputParams.kSize, MICROSCALING_GROUP_SIZE * 2UL);
178 uint64_t level0ScaleKSize = ops::CeilDiv<uint64_t>(inputParams.kSize, DEFAULT_LEVEL0_GROUP_SIZE);201 uint64_t level0ScaleKSize = ops::CeilDiv<uint64_t>(inputParams.kSize, DEFAULT_LEVEL0_GROUP_SIZE);
179 202 
180- if (!CheckInputShape(203+ if (!CheckInputShape(context, "x1Level1Scale", x1Level1ScaleShape, {inputParams.mSize, level1ScaleKSize, 2UL})) {
181- inputParams.opName, "x1Level1Scale", x1Level1ScaleShape, {inputParams.mSize, level1ScaleKSize, 2UL})) {
182 return false;204 return false;
183 }205 }
184- if (!CheckInputShape(206+ if (!CheckInputShape(context, "x1Level0Scale", x1Level0ScaleShape, {inputParams.mSize, level0ScaleKSize})) {
185- inputParams.opName, "x1Level0Scale", x1Level0ScaleShape, {inputParams.mSize, level0ScaleKSize})) {
186 return false;207 return false;
187 }208 }
188- if (!CheckInputShape(209+ if (!CheckInputShape(context, "x2Level1Scale", x2Level1ScaleShape, {inputParams.nSize, level1ScaleKSize, 2UL})) {
189- inputParams.opName, "x2Level1Scale", x2Level1ScaleShape, {inputParams.nSize, level1ScaleKSize, 2UL})) {
190 return false;210 return false;
191 }211 }
192- if (!CheckInputShape(212+ if (!CheckInputShape(context, "x2Level0Scale", x2Level0ScaleShape, {level0ScaleKSize, inputParams.nSize})) {
193- inputParams.opName, "x2Level0Scale", x2Level0ScaleShape, {level0ScaleKSize, inputParams.nSize})) {
194 return false;213 return false;
195 }214 }
196 215 
197 if (inputParams.hasBias) {216 if (inputParams.hasBias) {
198 auto& biasShape = context->GetInputShape(BIAS_INDEX)->GetOriginShape();217 auto& biasShape = context->GetInputShape(BIAS_INDEX)->GetOriginShape();
199- if (!CheckInputShape(inputParams.opName, "bias", biasShape, {inputParams.nSize})) {218+ OP_TILING_CHECK(
219+ biasShape.GetShapeSize() == 0,
220+ VECTOR_INNER_ERR_REPORT_TILIING(
221+ context,
222+ "Optional input bias is not yet support empty tensor, "
223+ "if the meaning is that no bias is needed, please use a null pointer"),
224+ return false);
225+ if (!CheckInputShape(context, "bias", biasShape, {inputParams.nSize})) {
200 return false;226 return false;
201 }227 }
202 }228 }
203 return true;229 return true;
204}230}
205 231 
206-} // namespace checker232+} // Ops::NN::DLQBMMChecker
207-} // namespace optiling
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_checker.h+9-8
@@ -96,26 +96,27 @@ struct DualLevelQuantBatchMatmulInfo {
96 uint64_t libApiWorkSpaceSize = 0UL;96 uint64_t libApiWorkSpaceSize = 0UL;
97 QuantType level1QuantType = QuantType::MX;97 QuantType level1QuantType = QuantType::MX;
98 QuantType level0QuantType = QuantType::PER_GROUP;98 QuantType level0QuantType = QuantType::PER_GROUP;
99- const char* opName = nullptr;99+ ge::Format x1Format = ge::FORMAT_ND;
CANN-robot
CANN-robotCANN-robot1月31日

数据结构设计缺陷: 在结构体DualLevelQuantBatchMatmulInfo中,x1Format成员被硬编码为ge::FORMAT_ND,而x2Format被硬编码为ge::FORMAT_FRACTAL_NZ。这种硬编码设计存在以下问题:1. 限制了算子的通用性,无法支持其他输入格式;2. 与结构体中其他可配置参数(如transA、transB等)的设计风格不一致;3. 当算子需要支持其他格式时,必须修改头文件定义,违反了开闭原则。

问题类型: 数据结构设计缺陷 文件路径: matmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_checker.h 行号: 99 问题代码:

    ge::Format x1Format = ge::FORMAT_ND;
    ge::Format x2Format = ge::FORMAT_FRACTAL_NZ;

修改建议:

建议将格式参数改为从外部传入的可配置参数:1. 在结构体构造函数或初始化函数中添加格式参数;2. 或者通过算子属性获取格式信息;3. 至少应该将默认值定义为常量,便于后续修改。例如:
    ge::Format x1Format = DEFAULT_X1_FORMAT;
    ge::Format x2Format = DEFAULT_X2_FORMAT;
    static constexpr ge::Format DEFAULT_X1_FORMAT = ge::FORMAT_ND;
    static constexpr ge::Format DEFAULT_X2_FORMAT = ge::FORMAT_FRACTAL_NZ;

此评论由代码审查工具自动生成

likedislike
100 ge::Format x2Format = ge::FORMAT_FRACTAL_NZ;100 ge::Format x2Format = ge::FORMAT_FRACTAL_NZ;
101+ const char* opName = nullptr; // tiling计算逻辑中使用,不直接依赖GE数据结构
101};102};
103+} // namespace optiling
102 104 
103-namespace checker {105+namespace Ops::NN::DLQBMMChecker {
104 106 
105-ge::graphStatus CheckContext(gert::TilingContext* context, const char* opName, uint64_t tilingDataSize);107+ge::graphStatus CheckContext(gert::TilingContext* context, uint64_t tilingDataSize);
106 108 
107bool CheckAttrs(109bool CheckAttrs(
108 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,110 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,
109- const DualLevelQuantBatchMatmulInfo& inputParams);111+ const optiling::DualLevelQuantBatchMatmulInfo& inputParams);
110 112 
111bool CheckDtypes(113bool CheckDtypes(
112 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,114 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,
113- const DualLevelQuantBatchMatmulInfo& inputParams);115+ const optiling::DualLevelQuantBatchMatmulInfo& inputParams);
114 116 
115bool CheckInputs(117bool CheckInputs(
116 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,118 [[maybe_unused]] gert::TilingContext* context, [[maybe_unused]] NpuArch npuArch,
117- const DualLevelQuantBatchMatmulInfo& inputParams);119+ const optiling::DualLevelQuantBatchMatmulInfo& inputParams);
118 120 
119-} // namespace checker121+} // namespace Ops::NN::DLQBMMChecker
120-} // namespace optiling
121#endif // DUAL_LEVEL_QUANT_BATCH_MATMUL_CHECKER_H122#endif // DUAL_LEVEL_QUANT_BATCH_MATMUL_CHECKER_H
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_tiling_base.cpp+25-32
@@ -32,11 +32,12 @@ void LogDebugMatmulInfo(gert::TilingContext* context, const optiling::DualLevelQ
32 OP_LOGD(32 OP_LOGD(
33 context,33 context,
34 "input params: MKN[%lu, %lu, %lu], transA[%s], transB[%s], bias[%s], "34 "input params: MKN[%lu, %lu, %lu], transA[%s], transB[%s], bias[%s], "
35- "level0 group size[%lu], x2format[%s], x1Dtype[%s], x2Dtype[%s], biasDtype[%s], "35+ "level0 group size[%lu], x1Format[%s], x2Format[%s], x1Dtype[%s], x2Dtype[%s], biasDtype[%s], "
36 "x1Level0ScaleDtype[%s], x1Level1ScaleDtype[%s], x2Level0ScaleDtype[%s], "36 "x1Level0ScaleDtype[%s], x1Level1ScaleDtype[%s], x2Level0ScaleDtype[%s], "
37 "x2Level1ScaleDtype[%s], yDtype[%s], level1QuantType[%s], level0QuantType[%s]",37 "x2Level1ScaleDtype[%s], yDtype[%s], level1QuantType[%s], level0QuantType[%s]",
38 matmulInfo.mSize, matmulInfo.kSize, matmulInfo.nSize, matmulInfo.transA ? "true" : "false",38 matmulInfo.mSize, matmulInfo.kSize, matmulInfo.nSize, matmulInfo.transA ? "true" : "false",
39 matmulInfo.transB ? "true" : "false", matmulInfo.hasBias ? "true" : "false", matmulInfo.level0GroupSize,39 matmulInfo.transB ? "true" : "false", matmulInfo.hasBias ? "true" : "false", matmulInfo.level0GroupSize,
40+ ge::TypeUtils::FormatToAscendString(matmulInfo.x1Format).GetString(),
40 ge::TypeUtils::FormatToAscendString(matmulInfo.x2Format).GetString(),41 ge::TypeUtils::FormatToAscendString(matmulInfo.x2Format).GetString(),
41 ge::TypeUtils::DataTypeToAscendString(matmulInfo.x1Dtype).GetString(),42 ge::TypeUtils::DataTypeToAscendString(matmulInfo.x1Dtype).GetString(),
42 ge::TypeUtils::DataTypeToAscendString(matmulInfo.x2Dtype).GetString(),43 ge::TypeUtils::DataTypeToAscendString(matmulInfo.x2Dtype).GetString(),
@@ -61,13 +62,11 @@ constexpr T GetOrDefault(const T* ptr, T defaultValue)
61bool GetAttrs(DualLevelQuantBatchMatmulInfo& matmulInfo, const gert::TilingContext* context)62bool GetAttrs(DualLevelQuantBatchMatmulInfo& matmulInfo, const gert::TilingContext* context)
62{63{
63 auto attrs = context->GetAttrs();64 auto attrs = context->GetAttrs();
64- // const auto* yDtypeAttr = attrs->GetAttrPointer<int64_t>(ATTR_DTYPE_INDEX);
65 const bool* transposeX1Attr = attrs->GetAttrPointer<bool>(ATTR_TRANSPOSE_X1_INDEX);65 const bool* transposeX1Attr = attrs->GetAttrPointer<bool>(ATTR_TRANSPOSE_X1_INDEX);
66 const bool* transposeX2Attr = attrs->GetAttrPointer<bool>(ATTR_TRANSPOSE_X2_INDEX);66 const bool* transposeX2Attr = attrs->GetAttrPointer<bool>(ATTR_TRANSPOSE_X2_INDEX);
67 const int64_t* level0GroupSizeAttr = attrs->GetAttrPointer<int64_t>(ATTR_LEVEL0_GROUP_SIZE_INDEX);67 const int64_t* level0GroupSizeAttr = attrs->GetAttrPointer<int64_t>(ATTR_LEVEL0_GROUP_SIZE_INDEX);
68 const int64_t* level1GroupSizeAttr = attrs->GetAttrPointer<int64_t>(ATTR_LEVEL1_GROUP_SIZE_INDEX);68 const int64_t* level1GroupSizeAttr = attrs->GetAttrPointer<int64_t>(ATTR_LEVEL1_GROUP_SIZE_INDEX);
69 69 
70- // matmulInfo.yDtype = *yDtypeAttr; // TODO: yDtype从输入参数获取还是从output中获取?
71 matmulInfo.transA = GetOrDefault(transposeX1Attr, false);70 matmulInfo.transA = GetOrDefault(transposeX1Attr, false);
72 matmulInfo.transB = GetOrDefault(transposeX2Attr, true);71 matmulInfo.transB = GetOrDefault(transposeX2Attr, true);
73 matmulInfo.level0GroupSize = static_cast<uint64_t>(GetOrDefault(level0GroupSizeAttr, 512L));72 matmulInfo.level0GroupSize = static_cast<uint64_t>(GetOrDefault(level0GroupSizeAttr, 512L));
@@ -99,6 +98,7 @@ bool GetInputs(DualLevelQuantBatchMatmulInfo& matmulInfo, const gert::TilingCont
99 static constexpr size_t DIM_NUM = 2;98 static constexpr size_t DIM_NUM = 2;
100 auto& x1Shape = context->GetInputShape(X1_INDEX)->GetOriginShape();99 auto& x1Shape = context->GetInputShape(X1_INDEX)->GetOriginShape();
101 auto& x2Shape = context->GetInputShape(X2_INDEX)->GetOriginShape();100 auto& x2Shape = context->GetInputShape(X2_INDEX)->GetOriginShape();
101+ matmulInfo.x1Format = GetInputStorageFormat(context, X1_INDEX);
102 matmulInfo.x2Format = GetInputStorageFormat(context, X2_INDEX);102 matmulInfo.x2Format = GetInputStorageFormat(context, X2_INDEX);
103 103 
104 auto x1ShapeLen = x1Shape.GetDimNum();104 auto x1ShapeLen = x1Shape.GetDimNum();
@@ -106,7 +106,7 @@ bool GetInputs(DualLevelQuantBatchMatmulInfo& matmulInfo, const gert::TilingCont
106 OP_TILING_CHECK(106 OP_TILING_CHECK(
107 x1ShapeLen != DIM_NUM || x2ShapeLen != DIM_NUM,107 x1ShapeLen != DIM_NUM || x2ShapeLen != DIM_NUM,
108 VECTOR_INNER_ERR_REPORT_TILIING(108 VECTOR_INNER_ERR_REPORT_TILIING(
109- matmulInfo.opName,109+ context,
110 "input x1 dimension and x2 dimension should be 2, "110 "input x1 dimension and x2 dimension should be 2, "
111 "but x1 dimension: %zu, x2 dimension: %zu",111 "but x1 dimension: %zu, x2 dimension: %zu",
112 x1ShapeLen, x2ShapeLen),112 x1ShapeLen, x2ShapeLen),
@@ -115,7 +115,7 @@ bool GetInputs(DualLevelQuantBatchMatmulInfo& matmulInfo, const gert::TilingCont
115 // not yet support empty tensor for input115 // not yet support empty tensor for input
116 OP_TILING_CHECK(116 OP_TILING_CHECK(
117 x1Shape.GetShapeSize() == 0 || x2Shape.GetShapeSize() == 0,117 x1Shape.GetShapeSize() == 0 || x2Shape.GetShapeSize() == 0,
118- VECTOR_INNER_ERR_REPORT_TILIING(matmulInfo.opName, "Not yet support empty tensor"), return false);118+ VECTOR_INNER_ERR_REPORT_TILIING(context, "Not yet support empty tensor"), return false);
119 119 
120 auto x1Outer = x1Shape.GetDim(0);120 auto x1Outer = x1Shape.GetDim(0);
121 auto x1Inner = x1Shape.GetDim(1);121 auto x1Inner = x1Shape.GetDim(1);
@@ -128,7 +128,7 @@ bool GetInputs(DualLevelQuantBatchMatmulInfo& matmulInfo, const gert::TilingCont
128 OP_TILING_CHECK(128 OP_TILING_CHECK(
129 kX1 != kX2,129 kX1 != kX2,
130 VECTOR_INNER_ERR_REPORT_TILIING(130 VECTOR_INNER_ERR_REPORT_TILIING(
131- matmulInfo.opName,131+ context,
132 "Inputs dimension is not match, "132 "Inputs dimension is not match, "
133 "x1 kSize: %ld, x2 kSize: %ld",133 "x1 kSize: %ld, x2 kSize: %ld",
134 kX1, kX2),134 kX1, kX2),
@@ -144,13 +144,7 @@ DualLevelQuantBatchMatmulBaseTiling::DualLevelQuantBatchMatmulBaseTiling(gert::T
144bool DualLevelQuantBatchMatmulBaseTiling::InitMatmulInfo()144bool DualLevelQuantBatchMatmulBaseTiling::InitMatmulInfo()
145{145{
146 // 初始化参数信息结构体146 // 初始化参数信息结构体
147- try {147+ matmulInfo_.opName = context_->GetNodeName();
148- matmulInfoPtr_ = std::make_unique<DualLevelQuantBatchMatmulInfo>();
149- } catch (const std::bad_alloc& e) {
150- return false;
151- }
152- opName_ = context_->GetNodeName();
153- matmulInfoPtr_->opName = opName_;
154 return true;148 return true;
155}149}
156 150 
@@ -160,36 +154,36 @@ ge::graphStatus DualLevelQuantBatchMatmulBaseTiling::GetShapeAttrsInfo()
160 OP_LOGE_IF(!InitMatmulInfo(), ge::GRAPH_FAILED, context_->GetNodeName(), "failed to instantiate matmul info");154 OP_LOGE_IF(!InitMatmulInfo(), ge::GRAPH_FAILED, context_->GetNodeName(), "failed to instantiate matmul info");
161 155 
162 // 设置tiling相关的platform信息156 // 设置tiling相关的platform信息
163- OP_LOGE_IF(!SetPlatformInfoForTiling(), ge::GRAPH_FAILED, opName_, "Set PlatformInfoFortiling fail");157+ OP_LOGE_IF(!SetPlatformInfoForTiling(), ge::GRAPH_FAILED, context_, "Set PlatformInfoFortiling fail");
164 // 检查context必要参数是否存在,避免重复判断158 // 检查context必要参数是否存在,避免重复判断
165 OP_TILING_CHECK(159 OP_TILING_CHECK(
166- checker::CheckContext(context_, opName_, tilingDataSize_) != ge::GRAPH_SUCCESS,160+ Ops::NN::DLQBMMChecker::CheckContext(context_, tilingDataSize_) != ge::GRAPH_SUCCESS,
167- VECTOR_INNER_ERR_REPORT_TILIING(matmulInfoPtr_->opName, "Invalid context."), return ge::GRAPH_FAILED);161+ VECTOR_INNER_ERR_REPORT_TILIING(context_, "Invalid context."), return ge::GRAPH_FAILED);
168 162 
169 // 获取并检查参数信息163 // 获取并检查参数信息
170- OPS_LOG_I(opName_, "TilingContext: %s", Ops::NN::DebugTilingContext(context_).c_str());164+ OPS_LOG_I(context_, "TilingContext: %s", Ops::NN::DebugTilingContext(context_).c_str());
171 165 
172 OP_TILING_CHECK(166 OP_TILING_CHECK(
173- !GetAttrs(*matmulInfoPtr_, context_), VECTOR_INNER_ERR_REPORT_TILIING(opName_, "Failed to GetAttrs"),167+ !GetAttrs(matmulInfo_, context_), VECTOR_INNER_ERR_REPORT_TILIING(context_, "Failed to GetAttrs"),
174 return ge::GRAPH_FAILED);168 return ge::GRAPH_FAILED);
175 OP_TILING_CHECK(169 OP_TILING_CHECK(
176- !checker::CheckAttrs(context_, compileInfo_.npuArch, *matmulInfoPtr_),170+ !Ops::NN::DLQBMMChecker::CheckAttrs(context_, compileInfo_.npuArch, matmulInfo_),
177- VECTOR_INNER_ERR_REPORT_TILIING(opName_, "Failed to check attrs."), return ge::GRAPH_FAILED);171+ VECTOR_INNER_ERR_REPORT_TILIING(context_, "Failed to check attrs."), return ge::GRAPH_FAILED);
178 172 
179 OP_TILING_CHECK(173 OP_TILING_CHECK(
180- !GetDtype(*matmulInfoPtr_, context_), VECTOR_INNER_ERR_REPORT_TILIING(opName_, "Failed to GetDtype"),174+ !GetDtype(matmulInfo_, context_), VECTOR_INNER_ERR_REPORT_TILIING(context_, "Failed to GetDtype"),
181 return ge::GRAPH_FAILED);175 return ge::GRAPH_FAILED);
182 OP_TILING_CHECK(176 OP_TILING_CHECK(
183- !checker::CheckDtypes(context_, compileInfo_.npuArch, *matmulInfoPtr_),177+ !Ops::NN::DLQBMMChecker::CheckDtypes(context_, compileInfo_.npuArch, matmulInfo_),
184- VECTOR_INNER_ERR_REPORT_TILIING(opName_, "Failed to check dtypes."), return ge::GRAPH_FAILED);178+ VECTOR_INNER_ERR_REPORT_TILIING(context_, "Failed to check dtypes."), return ge::GRAPH_FAILED);
185 179 
186 OP_TILING_CHECK(180 OP_TILING_CHECK(
187- !GetInputs(*matmulInfoPtr_, context_), VECTOR_INNER_ERR_REPORT_TILIING(opName_, "Failed to GetInputs"),181+ !GetInputs(matmulInfo_, context_), VECTOR_INNER_ERR_REPORT_TILIING(context_, "Failed to GetInputs"),
188 return ge::GRAPH_FAILED);182 return ge::GRAPH_FAILED);
189 OP_TILING_CHECK(183 OP_TILING_CHECK(
190- !checker::CheckInputs(context_, compileInfo_.npuArch, *matmulInfoPtr_),184+ !Ops::NN::DLQBMMChecker::CheckInputs(context_, compileInfo_.npuArch, matmulInfo_),
191- VECTOR_INNER_ERR_REPORT_TILIING(opName_, "Failed to check inputs."), return ge::GRAPH_FAILED);185+ VECTOR_INNER_ERR_REPORT_TILIING(context_, "Failed to check inputs."), return ge::GRAPH_FAILED);
192- LogDebugMatmulInfo(context_, *matmulInfoPtr_);186+ LogDebugMatmulInfo(context_, matmulInfo_);
193 return ge::GRAPH_SUCCESS;187 return ge::GRAPH_SUCCESS;
194}188}
195 189 
@@ -228,21 +222,20 @@ bool DualLevelQuantBatchMatmulBaseTiling::SetPlatformInfoForTiling()
228 const auto* mmCompileInfo =222 const auto* mmCompileInfo =
229 reinterpret_cast<const DualLevelQuantBatchMatmulCompileInfo*>(context_->GetCompileInfo());223 reinterpret_cast<const DualLevelQuantBatchMatmulCompileInfo*>(context_->GetCompileInfo());
230 OP_TILING_CHECK(224 OP_TILING_CHECK(
231- mmCompileInfo == nullptr, CUBE_INNER_ERR_REPORT(matmulInfoPtr_->opName, "GetCompileInfo is null"),225+ mmCompileInfo == nullptr, CUBE_INNER_ERR_REPORT(context_, "GetCompileInfo is null"), return false);
232- return false);
233 compileInfo_ = *mmCompileInfo;226 compileInfo_ = *mmCompileInfo;
234 }227 }
235 228 
236- matmulInfoPtr_->libApiWorkSpaceSize = compileInfo_.workspaceNum;229+ matmulInfo_.libApiWorkSpaceSize = compileInfo_.workspaceNum;
237 230 
238 OP_LOGE_IF(231 OP_LOGE_IF(
239 compileInfo_.aivNum <= 0 || compileInfo_.aicNum == 0 || compileInfo_.l1Size == 0UL ||232 compileInfo_.aivNum <= 0 || compileInfo_.aicNum == 0 || compileInfo_.l1Size == 0UL ||
240 compileInfo_.l0cSize == 0UL,233 compileInfo_.l0cSize == 0UL,
241- false, opName_, "coreNum/L1Size/L0cSize should not be 0. aicNum: %u, aivNum: %u, L1Size: %lu, L0cSize: %lu",234+ false, context_, "coreNum/L1Size/L0cSize should not be 0. aicNum: %u, aivNum: %u, L1Size: %lu, L0cSize: %lu",
242 compileInfo_.aicNum, compileInfo_.aivNum, compileInfo_.l1Size, compileInfo_.l0cSize);235 compileInfo_.aicNum, compileInfo_.aivNum, compileInfo_.l1Size, compileInfo_.l0cSize);
243 236 
244 OP_LOGD(237 OP_LOGD(
245- opName_,238+ context_,
246 "get platform: aivNum(%u) aicNum(%u) ubSize(%lu) l1Size(%lu) "239 "get platform: aivNum(%u) aicNum(%u) ubSize(%lu) l1Size(%lu) "
247 "l0cSize(%lu) l0aSize(%lu) l0bSize(%lu)",240 "l0cSize(%lu) l0aSize(%lu) l0bSize(%lu)",
248 compileInfo_.aivNum, compileInfo_.aicNum, compileInfo_.ubSize, compileInfo_.l1Size, compileInfo_.l0cSize,241 compileInfo_.aivNum, compileInfo_.aicNum, compileInfo_.ubSize, compileInfo_.l1Size, compileInfo_.l0cSize,
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_tiling_base.h+1-3
@@ -56,10 +56,8 @@ protected:
56 56 
57 bool SetPlatformInfoForTiling();57 bool SetPlatformInfoForTiling();
58 58 
59- // 算子名称
60- const char* opName_;
61 // 输入信息59 // 输入信息
62- std::unique_ptr<DualLevelQuantBatchMatmulInfo> matmulInfoPtr_;60+ DualLevelQuantBatchMatmulInfo matmulInfo_;
63 // 平台相关信息61 // 平台相关信息
64 DualLevelQuantBatchMatmulCompileInfo compileInfo_;62 DualLevelQuantBatchMatmulCompileInfo compileInfo_;
65 bool isCompileInfoInit = false;63 bool isCompileInfoInit = false;
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_tiling_registry.cpp+5-4
@@ -21,14 +21,16 @@
21#include "common/inc/error_util.h"21#include "common/inc/error_util.h"
22 22 
23using Ops::NN::TilingPrepareForOpCache;23using Ops::NN::TilingPrepareForOpCache;
24-using Ops::NN::Optiling::TilingRegistry;24+using Ops::NN::Optiling::TilingRegistryNew;
25 25 
26namespace optiling {26namespace optiling {
27using dual_level_quant_batch_matmul::DualLevelQuantBatchMatmulTilingASW;27using dual_level_quant_batch_matmul::DualLevelQuantBatchMatmulTilingASW;
28 28 
29// tiling模板查找的key29// tiling模板查找的key
30constexpr int32_t ASW_CUBE_BOUND_TEMPLATE = 0;30constexpr int32_t ASW_CUBE_BOUND_TEMPLATE = 0;
31-REGISTER_TILING_TEMPLATE("DualLevelQuantBatchMatmul", DualLevelQuantBatchMatmulTilingASW, ASW_CUBE_BOUND_TEMPLATE);31+REGISTER_TILING_TEMPLATE_WITH_SOCVERSION(
32+ DualLevelQuantBatchMatmul, DualLevelQuantBatchMatmulTilingASW,
33+ static_cast<int>(platform_ascendc::SocVersion::ASCEND950), ASW_CUBE_BOUND_TEMPLATE);
32 34 
33static ge::graphStatus DualLevelQuantBatchMatmulTilingFunc(gert::TilingContext* context)35static ge::graphStatus DualLevelQuantBatchMatmulTilingFunc(gert::TilingContext* context)
34{36{
@@ -47,8 +49,7 @@ static ge::graphStatus DualLevelQuantBatchMatmulTilingFunc(gert::TilingContext*
47 npuArch = compileInfoPtr->npuArch;49 npuArch = compileInfoPtr->npuArch;
48 }50 }
49 OP_LOGE_IF(npuArch != NpuArch::DAV_3510, ge::GRAPH_FAILED, context->GetNodeName(), "Platform not supported");51 OP_LOGE_IF(npuArch != NpuArch::DAV_3510, ge::GRAPH_FAILED, context->GetNodeName(), "Platform not supported");
50- std::vector<int32_t> registerList = {ASW_CUBE_BOUND_TEMPLATE};52+ return TilingRegistryNew::GetInstance().DoTilingImpl(context);
51- return TilingRegistry::GetInstance().DoTilingImpl(context, registerList);
52}53}
53 54 
54static ge::graphStatus TilingParseForDualLevelQuantBatchMatmul(gert::TilingParseContext* context)55static ge::graphStatus TilingParseForDualLevelQuantBatchMatmul(gert::TilingParseContext* context)
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_tiling_tool.cpp+0-60
@@ -21,66 +21,6 @@ constexpr int64_t B16_BITS = 16;
21constexpr int64_t B8_BITS = 8;21constexpr int64_t B8_BITS = 8;
22constexpr int64_t B4_BITS = 4;22constexpr int64_t B4_BITS = 4;
23 23 
24-uint64_t GetBlockAlignSizeByDataType(ge::DataType dtype)
25-{
26- if (dtype == ge::DT_INT4 || dtype == ge::DT_FLOAT4_E2M1 || dtype == ge::DT_FLOAT4_E1M2) {
27- return ONE_BLK_SIZE + ONE_BLK_SIZE;
28- } else {
29- return ONE_BLK_SIZE / static_cast<uint32_t>(ge::GetSizeByDataType(dtype));
30- }
31-}
32- 
33-uint64_t GetShapeSizeWithDataType(uint64_t shapeSize, ge::DataType dtype)
34-{
35- if (dtype == ge::DT_INT4) {
36- return (shapeSize + 1) >> 1;
37- } else {
38- return shapeSize * static_cast<uint64_t>(ge::GetSizeByDataType(dtype));
39- }
40-}
41- 
42-bool CheckOptionalInputByShape(const gert::StorageShape* storageShape)
43-{
44- return storageShape != nullptr && storageShape->GetStorageShape().GetShapeSize() != 0;
45-}
46- 
47-int64_t GetDtypeBits(ge::DataType dtype)
48-{
49- if (dtype == ge::DT_INT4 || dtype == ge::DT_FLOAT4_E2M1 || dtype == ge::DT_FLOAT4_E1M2) {
50- return B4_BITS;
51- } else if (
52- dtype == ge::DT_INT8 || dtype == ge::DT_HIFLOAT8 || dtype == ge::DT_FLOAT8_E5M2 ||
53- dtype == ge::DT_FLOAT8_E4M3FN) {
54- return B8_BITS;
55- } else if (dtype == ge::DT_FLOAT16 || dtype == ge::DT_BF16) {
56- return B16_BITS;
57- } else if (dtype == ge::DT_FLOAT) {
58- return B32_BITS;
59- } else {
60- return 0;
61- }
62-}
63- 
64-const std::unordered_map<ge::DataType, matmul_tiling::DataType> DTYPE_MAP = {
65- {ge::DT_FLOAT16, matmul_tiling::DataType::DT_FLOAT16},
66- {ge::DT_FLOAT, matmul_tiling::DataType::DT_FLOAT},
67- {ge::DT_INT8, matmul_tiling::DataType::DT_INT8},
68- {ge::DT_BF16, matmul_tiling::DataType::DT_BF16},
69- {ge::DT_INT4, matmul_tiling::DataType::DT_INT4},
70- {ge::DT_FLOAT8_E8M0, matmul_tiling::DataType::DT_FLOAT8_E8M0},
71- {ge::DT_FLOAT8_E5M2, matmul_tiling::DataType::DT_FLOAT8_E5M2},
72- {ge::DT_FLOAT8_E4M3FN, matmul_tiling::DataType::DT_FLOAT8_E4M3FN},
73- {ge::DT_FLOAT4_E2M1, matmul_tiling::DataType::DT_FLOAT4_E2M1},
74- {ge::DT_FLOAT4_E1M2, matmul_tiling::DataType::DT_FLOAT4_E1M2},
75-};
76- 
77-matmul_tiling::DataType GetMatmulTilingDtype(ge::DataType dtype)
78-{
79- auto it = DTYPE_MAP.find(dtype);
80- // impossible to get runtime error
81- return it != DTYPE_MAP.end() ? it->second : matmul_tiling::DataType::DT_FLOAT16;
82-}
83- 
84ge::Format GetInputStorageFormat(const gert::TilingContext* context, size_t id)24ge::Format GetInputStorageFormat(const gert::TilingContext* context, size_t id)
85{25{
86 auto desc = context->GetInputDesc(id);26 auto desc = context->GetInputDesc(id);
Mmatmul/dual_level_quant_batch_matmul/op_host/op_tiling/dual_level_quant_batch_matmul_tiling_tool.h+19-9
@@ -24,7 +24,6 @@
24 24 
25using AscendC::BLOCK_CUBE;25using AscendC::BLOCK_CUBE;
26using AscendC::ONE_BLK_SIZE;26using AscendC::ONE_BLK_SIZE;
27-using matmul_tiling::MatrixTraverse;
28 27 
29namespace optiling::tool {28namespace optiling::tool {
30 29 
@@ -41,16 +40,27 @@ T2 CalcTailSize(T1 num1, T2 num2)
41 return mod != 0 ? static_cast<T2>(mod) : num2;40 return mod != 0 ? static_cast<T2>(mod) : num2;
42}41}
43 42 
44-int64_t GetDtypeBits(ge::DataType dtype);43+template <typename T>
44+T GetShapeWithDataType(T size, ge::DataType dtype)
45+{
46+ if (dtype == ge::DT_INT4 || dtype == ge::DT_FLOAT4_E2M1 || dtype == ge::DT_FLOAT4_E1M2) {
47+ return size + size;
48+ } else {
49+ return size / static_cast<T>(ge::GetSizeByDataType(dtype));
50+ }
51+}
45 52 
46-uint64_t GetBlockAlignSizeByDataType(ge::DataType dtype);53+template <typename T>
47- 54+T GetSizeWithDataType(T shape, ge::DataType dtype)
48-uint64_t GetShapeSizeWithDataType(uint64_t shapeSize, ge::DataType dtype);55+{
49- 56+ if (dtype == ge::DT_FLOAT4_E2M1 || dtype == ge::DT_FLOAT4_E1M2 || dtype == ge::DT_INT4) {
50-bool CheckOptionalInputByShape(const gert::StorageShape* storageShape);57+ return (shape + 1) >> 1;
51- 58+ } else {
52-matmul_tiling::DataType GetMatmulTilingDtype(ge::DataType dtype);59+ return shape * static_cast<T>(ge::GetSizeByDataType(dtype));
60+ }
61+}
53 62 
54ge::Format GetInputStorageFormat(const gert::TilingContext* context, size_t id);63ge::Format GetInputStorageFormat(const gert::TilingContext* context, size_t id);
64+ 
55} // namespace optiling::tool65} // namespace optiling::tool
56#endif // DUAL_LEVEL_QUANT_BATCH_MATMUL_TOOL_H66#endif // DUAL_LEVEL_QUANT_BATCH_MATMUL_TOOL_H
Mmatmul/dual_level_quant_batch_matmul/op_kernel/dual_level_quant_batch_matmul_tiling_data.h+4-4
@@ -23,10 +23,10 @@
23 23 
24enum class L2CacheMode : std::uint32_t24enum class L2CacheMode : std::uint32_t
25{25{
26- L2_CACHE_DEFAULT = 0x00,26+ L2_CACHE_DEFAULT = 0,
27- A_L2_CACHE_DISABLE = 0x01,27+ A_L2_CACHE_DISABLE = 1,
28- B_L2_CACHE_DISABLE = 0x02,28+ B_L2_CACHE_DISABLE = 2,
29- ALL_L2_CACHE_DISABLE = 0x03,29+ ALL_L2_CACHE_DISABLE = 3,
30};30};
31 31 
32// tiling data注意8B对齐,尽量手动添加对齐的保留字段32// tiling data注意8B对齐,尽量手动添加对齐的保留字段
Mmatmul/dual_level_quant_batch_matmul/tests/ut/op_host/test_dual_level_quant_batch_matmul_tiling.cpp+3-2文件内容审核中,请稍后刷新重试