Skip to content

Commit

Permalink
grid: Fix out-of-bounds access in grid_library_counter_add
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Mar 17, 2021
1 parent 38be7c2 commit 6ab7065
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/grid/common/grid_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ grid_library_config grid_library_get_config(void) { return config; }
void grid_library_counter_add(const int lp, const enum grid_backend backend,
const enum grid_library_kernel kernel,
const int increment) {
assert(lp >= 0);
const int back = backend - GRID_BACKEND_REF;
const int idx = back * 4 * 20 + kernel * 20 + imin(lp, 19);
const int ithread = omp_get_thread_num();
Expand Down
14 changes: 7 additions & 7 deletions src/grid/gpu/grid_gpu_collocate.cu
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ void grid_gpu_collocate_one_grid_level(
const cudaStream_t stream, const double *pab_blocks_dev, double *grid_dev,
int *lp_diff) {

const int ntasks = last_task - first_task + 1;
if (ntasks == 0) {
return; // Nothing to do.
}

init_constant_memory();

// Compute max angular momentum.
const prepare_ldiffs ldiffs = prepare_get_ldiffs(func);
*lp_diff = ldiffs.la_max_diff + ldiffs.lb_max_diff; // for reporting stats
const int la_max = task_list->lmax + ldiffs.la_max_diff;
const int lb_max = task_list->lmax + ldiffs.lb_max_diff;
const int lp_max = la_max + lb_max;

const int ntasks = last_task - first_task + 1;
if (ntasks == 0) {
return; // Nothing to do and lp_diff already set.
}

init_constant_memory();

// Compute required shared memory.
// TODO: Currently, cab's indicies run over 0...ncoset[lmax],
// however only ncoset(lmin)...ncoset(lmax) are actually needed.
Expand Down
14 changes: 7 additions & 7 deletions src/grid/gpu/grid_gpu_integrate.cu
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,6 @@ void grid_gpu_integrate_one_grid_level(
const double *grid_dev, double *hab_blocks_dev, double *forces_dev,
double *virial_dev, int *lp_diff) {

const int ntasks = last_task - first_task + 1;
if (ntasks == 0) {
return; // Nothing to do.
}

init_constant_memory();

// Compute max angular momentum.
const bool calculate_forces = (forces_dev != NULL);
const bool calculate_virial = (virial_dev != NULL);
Expand All @@ -227,6 +220,13 @@ void grid_gpu_integrate_one_grid_level(
const int lb_max = task_list->lmax + ldiffs.lb_max_diff;
const int lp_max = la_max + lb_max;

const int ntasks = last_task - first_task + 1;
if (ntasks == 0) {
return; // Nothing to do and lp_diff already set.
}

init_constant_memory();

// Compute required shared memory.
// TODO: Currently, cab's indicies run over 0...ncoset[lmax],
// however only ncoset(lmin)...ncoset(lmax) are actually needed.
Expand Down

0 comments on commit 6ab7065

Please sign in to comment.