1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
[ { "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" ] } ] } ] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
[ { "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需一一对应。若仅填充其中一项的唯一值,msOpGen工具将会以未填充项的唯一输入值为准自动补充至已填充项的长度。例如用户配置为format:["ND"] /type:["fp16","float","int32"],msOpGen工具将会以format的唯一输入值("ND")为准自动补充至type参数的长度,自动补充后的配置为format:["ND","ND","ND"]/type:["fp16","float","int32"]。 |
||
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需一一对应。若仅填充其中一项的唯一值,msOpGen工具将会以未填充项的唯一输入值为准自动补充至已填充项的长度。例如用户配置为format:["ND"] /type:["fp16","float","int32"],msOpGen工具将会以format的唯一输入值("ND")为准自动补充至type参数的长度,自动补充后的配置为format:["ND","ND","ND"]/type:["fp16","float","int32"]。 |
||
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的算子工程为例,执行如下命令,参数说明请参见表2。
msopgen gen -i {*.json} -f {framework type} -c {Compute Resource} -lan cpp -out {Output Path}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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 gen -i json_path/**.json -f tf -c ai_core-{Soc Version} -out ./output_data -m 1
在算子工程目录下追加**.json中的算子。MindSpore算子工程不能够添加非MindSpore框架的算子。