Skip to content

Commit 5c6f8b1

Browse files
[SYCL RTC] Add sycl-rtc-experimental-redist-mode option
1 parent 4c83753 commit 5c6f8b1

File tree

10 files changed

+239
-7
lines changed

10 files changed

+239
-7
lines changed

buildbot/configure.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ def do_configure(args, passthrough_args):
179179

180180
install_dir = os.path.join(abs_obj_dir, "install")
181181

182+
llvm_enable_runtimes = "libcxx"
183+
if platform.system() != "Windows":
184+
llvm_enable_runtimes += ";libcxxabi;libunwind"
185+
llvm_enable_runtimes += ";libc"
186+
182187
cmake_cmd = [
183188
"cmake",
184189
"-G",
@@ -195,6 +200,8 @@ def do_configure(args, passthrough_args):
195200
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
196201
"-DLLVM_EXTERNAL_SYCL_JIT_SOURCE_DIR={}".format(jit_dir),
197202
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
203+
"-DLLVM_ENABLE_RUNTIMES={}".format(llvm_enable_runtimes),
204+
"-DLLVM_LIBC_FULL_BUILD=ON",
198205
"-DSYCL_BUILD_PI_HIP_PLATFORM={}".format(sycl_build_pi_hip_platform),
199206
"-DLLVM_BUILD_TOOLS=ON",
200207
"-DLLVM_ENABLE_ZSTD={}".format(llvm_enable_zstd),

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7561,6 +7561,14 @@ let Visibility = [SYCLRTCOnlyOption] in {
75617561
: Joined<["--"], "persistent-auto-pch=">,
75627562
HelpText<"Use Persistent Auto-PCH cache located at <dir> for SYCL "
75637563
"RTC Compilation">;
7564+
def sycl_rtc_exp_redist_mode
7565+
: Flag<["--"], "sycl-rtc-experimental-redist-mode">,
7566+
HelpText<"Use in-memory system includes">;
7567+
def sycl_rtc_in_memory_fs_only
7568+
: Flag<["--"], "sycl-rtc-in-memory-fs-only">,
7569+
HelpText<"Disable real filesystem access for SCYl RTC compilation, "
7570+
"debug/testing only">,
7571+
Flags<[HelpHidden]>;
75647572
} // let Group = sycl_rtc_only_Group
75657573
} // let Visibility = [SYCLRTCOnlyOption]
75667574

sycl-jit/jit-compiler/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,46 @@ add_custom_target(rtc-prepare-resources
4545
${SYCL_JIT_RESOURCE_FILES}
4646
)
4747

48+
set(SYCL_JIT_RUNTIME_RESOURCE_DEPS)
49+
# set(SYCL_JIT_RUNTIME_RESOURCE_DEPS runtimes-configure)
50+
set(SYCL_JIT_RUNTIME_RESOURCE_INSTALL_COMPONENTS)
51+
52+
if ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
53+
list(APPEND SYCL_JIT_RUNTIME_RESOURCE_INSTALL_COMPONENTS cxx-headers)
54+
55+
# Without it: "<...>/"build/include/c++/v1/libcxx.imp": No such file
56+
list(APPEND SYCL_JIT_RUNTIME_RESOURCE_DEPS cxx)
57+
endif()
58+
59+
foreach(component IN LISTS SYCL_JIT_RUNTIME_RESOURCE_INSTALL_COMPONENTS)
60+
list(APPEND SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS
61+
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins --prefix ${CMAKE_CURRENT_BINARY_DIR}/rtc-resources-install --component "${component}"
62+
# COMMAND sed -i 's/_LIBCPP_HAS_THREADS 1/_LIBCPP_HAS_THREADS 0/' ${CMAKE_CURRENT_BINARY_DIR}/rtc-resources-install/include/x86_64-unknown-linux-gnu/c++/v1/__config_site
63+
COMMAND sed -i 's/_LIBCPP_HAS_THREAD_API_EXTERNAL 0/_LIBCPP_HAS_THREAD_API_EXTERNAL 1/' ${CMAKE_CURRENT_BINARY_DIR}/rtc-resources-install/include/x86_64-unknown-linux-gnu/c++/v1/__config_site
64+
)
65+
endforeach()
66+
67+
if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
68+
list(APPEND SYCL_JIT_RUNTIME_RESOURCE_DEPS libc)
69+
list(APPEND SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS
70+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins/libc/include ${SYCL_JIT_RESOURCE_INSTALL_DIR}/include/libc
71+
)
72+
endif()
73+
74+
add_custom_target(rtc-prepare-runtime-resources
75+
DEPENDS ${SYCL_JIT_RUNTIME_RESOURCE_DEPS}
76+
${SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS}
77+
)
78+
4879
add_custom_command(
4980
OUTPUT ${SYCL_JIT_RESOURCE_CPP}
5081
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/generate.py --toolchain-dir ${SYCL_JIT_RESOURCE_INSTALL_DIR} --output ${SYCL_JIT_RESOURCE_CPP} --prefix ${SYCL_JIT_VIRTUAL_TOOLCHAIN_ROOT}
5182
DEPENDS
5283
rtc-prepare-resources
5384
${SYCL_JIT_RESOURCE_DEPS}
5485
${SYCL_JIT_RESOURCE_FILES}
86+
rtc-prepare-runtime-resources
87+
${SYCL_JIT_RUNTIME_RESOURCE_DEPS}
5588
${CMAKE_CURRENT_SOURCE_DIR}/utils/generate.py
5689
)
5790

