[Mlir-commits] [mlir] 48a1a99 - [mlir] Fall back to posix_memalign for aligned_alloc on MacOS

Benjamin Kramer llvmlistbot at llvm.org
Tue Jul 26 02:32:19 PDT 2022


Author: Benjamin Kramer
Date: 2022-07-26T11:29:37+02:00
New Revision: 48a1a993fb7a8fc8a79e142de0aa43dcb4702533

URL: https://github.com/llvm/llvm-project/commit/48a1a993fb7a8fc8a79e142de0aa43dcb4702533
DIFF: https://github.com/llvm/llvm-project/commit/48a1a993fb7a8fc8a79e142de0aa43dcb4702533.diff

LOG: [mlir] Fall back to posix_memalign for aligned_alloc on MacOS

aligned_alloc was added in MacOS 10.15, some users want to support older
versions. The runtime functions makes this easy, so just put in a call
to posix_memalign, which provides the same functionality.

Added: 
    

Modified: 
    mlir/lib/ExecutionEngine/CRunnerUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
index e6ed5fabad30b..f2a43a5de95f0 100644
--- a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
+++ b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
@@ -127,6 +127,12 @@ extern "C" void *_mlir_alloc(uint64_t size) { return malloc(size); }
 extern "C" void *_mlir_aligned_alloc(uint64_t alignment, uint64_t size) {
 #ifdef _WIN32
   return _aligned_malloc(size, alignment);
+#elif defined(__APPLE__)
+  // aligned_alloc was added in MacOS 10.15. Fall back to posix_memalign to also
+  // support older versions.
+  void *result = nullptr;
+  (void)::posix_memalign(&result, alignment, size);
+  return result;
 #else
   return aligned_alloc(alignment, size);
 #endif


        


More information about the Mlir-commits mailing list