From 5006bb17f23ad99051a670a867e1fd88ee42d97e Mon Sep 17 00:00:00 2001 From: "raphael.bach" <raphael.bach@etu.hesge.ch> Date: Thu, 23 Jun 2022 21:43:24 +0200 Subject: [PATCH] Add `fmpi_futhark_free_data_{sync, async}()` --- include/internal/fmpi_futhark.h | 14 ++++++ .../internal/generic/fmpi_futhark_generic.h | 4 +- src/fmpi_futhark.c | 50 ++++++++++++++++--- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/include/internal/fmpi_futhark.h b/include/internal/fmpi_futhark.h index c87d0a0..19912fd 100644 --- a/include/internal/fmpi_futhark.h +++ b/include/internal/fmpi_futhark.h @@ -132,6 +132,20 @@ void * fmpi_futhark_new_data( const struct fmpi_futhark_ctx * ctx, const void * data, enum fmpi_type_base type, size_t dim_cnt, size_t x, size_t y, size_t z ); +/*------------------------------------------------------------------------------ + fmpi_futhark_free_data_sync() +------------------------------------------------------------------------------*/ +int fmpi_futhark_free_data_sync( + const struct fmpi_futhark_ctx * ctx, void * data, enum fmpi_type_base type, + size_t dim_cnt +); +/*------------------------------------------------------------------------------ + fmpi_futhark_free_data_async() +------------------------------------------------------------------------------*/ +int fmpi_futhark_free_data_async( + const struct fmpi_futhark_ctx * ctx, void * data, enum fmpi_type_base type, + size_t dim_cnt +); /*------------------------------------------------------------------------------ fmpi_futhark_get_data_sync() ------------------------------------------------------------------------------*/ diff --git a/include/internal/generic/fmpi_futhark_generic.h b/include/internal/generic/fmpi_futhark_generic.h index 266a52b..a00cea6 100644 --- a/include/internal/generic/fmpi_futhark_generic.h +++ b/include/internal/generic/fmpi_futhark_generic.h @@ -67,8 +67,8 @@ struct fmpi_futhark_ctx; 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, void * array \ +int fmpi_futhark_free_##D##d_##T( \ + const struct fmpi_futhark_ctx * ctx, void * data \ ); \ int fmpi_futhark_values_##D##d_##T( \ const struct fmpi_futhark_ctx * ctx, void * in, void * out \ diff --git a/src/fmpi_futhark.c b/src/fmpi_futhark.c index 90350bd..430d4fc 100644 --- a/src/fmpi_futhark.c +++ b/src/fmpi_futhark.c @@ -45,6 +45,15 @@ static const fmpi_futhark_new_data_func fmpi_futhark_new_data_func_list[] = { FMPI_FUTHARK_FUNC_ENTRY_LIST(new, 3) }; +typedef int (*fmpi_futhark_free_data_func)( + const struct fmpi_futhark_ctx * ctx, void * data +); +static const fmpi_futhark_free_data_func fmpi_futhark_free_data_func_list[] = { + FMPI_FUTHARK_FUNC_ENTRY_LIST(free, 1), + FMPI_FUTHARK_FUNC_ENTRY_LIST(free, 2), + FMPI_FUTHARK_FUNC_ENTRY_LIST(free, 3) +}; + typedef int (*fmpi_futhark_get_data_func)( const struct fmpi_futhark_ctx * ctx, void * in, void * out ); @@ -160,6 +169,33 @@ void * fmpi_futhark_new_data( const size_t idx = FMPI_PRIV_FUTHARK_FUNC_IDX(dim_cnt, type); return fmpi_futhark_new_data_func_list[idx](ctx, data, x, y, z); } +/*------------------------------------------------------------------------------ + fmpi_futhark_free_data_sync() +------------------------------------------------------------------------------*/ +int fmpi_futhark_free_data_sync( + const struct fmpi_futhark_ctx * const ctx, void * const data, + const enum fmpi_type_base type, const size_t dim_cnt +){ + assert(ctx != NULL); + assert(data != NULL); + const size_t idx = FMPI_PRIV_FUTHARK_FUNC_IDX(dim_cnt, type); + const int err = fmpi_futhark_free_data_func_list[idx](ctx, data); + fmpi_futhark_sync(ctx); + fmpi_futhark_check_error(ctx, "futhark_free_##T##_##D##"); + return err; +} +/*------------------------------------------------------------------------------ + fmpi_futhark_free_data_async() +------------------------------------------------------------------------------*/ +int fmpi_futhark_free_data_async( + const struct fmpi_futhark_ctx * const ctx, void * const data, + const enum fmpi_type_base type, const size_t dim_cnt +){ + assert(ctx != NULL); + assert(data != NULL); + const size_t idx = FMPI_PRIV_FUTHARK_FUNC_IDX(dim_cnt, type); + return fmpi_futhark_free_data_func_list[idx](ctx, data); +} /*------------------------------------------------------------------------------ fmpi_futhark_get_data_sync() ------------------------------------------------------------------------------*/ @@ -214,17 +250,17 @@ void * fmpi_futhark_new_##D##d_##T( \ fmpi_futhark_sync(ctx); \ return data; \ } \ -void fmpi_futhark_free_##D##d_##T( \ - const struct fmpi_futhark_ctx * const ctx, void * const array \ +int fmpi_futhark_free_##D##d_##T( \ + const struct fmpi_futhark_ctx * const ctx, void * const data \ ){ \ _Static_assert((D) <= FMPI_DIM_MAX, ""); \ assert(ctx != NULL); \ - assert(array != NULL); \ - fmpi_futhark_sync(ctx); \ - const int err = futhark_free_##T##_##D##d(ctx->ctx, array); \ - if(err != 0) { \ - fmpi_futhark_check_error(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)); \ + assert(data != NULL); \ + const int err = futhark_free_##T##_##D##d(ctx->ctx, data); \ + if(err != FUTHARK_SUCCESS) { \ + FMPI_RAISE_FUTHARK_ERROR(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)"() failed!"); \ } \ + return err; \ } \ int fmpi_futhark_values_##D##d_##T( \ const struct fmpi_futhark_ctx * const ctx, void * const in, void * const out \ -- GitLab