diff options
author | Young Jin Kim <youki@microsoft.com> | 2020-03-04 20:24:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-04 20:24:47 +0300 |
commit | f78e60988329b9207d086c743cafce1ac1bea3ab (patch) | |
tree | 1b8b79a4d59d95186f61103d17b59a7b668d15b7 /src/Utils.cc | |
parent | 84e66a976046180187724aff60a236c5378fde7c (diff) | |
parent | b7a88185fbe7661d1216b182bd343a1a7fe2e544 (diff) |
Merge pull request #2 from XapaJIaMnu/restore_mac_support
Support mac again
Diffstat (limited to 'src/Utils.cc')
-rwxr-xr-x | src/Utils.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Utils.cc b/src/Utils.cc index 2e88561..07d1f59 100755 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -17,6 +17,30 @@ namespace fbgemm { +void * genericAlignedAlloc(size_t size, size_t align) { + void* aligned_mem = nullptr; + int ret; +#ifdef _MSC_VER + aligned_mem = _aligned_malloc(size, align); + ret = 0; +#else + ret = posix_memalign(&aligned_mem, align, size); +#endif + // Throw std::bad_alloc in the case of memory allocation failure. + if (ret || aligned_mem == nullptr) { + throw std::bad_alloc(); + } + return aligned_mem; +} + +void genericFree(void * p) { +#ifdef _MSC_VER + _aligned_free(p); +#else + free(p); +#endif +} + /** * @brief Compare the reference and test result matrix to check the correctness. * @param ref The buffer for the reference result matrix. |