Skip to content

Commit 061bb9d

Browse files
authored
[NewIR]Refine and Split CINN Dilact directory (#56805)
* [NewIR]Refine CINN Dilact directory * fix conflict * fix deps * fix unittest deps
1 parent fa75ebe commit 061bb9d

File tree

19 files changed

+116
-82
lines changed

19 files changed

+116
-82
lines changed
Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,2 @@
1-
# TODO(Aurelius84): new_ir_compiler depends on pd_dialect and could
2-
# not found under CINN_ONLY mode
3-
if(NOT CINN_ONLY)
4-
set(CINN_DIALECT_SOURCE_DIR "${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect")
5-
set(CINN_DIALECT_BINARY_DIR "${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect")
6-
7-
# Generate cinn_dialect files defining op using op_gen_file
8-
set(cinn_op_gen_parsed_yaml_file
9-
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parse_op.py)
10-
11-
set(cinn_op_gen_file
12-
${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py)
13-
14-
set(cinn_op_compat_yaml_file
15-
${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml)
16-
17-
set(cinn_op_yaml_file
18-
${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/cinn_ops.yaml)
19-
20-
set(parsed_op_dir ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/generated)
21-
22-
set(cinn_op_parsed_yaml_file ${parsed_op_dir}/cinn_ops.parsed.yaml)
23-
24-
set(cinn_op_parsed_yaml_files ${cinn_op_parsed_yaml_file})
25-
26-
set(cinn_op_namespace cinn,dialect)
27-
set(cinn_dialect_name cinn)
28-
set(cinn_op_header_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.h)
29-
set(cinn_op_source_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.cc)
30-
set(cinn_op_header_file_tmp ${cinn_op_header_file}.tmp)
31-
set(cinn_op_source_file_tmp ${cinn_op_source_file}.tmp)
32-
33-
add_custom_command(
34-
OUTPUT ${cinn_op_parsed_yaml_file}
35-
COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir}
36-
COMMAND ${PYTHON_EXECUTABLE} ${cinn_op_gen_parsed_yaml_file} --op_yaml_path
37-
${cinn_op_yaml_file} --output_path ${cinn_op_parsed_yaml_file}
38-
VERBATIM)
39-
40-
add_custom_command(
41-
OUTPUT ${cinn_op_header_file} ${cinn_op_source_file}
42-
COMMAND
43-
${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files
44-
${cinn_op_parsed_yaml_files} --op_compat_yaml_file
45-
${cinn_op_compat_yaml_file} --namespaces ${cinn_op_namespace}
46-
--dialect_name ${cinn_dialect_name} --op_def_h_file
47-
${cinn_op_header_file_tmp} --op_def_cc_file ${cinn_op_source_file_tmp}
48-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_header_file_tmp}
49-
${cinn_op_header_file}
50-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_source_file_tmp}
51-
${cinn_op_source_file}
52-
DEPENDS ${cinn_op_gen_file} ${cinn_op_parsed_yaml_file}
53-
${cinn_op_compat_yaml_file}
54-
VERBATIM)
55-
56-
cinn_cc_library(
57-
cinn_dialect
58-
SRCS
59-
runtime_dialect.cc
60-
jit_kernel_op.cc
61-
cinn_dialect.cc
62-
cinn_op.cc
63-
DEPS
64-
pd_dialect)
65-
66-
target_include_directories(cinn_dialect PRIVATE ${CINN_DIALECT_BINARY_DIR})
67-
endif()
1+
add_subdirectory(cinn_dialect)
2+
add_subdirectory(runtime_dialect)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(ir)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# TODO(Aurelius84): new_ir_compiler depends on pd_dialect and could
2+
# not found under CINN_ONLY mode
3+
if(NOT CINN_ONLY)
4+
set(CINN_DIALECT_BINARY_DIR
5+
"${PADDLE_BINARY_DIR}/paddle/cinn/hlir/dialect/cinn_dialect/ir")
6+
7+
# Generate cinn_dialect files defining op using op_gen_file
8+
set(cinn_op_gen_parsed_yaml_file
9+
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parse_op.py)
10+
11+
set(cinn_op_gen_file
12+
${PADDLE_SOURCE_DIR}/paddle/fluid/ir/dialect/op_generator/op_gen.py)
13+
14+
set(cinn_op_compat_yaml_file
15+
${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml)
16+
17+
set(cinn_op_yaml_file
18+
${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_ops.yaml
19+
)
20+
21+
set(parsed_op_dir ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/generated)
22+
23+
set(cinn_op_parsed_yaml_file ${parsed_op_dir}/cinn_ops.parsed.yaml)
24+
25+
set(cinn_op_parsed_yaml_files ${cinn_op_parsed_yaml_file})
26+
27+
set(cinn_op_namespace cinn,dialect)
28+
set(cinn_dialect_name cinn)
29+
set(cinn_op_header_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.h)
30+
set(cinn_op_source_file ${CINN_DIALECT_BINARY_DIR}/cinn_op.cc)
31+
set(cinn_op_header_file_tmp ${cinn_op_header_file}.tmp)
32+
set(cinn_op_source_file_tmp ${cinn_op_source_file}.tmp)
33+
34+
add_custom_command(
35+
OUTPUT ${cinn_op_parsed_yaml_file}
36+
COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir}
37+
COMMAND ${PYTHON_EXECUTABLE} ${cinn_op_gen_parsed_yaml_file} --op_yaml_path
38+
${cinn_op_yaml_file} --output_path ${cinn_op_parsed_yaml_file}
39+
VERBATIM)
40+
41+
add_custom_command(
42+
OUTPUT ${cinn_op_header_file} ${cinn_op_source_file}
43+
COMMAND
44+
${PYTHON_EXECUTABLE} ${cinn_op_gen_file} --op_yaml_files
45+
${cinn_op_parsed_yaml_files} --op_compat_yaml_file
46+
${cinn_op_compat_yaml_file} --namespaces ${cinn_op_namespace}
47+
--dialect_name ${cinn_dialect_name} --op_def_h_file
48+
${cinn_op_header_file_tmp} --op_def_cc_file ${cinn_op_source_file_tmp}
49+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_header_file_tmp}
50+
${cinn_op_header_file}
51+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cinn_op_source_file_tmp}
52+
${cinn_op_source_file}
53+
DEPENDS ${cinn_op_gen_file} ${cinn_op_parsed_yaml_file}
54+
${cinn_op_compat_yaml_file}
55+
VERBATIM)
56+
57+
cinn_cc_library(cinn_dialect SRCS cinn_dialect.cc ${cinn_op_source_file} DEPS
58+
pd_dialect)
59+
60+
target_include_directories(cinn_dialect PRIVATE ${CINN_DIALECT_BINARY_DIR})
61+
endif()

paddle/cinn/hlir/dialect/cinn_dialect.cc renamed to paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "paddle/cinn/hlir/dialect/cinn_dialect.h"
15+
#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_dialect.h"
1616
// NOTE(chenxi67): File cinn_op.h is generated by op_gen.py, see details in
1717
// paddle/cinn/hlir/dialect/CMakeLists.txt.
18-
#include "paddle/cinn/hlir/dialect/cinn_op.h"
18+
#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_op.h"
1919

2020
namespace cinn {
2121
namespace dialect {
@@ -32,7 +32,7 @@ void CinnDialect::initialize() {
3232
// paddle/cinn/hlir/dialect/CMakeLists.txt.
3333
RegisterOps<
3434
#define GET_OP_LIST
35-
#include "paddle/cinn/hlir/dialect/cinn_op.h" // NOLINT
35+
#include "paddle/cinn/hlir/dialect/cinn_dialect/ir/cinn_op.h" // NOLINT
3636
>();
3737
}
3838

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
- name: add
2+
inputs:
3+
- typename: Tensor
4+
name: x
5+
optional: false
6+
no_need_buffer: false
7+
data_transform: {}
8+
- typename: Tensor
9+
name: y
10+
optional: false
11+
no_need_buffer: false
12+
data_transform: {}
13+
attrs: []
14+
outputs:
15+
- {typename: Tensor, name: out, optional: false, intermediate: false}
16+
no_need_buffer: null
17+
data_transform: null
18+
infer_meta:
19+
func: ElementwiseInferMeta
20+
param: [x, y]
21+
kernel:
22+
func: [add]
23+
param: [x, y]
24+
backend: null
25+
layout: null
26+
data_type: null
27+
dispatch: {add: null}
28+
force_backend: null
29+
inplace: {out: x}
30+
view: null
31+
backward: null
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(ir)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if(NOT CINN_ONLY)
2+
cinn_cc_library(runtime_dialect SRCS runtime_dialect.cc jit_kernel_op.cc DEPS
3+
ir_core)
4+
endif()

paddle/cinn/hlir/dialect/jit_kernel_op.cc renamed to paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "paddle/cinn/hlir/dialect/jit_kernel_op.h"
15+
#include "paddle/cinn/hlir/dialect/runtime_dialect/ir/jit_kernel_op.h"
1616

1717
#include "paddle/ir/core/builtin_attribute.h"
1818
#include "paddle/ir/core/enforce.h"

0 commit comments

Comments
 (0)