1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-08-25 06:31:45 +02:00

Now using posix_memalign

This commit is contained in:
Anthony Scemama 2023-10-06 11:33:33 +02:00
parent eaa44b45c4
commit a7523fbf77
2 changed files with 20 additions and 14 deletions

View File

@ -518,21 +518,27 @@ AC_MSG_RESULT([$ivdep])
# Checking ALIGNED # Checking ALIGNED
AC_MSG_CHECKING([for aligned_alloc]) AC_MSG_CHECKING([for posix_memalign])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#include <stdio.h>
]], [[ ]], [[
int main() { int main() {
void * pointer = aligned_alloc(64, 100); void *ptr;
free(pointer); int ret = posix_memalign(&ptr, 64, 1024);
if (ret != 0) {
return EXIT_FAILURE;
}
free(ptr);
return 0; return 0;
} }
]])], ]])],
[have_aligned_alloc=yes], [have_aligned_alloc=no [have_posix_memalign=yes], [have_posix_memalign=no
]) ])
AS_IF([test "x$have_aligned_alloc" = "xyes"], [ AS_IF([test "x$have_posix_memalign" = "xyes"], [
AC_DEFINE([HAVE_ALIGNED_ALLOC], [1], [Define to 1 if you have the aligned_alloc function.]) AC_DEFINE([HAVE_POSIX_MEMALIGN], [1], [Define to 1 if you have the posix_memalign function.])
]) ])
AC_MSG_RESULT([$have_aligned_alloc]) AC_MSG_RESULT([$have_posix_memalign])
aligned="" aligned=""
AC_MSG_CHECKING([for vector aligned pragma]) AC_MSG_CHECKING([for vector aligned pragma])
@ -550,7 +556,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
[aligned='_Pragma("vector aligned")'], [ [aligned='_Pragma("vector aligned")'], [
]) ])
AS_IF([test "x$have_aligned_alloc" = "xno"], [ AS_IF([test "x$have_posix_memalign" = "xno"], [
aligned="" aligned=""
]) ])

View File

@ -125,7 +125,7 @@ void* qmckl_malloc(qmckl_context context,
~qmckl_context~. ~qmckl_context~.
4. The function then allocates memory: 4. The function then allocates memory:
If the ~HAVE_HPC~ and ~HAVE_ALIGNED_ALLOC~ macros are defined, the memory If the ~HAVE_HPC~ and ~HAVE_POSIX_MEMALIGN~ macros are defined, the memory
allocation is done using the ~aligned_alloc~ function with a 64-byte alignment, allocation is done using the ~aligned_alloc~ function with a 64-byte alignment,
rounding up the requested size to the nearest multiple of 64 bytes. Else, the rounding up the requested size to the nearest multiple of 64 bytes. Else, the
memory allocation is done using the standard ~malloc~ function. memory allocation is done using the standard ~malloc~ function.
@ -153,11 +153,11 @@ void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info) {
qmckl_context_struct* const ctx = (qmckl_context_struct*) context; qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
/* Allocate memory and zero it */ /* Allocate memory and zero it */
#if defined(HAVE_HPC) && defined(HAVE_ALIGNED_ALLOC) void * pointer = NULL;
assert( ((info.size+64) >> 6) << 6 >= info.size ); #if defined(HAVE_HPC) && defined(HAVE_POSIX_MEMALIGN)
void * pointer = aligned_alloc(64, ((info.size+64) >> 6) << 6 ); if (posix_memalign(&pointer, 64, info.size) != 0) pointer = NULL;
#else #else
void * pointer = malloc(info.size); pointer = malloc(info.size);
#endif #endif
if (pointer == NULL) { if (pointer == NULL) {
return NULL; return NULL;