@@ -94,6 +127,7 @@ add_custom_command(
94127
${SYCL_JIT_RESOURCE_CPP}
95128
${SYCL_JIT_RESOURCE_DEPS}
96129
${SYCL_JIT_RESOURCE_FILES}
130+
${SYCL_JIT_RUNTIME_RESOURCE_DEPS}
97131
${CMAKE_CURRENT_SOURCE_DIR}/include/Resource.h
98132
)
99133

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
_LIBCPP_BEGIN_NAMESPACE_STD
2+
3+
using __libcpp_timespec_t = int;
4+
5+
//
6+
// Mutex
7+
//
8+
using __libcpp_mutex_t = int;
9+
#define _LIBCPP_MUTEX_INITIALIZER 0
10+
11+
using __libcpp_recursive_mutex_t = int;
12+
13+
int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t*);
14+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t*);
15+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t*);
16+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t*);
17+
int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t*);
18+
19+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_lock(__libcpp_mutex_t*);
20+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_mutex_trylock(__libcpp_mutex_t*);
21+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_unlock(__libcpp_mutex_t*);
22+
int __libcpp_mutex_destroy(__libcpp_mutex_t*);
23+
24+
//
25+
// Condition Variable
26+
//
27+
using __libcpp_condvar_t = int;
28+
#define _LIBCPP_CONDVAR_INITIALIZER 0
29+
30+
int __libcpp_condvar_signal(__libcpp_condvar_t*);
31+
int __libcpp_condvar_broadcast(__libcpp_condvar_t*);
32+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_condvar_wait(__libcpp_condvar_t*, __libcpp_mutex_t*);
33+
_LIBCPP_NO_THREAD_SAFETY_ANALYSIS
34+
int __libcpp_condvar_timedwait(__libcpp_condvar_t*, __libcpp_mutex_t*, __libcpp_timespec_t*);
35+
int __libcpp_condvar_destroy(__libcpp_condvar_t*);
36+
37+
//
38+
// Execute once
39+
//
40+
using __libcpp_exec_once_flag = int;
41+
#define _LIBCPP_EXEC_ONCE_INITIALIZER 0
42+
43+
int __libcpp_execute_once(__libcpp_exec_once_flag*, void (*__init_routine)());
44+
45+
//
46+
// Thread id
47+
//
48+
using __libcpp_thread_id = int;
49+
50+
bool __libcpp_thread_id_equal(__libcpp_thread_id, __libcpp_thread_id);
51+
bool __libcpp_thread_id_less(__libcpp_thread_id, __libcpp_thread_id);
52+
53+
//
54+
// Thread
55+
//
56+
#define _LIBCPP_NULL_THREAD 0
57+
using __libcpp_thread_t = int;
58+
59+
bool __libcpp_thread_isnull(const __libcpp_thread_t*);
60+
int __libcpp_thread_create(__libcpp_thread_t*, void* (*__func)(void*), void* __arg);
61+
__libcpp_thread_id __libcpp_thread_get_current_id();
62+
__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t*);
63+
int __libcpp_thread_join(__libcpp_thread_t*);
64+
int __libcpp_thread_detach(__libcpp_thread_t*);
65+
void __libcpp_thread_yield();
66+
void __libcpp_thread_sleep_for(const chrono::nanoseconds&);
67+
68+
//
69+
// Thread local storage
70+
//
71+
#define _LIBCPP_TLS_DESTRUCTOR_CC 0
72+
using __libcpp_tls_key = int;
73+
74+
int __libcpp_tls_create(__libcpp_tls_key*, void (*__at_exit)(void*));
75+
void* __libcpp_tls_get(__libcpp_tls_key);
76+
int __libcpp_tls_set(__libcpp_tls_key, void*);
77+
78+
_LIBCPP_END_NAMESPACE_STD

