Skip to content

Commit 9018371

Browse files
authored
fix vs2017 limit (#60528)
1 parent 5f1727b commit 9018371

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed

paddle/cinn/hlir/dialect/operator/ir/op_dialect.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,25 @@ void OperatorDialect::initialize() {
3333
// NOTE(chenxi67): GET_OP_LIST is defined in cinn_op.h which is
3434
// generated by op_gen.py, see details in
3535
// paddle/cinn/hlir/dialect/CMakeLists.txt.
36+
37+
// NOTE(cocoshe): VS2017 has a limit on the length of template
38+
// parameters, which causes "fatal error C1202".
39+
// Split GET_OP_LIST into two part on WIN32 here.
40+
#ifdef WIN32
41+
RegisterOps<
42+
#define GET_OP_LIST1
43+
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op_info.cc" // NOLINT
44+
>();
45+
RegisterOps<
46+
#define GET_OP_LIST2
47+
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op_info.cc" // NOLINT
48+
>();
49+
#else
3650
RegisterOps<
3751
#define GET_OP_LIST
3852
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op_info.cc" // NOLINT
3953
>();
54+
#endif
4055
RegisterOp<GroupOp>();
4156
RegisterOp<ConcatOp>();
4257
RegisterOp<SplitOp>();

paddle/fluid/pir/dialect/op_generator/op_gen.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,24 @@ class {TEST_API} {op_name} : public pir::Op<{op_name}{interfaces}{traits}> {{
167167
168168
{define_type_id}
169169
"""
170-
171-
CC_OP_INFO_FILE_TEMPLATE = """#ifdef GET_OP_LIST
170+
# NOTE(cocoshe): Use CC_OP_INFO_FILE_TEMPLATE_WIN_PART1 to generate two GET_OP_LIST to avoid
171+
# "fatal error C1202: recursive type or function dependency context too complex" error
172+
# when compiling on vs2017 because the GET_OP_LIST is too long.
173+
# And use CC_OP_INFO_FILE_TEMPLATE_PART1 to generate just one GET_OP_LIST for other compiler.
174+
CC_OP_INFO_FILE_TEMPLATE_PART1 = """#ifdef GET_OP_LIST
172175
#undef GET_OP_LIST
173176
{op_declare}
177+
"""
178+
179+
CC_OP_INFO_FILE_TEMPLATE_WIN_PART1 = """#ifdef GET_OP_LIST1
180+
#undef GET_OP_LIST1
181+
{op_declare_first_part}
182+
#elif defined(GET_OP_LIST2)
183+
#undef GET_OP_LIST2
184+
{op_declare_second_part}
185+
"""
186+
187+
CC_OP_INFO_FILE_TEMPLATE_PART2 = """
174188
#else
175189
// This file is generated by "paddle/fluid/pir/dialect/op_generator/op_gen.py"
176190
#include "{h_file}"
@@ -1994,11 +2008,33 @@ def OpGenerator(
19942008
op_to_multi_kernels_map_str = ""
19952009

19962010
if op_info_file is not None:
1997-
op_info_str = CC_OP_INFO_FILE_TEMPLATE.format(
1998-
op_declare=",".join(op_list_strs).replace("\n", ""),
1999-
op_to_multi_kernels_map=op_to_multi_kernels_map_str,
2000-
h_file=op_def_h_file[:-4],
2001-
)
2011+
if sys.platform == "win32":
2012+
n = len(op_list_strs) // 2
2013+
first_part_op_info = op_list_strs[:n]
2014+
second_part_op_info = op_list_strs[n:]
2015+
CC_OP_INFO_FILE_TEMPLATE = (
2016+
CC_OP_INFO_FILE_TEMPLATE_WIN_PART1
2017+
+ CC_OP_INFO_FILE_TEMPLATE_PART2
2018+
)
2019+
op_info_str = CC_OP_INFO_FILE_TEMPLATE.format(
2020+
op_declare_first_part=",".join(first_part_op_info).replace(
2021+
"\n", ""
2022+
),
2023+
op_declare_second_part=",".join(second_part_op_info).replace(
2024+
"\n", ""
2025+
),
2026+
op_to_multi_kernels_map=op_to_multi_kernels_map_str,
2027+
h_file=op_def_h_file[:-4],
2028+
)
2029+
else:
2030+
CC_OP_INFO_FILE_TEMPLATE = (
2031+
CC_OP_INFO_FILE_TEMPLATE_PART1 + CC_OP_INFO_FILE_TEMPLATE_PART2
2032+
)
2033+
op_info_str = CC_OP_INFO_FILE_TEMPLATE.format(
2034+
op_declare=",".join(op_list_strs).replace("\n", ""),
2035+
op_to_multi_kernels_map=op_to_multi_kernels_map_str,
2036+
h_file=op_def_h_file[:-4],
2037+
)
20022038

20032039
with open(op_info_file, 'w') as f:
20042040
f.write(op_info_str)

paddle/fluid/pir/dialect/operator/ir/op_dialect.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,26 @@ void OperatorDialect::initialize() {
156156
// paddle/fluid/pir/dialect/CMakeLists.txt.
157157
// NOTE(Ruting)GET_MANUAL_OP_LIST is define in manual_op.h"
158158
// use RegisterOps when list has more than two ops.
159+
160+
// NOTE(cocoshe): VS2017 has a limit on the length of template
161+
// parameters, which causes "fatal error C1202".
162+
// Split GET_OP_LIST into two part on WIN32 here.
163+
#ifdef WIN32
159164
RegisterOps<
160-
#define GET_OP_LIST
165+
#define GET_OP_LIST1
161166
#include "paddle/fluid/pir/dialect/operator/ir/pd_op_info.cc" // NOLINT
162167
>();
163168

169+
RegisterOps<
170+
#define GET_OP_LIST2
171+
#include "paddle/fluid/pir/dialect/operator/ir/pd_op_info.cc" // NOLINT
172+
>();
173+
#else
174+
RegisterOps<
175+
#define GET_OP_LIST
176+
#include "paddle/fluid/pir/dialect/operator/ir/pd_op_info.cc" // NOLINT
177+
>();
178+
#endif
164179
RegisterOps<
165180
#define GET_OP_LIST
166181
#include "paddle/fluid/pir/dialect/operator/ir/control_flow_op.cc" // NOLINT

paddle/fluid/pir/dialect/operator/ir/op_onednn_dialect.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,25 @@ void OneDNNOperatorDialect::initialize() {
4444
// paddle/fluid/pir/dialect/CMakeLists.txt.
4545
// NOTE(Ruting)GET_MANUAL_OP_LIST is define in manual_op.h"
4646
// use RegisterOps when list has more than two ops.
47+
48+
// NOTE(cocoshe): VS2017 has a limit on the length of template
49+
// parameters, which causes "fatal error C1202".
50+
// Split GET_OP_LIST into two part on WIN32 here.
51+
#ifdef WIN32
52+
RegisterOps<
53+
#define GET_OP_LIST1
54+
#include "paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.cc" // NOLINT
55+
>();
56+
RegisterOps<
57+
#define GET_OP_LIST2
58+
#include "paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.cc" // NOLINT
59+
>();
60+
#else
4761
RegisterOps<
4862
#define GET_OP_LIST
4963
#include "paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.cc" // NOLINT
5064
>();
65+
#endif
5166
}
5267

5368
void OneDNNOperatorDialect::PrintType(pir::Type type, std::ostream &os) const {

0 commit comments

Comments
 (0)