---
title: 定义必选输入算子（SoftmaxV2）
description: "下面以SoftmaxV2为例，介绍如何进行算子定义。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/programug/graphdevg/atlasag_25_0013.html
sourcePath: /source/zh/canncommercial/900/programug/graphdevg/atlasag_25_0013.html
indexId: b8a55488199d35479bcc43d3f03302c3079cdf425edec5d5e8602d3c240e9a2670
---
# 定义必选输入算子（SoftmaxV2）

下面以SoftmaxV2为例，介绍如何进行算子定义。

SoftmaxV2算子原型定义：

```
REG_OP(SoftmaxV2)
    .INPUT(x, TensorType({ DT_DOUBLE, DT_FLOAT16, DT_BF16, DT_FLOAT }))
    .OUTPUT(y, TensorType({ DT_DOUBLE, DT_FLOAT16, DT_BF16, DT_FLOAT }))
    .ATTR(axes, ListInt, {-1})
    .ATTR(half_to_float, Bool, false)
    .OP_END_FACTORY_REG(SoftmaxV2)
```

从SoftmaxV2算子原型可以看到，SoftmaxV2算子有一个必选输入，输入名称为x。创建SoftmaxV2算子实例：

```
auto softmax = op::SoftmaxV2("Softmax")     // 创建算子实例，传算子名称（例如Softmax）作为入参
    .set_input_x(matmul2);                  // 设置算子输入（例如matmul2）
```
