Skip to content

Instantly share code, notes, and snippets.

@nqpz
Created February 12, 2023 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nqpz/94e0e7499be770e86c90231ff0060014 to your computer and use it in GitHub Desktop.
Save nqpz/94e0e7499be770e86c90231ff0060014 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "lib.h"
#define ISSUE_DIMS 2
#if ISSUE_DIMS == 1
typedef struct futhark_f32_1d cells_t;
#define free_cells futhark_free_f32_1d
#define init futhark_entry_init_1d
#define step futhark_entry_step_1d
#elif ISSUE_DIMS == 2
typedef struct futhark_f32_2d cells_t;
#define free_cells futhark_free_f32_2d
#define init futhark_entry_init_2d
#define step futhark_entry_step_2d
#endif
#define FUT_CHECK(ctx, x) _fut_check(ctx, x, __FILE__, __LINE__)
static inline void _fut_check(struct futhark_context *ctx, int res,
const char *file, int line) {
if (res != 0) {
fprintf(stderr, "%s:%d: Futhark error %d: %s\n",
file, line, res, futhark_context_get_error(ctx));
exit(EXIT_FAILURE);
}
}
int main() {
struct futhark_context *futctx;
struct futhark_context_config *futcfg;
cells_t *cells;
futcfg = futhark_context_config_new();
assert(futcfg != NULL);
futctx = futhark_context_new(futcfg);
assert(futctx != NULL);
init(futctx, &cells, 1000);
for (int i = 0; i < 1000; i++) {
printf("Iteration %d\n", i);
cells_t *new_cells;
cells_t *old_cells = cells;
FUT_CHECK(futctx, step(futctx, &new_cells, old_cells));
cells = new_cells;
FUT_CHECK(futctx, free_cells(futctx, old_cells));
}
FUT_CHECK(futctx, free_cells(futctx, cells));
futhark_context_free(futctx);
futhark_context_config_free(futcfg);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment