Verified Commit 3f1c063d authored by baptiste.coudray's avatar baptiste.coudray
Browse files

Updated LBM

parent b7165a20
......@@ -368,10 +368,10 @@ extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_
}
extern void dispatch_context_print(struct dispatch_context *dc) {
printf("[dispatch_context] my_rank = %d, world_size = %d, network_dimensions = [%d][%d][%d], n_dimensions = %d, data_dimensions = [%d][%d][%d], coordinates = (%d, %d, %d)\n",
printf("[dispatch_context] my_rank = %d, world_size = %d, network_dimensions = [%d][%d][%d], n_dimensions = %d, data_dimensions = [%d][%d][%d], coordinates = (%d, %d, %d), type = %d\n",
dc->my_rank, dc->world_size, dc->network_dimensions[0], dc->network_dimensions[1], dc->network_dimensions[2],
dc->n_dimensions, dc->data_dimensions[0], dc->data_dimensions[1], dc->data_dimensions[2],
dc->coordinates[0], dc->coordinates[1], dc->coordinates[2]);
dc->coordinates[0], dc->coordinates[1], dc->coordinates[2], dc->type);
}
static envelope_t *get_inner_envelope_1d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
......@@ -1897,7 +1897,7 @@ futhark_outer_envelope_3d_new(struct dispatch_context *dc, struct futhark_contex
static void *
get_chunk_with_envelope_1d(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
void *f(struct futhark_context *, const uint8_t *, int64_t)) {
void *f(struct futhark_context *, const void *, int64_t)) {
struct futhark_u8_1d *fut_chunk_xs = futhark_new_u8_1d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[1] * dc->type);
struct futhark_u8_1d *fut_chunk_xs_with_envelope;
......@@ -1925,7 +1925,7 @@ get_chunk_with_envelope_1d(struct dispatch_context *dc, struct futhark_context *
static void *
get_chunk_with_envelope_2d(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
void *f(struct futhark_context *, const uint8_t *, int64_t, int64_t)) {
void *f(struct futhark_context *, const void *, int64_t, int64_t)) {
struct futhark_u8_2d *fut_chunk_elems = futhark_new_u8_2d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[0],
dc->chunk_info->dimensions[1] * dc->type);
......@@ -1954,7 +1954,7 @@ get_chunk_with_envelope_2d(struct dispatch_context *dc, struct futhark_context *
static void *
get_chunk_with_envelope_3d(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
void *f(struct futhark_context *, const uint8_t *, int64_t, int64_t, int64_t)) {
void *f(struct futhark_context *, const void *, int64_t, int64_t, int64_t)) {
struct futhark_u8_3d *fut_chunk_cube = futhark_new_u8_3d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[0],
dc->chunk_info->dimensions[1],
......@@ -1984,20 +1984,20 @@ get_chunk_with_envelope_3d(struct dispatch_context *dc, struct futhark_context *
extern void *
get_chunk_with_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness,
void *f(struct futhark_context *, const uint8_t *, ...)) {
void *f(struct futhark_context *, const void *, ...)) {
envelope_t *outer_envelope = get_outer_envelope(dc, fc, thickness);
switch (dc->n_dimensions) {
case 1:
return get_chunk_with_envelope_1d(dc, fc, outer_envelope,
(void *(*)(struct futhark_context *, const uint8_t *, int64_t)) f);
(void *(*)(struct futhark_context *, const void *, int64_t)) f);
case 2:
return get_chunk_with_envelope_2d(dc, fc, outer_envelope,
(void *(*)(struct futhark_context *, const uint8_t *, int64_t,
(void *(*)(struct futhark_context *, const void *, int64_t,
int64_t)) f);
case 3:
return get_chunk_with_envelope_3d(dc, fc, outer_envelope,
(void *(*)(struct futhark_context *, const uint8_t *, int64_t, int64_t,
(void *(*)(struct futhark_context *, const void *, int64_t, int64_t,
int64_t)) f);
break;
}
......
......@@ -3,8 +3,8 @@
//#include "envelope.h"
//#include "../elementary/elementary.h"
#include "../game_of_life/gol.h"
//#include "../lattice_boltzmann/lbm.h"
//#include "../game_of_life/gol.h"
#include "../lattice_boltzmann/lbm.h"
#include "chunk_info.h"
#define NB_SIDES 6
......@@ -67,7 +67,7 @@ extern envelope_t *get_outer_envelope(struct dispatch_context *dc, struct futhar
extern chunk_info_t get_chunk_info(struct dispatch_context *dc);
extern void *get_chunk_with_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness,
void *f(struct futhark_context*, const uint8_t *, ...));
void *f(struct futhark_context*, const void *, ...));
extern void *get_data(struct dispatch_context *dc);
......
......@@ -5,27 +5,6 @@ type envelope_2d_t [n][m][ty][tx] = env.envelope_2d_t [n][m][ty][tx]
type~ side_envelope_3d_t = env.side_envelope_3d_t
type~ envelope_3d_t = env.envelope_3d_t
type~ side_envelope_3d = {
east: [][][]f32, -- edge
north: [][][]f32, -- edge
north_east: [][][]f32, -- vertice
north_west: [][][]f32, -- vertice
south: [][][]f32, -- edge
south_east: [][][]f32, -- vertice
south_west: [][][]f32, -- vertice
surface: [][][]f32,
west: [][][]f32 -- edge
}
type~ envelope_3d_f32 = {
back: side_envelope_3d,
bottom: side_envelope_3d,
front: side_envelope_3d,
left: side_envelope_3d,
right: side_envelope_3d,
top: side_envelope_3d
}
entry get_envelope_1d [n] (xs: [n]u8) (thickness: i64) : envelope_1d_t [thickness] =
env.get_envelope_1d xs thickness
......@@ -35,68 +14,11 @@ entry get_envelope_2d [n][m] (matrix: [n][m]u8) (thickness_y: i64) (thickness_x:
entry get_envelope_3d [n][m][l] (cube: [n][m][l]u8) (thickness_y: i64) (thickness_x: i64) (thickness_z: i64): envelope_3d_t =
env.get_envelope_3d cube thickness_y thickness_x thickness_z
entry get_subdomain_1d = env.get_subdomain_1d
entry get_subdomain_2d = env.get_subdomain_2d
entry get_subdomain_3d = env.get_subdomain_3d
let augment_lbm [n][m][l] (chunk_lbm:[n][m][l]f32) (envelope: envelope_3d_f32) : [][][]f32 =
let n_aug = n+2
let m_aug = m+2
let l_aug = l+2
in tabulate_3d (n_aug) (m_aug) (l_aug) (\i j k ->
-- Top-South-West
if (i == 0 && j == 0 && k == 0) then envelope.top.south_west[i,j,k]
-- Top-West
else if (i == 0 && j == 0 && k >= 1 && k <= l_aug-2) then envelope.top.west[i,j,k-1]
-- Top-North-West
else if (i == 0 && j == 0 && k == l_aug-1) then envelope.top.north_west[i,j,0]
-- Top-South
else if (i == 0 && j >= 1 && j <= m_aug-2 && k == 0) then envelope.top.south[i,j-1,k]
-- Top-Surface
else if (i == 0 && j >= 1 && j <= m_aug-2 && k >= 1 && k <= l_aug-2) then envelope.top.surface[i,j-1,k-1]
-- Top North
else if (i == 0 && j >= 1 && j <= m_aug-2 && k == l_aug-1) then envelope.top.north[i,j-1,0]
-- Top South East
else if (i == 0 && j == m_aug-1 && k == 0) then envelope.top.south_east[i,j-1,0]
-- Top East
else if (i == 0 && j == m_aug-1 && k >= 1 && k <= l_aug-2) then envelope.top.east[i,0,k-1]
-- Top North East
else if (i == 0 && j == m_aug-1 && k == l_aug-1) then envelope.top.north_east[i,0,0]
-- Front-West
else if (i >= 1 && i <= n_aug-2 && j == 0 && k == 0) then envelope.front.west[i-1,0,0]
-- Left
else if (i >= 1 && i <= n_aug-2 && j == 0 && k >= 1 && k <= l_aug-1) then envelope.left.surface[i-1,0,k-1]
-- Back West
else if (i >= 1 && i <= n_aug-2 && j == 0 && k == l_aug-1) then envelope.back.west[i-1,0,0]
-- Front East
else if (i >= 1 && i <= n_aug-2 && j == m_aug-1 && k == 0) then envelope.front.east[i-1,0,0]
-- Right
else if (i >= 1 && i <= n_aug-2 && j == m_aug-1 && k >= 1 && k <= l_aug-1) then envelope.right.surface[i-1,0,k-1]
-- Back East
else if (i >= 1 && i <= n_aug-2 && j == m_aug-1 && k == l_aug-1) then envelope.back.west[i-1,0,0]
-- Bottom-South-West
else if (i == n_aug-1 && j == 0 && k == 0) then envelope.bottom.south_west[0,j,k]
-- Bottom-West
else if (i == n_aug-1 && j == 0 && k >= 1 && k <= l_aug-2) then envelope.bottom.west[0,j,k-1]
-- Bottom-North-West
else if (i == n_aug-1 && j == 0 && k == l_aug-1) then envelope.bottom.north_west[0,j,0]
-- Bottom-South
else if (i == n_aug-1 && j >= 1 && j <= m_aug-2 && k == 0) then envelope.bottom.south[0,j-1,k]
-- Bottom-Surface
else if (i == n_aug-1 && j >= 1 && j <= m_aug-2 && k >= 1 && k <= l_aug-2) then envelope.bottom.surface[0,j-1,k-1]
-- Bottom North
else if (i == n_aug-1 && j >= 1 && j <= m_aug-2 && k == l_aug-1) then envelope.bottom.north[0,j-1,0]
-- Bottom South East
else if (i == n_aug-1 && j == m_aug-1 && k == 0) then envelope.bottom.south_east[0,j-1,0]
-- Bottom East
else if (i == n_aug-1 && j == m_aug-1 && k >= 1 && k <= l_aug-2) then envelope.bottom.east[0,0,k-1]
-- Bottom North East
else if (i == n_aug-1 && j == m_aug-1 && k == l_aug-1) then envelope.bottom.north_east[0,0,0]
else chunk_lbm[i-1, j-1, l-1]
)
entry augment_1d [n][tx] (xs: [n]u8) (envelope: envelope_1d_t [tx]) :[]u8 = env.augment_1d xs envelope
entry augment_2d [n][m][ty][tx] (matrix: [n][m]u8) (envelope: envelope_2d_t [n][m][tx][ty]) :[][]u8 = env.augment_2d matrix envelope
entry augment_3d [n][m][l] (cube: [n][m][l]u8) (envelope: envelope_3d_t) :[][][]u8 = env.augment_3d cube envelope
entry next_chunk_lbm [n][m][l] (chunk_lbm :[n][m][l]f32) (envelope: envelope_3d_f32) :[n][m][l]f32 =
let augmented_lbm = augment_lbm chunk_lbm envelope
entry next_chunk_lbm [n][m][l][b] (chunk_lbm :[n][m][l][b]f32) :[][][][b]f32 =
-- TODO: Here, compute next lbm
in augmented_lbm[1:n+1, 1:m+1, 1:l+1] :> [n][m][l]f32
-- in next_lbm[1:n+1, 1:m+1, 1:l+1] :> [n][m][l]f32
let next_lbm = chunk_lbm
in next_lbm[1:n-1, 1:m-1, 1:l-1, :]
......@@ -14,9 +14,15 @@
#define INDEX_3D_TO_1D(y, x, z, nb_columns, nb_depths) ((x) + (nb_columns) * ((y) + (nb_depths) * (z)))
#define N_ITERATIONS 200
#define NB_VALUES 27
typedef struct lbm_values {
float values[NB_VALUES];
} lbm_values_t;
void init_chunk_lbm(chunk_info_t *ci) {
int *data32 = ci->data;
float *data32 = ci->data;
for (int i = 0; i < ci->dimensions[0]; ++i) {
for (int j = 0; j < ci->dimensions[1]; ++j) {
for (int k = 0; k < ci->dimensions[2]; ++k) {
......@@ -27,28 +33,24 @@ void init_chunk_lbm(chunk_info_t *ci) {
}
}
void compute_next_lbm(struct dispatch_context *dc, struct futhark_context *fc, chunk_info_t *ci) {
envelope_t *outer_envelope = get_outer_envelope(dc, fc, 1);
struct futhark_opaque_envelope_3d_f32 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, outer_envelope,
futhark_restore_opaque_envelope_3d_f32,
FUTHARK_F32);
struct futhark_f32_4d *
convert_chunk_with_envelope(struct futhark_context *fc, const void *data, int64_t dim0, int64_t dim1, int64_t dim2) {
return futhark_new_f32_4d(fc, data, dim0, dim1, dim2, NB_VALUES);
}
struct futhark_f32_3d *fut_chunk_lbm = futhark_new_f32_3d(fc, ci->data, ci->dimensions[0], ci->dimensions[1],
ci->dimensions[2]);
struct futhark_f32_3d *fut_next_chunk_lbm;
void compute_next_lbm(struct dispatch_context *dc, struct futhark_context *fc, chunk_info_t *ci) {
struct futhark_f32_4d *fut_chunk_with_envelope = get_chunk_with_envelope(dc, fc, 1, convert_chunk_with_envelope);
futhark_context_sync(fc);
futhark_entry_next_chunk_lbm(fc, &fut_next_chunk_lbm, fut_chunk_lbm, fut_outer_envelope);
struct futhark_f32_4d *fut_next_chunk_lbm;
futhark_entry_next_chunk_lbm(fc, &fut_next_chunk_lbm, fut_chunk_with_envelope);
futhark_context_sync(fc);
futhark_values_f32_3d(fc, fut_next_chunk_lbm, ci->data);
futhark_values_f32_4d(fc, fut_next_chunk_lbm, ci->data);
futhark_context_sync(fc);
futhark_free_f32_3d(fc, fut_next_chunk_lbm);
futhark_free_f32_3d(fc, fut_chunk_lbm);
futhark_free_opaque_envelope_3d_f32(fc, fut_outer_envelope);
envelope_free(outer_envelope);
futhark_free_f32_4d(fc, fut_chunk_with_envelope);
futhark_free_f32_4d(fc, fut_next_chunk_lbm);
}
int main(int argc, char *argv[]) {
......@@ -68,7 +70,21 @@ int main(int argc, char *argv[]) {
int lbm_dimensions[3] = {atoi(argv[1]), atoi(argv[2]), atoi(argv[3])};
struct dispatch_context *disp_context = dispatch_context_new(lbm_dimensions, MPI_FLOAT, 3);
MPI_Datatype cell;
int lengths[1] = {NB_VALUES};
MPI_Aint displacements[3];
struct lbm_values dummy_values;
MPI_Aint base_address;
MPI_Get_address(&dummy_values, &base_address);
displacements[0] = MPI_Aint_diff(displacements[0], base_address);
MPI_Datatype types[1] = {MPI_FLOAT};
MPI_Type_create_struct(1, lengths, displacements, types, &cell);
MPI_Type_commit(&cell);
struct dispatch_context *disp_context = dispatch_context_new(lbm_dimensions, cell, 3);
dispatch_context_print(disp_context);
chunk_info_t ci = get_chunk_info(disp_context);
init_chunk_lbm(&ci);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment