CANN asc-devkit Maxs API参考
Maxs【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品 / Atlas A3 推理系列产品√Atlas A2 训练系列产品 / Atlas A2 推理系列产品√Kirin X90√Kirin 9030√功能说明源操作数矢量内每个元素与标量相比如果比标量大则取源操作数值比标量的值小则取标量值。计算公式如下函数原型tensor前n个数据计算template typename T, bool isSetMask true __aicore__ inline void Maxs(const LocalTensorT dst, const LocalTensorT src, const T scalarValue, const int32_t count)tensor高维切分计算mask逐bit模式template typename T, bool isSetMask true __aicore__ inline void Maxs(const LocalTensorT dst, const LocalTensorT src, const T scalarValue, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams repeatParams)mask连续模式template typename T, bool isSetMask true __aicore__ inline void Maxs(const LocalTensorT dst, const LocalTensorT src, const T scalarValue, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams repeatParams)dst和src使用TensorTrait类型时其数据类型TensorTrait和scalarValue的数据类型对应TensorTrait中的LiteType类型不一致。因此新增模板类型U表示scalarValue的数据类型并通过std::enable_if检查T中萃取出的LiteType和U是否完全一致一致则接口通过编译否则编译失败。接口原型定义如下:tensor前n个数据计算template typename T, typename U, bool isSetMask true, typename Std::enable_ifStd::is_samePrimTT, U::value, bool::type true __aicore__ inline void Maxs(const LocalTensorT dst, const LocalTensorT src, const U scalarValue, const int32_t count)tensor高维切分计算mask逐bit模式template typename T, typename U, bool isSetMask true, typename Std::enable_ifStd::is_samePrimTT, U::value, bool::type true __aicore__ inline void Maxs(const LocalTensorT dst, const LocalTensorT src, const U scalarValue, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams repeatParams)mask连续模式template typename T, typename U, bool isSetMask true, typename Std::enable_ifStd::is_samePrimTT, U::value, bool::type true __aicore__ inline void Maxs(const LocalTensorT dst, const LocalTensorT src, const U scalarValue, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams repeatParams)参数说明表 1模板参数说明参数名描述T操作数数据类型。Atlas A2 训练系列产品 / Atlas A2 推理系列产品支持的数据类型为half、int16_t、float、int32_t。Atlas A3 训练系列产品 / Atlas A3 推理系列产品支持的数据类型为half、int16_t、float、int32_t。Ascend 950PR/Ascend 950DT支持的数据类型为uint8_t、int8_t、half、bfloat16_t、int16_t、float、int32_t、uint64_t、int64_t。Kirin X90支持的数据类型为half、int16_t、int32_t、float。Kirin 9030支持的数据类型为half、int16_t、int32_t、float。UscalarValue数据类型。Atlas A2 训练系列产品 / Atlas A2 推理系列产品支持的数据类型为half、int16_t、float、int32_t。Atlas A3 训练系列产品 / Atlas A3 推理系列产品支持的数据类型为half、int16_t、float、int32_t。Ascend 950PR/Ascend 950DT支持的数据类型为uint8_t、int8_t、half、bfloat16_t、int16_t、float、int32_t、uint64_t、int64_t。Kirin X90支持的数据类型为half、int16_t、int32_t、float。Kirin 9030支持的数据类型为half、int16_t、int32_t、float。isSetMask是否在接口内部设置mask模式和mask值。true表示在接口内部设置。tensor高维切分计算API/tensor前n个数据计算API内部使用了mask的Normal模式/Counter模式一般情况下保持isSetMask默认值即可表示在API内部进行根据开发者传入的mask/count参数进行mask模式和mask值的设置。false表示在接口外部设置。针对tensor高维切分计算接口对性能要求较高的部分场景下开发者需要使用SetMaskNorm/SetMaskCount设置mask模式并通过SetVectorMask接口设置mask值。本接口入参中的mask值必须设置为MASK_PLACEHOLDER。针对tensor前n个数据计算接口对性能要求较高的部分场景下开发者需要使用SetMaskCount设置mask模式为Counter模式并通过SetVectorMask接口设置mask值。本接口入参中的count不生效建议设置成1。针对以下型号tensor前n个数据计算API中的isSetMask参数不生效保持默认值即可。针对Ascend 950PR/Ascend 950DT表 2参数说明参数名称类型说明dst输出目的操作数。类型为LocalTensor支持的TPosition为VECIN/VECCALC/VECOUT。LocalTensor的起始地址需要32字节对齐。src输入源操作数。类型为LocalTensor支持的TPosition为VECIN/VECCALC/VECOUT。LocalTensor的起始地址需要32字节对齐。数据类型需要与目的操作数保持一致。scalarValue输入源操作数数据类型需要与目的操作数Tensor中元素的数据类型保持一致。count输入参与计算的元素个数。mask/mask[]输入mask用于控制每次迭代内参与计算的元素。逐bit模式可以按位控制哪些元素参与计算bit位的值为1表示参与计算0表示不参与。mask为数组形式数组长度和数组元素的取值范围和操作数的数据类型有关。当操作数为16位时数组长度为2mask[0]、mask[1]∈[0, 264-1]并且不同时为0当操作数为32位时数组长度为1mask[0]∈(0, 264-1]当操作数为64位时数组长度为1mask[0]∈(0, 232-1]。例如mask[8, 0]80b1000表示仅第4个元素参与计算。连续模式表示前面连续的多少个元素参与计算。取值范围和操作数的数据类型有关数据类型不同每次迭代内能够处理的元素个数最大值不同。当操作数为16位时mask∈[1, 128]当操作数为32位时mask∈[1, 64]当操作数为64位时mask∈[1, 32]。repeatTime输入重复迭代次数。 矢量计算单元每次读取连续的256Bytes数据进行计算为完成对输入数据的处理必须通过多次迭代repeat才能完成所有数据的读取与计算。repeatTime表示迭代的次数。repeatParams输入元素操作控制结构信息具体请参考UnaryRepeatParams。返回值说明无约束说明操作数地址对齐要求请参见通用地址对齐约束。操作数地址重叠约束请参考通用地址重叠约束。针对Ascend 950PR/Ascend 950DTint8_t/uint8_t/uint64_t/int64_t数据类型仅支持tensor前n个数据计算接口。调用示例更多样例可参考LINK。tensor高维切分计算样例-mask连续模式uint64_t mask 128; int16_t scalar 2; // repeatTime 4, 单次迭代处理128个数计算512个数需要迭代4次 // dstBlkStride, srcBlkStride 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride 8, 相邻迭代间的地址间隔为8个datablock表示相邻迭代间数据连续读取和写入 AscendC::Maxs(dstLocal, srcLocal, scalar, mask, 4, { 1, 1, 8, 8 });tensor高维切分计算样例-mask逐bit模式uint64_t mask[2] { UINT64_MAX, UINT64_MAX }; int16_t scalar 2; // repeatTime 4, 单次迭代处理128个数计算512个数需要迭代4次 // dstBlkStride, srcBlkStride 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride 8, 相邻迭代间的地址间隔为8个datablock表示相邻迭代间数据连续读取和写入 AscendC::Maxs(dstLocal, srcLocal, scalar, mask, 4, {1, 1, 8, 8});tensor前n个数据计算样例int16_t scalar 2; AscendC::Maxs(dstLocal, srcLocal, scalar, 512);结果示例如下输入数据src0Local[1 2 3 ... 512] 输入数据scalar 2 输出数据dstLocal[2 2 3 ... 512]【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考