From 7517592280d12a15261cce445ba5aa50df5c27b9 Mon Sep 17 00:00:00 2001 From: "raphael.bach" <raphael.bach@etu.hesge.ch> Date: Sun, 22 May 2022 17:13:53 +0200 Subject: [PATCH] Add `fmpi_futhark_new_data()` --- include/internal/fmpi_futhark.h | 10 +++++- .../internal/generic/fmpi_futhark_generic.h | 15 ++++++-- src/fmpi_futhark.c | 34 +++++++++++++++++-- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/include/internal/fmpi_futhark.h b/include/internal/fmpi_futhark.h index 92688f7..1e09e3f 100644 --- a/include/internal/fmpi_futhark.h +++ b/include/internal/fmpi_futhark.h @@ -29,7 +29,8 @@ // C Standard Library // Internal #include "fmpi_error.h" -#include "generic/fmpi_futhark_generic.h" +#include "internal/generic/fmpi_futhark_generic.h" +#include "internal/generic/fmpi_type.h" /*============================================================================== STRUCT ==============================================================================*/ @@ -127,6 +128,13 @@ int fmpi_futhark_sync(const struct fmpi_futhark_ctx * ctx); * - \p{func} must not be `NULL`. */ _Bool fmpi_futhark_check_error(const struct fmpi_futhark_ctx * ctx, const char * func); +/*------------------------------------------------------------------------------ + fmpi_futhark_new_data() +------------------------------------------------------------------------------*/ +void * fmpi_futhark_new_data( + const struct fmpi_futhark_ctx * ctx, const void * data, enum fmpi_type type, + size_t dim_cnt, size_t x, size_t y, size_t z +); /*============================================================================== MACRO ==============================================================================*/ diff --git a/include/internal/generic/fmpi_futhark_generic.h b/include/internal/generic/fmpi_futhark_generic.h index f860baf..29732ce 100644 --- a/include/internal/generic/fmpi_futhark_generic.h +++ b/include/internal/generic/fmpi_futhark_generic.h @@ -28,7 +28,10 @@ ==============================================================================*/ // C Standard Library #include <stddef.h> // size_t +// External +#include "../../../external/cpl/cpl_map.h" // Internal +#include "../fmpi_common.h" #include "fmpi_generic.h" /*============================================================================== MACRO @@ -38,6 +41,12 @@ struct fmpi_futhark_ctx; #define FMPI_FUTHARK_TYPES \ FMPI_TYPE_REAL +#define FMPI_PRIV_FUTHARK_ARRAY_ENTRY(D, T) \ + [FMPI_TYPE_##T * (FMPI_DIM_MAX) + ((D)-1)] = fmpi_futhark_new_##D##d_##T + +#define FMPI_FUTHARK_ARRAY_ENTRY_LIST(D) \ + CPL_MAP_FIXED(FMPI_PRIV_FUTHARK_ARRAY_ENTRY, CPL_COMMA, (D), FMPI_FUTHARK_TYPES) + #if defined(__GNUC__) || defined(__GNUG__) _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") _Pragma("GCC diagnostic push") @@ -62,11 +71,11 @@ struct fmpi_futhark_ctx; futhark_new_##T##_3d(ctx, array, (int64_t)(x), (int64_t)(y), (int64_t)(z)); #define FMPI_FUTHARK_DECLARATION(D, T) \ -struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \ - const struct fmpi_futhark_ctx * ctx, const T * array, size_t x, size_t y, size_t z \ +void * fmpi_futhark_new_##D##d_##T( \ + const struct fmpi_futhark_ctx * ctx, const void * array, size_t x, size_t y, size_t z \ ); \ void fmpi_futhark_free_##D##d_##T( \ - const struct fmpi_futhark_ctx * ctx, struct futhark_##T##_##D##d * array \ + const struct fmpi_futhark_ctx * ctx, void * array \ ) FMPI_DECLARE_DIM_FUNCS(FMPI_FUTHARK_DECLARATION, 1, FMPI_FUTHARK_TYPES); diff --git a/src/fmpi_futhark.c b/src/fmpi_futhark.c index f5a23bd..e49b554 100644 --- a/src/fmpi_futhark.c +++ b/src/fmpi_futhark.c @@ -29,9 +29,22 @@ #include <stdint.h> // int64_t #include <stdlib.h> // Internal +#include "internal/fmpi_common.h" #include "internal/fmpi_ctx.h" #include "internal/fmpi_futhark_entry.h" #include "internal/generic/fmpi_generic.h" +/*============================================================================== + STATIC +==============================================================================*/ +typedef void * (*fmpi_futhark_new_data_func)( + const struct fmpi_futhark_ctx * ctx, const void * data, + size_t x, size_t y, size_t z +); +static const fmpi_futhark_new_data_func fmpi_futhark_new_data_func_list[] = { + FMPI_FUTHARK_ARRAY_ENTRY_LIST(1), + FMPI_FUTHARK_ARRAY_ENTRY_LIST(2), + FMPI_FUTHARK_ARRAY_ENTRY_LIST(3) +}; /*============================================================================== MACRO ==============================================================================*/ @@ -127,10 +140,25 @@ _Bool fmpi_futhark_check_error( } return false; } +/*------------------------------------------------------------------------------ + fmpi_futhark_new_data() +------------------------------------------------------------------------------*/ +void * fmpi_futhark_new_data( + const struct fmpi_futhark_ctx * ctx, const void * const data, + const enum fmpi_type type, const size_t dim_cnt, + const size_t x, const size_t y, const size_t z +){ + assert(ctx != NULL); + assert(data != NULL); + assert(dim_cnt <= FMPI_DIM_MAX); + const size_t idx = (type * (FMPI_DIM_MAX) + ((dim_cnt)-1)); + return fmpi_futhark_new_data_func_list[idx](ctx, data, x, y, z); +} #define FMPI_FUTHARK_DEFINITION(D, T) \ -struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \ - const struct fmpi_futhark_ctx * const ctx, const T * const array, size_t x, size_t y, size_t z \ +void * fmpi_futhark_new_##D##d_##T( \ + const struct fmpi_futhark_ctx * const ctx, const void * const array, \ + const size_t x, const size_t y, const size_t z \ ){ \ assert(ctx != NULL); \ assert(array != NULL); \ @@ -142,7 +170,7 @@ struct futhark_##T##_##D##d * fmpi_futhark_new_##D##d_##T( \ return data; \ }\ void fmpi_futhark_free_##D##d_##T( \ - const struct fmpi_futhark_ctx * const ctx, struct futhark_##T##_##D##d * const array \ + const struct fmpi_futhark_ctx * const ctx, void * const array \ ){ \ assert(ctx != NULL); \ assert(array != NULL); \ -- GitLab