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

1 2 | template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Muls(const U& dst, const S& src0, const V& src1, const int32_t& count) |
1 2 | template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Muls(const U& dst, const S& src0, const V& src1, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams) |
1 2 | template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Muls(const U& dst, const S& src0, const V& src1, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams) |
参数名 |
描述 |
||
|---|---|---|---|
T |
操作数数据类型。 对于灵活标量位置接口,为预留参数,暂未启用,为后续的功能扩展做保留,需要指定时,传入默认值BinaryDefaultType即可。 |
||
isSetMask |
是否在接口内部设置mask模式和mask值。
针对以下型号,tensor前n个数据计算API中的isSetMask参数不生效,保持默认值即可。
|
||
config |
类型为BinaryConfig,当标量为LocalTensor单点元素类型时生效,用于指定单点元素操作数位置。默认值DEFAULT_BINARY_CONFIG,表示右操作数为标量。
|
||
U |
LocalTensor类型,根据输入参数dst自动推导相应的数据类型,开发者无需配置该参数,保证dst满足数据类型的约束即可。 |
||
S |
LocalTensor类型或标量类型,根据输入参数src0自动推导相应的数据类型,开发者无需配置该参数,保证src0满足数据类型的约束即可。 |
||
V |
LocalTensor类型或标量类型,根据输入参数src1自动推导相应的数据类型,开发者无需配置该参数,保证src1满足数据类型的约束即可。 |
参数名称 |
类型 |
说明 |
|---|---|---|
dst |
输出 |
目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 Ascend 950PR/Ascend 950DT,支持的数据类型为:half/bfloat16_t/int16_t/float/int32_t/uint64_t/int64_t/complex32/complex64 |
src0/src1 |
输入 |
灵活标量位置接口中源操作数。
数据类型需要与目的操作数保持一致。 |
count |
输入 |
参与计算的元素个数。 |
mask/mask[] |
输入 |
mask用于控制每次迭代内参与计算的元素。
|
repeatTime |
输入 |
重复迭代次数。 矢量计算单元,每次读取连续的256Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTime表示迭代的次数。 关于该参数的具体描述请参考高维切分API。 |
repeatParams |
输入 |
元素操作控制结构信息,具体请参考UnaryRepeatParams。 |
无
更多样例可参考LINK。
1 2 3 4 5 6 7 8 9 10 | uint64_t mask = 128; // repeatTime = 4, 单次迭代处理128个数,计算512个数需要迭代4次 // dstBlkStride, srcBlkStride = 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock,表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride = 8, 相邻迭代间的地址间隔为8个datablock,表示相邻迭代间数据连续读取和写入 // 标量在后调用示例 AscendC::Muls(dstLocal, src0Local, src1Local[0], mask, 4, { 1, 1, 8, 8 }); // 标量在前调用示例 static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Muls<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, mask, 4, { 1, 1, 8, 8 }); |
1 2 3 4 5 6 7 8 9 10 | uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4, 单次迭代处理128个数,计算512个数需要迭代4次 // dstBlkStride, srcBlkStride = 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock,表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride = 8, 相邻迭代间的地址间隔为8个datablock,表示相邻迭代间数据连续读取和写入 // 标量在后调用示例 AscendC::Muls(dstLocal, src0Local, src1Local[0], mask, 4, {1, 1, 8, 8}); // 标量在前调用示例 static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Muls<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, mask, 4, { 1, 1, 8, 8 }); |
1 2 3 4 5 6 | // 标量在后调用示例 AscendC::Muls(dstLocal, src0Local, src1Local[0], 512); // 标量在前调用示例 static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Muls<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, 512); |
输入数据src0Local:[1 2 3 ... 512] 输入数据src1Local:[2 2 2 ... 2] // 标量在前,src0Local[0]作为标量 输出数据dstLocal:[2 2 2 ... 2] // 标量在后,src1Local[0]作为标量 输出数据dstLocal:[2 4 6 ... 1024]