Skip to content

Commit 7dd93c9

Browse files
authored
[SYCL][NFC] Mark external libc functions. (#19368)
<sycl/detail/defines_elementary.hpp> defines a __DPCPP_SYCL_EXTERNAL macro for functions that are defined elsewhere. This macro is used both for functions defined by the platform's system libraries and for functions defined in libclc/libdevice. For Native CPU, these should be treated differently: functions defined by the platform's system libraries should be processed according to the platform's ABI, functions defined by libclc/libdevice should be processed in a host-target-independent way. Therefore, this PR introduces a __DPCPP_SYCL_EXTERNAL_LIBC macro so that libc functions can be tagged as such. This PR does not yet make the changes to Native CPU to define __DPCPP_SYCL_EXTERNAL and __DPCPP_SYCL_EXTERNAL_LIBC differently.
1 parent 3d8e049 commit 7dd93c9

File tree

3 files changed

+206
-170
lines changed

3 files changed

+206
-170
lines changed

sycl/include/sycl/builtins.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#ifdef __SYCL_DEVICE_ONLY__
1616
extern "C" {
1717

18-
extern __DPCPP_SYCL_EXTERNAL void *memcpy(void *dest, const void *src,
19-
size_t n);
20-
extern __DPCPP_SYCL_EXTERNAL void *memset(void *dest, int c, size_t n);
21-
extern __DPCPP_SYCL_EXTERNAL int memcmp(const void *s1, const void *s2,
22-
size_t n);
23-
extern __DPCPP_SYCL_EXTERNAL int rand();
24-
extern __DPCPP_SYCL_EXTERNAL void srand(unsigned int seed);
18+
extern __DPCPP_SYCL_EXTERNAL_LIBC void *memcpy(void *dest, const void *src,
19+
size_t n);
20+
extern __DPCPP_SYCL_EXTERNAL_LIBC void *memset(void *dest, int c, size_t n);
21+
extern __DPCPP_SYCL_EXTERNAL_LIBC int memcmp(const void *s1, const void *s2,
22+
size_t n);
23+
extern __DPCPP_SYCL_EXTERNAL_LIBC int rand();
24+
extern __DPCPP_SYCL_EXTERNAL_LIBC void srand(unsigned int seed);
2525
extern __DPCPP_SYCL_EXTERNAL long long int __imf_llmax(long long int x,
2626
long long int y);
2727
extern __DPCPP_SYCL_EXTERNAL long long int __imf_llmin(long long int x,
@@ -634,15 +634,15 @@ extern __DPCPP_SYCL_EXTERNAL int __imf_vimin_s32_relu(int x, int y);
634634
}
635635
#ifdef __GLIBC__
636636
namespace std {
637-
extern __DPCPP_SYCL_EXTERNAL void
637+
extern __DPCPP_SYCL_EXTERNAL_LIBC void
638638
__glibcxx_assert_fail(const char *file, int line, const char *func,
639639
const char *cond) noexcept;
640640
} // namespace std
641641
extern "C" {
642-
extern __DPCPP_SYCL_EXTERNAL void __assert_fail(const char *expr,
643-
const char *file,
644-
unsigned int line,
645-
const char *func);
642+
extern __DPCPP_SYCL_EXTERNAL_LIBC void __assert_fail(const char *expr,
643+
const char *file,
644+
unsigned int line,
645+
const char *func);
646646
}
647647
#elif defined(_WIN32)
648648
extern "C" {
@@ -652,8 +652,8 @@ extern "C" {
652652
// APIs used by STL, such as _Cosh, are undocumented, even though
653653
// they are open-sourced. Recognizing them as builtins is not
654654
// straightforward currently.
655-
extern __DPCPP_SYCL_EXTERNAL void _wassert(const wchar_t *wexpr,
656-
const wchar_t *wfile, unsigned line);
655+
extern __DPCPP_SYCL_EXTERNAL_LIBC void
656+
_wassert(const wchar_t *wexpr, const wchar_t *wfile, unsigned line);
657657
}
658658
#endif
659659
#endif // __SYCL_DEVICE_ONLY__

sycl/include/sycl/detail/defines_elementary.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#endif
3636
#endif
3737

38+
#ifndef __DPCPP_SYCL_EXTERNAL_LIBC
39+
#define __DPCPP_SYCL_EXTERNAL_LIBC __DPCPP_SYCL_EXTERNAL
40+
#endif
41+
3842
// Helper for enabling empty-base optimizations on MSVC.
3943
// TODO: Remove this when MSVC has this optimization enabled by default.
4044
#ifdef _MSC_VER

0 commit comments

Comments
 (0)