对源操作数中的每个元素进行左移操作,左移的位数由输入参数scalarValue决定。根据源操作数的数据类型,左移操作分为以下两种情况:
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值。
针对以下型号,tensor前n个数据计算API中的isSetMask参数不生效,保持默认值即可。
|
参数名称 |
输入/输出 |
说明 |
---|---|---|
dstLocal |
输出 |
目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 |
srcLocal |
输入 |
源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 数据类型需要与目的操作数保持一致。 |
scalarValue |
输入 |
左移的位数,数据类型需要与目的操作数Tensor中的元素数据类型保持一致。 针对 针对 |
calCount |
输入 |
参与计算的元素个数。 |
mask/mask[] |
输入 |
mask用于控制每次迭代内参与计算的元素。
|
repeatTimes |
输入 |
重复迭代次数。 矢量计算单元,每次读取连续的256Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTimes表示迭代的次数。 关于该参数的具体描述请参考通用参数说明。 |
repeatParams |
输入 |
元素操作控制结构信息,具体请参考UnaryRepeatParams。 |
无
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]