From cf27635b26151e77065a23836136f2f098ed02ec Mon Sep 17 00:00:00 2001 From: Zijiang Yang Date: Tue, 18 Apr 2023 16:40:33 +0800 Subject: [PATCH] [Bugfix][VTA] Fix FSIM compile error on macOS. VTA FSIM could not be built on macOS, for it leverages malloc.h and memalign, yet both have been deprecated and are not provided by macOS. This issue was captured in #13173. This commit stops including malloc.h in VTA Runtime as stdlib.h has provided functions we need. This commit uses posix_memalign instead of memalign. It is a portable standard function. --- vta/runtime/runtime.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vta/runtime/runtime.cc b/vta/runtime/runtime.cc index c3d37a13133b..6ffcfd90f33a 100644 --- a/vta/runtime/runtime.cc +++ b/vta/runtime/runtime.cc @@ -27,7 +27,6 @@ #include "runtime.h" #include -#include #include #include #include @@ -76,7 +75,12 @@ class AlignmentAllocator : public std::allocator { inline const_pointer address(const_reference r) const { return &r; } - inline pointer allocate(size_type n) { return (pointer)memalign(N, n * sizeof(value_type)); } + inline pointer allocate(size_type n) { + pointer mem = nullptr; + const int err = posix_memalign((void **) &mem, N, n * sizeof(value_type)); + ICHECK_EQ(err, 0) << "InternalError: failed to allocate aligned memory. "; + return mem; + } inline void deallocate(pointer p, size_type) { free(p); } @@ -528,7 +532,9 @@ class UopQueue : public BaseQueue { total_size += ksize; } - char* lbuf = (char*)memalign(ALLOC_ALIGNMENT, total_size); + char* lbuf = nullptr; + const int err = posix_memalign((void **) &lbuf, ALLOC_ALIGNMENT, total_size); + ICHECK_EQ(err, 0) << "InternalError: failed to allocate aligned memory for load buffer. "; uint32_t offset = 0; for (uint32_t i = 0; i < cache_.size(); ++i) { uint32_t ksize = cache_[i]->size() * kElemBytes;