Skip to content

Commit

Permalink
New tiling variants, do_tile wrapper in easypap. New tracking mode in…
Browse files Browse the repository at this point in the history
… easyview.
  • Loading branch information
gforgeron committed Jan 9, 2022
1 parent 35e4b16 commit 1841a7a
Show file tree
Hide file tree
Showing 38 changed files with 975 additions and 568 deletions.
30 changes: 10 additions & 20 deletions data/templates/kernel_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ static unsigned compute_color (int i, int j)
return cur_img (i, j);
}

int <template>_do_tile_default (int x, int y, int width, int height)
{
for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++)
cur_img (i, j) = compute_color (i, j);

return 0;
}

// The kernel returns 0, or the iteration step at which computation has
// completed (e.g. stabilized).

Expand All @@ -39,9 +48,7 @@ unsigned <template>_compute_seq (unsigned nb_iter)
{
for (unsigned it = 1; it <= nb_iter; it++) {

for (int i = 0; i < DIM; i++)
for (int j = 0; j < DIM; j++)
next_img (i, j) = compute_color (i, j);
do_tile (0, 0, DIM, DIM, 0);

swap_images ();
}
Expand All @@ -56,23 +63,6 @@ unsigned <template>_compute_seq (unsigned nb_iter)
// or
// ./run -k <template> -v tiled -ts 64 -m
//
static void do_tile (int x, int y, int width, int height, int who)
{
// Calling monitoring_{start|end}_tile before/after actual computation allows
// to monitor the execution in real time (--monitoring) and/or to generate an
// execution trace (--trace).
// monitoring_start_tile only needs the cpu number
monitoring_start_tile (who);

for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++)
next_img (i, j) = compute_color (i, j);

// In addition to the cpu number, monitoring_end_tile also needs the tile
// coordinates
monitoring_end_tile (x, y, width, height, who);
}

unsigned <template>_compute_tiled (unsigned nb_iter)
{
for (unsigned it = 1; it <= nb_iter; it++) {
Expand Down
3 changes: 2 additions & 1 deletion include/api_funcs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef API_FUNCS_IS_DEF
#define API_FUNCS_IS_DEF


#include "trace_common.h"

typedef enum {
Expand All @@ -22,7 +23,7 @@ unsigned easypap_gpu_lane (task_type_t task_type);
int easypap_mpi_rank (void);
int easypap_mpi_size (void);
void easypap_check_mpi (void);
void easypap_check_vectorization (vec_type_t vec_type, direction_t dir);
void easypap_vec_check (unsigned vec_width_in_bytes, direction_t dir);
int easypap_proc_is_master (void);


Expand Down
36 changes: 20 additions & 16 deletions include/arch_flags.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
#ifndef ARCH_FLAGS_IS_DEF
#define ARCH_FLAGS_IS_DEF

#ifdef ENABLE_VECTO
#include <stdint.h>

#if __AVX2__ == 1
#define IS_LITTLE_ENDIAN \
((union { \
uint32_t u; \
uint8_t c; \
}){.u = 1} \
.c)
#define IS_BIG_ENDIAN (!IS_LITTLE_ENDIAN)

#define VEC_SIZE_CHAR 32
#define VEC_SIZE_INT 8
#define VEC_SIZE_FLOAT 8
#define VEC_SIZE_DOUBLE 4
#ifdef ENABLE_VECTO

#define AVX2 1
#define AVX_VEC_SIZE_CHAR 32
#define AVX_VEC_SIZE_INT 8
#define AVX_VEC_SIZE_FLOAT 8
#define AVX_VEC_SIZE_DOUBLE 4

#elif __SSE__ == 1
#define AVX_WIDTH AVX_VEC_SIZE_CHAR

#define VEC_SIZE_CHAR 16
#define VEC_SIZE_INT 4
#define VEC_SIZE_FLOAT 4
#define VEC_SIZE_DOUBLE 2
#define SSE_VEC_SIZE_CHAR 16
#define SSE_VEC_SIZE_INT 4
#define SSE_VEC_SIZE_FLOAT 4
#define SSE_VEC_SIZE_DOUBLE 2

#define SSE 1

#endif
#define SSE_WIDTH SSE_VEC_SIZE_CHAR

#endif

void arch_flags_print (void);

#endif
#endif
2 changes: 1 addition & 1 deletion include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ extern char *draw_param;
extern unsigned opencl_used;
extern unsigned easypap_mpirun;

extern char *kernel_name, *variant_name;
extern char *kernel_name, *variant_name, *tile_name;

#endif
7 changes: 6 additions & 1 deletion include/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
typedef void (*void_func_t) (void);
typedef unsigned (*int_func_t) (unsigned);
typedef void (*draw_func_t) (char *);
typedef int (*tile_func_t) (int, int, int, int);

extern draw_func_t the_config;
extern void_func_t the_init;
Expand All @@ -12,11 +13,15 @@ extern draw_func_t the_draw;
extern void_func_t the_finalize;
extern int_func_t the_compute;
extern void_func_t the_refresh_img;
extern void_func_t the_tile_check;

void *hooks_find_symbol (char *symbol);
void hooks_establish_bindings (int silent);

// Call function ${kernel}_draw_${suffix}, or default_func if symbol not found
void hooks_draw_helper (char *suffix, void_func_t default_func);

#endif
// Call appropriate do_tile_${suffix} function, with calls to monitoring start/end
int do_tile (int x, int y, int width, int height, int who);

#endif
19 changes: 8 additions & 11 deletions kernel/c/blur.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Suggested cmdline(s):
// ./run -l images/1024.png -k blur -v seq -si
//
static void do_tile_reg (int x, int y, int width, int height)
int blur_do_tile_default (int x, int y, int width, int height)
{
for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++) {
Expand Down Expand Up @@ -35,13 +35,19 @@ static void do_tile_reg (int x, int y, int width, int height)

next_img (i, j) = rgba (r, g, b, a);
}

return 0;
}

///////////////////////////// Sequential version (tiled)
// Suggested cmdline(s):
// ./run -l images/1024.png -k blur -v seq
//
unsigned blur_compute_seq (unsigned nb_iter)
{
for (unsigned it = 1; it <= nb_iter; it++) {

do_tile_reg (0, 0, DIM, DIM);
do_tile (0, 0, DIM, DIM, 0);

swap_images ();
}
Expand All @@ -53,15 +59,6 @@ unsigned blur_compute_seq (unsigned nb_iter)
// Suggested cmdline(s):
// ./run -l images/1024.png -k blur -v tiled -ts 32 -m si
//
static inline void do_tile (int x, int y, int width, int height, int who)
{
monitoring_start_tile (who);

do_tile_reg (x, y, width, height);

monitoring_end_tile (x, y, width, height, who);
}

unsigned blur_compute_tiled (unsigned nb_iter)
{
for (unsigned it = 1; it <= nb_iter; it++) {
Expand Down
25 changes: 9 additions & 16 deletions kernel/c/invert.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ static inline unsigned compute_color (int i, int j)
return INV_MASK ^ cur_img (i, j);
}

int invert_do_tile_default (int x, int y, int width, int height)
{
for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++)
cur_img (i, j) = compute_color (i, j);

return 0;
}

///////////////////////////// Simple sequential version (seq)
// Suggested cmdline(s):
// ./run -l images/shibuya.png -k invert -v seq -i 100 -n
Expand All @@ -26,22 +35,6 @@ unsigned invert_compute_seq (unsigned nb_iter)
return 0;
}

// Tile inner computation
static void do_tile_reg (int x, int y, int width, int height)
{
for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++)
cur_img (i, j) = compute_color (i, j);
}

static void do_tile (int x, int y, int width, int height, int who)
{
monitoring_start_tile (who);

do_tile_reg (x, y, width, height);

monitoring_end_tile (x, y, width, height, who);
}

///////////////////////////// Tiled sequential version (tiled)
// Suggested cmdline(s):
Expand Down
76 changes: 24 additions & 52 deletions kernel/c/life.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,79 +65,51 @@ static inline void swap_tables (void)
_alternate_table = tmp;
}

