-
Notifications
You must be signed in to change notification settings - Fork 845
[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
base: sycl
Are you sure you want to change the base?
Changes from all commits
71170e8
4ad4d5f
ba1bedf
b3162a6
84e14dd
22bb108
5b71eed
8fb71fc
e79b396
e4a4991
537acd9
48bf119
a609844
8d91041
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||||||||||||||||||||||||||||||
| // REQUIRES: zstd && system-linux && x86-registered-target | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // clang-linker-wrapper compression test: checks that the wrapper compresses | ||||||||||||||||||||||||||||||||||||||
| // 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: build a bitcode module, pack it into an | ||||||||||||||||||||||||||||||||||||||
| // llvm-offload-binary, and embed it into an ELF object as the linker-wrapper | ||||||||||||||||||||||||||||||||||||||
| // input. The bitcode is large enough (well over the 512-byte compression | ||||||||||||||||||||||||||||||||||||||
| // threshold in wrapSYCLBinariesFromFile) that 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 | ||||||||||||||||||||||||||||||||||||||
|
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 think we also need
Contributor
Author
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. Fixed. |
||||||||||||||||||||||||||||||||||||||
| // 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: -sycl-post-link-options="-split=auto -symbols -properties" \ | ||||||||||||||||||||||||||||||||||||||
| // 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 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 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 that the compressed size is strictly smaller than the original size | ||||||||||||||||||||||||||||||||||||||
| // (i.e. ORIG - COMP > 0). FileCheck's numeric matching form only supports the | ||||||||||||||||||||||||||||||||||||||
| // `==` constraint — there is no `<` or `>` — 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 vacuously. | ||||||||||||||||||||||||||||||||||||||
| // * when COMP >= ORIG, sub() underflows and FileCheck fails the pattern. | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+41
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. nit. too verbose for me :)
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| // CHECK-COMPRESS-NOT: COMPRESSION_SIZE_CHECK[[#sub(ORIG, COMP)]] | ||||||||||||||||||||||||||||||||||||||
| // The tgt_device_image struct is { i16 Version, i8 Kind, i8 Format, ptr ... }; | ||||||||||||||||||||||||||||||||||||||
| // Kind for SYCL is 4, Format for BIF_Compressed is also 4. | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+44
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. nit. All we need is to check BIF_Compressed and it is already explained in the comments above that it is 4. The check is fine, but I don't think we need to provide verbose comments explaining each small detail not related to the functionality we test.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| // 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: -sycl-post-link-options="-split=auto -symbols -properties" \ | ||||||||||||||||||||||||||||||||||||||
| // 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: -sycl-post-link-options="-split=auto -symbols -properties" \ | ||||||||||||||||||||||||||||||||||||||
| // 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" { | ||||||||||||||||||||||||||||||||||||||
| // Symbols so the linker doesn't fail resolving them. | ||||||||||||||||||||||||||||||||||||||
| void __sycl_register_lib(void *) {} | ||||||||||||||||||||||||||||||||||||||
| void __sycl_unregister_lib(void *) {} | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| int main() { | ||||||||||||||||||||||||||||||||||||||
| kernel<class fake_kernel>([](){}); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| 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 \ | ||
|
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. should we check the opposite case, where we have |
||
| // 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" | ||
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.
nit. I think comments are unnecessarily verbose.