【免费下载链接】atvcATVC(Ascend C Templates for Vector Compute),是为基于Ascend C开发的典型Vector算子封装的一系列模板头文件的集合,可帮助用户快速开发典型Vector算子。项目地址: https://gitcode.com/cann/atvc
AddCustom算子样例
概述
样例概述:本样例介绍了如何利用ATVC搭建标量参与计算的自定义算子并完成算子验证。
- 算子功能:标量参与计算的自定义算子
- 使用的ATVC模板:Elementwise
- 调用方式:Kernel直调
样例支持AI处理器型号:
- Ascend 910C
- Ascend 910B
算子描述
该自定义算子数学计算公式为:
$$ c = \begin{cases} 2 * a + b& \text{if conditionVal = 1}\ 2 * a - b& \text{if conditionVal != 1} \end{cases} $$
算子规格:
| 算子类型(OpType) | 自定义算子 | |||
| 算子输入 | ||||
| name | shape | data type | format | |
| a | 8 * 2048 | float | ND | |
| b | 8 * 2048 | float | ND | |
| 算子输出 | ||||
| c | 8 * 2048 | float | ND | |
| 核函数名 | AddCustom | |||
目录结构
| 文件名 | 描述 |
|---|---|
| add_with_scalar.cpp | 自定义算子代码实现以及调用样例 |
算子运行
在ascendc-api-adv代码仓目录下执行:
cd ./ops_templates/atvc/examples bash run_examples.sh add_with_scalar【免费下载链接】atvcATVC(Ascend C Templates for Vector Compute),是为基于Ascend C开发的典型Vector算子封装的一系列模板头文件的集合,可帮助用户快速开发典型Vector算子。项目地址: https://gitcode.com/cann/atvc
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考