源操作数内每个element做逻辑左移,逻辑左移的位数由输入参数scalar决定。
所谓逻辑左移,是指去掉最高位,最低位补0,例:二进制数 1010101010101010,逻辑左移一位结果为 0101010101010100。
1 2 |
template <typename T, bool isSetMask = true> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, const int32_t& calCount) |
1 2 |
template <typename T, bool isSetMask = true> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, uint64_t mask[], const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) |
1 2 |
template <typename T, bool isSetMask = true> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, uint64_t mask, const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) |
dstLocal和srcLocal使用TensorTrait类型时,其数据类型TensorTrait和scalarValue的数据类型(对应TensorTrait中的LiteType类型)不一致。因此新增模板类型U表示scalarValue的数据类型,并通过std::enable_if检查T中萃取出的LiteType和U是否完全一致,一致则接口通过编译,否则编译失败。接口原型定义如下:
1 2 |
template <typename T, typename U, bool isSetMask = true, typename std::enable_if<IsSameType<PrimT<T>, U>::value, bool>::type = true> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const U& scalarValue, const int32_t& calCount) |
1 2 |
template <typename T, typename U, bool isSetMask = true, typename std::enable_if<IsSameType<PrimT<T>, U>::value, bool>::type = true> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const U& scalarValue, uint64_t mask[], const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) |
1 2 |
template <typename T, typename U, bool isSetMask = true, typename std::enable_if<IsSameType<PrimT<T>, U>::value, bool>::type = true> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const U& scalarValue, uint64_t mask, const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) |
参数名 |
描述 |
---|---|
T |
操作数数据类型。 |
U |
scalarValue数据类型。 |
isSetMask |
是否在接口内部设置mask模式和mask值。
|
参数名称 |
类型 |
说明 |
---|---|---|
dstLocal |
输出 |
目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:Tensor(uint16/int16/uint32/int32) Atlas 200I/500 A2推理产品,支持的数据类型为:Tensor(uint16/int16/uint32/int32) |
srcLocal |
输入 |
源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 数据类型需要与目的操作数保持一致。 Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:Tensor(uint16/int16/uint32/int32) Atlas 200I/500 A2推理产品,支持的数据类型为:Tensor(uint16/int16/uint32/int32) |
scalarValue |
输入 |
源操作数,数据类型需要与目的操作数Tensor中的元素数据类型保持一致。
Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:uint16/int16/uint32/int32 Atlas 200I/500 A2推理产品,支持的数据类型为:uint16/int16/uint32/int32 |
calCount |
输入 |
输入数据元素个数。 参数取值范围和操作数的数据类型有关,数据类型不同,能够处理的元素个数最大值不同。 矢量计算单元,每个迭代读取连续256 Bytes数据进行计算,通过多次迭代完成所有数据的读取与计算。所以当操作数为16位时,calCount∈[1,128*255],255表示迭代次数的最大值,128表示每次迭代内能够处理128个16位数据;当操作数为32位时,calCount∈[1,64*255],64表示每次迭代内能够处理64个32位数据。 |
mask |
输入 |
mask用于控制每次迭代内参与计算的元素。
|
repeatTimes |
输入 |
重复迭代次数。 矢量计算单元,每次读取连续的256 Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTimes表示迭代的次数。 关于该参数的具体描述请参考通用参数说明。 |
repeatParams |
输入 |
元素操作控制结构信息,具体请参考UnaryRepeatParams。 |
无
Atlas A2训练系列产品/Atlas 800I A2推理产品
Atlas 200I/500 A2推理产品
1 2 3 4 5 6 |
uint64_t mask = 128; int16_t scalar = 2; // repeatTimes = 4, 单次迭代处理128个数,计算512个数需要迭代4次 // dstBlkStride, srcBlkStride = 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock,表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride = 8, 相邻迭代间的地址间隔为8个datablock,表示相邻迭代间数据连续读取和写入 AscendC::ShiftLeft(dstLocal, srcLocal, scalar, mask, 4, { 1, 1, 8, 8 }); |
1 2 3 4 5 6 |
uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; int16_t scalar = 2; // repeatTimes = 4, 单次迭代处理128个数,计算512个数需要迭代4次 // dstBlkStride, srcBlkStride = 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock,表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride = 8, 相邻迭代间的地址间隔为8个datablock,表示相邻迭代间数据连续读取和写入 AscendC::ShiftLeft(dstLocal, srcLocal, scalar, mask, 4, {1, 1, 8, 8}); |
1 2 |
int16_t scalar = 2; AscendC::ShiftLeft(dstLocal, srcLocal, scalar, 512); |
输入数据(src0Local): [1 2 3 ... 512] 输入数据 scalar = 2 输出数据(dstLocal): [4 8 12 ... 2048]