Skip to content

Commit

Permalink
Bump dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Sep 1, 2023
1 parent 11596c9 commit dec2ebe
Show file tree
Hide file tree
Showing 41 changed files with 1,982 additions and 339 deletions.
2 changes: 1 addition & 1 deletion accelerate/julia/futhark.pkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require {
github.com/diku-dk/complex 0.2.0 #19c5afb0931c4cfe4d8f2e9540ba01edd9460639
github.com/athas/matte 0.1.3 #ec4243a5f64cb818a4289dbc4953460ea19da12c
github.com/diku-dk/lys 0.1.20 #c67c64659893ee9657845d00c5be8bdb6ed495ff
github.com/diku-dk/lys 0.1.23 #9248502662fba6286b975b3f29e881dc8424ed03
}
114 changes: 71 additions & 43 deletions accelerate/julia/lib/github.com/diku-dk/lys/ncurses/liblys.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ void def() {
printf("\033[0m");
}

void fg_rgb(uint8_t r, uint8_t g, uint8_t b) {
printf("\033[38;2;%d;%d;%dm", r, g, b);
void fg_rgb(FILE *f, uint8_t r, uint8_t g, uint8_t b) {
fprintf(f, "\033[38;2;%d;%d;%dm", r, g, b);
}

void bg_rgb(uint8_t r, uint8_t g, uint8_t b) {
printf("\033[48;2;%d;%d;%dm", r, g, b);
void bg_rgb(FILE *f, uint8_t r, uint8_t g, uint8_t b) {
fprintf(f, "\033[48;2;%d;%d;%dm", r, g, b);
}

void cursor_goto(int x, int y) {
Expand All @@ -38,7 +38,7 @@ void render(int nrows, int ncols, const uint32_t *rgbs,
}
}

void display(int nrows, int ncols,
void display(FILE *f, bool eol, int nrows, int ncols,
const uint32_t *fgs, const uint32_t *bgs, const char *chars) {
uint32_t prev_w0 = 0xdeadbeef;
uint32_t prev_w1 = 0xdeadbeef;
Expand All @@ -55,18 +55,21 @@ void display(int nrows, int ncols,
r1 = (w1>>16)&0xFF;
g1 = (w1>>8)&0xFF;
b1 = (w1>>0)&0xFF;
fg_rgb(r0, g0, b0);
bg_rgb(r1, g1, b1);
fg_rgb(f, r0, g0, b0);
bg_rgb(f, r1, g1, b1);
prev_w0 = w0;
prev_w1 = w1;
}
char c = chars[i*ncols+j];
if (c == 127) {
fputs("▀", stdout);
fputs("▀", f);
} else {
fputc(c, stdout);
fputc(c, f);
}
}
if (eol) {
fputc('\n', f);
}
}
}

Expand Down Expand Up @@ -127,6 +130,7 @@ void check_input(struct lys_context *ctx) {
resize(ctx);
break;
case KEY_F0+1:
ctx->event_handler(ctx, LYS_F1);
keydown(ctx, 0x4000003A);
return;
case KEY_F0+2:
Expand Down Expand Up @@ -166,13 +170,23 @@ void lys_run_ncurses(struct lys_context *ctx) {
ctx->running = 1;
ctx->last_time = lys_wall_time();

resize(ctx);
if (ctx->interactive) {
resize(ctx);
}

int num_frames = 0;

ctx->event_handler(ctx, LYS_LOOP_START);

while (ctx->running) {
while (ctx->running && ctx->num_frames-- > 0) {
num_frames++;
int64_t now = lys_wall_time();
float delta = ((float)(now - ctx->last_time))/1000000.0;
float delta;
if (ctx->interactive) {
delta = ((float)(now - ctx->last_time))/1000000.0;
} else {
delta = 1/(double)ctx->max_fps;
}
ctx->fps = (ctx->fps*0.9 + (1/delta)*0.1);
ctx->last_time = now;
struct futhark_opaque_state *new_state, *old_state = ctx->state;
Expand All @@ -191,26 +205,31 @@ void lys_run_ncurses(struct lys_context *ctx) {
int ncols = ctx->width;
render(nrows, ncols, ctx->rgbs, ctx->fgs, ctx->bgs, ctx->chars);
ctx->event_handler(ctx, LYS_LOOP_ITERATION);
cursor_goto(0,0);
display(nrows, ncols, ctx->fgs, ctx->bgs, ctx->chars);
fflush(stdout);
if (ctx->interactive) {
cursor_goto(0,0);
}
display(ctx->out, !ctx->interactive, nrows, ncols, ctx->fgs, ctx->bgs, ctx->chars);
}
if (ctx->interactive) {
fflush(stdout);
check_input(ctx);

check_input(ctx);
int delay = 1000.0/ctx->max_fps - delta*1000.0;
if (delay > 0) {
usleep(delay*1000);
}

int delay = 1000.0/ctx->max_fps - delta*1000.0;
if (delay > 0) {
usleep(delay*1000);
def();
}

def();
}

ctx->event_handler(ctx, LYS_LOOP_END);

// Ncurses cleanup.
clrtobot();
endwin();
if (ctx->interactive) {
// Ncurses cleanup.
clrtobot();
endwin();
}

// Our cleanup.
free(ctx->rgbs);
Expand All @@ -220,29 +239,38 @@ void lys_run_ncurses(struct lys_context *ctx) {
FUT_CHECK(ctx->fut, futhark_free_opaque_state(ctx->fut, ctx->state));
}

void lys_setup(struct lys_context *ctx, int max_fps) {
// ncurses initialisation.
initscr(); // Initialise ncurses.
raw(); // Disable line buffering.
nodelay(stdscr, TRUE); // Non-blocking getch().
keypad(stdscr, TRUE); // F keys, arrow keys, etc.
noecho(); // Admit nothing.
intrflush(stdscr, TRUE); // Interrupts take precedence.
curs_set(0); // Hide cursor.

void lys_setup(struct lys_context *ctx, int max_fps, int num_frames, FILE* out, int width, int height) {
memset(ctx, 0, sizeof(struct lys_context));

int nrows, ncols;
getmaxyx(stdscr, nrows, ncols);

ctx->width = ncols;
ctx->height = nrows*2;
ctx->fps = 0;
ctx->max_fps = max_fps;
ctx->fgs = NULL;
ctx->bgs = NULL;
ctx->chars = NULL;
ctx->rgbs = NULL;
ctx->num_frames = num_frames;
ctx->interactive = out == NULL;

if (ctx->interactive) {
// ncurses initialisation.
initscr(); // Initialise ncurses.
raw(); // Disable line buffering.
nodelay(stdscr, TRUE); // Non-blocking getch().
keypad(stdscr, TRUE); // F keys, arrow keys, etc.
noecho(); // Admit nothing.
intrflush(stdscr, TRUE); // Interrupts take precedence.
curs_set(0); // Hide cursor.
int nrows, ncols;
getmaxyx(stdscr, nrows, ncols);
ctx->width = ncols;
ctx->height = nrows*2;
ctx->out = stdout;
} else {
ctx->out = out;
ctx->width = width;
ctx->height = height;
}

ctx->fgs = malloc(ctx->width * ctx->height * sizeof(uint32_t));
ctx->bgs = malloc(ctx->width * ctx->height * sizeof(uint32_t));
ctx->chars = malloc(ctx->width * ctx->height * sizeof(char));
ctx->rgbs = malloc(ctx->width*ctx->height*sizeof(uint32_t));
ctx->key_pressed = 0;
}

Expand Down
5 changes: 4 additions & 1 deletion accelerate/julia/lib/github.com/diku-dk/lys/ncurses/liblys.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ struct lys_context {
bool mouse_grabbed;
float fps;
int max_fps;
int num_frames;
void* event_handler_data;
void (*event_handler)(struct lys_context*, enum lys_event);
int key_pressed;
bool interactive;
FILE* out;
};

void lys_setup(struct lys_context *ctx, int max_fps);
void lys_setup(struct lys_context *ctx, int max_fps, int num_frames, FILE *output, int width, int height);

void lys_run_ncurses(struct lys_context *ctx);

Expand Down
42 changes: 33 additions & 9 deletions accelerate/julia/lib/github.com/diku-dk/lys/ncurses/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#include <unistd.h>
#include <getopt.h>
#include <string.h>

#define INITIAL_WIDTH 800
#define INITIAL_HEIGHT 600
#include <errno.h>

void loop_start(struct lys_context *ctx, struct lys_text *text) {
prepare_text(ctx->fut, text);
Expand Down Expand Up @@ -74,17 +72,22 @@ void usage(char **argv) {
puts(" -? Print this help and exit.");
puts(" -d DEV Set the computation device.");
puts(" -r INT Maximum frames per second.");
puts(" -f INT Frames rendered.");
puts(" -i Select execution device interactively.");
puts(" -b <render|step> Benchmark program.");
puts(" -n FILE Render frames to FILE.");
}

int main(int argc, char** argv) {
int max_fps = 60;
char *deviceopt = NULL;
bool device_interactive = false;
FILE *output = NULL;
int width = 74;
int height = 25*2;
int num_frames = -1;

int c;
while ( (c = getopt(argc, argv, "r:d:i")) != -1) {
while ( (c = getopt(argc, argv, "r:d:in:f:")) != -1) {
switch (c) {
case 'r':
max_fps = atoi(optarg);
Expand All @@ -93,12 +96,26 @@ int main(int argc, char** argv) {
exit(EXIT_FAILURE);
}
break;
case 'f':
num_frames = atoi(optarg);
if (num_frames <= 0) {
fprintf(stderr, "'%s' is not a number of frames.\n", optarg);
exit(EXIT_FAILURE);
}
break;
case 'd':
deviceopt = optarg;
break;
case 'i':
device_interactive = true;
break;
case 'n':
output = fopen(optarg, "w+");
if (output == NULL) {
fprintf(stderr, "Cannot open %s: %s\n", optarg, strerror(errno));
exit(1);
}
break;
case '?':
usage(argv);
return EXIT_SUCCESS;
Expand All @@ -109,9 +126,13 @@ int main(int argc, char** argv) {
}
}

void* buf = malloc(1024*1024);
setvbuf(stdout, buf, _IOFBF, 1024*1024);

if (num_frames < 0) {
if (output == NULL) {
num_frames = 1<<30;
} else {
num_frames = max_fps;
}
}

if (optind < argc) {
fprintf(stderr, "Excess non-options: ");
Expand All @@ -121,9 +142,12 @@ int main(int argc, char** argv) {
exit(EXIT_FAILURE);
}

void* buf = malloc(1024*1024);
setvbuf(stdout, buf, _IOFBF, 1024*1024);

struct lys_context ctx;
struct futhark_context_config *futcfg;
lys_setup(&ctx, max_fps);
lys_setup(&ctx, max_fps, num_frames, output, width, height);

char* opencl_device_name = NULL;
lys_setup_futhark_context(deviceopt, device_interactive,
Expand Down
6 changes: 4 additions & 2 deletions accelerate/julia/lib/github.com/diku-dk/lys/setup_flags.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ else
DEVICE_LDFLAGS=-lOpenCL
endif
else ifeq ($(LYS_BACKEND),cuda)
DEVICE_LDFLAGS=-lcuda -lnvrtc
DEVICE_LDFLAGS=-lcuda -lnvrtc -lcudart
else ifeq ($(LYS_BACKEND),hip)
DEVICE_LDFLAGS=-lamdhip64 -lhiprtc
else ifeq ($(LYS_BACKEND),c)
DEVICE_LDFLAGS=
else ifeq ($(LYS_BACKEND),multicore)
DEVICE_LDFLAGS=-lpthread
else
$(error Unknown LYS_BACKEND: $(LYS_BACKEND). Must be 'opencl', 'cuda', 'multicore', or 'c')
$(error Unknown LYS_BACKEND: $(LYS_BACKEND). Must be 'opencl', 'cuda', 'hip', 'multicore', or 'c')
endif

LDFLAGS?=-lm $(PKG_LDFLAGS) $(DEVICE_LDFLAGS)
2 changes: 1 addition & 1 deletion accelerate/mandelbrot/futhark.pkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require {
github.com/diku-dk/complex 0.2.0 #19c5afb0931c4cfe4d8f2e9540ba01edd9460639
github.com/athas/matte 0.1.3 #ec4243a5f64cb818a4289dbc4953460ea19da12c
github.com/diku-dk/lys 0.1.20 #c67c64659893ee9657845d00c5be8bdb6ed495ff
github.com/diku-dk/lys 0.1.23 #9248502662fba6286b975b3f29e881dc8424ed03
}
Loading

0 comments on commit dec2ebe

Please sign in to comment.