Skip to content

Commit 117641e

Browse files
authored
[SYCL] Use same source for libsycl-crt (#3019)
Currently, the implementation of assert support for Linux and Windows are in 2 files glibc_wrapper.cpp and msvc_wrapper.cpp. We can merge them into one source and use macro "_WIN32" to separate Windows and Linux specific code. We plan to add some more functions in libsycl-crt in the future and the implementation may be same for both Linux and Windows platform, keeping 2 different sources for Linux and Windows will lead to duplicate code then. Signed-off-by: gejin <[email protected]>
1 parent 37a9a2a commit 117641e

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ set(obj_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
22
if (WIN32)
33
set(lib-suffix obj)
44
set(spv_binary_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
5-
set(lib_crt_source msvc_wrapper.cpp)
65
else()
76
set(lib-suffix o)
87
set(spv_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
9-
set(lib_crt_source glibc_wrapper.cpp)
108
endif()
119
set(clang $<TARGET_FILE:clang>)
1210

@@ -33,9 +31,9 @@ set(devicelib-obj-file ${obj_binary_dir}/libsycl-crt.${lib-suffix})
3331
add_custom_command(OUTPUT ${devicelib-obj-file}
3432
COMMAND ${clang} -fsycl -c
3533
${compile_opts} ${sycl_targets_opt}
36-
${CMAKE_CURRENT_SOURCE_DIR}/${lib_crt_source}
34+
${CMAKE_CURRENT_SOURCE_DIR}/crt_wrapper.cpp
3735
-o ${devicelib-obj-file}
38-
MAIN_DEPENDENCY ${lib_crt_source}
36+
MAIN_DEPENDENCY crt_wrapper.cpp
3937
DEPENDS wrapper.h device.h spirv_vars.h clang clang-offload-bundler
4038
VERBATIM)
4139

libdevice/msvc_wrapper.cpp renamed to libdevice/crt_wrapper.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==--- msvc_wrapper.cpp - wrappers for Microsoft C library functions ------==//
1+
//==------ crt_wrapper.cpp - wrappers for libc internal functions ----------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,6 +9,7 @@
99
#include "wrapper.h"
1010

1111
#ifdef __SPIR__
12+
#if defined(_WIN32)
1213
// Truncates a wide (16 or 32 bit) string (wstr) into an ASCII string (str).
1314
// Any non-ASCII characters are replaced by question mark '?'.
1415
static void __truncate_wchar_char_str(const wchar_t *wstr, char *str,
@@ -37,4 +38,15 @@ void _wassert(const wchar_t *wexpr, const wchar_t *wfile, unsigned line) {
3738
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
3839
__spirv_LocalInvocationId_z());
3940
}
41+
#else
42+
DEVICE_EXTERN_C
43+
void __assert_fail(const char *expr, const char *file, unsigned int line,
44+
const char *func) {
45+
__devicelib_assert_fail(
46+
expr, file, line, func, __spirv_GlobalInvocationId_x(),
47+
__spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(),
48+
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
49+
__spirv_LocalInvocationId_z());
50+
}
51+
#endif
4052
#endif // __SPIR__

libdevice/glibc_wrapper.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)