Skip to content
Snippets Groups Projects
Verified Commit 31737f95 authored by raphael.bach's avatar raphael.bach
Browse files

Make `fmpi_futhark_{new,free}()` take a `fmpi_futhark_ctx` instead of a `fmpi_ctx`

parent e82c4ec7
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
/*============================================================================== /*==============================================================================
MACRO MACRO
==============================================================================*/ ==============================================================================*/
struct fmpi_ctx; struct fmpi_futhark_ctx;
#define FMPI_FUTHARK_TYPES \ #define FMPI_FUTHARK_TYPES \
FMPI_TYPE_REAL FMPI_TYPE_REAL
...@@ -63,10 +63,10 @@ struct fmpi_ctx; ...@@ -63,10 +63,10 @@ struct fmpi_ctx;
#define FMPI_FUTHARK_DECLARATION(D, T) \ #define FMPI_FUTHARK_DECLARATION(D, T) \
struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \ struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \
const struct fmpi_ctx * ctx, const T * array, size_t x, size_t y, size_t z \ const struct fmpi_futhark_ctx * ctx, const T * array, size_t x, size_t y, size_t z \
); \ ); \
void fmpi_futhark_free_##D##d_##T( \ void fmpi_futhark_free_##D##d_##T( \
const struct fmpi_ctx * ctx, struct futhark_##T##_##D##d * array \ const struct fmpi_futhark_ctx * ctx, struct futhark_##T##_##D##d * array \
) )
FMPI_DECLARE_DIM_FUNCS(FMPI_FUTHARK_DECLARATION, 1, FMPI_FUTHARK_TYPES); FMPI_DECLARE_DIM_FUNCS(FMPI_FUTHARK_DECLARATION, 1, FMPI_FUTHARK_TYPES);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <stdio.h> // fprintf() #include <stdio.h> // fprintf()
#include <stdlib.h> // malloc() #include <stdlib.h> // malloc()
// Internal // Internal
#include "internal/fmpi_ctx.h"
#include "internal/fmpi_futhark.h" #include "internal/fmpi_futhark.h"
#include "internal/generic/fmpi_type.h" #include "internal/generic/fmpi_type.h"
/*============================================================================== /*==============================================================================
...@@ -56,7 +57,7 @@ struct fmpi_data fmpi_data_##D##d_in_new_##T( \ ...@@ -56,7 +57,7 @@ struct fmpi_data fmpi_data_##D##d_in_new_##T( \
assert(ctx != NULL); \ assert(ctx != NULL); \
assert(data != NULL); \ assert(data != NULL); \
_Static_assert(D <= 3, ""); \ _Static_assert(D <= 3, ""); \
struct futhark_##T##_##D##d * const start = fmpi_futhark_new_##D##d_##T(ctx, data, x, y, z); \ struct futhark_##T##_##D##d * const start = fmpi_futhark_new_##D##d_##T(ctx->fut, data, x, y, z); \
return (struct fmpi_data){ \ return (struct fmpi_data){ \
.type = FMPI_TYPE_##T, \ .type = FMPI_TYPE_##T, \
.dims_length = {x, y, z}, \ .dims_length = {x, y, z}, \
......
...@@ -130,26 +130,26 @@ _Bool fmpi_futhark_check_error( ...@@ -130,26 +130,26 @@ _Bool fmpi_futhark_check_error(
#define FMPI_FUTHARK_DEFINITION(D, T) \ #define FMPI_FUTHARK_DEFINITION(D, T) \
struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \ struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \
const struct fmpi_ctx * const ctx, const T * const array, size_t x, size_t y, size_t z \ const struct fmpi_futhark_ctx * const ctx, const T * const array, size_t x, size_t y, size_t z \
){ \ ){ \
assert(ctx != NULL); \ assert(ctx != NULL); \
assert(array != NULL); \ assert(array != NULL); \
struct futhark_##T##_##D##d * data = FMPI_FUTHARK_NEW_##D(D, T, ctx->fut->ctx, array, x, y, z); \ struct futhark_##T##_##D##d * data = FMPI_FUTHARK_NEW_##D(D, T, ctx->ctx, array, x, y, z); \
if(data == NULL) { \ if(data == NULL) { \
fmpi_futhark_check_error(ctx->fut, CPL_STRINGIFY(futhark_new_##T##_##D##d)); \ fmpi_futhark_check_error(ctx, CPL_STRINGIFY(futhark_new_##T##_##D##d)); \
} \ } \
fmpi_futhark_sync(ctx->fut); \ fmpi_futhark_sync(ctx); \
return data; \ return data; \
}\ }\
void fmpi_futhark_free_##D##d_##T( \ void fmpi_futhark_free_##D##d_##T( \
const struct fmpi_ctx * const ctx, struct futhark_##T##_##D##d * const array \ const struct fmpi_futhark_ctx * const ctx, struct futhark_##T##_##D##d * const array \
){ \ ){ \
assert(ctx != NULL); \ assert(ctx != NULL); \
assert(array != NULL); \ assert(array != NULL); \
fmpi_futhark_sync(ctx->fut);\ fmpi_futhark_sync(ctx);\
const int err = futhark_free_##T##_##D##d(ctx->fut->ctx, array); \ const int err = futhark_free_##T##_##D##d(ctx->ctx, array); \
if(err != 0) { \ if(err != 0) { \
fmpi_futhark_check_error(ctx->fut, CPL_STRINGIFY(futhark_free_##T##_##D##d)); \ fmpi_futhark_check_error(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)); \
} \ } \
} }
......
...@@ -46,14 +46,14 @@ T fmpi_local_reduce_prod_##T( \ ...@@ -46,14 +46,14 @@ T fmpi_local_reduce_prod_##T( \
){ \ ){ \
assert(ctx != NULL); \ assert(ctx != NULL); \
assert(array != NULL); \ assert(array != NULL); \
struct futhark_##T##_1d * data = fmpi_futhark_new_1d_##T(ctx, array, length, 0, 0);\ struct futhark_##T##_1d * data = fmpi_futhark_new_1d_##T(ctx->fut, array, length, 0, 0);\
T result = FMPI_TYPE_DEFAULT_##T; \ T result = FMPI_TYPE_DEFAULT_##T; \
const int err = futhark_entry_reduce_prod_##T(ctx->fut->ctx, &result, data); \ const int err = futhark_entry_reduce_prod_##T(ctx->fut->ctx, &result, data); \
if(err != 0) { \ if(err != 0) { \
fmpi_futhark_check_error(ctx->fut, CPL_STRINGIFY(futhark_entry_reduce_prod_##T)); \ fmpi_futhark_check_error(ctx->fut, CPL_STRINGIFY(futhark_entry_reduce_prod_##T)); \
} \ } \
fmpi_futhark_sync(ctx->fut); \ fmpi_futhark_sync(ctx->fut); \
fmpi_futhark_free_1d_##T(ctx, data); \ fmpi_futhark_free_1d_##T(ctx->fut, data); \
return result; \ return result; \
}\ }\
T fmpi_reduce_prod_##T(const struct fmpi_ctx * const ctx, const T * const array) \ T fmpi_reduce_prod_##T(const struct fmpi_ctx * const ctx, const T * const array) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment