未验证 提交 e518058a 编写于 作者: C chen2016013 提交者: GitHub

[IR] Generate cinn_ops.parsed.yaml file from cinn_ops.yaml file (#56588)

* generate .parsed.yaml file from .yaml file

* code style fix

* bug fix

* remove backward op

* add generator/ folder

* add .gitignore

* fix bug : mkdir for .parsed.yaml file

* try to fix bug:add dir
上级 1aef42eb
...@@ -5,16 +5,23 @@ if(NOT CINN_ONLY) ...@@ -5,16 +5,23 @@ if(NOT CINN_ONLY)
set(CINN_DIALECT_BINARY_DIR "${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect") set(CINN_DIALECT_BINARY_DIR "${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect")
# Generate cinn_dialect files defining op using op_gen_file # Generate cinn_dialect files defining op using op_gen_file
set(cinn_op_gen_parsed_yaml_file
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parse_op.py)
set(cinn_op_gen_file set(cinn_op_gen_file
${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py) ${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py)
set(cinn_op_compat_yaml_file set(cinn_op_compat_yaml_file
${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml)
set(cinn_op_forward_yaml_file1 set(cinn_op_yaml_file
${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/cinn_ops.parsed.yaml) ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/cinn_ops.yaml)
set(parsed_op_dir ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/generated)
set(cinn_op_parsed_yaml_file ${parsed_op_dir}/cinn_ops.parsed.yaml)
set(cinn_op_yaml_files ${cinn_op_forward_yaml_file1}) set(cinn_op_parsed_yaml_files ${cinn_op_parsed_yaml_file})
set(cinn_op_namespace cinn,dialect) set(cinn_op_namespace cinn,dialect)
set(cinn_dialect_name cinn) set(cinn_dialect_name cinn)
...@@ -23,19 +30,26 @@ if(NOT CINN_ONLY) ...@@ -23,19 +30,26 @@ if(NOT CINN_ONLY)
set(cinn_op_header_file_tmp ${cinn_op_header_file}.tmp) set(cinn_op_header_file_tmp ${cinn_op_header_file}.tmp)
set(cinn_op_source_file_tmp ${cinn_op_source_file}.tmp) set(cinn_op_source_file_tmp ${cinn_op_source_file}.tmp)
add_custom_command(
OUTPUT ${cinn_op_parsed_yaml_file}
COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir}
COMMAND ${PYTHON_EXECUTABLE} ${cinn_op_gen_parsed_yaml_file} --op_yaml_path
${cinn_op_yaml_file} --output_path ${cinn_op_parsed_yaml_file}
VERBATIM)
add_custom_command( add_custom_command(
OUTPUT ${cinn_op_header_file} ${cinn_op_source_file} OUTPUT ${cinn_op_header_file} ${cinn_op_source_file}
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files ${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files
${cinn_op_yaml_files} --op_compat_yaml_file ${cinn_op_compat_yaml_file} ${cinn_op_parsed_yaml_files} --op_compat_yaml_file
--namespaces ${cinn_op_namespace} --dialect_name ${cinn_dialect_name} ${cinn_op_compat_yaml_file} --namespaces ${cinn_op_namespace}
--op_def_h_file ${cinn_op_header_file_tmp} --op_def_cc_file --dialect_name ${cinn_dialect_name} --op_def_h_file
${cinn_op_source_file_tmp} ${cinn_op_header_file_tmp} --op_def_cc_file ${cinn_op_source_file_tmp}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_header_file_tmp} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_header_file_tmp}
${cinn_op_header_file} ${cinn_op_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_source_file_tmp} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_source_file_tmp}
${cinn_op_source_file} ${cinn_op_source_file}
DEPENDS ${cinn_op_gen_file} ${cinn_op_forward_yaml_file1} DEPENDS ${cinn_op_gen_file} ${cinn_op_parsed_yaml_file}
${cinn_op_compat_yaml_file} ${cinn_op_compat_yaml_file}
VERBATIM) VERBATIM)
......
- name: add
inputs:
- typename: Tensor
name: x
optional: false
no_need_buffer: false
data_transform: {}
- typename: Tensor
name: y
optional: false
no_need_buffer: false
data_transform: {}
attrs: []
outputs:
- {typename: Tensor, name: out, optional: false, intermediate: false}
no_need_buffer: null
data_transform: null
infer_meta:
func: ElementwiseInferMeta
param: [x, y]
kernel:
func: [add]
param: [x, y]
backend: null
layout: null
data_type: null
dispatch: {add: null}
force_backend: null
inplace: {out: x}
view: null
backward: add_grad
- name: add_grad
inputs:
- typename: Tensor
name: x
optional: false
no_need_buffer: true
data_transform: {}
- typename: Tensor
name: y
optional: false
no_need_buffer: true
data_transform: {}
- typename: Tensor
name: out_grad
optional: false
no_need_buffer: false
data_transform: {}
attrs:
- {typename: int, name: axis, default_value: '-1'}
outputs:
- {typename: Tensor, name: x_grad, optional: false, intermediate: false}
- {typename: Tensor, name: y_grad, optional: false, intermediate: false}
no_need_buffer: [x, y]
data_transform: null
infer_meta:
func: GeneralBinaryGradInferMeta
param: [x, y]
kernel:
func: [add_grad]
param: [x, y, out_grad, axis]
backend: null
layout: null
data_type: null
dispatch: {add_grad: null}
force_backend: null
inplace: {x_grad: out_grad}
view: null
composite: {func_name: add_grad, func_args: 'x, y, out_grad, axis, x_grad, y_grad'}
backward: add_double_grad
forward:
name: add
inputs:
- {name: x, typename: Tensor}
- {name: y, typename: Tensor}
attrs: []
outputs:
- {name: out, typename: Tensor}
- op : add
args : (Tensor x, Tensor y)
output : Tensor(out)
infer_meta :
func : ElementwiseInferMeta
kernel :
func : add
inplace : (x -> out)
...@@ -1072,8 +1072,11 @@ def OpGenerator( ...@@ -1072,8 +1072,11 @@ def OpGenerator(
# =================================== # # =================================== #
# generate op vjp function str # generate op vjp function str
op_vjp_str = ''
op_vjp_str = ''
if dialect_name == "cinn":
logging.warning("cinn is currently not support Vjp function")
else:
# TODO(chenzhiyang) add vjp gen code # TODO(chenzhiyang) add vjp gen code
if ( if (
op_info.backward_name op_info.backward_name
...@@ -1100,7 +1103,7 @@ def OpGenerator( ...@@ -1100,7 +1103,7 @@ def OpGenerator(
ops_defined_list.append(op_infer_meta_str) ops_defined_list.append(op_infer_meta_str)
# NOTE(chenxi67)skip if dialect_name==cinn # NOTE(chenxi67)skip if dialect_name==cinn
if dialect_name == "cinn": if dialect_name == "cinn":
logging.warning("cinn is currently not support Vjp function") pass
else: else:
ops_vjp_defined_list.append(op_vjp_str) ops_vjp_defined_list.append(op_vjp_str)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册