[ { "op": "AddCustom", "input_desc": [ { "name": "x", "param_type": "required", "format": [ "ND", "ND", "ND" ], "type": [ "fp16", "float", "int32" ] }, { "name": "y", "param_type": "required", "format": [ "ND", "ND", "ND" ], "type": [ "fp16", "float", "int32" ] } ], "output_desc": [ { "name": "z", "param_type": "required", "format": [ "ND", "ND", "ND" ], "type": [ "fp16", "float", "int32" ] } ] } ]
[ { "op": "ReduceMaxCustom", "input_desc": [ { "name": "x", "param_type": "required", "format": ["ND"], "type": ["float16"] } ], "output_desc": [ { "name": "y", "param_type": "required", "format": ["ND"], "type": ["float16"] }, { "name": "idx", "param_type": "required", "format": ["ND"], "type": ["int32"] } ], "attr": [ { "name": "reduceDim", "param_type": "required", "type": "int" }, { "name": "isKeepDim", "param_type": "optional", "type": "int", "default_value": 1 } ] } ]
配置字段 |
类型 |
含义 |
是否必选 |
|
---|---|---|---|---|
op |
- |
字符串 |
算子的Operator Type。 |
是 |
input_desc |
- |
列表 |
输入参数描述。 |
否 |
name |
字符串 |
算子输入参数的名称。 |
||
param_type |
字符串 |
参数类型:
未配置默认为required。 |
||
format |
列表 |
针对类型为tensor的参数,配置为tensor支持的数据排布格式。 包含如下取值: ND,NHWC,NCHW,HWCN,NC1HWC0,FRACTAL_Z等。 说明:
format与type需一一对应。 |
||
type |
列表 |
算子参数的类型。 取值范围:float, half, float16 (fp16), float32 (fp32), int8, int16, int32, int64, uint8, uint16, uint32, uint64, qint8, qint16, qint32, quint8, quint16, quint32, bool, double, string, resource, complex64, complex128, bf16, numbertype, realnumbertype, quantizedtype, all, BasicType, IndexNumberType等。 说明:
|
||
output_desc |
- |
列表 |
输出参数描述。 |
是 |
name |
字符串 |
算子输出参数的名称。 |
||
param_type |
字符串 |
参数类型:
未配置默认为required。 |
||
format |
列表 |
针对类型为tensor的参数,配置为tensor支持的数据排布格式。 包含如下取值: ND,NHWC,NCHW,HWCN,NC1HWC0,FRACTAL_Z等。 format与type需一一对应。 |
||
type |
列表 |
算子参数的类型。 取值范围:float, half, float16 (fp16), float32 (fp32), int8, int16, int32, int64, uint8, uint16, uint32, uint64, qint8, qint16, qint32, quint8, quint16, quint32, bool, double, string, resource, complex64, complex128, bf16, numbertype, realnumbertype, quantizedtype, all, BasicType, IndexNumberType等。 说明:
|
||
attr |
- |
列表 |
属性描述。 |
否 |
name |
字符串 |
算子属性参数的名称。 |
||
param_type |
字符串 |
参数类型:
未配置默认为required。 |
||
type |
字符串 |
算子参数的类型。 包含如下取值: int、bool、float、string、list_int、list_float等。 |
||
default_value |
- |
默认值。 |
例如,第一个输入x的type配置为[“int8”,“int32”],第二个输入y的type配置为[“fp16”,“fp32”],输出z的type配置为[“int32”,“int64”],最终这个算子支持输入(“int8”,“fp16”)生成int32,或者(“int32”,“fp32”)生成int64,即输入和输出的type是垂直对应的,类型不能交叉。
以生成AddCustom的算子工程为例,进入msopgen工具所在目录执行如下命令,参数说明请参见表2。
./msopgen gen -i {*.json} -f {framework type} -c {Compute Resource} -lan cpp -out {Output Path}
参数名称 |
参数描述 |
是否必选 |
---|---|---|
gen |
用于生成算子开发交付件。 |
是 |
-i,--input |
算子原型定义文件(.json)路径,可配置为绝对路径或者相对路径。工具执行用户需要有此路径的可读权限。 |
是 |
-f,--framework |
框架类型。
说明:
所有参数值大小写不敏感。 |
否 |
-c,--compute_unit |
算子使用的计算资源。 配置格式为:ai_core-{soc version},ai_core与{soc version}之间用中划线“-”连接。 请根据实际昇腾AI处理器版本进行选择。 说明:
|
是 |
-out,--output |
生成文件所在路径,可配置为绝对路径或者相对路径,并且工具执行用户具有可读写权限。 若不配置,则默认生成在执行命令的当前路径。 |
否 |
-m,--mode |
生成交付件模式。
默认值:0。 |
否 |
-op,--operator |
配置算子的类型,如:Conv2DTik。 若不配置此参数,当算子原型定义文件中存在多个算子时,工具会提示用户选择算子。 |
否 |
-lan,--language |
算子编码语言。
默认值:py。 |
否 |
示例:
./msopgen gen -i json_path/add_custom.json -f tf -c ai_core-{Soc Version} -lan cpp -out ./output_data
工具会提示输入选择的算子序号,输入:1。
There is more than one operator in the .json file: 1 Op_1 2 Op_2 Input the number of the op: 1
当命令行提示:Generation completed,则完成Op_1算子工程的创建。Op_1为文件中"op"的值。
output_data ├── build.sh // 编译入口脚本 ├── cmake │ ├── config.cmake │ ├── util // 算子工程编译所需脚本及公共编译文件存放目录 ├── CMakeLists.txt // 算子工程的CMakeLists.txt ├── CMakePresets.json // 编译配置项 ├── framework // 算子插件实现文件目录,单算子模型文件的生成不依赖算子适配插件,无需关注 ├── op_host // host侧实现文件 │ ├── add_custom_tiling.h // 算子tiling定义文件 │ ├── add_custom.cpp // 算子原型注册、shape推导、信息库、tiling实现等内容文件 │ ├── CMakeLists.txt ├── op_kernel // kernel侧实现文件 │ ├── CMakeLists.txt │ ├── add_custom.cpp // 算子代码实现文件 ├── scripts // 自定义算子工程打包相关脚本所在目录
进入msopgen工具所在目录执行如下命令:
./msopgen gen -i json_path/**.json -f tf -c ai_core-{Soc Version} -out ./output_data -m 1
在算子工程目录下追加**.json中的算子。MindSpore算子工程不能够添加非MindSpore框架的算子。