Skip to content

Commit

Permalink
Abstract neighborlists layout
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Ravedutti <[email protected]>
  • Loading branch information
rafaelravedutti committed Jul 10, 2020
1 parent a2fd46a commit 9aa7c33
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
11 changes: 1 addition & 10 deletions backend/mapping_cpu.impala
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
fn @is_nvvm() -> bool { false }
fn @is_cuda() -> bool { false }
fn @is_opencl() -> bool { false }
fn @is_amdgpu() -> bool { false }
fn @has_ldg() -> bool { false }

fn @NeighborlistLayout() -> ArrayLayout { column_major_order_array(0) }
type dev_i32_ptr = &mut i32;

fn @device() -> Device {
Expand Down Expand Up @@ -87,7 +82,3 @@ fn @reduce_aabb(n: i32, b: AABB, reduce: fn(AABB, AABB) -> AABB, body: fn(i32) -

red
}

fn @get_neighborlist_index(particle_index: i32, neighbor_index: i32, grid: Grid) -> i32 {
grid.neighborlist_capacity * particle_index + neighbor_index
}
10 changes: 1 addition & 9 deletions backend/mapping_gpu.impala
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
fn @is_x86() -> bool { false }
fn @is_sse() -> bool { false }
fn @is_avx() -> bool { false }
fn @is_avx2() -> bool { false }

fn @NeighborlistLayout() -> ArrayLayout { row_major_order_array(0) }
type dev_i32_ptr = &mut[1]i32;

struct ReductionBuffers {
Expand Down Expand Up @@ -222,7 +218,3 @@ fn @reduce_aabb(n: i32, b: AABB, reduce: fn(AABB, AABB) -> AABB, body: fn(i32) -

red
}

fn get_neighborlist_index(particle_index: i32, neighbor_index: i32, grid: Grid) -> i32 {
grid.particle_capacity * neighbor_index + particle_index
}
2 changes: 1 addition & 1 deletion core/compute.impala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn @(?half_nb) compute_potential(
let pos_i = get_position(i, grid);

for n in range(0, nb_list_size) {
let j = neighborlists(get_neighborlist_index(i, n, grid));
let j = array_2d_get_i32(array_dev, NeighborlistLayout(), grid.neighborlists, i, n);
let pos_j = get_position(j, grid);
let del = vector_sub(pos_i, pos_j);
let rsq = vector_len2(del);
Expand Down
8 changes: 8 additions & 0 deletions core/layouts.impala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ fn @array_2d_get_real(@target_fn: ArrayTargetFn, @layout: ArrayLayout, array: Ar
bitcast[&[real_t]](target_fn(array).data)(layout.index_2d_fn(array, i, j))
}

fn @array_2d_set_i32(@target_fn: ArrayTargetFn, @layout: ArrayLayout, array: ArrayData, i: i32, j: i32, value: i32) -> () {
bitcast[&mut[i32]](target_fn(array).data)(layout.index_2d_fn(array, i, j)) = value;
}

fn @array_2d_get_i32(@target_fn: ArrayTargetFn, @layout: ArrayLayout, array: ArrayData, i: i32, j: i32) -> i32 {
bitcast[&[i32]](target_fn(array).data)(layout.index_2d_fn(array, i, j))
}

fn @array_2d_add_real(@layout: ArrayLayout, array: ArrayData, i: i32, j: i32, value: real_t) -> () {
layout.add_fn(array, layout.index_2d_fn(array, i, j), value);
}
Expand Down
3 changes: 1 addition & 2 deletions core/neighborlist.impala
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ fn @(?half_nb) neighbor_cells(index: i32, nx: i32, ny: i32, ncells: i32, half_nb
}

fn @append_neighbor(grid: Grid, particle_index: i32, neighbor_index: i32) -> () {
let neighborlists = get_array_i32_ref(array_dev, grid.neighborlists);
let neighbors_sizes = get_array_i32_ref(array_dev, grid.neighbors_sizes);
let nb_list_size = neighbors_sizes(particle_index);

if nb_list_size >= grid.neighborlist_capacity {
grow_resize(nb_list_size, grid);
} else {
neighborlists(get_neighborlist_index(particle_index, nb_list_size, grid)) = neighbor_index;
array_2d_set_i32(array_dev, NeighborlistLayout(), grid.neighborlists, particle_index, nb_list_size, neighbor_index);
}

neighbors_sizes(particle_index)++;
Expand Down

0 comments on commit 9aa7c33

Please sign in to comment.