This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 03f7b3b852 [Bugfix][VTA] Fix FSIM compile error on macOS (#14655)
03f7b3b852 is described below

commit 03f7b3b8525ed81b6b7213df7032869d408a7403
Author: XinhuaHamiMelon <[email protected]>
AuthorDate: Tue Nov 7 00:34:55 2023 +0800

    [Bugfix][VTA] Fix FSIM compile error on macOS (#14655)
    
    * [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.
---
 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 c3d37a1313..66a428cc55 100644
--- a/vta/runtime/runtime.cc
+++ b/vta/runtime/runtime.cc
@@ -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>
@@ -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); }
 
@@ -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;

Reply via email to