Skip to content

Commit d466092

Browse files
[Clang][Doc][NFC] Improve -offload-compress documentation and error message (#17990)
Based on the user's feedback in #17957 and #17914 --------- Co-authored-by: Steffen Larsen <[email protected]>
1 parent b6af150 commit d466092

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

buildbot/configure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def do_configure(args, passthrough_args):
134134
if args.use_lld:
135135
llvm_enable_lld = "ON"
136136

137+
if args.use_zstd:
138+
llvm_enable_zstd = "FORCE_ON"
139+
137140
# CI Default conditionally appends to options, keep it at the bottom of
138141
# args handling
139142
if args.ci_defaults:
@@ -417,6 +420,9 @@ def main():
417420
"--native-cpu-libclc-targets",
418421
help="Target triples for libclc, used by the Native CPU backend",
419422
)
423+
parser.add_argument(
424+
"--use-zstd", action="store_true", help="Force zstd linkage while building."
425+
)
420426
args, passthrough_args = parser.parse_known_intermixed_args()
421427

422428
print("args:{}".format(args))

clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,13 @@ class BinaryWrapper {
11131113
if (OffloadCompressDevImgs && !llvm::compression::zstd::isAvailable()) {
11141114
return createStringError(
11151115
inconvertibleErrorCode(),
1116-
"'--offload-compress' option is specified but zstd "
1117-
"is not available. The device image will not be "
1118-
"compressed.");
1116+
"'--offload-compress' is specified but the compiler is "
1117+
"built without zstd support.\n"
1118+
"If you are using a custom DPC++ build, please refer to "
1119+
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
1120+
"GetStartedGuide.md#build-dpc-toolchain-with-device-image-"
1121+
"compression-support"
1122+
" for more information on how to build with zstd support.");
11191123
}
11201124

11211125
// Don't compress if the user explicitly specifies the binary image

