Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolay Bogoychev <nheart@gmail.com>2020-01-22 20:12:17 +0300
committerNikolay Bogoychev <nheart@gmail.com>2020-01-22 20:12:17 +0300
commit4f7a50b504b0bd3bbb8f0f9804ef8c4bfa97925e (patch)
treed5c761a754354be8fa0e17af031946b87f0d7483
parent1cd6f6b83a8e110ac3e44d7d1effdec65bbe9bb6 (diff)
Use posix_memalign on mac, and proper aligned_alloc elsewheremac_support
-rw-r--r--CMakeLists.txt6
-rw-r--r--aligned.h9
2 files changed, 8 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc757d0..5baf7b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,11 +8,7 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
-if(APPLE)
- set(CMAKE_CXX_STANDARD 17) # aligned_alloc doesn't work otherwise
-else(APPLE)
- set(CMAKE_CXX_STANDARD 11)
-endif(APPLE)
+set(CMAKE_CXX_STANDARD 11)
# Check if compiler supports AVX512
try_compile(INTGEMM_COMPILER_SUPPORTS_AVX512
diff --git a/aligned.h b/aligned.h
index b5512ba..1155a62 100644
--- a/aligned.h
+++ b/aligned.h
@@ -1,6 +1,6 @@
#pragma once
#include <cstdlib>
-#include <algorithm>
+#include <stdlib.h>
// 64-byte aligned simple vector.
@@ -9,7 +9,12 @@ namespace intgemm {
template <class T> class AlignedVector {
public:
explicit AlignedVector(std::size_t size)
- : mem_(static_cast<T*>(aligned_alloc(64, (size * sizeof(T) + 63) & ~63))), size_(size) {
+ : size_(size) {
+ #ifdef __APPLE__
+ posix_memalign(reinterpret_cast<void **>(&mem_), 64, size * sizeof(T));
+ #else
+ mem_ = aligned_alloc(64, (size * sizeof(T) + 63) & ~63))); # pedantic requirements for memory size on aligned_alloc in case it's not just a call to posix_memalign
+ #endif
}
AlignedVector(const AlignedVector&) = delete;