Skip to content

Commit 6fd7a1a

Browse files
author
Jeff Hammond
committed
do not assume Linux always has aligned_alloc
Older glibc lacks aligned_alloc (C11 and C++17). Dropping through to the POSIX option (posix_memalign) is necessary on such systems. The lazy way to detect if aligned_alloc is supported is: defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) || defined(_LIBCPP_HAS_C11_FEATURES) This does not work for C++ libraries besides GCC and LLVM (e.g. MUSL) but unless those are explicitly supported and tested, we should not need to include them here anyways. The inclusion of stdlib.h was changed to cstdlib, as appropriate for C++ code. The conditional inclusion of cstdlib in the cpp file was removed since it was included unconditionally in the header. Signed-off-by: Jeff Hammond <[email protected]>
1 parent 8c667b6 commit 6fd7a1a

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

sycl/include/CL/sycl/detail/os_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <CL/sycl/detail/export.hpp>
1515

1616
#include <cstdint>
17-
#include <stdlib.h>
17+
#include <cstdlib>
1818
#include <string>
1919

2020
#ifdef _WIN32

sycl/source/detail/os_util.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
#include <cassert>
1313

14-
#ifdef SYCL_RT_OS_POSIX_SUPPORT
15-
#include <cstdlib>
16-
#endif
17-
1814
#if defined(SYCL_RT_OS_LINUX)
1915

2016
#ifndef _GNU_SOURCE
@@ -242,7 +238,8 @@ size_t OSUtil::getOSMemSize() {
242238
}
243239

244240
void *OSUtil::alignedAlloc(size_t Alignment, size_t NumBytes) {
245-
#if defined(SYCL_RT_OS_LINUX)
241+
#if defined(SYCL_RT_OS_LINUX) && (defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) || \
242+
defined(_LIBCPP_HAS_C11_FEATURES))
246243
return aligned_alloc(Alignment, NumBytes);
247244
#elif defined(SYCL_RT_OS_POSIX_SUPPORT)
248245
void *Addr = nullptr;

0 commit comments

Comments
 (0)