Skip to content

Commit

Permalink
aligned_alloc requires the allocated size to be a multiple of the ali…
Browse files Browse the repository at this point in the history
…gnment. Replace by malloc and grid_allocate_scratch()

the doc of aligned_alloc states that the size allocation should be a multiple of the alignment (posix_memalign does not).
so revert back to malloc and grid_allocate_scratch (call libxsmm routine if found)
  • Loading branch information
mtaillefumier authored and mkrack committed Mar 12, 2021
1 parent 3359402 commit a695227
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/grid/cpu/collocation_integration.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ void initialize_W_and_T(collocation_integration *const handler,

if (handler->scratch)
free(handler->scratch);
handler->scratch =
aligned_alloc(64, sizeof(double) * handler->scratch_alloc_size);
handler->scratch = malloc(sizeof(double) * handler->scratch_alloc_size);
if (handler->scratch == NULL)
abort();
}
Expand Down Expand Up @@ -139,8 +138,7 @@ void initialize_W_and_T_integrate(collocation_integration *const handler,

if (handler->scratch)
free(handler->scratch);
handler->scratch =
aligned_alloc(64, sizeof(double) * handler->scratch_alloc_size);
handler->scratch = malloc(sizeof(double) * handler->scratch_alloc_size);
if (handler->scratch == NULL)
abort();
}
Expand Down
3 changes: 1 addition & 2 deletions src/grid/cpu/grid_integrate_dgemm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,7 @@ void grid_cpu_integrate_task_list(
const int max_threads = omp_get_max_threads();

if (ctx->scratch == NULL)
ctx->scratch =
aligned_alloc(sysconf(_SC_PAGESIZE), hab_blocks->size * max_threads);
ctx->scratch = malloc(hab_blocks->size * max_threads);

ctx->orthorhombic = orthorhombic;

Expand Down
16 changes: 8 additions & 8 deletions src/grid/cpu/non_orthorombic_corrections.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ void calculate_non_orthorombic_corrections_tensor(
initialize_tensor_3(Exp, 3, max_elem, max_elem);
realloc_tensor(Exp);

x1 = aligned_alloc(64, sizeof(double) * max_elem);
x2 = aligned_alloc(64, sizeof(double) * max_elem);
x1 = grid_allocate_scratch(sizeof(double) * max_elem);
x2 = grid_allocate_scratch(sizeof(double) * max_elem);
initialize_tensor_2(&exp_tmp, Exp->size[1], Exp->size[2]);

memset(&idx3(Exp[0], 0, 0, 0), 0, sizeof(double) * Exp->alloc_size_);
Expand All @@ -142,8 +142,8 @@ void calculate_non_orthorombic_corrections_tensor(
&exp_tmp);
}
}
free(x1);
free(x2);
grid_free_scratch(x1);
grid_free_scratch(x2);
}

void calculate_non_orthorombic_corrections_tensor_blocked(
Expand Down Expand Up @@ -198,8 +198,8 @@ void calculate_non_orthorombic_corrections_tensor_blocked(
block_size[2]};

const int max_elem = imax(imax(cube_size[0], cube_size[1]), cube_size[2]);
x1 = aligned_alloc(64, sizeof(double) * max_elem);
x2 = aligned_alloc(64, sizeof(double) * max_elem);
x1 = grid_allocate_scratch(sizeof(double) * max_elem);
x2 = grid_allocate_scratch(sizeof(double) * max_elem);

initialize_tensor_4(Exp, 3,
imax(upper_corner[0] - lower_corner[0],
Expand Down Expand Up @@ -248,8 +248,8 @@ void calculate_non_orthorombic_corrections_tensor_blocked(
}
}

free(x1);
free(x2);
grid_free_scratch(x1);
grid_free_scratch(x2);
/* free(exp_tmp.data); */
}

Expand Down
6 changes: 2 additions & 4 deletions src/grid/cpu/tensor_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ size_t realloc_tensor(tensor *t) {
t->data = NULL;

if (t->data == NULL) {
t->data =
aligned_alloc(sysconf(_SC_PAGESIZE), sizeof(double) * t->alloc_size_);
t->data = malloc(sizeof(double) * t->alloc_size_);
if (!t->data)
abort();
t->old_alloc_size_ = t->alloc_size_;
Expand All @@ -43,8 +42,7 @@ void alloc_tensor(tensor *t) {
abort();
}

t->data =
aligned_alloc(sysconf(_SC_PAGESIZE), sizeof(double) * t->alloc_size_);
t->data = malloc(sizeof(double) * t->alloc_size_);
if (!t->data)
abort();
t->old_alloc_size_ = t->alloc_size_;
Expand Down
2 changes: 1 addition & 1 deletion src/grid/cpu/tensor_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static inline tensor *create_tensor(const int dim, const int *sizes) {
abort();

initialize_tensor(a, dim, sizes);
a->data = (double *)aligned_alloc(64, sizeof(double) * a->alloc_size_);
a->data = (double *)malloc(sizeof(double) * a->alloc_size_);
if (a->data == NULL)
abort();
a->old_alloc_size_ = a->alloc_size_;
Expand Down

0 comments on commit a695227

Please sign in to comment.