9
9
#include < CL/sycl/detail/os_util.hpp>
10
10
#include < CL/sycl/exception.hpp>
11
11
12
+ #ifdef SYCL_RT_OS_POSIX_SUPPORT
13
+ #include < cstdlib>
14
+ #endif
15
+
12
16
#if defined(SYCL_RT_OS_LINUX)
13
17
14
18
#ifndef _GNU_SOURCE
15
19
#define _GNU_SOURCE
16
20
#endif // _GNU_SOURCE
17
21
22
+ #include < cstdio>
18
23
#include < link.h>
19
- #include < stdio.h>
20
24
#include < sys/sysinfo.h>
21
25
22
26
#elif defined(SYCL_RT_OS_WINDOWS)
23
27
24
28
#include < Windows.h>
25
29
#include < malloc.h>
26
- #endif
30
+
31
+ #elif defined(SYCL_RT_OS_DARWIN)
32
+
33
+ #include < dlfcn.h>
34
+ #include < sys/sysctl.h>
35
+ #include < sys/types.h>
36
+
37
+ #endif // SYCL_RT_OS
27
38
28
39
namespace cl {
29
40
namespace sycl {
@@ -73,15 +84,23 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
73
84
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
74
85
auto LpModuleAddr = reinterpret_cast <LPCSTR>(VirtAddr);
75
86
if (!GetModuleHandleExA (Flag, LpModuleAddr, &PhModule)) {
76
- // Expect the caller to check for zero and take
77
- // necessary action
78
- return 0 ;
87
+ // Expect the caller to check for zero and take
88
+ // necessary action
89
+ return 0 ;
79
90
}
80
91
if (PhModule == GetModuleHandleA (nullptr ))
81
92
return OSUtil::ExeModuleHandle;
82
93
return reinterpret_cast <OSModuleHandle>(PhModule);
83
94
}
84
- #endif // SYCL_RT_OS_WINDOWS
95
+
96
+ #elif defined(SYCL_RT_OS_DARWIN)
97
+ OSModuleHandle OSUtil::getOSModuleHandle (const void *VirtAddr) {
98
+ Dl_info Res;
99
+ dladdr (VirtAddr, &Res);
100
+ return reinterpret_cast <OSModuleHandle>(Res.dli_fbase );
101
+ }
102
+
103
+ #endif // SYCL_RT_OS
85
104
86
105
size_t OSUtil::getOSMemSize () {
87
106
#if defined(SYCL_RT_OS_LINUX)
@@ -93,19 +112,27 @@ size_t OSUtil::getOSMemSize() {
93
112
MemInfo.dwLength = sizeof (MemInfo);
94
113
GlobalMemoryStatusEx (&MemInfo);
95
114
return static_cast <size_t >(MemInfo.ullTotalPhys );
96
- #endif
115
+ #elif defined(SYCL_RT_OS_DARWIN)
116
+ int64_t Size = 0 ;
117
+ sysctlbyname (" hw.memsize" , &Size, nullptr , nullptr , 0 );
118
+ return static_cast <size_t >(Size);
119
+ #endif // SYCL_RT_OS
97
120
}
98
121
99
122
void *OSUtil::alignedAlloc (size_t Alignment, size_t NumBytes) {
100
123
#if defined(SYCL_RT_OS_LINUX)
101
124
return aligned_alloc (Alignment, NumBytes);
125
+ #elif defined(SYCL_RT_OS_POSIX_SUPPORT)
126
+ void *Addr = nullptr ;
127
+ int ReturnCode = posix_memalign (&Addr, Alignment, NumBytes);
128
+ return (ReturnCode == 0 ) ? Addr : nullptr ;
102
129
#elif defined(SYCL_RT_OS_WINDOWS)
103
130
return _aligned_malloc (NumBytes, Alignment);
104
131
#endif
105
132
}
106
133
107
134
void OSUtil::alignedFree (void *Ptr) {
108
- #if defined(SYCL_RT_OS_LINUX)
135
+ #if defined(SYCL_RT_OS_LINUX) || defined(SYCL_RT_OS_POSIX_SUPPORT)
109
136
free (Ptr);
110
137
#elif defined(SYCL_RT_OS_WINDOWS)
111
138
_aligned_free (Ptr);
0 commit comments