Sort32
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
Function Usage
Sorts a maximum of 32 elements in each repeat. The data needs to be stored according to the following structure:
Scores and indexes are stored in src0 and src1 respectively. The sorting is based on scores in descending order. The sorted scores and their indexes are stored in dst in the (score, index) structure. No matter whether the scores are of the half or float type, the (score, index) structure in dst always occupies 8 bytes.
See the following examples:
- When the score type is float and the index type is uint32_t, in the computation result, the indexes are stored in the upper 4 bytes and the scores are stored in the lower 4 bytes.
- When the score type is half and the index type is uint32_t, in the computation result, the indexes are stored in the upper 4 bytes, the scores are stored in the lower 2 bytes, and the middle 2 bytes are reserved.
Prototype
1 2 |
template <typename T> __aicore__ inline void Sort32(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<uint32_t>& src1, const int32_t repeatTime) |
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Operand data type. 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. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. |
|
src0 |
Input |
Source operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. The source operand must have the same data type as the destination operand. |
|
src1 |
Input |
Source operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. This source operand is fixed at the uint32_t data type. |
|
repeatTime |
Input |
Number of iteration repeats. The value is of the int32_t type. 32 elements are sorted in each iteration. In the next iteration, 32 elements are skipped in src0 and src1 respectively, and 32 x 8 bytes are skipped in dst. Value range: repeatTime ∈ [0,255] |
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.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
Examples
1 2 3 4 5 6 7 8 |
AscendC::LocalTensor<float> srcLocal0 = inQueueSrc0.DeQue<float>(); AscendC::LocalTensor<uint32_t> srcLocal1 = inQueueSrc1.DeQue<uint32_t>(); AscendC::LocalTensor<float> dstLocal = outQueueDst.AllocTensor<float>(); // repeatTime = 4. Divide 128 elements into four groups and sort the 32 elements in each group each time. AscendC::Sort32<float>(dstLocal, srcLocal0, srcLocal1, 4); outQueueDst.EnQue<float>(dstLocal); inQueueSrc0.FreeTensor(srcLocal0); inQueueSrc1.FreeTensor(srcLocal1); |

