Skip to content

Commit 7db8df5

Browse files
enable image compression test for new offload model
1 parent 5a8910d commit 7db8df5

File tree

5 files changed

+128
-8
lines changed

5 files changed

+128
-8
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,13 @@ class Driver {
626626
/// @name Helper Methods
627627
/// @{
628628

629+
/// Utility function to parse all devices passed via -fsycl-targets.
630+
/// Return 'true' for JIT, AOT Intel CPU/GPUs and NVidia/AMD targets.
631+
/// Otherwise return 'false'.
632+
bool
633+
GetUseNewOffloadDriverForSYCLOffload(Compilation &C,
634+
const llvm::opt::ArgList &Args) const;
635+
629636
/// getSYCLDeviceTriple - Returns the SYCL device triple for the
630637
/// specified subarch
631638
// TODO: Additional Arg input parameter is for diagnostic output information

clang/lib/Driver/Driver.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,32 @@ static void appendOneArg(InputArgList &Args, const Arg *Opt) {
15651565
}
15661566
}
15671567

1568+
// Utility function to parse all devices passed via -fsycl-targets.
1569+
// Return 'true' for JIT, AOT Intel CPU/GPUs and NVidia/AMD targets.
1570+
// Otherwise return 'false'.
1571+
bool Driver::GetUseNewOffloadDriverForSYCLOffload(Compilation &C,
1572+
const ArgList &Args) const {
1573+
// Check only if enabled with -fsycl
1574+
if (!Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
1575+
return false;
1576+
1577+
if (Args.hasFlag(options::OPT_no_offload_new_driver,
1578+
options::OPT_offload_new_driver, false))
1579+
return false;
1580+
1581+
if (Args.hasArg(options::OPT_fintelfpga))
1582+
return false;
1583+
1584+
if (const Arg *A = Args.getLastArg(options::OPT_fsycl_targets_EQ)) {
1585+
for (const char *Val : A->getValues()) {
1586+
llvm::Triple TT(C.getDriver().getSYCLDeviceTriple(Val));
1587+
if ((!TT.isSPIROrSPIRV()) || TT.isSPIRAOT())
1588+
return false;
1589+
}
1590+
}
1591+
return true;
1592+
}
1593+
15681594
bool Driver::readConfigFile(StringRef FileName,
15691595
llvm::cl::ExpansionContext &ExpCtx) {
15701596
// Try opening the given file.
@@ -2195,12 +2221,12 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
21952221
// Use new offloading path for OpenMP. This is disabled as the SYCL
21962222
// offloading path is not properly setup to use the updated device linking
21972223
// scheme.
2198-
if ((C->isOffloadingHostKind(Action::OFK_OpenMP) &&
2199-
TranslatedArgs->hasFlag(options::OPT_fopenmp_new_driver,
2200-
options::OPT_no_offload_new_driver, true)) ||
2224+
if (C->isOffloadingHostKind(Action::OFK_OpenMP) ||
22012225
TranslatedArgs->hasFlag(options::OPT_offload_new_driver,
2202-
options::OPT_no_offload_new_driver, false))
2226+
options::OPT_no_offload_new_driver, false) ||
2227+
GetUseNewOffloadDriverForSYCLOffload(*C, *TranslatedArgs)) {
22032228
setUseNewOffloadingDriver();
2229+
}
22042230

22052231
// Construct the list of abstract actions to perform for this compilation. On
22062232
// MachO targets this uses the driver-driver and universal actions.
@@ -7095,7 +7121,8 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
70957121
options::OPT_fno_offload_via_llvm, false) ||
70967122
Args.hasFlag(options::OPT_offload_new_driver,
70977123
options::OPT_no_offload_new_driver,
7098-
C.isOffloadingHostKind(Action::OFK_Cuda));
7124+
C.isOffloadingHostKind(Action::OFK_Cuda)) ||
7125+
GetUseNewOffloadDriverForSYCLOffload(C, Args);
70997126

71007127
bool HIPNoRDC =
71017128
C.isOffloadingHostKind(Action::OFK_HIP) &&

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5232,7 +5232,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52325232
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
52335233
Args.hasFlag(options::OPT_offload_new_driver,
52345234
options::OPT_no_offload_new_driver,
5235-
C.isOffloadingHostKind(Action::OFK_Cuda)));
5235+
C.isOffloadingHostKind(Action::OFK_Cuda))) ||
5236+
(JA.isHostOffloading(Action::OFK_SYCL) &&
5237+
C.getDriver().GetUseNewOffloadDriverForSYCLOffload(C, Args));
52365238

52375239
bool IsRDCMode =
52385240
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, IsSYCL);

