已合并
sort/sort_with_index/top_k_v2/kth_value err msg整改 #3943
wuxiyuan创建于 7月9日
sort/sort_with_index/top_k_v2/kth_value err msg整改 #3943
已合并
共 12 个文件变更+1342-1083
| @@ -12,6 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | 18 | ||
| @@ -42,7 +43,7 @@ static ge::graphStatus CheckKthValueDtypes(gert::TilingContext* context, ge::Dat | |||
| 42 | OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON( | 43 | OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON( |
| 43 | context->GetNodeName(), "x, values", | 44 | context->GetNodeName(), "x, values", |
| 44 | (Ops::Base::ToString(dataType) + ", " + Ops::Base::ToString(valuesDesc->GetDataType())).c_str(), | 45 | (Ops::Base::ToString(dataType) + ", " + Ops::Base::ToString(valuesDesc->GetDataType())).c_str(), |
| 45 | - "The dtype of input x should be the same as output values"), | 46 | + "The dtypes of x and values must be the same."), |
| 46 | return ge::GRAPH_FAILED); | 47 | return ge::GRAPH_FAILED); |
| 47 | OP_CHECK_IF(indicesDesc->GetDataType() != ge::DT_INT64, | 48 | OP_CHECK_IF(indicesDesc->GetDataType() != ge::DT_INT64, |
| 48 | OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "indices", | 49 | OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "indices", |
| @@ -59,13 +60,16 @@ static ge::graphStatus ValidateKthValueShapes(gert::TilingContext* context, cons | |||
| 59 | OP_CHECK_NULL_WITH_CONTEXT(context, valuesShapePtr); | 60 | OP_CHECK_NULL_WITH_CONTEXT(context, valuesShapePtr); |
| 60 | auto indicesShapePtr = context->GetOutputShape(1); | 61 | auto indicesShapePtr = context->GetOutputShape(1); |
| 61 | OP_CHECK_NULL_WITH_CONTEXT(context, indicesShapePtr); | 62 | OP_CHECK_NULL_WITH_CONTEXT(context, indicesShapePtr); |
| 62 | - OP_CHECK_IF(xShape->GetStorageShape().GetShapeSize() == 0 || | 63 | + OP_CHECK_IF( |
| 63 | - valuesShapePtr->GetStorageShape().GetShapeSize() == 0 || | 64 | + xShape->GetStorageShape().GetShapeSize() == 0 || valuesShapePtr->GetStorageShape().GetShapeSize() == 0 || |
| 64 | - indicesShapePtr->GetStorageShape().GetShapeSize() == 0, | 65 | + indicesShapePtr->GetStorageShape().GetShapeSize() == 0, |
| 65 | - OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( | 66 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "x, values, indices", |
| 66 | - context->GetNodeName(), "x, values, indices", "0", | 67 | + (std::to_string(xShape->GetStorageShape().GetShapeSize()) + ", " + |
| 67 | - "The shape size of input x, output values and output indices should be positive"), | 68 | + std::to_string(valuesShapePtr->GetStorageShape().GetShapeSize()) + ", " + |
| 68 | - return ge::GRAPH_FAILED); | 69 | + std::to_string(indicesShapePtr->GetStorageShape().GetShapeSize())) |
| 70 | + .c_str(), | ||
| 71 | + "The values of shape sizes of x, values, and indices must be positive."), | ||
| 72 | + return ge::GRAPH_FAILED); | ||
| 69 | xStorageShape = &xShape->GetStorageShape(); | 73 | xStorageShape = &xShape->GetStorageShape(); |
| 70 | return ge::GRAPH_SUCCESS; | 74 | return ge::GRAPH_SUCCESS; |
| 71 | } | 75 | } |
| @@ -80,7 +84,7 @@ static ge::graphStatus ParseKthValueShapeInfo(gert::TilingContext* context, cons | |||
| 80 | info.rank = xStorageShape->GetDimNum(); | 84 | info.rank = xStorageShape->GetDimNum(); |
| 81 | if (info.rank <= 0) { | 85 | if (info.rank <= 0) { |
| 82 | OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context->GetNodeName(), "x", (std::to_string(info.rank) + "D").c_str(), | 86 | OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context->GetNodeName(), "x", (std::to_string(info.rank) + "D").c_str(), |
| 83 | - "The shape dim of input x should be greater than 0"); | 87 | + "The shape dim of x must be greater than 0."); |
| 84 | return ge::GRAPH_FAILED; | 88 | return ge::GRAPH_FAILED; |
| 85 | } | 89 | } |
| 86 | int64_t originSortAxis = (dimAttr == nullptr) ? -1 : *dimAttr; | 90 | int64_t originSortAxis = (dimAttr == nullptr) ? -1 : *dimAttr; |
| @@ -94,7 +98,7 @@ static ge::graphStatus ParseKthValueShapeInfo(gert::TilingContext* context, cons | |||
| 94 | info.lastAxis = xStorageShape->GetDim(info.sortAxis); | 98 | info.lastAxis = xStorageShape->GetDim(info.sortAxis); |
| 95 | if (info.lastAxis <= 0) { | 99 | if (info.lastAxis <= 0) { |
| 96 | OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "x", std::to_string(info.lastAxis).c_str(), | 100 | OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "x", std::to_string(info.lastAxis).c_str(), |
| 97 | - "The sort axis of input x should be greater than 0"); | 101 | + "The value of sort axis of x must be greater than 0."); |
| 98 | return ge::GRAPH_FAILED; | 102 | return ge::GRAPH_FAILED; |
| 99 | } | 103 | } |
| 100 | if (*kAttr < 1 || *kAttr > info.lastAxis) { | 104 | if (*kAttr < 1 || *kAttr > info.lastAxis) { |
| @@ -116,8 +120,11 @@ static ge::graphStatus ComputeKthValueUbInfo(gert::TilingContext* context, | |||
| 116 | { | 120 | { |
| 117 | uint64_t ubSize64 = 0; | 121 | uint64_t ubSize64 = 0; |
| 118 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize64); | 122 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize64); |
| 119 | - OP_CHECK_IF((ubSize64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())), | 123 | + OP_CHECK_IF( |
| 120 | - OP_LOGE(context->GetNodeName(), "kth_value UB size exceeds uint32 limit."), return ge::GRAPH_FAILED); | 124 | + (ubSize64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())), |
| 125 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ubSize", std::to_string(ubSize64).c_str(), | ||
| 126 | + "The value of ubSize must be less than or equal to uint32 max."), | ||
| 127 | + return ge::GRAPH_FAILED); | ||
| 121 | info.ubSize = static_cast<uint32_t>(ubSize64); | 128 | info.ubSize = static_cast<uint32_t>(ubSize64); |
| 122 | int64_t int32Max = static_cast<int64_t>(std::numeric_limits<int32_t>::max()); | 129 | int64_t int32Max = static_cast<int64_t>(std::numeric_limits<int32_t>::max()); |
| 123 | info.isInt32 = static_cast<uint32_t>(info.lastAxis <= int32Max); | 130 | info.isInt32 = static_cast<uint32_t>(info.lastAxis <= int32Max); |
| @@ -253,9 +260,11 @@ static bool ComputeKthNonLastSmallAxisPeakUb(const SortKthTileInfo& info, uint32 | |||
| 253 | static ge::graphStatus SetRadixOneCoreTiling(gert::TilingContext* context, const SortKthTileInfo& info, | 260 | static ge::graphStatus SetRadixOneCoreTiling(gert::TilingContext* context, const SortKthTileInfo& info, |
| 254 | KthValueTilingData* tilingData) | 261 | KthValueTilingData* tilingData) |
| 255 | { | 262 | { |
| 256 | - OP_CHECK_IF((info.oneBufferQueSize >= info.ubSize), | 263 | + OP_CHECK_IF( |
| 257 | - OP_LOGE(context->GetNodeName(), "kth_value radix one-core UB is insufficient."), | 264 | + (info.oneBufferQueSize >= info.ubSize), |
| 258 | - return ge::GRAPH_FAILED); | 265 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ubSize", std::to_string(info.ubSize).c_str(), |
| 266 | + "The value of ubSize must be greater than oneBufferQueSize."), | ||
| 267 | + return ge::GRAPH_FAILED); | ||
| 259 | tilingData->numTileDataSize = static_cast<uint32_t>(info.lastAxis); | 268 | tilingData->numTileDataSize = static_cast<uint32_t>(info.lastAxis); |
| 260 | tilingData->lastDimTileNum = 1; | 269 | tilingData->lastDimTileNum = 1; |
| 261 | tilingData->lastDimNeedCore = 1; | 270 | tilingData->lastDimNeedCore = 1; |
| @@ -266,10 +275,14 @@ static ge::graphStatus SetRadixOneCoreTiling(gert::TilingContext* context, const | |||
| 266 | tilingData->keyParams4 = info.outputRowsPerLoop; | 275 | tilingData->keyParams4 = info.outputRowsPerLoop; |
| 267 | tilingData->keyParams5 = 0; | 276 | tilingData->keyParams5 = 0; |
| 268 | OP_CHECK_IF(!QuerySortTmpSizeRadix(info.dataType, static_cast<uint32_t>(info.lastAxis), tilingData->tmpUbSize), | 277 | OP_CHECK_IF(!QuerySortTmpSizeRadix(info.dataType, static_cast<uint32_t>(info.lastAxis), tilingData->tmpUbSize), |
| 269 | - OP_LOGE(context->GetNodeName(), "kth_value get radix sort tmp size failed."), return ge::GRAPH_FAILED); | 278 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "QuerySortTmpSizeRadix", "false", |
| 279 | + "The value of QuerySortTmpSizeRadix must be true."), | ||
| 280 | + return ge::GRAPH_FAILED); | ||
| 270 | uint64_t remainUb = (info.ubSize - info.oneBufferQueSize) / info.blockUbSize * info.blockUbSize; | 281 | uint64_t remainUb = (info.ubSize - info.oneBufferQueSize) / info.blockUbSize * info.blockUbSize; |
| 271 | OP_CHECK_IF((static_cast<uint64_t>(tilingData->tmpUbSize) > remainUb), | 282 | OP_CHECK_IF((static_cast<uint64_t>(tilingData->tmpUbSize) > remainUb), |
| 272 | - OP_LOGE(context->GetNodeName(), "kth_value radix one-core tmp UB is insufficient."), | 283 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "tmpUbSize", |
| 284 | + std::to_string(tilingData->tmpUbSize).c_str(), | ||
| 285 | + "The value of tmpUbSize must be less than or equal to remainUb."), | ||
| 273 | return ge::GRAPH_FAILED); | 286 | return ge::GRAPH_FAILED); |
| 274 | uint64_t doubleBufferRemainUb = info.ubSize > info.oneBufferQueSize * 2 ? | 287 | uint64_t doubleBufferRemainUb = info.ubSize > info.oneBufferQueSize * 2 ? |
| 275 | (info.ubSize - info.oneBufferQueSize * 2) / info.blockUbSize * | 288 | (info.ubSize - info.oneBufferQueSize * 2) / info.blockUbSize * |
| @@ -300,17 +313,21 @@ static bool ComputeKthValueRadixMoreCoreWorkspace(int64_t axisLen, uint32_t dtyp | |||
| 300 | 313 | ||
| 301 | static ge::graphStatus SetRadixMoreCoreTiling(gert::TilingContext* context, SortKthTileInfo& info, uint32_t& blockDim) | 314 | static ge::graphStatus SetRadixMoreCoreTiling(gert::TilingContext* context, SortKthTileInfo& info, uint32_t& blockDim) |
| 302 | { | 315 | { |
| 303 | - OP_CHECK_IF(!FillRadixMoreCoreInfo(info), OP_LOGE(context->GetNodeName(), "kth_value radix more-core plan failed."), | 316 | + OP_CHECK_IF(!FillRadixMoreCoreInfo(info), |
| 317 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "FillRadixMoreCoreInfo", "false", | ||
| 318 | + "The value of FillRadixMoreCoreInfo must be true."), | ||
| 304 | return ge::GRAPH_FAILED); | 319 | return ge::GRAPH_FAILED); |
| 305 | blockDim = info.coreNumNeed; | 320 | blockDim = info.coreNumNeed; |
| 306 | uint32_t indexSize = info.isInt32 != 0 ? static_cast<uint32_t>(sizeof(int32_t)) : | 321 | uint32_t indexSize = info.isInt32 != 0 ? static_cast<uint32_t>(sizeof(int32_t)) : |
| 307 | static_cast<uint32_t>(sizeof(int64_t)); | 322 | static_cast<uint32_t>(sizeof(int64_t)); |
| 308 | uint64_t totalWorkspace = 0; | 323 | uint64_t totalWorkspace = 0; |
| 309 | - OP_CHECK_IF(!ComputeKthValueRadixMoreCoreWorkspace(info.lastAxis, info.dtypeSize, indexSize, | 324 | + OP_CHECK_IF( |
| 310 | - info.unsortedDimParallel, info.blockUbSize, | 325 | + !ComputeKthValueRadixMoreCoreWorkspace(info.lastAxis, info.dtypeSize, indexSize, info.unsortedDimParallel, |
| 311 | - static_cast<uint64_t>(info.workspaceSize), totalWorkspace), | 326 | + info.blockUbSize, static_cast<uint64_t>(info.workspaceSize), |
| 312 | - OP_LOGE(context->GetNodeName(), "kth_value radix more-core workspace overflow."), | 327 | + totalWorkspace), |
| 313 | - return ge::GRAPH_FAILED); | 328 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeKthValueRadixMoreCoreWorkspace", "false", |
| 329 | + "The value of ComputeKthValueRadixMoreCoreWorkspace must be true."), | ||
| 330 | + return ge::GRAPH_FAILED); | ||
| 314 | size_t* userWorkspaceSize = context->GetWorkspaceSizes(1); | 331 | size_t* userWorkspaceSize = context->GetWorkspaceSizes(1); |
| 315 | OP_CHECK_NULL_WITH_CONTEXT(context, userWorkspaceSize); | 332 | OP_CHECK_NULL_WITH_CONTEXT(context, userWorkspaceSize); |
| 316 | userWorkspaceSize[0] = static_cast<size_t>(totalWorkspace); | 333 | userWorkspaceSize[0] = static_cast<size_t>(totalWorkspace); |
| @@ -322,7 +339,9 @@ static ge::graphStatus SetKthValueMergeSortTiling(gert::TilingContext* context, | |||
| 322 | uint32_t& blockDim, uint64_t& schId) | 339 | uint32_t& blockDim, uint64_t& schId) |
| 323 | { | 340 | { |
| 324 | OP_CHECK_IF(!ComputeMergeSortTiling(context, info, static_cast<uint32_t>(sizeof(uint32_t))), | 341 | OP_CHECK_IF(!ComputeMergeSortTiling(context, info, static_cast<uint32_t>(sizeof(uint32_t))), |
| 325 | - OP_LOGE(context->GetNodeName(), "kth_value merge sort tiling failed."), return ge::GRAPH_FAILED); | 342 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeMergeSortTiling", "false", |
| 343 | + "The value of ComputeMergeSortTiling must be true."), | ||
| 344 | + return ge::GRAPH_FAILED); | ||
| 326 | blockDim = info.coreNumNeed; | 345 | blockDim = info.coreNumNeed; |
| 327 | schId = info.lastAxis <= SORT32_SMALL_AXIS_THRESHOLD ? KTH_VALUE_SCHID_SORT32_SMALL_AXIS : | 346 | schId = info.lastAxis <= SORT32_SMALL_AXIS_THRESHOLD ? KTH_VALUE_SCHID_SORT32_SMALL_AXIS : |
| 328 | KTH_VALUE_SCHID_MERGE_SORT; | 347 | KTH_VALUE_SCHID_MERGE_SORT; |
| @@ -337,7 +356,9 @@ static ge::graphStatus SetMergeMoreCoreTiling(gert::TilingContext* context, Sort | |||
| 337 | MERGE_SORT_LIST_NUM * sizeof(uint32_t) + | 356 | MERGE_SORT_LIST_NUM * sizeof(uint32_t) + |
| 338 | MERGE_SORT_LIST_NUM * sizeof(int64_t) + MERGE_SORT_LIST_NUM * sizeof(float); | 357 | MERGE_SORT_LIST_NUM * sizeof(int64_t) + MERGE_SORT_LIST_NUM * sizeof(float); |
| 339 | OP_CHECK_IF(!ComputeMergeMoreCoreTiling(context, info, mergeBytesPerElem), | 358 | OP_CHECK_IF(!ComputeMergeMoreCoreTiling(context, info, mergeBytesPerElem), |
| 340 | - OP_LOGE(context->GetNodeName(), "kth_value merge more-core plan failed."), return ge::GRAPH_FAILED); | 359 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeMergeMoreCoreTiling", "false", |
| 360 | + "The value of ComputeMergeMoreCoreTiling must be true."), | ||
| 361 | + return ge::GRAPH_FAILED); | ||
| 341 | blockDim = info.coreNumNeed; | 362 | blockDim = info.coreNumNeed; |
| 342 | OP_LOGI("KthValueMergeMoreCoreTiling", "maxDealingNum: %u", info.keyParams0); | 363 | OP_LOGI("KthValueMergeMoreCoreTiling", "maxDealingNum: %u", info.keyParams0); |
| 343 | return ge::GRAPH_SUCCESS; | 364 | return ge::GRAPH_SUCCESS; |
| @@ -346,7 +367,9 @@ static ge::graphStatus SetMergeMoreCoreTiling(gert::TilingContext* context, Sort | |||
| 346 | static ge::graphStatus SetMergeIntraCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) | 367 | static ge::graphStatus SetMergeIntraCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) |
| 347 | { | 368 | { |
| 348 | OP_CHECK_IF(!ComputeMergeIntraCoreTiling(context, info), | 369 | OP_CHECK_IF(!ComputeMergeIntraCoreTiling(context, info), |
| 349 | - OP_LOGE(context->GetNodeName(), "kth_value merge intra-core plan failed."), return ge::GRAPH_FAILED); | 370 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeMergeIntraCoreTiling", "false", |
| 371 | + "The value of ComputeMergeIntraCoreTiling must be true."), | ||
| 372 | + return ge::GRAPH_FAILED); | ||
| 350 | OP_LOGI("KthValueMergeIntraCoreTiling", | 373 | OP_LOGI("KthValueMergeIntraCoreTiling", |
| 351 | "B %ld, N %ld, batchPerCore %u, actualCoreNum %u, blockSortSize %u, extractChunkSize %u, " | 374 | "B %ld, N %ld, batchPerCore %u, actualCoreNum %u, blockSortSize %u, extractChunkSize %u, " |
| 352 | "blocksPerRow %u, alignNum %u, ubSize %u", | 375 | "blocksPerRow %u, alignNum %u, ubSize %u", |
| @@ -470,23 +493,29 @@ static ge::graphStatus SetAxisOneCopyTiling(gert::TilingContext* context, SortKt | |||
| 470 | uint64_t bytesPerElem = static_cast<uint64_t>(2) * | 493 | uint64_t bytesPerElem = static_cast<uint64_t>(2) * |
| 471 | (static_cast<uint64_t>(info.dtypeSize) + static_cast<uint64_t>(sizeof(int64_t))); | 494 | (static_cast<uint64_t>(info.dtypeSize) + static_cast<uint64_t>(sizeof(int64_t))); |
| 472 | if (bytesPerElem == 0) { | 495 | if (bytesPerElem == 0) { |
| 473 | - OP_LOGE(context->GetNodeName(), "bytesPerElem is 0, invalid dtype configuration"); | 496 | + OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(context->GetNodeName(), "x", Ops::Base::ToString(info.dataType).c_str(), |
| 497 | + "The dtype size of x must be greater than 0."); | ||
| 474 | return ge::GRAPH_FAILED; | 498 | return ge::GRAPH_FAILED; |
| 475 | } | 499 | } |
| 476 | uint64_t copyElemsPerLoop64 = static_cast<uint64_t>(info.ubSize) / bytesPerElem; | 500 | uint64_t copyElemsPerLoop64 = static_cast<uint64_t>(info.ubSize) / bytesPerElem; |
| 477 | if (copyElemsPerLoop64 == 0) { | 501 | if (copyElemsPerLoop64 == 0) { |
| 478 | - OP_LOGE(context->GetNodeName(), "copyElemsPerLoop is 0, ub is too small for axis-one copy"); | 502 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "copyElemsPerLoop", |
| 503 | + std::to_string(copyElemsPerLoop64).c_str(), | ||
| 504 | + "The value of copyElemsPerLoop must be greater than 0."); | ||
| 479 | return ge::GRAPH_FAILED; | 505 | return ge::GRAPH_FAILED; |
| 480 | } | 506 | } |
| 481 | if (copyElemsPerLoop64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 507 | if (copyElemsPerLoop64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 482 | - OP_LOGE(context->GetNodeName(), "copyElemsPerLoop exceeds uint32_t limit"); | 508 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 509 | + context->GetNodeName(), "copyElemsPerLoop", std::to_string(copyElemsPerLoop64).c_str(), | ||
| 510 | + "The value of copyElemsPerLoop must be less than or equal to uint32 max."); | ||
| 483 | return ge::GRAPH_FAILED; | 511 | return ge::GRAPH_FAILED; |
| 484 | } | 512 | } |
| 485 | uint32_t copyElemsPerLoop = static_cast<uint32_t>(copyElemsPerLoop64); | 513 | uint32_t copyElemsPerLoop = static_cast<uint32_t>(copyElemsPerLoop64); |
| 486 | uint64_t totalElems = static_cast<uint64_t>(info.unsortedDim) * static_cast<uint64_t>(info.lastAxis); | 514 | uint64_t totalElems = static_cast<uint64_t>(info.unsortedDim) * static_cast<uint64_t>(info.lastAxis); |
| 487 | uint64_t loopTimes64 = (totalElems + copyElemsPerLoop64 - 1) / copyElemsPerLoop64; | 515 | uint64_t loopTimes64 = (totalElems + copyElemsPerLoop64 - 1) / copyElemsPerLoop64; |
| 488 | if (loopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 516 | if (loopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 489 | - OP_LOGE(context->GetNodeName(), "loopTimes exceeds uint32_t limit"); | 517 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "loopTimes", std::to_string(loopTimes64).c_str(), |
| 518 | + "The value of loopTimes must be less than or equal to uint32 max."); | ||
| 490 | return ge::GRAPH_FAILED; | 519 | return ge::GRAPH_FAILED; |
| 491 | } | 520 | } |
| 492 | uint32_t loopTimes = static_cast<uint32_t>(loopTimes64); | 521 | uint32_t loopTimes = static_cast<uint32_t>(loopTimes64); |
| @@ -827,7 +856,9 @@ static ge::graphStatus SelectKthValueRoute(gert::TilingContext* context, SortKth | |||
| 827 | return ge::GRAPH_SUCCESS; | 856 | return ge::GRAPH_SUCCESS; |
| 828 | } | 857 | } |
| 829 | if (info.isNonLastAxis) { | 858 | if (info.isNonLastAxis) { |
| 830 | - OP_LOGE(context->GetNodeName(), "non-last kth_value axis does not meet no-transpose schedule constraints"); | 859 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 860 | + context->GetNodeName(), "sortAxis", std::to_string(info.sortAxis).c_str(), | ||
| 861 | + "The value of sortAxis must be the last axis or meet no-transpose schedule constraints."); | ||
| 831 | return ge::GRAPH_FAILED; | 862 | return ge::GRAPH_FAILED; |
| 832 | } | 863 | } |
| 833 | if (TryMerge(context, info, tilingData, blockDim, schId) || TryRadixOneCore(context, info, tilingData, schId) || | 864 | if (TryMerge(context, info, tilingData, blockDim, schId) || TryRadixOneCore(context, info, tilingData, schId) || |
| @@ -836,7 +867,9 @@ static ge::graphStatus SelectKthValueRoute(gert::TilingContext* context, SortKth | |||
| 836 | return ge::GRAPH_SUCCESS; | 867 | return ge::GRAPH_SUCCESS; |
| 837 | } | 868 | } |
| 838 | OP_CHECK_IF((SetRadixMoreCoreTiling(context, info, blockDim) != ge::GRAPH_SUCCESS), | 869 | OP_CHECK_IF((SetRadixMoreCoreTiling(context, info, blockDim) != ge::GRAPH_SUCCESS), |
| 839 | - OP_LOGE(context->GetNodeName(), "kth_value radix more-core tiling failed."), return ge::GRAPH_FAILED); | 870 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SetRadixMoreCoreTiling", "GRAPH_FAILED", |
| 871 | + "The value of SetRadixMoreCoreTiling must be GRAPH_SUCCESS."), | ||
| 872 | + return ge::GRAPH_FAILED); | ||
| 840 | PlanToTilingData(info, tilingData); | 873 | PlanToTilingData(info, tilingData); |
| 841 | schId = KTH_VALUE_SCHID_RADIX_MORE_CORE; | 874 | schId = KTH_VALUE_SCHID_RADIX_MORE_CORE; |
| 842 | return ge::GRAPH_SUCCESS; | 875 | return ge::GRAPH_SUCCESS; |
| @@ -850,14 +883,18 @@ static ge::graphStatus FinalizeKthValueRoute(gert::TilingContext* context, | |||
| 850 | if (schId == KTH_VALUE_SCHID_RADIX_ONE_CORE) { | 883 | if (schId == KTH_VALUE_SCHID_RADIX_ONE_CORE) { |
| 851 | blockDim = static_cast<uint32_t>(std::min<int64_t>(ascendcPlatform.GetCoreNumAiv(), info.unsortedDim)); | 884 | blockDim = static_cast<uint32_t>(std::min<int64_t>(ascendcPlatform.GetCoreNumAiv(), info.unsortedDim)); |
| 852 | if (blockDim == 0U) { | 885 | if (blockDim == 0U) { |
| 853 | - OP_LOGE(context->GetNodeName(), "kth_value blockDim is zero."); | 886 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "blockDim", std::to_string(blockDim).c_str(), |
| 887 | + "The value of blockDim must be greater than 0."); | ||
| 854 | return ge::GRAPH_FAILED; | 888 | return ge::GRAPH_FAILED; |
| 855 | } | 889 | } |
| 856 | uint64_t maxRowsPerCore = Ops::Base::CeilDiv(static_cast<uint64_t>(info.unsortedDim), | 890 | uint64_t maxRowsPerCore = Ops::Base::CeilDiv(static_cast<uint64_t>(info.unsortedDim), |
| 857 | static_cast<uint64_t>(blockDim)); | 891 | static_cast<uint64_t>(blockDim)); |
| 858 | uint64_t sortLoopTimes = Ops::Base::CeilDiv(maxRowsPerCore, static_cast<uint64_t>(info.outputRowsPerLoop)); | 892 | uint64_t sortLoopTimes = Ops::Base::CeilDiv(maxRowsPerCore, static_cast<uint64_t>(info.outputRowsPerLoop)); |
| 859 | OP_CHECK_IF((sortLoopTimes > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())), | 893 | OP_CHECK_IF((sortLoopTimes > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())), |
| 860 | - OP_LOGE(context->GetNodeName(), "kth_value sortLoopTimes exceeds uint32 limit."), | 894 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "sortLoopTimes", |
| 895 | + std::to_string(sortLoopTimes).c_str(), | ||
| 896 | + "The value of sortLoopTimes must be less than or equal to " | ||
| 897 | + "uint32 max."), | ||
| 861 | return ge::GRAPH_FAILED); | 898 | return ge::GRAPH_FAILED); |
| 862 | tilingData->unsortedDimParallel = blockDim; | 899 | tilingData->unsortedDimParallel = blockDim; |
| 863 | tilingData->sortLoopTimes = static_cast<uint32_t>(sortLoopTimes); | 900 | tilingData->sortLoopTimes = static_cast<uint32_t>(sortLoopTimes); |
| @@ -899,7 +936,9 @@ static ge::graphStatus Tiling4KthValue(gert::TilingContext* context) | |||
| 899 | auto tilingData = context->GetTilingData<KthValueTilingData>(); | 936 | auto tilingData = context->GetTilingData<KthValueTilingData>(); |
| 900 | OP_CHECK_NULL_WITH_CONTEXT(context, tilingData); | 937 | OP_CHECK_NULL_WITH_CONTEXT(context, tilingData); |
| 901 | OP_CHECK_IF((memset_s(tilingData, sizeof(KthValueTilingData), 0, sizeof(KthValueTilingData)) != EOK), | 938 | OP_CHECK_IF((memset_s(tilingData, sizeof(KthValueTilingData), 0, sizeof(KthValueTilingData)) != EOK), |
| 902 | - OP_LOGE(context->GetNodeName(), "memset tilingdata failed"), return ge::GRAPH_FAILED); | 939 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "memset_s", "not EOK", |
| 940 | + "The value of memset_s must be EOK."), | ||
| 941 | + return ge::GRAPH_FAILED); | ||
| 903 | auto attrs = context->GetAttrs(); | 942 | auto attrs = context->GetAttrs(); |
| 904 | OP_CHECK_NULL_WITH_CONTEXT(context, attrs); | 943 | OP_CHECK_NULL_WITH_CONTEXT(context, attrs); |
| 905 | const int64_t* kAttr = attrs->GetAttrPointer<int64_t>(0); | 944 | const int64_t* kAttr = attrs->GetAttrPointer<int64_t>(0); |
| @@ -910,7 +949,9 @@ static ge::graphStatus Tiling4KthValue(gert::TilingContext* context) | |||
| 910 | ge::DataType dataType = inputDesc->GetDataType(); | 949 | ge::DataType dataType = inputDesc->GetDataType(); |
| 911 | uint32_t dtypeSize = 0; | 950 | uint32_t dtypeSize = 0; |
| 912 | OP_CHECK_IF((CheckKthValueDtypes(context, dataType, dtypeSize) != ge::GRAPH_SUCCESS), | 951 | OP_CHECK_IF((CheckKthValueDtypes(context, dataType, dtypeSize) != ge::GRAPH_SUCCESS), |
| 913 | - OP_LOGE(context->GetNodeName(), "kth_value dtype check failed."), return ge::GRAPH_FAILED); | 952 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "CheckKthValueDtypes", "GRAPH_FAILED", |
| 953 | + "The value of CheckKthValueDtypes must be GRAPH_SUCCESS."), | ||
| 954 | + return ge::GRAPH_FAILED); | ||
| 914 | SortKthTileInfo info; | 955 | SortKthTileInfo info; |
| 915 | info.dataType = dataType; | 956 | info.dataType = dataType; |
| 916 | info.dtypeSize = dtypeSize; | 957 | info.dtypeSize = dtypeSize; |
| @@ -918,20 +959,28 @@ static ge::graphStatus Tiling4KthValue(gert::TilingContext* context) | |||
| 918 | info.blockUbSize = Ops::Base::GetUbBlockSize(context); | 959 | info.blockUbSize = Ops::Base::GetUbBlockSize(context); |
| 919 | info.maxCoreNum = ascendcPlatform.GetCoreNumAiv(); | 960 | info.maxCoreNum = ascendcPlatform.GetCoreNumAiv(); |
| 920 | OP_CHECK_IF((ParseKthValueShapeInfo(context, kAttr, dimAttr, info) != ge::GRAPH_SUCCESS), | 961 | OP_CHECK_IF((ParseKthValueShapeInfo(context, kAttr, dimAttr, info) != ge::GRAPH_SUCCESS), |
| 921 | - OP_LOGE(context->GetNodeName(), "kth_value shape parse failed."), return ge::GRAPH_FAILED); | 962 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ParseKthValueShapeInfo", "GRAPH_FAILED", |
| 963 | + "The value of ParseKthValueShapeInfo must be GRAPH_SUCCESS."), | ||
| 964 | + return ge::GRAPH_FAILED); | ||
| 922 | info.isNonLastAxis = (info.sortAxis != info.rank - 1); | 965 | info.isNonLastAxis = (info.sortAxis != info.rank - 1); |
| 923 | bool oneCoreUbValid = false; | 966 | bool oneCoreUbValid = false; |
| 924 | OP_CHECK_IF((ComputeKthValueUbInfo(context, ascendcPlatform, info, oneCoreUbValid) != ge::GRAPH_SUCCESS), | 967 | OP_CHECK_IF((ComputeKthValueUbInfo(context, ascendcPlatform, info, oneCoreUbValid) != ge::GRAPH_SUCCESS), |
| 925 | - OP_LOGE(context->GetNodeName(), "kth_value UB info compute failed."), return ge::GRAPH_FAILED); | 968 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeKthValueUbInfo", "GRAPH_FAILED", |
| 969 | + "The value of ComputeKthValueUbInfo must be GRAPH_SUCCESS."), | ||
| 970 | + return ge::GRAPH_FAILED); | ||
| 926 | InitKthValueBaseTiling(tilingData, info, oneCoreUbValid, *kAttr - 1); | 971 | InitKthValueBaseTiling(tilingData, info, oneCoreUbValid, *kAttr - 1); |
| 927 | KthValueTilingData candidateTilingData = *tilingData; | 972 | KthValueTilingData candidateTilingData = *tilingData; |
| 928 | uint64_t schId = KTH_VALUE_SCHID_RADIX_MORE_CORE; | 973 | uint64_t schId = KTH_VALUE_SCHID_RADIX_MORE_CORE; |
| 929 | uint32_t blockDim = 1; | 974 | uint32_t blockDim = 1; |
| 930 | OP_CHECK_IF((SelectKthValueRoute(context, info, &candidateTilingData, blockDim, schId) != ge::GRAPH_SUCCESS), | 975 | OP_CHECK_IF((SelectKthValueRoute(context, info, &candidateTilingData, blockDim, schId) != ge::GRAPH_SUCCESS), |
| 931 | - OP_LOGE(context->GetNodeName(), "kth_value route selection failed."), return ge::GRAPH_FAILED); | 976 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SelectKthValueRoute", "GRAPH_FAILED", |
| 977 | + "The value of SelectKthValueRoute must be GRAPH_SUCCESS."), | ||
| 978 | + return ge::GRAPH_FAILED); | ||
| 932 | OP_CHECK_IF((FinalizeKthValueRoute(context, ascendcPlatform, info, &candidateTilingData, schId, blockDim) != | 979 | OP_CHECK_IF((FinalizeKthValueRoute(context, ascendcPlatform, info, &candidateTilingData, schId, blockDim) != |
| 933 | ge::GRAPH_SUCCESS), | 980 | ge::GRAPH_SUCCESS), |
| 934 | - OP_LOGE(context->GetNodeName(), "kth_value route finalize failed."), return ge::GRAPH_FAILED); | 981 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "FinalizeKthValueRoute", "GRAPH_FAILED", |
| 982 | + "The value of FinalizeKthValueRoute must be GRAPH_SUCCESS."), | ||
| 983 | + return ge::GRAPH_FAILED); | ||
| 935 | *tilingData = candidateTilingData; | 984 | *tilingData = candidateTilingData; |
| 936 | OP_LOGI(context->GetNodeName(), | 985 | OP_LOGI(context->GetNodeName(), |
| 937 | "KthValueTiling: schId=%lu, blockDim=%u, lastAxis=%ld, unsortedDim=%ld, " | 986 | "KthValueTiling: schId=%lu, blockDim=%u, lastAxis=%ld, unsortedDim=%ld, " |
| @@ -943,10 +992,16 @@ static ge::graphStatus Tiling4KthValue(gert::TilingContext* context) | |||
| 943 | 992 | ||
| 944 | static ge::graphStatus TilingPrepare4KthValue(gert::TilingParseContext* context) | 993 | static ge::graphStatus TilingPrepare4KthValue(gert::TilingParseContext* context) |
| 945 | { | 994 | { |
| 995 | + auto compileInfo = context->GetCompiledInfo<KthValueCompileInfo>(); | ||
| 996 | + OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | ||
| 946 | auto platformInfo = context->GetPlatformInfo(); | 997 | auto platformInfo = context->GetPlatformInfo(); |
| 947 | OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | 998 | OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); |
| 948 | auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | 999 | auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); |
| 949 | - OP_CHECK_IF((ascendcPlatform.GetCoreNumAiv() <= 0), OP_LOGE(context->GetNodeName(), "The core num is invalid."), | 1000 | + compileInfo->coreNum = ascendcPlatform.GetCoreNumAiv(); |
| 1001 | + OP_CHECK_IF((compileInfo->coreNum <= 0), | ||
| 1002 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "coreNum", | ||
| 1003 | + std::to_string(compileInfo->coreNum).c_str(), | ||
| 1004 | + "The value of coreNum must be greater than 0."), | ||
| 950 | return ge::GRAPH_FAILED); | 1005 | return ge::GRAPH_FAILED); |
| 951 | return ge::GRAPH_SUCCESS; | 1006 | return ge::GRAPH_SUCCESS; |
| 952 | } | 1007 | } |
| @@ -8,6 +8,8 @@ | |||
| 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 | + | ||
| 11 | 13 | ||
| 12 | 14 | ||
| 13 | 15 | ||
| @@ -27,7 +29,9 @@ static ge::graphStatus KthValueInferShapeFunc(gert::InferShapeContext* context) | |||
| 27 | int64_t dim = (dimAttr == nullptr) ? -1 : *dimAttr; | 29 | int64_t dim = (dimAttr == nullptr) ? -1 : *dimAttr; |
| 28 | int64_t normDim = dim < 0 ? dim + rank : dim; | 30 | int64_t normDim = dim < 0 ? dim + rank : dim; |
| 29 | if (normDim < 0 || normDim >= rank) { | 31 | if (normDim < 0 || normDim >= rank) { |
| 30 | - OP_LOGE(context->GetNodeName(), "dim should be in range [%ld, %ld].", -rank, rank - 1); | 32 | + std::string dimValue = std::to_string(dim); |
| 33 | + std::string dimRange = "[" + std::to_string(-rank) + ", " + std::to_string(rank - 1) + "]"; | ||
| 34 | + OP_LOGE_WITH_INVALID_ATTR(context->GetNodeName(), "dim", dimValue.c_str(), dimRange.c_str()); | ||
| 31 | return ge::GRAPH_FAILED; | 35 | return ge::GRAPH_FAILED; |
| 32 | } | 36 | } |
| 33 | auto* valuesShape = context->GetOutputShape(0); | 37 | auto* valuesShape = context->GetOutputShape(0); |
| @@ -19,28 +19,30 @@ using namespace ge; | |||
| 19 | namespace ops { | 19 | namespace ops { |
| 20 | graphStatus InferDataType4Sort(gert::InferDataTypeContext* context) | 20 | graphStatus InferDataType4Sort(gert::InferDataTypeContext* context) |
| 21 | { | 21 | { |
| 22 | - context->SetOutputDataType(0, context->GetInputDataType(0)); | 22 | + context->SetOutputDataType(0, context->GetInputDataType(0)); |
| 23 | - auto attrs = context->GetAttrs(); | 23 | + auto attrs = context->GetAttrs(); |
| 24 | - OP_CHECK_NULL_WITH_CONTEXT(context, attrs); | 24 | + OP_CHECK_NULL_WITH_CONTEXT(context, attrs); |
| 25 | - int64_t y2Dtype = static_cast<int64_t>(ge::DataType::DT_INT32); | 25 | + int64_t y2Dtype = static_cast<int64_t>(ge::DataType::DT_INT32); |
| 26 | - ge::DataType indicesDtype = ge::DT_INT32; | 26 | + ge::DataType indicesDtype = ge::DT_INT32; |
| 27 | - OP_LOGI(context->GetNodeName(), "The default dtype of output indices is int32."); | 27 | + OP_LOGI(context->GetNodeName(), "The default dtype of output indices is int32."); |
| 28 | - auto out_idx_dtype_ptr = attrs->GetAttrPointer<int64_t>(3); | 28 | + auto out_idx_dtype_ptr = attrs->GetAttrPointer<int64_t>(3); |
| 29 | - if (out_idx_dtype_ptr != nullptr) { | 29 | + if (out_idx_dtype_ptr != nullptr) { |
| 30 | - y2Dtype = *out_idx_dtype_ptr; | 30 | + y2Dtype = *out_idx_dtype_ptr; |
| 31 | - if (y2Dtype == static_cast<int64_t>(ge::DataType::DT_INT64)) { | 31 | + if (y2Dtype == static_cast<int64_t>(ge::DataType::DT_INT64)) { |
| 32 | - OP_LOGI(context->GetNodeName(), "The dtype of output indices is set as int64."); | 32 | + OP_LOGI(context->GetNodeName(), "The dtype of output indices is set as int64."); |
| 33 | - indicesDtype = ge::DT_INT64; | 33 | + indicesDtype = ge::DT_INT64; |
| 34 | - } else { | 34 | + } else { |
| 35 | - if (y2Dtype != static_cast<int64_t>(ge::DataType::DT_INT32)) { | 35 | + if (y2Dtype != static_cast<int64_t>(ge::DataType::DT_INT32)) { |
| 36 | - OP_LOGE(context->GetNodeName(), "The dtype of output indices only support int64 or int32."); | 36 | + OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "indices_dtype", |
| 37 | - return GRAPH_FAILED; | 37 | + Ops::Base::ToString(static_cast<ge::DataType>(y2Dtype)).c_str(), |
| 38 | - } | 38 | + "INT32 or INT64"); |
| 39 | + return GRAPH_FAILED; | ||
| 40 | + } | ||
| 41 | + } | ||
| 39 | } | 42 | } |
| 40 | - } | 43 | + context->SetOutputDataType(1, indicesDtype); |
| 41 | - context->SetOutputDataType(1, indicesDtype); | 44 | + return GRAPH_SUCCESS; |
| 42 | - return GRAPH_SUCCESS; | ||
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | IMPL_OP(Sort).InferDataType(InferDataType4Sort); | 47 | IMPL_OP(Sort).InferDataType(InferDataType4Sort); |
| 46 | -} // namespace ops | 48 | +} // namespace ops |
| @@ -19,43 +19,49 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | + | ||
| 23 | + | ||
| 22 | using namespace ge; | 24 | using namespace ge; |
| 23 | 25 | ||
| 24 | namespace { | 26 | namespace { |
| 25 | const int64_t INT_BYTES = 4; | 27 | const int64_t INT_BYTES = 4; |
| 26 | -const int64_t SORT_BYTES = 8; // for 910B sort struct | 28 | +const int64_t SORT_BYTES = 8; // for 910B sort struct |
| 27 | const int64_t TMP_VAL = 0; | 29 | const int64_t TMP_VAL = 0; |
| 28 | const int64_t TMP_IDX = 1; | 30 | const int64_t TMP_IDX = 1; |
| 29 | const int64_t TMP_CACHE = 2; | 31 | const int64_t TMP_CACHE = 2; |
| 30 | const int64_t TMP_CONV = 3; | 32 | const int64_t TMP_CONV = 3; |
| 31 | const string kSortWithIndex = "SortWithIndex"; | 33 | const string kSortWithIndex = "SortWithIndex"; |
| 32 | -} // namespace | 34 | +} // namespace |
| 33 | 35 | ||
| 34 | namespace optiling { | 36 | namespace optiling { |
| 35 | -static ge::graphStatus Tiling4Sort(gert::TilingContext* context) { | 37 | +static ge::graphStatus Tiling4Sort(gert::TilingContext* context) |
| 36 | - auto platformInfo = context->GetPlatformInfo(); | 38 | +{ |
| 37 | - OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | 39 | + auto platformInfo = context->GetPlatformInfo(); |
| 38 | - auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | 40 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); |
| 39 | - std::string opType(context->GetNodeType()); | 41 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); |
| 40 | - OP_LOGD(context->GetNodeName(), "AscendC Sort simt tiling"); | 42 | + std::string opType(context->GetNodeType()); |
| 41 | - OP_CHECK_IF(SortTilingSimt(context, ascendcPlatform.GetCoreNumAiv()) != ge::GRAPH_SUCCESS, | 43 | + OP_LOGD(context->GetNodeName(), "AscendC Sort simt tiling"); |
| 42 | - OP_LOGE(context->GetNodeName(), | 44 | + OP_CHECK_IF(SortTilingSimt(context, ascendcPlatform.GetCoreNumAiv()) != ge::GRAPH_SUCCESS, |
| 43 | - "The simt tiling function failed"), return ge::GRAPH_FAILED); | 45 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SortTilingSimt", "GRAPH_FAILED", |
| 44 | - return ge::GRAPH_SUCCESS; | 46 | + "The value of SortTilingSimt must be GRAPH_SUCCESS."), |
| 47 | + return ge::GRAPH_FAILED); | ||
| 48 | + return ge::GRAPH_SUCCESS; | ||
| 45 | } | 49 | } |
| 46 | 50 | ||
| 47 | -static ge::graphStatus TilingPrepare4Sort(gert::TilingParseContext* context) { | 51 | +static ge::graphStatus TilingPrepare4Sort(gert::TilingParseContext* context) |
| 48 | - OP_LOGD(context->GetNodeName(), "AscendC Tiling starting GRAPH_SUCCESS"); | 52 | +{ |
| 49 | - auto platformInfo = context->GetPlatformInfo(); | 53 | + OP_LOGD(context->GetNodeName(), "AscendC Tiling starting GRAPH_SUCCESS"); |
| 50 | - OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | 54 | + auto platformInfo = context->GetPlatformInfo(); |
| 51 | - auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | 55 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); |
| 52 | - OP_CHECK_IF((ascendcPlatform.GetCoreNumAiv() <= 0), | 56 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); |
| 53 | - OP_LOGE(context->GetNodeName(), | 57 | + OP_CHECK_IF((ascendcPlatform.GetCoreNumAiv() <= 0), |
| 54 | - "The core num is invaild."), | 58 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "coreNum", |
| 55 | - return ge::GRAPH_FAILED); | 59 | + std::to_string(ascendcPlatform.GetCoreNumAiv()).c_str(), |
| 56 | - return ge::GRAPH_SUCCESS; | 60 | + "The value of coreNum must be greater than 0."), |
| 61 | + return ge::GRAPH_FAILED); | ||
| 62 | + return ge::GRAPH_SUCCESS; | ||
| 57 | } | 63 | } |
| 58 | 64 | ||
| 59 | IMPL_OP_OPTILING(Sort).Tiling(Tiling4Sort).TilingParse<SortCompileInfo>(TilingPrepare4Sort); | 65 | IMPL_OP_OPTILING(Sort).Tiling(Tiling4Sort).TilingParse<SortCompileInfo>(TilingPrepare4Sort); |
| 60 | IMPL_OP_OPTILING(SortV2).Tiling(Tiling4Sort).TilingParse<SortCompileInfo>(TilingPrepare4Sort); | 66 | IMPL_OP_OPTILING(SortV2).Tiling(Tiling4Sort).TilingParse<SortCompileInfo>(TilingPrepare4Sort); |
| 61 | -} // namespace optiling | 67 | +} // namespace optiling |
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | + | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | 23 | ||
| @@ -42,7 +43,8 @@ ge::graphStatus CheckInputAndOutput(gert::TilingContext* context, SortKthTileInf | |||
| 42 | uint64_t ubSize = 0; | 43 | uint64_t ubSize = 0; |
| 43 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); | 44 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); |
| 44 | OP_CHECK_IF(ubSize <= static_cast<uint64_t>(SIMT_UB), | 45 | OP_CHECK_IF(ubSize <= static_cast<uint64_t>(SIMT_UB), |
| 45 | - OP_LOGE(context->GetNodeName(), "ubSize must be greater than %u, but is %lu", SIMT_UB, ubSize), | 46 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(), |
| 47 | + "The value of ubSize must be greater than SIMT_UB."), | ||
| 46 | return ge::GRAPH_FAILED); | 48 | return ge::GRAPH_FAILED); |
| 47 | sortTileInfo.blockUbSize = Ops::Base::GetUbBlockSize(context); | 49 | sortTileInfo.blockUbSize = Ops::Base::GetUbBlockSize(context); |
| 48 | OP_LOGI(context->GetNodeName(), "ubSize is %ld, blockUbSize %u", ubSize, sortTileInfo.blockUbSize); | 50 | OP_LOGI(context->GetNodeName(), "ubSize is %ld, blockUbSize %u", ubSize, sortTileInfo.blockUbSize); |
| @@ -56,17 +58,20 @@ ge::graphStatus CheckInputAndOutput(gert::TilingContext* context, SortKthTileInf | |||
| 56 | auto yStorage1 = context->GetOutputShape(1); | 58 | auto yStorage1 = context->GetOutputShape(1); |
| 57 | OP_CHECK_NULL_WITH_CONTEXT(context, yStorage1); | 59 | OP_CHECK_NULL_WITH_CONTEXT(context, yStorage1); |
| 58 | const gert::Shape& outShape1 = Ops::Base::EnsureNotScalar(yStorage1->GetStorageShape()); | 60 | const gert::Shape& outShape1 = Ops::Base::EnsureNotScalar(yStorage1->GetStorageShape()); |
| 59 | - OP_CHECK_IF(inputShape.GetShapeSize() == 0 || outShape.GetShapeSize() == 0, | 61 | + OP_CHECK_IF( |
| 60 | - OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "x, y1", "0", | 62 | + inputShape.GetShapeSize() == 0 || outShape.GetShapeSize() == 0, |
| 61 | - "The shape size of input x and output y1 should be positive"), | 63 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 62 | - return ge::GRAPH_FAILED); | 64 | + context->GetNodeName(), "x, y1", |
| 65 | + (std::to_string(inputShape.GetShapeSize()) + ", " + std::to_string(outShape.GetShapeSize())).c_str(), | ||
| 66 | + "The values of shape sizes of x and y1 must be positive."), | ||
| 67 | + return ge::GRAPH_FAILED); | ||
| 63 | OP_CHECK_IF( | 68 | OP_CHECK_IF( |
| 64 | outShape != outShape1 || outShape != inputShape, | 69 | outShape != outShape1 || outShape != inputShape, |
| 65 | OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context->GetNodeName(), "x, y1, y2", | 70 | OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context->GetNodeName(), "x, y1, y2", |
| 66 | (Ops::Base::ToString(inputShape) + ", " + Ops::Base::ToString(outShape) + | 71 | (Ops::Base::ToString(inputShape) + ", " + Ops::Base::ToString(outShape) + |
| 67 | ", " + Ops::Base::ToString(outShape1)) | 72 | ", " + Ops::Base::ToString(outShape1)) |
| 68 | .c_str(), | 73 | .c_str(), |
| 69 | - "The shape of input x, output y1 and y2 should be the same"), | 74 | + "The shapes of x, y1, and y2 must be the same."), |
| 70 | return ge::GRAPH_FAILED); | 75 | return ge::GRAPH_FAILED); |
| 71 | int32_t xDimNum = inputShape.GetDimNum(); | 76 | int32_t xDimNum = inputShape.GetDimNum(); |
| 72 | sortTileInfo.rank = xDimNum; | 77 | sortTileInfo.rank = xDimNum; |
| @@ -92,7 +97,7 @@ ge::graphStatus CheckSortOutputDtypes(gert::TilingContext* context, SortKthTileI | |||
| 92 | OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON( | 97 | OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON( |
| 93 | context->GetNodeName(), "x, y1", | 98 | context->GetNodeName(), "x, y1", |
| 94 | (Ops::Base::ToString(dataType) + ", " + Ops::Base::ToString(y1DType)).c_str(), | 99 | (Ops::Base::ToString(dataType) + ", " + Ops::Base::ToString(y1DType)).c_str(), |
| 95 | - "The dtype of input x should be the same as output y1"), | 100 | + "The dtypes of x and y1 must be the same."), |
| 96 | return ge::GRAPH_FAILED); | 101 | return ge::GRAPH_FAILED); |
| 97 | ge::TypeUtils::GetDataTypeLength(y2DType, sortTileInfo.y2DtypeSize); | 102 | ge::TypeUtils::GetDataTypeLength(y2DType, sortTileInfo.y2DtypeSize); |
| 98 | return ge::GRAPH_SUCCESS; | 103 | return ge::GRAPH_SUCCESS; |
| @@ -110,7 +115,9 @@ ge::graphStatus ComputeNonLastAxisLayout(gert::TilingContext* context, SortKthTi | |||
| 110 | ge::graphStatus SortCheckParams(gert::TilingContext* context, SortKthTileInfo& sortTileInfo) | 115 | ge::graphStatus SortCheckParams(gert::TilingContext* context, SortKthTileInfo& sortTileInfo) |
| 111 | { | 116 | { |
| 112 | OP_CHECK_IF(CheckInputAndOutput(context, sortTileInfo) != ge::GRAPH_SUCCESS, | 117 | OP_CHECK_IF(CheckInputAndOutput(context, sortTileInfo) != ge::GRAPH_SUCCESS, |
| 113 | - OP_LOGE(context->GetNodeName(), "CheckInputAndOutput failed"), return ge::GRAPH_FAILED); | 118 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "CheckInputAndOutput", "GRAPH_FAILED", |
| 119 | + "The value of CheckInputAndOutput must be GRAPH_SUCCESS."), | ||
| 120 | + return ge::GRAPH_FAILED); | ||
| 114 | auto inputDescPtr = context->GetInputDesc(0); | 121 | auto inputDescPtr = context->GetInputDesc(0); |
| 115 | OP_CHECK_NULL_WITH_CONTEXT(context, inputDescPtr); | 122 | OP_CHECK_NULL_WITH_CONTEXT(context, inputDescPtr); |
| 116 | ge::DataType dataType = inputDescPtr->GetDataType(); | 123 | ge::DataType dataType = inputDescPtr->GetDataType(); |
| @@ -121,7 +128,9 @@ ge::graphStatus SortCheckParams(gert::TilingContext* context, SortKthTileInfo& s | |||
| 121 | "INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, FLOAT, FLOAT16, BF16"), | 128 | "INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, FLOAT, FLOAT16, BF16"), |
| 122 | return ge::GRAPH_FAILED); | 129 | return ge::GRAPH_FAILED); |
| 123 | OP_CHECK_IF(CheckSortOutputDtypes(context, sortTileInfo, dataType) != ge::GRAPH_SUCCESS, | 130 | OP_CHECK_IF(CheckSortOutputDtypes(context, sortTileInfo, dataType) != ge::GRAPH_SUCCESS, |
| 124 | - OP_LOGE(context->GetNodeName(), "CheckSortOutputDtypes failed"), return ge::GRAPH_FAILED); | 131 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "CheckSortOutputDtypes", "GRAPH_FAILED", |
| 132 | + "The value of CheckSortOutputDtypes must be GRAPH_SUCCESS."), | ||
| 133 | + return ge::GRAPH_FAILED); | ||
| 125 | auto const attrs = context->GetAttrs(); | 134 | auto const attrs = context->GetAttrs(); |
| 126 | OP_CHECK_NULL_WITH_CONTEXT(context, attrs); | 135 | OP_CHECK_NULL_WITH_CONTEXT(context, attrs); |
| 127 | const bool* isDescending = attrs->GetAttrPointer<bool>(1); | 136 | const bool* isDescending = attrs->GetAttrPointer<bool>(1); |
| @@ -137,8 +146,12 @@ ge::graphStatus SortCheckParams(gert::TilingContext* context, SortKthTileInfo& s | |||
| 137 | sortTileInfo.sortAxis = sortAxis; | 146 | sortTileInfo.sortAxis = sortAxis; |
| 138 | sortTileInfo.isNonLastAxis = (sortAxis != (static_cast<int32_t>(sortTileInfo.rank) - 1)); | 147 | sortTileInfo.isNonLastAxis = (sortAxis != (static_cast<int32_t>(sortTileInfo.rank) - 1)); |
| 139 | if (sortTileInfo.isNonLastAxis) { | 148 | if (sortTileInfo.isNonLastAxis) { |
| 140 | - OP_CHECK_IF(ComputeNonLastAxisLayout(context, sortTileInfo, sortAxis) != ge::GRAPH_SUCCESS, | 149 | + OP_CHECK_IF( |
| 141 | - OP_LOGE(context->GetNodeName(), "ComputeNonLastAxisLayout failed"), return ge::GRAPH_FAILED); | 150 | + ComputeNonLastAxisLayout(context, sortTileInfo, sortAxis) != ge::GRAPH_SUCCESS, |
| 151 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeNonLastAxisLayout", "GRAPH_FAILED", | ||
| 152 | + "The value of ComputeNonLastAxisLayout must be " | ||
| 153 | + "GRAPH_SUCCESS."), | ||
| 154 | + return ge::GRAPH_FAILED); | ||
| 142 | } | 155 | } |
| 143 | return ge::GRAPH_SUCCESS; | 156 | return ge::GRAPH_SUCCESS; |
| 144 | } | 157 | } |
| @@ -263,16 +276,22 @@ ge::graphStatus SetAxisOneCopyTiling(gert::TilingContext* context, SortKthTileIn | |||
| 263 | uint64_t bytesPerElem = static_cast<uint64_t>(2) * (static_cast<uint64_t>(sortTileInfo.dtypeSize) + | 276 | uint64_t bytesPerElem = static_cast<uint64_t>(2) * (static_cast<uint64_t>(sortTileInfo.dtypeSize) + |
| 264 | static_cast<uint64_t>(sortTileInfo.y2DtypeSize)); | 277 | static_cast<uint64_t>(sortTileInfo.y2DtypeSize)); |
| 265 | if (bytesPerElem == 0) { | 278 | if (bytesPerElem == 0) { |
| 266 | - OP_LOGE(context->GetNodeName(), "bytesPerElem is 0, invalid dtype configuration"); | 279 | + OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(context->GetNodeName(), "x", |
| 280 | + Ops::Base::ToString(sortTileInfo.dataType).c_str(), | ||
| 281 | + "The dtype size of x must be greater than 0."); | ||
| 267 | return ge::GRAPH_FAILED; | 282 | return ge::GRAPH_FAILED; |
| 268 | } | 283 | } |
| 269 | uint64_t copyElemsPerLoop64 = static_cast<uint64_t>(sortTileInfo.ubSize) / bytesPerElem; | 284 | uint64_t copyElemsPerLoop64 = static_cast<uint64_t>(sortTileInfo.ubSize) / bytesPerElem; |
| 270 | if (copyElemsPerLoop64 == 0) { | 285 | if (copyElemsPerLoop64 == 0) { |
| 271 | - OP_LOGE(context->GetNodeName(), "copyElemsPerLoop is 0, ub is too small for axis-one copy"); | 286 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "copyElemsPerLoop", |
| 287 | + std::to_string(copyElemsPerLoop64).c_str(), | ||
| 288 | + "The value of copyElemsPerLoop must be greater than 0."); | ||
| 272 | return ge::GRAPH_FAILED; | 289 | return ge::GRAPH_FAILED; |
| 273 | } | 290 | } |
| 274 | if (copyElemsPerLoop64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 291 | if (copyElemsPerLoop64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 275 | - OP_LOGE(context->GetNodeName(), "copyElemsPerLoop exceeds uint32_t limit"); | 292 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 293 | + context->GetNodeName(), "copyElemsPerLoop", std::to_string(copyElemsPerLoop64).c_str(), | ||
| 294 | + "The value of copyElemsPerLoop must be less than or equal to uint32 max."); | ||
| 276 | return ge::GRAPH_FAILED; | 295 | return ge::GRAPH_FAILED; |
| 277 | } | 296 | } |
| 278 | uint32_t copyElemsPerLoop = static_cast<uint32_t>(copyElemsPerLoop64); | 297 | uint32_t copyElemsPerLoop = static_cast<uint32_t>(copyElemsPerLoop64); |
| @@ -280,7 +299,8 @@ ge::graphStatus SetAxisOneCopyTiling(gert::TilingContext* context, SortKthTileIn | |||
| 280 | static_cast<uint64_t>(sortTileInfo.lastAxis); | 299 | static_cast<uint64_t>(sortTileInfo.lastAxis); |
| 281 | uint64_t loopTimes64 = (totalElems + copyElemsPerLoop64 - 1) / copyElemsPerLoop64; | 300 | uint64_t loopTimes64 = (totalElems + copyElemsPerLoop64 - 1) / copyElemsPerLoop64; |
| 282 | if (loopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 301 | if (loopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 283 | - OP_LOGE(context->GetNodeName(), "loopTimes exceeds uint32_t limit"); | 302 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "loopTimes", std::to_string(loopTimes64).c_str(), |
| 303 | + "The value of loopTimes must be less than or equal to uint32 max."); | ||
| 284 | return ge::GRAPH_FAILED; | 304 | return ge::GRAPH_FAILED; |
| 285 | } | 305 | } |
| 286 | uint32_t loopTimes = static_cast<uint32_t>(loopTimes64); | 306 | uint32_t loopTimes = static_cast<uint32_t>(loopTimes64); |
| @@ -305,7 +325,7 @@ ge::graphStatus SetAxisOneCopyTiling(gert::TilingContext* context, SortKthTileIn | |||
| 305 | 325 | ||
| 306 | void FillSmallAxisBatched(gert::TilingContext* context, SortKthTileInfo& sortTileInfo, const SmallAxisRoutePlan& plan) | 326 | void FillSmallAxisBatched(gert::TilingContext* context, SortKthTileInfo& sortTileInfo, const SmallAxisRoutePlan& plan) |
| 307 | { | 327 | { |
| 308 | - sortTileInfo.ubSize = sortTileInfo.ubSize - SIMT_UB; // reserve 32KB for SIMT kernel scratch | 328 | + sortTileInfo.ubSize = sortTileInfo.ubSize - SIMT_UB; // reserve 32KB for SIMT kernel scratch |
| 309 | sortTileInfo.numTileDataSize = static_cast<uint32_t>(sortTileInfo.lastAxis); | 329 | sortTileInfo.numTileDataSize = static_cast<uint32_t>(sortTileInfo.lastAxis); |
| 310 | sortTileInfo.keyParams0 = plan.batchSize; // rows per batch | 330 | sortTileInfo.keyParams0 = plan.batchSize; // rows per batch |
| 311 | sortTileInfo.keyParams1 = plan.batchNum; // total batches | 331 | sortTileInfo.keyParams1 = plan.batchNum; // total batches |
| @@ -326,14 +346,16 @@ void FillSmallAxisBatched(gert::TilingContext* context, SortKthTileInfo& sortTil | |||
| 326 | // how many rows fit in available UB via ComputeMergeMoreCoreTiling. | 346 | // how many rows fit in available UB via ComputeMergeMoreCoreTiling. |
| 327 | ge::graphStatus SetMergeMoreCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) | 347 | ge::graphStatus SetMergeMoreCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) |
| 328 | { | 348 | { |
| 329 | - uint32_t byteNum = MERGE_SORT_LIST_NUM * MERGE_SORT_DATA_BYTES * 2; // value double buffer | 349 | + uint32_t byteNum = MERGE_SORT_LIST_NUM * MERGE_SORT_DATA_BYTES * 2; // value double buffer |
| 330 | - byteNum += MERGE_SORT_LIST_NUM * static_cast<uint32_t>(sizeof(uint32_t)); // int32 index | 350 | + byteNum += MERGE_SORT_LIST_NUM * static_cast<uint32_t>(sizeof(uint32_t)); // int32 index |
| 331 | if (info.y2DtypeSize == sizeof(int64_t)) { | 351 | if (info.y2DtypeSize == sizeof(int64_t)) { |
| 332 | byteNum += MERGE_SORT_LIST_NUM * static_cast<uint32_t>(sizeof(int64_t)); // int64 index extra | 352 | byteNum += MERGE_SORT_LIST_NUM * static_cast<uint32_t>(sizeof(int64_t)); // int64 index extra |
| 333 | } | 353 | } |
| 334 | byteNum += MERGE_SORT_LIST_NUM * info.dtypeSize; | 354 | byteNum += MERGE_SORT_LIST_NUM * info.dtypeSize; |
| 335 | OP_CHECK_IF(!ComputeMergeMoreCoreTiling(context, info, byteNum), | 355 | OP_CHECK_IF(!ComputeMergeMoreCoreTiling(context, info, byteNum), |
| 336 | - OP_LOGE(context->GetNodeName(), "merge more-core plan failed"), return ge::GRAPH_FAILED); | 356 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeMergeMoreCoreTiling", "false", |
| 357 | + "The value of ComputeMergeMoreCoreTiling must be true."), | ||
| 358 | + return ge::GRAPH_FAILED); | ||
| 337 | OP_LOGI("[mergeSort]", "maxDealingNum: %u", info.keyParams0); | 359 | OP_LOGI("[mergeSort]", "maxDealingNum: %u", info.keyParams0); |
| 338 | return ge::GRAPH_SUCCESS; | 360 | return ge::GRAPH_SUCCESS; |
| 339 | } | 361 | } |
| @@ -346,7 +368,9 @@ ge::graphStatus SetRadixOneCoreTiling(gert::TilingContext* context, SortKthTileI | |||
| 346 | uint64_t sortLoopTimes64 = Ops::Base::CeilDiv(sortTileInfo.unsortedDim, | 368 | uint64_t sortLoopTimes64 = Ops::Base::CeilDiv(sortTileInfo.unsortedDim, |
| 347 | static_cast<int64_t>(sortTileInfo.maxCoreNum)); | 369 | static_cast<int64_t>(sortTileInfo.maxCoreNum)); |
| 348 | if (sortLoopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 370 | if (sortLoopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 349 | - OP_LOGE(context->GetNodeName(), "sortLoopTimes exceeds uint32_t limit"); | 371 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "sortLoopTimes", |
| 372 | + std::to_string(sortLoopTimes64).c_str(), | ||
| 373 | + "The value of sortLoopTimes must be less than or equal to uint32 max."); | ||
| 350 | return ge::GRAPH_FAILED; | 374 | return ge::GRAPH_FAILED; |
| 351 | } | 375 | } |
| 352 | sortTileInfo.sortLoopTimes = static_cast<uint32_t>(sortLoopTimes64); | 376 | sortTileInfo.sortLoopTimes = static_cast<uint32_t>(sortLoopTimes64); |
| @@ -364,7 +388,9 @@ ge::graphStatus SetRadixOneCoreTiling(gert::TilingContext* context, SortKthTileI | |||
| 364 | 388 | ||
| 365 | ge::graphStatus SetRadixMoreCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) | 389 | ge::graphStatus SetRadixMoreCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) |
| 366 | { | 390 | { |
| 367 | - OP_CHECK_IF(!FillRadixMoreCoreInfo(info), OP_LOGE(context->GetNodeName(), "radix more-core plan failed"), | 391 | + OP_CHECK_IF(!FillRadixMoreCoreInfo(info), |
| 392 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "FillRadixMoreCoreInfo", "false", | ||
| 393 | + "The value of FillRadixMoreCoreInfo must be true."), | ||
| 368 | return ge::GRAPH_FAILED); | 394 | return ge::GRAPH_FAILED); |
| 369 | info.ubSize = info.ubSize - SIMT_UB; | 395 | info.ubSize = info.ubSize - SIMT_UB; |
| 370 | size_t* userWorkSpaceSize = context->GetWorkspaceSizes(1); | 396 | size_t* userWorkSpaceSize = context->GetWorkspaceSizes(1); |
| @@ -401,14 +427,18 @@ void PrintTilingDataSort(gert::TilingContext* context, SortKthTileInfo& sortTile | |||
| 401 | ge::graphStatus SetMergeSortTiling(gert::TilingContext* context, SortKthTileInfo& info) | 427 | ge::graphStatus SetMergeSortTiling(gert::TilingContext* context, SortKthTileInfo& info) |
| 402 | { | 428 | { |
| 403 | OP_CHECK_IF(!ComputeMergeSortTiling(context, info, info.y2DtypeSize), | 429 | OP_CHECK_IF(!ComputeMergeSortTiling(context, info, info.y2DtypeSize), |
| 404 | - OP_LOGE(context->GetNodeName(), "merge sort tiling failed"), return ge::GRAPH_FAILED); | 430 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeMergeSortTiling", "false", |
| 431 | + "The value of ComputeMergeSortTiling must be true."), | ||
| 432 | + return ge::GRAPH_FAILED); | ||
| 405 | return ge::GRAPH_SUCCESS; | 433 | return ge::GRAPH_SUCCESS; |
| 406 | } | 434 | } |
| 407 | 435 | ||
| 408 | ge::graphStatus SetMergeIntraCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) | 436 | ge::graphStatus SetMergeIntraCoreTiling(gert::TilingContext* context, SortKthTileInfo& info) |
| 409 | { | 437 | { |
| 410 | OP_CHECK_IF(!ComputeMergeIntraCoreTiling(context, info), | 438 | OP_CHECK_IF(!ComputeMergeIntraCoreTiling(context, info), |
| 411 | - OP_LOGE(context->GetNodeName(), "merge intra-core plan computation failed"), return ge::GRAPH_FAILED); | 439 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ComputeMergeIntraCoreTiling", "false", |
| 440 | + "The value of ComputeMergeIntraCoreTiling must be true."), | ||
| 441 | + return ge::GRAPH_FAILED); | ||
| 412 | OP_LOGI("MergeIntraCoreTiling", | 442 | OP_LOGI("MergeIntraCoreTiling", |
| 413 | "B %ld, N %ld, batchPerCore %u, actualCoreNum %u, blockSortSize %u, extractChunkSize %u, " | 443 | "B %ld, N %ld, batchPerCore %u, actualCoreNum %u, blockSortSize %u, extractChunkSize %u, " |
| 414 | "blocksPerRow %u, alignNum %u, ubSize %u", | 444 | "blocksPerRow %u, alignNum %u, ubSize %u", |
| @@ -692,7 +722,9 @@ ge::graphStatus SelectSortSchedule(gert::TilingContext* context, SortKthTileInfo | |||
| 692 | if (sortTileInfo.isNonLastAxis) { | 722 | if (sortTileInfo.isNonLastAxis) { |
| 693 | // L0 Sort cannot fall back to full-tensor transpose here. aclnnSort should only | 723 | // L0 Sort cannot fall back to full-tensor transpose here. aclnnSort should only |
| 694 | // dispatch non-last axes that satisfy one of the no-transpose schedules above. | 724 | // dispatch non-last axes that satisfy one of the no-transpose schedules above. |
| 695 | - OP_LOGE(context->GetNodeName(), "non-last sort axis does not meet no-transpose schedule constraints"); | 725 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 726 | + context->GetNodeName(), "sortAxis", std::to_string(sortTileInfo.sortAxis).c_str(), | ||
| 727 | + "The value of sortAxis must be the last axis or meet no-transpose schedule constraints."); | ||
| 696 | return ge::GRAPH_FAILED; | 728 | return ge::GRAPH_FAILED; |
| 697 | } | 729 | } |
| 698 | if (TryMerge(context, sortTileInfo, schId) || TryRadixOneCore(context, sortTileInfo, schId) || | 730 | if (TryMerge(context, sortTileInfo, schId) || TryRadixOneCore(context, sortTileInfo, schId) || |
| @@ -702,7 +734,9 @@ ge::graphStatus SelectSortSchedule(gert::TilingContext* context, SortKthTileInfo | |||
| 702 | 734 | ||
| 703 | schId = SORT_SCHID_2; | 735 | schId = SORT_SCHID_2; |
| 704 | OP_CHECK_IF(SetRadixMoreCoreTiling(context, sortTileInfo) != ge::GRAPH_SUCCESS, | 736 | OP_CHECK_IF(SetRadixMoreCoreTiling(context, sortTileInfo) != ge::GRAPH_SUCCESS, |
| 705 | - OP_LOGE(context->GetNodeName(), "radix more-core tiling failed"), return ge::GRAPH_FAILED); | 737 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SetRadixMoreCoreTiling", "GRAPH_FAILED", |
| 738 | + "The value of SetRadixMoreCoreTiling must be GRAPH_SUCCESS."), | ||
| 739 | + return ge::GRAPH_FAILED); | ||
| 706 | return ge::GRAPH_SUCCESS; | 740 | return ge::GRAPH_SUCCESS; |
| 707 | } | 741 | } |
| 708 | 742 | ||
| @@ -713,13 +747,17 @@ ge::graphStatus RadixSortTiling(gert::TilingContext* context, int32_t maxCoreNum | |||
| 713 | { | 747 | { |
| 714 | SortRegBaseTilingData* sortTilingData{nullptr}; | 748 | SortRegBaseTilingData* sortTilingData{nullptr}; |
| 715 | sortTilingData = context->GetTilingData<SortRegBaseTilingData>(); | 749 | sortTilingData = context->GetTilingData<SortRegBaseTilingData>(); |
| 716 | - OP_CHECK_IF(sortTilingData == nullptr, OP_LOGE(context->GetNodeName(), "get tilingdata ptr failed"), | 750 | + OP_CHECK_IF(sortTilingData == nullptr, OP_LOGE_WITH_INVALID_INPUT(context->GetNodeName(), "tilingData"), |
| 717 | return ge::GRAPH_FAILED); | 751 | return ge::GRAPH_FAILED); |
| 718 | OP_CHECK_IF((memset_s(sortTilingData, sizeof(SortRegBaseTilingData), 0, sizeof(SortRegBaseTilingData)) != EOK), | 752 | OP_CHECK_IF((memset_s(sortTilingData, sizeof(SortRegBaseTilingData), 0, sizeof(SortRegBaseTilingData)) != EOK), |
| 719 | - OP_LOGE(context->GetNodeName(), "memset tilingdata failed"), return ge::GRAPH_FAILED); | 753 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "memset_s", "not EOK", |
| 754 | + "The value of memset_s must be EOK."), | ||
| 755 | + return ge::GRAPH_FAILED); | ||
| 720 | SortKthTileInfo sortTileInfo; | 756 | SortKthTileInfo sortTileInfo; |
| 721 | OP_CHECK_IF(SortCheckParams(context, sortTileInfo) != ge::GRAPH_SUCCESS, | 757 | OP_CHECK_IF(SortCheckParams(context, sortTileInfo) != ge::GRAPH_SUCCESS, |
| 722 | - OP_LOGE(context->GetNodeName(), "check params failed"), return ge::GRAPH_FAILED); | 758 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SortCheckParams", "GRAPH_FAILED", |
| 759 | + "The value of SortCheckParams must be GRAPH_SUCCESS."), | ||
| 760 | + return ge::GRAPH_FAILED); | ||
| 723 | sortTileInfo.maxCoreNum = static_cast<uint32_t>(maxCoreNum); | 761 | sortTileInfo.maxCoreNum = static_cast<uint32_t>(maxCoreNum); |
| 724 | int64_t int32Max = static_cast<int64_t>(std::numeric_limits<int32_t>::max()); | 762 | int64_t int32Max = static_cast<int64_t>(std::numeric_limits<int32_t>::max()); |
| 725 | uint64_t isInt32 = static_cast<uint64_t>((sortTileInfo.lastAxis <= int32Max)); | 763 | uint64_t isInt32 = static_cast<uint64_t>((sortTileInfo.lastAxis <= int32Max)); |
| @@ -730,7 +768,9 @@ ge::graphStatus RadixSortTiling(gert::TilingContext* context, int32_t maxCoreNum | |||
| 730 | OP_LOGI(context->GetNodeName(), "isInt32 is %lu, isDescend is %lu", isInt32, isDescend); | 768 | OP_LOGI(context->GetNodeName(), "isInt32 is %lu, isDescend is %lu", isInt32, isDescend); |
| 731 | uint64_t schId = static_cast<uint64_t>(0); | 769 | uint64_t schId = static_cast<uint64_t>(0); |
| 732 | OP_CHECK_IF(SelectSortSchedule(context, sortTileInfo, schId) != ge::GRAPH_SUCCESS, | 770 | OP_CHECK_IF(SelectSortSchedule(context, sortTileInfo, schId) != ge::GRAPH_SUCCESS, |
| 733 | - OP_LOGE(context->GetNodeName(), "select sort schedule failed"), return ge::GRAPH_FAILED); | 771 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SelectSortSchedule", "GRAPH_FAILED", |
| 772 | + "The value of SelectSortSchedule must be GRAPH_SUCCESS."), | ||
| 773 | + return ge::GRAPH_FAILED); | ||
| 734 | const uint64_t tilingKey = GET_TPL_TILING_KEY(schId, isInt32, isDescend); | 774 | const uint64_t tilingKey = GET_TPL_TILING_KEY(schId, isInt32, isDescend); |
| 735 | OP_LOGI(context->GetNodeName(), "tilingKey is %lu, maxCoreNum %d, schId %lu", tilingKey, maxCoreNum, schId); | 775 | OP_LOGI(context->GetNodeName(), "tilingKey is %lu, maxCoreNum %d, schId %lu", tilingKey, maxCoreNum, schId); |
| 736 | context->SetTilingKey(tilingKey); | 776 | context->SetTilingKey(tilingKey); |
| @@ -12,6 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | 18 | ||
| @@ -79,9 +80,8 @@ uint32_t GetPreferredInnerChunk(ge::DataType dataType, uint32_t index) | |||
| 79 | group = 0; // 8-byte types | 80 | group = 0; // 8-byte types |
| 80 | } else if (dataType == ge::DT_FLOAT || dataType == ge::DT_INT32 || dataType == ge::DT_UINT32) { | 81 | } else if (dataType == ge::DT_FLOAT || dataType == ge::DT_INT32 || dataType == ge::DT_UINT32) { |
| 81 | group = 1; // 4-byte types | 82 | group = 1; // 4-byte types |
| 82 | - } else if ( | 83 | + } else if (dataType == ge::DT_FLOAT16 || dataType == ge::DT_BF16 || dataType == ge::DT_INT16 || |
| 83 | - dataType == ge::DT_FLOAT16 || dataType == ge::DT_BF16 || dataType == ge::DT_INT16 || | 84 | + dataType == ge::DT_UINT16) { |
| 84 | - dataType == ge::DT_UINT16) { | ||
| 85 | group = 2; // 2-byte types | 85 | group = 2; // 2-byte types |
| 86 | } else if (dataType == ge::DT_INT8 || dataType == ge::DT_UINT8) { | 86 | } else if (dataType == ge::DT_INT8 || dataType == ge::DT_UINT8) { |
| 87 | group = 3; // 1-byte types | 87 | group = 3; // 1-byte types |
| @@ -116,16 +116,14 @@ const SmallAxisRule* FindSmallAxisRule(ge::DataType dataType) | |||
| 116 | 116 | ||
| 117 | bool UseTwoStageRankInverse(uint32_t axisLen) { return axisLen <= TWO_STAGE_RANK_INVERSE_MAX_N; } | 117 | bool UseTwoStageRankInverse(uint32_t axisLen) { return axisLen <= TWO_STAGE_RANK_INVERSE_MAX_N; } |
| 118 | 118 | ||
| 119 | -uint32_t ComputeInsertionBytesPerSeg( | 119 | +uint32_t ComputeInsertionBytesPerSeg(ge::DataType dataType, uint32_t axisLen, uint32_t dtypeSize, |
| 120 | - ge::DataType dataType, uint32_t axisLen, uint32_t dtypeSize, uint32_t indexDtypeSize, uint32_t blockUbSize) | 120 | + uint32_t indexDtypeSize, uint32_t blockUbSize) |
| 121 | { | 121 | { |
| 122 | uint64_t valueRawBytes = 0U; | 122 | uint64_t valueRawBytes = 0U; |
| 123 | uint64_t idxRawBytes = 0U; | 123 | uint64_t idxRawBytes = 0U; |
| 124 | - if (ge::MulOverflow(axisLen, dtypeSize, valueRawBytes) || | 124 | + if (ge::MulOverflow(axisLen, dtypeSize, valueRawBytes) || ge::MulOverflow(axisLen, indexDtypeSize, idxRawBytes)) { |
| 125 | - ge::MulOverflow(axisLen, indexDtypeSize, idxRawBytes)) { | 125 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("ComputeInsertionBytesPerSeg", "axisLen", std::to_string(axisLen).c_str(), |
| 126 | - OP_LOGE("ComputeInsertionBytesPerSeg", | 126 | + "The value of axisLen must not cause raw byte size overflow."); |
| 127 | - "raw byte size overflow, axisLen %u, dtypeSize %u, indexDtypeSize %u", axisLen, dtypeSize, | ||
| 128 | - indexDtypeSize); | ||
| 129 | return 0; | 127 | return 0; |
| 130 | } | 128 | } |
| 131 | uint64_t valueBytes = Ops::Base::CeilAlign<uint64_t>(valueRawBytes, blockUbSize); | 129 | uint64_t valueBytes = Ops::Base::CeilAlign<uint64_t>(valueRawBytes, blockUbSize); |
| @@ -135,14 +133,17 @@ uint32_t ComputeInsertionBytesPerSeg( | |||
| 135 | } | 133 | } |
| 136 | uint64_t bytesPerSeg = 0U; | 134 | uint64_t bytesPerSeg = 0U; |
| 137 | if (ge::AddOverflow(valueBytes, idxBytes, bytesPerSeg)) { | 135 | if (ge::AddOverflow(valueBytes, idxBytes, bytesPerSeg)) { |
| 138 | - OP_LOGE("ComputeInsertionBytesPerSeg", "bytesPerSeg overflow, valueBytes %lu, idxBytes %lu", valueBytes, | 136 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("ComputeInsertionBytesPerSeg", "bytesPerSeg", |
| 139 | - idxBytes); | 137 | + (std::to_string(valueBytes) + ", " + std::to_string(idxBytes)).c_str(), |
| 138 | + "The value of valueBytes plus idxBytes must not overflow."); | ||
| 140 | return 0; | 139 | return 0; |
| 141 | } | 140 | } |
| 142 | if (dataType == ge::DT_BF16) { | 141 | if (dataType == ge::DT_BF16) { |
| 143 | uint64_t castRawBytes = 0U; | 142 | uint64_t castRawBytes = 0U; |
| 144 | if (ge::MulOverflow(axisLen, sizeof(int16_t), castRawBytes)) { | 143 | if (ge::MulOverflow(axisLen, sizeof(int16_t), castRawBytes)) { |
| 145 | - OP_LOGE("ComputeInsertionBytesPerSeg", "cast raw byte size overflow, axisLen %u", axisLen); | 144 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("ComputeInsertionBytesPerSeg", "axisLen", |
| 145 | + std::to_string(axisLen).c_str(), | ||
| 146 | + "The value of axisLen must not cause cast raw byte size overflow."); | ||
| 146 | return 0; | 147 | return 0; |
| 147 | } | 148 | } |
| 148 | uint64_t castBytes = Ops::Base::CeilAlign<uint64_t>(castRawBytes, blockUbSize); | 149 | uint64_t castBytes = Ops::Base::CeilAlign<uint64_t>(castRawBytes, blockUbSize); |
| @@ -153,14 +154,18 @@ uint32_t ComputeInsertionBytesPerSeg( | |||
| 153 | if (ge::MulOverflow(castRowElems, sizeof(float), valueBytes) || | 154 | if (ge::MulOverflow(castRowElems, sizeof(float), valueBytes) || |
| 154 | ge::AddOverflow(valueBytes, idxBytes, bytesPerSeg) || | 155 | ge::AddOverflow(valueBytes, idxBytes, bytesPerSeg) || |
| 155 | ge::AddOverflow(bytesPerSeg, castBytes, bytesPerSeg)) { | 156 | ge::AddOverflow(bytesPerSeg, castBytes, bytesPerSeg)) { |
| 156 | - OP_LOGE("ComputeInsertionBytesPerSeg", | 157 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 157 | - "bf16 bytesPerSeg overflow, castRowElems %lu, idxBytes %lu, castBytes %lu", castRowElems, | 158 | + "ComputeInsertionBytesPerSeg", "bytesPerSeg", |
| 158 | - idxBytes, castBytes); | 159 | + (std::to_string(castRowElems) + ", " + std::to_string(idxBytes) + ", " + std::to_string(castBytes)) |
| 160 | + .c_str(), | ||
| 161 | + "The value of bf16 bytesPerSeg must not overflow."); | ||
| 159 | return 0; | 162 | return 0; |
| 160 | } | 163 | } |
| 161 | } | 164 | } |
| 162 | if (bytesPerSeg > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 165 | if (bytesPerSeg > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 163 | - OP_LOGE("ComputeInsertionBytesPerSeg", "bytesPerSeg %lu exceeds uint32_t max", bytesPerSeg); | 166 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("ComputeInsertionBytesPerSeg", "bytesPerSeg", |
| 167 | + std::to_string(bytesPerSeg).c_str(), | ||
| 168 | + "The value of bytesPerSeg must be less than or equal to uint32 max."); | ||
| 164 | return 0; | 169 | return 0; |
| 165 | } | 170 | } |
| 166 | return static_cast<uint32_t>(bytesPerSeg); | 171 | return static_cast<uint32_t>(bytesPerSeg); |
| @@ -239,8 +244,8 @@ bool IsMergeSortSupported(ge::DataType dataType, int64_t axisLen) | |||
| 239 | ((dataType == ge::DT_FLOAT) && (axisLen <= static_cast<int64_t>(MERGE_SORT_MAX_AXIS_FP32))); | 244 | ((dataType == ge::DT_FLOAT) && (axisLen <= static_cast<int64_t>(MERGE_SORT_MAX_AXIS_FP32))); |
| 240 | } | 245 | } |
| 241 | 246 | ||
| 242 | -bool GetNonLastSortTmpSize( | 247 | +bool GetNonLastSortTmpSize(ge::DataType dataType, uint32_t sortCount, bool useMergeSort, bool isDescend, |
| 243 | - ge::DataType dataType, uint32_t sortCount, bool useMergeSort, bool isDescend, uint32_t& tmpUbSize) | 248 | + uint32_t& tmpUbSize) |
| 244 | { | 249 | { |
| 245 | std::vector<int64_t> shapeVec = {static_cast<int64_t>(sortCount)}; | 250 | std::vector<int64_t> shapeVec = {static_cast<int64_t>(sortCount)}; |
| 246 | ge::Shape srcShape(shapeVec); | 251 | ge::Shape srcShape(shapeVec); |
| @@ -251,8 +256,8 @@ bool GetNonLastSortTmpSize( | |||
| 251 | config.hasDstIndex = true; | 256 | config.hasDstIndex = true; |
| 252 | uint32_t maxValue = 0; | 257 | uint32_t maxValue = 0; |
| 253 | uint32_t minValue = 0; | 258 | uint32_t minValue = 0; |
| 254 | - AscendC::GetSortMaxMinTmpSize( | 259 | + AscendC::GetSortMaxMinTmpSize(srcShape, GetNonLastSortDtype(dataType, useMergeSort), ge::DT_UINT32, true, config, |
| 255 | - srcShape, GetNonLastSortDtype(dataType, useMergeSort), ge::DT_UINT32, true, config, maxValue, minValue); | 260 | + maxValue, minValue); |
| 256 | tmpUbSize = maxValue; | 261 | tmpUbSize = maxValue; |
| 257 | return maxValue > 0; | 262 | return maxValue > 0; |
| 258 | } | 263 | } |
| @@ -286,8 +291,8 @@ bool SearchNonLastSmallAxisPlan( | |||
| 286 | if (!estimateUb(candidateInfo, chunk, cur.peakUb, cur) || cur.peakUb > usableUb) { | 291 | if (!estimateUb(candidateInfo, chunk, cur.peakUb, cur) || cur.peakUb > usableUb) { |
| 287 | continue; | 292 | continue; |
| 288 | } | 293 | } |
| 289 | - cur.activeCore = | 294 | + cur.activeCore = static_cast<uint32_t>( |
| 290 | - static_cast<uint32_t>(std::min<uint64_t>(static_cast<uint64_t>(info.maxCoreNum), cur.tileCount)); | 295 | + std::min<uint64_t>(static_cast<uint64_t>(info.maxCoreNum), cur.tileCount)); |
| 291 | bool betterCoreUse = cur.activeCore > best.activeCore; | 296 | bool betterCoreUse = cur.activeCore > best.activeCore; |
| 292 | bool sameCoreUseLargerChunk = cur.activeCore == best.activeCore && cur.innerChunk > best.innerChunk; | 297 | bool sameCoreUseLargerChunk = cur.activeCore == best.activeCore && cur.innerChunk > best.innerChunk; |
| 293 | if (betterCoreUse || sameCoreUseLargerChunk) { | 298 | if (betterCoreUse || sameCoreUseLargerChunk) { |
| @@ -312,9 +317,8 @@ uint32_t ComputeRadixRemainUb(uint32_t usableUb, uint32_t tileData, uint32_t ubE | |||
| 312 | return usableUb - static_cast<uint32_t>(usedUb); | 317 | return usableUb - static_cast<uint32_t>(usedUb); |
| 313 | } | 318 | } |
| 314 | 319 | ||
| 315 | -void AdjustRadixTmpUb( | 320 | +void AdjustRadixTmpUb(uint32_t usableUb, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor, uint32_t blockUbSize, |
| 316 | - uint32_t usableUb, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor, uint32_t blockUbSize, | 321 | + uint32_t& tmpUbSize) |
| 317 | - uint32_t& tmpUbSize) | ||
| 318 | { | 322 | { |
| 319 | if (blockUbSize == 0U) { | 323 | if (blockUbSize == 0U) { |
| 320 | return; | 324 | return; |
| @@ -325,9 +329,9 @@ void AdjustRadixTmpUb( | |||
| 325 | tmpUbSize += (remainUb / blockUbSize) * blockUbSize; | 329 | tmpUbSize += (remainUb / blockUbSize) * blockUbSize; |
| 326 | } | 330 | } |
| 327 | 331 | ||
| 328 | -bool ComputeRadixTileDataForAllCore( | 332 | +bool ComputeRadixTileDataForAllCore(int64_t axisLen, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, |
| 329 | - int64_t axisLen, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, uint32_t tileFactor, | 333 | + uint32_t tileFactor, uint32_t blockUbSize, uint32_t lastDimTileNum, |
| 330 | - uint32_t blockUbSize, uint32_t lastDimTileNum, uint32_t& tileData, uint32_t& tmpUbSize) | 334 | + uint32_t& tileData, uint32_t& tmpUbSize) |
| 331 | { | 335 | { |
| 332 | if (axisLen <= 0 || maxCoreNum == 0U || lastDimTileNum == 0U) { | 336 | if (axisLen <= 0 || maxCoreNum == 0U || lastDimTileNum == 0U) { |
| 333 | return false; | 337 | return false; |
| @@ -366,9 +370,9 @@ bool QuerySortTmpSizeRadix(ge::DataType dataType, uint32_t sortAxisNum, uint32_t | |||
| 366 | return maxValue > 0; | 370 | return maxValue > 0; |
| 367 | } | 371 | } |
| 368 | 372 | ||
| 369 | -static bool AdjustSingleRowSingleTile( | 373 | +static bool AdjustSingleRowSingleTile(int64_t axisLen, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, |
| 370 | - int64_t axisLen, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, uint32_t tileFactor, | 374 | + uint32_t tileFactor, uint32_t blockUbSize, uint32_t& tileData, |
| 371 | - uint32_t blockUbSize, uint32_t& tileData, uint32_t& tmpUbSize, bool& adjusted) | 375 | + uint32_t& tmpUbSize, bool& adjusted) |
| 372 | { | 376 | { |
| 373 | uint32_t newTileData = 0; | 377 | uint32_t newTileData = 0; |
| 374 | if (!CeilDivUint32(static_cast<uint64_t>(axisLen), static_cast<uint64_t>(maxCoreNum), newTileData) || | 378 | if (!CeilDivUint32(static_cast<uint64_t>(axisLen), static_cast<uint64_t>(maxCoreNum), newTileData) || |
| @@ -384,9 +388,9 @@ static bool AdjustSingleRowSingleTile( | |||
| 384 | return true; | 388 | return true; |
| 385 | } | 389 | } |
| 386 | 390 | ||
| 387 | -static bool AdjustBSharedSingleHTile( | 391 | +static bool AdjustBSharedSingleHTile(int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t usableUb, |
| 388 | - int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, uint32_t tileFactor, | 392 | + uint32_t ubExtra, uint32_t tileFactor, uint32_t blockUbSize, uint32_t& tileData, |
| 389 | - uint32_t blockUbSize, uint32_t& tileData, uint32_t& tmpUbSize, bool& adjusted) | 393 | + uint32_t& tmpUbSize, bool& adjusted) |
| 390 | { | 394 | { |
| 391 | uint32_t hCore = maxCoreNum / static_cast<uint32_t>(unsortedDim); | 395 | uint32_t hCore = maxCoreNum / static_cast<uint32_t>(unsortedDim); |
| 392 | if (hCore == 0U) { | 396 | if (hCore == 0U) { |
| @@ -404,9 +408,10 @@ static bool AdjustBSharedSingleHTile( | |||
| 404 | return true; | 408 | return true; |
| 405 | } | 409 | } |
| 406 | 410 | ||
| 407 | -static bool AdjustMultiTileHWithBSharing( | 411 | +static bool AdjustMultiTileHWithBSharing(int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t usableUb, |
| 408 | - int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, uint32_t tileFactor, | 412 | + uint32_t ubExtra, uint32_t tileFactor, uint32_t blockUbSize, |
| 409 | - uint32_t blockUbSize, uint32_t& tileData, uint32_t lastDimTileNum, uint32_t& tmpUbSize, bool& adjusted) | 413 | + uint32_t& tileData, uint32_t lastDimTileNum, uint32_t& tmpUbSize, |
| 414 | + bool& adjusted) | ||
| 410 | { | 415 | { |
| 411 | uint64_t newTileData64 = static_cast<uint64_t>(axisLen) / static_cast<uint64_t>(lastDimTileNum); | 416 | uint64_t newTileData64 = static_cast<uint64_t>(axisLen) / static_cast<uint64_t>(lastDimTileNum); |
| 412 | if (!CeilAlignUint32(newTileData64, BIN_NUM, tileData)) { | 417 | if (!CeilAlignUint32(newTileData64, BIN_NUM, tileData)) { |
| @@ -428,9 +433,8 @@ static bool AdjustMultiTileHWithBSharing( | |||
| 428 | } | 433 | } |
| 429 | } | 434 | } |
| 430 | if (bCore == 1U && adjustedLastDimTileNum < maxCoreNum) { | 435 | if (bCore == 1U && adjustedLastDimTileNum < maxCoreNum) { |
| 431 | - if (!ComputeRadixTileDataForAllCore( | 436 | + if (!ComputeRadixTileDataForAllCore(axisLen, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, |
| 432 | - axisLen, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, adjustedLastDimTileNum, tileData, | 437 | + adjustedLastDimTileNum, tileData, tmpUbSize)) { |
| 433 | - tmpUbSize)) { | ||
| 434 | return false; | 438 | return false; |
| 435 | } | 439 | } |
| 436 | adjusted = true; | 440 | adjusted = true; |
| @@ -444,21 +448,21 @@ static bool AdjustMultiTileHWithBSharing( | |||
| 444 | return true; | 448 | return true; |
| 445 | } | 449 | } |
| 446 | 450 | ||
| 447 | -bool NeedAdjustRadixTileData( | 451 | +bool NeedAdjustRadixTileData(int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t usableUb, |
| 448 | - int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t usableUb, uint32_t ubExtra, uint32_t tileFactor, | 452 | + uint32_t ubExtra, uint32_t tileFactor, uint32_t blockUbSize, uint32_t& tileData, |
| 449 | - uint32_t blockUbSize, uint32_t& tileData, uint32_t lastDimTileNum, uint32_t& tmpUbSize, bool& adjusted) | 453 | + uint32_t lastDimTileNum, uint32_t& tmpUbSize, bool& adjusted) |
| 450 | { | 454 | { |
| 451 | adjusted = false; | 455 | adjusted = false; |
| 452 | if (axisLen <= 0 || maxCoreNum == 0U) { | 456 | if (axisLen <= 0 || maxCoreNum == 0U) { |
| 453 | return false; | 457 | return false; |
| 454 | } | 458 | } |
| 455 | if (unsortedDim == static_cast<int64_t>(1) && lastDimTileNum == 1U) { | 459 | if (unsortedDim == static_cast<int64_t>(1) && lastDimTileNum == 1U) { |
| 456 | - return AdjustSingleRowSingleTile( | 460 | + return AdjustSingleRowSingleTile(axisLen, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, tileData, |
| 457 | - axisLen, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, tileData, tmpUbSize, adjusted); | 461 | + tmpUbSize, adjusted); |
| 458 | } | 462 | } |
| 459 | if (unsortedDim == static_cast<int64_t>(1) || lastDimTileNum >= maxCoreNum) { | 463 | if (unsortedDim == static_cast<int64_t>(1) || lastDimTileNum >= maxCoreNum) { |
| 460 | - if (!ComputeRadixTileDataForAllCore( | 464 | + if (!ComputeRadixTileDataForAllCore(axisLen, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, |
| 461 | - axisLen, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, lastDimTileNum, tileData, tmpUbSize)) { | 465 | + lastDimTileNum, tileData, tmpUbSize)) { |
| 462 | return false; | 466 | return false; |
| 463 | } | 467 | } |
| 464 | adjusted = true; | 468 | adjusted = true; |
| @@ -466,21 +470,19 @@ bool NeedAdjustRadixTileData( | |||
| 466 | } | 470 | } |
| 467 | if (unsortedDim > static_cast<int64_t>(1) && unsortedDim < static_cast<int64_t>(maxCoreNum) && | 471 | if (unsortedDim > static_cast<int64_t>(1) && unsortedDim < static_cast<int64_t>(maxCoreNum) && |
| 468 | lastDimTileNum == 1U) { | 472 | lastDimTileNum == 1U) { |
| 469 | - return AdjustBSharedSingleHTile( | 473 | + return AdjustBSharedSingleHTile(axisLen, unsortedDim, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, |
| 470 | - axisLen, unsortedDim, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, tileData, tmpUbSize, | 474 | + tileData, tmpUbSize, adjusted); |
| 471 | - adjusted); | ||
| 472 | } | 475 | } |
| 473 | if (unsortedDim > static_cast<int64_t>(1) && lastDimTileNum > 1U) { | 476 | if (unsortedDim > static_cast<int64_t>(1) && lastDimTileNum > 1U) { |
| 474 | - return AdjustMultiTileHWithBSharing( | 477 | + return AdjustMultiTileHWithBSharing(axisLen, unsortedDim, maxCoreNum, usableUb, ubExtra, tileFactor, |
| 475 | - axisLen, unsortedDim, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, tileData, lastDimTileNum, | 478 | + blockUbSize, tileData, lastDimTileNum, tmpUbSize, adjusted); |
| 476 | - tmpUbSize, adjusted); | ||
| 477 | } | 479 | } |
| 478 | return true; | 480 | return true; |
| 479 | } | 481 | } |
| 480 | 482 | ||
| 481 | -bool ComputeRadixTileData( | 483 | +bool ComputeRadixTileData(int64_t axisLen, int64_t unsortedDim, uint32_t dtypeSize, uint32_t indexSize, |
| 482 | - int64_t axisLen, int64_t unsortedDim, uint32_t dtypeSize, uint32_t indexSize, uint32_t maxCoreNum, | 484 | + uint32_t maxCoreNum, uint32_t usableUb, uint32_t blockUbSize, uint32_t& tileData, |
| 483 | - uint32_t usableUb, uint32_t blockUbSize, uint32_t& tileData, uint32_t& tmpUbSize) | 485 | + uint32_t& tmpUbSize) |
| 484 | { | 486 | { |
| 485 | if (maxCoreNum == 0U) { | 487 | if (maxCoreNum == 0U) { |
| 486 | return false; | 488 | return false; |
| @@ -518,9 +520,8 @@ bool ComputeRadixTileData( | |||
| 518 | bool adjusted = false; | 520 | bool adjusted = false; |
| 519 | if ((lastDimTileNum % maxCoreNum == 0U) || smallTile) { | 521 | if ((lastDimTileNum % maxCoreNum == 0U) || smallTile) { |
| 520 | AdjustRadixTmpUb(usableUb, tileData, ubExtra, tileFactor, blockUbSize, tmpUbSize); | 522 | AdjustRadixTmpUb(usableUb, tileData, ubExtra, tileFactor, blockUbSize, tmpUbSize); |
| 521 | - } else if (!NeedAdjustRadixTileData( | 523 | + } else if (!NeedAdjustRadixTileData(axisLen, unsortedDim, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, |
| 522 | - axisLen, unsortedDim, maxCoreNum, usableUb, ubExtra, tileFactor, blockUbSize, tileData, | 524 | + tileData, lastDimTileNum, tmpUbSize, adjusted)) { |
| 523 | - lastDimTileNum, tmpUbSize, adjusted)) { | ||
| 524 | return false; | 525 | return false; |
| 525 | } else if (!adjusted) { | 526 | } else if (!adjusted) { |
| 526 | AdjustRadixTmpUb(usableUb, tileData, ubExtra, tileFactor, blockUbSize, tmpUbSize); | 527 | AdjustRadixTmpUb(usableUb, tileData, ubExtra, tileFactor, blockUbSize, tmpUbSize); |
| @@ -528,9 +529,9 @@ bool ComputeRadixTileData( | |||
| 528 | return true; | 529 | return true; |
| 529 | } | 530 | } |
| 530 | 531 | ||
| 531 | -bool FillRadixKernelParams( | 532 | +bool FillRadixKernelParams(uint32_t dtypeSize, uint32_t indexSize, uint32_t coreNumNeed, uint32_t lastDimTileNum, |
| 532 | - uint32_t dtypeSize, uint32_t indexSize, uint32_t coreNumNeed, uint32_t lastDimTileNum, uint32_t unsortedDimParallel, | 533 | + uint32_t unsortedDimParallel, uint32_t blockUbSize, uint32_t tmpUbSize, |
| 533 | - uint32_t blockUbSize, uint32_t tmpUbSize, RadixClearParams& out) | 534 | + RadixClearParams& out) |
| 534 | { | 535 | { |
| 535 | if (indexSize == 0U) { | 536 | if (indexSize == 0U) { |
| 536 | return false; | 537 | return false; |
| @@ -563,26 +564,26 @@ bool FillRadixKernelParams( | |||
| 563 | return true; | 564 | return true; |
| 564 | } | 565 | } |
| 565 | 566 | ||
| 566 | -bool ComputeRadixSortWorkspace( | 567 | +bool ComputeRadixSortWorkspace(int64_t axisLen, uint32_t dtypeSize, uint32_t indexSize, uint32_t lastDimTileNum, |
| 567 | - int64_t axisLen, uint32_t dtypeSize, uint32_t indexSize, uint32_t lastDimTileNum, uint32_t numTileDataSize, | 568 | + uint32_t numTileDataSize, uint32_t unsortedDimParallel, uint32_t keyParams0, |
| 568 | - uint32_t unsortedDimParallel, uint32_t keyParams0, uint32_t keyParams1, uint32_t keyParams2, uint32_t keyParams3, | 569 | + uint32_t keyParams1, uint32_t keyParams2, uint32_t keyParams3, uint32_t keyParams4, |
| 569 | - uint32_t keyParams4, uint32_t blockUbSize, uint64_t& workspaceSize) | 570 | + uint32_t blockUbSize, uint64_t& workspaceSize) |
| 570 | { | 571 | { |
| 571 | uint64_t indexSize64 = static_cast<uint64_t>(indexSize); | 572 | uint64_t indexSize64 = static_cast<uint64_t>(indexSize); |
| 572 | uint64_t blockUbSize64 = static_cast<uint64_t>(blockUbSize); | 573 | uint64_t blockUbSize64 = static_cast<uint64_t>(blockUbSize); |
| 573 | uint64_t unsortedDimParallel64 = static_cast<uint64_t>(unsortedDimParallel); | 574 | uint64_t unsortedDimParallel64 = static_cast<uint64_t>(unsortedDimParallel); |
| 574 | uint64_t axisLen64 = static_cast<uint64_t>(axisLen); | 575 | uint64_t axisLen64 = static_cast<uint64_t>(axisLen); |
| 575 | 576 | ||
| 576 | - uint64_t excusiveBins = | 577 | + uint64_t excusiveBins = Ops::Base::CeilAlign(static_cast<uint64_t>(keyParams1) * keyParams4 * indexSize64, |
| 577 | - Ops::Base::CeilAlign(static_cast<uint64_t>(keyParams1) * keyParams4 * indexSize64, blockUbSize64); | 578 | + blockUbSize64); |
| 578 | - uint64_t globalHist = | 579 | + uint64_t globalHist = Ops::Base::CeilAlign( |
| 579 | - Ops::Base::CeilAlign(static_cast<uint64_t>(keyParams3) * keyParams2 * keyParams0 * indexSize64, blockUbSize64); | 580 | + static_cast<uint64_t>(keyParams3) * keyParams2 * keyParams0 * indexSize64, blockUbSize64); |
| 580 | uint64_t sortedIdx = Ops::Base::CeilAlign(axisLen64 * unsortedDimParallel64 * indexSize64, blockUbSize64); | 581 | uint64_t sortedIdx = Ops::Base::CeilAlign(axisLen64 * unsortedDimParallel64 * indexSize64, blockUbSize64); |
| 581 | uint64_t histTile = static_cast<uint64_t>(lastDimTileNum) * BIN_NUM * unsortedDimParallel64 * sizeof(uint16_t) * 2U; | 582 | uint64_t histTile = static_cast<uint64_t>(lastDimTileNum) * BIN_NUM * unsortedDimParallel64 * sizeof(uint16_t) * 2U; |
| 582 | - uint64_t xB8 = Ops::Base::CeilAlign( | 583 | + uint64_t xB8 = Ops::Base::CeilAlign(static_cast<uint64_t>(lastDimTileNum) * numTileDataSize * unsortedDimParallel64, |
| 583 | - static_cast<uint64_t>(lastDimTileNum) * numTileDataSize * unsortedDimParallel64, blockUbSize64); | 584 | + blockUbSize64); |
| 584 | - uint64_t sortedValue = | 585 | + uint64_t sortedValue = Ops::Base::CeilAlign(axisLen64 * unsortedDimParallel64 * static_cast<uint64_t>(dtypeSize), |
| 585 | - Ops::Base::CeilAlign(axisLen64 * unsortedDimParallel64 * static_cast<uint64_t>(dtypeSize), blockUbSize64); | 586 | + blockUbSize64); |
| 586 | 587 | ||
| 587 | workspaceSize = excusiveBins + globalHist + sortedIdx + histTile + xB8 + sortedValue; | 588 | workspaceSize = excusiveBins + globalHist + sortedIdx + histTile + xB8 + sortedValue; |
| 588 | return true; | 589 | return true; |
| @@ -591,13 +592,12 @@ bool ComputeRadixSortWorkspace( | |||
| 591 | bool FillRadixMoreCoreInfo(SortKthTileInfo& info) | 592 | bool FillRadixMoreCoreInfo(SortKthTileInfo& info) |
| 592 | { | 593 | { |
| 593 | uint32_t usableUb = info.ubSize > SIMT_UB ? info.ubSize - SIMT_UB : 0; | 594 | uint32_t usableUb = info.ubSize > SIMT_UB ? info.ubSize - SIMT_UB : 0; |
| 594 | - uint32_t indexSize = | 595 | + uint32_t indexSize = info.isInt32 != 0 ? static_cast<uint32_t>(sizeof(int32_t)) : |
| 595 | - info.isInt32 != 0 ? static_cast<uint32_t>(sizeof(int32_t)) : static_cast<uint32_t>(sizeof(int64_t)); | 596 | + static_cast<uint32_t>(sizeof(int64_t)); |
| 596 | uint32_t tileData = 0; | 597 | uint32_t tileData = 0; |
| 597 | uint32_t tmpUbSize = 0; | 598 | uint32_t tmpUbSize = 0; |
| 598 | - if (!ComputeRadixTileData( | 599 | + if (!ComputeRadixTileData(info.lastAxis, info.unsortedDim, info.dtypeSize, indexSize, info.maxCoreNum, usableUb, |
| 599 | - info.lastAxis, info.unsortedDim, info.dtypeSize, indexSize, info.maxCoreNum, usableUb, info.blockUbSize, | 600 | + info.blockUbSize, tileData, tmpUbSize)) { |
| 600 | - tileData, tmpUbSize)) { | ||
| 601 | return false; | 601 | return false; |
| 602 | } | 602 | } |
| 603 | info.tmpUbSize = tmpUbSize; | 603 | info.tmpUbSize = tmpUbSize; |
| @@ -614,8 +614,8 @@ bool FillRadixMoreCoreInfo(SortKthTileInfo& info) | |||
| 614 | } | 614 | } |
| 615 | } | 615 | } |
| 616 | info.numTileDataSize = tileData; | 616 | info.numTileDataSize = tileData; |
| 617 | - uint64_t sortLoopTimes64 = | 617 | + uint64_t sortLoopTimes64 = (static_cast<uint64_t>(info.unsortedDim) + info.unsortedDimParallel - 1U) / |
| 618 | - (static_cast<uint64_t>(info.unsortedDim) + info.unsortedDimParallel - 1U) / info.unsortedDimParallel; | 618 | + info.unsortedDimParallel; |
| 619 | if (sortLoopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { | 619 | if (sortLoopTimes64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) { |
| 620 | return false; | 620 | return false; |
| 621 | } | 621 | } |
| @@ -624,9 +624,8 @@ bool FillRadixMoreCoreInfo(SortKthTileInfo& info) | |||
| 624 | info.coreNumNeed = info.unsortedDimParallel * info.lastDimNeedCore; | 624 | info.coreNumNeed = info.unsortedDimParallel * info.lastDimNeedCore; |
| 625 | info.lastDimTileNum = lastDimTileNum; | 625 | info.lastDimTileNum = lastDimTileNum; |
| 626 | RadixClearParams clearParams; | 626 | RadixClearParams clearParams; |
| 627 | - if (!FillRadixKernelParams( | 627 | + if (!FillRadixKernelParams(info.dtypeSize, indexSize, info.coreNumNeed, lastDimTileNum, info.unsortedDimParallel, |
| 628 | - info.dtypeSize, indexSize, info.coreNumNeed, lastDimTileNum, info.unsortedDimParallel, info.blockUbSize, | 628 | + info.blockUbSize, tmpUbSize, clearParams)) { |
| 629 | - tmpUbSize, clearParams)) { | ||
| 630 | return false; | 629 | return false; |
| 631 | } | 630 | } |
| 632 | info.keyParams0 = clearParams.keyParams0; | 631 | info.keyParams0 = clearParams.keyParams0; |
| @@ -636,19 +635,17 @@ bool FillRadixMoreCoreInfo(SortKthTileInfo& info) | |||
| 636 | info.keyParams4 = clearParams.keyParams4; | 635 | info.keyParams4 = clearParams.keyParams4; |
| 637 | info.keyParams5 = clearParams.keyParams5; | 636 | info.keyParams5 = clearParams.keyParams5; |
| 638 | uint64_t sortWorkspaceSize = 0; | 637 | uint64_t sortWorkspaceSize = 0; |
| 639 | - if (!ComputeRadixSortWorkspace( | 638 | + if (!ComputeRadixSortWorkspace(info.lastAxis, info.dtypeSize, indexSize, lastDimTileNum, info.numTileDataSize, |
| 640 | - info.lastAxis, info.dtypeSize, indexSize, lastDimTileNum, info.numTileDataSize, info.unsortedDimParallel, | 639 | + info.unsortedDimParallel, info.keyParams0, info.keyParams1, info.keyParams2, |
| 641 | - info.keyParams0, info.keyParams1, info.keyParams2, info.keyParams3, info.keyParams4, info.blockUbSize, | 640 | + info.keyParams3, info.keyParams4, info.blockUbSize, sortWorkspaceSize)) { |
| 642 | - sortWorkspaceSize)) { | ||
| 643 | return false; | 641 | return false; |
| 644 | } | 642 | } |
| 645 | info.workspaceSize = static_cast<size_t>(sortWorkspaceSize + WORK_SPACE_SIZE); | 643 | info.workspaceSize = static_cast<size_t>(sortWorkspaceSize + WORK_SPACE_SIZE); |
| 646 | return true; | 644 | return true; |
| 647 | } | 645 | } |
| 648 | 646 | ||
| 649 | -bool ComputeRadixOneCoreUbSizes( | 647 | +bool ComputeRadixOneCoreUbSizes(int64_t lastAxis, uint32_t dtypeSize, uint32_t indexElemSize, uint32_t blockUbSize, |
| 650 | - int64_t lastAxis, uint32_t dtypeSize, uint32_t indexElemSize, uint32_t blockUbSize, uint32_t& xUbSize, | 648 | + uint32_t& xUbSize, uint32_t& idxUbSize) |
| 651 | - uint32_t& idxUbSize) | ||
| 652 | { | 649 | { |
| 653 | uint64_t xBytes = static_cast<uint64_t>(lastAxis) * dtypeSize; | 650 | uint64_t xBytes = static_cast<uint64_t>(lastAxis) * dtypeSize; |
| 654 | uint64_t idxBytes = static_cast<uint64_t>(lastAxis) * indexElemSize; | 651 | uint64_t idxBytes = static_cast<uint64_t>(lastAxis) * indexElemSize; |
| @@ -658,9 +655,8 @@ bool ComputeRadixOneCoreUbSizes( | |||
| 658 | // ============================================================================= | 655 | // ============================================================================= |
| 659 | // Merge sort — common | 656 | // Merge sort — common |
| 660 | // ============================================================================= | 657 | // ============================================================================= |
| 661 | -bool ComputeMergeSortPlan( | 658 | +bool ComputeMergeSortPlan(int64_t axisLen, int64_t unsortedDim, uint32_t blockUbSize, uint32_t tileDataNum, |
| 662 | - int64_t axisLen, int64_t unsortedDim, uint32_t blockUbSize, uint32_t tileDataNum, uint32_t maxCoreNum, | 659 | + uint32_t maxCoreNum, MergeSortPlan& plan) |
| 663 | - MergeSortPlan& plan) | ||
| 664 | { | 660 | { |
| 665 | uint64_t alignNum64 = Ops::Base::CeilAlign(static_cast<uint64_t>(axisLen), static_cast<uint64_t>(blockUbSize)); | 661 | uint64_t alignNum64 = Ops::Base::CeilAlign(static_cast<uint64_t>(axisLen), static_cast<uint64_t>(blockUbSize)); |
| 666 | if (alignNum64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) || alignNum64 == 0U) { | 662 | if (alignNum64 > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) || alignNum64 == 0U) { |
| @@ -694,8 +690,8 @@ bool FillMergeSortInfo(SortKthTileInfo& info, uint32_t indexDtypeSize, uint32_t | |||
| 694 | { | 690 | { |
| 695 | constexpr uint32_t TILE_DATA_NUM = 4096; | 691 | constexpr uint32_t TILE_DATA_NUM = 4096; |
| 696 | MergeSortPlan plan; | 692 | MergeSortPlan plan; |
| 697 | - if (!ComputeMergeSortPlan( | 693 | + if (!ComputeMergeSortPlan(info.lastAxis, info.unsortedDim, info.blockUbSize, TILE_DATA_NUM, info.maxCoreNum, |
| 698 | - info.lastAxis, info.unsortedDim, info.blockUbSize, TILE_DATA_NUM, info.maxCoreNum, plan)) { | 694 | + plan)) { |
| 699 | return false; | 695 | return false; |
| 700 | } | 696 | } |
| 701 | info.sortLoopTimes = plan.sortLoopTimes; | 697 | info.sortLoopTimes = plan.sortLoopTimes; |
| @@ -718,8 +714,8 @@ bool ComputeMergeSortTiling(gert::TilingContext* context, SortKthTileInfo& info, | |||
| 718 | { | 714 | { |
| 719 | constexpr uint32_t TILE_DATA_NUM = 4096; | 715 | constexpr uint32_t TILE_DATA_NUM = 4096; |
| 720 | MergeSortPlan plan; | 716 | MergeSortPlan plan; |
| 721 | - if (!ComputeMergeSortPlan( | 717 | + if (!ComputeMergeSortPlan(info.lastAxis, info.unsortedDim, info.blockUbSize, TILE_DATA_NUM, info.maxCoreNum, |
| 722 | - info.lastAxis, info.unsortedDim, info.blockUbSize, TILE_DATA_NUM, info.maxCoreNum, plan)) { | 718 | + plan)) { |
| 723 | return false; | 719 | return false; |
| 724 | } | 720 | } |
| 725 | auto platformInfo = context->GetPlatformInfo(); | 721 | auto platformInfo = context->GetPlatformInfo(); |
| @@ -747,8 +743,8 @@ bool IsMergeMoreCoreSupported(ge::DataType dataType, int64_t axisLen, int64_t un | |||
| 747 | return hCoreNum > 0 && static_cast<uint64_t>(unsortedDim) * hCoreNum <= maxCoreNum; | 743 | return hCoreNum > 0 && static_cast<uint64_t>(unsortedDim) * hCoreNum <= maxCoreNum; |
| 748 | } | 744 | } |
| 749 | 745 | ||
| 750 | -bool ComputeMergeMoreCorePlan( | 746 | +bool ComputeMergeMoreCorePlan(int64_t axisLen, int64_t unsortedDim, uint32_t ubSize, uint32_t mergeBytesPerElem, |
| 751 | - int64_t axisLen, int64_t unsortedDim, uint32_t ubSize, uint32_t mergeBytesPerElem, MergeMoreCorePlan& plan) | 747 | + MergeMoreCorePlan& plan) |
| 752 | { | 748 | { |
| 753 | if (axisLen <= 0 || unsortedDim <= 0 || mergeBytesPerElem == 0U) { | 749 | if (axisLen <= 0 || unsortedDim <= 0 || mergeBytesPerElem == 0U) { |
| 754 | return false; | 750 | return false; |
| @@ -791,8 +787,8 @@ bool FillMergeMoreCoreInfo(SortKthTileInfo& info, uint32_t mergeBytesPerElem) | |||
| 791 | info.sortLoopTimes = plan.sortLoopTimes; | 787 | info.sortLoopTimes = plan.sortLoopTimes; |
| 792 | info.coreNumNeed = plan.coreNumNeed; | 788 | info.coreNumNeed = plan.coreNumNeed; |
| 793 | info.keyParams0 = plan.keyParams0; | 789 | info.keyParams0 = plan.keyParams0; |
| 794 | - uint64_t wsBytes = | 790 | + uint64_t wsBytes = static_cast<uint64_t>(MERGE_SORT_WORKSPACE_PARAM) * info.lastAxis * info.unsortedDim * |
| 795 | - static_cast<uint64_t>(MERGE_SORT_WORKSPACE_PARAM) * info.lastAxis * info.unsortedDim * sizeof(int32_t); | 791 | + sizeof(int32_t); |
| 796 | info.workspaceSize = static_cast<size_t>(wsBytes + WORK_SPACE_SIZE); | 792 | info.workspaceSize = static_cast<size_t>(wsBytes + WORK_SPACE_SIZE); |
| 797 | return true; | 793 | return true; |
| 798 | } | 794 | } |
| @@ -820,14 +816,14 @@ uint32_t ComputeMergeIntraCoreBlockSortSize(uint32_t ubSize) | |||
| 820 | 816 | ||
| 821 | uint32_t ComputeMergeIntraCoreExtractChunkSize(uint32_t ubSize) | 817 | uint32_t ComputeMergeIntraCoreExtractChunkSize(uint32_t ubSize) |
| 822 | { | 818 | { |
| 823 | - constexpr uint32_t PHASE3_BYTES_PER_ELEM = | 819 | + constexpr uint32_t PHASE3_BYTES_PER_ELEM = (SORT_STRUCT_BYTES + sizeof(float) + sizeof(int32_t) + sizeof(int64_t)) * |
| 824 | - (SORT_STRUCT_BYTES + sizeof(float) + sizeof(int32_t) + sizeof(int64_t)) * 2; | 820 | + 2; |
| 825 | uint32_t extractChunkSize = ubSize / PHASE3_BYTES_PER_ELEM; | 821 | uint32_t extractChunkSize = ubSize / PHASE3_BYTES_PER_ELEM; |
| 826 | return (extractChunkSize / MERGE_INTRA_CORE_SORT_ALIGN) * MERGE_INTRA_CORE_SORT_ALIGN; | 822 | return (extractChunkSize / MERGE_INTRA_CORE_SORT_ALIGN) * MERGE_INTRA_CORE_SORT_ALIGN; |
| 827 | } | 823 | } |
| 828 | 824 | ||
| 829 | -bool IsMergeIntraCoreSupported( | 825 | +bool IsMergeIntraCoreSupported(ge::DataType dataType, int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, |
| 830 | - ge::DataType dataType, int64_t axisLen, int64_t unsortedDim, uint32_t maxCoreNum, uint32_t ubSize) | 826 | + uint32_t ubSize) |
| 831 | { | 827 | { |
| 832 | if (dataType != ge::DT_FLOAT || axisLen <= static_cast<int64_t>(MERGE_SORT_MAX_AXIS_FP32) || | 828 | if (dataType != ge::DT_FLOAT || axisLen <= static_cast<int64_t>(MERGE_SORT_MAX_AXIS_FP32) || |
| 833 | unsortedDim < static_cast<int64_t>(maxCoreNum / 2)) { | 829 | unsortedDim < static_cast<int64_t>(maxCoreNum / 2)) { |
| @@ -845,8 +841,8 @@ bool IsMergeIntraCoreSupported( | |||
| 845 | return axisLen <= static_cast<int64_t>(blockSortSize) * MERGE_INTRA_CORE_MAX_BLOCKS; | 841 | return axisLen <= static_cast<int64_t>(blockSortSize) * MERGE_INTRA_CORE_MAX_BLOCKS; |
| 846 | } | 842 | } |
| 847 | 843 | ||
| 848 | -bool ComputeMergeIntraCorePlan( | 844 | +bool ComputeMergeIntraCorePlan(int64_t axisLen, int64_t unsortedDim, uint32_t ubSize, uint32_t maxCoreNum, |
| 849 | - int64_t axisLen, int64_t unsortedDim, uint32_t ubSize, uint32_t maxCoreNum, MergeIntraCorePlan& plan) | 845 | + MergeIntraCorePlan& plan) |
| 850 | { | 846 | { |
| 851 | if (axisLen <= 0 || unsortedDim <= 0 || maxCoreNum == 0U) { | 847 | if (axisLen <= 0 || unsortedDim <= 0 || maxCoreNum == 0U) { |
| 852 | return false; | 848 | return false; |
| @@ -920,8 +916,8 @@ bool ComputeMergeIntraCoreTiling(gert::TilingContext* context, SortKthTileInfo& | |||
| 920 | // ============================================================================= | 916 | // ============================================================================= |
| 921 | // Two-stage sort | 917 | // Two-stage sort |
| 922 | // ============================================================================= | 918 | // ============================================================================= |
| 923 | -bool SearchTwoStageBatchPlan( | 919 | +bool SearchTwoStageBatchPlan(uint32_t maxBatch, std::function<bool(uint32_t, TwoStageBatchPlan&)> tryCandidate, |
| 924 | - uint32_t maxBatch, std::function<bool(uint32_t, TwoStageBatchPlan&)> tryCandidate, TwoStageBatchPlan& result) | 920 | + TwoStageBatchPlan& result) |
| 925 | { | 921 | { |
| 926 | if (maxBatch == 0U) { | 922 | if (maxBatch == 0U) { |
| 927 | return false; | 923 | return false; |
| @@ -979,8 +975,8 @@ uint32_t MaxTwoStageU16SafeBatch(uint32_t axisLen) | |||
| 979 | return maxBatch; | 975 | return maxBatch; |
| 980 | } | 976 | } |
| 981 | 977 | ||
| 982 | -bool ComputeTwoStageSortTmpUb( | 978 | +bool ComputeTwoStageSortTmpUb(ge::DataType dataType, uint32_t axisLen, uint32_t totalElems, uint32_t blockUbSize, |
| 983 | - ge::DataType dataType, uint32_t axisLen, uint32_t totalElems, uint32_t blockUbSize, uint32_t& tmpUbSize) | 979 | + uint32_t& tmpUbSize) |
| 984 | { | 980 | { |
| 985 | tmpUbSize = 0; | 981 | tmpUbSize = 0; |
| 986 | QuerySortTmpSizeRadix(dataType, totalElems, tmpUbSize); | 982 | QuerySortTmpSizeRadix(dataType, totalElems, tmpUbSize); |
| @@ -1010,9 +1006,9 @@ uint64_t EstimateTwoStageUbBytes(const SortKthTileInfo& info, uint32_t totalElem | |||
| 1010 | if (ge::MulOverflow(totalElems, info.dtypeSize, valueRawBytes) || | 1006 | if (ge::MulOverflow(totalElems, info.dtypeSize, valueRawBytes) || |
| 1011 | ge::MulOverflow(totalElems, sizeof(uint32_t), idxRawBytes) || | 1007 | ge::MulOverflow(totalElems, sizeof(uint32_t), idxRawBytes) || |
| 1012 | ge::MulOverflow(totalElems, info.y2DtypeSize, aliasRawBytes)) { | 1008 | ge::MulOverflow(totalElems, info.y2DtypeSize, aliasRawBytes)) { |
| 1013 | - OP_LOGE("EstimateTwoStageUbBytes", | 1009 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("EstimateTwoStageUbBytes", "totalElems", |
| 1014 | - "raw byte size overflow, totalElems %u, dtypeSize %u, y2DtypeSize %u", totalElems, info.dtypeSize, | 1010 | + std::to_string(totalElems).c_str(), |
| 1015 | - info.y2DtypeSize); | 1011 | + "The value of totalElems must not cause raw byte size overflow."); |
| 1016 | return std::numeric_limits<uint64_t>::max(); | 1012 | return std::numeric_limits<uint64_t>::max(); |
| 1017 | } | 1013 | } |
| 1018 | uint64_t valueBytes = Ops::Base::CeilAlign<uint64_t>(valueRawBytes, info.blockUbSize); | 1014 | uint64_t valueBytes = Ops::Base::CeilAlign<uint64_t>(valueRawBytes, info.blockUbSize); |
| @@ -1024,23 +1020,22 @@ uint64_t EstimateTwoStageUbBytes(const SortKthTileInfo& info, uint32_t totalElem | |||
| 1024 | uint32_t idxBufferCount = UseTwoStageRankInverse(static_cast<uint32_t>(info.lastAxis)) ? 2U : 3U; | 1020 | uint32_t idxBufferCount = UseTwoStageRankInverse(static_cast<uint32_t>(info.lastAxis)) ? 2U : 3U; |
| 1025 | uint64_t totalBytes = 0U; | 1021 | uint64_t totalBytes = 0U; |
| 1026 | uint64_t idxTotalBytes = 0U; | 1022 | uint64_t idxTotalBytes = 0U; |
| 1027 | - if (ge::MulOverflow(valueBytes, 2U, totalBytes) || | 1023 | + if (ge::MulOverflow(valueBytes, 2U, totalBytes) || ge::MulOverflow(idxBytes, idxBufferCount, idxTotalBytes) || |
| 1028 | - ge::MulOverflow(idxBytes, idxBufferCount, idxTotalBytes) || | 1024 | + ge::AddOverflow(totalBytes, idxTotalBytes, totalBytes) || ge::AddOverflow(totalBytes, aliasBytes, totalBytes) || |
| 1029 | - ge::AddOverflow(totalBytes, idxTotalBytes, totalBytes) || | ||
| 1030 | - ge::AddOverflow(totalBytes, aliasBytes, totalBytes) || | ||
| 1031 | ge::AddOverflow(totalBytes, sortTmpUb, totalBytes)) { | 1025 | ge::AddOverflow(totalBytes, sortTmpUb, totalBytes)) { |
| 1032 | - OP_LOGE("EstimateTwoStageUbBytes", | 1026 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| 1033 | - "total byte size overflow, valueBytes %lu, idxBytes %lu, idxBufferCount %u, aliasBytes %lu, " | 1027 | + "EstimateTwoStageUbBytes", "totalBytes", |
| 1034 | - "sortTmpUb %u", | 1028 | + (std::to_string(valueBytes) + ", " + std::to_string(idxBytes) + ", " + std::to_string(idxBufferCount) + |
| 1035 | - valueBytes, idxBytes, idxBufferCount, aliasBytes, sortTmpUb); | 1029 | + ", " + std::to_string(aliasBytes) + ", " + std::to_string(sortTmpUb)) |
| 1030 | + .c_str(), | ||
| 1031 | + "The value of totalBytes must not overflow."); | ||
| 1036 | return std::numeric_limits<uint64_t>::max(); | 1032 | return std::numeric_limits<uint64_t>::max(); |
| 1037 | } | 1033 | } |
| 1038 | return totalBytes; | 1034 | return totalBytes; |
| 1039 | } | 1035 | } |
| 1040 | 1036 | ||
| 1041 | -bool PrepareTwoStageBatchCandidate( | 1037 | +bool PrepareTwoStageBatchCandidate(const SortKthTileInfo& info, uint32_t candidate, uint32_t& totalElems, |
| 1042 | - const SortKthTileInfo& info, uint32_t candidate, uint32_t& totalElems, uint32_t& tmpUbSize, bool& useRankInverse, | 1038 | + uint32_t& tmpUbSize, bool& useRankInverse, uint64_t& totalBytes) |
| 1043 | - uint64_t& totalBytes) | ||
| 1044 | { | 1039 | { |
| 1045 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); | 1040 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); |
| 1046 | uint64_t totalElems64 = static_cast<uint64_t>(candidate) * axisLen; | 1041 | uint64_t totalElems64 = static_cast<uint64_t>(candidate) * axisLen; |
| @@ -1057,14 +1052,14 @@ bool PrepareTwoStageBatchCandidate( | |||
| 1057 | return true; | 1052 | return true; |
| 1058 | } | 1053 | } |
| 1059 | 1054 | ||
| 1060 | -static bool ComputeSmallAxisInsertionBatchParams( | 1055 | +static bool ComputeSmallAxisInsertionBatchParams(const SortKthTileInfo& info, uint32_t axisLen, uint32_t& bytesPerSeg, |
| 1061 | - const SortKthTileInfo& info, uint32_t axisLen, uint32_t& bytesPerSeg, uint32_t& usableUb, uint32_t& maxBatchByUb) | 1056 | + uint32_t& usableUb, uint32_t& maxBatchByUb) |
| 1062 | { | 1057 | { |
| 1063 | if (info.ubSize <= SIMT_UB) { | 1058 | if (info.ubSize <= SIMT_UB) { |
| 1064 | return false; | 1059 | return false; |
| 1065 | } | 1060 | } |
| 1066 | - bytesPerSeg = | 1061 | + bytesPerSeg = ComputeInsertionBytesPerSeg(info.dataType, axisLen, info.dtypeSize, info.y2DtypeSize, |
| 1067 | - ComputeInsertionBytesPerSeg(info.dataType, axisLen, info.dtypeSize, info.y2DtypeSize, info.blockUbSize); | 1062 | + info.blockUbSize); |
| 1068 | if (bytesPerSeg == 0U) { | 1063 | if (bytesPerSeg == 0U) { |
| 1069 | return false; | 1064 | return false; |
| 1070 | } | 1065 | } |
| @@ -1074,8 +1069,8 @@ static bool ComputeSmallAxisInsertionBatchParams( | |||
| 1074 | } | 1069 | } |
| 1075 | 1070 | ||
| 1076 | template <typename ComputeBatchNumFn> | 1071 | template <typename ComputeBatchNumFn> |
| 1077 | -static bool EstimateSmallAxisInsertionBatching( | 1072 | +static bool EstimateSmallAxisInsertionBatching(const SortKthTileInfo& info, uint32_t batchSizeCap, |
| 1078 | - const SortKthTileInfo& info, uint32_t batchSizeCap, ComputeBatchNumFn computeBatchNum, SmallAxisRoutePlan& plan) | 1073 | + ComputeBatchNumFn computeBatchNum, SmallAxisRoutePlan& plan) |
| 1079 | { | 1074 | { |
| 1080 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); | 1075 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); |
| 1081 | uint32_t bytesPerSeg = 0; | 1076 | uint32_t bytesPerSeg = 0; |
| @@ -1098,8 +1093,8 @@ static bool EstimateSmallAxisInsertionBatching( | |||
| 1098 | } | 1093 | } |
| 1099 | 1094 | ||
| 1100 | template <typename ComputeBatchNumFn> | 1095 | template <typename ComputeBatchNumFn> |
| 1101 | -static bool TrySmallAxisTwoStageBatchCandidate( | 1096 | +static bool TrySmallAxisTwoStageBatchCandidate(const SortKthTileInfo& info, uint32_t candidate, |
| 1102 | - const SortKthTileInfo& info, uint32_t candidate, ComputeBatchNumFn computeBatchNum, SmallAxisRoutePlan& plan) | 1097 | + ComputeBatchNumFn computeBatchNum, SmallAxisRoutePlan& plan) |
| 1103 | { | 1098 | { |
| 1104 | uint32_t totalElems = 0; | 1099 | uint32_t totalElems = 0; |
| 1105 | uint32_t tmpUbSize = 0; | 1100 | uint32_t tmpUbSize = 0; |
| @@ -1142,8 +1137,8 @@ static bool TrySmallAxisTwoStageBatchCandidate( | |||
| 1142 | // SearchTwoStageBatchPlan() which picks the batch size that minimises | 1137 | // SearchTwoStageBatchPlan() which picks the batch size that minimises |
| 1143 | // idle core slots while keeping the same per-core loop count. | 1138 | // idle core slots while keeping the same per-core loop count. |
| 1144 | template <typename ComputeBatchNumFn> | 1139 | template <typename ComputeBatchNumFn> |
| 1145 | -static bool EstimateSmallAxisTwoStageBatching( | 1140 | +static bool EstimateSmallAxisTwoStageBatching(const SortKthTileInfo& info, uint32_t batchSizeCap, |
| 1146 | - const SortKthTileInfo& info, uint32_t batchSizeCap, ComputeBatchNumFn computeBatchNum, SmallAxisRoutePlan& plan) | 1141 | + ComputeBatchNumFn computeBatchNum, SmallAxisRoutePlan& plan) |
| 1147 | { | 1142 | { |
| 1148 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); | 1143 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); |
| 1149 | if (info.ubSize <= SIMT_UB || axisLen == 0U || batchSizeCap == 0U) { | 1144 | if (info.ubSize <= SIMT_UB || axisLen == 0U || batchSizeCap == 0U) { |
| @@ -1186,9 +1181,8 @@ static bool EstimateSmallAxisTwoStageBatching( | |||
| 1186 | // ============================================================================= | 1181 | // ============================================================================= |
| 1187 | // Small-axis route selection | 1182 | // Small-axis route selection |
| 1188 | // ============================================================================= | 1183 | // ============================================================================= |
| 1189 | -static bool SelectSmallAxisRouteImpl( | 1184 | +static bool SelectSmallAxisRouteImpl(const SortKthTileInfo& info, uint32_t batchSizeCap, |
| 1190 | - const SortKthTileInfo& info, uint32_t batchSizeCap, std::function<bool(uint32_t, uint32_t&)> computeBatchNum, | 1185 | + std::function<bool(uint32_t, uint32_t&)> computeBatchNum, SmallAxisRoutePlan& plan) |
| 1191 | - SmallAxisRoutePlan& plan) | ||
| 1192 | { | 1186 | { |
| 1193 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); | 1187 | uint32_t axisLen = static_cast<uint32_t>(info.lastAxis); |
| 1194 | if (axisLen <= 1U) { | 1188 | if (axisLen <= 1U) { |
| @@ -18,30 +18,32 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | + | ||
| 22 | + | ||
| 21 | namespace optiling { | 23 | namespace optiling { |
| 22 | -constexpr size_t WORK_SPACE_SIZE = 16777216; // 16 * 1024 * 1024; | 24 | +constexpr size_t WORK_SPACE_SIZE = 16777216; // 16 * 1024 * 1024; |
| 23 | const uint32_t BIN_NUM = 256; | 25 | const uint32_t BIN_NUM = 256; |
| 24 | const uint32_t TILE_DATA_NUM = 4096; | 26 | const uint32_t TILE_DATA_NUM = 4096; |
| 25 | const uint32_t MEDIUM_TILE_DATA_NUM = 2048; | 27 | const uint32_t MEDIUM_TILE_DATA_NUM = 2048; |
| 26 | const uint32_t SMALL_TILE_DATA_NUM = 1024; | 28 | const uint32_t SMALL_TILE_DATA_NUM = 1024; |
| 27 | const uint32_t TILE_DATA_NUM_B64 = 2048; | 29 | const uint32_t TILE_DATA_NUM_B64 = 2048; |
| 28 | -const uint32_t TMP_UB = 1024; // 暂预留给sort高级api的大小 | 30 | +const uint32_t TMP_UB = 1024; // 暂预留给sort高级api的大小 |
| 29 | -const uint32_t CONST_10 = 10; // int32索引时, 计算各种tensor的乘法因子 | 31 | +const uint32_t CONST_10 = 10; // int32索引时, 计算各种tensor的乘法因子 |
| 30 | -const uint32_t CONST_14 = 14; // int64索引时, 计算各种tensor的乘法因子 | 32 | +const uint32_t CONST_14 = 14; // int64索引时, 计算各种tensor的乘法因子 |
| 31 | -const uint32_t CONST_6 = 6; // int64索引时, 计算各种tensor的乘法因子 | 33 | +const uint32_t CONST_6 = 6; // int64索引时, 计算各种tensor的乘法因子 |
| 32 | const uint32_t CONST_1 = 1; | 34 | const uint32_t CONST_1 = 1; |
| 33 | const uint32_t CONST_2 = 2; | 35 | const uint32_t CONST_2 = 2; |
| 34 | const uint32_t INT64_BYTE = 8; | 36 | const uint32_t INT64_BYTE = 8; |
| 35 | const uint32_t INT32_BYTE = 4; | 37 | const uint32_t INT32_BYTE = 4; |
| 36 | -const uint32_t SIMT_UB = 32768; // 预留了32k给simt使用 | 38 | +const uint32_t SIMT_UB = 32768; // 预留了32k给simt使用 |
| 37 | -const uint32_t NEED_UB_SIZE_BYTE = 221184; // 预留了32k给simt使用 | 39 | +const uint32_t NEED_UB_SIZE_BYTE = 221184; // 预留了32k给simt使用 |
| 38 | const uint32_t SMALL_SORT_MAX_DATA_SIZE = 512; | 40 | const uint32_t SMALL_SORT_MAX_DATA_SIZE = 512; |
| 39 | const uint32_t AGLIN_VALUE = 32; | 41 | const uint32_t AGLIN_VALUE = 32; |
| 40 | const uint32_t MERGE_SORT_TILING_OFFSET = 10000; | 42 | const uint32_t MERGE_SORT_TILING_OFFSET = 10000; |
| 41 | -const uint32_t UB_CONST_INT32 = 4096; // 输出idx为int32时kernel侧需要的固定ub大小 | 43 | +const uint32_t UB_CONST_INT32 = 4096; // 输出idx为int32时kernel侧需要的固定ub大小 |
| 42 | -const uint32_t UB_CONST_INT64 = 7168; // 输出idx为int64时kernel侧需要的固定ub大小 | 44 | +const uint32_t UB_CONST_INT64 = 7168; // 输出idx为int64时kernel侧需要的固定ub大小 |
| 43 | -// 排序轴在int32范围内的最大值, 超过这个值, cutsum,前缀和就要用int64数据范围表示 | 45 | +// 排序轴在int32范围内的最大值, 超过这个值, cutsum,前缀和就要用int64数据范围表示 |
| 44 | -const uint32_t INT32_MAX_RANGE_VALUE = 1073741823; | 46 | +const uint32_t INT32_MAX_RANGE_VALUE = 1073741823; |
| 45 | const uint32_t SMALL_SIZE_OPTIM_MODE = 0; | 47 | const uint32_t SMALL_SIZE_OPTIM_MODE = 0; |
| 46 | const uint32_t SMALL_SIZE_MODE = 1; | 48 | const uint32_t SMALL_SIZE_MODE = 1; |
| 47 | const uint32_t MULT_CORE_MODE = 2; | 49 | const uint32_t MULT_CORE_MODE = 2; |
| @@ -70,7 +72,7 @@ struct SortTileInfo { | |||
| 70 | uint32_t isInt32 = 0; | 72 | uint32_t isInt32 = 0; |
| 71 | int32_t xDimNum = 0; | 73 | int32_t xDimNum = 0; |
| 72 | int64_t sortAxisNum = 1; | 74 | int64_t sortAxisNum = 1; |
| 73 | - int64_t unSortDimNum = 1; | 75 | + int64_t unSortDimNum = 1; |
| 74 | }; | 76 | }; |
| 75 | 77 | ||
| 76 | static const std::map<ge::DataType, uint32_t> tilingDataTypeKeyMap = { | 78 | static const std::map<ge::DataType, uint32_t> tilingDataTypeKeyMap = { |
| @@ -93,7 +95,7 @@ uint32_t CeilDiv1(int64_t a, int64_t b) | |||
| 93 | } | 95 | } |
| 94 | 96 | ||
| 95 | template <typename T> | 97 | template <typename T> |
| 96 | -auto CeilDivMul1(int64_t a, int64_t b) ->T const | 98 | +auto CeilDivMul1(int64_t a, int64_t b) -> T const |
| 97 | { | 99 | { |
| 98 | if (b == 0) { | 100 | if (b == 0) { |
| 99 | return static_cast<T>(a); | 101 | return static_cast<T>(a); |
| @@ -101,9 +103,8 @@ auto CeilDivMul1(int64_t a, int64_t b) ->T const | |||
| 101 | return static_cast<T>(((a + b - 1) / b) * b); | 103 | return static_cast<T>(((a + b - 1) / b) * b); |
| 102 | } | 104 | } |
| 103 | 105 | ||
| 104 | -void SetSortTmpSizeOfIdx( | 106 | +void SetSortTmpSizeOfIdx(ge::DataType dataType, int64_t lastAxisNum, uint32_t tileData, bool isDescend, bool hasIndex, |
| 105 | - ge::DataType dataType, int64_t lastAxisNum, uint32_t tileData, bool isDescend, bool hasIndex, | 107 | + SortWithIndexTilingDataSimt& sortTilingData, SortTileInfo& sortTileInfo) |
| 106 | - SortWithIndexTilingDataSimt& sortTilingData, SortTileInfo& sortTileInfo) | ||
| 107 | { | 108 | { |
| 108 | int64_t reanLen = std::min(lastAxisNum, static_cast<int64_t>(tileData)); | 109 | int64_t reanLen = std::min(lastAxisNum, static_cast<int64_t>(tileData)); |
| 109 | std::vector<int64_t> shapeVec = {reanLen}; | 110 | std::vector<int64_t> shapeVec = {reanLen}; |
| @@ -123,9 +124,8 @@ void SetSortTmpSizeOfIdx( | |||
| 123 | sortTileInfo.tmpUbSize = maxValue; | 124 | sortTileInfo.tmpUbSize = maxValue; |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | -void SetMergeSortTmpSizeOfIdx( | 127 | +void SetMergeSortTmpSizeOfIdx(gert::TilingContext* context, ge::DataType dataType, int64_t lastAxisNum, |
| 127 | - gert::TilingContext* context, ge::DataType dataType, int64_t lastAxisNum, | 128 | + SortWithIndexTilingDataSimt& sortTilingData) |
| 128 | - SortWithIndexTilingDataSimt& sortTilingData) | ||
| 129 | { | 129 | { |
| 130 | uint32_t reanLen = 0; | 130 | uint32_t reanLen = 0; |
| 131 | if ((lastAxisNum <= SMALL_SORT_MAX_DATA_SIZE) && (optDataTypeBitMap.count(dataType) != 0)) { | 131 | if ((lastAxisNum <= SMALL_SORT_MAX_DATA_SIZE) && (optDataTypeBitMap.count(dataType) != 0)) { |
| @@ -136,26 +136,30 @@ void SetMergeSortTmpSizeOfIdx( | |||
| 136 | optDataTypeBitMap.find(dataType)->second; | 136 | optDataTypeBitMap.find(dataType)->second; |
| 137 | auto platform_info = context->GetPlatformInfo(); | 137 | auto platform_info = context->GetPlatformInfo(); |
| 138 | if (nullptr == platform_info) { | 138 | if (nullptr == platform_info) { |
| 139 | - OP_LOGE("[SortWithIndexTilingForAscendC]", "platform_info is nullptr."); | 139 | + OP_LOGE_WITH_INVALID_INPUT(context->GetNodeName(), "platform_info"); |
| 140 | } | 140 | } |
| 141 | auto plat = platform_ascendc::PlatformAscendC(platform_info); | 141 | auto plat = platform_ascendc::PlatformAscendC(platform_info); |
| 142 | uint32_t dataSizeNeed = AscendC::GetConcatTmpSize(plat, aglinDataSize, dataTypeSize); | 142 | uint32_t dataSizeNeed = AscendC::GetConcatTmpSize(plat, aglinDataSize, dataTypeSize); |
| 143 | OP_LOGW("[SortWithIndexTilingForAscendC]", "Allocal buffer mergesort element len = %u ac sort api", reanLen); | 143 | OP_LOGW("[SortWithIndexTilingForAscendC]", "Allocal buffer mergesort element len = %u ac sort api", reanLen); |
| 144 | OP_LOGW("[SortWithIndexTilingForAscendC]", "Merge sort need tmp buffer %u byte for ac api", dataSizeNeed); | 144 | OP_LOGW("[SortWithIndexTilingForAscendC]", "Merge sort need tmp buffer %u byte for ac api", dataSizeNeed); |
| 145 | sortTilingData.set_mergSortAcApiNeedBufferSize(dataSizeNeed); | 145 | sortTilingData.set_mergSortAcApiNeedBufferSize(dataSizeNeed); |
| 146 | - size_t *userWorkSpaceSize = context->GetWorkspaceSizes(1); | 146 | + size_t* userWorkSpaceSize = context->GetWorkspaceSizes(1); |
| 147 | userWorkSpaceSize[0] = WORK_SPACE_SIZE; | 147 | userWorkSpaceSize[0] = WORK_SPACE_SIZE; |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | -void TileModeSmallSizeOptimOfIdx( | 150 | +void TileModeSmallSizeOptimOfIdx(uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_t lastAxisNum, uint32_t tileData, |
| 151 | - uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_t lastAxisNum, uint32_t tileData, SortTileInfo& sortTileInfo) | 151 | + SortTileInfo& sortTileInfo) |
| 152 | { | 152 | { |
| 153 | uint32_t aglinNum = static_cast<uint32_t>((lastAxisNum + AGLIN_VALUE - 1) / AGLIN_VALUE * AGLIN_VALUE); | 153 | uint32_t aglinNum = static_cast<uint32_t>((lastAxisNum + AGLIN_VALUE - 1) / AGLIN_VALUE * AGLIN_VALUE); |
| 154 | uint32_t oneCoreRowNum = static_cast<uint32_t>((tileData / 2) / aglinNum); | 154 | uint32_t oneCoreRowNum = static_cast<uint32_t>((tileData / 2) / aglinNum); |
| 155 | oneCoreRowNum = static_cast<uint32_t>(oneCoreRowNum == 0 ? 1 : oneCoreRowNum); | 155 | oneCoreRowNum = static_cast<uint32_t>(oneCoreRowNum == 0 ? 1 : oneCoreRowNum); |
| 156 | uint32_t virUnsortedDimNum = static_cast<uint32_t>((unsortedDimNum + oneCoreRowNum - 1) / oneCoreRowNum); | 156 | uint32_t virUnsortedDimNum = static_cast<uint32_t>((unsortedDimNum + oneCoreRowNum - 1) / oneCoreRowNum); |
| 157 | uint32_t coreNumNeed = 0; | 157 | uint32_t coreNumNeed = 0; |
| 158 | - OP_CHECK_IF(maxCoreNum == 0, OP_LOGE("TileModeSmallSizeOptimOfIdx", "maxCoreNum is zero"), return); | 158 | + OP_CHECK_IF(maxCoreNum == 0, |
| 159 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("TileModeSmallSizeOptimOfIdx", "maxCoreNum", | ||
| 160 | + std::to_string(maxCoreNum).c_str(), | ||
| 161 | + "The value of maxCoreNum must be greater than 0."), | ||
| 162 | + return); | ||
| 159 | uint32_t sortLoopTimes = static_cast<uint32_t>((virUnsortedDimNum + maxCoreNum - 1) / maxCoreNum); | 163 | uint32_t sortLoopTimes = static_cast<uint32_t>((virUnsortedDimNum + maxCoreNum - 1) / maxCoreNum); |
| 160 | if (sortLoopTimes == 1u) { | 164 | if (sortLoopTimes == 1u) { |
| 161 | uint32_t realCoreNum = virUnsortedDimNum % maxCoreNum; | 165 | uint32_t realCoreNum = virUnsortedDimNum % maxCoreNum; |
| @@ -173,15 +177,21 @@ void TileModeSmallSizeOptimOfIdx( | |||
| 173 | sortTileInfo.lastDimNeedCore = 1; | 177 | sortTileInfo.lastDimNeedCore = 1; |
| 174 | sortTileInfo.sortLoopTimes = sortLoopTimes; | 178 | sortTileInfo.sortLoopTimes = sortLoopTimes; |
| 175 | sortTileInfo.numTileDataSize = lastAxisNum; | 179 | sortTileInfo.numTileDataSize = lastAxisNum; |
| 176 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "Small size opt mode coreNumNeed=%u, sortLoopTimes=%u, lastAxisNum=%ld, " | 180 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 177 | - "oneCoreRowNum=%ld, ubsize=%lu.", coreNumNeed, sortLoopTimes, lastAxisNum, oneCoreRowNum, sortTileInfo.ubSize); | 181 | + "Small size opt mode coreNumNeed=%u, sortLoopTimes=%u, lastAxisNum=%ld, " |
| 182 | + "oneCoreRowNum=%ld, ubsize=%lu.", | ||
| 183 | + coreNumNeed, sortLoopTimes, lastAxisNum, oneCoreRowNum, sortTileInfo.ubSize); | ||
| 178 | } | 184 | } |
| 179 | 185 | ||
| 180 | -void TileModeSmallSizeOfIdx(gert::TilingContext *context, uint64_t unsortedDimNum, uint32_t maxCoreNum, | 186 | +void TileModeSmallSizeOfIdx(gert::TilingContext* context, uint64_t unsortedDimNum, uint32_t maxCoreNum, |
| 181 | - int64_t lastAxisNum, SortTileInfo& sortTileInfo) | 187 | + int64_t lastAxisNum, SortTileInfo& sortTileInfo) |
| 182 | { | 188 | { |
| 183 | uint32_t coreNumNeed = 0; | 189 | uint32_t coreNumNeed = 0; |
| 184 | - OP_CHECK_IF(maxCoreNum == 0, OP_LOGE("TileModeSmallSizeOfIdx", "maxCoreNum is zero"), return); | 190 | + OP_CHECK_IF( |
| 191 | + maxCoreNum == 0, | ||
| 192 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "maxCoreNum", std::to_string(maxCoreNum).c_str(), | ||
| 193 | + "The value of maxCoreNum must be greater than 0."), | ||
| 194 | + return); | ||
| 185 | uint32_t sortLoopTimes = static_cast<uint32_t>((unsortedDimNum + maxCoreNum - 1) / maxCoreNum); | 195 | uint32_t sortLoopTimes = static_cast<uint32_t>((unsortedDimNum + maxCoreNum - 1) / maxCoreNum); |
| 186 | if (sortLoopTimes == 1u) { | 196 | if (sortLoopTimes == 1u) { |
| 187 | uint32_t realCoreNum = unsortedDimNum % maxCoreNum; | 197 | uint32_t realCoreNum = unsortedDimNum % maxCoreNum; |
| @@ -198,36 +208,37 @@ void TileModeSmallSizeOfIdx(gert::TilingContext *context, uint64_t unsortedDimNu | |||
| 198 | sortTileInfo.lastDimNeedCore = 1; | 208 | sortTileInfo.lastDimNeedCore = 1; |
| 199 | sortTileInfo.numTileDataSize = static_cast<uint32_t>(lastAxisNum); | 209 | sortTileInfo.numTileDataSize = static_cast<uint32_t>(lastAxisNum); |
| 200 | sortTileInfo.sortLoopTimes = sortLoopTimes; | 210 | sortTileInfo.sortLoopTimes = sortLoopTimes; |
| 201 | - size_t *userWorkSpaceSize = context->GetWorkspaceSizes(1); | 211 | + size_t* userWorkSpaceSize = context->GetWorkspaceSizes(1); |
| 202 | userWorkSpaceSize[0] = WORK_SPACE_SIZE; | 212 | userWorkSpaceSize[0] = WORK_SPACE_SIZE; |
| 203 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "Small size mode coreNumNeed=%u sortLoopTimes=%u " | 213 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 204 | - "lastAxisNum=%ld", coreNumNeed, sortLoopTimes, lastAxisNum); | 214 | + "Small size mode coreNumNeed=%u sortLoopTimes=%u " |
| 215 | + "lastAxisNum=%ld", | ||
| 216 | + coreNumNeed, sortLoopTimes, lastAxisNum); | ||
| 205 | } | 217 | } |
| 206 | 218 | ||
| 207 | void PrintTilingDataOfIdx(SortTileInfo& sortTileInfo, SortWithIndexTilingDataSimt& sortTilingData) | 219 | void PrintTilingDataOfIdx(SortTileInfo& sortTileInfo, SortWithIndexTilingDataSimt& sortTilingData) |
| 208 | { | 220 | { |
| 209 | - OP_LOGI( | 221 | + OP_LOGI("[Print SortWithIndexTilingForAscendC TilingData]", |
| 210 | - "[Print SortWithIndexTilingForAscendC TilingData]", | 222 | + "coreNum is %u, lastAxisNum is %ld, isInInt32Range is %u, " |
| 211 | - "coreNum is %u, lastAxisNum is %ld, isInInt32Range is %u, " | 223 | + "sortLoopTimes is %u, unsortedDimParallel is %u, unsortedDimNum is %u, " |
| 212 | - "sortLoopTimes is %u, unsortedDimParallel is %u, unsortedDimNum is %u, " | 224 | + "lastDimTileNum is %u, lastDimNeedCore is %u, numTileDataSize is %u, " |
| 213 | - "lastDimTileNum is %u, lastDimNeedCore is %u, numTileDataSize is %u, " | 225 | + "sortAcApiNeedBufferSize is %u, mergSortAcApiNeedBufferSize is %u, " |
| 214 | - "sortAcApiNeedBufferSize is %u, mergSortAcApiNeedBufferSize is %u, " | 226 | + "oneCoreRowNum is %u, outputLastDimValue is %u, tmp ub size is %u, " |
| 215 | - "oneCoreRowNum is %u, outputLastDimValue is %u, tmp ub size is %u, " | 227 | + "keyParams0 is %u, keyParams1 is %u, keyParams2 is %u, keyParams3 is %u, keyParams4 is %u, " |
| 216 | - "keyParams0 is %u, keyParams1 is %u, keyParams2 is %u, keyParams3 is %u, keyParams4 is %u, " | 228 | + "keyParams5 is %u, ub avalibal size=%lu, modeType=%u.", |
| 217 | - "keyParams5 is %u, ub avalibal size=%lu, modeType=%u.", | 229 | + sortTileInfo.coreNumNeed, sortTilingData.get_lastAxisNum(), sortTilingData.get_isInInt32Range(), |
| 218 | - sortTileInfo.coreNumNeed, sortTilingData.get_lastAxisNum(), sortTilingData.get_isInInt32Range(), | 230 | + sortTilingData.get_sortLoopTimes(), sortTilingData.get_unsortedDimParallel(), |
| 219 | - sortTilingData.get_sortLoopTimes(), sortTilingData.get_unsortedDimParallel(), | 231 | + sortTilingData.get_unsortedDimNum(), sortTilingData.get_lastDimTileNum(), |
| 220 | - sortTilingData.get_unsortedDimNum(), sortTilingData.get_lastDimTileNum(), | 232 | + sortTilingData.get_lastDimNeedCore(), sortTilingData.get_numTileDataSize(), |
| 221 | - sortTilingData.get_lastDimNeedCore(),sortTilingData.get_numTileDataSize(), | 233 | + sortTilingData.get_sortAcApiNeedBufferSize(), sortTilingData.get_mergSortAcApiNeedBufferSize(), |
| 222 | - sortTilingData.get_sortAcApiNeedBufferSize(),sortTilingData.get_mergSortAcApiNeedBufferSize(), | 234 | + sortTilingData.get_oneCoreRowNum(), sortTilingData.get_outputLastDimValue(), sortTilingData.get_tmpUbSize(), |
| 223 | - sortTilingData.get_oneCoreRowNum(), sortTilingData.get_outputLastDimValue(), | 235 | + sortTilingData.get_keyParams0(), sortTilingData.get_keyParams1(), sortTilingData.get_keyParams2(), |
| 224 | - sortTilingData.get_tmpUbSize(), sortTilingData.get_keyParams0(), sortTilingData.get_keyParams1(), | 236 | + sortTilingData.get_keyParams3(), sortTilingData.get_keyParams4(), sortTilingData.get_keyParams5(), |
| 225 | - sortTilingData.get_keyParams2(), sortTilingData.get_keyParams3(), sortTilingData.get_keyParams4(), | 237 | + sortTileInfo.ubSize, sortTilingData.get_modeType()); |
| 226 | - sortTilingData.get_keyParams5(), sortTileInfo.ubSize, sortTilingData.get_modeType()); | ||
| 227 | return; | 238 | return; |
| 228 | } | 239 | } |
| 229 | 240 | ||
| 230 | -void FillRadixSortTilingDataSort(SortTileInfo &sortTileInfo, SortWithIndexTilingDataSimt &sortTilingData) | 241 | +void FillRadixSortTilingDataSort(SortTileInfo& sortTileInfo, SortWithIndexTilingDataSimt& sortTilingData) |
| 231 | { | 242 | { |
| 232 | sortTilingData.set_numTileDataSize(sortTileInfo.numTileDataSize); | 243 | sortTilingData.set_numTileDataSize(sortTileInfo.numTileDataSize); |
| 233 | sortTilingData.set_unsortedDimParallel(sortTileInfo.unsortedDimParallel); | 244 | sortTilingData.set_unsortedDimParallel(sortTileInfo.unsortedDimParallel); |
| @@ -246,10 +257,10 @@ void FillRadixSortTilingDataSort(SortTileInfo &sortTileInfo, SortWithIndexTiling | |||
| 246 | return; | 257 | return; |
| 247 | } | 258 | } |
| 248 | 259 | ||
| 249 | -void SetSortTmpSize1(ge::DataType dataType, uint32_t tileData, bool isDescend, SortTileInfo &sortTileInfo) | 260 | +void SetSortTmpSize1(ge::DataType dataType, uint32_t tileData, bool isDescend, SortTileInfo& sortTileInfo) |
| 250 | { | 261 | { |
| 251 | int64_t realLen = std::min(sortTileInfo.sortAxisNum, static_cast<int64_t>(tileData)); | 262 | int64_t realLen = std::min(sortTileInfo.sortAxisNum, static_cast<int64_t>(tileData)); |
| 252 | - std::vector<int64_t> shapeVec = { realLen }; | 263 | + std::vector<int64_t> shapeVec = {realLen}; |
| 253 | ge::Shape srcShape(shapeVec); | 264 | ge::Shape srcShape(shapeVec); |
| 254 | AscendC::SortConfig config; | 265 | AscendC::SortConfig config; |
| 255 | config.type = AscendC::SortType::RADIX_SORT; | 266 | config.type = AscendC::SortType::RADIX_SORT; |
| @@ -263,26 +274,30 @@ void SetSortTmpSize1(ge::DataType dataType, uint32_t tileData, bool isDescend, S | |||
| 263 | return; | 274 | return; |
| 264 | } | 275 | } |
| 265 | 276 | ||
| 266 | -uint32_t ComputeRemainUb1(SortTileInfo &sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) | 277 | +uint32_t ComputeRemainUb1(SortTileInfo& sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) |
| 267 | { | 278 | { |
| 268 | uint32_t tmpUb = sortTileInfo.ubSize - (ubExtra + tileFactor * tileData); | 279 | uint32_t tmpUb = sortTileInfo.ubSize - (ubExtra + tileFactor * tileData); |
| 269 | - OP_LOGD("[SortWithIndexTilingForAscendC]", "ComputeRemainUb1 ubSize=%u, ubExtra=%lu, tileFactor=%lu, " | 280 | + OP_LOGD("[SortWithIndexTilingForAscendC]", |
| 270 | - "tileData=%lu, tmpUb=%lu.", sortTileInfo.ubSize, ubExtra, tileFactor, tileData, tmpUb); | 281 | + "ComputeRemainUb1 ubSize=%u, ubExtra=%lu, tileFactor=%lu, " |
| 282 | + "tileData=%lu, tmpUb=%lu.", | ||
| 283 | + sortTileInfo.ubSize, ubExtra, tileFactor, tileData, tmpUb); | ||
| 271 | return tmpUb; | 284 | return tmpUb; |
| 272 | } | 285 | } |
| 273 | 286 | ||
| 274 | -void AdjTmpUb1(SortTileInfo &sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) | 287 | +void AdjTmpUb1(SortTileInfo& sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) |
| 275 | { | 288 | { |
| 276 | uint32_t remainUbNew = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor) - sortTileInfo.tmpUbSize; | 289 | uint32_t remainUbNew = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor) - sortTileInfo.tmpUbSize; |
| 277 | remainUbNew = remainUbNew > sortTileInfo.blockUbSize ? (remainUbNew - sortTileInfo.blockUbSize) : uint32_t(0); | 290 | remainUbNew = remainUbNew > sortTileInfo.blockUbSize ? (remainUbNew - sortTileInfo.blockUbSize) : uint32_t(0); |
| 278 | uint32_t alignUbSize = (remainUbNew / sortTileInfo.blockUbSize) * sortTileInfo.blockUbSize; | 291 | uint32_t alignUbSize = (remainUbNew / sortTileInfo.blockUbSize) * sortTileInfo.blockUbSize; |
| 279 | - OP_LOGD("[SortWithIndexTilingForAscendC]", "alignUbSize %u, sortTileInfo.tmpUbSize=%lu, " | 292 | + OP_LOGD("[SortWithIndexTilingForAscendC]", |
| 280 | - "sortTileInfo.blockUbSize=%lu.", alignUbSize, sortTileInfo.tmpUbSize, sortTileInfo.blockUbSize); | 293 | + "alignUbSize %u, sortTileInfo.tmpUbSize=%lu, " |
| 294 | + "sortTileInfo.blockUbSize=%lu.", | ||
| 295 | + alignUbSize, sortTileInfo.tmpUbSize, sortTileInfo.blockUbSize); | ||
| 281 | sortTileInfo.tmpUbSize = sortTileInfo.tmpUbSize + alignUbSize; // 剩余的ub都给tmpUbsize | 296 | sortTileInfo.tmpUbSize = sortTileInfo.tmpUbSize + alignUbSize; // 剩余的ub都给tmpUbsize |
| 282 | } | 297 | } |
| 283 | 298 | ||
| 284 | -void ComputeTileDataOne1(SortTileInfo &sortTileInfo, uint32_t lastDimTileNum, uint32_t ubExtra, uint32_t &tileData, | 299 | +void ComputeTileDataOne1(SortTileInfo& sortTileInfo, uint32_t lastDimTileNum, uint32_t ubExtra, uint32_t& tileData, |
| 285 | - uint32_t tileFactor) | 300 | + uint32_t tileFactor) |
| 286 | { | 301 | { |
| 287 | uint32_t allCore = CeilDivMul1<uint32_t>(int64_t(lastDimTileNum), int64_t(sortTileInfo.maxCoreNum)); | 302 | uint32_t allCore = CeilDivMul1<uint32_t>(int64_t(lastDimTileNum), int64_t(sortTileInfo.maxCoreNum)); |
| 288 | uint32_t newTileData = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(allCore)); | 303 | uint32_t newTileData = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(allCore)); |
| @@ -293,8 +308,8 @@ void ComputeTileDataOne1(SortTileInfo &sortTileInfo, uint32_t lastDimTileNum, u | |||
| 293 | return; | 308 | return; |
| 294 | } | 309 | } |
| 295 | 310 | ||
| 296 | -bool NeedAdjTileData1(SortTileInfo &sortTileInfo, uint32_t &tileData, uint32_t lastDimTileNum, uint32_t ubExtra, | 311 | +bool NeedAdjTileData1(SortTileInfo& sortTileInfo, uint32_t& tileData, uint32_t lastDimTileNum, uint32_t ubExtra, |
| 297 | - uint32_t tileFactor) | 312 | + uint32_t tileFactor) |
| 298 | { | 313 | { |
| 299 | if (sortTileInfo.unSortDimNum == 1L && lastDimTileNum == 1U) { | 314 | if (sortTileInfo.unSortDimNum == 1L && lastDimTileNum == 1U) { |
| 300 | OP_LOGI("[SortWithIndexTilingForAscendC]", "unSortDimNum and lastDimTileNum is 1"); | 315 | OP_LOGI("[SortWithIndexTilingForAscendC]", "unSortDimNum and lastDimTileNum is 1"); |
| @@ -313,8 +328,8 @@ bool NeedAdjTileData1(SortTileInfo &sortTileInfo, uint32_t &tileData, uint32_t l | |||
| 313 | } | 328 | } |
| 314 | if (sortTileInfo.unSortDimNum > 1L && sortTileInfo.unSortDimNum < int64_t(sortTileInfo.maxCoreNum) && | 329 | if (sortTileInfo.unSortDimNum > 1L && sortTileInfo.unSortDimNum < int64_t(sortTileInfo.maxCoreNum) && |
| 315 | lastDimTileNum == 1U) { | 330 | lastDimTileNum == 1U) { |
| 316 | - OP_LOGI("[SortWithIndexTilingForAscendC]", | 331 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 317 | - "unSortDimNum greater than 1,and unSortDimNum small and lastDimTileNum is one"); | 332 | + "unSortDimNum greater than 1,and unSortDimNum small and lastDimTileNum is one"); |
| 318 | uint32_t hCore = sortTileInfo.maxCoreNum / static_cast<uint32_t>(sortTileInfo.unSortDimNum); | 333 | uint32_t hCore = sortTileInfo.maxCoreNum / static_cast<uint32_t>(sortTileInfo.unSortDimNum); |
| 319 | uint32_t hTileData = static_cast<uint32_t>(sortTileInfo.sortAxisNum) / hCore; | 334 | uint32_t hTileData = static_cast<uint32_t>(sortTileInfo.sortAxisNum) / hCore; |
| 320 | tileData = CeilDivMul1<uint32_t>(int64_t(hTileData), int64_t(BIN_NUM)); | 335 | tileData = CeilDivMul1<uint32_t>(int64_t(hTileData), int64_t(BIN_NUM)); |
| @@ -347,7 +362,7 @@ bool NeedAdjTileData1(SortTileInfo &sortTileInfo, uint32_t &tileData, uint32_t l | |||
| 347 | return false; | 362 | return false; |
| 348 | } | 363 | } |
| 349 | 364 | ||
| 350 | -uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | 365 | +uint32_t ComputeTileData1(SortTileInfo& sortTileInfo) |
| 351 | { | 366 | { |
| 352 | uint32_t ubExtra; | 367 | uint32_t ubExtra; |
| 353 | uint32_t tileFactor; | 368 | uint32_t tileFactor; |
| @@ -361,8 +376,10 @@ uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | |||
| 361 | 376 | ||
| 362 | uint32_t tileData = (sortTileInfo.ubSize - ubExtra) / tileFactor; | 377 | uint32_t tileData = (sortTileInfo.ubSize - ubExtra) / tileFactor; |
| 363 | tileData = (tileData / BIN_NUM) * BIN_NUM; | 378 | tileData = (tileData / BIN_NUM) * BIN_NUM; |
| 364 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "ubExtra=%u, tileFactor=%u, dtypeSize=%u, y2DtypeSize=%lu, " | 379 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 365 | - "tileData=%lu.", ubExtra, tileFactor, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, tileData); | 380 | + "ubExtra=%u, tileFactor=%u, dtypeSize=%u, y2DtypeSize=%lu, " |
| 381 | + "tileData=%lu.", | ||
| 382 | + ubExtra, tileFactor, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, tileData); | ||
| 366 | uint32_t remainUb = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor); | 383 | uint32_t remainUb = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor); |
| 367 | SetSortTmpSize1(ge::DT_UINT8, tileData, false, sortTileInfo); | 384 | SetSortTmpSize1(ge::DT_UINT8, tileData, false, sortTileInfo); |
| 368 | 385 | ||
| @@ -374,10 +391,10 @@ uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | |||
| 374 | tmpUbSize = sortTileInfo.tmpUbSize; | 391 | tmpUbSize = sortTileInfo.tmpUbSize; |
| 375 | } | 392 | } |
| 376 | uint32_t lastDimTileNum = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(tileData)); | 393 | uint32_t lastDimTileNum = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(tileData)); |
| 377 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "tileData %u, lastDimTileNum %u, tmpUbSize %u", tileData, | 394 | + OP_LOGI("[SortWithIndexTilingForAscendC]", "tileData %u, lastDimTileNum %u, tmpUbSize %u", tileData, lastDimTileNum, |
| 378 | - lastDimTileNum, tmpUbSize); | 395 | + tmpUbSize); |
| 379 | - bool smallTile = | 396 | + bool smallTile = (sortTileInfo.sortAxisNum <= static_cast<int64_t>(SMALL_TILE_DATA_NUM)) && |
| 380 | - (sortTileInfo.sortAxisNum <= static_cast<int64_t>(SMALL_TILE_DATA_NUM)) && lastDimTileNum == uint32_t(1); | 397 | + lastDimTileNum == uint32_t(1); |
| 381 | if ((lastDimTileNum % sortTileInfo.maxCoreNum == 0U) || smallTile) { | 398 | if ((lastDimTileNum % sortTileInfo.maxCoreNum == 0U) || smallTile) { |
| 382 | OP_LOGI("[SortWithIndexTilingForAscendC]", "lastDimTileNum align or smallTile"); | 399 | OP_LOGI("[SortWithIndexTilingForAscendC]", "lastDimTileNum align or smallTile"); |
| 383 | AdjTmpUb1(sortTileInfo, tileData, ubExtra, tileFactor); | 400 | AdjTmpUb1(sortTileInfo, tileData, ubExtra, tileFactor); |
| @@ -390,7 +407,7 @@ uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | |||
| 390 | return tileData; | 407 | return tileData; |
| 391 | } | 408 | } |
| 392 | 409 | ||
| 393 | -void ComputeWorkSpace1(gert::TilingContext *context, SortTileInfo &sortTileInfo) | 410 | +void ComputeWorkSpace1(gert::TilingContext* context, SortTileInfo& sortTileInfo) |
| 394 | { | 411 | { |
| 395 | uint32_t dtypeSizeWk = static_cast<uint32_t>(sizeof(int32_t)); | 412 | uint32_t dtypeSizeWk = static_cast<uint32_t>(sizeof(int32_t)); |
| 396 | if (sortTileInfo.isInt32 == 0U) { | 413 | if (sortTileInfo.isInt32 == 0U) { |
| @@ -399,50 +416,51 @@ void ComputeWorkSpace1(gert::TilingContext *context, SortTileInfo &sortTileInfo) | |||
| 399 | size_t excusiveBinsGmWkSize = static_cast<size_t>(sortTileInfo.keyParams1) * sortTileInfo.keyParams4 * dtypeSizeWk; | 416 | size_t excusiveBinsGmWkSize = static_cast<size_t>(sortTileInfo.keyParams1) * sortTileInfo.keyParams4 * dtypeSizeWk; |
| 400 | excusiveBinsGmWkSize = CeilDivMul1<size_t>(int64_t(excusiveBinsGmWkSize), int64_t(sortTileInfo.blockUbSize)); | 417 | excusiveBinsGmWkSize = CeilDivMul1<size_t>(int64_t(excusiveBinsGmWkSize), int64_t(sortTileInfo.blockUbSize)); |
| 401 | 418 | ||
| 402 | - size_t globalHistGmWkSize = | 419 | + size_t globalHistGmWkSize = static_cast<size_t>(sortTileInfo.keyParams3) * sortTileInfo.keyParams2 * |
| 403 | - static_cast<size_t>(sortTileInfo.keyParams3) * sortTileInfo.keyParams2 * sortTileInfo.keyParams0 * dtypeSizeWk; | 420 | + sortTileInfo.keyParams0 * dtypeSizeWk; |
| 404 | globalHistGmWkSize = CeilDivMul1<size_t>(int64_t(globalHistGmWkSize), int64_t(sortTileInfo.blockUbSize)); | 421 | globalHistGmWkSize = CeilDivMul1<size_t>(int64_t(globalHistGmWkSize), int64_t(sortTileInfo.blockUbSize)); |
| 405 | 422 | ||
| 406 | - size_t outIdxDbWK = | 423 | + size_t outIdxDbWK = static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * |
| 407 | - static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * sortTileInfo.y2DtypeSize; | 424 | + sortTileInfo.y2DtypeSize; |
| 408 | outIdxDbWK = CeilDivMul1<size_t>(int64_t(outIdxDbWK), int64_t(sortTileInfo.blockUbSize)); | 425 | outIdxDbWK = CeilDivMul1<size_t>(int64_t(outIdxDbWK), int64_t(sortTileInfo.blockUbSize)); |
| 409 | 426 | ||
| 410 | - size_t histTileGmWk = static_cast<size_t>(sortTileInfo.lastDimTileNum) * BIN_NUM * sortTileInfo.unsortedDimParallel * | 427 | + size_t histTileGmWk = static_cast<size_t>(sortTileInfo.lastDimTileNum) * BIN_NUM * |
| 411 | - sizeof(int16_t) * CONST_2; | 428 | + sortTileInfo.unsortedDimParallel * sizeof(int16_t) * CONST_2; |
| 412 | 429 | ||
| 413 | size_t xB8GmWkSize = static_cast<size_t>(sortTileInfo.lastDimTileNum) * sortTileInfo.numTileDataSize * | 430 | size_t xB8GmWkSize = static_cast<size_t>(sortTileInfo.lastDimTileNum) * sortTileInfo.numTileDataSize * |
| 414 | - sortTileInfo.unsortedDimParallel; | 431 | + sortTileInfo.unsortedDimParallel; |
| 415 | xB8GmWkSize = CeilDivMul1<size_t>(int64_t(xB8GmWkSize), int64_t(sortTileInfo.blockUbSize)); | 432 | xB8GmWkSize = CeilDivMul1<size_t>(int64_t(xB8GmWkSize), int64_t(sortTileInfo.blockUbSize)); |
| 416 | 433 | ||
| 417 | - size_t outValueDbWKSize = | 434 | + size_t outValueDbWKSize = static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * |
| 418 | - static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * sortTileInfo.dtypeSize; | 435 | + sortTileInfo.dtypeSize; |
| 419 | outValueDbWKSize = CeilDivMul1<size_t>(int64_t(outValueDbWKSize), int64_t(sortTileInfo.blockUbSize)); | 436 | outValueDbWKSize = CeilDivMul1<size_t>(int64_t(outValueDbWKSize), int64_t(sortTileInfo.blockUbSize)); |
| 420 | - size_t *userWorkSpaceSize = context->GetWorkspaceSizes(1); | 437 | + size_t* userWorkSpaceSize = context->GetWorkspaceSizes(1); |
| 421 | - size_t usrSize = excusiveBinsGmWkSize + globalHistGmWkSize + outIdxDbWK + histTileGmWk + xB8GmWkSize + outValueDbWKSize; | 438 | + size_t usrSize = excusiveBinsGmWkSize + globalHistGmWkSize + outIdxDbWK + histTileGmWk + xB8GmWkSize + |
| 439 | + outValueDbWKSize; | ||
| 422 | OP_LOGD("[SortWithIndexTilingForAscendC]", | 440 | OP_LOGD("[SortWithIndexTilingForAscendC]", |
| 423 | - "excusiveBinsGmWkSize=%lu, globalHistGmWkSize=%lu, histTileGmWk=%lu," | 441 | + "excusiveBinsGmWkSize=%lu, globalHistGmWkSize=%lu, histTileGmWk=%lu," |
| 424 | - " xB8GmWkSize=%lu, outValueDbWKSize=%lu, outIdxDbWK=%lu, usrSize=%lu.", | 442 | + " xB8GmWkSize=%lu, outValueDbWKSize=%lu, outIdxDbWK=%lu, usrSize=%lu.", |
| 425 | - excusiveBinsGmWkSize, globalHistGmWkSize, histTileGmWk, xB8GmWkSize, outValueDbWKSize, outIdxDbWK, usrSize); | 443 | + excusiveBinsGmWkSize, globalHistGmWkSize, histTileGmWk, xB8GmWkSize, outValueDbWKSize, outIdxDbWK, usrSize); |
| 426 | userWorkSpaceSize[0] = usrSize + WORK_SPACE_SIZE; | 444 | userWorkSpaceSize[0] = usrSize + WORK_SPACE_SIZE; |
| 427 | return; | 445 | return; |
| 428 | } | 446 | } |
| 429 | 447 | ||
| 430 | -void TileMoreCoreModeOfIdx(gert::TilingContext *context, SortTileInfo &sortTileInfo) | 448 | +void TileMoreCoreModeOfIdx(gert::TilingContext* context, SortTileInfo& sortTileInfo) |
| 431 | { | 449 | { |
| 432 | uint32_t tileData = ComputeTileData1(sortTileInfo); | 450 | uint32_t tileData = ComputeTileData1(sortTileInfo); |
| 433 | uint32_t lastDimTileNum = CeilDiv1(int64_t(sortTileInfo.sortAxisNum), int64_t(tileData)); | 451 | uint32_t lastDimTileNum = CeilDiv1(int64_t(sortTileInfo.sortAxisNum), int64_t(tileData)); |
| 434 | if (sortTileInfo.maxCoreNum <= lastDimTileNum) { | 452 | if (sortTileInfo.maxCoreNum <= lastDimTileNum) { |
| 435 | sortTileInfo.unsortedDimParallel = 1U; | 453 | sortTileInfo.unsortedDimParallel = 1U; |
| 436 | } else { | 454 | } else { |
| 437 | - sortTileInfo.unsortedDimParallel = | 455 | + sortTileInfo.unsortedDimParallel = lastDimTileNum == 0U ? sortTileInfo.maxCoreNum : |
| 438 | - lastDimTileNum == 0U ? sortTileInfo.maxCoreNum : sortTileInfo.maxCoreNum / lastDimTileNum; | 456 | + sortTileInfo.maxCoreNum / lastDimTileNum; |
| 439 | if (sortTileInfo.unSortDimNum < static_cast<int64_t>(sortTileInfo.unsortedDimParallel)) { | 457 | if (sortTileInfo.unSortDimNum < static_cast<int64_t>(sortTileInfo.unsortedDimParallel)) { |
| 440 | sortTileInfo.unsortedDimParallel = static_cast<uint32_t>(sortTileInfo.unSortDimNum); | 458 | sortTileInfo.unsortedDimParallel = static_cast<uint32_t>(sortTileInfo.unSortDimNum); |
| 441 | } | 459 | } |
| 442 | } | 460 | } |
| 443 | sortTileInfo.numTileDataSize = tileData; | 461 | sortTileInfo.numTileDataSize = tileData; |
| 444 | - sortTileInfo.sortLoopTimes = | 462 | + sortTileInfo.sortLoopTimes = CeilDiv1(int64_t(sortTileInfo.unSortDimNum), |
| 445 | - CeilDiv1(int64_t(sortTileInfo.unSortDimNum), int64_t(sortTileInfo.unsortedDimParallel)); | 463 | + int64_t(sortTileInfo.unsortedDimParallel)); |
| 446 | sortTileInfo.lastDimNeedCore = std::min(sortTileInfo.maxCoreNum, lastDimTileNum); | 464 | sortTileInfo.lastDimNeedCore = std::min(sortTileInfo.maxCoreNum, lastDimTileNum); |
| 447 | sortTileInfo.coreNumNeed = sortTileInfo.unsortedDimParallel * sortTileInfo.lastDimNeedCore; | 465 | sortTileInfo.coreNumNeed = sortTileInfo.unsortedDimParallel * sortTileInfo.lastDimNeedCore; |
| 448 | sortTileInfo.lastDimTileNum = lastDimTileNum; | 466 | sortTileInfo.lastDimTileNum = lastDimTileNum; |
| @@ -454,15 +472,15 @@ void TileMoreCoreModeOfIdx(gert::TilingContext *context, SortTileInfo &sortTileI | |||
| 454 | uint32_t allNumGloblHist = BIN_NUM * lastDimTileNum * sortTileInfo.dtypeSize * sortTileInfo.unsortedDimParallel; | 472 | uint32_t allNumGloblHist = BIN_NUM * lastDimTileNum * sortTileInfo.dtypeSize * sortTileInfo.unsortedDimParallel; |
| 455 | uint32_t allNumExcusiveBin = BIN_NUM * sortTileInfo.dtypeSize * sortTileInfo.unsortedDimParallel; | 473 | uint32_t allNumExcusiveBin = BIN_NUM * sortTileInfo.dtypeSize * sortTileInfo.unsortedDimParallel; |
| 456 | uint32_t oneCoreSize = CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.coreNumNeed)); | 474 | uint32_t oneCoreSize = CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.coreNumNeed)); |
| 457 | - sortTileInfo.keyParams5 = | 475 | + sortTileInfo.keyParams5 = std::max(static_cast<int64_t>(oneCoreSize), |
| 458 | - std::max(static_cast<int64_t>(oneCoreSize), static_cast<int64_t>(sortTileInfo.blockUbSize)); | 476 | + static_cast<int64_t>(sortTileInfo.blockUbSize)); |
| 459 | sortTileInfo.keyParams0 = CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.keyParams5)); | 477 | sortTileInfo.keyParams0 = CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.keyParams5)); |
| 460 | sortTileInfo.keyParams3 = CeilDiv1(int64_t(sortTileInfo.keyParams5), int64_t(ubSizeNum)); | 478 | sortTileInfo.keyParams3 = CeilDiv1(int64_t(sortTileInfo.keyParams5), int64_t(ubSizeNum)); |
| 461 | sortTileInfo.keyParams2 = sortTileInfo.keyParams5 > ubSizeNum ? ubSizeNum : sortTileInfo.keyParams5; | 479 | sortTileInfo.keyParams2 = sortTileInfo.keyParams5 > ubSizeNum ? ubSizeNum : sortTileInfo.keyParams5; |
| 462 | 480 | ||
| 463 | uint32_t oneCoreSize1 = CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.coreNumNeed)); | 481 | uint32_t oneCoreSize1 = CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.coreNumNeed)); |
| 464 | - sortTileInfo.keyParams4 = | 482 | + sortTileInfo.keyParams4 = std::max(static_cast<int64_t>(oneCoreSize1), |
| 465 | - std::max(static_cast<int64_t>(oneCoreSize1), static_cast<int64_t>(sortTileInfo.blockUbSize)); | 483 | + static_cast<int64_t>(sortTileInfo.blockUbSize)); |
| 466 | 484 | ||
| 467 | sortTileInfo.keyParams1 = CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.keyParams4)); | 485 | sortTileInfo.keyParams1 = CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.keyParams4)); |
| 468 | ComputeWorkSpace1(context, sortTileInfo); | 486 | ComputeWorkSpace1(context, sortTileInfo); |
| @@ -474,16 +492,16 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, int32_t maxCo | |||
| 474 | { | 492 | { |
| 475 | OP_LOGI(context->GetNodeName(), "SortWithIndexTIling start"); | 493 | OP_LOGI(context->GetNodeName(), "SortWithIndexTIling start"); |
| 476 | SortWithIndexTilingDataSimt sortTilingData; | 494 | SortWithIndexTilingDataSimt sortTilingData; |
| 477 | - const gert::Shape inputShape = | 495 | + const gert::Shape inputShape = Ops::Base::EnsureNotScalar(context->GetInputShape(0)->GetStorageShape()); |
| 478 | - Ops::Base::EnsureNotScalar(context->GetInputShape(0)->GetStorageShape()); | ||
| 479 | auto dataType = context->GetInputDesc(0)->GetDataType(); | 496 | auto dataType = context->GetInputDesc(0)->GetDataType(); |
| 480 | // out index type | 497 | // out index type |
| 481 | auto y2DType = context->GetOutputDesc(1)->GetDataType(); | 498 | auto y2DType = context->GetOutputDesc(1)->GetDataType(); |
| 482 | 499 | ||
| 483 | - OP_CHECK_IF(tilingDataTypeKeyMap.count(dataType) == 0, | 500 | + OP_CHECK_IF( |
| 484 | - OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "x", | 501 | + tilingDataTypeKeyMap.count(dataType) == 0, |
| 485 | - Ops::Base::ToString(dataType).c_str(), | 502 | + OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "x", Ops::Base::ToString(dataType).c_str(), |
| 486 | - "INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, FLOAT, FLOAT16, BF16"), return ge::GRAPH_FAILED); | 503 | + "INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, FLOAT, FLOAT16, BF16"), |
| 504 | + return ge::GRAPH_FAILED); | ||
| 487 | auto tilingKey = tilingDataTypeKeyMap.find(dataType)->second; | 505 | auto tilingKey = tilingDataTypeKeyMap.find(dataType)->second; |
| 488 | std::string opType(context->GetNodeType()); | 506 | std::string opType(context->GetNodeType()); |
| 489 | 507 | ||
| @@ -492,8 +510,9 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, int32_t maxCo | |||
| 492 | uint64_t ubSize = 0; | 510 | uint64_t ubSize = 0; |
| 493 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); | 511 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); |
| 494 | OP_CHECK_IF(ubSize <= static_cast<uint64_t>(SIMT_UB), | 512 | OP_CHECK_IF(ubSize <= static_cast<uint64_t>(SIMT_UB), |
| 495 | - OP_LOGE(context->GetNodeName(), "ubSize must be greater than %u, but is %lu", SIMT_UB, ubSize), | 513 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(), |
| 496 | - return ge::GRAPH_FAILED); | 514 | + "The value of ubSize must be greater than SIMT_UB."), |
| 515 | + return ge::GRAPH_FAILED); | ||
| 497 | 516 | ||
| 498 | OP_LOGW(context->GetNodeName(), "Get op_type[%s]", opType.c_str()); | 517 | OP_LOGW(context->GetNodeName(), "Get op_type[%s]", opType.c_str()); |
| 499 | 518 | ||
| @@ -534,7 +553,7 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, int32_t maxCo | |||
| 534 | sortTileInfo.isInt32 = isInInt32Range; | 553 | sortTileInfo.isInt32 = isInInt32Range; |
| 535 | sortTileInfo.isDescend = isDescending; | 554 | sortTileInfo.isDescend = isDescending; |
| 536 | sortTileInfo.numTileDataSize = tileData; | 555 | sortTileInfo.numTileDataSize = tileData; |
| 537 | - | 556 | + |
| 538 | // 设置高级api tmpUbSize需要的空间 | 557 | // 设置高级api tmpUbSize需要的空间 |
| 539 | SetSortTmpSizeOfIdx(dataType, sortAxisNum, tileData, *isDescending, true, sortTilingData, sortTileInfo); | 558 | SetSortTmpSizeOfIdx(dataType, sortAxisNum, tileData, *isDescending, true, sortTilingData, sortTileInfo); |
| 540 | if (sortAxisNum <= SMALL_SORT_MAX_DATA_SIZE && optDataTypeBitMap.count(dataType) != 0) { | 559 | if (sortAxisNum <= SMALL_SORT_MAX_DATA_SIZE && optDataTypeBitMap.count(dataType) != 0) { |
| @@ -551,9 +570,11 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, int32_t maxCo | |||
| 551 | sortTilingData.set_modeType(MULT_CORE_MODE); | 570 | sortTilingData.set_modeType(MULT_CORE_MODE); |
| 552 | TileMoreCoreModeOfIdx(context, sortTileInfo); | 571 | TileMoreCoreModeOfIdx(context, sortTileInfo); |
| 553 | } | 572 | } |
| 554 | - OP_LOGI(context->GetNodeName(), "ubSize: %ld, ubAglinSize: %ld, dtypeSize: %u, y2DtypeSize=%u," | 573 | + OP_LOGI(context->GetNodeName(), |
| 555 | - " sortTileInfo.ubSize=%u, maxCoreNum=%lu.", ubSize, blockUbAglinSize, | 574 | + "ubSize: %ld, ubAglinSize: %ld, dtypeSize: %u, y2DtypeSize=%u," |
| 556 | - sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, sortTileInfo.ubSize, maxCoreNum); | 575 | + " sortTileInfo.ubSize=%u, maxCoreNum=%lu.", |
| 576 | + ubSize, blockUbAglinSize, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, sortTileInfo.ubSize, | ||
| 577 | + maxCoreNum); | ||
| 557 | 578 | ||
| 558 | context->SetTilingKey(tilingKey); | 579 | context->SetTilingKey(tilingKey); |
| 559 | context->SetBlockDim(sortTileInfo.coreNumNeed); | 580 | context->SetBlockDim(sortTileInfo.coreNumNeed); |
| @@ -583,7 +604,9 @@ static ge::graphStatus Tiling4SortWithIndex(gert::TilingContext* context) | |||
| 583 | 604 | ||
| 584 | OP_LOGD(context->GetNodeName(), "AscendC SortWithIndex simt tiling"); | 605 | OP_LOGD(context->GetNodeName(), "AscendC SortWithIndex simt tiling"); |
| 585 | OP_CHECK_IF(SortWithIndexTilingSimt(context, compile_info->core_num) != ge::GRAPH_SUCCESS, | 606 | OP_CHECK_IF(SortWithIndexTilingSimt(context, compile_info->core_num) != ge::GRAPH_SUCCESS, |
| 586 | - OP_LOGE(context->GetNodeName(), "The simt tiling function failed"), return ge::GRAPH_FAILED); | 607 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "SortWithIndexTilingSimt", "GRAPH_FAILED", |
| 608 | + "The value of SortWithIndexTilingSimt must be GRAPH_SUCCESS."), | ||
| 609 | + return ge::GRAPH_FAILED); | ||
| 587 | 610 | ||
| 588 | return ge::GRAPH_SUCCESS; | 611 | return ge::GRAPH_SUCCESS; |
| 589 | } | 612 | } |
| @@ -598,9 +621,14 @@ static ge::graphStatus TilingPrepare4SortWithIndex(gert::TilingParseContext* con | |||
| 598 | auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | 621 | auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); |
| 599 | compileInfo->core_num = ascendcPlatform.GetCoreNumAiv(); | 622 | compileInfo->core_num = ascendcPlatform.GetCoreNumAiv(); |
| 600 | OP_CHECK_IF((compileInfo->core_num <= 0), | 623 | OP_CHECK_IF((compileInfo->core_num <= 0), |
| 601 | - OP_LOGE(context->GetNodeName(), "The core num is invaild."), return ge::GRAPH_FAILED); | 624 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "coreNum", |
| 625 | + std::to_string(compileInfo->core_num).c_str(), | ||
| 626 | + "The value of coreNum must be greater than 0."), | ||
| 627 | + return ge::GRAPH_FAILED); | ||
| 602 | return ge::GRAPH_SUCCESS; | 628 | return ge::GRAPH_SUCCESS; |
| 603 | } | 629 | } |
| 604 | 630 | ||
| 605 | -IMPL_OP_OPTILING(SortWithIndex).Tiling(Tiling4SortWithIndex).TilingParse<SortWithIndexCompileInfo>(TilingPrepare4SortWithIndex); | 631 | +IMPL_OP_OPTILING(SortWithIndex) |
| 632 | + .Tiling(Tiling4SortWithIndex) | ||
| 633 | + .TilingParse<SortWithIndexCompileInfo>(TilingPrepare4SortWithIndex); | ||
| 606 | } // namespace optiling | 634 | } // namespace optiling |
| @@ -17,9 +17,10 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | + | ||
| 21 | + | ||
| 20 | using namespace ge; | 22 | using namespace ge; |
| 21 | -namespace ops | 23 | +namespace ops { |
| 22 | -{ | ||
| 23 | static constexpr int INPUT_NODE_NUM = 2; | 24 | static constexpr int INPUT_NODE_NUM = 2; |
| 24 | static constexpr int OUTPUT_NODE_NUM = 2; | 25 | static constexpr int OUTPUT_NODE_NUM = 2; |
| 25 | static constexpr int X_IDX = 0; | 26 | static constexpr int X_IDX = 0; |
| @@ -33,7 +34,11 @@ ge::graphStatus InferShape4SortWithIndex(gert::InferShapeContext* context) | |||
| 33 | 34 | ||
| 34 | OP_CHECK_IF( | 35 | OP_CHECK_IF( |
| 35 | (context->GetComputeNodeInputNum() != INPUT_NODE_NUM || context->GetComputeNodeOutputNum() != OUTPUT_NODE_NUM), | 36 | (context->GetComputeNodeInputNum() != INPUT_NODE_NUM || context->GetComputeNodeOutputNum() != OUTPUT_NODE_NUM), |
| 36 | - OP_LOGE(context->GetNodeName(), "Get input or output num failed, infershape failed."), | 37 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "inputOutputNum", |
| 38 | + (std::to_string(context->GetComputeNodeInputNum()) + ", " + | ||
| 39 | + std::to_string(context->GetComputeNodeOutputNum())) | ||
| 40 | + .c_str(), | ||
| 41 | + "The values of input num and output num must be 2."), | ||
| 37 | return GRAPH_FAILED); | 42 | return GRAPH_FAILED); |
| 38 | 43 | ||
| 39 | const gert::Shape* xShape = context->GetInputShape(X_IDX); | 44 | const gert::Shape* xShape = context->GetInputShape(X_IDX); |
| @@ -41,14 +46,17 @@ ge::graphStatus InferShape4SortWithIndex(gert::InferShapeContext* context) | |||
| 41 | const gert::Shape* indexShape = context->GetInputShape(INDEX_IDX); | 46 | const gert::Shape* indexShape = context->GetInputShape(INDEX_IDX); |
| 42 | OP_CHECK_NULL_WITH_CONTEXT(context, indexShape); | 47 | OP_CHECK_NULL_WITH_CONTEXT(context, indexShape); |
| 43 | 48 | ||
| 44 | - bool isDynamicShape = (Ops::Base::IsUnknownRank(*xShape) || Ops::Base::IsUnknownRank(*indexShape) || | 49 | + bool isDynamicShape = (Ops::Base::IsUnknownRank(*xShape) || Ops::Base::IsUnknownRank(*indexShape) || |
| 45 | Ops::Base::IsUnknownShape(*xShape) || Ops::Base::IsUnknownShape(*indexShape)); | 50 | Ops::Base::IsUnknownShape(*xShape) || Ops::Base::IsUnknownShape(*indexShape)); |
| 46 | 51 | ||
| 47 | OP_LOGD(context->GetNodeName(), "isDynamicShape=[%d]", isDynamicShape); | 52 | OP_LOGD(context->GetNodeName(), "isDynamicShape=[%d]", isDynamicShape); |
| 48 | if (!isDynamicShape) { | 53 | if (!isDynamicShape) { |
| 49 | OP_CHECK_IF((*xShape != *indexShape), | 54 | OP_CHECK_IF((*xShape != *indexShape), |
| 50 | - OP_LOGE(context->GetNodeName(), "input[x] and input[index] shape is different, infershape failed."), | 55 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON( |
| 51 | - return GRAPH_FAILED); | 56 | + context->GetNodeName(), "x, index", |
| 57 | + (Ops::Base::ToString(*xShape) + ", " + Ops::Base::ToString(*indexShape)).c_str(), | ||
| 58 | + "The shapes of x and index must be the same."), | ||
| 59 | + return GRAPH_FAILED); | ||
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | gert::Shape* y1Shape = context->GetOutputShape(Y1_IDX); | 62 | gert::Shape* y1Shape = context->GetOutputShape(Y1_IDX); |
| @@ -64,4 +72,4 @@ ge::graphStatus InferShape4SortWithIndex(gert::InferShapeContext* context) | |||
| 64 | } | 72 | } |
| 65 | 73 | ||
| 66 | IMPL_OP_INFERSHAPE(SortWithIndex).InferShape(InferShape4SortWithIndex); | 74 | IMPL_OP_INFERSHAPE(SortWithIndex).InferShape(InferShape4SortWithIndex); |
| 67 | -} // namespace ops | 75 | +} // namespace ops |
| @@ -33,7 +33,9 @@ static graphStatus InferDataType4TopKV2(gert::InferDataTypeContext* context) | |||
| 33 | OP_LOGI(context->GetNodeName(), "The dtype of output indices is set as int64."); | 33 | OP_LOGI(context->GetNodeName(), "The dtype of output indices is set as int64."); |
| 34 | indicesDtype = ge::DT_INT64; | 34 | indicesDtype = ge::DT_INT64; |
| 35 | } else if (raw_indices_dtype != static_cast<int64_t>(ge::DataType::DT_INT32)) { | 35 | } else if (raw_indices_dtype != static_cast<int64_t>(ge::DataType::DT_INT32)) { |
| 36 | - OP_LOGE(context->GetNodeName(), "The dtype of output indices only support int64 or int32."); | 36 | + OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "indices_dtype", |
| 37 | + Ops::Base::ToString(static_cast<ge::DataType>(raw_indices_dtype)).c_str(), | ||
| 38 | + "INT32 or INT64"); | ||
| 37 | return GRAPH_FAILED; | 39 | return GRAPH_FAILED; |
| 38 | } | 40 | } |
| 39 | } | 41 | } |
| @@ -9,9 +9,9 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | /*! | 11 | /*! |
| 12 | -* \file sort_with_index_tiling.h | 12 | + * \file sort_with_index_tiling.h |
| 13 | -* \brief sort_with_index ac tiling impl | 13 | + * \brief sort_with_index ac tiling impl |
| 14 | -*/ | 14 | + */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| @@ -19,31 +19,33 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | + | ||
| 23 | + | ||
| 22 | namespace optiling { | 24 | namespace optiling { |
| 23 | namespace sortWithIndex { | 25 | namespace sortWithIndex { |
| 24 | -constexpr size_t WORK_SPACE_SIZE = 16777216; // 16 * 1024 * 1024; | 26 | +constexpr size_t WORK_SPACE_SIZE = 16777216; // 16 * 1024 * 1024; |
| 25 | const uint32_t BIN_NUM = 256; | 27 | const uint32_t BIN_NUM = 256; |
| 26 | const uint32_t TILE_DATA_NUM = 4096; | 28 | const uint32_t TILE_DATA_NUM = 4096; |
| 27 | const uint32_t MEDIUM_TILE_DATA_NUM = 2048; | 29 | const uint32_t MEDIUM_TILE_DATA_NUM = 2048; |
| 28 | const uint32_t SMALL_TILE_DATA_NUM = 1024; | 30 | const uint32_t SMALL_TILE_DATA_NUM = 1024; |
| 29 | const uint32_t TILE_DATA_NUM_B64 = 2048; | 31 | const uint32_t TILE_DATA_NUM_B64 = 2048; |
| 30 | -const uint32_t TMP_UB = 1024; // 暂预留给sort高级api的大小 | 32 | +const uint32_t TMP_UB = 1024; // 暂预留给sort高级api的大小 |
| 31 | -const uint32_t CONST_10 = 10; // int32索引时, 计算各种tensor的乘法因子 | 33 | +const uint32_t CONST_10 = 10; // int32索引时, 计算各种tensor的乘法因子 |
| 32 | -const uint32_t CONST_14 = 14; // int64索引时, 计算各种tensor的乘法因子 | 34 | +const uint32_t CONST_14 = 14; // int64索引时, 计算各种tensor的乘法因子 |
| 33 | -const uint32_t CONST_6 = 6; // int64索引时, 计算各种tensor的乘法因子 | 35 | +const uint32_t CONST_6 = 6; // int64索引时, 计算各种tensor的乘法因子 |
| 34 | const uint32_t CONST_1 = 1; | 36 | const uint32_t CONST_1 = 1; |
| 35 | const uint32_t CONST_2 = 2; | 37 | const uint32_t CONST_2 = 2; |
| 36 | const uint32_t INT64_BYTE = 8; | 38 | const uint32_t INT64_BYTE = 8; |
| 37 | const uint32_t INT32_BYTE = 4; | 39 | const uint32_t INT32_BYTE = 4; |
| 38 | -const uint32_t SIMT_UB = 32768; // 预留了32k给simt使用 | 40 | +const uint32_t SIMT_UB = 32768; // 预留了32k给simt使用 |
| 39 | -const uint32_t NEED_UB_SIZE_BYTE = 221184; // 预留了32k给simt使用 | 41 | +const uint32_t NEED_UB_SIZE_BYTE = 221184; // 预留了32k给simt使用 |
| 40 | const uint32_t SMALL_SORT_MAX_DATA_SIZE = 512; | 42 | const uint32_t SMALL_SORT_MAX_DATA_SIZE = 512; |
| 41 | const uint32_t AGLIN_VALUE = 32; | 43 | const uint32_t AGLIN_VALUE = 32; |
| 42 | const uint32_t MERGE_SORT_TILING_OFFSET = 10000; | 44 | const uint32_t MERGE_SORT_TILING_OFFSET = 10000; |
| 43 | -const uint32_t UB_CONST_INT32 = 4096; // 输出idx为int32时kernel侧需要的固定ub大小 | 45 | +const uint32_t UB_CONST_INT32 = 4096; // 输出idx为int32时kernel侧需要的固定ub大小 |
| 44 | -const uint32_t UB_CONST_INT64 = 7168; // 输出idx为int64时kernel侧需要的固定ub大小 | 46 | +const uint32_t UB_CONST_INT64 = 7168; // 输出idx为int64时kernel侧需要的固定ub大小 |
| 45 | -// 排序轴在int32范围内的最大值, 超过这个值, cutsum,前缀和就要用int64数据范围表示 | 47 | +// 排序轴在int32范围内的最大值, 超过这个值, cutsum,前缀和就要用int64数据范围表示 |
| 46 | -const uint32_t INT32_MAX_RANGE_VALUE = 1073741823; | 48 | +const uint32_t INT32_MAX_RANGE_VALUE = 1073741823; |
| 47 | const uint32_t SMALL_SIZE_OPTIM_MODE = 0; | 49 | const uint32_t SMALL_SIZE_OPTIM_MODE = 0; |
| 48 | const uint32_t SMALL_SIZE_MODE = 1; | 50 | const uint32_t SMALL_SIZE_MODE = 1; |
| 49 | const uint32_t MULT_CORE_MODE = 2; | 51 | const uint32_t MULT_CORE_MODE = 2; |
| @@ -72,7 +74,7 @@ struct SortTileInfo { | |||
| 72 | uint32_t isInt32 = 0; | 74 | uint32_t isInt32 = 0; |
| 73 | int32_t xDimNum = 0; | 75 | int32_t xDimNum = 0; |
| 74 | int64_t sortAxisNum = 1; | 76 | int64_t sortAxisNum = 1; |
| 75 | - int64_t unSortDimNum = 1; | 77 | + int64_t unSortDimNum = 1; |
| 76 | }; | 78 | }; |
| 77 | 79 | ||
| 78 | static const std::map<ge::DataType, uint32_t> tilingDataTypeKeyMap = { | 80 | static const std::map<ge::DataType, uint32_t> tilingDataTypeKeyMap = { |
| @@ -95,7 +97,7 @@ uint32_t CeilDiv1(int64_t a, int64_t b) | |||
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | template <typename T> | 99 | template <typename T> |
| 98 | -auto CeilDivMul1(int64_t a, int64_t b) ->T const | 100 | +auto CeilDivMul1(int64_t a, int64_t b) -> T const |
| 99 | { | 101 | { |
| 100 | if (b == 0) { | 102 | if (b == 0) { |
| 101 | return static_cast<T>(a); | 103 | return static_cast<T>(a); |
| @@ -104,7 +106,7 @@ auto CeilDivMul1(int64_t a, int64_t b) ->T const | |||
| 104 | } | 106 | } |
| 105 | 107 | ||
| 106 | void SetSortTmpSizeOfIdx(ge::DataType dataType, int64_t lastAxisNum, uint32_t tileData, bool isDescend, bool hasIndex, | 108 | void SetSortTmpSizeOfIdx(ge::DataType dataType, int64_t lastAxisNum, uint32_t tileData, bool isDescend, bool hasIndex, |
| 107 | - TopKV2TilingDataSimd& topkTilingData, sortWithIndex::SortTileInfo& sortTileInfo) | 109 | + TopKV2TilingDataSimd& topkTilingData, sortWithIndex::SortTileInfo& sortTileInfo) |
| 108 | { | 110 | { |
| 109 | int64_t reanLen = std::min(lastAxisNum, static_cast<int64_t>(tileData)); | 111 | int64_t reanLen = std::min(lastAxisNum, static_cast<int64_t>(tileData)); |
| 110 | std::vector<int64_t> shapeVec = {reanLen}; | 112 | std::vector<int64_t> shapeVec = {reanLen}; |
| @@ -125,19 +127,20 @@ void SetSortTmpSizeOfIdx(ge::DataType dataType, int64_t lastAxisNum, uint32_t ti | |||
| 125 | } | 127 | } |
| 126 | 128 | ||
| 127 | void SetMergeSortTmpSizeOfIdx(gert::TilingContext* context, ge::DataType dataType, int64_t lastAxisNum, | 129 | void SetMergeSortTmpSizeOfIdx(gert::TilingContext* context, ge::DataType dataType, int64_t lastAxisNum, |
| 128 | - TopKV2TilingDataSimd& topkTilingData) | 130 | + TopKV2TilingDataSimd& topkTilingData) |
| 129 | { | 131 | { |
| 130 | uint32_t reanLen = 0; | 132 | uint32_t reanLen = 0; |
| 131 | - if ((lastAxisNum <= sortWithIndex::SMALL_SORT_MAX_DATA_SIZE) && (sortWithIndex::optDataTypeBitMap.count(dataType) != 0)) { | 133 | + if ((lastAxisNum <= sortWithIndex::SMALL_SORT_MAX_DATA_SIZE) && |
| 134 | + (sortWithIndex::optDataTypeBitMap.count(dataType) != 0)) { | ||
| 132 | reanLen = std::min(static_cast<uint32_t>(lastAxisNum), sortWithIndex::SMALL_SORT_MAX_DATA_SIZE); | 135 | reanLen = std::min(static_cast<uint32_t>(lastAxisNum), sortWithIndex::SMALL_SORT_MAX_DATA_SIZE); |
| 133 | } | 136 | } |
| 134 | uint32_t aglinDataSize = static_cast<uint32_t>((reanLen + sortWithIndex::AGLIN_VALUE - 1) / | 137 | uint32_t aglinDataSize = static_cast<uint32_t>((reanLen + sortWithIndex::AGLIN_VALUE - 1) / |
| 135 | - sortWithIndex::AGLIN_VALUE * sortWithIndex::AGLIN_VALUE); | 138 | + sortWithIndex::AGLIN_VALUE * sortWithIndex::AGLIN_VALUE); |
| 136 | uint32_t dataTypeSize = (dataType == ge::DT_BF16) ? sortWithIndex::optDataTypeBitMap.find(ge::DT_FLOAT)->second : | 139 | uint32_t dataTypeSize = (dataType == ge::DT_BF16) ? sortWithIndex::optDataTypeBitMap.find(ge::DT_FLOAT)->second : |
| 137 | sortWithIndex::optDataTypeBitMap.find(dataType)->second; | 140 | sortWithIndex::optDataTypeBitMap.find(dataType)->second; |
| 138 | auto platform_info = context->GetPlatformInfo(); | 141 | auto platform_info = context->GetPlatformInfo(); |
| 139 | if (nullptr == platform_info) { | 142 | if (nullptr == platform_info) { |
| 140 | - OP_LOGE("[SortWithIndexTilingForAscendC]", "platform_info is nullptr."); | 143 | + OP_LOGE_WITH_INVALID_INPUT(context->GetNodeName(), "platform_info"); |
| 141 | } | 144 | } |
| 142 | auto plat = platform_ascendc::PlatformAscendC(platform_info); | 145 | auto plat = platform_ascendc::PlatformAscendC(platform_info); |
| 143 | uint32_t dataSizeNeed = AscendC::GetConcatTmpSize(plat, aglinDataSize, dataTypeSize); | 146 | uint32_t dataSizeNeed = AscendC::GetConcatTmpSize(plat, aglinDataSize, dataTypeSize); |
| @@ -146,15 +149,19 @@ void SetMergeSortTmpSizeOfIdx(gert::TilingContext* context, ge::DataType dataTyp | |||
| 146 | topkTilingData.set_mergSortAcApiNeedBufferSizeForSort(dataSizeNeed); | 149 | topkTilingData.set_mergSortAcApiNeedBufferSizeForSort(dataSizeNeed); |
| 147 | } | 150 | } |
| 148 | 151 | ||
| 149 | -void TileModeSmallSizeOptimOfIdx( | 152 | +void TileModeSmallSizeOptimOfIdx(uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_t lastAxisNum, uint32_t tileData, |
| 150 | - uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_t lastAxisNum, uint32_t tileData, SortTileInfo& sortTileInfo) | 153 | + SortTileInfo& sortTileInfo) |
| 151 | { | 154 | { |
| 152 | uint32_t aglinNum = static_cast<uint32_t>((lastAxisNum + AGLIN_VALUE - 1) / AGLIN_VALUE * AGLIN_VALUE); | 155 | uint32_t aglinNum = static_cast<uint32_t>((lastAxisNum + AGLIN_VALUE - 1) / AGLIN_VALUE * AGLIN_VALUE); |
| 153 | uint32_t oneCoreRowNum = static_cast<uint32_t>((tileData / 2) / aglinNum); | 156 | uint32_t oneCoreRowNum = static_cast<uint32_t>((tileData / 2) / aglinNum); |
| 154 | oneCoreRowNum = static_cast<uint32_t>(oneCoreRowNum == 0 ? 1 : oneCoreRowNum); | 157 | oneCoreRowNum = static_cast<uint32_t>(oneCoreRowNum == 0 ? 1 : oneCoreRowNum); |
| 155 | uint32_t virUnsortedDimNum = static_cast<uint32_t>((unsortedDimNum + oneCoreRowNum - 1) / oneCoreRowNum); | 158 | uint32_t virUnsortedDimNum = static_cast<uint32_t>((unsortedDimNum + oneCoreRowNum - 1) / oneCoreRowNum); |
| 156 | uint32_t coreNumNeed = 0; | 159 | uint32_t coreNumNeed = 0; |
| 157 | - OP_CHECK_IF(maxCoreNum == 0, OP_LOGE("TileModeSmallSizeOptimOfIdx", "maxCoreNum is zero"), return); | 160 | + OP_CHECK_IF(maxCoreNum == 0, |
| 161 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("TileModeSmallSizeOptimOfIdx", "maxCoreNum", | ||
| 162 | + std::to_string(maxCoreNum).c_str(), | ||
| 163 | + "The value of maxCoreNum must be greater than 0."), | ||
| 164 | + return); | ||
| 158 | uint32_t sortLoopTimes = static_cast<uint32_t>((virUnsortedDimNum + maxCoreNum - 1) / maxCoreNum); | 165 | uint32_t sortLoopTimes = static_cast<uint32_t>((virUnsortedDimNum + maxCoreNum - 1) / maxCoreNum); |
| 159 | if (sortLoopTimes == 1u) { | 166 | if (sortLoopTimes == 1u) { |
| 160 | uint32_t realCoreNum = virUnsortedDimNum % maxCoreNum; | 167 | uint32_t realCoreNum = virUnsortedDimNum % maxCoreNum; |
| @@ -172,15 +179,21 @@ void TileModeSmallSizeOptimOfIdx( | |||
| 172 | sortTileInfo.lastDimNeedCore = 1; | 179 | sortTileInfo.lastDimNeedCore = 1; |
| 173 | sortTileInfo.sortLoopTimes = sortLoopTimes; | 180 | sortTileInfo.sortLoopTimes = sortLoopTimes; |
| 174 | sortTileInfo.numTileDataSize = lastAxisNum; | 181 | sortTileInfo.numTileDataSize = lastAxisNum; |
| 175 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "Small size opt mode coreNumNeed=%u, sortLoopTimes=%u, lastAxisNum=%ld, " | 182 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 176 | - "oneCoreRowNum=%ld, ubsize=%lu.", coreNumNeed, sortLoopTimes, lastAxisNum, oneCoreRowNum, sortTileInfo.ubSize); | 183 | + "Small size opt mode coreNumNeed=%u, sortLoopTimes=%u, lastAxisNum=%ld, " |
| 184 | + "oneCoreRowNum=%ld, ubsize=%lu.", | ||
| 185 | + coreNumNeed, sortLoopTimes, lastAxisNum, oneCoreRowNum, sortTileInfo.ubSize); | ||
| 177 | } | 186 | } |
| 178 | 187 | ||
| 179 | void TileModeSmallSizeOfIdx(uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_t lastAxisNum, | 188 | void TileModeSmallSizeOfIdx(uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_t lastAxisNum, |
| 180 | - sortWithIndex::SortTileInfo& sortTileInfo) | 189 | + sortWithIndex::SortTileInfo& sortTileInfo) |
| 181 | { | 190 | { |
| 182 | uint32_t coreNumNeed = 0; | 191 | uint32_t coreNumNeed = 0; |
| 183 | - OP_CHECK_IF(maxCoreNum == 0, OP_LOGE("TileModeSmallSizeOfIdx", "maxCoreNum is zero"), return); | 192 | + OP_CHECK_IF(maxCoreNum == 0, |
| 193 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("TileModeSmallSizeOfIdx", "maxCoreNum", | ||
| 194 | + std::to_string(maxCoreNum).c_str(), | ||
| 195 | + "The value of maxCoreNum must be greater than 0."), | ||
| 196 | + return); | ||
| 184 | uint32_t sortLoopTimes = static_cast<uint32_t>((unsortedDimNum + maxCoreNum - 1) / maxCoreNum); | 197 | uint32_t sortLoopTimes = static_cast<uint32_t>((unsortedDimNum + maxCoreNum - 1) / maxCoreNum); |
| 185 | if (sortLoopTimes == 1u) { | 198 | if (sortLoopTimes == 1u) { |
| 186 | uint32_t realCoreNum = unsortedDimNum % maxCoreNum; | 199 | uint32_t realCoreNum = unsortedDimNum % maxCoreNum; |
| @@ -197,34 +210,36 @@ void TileModeSmallSizeOfIdx(uint64_t unsortedDimNum, uint32_t maxCoreNum, int64_ | |||
| 197 | sortTileInfo.lastDimNeedCore = 1; | 210 | sortTileInfo.lastDimNeedCore = 1; |
| 198 | sortTileInfo.numTileDataSize = static_cast<uint32_t>(lastAxisNum); | 211 | sortTileInfo.numTileDataSize = static_cast<uint32_t>(lastAxisNum); |
| 199 | sortTileInfo.sortLoopTimes = sortLoopTimes; | 212 | sortTileInfo.sortLoopTimes = sortLoopTimes; |
| 200 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "Small size mode coreNumNeed=%u sortLoopTimes=%u " | 213 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 201 | - "lastAxisNum=%ld", coreNumNeed, sortLoopTimes, lastAxisNum); | 214 | + "Small size mode coreNumNeed=%u sortLoopTimes=%u " |
| 215 | + "lastAxisNum=%ld", | ||
| 216 | + coreNumNeed, sortLoopTimes, lastAxisNum); | ||
| 202 | } | 217 | } |
| 203 | 218 | ||
| 204 | -void PrintTilingDataOfIdx(sortWithIndex::SortTileInfo& sortTileInfo, TopKV2TilingDataSimd &topkTilingData) | 219 | +void PrintTilingDataOfIdx(sortWithIndex::SortTileInfo& sortTileInfo, TopKV2TilingDataSimd& topkTilingData) |
| 205 | { | 220 | { |
| 206 | - OP_LOGI( | 221 | + OP_LOGI("[Print SortWithIndexTilingForAscendC TilingData]", |
| 207 | - "[Print SortWithIndexTilingForAscendC TilingData]", | 222 | + "coreNum is %u, lastAxisNum is %ld, isInInt32Range is %u, " |
| 208 | - "coreNum is %u, lastAxisNum is %ld, isInInt32Range is %u, " | 223 | + "sortLoopTimes is %u, unsortedDimParallel is %u, unsortedDimNum is %u, " |
| 209 | - "sortLoopTimes is %u, unsortedDimParallel is %u, unsortedDimNum is %u, " | 224 | + "lastDimTileNum is %u, lastDimNeedCore is %u, numTileDataSize is %u, " |
| 210 | - "lastDimTileNum is %u, lastDimNeedCore is %u, numTileDataSize is %u, " | 225 | + "sortAcApiNeedBufferSize is %u, mergSortAcApiNeedBufferSize is %u, " |
| 211 | - "sortAcApiNeedBufferSize is %u, mergSortAcApiNeedBufferSize is %u, " | 226 | + "oneCoreRowNum is %u, outputLastDimValue is %u, tmp ub size is %u, " |
| 212 | - "oneCoreRowNum is %u, outputLastDimValue is %u, tmp ub size is %u, " | 227 | + "keyParams0 is %u, keyParams1 is %u, keyParams2 is %u, keyParams3 is %u, keyParams4 is %u, " |
| 213 | - "keyParams0 is %u, keyParams1 is %u, keyParams2 is %u, keyParams3 is %u, keyParams4 is %u, " | 228 | + "keyParams5 is %u, ub avalibal size=%lu, modeType=%u.", |
| 214 | - "keyParams5 is %u, ub avalibal size=%lu, modeType=%u.", | 229 | + sortTileInfo.coreNumNeed, topkTilingData.get_lastAxisNumForSort(), |
| 215 | - sortTileInfo.coreNumNeed, topkTilingData.get_lastAxisNumForSort(), topkTilingData.get_isInInt32RangeForSort(), | 230 | + topkTilingData.get_isInInt32RangeForSort(), topkTilingData.get_sortLoopTimesForSort(), |
| 216 | - topkTilingData.get_sortLoopTimesForSort(), topkTilingData.get_unsortedDimParallelForSort(), | 231 | + topkTilingData.get_unsortedDimParallelForSort(), topkTilingData.get_unsortedDimNumForSort(), |
| 217 | - topkTilingData.get_unsortedDimNumForSort(), topkTilingData.get_lastDimTileNumForSort(), | 232 | + topkTilingData.get_lastDimTileNumForSort(), topkTilingData.get_lastDimNeedCoreForSort(), |
| 218 | - topkTilingData.get_lastDimNeedCoreForSort(),topkTilingData.get_numTileDataSizeForSort(), | 233 | + topkTilingData.get_numTileDataSizeForSort(), topkTilingData.get_sortAcApiNeedBufferSizeForSort(), |
| 219 | - topkTilingData.get_sortAcApiNeedBufferSizeForSort(),topkTilingData.get_mergSortAcApiNeedBufferSizeForSort(), | 234 | + topkTilingData.get_mergSortAcApiNeedBufferSizeForSort(), topkTilingData.get_oneCoreRowNumForSort(), |
| 220 | - topkTilingData.get_oneCoreRowNumForSort(), topkTilingData.get_outputLastDimValueForSort(), | 235 | + topkTilingData.get_outputLastDimValueForSort(), topkTilingData.get_tmpUbSize(), |
| 221 | - topkTilingData.get_tmpUbSize(), topkTilingData.get_keyParams0(), topkTilingData.get_keyParams1(), | 236 | + topkTilingData.get_keyParams0(), topkTilingData.get_keyParams1(), topkTilingData.get_keyParams2(), |
| 222 | - topkTilingData.get_keyParams2(), topkTilingData.get_keyParams3(), topkTilingData.get_keyParams4(), | 237 | + topkTilingData.get_keyParams3(), topkTilingData.get_keyParams4(), topkTilingData.get_keyParams5(), |
| 223 | - topkTilingData.get_keyParams5(), sortTileInfo.ubSize, topkTilingData.get_modeTypeForSort()); | 238 | + sortTileInfo.ubSize, topkTilingData.get_modeTypeForSort()); |
| 224 | return; | 239 | return; |
| 225 | } | 240 | } |
| 226 | 241 | ||
| 227 | -void FillRadixSortTilingDataSort(sortWithIndex::SortTileInfo &sortTileInfo, TopKV2TilingDataSimd &topkTilingData) | 242 | +void FillRadixSortTilingDataSort(sortWithIndex::SortTileInfo& sortTileInfo, TopKV2TilingDataSimd& topkTilingData) |
| 228 | { | 243 | { |
| 229 | topkTilingData.set_numTileDataSizeForSort(sortTileInfo.numTileDataSize); | 244 | topkTilingData.set_numTileDataSizeForSort(sortTileInfo.numTileDataSize); |
| 230 | topkTilingData.set_unsortedDimParallelForSort(sortTileInfo.unsortedDimParallel); | 245 | topkTilingData.set_unsortedDimParallelForSort(sortTileInfo.unsortedDimParallel); |
| @@ -243,10 +258,10 @@ void FillRadixSortTilingDataSort(sortWithIndex::SortTileInfo &sortTileInfo, TopK | |||
| 243 | return; | 258 | return; |
| 244 | } | 259 | } |
| 245 | 260 | ||
| 246 | -void SetSortTmpSize1(ge::DataType dataType, uint32_t tileData, bool isDescend, SortTileInfo &sortTileInfo) | 261 | +void SetSortTmpSize1(ge::DataType dataType, uint32_t tileData, bool isDescend, SortTileInfo& sortTileInfo) |
| 247 | { | 262 | { |
| 248 | int64_t realLen = std::min(sortTileInfo.sortAxisNum, static_cast<int64_t>(tileData)); | 263 | int64_t realLen = std::min(sortTileInfo.sortAxisNum, static_cast<int64_t>(tileData)); |
| 249 | - std::vector<int64_t> shapeVec = { realLen }; | 264 | + std::vector<int64_t> shapeVec = {realLen}; |
| 250 | ge::Shape srcShape(shapeVec); | 265 | ge::Shape srcShape(shapeVec); |
| 251 | AscendC::SortConfig config; | 266 | AscendC::SortConfig config; |
| 252 | config.type = AscendC::SortType::RADIX_SORT; | 267 | config.type = AscendC::SortType::RADIX_SORT; |
| @@ -260,26 +275,30 @@ void SetSortTmpSize1(ge::DataType dataType, uint32_t tileData, bool isDescend, S | |||
| 260 | return; | 275 | return; |
| 261 | } | 276 | } |
| 262 | 277 | ||
| 263 | -uint32_t ComputeRemainUb1(SortTileInfo &sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) | 278 | +uint32_t ComputeRemainUb1(SortTileInfo& sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) |
| 264 | { | 279 | { |
| 265 | uint32_t tmpUb = sortTileInfo.ubSize - (ubExtra + tileFactor * tileData); | 280 | uint32_t tmpUb = sortTileInfo.ubSize - (ubExtra + tileFactor * tileData); |
| 266 | - OP_LOGD("[SortWithIndexTilingForAscendC]", "ComputeRemainUb1 ubSize=%u, ubExtra=%lu, tileFactor=%lu, " | 281 | + OP_LOGD("[SortWithIndexTilingForAscendC]", |
| 267 | - "tileData=%lu, tmpUb=%lu.", sortTileInfo.ubSize, ubExtra, tileFactor, tileData, tmpUb); | 282 | + "ComputeRemainUb1 ubSize=%u, ubExtra=%lu, tileFactor=%lu, " |
| 283 | + "tileData=%lu, tmpUb=%lu.", | ||
| 284 | + sortTileInfo.ubSize, ubExtra, tileFactor, tileData, tmpUb); | ||
| 268 | return tmpUb; | 285 | return tmpUb; |
| 269 | } | 286 | } |
| 270 | 287 | ||
| 271 | -void AdjTmpUb1(SortTileInfo &sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) | 288 | +void AdjTmpUb1(SortTileInfo& sortTileInfo, uint32_t tileData, uint32_t ubExtra, uint32_t tileFactor) |
| 272 | { | 289 | { |
| 273 | uint32_t remainUbNew = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor) - sortTileInfo.tmpUbSize; | 290 | uint32_t remainUbNew = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor) - sortTileInfo.tmpUbSize; |
| 274 | remainUbNew = remainUbNew > sortTileInfo.blockUbSize ? (remainUbNew - sortTileInfo.blockUbSize) : uint32_t(0); | 291 | remainUbNew = remainUbNew > sortTileInfo.blockUbSize ? (remainUbNew - sortTileInfo.blockUbSize) : uint32_t(0); |
| 275 | uint32_t alignUbSize = (remainUbNew / sortTileInfo.blockUbSize) * sortTileInfo.blockUbSize; | 292 | uint32_t alignUbSize = (remainUbNew / sortTileInfo.blockUbSize) * sortTileInfo.blockUbSize; |
| 276 | - OP_LOGD("[SortWithIndexTilingForAscendC]", "alignUbSize %u, sortTileInfo.tmpUbSize=%lu, " | 293 | + OP_LOGD("[SortWithIndexTilingForAscendC]", |
| 277 | - "sortTileInfo.blockUbSize=%lu.", alignUbSize, sortTileInfo.tmpUbSize, sortTileInfo.blockUbSize); | 294 | + "alignUbSize %u, sortTileInfo.tmpUbSize=%lu, " |
| 295 | + "sortTileInfo.blockUbSize=%lu.", | ||
| 296 | + alignUbSize, sortTileInfo.tmpUbSize, sortTileInfo.blockUbSize); | ||
| 278 | sortTileInfo.tmpUbSize = sortTileInfo.tmpUbSize + alignUbSize; // 剩余的ub都给tmpUbsize | 297 | sortTileInfo.tmpUbSize = sortTileInfo.tmpUbSize + alignUbSize; // 剩余的ub都给tmpUbsize |
| 279 | } | 298 | } |
| 280 | 299 | ||
| 281 | -void ComputeTileDataOne1(SortTileInfo &sortTileInfo, uint32_t lastDimTileNum, uint32_t ubExtra, uint32_t &tileData, | 300 | +void ComputeTileDataOne1(SortTileInfo& sortTileInfo, uint32_t lastDimTileNum, uint32_t ubExtra, uint32_t& tileData, |
| 282 | - uint32_t tileFactor) | 301 | + uint32_t tileFactor) |
| 283 | { | 302 | { |
| 284 | uint32_t allCore = CeilDivMul1<uint32_t>(int64_t(lastDimTileNum), int64_t(sortTileInfo.maxCoreNum)); | 303 | uint32_t allCore = CeilDivMul1<uint32_t>(int64_t(lastDimTileNum), int64_t(sortTileInfo.maxCoreNum)); |
| 285 | uint32_t newTileData = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(allCore)); | 304 | uint32_t newTileData = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(allCore)); |
| @@ -290,8 +309,8 @@ void ComputeTileDataOne1(SortTileInfo &sortTileInfo, uint32_t lastDimTileNum, u | |||
| 290 | return; | 309 | return; |
| 291 | } | 310 | } |
| 292 | 311 | ||
| 293 | -bool NeedAdjTileData1(SortTileInfo &sortTileInfo, uint32_t &tileData, uint32_t lastDimTileNum, uint32_t ubExtra, | 312 | +bool NeedAdjTileData1(SortTileInfo& sortTileInfo, uint32_t& tileData, uint32_t lastDimTileNum, uint32_t ubExtra, |
| 294 | - uint32_t tileFactor) | 313 | + uint32_t tileFactor) |
| 295 | { | 314 | { |
| 296 | if (sortTileInfo.unSortDimNum == 1L && lastDimTileNum == 1U) { | 315 | if (sortTileInfo.unSortDimNum == 1L && lastDimTileNum == 1U) { |
| 297 | OP_LOGI("[SortWithIndexTilingForAscendC]", "unSortDimNum and lastDimTileNum is 1"); | 316 | OP_LOGI("[SortWithIndexTilingForAscendC]", "unSortDimNum and lastDimTileNum is 1"); |
| @@ -310,8 +329,8 @@ bool NeedAdjTileData1(SortTileInfo &sortTileInfo, uint32_t &tileData, uint32_t l | |||
| 310 | } | 329 | } |
| 311 | if (sortTileInfo.unSortDimNum > 1L && sortTileInfo.unSortDimNum < int64_t(sortTileInfo.maxCoreNum) && | 330 | if (sortTileInfo.unSortDimNum > 1L && sortTileInfo.unSortDimNum < int64_t(sortTileInfo.maxCoreNum) && |
| 312 | lastDimTileNum == 1U) { | 331 | lastDimTileNum == 1U) { |
| 313 | - OP_LOGI("[SortWithIndexTilingForAscendC]", | 332 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 314 | - "unSortDimNum greater than 1,and unSortDimNum small and lastDimTileNum is one"); | 333 | + "unSortDimNum greater than 1,and unSortDimNum small and lastDimTileNum is one"); |
| 315 | uint32_t hCore = sortTileInfo.maxCoreNum / static_cast<uint32_t>(sortTileInfo.unSortDimNum); | 334 | uint32_t hCore = sortTileInfo.maxCoreNum / static_cast<uint32_t>(sortTileInfo.unSortDimNum); |
| 316 | uint32_t hTileData = static_cast<uint32_t>(sortTileInfo.sortAxisNum) / hCore; | 335 | uint32_t hTileData = static_cast<uint32_t>(sortTileInfo.sortAxisNum) / hCore; |
| 317 | tileData = CeilDivMul1<uint32_t>(int64_t(hTileData), int64_t(BIN_NUM)); | 336 | tileData = CeilDivMul1<uint32_t>(int64_t(hTileData), int64_t(BIN_NUM)); |
| @@ -344,7 +363,7 @@ bool NeedAdjTileData1(SortTileInfo &sortTileInfo, uint32_t &tileData, uint32_t l | |||
| 344 | return false; | 363 | return false; |
| 345 | } | 364 | } |
| 346 | 365 | ||
| 347 | -uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | 366 | +uint32_t ComputeTileData1(SortTileInfo& sortTileInfo) |
| 348 | { | 367 | { |
| 349 | uint32_t ubExtra; | 368 | uint32_t ubExtra; |
| 350 | uint32_t tileFactor; | 369 | uint32_t tileFactor; |
| @@ -358,8 +377,10 @@ uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | |||
| 358 | 377 | ||
| 359 | uint32_t tileData = (sortTileInfo.ubSize - ubExtra) / tileFactor; | 378 | uint32_t tileData = (sortTileInfo.ubSize - ubExtra) / tileFactor; |
| 360 | tileData = (tileData / BIN_NUM) * BIN_NUM; | 379 | tileData = (tileData / BIN_NUM) * BIN_NUM; |
| 361 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "ubExtra=%u, tileFactor=%u, dtypeSize=%u, y2DtypeSize=%lu, " | 380 | + OP_LOGI("[SortWithIndexTilingForAscendC]", |
| 362 | - "tileData=%lu.", ubExtra, tileFactor, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, tileData); | 381 | + "ubExtra=%u, tileFactor=%u, dtypeSize=%u, y2DtypeSize=%lu, " |
| 382 | + "tileData=%lu.", | ||
| 383 | + ubExtra, tileFactor, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, tileData); | ||
| 363 | uint32_t remainUb = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor); | 384 | uint32_t remainUb = ComputeRemainUb1(sortTileInfo, tileData, ubExtra, tileFactor); |
| 364 | SetSortTmpSize1(ge::DT_UINT8, tileData, false, sortTileInfo); | 385 | SetSortTmpSize1(ge::DT_UINT8, tileData, false, sortTileInfo); |
| 365 | 386 | ||
| @@ -371,10 +392,10 @@ uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | |||
| 371 | tmpUbSize = sortTileInfo.tmpUbSize; | 392 | tmpUbSize = sortTileInfo.tmpUbSize; |
| 372 | } | 393 | } |
| 373 | uint32_t lastDimTileNum = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(tileData)); | 394 | uint32_t lastDimTileNum = CeilDiv1(sortTileInfo.sortAxisNum, int64_t(tileData)); |
| 374 | - OP_LOGI("[SortWithIndexTilingForAscendC]", "tileData %u, lastDimTileNum %u, tmpUbSize %u", tileData, | 395 | + OP_LOGI("[SortWithIndexTilingForAscendC]", "tileData %u, lastDimTileNum %u, tmpUbSize %u", tileData, lastDimTileNum, |
| 375 | - lastDimTileNum, tmpUbSize); | 396 | + tmpUbSize); |
| 376 | - bool smallTile = | 397 | + bool smallTile = (sortTileInfo.sortAxisNum <= static_cast<int64_t>(SMALL_TILE_DATA_NUM)) && |
| 377 | - (sortTileInfo.sortAxisNum <= static_cast<int64_t>(SMALL_TILE_DATA_NUM)) && lastDimTileNum == uint32_t(1); | 398 | + lastDimTileNum == uint32_t(1); |
| 378 | if ((lastDimTileNum % sortTileInfo.maxCoreNum == 0U) || smallTile) { | 399 | if ((lastDimTileNum % sortTileInfo.maxCoreNum == 0U) || smallTile) { |
| 379 | OP_LOGI("[SortWithIndexTilingForAscendC]", "lastDimTileNum align or smallTile"); | 400 | OP_LOGI("[SortWithIndexTilingForAscendC]", "lastDimTileNum align or smallTile"); |
| 380 | AdjTmpUb1(sortTileInfo, tileData, ubExtra, tileFactor); | 401 | AdjTmpUb1(sortTileInfo, tileData, ubExtra, tileFactor); |
| @@ -387,7 +408,7 @@ uint32_t ComputeTileData1(SortTileInfo &sortTileInfo) | |||
| 387 | return tileData; | 408 | return tileData; |
| 388 | } | 409 | } |
| 389 | 410 | ||
| 390 | -void ComputeWorkSpace1(sortWithIndex::SortTileInfo &sortTileInfo, size_t* usrSize) | 411 | +void ComputeWorkSpace1(sortWithIndex::SortTileInfo& sortTileInfo, size_t* usrSize) |
| 391 | { | 412 | { |
| 392 | uint32_t dtypeSizeWk = static_cast<uint32_t>(sizeof(int32_t)); | 413 | uint32_t dtypeSizeWk = static_cast<uint32_t>(sizeof(int32_t)); |
| 393 | if (sortTileInfo.isInt32 == 0U) { | 414 | if (sortTileInfo.isInt32 == 0U) { |
| @@ -395,50 +416,52 @@ void ComputeWorkSpace1(sortWithIndex::SortTileInfo &sortTileInfo, size_t* usrSiz | |||
| 395 | } | 416 | } |
| 396 | size_t excusiveBinsGmWkSize = static_cast<size_t>(sortTileInfo.keyParams1) * sortTileInfo.keyParams4 * dtypeSizeWk; | 417 | size_t excusiveBinsGmWkSize = static_cast<size_t>(sortTileInfo.keyParams1) * sortTileInfo.keyParams4 * dtypeSizeWk; |
| 397 | excusiveBinsGmWkSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(excusiveBinsGmWkSize), | 418 | excusiveBinsGmWkSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(excusiveBinsGmWkSize), |
| 398 | - int64_t(sortTileInfo.blockUbSize)); | 419 | + int64_t(sortTileInfo.blockUbSize)); |
| 399 | 420 | ||
| 400 | - size_t globalHistGmWkSize = | 421 | + size_t globalHistGmWkSize = static_cast<size_t>(sortTileInfo.keyParams3) * sortTileInfo.keyParams2 * |
| 401 | - static_cast<size_t>(sortTileInfo.keyParams3) * sortTileInfo.keyParams2 * sortTileInfo.keyParams0 * dtypeSizeWk; | 422 | + sortTileInfo.keyParams0 * dtypeSizeWk; |
| 402 | - globalHistGmWkSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(globalHistGmWkSize), int64_t(sortTileInfo.blockUbSize)); | 423 | + globalHistGmWkSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(globalHistGmWkSize), |
| 424 | + int64_t(sortTileInfo.blockUbSize)); | ||
| 403 | 425 | ||
| 404 | - size_t outIdxDbWK = | 426 | + size_t outIdxDbWK = static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * |
| 405 | - static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * sortTileInfo.y2DtypeSize; | 427 | + sortTileInfo.y2DtypeSize; |
| 406 | outIdxDbWK = sortWithIndex::CeilDivMul1<size_t>(int64_t(outIdxDbWK), int64_t(sortTileInfo.blockUbSize)); | 428 | outIdxDbWK = sortWithIndex::CeilDivMul1<size_t>(int64_t(outIdxDbWK), int64_t(sortTileInfo.blockUbSize)); |
| 407 | 429 | ||
| 408 | size_t histTileGmWk = static_cast<size_t>(sortTileInfo.lastDimTileNum) * sortWithIndex::BIN_NUM * | 430 | size_t histTileGmWk = static_cast<size_t>(sortTileInfo.lastDimTileNum) * sortWithIndex::BIN_NUM * |
| 409 | - sortTileInfo.unsortedDimParallel * sizeof(int16_t) * sortWithIndex::CONST_2; | 431 | + sortTileInfo.unsortedDimParallel * sizeof(int16_t) * sortWithIndex::CONST_2; |
| 410 | 432 | ||
| 411 | size_t xB8GmWkSize = static_cast<size_t>(sortTileInfo.lastDimTileNum) * sortTileInfo.numTileDataSize * | 433 | size_t xB8GmWkSize = static_cast<size_t>(sortTileInfo.lastDimTileNum) * sortTileInfo.numTileDataSize * |
| 412 | - sortTileInfo.unsortedDimParallel; | 434 | + sortTileInfo.unsortedDimParallel; |
| 413 | xB8GmWkSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(xB8GmWkSize), int64_t(sortTileInfo.blockUbSize)); | 435 | xB8GmWkSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(xB8GmWkSize), int64_t(sortTileInfo.blockUbSize)); |
| 414 | 436 | ||
| 415 | - size_t outValueDbWKSize = | 437 | + size_t outValueDbWKSize = static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * |
| 416 | - static_cast<size_t>(sortTileInfo.sortAxisNum) * sortTileInfo.unsortedDimParallel * sortTileInfo.dtypeSize; | 438 | + sortTileInfo.dtypeSize; |
| 417 | outValueDbWKSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(outValueDbWKSize), int64_t(sortTileInfo.blockUbSize)); | 439 | outValueDbWKSize = sortWithIndex::CeilDivMul1<size_t>(int64_t(outValueDbWKSize), int64_t(sortTileInfo.blockUbSize)); |
| 418 | *usrSize += excusiveBinsGmWkSize + globalHistGmWkSize + outIdxDbWK + histTileGmWk + xB8GmWkSize + outValueDbWKSize; | 440 | *usrSize += excusiveBinsGmWkSize + globalHistGmWkSize + outIdxDbWK + histTileGmWk + xB8GmWkSize + outValueDbWKSize; |
| 419 | OP_LOGD("[SortWithIndexTilingForAscendC]", | 441 | OP_LOGD("[SortWithIndexTilingForAscendC]", |
| 420 | - "excusiveBinsGmWkSize=%lu, globalHistGmWkSize=%lu, histTileGmWk=%lu," | 442 | + "excusiveBinsGmWkSize=%lu, globalHistGmWkSize=%lu, histTileGmWk=%lu," |
| 421 | - " xB8GmWkSize=%lu, outValueDbWKSize=%lu, outIdxDbWK=%lu, usrSize=%lu.", | 443 | + " xB8GmWkSize=%lu, outValueDbWKSize=%lu, outIdxDbWK=%lu, usrSize=%lu.", |
| 422 | - excusiveBinsGmWkSize, globalHistGmWkSize, histTileGmWk, xB8GmWkSize, outValueDbWKSize, outIdxDbWK, *usrSize); | 444 | + excusiveBinsGmWkSize, globalHistGmWkSize, histTileGmWk, xB8GmWkSize, outValueDbWKSize, outIdxDbWK, |
| 445 | + *usrSize); | ||
| 423 | return; | 446 | return; |
| 424 | } | 447 | } |
| 425 | 448 | ||
| 426 | -void TileMoreCoreModeOfIdx(sortWithIndex::SortTileInfo &sortTileInfo, size_t* usrSize) | 449 | +void TileMoreCoreModeOfIdx(sortWithIndex::SortTileInfo& sortTileInfo, size_t* usrSize) |
| 427 | { | 450 | { |
| 428 | uint32_t tileData = sortWithIndex::ComputeTileData1(sortTileInfo); | 451 | uint32_t tileData = sortWithIndex::ComputeTileData1(sortTileInfo); |
| 429 | uint32_t lastDimTileNum = sortWithIndex::CeilDiv1(int64_t(sortTileInfo.sortAxisNum), int64_t(tileData)); | 452 | uint32_t lastDimTileNum = sortWithIndex::CeilDiv1(int64_t(sortTileInfo.sortAxisNum), int64_t(tileData)); |
| 430 | if (sortTileInfo.maxCoreNum <= lastDimTileNum) { | 453 | if (sortTileInfo.maxCoreNum <= lastDimTileNum) { |
| 431 | sortTileInfo.unsortedDimParallel = 1U; | 454 | sortTileInfo.unsortedDimParallel = 1U; |
| 432 | } else { | 455 | } else { |
| 433 | - sortTileInfo.unsortedDimParallel = | 456 | + sortTileInfo.unsortedDimParallel = lastDimTileNum == 0U ? sortTileInfo.maxCoreNum : |
| 434 | - lastDimTileNum == 0U ? sortTileInfo.maxCoreNum : sortTileInfo.maxCoreNum / lastDimTileNum; | 457 | + sortTileInfo.maxCoreNum / lastDimTileNum; |
| 435 | if (sortTileInfo.unSortDimNum < static_cast<int64_t>(sortTileInfo.unsortedDimParallel)) { | 458 | if (sortTileInfo.unSortDimNum < static_cast<int64_t>(sortTileInfo.unsortedDimParallel)) { |
| 436 | sortTileInfo.unsortedDimParallel = static_cast<uint32_t>(sortTileInfo.unSortDimNum); | 459 | sortTileInfo.unsortedDimParallel = static_cast<uint32_t>(sortTileInfo.unSortDimNum); |
| 437 | } | 460 | } |
| 438 | } | 461 | } |
| 439 | sortTileInfo.numTileDataSize = tileData; | 462 | sortTileInfo.numTileDataSize = tileData; |
| 440 | - sortTileInfo.sortLoopTimes = | 463 | + sortTileInfo.sortLoopTimes = sortWithIndex::CeilDiv1(int64_t(sortTileInfo.unSortDimNum), |
| 441 | - sortWithIndex::CeilDiv1(int64_t(sortTileInfo.unSortDimNum), int64_t(sortTileInfo.unsortedDimParallel)); | 464 | + int64_t(sortTileInfo.unsortedDimParallel)); |
| 442 | sortTileInfo.lastDimNeedCore = std::min(sortTileInfo.maxCoreNum, lastDimTileNum); | 465 | sortTileInfo.lastDimNeedCore = std::min(sortTileInfo.maxCoreNum, lastDimTileNum); |
| 443 | sortTileInfo.coreNumNeed = sortTileInfo.unsortedDimParallel * sortTileInfo.lastDimNeedCore; | 466 | sortTileInfo.coreNumNeed = sortTileInfo.unsortedDimParallel * sortTileInfo.lastDimNeedCore; |
| 444 | sortTileInfo.lastDimTileNum = lastDimTileNum; | 467 | sortTileInfo.lastDimTileNum = lastDimTileNum; |
| @@ -448,26 +471,26 @@ void TileMoreCoreModeOfIdx(sortWithIndex::SortTileInfo &sortTileInfo, size_t* us | |||
| 448 | ubSizeNum = sortTileInfo.tmpUbSize / static_cast<uint32_t>(sizeof(int64_t)); | 471 | ubSizeNum = sortTileInfo.tmpUbSize / static_cast<uint32_t>(sizeof(int64_t)); |
| 449 | } | 472 | } |
| 450 | uint32_t allNumGloblHist = sortWithIndex::BIN_NUM * lastDimTileNum * sortTileInfo.dtypeSize * | 473 | uint32_t allNumGloblHist = sortWithIndex::BIN_NUM * lastDimTileNum * sortTileInfo.dtypeSize * |
| 451 | - sortTileInfo.unsortedDimParallel; | 474 | + sortTileInfo.unsortedDimParallel; |
| 452 | uint32_t allNumExcusiveBin = sortWithIndex::BIN_NUM * sortTileInfo.dtypeSize * sortTileInfo.unsortedDimParallel; | 475 | uint32_t allNumExcusiveBin = sortWithIndex::BIN_NUM * sortTileInfo.dtypeSize * sortTileInfo.unsortedDimParallel; |
| 453 | uint32_t oneCoreSize = sortWithIndex::CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.coreNumNeed)); | 476 | uint32_t oneCoreSize = sortWithIndex::CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.coreNumNeed)); |
| 454 | - sortTileInfo.keyParams5 = | 477 | + sortTileInfo.keyParams5 = std::max(static_cast<int64_t>(oneCoreSize), |
| 455 | - std::max(static_cast<int64_t>(oneCoreSize), static_cast<int64_t>(sortTileInfo.blockUbSize)); | 478 | + static_cast<int64_t>(sortTileInfo.blockUbSize)); |
| 456 | sortTileInfo.keyParams0 = sortWithIndex::CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.keyParams5)); | 479 | sortTileInfo.keyParams0 = sortWithIndex::CeilDiv1(int64_t(allNumGloblHist), int64_t(sortTileInfo.keyParams5)); |
| 457 | sortTileInfo.keyParams3 = sortWithIndex::CeilDiv1(int64_t(sortTileInfo.keyParams5), int64_t(ubSizeNum)); | 480 | sortTileInfo.keyParams3 = sortWithIndex::CeilDiv1(int64_t(sortTileInfo.keyParams5), int64_t(ubSizeNum)); |
| 458 | sortTileInfo.keyParams2 = sortTileInfo.keyParams5 > ubSizeNum ? ubSizeNum : sortTileInfo.keyParams5; | 481 | sortTileInfo.keyParams2 = sortTileInfo.keyParams5 > ubSizeNum ? ubSizeNum : sortTileInfo.keyParams5; |
| 459 | 482 | ||
| 460 | uint32_t oneCoreSize1 = sortWithIndex::CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.coreNumNeed)); | 483 | uint32_t oneCoreSize1 = sortWithIndex::CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.coreNumNeed)); |
| 461 | - sortTileInfo.keyParams4 = | 484 | + sortTileInfo.keyParams4 = std::max(static_cast<int64_t>(oneCoreSize1), |
| 462 | - std::max(static_cast<int64_t>(oneCoreSize1), static_cast<int64_t>(sortTileInfo.blockUbSize)); | 485 | + static_cast<int64_t>(sortTileInfo.blockUbSize)); |
| 463 | 486 | ||
| 464 | sortTileInfo.keyParams1 = sortWithIndex::CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.keyParams4)); | 487 | sortTileInfo.keyParams1 = sortWithIndex::CeilDiv1(int64_t(allNumExcusiveBin), int64_t(sortTileInfo.keyParams4)); |
| 465 | ComputeWorkSpace1(sortTileInfo, usrSize); | 488 | ComputeWorkSpace1(sortTileInfo, usrSize); |
| 466 | return; | 489 | return; |
| 467 | } | 490 | } |
| 468 | 491 | ||
| 469 | -ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, TopKV2TilingDataSimd &topkTilingData, | 492 | +ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, TopKV2TilingDataSimd& topkTilingData, |
| 470 | - int32_t maxCoreNum, size_t* usrSize) | 493 | + int32_t maxCoreNum, size_t* usrSize) |
| 471 | { | 494 | { |
| 472 | OP_LOGI(context->GetNodeName(), "SortWithIndexTIling for topk start"); | 495 | OP_LOGI(context->GetNodeName(), "SortWithIndexTIling for topk start"); |
| 473 | auto dataType = context->GetInputDesc(0)->GetDataType(); | 496 | auto dataType = context->GetInputDesc(0)->GetDataType(); |
| @@ -481,8 +504,9 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, TopKV2TilingD | |||
| 481 | uint64_t ubSize = 0; | 504 | uint64_t ubSize = 0; |
| 482 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); | 505 | ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); |
| 483 | OP_CHECK_IF(ubSize <= static_cast<uint64_t>(sortWithIndex::SIMT_UB), | 506 | OP_CHECK_IF(ubSize <= static_cast<uint64_t>(sortWithIndex::SIMT_UB), |
| 484 | - OP_LOGE(context->GetNodeName(), "block total ub size must greater than simtUb, " | 507 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context->GetNodeName(), "ubSize", std::to_string(ubSize).c_str(), |
| 485 | - "but is %lu", ubSize), return ge::GRAPH_FAILED); | 508 | + "The value of ubSize must be greater than SIMT_UB."), |
| 509 | + return ge::GRAPH_FAILED); | ||
| 486 | OP_LOGW(context->GetNodeName(), "Get op_type[%s]", opType.c_str()); | 510 | OP_LOGW(context->GetNodeName(), "Get op_type[%s]", opType.c_str()); |
| 487 | 511 | ||
| 488 | auto const attrs = context->GetAttrs(); | 512 | auto const attrs = context->GetAttrs(); |
| @@ -524,7 +548,8 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, TopKV2TilingD | |||
| 524 | 548 | ||
| 525 | // 设置高级api tmpUbSize需要的空间 | 549 | // 设置高级api tmpUbSize需要的空间 |
| 526 | SetSortTmpSizeOfIdx(dataType, sortAxisNum, tileData, *isDescending, true, topkTilingData, sortTileInfo); | 550 | SetSortTmpSizeOfIdx(dataType, sortAxisNum, tileData, *isDescending, true, topkTilingData, sortTileInfo); |
| 527 | - if (sortAxisNum <= sortWithIndex::SMALL_SORT_MAX_DATA_SIZE && sortWithIndex::optDataTypeBitMap.count(dataType) != 0) { | 551 | + if (sortAxisNum <= sortWithIndex::SMALL_SORT_MAX_DATA_SIZE && |
| 552 | + sortWithIndex::optDataTypeBitMap.count(dataType) != 0) { | ||
| 528 | topkTilingData.set_modeTypeForSort(sortWithIndex::SMALL_SIZE_OPTIM_MODE); | 553 | topkTilingData.set_modeTypeForSort(sortWithIndex::SMALL_SIZE_OPTIM_MODE); |
| 529 | uint32_t tileDataS = sortWithIndex::TILE_DATA_NUM; | 554 | uint32_t tileDataS = sortWithIndex::TILE_DATA_NUM; |
| 530 | TileModeSmallSizeOptimOfIdx(unSortDimNum, maxCoreNum, sortAxisNum, tileDataS, sortTileInfo); | 555 | TileModeSmallSizeOptimOfIdx(unSortDimNum, maxCoreNum, sortAxisNum, tileDataS, sortTileInfo); |
| @@ -538,10 +563,11 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, TopKV2TilingD | |||
| 538 | topkTilingData.set_modeTypeForSort(sortWithIndex::MULT_CORE_MODE); | 563 | topkTilingData.set_modeTypeForSort(sortWithIndex::MULT_CORE_MODE); |
| 539 | TileMoreCoreModeOfIdx(sortTileInfo, usrSize); | 564 | TileMoreCoreModeOfIdx(sortTileInfo, usrSize); |
| 540 | } | 565 | } |
| 541 | - OP_LOGI(context->GetNodeName(), "ubSize: %ld, ubAglinSize: %ld, dtypeSize: %u, y2DtypeSize=%u," | 566 | + OP_LOGI(context->GetNodeName(), |
| 542 | - " sortTileInfo.ubSize=%u, maxCoreNum=%lu, usrSize=%d, modeType=%u.", | 567 | + "ubSize: %ld, ubAglinSize: %ld, dtypeSize: %u, y2DtypeSize=%u," |
| 543 | - ubSize, blockUbAglinSize, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, sortTileInfo.ubSize, maxCoreNum, | 568 | + " sortTileInfo.ubSize=%u, maxCoreNum=%lu, usrSize=%d, modeType=%u.", |
| 544 | - *usrSize, topkTilingData.get_modeTypeForSort()); | 569 | + ubSize, blockUbAglinSize, sortTileInfo.dtypeSize, sortTileInfo.y2DtypeSize, sortTileInfo.ubSize, maxCoreNum, |
| 570 | + *usrSize, topkTilingData.get_modeTypeForSort()); | ||
| 545 | 571 | ||
| 546 | topkTilingData.set_tilingKeyForSort(tilingKey); | 572 | topkTilingData.set_tilingKeyForSort(tilingKey); |
| 547 | topkTilingData.set_lastAxisNumForSort(sortAxisNum); | 573 | topkTilingData.set_lastAxisNumForSort(sortAxisNum); |
| @@ -553,14 +579,14 @@ ge::graphStatus RadixSortTilingOfIdx(gert::TilingContext* context, TopKV2TilingD | |||
| 553 | 579 | ||
| 554 | // add sortwithindex workspace | 580 | // add sortwithindex workspace |
| 555 | int64_t topkValuesGmSize = CeilDivMul1<int64_t>(int64_t(sortAxisNum * unSortDimNum * sortTileInfo.dtypeSize), | 581 | int64_t topkValuesGmSize = CeilDivMul1<int64_t>(int64_t(sortAxisNum * unSortDimNum * sortTileInfo.dtypeSize), |
| 556 | - int64_t(AGLIN_VALUE)); | 582 | + int64_t(AGLIN_VALUE)); |
| 557 | int64_t topkIndicesGmSize = CeilDivMul1<int64_t>(int64_t(sortAxisNum * unSortDimNum * sortTileInfo.y2DtypeSize), | 583 | int64_t topkIndicesGmSize = CeilDivMul1<int64_t>(int64_t(sortAxisNum * unSortDimNum * sortTileInfo.y2DtypeSize), |
| 558 | - int64_t(AGLIN_VALUE)); | 584 | + int64_t(AGLIN_VALUE)); |
| 559 | *usrSize = *usrSize + topkValuesGmSize + topkIndicesGmSize; | 585 | *usrSize = *usrSize + topkValuesGmSize + topkIndicesGmSize; |
| 560 | OP_LOGI(context->GetNodeName(), | 586 | OP_LOGI(context->GetNodeName(), |
| 561 | - "RadixSortTilingOfIdx final usrSize=%ld, topkValuesGmSize: %ld, topkIndicesGmSize: %ld.", | 587 | + "RadixSortTilingOfIdx final usrSize=%ld, topkValuesGmSize: %ld, topkIndicesGmSize: %ld.", *usrSize, |
| 562 | - *usrSize, topkValuesGmSize, topkIndicesGmSize); | 588 | + topkValuesGmSize, topkIndicesGmSize); |
| 563 | return ge::GRAPH_SUCCESS; | 589 | return ge::GRAPH_SUCCESS; |
| 564 | } | 590 | } |
| 565 | -} // namespace sortWithIndex | 591 | +} // namespace sortWithIndex |
| 566 | } // namespace optiling | 592 | } // namespace optiling |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | -* Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 3 | * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -15,74 +15,81 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | + | ||
| 19 | + | ||
| 18 | static constexpr int OUTPUT_VALUES_INDEX = 0; | 20 | static constexpr int OUTPUT_VALUES_INDEX = 0; |
| 19 | static constexpr int OUTPUT_INDICES_INDEX = 1; | 21 | static constexpr int OUTPUT_INDICES_INDEX = 1; |
| 20 | static constexpr int INPUT_X_INDEX = 0; | 22 | static constexpr int INPUT_X_INDEX = 0; |
| 21 | using namespace ge; | 23 | using namespace ge; |
| 22 | namespace ops { | 24 | namespace ops { |
| 23 | -static bool InferShapeForTopKCommon(gert::InferShapeContext* context, int64_t k, const int64_t* dim) { | 25 | +static bool InferShapeForTopKCommon(gert::InferShapeContext* context, int64_t k, const int64_t* dim) |
| 24 | - const gert::Shape *input_x_shape = context->GetInputShape(INPUT_X_INDEX); | 26 | +{ |
| 25 | - OP_CHECK_NULL_WITH_CONTEXT(context, input_x_shape); | 27 | + const gert::Shape* input_x_shape = context->GetInputShape(INPUT_X_INDEX); |
| 26 | - size_t dim_size = input_x_shape->GetDimNum(); | 28 | + OP_CHECK_NULL_WITH_CONTEXT(context, input_x_shape); |
| 27 | - if (dim_size <= 0) { | 29 | + size_t dim_size = input_x_shape->GetDimNum(); |
| 28 | - OP_LOGE(context->GetNodeName(), "The dims_in size should more than 0!"); | 30 | + if (dim_size <= 0) { |
| 29 | - return GRAPH_FAILED; | 31 | + OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(context->GetNodeName(), "x", (std::to_string(dim_size) + "D").c_str(), |
| 30 | - } | 32 | + "The shape dim of x must be greater than 0."); |
| 31 | - int64_t sorted_axis = dim_size - 1; | 33 | + return GRAPH_FAILED; |
| 32 | - | ||
| 33 | - if (dim != nullptr) { | ||
| 34 | - sorted_axis = *dim; | ||
| 35 | - if (sorted_axis < 0) { | ||
| 36 | - sorted_axis += dim_size; | ||
| 37 | } | 34 | } |
| 38 | - if (sorted_axis >= static_cast<int64_t>(dim_size)) { | 35 | + int64_t sorted_axis = dim_size - 1; |
| 39 | - OP_LOGE(context->GetNodeName(), "Dim is out of shape size."); | ||
| 40 | - return GRAPH_FAILED; | ||
| 41 | - } | ||
| 42 | - } | ||
| 43 | 36 | ||
| 44 | - gert::Shape *output_values_shape = context->GetOutputShape(OUTPUT_VALUES_INDEX); | 37 | + if (dim != nullptr) { |
| 45 | - OP_CHECK_NULL_WITH_CONTEXT(context, output_values_shape); | 38 | + sorted_axis = *dim; |
| 46 | - gert::Shape *output_indices_shape = context->GetOutputShape(OUTPUT_INDICES_INDEX); | 39 | + if (sorted_axis < 0) { |
| 47 | - OP_CHECK_NULL_WITH_CONTEXT(context, output_indices_shape); | 40 | + sorted_axis += dim_size; |
| 48 | - | 41 | + } |
| 49 | - output_values_shape->SetDimNum(dim_size); | 42 | + if (sorted_axis >= static_cast<int64_t>(dim_size)) { |
| 50 | - output_indices_shape->SetDimNum(dim_size); | 43 | + OP_LOGE_WITH_INVALID_ATTR( |
| 51 | - for (size_t i = 0; i < dim_size; i++) { | 44 | + context->GetNodeName(), "dim", std::to_string(*dim).c_str(), |
| 52 | - if (static_cast<int64_t>(i) == sorted_axis) { | 45 | + ("[-" + std::to_string(dim_size) + ", " + std::to_string(static_cast<int64_t>(dim_size) - 1) + "]") |
| 53 | - output_values_shape->SetDim(i, k); | 46 | + .c_str()); |
| 54 | - output_indices_shape->SetDim(i, k); | 47 | + return GRAPH_FAILED; |
| 55 | - continue; | 48 | + } |
| 56 | } | 49 | } |
| 57 | - output_values_shape->SetDim(i, input_x_shape->GetDim(i)); | 50 | + |
| 58 | - output_indices_shape->SetDim(i, input_x_shape->GetDim(i)); | 51 | + gert::Shape* output_values_shape = context->GetOutputShape(OUTPUT_VALUES_INDEX); |
| 59 | - } | 52 | + OP_CHECK_NULL_WITH_CONTEXT(context, output_values_shape); |
| 60 | - return GRAPH_SUCCESS; | 53 | + gert::Shape* output_indices_shape = context->GetOutputShape(OUTPUT_INDICES_INDEX); |
| 54 | + OP_CHECK_NULL_WITH_CONTEXT(context, output_indices_shape); | ||
| 55 | + | ||
| 56 | + output_values_shape->SetDimNum(dim_size); | ||
| 57 | + output_indices_shape->SetDimNum(dim_size); | ||
| 58 | + for (size_t i = 0; i < dim_size; i++) { | ||
| 59 | + if (static_cast<int64_t>(i) == sorted_axis) { | ||
| 60 | + output_values_shape->SetDim(i, k); | ||
| 61 | + output_indices_shape->SetDim(i, k); | ||
| 62 | + continue; | ||
| 63 | + } | ||
| 64 | + output_values_shape->SetDim(i, input_x_shape->GetDim(i)); | ||
| 65 | + output_indices_shape->SetDim(i, input_x_shape->GetDim(i)); | ||
| 66 | + } | ||
| 67 | + return GRAPH_SUCCESS; | ||
| 61 | } | 68 | } |
| 62 | 69 | ||
| 63 | -static graphStatus InferShapeForTopKV2D(gert::InferShapeContext* context) { | 70 | +static graphStatus InferShapeForTopKV2D(gert::InferShapeContext* context) |
| 64 | - OP_LOGD(context->GetNodeName(), "Begin to do TopKV2DInferShape"); | 71 | +{ |
| 65 | - const gert::RuntimeAttrs *attrs = context->GetAttrs(); | 72 | + OP_LOGD(context->GetNodeName(), "Begin to do TopKV2DInferShape"); |
| 66 | - OP_CHECK_NULL_WITH_CONTEXT(context, attrs); | 73 | + const gert::RuntimeAttrs* attrs = context->GetAttrs(); |
| 67 | - const int64_t *dim = attrs->GetInt(1); | 74 | + OP_CHECK_NULL_WITH_CONTEXT(context, attrs); |
| 68 | - const gert::Tensor *input_k_tensor = context->GetInputTensor(1); | 75 | + const int64_t* dim = attrs->GetInt(1); |
| 69 | - OP_CHECK_NULL_WITH_CONTEXT(context, input_k_tensor); | 76 | + const gert::Tensor* input_k_tensor = context->GetInputTensor(1); |
| 70 | - DataType input_k_dtype = input_k_tensor->GetDataType(); | 77 | + OP_CHECK_NULL_WITH_CONTEXT(context, input_k_tensor); |
| 71 | - if (input_k_dtype == DT_INT32) { | 78 | + DataType input_k_dtype = input_k_tensor->GetDataType(); |
| 72 | - const int32_t *k = input_k_tensor->GetData<int32_t>(); | 79 | + if (input_k_dtype == DT_INT32) { |
| 73 | - OP_CHECK_NULL_WITH_CONTEXT(context, k); | 80 | + const int32_t* k = input_k_tensor->GetData<int32_t>(); |
| 74 | - return InferShapeForTopKCommon(context, *k, dim); | 81 | + OP_CHECK_NULL_WITH_CONTEXT(context, k); |
| 75 | - } else if (input_k_dtype == DT_INT64) { | 82 | + return InferShapeForTopKCommon(context, *k, dim); |
| 76 | - const int64_t *k = input_k_tensor->GetData<int64_t>(); | 83 | + } else if (input_k_dtype == DT_INT64) { |
| 77 | - OP_CHECK_NULL_WITH_CONTEXT(context, k); | 84 | + const int64_t* k = input_k_tensor->GetData<int64_t>(); |
| 78 | - return InferShapeForTopKCommon(context, *k, dim); | 85 | + OP_CHECK_NULL_WITH_CONTEXT(context, k); |
| 79 | - } else { | 86 | + return InferShapeForTopKCommon(context, *k, dim); |
| 80 | - OP_LOGE(context->GetNodeName(), "The type of k Error!"); | 87 | + } else { |
| 81 | - return GRAPH_FAILED; | 88 | + OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), "k", Ops::Base::ToString(input_k_dtype).c_str(), |
| 82 | - } | 89 | + "INT32 or INT64"); |
| 90 | + return GRAPH_FAILED; | ||
| 91 | + } | ||
| 83 | } | 92 | } |
| 84 | 93 | ||
| 85 | -IMPL_OP_INFERSHAPE(TopKV2) | 94 | +IMPL_OP_INFERSHAPE(TopKV2).InferShape(InferShapeForTopKV2D).InputsDataDependency({1}); |
| 86 | - .InferShape(InferShapeForTopKV2D) | 95 | +} // namespace ops |
| 87 | - .InputsDataDependency({1}); | ||
| 88 | -} // namespace ops | ||