Merged
fix(machine): Execount optimize #5954
yanggenAdd on Sep 4
fix(machine): Execount optimize #5954
Merged
Merged fromyanggen/pypto_4679masterintocann/pyptomaster
Total: 4 files changed+58-13
| @@ -70,6 +70,7 @@ INLINE void DrcoBusyBackOff() | |||
| 70 | 70 | ||
| 71 | constexpr uint16_t SYNC_MODE_SHIFT_VALUE = 4; | 71 | constexpr uint16_t SYNC_MODE_SHIFT_VALUE = 4; |
| 72 | constexpr uint16_t SYNC_FLAG_SHIFT_VALUE = 8; | 72 | constexpr uint16_t SYNC_FLAG_SHIFT_VALUE = 8; |
| 73 | +constexpr uint32_t BATCH_PUSH_BUF_SIZE = 6; | ||
| 73 | 74 | ||
| 74 | __aicore__ inline uint16_t GetffstMsg(uint16_t mode, uint16_t flagId) | 75 | __aicore__ inline uint16_t GetffstMsg(uint16_t mode, uint16_t flagId) |
| 75 | { | 76 | { |
| @@ -206,11 +207,28 @@ INLINE bool DrcoLocalReadyQueuePushTask(__gm__ DrcoLocalReadyQueue* queue, uint3 | |||
| 206 | return result == 0; | 207 | return result == 0; |
| 207 | } | 208 | } |
| 208 | 209 | ||
| 210 | +INLINE int DrcoLocalReadyQueueTryBatchPushTask(__gm__ DrcoLocalReadyQueue* queue, uint32_t* readyTaskList, uint32_t n) | ||
| 211 | +{ | ||
| 212 | + __gm__ uint32_t* tailPtr = &queue->tail; | ||
| 213 | + uint32_t tail = DrcoAtomicLoad(tailPtr); | ||
| 214 | + if (tail >= DrcoGmLoad(&queue->size)) { | ||
| 215 | + return -1; | ||
| 216 | + } | ||
| 217 | + uint32_t tailPrev = DrcoAtomicCasTo(&queue->tail, tail, tail + n); | ||
| 218 | + if (tailPrev == tail) { | ||
| 219 | + for (uint32_t i = 0; i < n; i++) { | ||
| 220 | + DrcoAtomicExchTo(&queue->taskList[tail + i], DRCO_ENCODE_TASK(readyTaskList[i])); | ||
| 221 | + } | ||
| 222 | + return 0; | ||
| 223 | + } | ||
| 224 | + return 1; | ||
| 225 | +} | ||
| 226 | + | ||
| 209 | INLINE void DrcoLocalReadyQueuePushBatch(__gm__ DrcoLocalReadyQueue* queue, uint32_t* readyTaskList, uint32_t n) | 227 | INLINE void DrcoLocalReadyQueuePushBatch(__gm__ DrcoLocalReadyQueue* queue, uint32_t* readyTaskList, uint32_t n) |
| 210 | { | 228 | { |
| 211 | - uint32_t tail = DrcoAtomicAddTo(&queue->tail, n); | 229 | + int result = DrcoLocalReadyQueueTryBatchPushTask(queue, readyTaskList, n); |
| 212 | - for (uint32_t i = 0; i < n; i++) { | 230 | + while (result == 1) { |
| 213 | - DrcoAtomicExchTo(&queue->taskList[tail + i], DRCO_ENCODE_TASK(readyTaskList[i])); | 231 | + result = DrcoLocalReadyQueueTryBatchPushTask(queue, readyTaskList, n); |
| 214 | } | 232 | } |
| 215 | } | 233 | } |
| 216 | 234 | ||
| @@ -390,8 +408,9 @@ struct DrcoDynFuncDataListPush { | |||
| 390 | }; | 408 | }; |
| 391 | 409 | ||
| 392 | template <typename GlobalReadyQueueHandler> | 410 | template <typename GlobalReadyQueueHandler> |
| 393 | -INLINE void DrcoFlushBatchTasks(__gm__ npu::tile_fwk::DrcoRootFuncList* rootFuncList, uint32_t batchTaskIds[][64], | 411 | +INLINE void DrcoFlushBatchTasks(__gm__ npu::tile_fwk::DrcoRootFuncList* rootFuncList, |
| 394 | - uint32_t batchCount[], uint32_t aicCoreNum) | 412 | + uint32_t batchTaskIds[][BATCH_PUSH_BUF_SIZE], uint32_t batchCount[], |
| 413 | + uint32_t aicCoreNum) | ||
| 395 | { | 414 | { |
| 396 | for (uint32_t ct = 0; ct < npu::tile_fwk::NUM_CORE_TYPES; ct++) { | 415 | for (uint32_t ct = 0; ct < npu::tile_fwk::NUM_CORE_TYPES; ct++) { |
| 397 | if (batchCount[ct] > 0) { | 416 | if (batchCount[ct] > 0) { |
| @@ -405,7 +424,6 @@ template <typename GlobalReadyQueueHandler> | |||
| 405 | INLINE void ExecDrcoResolve(ExecuteContext* ctx, __gm__ npu::tile_fwk::DrcoRootFuncList* rootFuncList, uint32_t taskId) | 424 | INLINE void ExecDrcoResolve(ExecuteContext* ctx, __gm__ npu::tile_fwk::DrcoRootFuncList* rootFuncList, uint32_t taskId) |
| 406 | { | 425 | { |
| 407 | constexpr uint32_t HUB_STACK_SIZE = 64; | 426 | constexpr uint32_t HUB_STACK_SIZE = 64; |
| 408 | - constexpr uint32_t BATCH_PUSH_BUF_SIZE = 64; | ||
| 409 | uint32_t hubStack[HUB_STACK_SIZE]; | 427 | uint32_t hubStack[HUB_STACK_SIZE]; |
| 410 | int32_t hubStackTop = -1; | 428 | int32_t hubStackTop = -1; |
| 411 | hubStack[++hubStackTop] = taskId; | 429 | hubStack[++hubStackTop] = taskId; |
| @@ -690,9 +708,9 @@ INLINE uint32_t DrcoDynFuncDataListGetFirstTask(__gm__ npu::tile_fwk::DrcoRootFu | |||
| 690 | } | 708 | } |
| 691 | } | 709 | } |
| 692 | 710 | ||
| 693 | - uint32_t execCnt = DrcoAtomicLoad(&rootFuncList->executedTaskCount); | 711 | + __gm__ DrcoGlobalReadyQueue* |
| 694 | - uint32_t totCnt = DrcoAtomicLoad(&rootFuncList->totalTaskCount); | 712 | + myGq = rootFuncList->globalReadyQueueList[static_cast<uint32_t>(npu::tile_fwk::drcoCoreType)].ptr; |
| 695 | - if (execCnt >= totCnt) { | 713 | + if (DrcoAtomicLoad(&myGq->executedCount) >= myGq->size) { |
| 696 | return static_cast<uint32_t>(AICORE_TASK_ALL_FINISH); | 714 | return static_cast<uint32_t>(AICORE_TASK_ALL_FINISH); |
| 697 | } | 715 | } |
| 698 | } | 716 | } |
| @@ -834,7 +852,9 @@ INLINE void ExecDrcoPerCoreTasks(ExecuteContext* ctx, __gm__ npu::tile_fwk::PerC | |||
| 834 | #ifdef __HAS_SUB_FUNC__ | 852 | #ifdef __HAS_SUB_FUNC__ |
| 835 | ExecDrcoResolve<GlobalReadyQueueHandler>(ctx, rootFuncList, taskId); | 853 | ExecDrcoResolve<GlobalReadyQueueHandler>(ctx, rootFuncList, taskId); |
| 836 | #endif | 854 | #endif |
| 837 | - DrcoAtomicAddTo(&rootFuncList->executedTaskCount, 1); | 855 | + __gm__ DrcoGlobalReadyQueue* execQueue = GetDrcoGlobalReadyQueue( |
| 856 | + rootFuncList, static_cast<uint32_t>(npu::tile_fwk::drcoCoreType)); | ||
| 857 | + DrcoAtomicAddTo(&execQueue->executedCount, 1); | ||
| 838 | } | 858 | } |
| 839 | } | 859 | } |
| 840 | 860 | ||
| @@ -881,7 +901,9 @@ INLINE void ExecDrcoReadyQueueTasks(ExecuteContext* ctx, __gm__ npu::tile_fwk::D | |||
| 881 | #ifdef __HAS_SUB_FUNC__ | 901 | #ifdef __HAS_SUB_FUNC__ |
| 882 | ExecDrcoResolve<GlobalReadyQueueHandler>(ctx, rootFuncList, taskId); | 902 | ExecDrcoResolve<GlobalReadyQueueHandler>(ctx, rootFuncList, taskId); |
| 883 | #endif | 903 | #endif |
| 884 | - DrcoAtomicAddTo(&rootFuncList->executedTaskCount, 1); | 904 | + __gm__ DrcoGlobalReadyQueue* execQueue = GetDrcoGlobalReadyQueue( |
| 905 | + rootFuncList, static_cast<uint32_t>(npu::tile_fwk::drcoCoreType)); | ||
| 906 | + DrcoAtomicAddTo(&execQueue->executedCount, 1); | ||
| 885 | } | 907 | } |
| 886 | } | 908 | } |
| 887 | taskId = DrcoDynFuncDataListGetFirstTask(rootFuncList, blockIdx, outCoreType); | 909 | taskId = DrcoDynFuncDataListGetFirstTask(rootFuncList, blockIdx, outCoreType); |
| @@ -125,7 +125,9 @@ struct PerCorePendingQueue { | |||
| 125 | 125 | ||
| 126 | struct DrcoLocalReadyQueue { | 126 | struct DrcoLocalReadyQueue { |
| 127 | uint32_t head; | 127 | uint32_t head; |
| 128 | + uint8_t pad[64 - sizeof(uint32_t)]; | ||
| 128 | uint32_t tail; | 129 | uint32_t tail; |
| 130 | + uint8_t pad2[64 - sizeof(uint32_t)]; | ||
| 129 | uint32_t size; | 131 | uint32_t size; |
| 130 | LeafTaskId taskList[0]; | 132 | LeafTaskId taskList[0]; |
| 131 | #ifdef __TILE_FWK_HOST__ | 133 | #ifdef __TILE_FWK_HOST__ |
| @@ -140,9 +142,10 @@ struct DrcoGlobalReadyQueue { | |||
| 140 | uint32_t head; | 142 | uint32_t head; |
| 141 | uint32_t tail; | 143 | uint32_t tail; |
| 142 | uint32_t size; | 144 | uint32_t size; |
| 145 | + uint32_t executedCount; | ||
| 143 | LeafTaskId taskList[0]; | 146 | LeafTaskId taskList[0]; |
| 144 | -#ifdef __TILE_FWK_HOST__ | 147 | +#if defined(__TILE_FWK_HOST__) |
| 145 | - DrcoGlobalReadyQueue() : head(0), tail(0), size(0) {} | 148 | + DrcoGlobalReadyQueue() : head(0), tail(0), size(0), executedCount(0) {} |
| 146 | 149 | ||
| 147 | void UnsafeEnqueue(LeafTaskId task) { taskList[tail++] = DRCO_ENCODE_TASK(task); } | 150 | void UnsafeEnqueue(LeafTaskId task) { taskList[tail++] = DRCO_ENCODE_TASK(task); } |
| 148 | #endif | 151 | #endif |
| @@ -28,11 +28,30 @@ void DeviceTaskContext::InitDrcoRootFuncList(DynDeviceTask* dyntask) | |||
| 28 | uint32_t queueCapacity = dyntask->devTask.coreFunctionCnt; | 28 | uint32_t queueCapacity = dyntask->devTask.coreFunctionCnt; |
| 29 | uint32_t globalReadyQueueSize = sizeof(npu::tile_fwk::DrcoGlobalReadyQueue) + | 29 | uint32_t globalReadyQueueSize = sizeof(npu::tile_fwk::DrcoGlobalReadyQueue) + |
| 30 | queueCapacity * sizeof(npu::tile_fwk::LeafTaskId); | 30 | queueCapacity * sizeof(npu::tile_fwk::LeafTaskId); |
| 31 | + uint32_t aicTaskCnt = 0; | ||
| 32 | + uint32_t aivTaskCnt = 0; | ||
| 33 | + for (uint64_t funcId = 0; funcId < dyntask->dynFuncDataCacheListSize; ++funcId) { | ||
| 34 | + auto callList = dyntask->dynFuncDataCacheList[funcId].calleeList; | ||
| 35 | + for (size_t opIndex = 0; opIndex < dyntask->dynFuncDataCacheList[funcId].devFunc->GetOperationSize(); | ||
| 36 | + ++opIndex) { | ||
| 37 | + auto coreType = dyntask->cceBinary[callList[opIndex]].coreType; | ||
| 38 | + if (coreType == static_cast<int>(CoreType::AIC)) { | ||
| 39 | + aicTaskCnt++; | ||
| 40 | + } else if (coreType == static_cast<int>(CoreType::AIV)) { | ||
| 41 | + aivTaskCnt++; | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + } | ||
| 31 | for (size_t i = 0; i < npu::tile_fwk::DRCO_QUEUE_MAX; i++) { | 45 | for (size_t i = 0; i < npu::tile_fwk::DRCO_QUEUE_MAX; i++) { |
| 32 | auto* q = workspace_->AllocateDrcoGlobalReadyQueue(globalReadyQueueSize); | 46 | auto* q = workspace_->AllocateDrcoGlobalReadyQueue(globalReadyQueueSize); |
| 33 | new (q) npu::tile_fwk::DrcoGlobalReadyQueue(); | 47 | new (q) npu::tile_fwk::DrcoGlobalReadyQueue(); |
| 34 | (void)memset_s(reinterpret_cast<uint8_t*>(q) + sizeof(DrcoGlobalReadyQueue), queueCapacity * sizeof(LeafTaskId), | 48 | (void)memset_s(reinterpret_cast<uint8_t*>(q) + sizeof(DrcoGlobalReadyQueue), queueCapacity * sizeof(LeafTaskId), |
| 35 | 0, queueCapacity * sizeof(LeafTaskId)); | 49 | 0, queueCapacity * sizeof(LeafTaskId)); |
| 50 | + if (i == npu::tile_fwk::DRCO_QUEUE_AIC) { | ||
| 51 | + q->size = aicTaskCnt; | ||
| 52 | + } else if (i == npu::tile_fwk::DRCO_QUEUE_AIV) { | ||
| 53 | + q->size = aivTaskCnt; | ||
| 54 | + } | ||
| 36 | rootFuncList->globalReadyQueueList[i].ptr = q; | 55 | rootFuncList->globalReadyQueueList[i].ptr = q; |
| 37 | } | 56 | } |
| 38 | uint32_t perCoreSize = sizeof(npu::tile_fwk::PerCorePendingQueue) + | 57 | uint32_t perCoreSize = sizeof(npu::tile_fwk::PerCorePendingQueue) + |
| @@ -212,6 +212,7 @@ void DevControlFlowCache::DrcoReadyQueueDataRestore(DynDeviceTaskBase* base, uin | |||
| 212 | } | 212 | } |
| 213 | gq->head = 0; | 213 | gq->head = 0; |
| 214 | gq->tail = 0; | 214 | gq->tail = 0; |
| 215 | + gq->executedCount = 0; | ||
| 215 | (void)memset_s(reinterpret_cast<uint8_t*>(gq) + sizeof(DrcoGlobalReadyQueue), queueTaskListSize, 0, | 216 | (void)memset_s(reinterpret_cast<uint8_t*>(gq) + sizeof(DrcoGlobalReadyQueue), queueTaskListSize, 0, |
| 216 | queueTaskListSize); | 217 | queueTaskListSize); |
| 217 | } | 218 | } |