Skip to content

Commit

Permalink
[Bugfix][VTA] Fix FSIM compile error on macOS (#14655)
Browse files Browse the repository at this point in the history
* [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.

* Fix format.
  • Loading branch information
xhmelon committed Nov 6, 2023
1 parent ffa0033 commit 03f7b3b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vta/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "runtime.h"

#include <dmlc/logging.h>
#include <malloc.h>
#include <stdlib.h>
#include <tvm/runtime/c_runtime_api.h>
#include <vta/driver.h>
Expand Down Expand Up @@ -76,7 +75,12 @@ class AlignmentAllocator : public std::allocator<T> {

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); }

Expand Down Expand Up @@ -528,7 +532,9 @@ class UopQueue : public BaseQueue<VTAUop> {
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;
Expand Down

0 comments on commit 03f7b3b

Please sign in to comment.