Merged
feat(operation): Optimize TopK RadixSelect #5239
刘奕哲Add on Aug 3
feat(operation): Optimize TopK RadixSelect #5239
Merged
Merged fromCreeeeper/pyptoperf-topkintocann/pyptomaster
Total: 6 files changed+452-371
| @@ -44,7 +44,7 @@ topk(input: Tensor, k: int, dim: Optional[int] = None, largest: bool = True, alg | |||
| 44 | 44 | ||
| 45 | 1. 只支持对尾轴进行topk操作; | 45 | 1. 只支持对尾轴进行topk操作; |
| 46 | 2. 选用MERGE_SORT算法时,TileShape尾轴需要小于22KB\(TileShape\[-1\]\*4 < 22KB\); | 46 | 2. 选用MERGE_SORT算法时,TileShape尾轴需要小于22KB\(TileShape\[-1\]\*4 < 22KB\); |
| 47 | -3. 选用RADIX_SELECT算法时,记TileShape尾轴为tile,tile对齐到128记为tileAlign,则需要临时空间:26\*tileAlign,临时空间加上输入输出的tile块不能超过UB大小; | 47 | +3. 选用RADIX_SELECT算法时,记TileShape的次尾轴为tileH(若不存在则为1),尾轴为tileW,tileW对齐到128记为tileAlign,则需要临时空间:26\*tileH\*tileAlign,临时空间加上输入输出的tile块不能超过UB大小; |
| 48 | 4. 选用RADIX_SELECT算法时,尾轴不可切分,TileShape\[-1\]必须大于等于input.shape\[-1\]; | 48 | 4. 选用RADIX_SELECT算法时,尾轴不可切分,TileShape\[-1\]必须大于等于input.shape\[-1\]; |
| 49 | 5. k <= TileShape\[-1\] && k <= input.shape\[-1\]; | 49 | 5. k <= TileShape\[-1\] && k <= input.shape\[-1\]; |
| 50 | 6. RADIX_SELECT算法在不同型号的支持度: | 50 | 6. RADIX_SELECT算法在不同型号的支持度: |
| @@ -486,6 +486,9 @@ void TiledTopKRadixSelect(Function& function, const TileShape& tileShape, size_t | |||
| 486 | auto valueTile = valueResult->View(function, input.tileInfo.shape, input.tileInfo.offset); | 486 | auto valueTile = valueResult->View(function, input.tileInfo.shape, input.tileInfo.offset); |
| 487 | auto indexTile = indexResult->View(function, input.tileInfo.shape, input.tileInfo.offset); | 487 | auto indexTile = indexResult->View(function, input.tileInfo.shape, input.tileInfo.offset); |
| 488 | std::vector<int64_t> tmpShape = {static_cast<int64_t>(AlignUp(lastDim, NUM_VALUE_128) * NUM_VALUE_26)}; | 488 | std::vector<int64_t> tmpShape = {static_cast<int64_t>(AlignUp(lastDim, NUM_VALUE_128) * NUM_VALUE_26)}; |
| 489 | + if (cur > 0) { | ||
| 490 | + tmpShape[0] *= input.tileInfo.shape[cur - 1]; | ||
| 491 | + } | ||
| 489 | auto tempTensor = std::make_shared<LogicalTensor>(function, DataType::DT_UINT8, tmpShape); | 492 | auto tempTensor = std::make_shared<LogicalTensor>(function, DataType::DT_UINT8, tmpShape); |
| 490 | auto& newOp = function.AddOperation(Opcode::OP_RADIX_SELECT, {inputTile}, {valueTile, indexTile, tempTensor}); | 493 | auto& newOp = function.AddOperation(Opcode::OP_RADIX_SELECT, {inputTile}, {valueTile, indexTile, tempTensor}); |
| 491 | newOp.SetAttribute(TOPK_AXIS, axis); | 494 | newOp.SetAttribute(TOPK_AXIS, axis); |
| @@ -40,94 +40,71 @@ TILEOP void RadixSelectCalcB1(VAL value, IDX index, TMP tmp, SRC src) | |||
| 40 | constexpr bool isFloat = !(std::is_same_v<SrcDType, uint8_t> || std::is_same_v<SrcDType, int8_t>); | 40 | constexpr bool isFloat = !(std::is_same_v<SrcDType, uint8_t> || std::is_same_v<SrcDType, int8_t>); |
| 41 | // Define memory address | 41 | // Define memory address |
| 42 | size_t point = tmp.GetAddr(); | 42 | size_t point = tmp.GetAddr(); |
| 43 | - size_t srcMaskAddr = DefineWorkSpace<uint16_t>(point, AlignUp(srcTileW, 128)); | 43 | + size_t srcMaskAddr = DefineWorkSpace<uint16_t, srcTileH * srcMaskShape>(point); |
| 44 | size_t sortTmpAddr_ = point; | 44 | size_t sortTmpAddr_ = point; |
| 45 | - size_t srcTwiddleInAddr = DefineWorkSpace<SrcDType>(point, srcTileW); | 45 | + size_t srcTwiddleInAddr = DefineWorkSpace<SrcDType, srcTileH * srcTileW>(point); |
| 46 | - size_t cmpAddr = DefineWorkSpace<uint8_t>(point, AlignUp(cmpSize, 32)); | 46 | + size_t cmpAddr = DefineWorkSpace<uint8_t, srcTileH * cmpAlign>(point); |
| 47 | size_t srcTmpAddr = cmpAddr; | 47 | size_t srcTmpAddr = cmpAddr; |
| 48 | - size_t highAddr = DefineWorkSpace<uint8_t>(point, 32); | 48 | + size_t highAddr = DefineWorkSpace<uint8_t, srcTileH * 32>(point); |
| 49 | - size_t selectCountGTAddr = DefineWorkSpace<uint32_t>(point, 8); | 49 | + size_t selectCountGTAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 50 | size_t rowMinAddr = selectCountGTAddr; | 50 | size_t rowMinAddr = selectCountGTAddr; |
| 51 | - size_t selectCountEQAddr = DefineWorkSpace<uint32_t>(point, 8); | 51 | + size_t selectCountEQAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 52 | size_t gatherAddr = selectCountEQAddr; | 52 | size_t gatherAddr = selectCountEQAddr; |
| 53 | - size_t uselessAddr = DefineWorkSpace<uint32_t>(point, 8); | 53 | + size_t uselessAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 54 | - size_t histogramAddr = DefineWorkSpace<uint32_t>(point, 256); | 54 | + size_t histogramAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); |
| 55 | - size_t histogramTmpAddr = DefineWorkSpace<uint32_t>(point, 256); | 55 | + size_t histogramTmpAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); |
| 56 | point = histogramAddr; | 56 | point = histogramAddr; |
| 57 | - size_t selectGTAddr = DefineWorkSpace<uint32_t>(point, kAlign); | 57 | + size_t selectGTAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); |
| 58 | - size_t selectEQAddr = DefineWorkSpace<uint32_t>(point, kAlign); | 58 | + size_t selectEQAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); |
| 59 | - point = sortTmpAddr_; | 59 | + PTO_RS_SORT_ADDR_DEFINE(16); |
| 60 | - size_t sortTmpAddr = DefineWorkSpace<uint16_t>(point, kAlign); | ||
| 61 | - PTO_RS_SORT_ADDR_DEFINE; | ||
| 62 | // Define tile | 60 | // Define tile |
| 63 | PTO_RS_COMMON_TILE_DEFINE; | 61 | PTO_RS_COMMON_TILE_DEFINE; |
| 64 | - auto twiddleIntTile = DefineTile<ConvIntType>(1, srcShape[4], srcTwiddleInAddr); | 62 | + auto srcMaskUInt8KTile = DefineTile<uint8_t, srcTileH, srcMaskShape>(srcShape[3], k, srcMaskAddr); |
| 65 | - auto twiddleUIntTile = DefineTile<ConvUIntType>(1, srcShape[4], srcTwiddleInAddr); | 63 | + auto srcMaskInt8KTile = DefineTile<int8_t, srcTileH, srcMaskShape>(srcShape[3], k, srcMaskAddr); |
| 66 | - auto srcMaskUInt8KTile = DefineTile<uint8_t>(1, k, srcMaskAddr); | 64 | + auto srcMaskUInt16Tile = DefineTile<uint16_t, srcTileH, srcMaskShape>(srcShape[3], srcShape[4], srcMaskAddr); |
| 67 | - auto srcMaskInt8KTile = DefineTile<int8_t>(1, k, srcMaskAddr); | 65 | + auto srcMaskInt16Tile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], srcShape[4], srcMaskAddr); |
| 68 | - auto srcMaskUInt16Tile = DefineTile<uint16_t>(1, srcShape[4], srcMaskAddr); | 66 | + auto srcMaskInt16KTile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], k, srcMaskAddr); |
| 69 | - auto srcMaskInt16Tile = DefineTile<int16_t>(1, srcShape[4], srcMaskAddr); | 67 | + auto srcMaskInt16MaxTile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], srcMaskShape, srcMaskAddr); |
| 70 | - auto srcMaskInt16KTile = DefineTile<int16_t>(1, k, srcMaskAddr); | 68 | + auto srcTmpInt16KTile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], k, srcTmpAddr); |
| 71 | - auto srcMaskInt16MaxTile = DefineTile<int16_t>(1, AlignUp(srcTileW, 128), srcMaskAddr); | 69 | + auto highTile = DefineTile<uint8_t, srcTileH, 32, true>(1, srcShape[3], highAddr); |
| 72 | - auto srcTmpInt16KTile = DefineTile<int16_t>(1, k, srcTmpAddr); | 70 | + auto highIntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, highAddr); |
| 73 | - auto highTile = DefineTile<uint8_t, 32, true>(1, 1, highAddr); | 71 | + auto highUInt16Tile = DefineTile<uint16_t, srcTileH>(srcShape[3], 16, highAddr); |
| 74 | - auto highIntTile = DefineTile<int32_t>(1, 8, highAddr); | 72 | + auto histogramUInt32Tile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr); |
| 75 | - auto highUInt16Tile = DefineTile<uint16_t>(1, 16, highAddr); | 73 | + auto histogramTmpUInt32Tile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, histogramTmpAddr); |
| 76 | - auto histogramUInt32Tile = DefineTile<uint32_t>(1, 256, histogramAddr); | 74 | + auto histogramTmpInt32Tile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramTmpAddr); |
| 77 | - auto histogramTmpUInt32Tile = DefineTile<uint32_t>(1, 256, histogramTmpAddr); | ||
| 78 | - auto histogramTmpInt32Tile = DefineTile<int32_t>(1, 256, histogramTmpAddr); | ||
| 79 | PTO_RS_SORT_TILE_DEFINE(16); | 75 | PTO_RS_SORT_TILE_DEFINE(16); |
| 80 | 76 | ||
| 81 | for (LoopVar n0Index = 0; n0Index < srcShape[0]; ++n0Index) { | 77 | for (LoopVar n0Index = 0; n0Index < srcShape[0]; ++n0Index) { |
| 82 | for (LoopVar n1Index = 0; n1Index < srcShape[1]; ++n1Index) { | 78 | for (LoopVar n1Index = 0; n1Index < srcShape[1]; ++n1Index) { |
| 83 | for (LoopVar n2Index = 0; n2Index < srcShape[2]; ++n2Index) { | 79 | for (LoopVar n2Index = 0; n2Index < srcShape[2]; ++n2Index) { |
| 84 | - for (LoopVar n3Index = 0; n3Index < srcShape[3]; ++n3Index) { | 80 | + RadixSelectBatchAssign(src, value, index, n0Index, n1Index, n2Index, srcStride, valStride, idxStride, |
| 85 | - uint64_t srcAddr = src.GetAddr() + (n0Index * srcStride[0] + n1Index * srcStride[1] + | 81 | + srcTypeSize, idxTypeSize, srcIntTile, valIntTile, idxTile); |
| 86 | - n2Index * srcStride[2] + n3Index * srcStride[3]) * | 82 | + RadixSelectTwiddle<isLargest, true, isUInt, isFloat, SrcDType>(twiddleIntTile, srcIntTile, uselessTile, |
| 87 | - srcTypeSize; | 83 | + uselessTile, uselessTile); |
| 88 | - uint64_t valAddr = value.GetAddr() + (n0Index * valStride[0] + n1Index * valStride[1] + | 84 | + pto::TEXPANDS(srcMaskInt16MaxTile, static_cast<int16_t>(0)); |
| 89 | - n2Index * valStride[2] + n3Index * valStride[3]) * | 85 | + pto::TEXPANDS(highUInt16Tile, 0); |
| 90 | - srcTypeSize; | 86 | + pto::TCVT(srcMaskUInt16Tile, twiddleUIntTile, pto::RoundMode::CAST_TRUNC); |
| 91 | - uint64_t idxAddr = index.GetAddr() + (n0Index * idxStride[0] + n1Index * idxStride[1] + | 87 | + RadixSelectHistogram<pto::HistByte::BYTE_0>(histogramUInt32Tile, srcMaskUInt16Tile, highTile); |
| 92 | - n2Index * idxStride[2] + n3Index * idxStride[3]) * | 88 | + pto::TCMPS(cmpTile, histogramUInt32Tile, static_cast<uint32_t>(srcShape[4] - k), pto::CmpMode::GT); |
| 93 | - idxTypeSize; | 89 | + RadixSelectTCI(histogramTmpUInt32Tile); |
| 94 | - pto::TASSIGN(srcIntTile, srcAddr); | 90 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 95 | - pto::TASSIGN(valIntTile, valAddr); | 91 | + pto::TROWMIN(highIntTile, histogramTmpInt32Tile, uselessTile); |
| 96 | - pto::TASSIGN(idxTile, idxAddr); | 92 | + RadixSelectFinalSelect(selectInt32GTTile, selectInt32EQTile, srcMaskInt16Tile, highUInt16Tile, |
| 97 | - RadixSelectTwiddle<isLargest, true, isUInt, isFloat, SrcDType>( | 93 | + selectCountUInt32GTTile, selectCountUInt32EQTile, idxTile, uselessTile); |
| 98 | - twiddleIntTile, srcIntTile, uselessTile, uselessTile, uselessTile); | 94 | + RadixSelectGather(srcTmpInt16KTile, srcMaskInt16Tile, idxTile, uselessTile); |
| 99 | - pto::TEXPANDS(srcMaskInt16MaxTile, static_cast<int16_t>(0)); | 95 | + pto::TEXPANDS(srcMaskInt16MaxTile, 0x7fff); |
| 100 | - pto::TCVT(srcMaskUInt16Tile, twiddleUIntTile, pto::RoundMode::CAST_TRUNC); | 96 | + pto::TMOV(srcMaskInt16KTile, srcTmpInt16KTile); |
| 101 | - pto::TEXPANDS(highTile, static_cast<uint8_t>(0)); | 97 | + RadixSelectSortPrepare(sortTempInt16MaxTile, number0UInt16Tile, number1UInt16Tile, number2UInt16Tile, |
| 102 | - pto::THISTOGRAM<pto::HistByte::BYTE_0>(histogramUInt32Tile, srcMaskUInt16Tile, highTile); | 98 | + number3UInt16Tile); |
| 103 | - pto::TCMPS(cmpTile, histogramUInt32Tile, static_cast<uint32_t>(srcShape[4] - k), pto::CmpMode::GT); | 99 | + RadixSelectSortTwoBit<0, 8>(srcMaskInt16KTile, srcMaskInt16KTile, indexInt32Tile, sortTempInt16KTile, |
| 104 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | 100 | + sortTempInt16KTile, uselessTile, select1Int32Tile, select2Int32Tile, |
| 105 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | 101 | + select3Int32Tile, cnt1UInt32Tile, cnt2UInt32Tile, cnt3UInt32Tile, |
| 106 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | 102 | + number0UInt16Tile, number1UInt16Tile, number2UInt16Tile, number3UInt16Tile); |
| 107 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | 103 | + RadixSelectGather(select1Int32Tile, idxTile, indexInt32Tile, uselessTile); |
| 108 | - pto::TEXPANDS(gatherIntTile, 0); | 104 | + pto::TMOV(idxTile, select1Int32Tile); |
| 109 | - pto::TGATHER(highIntTile, rowMinTile, gatherIntTile, uselessTile); | 105 | + pto::TCVT(srcMaskUInt8KTile, srcMaskInt16KTile, pto::RoundMode::CAST_TRUNC); |
| 110 | - RadixSelectGather<pto::CmpMode::GT>(selectInt32GTTile, srcMaskInt16Tile, highUInt16Tile, | 106 | + RadixSelectTwiddle<isLargest, false, isUInt, isFloat, SrcDType>(valIntTile, srcMaskInt8KTile, |
| 111 | - selectCountUInt32GTTile, uselessTile); | 107 | + uselessTile, uselessTile, uselessTile); |
| 112 | - RadixSelectGather<pto::CmpMode::EQ>(selectInt32EQTile, srcMaskInt16Tile, highUInt16Tile, | ||
| 113 | - selectCountUInt32EQTile, uselessTile); | ||
| 114 | - pto::TCONCAT(idxTile, selectInt32GTTile, selectInt32EQTile, selectCountUInt32GTTile, | ||
| 115 | - selectCountUInt32EQTile); | ||
| 116 | - pto::TGATHER(srcTmpInt16KTile, srcMaskInt16Tile, idxTile, uselessTile); | ||
| 117 | - pto::TEXPANDS(srcMaskInt16MaxTile, 0); | ||
| 118 | - pto::TMOV(srcMaskInt16KTile, srcTmpInt16KTile); | ||
| 119 | - RadixSelectSortPrepare(sortTempInt16MaxTile, number0UInt16Tile, number1UInt16Tile, | ||
| 120 | - number2UInt16Tile, number3UInt16Tile); | ||
| 121 | - RadixSelectSortTwoBit<0, 8>( | ||
| 122 | - srcMaskInt16KTile, indexInt32Tile, sortTempInt16KTile, sortTempInt16KTile, uselessTile, | ||
| 123 | - select1Int32Tile, select2Int32Tile, select3Int32Tile, cnt1UInt32Tile, cnt2UInt32Tile, | ||
| 124 | - cnt3UInt32Tile, number0UInt16Tile, number1UInt16Tile, number2UInt16Tile, number3UInt16Tile); | ||
| 125 | - pto::TGATHER(select1Int32Tile, idxTile, indexInt32Tile, uselessTile); | ||
| 126 | - pto::TMOV(idxTile, select1Int32Tile); | ||
| 127 | - pto::TCVT(srcMaskUInt8KTile, srcMaskInt16KTile, pto::RoundMode::CAST_TRUNC); | ||
| 128 | - RadixSelectTwiddle<isLargest, false, isUInt, isFloat, SrcDType>( | ||
| 129 | - valIntTile, srcMaskInt8KTile, uselessTile, uselessTile, uselessTile); | ||
| 130 | - } | ||
| 131 | } | 108 | } |
| 132 | } | 109 | } |
| 133 | } | 110 | } |
| @@ -31,6 +31,7 @@ selectCountEQAddr | 8 uint32 | and gatherAddr | |||
| 31 | uselessAddr | 8 uint32 | | 31 | uselessAddr | 8 uint32 | |
| 32 | histogramAddr | 256 uint32 | selectGTAddr | kAlign uint32 | | 32 | histogramAddr | 256 uint32 | selectGTAddr | kAlign uint32 | |
| 33 | histogramTmpAddr | 256 uint32 | selectEQAddr | kAlign uint32 | | 33 | histogramTmpAddr | 256 uint32 | selectEQAddr | kAlign uint32 | |
| 34 | +tciAddr | 256 uint32 | | ||
| 34 | */ | 35 | */ |
| 35 | template <int k, bool isLargest, typename VAL, typename IDX, typename TMP, typename SRC> | 36 | template <int k, bool isLargest, typename VAL, typename IDX, typename TMP, typename SRC> |
| 36 | TILEOP void RadixSelectCalcB2(VAL value, IDX index, TMP tmp, SRC src) | 37 | TILEOP void RadixSelectCalcB2(VAL value, IDX index, TMP tmp, SRC src) |
| @@ -40,107 +41,84 @@ TILEOP void RadixSelectCalcB2(VAL value, IDX index, TMP tmp, SRC src) | |||
| 40 | constexpr bool isFloat = !(std::is_same_v<SrcDType, uint16_t> || std::is_same_v<SrcDType, int16_t>); | 41 | constexpr bool isFloat = !(std::is_same_v<SrcDType, uint16_t> || std::is_same_v<SrcDType, int16_t>); |
| 41 | // Define memory address | 42 | // Define memory address |
| 42 | size_t point = tmp.GetAddr(); | 43 | size_t point = tmp.GetAddr(); |
| 43 | - size_t srcMaskAddr = DefineWorkSpace<uint16_t>(point, AlignUp(srcTileW, 128)); | 44 | + size_t srcMaskAddr = DefineWorkSpace<uint16_t, srcTileH * srcMaskShape>(point); |
| 44 | size_t sortTmpAddr_ = point; | 45 | size_t sortTmpAddr_ = point; |
| 45 | - size_t srcTwiddleInAddr = DefineWorkSpace<SrcDType>(point, srcTileW); | 46 | + size_t srcTwiddleInAddr = DefineWorkSpace<SrcDType, srcTileH * srcTileW>(point); |
| 46 | - size_t cmpAddr = DefineWorkSpace<uint8_t>(point, AlignUp(cmpSize, 32)); | 47 | + size_t cmpAddr = DefineWorkSpace<uint8_t, srcTileH * cmpAlign>(point); |
| 47 | - size_t highAddr = DefineWorkSpace<uint8_t>(point, 32); | 48 | + size_t highAddr = DefineWorkSpace<uint8_t, srcTileH * 32>(point); |
| 48 | - size_t selectCountGTAddr = DefineWorkSpace<uint32_t>(point, 8); | 49 | + size_t selectCountGTAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 49 | size_t rowMinAddr = selectCountGTAddr; | 50 | size_t rowMinAddr = selectCountGTAddr; |
| 50 | - size_t selectCountEQAddr = DefineWorkSpace<uint32_t>(point, 8); | 51 | + size_t selectCountEQAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 51 | size_t gatherAddr = selectCountEQAddr; | 52 | size_t gatherAddr = selectCountEQAddr; |
| 52 | - size_t uselessAddr = DefineWorkSpace<uint32_t>(point, 8); | 53 | + size_t uselessAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 53 | - size_t histogramAddr = DefineWorkSpace<uint32_t>(point, 256); | 54 | + size_t histogramAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); |
| 54 | - size_t histogramTmpAddr = DefineWorkSpace<uint32_t>(point, 256); | 55 | + size_t histogramTmpAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); |
| 56 | + size_t tciAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); | ||
| 55 | point = histogramAddr; | 57 | point = histogramAddr; |
| 56 | - size_t selectGTAddr = DefineWorkSpace<uint32_t>(point, kAlign); | 58 | + size_t selectGTAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); |
| 57 | - size_t selectEQAddr = DefineWorkSpace<uint32_t>(point, kAlign); | 59 | + size_t selectEQAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); |
| 58 | - point = sortTmpAddr_; | 60 | + PTO_RS_SORT_ADDR_DEFINE(16); |
| 59 | - size_t sortTmpAddr = DefineWorkSpace<uint16_t>(point, kAlign); | ||
| 60 | - PTO_RS_SORT_ADDR_DEFINE; | ||
| 61 | // Define tile | 61 | // Define tile |
| 62 | PTO_RS_COMMON_TILE_DEFINE; | 62 | PTO_RS_COMMON_TILE_DEFINE; |
| 63 | - auto twiddleIntTile = DefineTile<ConvIntType>(1, srcShape[4], srcTwiddleInAddr); | 63 | + auto twiddleIntKTile = DefineTile<ConvIntType, srcTileH, srcTileW>(srcShape[3], k, srcTwiddleInAddr); |
| 64 | - auto twiddleIntKTile = DefineTile<ConvIntType>(1, k, srcTwiddleInAddr); | 64 | + auto srcMaskInt16Tile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], srcShape[4], srcMaskAddr); |
| 65 | - auto twiddleUIntTile = DefineTile<ConvUIntType>(1, srcShape[4], srcTwiddleInAddr); | 65 | + auto srcMaskInt16MaxTile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], srcMaskShape, srcMaskAddr); |
| 66 | - auto srcMaskInt16Tile = DefineTile<int16_t>(1, srcShape[4], srcMaskAddr); | 66 | + auto srcMaskInt16KTile = DefineTile<int16_t, srcTileH, srcMaskShape>(srcShape[3], k, srcMaskAddr); |
| 67 | - auto srcMaskInt16MaxTile = DefineTile<int16_t>(1, AlignUp(srcTileW, 128), srcMaskAddr); | 67 | + auto highTile = DefineTile<uint8_t, srcTileH, 32, true>(1, srcShape[3], highAddr); |
| 68 | - auto srcMaskInt16KTile = DefineTile<int16_t>(1, k, srcMaskAddr); | 68 | + auto highIntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, highAddr); |
| 69 | - auto highTile = DefineTile<uint8_t, 32, true>(1, 1, highAddr); | 69 | + auto highUInt16Tile = DefineTile<uint16_t, srcTileH>(srcShape[3], 16, highAddr); |
| 70 | - auto highIntTile = DefineTile<int32_t>(1, 8, highAddr); | 70 | + auto histogramUInt32Tile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr); |
| 71 | - auto highUInt16Tile = DefineTile<uint16_t>(1, 16, highAddr); | 71 | + auto histogramInt32Tile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr); |
| 72 | - auto histogramUInt32Tile = DefineTile<uint32_t>(1, 256, histogramAddr); | 72 | + auto histogramInt32PreTile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr - 32); |
| 73 | - auto histogramInt32Tile = DefineTile<int32_t>(1, 256, histogramAddr); | 73 | + auto histogramTmpUInt32Tile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, histogramTmpAddr); |
| 74 | - auto histogramTmpUInt32Tile = DefineTile<uint32_t>(1, 256, histogramTmpAddr); | 74 | + auto histogramTmpInt32Tile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramTmpAddr); |
| 75 | - auto histogramTmpInt32Tile = DefineTile<int32_t>(1, 256, histogramTmpAddr); | 75 | + auto tciTile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, tciAddr); |
| 76 | PTO_RS_SORT_TILE_DEFINE(16); | 76 | PTO_RS_SORT_TILE_DEFINE(16); |
| 77 | 77 | ||
| 78 | for (LoopVar n0Index = 0; n0Index < srcShape[0]; ++n0Index) { | 78 | for (LoopVar n0Index = 0; n0Index < srcShape[0]; ++n0Index) { |
| 79 | for (LoopVar n1Index = 0; n1Index < srcShape[1]; ++n1Index) { | 79 | for (LoopVar n1Index = 0; n1Index < srcShape[1]; ++n1Index) { |
| 80 | for (LoopVar n2Index = 0; n2Index < srcShape[2]; ++n2Index) { | 80 | for (LoopVar n2Index = 0; n2Index < srcShape[2]; ++n2Index) { |
| 81 | - for (LoopVar n3Index = 0; n3Index < srcShape[3]; ++n3Index) { | 81 | + RadixSelectBatchAssign(src, value, index, n0Index, n1Index, n2Index, srcStride, valStride, idxStride, |
| 82 | - uint64_t srcAddr = src.GetAddr() + (n0Index * srcStride[0] + n1Index * srcStride[1] + | 82 | + srcTypeSize, idxTypeSize, srcIntTile, valIntTile, idxTile); |
| 83 | - n2Index * srcStride[2] + n3Index * srcStride[3]) * | 83 | + RadixSelectTCI(tciTile); |
| 84 | - srcTypeSize; | 84 | + RadixSelectTwiddle<isLargest, true, isUInt, isFloat, SrcDType>(twiddleIntTile, srcIntTile, |
| 85 | - uint64_t valAddr = value.GetAddr() + (n0Index * valStride[0] + n1Index * valStride[1] + | 85 | + srcMaskInt16Tile, cmpTile, uselessTile); |
| 86 | - n2Index * valStride[2] + n3Index * valStride[3]) * | 86 | + RadixSelectHistogram<pto::HistByte::BYTE_1>(histogramUInt32Tile, twiddleUIntTile, highTile); |
| 87 | - srcTypeSize; | 87 | + pto::TCMPS(cmpTile, histogramUInt32Tile, static_cast<uint32_t>(srcShape[4] - k), pto::CmpMode::GT); |
| 88 | - uint64_t idxAddr = index.GetAddr() + (n0Index * idxStride[0] + n1Index * idxStride[1] + | 88 | + pto::TMOV(histogramTmpUInt32Tile, tciTile); |
| 89 | - n2Index * idxStride[2] + n3Index * idxStride[3]) * | 89 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 90 | - idxTypeSize; | 90 | + pto::TEXPANDS(highIntTile, 0); |
| 91 | - pto::TASSIGN(srcIntTile, srcAddr); | 91 | + pto::TROWMIN(highIntTile, histogramTmpInt32Tile, uselessTile); |
| 92 | - pto::TASSIGN(valIntTile, valAddr); | 92 | + pto::TCMPS(cmpTile, highIntTile, 0, pto::CmpMode::NE); |
| 93 | - pto::TASSIGN(idxTile, idxAddr); | 93 | + pto::TADDS(rowMinTile, highIntTile, 7); |
| 94 | - RadixSelectTwiddle<isLargest, true, isUInt, isFloat, SrcDType>( | 94 | + RadixSelectGather(gatherIntTile, histogramInt32PreTile, rowMinTile, uselessTile); |
| 95 | - twiddleIntTile, srcIntTile, srcMaskInt16Tile, cmpTile, uselessTile); | 95 | + pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); |
| 96 | - pto::TEXPANDS(highTile, static_cast<uint8_t>(0)); | 96 | + pto::TEXPANDS(rowMinTile, static_cast<int32_t>(srcShape[4] - k)); |
| 97 | - pto::THISTOGRAM<pto::HistByte::BYTE_1>(histogramUInt32Tile, twiddleUIntTile, highTile); | 97 | + pto::TSUB(rowMinTile, rowMinTile, gatherIntTile); |
| 98 | - pto::TCMPS(cmpTile, histogramUInt32Tile, static_cast<uint32_t>(srcShape[4] - k), pto::CmpMode::GT); | 98 | + RadixSelectHistogram<pto::HistByte::BYTE_0>(histogramUInt32Tile, twiddleUIntTile, highTile); |
| 99 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | 99 | + RadixSelectCmps<pto::CmpMode::GT>(cmpTile, histogramInt32Tile, rowMinTile); |
| 100 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | 100 | + pto::TMOV(histogramTmpUInt32Tile, tciTile); |
| 101 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | 101 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 102 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | 102 | + pto::TEXPANDS(rowMinTile, 0); |
| 103 | - pto::TEXPANDS(gatherIntTile, 0); | 103 | + pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); |
| 104 | - pto::TGATHER(highIntTile, rowMinTile, gatherIntTile, uselessTile); | 104 | + pto::TSHLS(highIntTile, highIntTile, 8); |
| 105 | - pto::TCMPS(cmpTile, highIntTile, 0, pto::CmpMode::NE); | 105 | + pto::TADD(highIntTile, highIntTile, rowMinTile); |
| 106 | - pto::TSUBS(rowMinTile, rowMinTile, 1); | 106 | + pto::TEXPANDS(srcMaskInt16MaxTile, static_cast<int16_t>(0)); |
| 107 | - pto::TSELS(rowMinTile, cmpTile, rowMinTile, uselessTile, 0); | 107 | + pto::TMOV(srcMaskInt16Tile, twiddleIntTile); |
| 108 | - pto::TGATHER(gatherIntTile, rowMinTile, gatherIntTile, uselessTile); | 108 | + RadixSelectFinalSelect(selectInt32GTTile, selectInt32EQTile, srcMaskInt16Tile, highUInt16Tile, |
| 109 | - pto::TGATHER(gatherIntTile, histogramInt32Tile, gatherIntTile, uselessTile); | 109 | + selectCountUInt32GTTile, selectCountUInt32EQTile, idxTile, uselessTile); |
| 110 | - pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); | 110 | + pto::TEXPANDS(srcMaskInt16MaxTile, 0x7fff); |
| 111 | - pto::TEXPANDS(rowMinTile, static_cast<int32_t>(srcShape[4] - k)); | 111 | + RadixSelectGather(srcMaskInt16KTile, twiddleIntTile, idxTile, uselessTile); |
| 112 | - pto::TSUB(rowMinTile, rowMinTile, gatherIntTile); | 112 | + RadixSelectSortPrepare(sortTempInt16MaxTile, number0UInt16Tile, number1UInt16Tile, number2UInt16Tile, |
| 113 | - pto::THISTOGRAM<pto::HistByte::BYTE_0>(histogramUInt32Tile, twiddleUIntTile, highTile); | 113 | + number3UInt16Tile); |
| 114 | - pto::TCMPS(cmpTile, histogramInt32Tile, rowMinTile, pto::CmpMode::GT); | 114 | + RadixSelectSortTwoBit<0, 16>( |
| 115 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | 115 | + srcMaskInt16KTile, srcMaskInt16KTile, indexInt32Tile, sortTempInt16KTile, sortTempInt16KTile, |
| 116 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | 116 | + uselessTile, select1Int32Tile, select2Int32Tile, select3Int32Tile, cnt1UInt32Tile, cnt2UInt32Tile, |
| 117 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | 117 | + cnt3UInt32Tile, number0UInt16Tile, number1UInt16Tile, number2UInt16Tile, number3UInt16Tile); |
| 118 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | 118 | + RadixSelectGather(select1Int32Tile, idxTile, indexInt32Tile, uselessTile); |
| 119 | - pto::TEXPANDS(gatherIntTile, 0); | 119 | + pto::TMOV(idxTile, select1Int32Tile); |
| 120 | - pto::TGATHER(rowMinTile, rowMinTile, gatherIntTile, uselessTile); | 120 | + RadixSelectTwiddle<isLargest, false, isUInt, isFloat, SrcDType>(valIntTile, srcMaskInt16KTile, |
| 121 | - pto::TSHLS(highIntTile, highIntTile, 8); | 121 | + twiddleIntKTile, cmpTile, uselessTile); |
| 122 | - pto::TADD(highIntTile, highIntTile, rowMinTile); | ||
| 123 | - pto::TEXPANDS(srcMaskInt16MaxTile, static_cast<int16_t>(0)); | ||
| 124 | - pto::TMOV(srcMaskInt16Tile, twiddleIntTile); | ||
| 125 | - RadixSelectGather<pto::CmpMode::GT>(selectInt32GTTile, srcMaskInt16Tile, highUInt16Tile, | ||
| 126 | - selectCountUInt32GTTile, uselessTile); | ||
| 127 | - RadixSelectGather<pto::CmpMode::EQ>(selectInt32EQTile, srcMaskInt16Tile, highUInt16Tile, | ||
| 128 | - selectCountUInt32EQTile, uselessTile); | ||
| 129 | - pto::TCONCAT(idxTile, selectInt32GTTile, selectInt32EQTile, selectCountUInt32GTTile, | ||
| 130 | - selectCountUInt32EQTile); | ||
| 131 | - pto::TEXPANDS(srcMaskInt16MaxTile, static_cast<int16_t>(0)); | ||
| 132 | - pto::TGATHER(srcMaskInt16KTile, twiddleIntTile, idxTile, uselessTile); | ||
| 133 | - RadixSelectSortPrepare(sortTempInt16MaxTile, number0UInt16Tile, number1UInt16Tile, | ||
| 134 | - number2UInt16Tile, number3UInt16Tile); | ||
| 135 | - RadixSelectSortTwoBit<0, 16>( | ||
| 136 | - srcMaskInt16KTile, indexInt32Tile, sortTempInt16KTile, sortTempInt16KTile, uselessTile, | ||
| 137 | - select1Int32Tile, select2Int32Tile, select3Int32Tile, cnt1UInt32Tile, cnt2UInt32Tile, | ||
| 138 | - cnt3UInt32Tile, number0UInt16Tile, number1UInt16Tile, number2UInt16Tile, number3UInt16Tile); | ||
| 139 | - pto::TGATHER(select1Int32Tile, idxTile, indexInt32Tile, uselessTile); | ||
| 140 | - pto::TMOV(idxTile, select1Int32Tile); | ||
| 141 | - RadixSelectTwiddle<isLargest, false, isUInt, isFloat, SrcDType>( | ||
| 142 | - valIntTile, srcMaskInt16KTile, twiddleIntKTile, cmpTile, uselessTile); | ||
| 143 | - } | ||
| 144 | } | 122 | } |
| 145 | } | 123 | } |
| 146 | } | 124 | } |
| @@ -36,6 +36,7 @@ tmpAddr | 8 uint32 | | |||
| 36 | uselessAddr | 8 uint32 | | 36 | uselessAddr | 8 uint32 | |
| 37 | histogramAddr | 256 uint32 | selectGTAddr | kAlign uint32 | | 37 | histogramAddr | 256 uint32 | selectGTAddr | kAlign uint32 | |
| 38 | histogramTmpAddr | 256 uint32 | selectEQAddr | kAlign uint32 | | 38 | histogramTmpAddr | 256 uint32 | selectEQAddr | kAlign uint32 | |
| 39 | +tciAddr | 256 uint32 | | ||
| 39 | */ | 40 | */ |
| 40 | template <int k, bool isLargest, typename VAL, typename IDX, typename TMP, typename SRC> | 41 | template <int k, bool isLargest, typename VAL, typename IDX, typename TMP, typename SRC> |
| 41 | TILEOP void RadixSelectCalcB4(VAL value, IDX index, TMP tmp, SRC src) | 42 | TILEOP void RadixSelectCalcB4(VAL value, IDX index, TMP tmp, SRC src) |
| @@ -45,156 +46,123 @@ TILEOP void RadixSelectCalcB4(VAL value, IDX index, TMP tmp, SRC src) | |||
| 45 | constexpr bool isFloat = !(std::is_same_v<SrcDType, uint32_t> || std::is_same_v<SrcDType, int32_t>); | 46 | constexpr bool isFloat = !(std::is_same_v<SrcDType, uint32_t> || std::is_same_v<SrcDType, int32_t>); |
| 46 | // Define memory address | 47 | // Define memory address |
| 47 | size_t point = tmp.GetAddr(); | 48 | size_t point = tmp.GetAddr(); |
| 48 | - size_t srcMaskAddr = DefineWorkSpace<uint32_t>(point, AlignUp(srcTileW, 128)); | 49 | + size_t srcMaskAddr = DefineWorkSpace<uint32_t, srcTileH * srcMaskShape>(point); |
| 49 | size_t sortTmpAddr_ = point; | 50 | size_t sortTmpAddr_ = point; |
| 50 | - size_t srcTwiddleInAddr = DefineWorkSpace<SrcDType>(point, srcTileW); | 51 | + size_t srcTwiddleInAddr = DefineWorkSpace<SrcDType, srcTileH * srcTileW>(point); |
| 51 | - size_t cmpAddr = DefineWorkSpace<uint8_t>(point, AlignUp(cmpSize, 32)); | 52 | + size_t cmpAddr = DefineWorkSpace<uint8_t, srcTileH * cmpAlign>(point); |
| 52 | - size_t high1Addr = DefineWorkSpace<uint8_t>(point, 32); | 53 | + size_t high1Addr = DefineWorkSpace<uint8_t, srcTileH * 32>(point); |
| 53 | - size_t high2Addr = DefineWorkSpace<uint8_t>(point, 32); | 54 | + size_t high2Addr = DefineWorkSpace<uint8_t, srcTileH * 32>(point); |
| 54 | - size_t high3Addr = DefineWorkSpace<uint8_t>(point, 32); | 55 | + size_t high3Addr = DefineWorkSpace<uint8_t, srcTileH * 32>(point); |
| 55 | - size_t selectCountGTAddr = DefineWorkSpace<uint32_t>(point, 8); | 56 | + size_t selectCountGTAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 56 | size_t rowMinAddr = selectCountGTAddr; | 57 | size_t rowMinAddr = selectCountGTAddr; |
| 57 | - size_t selectCountEQAddr = DefineWorkSpace<uint32_t>(point, 8); | 58 | + size_t selectCountEQAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 58 | size_t gatherAddr = selectCountEQAddr; | 59 | size_t gatherAddr = selectCountEQAddr; |
| 59 | - size_t remindKAddr = DefineWorkSpace<uint32_t>(point, 8); | 60 | + size_t remindKAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 60 | - size_t kthValueAddr = DefineWorkSpace<uint32_t>(point, 8); | 61 | + size_t kthValueAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 61 | - size_t tmpAddr = DefineWorkSpace<uint32_t>(point, 8); | 62 | + size_t tmpAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 62 | - size_t uselessAddr = DefineWorkSpace<uint32_t>(point, 8); | 63 | + size_t uselessAddr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); |
| 63 | - size_t histogramAddr = DefineWorkSpace<uint32_t>(point, 256); | 64 | + size_t histogramAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); |
| 64 | - size_t histogramTmpAddr = DefineWorkSpace<uint32_t>(point, 256); | 65 | + size_t histogramTmpAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); |
| 66 | + size_t tciAddr = DefineWorkSpace<uint32_t, srcTileH * 256>(point); | ||
| 65 | point = histogramAddr; | 67 | point = histogramAddr; |
| 66 | - size_t selectGTAddr = DefineWorkSpace<uint32_t>(point, kAlign); | 68 | + size_t selectGTAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); |
| 67 | - size_t selectEQAddr = DefineWorkSpace<uint32_t>(point, kAlign); | 69 | + size_t selectEQAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); |
| 68 | - point = sortTmpAddr_; | 70 | + PTO_RS_SORT_ADDR_DEFINE(32); |
| 69 | - size_t sortTmpAddr = DefineWorkSpace<uint32_t>(point, kAlign); | ||
| 70 | - PTO_RS_SORT_ADDR_DEFINE; | ||
| 71 | // Define tile | 71 | // Define tile |
| 72 | PTO_RS_COMMON_TILE_DEFINE; | 72 | PTO_RS_COMMON_TILE_DEFINE; |
| 73 | - auto twiddleIntTile = DefineTile<ConvIntType>(1, srcShape[4], srcTwiddleInAddr); | 73 | + auto twiddleIntKTile = DefineTile<ConvIntType, srcTileH, srcTileW>(srcShape[3], k, srcTwiddleInAddr); |
| 74 | - auto twiddleIntKTile = DefineTile<ConvIntType>(1, k, srcTwiddleInAddr); | 74 | + auto srcMaskInt32Tile = DefineTile<int32_t, srcTileH, srcMaskShape>(srcShape[3], srcShape[4], srcMaskAddr); |
| 75 | - auto twiddleUIntTile = DefineTile<ConvUIntType, 32>(1, srcShape[4], srcTwiddleInAddr); | 75 | + auto srcMaskInt32MaxTile = DefineTile<int32_t, srcTileH, srcMaskShape>(srcShape[3], srcMaskShape, srcMaskAddr); |
| 76 | - auto srcMaskInt32Tile = DefineTile<int32_t>(1, srcShape[4], srcMaskAddr); | 76 | + auto srcMaskInt32KTile = DefineTile<int32_t, srcTileH, srcMaskShape>(srcShape[3], k, srcMaskAddr); |
| 77 | - auto srcMaskInt32MaxTile = DefineTile<int32_t>(1, AlignUp(srcTileW, 128), srcMaskAddr); | 77 | + auto srcMaskUInt32KTile = DefineTile<uint32_t, srcTileH, srcMaskShape>(srcShape[3], k, srcMaskAddr); |
| 78 | - auto srcMaskInt32KTile = DefineTile<int32_t>(1, k, srcMaskAddr); | 78 | + auto high1Tile = DefineTile<uint8_t, 1>(1, 1, high1Addr); |
| 79 | - auto high1Tile = DefineTile<uint8_t, 32, false, 1>(1, 1, high1Addr); | 79 | + auto high2Tile = DefineTile<uint8_t, 2>(2, 1, high1Addr); |
| 80 | - auto high2Tile = DefineTile<uint8_t, 32, false, 2>(2, 1, high1Addr); | 80 | + auto high3Tile = DefineTile<uint8_t, 3>(3, 1, high1Addr); |
| 81 | - auto high3Tile = DefineTile<uint8_t, 32, false, 3>(3, 1, high1Addr); | 81 | + auto high1IntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, high1Addr); |
| 82 | - auto high1IntTile = DefineTile<int32_t>(1, 8, high1Addr); | 82 | + auto high2IntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, high2Addr); |
| 83 | - auto high2IntTile = DefineTile<int32_t>(1, 8, high2Addr); | 83 | + auto high3IntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, high3Addr); |
| 84 | - auto high3IntTile = DefineTile<int32_t>(1, 8, high3Addr); | 84 | + auto hignMaxIntTile = DefineTile<int32_t, srcTileH * 3>(srcShape[3] * 3, 8, high1Addr); |
| 85 | - auto histogramUInt32Tile = DefineTile<uint32_t>(1, 256, histogramAddr); | 85 | + auto histogramUInt32Tile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr); |
| 86 | - auto histogramInt32Tile = DefineTile<int32_t>(1, 256, histogramAddr); | 86 | + auto histogramInt32Tile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr); |
| 87 | - auto histogramTmpUInt32Tile = DefineTile<uint32_t>(1, 256, histogramTmpAddr); | 87 | + auto histogramInt32PreTile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramAddr - 32); |
| 88 | - auto histogramTmpInt32Tile = DefineTile<int32_t>(1, 256, histogramTmpAddr); | 88 | + auto histogramTmpUInt32Tile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, histogramTmpAddr); |
| 89 | - auto remindKTile = DefineTile<int32_t>(1, 8, remindKAddr); | 89 | + auto histogramTmpInt32Tile = DefineTile<int32_t, srcTileH, 256>(srcShape[3], 256, histogramTmpAddr); |
| 90 | - auto kthValueIntTile = DefineTile<int32_t>(1, 8, kthValueAddr); | 90 | + auto remindKTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, remindKAddr); |
| 91 | - auto kthValueUInt32Tile = DefineTile<uint32_t>(1, 8, kthValueAddr); | 91 | + auto kthValueIntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, kthValueAddr); |
| 92 | - auto tmpIntTile = DefineTile<int32_t>(1, 8, tmpAddr); | 92 | + auto kthValueUInt32Tile = DefineTile<uint32_t, srcTileH>(srcShape[3], 8, kthValueAddr); |
| 93 | - auto sortTempUInt32KTile = DefineTile<uint32_t>(1, k, sortTmpAddr); | 93 | + auto tmpIntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, tmpAddr); |
| 94 | + auto sortTempUInt32KTile = DefineTile<uint32_t, srcTileH, kAlign>(srcShape[3], k, sortTmpAddr); | ||
| 95 | + auto tciTile = DefineTile<uint32_t, srcTileH, 256>(srcShape[3], 256, tciAddr); | ||
| 94 | PTO_RS_SORT_TILE_DEFINE(32); | 96 | PTO_RS_SORT_TILE_DEFINE(32); |
| 95 | 97 | ||
| 96 | for (LoopVar n0Index = 0; n0Index < srcShape[0]; ++n0Index) { | 98 | for (LoopVar n0Index = 0; n0Index < srcShape[0]; ++n0Index) { |
| 97 | for (LoopVar n1Index = 0; n1Index < srcShape[1]; ++n1Index) { | 99 | for (LoopVar n1Index = 0; n1Index < srcShape[1]; ++n1Index) { |
| 98 | for (LoopVar n2Index = 0; n2Index < srcShape[2]; ++n2Index) { | 100 | for (LoopVar n2Index = 0; n2Index < srcShape[2]; ++n2Index) { |
| 99 | - for (LoopVar n3Index = 0; n3Index < srcShape[3]; ++n3Index) { | 101 | + RadixSelectBatchAssign(src, value, index, n0Index, n1Index, n2Index, srcStride, valStride, idxStride, |
| 100 | - uint64_t srcAddr = src.GetAddr() + (n0Index * srcStride[0] + n1Index * srcStride[1] + | 102 | + srcTypeSize, idxTypeSize, srcIntTile, valIntTile, idxTile); |
| 101 | - n2Index * srcStride[2] + n3Index * srcStride[3]) * | 103 | + RadixSelectTCI(tciTile); |
| 102 | - srcTypeSize; | 104 | + RadixSelectTwiddle<isLargest, true, isUInt, isFloat, SrcDType>(twiddleIntTile, srcIntTile, |
| 103 | - uint64_t valAddr = value.GetAddr() + (n0Index * valStride[0] + n1Index * valStride[1] + | 105 | + srcMaskInt32Tile, cmpTile, uselessTile); |
| 104 | - n2Index * valStride[2] + n3Index * valStride[3]) * | 106 | + pto::TEXPANDS(kthValueIntTile, static_cast<int32_t>(0)); |
| 105 | - srcTypeSize; | 107 | + pto::TEXPANDS(hignMaxIntTile, 0); |
| 106 | - uint64_t idxAddr = index.GetAddr() + (n0Index * idxStride[0] + n1Index * idxStride[1] + | 108 | + RadixSelectHistogramB4<pto::HistByte::BYTE_3>(histogramUInt32Tile, twiddleUIntTile, high1Tile); |
| 107 | - n2Index * idxStride[2] + n3Index * idxStride[3]) * | 109 | + pto::TEXPANDS(remindKTile, static_cast<int32_t>(srcShape[4] - k)); |
| 108 | - idxTypeSize; | 110 | + pto::TCMPS(cmpTile, histogramInt32Tile, static_cast<uint32_t>(srcShape[4] - k), pto::CmpMode::GT); |
| 109 | - pto::TASSIGN(srcIntTile, srcAddr); | 111 | + pto::TMOV(histogramTmpUInt32Tile, tciTile); |
| 110 | - pto::TASSIGN(valIntTile, valAddr); | 112 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 111 | - pto::TASSIGN(idxTile, idxAddr); | 113 | + pto::TROWMIN(high1IntTile, histogramTmpInt32Tile, uselessTile); |
| 112 | - RadixSelectTwiddle<isLargest, true, isUInt, isFloat, SrcDType>( | 114 | + pto::TSHLS(kthValueIntTile, high1IntTile, 24); |
| 113 | - twiddleIntTile, srcIntTile, srcMaskInt32Tile, cmpTile, uselessTile); | 115 | + pto::TCMPS(cmpTile, high1IntTile, 0, pto::CmpMode::NE); |
| 114 | - pto::TEXPANDS(kthValueIntTile, static_cast<int32_t>(0)); | 116 | + pto::TADDS(rowMinTile, high1IntTile, 7); |
| 115 | - pto::TEXPANDS(high1Tile, static_cast<uint8_t>(0)); | 117 | + RadixSelectGather(gatherIntTile, histogramInt32PreTile, rowMinTile, uselessTile); |
| 116 | - pto::THISTOGRAM<pto::HistByte::BYTE_3>(histogramUInt32Tile, twiddleUIntTile, high1Tile); | 118 | + pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); |
| 117 | - pto::TEXPANDS(remindKTile, static_cast<int32_t>(srcShape[4] - k)); | 119 | + pto::TSUB(remindKTile, remindKTile, gatherIntTile); |
| 118 | - pto::TCMPS(cmpTile, histogramInt32Tile, remindKTile, pto::CmpMode::GT); | 120 | + RadixSelectHistogramB4<pto::HistByte::BYTE_2>(histogramUInt32Tile, twiddleUIntTile, high1Tile); |
| 119 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | 121 | + RadixSelectCmps<pto::CmpMode::GT>(cmpTile, histogramInt32Tile, remindKTile); |
| 120 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | 122 | + pto::TMOV(histogramTmpUInt32Tile, tciTile); |
| 121 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | 123 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 122 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | 124 | + pto::TROWMIN(high2IntTile, histogramTmpInt32Tile, uselessTile); |
| 123 | - pto::TEXPANDS(gatherIntTile, 0); | 125 | + pto::TSHLS(tmpIntTile, high2IntTile, 16); |
| 124 | - pto::TGATHER(high1IntTile, rowMinTile, gatherIntTile, uselessTile); | 126 | + pto::TOR(kthValueIntTile, kthValueIntTile, tmpIntTile); |
| 125 | - pto::TSHLS(tmpIntTile, high1IntTile, 24); | 127 | + pto::TCMPS(cmpTile, high2IntTile, 0, pto::CmpMode::NE); |
| 126 | - pto::TOR(kthValueIntTile, kthValueIntTile, tmpIntTile); | 128 | + pto::TADDS(rowMinTile, high2IntTile, 7); |
| 127 | - pto::TCMPS(cmpTile, high1IntTile, 0, pto::CmpMode::NE); | 129 | + RadixSelectGather(gatherIntTile, histogramInt32PreTile, rowMinTile, uselessTile); |
| 128 | - pto::TSUBS(rowMinTile, rowMinTile, 1); | 130 | + pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); |
| 129 | - pto::TSELS(rowMinTile, cmpTile, rowMinTile, uselessTile, 0); | 131 | + pto::TSUB(remindKTile, remindKTile, gatherIntTile); |
| 130 | - pto::TGATHER(gatherIntTile, rowMinTile, gatherIntTile, uselessTile); | 132 | + RadixSelectHistogramB4<pto::HistByte::BYTE_1>(histogramUInt32Tile, twiddleUIntTile, high2Tile); |
| 131 | - pto::TGATHER(gatherIntTile, histogramInt32Tile, gatherIntTile, uselessTile); | 133 | + RadixSelectCmps<pto::CmpMode::GT>(cmpTile, histogramInt32Tile, remindKTile); |
| 132 | - pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); | 134 | + pto::TMOV(histogramTmpUInt32Tile, tciTile); |
| 133 | - pto::TSUB(remindKTile, remindKTile, gatherIntTile); | 135 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 134 | - pto::THISTOGRAM<pto::HistByte::BYTE_2>(histogramUInt32Tile, twiddleUIntTile, high1Tile); | 136 | + pto::TROWMIN(high3IntTile, histogramTmpInt32Tile, uselessTile); |
| 135 | - pto::TCMPS(cmpTile, histogramInt32Tile, remindKTile, pto::CmpMode::GT); | 137 | + pto::TSHLS(tmpIntTile, high3IntTile, 8); |
| 136 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | 138 | + pto::TOR(kthValueIntTile, kthValueIntTile, tmpIntTile); |
| 137 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | 139 | + pto::TCMPS(cmpTile, high3IntTile, 0, pto::CmpMode::NE); |
| 138 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | 140 | + pto::TADDS(rowMinTile, high3IntTile, 7); |
| 139 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | 141 | + RadixSelectGather(gatherIntTile, histogramInt32PreTile, rowMinTile, uselessTile); |
| 140 | - pto::TEXPANDS(gatherIntTile, 0); | 142 | + pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); |
| 141 | - pto::TGATHER(high2IntTile, rowMinTile, gatherIntTile, uselessTile); | 143 | + pto::TSUB(remindKTile, remindKTile, gatherIntTile); |
| 142 | - pto::TSHLS(tmpIntTile, high2IntTile, 16); | 144 | + RadixSelectHistogramB4<pto::HistByte::BYTE_0>(histogramUInt32Tile, twiddleUIntTile, high3Tile); |
| 143 | - pto::TOR(kthValueIntTile, kthValueIntTile, tmpIntTile); | 145 | + RadixSelectCmps<pto::CmpMode::GT>(cmpTile, histogramInt32Tile, remindKTile); |
| 144 | - pto::TCMPS(cmpTile, high2IntTile, 0, pto::CmpMode::NE); | 146 | + pto::TMOV(histogramTmpUInt32Tile, tciTile); |
| 145 | - pto::TSUBS(rowMinTile, rowMinTile, 1); | 147 | + pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); |
| 146 | - pto::TSELS(rowMinTile, cmpTile, rowMinTile, uselessTile, 0); | 148 | + pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); |
| 147 | - pto::TGATHER(gatherIntTile, rowMinTile, gatherIntTile, uselessTile); | 149 | + pto::TOR(kthValueIntTile, kthValueIntTile, rowMinTile); |
| 148 | - pto::TGATHER(gatherIntTile, histogramInt32Tile, gatherIntTile, uselessTile); | 150 | + pto::TEXPANDS(srcMaskInt32MaxTile, static_cast<int32_t>(0)); |
| 149 | - pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); | 151 | + pto::TMOV(srcMaskInt32Tile, twiddleIntTile); |
| 150 | - pto::TSUB(remindKTile, remindKTile, gatherIntTile); | 152 | + RadixSelectFinalSelect(selectInt32GTTile, selectInt32EQTile, twiddleUIntTile, kthValueUInt32Tile, |
| 151 | - pto::THISTOGRAM<pto::HistByte::BYTE_1>(histogramUInt32Tile, twiddleUIntTile, high2Tile); | 153 | + selectCountUInt32GTTile, selectCountUInt32EQTile, idxTile, uselessTile); |
| 152 | - pto::TCMPS(cmpTile, histogramInt32Tile, remindKTile, pto::CmpMode::GT); | 154 | + pto::TEXPANDS(srcMaskInt32MaxTile, 0x7fff); |
| 153 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | 155 | + RadixSelectGather(srcMaskInt32KTile, twiddleIntTile, idxTile, uselessTile); |
| 154 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | 156 | + RadixSelectSortPrepare(sortTempInt32MaxTile, number0UInt32Tile, number1UInt32Tile, number2UInt32Tile, |
| 155 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | 157 | + number3UInt32Tile); |
| 156 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | 158 | + RadixSelectSortTwoBit<0, 32>( |
| 157 | - pto::TEXPANDS(gatherIntTile, 0); | 159 | + srcMaskInt32KTile, srcMaskUInt32KTile, indexInt32Tile, sortTempInt32KTile, sortTempUInt32KTile, |
| 158 | - pto::TGATHER(high3IntTile, rowMinTile, gatherIntTile, uselessTile); | 160 | + uselessTile, select1Int32Tile, select2Int32Tile, select3Int32Tile, cnt1UInt32Tile, cnt2UInt32Tile, |
| 159 | - pto::TSHLS(tmpIntTile, high3IntTile, 8); | 161 | + cnt3UInt32Tile, number0UInt32Tile, number1UInt32Tile, number2UInt32Tile, number3UInt32Tile); |
| 160 | - pto::TOR(kthValueIntTile, kthValueIntTile, tmpIntTile); | 162 | + RadixSelectGather(select1Int32Tile, idxTile, indexInt32Tile, uselessTile); |
| 161 | - pto::TCMPS(cmpTile, high3IntTile, 0, pto::CmpMode::NE); | 163 | + pto::TMOV(idxTile, select1Int32Tile); |
| 162 | - pto::TSUBS(rowMinTile, rowMinTile, 1); | 164 | + RadixSelectTwiddle<isLargest, false, isUInt, isFloat, SrcDType>(valIntTile, srcMaskInt32KTile, |
| 163 | - pto::TSELS(rowMinTile, cmpTile, rowMinTile, uselessTile, 0); | 165 | + twiddleIntKTile, cmpTile, uselessTile); |
| 164 | - pto::TGATHER(gatherIntTile, rowMinTile, gatherIntTile, uselessTile); | ||
| 165 | - pto::TGATHER(gatherIntTile, histogramInt32Tile, gatherIntTile, uselessTile); | ||
| 166 | - pto::TSELS(gatherIntTile, cmpTile, gatherIntTile, uselessTile, 0); | ||
| 167 | - pto::TSUB(remindKTile, remindKTile, gatherIntTile); | ||
| 168 | - pto::THISTOGRAM<pto::HistByte::BYTE_0>(histogramUInt32Tile, twiddleUIntTile, high3Tile); | ||
| 169 | - pto::TCMPS(cmpTile, histogramInt32Tile, remindKTile, pto::CmpMode::GT); | ||
| 170 | - pto::TCI<RSTile<uint32_t>::U, RSTile<uint32_t>::U, uint32_t, 0>( | ||
| 171 | - histogramTmpUInt32Tile, static_cast<uint32_t>(0), histogramTmpUInt32Tile); | ||
| 172 | - pto::TSELS(histogramTmpUInt32Tile, cmpTile, histogramTmpUInt32Tile, uselessTile, 0x7fffffffu); | ||
| 173 | - pto::TROWMIN(rowMinTile, histogramTmpInt32Tile, uselessTile); | ||
| 174 | - pto::TEXPANDS(gatherIntTile, 0); | ||
| 175 | - pto::TGATHER(high2IntTile, rowMinTile, gatherIntTile, uselessTile); | ||
| 176 | - pto::TOR(kthValueIntTile, kthValueIntTile, high2IntTile); | ||
| 177 | - pto::TEXPANDS(srcMaskInt32MaxTile, static_cast<int32_t>(0)); | ||
| 178 | - pto::TMOV(srcMaskInt32Tile, twiddleIntTile); | ||
| 179 | - RadixSelectGather<pto::CmpMode::GT>(selectInt32GTTile, twiddleUIntTile, kthValueUInt32Tile, | ||
| 180 | - selectCountUInt32GTTile, uselessTile); | ||
| 181 | - RadixSelectGather<pto::CmpMode::EQ>(selectInt32EQTile, twiddleUIntTile, kthValueUInt32Tile, | ||
| 182 | - selectCountUInt32EQTile, uselessTile); | ||
| 183 | - pto::TCONCAT(idxTile, selectInt32GTTile, selectInt32EQTile, selectCountUInt32GTTile, | ||
| 184 | - selectCountUInt32EQTile); | ||
| 185 | - pto::TEXPANDS(srcMaskInt32MaxTile, static_cast<int32_t>(0)); | ||
| 186 | - pto::TGATHER(srcMaskInt32KTile, twiddleIntTile, idxTile, uselessTile); | ||
| 187 | - RadixSelectSortPrepare(sortTempInt32MaxTile, number0UInt32Tile, number1UInt32Tile, | ||
| 188 | - number2UInt32Tile, number3UInt32Tile); | ||
| 189 | - RadixSelectSortTwoBit<0, 32>( | ||
| 190 | - srcMaskInt32KTile, indexInt32Tile, sortTempInt32KTile, sortTempUInt32KTile, uselessTile, | ||
| 191 | - select1Int32Tile, select2Int32Tile, select3Int32Tile, cnt1UInt32Tile, cnt2UInt32Tile, | ||
| 192 | - cnt3UInt32Tile, number0UInt32Tile, number1UInt32Tile, number2UInt32Tile, number3UInt32Tile); | ||
| 193 | - pto::TGATHER(select1Int32Tile, idxTile, indexInt32Tile, uselessTile); | ||
| 194 | - pto::TMOV(idxTile, select1Int32Tile); | ||
| 195 | - RadixSelectTwiddle<isLargest, false, isUInt, isFloat, SrcDType>( | ||
| 196 | - valIntTile, srcMaskInt32KTile, twiddleIntKTile, cmpTile, uselessTile); | ||
| 197 | - } | ||
| 198 | } | 166 | } |
| 199 | } | 167 | } |
| 200 | } | 168 | } |
| @@ -57,26 +57,30 @@ struct SignByType { | |||
| 57 | using U = typename IntBySize<sizeof(T)>::T; | 57 | using U = typename IntBySize<sizeof(T)>::T; |
| 58 | static constexpr U value = U(1) << (sizeof(U) * 8 - 1); | 58 | static constexpr U value = U(1) << (sizeof(U) * 8 - 1); |
| 59 | }; | 59 | }; |
| 60 | -template <typename T, size_t tile = 32ULL / sizeof(T), bool isCol = false, size_t other = 1> | 60 | +template <typename T> |
| 61 | +struct RSExchangeTile { | ||
| 62 | + using U = typename pto::Tile<T::Loc, typename T::DType, T::ColStride, T::RowStride, T::BFractal, -1, -1>; | ||
| 63 | +}; | ||
| 64 | +template <typename T, size_t other = 1, size_t tile = 32ULL / sizeof(T), bool isCol = false> | ||
| 61 | struct RSTile { | 65 | struct RSTile { |
| 62 | using U = typename std::conditional_t< | 66 | using U = typename std::conditional_t< |
| 63 | isCol, typename pto::Tile<pto::TileType::Vec, T, tile, other, pto::BLayout::ColMajor, -1, -1>, | 67 | isCol, typename pto::Tile<pto::TileType::Vec, T, tile, other, pto::BLayout::ColMajor, -1, -1>, |
| 64 | typename pto::Tile<pto::TileType::Vec, T, other, tile, pto::BLayout::RowMajor, -1, -1> >; | 68 | typename pto::Tile<pto::TileType::Vec, T, other, tile, pto::BLayout::RowMajor, -1, -1> >; |
| 65 | }; | 69 | }; |
| 66 | -template <typename T, size_t tile = 32ULL / sizeof(T), bool isCol = false, size_t other = 1> | 70 | +template <typename T, size_t other = 1, size_t tile = 32ULL / sizeof(T), bool isCol = false> |
| 67 | __aicore__ inline auto DefineTile(size_t row, size_t col, size_t addr) | 71 | __aicore__ inline auto DefineTile(size_t row, size_t col, size_t addr) |
| 68 | { | 72 | { |
| 69 | - typename RSTile<T, tile, isCol, other>::U t(row, col); | 73 | + typename RSTile<T, other, tile, isCol>::U t(row, col); |
| 70 | pto::TASSIGN(t, addr); | 74 | pto::TASSIGN(t, addr); |
| 71 | return t; | 75 | return t; |
| 72 | } | 76 | } |
| 73 | -template <typename T, size_t tile = 32ULL / sizeof(T), bool isCol = false, size_t other = 1> | 77 | +template <typename T, size_t other = 1, size_t tile = 32ULL / sizeof(T), bool isCol = false> |
| 74 | __aicore__ inline auto DefineTile(size_t row, size_t col) | 78 | __aicore__ inline auto DefineTile(size_t row, size_t col) |
| 75 | { | 79 | { |
| 76 | - return typename RSTile<T, tile, isCol, other>::U(row, col); | 80 | + return typename RSTile<T, other, tile, isCol>::U(row, col); |
| 77 | } | 81 | } |
| 78 | -template <typename T> | 82 | +template <typename T, size_t size> |
| 79 | -__aicore__ inline size_t DefineWorkSpace(size_t& point, size_t size) | 83 | +__aicore__ inline size_t DefineWorkSpace(size_t& point) |
| 80 | { | 84 | { |
| 81 | size_t result = point; | 85 | size_t result = point; |
| 82 | point += size * sizeof(T); | 86 | point += size * sizeof(T); |
| @@ -108,55 +112,202 @@ __aicore__ inline constexpr size_t AlignUp(size_t size, size_t align) | |||
| 108 | using ConvUIntType = typename UIntBySize<srcTypeSize>::T; \ | 112 | using ConvUIntType = typename UIntBySize<srcTypeSize>::T; \ |
| 109 | using ConvIntType = typename IntBySize<srcTypeSize>::T; \ | 113 | using ConvIntType = typename IntBySize<srcTypeSize>::T; \ |
| 110 | constexpr auto srcTileW = TileOp::GetTensorTileShapeDim<SRC, DIM_5TH, MAX_DIMS>(); \ | 114 | constexpr auto srcTileW = TileOp::GetTensorTileShapeDim<SRC, DIM_5TH, MAX_DIMS>(); \ |
| 115 | + constexpr auto srcTileH = TileOp::GetTensorTileShapeDim<SRC, DIM_4TH, MAX_DIMS>(); \ | ||
| 116 | + constexpr auto valTileW = TileOp::GetTensorTileShapeDim<VAL, DIM_5TH, MAX_DIMS>(); \ | ||
| 117 | + constexpr auto idxTileW = TileOp::GetTensorTileShapeDim<IDX, DIM_5TH, MAX_DIMS>(); \ | ||
| 118 | + constexpr auto srcMaskShape = AlignUp(srcTileW, 128); \ | ||
| 111 | constexpr int64_t cmpSize = (srcTileW > 256 ? srcTileW : 256) / 8; \ | 119 | constexpr int64_t cmpSize = (srcTileW > 256 ? srcTileW : 256) / 8; \ |
| 120 | + constexpr auto cmpAlign = AlignUp(cmpSize, 32); \ | ||
| 112 | constexpr auto kAlign = AlignUp(k, 128); \ | 121 | constexpr auto kAlign = AlignUp(k, 128); \ |
| 113 | PTO_RS_GET_SHAPE(srcShape, src); \ | 122 | PTO_RS_GET_SHAPE(srcShape, src); \ |
| 114 | PTO_RS_GET_STRIDE(srcStride, src); \ | 123 | PTO_RS_GET_STRIDE(srcStride, src); \ |
| 115 | PTO_RS_GET_STRIDE(valStride, value); \ | 124 | PTO_RS_GET_STRIDE(valStride, value); \ |
| 116 | PTO_RS_GET_STRIDE(idxStride, index) | 125 | PTO_RS_GET_STRIDE(idxStride, index) |
| 117 | -#define PTO_RS_SORT_ADDR_DEFINE \ | 126 | +#define PTO_RS_SORT_ADDR_DEFINE(type) \ |
| 118 | - size_t number0Addr = DefineWorkSpace<uint16_t>(point, 16); \ | 127 | + point = sortTmpAddr_; \ |
| 119 | - size_t number1Addr = DefineWorkSpace<uint16_t>(point, 16); \ | 128 | + size_t sortTmpAddr = DefineWorkSpace<uint##type##_t, srcTileH * kAlign>(point); \ |
| 120 | - size_t number2Addr = DefineWorkSpace<uint16_t>(point, 16); \ | 129 | + size_t number0Addr = DefineWorkSpace<uint16_t, srcTileH * 16>(point); \ |
| 121 | - size_t number3Addr = DefineWorkSpace<uint16_t>(point, 16); \ | 130 | + size_t number1Addr = DefineWorkSpace<uint16_t, srcTileH * 16>(point); \ |
| 122 | - size_t cnt1Addr = DefineWorkSpace<uint32_t>(point, 8); \ | 131 | + size_t number2Addr = DefineWorkSpace<uint16_t, srcTileH * 16>(point); \ |
| 123 | - size_t cnt2Addr = DefineWorkSpace<uint32_t>(point, 8); \ | 132 | + size_t number3Addr = DefineWorkSpace<uint16_t, srcTileH * 16>(point); \ |
| 124 | - size_t cnt3Addr = DefineWorkSpace<uint32_t>(point, 8); \ | 133 | + size_t cnt1Addr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); \ |
| 125 | - size_t select1Addr = DefineWorkSpace<uint32_t>(point, kAlign); \ | 134 | + size_t cnt2Addr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); \ |
| 126 | - size_t select2Addr = DefineWorkSpace<uint32_t>(point, kAlign); \ | 135 | + size_t cnt3Addr = DefineWorkSpace<uint32_t, srcTileH * 8>(point); \ |
| 127 | - size_t select3Addr = DefineWorkSpace<uint32_t>(point, kAlign); \ | 136 | + size_t select1Addr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); \ |
| 128 | - size_t indexAddr = DefineWorkSpace<uint32_t>(point, kAlign) | 137 | + size_t select2Addr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); \ |
| 129 | -#define PTO_RS_SORT_TILE_DEFINE(type) \ | 138 | + size_t select3Addr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point); \ |
| 130 | - auto sortTempInt##type##KTile = DefineTile<int##type##_t>(1, k, sortTmpAddr); \ | 139 | + size_t indexAddr = DefineWorkSpace<uint32_t, srcTileH * kAlign>(point) |
| 131 | - auto sortTempInt##type##MaxTile = DefineTile<int##type##_t>(1, kAlign, sortTmpAddr); \ | 140 | +#define PTO_RS_SORT_TILE_DEFINE(type) \ |
| 132 | - auto number0UInt##type##Tile = DefineTile<uint##type##_t>(1, 1, number0Addr); \ | 141 | + auto sortTempInt##type##KTile = DefineTile<int##type##_t, srcTileH, kAlign>(srcShape[3], k, sortTmpAddr); \ |
| 133 | - auto number1UInt##type##Tile = DefineTile<uint##type##_t>(1, 1, number1Addr); \ | 142 | + auto sortTempInt##type##MaxTile = DefineTile<int##type##_t, srcTileH, kAlign>(srcShape[3], kAlign, sortTmpAddr); \ |
| 134 | - auto number2UInt##type##Tile = DefineTile<uint##type##_t>(1, 1, number2Addr); \ | 143 | + auto number0UInt##type##Tile = DefineTile<uint##type##_t>(srcShape[3], 256 / type, number0Addr); \ |
| 135 | - auto number3UInt##type##Tile = DefineTile<uint##type##_t>(1, 1, number3Addr); \ | 144 | + auto number1UInt##type##Tile = DefineTile<uint##type##_t>(srcShape[3], 256 / type, number1Addr); \ |
| 136 | - auto cnt1UInt32Tile = DefineTile<uint32_t>(1, 1, cnt1Addr); \ | 145 | + auto number2UInt##type##Tile = DefineTile<uint##type##_t>(srcShape[3], 256 / type, number2Addr); \ |
| 137 | - auto cnt2UInt32Tile = DefineTile<uint32_t>(1, 1, cnt2Addr); \ | 146 | + auto number3UInt##type##Tile = DefineTile<uint##type##_t>(srcShape[3], 256 / type, number3Addr); \ |
| 138 | - auto cnt3UInt32Tile = DefineTile<uint32_t>(1, 1, cnt3Addr); \ | 147 | + auto cnt1UInt32Tile = DefineTile<uint32_t, srcTileH>(srcShape[3], 8, cnt1Addr); \ |
| 139 | - auto select1Int32Tile = DefineTile<int32_t>(1, k, select1Addr); \ | 148 | + auto cnt2UInt32Tile = DefineTile<uint32_t, srcTileH>(srcShape[3], 8, cnt2Addr); \ |
| 140 | - auto select2Int32Tile = DefineTile<int32_t>(1, k, select2Addr); \ | 149 | + auto cnt3UInt32Tile = DefineTile<uint32_t, srcTileH>(srcShape[3], 8, cnt3Addr); \ |
| 141 | - auto select3Int32Tile = DefineTile<int32_t>(1, k, select3Addr); \ | 150 | + auto select1Int32Tile = DefineTile<int32_t, srcTileH, kAlign>(srcShape[3], k, select1Addr); \ |
| 142 | - auto indexInt32Tile = DefineTile<int32_t>(1, k, indexAddr) | 151 | + auto select2Int32Tile = DefineTile<int32_t, srcTileH, kAlign>(srcShape[3], k, select2Addr); \ |
| 143 | -#define PTO_RS_COMMON_TILE_DEFINE \ | 152 | + auto select3Int32Tile = DefineTile<int32_t, srcTileH, kAlign>(srcShape[3], k, select3Addr); \ |
| 144 | - auto srcIntTile = DefineTile<ConvIntType>(1, srcShape[4]); \ | 153 | + auto indexInt32Tile = DefineTile<int32_t, srcTileH, kAlign>(srcShape[3], k, indexAddr) |
| 145 | - auto valIntTile = DefineTile<ConvIntType>(1, k); \ | 154 | +#define PTO_RS_COMMON_TILE_DEFINE \ |
| 146 | - auto idxTile = DefineTile<IdxDType>(1, k); \ | 155 | + auto srcIntTile = DefineTile<ConvIntType, srcTileH, srcTileW>(srcShape[3], srcShape[4]); \ |
| 147 | - auto cmpTile = DefineTile<uint8_t>(1, cmpSize, cmpAddr); \ | 156 | + auto valIntTile = DefineTile<ConvIntType, srcTileH, valTileW>(srcShape[3], k); \ |
| 148 | - auto selectInt32GTTile = DefineTile<int32_t>(1, k, selectGTAddr); \ | 157 | + auto idxTile = DefineTile<IdxDType, srcTileH, idxTileW>(srcShape[3], k); \ |
| 149 | - auto selectInt32EQTile = DefineTile<int32_t>(1, k, selectEQAddr); \ | 158 | + auto cmpTile = DefineTile<uint8_t, srcTileH, cmpAlign>(srcShape[3], cmpSize, cmpAddr); \ |
| 150 | - auto selectCountUInt32GTTile = DefineTile<uint32_t>(1, 1, selectCountGTAddr); \ | 159 | + auto selectInt32GTTile = DefineTile<int32_t, srcTileH, kAlign>(srcShape[3], k, selectGTAddr); \ |
| 151 | - auto selectCountUInt32EQTile = DefineTile<uint32_t>(1, 1, selectCountEQAddr); \ | 160 | + auto selectInt32EQTile = DefineTile<int32_t, srcTileH, kAlign>(srcShape[3], k, selectEQAddr); \ |
| 152 | - auto rowMinTile = DefineTile<int32_t>(1, 8, rowMinAddr); \ | 161 | + auto selectCountUInt32GTTile = DefineTile<uint32_t, srcTileH>(srcShape[3], 1, selectCountGTAddr); \ |
| 153 | - auto gatherIntTile = DefineTile<int32_t>(1, 8, gatherAddr); \ | 162 | + auto selectCountUInt32EQTile = DefineTile<uint32_t, srcTileH>(srcShape[3], 1, selectCountEQAddr); \ |
| 154 | - auto uselessTile = DefineTile<uint32_t>(1, 1, uselessAddr) | 163 | + auto rowMinTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, rowMinAddr); \ |
| 164 | + auto gatherIntTile = DefineTile<int32_t, srcTileH>(srcShape[3], 8, gatherAddr); \ | ||
| 165 | + auto uselessTile = DefineTile<uint32_t>(1, 1, uselessAddr); \ | ||
| 166 | + auto twiddleIntTile = DefineTile<ConvIntType, srcTileH, srcTileW>(srcShape[3], srcShape[4], srcTwiddleInAddr); \ | ||
| 167 | + auto twiddleUIntTile = DefineTile<ConvUIntType, srcTileH, srcTileW>(srcShape[3], srcShape[4], srcTwiddleInAddr) | ||
| 155 | 168 | ||
| 156 | template <pto::CmpMode cmpMode, typename SELECT, typename SRC, typename K, typename COUNT, typename USELESS> | 169 | template <pto::CmpMode cmpMode, typename SELECT, typename SRC, typename K, typename COUNT, typename USELESS> |
| 157 | TILEOP void RadixSelectGather(SELECT select, SRC src, K k, COUNT count, USELESS useless) | 170 | TILEOP void RadixSelectGather(SELECT select, SRC src, K k, COUNT count, USELESS useless) |
| 158 | { | 171 | { |
| 159 | - pto::TGATHER<SELECT, SRC, K, COUNT, USELESS, cmpMode>(select, src, k, count, useless, 0); | 172 | + auto validRow = select.GetValidRow(); |
| 173 | + using T1 = typename RSExchangeTile<SELECT>::U; | ||
| 174 | + T1 selectOneRow(1, select.GetValidCol()); | ||
| 175 | + using T2 = typename RSExchangeTile<SRC>::U; | ||
| 176 | + T2 srcOneRow(1, src.GetValidCol()); | ||
| 177 | + using T3 = typename RSExchangeTile<K>::U; | ||
| 178 | + T3 kOneRow(1, k.GetValidCol()); | ||
| 179 | + using T4 = typename RSExchangeTile<COUNT>::U; | ||
| 180 | + T4 countOneRow(1, count.GetValidCol()); | ||
| 181 | + for (LoopVar n3Index = 0; n3Index < validRow; ++n3Index) { | ||
| 182 | + pto::TASSIGN(selectOneRow, (int64_t)(select.data() + n3Index * SELECT::RowStride)); | ||
| 183 | + pto::TASSIGN(srcOneRow, (int64_t)(src.data() + n3Index * SRC::RowStride)); | ||
| 184 | + pto::TASSIGN(kOneRow, (int64_t)(k.data() + n3Index * K::RowStride)); | ||
| 185 | + pto::TASSIGN(countOneRow, (int64_t)(count.data() + n3Index * COUNT::RowStride)); | ||
| 186 | + pto::TGATHER<T1, T2, T3, T4, USELESS, cmpMode>(selectOneRow, srcOneRow, kOneRow, countOneRow, useless, 0); | ||
| 187 | + } | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +template <typename DST, typename SRC, typename IDX, typename USELESS> | ||
| 191 | +TILEOP void RadixSelectGather(DST dst, SRC src, IDX idx, USELESS useless) | ||
| 192 | +{ | ||
| 193 | + auto validRow = dst.GetValidRow(); | ||
| 194 | + typename RSExchangeTile<DST>::U dstOneRow(1, dst.GetValidCol()); | ||
| 195 | + typename RSExchangeTile<SRC>::U srcOneRow(1, src.GetValidCol()); | ||
| 196 | + typename RSExchangeTile<IDX>::U idxOneRow(1, idx.GetValidCol()); | ||
| 197 | + for (LoopVar n3Index = 0; n3Index < validRow; ++n3Index) { | ||
| 198 | + pto::TASSIGN(dstOneRow, (int64_t)(dst.data() + n3Index * DST::RowStride)); | ||
| 199 | + pto::TASSIGN(srcOneRow, (int64_t)(src.data() + n3Index * SRC::RowStride)); | ||
| 200 | + pto::TASSIGN(idxOneRow, (int64_t)(idx.data() + n3Index * IDX::RowStride)); | ||
| 201 | + pto::TGATHER(dstOneRow, srcOneRow, idxOneRow, useless); | ||
| 202 | + } | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +template <pto::CmpMode cmpMode, typename DST, typename SRC, typename VAL> | ||
| 206 | +TILEOP void RadixSelectCmps(DST dst, SRC src, VAL val) | ||
| 207 | +{ | ||
| 208 | + auto validRow = dst.GetValidRow(); | ||
| 209 | + typename RSExchangeTile<DST>::U dstOneRow(1, dst.GetValidCol()); | ||
| 210 | + typename RSExchangeTile<SRC>::U srcOneRow(1, src.GetValidCol()); | ||
| 211 | + typename RSExchangeTile<VAL>::U valOneRow(1, val.GetValidCol()); | ||
| 212 | + for (LoopVar n3Index = 0; n3Index < validRow; ++n3Index) { | ||
| 213 | + pto::TASSIGN(dstOneRow, (int64_t)(dst.data() + n3Index * DST::RowStride)); | ||
| 214 | + pto::TASSIGN(srcOneRow, (int64_t)(src.data() + n3Index * SRC::RowStride)); | ||
| 215 | + pto::TASSIGN(valOneRow, (int64_t)(val.data() + n3Index * VAL::RowStride)); | ||
| 216 | + pto::TCMPS(dstOneRow, srcOneRow, valOneRow, cmpMode); | ||
| 217 | + } | ||
| 218 | +} | ||
| 219 | + | ||
| 220 | +template <pto::HistByte histByte, typename DST, typename SRC, typename IDX> | ||
| 221 | +TILEOP void RadixSelectHistogram(DST dst, SRC src, IDX idx) | ||
| 222 | +{ | ||
| 223 | + auto validRow = dst.GetValidRow(); | ||
| 224 | + typename RSExchangeTile<DST>::U dstOneRow(1, dst.GetValidCol()); | ||
| 225 | + typename RSExchangeTile<SRC>::U srcOneRow(1, src.GetValidCol()); | ||
| 226 | + typename RSExchangeTile<IDX>::U idxOneRow(1, 1); | ||
| 227 | + for (LoopVar n3Index = 0; n3Index < validRow; ++n3Index) { | ||
| 228 | + pto::TASSIGN(dstOneRow, (int64_t)(dst.data() + n3Index * DST::RowStride)); | ||
| 229 | + pto::TASSIGN(srcOneRow, (int64_t)(src.data() + n3Index * SRC::RowStride)); | ||
| 230 | + pto::TASSIGN(idxOneRow, (int64_t)(idx.data() + n3Index * IDX::ColStride)); | ||
| 231 | + pto::THISTOGRAM<histByte>(dstOneRow, srcOneRow, idxOneRow); | ||
| 232 | + } | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +template <pto::HistByte histByte, typename DST, typename SRC, typename IDX> | ||
| 236 | +TILEOP void RadixSelectHistogramB4(DST dst, SRC src, IDX idx) | ||
| 237 | +{ | ||
| 238 | + auto validRow = dst.GetValidRow(); | ||
| 239 | + typename RSExchangeTile<DST>::U dstOneRow(1, dst.GetValidCol()); | ||
| 240 | + using SrcTile = typename pto::Tile<SRC::Loc, typename SRC::DType, SRC::Rows, SRC::Rows * 32, SRC::BFractal, -1, -1>; | ||
| 241 | + SrcTile srcOneRow(1, src.GetValidCol()); | ||
| 242 | + using IdxTile = typename pto::Tile<IDX::Loc, typename IDX::DType, IDX::Rows, SRC::Rows * 32, IDX::BFractal, -1, -1>; | ||
| 243 | + IdxTile idxOneRow(idx.GetValidRow(), 1); | ||
| 244 | + for (LoopVar n3Index = 0; n3Index < validRow; ++n3Index) { | ||
| 245 | + pto::TASSIGN(dstOneRow, (int64_t)(dst.data() + n3Index * DST::RowStride)); | ||
| 246 | + pto::TASSIGN(srcOneRow, (int64_t)(src.data() + n3Index * SRC::RowStride)); | ||
| 247 | + pto::TASSIGN(idxOneRow, (int64_t)(idx.data() + n3Index * IDX::RowStride)); | ||
| 248 | + pto::THISTOGRAM<histByte>(dstOneRow, srcOneRow, idxOneRow); | ||
| 249 | + } | ||
| 250 | +} | ||
| 251 | + | ||
| 252 | +template <typename DST> | ||
| 253 | +TILEOP void RadixSelectTCI(DST dst) | ||
| 254 | +{ | ||
| 255 | + auto validRow = dst.GetValidRow(); | ||
| 256 | + using T = typename RSExchangeTile<DST>::U; | ||
| 257 | + T dstOneRowOrigin(1, dst.GetValidCol()); | ||
| 258 | + pto::TASSIGN(dstOneRowOrigin, (int64_t)dst.data()); | ||
| 259 | + pto::TCI<T, T, uint32_t, 0>(dstOneRowOrigin, static_cast<uint32_t>(0), dstOneRowOrigin); | ||
| 260 | + T dstOneRow(1, dst.GetValidCol()); | ||
| 261 | + for (LoopVar n3Index = 1; n3Index < validRow; ++n3Index) { | ||
| 262 | + pto::TASSIGN(dstOneRow, (int64_t)(dst.data() + n3Index * DST::RowStride)); | ||
| 263 | + pto::TMOV(dstOneRow, dstOneRowOrigin); | ||
| 264 | + } | ||
| 265 | +} | ||
| 266 | + | ||
| 267 | +template <typename DST, typename CMP, typename SRC, typename IDX, typename USELESS> | ||
| 268 | +TILEOP void RadixSelectSel(DST dst, CMP cmp, SRC src, IDX idx, USELESS useless) | ||
| 269 | +{ | ||
| 270 | + auto validRow = dst.GetValidRow(); | ||
| 271 | + using TileDefine = typename pto::Tile<pto::TileType::Vec, typename DST::DType, 1, DST::RowStride, | ||
| 272 | + pto::BLayout::RowMajor, -1, -1>; | ||
| 273 | + TileDefine dstOneRow(1, dst.GetValidCol()); | ||
| 274 | + typename RSExchangeTile<CMP>::U cmpOneRow(1, cmp.GetValidCol()); | ||
| 275 | + TileDefine srcOneRow(1, src.GetValidCol()); | ||
| 276 | + TileDefine idxOneRow(1, idx.GetValidCol()); | ||
| 277 | + for (LoopVar n3Index = 0; n3Index < validRow; ++n3Index) { | ||
| 278 | + pto::TASSIGN(dstOneRow, (int64_t)(dst.data() + n3Index * DST::RowStride)); | ||
| 279 | + pto::TASSIGN(cmpOneRow, (int64_t)(cmp.data() + n3Index * CMP::RowStride)); | ||
| 280 | + pto::TASSIGN(srcOneRow, (int64_t)(src.data() + n3Index * SRC::RowStride)); | ||
| 281 | + pto::TASSIGN(idxOneRow, (int64_t)(idx.data() + n3Index * IDX::RowStride)); | ||
| 282 | + pto::TSEL(dstOneRow, cmpOneRow, srcOneRow, idxOneRow, useless); | ||
| 283 | + } | ||
| 284 | +} | ||
| 285 | + | ||
| 286 | +template <typename SRC, typename VAL, typename IDX, typename SRCTILE, typename VALTILE, typename IDXTILE> | ||
| 287 | +TILEOP void RadixSelectBatchAssign(SRC src, VAL value, IDX index, LoopVar n0Index, LoopVar n1Index, LoopVar n2Index, | ||
| 288 | + const size_t (&srcStride)[4], const size_t (&valStride)[4], | ||
| 289 | + const size_t (&idxStride)[4], size_t srcTypeSize, size_t idxTypeSize, | ||
| 290 | + SRCTILE& srcIntTile, VALTILE& valIntTile, IDXTILE& idxTile) | ||
| 291 | +{ | ||
| 292 | + uint64_t srcAddr = src.GetAddr() + | ||
| 293 | + (n0Index * srcStride[0] + n1Index * srcStride[1] + n2Index * srcStride[2]) * srcTypeSize; | ||
| 294 | + uint64_t valAddr = value.GetAddr() + | ||
| 295 | + (n0Index * valStride[0] + n1Index * valStride[1] + n2Index * valStride[2]) * srcTypeSize; | ||
| 296 | + uint64_t idxAddr = index.GetAddr() + | ||
| 297 | + (n0Index * idxStride[0] + n1Index * idxStride[1] + n2Index * idxStride[2]) * idxTypeSize; | ||
| 298 | + pto::TASSIGN(srcIntTile, srcAddr); | ||
| 299 | + pto::TASSIGN(valIntTile, valAddr); | ||
| 300 | + pto::TASSIGN(idxTile, idxAddr); | ||
| 301 | +} | ||
| 302 | + | ||
| 303 | +template <typename GT, typename EQ, typename SRC, typename K, typename CGT, typename CEQ, typename IDX, | ||
| 304 | + typename USELESS> | ||
| 305 | +TILEOP void RadixSelectFinalSelect(GT selectGT, EQ selectEQ, SRC srcMask, K kth, CGT countGT, CEQ countEQ, IDX idx, | ||
| 306 | + USELESS useless) | ||
| 307 | +{ | ||
| 308 | + RadixSelectGather<pto::CmpMode::GT>(selectGT, srcMask, kth, countGT, useless); | ||
| 309 | + RadixSelectGather<pto::CmpMode::EQ>(selectEQ, srcMask, kth, countEQ, useless); | ||
| 310 | + pto::TCONCAT(idx, selectGT, selectEQ, countGT, countEQ); | ||
| 160 | } | 311 | } |
| 161 | 312 | ||
| 162 | /* | 313 | /* |
| @@ -175,11 +326,11 @@ select2Addr | kAlign uint32 | | |||
| 175 | select3Addr | kAlign uint32 | | 326 | select3Addr | kAlign uint32 | |
| 176 | indexAddr | kAlign uint32 | | 327 | indexAddr | kAlign uint32 | |
| 177 | */ | 328 | */ |
| 178 | -template <int64_t bit, typename SRC, typename IDX, typename TMP, typename TMP2, typename SELECT, typename COUNT, | 329 | +template <int64_t bit, typename SRC, typename SRC2, typename IDX, typename TMP, typename TMP2, typename SELECT, |
| 179 | - typename NUM, typename USELESS> | 330 | + typename COUNT, typename NUM, typename USELESS> |
| 180 | -TILEOP void RadixSelectSortTwoBitCalc(SRC src, IDX index, TMP tmp, TMP2 tmp2, USELESS useless, SELECT select1, | 331 | +TILEOP void RadixSelectSortTwoBitCalc(SRC src, SRC2 src2, IDX index, TMP tmp, TMP2 tmp2, USELESS useless, |
| 181 | - SELECT select2, SELECT select3, COUNT count1, COUNT count2, COUNT count3, | 332 | + SELECT select1, SELECT select2, SELECT select3, COUNT count1, COUNT count2, |
| 182 | - NUM num0, NUM num1, NUM num2, NUM num3) | 333 | + COUNT count3, NUM num0, NUM num1, NUM num2, NUM num3) |
| 183 | { | 334 | { |
| 184 | pto::TSHRS(tmp, src, bit); | 335 | pto::TSHRS(tmp, src, bit); |
| 185 | pto::TANDS(tmp, tmp, 0x3); | 336 | pto::TANDS(tmp, tmp, 0x3); |
| @@ -190,29 +341,33 @@ TILEOP void RadixSelectSortTwoBitCalc(SRC src, IDX index, TMP tmp, TMP2 tmp2, US | |||
| 190 | RadixSelectGather<pto::CmpMode::EQ>(select1, tmp2, num1, count1, useless); | 341 | RadixSelectGather<pto::CmpMode::EQ>(select1, tmp2, num1, count1, useless); |
| 191 | pto::TADD(count2, count1, count3); | 342 | pto::TADD(count2, count1, count3); |
| 192 | pto::TCONCAT(select2, select3, select1, count3, count1); | 343 | pto::TCONCAT(select2, select3, select1, count3, count1); |
| 193 | - RadixSelectGather<pto::CmpMode::EQ>(select1, tmp2, num0, count1, useless); | ||
| 194 | if constexpr (bit == 0) { | 344 | if constexpr (bit == 0) { |
| 195 | - pto::TCONCAT(index, select2, select1, count2, count1); | 345 | + RadixSelectGather<pto::CmpMode::EQ>(select3, tmp2, num0, count3, useless); |
| 196 | - pto::TGATHER(tmp, src, index, useless); | 346 | + pto::TCONCAT(select1, select2, select3, count2, count3); |
| 347 | + RadixSelectGather(tmp, src, select1, useless); | ||
| 197 | } else { | 348 | } else { |
| 349 | + RadixSelectGather<pto::CmpMode::EQ>(select1, tmp2, num0, count1, useless); | ||
| 198 | pto::TCONCAT(select3, select2, select1, count2, count1); | 350 | pto::TCONCAT(select3, select2, select1, count2, count1); |
| 199 | - pto::TGATHER(select1, index, select3, useless); | 351 | + RadixSelectGather(select1, index, select3, useless); |
| 200 | - pto::TMOV(index, select1); | 352 | + RadixSelectGather(tmp, src, select3, useless); |
| 201 | - pto::TGATHER(tmp, src, select3, useless); | ||
| 202 | } | 353 | } |
| 203 | - pto::TMOV(src, tmp); | ||
| 204 | } | 354 | } |
| 205 | 355 | ||
| 206 | -template <int64_t bit, int64_t lastBit, typename SRC, typename IDX, typename TMP, typename TMP2, typename SELECT, | 356 | +template <int64_t bit, int64_t lastBit, typename SRC, typename SRC2, typename IDX, typename TMP, typename TMP2, |
| 207 | - typename COUNT, typename NUM, typename USELESS> | 357 | + typename SELECT, typename COUNT, typename NUM, typename USELESS> |
| 208 | -TILEOP void RadixSelectSortTwoBit(SRC src, IDX index, TMP tmp, TMP2 tmp2, USELESS useless, SELECT select1, | 358 | +TILEOP void RadixSelectSortTwoBit(SRC src, SRC2 src2, IDX index, TMP tmp, TMP2 tmp2, USELESS useless, SELECT select1, |
| 209 | SELECT select2, SELECT select3, COUNT count1, COUNT count2, COUNT count3, NUM num0, | 359 | SELECT select2, SELECT select3, COUNT count1, COUNT count2, COUNT count3, NUM num0, |
| 210 | NUM num1, NUM num2, NUM num3) | 360 | NUM num1, NUM num2, NUM num3) |
| 211 | { | 361 | { |
| 212 | if constexpr (bit < lastBit) { | 362 | if constexpr (bit < lastBit) { |
| 213 | - RadixSelectSortTwoBitCalc<bit>(src, index, tmp, tmp2, useless, select1, select2, select3, count1, count2, | 363 | + if constexpr (bit % 4 == 0) { |
| 214 | - count3, num0, num1, num2, num3); | 364 | + RadixSelectSortTwoBitCalc<bit>(src, src2, index, tmp, tmp2, useless, select1, select2, select3, count1, |
| 215 | - RadixSelectSortTwoBit<bit + 2, lastBit>(src, index, tmp, tmp2, useless, select1, select2, select3, count1, | 365 | + count2, count3, num0, num1, num2, num3); |
| 366 | + } else { | ||
| 367 | + RadixSelectSortTwoBitCalc<bit>(tmp, tmp2, select1, src, src2, useless, index, select2, select3, count1, | ||
| 368 | + count2, count3, num0, num1, num2, num3); | ||
| 369 | + } | ||
| 370 | + RadixSelectSortTwoBit<bit + 2, lastBit>(src, src2, index, tmp, tmp2, useless, select1, select2, select3, count1, | ||
| 216 | count2, count3, num0, num1, num2, num3); | 371 | count2, count3, num0, num1, num2, num3); |
| 217 | } | 372 | } |
| 218 | } | 373 | } |
| @@ -240,7 +395,7 @@ TILEOP void RadixSelectTwiddle(TWI twi, SRC src, TMP tmp, CMP cmp, USELESS usele | |||
| 240 | pto::TCMPS(cmp, src, 0, cmpMode); | 395 | pto::TCMPS(cmp, src, 0, cmpMode); |
| 241 | pto::TXORS(tmp, src, SIGN, useless); | 396 | pto::TXORS(tmp, src, SIGN, useless); |
| 242 | pto::TNOT(twi, src); | 397 | pto::TNOT(twi, src); |
| 243 | - pto::TSEL(twi, cmp, twi, tmp, useless); | 398 | + RadixSelectSel(twi, cmp, twi, tmp, useless); |
| 244 | } else if constexpr (isUInt) { | 399 | } else if constexpr (isUInt) { |
| 245 | pto::TMOV(twi, src); | 400 | pto::TMOV(twi, src); |
| 246 | } else { | 401 | } else { |