sycl-jit/jit-compiler/lib/resource-includes/include/sycl-rtc-standalone/linux/errno.h

Whitespace-only changes.

sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,26 @@ class SYCLToolchain {
262262
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_offload_arch_EQ), CPU);
263263
}
264264

265+
if (UserArgList.hasArg(OPT_sycl_rtc_exp_redist_mode)) {
266+
DAL.AddFlagArg(nullptr, OptTable.getOption(OPT_nostdlibinc));
267+
auto AddInc = [&](auto RelPath) {
268+
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_isystem),
269+
(getPrefix() + RelPath).str());
270+
};
271+
AddInc("include/sycl/stl_wrappers");
272+
AddInc("include/x86_64-unknown-linux-gnu/c++/v1");
273+
AddInc("include/c++/v1");
274+
AddInc("include/libc");
275+
AddInc("include/");
276+
AddInc("include/sycl-rtc-standalone/");
277+
AddInc("include/lib/clang/22/include/");
278+
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_D),
279+
"_LIBCPP_REMOVE_TRANSITIVE_INCLUDES");
280+
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_include), "stdio.h");
281+
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_include), "wchar.h");
282+
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_include), "time.h");
283+
}
284+
265285
ArgStringList ASL;
266286
for (Arg *A : DAL)
267287
A->render(DAL, ASL);
@@ -543,9 +563,15 @@ class SYCLToolchain {
543563
std::vector<std::string> CommandLine =
544564
createCommandLine(UserArgList, Format, SourceFilePath);
545565

546-
auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
547-
llvm::vfs::getRealFileSystem());
548-
FS->pushOverlay(getToolchainFS());
566+
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FS;
567+
if (UserArgList.hasArg(OPT_sycl_rtc_in_memory_fs_only)) {
568+
FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
569+
getToolchainFS());
570+
} else {
571+
FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
572+
llvm::vfs::getRealFileSystem());
573+
FS->pushOverlay(getToolchainFS());
574+
}
549575
if (FSOverlay)
550576
FS->pushOverlay(std::move(FSOverlay));
551577

