---
title: Exp
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendcopapi/atlasascendc_api_07_0025.html
sourcePath: /source/zh/canncommercial/900/API/ascendcopapi/atlasascendc_api_07_0025.html
indexId: 54e3c1b4c7b9de714e1be937e11572e70504b1f14527027448a0957361b9518b76
---
# Exp

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |
| Atlas 推理系列产品 AI Core | √ |
| Atlas 推理系列产品 Vector Core | x |
| Atlas 训练系列产品 | √ |


#### 功能说明

按元素取自然指数，计算公式如下：


#### 函数原型

- tensor前n个数据计算
  1 2 template <typename T, const ExpConfig& config = DEFAULT_EXP_CONFIG> __aicore__ inline void Exp(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t& count)

- tensor高维切分计算

  - mask逐bit模式
    1 2 template <typename T, bool isSetMask = true, const ExpConfig& config = DEFAULT_EXP_CONFIG> __aicore__ inline void Exp(const LocalTensor<T>& dst, const LocalTensor<T>& src, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)

  - mask连续模式
    1 2 template <typename T, bool isSetMask = true, const ExpConfig& config = DEFAULT_EXP_CONFIG> __aicore__ inline void Exp(const LocalTensor<T>& dst, const LocalTensor<T>& src, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)


#### 参数说明


**表1 模板参数说明**

| 参数名 | 描述 |  |  |  |  |
| --- | --- | --- | --- | --- | --- |
| T | 操作数数据类型。 Atlas 350 加速卡，支持的数据类型为：half、float。 Atlas A3 训练系列产品 / Atlas A3 推理系列产品 ，支持的数据类型为：half、float。 Atlas A2 训练系列产品 / Atlas A2 推理系列产品 ，支持的数据类型为：half、float。 Atlas 200I/500 A2 推理产品 ，支持的数据类型为：half、float。 Atlas 推理系列产品 AI Core，支持的数据类型为：half、float。 Atlas 训练系列产品 ，支持的数据类型为：half、float。 |  |  |  |  |
| isSetMask | 是否在接口内部设置mask。 true，表示在接口内部设置mask。 false，表示在接口外部设置mask，开发者需要使用SetVectorMask接口设置mask值。这种模式下，本接口入参中的mask值必须设置为占位符MASK\_PLACEHOLDER。 |  |  |  |  |
| config | 该参数仅支持Atlas 350 加速卡。 用于配置Subnormal计算模式，ExpConfig类型，定义如下： 1 2 3 4 5 6 7 8 enum class ExpAlgo { INTRINSIC = 0, PRECISION\_1ULP\_FTZ\_TRUE, PRECISION\_1ULP\_FTZ\_FALSE, }; struct ExpConfig { ExpAlgo algo = ExpAlgo::INTRINSIC; } 通过ExpConfig结构体的参数algo来配置Subnormal计算模式。algo取值如下： ExpAlgo::INTRINSIC、ExpAlgo::PRECISION\_1ULP\_FTZ\_TRUE，使用单指令计算得出结果，所有Subnormal被近似为0。 ExpAlgo::PRECISION\_1ULP\_FTZ\_FALSE，支持Subnormal数据计算。 该参数的默认值DEFAULT\_EXP\_CONFIG的取值如下： 1 constexpr ExpConfig DEFAULT\_EXP\_CONFIG = { ExpAlgo::INTRINSIC }; | 1 2 3 4 5 6 7 8 | enum class ExpAlgo { INTRINSIC = 0, PRECISION\_1ULP\_FTZ\_TRUE, PRECISION\_1ULP\_FTZ\_FALSE, }; struct ExpConfig { ExpAlgo algo = ExpAlgo::INTRINSIC; } | 1 | constexpr ExpConfig DEFAULT\_EXP\_CONFIG = { ExpAlgo::INTRINSIC }; |
| 1 2 3 4 5 6 7 8 | enum class ExpAlgo { INTRINSIC = 0, PRECISION\_1ULP\_FTZ\_TRUE, PRECISION\_1ULP\_FTZ\_FALSE, }; struct ExpConfig { ExpAlgo algo = ExpAlgo::INTRINSIC; } |  |  |  |  |
| 1 | constexpr ExpConfig DEFAULT\_EXP\_CONFIG = { ExpAlgo::INTRINSIC }; |  |  |  |  |


