产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
提供灵活标量位置的接口,支持标量在前和标量在后两种场景。其中标量输入支持配置LocalTensor单点元素,计算公式如下,idx表示LocalTensor单点元素的位置系数。

支持多种比较模式:
1 2 | template <typename T0 = BinaryDefaultType, typename T1 = BinaryDefaultType, bool isSetMask = true, const BinaryConfig &config = DEFAULT_BINARY_CONFIG, typename T2, typename T3, typename T4> __aicore__ inline void Compares(const T2& dst, const T3& src0, const T4& src1, CMPMODE cmpMode, uint32_t count) |
1 2 | template <typename T0 = BinaryDefaultType, typename T1 = BinaryDefaultType, bool isSetMask = true, const BinaryConfig &config = DEFAULT_BINARY_CONFIG, typename T2, typename T3, typename T4> __aicore__ inline void Compares(const T2& dst, const T3& src0, const T4& src1, CMPMODE cmpMode, const uint64_t mask[], uint8_t repeatTime, const UnaryRepeatParams& repeatParams) |
1 2 | template <typename T0 = BinaryDefaultType, typename T1 = BinaryDefaultType, bool isSetMask = true, const BinaryConfig &config = DEFAULT_BINARY_CONFIG, typename T2, typename T3, typename T4> __aicore__ inline void Compares(const T2& dst, const T3& src0, const T4& src1, CMPMODE cmpMode, const uint64_t mask, uint8_t repeatTime, const UnaryRepeatParams& repeatParams) |
参数名 |
描述 |
||
|---|---|---|---|
T0 |
对于固定标量位置接口,表示源操作数数据类型。 特别地,对于灵活标量位置接口,为预留参数,暂未启用,为后续的功能扩展做保留,需要指定时,传入默认值BinaryDefaultType即可。 |
||
T1 |
对于固定标量位置接口,表示目的操作数数据类型。 特别地,对于灵活标量位置接口,为预留参数,暂未启用,为后续的功能扩展做保留,需要指定时,传入默认值BinaryDefaultType即可。 |
||
isSetMask |
是否在接口内部设置mask。
|
||
config |
类型为BinaryConfig,当标量为LocalTensor单点元素类型时生效,用于指定单点元素操作数位置。默认值DEFAULT_BINARY_CONFIG,表示右操作数为标量。
|
||
T2 |
LocalTensor类型,根据输入参数dst自动推导相应的数据类型,开发者无需配置该参数,保证dst满足数据类型的约束即可。 |
||
T3 |
LocalTensor类型或标量类型,根据输入参数src0自动推导相应的数据类型,开发者无需配置该参数,保证src0满足数据类型的约束即可。 |
||
T4 |
LocalTensor类型或标量类型,根据输入参数src1自动推导相应的数据类型,开发者无需配置该参数,保证src1满足数据类型的约束即可。 |
参数名称 |
输入/输出 |
含义 |
|---|---|---|
dst |
输出 |
目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 dst用于存储比较结果,将dst中uint8_t类型的数据按照bit位展开,由左至右依次表征对应位置的src0和src1的比较结果,如果比较后的结果为真,则对应比特位为1,否则为0。 Ascend 950PR/Ascend 950DT,支持的数据类型为:uint8_t |
src0/src1 |
输入 |
灵活标量位置接口中源操作数。
数据类型需要与目的操作数保持一致。 |
cmpMode |
输入 |
CMPMODE类型,表示比较模式,包括EQ,NE,GE,LE,GT,LT。
|
mask/mask[] |
输入 |
mask用于控制每次迭代内参与计算的元素。
|
repeatTime |
输入 |
重复迭代次数。矢量计算单元,每次读取连续的256Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTime表示迭代的次数。 关于该参数的具体描述请参考高维切分API。 |
repeatParams |
输入 |
控制操作数地址步长的参数。UnaryRepeatParams类型,包含操作数相邻迭代间相同DataBlock的地址步长,操作数同一迭代内不同DataBlock的地址步长等参数。 相邻迭代间的地址步长参数说明请参考repeatStride;同一迭代内DataBlock的地址步长参数说明请参考dataBlockStride。 |
count |
输入 |
参与计算的元素个数。设置count时,需要保证count个元素所占空间256字节对齐。 |
无
对于灵活标量位置接口,支持直接传入立即数或单点LocalTensor作为标量,并且支持标量在前和在后两种调用方式。
1 2 3 4 5 6 | // 标量在后,src1Local[0]作为标量 AscendC::Compares(dstLocal, src0Local, src1Local[0], AscendC::CMPMODE::LT, srcDataSize); // 标量在前,src0Local[0]作为标量 static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Compares<BinaryDefaultType, BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, AscendC::CMPMODE::LT, srcDataSize); |
1 2 3 4 5 6 7 8 9 10 11 12 | uint64_t mask = 256 / sizeof(float); // 256为每个迭代处理的字节数 int repeat = 4; AscendC::UnaryRepeatParams repeatParams = { 1, 1, 8, 8 }; // repeat = 4, 64 elements one repeat, 256 elements total // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat // dstRepStride, srcRepStride = 8, no gap between repeats // 标量在后,src1Local[0]作为标量 AscendC::Compares(dstLocal, src0Local, src1Local[0], AscendC::CMPMODE::LT, mask, repeat, repeatParams); // 标量在前,src0Local[0]作为标量 static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Compares<BinaryDefaultType, BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, AscendC::CMPMODE::LT, mask, repeat, repeatParams); |
1 2 3 4 5 6 7 8 9 10 11 12 | uint64_t mask[2] = { UINT64_MAX, 0}; int repeat = 4; AscendC::UnaryRepeatParams repeatParams = { 1, 1, 8, 8 }; // repeat = 4, 64 elements one repeat, 256 elements total // srcBlkStride, = 1, no gap between blocks in one repeat // dstRepStride, srcRepStride = 8, no gap between repeats // 标量在后,src1Local[0]作为标量 AscendC::Compares(dstLocal, src0Local, src1Local[0], AscendC::CMPMODE::LT, mask, repeat, repeatParams); // 标量在前,src0Local[0]作为标量 static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Compares<BinaryDefaultType, BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, AscendC::CMPMODE::LT, mask, repeat, repeatParams); |