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

Add `struct fmpi_type`

- Rename `enum fmpi_type` to `enum fmpi_type_base`
- Rename `enum fmpi_derived_type` to `enum fmpi_type_derived`
- Replace type information in `fmpi_data` with the new `fmpi_type`
parent 0cabcc80
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
// Internal // Internal
#include "internal/fmpi_common.h" #include "internal/fmpi_common.h"
#include "internal/generic/fmpi_data_generic.h" #include "internal/generic/fmpi_data_generic.h"
#include "internal/generic/fmpi_type.h"
/*============================================================================== /*==============================================================================
TYPE TYPE
==============================================================================*/ ==============================================================================*/
...@@ -41,10 +42,9 @@ ...@@ -41,10 +42,9 @@
* Holds informations about data such as its type, count, size, etc. * Holds informations about data such as its type, count, size, etc.
*/ */
typedef struct fmpi_data { typedef struct fmpi_data {
enum fmpi_type type; //!< Type of the data. struct fmpi_type type; //!< Type of the data.
size_t type_size; //!< Size of the type `(sizeof(T))`.
size_t cnt; //!< Total number of elements. size_t cnt; //!< Total number of elements.
size_t size; //!< Total size `(cnt * type_size)`. size_t size; //!< Total size `(cnt * type.size)`.
size_t dim_len[FMPI_DIM_MAX]; //!< Length of each dimension. size_t dim_len[FMPI_DIM_MAX]; //!< Length of each dimension.
size_t dim_cnt; //!< Number of dimensions. size_t dim_cnt; //!< Number of dimensions.
void * start; //!< Pointer to the start of the data. void * start; //!< Pointer to the start of the data.
......
...@@ -129,8 +129,8 @@ _Bool fmpi_futhark_check_error(const struct fmpi_futhark_ctx * ctx, const char * ...@@ -129,8 +129,8 @@ _Bool fmpi_futhark_check_error(const struct fmpi_futhark_ctx * ctx, const char *
fmpi_futhark_new_data() fmpi_futhark_new_data()
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
void * fmpi_futhark_new_data( void * fmpi_futhark_new_data(
const struct fmpi_futhark_ctx * ctx, const void * data, enum fmpi_type type, const struct fmpi_futhark_ctx * ctx, const void * data,
size_t dim_cnt, size_t x, size_t y, size_t z enum fmpi_type_base type, size_t dim_cnt, size_t x, size_t y, size_t z
); );
/*============================================================================== /*==============================================================================
MACRO MACRO
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
INCLUDE INCLUDE
==============================================================================*/ ==============================================================================*/
// C Standard Library // C Standard Library
#include <stddef.h> // size_t
#include <stdint.h> #include <stdint.h>
/*============================================================================== /*==============================================================================
TYPEDEF TYPEDEF
...@@ -46,7 +47,7 @@ typedef _Bool bool; ...@@ -46,7 +47,7 @@ typedef _Bool bool;
/*============================================================================== /*==============================================================================
ENUM ENUM
==============================================================================*/ ==============================================================================*/
typedef enum fmpi_type { typedef enum fmpi_type_base {
FMPI_TYPE_START = 0, FMPI_TYPE_START = 0,
FMPI_TYPE_i8 = 0, FMPI_TYPE_i8 = 0,
FMPI_TYPE_i16 = 1, FMPI_TYPE_i16 = 1,
...@@ -60,7 +61,7 @@ typedef enum fmpi_type { ...@@ -60,7 +61,7 @@ typedef enum fmpi_type {
FMPI_TYPE_f64 = 9, FMPI_TYPE_f64 = 9,
FMPI_TYPE_bool = 10, FMPI_TYPE_bool = 10,
FMI_TYPE_END FMI_TYPE_END
} fmpi_type; } fmpi_type_base;
/** /**
* Derived types * Derived types
* *
...@@ -69,10 +70,18 @@ typedef enum fmpi_type { ...@@ -69,10 +70,18 @@ typedef enum fmpi_type {
* `array type`. * `array type`.
* - Loosely based on the definition of derived types in C17 6.2.5 * - Loosely based on the definition of derived types in C17 6.2.5
*/ */
typedef enum fmpi_derived_type { typedef enum fmpi_type_derived {
FMPI_TYPE_NONE, //!< Arithmetic type FMPI_TYPE_NONE, //!< Arithmetic type
FMPI_TYPE_ARRAY //!< Array type FMPI_TYPE_ARRAY //!< Array type
} fmpi_derived_type; } fmpi_type_derived;
/*==============================================================================
STRUCT
==============================================================================*/
typedef struct fmpi_type {
enum fmpi_type_base base;
enum fmpi_type_derived derived;
size_t size;
} fmpi_type;
/*============================================================================== /*==============================================================================
DEFINE DEFINE
==============================================================================*/ ==============================================================================*/
......
...@@ -43,8 +43,11 @@ struct fmpi_data fmpi_data_##D##d_in_##T( \ ...@@ -43,8 +43,11 @@ struct fmpi_data fmpi_data_##D##d_in_##T( \
assert(data != NULL); \ assert(data != NULL); \
const size_t cnt = (x * y * z); \ const size_t cnt = (x * y * z); \
return (struct fmpi_data){ \ return (struct fmpi_data){ \
.type = FMPI_TYPE_##T, \ .type = { \
.type_size = sizeof(T), \ .base = FMPI_TYPE_##T, \
.derived = FMPI_TYPE_ARRAY, \
.size = sizeof(T) \
}, \
.cnt = cnt, \ .cnt = cnt, \
.size = cnt * sizeof(T), \ .size = cnt * sizeof(T), \
.dim_len = {x, y, z}, \ .dim_len = {x, y, z}, \
...@@ -61,8 +64,11 @@ struct fmpi_data fmpi_data_##D##d_in_new_##T( \ ...@@ -61,8 +64,11 @@ struct fmpi_data fmpi_data_##D##d_in_new_##T( \
assert(data != NULL); \ assert(data != NULL); \
const size_t cnt = (x * y * z); \ const size_t cnt = (x * y * z); \
return (struct fmpi_data){ \ return (struct fmpi_data){ \
.type = FMPI_TYPE_##T, \ .type = { \
.type_size = sizeof(T), \ .base = FMPI_TYPE_##T, \
.derived = FMPI_TYPE_ARRAY, \
.size = sizeof(T) \
}, \
.cnt = cnt, \ .cnt = cnt, \
.size = cnt * sizeof(T), \ .size = cnt * sizeof(T), \
.dim_len = {x, y, z}, \ .dim_len = {x, y, z}, \
...@@ -79,8 +85,11 @@ struct fmpi_data fmpi_data_##D##d_out_##T( \ ...@@ -79,8 +85,11 @@ struct fmpi_data fmpi_data_##D##d_out_##T( \
assert(data != NULL); \ assert(data != NULL); \
const size_t cnt = (x * y * z); \ const size_t cnt = (x * y * z); \
return (struct fmpi_data){ \ return (struct fmpi_data){ \
.type = FMPI_TYPE_##T, \ .type = { \
.type_size = sizeof(T), \ .base = FMPI_TYPE_##T, \
.derived = FMPI_TYPE_ARRAY, \
.size = sizeof(T) \
}, \
.cnt = cnt, \ .cnt = cnt, \
.size = cnt * sizeof(T), \ .size = cnt * sizeof(T), \
.dim_len = {x, y, z}, \ .dim_len = {x, y, z}, \
......
...@@ -89,10 +89,9 @@ static struct fmpi_data * fmpi_partition_block_1d( ...@@ -89,10 +89,9 @@ static struct fmpi_data * fmpi_partition_block_1d(
for(size_t i = 0; i < proc_cnt; i++) { for(size_t i = 0; i < proc_cnt; i++) {
const size_t cnt = rem != 0 ? cnt_per_proc + 1 : cnt_per_proc; const size_t cnt = rem != 0 ? cnt_per_proc + 1 : cnt_per_proc;
rem = rem != 0 ? rem - 1 : rem; rem = rem != 0 ? rem - 1 : rem;
const size_t size = cnt * data->type_size; const size_t size = cnt * data->type.size;
parts[i] = (struct fmpi_data){ \ parts[i] = (struct fmpi_data){ \
.type = data->type, .type = data->type,
.type_size = data->type_size,
.cnt = cnt, .cnt = cnt,
.size = size, .size = size,
.dim_len = {cnt, 1, 1}, .dim_len = {cnt, 1, 1},
......
...@@ -141,7 +141,7 @@ _Bool fmpi_futhark_check_error( ...@@ -141,7 +141,7 @@ _Bool fmpi_futhark_check_error(
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
void * fmpi_futhark_new_data( void * fmpi_futhark_new_data(
const struct fmpi_futhark_ctx * const ctx, const void * const data, const struct fmpi_futhark_ctx * const ctx, const void * const data,
const enum fmpi_type type, const size_t dim_cnt, const enum fmpi_type_base type, const size_t dim_cnt,
const size_t x, const size_t y, const size_t z const size_t x, const size_t y, const size_t z
){ ){
assert(ctx != NULL); assert(ctx != NULL);
......
...@@ -62,7 +62,7 @@ struct fmpi_task fmpi_task_register( ...@@ -62,7 +62,7 @@ struct fmpi_task fmpi_task_register(
continue; continue;
} }
void * start = fmpi_futhark_new_data( void * start = fmpi_futhark_new_data(
ctx->fut, task.domains[i].parts[rank].start, task.domains[i].data.type, ctx->fut, task.domains[i].parts[rank].start, task.domains[i].data.type.base,
task.domains[i].data.dim_cnt, task.domains[i].data.dim_cnt,
task.domains[i].parts[rank].dim_len[0], task.domains[i].parts[rank].dim_len[0],
task.domains[i].parts[rank].dim_len[1], task.domains[i].parts[rank].dim_len[1],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment