Skip to content
Snippets Groups Projects
Verified Commit f283c608 authored by baptiste.coudray's avatar baptiste.coudray
Browse files

Refactored code

parent d989c412
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,22 @@
#define CHUNK_DATA_TAG 8
#define ROOT_RANK 0
struct futhark_opaque_envelope_1d_t {
struct futhark_i8_1d *v0;
struct futhark_i8_1d *v1;
};
struct futhark_opaque_envelope_2d_t {
struct futhark_i8_2d *v0;
struct futhark_i8_2d *v1;
struct futhark_i8_2d *v2;
struct futhark_i8_2d *v3;
struct futhark_i8_2d *v4;
struct futhark_i8_2d *v5;
struct futhark_i8_2d *v6;
struct futhark_i8_2d *v7;
};
struct dispatch_context {
int my_rank;
int world_size;
......@@ -223,22 +239,6 @@ extern void dispatch_context_print(struct dispatch_context *dc) {
dc->data_dimensions[0], dc->data_dimensions[1], dc->data_dimensions[2]);
}
struct futhark_opaque_envelope_1d_t {
struct futhark_i8_1d *v0;
struct futhark_i8_1d *v1;
};
struct futhark_opaque_envelope_2d_t {
struct futhark_i8_2d *v0;
struct futhark_i8_2d *v1;
struct futhark_i8_2d *v2;
struct futhark_i8_2d *v3;
struct futhark_i8_2d *v4;
struct futhark_i8_2d *v5;
struct futhark_i8_2d *v6;
struct futhark_i8_2d *v7;
};
static envelope_t get_inner_envelope_1d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
struct futhark_u8_1d *fut_chunk_data = futhark_new_u8_1d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[1] * dc->type);
......@@ -279,8 +279,6 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int thickness_y = min(thickness, dc->active_domain.dimensions[0]);
int thickness_x = min(thickness, dc->active_domain.dimensions[1]);
struct futhark_opaque_envelope_2d_t *fut_inner_envelope;
futhark_context_sync(fc);
......@@ -366,11 +364,12 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
return inner_envelope;
}
static uint8_t *chunk_info_to_futhark(struct dispatch_context *dc, uint8_t *out, chunk_info_t *ci, char *fut_type) {
static uint8_t *
chunk_info_to_futhark_struct(chunk_info_t *ci, struct dispatch_context *dc, uint8_t *out, char *futhark_type) {
*out++ = 'b';
*out++ = 2;
*out++ = dc->n_dimensions;
memcpy(out, fut_type, 4);
memcpy(out, futhark_type, 4);
out += 4;
int64_t dimensions64[3];
......@@ -382,6 +381,8 @@ static uint8_t *chunk_info_to_futhark(struct dispatch_context *dc, uint8_t *out,
memcpy(out, &dimensions64[1], 1 * sizeof(int64_t));
} else if (dc->n_dimensions == 2) {
memcpy(out, dimensions64, 2 * sizeof(int64_t));
} else {
memcpy(out, dimensions64, 3 * sizeof(int64_t));
}
out += dc->n_dimensions * sizeof(int64_t);
memcpy(out, ci->data, ci->count * dc->type);
......@@ -391,18 +392,18 @@ static uint8_t *chunk_info_to_futhark(struct dispatch_context *dc, uint8_t *out,
static void *
futhark_outer_envelope_1d_new(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
void *f(struct futhark_context *, const void *), char *fut_type) {
void *f(struct futhark_context *, const void *), char *futhark_type) {
int64_t size_0 = 7 + 1 * sizeof(int64_t) + outer_envelope->east.count * dc->type;
int64_t size_1 = 7 + 1 * sizeof(int64_t) + outer_envelope->west.count * dc->type;
void *opaque_struct = calloc(size_0 * size_1, sizeof(uint8_t));
uint8_t *out = (uint8_t *) opaque_struct;
uint8_t *opaque_struct8 = (uint8_t *) opaque_struct;
// East
out = chunk_info_to_futhark(dc, out, &outer_envelope->east, fut_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->east, dc, opaque_struct8, futhark_type);
// West
chunk_info_to_futhark(dc, out, &outer_envelope->west, fut_type);
chunk_info_to_futhark_struct(&outer_envelope->west, dc, opaque_struct8, futhark_type);
void *fut_opaque_struct = f(fc, opaque_struct);
futhark_context_sync(fc);
......@@ -413,8 +414,7 @@ futhark_outer_envelope_1d_new(struct dispatch_context *dc, struct futhark_contex
static void *
futhark_outer_envelope_2d_new(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
void *f(struct futhark_context *, const void *),
char *fut_type) {
void *f(struct futhark_context *, const void *), char *futhark_type) {
int64_t size_0 = 7 + 2 * sizeof(int64_t) + outer_envelope->east.count * dc->type;
int64_t size_1 = 7 + 2 * sizeof(int64_t) + outer_envelope->north.count * dc->type;
......@@ -427,16 +427,16 @@ futhark_outer_envelope_2d_new(struct dispatch_context *dc, struct futhark_contex
void *opaque_struct = calloc(size_0 + size_1 + size_2 + size_3 + size_4 + size_5 + size_6 + size_7,
sizeof(uint8_t));
uint8_t *out = (uint8_t *) opaque_struct;
uint8_t *opaque_struct8 = (uint8_t *) opaque_struct;
out = chunk_info_to_futhark(dc, out, &outer_envelope->east, fut_type);
out = chunk_info_to_futhark(dc, out, &outer_envelope->north, fut_type);
out = chunk_info_to_futhark(dc, out, &outer_envelope->north_east, fut_type);
out = chunk_info_to_futhark(dc, out, &outer_envelope->north_west, fut_type);
out = chunk_info_to_futhark(dc, out, &outer_envelope->south, fut_type);
out = chunk_info_to_futhark(dc, out, &outer_envelope->south_east, fut_type);
out = chunk_info_to_futhark(dc, out, &outer_envelope->south_west, fut_type);
chunk_info_to_futhark(dc, out, &outer_envelope->west, fut_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->east, dc, opaque_struct8, futhark_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->north, dc, opaque_struct8, futhark_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->north_east, dc, opaque_struct8, futhark_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->north_west, dc, opaque_struct8, futhark_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->south, dc, opaque_struct8, futhark_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->south_east, dc, opaque_struct8, futhark_type);
opaque_struct8 = chunk_info_to_futhark_struct(&outer_envelope->south_west, dc, opaque_struct8, futhark_type);
chunk_info_to_futhark_struct(&outer_envelope->west, dc, opaque_struct8, futhark_type);
void *fut_opaque_struct = f(fc, opaque_struct);
futhark_context_sync(fc);
......@@ -447,12 +447,12 @@ futhark_outer_envelope_2d_new(struct dispatch_context *dc, struct futhark_contex
extern void *futhark_outer_envelope_new(struct dispatch_context *dc, struct futhark_context *fc,
envelope_t *outer_envelope, void *f(struct futhark_context *, const void *),
char *fut_type) {
char *futhark_type) {
switch (dc->n_dimensions) {
case 1:
return futhark_outer_envelope_1d_new(dc, fc, outer_envelope, f, fut_type);
return futhark_outer_envelope_1d_new(dc, fc, outer_envelope, f, futhark_type);
case 2:
return futhark_outer_envelope_2d_new(dc, fc, outer_envelope, f, fut_type);
return futhark_outer_envelope_2d_new(dc, fc, outer_envelope, f, futhark_type);
default:
return NULL;
}
......
......@@ -4,16 +4,16 @@
#include "../game_of_life/gol.h"
#include "chunk_info.h"
#define FUT_I8 " i8"
#define FUT_U8 " i8"
#define FUT_I16 " i16"
#define FUT_U16 " i16"
#define FUT_I32 " i32"
#define FUT_U32 " i32"
#define FUT_I64 " i64"
#define FUT_U64 " i64"
#define FUT_F32 " f32"
#define FUT_F64 " f64"
#define FUTHARK_I8 " i8"
#define FUTHARK_U8 " i8"
#define FUTHARK_I16 " i16"
#define FUTHARK_U16 " i16"
#define FUTHARK_I32 " i32"
#define FUTHARK_U32 " i32"
#define FUTHARK_I64 " i64"
#define FUTHARK_U64 " i64"
#define FUTHARK_F32 " f32"
#define FUTHARK_F64 " f64"
struct dispatch_context;
......@@ -38,7 +38,7 @@ extern envelope_t get_outer_envelope(struct dispatch_context *dc, struct futhark
extern void *
futhark_outer_envelope_new(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
void *f(struct futhark_context *, const void *), char *fut_type);
void *f(struct futhark_context *, const void *), char *futhark_type);
extern chunk_info_t get_chunk_info(struct dispatch_context *dc);
......
......@@ -33,7 +33,7 @@ void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_contex
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
futhark_restore_opaque_envelope_2d_i8,
FUT_I8);
FUTHARK_I8);
struct futhark_i8_2d *fut_chunk_board = futhark_new_i8_2d(fc, ci->data, ci->dimensions[0], ci->dimensions[1]);
struct futhark_i8_2d *fut_next_chunk_board;
......
......@@ -33,7 +33,7 @@ void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_contex
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
futhark_restore_opaque_envelope_2d_i8,
FUT_I8);
FUTHARK_I8);
struct futhark_i8_2d *fut_chunk_board = futhark_new_i8_2d(fc, ci->data, ci->dimensions[0], ci->dimensions[1]);
struct futhark_i8_2d *fut_next_chunk_board;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment