Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vs2017 limit #60528

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions paddle/cinn/hlir/dialect/operator/ir/op_dialect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@ void OperatorDialect::initialize() {
// NOTE(chenxi67): GET_OP_LIST is defined in cinn_op.h which is
// generated by op_gen.py, see details in
// paddle/cinn/hlir/dialect/CMakeLists.txt.

// NOTE(cocoshe): VS2017 has a limit on the length of template
// parameters, which causes "fatal error C1202".
// Split GET_OP_LIST into two part on WIN32 here.
#ifdef WIN32
RegisterOps<
#define GET_OP_LIST1
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op_info.cc" // NOLINT
>();
RegisterOps<
#define GET_OP_LIST2
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op_info.cc" // NOLINT
>();
#else
RegisterOps<
#define GET_OP_LIST
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op_info.cc" // NOLINT
>();
#endif
RegisterOp<GroupOp>();
RegisterOp<ConcatOp>();
RegisterOp<SplitOp>();
Expand Down
50 changes: 43 additions & 7 deletions paddle/fluid/pir/dialect/op_generator/op_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,24 @@ class {TEST_API} {op_name} : public pir::Op<{op_name}{interfaces}{traits}> {{

{define_type_id}
"""

CC_OP_INFO_FILE_TEMPLATE = """#ifdef GET_OP_LIST
# NOTE(cocoshe): Use CC_OP_INFO_FILE_TEMPLATE_WIN_PART1 to generate two GET_OP_LIST to avoid
# "fatal error C1202: recursive type or function dependency context too complex" error
# when compiling on vs2017 because the GET_OP_LIST is too long.
# And use CC_OP_INFO_FILE_TEMPLATE_PART1 to generate just one GET_OP_LIST for other compiler.
CC_OP_INFO_FILE_TEMPLATE_PART1 = """#ifdef GET_OP_LIST
#undef GET_OP_LIST
{op_declare}
"""

CC_OP_INFO_FILE_TEMPLATE_WIN_PART1 = """#ifdef GET_OP_LIST1
#undef GET_OP_LIST1
{op_declare_first_part}
#elif defined(GET_OP_LIST2)
#undef GET_OP_LIST2
{op_declare_second_part}
"""

CC_OP_INFO_FILE_TEMPLATE_PART2 = """
#else
// This file is generated by "paddle/fluid/pir/dialect/op_generator/op_gen.py"
#include "{h_file}"
Expand Down Expand Up @@ -1994,11 +2008,33 @@ def OpGenerator(
op_to_multi_kernels_map_str = ""

if op_info_file is not None:
op_info_str = CC_OP_INFO_FILE_TEMPLATE.format(
op_declare=",".join(op_list_strs).replace("\n", ""),
op_to_multi_kernels_map=op_to_multi_kernels_map_str,
h_file=op_def_h_file[:-4],
)
if sys.platform == "win32":
n = len(op_list_strs) // 2
first_part_op_info = op_list_strs[:n]
second_part_op_info = op_list_strs[n:]
CC_OP_INFO_FILE_TEMPLATE = (
CC_OP_INFO_FILE_TEMPLATE_WIN_PART1
+ CC_OP_INFO_FILE_TEMPLATE_PART2
)
op_info_str = CC_OP_INFO_FILE_TEMPLATE.format(
op_declare_first_part=",".join(first_part_op_info).replace(
"\n", ""
),
op_declare_second_part=",".join(second_part_op_info).replace(
"\n", ""
),
op_to_multi_kernels_map=op_to_multi_kernels_map_str,
h_file=op_def_h_file[:-4],
)
else:
CC_OP_INFO_FILE_TEMPLATE = (
CC_OP_INFO_FILE_TEMPLATE_PART1 + CC_OP_INFO_FILE_TEMPLATE_PART2
)
op_info_str = CC_OP_INFO_FILE_TEMPLATE.format(
op_declare=",".join(op_list_strs).replace("\n", ""),
op_to_multi_kernels_map=op_to_multi_kernels_map_str,
h_file=op_def_h_file[:-4],
)

with open(op_info_file, 'w') as f:
f.write(op_info_str)
Expand Down
17 changes: 16 additions & 1 deletion paddle/fluid/pir/dialect/operator/ir/op_dialect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,26 @@ void OperatorDialect::initialize() {
// paddle/fluid/pir/dialect/CMakeLists.txt.
// NOTE(Ruting)GET_MANUAL_OP_LIST is define in manual_op.h"
// use RegisterOps when list has more than two ops.

// NOTE(cocoshe): VS2017 has a limit on the length of template
// parameters, which causes "fatal error C1202".
// Split GET_OP_LIST into two part on WIN32 here.
#ifdef WIN32
RegisterOps<
#define GET_OP_LIST
#define GET_OP_LIST1
#include "paddle/fluid/pir/dialect/operator/ir/pd_op_info.cc" // NOLINT
>();

RegisterOps<
#define GET_OP_LIST2
#include "paddle/fluid/pir/dialect/operator/ir/pd_op_info.cc" // NOLINT
>();
#else
RegisterOps<
#define GET_OP_LIST
#include "paddle/fluid/pir/dialect/operator/ir/pd_op_info.cc" // NOLINT
>();
#endif
RegisterOps<
#define GET_OP_LIST
#include "paddle/fluid/pir/dialect/operator/ir/control_flow_op.cc" // NOLINT
Expand Down
15 changes: 15 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/op_onednn_dialect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,25 @@ void OneDNNOperatorDialect::initialize() {
// paddle/fluid/pir/dialect/CMakeLists.txt.
// NOTE(Ruting)GET_MANUAL_OP_LIST is define in manual_op.h"
// use RegisterOps when list has more than two ops.

// NOTE(cocoshe): VS2017 has a limit on the length of template
// parameters, which causes "fatal error C1202".
// Split GET_OP_LIST into two part on WIN32 here.
#ifdef WIN32
RegisterOps<
#define GET_OP_LIST1
#include "paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.cc" // NOLINT
>();
RegisterOps<
#define GET_OP_LIST2
#include "paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.cc" // NOLINT
>();
#else
RegisterOps<
#define GET_OP_LIST
#include "paddle/fluid/pir/dialect/operator/ir/pd_onednn_op_info.cc" // NOLINT
>();
#endif
}

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