MrgSort
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
√ |
|
x |
|
x |
|
x |
Function Usage
Merges at most four sorted queues into one. The results are sorted in descending order of the score fields.
Prototype
1 2 | template <typename T> __aicore__ inline void MrgSort(const LocalTensor<T>& dst, const MrgSortSrcList<T>& src, const MrgSort4Info& params) |
Parameters
Parameter |
Description |
|---|---|
T |
For the Atlas 350 Accelerator Card, the supported data types are half and float. For the For the For the |
Parameter |
Input/Output |
Meaning |
||
|---|---|---|---|---|
dst |
Output |
Destination operand, which stores sorted data. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. |
||
src |
Input |
Source operand of the MrgSortSrcList structure type, which contains four sorted queues. The definition is as follows:
The source operand must have the same data type as the destination operand. The type of src1, src2, src3, or src4 is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT. The start address of the LocalTensor must be 8-byte aligned. |
||
params |
Input |
Parameter required for sorting, which is of the MrgSort4Info structure type. For details, see ${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_proposal.h. Replace ${INSTALL_DIR} with the actual CANN component directory. For details about the parameter description, see Table 3. |
Parameter |
Meaning |
|---|---|
elementLengths |
Lengths of the four source queues (or numbers of the 8-byte structures), an array of the uint16_t type with a length of 4. Theoretically, the value range of each element is [0, 4095], but the value cannot exceed the storage space of the UB. |
ifExhaustedSuspension |
A bool specifying whether to stop the instruction when a queue is exhausted. The default value is false. |
validBit |
Number of valid queues. The values are as follows:
|
repeatTimes |
Number of iteration repeats. The total length of the four queues is skipped for the source and destination operands in each iteration. Value range: repeatTimes ∈ [1,255] The repeatTimes parameter takes effect only when the following conditions are met:
|
Returns
None
Restrictions
- If score [i] and score [j] are the same and i is greater than j, score [j] is selected first.
- Data within each iteration is sorted, but data among different iterations is not sorted.
- Note that the queues sorted by this function are not in the Region Proposal structure.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // Merge the eight sorted queues. Set repeatTimes to 2, and store the data consecutively. // Each queue contains 32 8-byte (score, index) structures. // Output the result after the 256 elements in the score fields are sorted. AscendC::MrgSort4Info params; params.elementLengths[0] = 32; params.elementLengths[1] = 32; params.elementLengths[2] = 32; params.elementLengths[3] = 32; params.ifExhaustedSuspension = false; params.validBit = 0b1111; params.repeatTimes = 2; AscendC::MrgSortSrcList<float> srcList; srcList.src1 = workLocal[0]; srcList.src2 = workLocal[64]; // workLocal is of the float type. Each queue occupies 256 bytes. srcList.src3 = workLocal[128]; srcList.src4 = workLocal[192]; AscendC::MrgSort<float>(dstLocal, srcList, params); outQueueDst.EnQue<float>(dstLocal); outQueueDst.FreeTensor(dstLocal); |

