Skip to content

Commit

Permalink
jit - count readers for user jit -i/-d
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Oct 22, 2024
1 parent 4753b77 commit aeb3a72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/ceed-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ struct Ceed_private {
Ceed op_fallback_ceed, op_fallback_parent;
const char *op_fallback_resource;
char **jit_source_roots;
CeedInt num_jit_source_roots, max_jit_source_roots;
CeedInt num_jit_source_roots, max_jit_source_roots, num_jit_source_roots_readers;
char **jit_defines;
CeedInt num_jit_defines, max_jit_defines;
CeedInt num_jit_defines, max_jit_defines, num_jit_defines_readers;
int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list *);
int (*SetStream)(Ceed, void *);
int (*GetPreferredMemType)(CeedMemType *);
Expand Down
29 changes: 23 additions & 6 deletions interface/ceed.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,14 @@ int CeedGetOperatorFallbackCeed(Ceed ceed, Ceed *fallback_ceed) {
fallback_ceed->Error = ceed->Error;
ceed->op_fallback_ceed = fallback_ceed;
{
const char **jit_source_dirs;
CeedInt num_jit_source_dirs = 0;
const char **jit_source_roots;
CeedInt num_jit_source_roots = 0;

CeedCall(CeedGetJitSourceRoots(ceed, &num_jit_source_dirs, &jit_source_dirs));
for (CeedInt i = 0; i < num_jit_source_dirs; i++) {
CeedCall(CeedAddJitSourceRoot(fallback_ceed, jit_source_dirs[i]));
CeedCall(CeedGetJitSourceRoots(ceed, &num_jit_source_roots, &jit_source_roots));
for (CeedInt i = 0; i < num_jit_source_roots; i++) {
CeedCall(CeedAddJitSourceRoot(fallback_ceed, jit_source_roots[i]));
}
CeedCall(CeedRestoreJitSourceRoots(ceed, &jit_source_dirs));
CeedCall(CeedRestoreJitSourceRoots(ceed, &jit_source_roots));
}
{
const char **jit_defines;
Expand Down Expand Up @@ -902,6 +902,7 @@ int CeedGetJitSourceRoots(Ceed ceed, CeedInt *num_source_roots, const char ***ji
CeedCall(CeedGetParent(ceed, &ceed_parent));
*num_source_roots = ceed_parent->num_jit_source_roots;
*jit_source_roots = (const char **)ceed_parent->jit_source_roots;
ceed_parent->num_jit_source_roots_readers++;
return CEED_ERROR_SUCCESS;
}

Expand All @@ -916,7 +917,11 @@ int CeedGetJitSourceRoots(Ceed ceed, CeedInt *num_source_roots, const char ***ji
@ref Backend
**/
int CeedRestoreJitSourceRoots(Ceed ceed, const char ***jit_source_roots) {
Ceed ceed_parent;

CeedCall(CeedGetParent(ceed, &ceed_parent));
*jit_source_roots = NULL;
ceed_parent->num_jit_source_roots_readers--;
return CEED_ERROR_SUCCESS;
}

Expand All @@ -939,6 +944,7 @@ int CeedGetJitDefines(Ceed ceed, CeedInt *num_defines, const char ***jit_defines
CeedCall(CeedGetParent(ceed, &ceed_parent));
*num_defines = ceed_parent->num_jit_defines;
*jit_defines = (const char **)ceed_parent->jit_defines;
ceed_parent->num_jit_defines_readers++;
return CEED_ERROR_SUCCESS;
}

Expand All @@ -953,7 +959,11 @@ int CeedGetJitDefines(Ceed ceed, CeedInt *num_defines, const char ***jit_defines
@ref Backend
**/
int CeedRestoreJitDefines(Ceed ceed, const char ***jit_defines) {
Ceed ceed_parent;

CeedCall(CeedGetParent(ceed, &ceed_parent));
*jit_defines = NULL;
ceed_parent->num_jit_defines_readers--;
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -1337,6 +1347,7 @@ int CeedAddJitSourceRoot(Ceed ceed, const char *jit_source_root) {
Ceed ceed_parent;

CeedCall(CeedGetParent(ceed, &ceed_parent));
CeedCheck(!ceed_parent->num_jit_source_roots_readers, ceed, CEED_ERROR_ACCESS, "Cannot add JiT source root, read access has been granted");

CeedInt index = ceed_parent->num_jit_source_roots;
size_t path_length = strlen(jit_source_root);
Expand Down Expand Up @@ -1366,6 +1377,7 @@ int CeedAddJitDefine(Ceed ceed, const char *jit_define) {
Ceed ceed_parent;

CeedCall(CeedGetParent(ceed, &ceed_parent));
CeedCheck(!ceed_parent->num_jit_defines_readers, ceed, CEED_ERROR_ACCESS, "Cannot add JiT define, read access has been granted");

CeedInt index = ceed_parent->num_jit_defines;
size_t define_length = strlen(jit_define);
Expand Down Expand Up @@ -1418,6 +1430,11 @@ int CeedDestroy(Ceed *ceed) {
*ceed = NULL;
return CEED_ERROR_SUCCESS;
}

CeedCheck(!(*ceed)->num_jit_source_roots_readers, *ceed, CEED_ERROR_ACCESS,
"Cannot destroy ceed context, read access for JiT source roots has been granted");
CeedCheck(!(*ceed)->num_jit_defines_readers, *ceed, CEED_ERROR_ACCESS, "Cannot add JiT source root, read access for JiT defines has been granted");

if ((*ceed)->delegate) CeedCall(CeedDestroy(&(*ceed)->delegate));

if ((*ceed)->obj_delegate_count > 0) {
Expand Down

0 comments on commit aeb3a72

Please sign in to comment.