sycl/test-e2e/Compression/compression_separate_compile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
////////////////////// Link device images
1818
// RUN: %{run-aux} %clangxx --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -v
1919

20-
// Make sure the clang-offload-wrapper is called with the --offload-compress
20+
// Make sure the clang-offload-wrapper is called with the --offload-compress when using the old offloading model
2121
// option.
22-
// RUN: %{run-aux} %clangxx --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -### &> %t_driver_opts.txt
22+
// RUN: %{run-aux} %clangxx --no-offload-new-driver --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -### &> %t_driver_opts.txt
2323
// RUN: %{run-aux} FileCheck -input-file=%t_driver_opts.txt %s --check-prefix=CHECK-DRIVER-OPTS
2424

2525
// CHECK-DRIVER-OPTS: clang-offload-wrapper{{.*}} "-offload-compress"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// End-to-End test for testing device image compression when we
2+
// separately compile and link device images for New Offloading Model.
3+
4+
// REQUIRES: zstd, opencl-aot, cpu, linux
5+
6+
// XFAIL: run-mode && preview-mode
7+
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/20397
8+
9+
// XFAIL: target-native_cpu
10+
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/20397
11+
12+
// CPU AOT targets host isa, so we compile everything on the run system instead.
13+
////////////////////// Compile device images
14+
// RUN: %clangxx --offload-new-driver -fsycl -fsycl-targets=spir64_x86_64 -fsycl-host-compiler=clang++ -fsycl-host-compiler-options='-std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -DENABLE_KERNEL1' -DENABLE_KERNEL1 -c %s -o %t_kernel1_aot.o
15+
// RUN: %clangxx --offload-new-driver -fsycl -fsycl-targets=spir64_x86_64 -fsycl-host-compiler=clang++ -fsycl-host-compiler-options='-std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -DENABLE_KERNEL2' -DENABLE_KERNEL2 -c %s -o %t_kernel2_aot.o
16+
17+
////////////////////// Link device images
18+
// RUN: %clangxx --offload-new-driver --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -v
19+
20+
// Make sure the clang-linker-wrapper is called with the --compress when using the new offloading model
21+
// option.
22+
// RUN: %clangxx --offload-new-driver --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -### &> %t_driver_opts.txt
23+
// RUN: FileCheck -input-file=%t_driver_opts.txt %s --check-prefix=CHECK-DRIVER-OPTS
24+
25+
// CHECK-DRIVER-OPTS: clang-linker-wrapper{{.*}} "--compress"
26+
27+
////////////////////// Compile the host program
28+
// RUN: %clangxx --offload-new-driver -fsycl -std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -c %s -o %t_main.o
29+
30+
////////////////////// Link the host program and compressed device images
31+
// RUN: %clangxx --offload-new-driver -fsycl %t_main.o %t_kernel1_aot.o %t_kernel2_aot.o %t_compressed_image.o -o %t_compress.out
32+
33+
// RUN: %{run} %t_compress.out
34+
35+
#include <sycl/detail/core.hpp>
36+
37+
using namespace sycl;
38+
39+
// Kernel 1
40+
#ifdef ENABLE_KERNEL1
41+
class test_kernel1;
42+
void run_kernel1(int *a, queue q) {
43+
q.single_task<test_kernel1>([=]() { *a *= 3; }).wait();
44+
}
45+
#endif
46+
47+
// Kernel 2
48+
#ifdef ENABLE_KERNEL2
49+
class test_kernel2;
50+
void run_kernel2(int *a, queue q) {
51+
q.single_task<test_kernel2>([=]() { *a += 42; }).wait();
52+
}
53+
#endif
54+
55+
// Main application.
56+
#if not defined(ENABLE_KERNEL1) && not defined(ENABLE_KERNEL2)
57+
#include <sycl/properties/all_properties.hpp>
58+
#include <sycl/usm.hpp>
59+
60+
#include <iostream>
61+
62+
class kernel_init;
63+
void run_kernel1(int *a, queue q);
64+
void run_kernel2(int *a, queue q);
65+
int main() {
66+
int retCode = 0;
67+
queue q;
68+
69+
if (!q.get_device().get_info<info::device::usm_shared_allocations>())
70+
return 0;
71+
72+
int *p = malloc_shared<int>(1, q);
73+
*p = 42;
74+
75+
run_kernel1(p, q);
76+
run_kernel2(p, q);
77+
q.wait();
78+
79+
retCode = *p != (42 * 3 + 42);
80+
81+
free(p, q);
82+
return retCode;
83+
}
84+
#endif

0 commit comments

Comments
 (0)