已合并
修复STFT算子int32/uint32溢出风险 #3133
east_yang创建于 6月4日
修复STFT算子int32/uint32溢出风险 #3133
已合并
共 6 个文件变更+88-85
| @@ -284,13 +284,13 @@ ge::graphStatus STFTTiling::GetWorkspaceSize() | |||
| 284 | // 每块workspace地址需要512B对齐 | 284 | // 每块workspace地址需要512B对齐 |
| 285 | // 第0块workspace用于存储按照窗口拆分之后的input data | 285 | // 第0块workspace用于存储按照窗口拆分之后的input data |
| 286 | size_t windowSplitWorkspaceSize = | 286 | size_t windowSplitWorkspaceSize = |
| 287 | - batchLoop * | 287 | + (uint64_t)batchLoop * |
| 288 | - ((aicCoreNum * frameCount * nfft * sizeof(float) + WORKSPACE_ALIGN_SIZE - 1) / WORKSPACE_ALIGN_SIZE) * | 288 | + (((uint64_t)aicCoreNum * frameCount * nfft * sizeof(float) + WORKSPACE_ALIGN_SIZE - 1) / WORKSPACE_ALIGN_SIZE) * |
| 289 | WORKSPACE_ALIGN_SIZE; | 289 | WORKSPACE_ALIGN_SIZE; |
| 290 | 290 | ||
| 291 | // 第一块workspace用于存储input data和plan mm运算之后的结果 | 291 | // 第一块workspace用于存储input data和plan mm运算之后的结果 |
| 292 | size_t matmulWorkspaceSize = | 292 | size_t matmulWorkspaceSize = |
| 293 | - ((batch * frameCount * matmulM * 2 * sizeof(float) + WORKSPACE_ALIGN_SIZE - 1) / WORKSPACE_ALIGN_SIZE) * | 293 | + (((uint64_t)batch * frameCount * matmulM * 2 * sizeof(float) + WORKSPACE_ALIGN_SIZE - 1) / WORKSPACE_ALIGN_SIZE) * |
| 294 | WORKSPACE_ALIGN_SIZE; | 294 | WORKSPACE_ALIGN_SIZE; |
| 295 | workspaceSize_ = windowSplitWorkspaceSize + matmulWorkspaceSize + EXTRA_WORKSPACE_SIZE; | 295 | workspaceSize_ = windowSplitWorkspaceSize + matmulWorkspaceSize + EXTRA_WORKSPACE_SIZE; |
| 296 | return ge::GRAPH_SUCCESS; | 296 | return ge::GRAPH_SUCCESS; |
| @@ -134,22 +134,22 @@ private: | |||
| 134 | 134 | ||
| 135 | void STFTGeneralizedTiling::GetPlanSplitStrategy() | 135 | void STFTGeneralizedTiling::GetPlanSplitStrategy() |
| 136 | { | 136 | { |
| 137 | - int32_t numBlocks = aivCoreNum; | 137 | + uint32_t numBlocks = aivCoreNum; |
| 138 | - int32_t oneRowSize = nfftAlign * 4; | 138 | + uint32_t oneRowSize = nfftAlign * 4; |
| 139 | - int32_t halfUbSize = (ubSize - oneRowSize) / 2; | 139 | + uint32_t halfUbSize = (ubSize - oneRowSize) / 2; |
| 140 | - int32_t mFactor = CeilDiv(2 * matmulM, numBlocks); | 140 | + uint32_t mFactor = CeilDiv(2 * matmulM, numBlocks); |
| 141 | - int32_t prevCnt = numBlocks * (mFactor - 1); | 141 | + uint32_t prevCnt = numBlocks * (mFactor - 1); |
| 142 | - int32_t remainCnt = 2 * matmulM - prevCnt; | 142 | + uint32_t remainCnt = 2 * matmulM - prevCnt; |
| 143 | - int32_t totalLine = mFactor; | 143 | + uint32_t totalLine = mFactor; |
| 144 | - int32_t tailBlockIdx = remainCnt; | 144 | + uint32_t tailBlockIdx = remainCnt; |
| 145 | - int32_t tailLine = mFactor; | 145 | + uint32_t tailLine = mFactor; |
| 146 | if (remainCnt < numBlocks) { | 146 | if (remainCnt < numBlocks) { |
| 147 | tailLine = mFactor - 1; | 147 | tailLine = mFactor - 1; |
| 148 | } | 148 | } |
| 149 | - int32_t ubMaxLine = halfUbSize / oneRowSize; | 149 | + uint32_t ubMaxLine = halfUbSize / oneRowSize; |
| 150 | - int32_t numsInOneRepeat = 64; | 150 | + uint32_t numsInOneRepeat = 64; |
| 151 | - int32_t totalInCol = nfftAlign / numsInOneRepeat; | 151 | + uint32_t totalInCol = nfftAlign / numsInOneRepeat; |
| 152 | - int32_t tailInCol = nfftAlign % numsInOneRepeat; | 152 | + uint32_t tailInCol = nfftAlign % numsInOneRepeat; |
| 153 | 153 | ||
| 154 | tilingData.planTilingData.set_totalInCol(totalInCol); | 154 | tilingData.planTilingData.set_totalInCol(totalInCol); |
| 155 | tilingData.planTilingData.set_tailInCol(tailInCol); | 155 | tilingData.planTilingData.set_tailInCol(tailInCol); |
| @@ -60,21 +60,21 @@ public: | |||
| 60 | { | 60 | { |
| 61 | inTilingData = tilingData; | 61 | inTilingData = tilingData; |
| 62 | size_t windowSplitWorkspaceSize = | 62 | size_t windowSplitWorkspaceSize = |
| 63 | - (((inTilingData->blockNum * inTilingData->frameCount * inTilingData->nfft * sizeof(T) + 511) / 512) * 512) * | 63 | + ((((uint64_t)inTilingData->blockNum * inTilingData->frameCount * inTilingData->nfft * sizeof(T) + 511) / 512) * 512) * |
| 64 | inTilingData->aivBatchLoop / sizeof(T); | 64 | inTilingData->aivBatchLoop / sizeof(T); |
| 65 | if (g_coreType == AIV) { | 65 | if (g_coreType == AIV) { |
| 66 | - inputGm.SetGlobalBuffer((__gm__ T*)x, inTilingData->batch * inTilingData->inputSize); | 66 | + inputGm.SetGlobalBuffer((__gm__ T*)x, (uint64_t)inTilingData->batch * inTilingData->inputSize); |
| 67 | windowSplitWorkspaceGm.SetGlobalBuffer( | 67 | windowSplitWorkspaceGm.SetGlobalBuffer( |
| 68 | (__gm__ T*)workspace, | 68 | (__gm__ T*)workspace, |
| 69 | - inTilingData->blockNum * inTilingData->aivBatchLoop * inTilingData->frameCount * inTilingData->nfft); | 69 | + (uint64_t)inTilingData->blockNum * inTilingData->aivBatchLoop * inTilingData->frameCount * inTilingData->nfft); |
| 70 | outputGm.SetGlobalBuffer( | 70 | outputGm.SetGlobalBuffer( |
| 71 | - (__gm__ T*)y, inTilingData->matmulM * inTilingData->frameCount * inTilingData->batch * DOUBLE_BUFFER); | 71 | + (__gm__ T*)y, (uint64_t)inTilingData->matmulM * inTilingData->frameCount * inTilingData->batch * DOUBLE_BUFFER); |
| 72 | gmReal.SetGlobalBuffer( | 72 | gmReal.SetGlobalBuffer( |
| 73 | reinterpret_cast<__gm__ T*>(workspace) + windowSplitWorkspaceSize, | 73 | reinterpret_cast<__gm__ T*>(workspace) + windowSplitWorkspaceSize, |
| 74 | - inTilingData->batch * inTilingData->matmulM * inTilingData->frameCount * DOUBLE_BUFFER); | 74 | + (uint64_t)inTilingData->batch * inTilingData->matmulM * inTilingData->frameCount * DOUBLE_BUFFER); |
| 75 | gmImag.SetGlobalBuffer( | 75 | gmImag.SetGlobalBuffer( |
| 76 | reinterpret_cast<__gm__ T*>(workspace) + windowSplitWorkspaceSize, | 76 | reinterpret_cast<__gm__ T*>(workspace) + windowSplitWorkspaceSize, |
| 77 | - inTilingData->batch * inTilingData->matmulM * inTilingData->frameCount * DOUBLE_BUFFER); | 77 | + (uint64_t)inTilingData->batch * inTilingData->matmulM * inTilingData->frameCount * DOUBLE_BUFFER); |
| 78 | pipe.InitBuffer( | 78 | pipe.InitBuffer( |
| 79 | inQueueInput, bufferNum, | 79 | inQueueInput, bufferNum, |
| 80 | (inTilingData->blkFrame * inTilingData->hop + (inTilingData->nfft - inTilingData->hop)) * sizeof(T)); | 80 | (inTilingData->blkFrame * inTilingData->hop + (inTilingData->nfft - inTilingData->hop)) * sizeof(T)); |
| @@ -84,13 +84,13 @@ public: | |||
| 84 | if (g_coreType == AIC) { | 84 | if (g_coreType == AIC) { |
| 85 | auto blockIdx = GetBlockIdx(); | 85 | auto blockIdx = GetBlockIdx(); |
| 86 | a1Global.SetGlobalBuffer( | 86 | a1Global.SetGlobalBuffer( |
| 87 | - reinterpret_cast<__gm__ T*>(window), inTilingData->matmulM * inTilingData->nfft * DOUBLE_BUFFER); | 87 | + reinterpret_cast<__gm__ T*>(window), (uint64_t)inTilingData->matmulM * inTilingData->nfft * DOUBLE_BUFFER); |
| 88 | bGlobal.SetGlobalBuffer( | 88 | bGlobal.SetGlobalBuffer( |
| 89 | reinterpret_cast<__gm__ T*>(workspace), | 89 | reinterpret_cast<__gm__ T*>(workspace), |
| 90 | - inTilingData->blockNum * inTilingData->nfft * inTilingData->frameCount * inTilingData->aivBatchLoop); | 90 | + (uint64_t)inTilingData->blockNum * inTilingData->nfft * inTilingData->frameCount * inTilingData->aivBatchLoop); |
| 91 | matMulWorkspaceGm.SetGlobalBuffer( | 91 | matMulWorkspaceGm.SetGlobalBuffer( |
| 92 | reinterpret_cast<__gm__ T*>(workspace) + windowSplitWorkspaceSize, | 92 | reinterpret_cast<__gm__ T*>(workspace) + windowSplitWorkspaceSize, |
| 93 | - inTilingData->matmulM * inTilingData->frameCount * inTilingData->batch * DOUBLE_BUFFER); | 93 | + (uint64_t)inTilingData->matmulM * inTilingData->frameCount * inTilingData->batch * DOUBLE_BUFFER); |
| 94 | 94 | ||
| 95 | curCoreM_ = inTilingData->aicTotalLen; | 95 | curCoreM_ = inTilingData->aicTotalLen; |
| 96 | curCoreN_ = inTilingData->mmTilingData.N; | 96 | curCoreN_ = inTilingData->mmTilingData.N; |
| @@ -180,15 +180,15 @@ public: | |||
| 180 | CreateGatherMask(maskTemp, maskCol, REAL_IMAG_COLS, 0, REAL_IMAG * gatherSizePerRepeat); | 180 | CreateGatherMask(maskTemp, maskCol, REAL_IMAG_COLS, 0, REAL_IMAG * gatherSizePerRepeat); |
| 181 | 181 | ||
| 182 | // 生成mask等差数列 | 182 | // 生成mask等差数列 |
| 183 | - int32_t offsetBase = 0; | 183 | + int64_t offsetBase = 0; |
| 184 | if (unlikely(blockIdx % windowLoop < aivMTailIdx)) { | 184 | if (unlikely(blockIdx % windowLoop < aivMTailIdx)) { |
| 185 | - offsetBase = ((blockIdx % windowLoop) / C_V_DOUBLE) * totalMLen * frameCount + | 185 | + offsetBase = (int64_t)((blockIdx % windowLoop) / C_V_DOUBLE) * totalMLen * frameCount + |
| 186 | - (blockIdx % C_V_DOUBLE) * (aivTotalEvenMLen * REAL_IMAG) * frameCount; | 186 | + (int64_t)(blockIdx % C_V_DOUBLE) * (aivTotalEvenMLen * REAL_IMAG) * frameCount; |
| 187 | } else { | 187 | } else { |
| 188 | - offsetBase = (aivMTailIdx / C_V_DOUBLE) * totalMLen * frameCount + | 188 | + offsetBase = (int64_t)(aivMTailIdx / C_V_DOUBLE) * totalMLen * frameCount + |
| 189 | - (((blockIdx % windowLoop) - aivMTailIdx) % C_V_DOUBLE) * (aivTailEvenMLen * REAL_IMAG) * | 189 | + (int64_t)(((blockIdx % windowLoop) - aivMTailIdx) % C_V_DOUBLE) * (aivTailEvenMLen * REAL_IMAG) * |
| 190 | frameCount + | 190 | frameCount + |
| 191 | - ((blockIdx % windowLoop) - aivMTailIdx) / C_V_DOUBLE * aicTailLen * frameCount; | 191 | + (int64_t)(((blockIdx % windowLoop) - aivMTailIdx) / C_V_DOUBLE) * aicTailLen * frameCount; |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | int repeats = (N * sizeof(T) + gatherSizePerRepeat - 1) / gatherSizePerRepeat; | 194 | int repeats = (N * sizeof(T) + gatherSizePerRepeat - 1) / gatherSizePerRepeat; |
| @@ -203,9 +203,9 @@ public: | |||
| 203 | AscendC::WaitEvent(flag_id_fix); | 203 | AscendC::WaitEvent(flag_id_fix); |
| 204 | 204 | ||
| 205 | int32_t curBatch = (blockIdx / windowLoop) * aicBatchLoop + i; | 205 | int32_t curBatch = (blockIdx / windowLoop) * aicBatchLoop + i; |
| 206 | - int32_t gmRealOffset = curBatch * matmulM * frameCount * DOUBLE_BUFFER; | 206 | + int64_t gmRealOffset = (int64_t)curBatch * matmulM * frameCount * DOUBLE_BUFFER; |
| 207 | - int32_t gmImagOffset = gmRealOffset + frameCount; | 207 | + int64_t gmImagOffset = gmRealOffset + frameCount; |
| 208 | - int32_t outputOffset = curBatch * matmulM * frameCount * DOUBLE_BUFFER; | 208 | + int64_t outputOffset = (int64_t)curBatch * matmulM * frameCount * DOUBLE_BUFFER; |
| 209 | 209 | ||
| 210 | gmRealOffset = gmRealOffset + offsetBase; | 210 | gmRealOffset = gmRealOffset + offsetBase; |
| 211 | gmImagOffset = gmImagOffset + offsetBase; | 211 | gmImagOffset = gmImagOffset + offsetBase; |
| @@ -266,15 +266,15 @@ public: | |||
| 266 | globalN_ = inTilingData->mmTilingData.N; | 266 | globalN_ = inTilingData->mmTilingData.N; |
| 267 | globalK_ = inTilingData->mmTilingData.Ka; | 267 | globalK_ = inTilingData->mmTilingData.Ka; |
| 268 | 268 | ||
| 269 | - int32_t a1GlobalOffset = 0; | 269 | + int64_t a1GlobalOffset = 0; |
| 270 | - int32_t outputOffsetBase = 0; | 270 | + int64_t outputOffsetBase = 0; |
| 271 | if (unlikely(blockIdx % aicMatmulMCore < aicMTailIdx)) { | 271 | if (unlikely(blockIdx % aicMatmulMCore < aicMTailIdx)) { |
| 272 | - a1GlobalOffset = innerReminder * totalMLen * nfft; | 272 | + a1GlobalOffset = (int64_t)innerReminder * totalMLen * nfft; |
| 273 | - outputOffsetBase = innerReminder * totalMLen * frameCount; | 273 | + outputOffsetBase = (int64_t)innerReminder * totalMLen * frameCount; |
| 274 | } else { | 274 | } else { |
| 275 | - a1GlobalOffset = aicMTailIdx * totalMLen * nfft + (innerReminder - aicMTailIdx) * aicTailLen * nfft; | 275 | + a1GlobalOffset = (int64_t)aicMTailIdx * totalMLen * nfft + (int64_t)(innerReminder - aicMTailIdx) * aicTailLen * nfft; |
| 276 | outputOffsetBase = | 276 | outputOffsetBase = |
| 277 | - aicMTailIdx * totalMLen * frameCount + (innerReminder - aicMTailIdx) * aicTailLen * frameCount; | 277 | + (int64_t)aicMTailIdx * totalMLen * frameCount + (int64_t)(innerReminder - aicMTailIdx) * aicTailLen * frameCount; |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | uint64_t flag_id_mte3 = 3; | 280 | uint64_t flag_id_mte3 = 3; |
| @@ -286,9 +286,9 @@ public: | |||
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | int32_t curBatch = curBatchBase + i; | 288 | int32_t curBatch = curBatchBase + i; |
| 289 | - int32_t bGlobalOffset = | 289 | + int64_t bGlobalOffset = |
| 290 | - blockIdx * aicBatchLoop * frameCount * inTilingData->nfft + i * frameCount * inTilingData->nfft; | 290 | + (int64_t)blockIdx * aicBatchLoop * frameCount * inTilingData->nfft + (int64_t)i * frameCount * inTilingData->nfft; |
| 291 | - int32_t outputOffset = curBatch * matmulM * frameCount * REAL_IMAG + outputOffsetBase; | 291 | + int64_t outputOffset = (int64_t)curBatch * matmulM * frameCount * REAL_IMAG + outputOffsetBase; |
| 292 | bGM = bGlobal[bGlobalOffset]; | 292 | bGM = bGlobal[bGlobalOffset]; |
| 293 | aGM = a1Global[a1GlobalOffset]; | 293 | aGM = a1Global[a1GlobalOffset]; |
| 294 | cGM = matMulWorkspaceGm[outputOffset]; | 294 | cGM = matMulWorkspaceGm[outputOffset]; |
| @@ -48,8 +48,8 @@ public: | |||
| 48 | return; | 48 | return; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | - uint64_t inputGmSize = tiling->batch * ((tiling->inputSize + tiling->nfft) * sizeof(T) + BLOCK_SIZE - 1) / | 51 | + uint64_t inputGmSize = (uint64_t)tiling->batch * (((uint64_t)(tiling->inputSize + tiling->nfft) * sizeof(T) + BLOCK_SIZE - 1) / |
| 52 | - BLOCK_SIZE * BLOCK_SIZE / sizeof(T); | 52 | + BLOCK_SIZE * BLOCK_SIZE / sizeof(T)); |
| 53 | inputGm.SetGlobalBuffer((__gm__ T*)x, inputGmSize); | 53 | inputGm.SetGlobalBuffer((__gm__ T*)x, inputGmSize); |
| 54 | 54 | ||
| 55 | uint64_t splitWindowGmSize = (uint64_t)tiling->batch * tiling->matmulN * tiling->nfftAlign; | 55 | uint64_t splitWindowGmSize = (uint64_t)tiling->batch * tiling->matmulN * tiling->nfftAlign; |
| @@ -159,14 +159,16 @@ public: | |||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | for (int i = 0; i < bFactor; i++) { | 161 | for (int i = 0; i < bFactor; i++) { |
| 162 | - int64_t inputOffset = (bOffset + i) * (tiling->inputSize + tiling->nfft) + nOffset * tiling->hopLength; | 162 | + int64_t inputOffset = (int64_t)(bOffset + i) * (tiling->inputSize + tiling->nfft) + |
| 163 | - int64_t splitWindowOffset = ((bOffset + i) * tiling->matmulN + nOffset) * tiling->nfftAlign; | 163 | + (int64_t)nOffset * tiling->hopLength; |
| 164 | + int64_t splitWindowOffset = ((int64_t)(bOffset + i) * tiling->matmulN + nOffset) * tiling->nfftAlign; | ||
| 164 | int64_t outputOffset = | 165 | int64_t outputOffset = |
| 165 | - (((bOffset + i) * tiling->matmulM + mOffset) * tiling->matmulN + nOffset) * IMAG_AND_REAL; | 166 | + (((int64_t)(bOffset + i) * tiling->matmulM + mOffset) * tiling->matmulN + nOffset) * IMAG_AND_REAL; |
| 166 | - int64_t realOffset = (bOffset + i) * tiling->matmulM * tiling->matmulN + mOffset * tiling->matmulN + | 167 | + int64_t realOffset = (int64_t)(bOffset + i) * tiling->matmulM * tiling->matmulN + |
| 167 | - nIdx * mFactor * tiling->matmulNCoreFactor; | 168 | + (int64_t)mOffset * tiling->matmulN + |
| 169 | + (int64_t)nIdx * mFactor * tiling->matmulNCoreFactor; | ||
| 168 | int64_t imagOffset = realOffset; | 170 | int64_t imagOffset = realOffset; |
| 169 | - int64_t a1Offset = mOffset * tiling->nfftAlign; | 171 | + int64_t a1Offset = (int64_t)mOffset * tiling->nfftAlign; |
| 170 | int64_t a2Offset = a1Offset; | 172 | int64_t a2Offset = a1Offset; |
| 171 | 173 | ||
| 172 | int64_t planOffset = IMAG_AND_REAL * mOffset * tiling->nfftAlign; | 174 | int64_t planOffset = IMAG_AND_REAL * mOffset * tiling->nfftAlign; |
| @@ -715,8 +717,8 @@ private: | |||
| 715 | int32_t total = 0; | 717 | int32_t total = 0; |
| 716 | while (total < nFactor) { | 718 | while (total < nFactor) { |
| 717 | LocalTensor<T> inputLocal = inCopy.template AllocTensor<T>(); | 719 | LocalTensor<T> inputLocal = inCopy.template AllocTensor<T>(); |
| 718 | - int32_t inputLeft = | 720 | + int64_t inputLeft = |
| 719 | - (tiling->batch * (tiling->inputSize + tiling->nfft) - total * tiling->hopLength - inputOffset) * | 721 | + ((int64_t)tiling->batch * (tiling->inputSize + tiling->nfft) - (int64_t)total * tiling->hopLength - inputOffset) * |
| 720 | sizeof(T); | 722 | sizeof(T); |
| 721 | int32_t copyLength = inputLeft > bufferSize ? bufferSize / sizeof(T) : inputLeft / sizeof(T); | 723 | int32_t copyLength = inputLeft > bufferSize ? bufferSize / sizeof(T) : inputLeft / sizeof(T); |
| 722 | DataCopyPadExtParams<T> dataCopyPadExtParams; | 724 | DataCopyPadExtParams<T> dataCopyPadExtParams; |
| @@ -53,11 +53,11 @@ public: | |||
| 53 | tiling = tilingData; | 53 | tiling = tilingData; |
| 54 | 54 | ||
| 55 | inputGm.SetGlobalBuffer( | 55 | inputGm.SetGlobalBuffer( |
| 56 | - (__gm__ T*)x, tiling->batch * | 56 | + (__gm__ T*)x, (uint64_t)tiling->batch * |
| 57 | - ((tiling->inputSize + tiling->nfft) * COMPLEX_COEFFICIENT * sizeof(T) + BLOCK_SIZE - 1) / | 57 | + (((uint64_t)(tiling->inputSize + tiling->nfft) * COMPLEX_COEFFICIENT * sizeof(T) + BLOCK_SIZE - 1) / |
| 58 | - BLOCK_SIZE * BLOCK_SIZE / sizeof(T)); | 58 | + BLOCK_SIZE * BLOCK_SIZE / sizeof(T))); |
| 59 | - size_t splitWindowWorkspaceSize = tiling->batch * tiling->matmulN * tiling->nfftAlign; | 59 | + uint64_t splitWindowWorkspaceSize = (uint64_t)tiling->batch * tiling->matmulN * tiling->nfftAlign; |
| 60 | - size_t splitWindowWorkspaceSizeAlign = | 60 | + uint64_t splitWindowWorkspaceSizeAlign = |
| 61 | (((splitWindowWorkspaceSize * sizeof(T) * COMPLEX_COEFFICIENT + WORKSPACE_ALIGN_SIZE - 1) / | 61 | (((splitWindowWorkspaceSize * sizeof(T) * COMPLEX_COEFFICIENT + WORKSPACE_ALIGN_SIZE - 1) / |
| 62 | WORKSPACE_ALIGN_SIZE) * | 62 | WORKSPACE_ALIGN_SIZE) * |
| 63 | WORKSPACE_ALIGN_SIZE) / | 63 | WORKSPACE_ALIGN_SIZE) / |
| @@ -66,7 +66,7 @@ public: | |||
| 66 | splitRealWindowGm.SetGlobalBuffer((__gm__ T*)workspace, splitWindowWorkspaceSize); | 66 | splitRealWindowGm.SetGlobalBuffer((__gm__ T*)workspace, splitWindowWorkspaceSize); |
| 67 | splitImagWindowGm.SetGlobalBuffer((__gm__ T*)workspace + splitWindowWorkspaceSize, splitWindowWorkspaceSize); | 67 | splitImagWindowGm.SetGlobalBuffer((__gm__ T*)workspace + splitWindowWorkspaceSize, splitWindowWorkspaceSize); |
| 68 | 68 | ||
| 69 | - size_t matmulWorkspaceSize = tiling->batch * tiling->matmulM * tiling->matmulN; | 69 | + uint64_t matmulWorkspaceSize = (uint64_t)tiling->batch * tiling->matmulM * tiling->matmulN; |
| 70 | 70 | ||
| 71 | aRealGm.SetGlobalBuffer((__gm__ T*)workspace + splitWindowWorkspaceSizeAlign, matmulWorkspaceSize); | 71 | aRealGm.SetGlobalBuffer((__gm__ T*)workspace + splitWindowWorkspaceSizeAlign, matmulWorkspaceSize); |
| 72 | aImagGm.SetGlobalBuffer( | 72 | aImagGm.SetGlobalBuffer( |
| @@ -76,11 +76,11 @@ public: | |||
| 76 | matmulWorkspaceSize); | 76 | matmulWorkspaceSize); |
| 77 | bImagGm.SetGlobalBuffer( | 77 | bImagGm.SetGlobalBuffer( |
| 78 | (__gm__ T*)workspace + splitWindowWorkspaceSizeAlign + matmulWorkspaceSize * 3, matmulWorkspaceSize); | 78 | (__gm__ T*)workspace + splitWindowWorkspaceSizeAlign + matmulWorkspaceSize * 3, matmulWorkspaceSize); |
| 79 | - outputGm.SetGlobalBuffer((__gm__ T*)y, tiling->batch * tiling->matmulM * tiling->matmulN * DOUBLE_BUFFER); | 79 | + outputGm.SetGlobalBuffer((__gm__ T*)y, (uint64_t)tiling->batch * tiling->matmulM * tiling->matmulN * DOUBLE_BUFFER); |
| 80 | - a1Global.SetGlobalBuffer(reinterpret_cast<__gm__ T*>(window), tiling->matmulM * tiling->nfftAlign); | 80 | + a1Global.SetGlobalBuffer(reinterpret_cast<__gm__ T*>(window), (uint64_t)tiling->matmulM * tiling->nfftAlign); |
| 81 | a2Global.SetGlobalBuffer( | 81 | a2Global.SetGlobalBuffer( |
| 82 | - reinterpret_cast<__gm__ T*>(window) + tiling->matmulM * tiling->nfftAlign, | 82 | + reinterpret_cast<__gm__ T*>(window) + (uint64_t)tiling->matmulM * tiling->nfftAlign, |
| 83 | - tiling->matmulM * tiling->nfftAlign); | 83 | + (uint64_t)tiling->matmulM * tiling->nfftAlign); |
| 84 | 84 | ||
| 85 | size_t ubAlignBufferSize = (tiling->nFactorUbFormer * COMPLEX_COEFFICIENT + REPEAT_NUM_FOR_FP32 - 1) / | 85 | size_t ubAlignBufferSize = (tiling->nFactorUbFormer * COMPLEX_COEFFICIENT + REPEAT_NUM_FOR_FP32 - 1) / |
| 86 | REPEAT_NUM_FOR_FP32 * REPEAT_NUM_FOR_FP32 * sizeof(T); | 86 | REPEAT_NUM_FOR_FP32 * REPEAT_NUM_FOR_FP32 * sizeof(T); |
| @@ -153,16 +153,17 @@ public: | |||
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | for (uint32_t i = 0; i < bFactor; i++) { | 155 | for (uint32_t i = 0; i < bFactor; i++) { |
| 156 | - int64_t inputOffset = (bOffset + i) * (tiling->inputSize + tiling->nfft) * COMPLEX_COEFFICIENT + | 156 | + int64_t inputOffset = (int64_t)(bOffset + i) * (tiling->inputSize + tiling->nfft) * COMPLEX_COEFFICIENT + |
| 157 | - nOffset * tiling->hopLength * COMPLEX_COEFFICIENT; | 157 | + (int64_t)nOffset * tiling->hopLength * COMPLEX_COEFFICIENT; |
| 158 | - int64_t realSplitWindowOffset = ((bOffset + i) * tiling->matmulN + nOffset) * tiling->nfftAlign; | 158 | + int64_t realSplitWindowOffset = ((int64_t)(bOffset + i) * tiling->matmulN + nOffset) * tiling->nfftAlign; |
| 159 | int64_t imagSplitWindowOffset = realSplitWindowOffset; | 159 | int64_t imagSplitWindowOffset = realSplitWindowOffset; |
| 160 | int64_t outputOffset = | 160 | int64_t outputOffset = |
| 161 | - (((bOffset + i) * tiling->matmulM + mOffset) * tiling->matmulN + nOffset) * DOUBLE_BUFFER; | 161 | + (((int64_t)(bOffset + i) * tiling->matmulM + mOffset) * tiling->matmulN + nOffset) * DOUBLE_BUFFER; |
| 162 | - int64_t realOffset = (bOffset + i) * tiling->matmulM * tiling->matmulN + mOffset * tiling->matmulN + | 162 | + int64_t realOffset = (int64_t)(bOffset + i) * tiling->matmulM * tiling->matmulN + |
| 163 | - nIdx * mFactor * tiling->matmulNCoreFactor; | 163 | + (int64_t)mOffset * tiling->matmulN + |
| 164 | + (int64_t)nIdx * mFactor * tiling->matmulNCoreFactor; | ||
| 164 | int64_t imagOffset = realOffset; | 165 | int64_t imagOffset = realOffset; |
| 165 | - int64_t a1Offset = mOffset * tiling->nfftAlign; | 166 | + int64_t a1Offset = (int64_t)mOffset * tiling->nfftAlign; |
| 166 | int64_t a2Offset = a1Offset; | 167 | int64_t a2Offset = a1Offset; |
| 167 | 168 | ||
| 168 | SplitWindows(inputOffset, realSplitWindowOffset, imagSplitWindowOffset, nFactor); | 169 | SplitWindows(inputOffset, realSplitWindowOffset, imagSplitWindowOffset, nFactor); |
| @@ -228,9 +229,9 @@ private: | |||
| 228 | __aicore__ inline void GatherForSmallNFactorAlign( | 229 | __aicore__ inline void GatherForSmallNFactorAlign( |
| 229 | int64_t realOffset, int64_t imagOffset, int64_t outputOffset, uint32_t mFactor, uint32_t nFactor) | 230 | int64_t realOffset, int64_t imagOffset, int64_t outputOffset, uint32_t mFactor, uint32_t nFactor) |
| 230 | { | 231 | { |
| 231 | - int32_t complexCount = mFactor * nFactor * DOUBLE_BUFFER; | 232 | + int64_t complexCount = (int64_t)mFactor * nFactor * DOUBLE_BUFFER; |
| 232 | int32_t ubCount = tiling->maskUBSize / sizeof(int32_t) / DOUBLE_BUFFER; | 233 | int32_t ubCount = tiling->maskUBSize / sizeof(int32_t) / DOUBLE_BUFFER; |
| 233 | - int32_t gatherCountPerLoop = complexCount > maskCount ? maskCount : complexCount; | 234 | + int32_t gatherCountPerLoop = (int32_t)(complexCount > maskCount ? maskCount : complexCount); |
| 234 | 235 | ||
| 235 | gatherCountPerLoop = gatherCountPerLoop - gatherCountPerLoop % (nFactor * DOUBLE_BUFFER); | 236 | gatherCountPerLoop = gatherCountPerLoop - gatherCountPerLoop % (nFactor * DOUBLE_BUFFER); |
| 236 | int32_t realCountPerLoop = gatherCountPerLoop / DOUBLE_BUFFER; | 237 | int32_t realCountPerLoop = gatherCountPerLoop / DOUBLE_BUFFER; |
| @@ -239,7 +240,7 @@ private: | |||
| 239 | AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID0); | 240 | AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID0); |
| 240 | AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID1); | 241 | AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID1); |
| 241 | int ping = 1; | 242 | int ping = 1; |
| 242 | - int repeats = (complexCount + gatherCountPerLoop - 1) / gatherCountPerLoop; | 243 | + int repeats = (int)((complexCount + gatherCountPerLoop - 1) / gatherCountPerLoop); |
| 243 | 244 | ||
| 244 | for (int i = 0; i < repeats; i++) { | 245 | for (int i = 0; i < repeats; i++) { |
| 245 | event_t event_id = ping ? EVENT_ID0 : EVENT_ID1; | 246 | event_t event_id = ping ? EVENT_ID0 : EVENT_ID1; |
| @@ -252,7 +253,7 @@ private: | |||
| 252 | int32_t copyLen = realCountPerLoop * sizeof(T); | 253 | int32_t copyLen = realCountPerLoop * sizeof(T); |
| 253 | 254 | ||
| 254 | if (i == repeats - 1) { | 255 | if (i == repeats - 1) { |
| 255 | - copyLen = (mFactor * nFactor - realCountPerLoop * i) * sizeof(T); | 256 | + copyLen = ((int64_t)mFactor * nFactor - (int64_t)realCountPerLoop * i) * sizeof(T); |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | int32_t nBlocks = (copyLen + BLOCK_SIZE - 1) / BLOCK_SIZE; | 259 | int32_t nBlocks = (copyLen + BLOCK_SIZE - 1) / BLOCK_SIZE; |
| @@ -304,8 +305,8 @@ private: | |||
| 304 | int64_t realOffset, int64_t imagOffset, int64_t outputOffset, uint32_t mFactor, uint32_t nFactor) | 305 | int64_t realOffset, int64_t imagOffset, int64_t outputOffset, uint32_t mFactor, uint32_t nFactor) |
| 305 | { | 306 | { |
| 306 | int32_t nFactorAlign = (nFactor * sizeof(T) + BLOCK_SIZE - 1) / BLOCK_SIZE * BLOCK_SIZE / sizeof(T); | 307 | int32_t nFactorAlign = (nFactor * sizeof(T) + BLOCK_SIZE - 1) / BLOCK_SIZE * BLOCK_SIZE / sizeof(T); |
| 307 | - int32_t complexCount = mFactor * nFactorAlign * DOUBLE_BUFFER; | 308 | + int64_t complexCount = (int64_t)mFactor * nFactorAlign * DOUBLE_BUFFER; |
| 308 | - int32_t gatherCountPerLoop = complexCount > maskCount ? maskCount : complexCount; | 309 | + int32_t gatherCountPerLoop = (int32_t)(complexCount > maskCount ? maskCount : complexCount); |
| 309 | gatherCountPerLoop = gatherCountPerLoop - gatherCountPerLoop % (nFactorAlign * DOUBLE_BUFFER); | 310 | gatherCountPerLoop = gatherCountPerLoop - gatherCountPerLoop % (nFactorAlign * DOUBLE_BUFFER); |
| 310 | int32_t realCountPerLoop = gatherCountPerLoop / DOUBLE_BUFFER; | 311 | int32_t realCountPerLoop = gatherCountPerLoop / DOUBLE_BUFFER; |
| 311 | int32_t imagCountPerLoop = gatherCountPerLoop / DOUBLE_BUFFER; | 312 | int32_t imagCountPerLoop = gatherCountPerLoop / DOUBLE_BUFFER; |
| @@ -314,7 +315,7 @@ private: | |||
| 314 | AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID1); | 315 | AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID1); |
| 315 | 316 | ||
| 316 | int ping = 1; | 317 | int ping = 1; |
| 317 | - int repeats = (complexCount + gatherCountPerLoop - 1) / gatherCountPerLoop; | 318 | + int repeats = (int)((complexCount + gatherCountPerLoop - 1) / gatherCountPerLoop); |
| 318 | 319 | ||
| 319 | for (int i = 0; i < repeats; i++) { | 320 | for (int i = 0; i < repeats; i++) { |
| 320 | event_t event_id = ping ? EVENT_ID0 : EVENT_ID1; | 321 | event_t event_id = ping ? EVENT_ID0 : EVENT_ID1; |
| @@ -326,7 +327,7 @@ private: | |||
| 326 | 327 | ||
| 327 | int32_t copyLen = realCountPerLoop * sizeof(T); | 328 | int32_t copyLen = realCountPerLoop * sizeof(T); |
| 328 | if (i == repeats - 1) { | 329 | if (i == repeats - 1) { |
| 329 | - copyLen = (mFactor * nFactorAlign - realCountPerLoop * i) * sizeof(T); | 330 | + copyLen = ((int64_t)mFactor * nFactorAlign - (int64_t)realCountPerLoop * i) * sizeof(T); |
| 330 | } | 331 | } |
| 331 | 332 | ||
| 332 | AscendC::WaitFlag<AscendC::HardEvent::MTE3_MTE2>(event_id); | 333 | AscendC::WaitFlag<AscendC::HardEvent::MTE3_MTE2>(event_id); |
| @@ -402,7 +403,7 @@ private: | |||
| 402 | 403 | ||
| 403 | int32_t copyLen = realCountPerLoop * sizeof(T); | 404 | int32_t copyLen = realCountPerLoop * sizeof(T); |
| 404 | if (i == repeats - 1) { | 405 | if (i == repeats - 1) { |
| 405 | - copyLen = (mFactor * nFactor - realCountPerLoop * i) * sizeof(T); | 406 | + copyLen = ((int64_t)mFactor * nFactor - (int64_t)realCountPerLoop * i) * sizeof(T); |
| 406 | } | 407 | } |
| 407 | 408 | ||
| 408 | int32_t nBlocks = (copyLen + BLOCK_SIZE - 1) / BLOCK_SIZE; | 409 | int32_t nBlocks = (copyLen + BLOCK_SIZE - 1) / BLOCK_SIZE; |
| @@ -476,7 +477,7 @@ private: | |||
| 476 | 477 | ||
| 477 | int32_t copyLen = realCountPerLoop * sizeof(T); | 478 | int32_t copyLen = realCountPerLoop * sizeof(T); |
| 478 | if (i == repeats - 1) { | 479 | if (i == repeats - 1) { |
| 479 | - copyLen = (mFactor * nFactor - realCountPerLoop * i) * sizeof(T); | 480 | + copyLen = ((int64_t)mFactor * nFactor - (int64_t)realCountPerLoop * i) * sizeof(T); |
| 480 | } | 481 | } |
| 481 | 482 | ||
| 482 | int32_t nBlocks = (copyLen + BLOCK_SIZE - 1) / BLOCK_SIZE; | 483 | int32_t nBlocks = (copyLen + BLOCK_SIZE - 1) / BLOCK_SIZE; |
| @@ -40,10 +40,10 @@ public: | |||
| 40 | col = inTilingData->oneRowLen; | 40 | col = inTilingData->oneRowLen; |
| 41 | ubMaxLine = inTilingData->ubMaxLine; | 41 | ubMaxLine = inTilingData->ubMaxLine; |
| 42 | row = totalRow; | 42 | row = totalRow; |
| 43 | - int32_t planGlobalOffset = blockIdx * totalRow * col; | 43 | + int64_t planGlobalOffset = (int64_t)blockIdx * totalRow * col; |
| 44 | if (blockIdx >= inTilingData->tailBlockIdx) { | 44 | if (blockIdx >= inTilingData->tailBlockIdx) { |
| 45 | - planGlobalOffset = inTilingData->tailBlockIdx * totalRow * col + | 45 | + planGlobalOffset = (int64_t)inTilingData->tailBlockIdx * totalRow * col + |
| 46 | - (blockIdx - inTilingData->tailBlockIdx) * tailRow * col; | 46 | + (int64_t)(blockIdx - inTilingData->tailBlockIdx) * tailRow * col; |
| 47 | row = tailRow; | 47 | row = tailRow; |
| 48 | } | 48 | } |
| 49 | uint64_t splitWindowWorkspaceSize = | 49 | uint64_t splitWindowWorkspaceSize = |
| @@ -56,9 +56,9 @@ public: | |||
| 56 | WORKSPACE_ALIGN_SIZE) * | 56 | WORKSPACE_ALIGN_SIZE) * |
| 57 | WORKSPACE_ALIGN_SIZE / sizeof(T); | 57 | WORKSPACE_ALIGN_SIZE / sizeof(T); |
| 58 | uint64_t planOffset = splitWindowWorkspaceSize + matmulWorkspaceSize; | 58 | uint64_t planOffset = splitWindowWorkspaceSize + matmulWorkspaceSize; |
| 59 | - planGm.SetGlobalBuffer((__gm__ T*)plan + planGlobalOffset, row * col); | 59 | + planGm.SetGlobalBuffer((__gm__ T*)plan + planGlobalOffset, (int64_t)row * col); |
| 60 | windowGm.SetGlobalBuffer((__gm__ T*)window, col); | 60 | windowGm.SetGlobalBuffer((__gm__ T*)window, col); |
| 61 | - outputGm.SetGlobalBuffer((__gm__ T*)workspace + planOffset + planGlobalOffset, row * col); | 61 | + outputGm.SetGlobalBuffer((__gm__ T*)workspace + planOffset + planGlobalOffset, (int64_t)row * col); |
| 62 | pipe->InitBuffer(planInQue, bufferNum, ubMaxLine * col * sizeof(T)); | 62 | pipe->InitBuffer(planInQue, bufferNum, ubMaxLine * col * sizeof(T)); |
| 63 | pipe->InitBuffer(planOutQue, bufferNum, ubMaxLine * col * sizeof(T)); | 63 | pipe->InitBuffer(planOutQue, bufferNum, ubMaxLine * col * sizeof(T)); |
| 64 | pipe->InitBuffer(windowInQue, 1, col * sizeof(T)); | 64 | pipe->InitBuffer(windowInQue, 1, col * sizeof(T)); |