[NNUE] Wrap aligned_alloc

For some systems std::aligned_alloc is not available even if c++17 is specified.
Wrap the function and use specific solutions.

Update macosx-version-min to the required minimum.

No functional change.
This commit is contained in:
Joost VandeVondele
2020-07-26 20:32:00 +02:00
parent 2b0ba70436
commit 98ffe0cd97
5 changed files with 31 additions and 4 deletions
+24
View File
@@ -46,6 +46,7 @@ typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdlib.h>
@@ -293,6 +294,29 @@ void prefetch(void* addr) {
#endif
/// Wrappers for systems where the c++17 implementation doesn't guarantee the availability of aligned_alloc.
/// Memory allocated with std_aligned_alloc must be freed with std_aligned_free.
///
void* std_aligned_alloc(size_t alignment, size_t size) {
#if defined(__APPLE__)
return aligned_alloc(alignment, size);
#elif defined(_MSC_VER)
return _aligned_alloc(size, alignment);
#else
return std::aligned_alloc(alignment, size);
#endif
}
void std_aligned_free(void* ptr) {
#if defined(__APPLE__)
free(ptr);
#elif defined(_MSC_VER)
_aligned_free(ptr);
#else
free(ptr);
#endif
}
/// aligned_ttmem_alloc() will return suitably aligned memory, and if possible use large pages.
/// The returned pointer is the aligned one, while the mem argument is the one that needs