Skip to content

Commit

Permalink
[Clang] Link ITT libraries in device code by default (#16094)
Browse files Browse the repository at this point in the history
Fixes: CMPLRLLVM-63157

**Problem**
Consider the following case:
```
clang++ -fsycl -c testFile.cpp -o obj1.o
clang++ -fsycl -c testFile2.cpp -o obj2.o -fsycl-instrument-device-code
clang++ -fsycl obj1.o obj2.o -o test.exe

// test.exe fails with:
JIT session error: Symbols not found: [ __itt_offload_wi_finish_wrapper, __itt_offload_wi_start_wrapper ]
```
This issue was observed while using MKL static libraries built with
`-fsycl-instrument-device-code` with the latest compiler that does not
link ITT annotations by default.

With this change, we link in ITT libraries by default to stays ABI
compliant with the previous release. During device code linking, if the
device code is not instrumented with ITT annotations, this library will
be omitted. Note that, even with this change, we are not instrumenting
device code with ITT annotations by default.
  • Loading branch information
uditagarwal97 authored Nov 15, 2024
1 parent 5fb7498 commit 620ac35
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,11 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
addLibraries(SYCLDeviceBfloat16FallbackLib);
}

// Link in ITT annotations library unless fsycl-no-instrument-device-code
// is specified. This ensures that we are ABI-compatible with the
// instrumented device code, which was the default not so long ago.
if (Args.hasFlag(options::OPT_fsycl_instrument_device_code,
options::OPT_fno_sycl_instrument_device_code, false))
options::OPT_fno_sycl_instrument_device_code, true))
addLibraries(SYCLDeviceAnnotationLibs);

#if !defined(_WIN32)
Expand Down
8 changes: 6 additions & 2 deletions clang/test/Driver/sycl-instrumentation-old-model.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
// CHECK-SPIRV-SAME: "{{.*}}libsycl-itt-stubs.bc"
// CHECK-HOST-NOT: "-cc1"{{.*}} "-fsycl-is-host"{{.*}} "-fsycl-instrument-device-code"

// ITT annotations in device code are disabled by default.
// ITT annotations in device code are disabled by default. However, for SYCL offloading,
// we still link ITT annotations libraries to ensure ABI compatibility with previous release.
// RUN: %clangxx -fsycl --no-offload-new-driver -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// RUN: | FileCheck -check-prefixes=CHECK-ITT-LINK-ONLY %s
// RUN: %clangxx -fsycl --no-offload-new-driver -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s

// CHECK-ITT-LINK-ONLY-NOT: "-fsycl-instrument-device-code"
// CHECK-ITT-LINK-ONLY: llvm-link{{.*}} {{.*}}libsycl-itt-{{.*}}

// RUN: %clangxx -fsycl --no-offload-new-driver -fno-sycl-instrument-device-code -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// RUN: %clangxx -fsycl --no-offload-new-driver -fsycl-targets=nvptx64-nvidia-cuda -fno-sycl-instrument-device-code -nocudalib -### %s 2>&1 \
Expand Down
8 changes: 6 additions & 2 deletions clang/test/Driver/sycl-instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
// CHECK-SPIRV-SAME: libsycl-itt-compiler-wrappers.new.o
// CHECK-SPIRV-SAME: libsycl-itt-stubs.new.o

// ITT annotations in device code are disabled by default.
// ITT annotations in device code are disabled by default. However, for SYCL offloading,
// we still link ITT annotations libraries to ensure ABI compatibility with previous release.
// RUN: %clangxx -fsycl --offload-new-driver -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// RUN: | FileCheck -check-prefixes=CHECK-ITT-LINK-ONLY %s
// RUN: %clangxx -fsycl --offload-new-driver -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s

// CHECK-ITT-LINK-ONLY-NOT: "-fsycl-instrument-device-code"
// CHECK-ITT-LINK-ONLY: clang-linker-wrapper{{.*}} {{.*}}libsycl-itt-{{.*}}

// RUN: %clangxx -fsycl --offload-new-driver -fno-sycl-instrument-device-code -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// RUN: %clangxx -fsycl --offload-new-driver -fsycl-targets=nvptx64-nvidia-cuda -fno-sycl-instrument-device-code -nocudalib -### %s 2>&1 \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl-offload-new-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
// RUN: --sysroot=%S/Inputs/SYCL -### %s 2>&1 \
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS %s
// WRAPPER_OPTIONS: clang-linker-wrapper{{.*}} "-sycl-device-libraries=libsycl-crt.new.o,libsycl-complex.new.o,libsycl-complex-fp64.new.o,libsycl-cmath.new.o,libsycl-cmath-fp64.new.o,libsycl-imf.new.o,libsycl-imf-fp64.new.o,libsycl-imf-bf16.new.o,libsycl-fallback-cassert.new.o,libsycl-fallback-cstring.new.o,libsycl-fallback-complex.new.o,libsycl-fallback-complex-fp64.new.o,libsycl-fallback-cmath.new.o,libsycl-fallback-cmath-fp64.new.o,libsycl-fallback-imf.new.o,libsycl-fallback-imf-fp64.new.o,libsycl-fallback-imf-bf16.new.o"
// WRAPPER_OPTIONS: clang-linker-wrapper{{.*}} "-sycl-device-libraries=libsycl-crt.new.o,libsycl-complex.new.o,libsycl-complex-fp64.new.o,libsycl-cmath.new.o,libsycl-cmath-fp64.new.o,libsycl-imf.new.o,libsycl-imf-fp64.new.o,libsycl-imf-bf16.new.o,libsycl-fallback-cassert.new.o,libsycl-fallback-cstring.new.o,libsycl-fallback-complex.new.o,libsycl-fallback-complex-fp64.new.o,libsycl-fallback-cmath.new.o,libsycl-fallback-cmath-fp64.new.o,libsycl-fallback-imf.new.o,libsycl-fallback-imf-fp64.new.o,libsycl-fallback-imf-bf16.new.o,libsycl-itt-user-wrappers.new.o,libsycl-itt-compiler-wrappers.new.o,libsycl-itt-stubs.new.o"
// WRAPPER_OPTIONS-SAME: "-sycl-device-library-location={{.*}}/lib"

/// Verify phases used to generate SPIR-V instead of LLVM-IR
Expand Down

0 comments on commit 620ac35

Please sign in to comment.