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

Add `fmpi_futhark_new_data()`

parent 78c6fb32
No related branches found
No related tags found
No related merge requests found
......@@ -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
==============================================================================*/
......
......@@ -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);
......
......@@ -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); \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment