Sort32
产品支持情况
功能说明
排序函数,一次迭代可以完成32个数的排序,数据需要按如下描述结构进行保存:
score和index分别存储在src0和src1中,按score进行排序(score大的排前面),排序好的score与其对应的index一起以(score, index)的结构存储在dst中。不论score为half还是float类型,dst中的(score, index)结构总是占据8Bytes空间。
如下所示:
-
当score为float,index为uint32_t类型时,计算结果中index存储在高4Bytes,score存储在低4Bytes。

-
当score为half,index为uint32_t类型时,计算结果中index存储在高4Bytes,score存储在低2Bytes, 中间的2Bytes保留。

函数原型
template <typename T>
__aicore__ inline void Sort32(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<uint32_t>& src1, const int32_t repeatTime)
参数说明
表 1 模板参数说明
|
Ascend 950PR/Ascend 950DT,支持的数据类型为:half/float |
表 2 参数说明
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
重复迭代次数,int32_t类型,每次迭代完成32个元素的排序,下次迭代src0和src1各跳过32个elements,dst跳过32*8 Byte空间。取值范围:repeatTime∈[0,255]。 |
返回值说明
无
约束说明
- 当存在score[i]与score[j]相同时,如果i>j,则score[j]将首先被选出来,排在前面。
- 每次迭代内的数据会进行排序,不同迭代间的数据不会进行排序。
- 操作数地址对齐要求请参见通用地址对齐约束。
调用示例
-
接口使用样例
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, 对128个数分成4组进行排序,每次完成1组32个数的排序 AscendC::Sort32<float>(dstLocal, srcLocal0, srcLocal1, 4); outQueueDst.EnQue<float>(dstLocal); inQueueSrc0.FreeTensor(srcLocal0); inQueueSrc1.FreeTensor(srcLocal1);