已合并
DynamicQuant 字面常量修改 #8346
dongfei创建于 8月6日
DynamicQuant 字面常量修改 #8346
已合并
共 1 个文件变更+20-10
| @@ -75,6 +75,16 @@ constexpr uint32_t PER_CHANNEL_N_BASE_SIZE = 64; | |||
| 75 | constexpr uint32_t PER_CHANNEL_RESERVED_FACTOR = 8; | 75 | constexpr uint32_t PER_CHANNEL_RESERVED_FACTOR = 8; |
| 76 | // perchannel float buffer 数量:col_max、col_min、scale、offset | 76 | // perchannel float buffer 数量:col_max、col_min、scale、offset |
| 77 | constexpr uint32_t PER_CHANNEL_FLOAT_BUF_NUM = 4; | 77 | constexpr uint32_t PER_CHANNEL_FLOAT_BUF_NUM = 4; |
| 78 | +// row 对齐到 16 字节 | ||
| 79 | +constexpr uint32_t ROW_ALIGN_SIZE = 16; | ||
| 80 | +// UB 队列平滑 buffer 系数 | ||
| 81 | +constexpr uint32_t SMOOTH_QUEUE_FACTOR = 2; | ||
| 82 | +// UB 队列主 buffer 系数 | ||
| 83 | +constexpr uint32_t MAIN_QUEUE_FACTOR = 4; | ||
| 84 | +// INT4 偶数对齐位掩码 | ||
| 85 | +constexpr uint32_t EVEN_ALIGN_MASK = 1; | ||
| 86 | +// batch mode 调度模式 | ||
| 87 | +constexpr uint32_t BATCH_SCHEDULE_MODE = 1; | ||
| 78 | 88 | ||
| 79 | constexpr float HIFLOAT8_MAX_VALUE = 32768.0; | 89 | constexpr float HIFLOAT8_MAX_VALUE = 32768.0; |
| 80 | constexpr float FLT_EPSILON = 1e-6f; | 90 | constexpr float FLT_EPSILON = 1e-6f; |
| @@ -540,7 +550,7 @@ void DynamicQuantRegbaseTiling::CalculateCoreNum(const gert::TilingContext* cont | |||
| 540 | void DynamicQuantRegbaseTiling::CalculateTilingData() | 550 | void DynamicQuantRegbaseTiling::CalculateTilingData() |
| 541 | { | 551 | { |
| 542 | // 每个row的元素数量对齐16 | 552 | // 每个row的元素数量对齐16 |
| 543 | - uint32_t alignedRowLen = AlignUp<16>(rowLen); | 553 | + uint32_t alignedRowLen = AlignUp<ROW_ALIGN_SIZE>(rowLen); |
| 544 | uint64_t maxUseUbSize = ubSize - RESERVED_LENGTH; | 554 | uint64_t maxUseUbSize = ubSize - RESERVED_LENGTH; |
| 545 | uint32_t smoothBuffer = (hasSmooth ? 1UL : 0UL); | 555 | uint32_t smoothBuffer = (hasSmooth ? 1UL : 0UL); |
| 546 | uint32_t offsetBuffer = 1UL; | 556 | uint32_t offsetBuffer = 1UL; |
| @@ -562,9 +572,9 @@ void DynamicQuantRegbaseTiling::CalculateTilingData() | |||
| 562 | CalculateTilingForPertenLargeMulticore(maxUseUbSize, smoothBuffer); | 572 | CalculateTilingForPertenLargeMulticore(maxUseUbSize, smoothBuffer); |
| 563 | return; | 573 | return; |
| 564 | } | 574 | } |
| 565 | - uint64_t calcLargeBuf = 2UL * (static_cast<uint64_t>(smoothBuffer) * 2UL + | 575 | + uint64_t calcLargeBuf = DOUBLE * (static_cast<uint64_t>(smoothBuffer) * SMOOTH_QUEUE_FACTOR + |
| 566 | - 4UL); // for inQueue,outQueue&smoothQueue DB | 576 | + MAIN_QUEUE_FACTOR); // for inQueue,outQueue&smoothQueue DB |
| 567 | - maxUseUbSize -= RESERVED_LENGTH; // for scaleQueue DB | 577 | + maxUseUbSize -= RESERVED_LENGTH; // for scaleQueue DB |
| 568 | useDb = true; | 578 | useDb = true; |
| 569 | innerLoopEle = static_cast<uint32_t>(maxUseUbSize) / static_cast<uint32_t>(calcLargeBuf) / FLOAT_NUM_ONE_RPT * | 579 | innerLoopEle = static_cast<uint32_t>(maxUseUbSize) / static_cast<uint32_t>(calcLargeBuf) / FLOAT_NUM_ONE_RPT * |
| 570 | FLOAT_NUM_ONE_RPT; | 580 | FLOAT_NUM_ONE_RPT; |
| @@ -720,8 +730,8 @@ void DynamicQuantRegbaseTiling::CalculateTilingForPertenLargeMulticore(uint64_t | |||
| 720 | 730 | ||
| 721 | // 每个 token 分配的核数(至少 2,由前置条件 rowNum <= vectorCoreNum/2 保证) | 731 | // 每个 token 分配的核数(至少 2,由前置条件 rowNum <= vectorCoreNum/2 保证) |
| 722 | uint32_t coreNumPerToken = vectorCoreNum / static_cast<uint32_t>(rowNum); | 732 | uint32_t coreNumPerToken = vectorCoreNum / static_cast<uint32_t>(rowNum); |
| 723 | - if (coreNumPerToken < 2) { | 733 | + if (coreNumPerToken < DOUBLE) { |
| 724 | - coreNumPerToken = 2; | 734 | + coreNumPerToken = DOUBLE; |
| 725 | } | 735 | } |
| 726 | 736 | ||
| 727 | // 每个核处理的 rowLen 切片大小 | 737 | // 每个核处理的 rowLen 切片大小 |
| @@ -730,13 +740,13 @@ void DynamicQuantRegbaseTiling::CalculateTilingForPertenLargeMulticore(uint64_t | |||
| 730 | 740 | ||
| 731 | if (yDtype == ge::DT_INT4) { | 741 | if (yDtype == ge::DT_INT4) { |
| 732 | if ((elePerTailCore & 1) != 0) { | 742 | if ((elePerTailCore & 1) != 0) { |
| 733 | - elePerTailCore = elePerTailCore & ~1U; | 743 | + elePerTailCore = elePerTailCore & ~EVEN_ALIGN_MASK; |
| 734 | } | 744 | } |
| 735 | uint32_t remaining = rowLen - elePerTailCore * coreNumPerToken; | 745 | uint32_t remaining = rowLen - elePerTailCore * coreNumPerToken; |
| 736 | if (remaining == 0) { | 746 | if (remaining == 0) { |
| 737 | elePerHeadCore = elePerTailCore; | 747 | elePerHeadCore = elePerTailCore; |
| 738 | } else { | 748 | } else { |
| 739 | - elePerHeadCore = elePerTailCore + 2; | 749 | + elePerHeadCore = elePerTailCore + DOUBLE; |
| 740 | } | 750 | } |
| 741 | } | 751 | } |
| 742 | 752 | ||
| @@ -752,7 +762,7 @@ void DynamicQuantRegbaseTiling::CalculateTilingForPertenLargeMulticore(uint64_t | |||
| 752 | coreNum = coreNumPerToken * static_cast<uint32_t>(rowNum); | 762 | coreNum = coreNumPerToken * static_cast<uint32_t>(rowNum); |
| 753 | 763 | ||
| 754 | // UB 内循环切分参数 | 764 | // UB 内循环切分参数 |
| 755 | - uint64_t calcBuf = 2UL * (static_cast<uint64_t>(smoothBuffer) * 2UL + 4UL); | 765 | + uint64_t calcBuf = DOUBLE * (static_cast<uint64_t>(smoothBuffer) * SMOOTH_QUEUE_FACTOR + MAIN_QUEUE_FACTOR); |
| 756 | uint64_t calcMaxUb = maxUseUbSize; | 766 | uint64_t calcMaxUb = maxUseUbSize; |
| 757 | calcMaxUb -= RESERVED_LENGTH; | 767 | calcMaxUb -= RESERVED_LENGTH; |
| 758 | 768 | ||
| @@ -908,7 +918,7 @@ ge::graphStatus DynamicQuantRegbaseTiling::RunFusionKernelTiling(gert::TilingCon | |||
| 908 | if (quantMode_ == TPL_PER_TENSOR_FULL_LOAD || quantMode_ == TPL_PER_TENSOR_LARGE_SHAPE || | 918 | if (quantMode_ == TPL_PER_TENSOR_FULL_LOAD || quantMode_ == TPL_PER_TENSOR_LARGE_SHAPE || |
| 909 | quantMode_ == TPL_MOE_PER_TENSOR_FULL_LOAD || quantMode_ == TPL_MOE_PER_TENSOR_LARGE_SHAPE || | 919 | quantMode_ == TPL_MOE_PER_TENSOR_FULL_LOAD || quantMode_ == TPL_MOE_PER_TENSOR_LARGE_SHAPE || |
| 910 | quantMode_ == TPL_PERTEN_LARGE_MULTICORE) { | 920 | quantMode_ == TPL_PERTEN_LARGE_MULTICORE) { |
| 911 | - context->SetScheduleMode(1); // 设置为batch mode模式,所有核同时启动 | 921 | + context->SetScheduleMode(BATCH_SCHEDULE_MODE); // 设置为batch mode模式,所有核同时启动 |
| 912 | } | 922 | } |
| 913 | context->SetBlockDim(coreNum); | 923 | context->SetBlockDim(coreNum); |
| 914 | return ge::GRAPH_SUCCESS; | 924 | return ge::GRAPH_SUCCESS; |