sycl-jit/jit-compiler/utils/generate.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def main():
3232
const resource_file ToolchainFiles[] = {"""
3333
)
3434

35-
def process_file(file_path):
35+
def process_file(file_path, relative_to):
3636
out.write(
3737
f"""
3838
{{
39-
{{"{args.prefix}{os.path.relpath(file_path, toolchain_dir).replace(os.sep, "/")}"}} ,
39+
{{"{args.prefix}{os.path.relpath(file_path, relative_to).replace(os.sep, "/")}"}} ,
4040
[]() {{
4141
static const char data[] = {{
4242
#embed "{file_path}" if_empty(0)
@@ -50,9 +50,17 @@ def process_dir(dir):
5050
for root, _, files in os.walk(dir):
5151
for file in files:
5252
file_path = os.path.join(root, file)
53-
process_file(file_path)
53+
process_file(file_path, dir)
5454

5555
process_dir(args.toolchain_dir)
56+
process_dir(
57+
os.path.realpath(
58+
os.path.join(
59+
os.path.dirname(os.path.realpath(__file__)),
60+
"../lib/resource-includes/"
61+
)
62+
)
63+
)
5664

5765
out.write(
5866
f"""

sycl/include/sycl/builtins.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ extern __DPCPP_SYCL_EXTERNAL_LIBC char *strncpy(char *dest, const char *src,
2727
extern __DPCPP_SYCL_EXTERNAL_LIBC int strcmp(const char *s1, const char *s2);
2828
extern __DPCPP_SYCL_EXTERNAL_LIBC int strncmp(const char *s1, const char *s2,
2929
size_t n);
30+
#ifdef __LLVM_LIBC__
31+
extern __DPCPP_SYCL_EXTERNAL_LIBC int rand() noexcept;
32+
extern __DPCPP_SYCL_EXTERNAL_LIBC void srand(unsigned int seed) noexcept;
33+
#else
3034
extern __DPCPP_SYCL_EXTERNAL_LIBC int rand();
3135
extern __DPCPP_SYCL_EXTERNAL_LIBC void srand(unsigned int seed);
36+
#endif
3237
extern __DPCPP_SYCL_EXTERNAL long long int __imf_llmax(long long int x,
3338
long long int y);
3439
extern __DPCPP_SYCL_EXTERNAL long long int __imf_llmin(long long int x,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %{build} -o %t.out
2+
// DEFINE: %{test_env} = %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %}
3+
4+
// RUN: %{test_env} %{run} %t.out
5+
6+
// Make sure that debug/test-only option `--sycl-rtc-in-memory-fs-only` works
7+
// RUN: %{test_env} %{run} not %t.out --sycl-rtc-in-memory-fs-only | FileCheck %s --check-prefix CHECK-ERROR
8+
// CHECK-ERROR-LABEL: Device compilation failed
9+
// CHECK-ERROR-NEXT: Detailed information:
10+
// CHECK-ERROR: In file included from rtc_0.cpp:2:
11+
// CHECK-ERROR-NEXT: In file included from /sycl-jit-toolchain//bin/../include/sycl/sycl.hpp:38:
12+
// CHECK-ERROR-NEXT: In file included from /sycl-jit-toolchain//bin/../include/sycl/detail/core.hpp:21:
13+
// CHECK-ERROR-NEXT: In file included from /sycl-jit-toolchain//bin/../include/sycl/accessor.hpp:11:
14+
// CHECK-ERROR-NEXT: /sycl-jit-toolchain//bin/../include/sycl/access/access.hpp:14:10: fatal error: 'type_traits' file not found
15+
// CHECK-ERROR-NEXT: 14 | #include <type_traits>
16+
// CHECK-ERROR-NEXT: | ^~~~~~~~~~~~~
17+
18+
// Now actually test the `--sycl-rtc-experimental-redist-mode` option:
19+
// RUN: %{test_env} %{run} %t.out --sycl-rtc-experimental-redist-mode --sycl-rtc-in-memory-fs-only
20+
// RUN: %{test_env} %{run} %t.out --sycl-rtc-experimental-redist-mode
21+
22+
// XFAIL: target-native_cpu
23+
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/20142
24+
25+
#include <sycl/detail/core.hpp>
26+
#include <sycl/kernel_bundle.hpp>
27+
#include <sycl/usm.hpp>
28+
29+
namespace syclexp = sycl::ext::oneapi::experimental;
30+
31+
int main(int argc, char *argv[]) {
32+
sycl::queue q;
33+
std::string source = R"""(
34+
#include <sycl/sycl.hpp>
35+
namespace syclext = sycl::ext::oneapi;
36+
namespace syclexp = sycl::ext::oneapi::experimental;
37+
38+
extern "C"
39+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel))
40+
void foo(int *p) {
41+
*p = 42;
42+
}
43+
)""";
44+
std::vector<std::string> opts;
45+
for (int i = 1; i < argc; ++i)
46+
opts.emplace_back(argv[i]);
47+
try {
48+
49+
auto kb_src = syclexp::create_kernel_bundle_from_source(
50+
q.get_context(), syclexp::source_language::sycl, source);
51+
auto kb_exe = syclexp::build(
52+
kb_src, syclexp::properties{syclexp::build_options{opts}});
53+
sycl::kernel krn = kb_exe.ext_oneapi_get_kernel("foo");
54+
auto *p = sycl::malloc_shared<int>(1, q);
55+
q.submit([&](sycl::handler &cgh) {
56+
cgh.set_args(p);
57+
cgh.single_task(krn);
58+
}).wait();
59+
std::cout << "Result: " << *p << std::endl;
60+
assert(*p == 42);
61+
sycl::free(p, q);
62+
} catch (const sycl::exception &e) {
63+
std::cout << e.what();
64+
return 1;
65+
}
66+
}

sycl/test/e2e_test_requirements/no_sycl_hpp_in_e2e_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// CHECK-DAG: README.md
77
// CHECK-DAG: lit.cfg.py
88
//
9-
// CHECK-NUM-MATCHES: 29
9+
// CHECK-NUM-MATCHES: 30
1010
//
1111
// This test verifies that `<sycl/sycl.hpp>` isn't used in E2E tests. Instead,
1212
// fine-grained includes should used, see

0 commit comments

Comments
 (0)