-
Notifications
You must be signed in to change notification settings - Fork 849
[SYCL][NewOffloadModel] Support -fno-sycl-rdc at compile step (-c) #22833
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
base: sycl
Are you sure you want to change the base?
Changes from all commits
90fe7b6
998d20f
80d7d10
dbd5c44
07a16e7
2a41c6f
d8ece47
97ecb2f
7a9c782
a45367c
a2bc665
0e6ce2e
187c79c
fede3c5
7746b37
2be9203
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9149,10 +9149,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, | |
| CmdArgs.push_back(CudaDeviceInput->getFilename()); | ||
| } else if (!HostOffloadingInputs.empty()) { | ||
| if ((IsCuda || IsHIP) && !IsRDCMode) { | ||
| // CUDA/HIP no-RDC: device image finalized per-TU, embed at compile time. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since HIP already goes through this path, can we reuse the same |
||
| assert(HostOffloadingInputs.size() == 1 && "Only one input expected"); | ||
| CmdArgs.push_back("-fcuda-include-gpubinary"); | ||
| CmdArgs.push_back(HostOffloadingInputs.front().getFilename()); | ||
| } else if (IsSYCL && !IsRDCMode) { | ||
| // SYCL no-RDC: per-TU finalized device image, embed at compile time. | ||
| assert(HostOffloadingInputs.size() == 1 && "One finalized image per TU"); | ||
| CmdArgs.push_back("-fsycl-include-target-binary"); | ||
| CmdArgs.push_back(HostOffloadingInputs.front().getFilename()); | ||
| } else { | ||
| // RDC: embed raw device bitcode for cross-TU device link at link time. | ||
| for (const InputInfo Input : HostOffloadingInputs) | ||
| CmdArgs.push_back(Args.MakeArgString("-fembed-offload-object=" + | ||
| TC.getInputFilename(Input))); | ||
|
|
@@ -12154,6 +12161,24 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, | |
| if (Args.hasArg(options::OPT_fsycl_link_EQ)) | ||
| CmdArgs.push_back(Args.MakeArgString("--sycl-device-link")); | ||
|
|
||
| // Propagate [no-]rdc mode to the linker wrapper for the SYCL case. | ||
| // The default behaviour is rdc mode ON, which requires no special flags. | ||
| // In order to enable non-rdc mode, we pass --no-sycl-rdc to the linker | ||
| // wrapper. Note: -f[no-]sycl-rdc is an alias of [no-]gpu_rdc. | ||
| bool IsSYCLNoRDC = | ||
| !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, | ||
| /*default=*/true); | ||
| if (IsSYCLNoRDC) { | ||
| CmdArgs.push_back("--no-sycl-rdc"); | ||
| // isDeviceOffloading(OFK_SYCL) distinguishes the per-TU finalizer | ||
| // (OFK_SYCL, from BuildOffloadingActions) from the final link-time | ||
| // invocation (OFK_Host) -- both produce TY_Image so output type alone | ||
| // is not a reliable discriminator. | ||
| if (C.getDriver().getFinalPhase(C.getArgs()) != phases::Link && | ||
| JA.isDeviceOffloading(Action::OFK_SYCL)) | ||
| CmdArgs.push_back("--sycl-device-link"); | ||
| } | ||
|
|
||
| // -sycl-device-library-location=<dir> provides the location in which the | ||
| // SYCL device libraries can be found. | ||
| SmallString<128> DeviceLibDir(D.Dir); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /// Tests for -fno-sycl-rdc at the compile step (-c) with --offload-new-driver. | ||
| /// Verifies that the driver inserts a per-TU clang-linker-wrapper finalize | ||
| /// action and routes the result to -fsycl-include-target-binary on the host | ||
| /// cc1, instead of deferring device processing to link time. | ||
|
|
||
| // RUN: touch %t.cpp | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't catch this in the first RDC PR, but why do we need to do this? We should be able just to use |
||
|
|
||
| // -fno-sycl-rdc -c: per-TU linker-wrapper with --sycl-device-link, host cc1 gets -fsycl-include-target-binary. | ||
| // RUN: %clang -### --offload-new-driver -Werror --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -fsycl -fno-sycl-rdc -c %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-COMPILE --implicit-check-not=-fembed-offload-object %s | ||
| // CHK-COMPILE: clang-linker-wrapper{{.*}} "--no-sycl-rdc"{{.*}} "--sycl-device-link" | ||
| // CHK-COMPILE: "-fsycl-is-host"{{.*}} "-fsycl-include-target-binary" | ||
|
|
||
| // Default RDC -c: -fembed-offload-object appears, no -fsycl-include-target-binary or --no-sycl-rdc. | ||
| // RUN: %clang -### --offload-new-driver --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -fsycl -c %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-RDC %s | ||
| // CHK-RDC: -fembed-offload-object | ||
| // CHK-RDC-NOT: -fsycl-include-target-binary | ||
| // CHK-RDC-NOT: --no-sycl-rdc | ||
|
|
||
| // -fno-sycl-rdc at link step: --no-sycl-rdc forwarded, --sycl-device-link must NOT appear. | ||
| // RUN: touch %t.o | ||
| // RUN: %clang -### --offload-new-driver -Werror --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -fsycl -fno-sycl-rdc %t.o 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-LINK %s | ||
| // CHK-LINK: clang-linker-wrapper{{.*}} "--no-sycl-rdc" | ||
| // CHK-LINK-NOT: clang-linker-wrapper{{.*}} "--sycl-device-link" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /// Tests for -f[no-]sycl-rdc with --offload-new-driver. | ||
|
|
||
| // Verifies that --no-sycl-rdc is propagated to clang-linker-wrapper when | ||
| // -fno-sycl-rdc is passed. RDC is ON by default; --no-sycl-rdc signals | ||
|
srividya-sundaram marked this conversation as resolved.
|
||
| // RDC is OFF. | ||
|
|
||
| // RUN: touch %t.cpp | ||
|
|
||
| // Default (no flag): RDC is ON by default for SYCL, so --no-sycl-rdc should NOT appear. | ||
| // RUN: %clang -### --offload-new-driver --target=x86_64-unknown-linux-gnu -fsycl %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-DEFAULT %s | ||
| // CHK-DEFAULT-NOT: --no-sycl-rdc | ||
|
|
||
| // -fno-sycl-rdc: --no-sycl-rdc should appear. | ||
| // RUN: %clang -### --offload-new-driver -Werror --target=x86_64-unknown-linux-gnu -fsycl -fno-sycl-rdc %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-NO-RDC %s | ||
| // CHK-NO-RDC: clang-linker-wrapper{{.*}} "--no-sycl-rdc" | ||
|
|
||
| // AOT Intel GPU target, default RDC: --no-sycl-rdc should NOT appear. | ||
| // RUN: %clang -### --offload-new-driver --target=x86_64-unknown-linux-gnu -fsycl -fsycl-targets=intel_gpu_pvc %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-AOT-RDC %s | ||
| // CHK-AOT-RDC-NOT: --no-sycl-rdc | ||
|
|
||
| // AOT Intel GPU target + -fno-sycl-rdc: --no-sycl-rdc should appear. | ||
| // RUN: %clang -### --offload-new-driver -Werror --target=x86_64-unknown-linux-gnu -fsycl -fsycl-targets=intel_gpu_pvc -fno-sycl-rdc %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-AOT-NO-RDC %s | ||
| // CHK-AOT-NO-RDC: clang-linker-wrapper{{.*}} "--no-sycl-rdc" | ||
|
|
||
| // -fno-sycl-rdc -flto -c: per-TU device link still happens, --sycl-device-link present. | ||
| // RUN: %clang -### --offload-new-driver -Werror --target=x86_64-unknown-linux-gnu -fsycl -fno-sycl-rdc -flto -c %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-NO-RDC-LTO-C %s | ||
| // CHK-NO-RDC-LTO-C: clang-linker-wrapper{{.*}} "--no-sycl-rdc"{{.*}} "--sycl-device-link" | ||
|
|
||
| // -fno-sycl-rdc -flto (link step): --sycl-device-link should NOT appear. | ||
| // RUN: %clang -### --offload-new-driver -Werror --target=x86_64-unknown-linux-gnu -fsycl -fno-sycl-rdc -flto %t.cpp 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-NO-RDC-LTO %s | ||
| // CHK-NO-RDC-LTO: clang-linker-wrapper{{.*}} "--no-sycl-rdc" | ||
| // CHK-NO-RDC-LTO-NOT: --sycl-device-link | ||
|
|
||
| // Verify pipeline with --offload-new-driver -fno-sycl-rdc. | ||
| // RUN: touch %t1.cpp | ||
| // RUN: touch %t2.cpp | ||
| // RUN: %clang -### --offload-new-driver --target=x86_64-unknown-linux-gnu -fsycl -fno-sycl-rdc %t1.cpp %t2.cpp 2>&1 -ccc-print-phases | FileCheck %s --check-prefix=CHECK-PIPELINE | ||
|
|
||
| // CHECK-PIPELINE: 0: input, "{{.*}}1.cpp", c++, (host-sycl) | ||
| // CHECK-PIPELINE: 1: preprocessor, {0}, c++-cpp-output, (host-sycl) | ||
| // CHECK-PIPELINE: 2: compiler, {1}, ir, (host-sycl) | ||
| // CHECK-PIPELINE: 3: input, "{{.*}}1.cpp", c++, (device-sycl) | ||
| // CHECK-PIPELINE: 4: preprocessor, {3}, c++-cpp-output, (device-sycl) | ||
| // CHECK-PIPELINE: 5: compiler, {4}, ir, (device-sycl) | ||
| // CHECK-PIPELINE: 6: backend, {5}, ir, (device-sycl) | ||
| // CHECK-PIPELINE: 7: offload, "device-sycl (spir64-unknown-unknown)" {6}, ir | ||
| // CHECK-PIPELINE: 8: llvm-offload-binary, {7}, image, (device-sycl) | ||
| // CHECK-PIPELINE: 9: clang-linker-wrapper, {8}, image, (device-sycl) | ||
| // CHECK-PIPELINE: 10: offload, "host-sycl (x86_64-unknown-linux-gnu)" {2}, "device-sycl (x86_64-unknown-linux-gnu)" {9}, ir | ||
| // CHECK-PIPELINE: 11: backend, {10}, assembler, (host-sycl) | ||
| // CHECK-PIPELINE: 12: assembler, {11}, object, (host-sycl) | ||
| // CHECK-PIPELINE: 13: input, "{{.*}}2.cpp", c++, (host-sycl) | ||
| // CHECK-PIPELINE: 14: preprocessor, {13}, c++-cpp-output, (host-sycl) | ||
| // CHECK-PIPELINE: 15: compiler, {14}, ir, (host-sycl) | ||
| // CHECK-PIPELINE: 16: input, "{{.*}}2.cpp", c++, (device-sycl) | ||
| // CHECK-PIPELINE: 17: preprocessor, {16}, c++-cpp-output, (device-sycl) | ||
| // CHECK-PIPELINE: 18: compiler, {17}, ir, (device-sycl) | ||
| // CHECK-PIPELINE: 19: backend, {18}, ir, (device-sycl) | ||
| // CHECK-PIPELINE: 20: offload, "device-sycl (spir64-unknown-unknown)" {19}, ir | ||
| // CHECK-PIPELINE: 21: llvm-offload-binary, {20}, image, (device-sycl) | ||
| // CHECK-PIPELINE: 22: clang-linker-wrapper, {21}, image, (device-sycl) | ||
| // CHECK-PIPELINE: 23: offload, "host-sycl (x86_64-unknown-linux-gnu)" {15}, "device-sycl (x86_64-unknown-linux-gnu)" {22}, ir | ||
| // CHECK-PIPELINE: 24: backend, {23}, assembler, (host-sycl) | ||
| // CHECK-PIPELINE: 25: assembler, {24}, object, (host-sycl) | ||
| // CHECK-PIPELINE: 26: clang-linker-wrapper, {12, 25}, image, (host-sycl) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind of a nit but i since the device binary will contain information on the offloading model and triple used (as it should be inside the OffloadBinary wrapper), i don't see any need for per-offload-model options, but since CUDA already did it, i guess we only can address this feedback when we implement an equivalent version of this change upstream, where we can unify them
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
This option was introduced based on the SYCL no-RDC design doc from @YuriPlyakhin : https://github.com/YuriPlyakhin/llvm-project/blob/6553d362c5e84114a30eff3a79cad70432fff3ef/sycl-no-rdc-plan.md#3-per-tu-device-finalize--host-compile-inclusion-cudahip-mirror
We can unify with the CUDA/HIP option when implementing the equivalent upstream change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it perhaps make sense to name the new option
-foffload-include-binaryor similar in anticipation of future unification?