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

Add `fmpi_task_register_{async,async}()`

parent b319f125
No related branches found
No related tags found
No related merge requests found
......@@ -150,12 +150,12 @@ do { \
FMPI_REGISTER_SYNC_TASK()
------------------------------------------------------------------------------*/
#define FMPI_REGISTER_SYNC_TASK(ctx, func, stencil, ...) \
FMPI_TASK_REGISTER(ctx, func, FMPI_TASK_TYPE_SYNC, stencil, __VA_ARGS__)
FMPI_TASK_REGISTER_IMPL(func, sync, ctx, stencil, __VA_ARGS__)
/*------------------------------------------------------------------------------
FMPI_REGISTER_ASYNC_TASK()
------------------------------------------------------------------------------*/
#define FMPI_REGISTER_ASYNC_TASK(ctx, func, stencil, ...) \
FMPI_TASK_REGISTER(ctx, func, FMPI_TASK_TYPE_ASYNC, stencil, __VA_ARGS__)
FMPI_TASK_REGISTER_IMPL(func, async, ctx, stencil, __VA_ARGS__)
/*==============================================================================
GUARD
==============================================================================*/
......
......@@ -109,7 +109,7 @@ typedef struct fmpi_task {
PUBLIC FUNCTION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_task_register()
fmpi_task_register_sync()
------------------------------------------------------------------------------*/
/**
* TODO
......@@ -129,10 +129,16 @@ typedef struct fmpi_task {
* TODO
* }
*/
struct fmpi_task fmpi_task_register(
struct fmpi_task fmpi_task_register_sync(
struct fmpi_ctx * ctx, fmpi_task_func func, const char * name,
enum fmpi_task_type type, struct fmpi_stencil stencil,
const struct fmpi_task_args * args
struct fmpi_stencil stencil, const struct fmpi_task_args * args
);
/*------------------------------------------------------------------------------
fmpi_task_register_async()
------------------------------------------------------------------------------*/
struct fmpi_task fmpi_task_register_async(
struct fmpi_ctx * ctx, fmpi_task_func func, const char * name,
struct fmpi_stencil stencil, const struct fmpi_task_args * args
);
/*------------------------------------------------------------------------------
fmpi_task_run_sync()
......@@ -181,11 +187,6 @@ int fmpi_task_run_async(const struct fmpi_ctx * ctx, const struct fmpi_task * ta
/*==============================================================================
MACRO
==============================================================================*/
/*------------------------------------------------------------------------------
FMPI_TASK_REGISTER()
------------------------------------------------------------------------------*/
#define FMPI_TASK_REGISTER(ctx, func, type, stencil, ...) \
FMPI_TASK_REGISTER_IMPL(ctx, func, type, stencil, __VA_ARGS__)
/*------------------------------------------------------------------------------
FMPI_TASK_FUTHARK()
------------------------------------------------------------------------------*/
......
......@@ -73,19 +73,19 @@ _Pragma("GCC diagnostic warning \"-Wincompatible-pointer-types\"")\
return futhark_entry_##FUNC(ctx, out, FMPI_PRIV_TASK_ARGS_##N(args_in)); \
}
#define FMPI_TASK_REGISTER_IMPL(ctx, FUNC, type, stencil, ...) \
#define FMPI_TASK_REGISTER_IMPL(FUNC, TYPE, ctx, stencil, ...) \
FMPI_PRIV_TASK_CONCAT(FMPI_PRIV_TASK_REGISTER_, CPL_ARG_COUNT(__VA_ARGS__)) \
(FUNC, ctx, type, stencil ,__VA_ARGS__)
(FUNC, TYPE, ctx, stencil ,__VA_ARGS__)
#define FMPI_PRIV_TASK_REGISTER_1(FUNC, ctx, type, stencil, arg_out) \
fmpi_task_register((ctx), FUNC##_0, #FUNC, (type), (stencil), &(struct fmpi_task_args){ \
#define FMPI_PRIV_TASK_REGISTER_1(FUNC, TYPE, ctx, stencil, arg_out) \
fmpi_task_register_##TYPE((ctx), FUNC##_0, #FUNC, (stencil), &(struct fmpi_task_args){ \
.out = (arg_out), \
.out_raw = NULL, \
.cnt = 0 \
})
#define FMPI_PRIV_TASK_REGISTER_N(N, FUNC, ctx, type, stencil, arg_out, ...) \
fmpi_task_register((ctx), FUNC##_##N, #FUNC, (type), (stencil), &(struct fmpi_task_args){ \
#define FMPI_PRIV_TASK_REGISTER_N(N, FUNC, TYPE, ctx, stencil, arg_out, ...) \
fmpi_task_register_##TYPE((ctx), FUNC##_##N, #FUNC, (stencil), &(struct fmpi_task_args){ \
.in = {__VA_ARGS__}, \
.out = (arg_out), \
.out_raw = NULL, \
......
......@@ -40,12 +40,12 @@
PUBLIC FUNCTION DEFINITION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_task_register()
fmpi_task_register_sync()
------------------------------------------------------------------------------*/
struct fmpi_task fmpi_task_register(
struct fmpi_task fmpi_task_register_sync(
struct fmpi_ctx * const ctx, const fmpi_task_func func,
const char * const name, const enum fmpi_task_type type,
const struct fmpi_stencil stencil, const struct fmpi_task_args * const args
const char * const name, const struct fmpi_stencil stencil,
const struct fmpi_task_args * const args
){
assert(ctx != NULL);
assert(ctx->task_cnt < FMPI_TASK_MAX);
......@@ -54,7 +54,7 @@ struct fmpi_task fmpi_task_register(
struct fmpi_task task = {
.func = func,
.name = name,
.type = type,
.type = FMPI_TASK_TYPE_SYNC,
.args = *args,
.stencil = stencil
};
......@@ -65,9 +65,8 @@ struct fmpi_task fmpi_task_register(
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_new_domain() failed!");
continue;
}
void * data = NULL;
if(task.type == FMPI_TASK_TYPE_SYNC) {
data = fmpi_futhark_new_data_sync(
//! @todo Could fmpi_futhark_new_data_async() could be called here?
void * data = fmpi_futhark_new_data_sync(
ctx->fut, task.domains[i].parts[rank].start, task.domains[i].data.type.base,
task.domains[i].data.dim_cnt,
task.domains[i].parts[rank].dim_len[0],
......@@ -79,8 +78,39 @@ struct fmpi_task fmpi_task_register(
"fmpi_futhark_new_data_sync() failed!"
);
}
} else {
data = fmpi_futhark_new_data_async(
task.args.in[i].start = data;
}
ctx->tasks[ctx->task_cnt++] = task;
fmpi_futhark_sync(ctx->fut);
return task;
}
/*------------------------------------------------------------------------------
fmpi_task_register_async()
------------------------------------------------------------------------------*/
struct fmpi_task fmpi_task_register_async(
struct fmpi_ctx * const ctx, const fmpi_task_func func,
const char * const name, const struct fmpi_stencil stencil,
const struct fmpi_task_args * const args
){
assert(ctx != NULL);
assert(ctx->task_cnt < FMPI_TASK_MAX);
assert(name != NULL);
assert(args != NULL);
struct fmpi_task task = {
.func = func,
.name = name,
.type = FMPI_TASK_TYPE_ASYNC,
.args = *args,
.stencil = stencil
};
const size_t rank = (size_t)ctx->mpi->rank;
for(size_t i = 0; i < task.args.cnt; i++) {
task.domains[i] = fmpi_new_domain(ctx, args->in[i]);
if(task.domains[i].parts == NULL) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_new_domain() failed!");
continue;
}
void * data = fmpi_futhark_new_data_async(
ctx->fut, task.domains[i].parts[rank].start, task.domains[i].data.type.base,
task.domains[i].data.dim_cnt,
task.domains[i].parts[rank].dim_len[0],
......@@ -92,13 +122,9 @@ struct fmpi_task fmpi_task_register(
"fmpi_futhark_new_data_async() failed!"
);
}
}
task.args.in[i].start = data;
}
ctx->tasks[ctx->task_cnt++] = task;
if(task.type == FMPI_TASK_TYPE_SYNC) {
fmpi_futhark_sync(ctx->fut);
}
return task;
}
/*------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment