Skip to content

Commit 70fddbb

Browse files
authored
[sycl-post-link][Driver] Pass in -emit-only-kernels-as-entry-point option by default (#12060)
sycl-post-link is one of the tools invoked during compilation of SYCL device code. One of the options passed to this tool is ‘emit-only-kernels-as-entry-points’. This option was introduced to stop treating `SYCL_EXTERNAL` functions as entry points. However, it was turned on by default only for FPGAs and turned off for other backends. We are noticing that there are no tangible benefits to treating `SYCL_EXTERNAL` functions as entry points and that treating them as entry points results in unnecessary device code bloating. This is a pain point reported by several customers. We propose to turn on ` emit-only-kernels-as-entry-points` by default for all Intel backends. However, we want to expose this option to users and allow them to turn it off if required. Hence we propose the following command line option to be added into compiler: -f[no]-sycl-remove-unused-external-funcs // Linux and Windows This option takes no arguments Thanks --------- Signed-off-by: Sudarsanam, Arvind <[email protected]>
1 parent 9f7ad1f commit 70fddbb

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,10 @@ def foperator_arrow_depth_EQ : Joined<["-"], "foperator-arrow-depth=">, Group<f_
39433943
Visibility<[ClangOption, CC1Option]>,
39443944
HelpText<"Maximum number of 'operator->'s to call for a member access">,
39453945
MarshallingInfoInt<LangOpts<"ArrowDepth">, "256">;
3946+
def fsycl_remove_unused_external_funcs : Flag<["-"], "fsycl-remove-unused-external-funcs">,
3947+
Group<sycl_Group>, HelpText<"Allow removal of unused `SYCL_EXTERNAL` functions (default)">;
3948+
def fno_sycl_remove_unused_external_funcs : Flag<["-"], "fno-sycl-remove-unused-external-funcs">,
3949+
Group<sycl_Group>, HelpText<"Prevent removal of unused `SYCL_EXTERNAL` functions">;
39463950

39473951
def fsave_optimization_record : Flag<["-"], "fsave-optimization-record">,
39483952
Visibility<[ClangOption, FlangOption]>,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10215,10 +10215,13 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
1021510215
addArgs(CmdArgs, TCArgs, {"-split=auto"});
1021610216
}
1021710217

10218-
// On FPGA target we don't need non-kernel functions as entry points, because
10219-
// it only increases amount of code for device compiler to handle, without any
10220-
// actual benefits.
10221-
if (T.getArchName() == "spir64_fpga")
10218+
// On Intel targets we don't need non-kernel functions as entry points,
10219+
// because it only increases amount of code for device compiler to handle,
10220+
// without any actual benefits.
10221+
// TODO: Try to extend this feature for non-Intel GPUs.
10222+
if (!TCArgs.hasFlag(options::OPT_fno_sycl_remove_unused_external_funcs,
10223+
options::OPT_fsycl_remove_unused_external_funcs, false) &&
10224+
!T.isNVPTX() && !T.isAMDGPU())
1022210225
addArgs(CmdArgs, TCArgs, {"-emit-only-kernels-as-entry-points"});
1022310226

1022410227
// OPT_fsycl_device_code_split is not checked as it is an alias to

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@
4141
// RUN: | FileCheck -check-prefix=CHK-NON-KERNEL-ENTRY-POINTS %s
4242
// CHK-NON-KERNEL-ENTRY-POINTS: sycl-post-link{{.*}} "-emit-only-kernels-as-entry-points"
4343

44-
/// Non-FPGA targets should not imply -emit-only-kernels-as-entry-points in sycl-post-link
45-
// RUN: %clang -### -fsycl -fsycl-targets=spir64_fpga,spir64_gen %s 2>&1 \
46-
// RUN: | FileCheck %s --check-prefix=CHK-NON-KERNEL-ENTRY-POINTS-NEG-1
47-
// CHK-NON-KERNEL-ENTRY-POINTS-NEG-1: clang{{.*}} "-triple" "spir64_fpga-unknown-unknown"
48-
// CHK-NON-KERNEL-ENTRY-POINTS-NEG-1: sycl-post-link{{.*}} "-emit-only-kernels-as-entry-points"
49-
// CHK-NON-KERNEL-ENTRY-POINTS-NEG-1: clang{{.*}} "-triple" "spir64_gen-unknown-unknown"
50-
// CHK-NON-KERNEL-ENTRY-POINTS-NEG-1: sycl-post-link
51-
// CHK-NON-KERNEL-ENTRY-POINTS-NEG-1-NOT: "-emit-only-kernels-as-entry-points"
52-
// RUN: %clang -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=CHK-NON-KERNEL-ENTRY-POINTS-NEG-2
53-
// CHK-NON-KERNEL-ENTRY-POINTS-NEG-2-NOT: "-emit-only-kernels-as-entry-points"
54-
5544
/// -fsycl-disable-range-rounding is applied to all compilations if fpga is used
5645
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_fpga-unknown-unknown,spir64_gen-unknown-unknown %s 2>&1 \
5746
// RUN: | FileCheck -check-prefix=CHK-RANGE-ROUNDING-MULTI %s

clang/test/Driver/sycl-offload.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,11 @@
170170
/// Check if the clang with fsycl adds C++ libraries to the link line
171171
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl %s 2>&1 | FileCheck -check-prefix=CHECK-FSYCL-WITH-CLANG %s
172172
// CHECK-FSYCL-WITH-CLANG: "-lstdc++"
173+
174+
/// Check selective passing of -emit-only-kernels-as-entry-points to sycl-post-link tool
175+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_fpga %s 2>&1 | FileCheck -check-prefix=CHECK_SYCL_POST_LINK_OPT_PASS %s
176+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_gen %s 2>&1 | FileCheck -check-prefix=CHECK_SYCL_POST_LINK_OPT_PASS %s
177+
// CHECK_SYCL_POST_LINK_OPT_PASS: sycl-post-link{{.*}}emit-only-kernels-as-entry-points
178+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_gen -fno-sycl-remove-unused-external-funcs %s 2>&1 | FileCheck -check-prefix=CHECK_SYCL_POST_LINK_OPT_NO_PASS %s
179+
// CHECK_SYCL_POST_LINK_OPT_NO_PASS-NOT: sycl-post-link{{.*}}emit-only-kernels-as-entry-points
180+

0 commit comments

Comments
 (0)