diff options
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. |