文档
注册

params归一格式的算子json配置

json配置说明

为了支持输入/输出参数交叉配置的场景,params归一配置格式应运而生,所有输入/输出参数均放在“params”配置项中。该算子json配置文件中参数可以按输入/输出规则排布,也可以按输入/输出交叉排布,只要保证参数顺序与Kernel入口函数的参数顺序保持一致即可。

  • 输入/输出规则排布(所有输出参数排布在输入参数之后):例如Kernel入口函数的参数排布为extern "C" __global__ __aicore__ void add_custom( GM_ADDR input1, GM_ADDR input2,uint32_t input3, GM_ADDR output)
  • 输入/输出交叉排布(输入/输出参数排布顺序有交叉):例如Kernel入口函数的参数排布为extern "C" __global__ __aicore__ void add_custom( GM_ADDR input1, GM_ADDR input2, GM_ADDR output,GM_ADDR input3),output参数排在input3之前。
  • 核函数直调工程场景的开发人员一般按此方式配置。
  • 以AddCustom算子为例(非原地算子),对应的json配置示例如下,参数说明参见表1
    {
        "op_type": "add_custom",
        "data_script": "",
        "gen_data": false,
        "params": [{
                    "name": "input_1",
                    "dtype": "float16",
                    "param_type": "input",
                    "shape": [1,16384],
                    "data_file": "input_1.bin"
                },
                {
                    "name": "output",
                    "dtype": "float16",
                    "param_type": "output",
                    "shape": [1,16384],
                    "data_file": "golden.bin"
                },
                {
                    "name": "input_2",
                    "dtype": "float16",
                    "param_type": "input",
                    "shape": [1,16384],
                    "data_file": "input_2.bin"
                },
        ],
        "kernel_info": {
            "kernel_source": "add_custom.cpp",
            "kernel_name": "add_custom",
            "kernel_includes": []
        }
    }
  • 以AddCustom算子为例(原地算子),对应的json配置示例如下,参数说明参见表1
    {
        "op_type": "abs_custom",
        "data_script": "abs_golden.py",
        "gen_data": true,
        "checkpoint_dump_path": "",
        "params": [
               
                {
                    "name": "x",
                    "dtype": "float16",
                    "param_type": "input",                
                    "shape": [1,32],
                    "data_file": "x.bin"
                },
                {
                    "name": "x",
                    "dtype": "float16",
                    "param_type": "output",               
                    "shape": [1,32],
                    "data_file": "ref_x.bin"
                },
                {
                    "name": "tileNumIn",
                    "dtype": "uint32",
                    "param_type": "input",
                    "shape": null,
                    "data_value": 8
                }
        ],
        "kernel_info": {
            "kernel_source": "abs_custom.cpp", 
            "kernel_name": "abs_custom",
            "kernel_includes": []
        } 
    }
表1 params归一格式的算子json全量参数说明

参数名

数据类型

参数说明

取值说明

是否必选

op_type

string

算子名。

与待调测算子严格匹配。

data_script

string

数据生成脚本(python),用于生成输入和标杆数据。

根据实际情况设置,如"/home/flash_attention_golden.py"。

说明:

若无数据生成脚本,填写空字符或null。

gen_data

bool

是否根据data_script生成输入和标杆数据。

  • true:采用脚本生成数据。
  • false:不采用脚本生成数据,默认false。

params

name

string

核函数输入/输出的参数名。

根据实际情况设置。

dtype

string

输入/输出的数据类型。

目前支持bool、int、int8、int16、int32、int64、uint8、uint16、uint32、uint64、float16、float32、float64、bfloat16。

说明:

算子json配置时dtype仅允许输入一种数据类型,不支持多种数据类型。

param_type

string

标识该节点是输入或输出。

  • input:表示为输入节点。
  • output:表示为输出节点。

shape

list

输入/输出的shape。

根据算子实际shape填写,例如[24,20,144,8]。

说明:

当输入为Scalar时,shape填null。

data_file

string

  • 当param_type为input:指定输入数据bin文件。
  • 当param_type为output:指定标杆数据bin文件。

根据实际情况设置数据bin文件路径,必须为绝对路径,例如"/home/data.bin"。

说明:
  • 当data_file设为空字符或null,表示不对运行输出作精度比对。
  • 当输入为Scalar时,data_file字段删除,只需配置data_value。

data_value

由dtype确定

输入的Scalar值。

根据实际情况填写。

说明:
  • 仅当param_type为input才可以配置该参数。
  • data_value与data_file互斥。若配置data_value则data_file必须删除,且shape必须为null,表示本节点是Scalar输入。

kernel_info

说明:

核函数直调工程场景需要设置kernel文件相关的配置。

kernel_source

string

Kernel入口源文件绝对路径,注意格式是“绝对路径+文件名”。

根据开发的核函数信息填写。

kernel_name

string

Kernel入口函数名。

根据开发的核函数信息填写。

kernel_includes

list

Kernel文件依赖的头文件所在的路径。

可为[],也可填入多个路径。

特殊格式输入

  • 场景1:支持Scalar格式的输入。

    当输入为Scalar格式,json中“params”配置项中删除data_file,param_type配为“input”,shape配为null,data_value配为指定的标量值。

    {
        "op_type": "xxxx",
        "data_script": "",
        "gen_data": false,
        "params": [{
                    "name": "input_1",
                    "dtype": "float16",
                    "param_type": "input",
                    "shape": null,
                  "data_value": 8
                },
                ......
        ]
    }
  • 场景2:支持TensorList格式的输入。
    当输入为TensorList格式,该参数需要用[ ]表示,List中的每一项表示一个Tensor,示例如下:
    {
        "op_type": "xxxx",
        "data_script": "",
        "gen_data": false,
        "params": [
                # 输入为tensor list
                [{
                    "name": "input_1",
                    "dtype": "float16",
                    "param_type": "input",
                    "shape": [1,16384],
                    "data_file": "input_1.bin"
                },  
                {
                    "name": "input_2",
                    "dtype": "float16",
                    "param_type": "input",
                    "shape": [1,16384],
                    "data_file": "input_2.bin"
                }],
                { 
                    "name": "output",
                    "dtype": "float16",
                    "param_type": "output",
                    "shape": [1,16384],
                    "data_file": "golden.bin"
                },
        ],
        "kernel_info": {
            "kernel_source": "add_custom.cpp",
            "kernel_name": "add_custom",
            "kernel_includes": []
        }
    }
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词