From 061bb9d50c5a8654d91289fd87059b4c0c3102de Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Sat, 2 Sep 2023 10:41:52 +0800 Subject: [PATCH] [NewIR]Refine and Split CINN Dilact directory (#56805) * [NewIR]Refine CINN Dilact directory * fix conflict * fix deps * fix unittest deps --- paddle/cinn/hlir/dialect/CMakeLists.txt | 69 +------------------ .../hlir/dialect/cinn_dialect/CMakeLists.txt | 1 + .../dialect/cinn_dialect/ir/CMakeLists.txt | 61 ++++++++++++++++ .../{ => cinn_dialect/ir}/cinn_dialect.cc | 6 +- .../{ => cinn_dialect/ir}/cinn_dialect.h | 0 .../{ => cinn_dialect/ir}/cinn_ops.yaml | 0 .../dialect/generated/cinn_ops.parsed.yaml | 31 +++++++++ .../dialect/runtime_dialect/CMakeLists.txt | 1 + .../dialect/runtime_dialect/ir/CMakeLists.txt | 4 ++ .../{ => runtime_dialect/ir}/jit_kernel_op.cc | 2 +- .../{ => runtime_dialect/ir}/jit_kernel_op.h | 0 .../ir}/runtime_dialect.cc | 4 +- .../ir}/runtime_dialect.h | 0 .../cinn/hlir/framework/convert_to_dialect.cc | 4 +- .../new_executor/instruction/CMakeLists.txt | 2 +- .../instruction/cinn_jit_instruction.cc | 4 +- test/cpp/ir/cinn/CMakeLists.txt | 1 + test/cpp/ir/cinn/jit_instruction_test.cc | 4 +- test/cpp/ir/cinn/new_ir_compiler_test.cc | 4 +- 19 files changed, 116 insertions(+), 82 deletions(-) create mode 100644 paddle/cinn/hlir/dialect/cinn_dialect/CMakeLists.txt create mode 100644 paddle/cinn/hlir/dialect/cinn_dialect/ir/CMakeLists.txt rename paddle/cinn/hlir/dialect/{ => cinn_dialect/ir}/cinn_dialect.cc (86%) rename paddle/cinn/hlir/dialect/{ => cinn_dialect/ir}/cinn_dialect.h (100%) rename paddle/cinn/hlir/dialect/{ => cinn_dialect/ir}/cinn_ops.yaml (100%) create mode 100644 paddle/cinn/hlir/dialect/generated/cinn_ops.parsed.yaml create mode 100644 paddle/cinn/hlir/dialect/runtime_dialect/CMakeLists.txt create mode 100644 paddle/cinn/hlir/dialect/runtime_dialect/ir/CMakeLists.txt rename paddle/cinn/hlir/dialect/{ => runtime_dialect/ir}/jit_kernel_op.cc (95%) rename paddle/cinn/hlir/dialect/{ => runtime_dialect/ir}/jit_kernel_op.h (100%) rename paddle/cinn/hlir/dialect/{ => runtime_dialect/ir}/runtime_dialect.cc (87%) rename paddle/cinn/hlir/dialect/{ => runtime_dialect/ir}/runtime_dialect.h (100%) diff --git a/paddle/cinn/hlir/dialect/CMakeLists.txt b/paddle/cinn/hlir/dialect/CMakeLists.txt index 68798ede2e5..5d30ab6d345 100755 --- a/paddle/cinn/hlir/dialect/CMakeLists.txt +++ b/paddle/cinn/hlir/dialect/CMakeLists.txt @@ -1,67 +1,2 @@ -# TODO(Aurelius84): new_ir_compiler depends on pd_dialect and could -# not found under CINN_ONLY mode -if(NOT CINN_ONLY) - set(CINN_DIALECT_SOURCE_DIR "${PADDLE_SOURCE_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 - set(cinn_op_gen_parsed_yaml_file - ${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parse_op.py) - - set(cinn_op_gen_file - ${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py) - - set(cinn_op_compat_yaml_file - ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) - - set(cinn_op_yaml_file - ${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_parsed_yaml_files ${cinn_op_parsed_yaml_file}) - - set(cinn_op_namespace cinn,dialect) - set(cinn_dialect_name cinn) - set(cinn_op_header_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.h) - set(cinn_op_source_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.cc) - set(cinn_op_header_file_tmp ${cinn_op_header_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( - OUTPUT ${cinn_op_header_file} ${cinn_op_source_file} - COMMAND - ${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files - ${cinn_op_parsed_yaml_files} --op_compat_yaml_file - ${cinn_op_compat_yaml_file} --namespaces ${cinn_op_namespace} - --dialect_name ${cinn_dialect_name} --op_def_h_file - ${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} - ${cinn_op_header_file} - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_source_file_tmp} - ${cinn_op_source_file} - DEPENDS ${cinn_op_gen_file} ${cinn_op_parsed_yaml_file} - ${cinn_op_compat_yaml_file} - VERBATIM) - - cinn_cc_library( - cinn_dialect - SRCS - runtime_dialect.cc - jit_kernel_op.cc - cinn_dialect.cc - cinn_op.cc - DEPS - pd_dialect) - - target_include_directories(cinn_dialect PRIVATE ${CINN_DIALECT_BINARY_DIR}) -endif() +add_subdirectory(cinn_dialect) +add_subdirectory(runtime_dialect) diff --git a/paddle/cinn/hlir/dialect/cinn_dialect/CMakeLists.txt b/paddle/cinn/hlir/dialect/cinn_dialect/CMakeLists.txt new file mode 100644 index 00000000000..dd1b708ce9f --- /dev/null +++ b/paddle/cinn/hlir/dialect/cinn_dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ir) diff --git a/paddle/cinn/hlir/dialect/cinn_dialect/ir/CMakeLists.txt b/paddle/cinn/hlir/dialect/cinn_dialect/ir/CMakeLists.txt new file mode 100644 index 00000000000..5fa53f74cc4 --- /dev/null +++ b/paddle/cinn/hlir/dialect/cinn_dialect/ir/CMakeLists.txt @@ -0,0 +1,61 @@ +# TODO(Aurelius84): new_ir_compiler depends on pd_dialect and could +# not found under CINN_ONLY mode +if(NOT CINN_ONLY) + set(CINN_DIALECT_BINARY_DIR + "${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect/cinn_dialect/ir") + + # 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 + ${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py) + + set(cinn_op_compat_yaml_file + ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) + + set(cinn_op_yaml_file + ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/cinn_dialect/ir/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_parsed_yaml_files ${cinn_op_parsed_yaml_file}) + + set(cinn_op_namespace cinn,dialect) + set(cinn_dialect_name cinn) + set(cinn_op_header_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.h) + set(cinn_op_source_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.cc) + set(cinn_op_header_file_tmp ${cinn_op_header_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( + OUTPUT ${cinn_op_header_file} ${cinn_op_source_file} + COMMAND + ${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files + ${cinn_op_parsed_yaml_files} --op_compat_yaml_file + ${cinn_op_compat_yaml_file} --namespaces ${cinn_op_namespace} + --dialect_name ${cinn_dialect_name} --op_def_h_file + ${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} + ${cinn_op_header_file} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_source_file_tmp} + ${cinn_op_source_file} + DEPENDS ${cinn_op_gen_file} ${cinn_op_parsed_yaml_file} + ${cinn_op_compat_yaml_file} + VERBATIM) + + cinn_cc_library(cinn_dialect SRCS cinn_dialect.cc ${cinn_op_source_file} DEPS + pd_dialect) + + target_include_directories(cinn_dialect PRIVATE ${CINN_DIALECT_BINARY_DIR}) +endif() diff --git a/paddle/cinn/hlir/dialect/cinn_dialect.cc b/paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.cc similarity index 86% rename from paddle/cinn/hlir/dialect/cinn_dialect.cc rename to paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.cc index 9bc6c6ff8c9..9e8ccfb6492 100644 --- a/paddle/cinn/hlir/dialect/cinn_dialect.cc +++ b/paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/cinn/hlir/dialect/cinn_dialect.h" +#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.h" // NOTE(chenxi67): File cinn_op.h is generated by op_gen.py, see details in // paddle/cinn/hlir/dialect/CMakeLists.txt. -#include "paddle/cinn/hlir/dialect/cinn_op.h" +#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_op.h" namespace cinn { namespace dialect { @@ -32,7 +32,7 @@ void CinnDialect::initialize() { // paddle/cinn/hlir/dialect/CMakeLists.txt. RegisterOps< #define GET_OP_LIST -#include "paddle/cinn/hlir/dialect/cinn_op.h" // NOLINT +#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_op.h" // NOLINT >(); } diff --git a/paddle/cinn/hlir/dialect/cinn_dialect.h b/paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.h similarity index 100% rename from paddle/cinn/hlir/dialect/cinn_dialect.h rename to paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.h diff --git a/paddle/cinn/hlir/dialect/cinn_ops.yaml b/paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_ops.yaml similarity index 100% rename from paddle/cinn/hlir/dialect/cinn_ops.yaml rename to paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_ops.yaml diff --git a/paddle/cinn/hlir/dialect/generated/cinn_ops.parsed.yaml b/paddle/cinn/hlir/dialect/generated/cinn_ops.parsed.yaml new file mode 100644 index 00000000000..b345bb69908 --- /dev/null +++ b/paddle/cinn/hlir/dialect/generated/cinn_ops.parsed.yaml @@ -0,0 +1,31 @@ +- 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: null diff --git a/paddle/cinn/hlir/dialect/runtime_dialect/CMakeLists.txt b/paddle/cinn/hlir/dialect/runtime_dialect/CMakeLists.txt new file mode 100644 index 00000000000..dd1b708ce9f --- /dev/null +++ b/paddle/cinn/hlir/dialect/runtime_dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ir) diff --git a/paddle/cinn/hlir/dialect/runtime_dialect/ir/CMakeLists.txt b/paddle/cinn/hlir/dialect/runtime_dialect/ir/CMakeLists.txt new file mode 100644 index 00000000000..1df80a5bb3f --- /dev/null +++ b/paddle/cinn/hlir/dialect/runtime_dialect/ir/CMakeLists.txt @@ -0,0 +1,4 @@ +if(NOT CINN_ONLY) + cinn_cc_library(runtime_dialect SRCS runtime_dialect.cc jit_kernel_op.cc DEPS + ir_core) +endif() diff --git a/paddle/cinn/hlir/dialect/jit_kernel_op.cc b/paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.cc similarity index 95% rename from paddle/cinn/hlir/dialect/jit_kernel_op.cc rename to paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.cc index dc25665e093..49e3685a847 100644 --- a/paddle/cinn/hlir/dialect/jit_kernel_op.cc +++ b/paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/cinn/hlir/dialect/jit_kernel_op.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h" #include "paddle/ir/core/builtin_attribute.h" #include "paddle/ir/core/enforce.h" diff --git a/paddle/cinn/hlir/dialect/jit_kernel_op.h b/paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h similarity index 100% rename from paddle/cinn/hlir/dialect/jit_kernel_op.h rename to paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h diff --git a/paddle/cinn/hlir/dialect/runtime_dialect.cc b/paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.cc similarity index 87% rename from paddle/cinn/hlir/dialect/runtime_dialect.cc rename to paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.cc index c3c90be703f..c21d21f1121 100644 --- a/paddle/cinn/hlir/dialect/runtime_dialect.cc +++ b/paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.cc @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/cinn/hlir/dialect/runtime_dialect.h" -#include "paddle/cinn/hlir/dialect/jit_kernel_op.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h" namespace cinn { namespace dialect { diff --git a/paddle/cinn/hlir/dialect/runtime_dialect.h b/paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h similarity index 100% rename from paddle/cinn/hlir/dialect/runtime_dialect.h rename to paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h diff --git a/paddle/cinn/hlir/framework/convert_to_dialect.cc b/paddle/cinn/hlir/framework/convert_to_dialect.cc index 63a1dd247a6..306e27dc1fe 100644 --- a/paddle/cinn/hlir/framework/convert_to_dialect.cc +++ b/paddle/cinn/hlir/framework/convert_to_dialect.cc @@ -17,8 +17,8 @@ #include #include -#include "paddle/cinn/hlir/dialect/jit_kernel_op.h" -#include "paddle/cinn/hlir/dialect/runtime_dialect.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h" #include "paddle/cinn/hlir/framework/program.h" #include "paddle/ir/core/builtin_attribute.h" #include "paddle/ir/core/program.h" diff --git a/paddle/fluid/framework/new_executor/instruction/CMakeLists.txt b/paddle/fluid/framework/new_executor/instruction/CMakeLists.txt index 17c8f8cd762..8a9247859b8 100644 --- a/paddle/fluid/framework/new_executor/instruction/CMakeLists.txt +++ b/paddle/fluid/framework/new_executor/instruction/CMakeLists.txt @@ -8,5 +8,5 @@ if(WITH_CINN AND NOT CINN_ONLY) cc_library( cinn_jit_instruction NOT_FOR_INFER SRCS cinn_jit_instruction.cc - DEPS phi cinnapi cinn_dialect) + DEPS phi cinnapi cinn_dialect runtime_dialect) endif() diff --git a/paddle/fluid/framework/new_executor/instruction/cinn_jit_instruction.cc b/paddle/fluid/framework/new_executor/instruction/cinn_jit_instruction.cc index f0dec72fc29..d56ccc7b7ba 100644 --- a/paddle/fluid/framework/new_executor/instruction/cinn_jit_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/cinn_jit_instruction.cc @@ -14,8 +14,8 @@ #include "paddle/fluid/framework/new_executor/instruction/cinn_jit_instruction.h" -#include "paddle/cinn/hlir/dialect/jit_kernel_op.h" -#include "paddle/cinn/hlir/dialect/runtime_dialect.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h" #include "paddle/cinn/hlir/framework/instruction.h" #include "paddle/fluid/framework/paddle2cinn/transform_type.h" diff --git a/test/cpp/ir/cinn/CMakeLists.txt b/test/cpp/ir/cinn/CMakeLists.txt index 20a3c18b100..360b6fc29ac 100644 --- a/test/cpp/ir/cinn/CMakeLists.txt +++ b/test/cpp/ir/cinn/CMakeLists.txt @@ -6,6 +6,7 @@ if(WITH_TESTING AND WITH_CINN) DEPS new_ir_compiler convert_to_dialect + runtime_dialect ir phi gtest diff --git a/test/cpp/ir/cinn/jit_instruction_test.cc b/test/cpp/ir/cinn/jit_instruction_test.cc index b7088ef448e..9b6f5b2c208 100644 --- a/test/cpp/ir/cinn/jit_instruction_test.cc +++ b/test/cpp/ir/cinn/jit_instruction_test.cc @@ -27,8 +27,8 @@ #include "paddle/ir/core/ir_context.h" #include "paddle/ir/core/program.h" -#include "paddle/cinn/hlir/dialect/jit_kernel_op.h" -#include "paddle/cinn/hlir/dialect/runtime_dialect.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h" #include "paddle/cinn/hlir/framework/convert_to_dialect.h" #include "paddle/cinn/hlir/framework/new_ir_compiler.h" #include "paddle/cinn/utils/data_util.h" diff --git a/test/cpp/ir/cinn/new_ir_compiler_test.cc b/test/cpp/ir/cinn/new_ir_compiler_test.cc index 4b55a71f8e9..1ea7a455e12 100644 --- a/test/cpp/ir/cinn/new_ir_compiler_test.cc +++ b/test/cpp/ir/cinn/new_ir_compiler_test.cc @@ -26,8 +26,8 @@ #include "paddle/cinn/utils/data_util.h" -#include "paddle/cinn/hlir/dialect/jit_kernel_op.h" -#include "paddle/cinn/hlir/dialect/runtime_dialect.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h" +#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/runtime_dialect.h" #include "paddle/cinn/hlir/framework/convert_to_dialect.h" #include "paddle/cinn/hlir/framework/new_ir_compiler.h" -- GitLab