///////////////////////////// Sequential version (seq)

static int compute_new_state (int y, int x)
///////////////////////////// Default tiling
int life_do_tile_default (int x, int y, int width, int height)
{
unsigned n = 0;
unsigned me = cur_table (y, x) != 0;
unsigned change = 0;
int change = 0;

for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++)
if (j > 0 && j < DIM - 1 && i > 0 && i < DIM - 1) {

if (x > 0 && x < DIM - 1 && y > 0 && y < DIM - 1) {
unsigned n = 0;
unsigned me = cur_table (i, j);

for (int i = y - 1; i <= y + 1; i++)
for (int j = x - 1; j <= x + 1; j++)
n += cur_table (i, j);
for (int yloc = i - 1; yloc < i + 2; yloc++)
for (int xloc = j - 1; xloc < j + 2; xloc++)
n += cur_table (yloc, xloc);

n = (n == 3 + me) | (n == 3);
if (n != me)
change |= 1;
n = (n == 3 + me) | (n == 3);
change |= (n != me);

next_table (y, x) = n;
}
next_table (i, j) = n;
}

return change;
}

///////////////////////////// Sequential version (seq)
//
unsigned life_compute_seq (unsigned nb_iter)
{
for (unsigned it = 1; it <= nb_iter; it++) {
int change = 0;

monitoring_start_tile (0);

for (int i = 0; i < DIM; i++)
for (int j = 0; j < DIM; j++)
change |= compute_new_state (i, j);

monitoring_end_tile (0, 0, DIM, DIM, 0);

swap_tables ();
int change = do_tile (0, 0, DIM, DIM, 0);

if (!change)
return it;

swap_tables ();
}

return 0;
}

///////////////////////////// Tiled sequential version (tiled)

// Tile inner computation
static int do_tile_reg (int x, int y, int width, int height)
{
int change = 0;

for (int i = y; i < y + height; i++)
for (int j = x; j < x + width; j++)
change |= compute_new_state (i, j);

return change;
}

static int do_tile (int x, int y, int width, int height, int who)
{
int r;

monitoring_start_tile (who);

r = do_tile_reg (x, y, width, height);

monitoring_end_tile (x, y, width, height, who);

return r;
}

///////////////////////////// Tiled sequential version (tiled)
//
unsigned life_compute_tiled (unsigned nb_iter)
{
unsigned res = 0;
Expand All @@ -151,7 +123,7 @@ unsigned life_compute_tiled (unsigned nb_iter)

swap_tables ();

if (!change) { // we stop when all cells are stable
if (!change) { // we stop if all cells are stable
res = it;
break;
}
Expand Down
Loading

0 comments on commit 1841a7a

Please sign in to comment.