Created
February 12, 2023 10:31
-
-
Save nqpz/94e0e7499be770e86c90231ff0060014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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