-
Notifications
You must be signed in to change notification settings - Fork 848
[SYCL] Support --offload-compress in clang-linker-wrapper #22605
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
71170e8
[SYCL] Support --offload-compress in clang-linker-wrapper
bviyer 4ad4d5f
Fixed a mistaken test
bviyer ba1bedf
Added two of the three changes requested by Nick.
bviyer b3162a6
Moved some functionality to a common function to share between
bviyer 84e14dd
Removed .gdbinit
bviyer 22bb108
Fixed changes mentioned by Nick
bviyer 5b71eed
Fixed the test
bviyer 8fb71fc
Fixed more issues mentioned by Nick.
bviyer e79b396
Added changes after rebase
bviyer e4a4991
Update llvm/include/llvm/Frontend/Offloading/Utility.h
bviyer 537acd9
Update clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
bviyer 48bf119
Added a functional test for the new compression
bviyer a609844
Fixed a clang-formatting issue
bviyer 8d91041
Added check that compressed size is less than original size
bviyer 72c2ce1
Update clang/test/Driver/clang-linker-wrapper-zstd.cpp
bviyer a910ec2
Update clang/test/Driver/clang-linker-wrapper-zstd.cpp
bviyer 676bc51
Potential fix for pull request finding
bviyer 5ef85dc
Update clang/test/Driver/clang-linker-wrapper-zstd.cpp
bviyer cbbc105
Update clang/test/Driver/clang-linker-wrapper-zstd.cpp
bviyer 9462cfe
Update clang/test/Driver/clang-linker-wrapper-zstd.cpp
bviyer fd00bfc
Update clang/test/Driver/clang-linker-wrapper-zstd.cpp
bviyer 5315269
Added all the changes requested by Srividya
bviyer 4c70396
Merge remote-tracking branch 'origin/bviyer-sycl-compress-support' in…
bviyer b49f47c
Moved test to clang linker wrapper as requested.
bviyer 516fbdf
Fixed an issue in test code.
bviyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /// Check that '--offload-compress' and '--offload-compression-level=' are | ||
| /// forwarded to clang-linker-wrapper under the new offloading driver via the | ||
| /// existing addOffloadCompressArgs() plumbing (as '--compress' and | ||
| /// '--compression-level='). The wrapper consumes them in | ||
| /// wrapSYCLBinariesFromFile to zstd-compress each SYCL device image and tag | ||
| /// it with BIF_Compressed. | ||
|
|
||
| // RUN: %clangxx -### -fsycl --offload-new-driver --offload-compress \ | ||
| // RUN: --offload-compression-level=3 %s 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-COMPRESS | ||
| // CHECK-COMPRESS: {{.*}}clang-linker-wrapper{{.*}}"--compress"{{.*}}"--compression-level=3" | ||
|
|
||
| // RUN: %clangxx -### -fsycl --offload-new-driver %s 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-NO-COMPRESS | ||
| // CHECK-NO-COMPRESS-NOT: {{.*}}clang-linker-wrapper{{.*}}"--compress" | ||
|
|
||
| // --no-offload-compress overrides an earlier --offload-compress. | ||
| // RUN: %clangxx -### -fsycl --offload-new-driver --offload-compress \ | ||
| // RUN: --no-offload-compress %s 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-NO-COMPRESS | ||
|
|
||
| // ...and vice versa: a later --offload-compress wins over --no-offload-compress. | ||
| // RUN: %clangxx -### -fsycl --offload-new-driver --no-offload-compress \ | ||
| // RUN: --offload-compress %s 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-COMPRESS-LAST | ||
| // CHECK-COMPRESS-LAST: {{.*}}clang-linker-wrapper{{.*}}"--compress" | ||
72 changes: 72 additions & 0 deletions
72
clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper-zstd.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // REQUIRES: zstd && system-linux && x86-registered-target | ||
|
|
||
| // clang-linker-wrapper compression test: checks that the wrapper compresses | ||
|
srividya-sundaram marked this conversation as resolved.
|
||
| // SYCL device images when --compress is set, tags them with | ||
| // SYCLBinaryImageFormat::BIF_Compressed (int8 value 4) in the emitted wrapper | ||
| // module, honors --compression-level=, and reports invalid values. | ||
|
|
||
| // Prepare test data. The bitcode is over the 512-byte compression threshold, | ||
| // so compression actually runs. | ||
| // RUN: %clang_cc1 -fsycl-is-device -disable-llvm-passes -triple=spir64-unknown-unknown %s -emit-llvm-bc -o %t.device.bc | ||
| // RUN: llvm-offload-binary -o %t.fat --image=file=%t.device.bc,kind=sycl,triple=spir64-unknown-unknown | ||
| // RUN: %clang_cc1 %s -triple=x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.fat | ||
| // RUN: touch %t.devicelib.bc | ||
|
|
||
| // With --compress and --wrapper-verbose the compression path fires and the | ||
| // wrapped image's Format slot in %__sycl.tgt_device_image is i8 4 | ||
| // (BIF_Compressed). | ||
| // RUN: clang-linker-wrapper --print-wrapped-module --host-triple=x86_64-unknown-linux-gnu \ | ||
| // RUN: --bitcode-library=spir64-unknown-unknown=%t.devicelib.bc \ | ||
| // RUN: --compress --compression-level=9 --wrapper-verbose \ | ||
| // RUN: %t.o -o %t.out --linker-path=/usr/bin/ld 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-COMPRESS | ||
|
bviyer marked this conversation as resolved.
|
||
|
|
||
| // Capture the original and compressed sizes. | ||
| // CHECK-COMPRESS: [Compression] Original image size: [[#ORIG:]] | ||
| // CHECK-COMPRESS: [Compression] Compressed image size: [[#COMP:]] | ||
| // CHECK-COMPRESS: [Compression] Compression level used: 9 | ||
| // | ||
| // Assert ORIG - COMP > 0. FileCheck's numeric matching form only supports | ||
| // `==`, but sub() rejects underflow at expression-evaluation time. We attach | ||
| // sub(ORIG, COMP) to a CHECK-NOT pattern that begins with a sentinel string | ||
| // never present in the output: | ||
| // * when ORIG > COMP, sub() succeeds; the substituted pattern is | ||
| // "COMPRESSION_SIZE_CHECK<some-number>", which doesn't appear, so the | ||
| // CHECK-NOT is satisfied. | ||
| // * when COMP >= ORIG, sub() underflows and FileCheck fails the pattern. | ||
| // CHECK-COMPRESS-NOT: COMPRESSION_SIZE_CHECK[[#sub(ORIG, COMP)]] | ||
| // CHECK-COMPRESS: @.sycl_offloading.device_images = internal unnamed_addr constant [1 x %__sycl.tgt_device_image] [%__sycl.tgt_device_image { i16 {{[0-9]+}}, i8 4, i8 4, | ||
|
|
||
| // Without --compress the image is left untagged (Format = BIF_None = 0) and | ||
| // no [Compression] verbose lines are emitted. | ||
| // RUN: clang-linker-wrapper --print-wrapped-module --host-triple=x86_64-unknown-linux-gnu \ | ||
| // RUN: --bitcode-library=spir64-unknown-unknown=%t.devicelib.bc \ | ||
| // RUN: --wrapper-verbose \ | ||
| // RUN: %t.o -o %t.out --linker-path=/usr/bin/ld 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-NO-COMPRESS | ||
|
|
||
| // CHECK-NO-COMPRESS-NOT: [Compression] | ||
| // CHECK-NO-COMPRESS: @.sycl_offloading.device_images = internal unnamed_addr constant [1 x %__sycl.tgt_device_image] [%__sycl.tgt_device_image { i16 {{[0-9]+}}, i8 4, i8 0, | ||
|
|
||
| // A non-integer --compression-level= is diagnosed. | ||
| // RUN: not clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu \ | ||
| // RUN: --bitcode-library=spir64-unknown-unknown=%t.devicelib.bc \ | ||
| // RUN: --compress --compression-level=notanumber \ | ||
| // RUN: %t.o -o %t.out --linker-path=/usr/bin/ld 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefix=CHECK-BAD-LEVEL | ||
|
|
||
| // CHECK-BAD-LEVEL: invalid value for --offload-compression-level=: 'notanumber' | ||
|
|
||
| template <typename t, typename Func> | ||
| __attribute__((sycl_kernel)) void kernel(const Func &func) { | ||
| func(); | ||
| } | ||
|
|
||
| extern "C" { | ||
| void __sycl_register_lib(void *) {} | ||
| void __sycl_unregister_lib(void *) {} | ||
| } | ||
|
|
||
| int main() { | ||
| kernel<class fake_kernel>([](){}); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.