已合并
hans_encode/hans_decode算子bug修复 #449
Nythas N创建于 2025年12月20日
hans_encode/hans_decode算子bug修复 #449
已合并
共 5 个文件变更+49-38
| @@ -0,0 +1,3 @@ | |||
| 1 | +# aclnnHansDecode | ||
| 2 | + | ||
| 3 | +本文档内容正按全新接口模板整改中,将陆续上线,如需使用该接口请访问昇腾社区[《算子库接口》](https://hiascend.com/document/redirect/CannCommunityOplist)对应的aclnnHansDecode章节。 | ||
| @@ -362,10 +362,10 @@ __aicore__ inline void HansDecode<IF_BF16>::GetNegativeBitNum(DecodeLoopConfig* | |||
| 362 | stateBufferBitNumberUb.template ReinterpretCast<float>(), const16Ub.template ReinterpretCast<float>(), | 362 | stateBufferBitNumberUb.template ReinterpretCast<float>(), const16Ub.template ReinterpretCast<float>(), |
| 363 | AscendC::CMPMODE::LE, EACH_LOOOP_STATE_READ_NUM); | 363 | AscendC::CMPMODE::LE, EACH_LOOOP_STATE_READ_NUM); |
| 364 | PipeBarrier<PIPE_V>(); | 364 | PipeBarrier<PIPE_V>(); |
| 365 | - GatherMask(negativeBitTempSpace.template ReinterpretCast<uint32_t>(), | 365 | + GatherMask( |
| 366 | - constOneUb.template ReinterpretCast<uint32_t>(), | 366 | + negativeBitTempSpace.template ReinterpretCast<uint32_t>(), constOneUb.template ReinterpretCast<uint32_t>(), |
| 367 | - negativeZeroCmpBitMask.template ReinterpretCast<uint32_t>(), | 367 | + negativeZeroCmpBitMask.template ReinterpretCast<uint32_t>(), true, EACH_REPEAT_BYTES / sizeof(uint32_t), |
| 368 | - false, 0, {1, 1, static_cast<uint8_t>(REPEAT_STRIDE), 1}, this->rsvdCnt); | 368 | + {1, 1, REPEAT_STRIDE, 0}, this->rsvdCnt); |
| 369 | PipeBarrier<PIPE_V>(); | 369 | PipeBarrier<PIPE_V>(); |
| 370 | config->negativeZeroSum = AscendC::AscendCUtils::GetRsvdCnt(); | 370 | config->negativeZeroSum = AscendC::AscendCUtils::GetRsvdCnt(); |
| 371 | config->loopDataIndex = config->loopDataIndex - EACH_LOOOP_STATE_READ_NUM; | 371 | config->loopDataIndex = config->loopDataIndex - EACH_LOOOP_STATE_READ_NUM; |
| @@ -561,11 +561,11 @@ __aicore__ inline void HansDecode<IF_BF16>::MoveOutFp32( | |||
| 561 | PipeBarrier<PIPE_V>(); | 561 | PipeBarrier<PIPE_V>(); |
| 562 | Cast(recoverMantissaFp162s32Ub, recoverMantissaFp16Ub, AscendC::RoundMode::CAST_CEIL, PROCESS_3072); | 562 | Cast(recoverMantissaFp162s32Ub, recoverMantissaFp16Ub, AscendC::RoundMode::CAST_CEIL, PROCESS_3072); |
| 563 | PipeBarrier<PIPE_V>(); | 563 | PipeBarrier<PIPE_V>(); |
| 564 | - GatherMask(recoverMantissaFp16GatherUb.template ReinterpretCast<uint16_t>(), | 564 | + GatherMask( |
| 565 | - recoverMantissaFp162s32Ub.template ReinterpretCast<uint16_t>(), | 565 | + recoverMantissaFp16GatherUb.template ReinterpretCast<uint16_t>(), |
| 566 | - mantissaBitMask.template ReinterpretCast<uint16_t>(), false, 0, | 566 | + recoverMantissaFp162s32Ub.template ReinterpretCast<uint16_t>(), |
| 567 | - {static_cast<uint8_t>(3 * mantissaRepeatTimes), 1, static_cast<uint8_t>(REPEAT_STRIDE), 1}, | 567 | + mantissaBitMask.template ReinterpretCast<uint16_t>(), true, 3 * mantissaRepeatTimes * EACH_REPEAT_BYTES / sizeof(uint16_t), |
| 568 | - this->rsvdCnt); | 568 | + {1, 1, REPEAT_STRIDE, 0}, this->rsvdCnt); |
| 569 | PipeBarrier<PIPE_V>(); | 569 | PipeBarrier<PIPE_V>(); |
| 570 | Cast( | 570 | Cast( |
| 571 | recoverMantissaFp16GatherUb.template ReinterpretCast<half>(), | 571 | recoverMantissaFp16GatherUb.template ReinterpretCast<half>(), |
| @@ -724,11 +724,10 @@ __aicore__ inline void HansDecode<IF_BF16>::ProcessFp32BeforeH2D( | |||
| 724 | AscendC::RoundMode::CAST_TRUNC, (size * (sizeof(float) - 1))); | 724 | AscendC::RoundMode::CAST_TRUNC, (size * (sizeof(float) - 1))); |
| 725 | PipeBarrier<PIPE_V>(); | 725 | PipeBarrier<PIPE_V>(); |
| 726 | SetVectorMask<uint64_t, MaskMode::NORMAL>((uint64_t)-1, (uint64_t)-1); | 726 | SetVectorMask<uint64_t, MaskMode::NORMAL>((uint64_t)-1, (uint64_t)-1); |
| 727 | - GatherMask(deviceExpUb[index].template ReinterpretCast<uint16_t>(), | 727 | + GatherMask( |
| 728 | - recoverUb[index].template ReinterpretCast<uint16_t>(), | 728 | + deviceExpUb[index].template ReinterpretCast<uint16_t>(), recoverUb[index].template ReinterpretCast<uint16_t>(), |
| 729 | - mantissaBitMask.template ReinterpretCast<uint16_t>(), false, 0, | 729 | + mantissaBitMask.template ReinterpretCast<uint16_t>(), true, (size * (sizeof(float) - 1) * 2) / CONST_128 * EACH_REPEAT_BYTES / sizeof(uint16_t), |
| 730 | - {static_cast<uint8_t>((size * (sizeof(float) - 1) * 2) / CONST_128), 1, static_cast<uint8_t>(REPEAT_STRIDE), 1}, | 730 | + {1, 1, REPEAT_STRIDE, 0}, this->rsvdCnt); |
| 731 | - this->rsvdCnt); | ||
| 732 | PipeBarrier<PIPE_V>(); | 731 | PipeBarrier<PIPE_V>(); |
| 733 | Cast( | 732 | Cast( |
| 734 | deviceExpUb[index].template ReinterpretCast<half>(), deviceExpUb[index].template ReinterpretCast<int16_t>(), | 733 | deviceExpUb[index].template ReinterpretCast<half>(), deviceExpUb[index].template ReinterpretCast<int16_t>(), |
| @@ -0,0 +1,3 @@ | |||
| 1 | +# aclnnHansEncode | ||
| 2 | + | ||
| 3 | +本文档内容正按全新接口模板整改中,将陆续上线,如需使用该接口请访问昇腾社区[《算子库接口》](https://hiascend.com/document/redirect/CannCommunityOplist)对应的aclnnHansEncode章节。 | ||
| @@ -287,10 +287,11 @@ class HansEncode { | |||
| 287 | GatherMask(this->inputExpHalfLocal, this->inputHalfLocal, expPattern, false, 0, expParams, this->rsvdCnt); | 287 | GatherMask(this->inputExpHalfLocal, this->inputHalfLocal, expPattern, false, 0, expParams, this->rsvdCnt); |
| 288 | PipeBarrier<PIPE_V>(); | 288 | PipeBarrier<PIPE_V>(); |
| 289 | if (this->dtypeSize == sizeof(float)) { | 289 | if (this->dtypeSize == sizeof(float)) { |
| 290 | - GatherMask(this->inputHalfLocal.template ReinterpretCast<uint16_t>(), | 290 | + GatherMask( |
| 291 | - this->inputHalfLocal.template ReinterpretCast<uint16_t>(), | 291 | + this->inputHalfLocal.template ReinterpretCast<uint16_t>(), |
| 292 | - this->fp32MantissaMaskLocal.template ReinterpretCast<uint16_t>(), | 292 | + this->inputHalfLocal.template ReinterpretCast<uint16_t>(), |
| 293 | - false, 0, {static_cast<uint8_t>(expParams.repeatTimes), 1, 8, 1}, this->rsvdCnt); | 293 | + this->fp32MantissaMaskLocal.template ReinterpretCast<uint16_t>(), true, |
| 294 | + expParams.repeatTimes * EACH_REPEAT_BYTES / sizeof(uint16_t), {1, 1, 8, 0}, this->rsvdCnt); | ||
| 294 | } else { | 295 | } else { |
| 295 | GatherMask(this->inputHalfLocal, this->inputHalfLocal, 1, false, 0, expParams, this->rsvdCnt); | 296 | GatherMask(this->inputHalfLocal, this->inputHalfLocal, 1, false, 0, expParams, this->rsvdCnt); |
| 296 | } | 297 | } |
| @@ -346,10 +347,11 @@ class HansEncode { | |||
| 346 | CompareScalar(stateBufferBitCmpLocal.ReinterpretCast<uint8_t>(), overflowCheckLocal.ReinterpretCast<float>(), | 347 | CompareScalar(stateBufferBitCmpLocal.ReinterpretCast<uint8_t>(), overflowCheckLocal.ReinterpretCast<float>(), |
| 347 | this->const16Float, AscendC::CMPMODE::GT, EACH_LOOOP_REPEAT_TIMES); | 348 | this->const16Float, AscendC::CMPMODE::GT, EACH_LOOOP_REPEAT_TIMES); |
| 348 | PipeBarrier<PIPE_V>(); | 349 | PipeBarrier<PIPE_V>(); |
| 349 | - GatherMask(this->inputHalfLocal.template ReinterpretCast<uint32_t>(), | 350 | + GatherMask( |
| 350 | - overflowCheckLocal.template ReinterpretCast<uint32_t>(), | 351 | + this->inputHalfLocal.template ReinterpretCast<uint32_t>(), |
| 351 | - stateBufferBitCmpLocal.template ReinterpretCast<uint32_t>(), | 352 | + overflowCheckLocal.template ReinterpretCast<uint32_t>(), |
| 352 | - false, 0, {1, 1, 8, 1}, this->rsvdCnt); | 353 | + stateBufferBitCmpLocal.template ReinterpretCast<uint32_t>(), true, EACH_REPEAT_BYTES / sizeof(uint32_t), |
| 354 | + {1, 1, 8, 0}, this->rsvdCnt); | ||
| 353 | uint64_t compressBufferOffset = AscendC::AscendCUtils::GetRsvdCnt(); | 355 | uint64_t compressBufferOffset = AscendC::AscendCUtils::GetRsvdCnt(); |
| 354 | this->bufOffset -= (EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t) + EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t)); | 356 | this->bufOffset -= (EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t) + EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t)); |
| 355 | if ((currentCoreOutputAcculmulateSize + EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t) + | 357 | if ((currentCoreOutputAcculmulateSize + EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t) + |
| @@ -410,18 +412,20 @@ class HansEncode { | |||
| 410 | PipeBarrier<PIPE_V>(); | 412 | PipeBarrier<PIPE_V>(); |
| 411 | Brcb(overflowFlagBrcbLocal, overflowFlagLocal, BYTE_BIT_NUM, {1, 8}); | 413 | Brcb(overflowFlagBrcbLocal, overflowFlagLocal, BYTE_BIT_NUM, {1, 8}); |
| 412 | PipeBarrier<PIPE_V>(); | 414 | PipeBarrier<PIPE_V>(); |
| 413 | - GatherMask(overflowFlagBrcbReduceLocal.template ReinterpretCast<uint32_t>(), | 415 | + GatherMask( |
| 414 | - overflowFlagBrcbLocal.template ReinterpretCast<uint32_t>(), | 416 | + overflowFlagBrcbReduceLocal.template ReinterpretCast<uint32_t>(), |
| 415 | - this->reduceLowBlockMaskLocal.template ReinterpretCast<uint32_t>(), | 417 | + overflowFlagBrcbLocal.template ReinterpretCast<uint32_t>(), |
| 416 | - false, 0, {8, 1, 8, 1}, this->rsvdCnt); | 418 | + this->reduceLowBlockMaskLocal.template ReinterpretCast<uint32_t>(), true, CONST_8 * EACH_REPEAT_BYTES / sizeof(uint32_t), |
| 419 | + {1, 1, 8, 0}, this->rsvdCnt); | ||
| 417 | PipeBarrier<PIPE_V>(); | 420 | PipeBarrier<PIPE_V>(); |
| 418 | Muls(overflowFlagBrcbReduceLocal, overflowFlagBrcbReduceLocal, (int32_t)INT32_LOW_16_BIT_MASK, | 421 | Muls(overflowFlagBrcbReduceLocal, overflowFlagBrcbReduceLocal, (int32_t)INT32_LOW_16_BIT_MASK, |
| 419 | EACH_LOOOP_PROCESS_NUM / (sizeof(uint16_t) * BYTE_BIT_NUM)); | 422 | EACH_LOOOP_PROCESS_NUM / (sizeof(uint16_t) * BYTE_BIT_NUM)); |
| 420 | PipeBarrier<PIPE_V>(); | 423 | PipeBarrier<PIPE_V>(); |
| 421 | - GatherMask(this->outputDeviceLocal.template ReinterpretCast<uint16_t>(), | 424 | + GatherMask( |
| 422 | - this->stateBufferLocal.template ReinterpretCast<uint16_t>(), | 425 | + this->outputDeviceLocal.template ReinterpretCast<uint16_t>(), |
| 423 | - overflowFlagBrcbReduceLocal.template ReinterpretCast<uint16_t>(), | 426 | + this->stateBufferLocal.template ReinterpretCast<uint16_t>(), |
| 424 | - false, 0, {static_cast<uint8_t>(processDataLength / BLOCK_SIZE), 1, 8, 1}, this->rsvdCnt); | 427 | + overflowFlagBrcbReduceLocal.template ReinterpretCast<uint16_t>(), true, |
| 428 | + processDataLength / BLOCK_SIZE * EACH_REPEAT_BYTES / sizeof(uint16_t), {1, 1, 8, 0}, this->rsvdCnt); | ||
| 425 | this->compressBufferOffset = AscendC::AscendCUtils::GetRsvdCnt(); | 429 | this->compressBufferOffset = AscendC::AscendCUtils::GetRsvdCnt(); |
| 426 | GatherOutput(overflowFlagBrcbLocal, overflowFlagLocal, processDataLength); | 430 | GatherOutput(overflowFlagBrcbLocal, overflowFlagLocal, processDataLength); |
| 427 | this->bufOffset -= (BLOCK_SIZE * sizeof(int32_t) + EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t) + | 431 | this->bufOffset -= (BLOCK_SIZE * sizeof(int32_t) + EACH_LOOOP_REPEAT_TIMES * sizeof(int32_t) + |
| @@ -626,10 +630,11 @@ class HansEncode { | |||
| 626 | this->rsvdCnt); | 630 | this->rsvdCnt); |
| 627 | PipeBarrier<PIPE_V>(); | 631 | PipeBarrier<PIPE_V>(); |
| 628 | if (this->dtypeSize == sizeof(int32_t)) { | 632 | if (this->dtypeSize == sizeof(int32_t)) { |
| 629 | - GatherMask(inputReaminMantissaFp16LocalList[index].template ReinterpretCast<uint16_t>(), | 633 | + GatherMask( |
| 630 | - inputReaminFp16LocalList[index].template ReinterpretCast<uint16_t>(), | 634 | + inputReaminMantissaFp16LocalList[index].template ReinterpretCast<uint16_t>(), |
| 631 | - this->fp32MantissaMaskLocal.template ReinterpretCast<uint16_t>(), | 635 | + inputReaminFp16LocalList[index].template ReinterpretCast<uint16_t>(), |
| 632 | - false, 0, {static_cast<uint8_t>(expParams.repeatTimes), 1, 8, 1}, this->rsvdCnt); | 636 | + this->fp32MantissaMaskLocal.template ReinterpretCast<uint16_t>(), true, expParams.repeatTimes * EACH_REPEAT_BYTES / sizeof(uint16_t), |
| 637 | + {1, 1, 8, 0}, this->rsvdCnt); | ||
| 633 | } else { | 638 | } else { |
| 634 | GatherMask(inputReaminMantissaFp16LocalList[index], inputReaminFp16LocalList[index], 1, false, 0, expParams, | 639 | GatherMask(inputReaminMantissaFp16LocalList[index], inputReaminFp16LocalList[index], 1, false, 0, expParams, |
| 635 | this->rsvdCnt); | 640 | this->rsvdCnt); |
| @@ -141,10 +141,11 @@ protected: | |||
| 141 | compareLocalInt.template ReinterpretCast<uint8_t>(), this->inputLocal, scalarValue, CMPMODE::EQ, | 141 | compareLocalInt.template ReinterpretCast<uint8_t>(), this->inputLocal, scalarValue, CMPMODE::EQ, |
| 142 | computeLength); | 142 | computeLength); |
| 143 | PipeBarrier<PIPE_V>(); | 143 | PipeBarrier<PIPE_V>(); |
| 144 | - GatherMask(this->expLocal.template ReinterpretCast<intType>(), | 144 | + GatherMask( |
| 145 | - this->inputLocal.template ReinterpretCast<intType>(), | 145 | + this->expLocal.template ReinterpretCast<intType>(), |
| 146 | - compareLocalInt.template ReinterpretCast<intType>(), | 146 | + this->inputLocal.template ReinterpretCast<intType>(), |
| 147 | - false, 0, {static_cast<uint8_t>(repeatTimes), 1, 8, 1}, this->rsvdCnt); | 147 | + compareLocalInt.template ReinterpretCast<intType>(), true, repeatTimes * EACH_REPEAT_BYTES / sizeof(intType), |
| 148 | + {1, 1, 8, 0}, this->rsvdCnt); | ||
| 148 | rsvdCnt = AscendC::AscendCUtils::GetRsvdCnt(); | 149 | rsvdCnt = AscendC::AscendCUtils::GetRsvdCnt(); |
| 149 | PipeBarrier<PIPE_V>(); | 150 | PipeBarrier<PIPE_V>(); |
| 150 | SetFlag<HardEvent::V_S>(eventVS); | 151 | SetFlag<HardEvent::V_S>(eventVS); |