Skip to content

Commit

Permalink
Throw error in clang-offload-wrapper when zstd is not present but sti…
Browse files Browse the repository at this point in the history
…ll do --offload-compress; Dynamically detect if zstd is present when running E2E tests.
  • Loading branch information
uditagarwal97 committed Sep 13, 2024
1 parent 44b41dd commit 1d81813
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
11 changes: 6 additions & 5 deletions clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,13 @@ class BinaryWrapper {
Fbin = *FBinOrErr;
} else {

// If '--offload-compress' option is specified and zstd is not available
// then warn the user that the image will not be compressed.
// If '--offload-compress' option is specified and zstd is not
// available, throw an error.
if (OffloadCompressDevImgs && !llvm::compression::zstd::isAvailable()) {
WithColor::warning(errs(), ToolName)
<< "'--offload-compress' option is specified but zstd is not "
"available. The device image will not be compressed.\n";
createStringError(inconvertibleErrorCode(),
"'--offload-compress' option is specified but zstd "
"is not available. The device image will not be "
"compressed.");
}

// Don't compress if the user explicitly specifies the binary image
Expand Down
1 change: 0 additions & 1 deletion sycl/source/detail/compression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,3 @@ class ZSTDCompressor {
} // namespace sycl

#endif // SYCL_RT_ZSTD_NOT_AVAIABLE

2 changes: 0 additions & 2 deletions sycl/test-e2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ if(NOT SYCL_TEST_E2E_STANDALONE)
)
endif() # Standalone.

find_package(zstd)

add_custom_target(check-sycl-e2e
COMMAND ${Python3_EXECUTABLE} ${LLVM_LIT} ${SYCL_E2E_TESTS_LIT_FLAGS} .
COMMENT "Running SYCL End-to-End tests"
Expand Down
4 changes: 2 additions & 2 deletions sycl/test-e2e/Compression/no_zstd_warning.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test to check warnings when using --offload-compress without zstd.
// using --offload-compress without zstd should throw an error.
// REQUIRES: !zstd
// RUN: %{build} -O0 -g --offload-compress %S/Inputs/single_kernel.cpp -o %t_compress.out 2>&1 | FileCheck %s

// CHECK: warning: '--offload-compress' option is specified but zstd is not available. The device image will not be compressed.
// XFAIL: *
30 changes: 27 additions & 3 deletions sycl/test-e2e/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,33 @@ def open_check_file(file_name):
if sp[0] == 0:
config.available_features.add("preview-breaking-changes-supported")

# Check if clang is built with ZSTD and compression support.
check_zstd_file = os.path.join(config.sycl_obj_root, "compression_available.cpp")
with open(check_zstd_file, "w") as fp:
print(
textwrap.dedent(
"""
#include <sycl/sycl.hpp>
using namespace sycl;
void kernel1(buffer<int, 1> &b, queue q) {
q.submit([&](sycl::handler &cgh) {
auto acc = sycl::accessor(b, cgh);
q.single_task([=] {acc[0] = acc[0] + 1;});
});
}
"""
),
file=fp,
)

sp = subprocess.getstatusoutput(
config.dpcpp_compiler +
" -fsycl --offload-compress -shared -fPIC " +
check_zstd_file
)
if sp[0] == 0:
config.available_features.add("zstd")

# Check for CUDA SDK
check_cuda_file = "cuda_include.cpp"
with open_check_file(check_cuda_file) as fp:
Expand Down Expand Up @@ -594,9 +621,6 @@ def open_check_file(file_name):
if lit_config.params.get("ze_debug"):
config.available_features.add("ze_debug")

if config.zstd_found and config.zstd_found == "TRUE":
config.available_features.add("zstd")

if config.run_launcher:
config.substitutions.append(("%e2e_tests_root", config.test_source_root))

Expand Down
2 changes: 0 additions & 2 deletions sycl/test-e2e/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ config.vulkan_include_dir = "@Vulkan_INCLUDE_DIRS@"
config.vulkan_lib = "@Vulkan_LIBRARY@"
config.vulkan_found = "@Vulkan_FOUND@"

config.zstd_found = "@zstd_FOUND@"

config.run_launcher = lit_config.params.get('run_launcher', "@SYCL_E2E_RUN_LAUNCHER@")
config.allow_unknown_arch = "@SYCL_E2E_LIT_ALLOW_UNKNOWN_ARCH@"

Expand Down

0 comments on commit 1d81813

Please sign in to comment.