Sort32
产品支持情况
|
产品 |
是否支持 |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
功能说明
排序函数,一次迭代可以完成32个数的排序,数据需要按如下描述结构进行保存:
score和index分别存储在src0和src1中,按score进行排序(score大的排前面),排序好的score与其对应的index一起以(score, index)的结构存储在dst中。不论score为half还是float类型,dst中的(score, index)结构总是占据8Bytes空间。
如下所示:
函数原型
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) |
参数说明
|
参数名 |
描述 |
|---|---|
|
T |
操作数数据类型。 |
|
参数名称 |
输入/输出 |
含义 |
|---|---|---|
|
dst |
输出 |
目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 |
|
src0 |
输入 |
源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 此源操作数的数据类型需要与目的操作数保持一致。 |
|
src1 |
输入 |
源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 此源操作数固定为uint32_t数据类型。 |
|
repeatTime |
输入 |
重复迭代次数,int32_t类型,每次迭代完成32个元素的排序,下次迭代src0和src1各跳过32个elements,dst跳过32*8 Byte空间。取值范围:repeatTime∈[0,255]。 |
返回值说明
无
约束说明
- 当存在score[i]与score[j]相同时,如果i>j,则score[j]将首先被选出来,排在前面。
- 每次迭代内的数据会进行排序,不同迭代间的数据不会进行排序。
- 操作数地址对齐要求请参见通用地址对齐约束。
调用示例
- 接口使用样例
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, 对128个数分成4组进行排序,每次完成1组32个数的排序 AscendC::Sort32<float>(dstLocal, srcLocal0, srcLocal1, 4); outQueueDst.EnQue<float>(dstLocal); inQueueSrc0.FreeTensor(srcLocal0); inQueueSrc1.FreeTensor(srcLocal1);

