Skip to content

Commit

Permalink
Provide workaround for current AnyDSL version
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Ravedutti <[email protected]>
  • Loading branch information
rafaelravedutti committed Oct 21, 2020
1 parent 9e5e2a8 commit 010c055
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions backend/device.impala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ struct Device {
cpu_target: fn() -> bool,
init: fn(Grid) -> (),
shutdown: fn() -> (),
alloc: fn(i32) -> Buffer,
alloc_mirror: fn(Buffer, i32) -> Buffer,
alloc: fn(i64) -> Buffer,
alloc_mirror: fn(Buffer, i64) -> Buffer,
transfer: fn(Buffer, Buffer) -> (),
sqrt: fn(real_t) -> real_t,
loop_1d: fn(bool, i32, fn(i32) -> ()) -> (),
Expand Down
12 changes: 6 additions & 6 deletions comm/comm.impala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static mut znext: i32;
fn @communicate_ghost_particles() -> bool { select(use_walberla(), false, true) }

// Maximum number of neighbor ranks
fn @get_initial_maximum_neighbor_ranks() -> i32 { select(use_walberla(), 30, 6) }
fn @get_initial_maximum_neighbor_ranks() -> i64 { select(use_walberla(), 30, 6) as i64 }

// Initialize and finalize MPI
fn mpi_initialize() -> () { mpi().init(); }
Expand Down Expand Up @@ -165,9 +165,9 @@ fn @pbc_correct(pos: Vector3D, grid: Grid) -> Vector3D {
fn alloc_comm(grid: Grid) -> Comm {
let mpih = mpi();
let max_neighs = get_initial_maximum_neighbor_ranks();
let max_faces_dim = math.max(math.max(grid.nx * grid.ny, grid.nx * grid.nz), grid.ny * grid.nz);
let send_capacity = max_neighs * max_faces_dim * 20;
let recv_capacity = max_neighs * max_faces_dim * 20;
let max_faces_dim = math.max(math.max(grid.nx * grid.ny, grid.nx * grid.nz), grid.ny * grid.nz) as i64;
let send_capacity = (max_neighs * max_faces_dim) as i32 * 20;
let recv_capacity = (max_neighs * max_faces_dim) as i32 * 20;
let null_buf = Buffer {
device: 0,
data: 0 as &[i8],
Expand All @@ -192,7 +192,7 @@ fn alloc_comm(grid: Grid) -> Comm {
recv_rank_lengths: alloc_cpu(max_neighs * sizeof[i32]()),
recv_capacity: recv_capacity,
recv_noffsets: 0,
max_neighs: max_neighs,
max_neighs: max_neighs as i32,
neighs: 0
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ fn release_comm(comm: Comm) -> () {
fn resize_max_neighbors_capacity(comm: &mut Comm, max_neighs: i32) -> () {
print_i32_with_rank("resize_max_neighbors_capacity()", max_neighs);
let realloc_max_neigh_buf = @|buf: &mut Buffer| {
let new_buf = alloc_cpu(max_neighs * sizeof[i32]());
let new_buf = alloc_cpu(max_neighs as i64 * sizeof[i32]());
copy(*buf, new_buf);
release(*buf);
*buf = new_buf;
Expand Down
8 changes: 4 additions & 4 deletions comm/lb.impala
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ fn @get_neighborhood_aabb(nbh: Neighborhood, index: i32) -> AABB {

fn initialize_neighborhood() -> () {
let rank_capacity = get_initial_maximum_neighbor_ranks();
let aabb_capacity = rank_capacity * 8;
let aabb_capacity = rank_capacity as i32 * 8;

neighborhood = Neighborhood {
nranks: 0,
ranks: alloc_cpu(rank_capacity * sizeof[i32]()),
naabbs: alloc_cpu(rank_capacity * sizeof[i32]()),
offsets: alloc_cpu(rank_capacity * sizeof[i32]()),
aabbs: allocate_array(aabb_capacity, 6, sizeof[real_t](), true),
rank_capacity: rank_capacity,
rank_capacity: rank_capacity as i32,
aabb_capacity: aabb_capacity
};
}
Expand All @@ -54,14 +54,14 @@ extern fn md_update_neighborhood(nranks: i32, total_aabbs: i32, ranks: &[i32], n
neighborhood.nranks = nranks;

if nranks > neighborhood.rank_capacity {
let new_capacity = nranks + 10;
let new_capacity = (nranks + 10) as i64;
release(neighborhood.ranks);
release(neighborhood.naabbs);
release(neighborhood.offsets);
neighborhood.ranks = alloc_cpu(new_capacity * sizeof[i32]());
neighborhood.naabbs = alloc_cpu(new_capacity * sizeof[i32]());
neighborhood.offsets = alloc_cpu(new_capacity * sizeof[i32]());
neighborhood.rank_capacity = new_capacity;
neighborhood.rank_capacity = new_capacity as i32;
}

if total_aabbs > neighborhood.aabb_capacity {
Expand Down
7 changes: 3 additions & 4 deletions core/grid.impala
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ fn initialize_grid(
positions: &[Vector3D],
velocities: &[Vector3D],
nparticles: i32,
grid: &mut Grid,
allocate: fn(i32) -> Buffer) -> () {
grid: &mut Grid) -> () {

let cell_sizes = get_array_i32_ref(array_host, grid.cell_sizes);

Expand All @@ -227,11 +226,11 @@ fn initialize_grid(
});

range(0, nparticles, |i| {
insert_particle(masses(i), positions(i), velocities(i), grid, allocate);
insert_particle(masses(i), positions(i), velocities(i), grid);
});
}

fn insert_particle(mass: real_t, position: Vector3D, velocity: Vector3D, grid: &mut Grid, allocate: fn(i32) -> Buffer) -> () {
fn insert_particle(mass: real_t, position: Vector3D, velocity: Vector3D, grid: &mut Grid) -> () {
let particle_index = grid.nparticles;
let neighbors_sizes = get_array_i32_ref(array_host, grid.neighbors_sizes);

Expand Down
12 changes: 6 additions & 6 deletions core/layouts.impala
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ fn @null_array() -> ArrayData {
}
}

fn allocate_array(size_x: i32, size_y: i32, elem_size: i32, host_mirror: bool) -> ArrayData {
fn allocate_array(size_x: i32, size_y: i32, elem_size: i64, host_mirror: bool) -> ArrayData {
let dev = device();
let buffer = dev.alloc(size_x * size_y * elem_size);
let buffer = dev.alloc(size_x as i64 * size_y as i64 * elem_size);

ArrayData {
buffer: buffer,
buffer_host: dev.alloc_mirror(buffer, size_x * size_y * elem_size),
buffer_host: dev.alloc_mirror(buffer, size_x as i64 * size_y as i64 * elem_size),
size_x: size_x,
size_y: size_y,
host_mirror: host_mirror
Expand Down Expand Up @@ -87,10 +87,10 @@ fn @clustered_array(@atomic: i32, @cluster_size: i32) -> ArrayLayout {
}
}

fn reallocate_array(array: &mut ArrayData, size_x: i32, size_y: i32, elem_size: i32, @preserve: bool) -> () {
fn reallocate_array(array: &mut ArrayData, size_x: i32, size_y: i32, elem_size: i64, @preserve: bool) -> () {
let dev = device();
let new_buffer = dev.alloc(size_x * size_y * elem_size);
let new_buffer_host = dev.alloc_mirror(new_buffer, size_x * size_y * elem_size);
let new_buffer = dev.alloc(size_x as i64 * size_y as i64 * elem_size);
let new_buffer_host = dev.alloc_mirror(new_buffer, size_x as i64 * size_y as i64 * elem_size);

if preserve {
copy(array.buffer_host, new_buffer_host);
Expand Down
2 changes: 1 addition & 1 deletion core/runtime.impala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern fn md_initialize_grid(

grid_ = allocate_grid(world_aabb, ext_rank_aabb, cell_spacing, cell_capacity, neighborlist_capacity);
comm_ = alloc_comm(grid_);
initialize_grid(masses, positions, velocities, nparticles, &mut grid_, alloc_cpu);
initialize_grid(masses, positions, velocities, nparticles, &mut grid_);
initialize_neighborhood();
device().init(grid_);
grid_.nparticles
Expand Down
6 changes: 4 additions & 2 deletions utils/atomic.impala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ fn atomic_op_f32(a: &mut f32, b: f32, op: fn(f32, f32) -> f32) -> f32 {
let mut value : u32;
while(!done) {
value = *addr_as_ui;
done = cmpxchg(addr_as_ui, value, bitcast[u32](op(bitcast[f32](value), b)))(1);
// TODO: set proper order and scope
// done = cmpxchg(addr_as_ui, value, bitcast[u32](op(bitcast[f32](value), b)))(1);
}
bitcast[f32](op(bitcast[f32](value),b))
}
Expand All @@ -15,7 +16,8 @@ fn atomic_op_f64(a: &mut f64, b: f64, op: fn(f64, f64) -> f64) -> f64 {
let mut value : u64;
while(!done) {
value = *addr_as_ui;
done = cmpxchg(addr_as_ui, value, bitcast[u64](op(bitcast[f64](value), b)))(1);
// TODO: set proper order and scope
// done = cmpxchg(addr_as_ui, value, bitcast[u64](op(bitcast[f64](value), b)))(1);
}
bitcast[f64](op(bitcast[f64](value),b))
}

0 comments on commit 010c055

Please sign in to comment.