返回输入x的互补误差函数结果,积分区间为x到无穷大。原始的理论计算公式如下,其中PAR表示矢量计算单元一个迭代能够处理的元素个数 :
由于Erfc函数没有初等函数表达方式,一般通过函数逼近的方式计算,近似计算公式如下所示:
其中,
R(z) = (((((((z * R0 + R1) * z + R2) * z + R3) * z + R4) * z + R5) * z + R6) * z + R7) * z + R8是关于z的8次多项式;
S(z) = (((((z + S1) * z + S2) * z + S3) * z + S4) * z + S5是关于z的4次多项式;
1 2 | template <typename T, bool isReuseSource = false> __aicore__ inline void Erfc(const LocalTensor<T>& dstTensor, const LocalTensor<T>& srcTensor, const LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t calCount) |
1 2 | template <typename T, bool isReuseSource = false> __aicore__ inline void Erfc(const LocalTensor<T>& dstTensor, const LocalTensor<T>& srcTensor, const LocalTensor<uint8_t>& sharedTmpBuffer) |
1 2 | template <typename T, bool isReuseSource = false> __aicore__ inline void Erfc(const LocalTensor<T>& dstTensor, const LocalTensor<T>& srcTensor, const uint32_t calCount) |
1 2 | template <typename T, bool isReuseSource = false> __aicore__ inline void Erfc(const LocalTensor<T>& dstTensor, const LocalTensor<T>& srcTensor) |
由于该接口的内部实现中涉及复杂的数学计算,需要额外的临时空间来存储计算过程中的中间变量。临时空间支持开发者通过sharedTmpBuffer入参传入和接口框架申请两种方式。
通过sharedTmpBuffer传入的情况,开发者需要为tensor申请空间;接口框架申请的方式,开发者需要预留临时空间。临时空间大小BufferSize的获取方式如下:通过GetErfcMaxMinTmpSize中提供的接口获取需要预留空间范围的大小。
参数名 |
描述 |
---|---|
T |
操作数的数据类型。 |
isReuseSource |
是否允许修改源操作数。该参数预留,传入默认值false即可。 |
参数名 |
输入/输出 |
描述 |
---|---|---|
dstTensor |
输出 |
目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:half/float Atlas推理系列产品AI Core,支持的数据类型为:half/float |
srcTensor |
输入 |
源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 源操作数的数据类型需要与目的操作数保持一致。 Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:half/float Atlas推理系列产品AI Core,支持的数据类型为:half/float |
sharedTmpBuffer |
输入 |
临时缓存。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 用于Erfc内部复杂计算时存储中间变量,由开发者提供。 临时空间大小BufferSize的获取方式请参考GetErfcMaxMinTmpSize。 |
calCount |
输入 |
实际计算元素个数,calCount∈[0, srcTensor.GetSize()]。 |
无
Atlas A2训练系列产品/Atlas 800I A2推理产品
Atlas推理系列产品AI Core
完整的调用样例请参考更多样例。
AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECCALC, 1> tmpQue; pipe.InitBuffer(tmpQue, 1, bufferSize); // bufferSize 通过Host侧tiling参数获取 AscendC::LocalTensor<uint8_t> sharedTmpBuffer = tmpQue.AllocTensor<uint8_t>(); // 输入shape信息为1024, 算子输入的数据类型为half, 实际计算个数为512 AscendC::Erfc(dstLocal, srcLocal, sharedTmpBuffer, 512);
输入数据(srcLocal): [-inf -1 0 ... 1 inf] 输出数据(dstLocal): [2.0000000 1.8427038 1.0000000 ... 0.1572961 0]