@@ -659,14 +659,24 @@ int CeedGetOperatorFallbackCeed(Ceed ceed, Ceed *fallback_ceed) {
659
659
fallback_ceed -> Error = ceed -> Error ;
660
660
ceed -> op_fallback_ceed = fallback_ceed ;
661
661
{
662
- const char * * jit_source_dirs ;
663
- CeedInt num_jit_source_dirs = 0 ;
662
+ const char * * jit_source_roots ;
663
+ CeedInt num_jit_source_roots = 0 ;
664
664
665
- CeedCall (CeedGetJitSourceRoots (ceed , & num_jit_source_dirs , & jit_source_dirs ));
666
- for (CeedInt i = 0 ; i < num_jit_source_dirs ; i ++ ) {
667
- CeedCall (CeedAddJitSourceRoot (fallback_ceed , jit_source_dirs [i ]));
665
+ CeedCall (CeedGetJitSourceRoots (ceed , & num_jit_source_roots , & jit_source_roots ));
666
+ for (CeedInt i = 0 ; i < num_jit_source_roots ; i ++ ) {
667
+ CeedCall (CeedAddJitSourceRoot (fallback_ceed , jit_source_roots [i ]));
668
668
}
669
- CeedCall (CeedRestoreJitSourceRoots (ceed , & jit_source_dirs ));
669
+ CeedCall (CeedRestoreJitSourceRoots (ceed , & jit_source_roots ));
670
+ }
671
+ {
672
+ const char * * jit_defines ;
673
+ CeedInt num_jit_defines = 0 ;
674
+
675
+ CeedCall (CeedGetJitDefines (ceed , & num_jit_defines , & jit_defines ));
676
+ for (CeedInt i = 0 ; i < num_jit_defines ; i ++ ) {
677
+ CeedCall (CeedAddJitSourceRoot (fallback_ceed , jit_defines [i ]));
678
+ }
679
+ CeedCall (CeedRestoreJitDefines (ceed , & jit_defines ));
670
680
}
671
681
}
672
682
* fallback_ceed = ceed -> op_fallback_ceed ;
@@ -874,7 +884,7 @@ int CeedRestoreWorkVector(Ceed ceed, CeedVector *vec) {
874
884
}
875
885
876
886
/**
877
- @brief Retrieve list ofadditional JiT source roots from `Ceed` context.
887
+ @brief Retrieve list of additional JiT source roots from `Ceed` context.
878
888
879
889
Note: The caller is responsible for restoring `jit_source_roots` with @ref CeedRestoreJitSourceRoots().
880
890
@@ -892,6 +902,7 @@ int CeedGetJitSourceRoots(Ceed ceed, CeedInt *num_source_roots, const char ***ji
892
902
CeedCall (CeedGetParent (ceed , & ceed_parent ));
893
903
* num_source_roots = ceed_parent -> num_jit_source_roots ;
894
904
* jit_source_roots = (const char * * )ceed_parent -> jit_source_roots ;
905
+ ceed_parent -> num_jit_source_roots_readers ++ ;
895
906
return CEED_ERROR_SUCCESS ;
896
907
}
897
908
@@ -906,7 +917,53 @@ int CeedGetJitSourceRoots(Ceed ceed, CeedInt *num_source_roots, const char ***ji
906
917
@ref Backend
907
918
**/
908
919
int CeedRestoreJitSourceRoots (Ceed ceed , const char * * * jit_source_roots ) {
920
+ Ceed ceed_parent ;
921
+
922
+ CeedCall (CeedGetParent (ceed , & ceed_parent ));
909
923
* jit_source_roots = NULL ;
924
+ ceed_parent -> num_jit_source_roots_readers -- ;
925
+ return CEED_ERROR_SUCCESS ;
926
+ }
927
+
928
+ /**
929
+ @brief Retrieve list of additional JiT defines from `Ceed` context.
930
+
931
+ Note: The caller is responsible for restoring `jit_defines` with @ref CeedRestoreJitDefines().
932
+
933
+ @param[in] ceed `Ceed` context
934
+ @param[out] num_jit_defines Number of JiT defines
935
+ @param[out] jit_defines Strings such as `foo=bar`, used as `-Dfoo=bar` in JiT
936
+
937
+ @return An error code: 0 - success, otherwise - failure
938
+
939
+ @ref Backend
940
+ **/
941
+ int CeedGetJitDefines (Ceed ceed , CeedInt * num_defines , const char * * * jit_defines ) {
942
+ Ceed ceed_parent ;
943
+
944
+ CeedCall (CeedGetParent (ceed , & ceed_parent ));
945
+ * num_defines = ceed_parent -> num_jit_defines ;
946
+ * jit_defines = (const char * * )ceed_parent -> jit_defines ;
947
+ ceed_parent -> num_jit_defines_readers ++ ;
948
+ return CEED_ERROR_SUCCESS ;
949
+ }
950
+
951
+ /**
952
+ @brief Restore list of additional JiT defines from with @ref CeedGetJitDefines()
953
+
954
+ @param[in] ceed `Ceed` context
955
+ @param[out] jit_defines String such as `foo=bar`, used as `-Dfoo=bar` in JiT
956
+
957
+ @return An error code: 0 - success, otherwise - failure
958
+
959
+ @ref Backend
960
+ **/
961
+ int CeedRestoreJitDefines (Ceed ceed , const char * * * jit_defines ) {
962
+ Ceed ceed_parent ;
963
+
964
+ CeedCall (CeedGetParent (ceed , & ceed_parent ));
965
+ * jit_defines = NULL ;
966
+ ceed_parent -> num_jit_defines_readers -- ;
910
967
return CEED_ERROR_SUCCESS ;
911
968
}
912
969
@@ -1290,17 +1347,52 @@ int CeedAddJitSourceRoot(Ceed ceed, const char *jit_source_root) {
1290
1347
Ceed ceed_parent ;
1291
1348
1292
1349
CeedCall (CeedGetParent (ceed , & ceed_parent ));
1350
+ CeedCheck (!ceed_parent -> num_jit_source_roots_readers , ceed , CEED_ERROR_ACCESS , "Cannot add JiT source root, read access has not been restored" );
1293
1351
1294
1352
CeedInt index = ceed_parent -> num_jit_source_roots ;
1295
1353
size_t path_length = strlen (jit_source_root );
1296
1354
1297
- CeedCall (CeedRealloc (index + 1 , & ceed_parent -> jit_source_roots ));
1355
+ if (ceed_parent -> num_jit_source_roots == ceed_parent -> max_jit_source_roots ) {
1356
+ if (ceed_parent -> max_jit_source_roots == 0 ) ceed_parent -> max_jit_source_roots = 1 ;
1357
+ ceed_parent -> max_jit_source_roots *= 2 ;
1358
+ CeedCall (CeedRealloc (ceed_parent -> max_jit_source_roots , & ceed_parent -> jit_source_roots ));
1359
+ }
1298
1360
CeedCall (CeedCalloc (path_length + 1 , & ceed_parent -> jit_source_roots [index ]));
1299
1361
memcpy (ceed_parent -> jit_source_roots [index ], jit_source_root , path_length );
1300
1362
ceed_parent -> num_jit_source_roots ++ ;
1301
1363
return CEED_ERROR_SUCCESS ;
1302
1364
}
1303
1365
1366
+ /**
1367
+ @brief Set additional JiT compiler define for `Ceed` context
1368
+
1369
+ @param[in,out] ceed `Ceed` context
1370
+ @param[in] jit_define String such as `foo=bar`, used as `-Dfoo=bar` in JiT
1371
+
1372
+ @return An error code: 0 - success, otherwise - failure
1373
+
1374
+ @ref User
1375
+ **/
1376
+ int CeedAddJitDefine (Ceed ceed , const char * jit_define ) {
1377
+ Ceed ceed_parent ;
1378
+
1379
+ CeedCall (CeedGetParent (ceed , & ceed_parent ));
1380
+ CeedCheck (!ceed_parent -> num_jit_defines_readers , ceed , CEED_ERROR_ACCESS , "Cannot add JiT define, read access has not been restored" );
1381
+
1382
+ CeedInt index = ceed_parent -> num_jit_defines ;
1383
+ size_t define_length = strlen (jit_define );
1384
+
1385
+ if (ceed_parent -> num_jit_defines == ceed_parent -> max_jit_defines ) {
1386
+ if (ceed_parent -> max_jit_defines == 0 ) ceed_parent -> max_jit_defines = 1 ;
1387
+ ceed_parent -> max_jit_defines *= 2 ;
1388
+ CeedCall (CeedRealloc (ceed_parent -> max_jit_defines , & ceed_parent -> jit_defines ));
1389
+ }
1390
+ CeedCall (CeedCalloc (define_length + 1 , & ceed_parent -> jit_defines [index ]));
1391
+ memcpy (ceed_parent -> jit_defines [index ], jit_define , define_length );
1392
+ ceed_parent -> num_jit_defines ++ ;
1393
+ return CEED_ERROR_SUCCESS ;
1394
+ }
1395
+
1304
1396
/**
1305
1397
@brief View a `Ceed`
1306
1398
@@ -1338,6 +1430,11 @@ int CeedDestroy(Ceed *ceed) {
1338
1430
* ceed = NULL ;
1339
1431
return CEED_ERROR_SUCCESS ;
1340
1432
}
1433
+
1434
+ CeedCheck (!(* ceed )-> num_jit_source_roots_readers , * ceed , CEED_ERROR_ACCESS ,
1435
+ "Cannot destroy ceed context, read access for JiT source roots has been granted" );
1436
+ CeedCheck (!(* ceed )-> num_jit_defines_readers , * ceed , CEED_ERROR_ACCESS , "Cannot add JiT source root, read access for JiT defines has been granted" );
1437
+
1341
1438
if ((* ceed )-> delegate ) CeedCall (CeedDestroy (& (* ceed )-> delegate ));
1342
1439
1343
1440
if ((* ceed )-> obj_delegate_count > 0 ) {
@@ -1355,6 +1452,11 @@ int CeedDestroy(Ceed *ceed) {
1355
1452
}
1356
1453
CeedCall (CeedFree (& (* ceed )-> jit_source_roots ));
1357
1454
1455
+ for (CeedInt i = 0 ; i < (* ceed )-> num_jit_defines ; i ++ ) {
1456
+ CeedCall (CeedFree (& (* ceed )-> jit_defines [i ]));
1457
+ }
1458
+ CeedCall (CeedFree (& (* ceed )-> jit_defines ));
1459
+
1358
1460
CeedCall (CeedFree (& (* ceed )-> f_offsets ));
1359
1461
CeedCall (CeedFree (& (* ceed )-> resource ));
1360
1462
CeedCall (CeedDestroy (& (* ceed )-> op_fallback_ceed ));
0 commit comments