Skip to content

Commit

Permalink
Now using posix_memalign
Browse files Browse the repository at this point in the history
  • Loading branch information
scemama committed Oct 6, 2023
1 parent eaa44b4 commit a7523fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
24 changes: 15 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -518,21 +518,27 @@ AC_MSG_RESULT([$ivdep])

# Checking ALIGNED

AC_MSG_CHECKING([for aligned_alloc])
AC_MSG_CHECKING([for posix_memalign])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#include <stdio.h>
]], [[
int main() {
void * pointer = aligned_alloc(64, 100);
free(pointer);
return 0;
void *ptr;
int ret = posix_memalign(&ptr, 64, 1024);
if (ret != 0) {
return EXIT_FAILURE;
}
free(ptr);
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"], [
AC_DEFINE([HAVE_ALIGNED_ALLOC], [1], [Define to 1 if you have the aligned_alloc function.])
AS_IF([test "x$have_posix_memalign" = "xyes"], [
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=""
AC_MSG_CHECKING([for vector aligned pragma])
Expand All @@ -550,7 +556,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
[aligned='_Pragma("vector aligned")'], [
])

AS_IF([test "x$have_aligned_alloc" = "xno"], [
AS_IF([test "x$have_posix_memalign" = "xno"], [
aligned=""
])

Expand Down
10 changes: 5 additions & 5 deletions org/qmckl_memory.org
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void* qmckl_malloc(qmckl_context context,
~qmckl_context~.

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,
rounding up the requested size to the nearest multiple of 64 bytes. Else, the
memory allocation is done using the standard ~malloc~ function.
Expand Down Expand Up @@ -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;

/* Allocate memory and zero it */
#if defined(HAVE_HPC) && defined(HAVE_ALIGNED_ALLOC)
assert( ((info.size+64) >> 6) << 6 >= info.size );
void * pointer = aligned_alloc(64, ((info.size+64) >> 6) << 6 );
void * pointer = NULL;
#if defined(HAVE_HPC) && defined(HAVE_POSIX_MEMALIGN)
if (posix_memalign(&pointer, 64, info.size) != 0) pointer = NULL;
#else
void * pointer = malloc(info.size);
pointer = malloc(info.size);
#endif
if (pointer == NULL) {
return NULL;
Expand Down

0 comments on commit a7523fb

Please sign in to comment.