Skip to content

Commit e0e431a

Browse files
add support for backward compatibility
1 parent 29b7540 commit e0e431a

File tree

4 files changed

+62
-30
lines changed

4 files changed

+62
-30
lines changed

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
include(CheckCXXCompilerFlag)
22
set(obj_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
3-
set(obj-new-offload_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
3+
set(obj-old-offload_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
44
if (MSVC)
55
set(obj-suffix obj)
6-
set(obj-new-offload-suffix new.obj)
6+
set(obj-old-offload-suffix old.obj)
77
set(spv_binary_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
88
set(install_dest_spv bin)
99
set(devicelib_host_static_obj sycl-devicelib-host.lib)
10-
set(devicelib_host_static_obj-new-offload sycl-devicelib-host.new.lib)
10+
set(devicelib_host_static_obj-old-offload sycl-devicelib-host.old.lib)
1111
else()
1212
set(obj-suffix o)
13-
set(obj-new-offload-suffix new.o)
13+
set(obj-old-offload-suffix old.o)
1414
set(spv_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
1515
set(install_dest_spv lib${LLVM_LIBDIR_SUFFIX})
1616
set(devicelib_host_static_obj libsycl-devicelib-host.a)
17-
set(devicelib_host_static_obj-new-offload libsycl-devicelib-host.new.a)
17+
set(devicelib_host_static_obj-old-offload libsycl-devicelib-host.old.a)
1818
endif()
1919
set(spv-suffix spv)
2020
set(bc-suffix bc)
2121
set(bc_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
2222
set(install_dest_obj lib${LLVM_LIBDIR_SUFFIX})
23-
set(install_dest_obj-new-offload lib${LLVM_LIBDIR_SUFFIX})
23+
set(install_dest_obj-old-offload lib${LLVM_LIBDIR_SUFFIX})
2424
set(install_dest_bc lib${LLVM_LIBDIR_SUFFIX})
2525

2626
string(CONCAT sycl_targets_opt
@@ -80,8 +80,8 @@ endif()
8080

8181
add_custom_target(libsycldevice)
8282

83-
set(filetypes obj obj-new-offload spv bc)
84-
set(filetypes_no_spv obj obj-new-offload bc)
83+
set(filetypes obj obj-old-offload spv bc)
84+
set(filetypes_no_spv obj obj-old-offload bc)
8585

8686
foreach(filetype IN LISTS filetypes)
8787
add_custom_target(libsycldevice-${filetype})
@@ -109,9 +109,9 @@ endif()
109109

110110
set(spv_device_compile_opts -fsycl-device-only -fsycl-device-obj=spirv)
111111
set(bc_device_compile_opts -fsycl-device-only -fsycl-device-obj=llvmir)
112-
set(obj-new-offload_device_compile_opts -fsycl -c --offload-new-driver
112+
set(obj-old-offload_device_compile_opts -fsycl -c ${sycl_targets_opt})
113+
set(obj_device_compile_opts -fsycl -c --offload-new-driver
113114
-foffload-lto=thin ${sycl_targets_opt})
114-
set(obj_device_compile_opts -fsycl -c ${sycl_targets_opt})
115115

116116
# Compiles and installs a single device library.
117117
#
@@ -364,47 +364,50 @@ if (NOT MSVC AND UR_SANITIZER_INCLUDE_DIR)
364364
-I${UR_SANITIZER_INCLUDE_DIR}
365365
-I${CMAKE_CURRENT_SOURCE_DIR})
366366

367-
set(sanitizer_pvc_compile_opts_obj -fsycl -c
367+
set(sanitizer_pvc_compile_opts_obj -fsycl -c --offload-new-driver
368+
-foffload-lto=thin
368369
${sanitizer_generic_compile_opts}
369370
${sycl_pvc_target_opt}
370371
-D__LIBDEVICE_PVC__)
371372

372-
set(sanitizer_cpu_compile_opts_obj -fsycl -c
373+
set(sanitizer_cpu_compile_opts_obj -fsycl -c --offload-new-driver
374+
-foffload-lto=thin
373375
${sanitizer_generic_compile_opts}
374376
${sycl_cpu_target_opt}
375377
-D__LIBDEVICE_CPU__)
376378

377-
set(sanitizer_dg2_compile_opts_obj -fsycl -c
379+
set(sanitizer_dg2_compile_opts_obj -fsycl -c --offload-new-driver
380+
-foffload-lto=thin
378381
${sanitizer_generic_compile_opts}
379382
${sycl_dg2_target_opt}
380383
-D__LIBDEVICE_DG2__)
381384

382-
set(sanitizer_pvc_compile_opts_bc ${bc_device_compile_opts}
385+
set(sanitizer_pvc_compile_opts_bc ${bc_device_compile_opts} --offload-new-driver
386+
-foffload-lto=thin
383387
${sanitizer_generic_compile_opts}
384388
-D__LIBDEVICE_PVC__)
385389

386-
set(sanitizer_cpu_compile_opts_bc ${bc_device_compile_opts}
390+
set(sanitizer_cpu_compile_opts_bc ${bc_device_compile_opts} --offload-new-driver
391+
-foffload-lto=thin
387392
${sanitizer_generic_compile_opts}
388393
-D__LIBDEVICE_CPU__)
389394

390-
set(sanitizer_dg2_compile_opts_bc ${bc_device_compile_opts}
395+
set(sanitizer_dg2_compile_opts_bc ${bc_device_compile_opts} --offload-new-driver
396+
-foffload-lto=thin
391397
${sanitizer_generic_compile_opts}
392398
-D__LIBDEVICE_DG2__)
393399

394-
set(sanitizer_pvc_compile_opts_obj-new-offload -fsycl -c --offload-new-driver
395-
-foffload-lto=thin
400+
set(sanitizer_pvc_compile_opts_obj-old-offload -fsycl -c
396401
${sanitizer_generic_compile_opts}
397402
${sycl_pvc_target_opt}
398403
-D__LIBDEVICE_PVC__)
399404

400-
set(sanitizer_cpu_compile_opts_obj-new-offload -fsycl -c --offload-new-driver
401-
-foffload-lto=thin
405+
set(sanitizer_cpu_compile_opts_obj-old-offload -fsycl -c
402406
${sanitizer_generic_compile_opts}
403407
${sycl_cpu_target_opt}
404408
-D__LIBDEVICE_CPU__)
405409

406-
set(sanitizer_dg2_compile_opts_obj-new-offload -fsycl -c --offload-new-driver
407-
-foffload-lto=thin
410+
set(sanitizer_dg2_compile_opts_obj-old-offload -fsycl -c
408411
${sanitizer_generic_compile_opts}
409412
${sycl_dg2_target_opt}
410413
-D__LIBDEVICE_DG2__)
@@ -704,8 +707,7 @@ if (NOT WIN32)
704707
add_imf_host_cxx_flags_compile_flags_if_supported("-fcf-protection=full")
705708
endif()
706709

707-
set(obj-new-offload_host_compile_opts ${imf_host_cxx_flags} --offload-new-driver
708-
-foffload-lto=thin)
710+
set(obj-old-offload_host_compile_opts ${imf_host_cxx_flags})
709711
set(obj_host_compile_opts ${imf_host_cxx_flags})
710712

711713
foreach(datatype IN ITEMS fp32 fp64 bf16)
@@ -834,9 +836,9 @@ foreach(arch IN LISTS full_build_archs)
834836
COMPONENT libsycldevice)
835837
endforeach()
836838

837-
# Add host device imf libraries for obj and new offload objects.
839+
# Add host device imf libraries for obj and old offload objects.
838840
foreach(dtype IN ITEMS bf16 fp32 fp64)
839-
foreach(ftype IN ITEMS obj obj-new-offload)
841+
foreach(ftype IN ITEMS obj obj-old-offload)
840842
set(tgt_name imf_fallback_${dtype}_host_${ftype})
841843

842844
add_lib_imf(fallback-imf-${dtype}-host
@@ -864,7 +866,7 @@ foreach(dtype IN ITEMS bf16 fp32 fp64)
864866
endforeach()
865867
endforeach()
866868

867-
foreach(ftype IN ITEMS obj obj-new-offload)
869+
foreach(ftype IN ITEMS obj obj-old-offload)
868870
add_custom_target(imf_host_${ftype}
869871
DEPENDS ${${ftype}_binary_dir}/${devicelib_host_static_${ftype}})
870872
add_custom_command(

sycl/test-e2e/Config/kernel_from_file.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
// RUN: %clangxx -Wno-error=ignored-attributes %sycl_include -DSYCL_DISABLE_FALLBACK_ASSERT %cxx_std_optionc++17 %include_option %t.h %s -o %t.out %sycl_options -Xclang -verify-ignore-unexpected=note,warning %if preview-mode %{-Wno-unused-command-line-argument%}
1616
// RUN: env SYCL_USE_KERNEL_SPV=%t.spv %{run} %t.out
1717

18+
// Check backward compatibility: verify that legacy SYCL object files can be unbundled to extract device code as in previous workflows.
19+
// >> ---- unbundle compiler wrapper and asan device objects
20+
// RUN: clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-itt-compiler-wrappers%obj_ext -output=%t_compiler_wrappers.bc -unbundle
21+
// RUN: %if linux %{ clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-asan%obj_ext -output=%t_asan.bc -unbundle %}
22+
23+
// >> ---- link device code
24+
// RUN: %if linux %{ llvm-link -o=%t_app.bc %t.bc %t_compiler_wrappers.bc %t_asan.bc %} %else %{ llvm-link -o=%t_app.bc %t.bc %t_compiler_wrappers.bc %}
25+
26+
1827
#include <iostream>
1928
#include <sycl/detail/core.hpp>
2029

sycl/test-e2e/SeparateCompile/test.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// >> ---- link device code
1919
// RUN: llvm-link -o=app.bc a_kernel.bc b_kernel.bc %sycl_static_libs_dir/libsycl-itt-compiler-wrappers.bc %sycl_static_libs_dir/libsycl-itt-stubs.bc %sycl_static_libs_dir/libsycl-itt-user-wrappers.bc
2020

21-
2221
// >> ---- produce entries data
2322
// RUN: sycl-post-link -split=auto -emit-param-info -symbols -emit-exported-symbols -o test.table app.bc
2423
//
@@ -38,6 +37,28 @@
3837
// RUN: %clangxx wrapper.o a.o b.o -Wno-unused-command-line-argument -o app.exe %sycl_options
3938
// RUN: %{run} ./app.exe
4039

40+
// Check backward compatibility: verify that legacy SYCL object files can be unbundled to extract device code as in previous workflows.
41+
// >> ---- bundle .o with .spv
42+
// >> run bundler
43+
// RUN: clang-offload-bundler -type=o -targets=host-x86_64,sycl-spir64-pc-linux-gnu -input=a.o -input=a_kernel.bc -output=a_fat.o
44+
// RUN: clang-offload-bundler -type=o -targets=host-x86_64,sycl-spir64-pc-linux-gnu -input=b.o -input=b_kernel.bc -output=b_fat.o
45+
//
46+
// >> ---- unbundle fat objects
47+
// RUN: clang-offload-bundler -type=o -targets=host-x86_64,sycl-spir64-pc-linux-gnu -output=a.o -output=a_kernel.bc -input=a_fat.o -unbundle
48+
// RUN: clang-offload-bundler -type=o -targets=host-x86_64,sycl-spir64-pc-linux-gnu -output=b.o -output=b_kernel.bc -input=b_fat.o -unbundle
49+
//
50+
// As we are doing a separate device compilation here, we need to explicitly
51+
// add the device lib instrumentation (itt_compiler_wrapper)
52+
// >> ---- unbundle compiler wrapper device object
53+
// RUN: clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-itt-compiler-wrappers%obj_ext -output=compiler_wrappers.bc -unbundle
54+
// RUN: clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-itt-stubs%obj_ext -output=itt_stubs.bc -unbundle
55+
// RUN: clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-itt-user-wrappers%obj_ext -output=user_wrappers.bc -unbundle
56+
//
57+
// >> ---- link device code
58+
// RUN: llvm-link -o=app.bc a_kernel.bc b_kernel.bc compiler_wrappers.bc itt_stubs.bc user_wrappers.bc
59+
60+
61+
4162
//==----------- test.cpp - Tests SYCL separate compilation -----------------==//
4263
//
4364
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

sycl/test-e2e/lit.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
213213
config.substitutions.append(
214214
("%sycl_static_libs_dir", config.sycl_libs_dir + "/../lib")
215215
)
216-
config.substitutions.append(("%obj_ext", ".obj"))
216+
config.substitutions.append(("%obj_ext", ".old.obj"))
217217
config.substitutions.append(
218218
("%sycl_include", "-Xclang -isystem -Xclang " + config.sycl_include)
219219
)
220220
elif platform.system() == "Linux":
221221
config.substitutions.append(("%sycl_static_libs_dir", config.sycl_libs_dir))
222-
config.substitutions.append(("%obj_ext", ".o"))
222+
config.substitutions.append(("%obj_ext", ".old.o"))
223223
config.substitutions.append(("%sycl_include", "-isystem " + config.sycl_include))
224224

225225
# Intel GPU FAMILY availability

0 commit comments

Comments
 (0)