**表2 参数说明**

| 参数名 | 输入/输出 | 描述 |
| --- | --- | --- |
| dst | 输出 | 目的操作数。 类型为LocalTensor，支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 |
| src | 输入 | 源操作数。 类型为LocalTensor，支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 源操作数的数据类型需要与目的操作数保持一致。 |
| count | 输入 | 参与计算的元素个数。 |
| mask[]/mask | 输入 | mask(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas\_ascendc\_10\_0022.html\#ZH\-CN\_TOPIC\_0000002562282205\_\_zh\-cn\_topic\_0000002267504656\_zh\-cn\_topic\_0000001764162593\_section4252658182)用于控制每次迭代内参与计算的元素。 逐bit模式：可以按位控制哪些元素参与计算，bit位的值为1表示参与计算，0表示不参与。 mask为数组形式，数组长度和数组元素的取值范围和操作数的数据类型有关。当操作数为16位时，数组长度为2，mask[0]、mask[1]∈[0, 264\-1]并且不同时为0；当操作数为32位时，数组长度为1，mask[0]∈(0, 264\-1]；当操作数为64位时，数组长度为1，mask[0]∈(0, 232\-1]。 例如，mask=[8, 0]，8=0b1000，表示仅第4个元素参与计算。 连续模式：表示前面连续的多少个元素参与计算。取值范围和操作数的数据类型有关，数据类型不同，每次迭代内能够处理的元素个数最大值不同。当操作数为16位时，mask∈[1, 128]；当操作数为32位时，mask∈[1, 64]；当操作数为64位时，mask∈[1, 32]。 |
| repeatTime | 输入 | 重复迭代次数。Vector计算单元，每次读取连续的256Bytes数据进行计算，为完成对输入数据的处理，必须通过多次迭代（repeat）才能完成所有数据的读取与计算。repeatTime表示迭代的次数。 关于该参数的具体描述请参考高维切分API(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas\_ascendc\_10\_0022.html)。 |
| repeatParams | 输入 | 控制操作数地址步长的参数。UnaryRepeatParams类型，包含操作数相邻迭代间相同DataBlock的地址步长，操作数同一迭代内不同DataBlock的地址步长等参数。 相邻迭代间的地址步长参数说明请参考repeatStride(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas\_ascendc\_10\_0022.html\#ZH\-CN\_TOPIC\_0000002562282205\_\_zh\-cn\_topic\_0000002267504656\_zh\-cn\_topic\_0000001764162593\_section139459347420)；同一迭代内DataBlock的地址步长参数说明请参考dataBlockStride(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas\_ascendc\_10\_0022.html\#ZH\-CN\_TOPIC\_0000002562282205\_\_zh\-cn\_topic\_0000002267504656\_zh\-cn\_topic\_0000001764162593\_section2815124173416)。 |


#### 返回值说明

无


#### 约束说明

- 操作数地址对齐要求请参见  通用地址对齐约束
。
- 操作数地址重叠约束请参考  通用地址重叠约束
。


#### 调用示例

本样例的srcLocal和dstLocal均为half类型。

更多样例可参考LINK。

- tensor高维切分计算样例-mask连续模式
  1 2 3 4 5 uint64_t mask = 256 / sizeof(half); // repeatTime = 4, 128 elements one repeat, 512 elements total // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat // dstRepStride, srcRepStride = 8, no gap between repeats AscendC::Exp(dstLocal, srcLocal, mask, 4, { 1, 1, 8, 8 });

- tensor高维切分计算样例-mask逐bit模式
  1 2 3 4 5 uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4, 128 elements one repeat, 512 elements total // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat // dstRepStride, srcRepStride = 8, no gap between repeats AscendC::Exp(dstLocal, srcLocal, mask, 4, { 1, 1, 8, 8 });

- tensor前n个数据计算接口样例
  1 2 3 AscendC::Exp(dstLocal, srcLocal, 512); static constexpr ExpConfig config = { ExpAlgo::PRECISION_1ULP_FTZ_FALSE }; AscendC::Exp<T, config>(dstLocal, srcLocal, 512);


结果示例如下：
```
输入数据srcLocal：[0.0 1.0 2.0 3.0 ...]
输出数据dstLocal：[1.0 2.719 7.391 20.08 ...]
```
