Skip to content

Commit 9d0562d

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

File tree

10 files changed

+232
-7
lines changed

10 files changed

+232
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,40 @@ add_custom_target(rtc-prepare-resources
4545
${SYCL_JIT_RESOURCE_FILES}
4646
)
4747

48+
set(SYCL_JIT_RUNTIME_RESOURCE_DEPS)
49+
set(SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS)
50+
51+
if ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
52+
list(APPEND SYCL_JIT_RUNTIME_RESOURCE_DEPS runtimes-configure)
53+
54+
list(APPEND SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS
55+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins --target generate-cxx-headers
56+
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins --prefix ${CMAKE_CURRENT_BINARY_DIR}/rtc-resources-install --component cxx-headers
57+
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
58+
)
59+
endif()
60+
61+
if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
62+
list(APPEND SYCL_JIT_RUNTIME_RESOURCE_DEPS libc)
63+
list(APPEND SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS
64+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins/libc/include ${SYCL_JIT_RESOURCE_INSTALL_DIR}/include/libc
65+
)
66+
endif()
67+
68+
add_custom_target(rtc-prepare-runtime-resources
69+
DEPENDS ${SYCL_JIT_RUNTIME_RESOURCE_DEPS}
70+
${SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS}
71+
)
72+
4873
add_custom_command(
4974
OUTPUT ${SYCL_JIT_RESOURCE_CPP}
5075
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}
5176
DEPENDS
5277
rtc-prepare-resources
5378
${SYCL_JIT_RESOURCE_DEPS}
5479
${SYCL_JIT_RESOURCE_FILES}
80+
rtc-prepare-runtime-resources
81+
${SYCL_JIT_RUNTIME_RESOURCE_DEPS}
5582
${CMAKE_CURRENT_SOURCE_DIR}/utils/generate.py
5683
)
5784

@@ -94,6 +121,7 @@ add_custom_command(
94121
${SYCL_JIT_RESOURCE_CPP}
95122
${SYCL_JIT_RESOURCE_DEPS}
96123
${SYCL_JIT_RESOURCE_FILES}
124+
${SYCL_JIT_RUNTIME_RESOURCE_DEPS}
97125
${CMAKE_CURRENT_SOURCE_DIR}/include/Resource.h
98126
)
99127

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

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)