sycl/doc/GetStartedGuide.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and a wide range of compute accelerators such as GPU and FPGA.
1515
* [Build DPC++ toolchain with support for ARM processors](#build-dpc-toolchain-with-support-for-arm-processors)
1616
* [Build DPC++ toolchain with support for runtime kernel fusion and JIT compilation](#build-dpc-toolchain-with-support-for-runtime-kernel-fusion-and-jit-compilation)
1717
* [Build DPC++ toolchain with a custom Unified Runtime](#build-dpc-toolchain-with-a-custom-unified-runtime)
18+
* [Build DPC++ toolchain with device image compression support](#build-dpc-toolchain-with-device-image-compression-support)
1819
* [Build Doxygen documentation](#build-doxygen-documentation)
1920
* [Deployment](#deployment)
2021
* [Use DPC++ toolchain](#use-dpc-toolchain)
@@ -47,6 +48,7 @@ and a wide range of compute accelerators such as GPU and FPGA.
4748
| [Ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) | |
4849
| `hwloc` | >= 2.3 (Linux only, `libhwloc-dev` or `hwloc-devel`) |
4950
| C++ compiler | [See LLVM](https://github.com/intel/llvm/blob/sycl/llvm/docs/GettingStarted.rst#host-c-toolchain-both-compiler-and-standard-library) |
51+
|`zstd` (optional) | >= 1.4.8 (see [ZSTD](#build-dpc-toolchain-with-device-image-compression-support)) |
5052

5153
Alternatively, you can create a Docker image that has everything you need for
5254
building pre-installed using the [Ubuntu 24.04 build Dockerfile](https://github.com/intel/llvm/blob/sycl/devops/containers/ubuntu2404_build.Dockerfile).
@@ -94,7 +96,8 @@ The easiest way to get started is to use the buildbot
9496
[compile](../../buildbot/compile.py) scripts.
9597

9698
In case you want to configure CMake manually the up-to-date reference for
97-
variables is in these files.
99+
variables is in these files. Note that the CMake variables set by default by the [configure.py](../../buildbot/configure.py) script are the ones commonly used by
100+
DPC++ developers and might not necessarily suffice for your project-specific needs.
98101

99102
**Linux**:
100103

@@ -127,6 +130,7 @@ flags can be found by launching the script with `--help`):
127130
* `-t` -> Build type (Debug or Release)
128131
* `-o` -> Path to build directory
129132
* `--cmake-gen` -> Set build system type (e.g. `--cmake-gen "Unix Makefiles"`)
133+
* `--use-zstd` -> Force link zstd while building LLVM (see [ZSTD](#build-dpc-toolchain-with-device-image-compression-support))
130134

131135
You can use the following flags with `compile.py` (full list of available flags
132136
can be found by launching the script with `--help`):
@@ -320,6 +324,33 @@ DPC++ toolchain, but add the `--disable-jit` flag.
320324
Both kernel fusion and JIT compilation of AMD and Nvidia kernels are currently
321325
not yet supported on the Windows platform.
322326

327+
### Build DPC++ toolchain with device image compression support
328+
329+
Device image compression enables the compression of device code (SYCL Kernels) during compilation and decompressing them on-demand during the execution of the corresponding SYCL application.
330+
This reduces the size of fat binaries for both Just-in-Time (JIT) and Ahead-of-Time (AOT) compilation. Refer to the [blog post](https://www.intel.com/content/www/us/en/developer/articles/technical/sycl-compilation-device-image-compression.html) for more details on this feature.
331+
332+
To enable device image compression, you need to build the DPC++ toolchain with the
333+
zstd compression library. By default, zstd is optional for DPC++ builds i.e. CMake will search for zstd installation but if not found, it will not fail the build
334+
and this feature will simply be disabled.
335+
336+
To override this behavior and force the build to use zstd, you can use the `--use-zstd` flag in the `configure.py` script or by adding `-DLLVM_ENABLE_ZSTD=FORCE_ON` to the CMake configuration command.
337+
338+
#### How to obtain zstd?
339+
340+
Minimum zstd version that we have tested with is *1.4.8*.
341+
342+
**Linux**:
343+
344+
You can install zstd using the package manager of your distribution. For example, on Ubuntu, you can run:
345+
```sh
346+
sudo apt-get install libzstd-dev
347+
```
348+
Note that the libzstd-dev package provided on Ubuntu 24.04 has a bug ([link](https://bugs.launchpad.net/ubuntu/+source/libzstd/+bug/2086543)) and the zstd static library is not built with the `-fPIC` flag. Linking to this library will result in a build failure. For example: [Issue#15935](https://github.com/intel/llvm/issues/15935). As an alternative, zstd can be built from source either manually or by using the [build_zstd_1_5_6_ub24.sh](https://github.com/intel/llvm/blob/sycl/devops/scripts/build_zstd_1_5_6_ub24.sh) script.
349+
350+
**Windows**
351+
352+
For Windows, prebuilt zstd binaries can be obtained from the [facebook/zstd](https://github.com/facebook/zstd/releases/tag/v1.5.6) release page. After obtaining the zstd binaries, you can add the path to the zstd installation directory to the `PATH` environment variable.
353+
323354
### Build Doxygen documentation
324355

325356
Building Doxygen documentation is similar to building the product itself. First,

sycl/doc/UsersManual.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,15 @@ and not recommended to use in production environment.
203203
**`--offload-compress`**
204204

205205
Enables device image compression for SYCL offloading. Device images
206-
are compressed using `zstd` compression algorithm and only if their size
206+
are compressed using zstd compression algorithm and only if their size
207207
exceeds 512 bytes.
208+
To use this option, DPC++ must be built with zstd support. Otherwise,
209+
the compiler will throw an error during compilation.
208210
Default value is false.
209211

210212
**`--offload-compression-level=<int>`**
211213

212-
`zstd` compression level used to compress device images when `--offload-
214+
zstd compression level used to compress device images when `--offload-
213215
compress` is enabled.
214216
The default value is 10.
215217

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// using --offload-compress without zstd should throw an error.
22
// REQUIRES: !zstd
33
// RUN: not %{build} %O0 -g --offload-compress %S/Inputs/single_kernel.cpp -o %t_compress.out 2>&1 | FileCheck %s
4-
// CHECK: '--offload-compress' option is specified but zstd is not available. The device image will not be compressed.
4+
// CHECK: error: '--offload-compress' is specified but the compiler is built without zstd support.
5+
// CHECK-NEXT: If you are using a custom DPC++ build, please refer to https://github.com/intel/llvm/blob/sycl/sycl/doc/GetStartedGuide.md#build-dpc-toolchain-with-device-image-compression-support for more information on how to build with zstd support.

0 commit comments

Comments
 (0)