Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fmpi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
raphael.bach
fmpi
Commits
2bc8471b
Verified
Commit
2bc8471b
authored
3 years ago
by
raphael.bach
Browse files
Options
Downloads
Patches
Plain Diff
Update error handling in `fmpi_futhark` module
parent
ab42b33e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/internal/fmpi_futhark.h
+1
-1
1 addition, 1 deletion
include/internal/fmpi_futhark.h
src/fmpi_futhark.c
+40
-38
40 additions, 38 deletions
src/fmpi_futhark.c
with
41 additions
and
39 deletions
include/internal/fmpi_futhark.h
+
1
−
1
View file @
2bc8471b
...
@@ -124,7 +124,7 @@ int fmpi_futhark_sync(const struct fmpi_futhark_ctx * ctx);
...
@@ -124,7 +124,7 @@ int fmpi_futhark_sync(const struct fmpi_futhark_ctx * ctx);
* - \p{ctx} must be a valid pointer allocated with fmpi_init().
* - \p{ctx} must be a valid pointer allocated with fmpi_init().
* - \p{func} must not be `NULL`.
* - \p{func} must not be `NULL`.
*/
*/
_Bool
fmpi_futhark_check_error
(
const
struct
fmpi_futhark_ctx
*
ctx
,
const
char
*
func
);
int
fmpi_futhark_check_error
(
const
struct
fmpi_futhark_ctx
*
ctx
,
const
char
*
func
);
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
fmpi_futhark_new_data_sync()
fmpi_futhark_new_data_sync()
------------------------------------------------------------------------------*/
------------------------------------------------------------------------------*/
...
...
This diff is collapsed.
Click to expand it.
src/fmpi_futhark.c
+
40
−
38
View file @
2bc8471b
...
@@ -82,14 +82,15 @@ struct fmpi_futhark_ctx * fmpi_futhark_init(
...
@@ -82,14 +82,15 @@ struct fmpi_futhark_ctx * fmpi_futhark_init(
){
){
struct
fmpi_futhark_ctx
*
ctx
=
malloc
(
sizeof
(
*
ctx
));
struct
fmpi_futhark_ctx
*
ctx
=
malloc
(
sizeof
(
*
ctx
));
if
(
ctx
==
NULL
)
{
if
(
ctx
==
NULL
)
{
FMPI_RAISE_ERROR
(
err_handler
,
"F
UTHARK
"
,
"malloc(fmpi_futhark_ctx) failed!"
);
FMPI_RAISE_ERROR
(
err_handler
,
"F
MPI
"
,
"malloc(fmpi_futhark_ctx) failed!"
);
return
NULL
;
return
NULL
;
}
}
ctx
->
err_handler
=
err_handler
;
ctx
->
err_handler
=
err_handler
;
ctx
->
cfg
=
futhark_context_config_new
();
ctx
->
cfg
=
futhark_context_config_new
();
if
(
ctx
->
cfg
==
NULL
)
{
if
(
ctx
->
cfg
==
NULL
)
{
FMPI_RAISE_FUTHARK_ERROR
(
ctx
,
"futhark_context_config_new() failed!"
);
FMPI_RAISE_FUTHARK_ERROR
(
ctx
,
"futhark_context_config_new() failed!"
);
return
ctx
;
free
(
ctx
);
return
NULL
;
}
}
ctx
->
ctx
=
futhark_context_new
(
ctx
->
cfg
);
ctx
->
ctx
=
futhark_context_new
(
ctx
->
cfg
);
// The doc says in case of error futhark_context_free() should be called
// The doc says in case of error futhark_context_free() should be called
...
@@ -100,12 +101,14 @@ struct fmpi_futhark_ctx * fmpi_futhark_init(
...
@@ -100,12 +101,14 @@ struct fmpi_futhark_ctx * fmpi_futhark_init(
if
(
ctx
->
ctx
==
NULL
)
{
if
(
ctx
->
ctx
==
NULL
)
{
FMPI_RAISE_FUTHARK_ERROR
(
ctx
,
"futhark_context_new() failed!"
);
FMPI_RAISE_FUTHARK_ERROR
(
ctx
,
"futhark_context_new() failed!"
);
futhark_context_config_free
(
ctx
->
cfg
);
futhark_context_config_free
(
ctx
->
cfg
);
return
ctx
;
free
(
ctx
);
return
NULL
;
}
}
if
(
fmpi_futhark_check_error
(
ctx
,
"futhark_context_new"
)
==
true
)
{
if
(
fmpi_futhark_check_error
(
ctx
,
"futhark_context_new"
)
!=
FMPI_SUCCESS
)
{
fmpi_futhark_sync
(
ctx
);
if
(
fmpi_futhark_exit
(
&
ctx
)
!=
FMPI_SUCCESS
)
{
futhark_context_free
(
ctx
->
ctx
);
FMPI_RAISE_ERROR
(
err_handler
,
"FMPI"
,
"fmpi_futhark_exit() failed!"
);
futhark_context_config_free
(
ctx
->
cfg
);
}
return
NULL
;
}
}
return
ctx
;
return
ctx
;
}
}
...
@@ -117,14 +120,14 @@ int fmpi_futhark_exit(struct fmpi_futhark_ctx ** const ctx)
...
@@ -117,14 +120,14 @@ int fmpi_futhark_exit(struct fmpi_futhark_ctx ** const ctx)
assert
(
ctx
!=
NULL
);
assert
(
ctx
!=
NULL
);
assert
(
*
ctx
!=
NULL
);
assert
(
*
ctx
!=
NULL
);
int
err_id
=
0
;
const
int
err
=
futhark_context_sync
((
*
ctx
)
->
ctx
);
if
(
futhark_context_sync
((
*
ctx
)
->
ctx
)
!=
0
)
{
err_id
=
-
1
;
}
futhark_context_free
((
*
ctx
)
->
ctx
);
futhark_context_free
((
*
ctx
)
->
ctx
);
futhark_context_config_free
((
*
ctx
)
->
cfg
);
futhark_context_config_free
((
*
ctx
)
->
cfg
);
free
(
*
ctx
);
*
ctx
=
NULL
;
free
(
*
ctx
);
*
ctx
=
NULL
;
return
err_id
;
if
(
err
!=
FUTHARK_SUCCESS
)
{
return
FMPI_ERR_FUTHARK
;
}
return
FMPI_SUCCESS
;
}
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
fmpi_futhark_sync()
fmpi_futhark_sync()
...
@@ -132,17 +135,15 @@ int fmpi_futhark_exit(struct fmpi_futhark_ctx ** const ctx)
...
@@ -132,17 +135,15 @@ int fmpi_futhark_exit(struct fmpi_futhark_ctx ** const ctx)
int
fmpi_futhark_sync
(
const
struct
fmpi_futhark_ctx
*
const
ctx
)
int
fmpi_futhark_sync
(
const
struct
fmpi_futhark_ctx
*
const
ctx
)
{
{
assert
(
ctx
!=
NULL
);
assert
(
ctx
!=
NULL
);
const
int
err
=
futhark_context_sync
(
ctx
->
ctx
);
if
(
futhark_context_sync
(
ctx
->
ctx
)
!=
FUTHARK_SUCCESS
)
{
if
(
err
!=
0
)
{
return
fmpi_futhark_check_error
(
ctx
,
"futhark_context_sync"
);
fmpi_futhark_check_error
(
ctx
,
"futhark_context_sync"
);
return
-
1
;
}
}
return
0
;
return
FMPI_SUCCESS
;
}
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
fmpi_futhark_check_error()
fmpi_futhark_check_error()
------------------------------------------------------------------------------*/
------------------------------------------------------------------------------*/
_Bool
fmpi_futhark_check_error
(
int
fmpi_futhark_check_error
(
const
struct
fmpi_futhark_ctx
*
const
ctx
,
const
char
*
const
func
const
struct
fmpi_futhark_ctx
*
const
ctx
,
const
char
*
const
func
){
){
assert
(
ctx
!=
NULL
);
assert
(
ctx
!=
NULL
);
...
@@ -150,10 +151,10 @@ _Bool fmpi_futhark_check_error(
...
@@ -150,10 +151,10 @@ _Bool fmpi_futhark_check_error(
char
*
err_str
=
futhark_context_get_error
(
ctx
->
ctx
);
char
*
err_str
=
futhark_context_get_error
(
ctx
->
ctx
);
if
(
err_str
!=
NULL
)
{
if
(
err_str
!=
NULL
)
{
FMPI_RAISE_FUTHARK_ERROR
(
ctx
,
"%s() failed! %s"
,
func
,
err_str
);
FMPI_RAISE_FUTHARK_ERROR
(
ctx
,
"%s() failed! %s"
,
func
,
err_str
);
free
(
err_str
);
err_str
=
NULL
;
free
(
err_str
);
return
true
;
return
FMPI_ERR_FUTHARK
;
}
}
return
false
;
return
FMPI_SUCCESS
;
}
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
fmpi_futhark_new_data_sync()
fmpi_futhark_new_data_sync()
...
@@ -169,7 +170,11 @@ void * fmpi_futhark_new_data_sync(
...
@@ -169,7 +170,11 @@ void * fmpi_futhark_new_data_sync(
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
void
*
new_data
=
fmpi_futhark_new_data_func_list
[
idx
](
ctx
,
data
,
x
,
y
,
z
);
void
*
new_data
=
fmpi_futhark_new_data_func_list
[
idx
](
ctx
,
data
,
x
,
y
,
z
);
fmpi_futhark_sync
(
ctx
);
fmpi_futhark_sync
(
ctx
);
fmpi_futhark_check_error
(
ctx
,
"futhark_new_##T##_##D##"
);
//! @todo Construct a proper string with dimension and type
const
int
err
=
fmpi_futhark_check_error
(
ctx
,
"futhark_new_##T##_##D##"
);
if
(
new_data
==
NULL
||
err
!=
FMPI_SUCCESS
)
{
return
NULL
;
}
return
new_data
;
return
new_data
;
}
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
...
@@ -196,10 +201,10 @@ int fmpi_futhark_free_data_sync(
...
@@ -196,10 +201,10 @@ int fmpi_futhark_free_data_sync(
assert
(
ctx
!=
NULL
);
assert
(
ctx
!=
NULL
);
assert
(
data
!=
NULL
);
assert
(
data
!=
NULL
);
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
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_free_data_func_list
[
idx
](
ctx
,
data
);
fmpi_futhark_sync
(
ctx
);
fmpi_futhark_sync
(
ctx
);
fmpi_futhark_check_error
(
ctx
,
"futhark_free_##T##_##D##"
);
//! @todo Construct a proper string with dimension and type
return
err
;
return
fmpi_futhark_check_error
(
ctx
,
"futhark_free_##T##_##D##"
)
;
}
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
fmpi_futhark_free_data_async()
fmpi_futhark_free_data_async()
...
@@ -227,7 +232,7 @@ void * fmpi_futhark_get_data_sync(
...
@@ -227,7 +232,7 @@ void * fmpi_futhark_get_data_sync(
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
fmpi_futhark_get_data_func_list
[
idx
](
ctx
,
in
,
out
);
fmpi_futhark_get_data_func_list
[
idx
](
ctx
,
in
,
out
);
fmpi_futhark_sync
(
ctx
);
fmpi_futhark_sync
(
ctx
);
if
(
fmpi_futhark_check_error
(
ctx
,
"futhark_values_##T##_##D##d"
)
=
=
true
)
{
if
(
fmpi_futhark_check_error
(
ctx
,
"futhark_values_##T##_##D##d"
)
!
=
FMPI_SUCCESS
)
{
return
NULL
;
return
NULL
;
}
}
return
out
;
return
out
;
...
@@ -244,19 +249,18 @@ void * fmpi_futhark_get_data_async(
...
@@ -244,19 +249,18 @@ void * fmpi_futhark_get_data_async(
assert
(
out
!=
NULL
);
assert
(
out
!=
NULL
);
assert
(
dim_cnt
<=
FMPI_DIM_MAX
);
assert
(
dim_cnt
<=
FMPI_DIM_MAX
);
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
const
size_t
idx
=
FMPI_PRIV_FUTHARK_FUNC_IDX
(
dim_cnt
,
type
);
const
int
err
=
fmpi_futhark_get_data_func_list
[
idx
](
ctx
,
in
,
out
);
if
(
fmpi_futhark_get_data_func_list
[
idx
](
ctx
,
in
,
out
)
!=
FMPI_SUCCESS
)
{
if
(
err
!=
FUTHARK_SUCCESS
)
{
return
NULL
;
return
NULL
;
}
}
return
out
;
return
out
;
}
}
#define FMPI_FUTHARK_DEFINITION(D, T) \
#define FMPI_FUTHARK_DEFINITION(D, T) \
_Static_assert((D) > 0 && (D) <= FMPI_DIM_MAX, ""); \
void * fmpi_futhark_new_##D##d_##T( \
void * fmpi_futhark_new_##D##d_##T( \
const struct fmpi_futhark_ctx * const ctx, const void * const data, \
const struct fmpi_futhark_ctx * const ctx, const void * const data, \
const size_t x, const size_t y, const size_t z \
const size_t x, const size_t y, const size_t z \
){ \
){ \
_Static_assert((D) <= FMPI_DIM_MAX, ""); \
assert(ctx != NULL); \
assert(ctx != NULL); \
assert(data != NULL); \
assert(data != NULL); \
struct futhark_##T##_##D##d * new_data = FMPI_FUTHARK_NEW_##D(T, ctx->ctx, data, x, y, z); \
struct futhark_##T##_##D##d * new_data = FMPI_FUTHARK_NEW_##D(T, ctx->ctx, data, x, y, z); \
...
@@ -268,27 +272,25 @@ void * fmpi_futhark_new_##D##d_##T( \
...
@@ -268,27 +272,25 @@ void * fmpi_futhark_new_##D##d_##T( \
int fmpi_futhark_free_##D##d_##T( \
int fmpi_futhark_free_##D##d_##T( \
const struct fmpi_futhark_ctx * const ctx, void * const data \
const struct fmpi_futhark_ctx * const ctx, void * const data \
){ \
){ \
_Static_assert((D) <= FMPI_DIM_MAX, ""); \
assert(ctx != NULL); \
assert(ctx != NULL); \
assert(data != NULL); \
assert(data != NULL); \
const int err = futhark_free_##T##_##D##d(ctx->ctx, data); \
if(futhark_free_##T##_##D##d(ctx->ctx, data) != FUTHARK_SUCCESS) { \
if(err != FUTHARK_SUCCESS) { \
FMPI_RAISE_FUTHARK_ERROR(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)"() failed!"); \
FMPI_RAISE_FUTHARK_ERROR(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)"() failed!"); \
return FMPI_ERR_FUTHARK; \
} \
} \
return
err
; \
return
FMPI_SUCCESS
; \
} \
} \
int fmpi_futhark_values_##D##d_##T( \
int fmpi_futhark_values_##D##d_##T( \
const struct fmpi_futhark_ctx * const ctx, void * const in, void * const out \
const struct fmpi_futhark_ctx * const ctx, void * const in, void * const out \
){ \
){ \
_Static_assert((D) <= FMPI_DIM_MAX, ""); \
assert(ctx != NULL); \
assert(ctx != NULL); \
assert(in != NULL); \
assert(in != NULL); \
assert(out != NULL); \
assert(out != NULL); \
const int err =
futhark_values_##T##_##D##d(ctx->ctx, in, out)
;
\
if(
futhark_values_##T##_##D##d(ctx->ctx, in, out)
!= FUTHARK_SUCCESS) {
\
if(err != FUTHARK_SUCCESS) {
\
FMPI_RAISE_FUTHARK_ERROR(ctx, CPL_STRINGIFY(fmpi_futhark_values_##T##_##D##d)"() failed!");
\
FMPI_RAISE_FUTHARK_ERROR(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)"() failed!")
; \
return FMPI_ERR_FUTHARK
; \
} \
} \
return
err
; \
return
FMPI_SUCCESS
; \
}
}
FMPI_DEFINE_FUNCS_DT
(
FMPI_FUTHARK_DEFINITION
,
1
,
FMPI_FUTHARK_TYPES
)
FMPI_DEFINE_FUNCS_DT
(
FMPI_FUTHARK_DEFINITION
,
1
,
FMPI_FUTHARK_TYPES
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment