Lines Matching +full:- +full:- +full:ceed

1 // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
4 // SPDX-License-Identifier: BSD-2-Clause
6 // This file is part of CEED: http://github.com/ceed
9 #include <ceed-impl.h>
10 #include <ceed.h>
11 #include <ceed/backend.h>
26 int (*init)(const char *resource, Ceed f);
35 /// Implementation of core components of Ceed library
87 Calling @ref CeedRequestWait() on a `NULL` request is a no-op.
91 @return An error code: 0 - success, otherwise - failure
102 /// ----------------------------------------------------------------------------
103 /// Ceed Library Internal Functions
104 /// ----------------------------------------------------------------------------
109 @brief Register a Ceed backend internally.
117 …lues are preferred in case the resource requested by @ref CeedInit() has non-unique best prefix ma…
119 @return An error code: 0 - success, otherwise - failure
123 int CeedRegisterImpl(const char *prefix, int (*init)(const char *, Ceed), unsigned int priority) { in CeedRegisterImpl() argument
129 backends[num_backends].prefix[CEED_MAX_RESOURCE_LEN - 1] = 0; in CeedRegisterImpl()
142 @brief Create a work vector space for a `ceed`
144 @param[in,out] ceed `Ceed` to create work vector space for
146 @return An error code: 0 - success, otherwise - failure
150 static int CeedWorkVectorsCreate(Ceed ceed) { in CeedWorkVectorsCreate() argument
151 CeedCall(CeedCalloc(1, &ceed->work_vectors)); in CeedWorkVectorsCreate()
156 @brief Destroy a work vector space for a `ceed`
158 @param[in,out] ceed `Ceed` to destroy work vector space for
160 @return An error code: 0 - success, otherwise - failure
164 static int CeedWorkVectorsDestroy(Ceed ceed) { in CeedWorkVectorsDestroy() argument
165 if (!ceed->work_vectors) return CEED_ERROR_SUCCESS; in CeedWorkVectorsDestroy()
166 for (CeedSize i = 0; i < ceed->work_vectors->num_vecs; i++) { in CeedWorkVectorsDestroy()
167 …CeedCheck(!ceed->work_vectors->is_in_use[i], ceed, CEED_ERROR_ACCESS, "Work vector %" CeedSize_FMT… in CeedWorkVectorsDestroy()
168 // Note: increase ref_count to prevent Ceed destructor from triggering again in CeedWorkVectorsDestroy()
169 CeedCall(CeedObjectReference((CeedObject)ceed)); in CeedWorkVectorsDestroy()
170 CeedCall(CeedObjectReference((CeedObject)ceed)); in CeedWorkVectorsDestroy()
171 CeedCall(CeedVectorDestroy(&ceed->work_vectors->vecs[i])); in CeedWorkVectorsDestroy()
173 CeedObjectDereference((CeedObject)ceed); in CeedWorkVectorsDestroy()
175 CeedCall(CeedFree(&ceed->work_vectors->is_in_use)); in CeedWorkVectorsDestroy()
176 CeedCall(CeedFree(&ceed->work_vectors->vecs)); in CeedWorkVectorsDestroy()
177 CeedCall(CeedFree(&ceed->work_vectors)); in CeedWorkVectorsDestroy()
182 @brief View a `Ceed` passed as a `CeedObject`
184 @param[in] ceed `Ceed` to view
187 @return An error code: 0 - success, otherwise - failure
191 static int CeedView_Object(CeedObject ceed, FILE *stream) { in CeedView_Object() argument
192 CeedCall(CeedView((Ceed)ceed, stream)); in CeedView_Object()
197 @brief Destroy a `Ceed` passed as a `CeedObject`
199 @param[in,out] ceed Address of `Ceed` context to destroy
201 @return An error code: 0 - success, otherwise - failure
205 static int CeedDestroy_Object(CeedObject *ceed) { in CeedDestroy_Object() argument
206 CeedCall(CeedDestroy((Ceed *)ceed)); in CeedDestroy_Object()
212 /// ----------------------------------------------------------------------------
213 /// Ceed Backend API
214 /// ----------------------------------------------------------------------------
221 @param[in] ceed `Ceed` context
223 @return Boolean value: true - debugging mode enabled
224 false - debugging mode disabled
229 bool CeedDebugFlag(const Ceed ceed) { return ceed->is_debug; } in CeedDebugFlag() argument
235 @return Boolean value: true - debugging mode enabled
236 false - debugging mode disabled
276 @return An error code: 0 - success, otherwise - failure
297 @return An error code: 0 - success, otherwise - failure
318 @return An error code: 0 - success, otherwise - failure
338 @return An error code: 0 - success, otherwise - failure
356 @return An error code: 0 - success, otherwise - failure
376 @return An error code: 0 - success, otherwise - failure
418 @return An error code: 0 - success, otherwise - failure
437 @return An error code: 0 - success, otherwise - failure
456 @return An error code: 0 - success, otherwise - failure
475 @return An error code: 0 - success, otherwise - failure
486 @brief Register a `Ceed` backend
492 …lues are preferred in case the resource requested by @ref CeedInit() has non-unique best prefix ma…
494 @return An error code: 0 - success, otherwise - failure
498 int CeedRegister(const char *prefix, int (*init)(const char *, Ceed), unsigned int priority) { in CeedRegister() argument
507 @param[in] ceed `Ceed` context to get debugging flag
510 @return An error code: 0 - success, otherwise - failure
514 int CeedIsDebug(Ceed ceed, bool *is_debug) { in CeedIsDebug() argument
515 *is_debug = ceed->is_debug; in CeedIsDebug()
524 @param[in] ceed `Ceed` context to get resource name of
529 @return An error code: 0 - success, otherwise - failure
533 int CeedGetResourceRoot(Ceed ceed, const char *resource, const char *delineator, char **resource_ro… in CeedGetResourceRoot() argument
535 …size_t resource_root_len = device_spec ? (size_t)(device_spec - resource) + 1 : strlen(resource) +… in CeedGetResourceRoot()
538 memcpy(*resource_root, resource, resource_root_len - 1); in CeedGetResourceRoot()
543 @brief Retrieve a parent `Ceed` context
545 @param[in] ceed `Ceed` context to retrieve parent of
548 @return An error code: 0 - success, otherwise - failure
552 int CeedGetParent(Ceed ceed, Ceed *parent) { in CeedGetParent() argument
553 if (ceed->parent) { in CeedGetParent()
554 CeedCall(CeedGetParent(ceed->parent, parent)); in CeedGetParent()
558 CeedCall(CeedReferenceCopy(ceed, parent)); in CeedGetParent()
563 @brief Retrieve a delegate `Ceed` context
565 @param[in] ceed `Ceed` context to retrieve delegate of
568 @return An error code: 0 - success, otherwise - failure
572 int CeedGetDelegate(Ceed ceed, Ceed *delegate) { in CeedGetDelegate() argument
574 if (ceed->delegate) CeedCall(CeedReferenceCopy(ceed->delegate, delegate)); in CeedGetDelegate()
579 @brief Set a delegate `Ceed` context
581 This function allows a `Ceed` context to set a delegate `Ceed` context.
582 All backend implementations default to the delegate `Ceed` context, unless overridden.
584 @param[in] ceed `Ceed` context to set delegate of
587 @return An error code: 0 - success, otherwise - failure
591 int CeedSetDelegate(Ceed ceed, Ceed delegate) { in CeedSetDelegate() argument
592 CeedCall(CeedReferenceCopy(delegate, &ceed->delegate)); in CeedSetDelegate()
593 delegate->parent = ceed; in CeedSetDelegate()
598 @brief Retrieve a delegate `Ceed` context for a specific object type
600 @param[in] ceed `Ceed` context to retrieve delegate of
604 @return An error code: 0 - success, otherwise - failure
608 int CeedGetObjectDelegate(Ceed ceed, Ceed *delegate, const char *obj_name) { in CeedGetObjectDelegate() argument
610 for (CeedInt i = 0; i < ceed->obj_delegate_count; i++) { in CeedGetObjectDelegate()
611 if (!strcmp(obj_name, ceed->obj_delegates->obj_name)) { in CeedGetObjectDelegate()
613 CeedCall(CeedReferenceCopy(ceed->obj_delegates->delegate, delegate)); in CeedGetObjectDelegate()
619 CeedCall(CeedGetDelegate(ceed, delegate)); in CeedGetObjectDelegate()
624 @brief Set a delegate `Ceed` context for a specific object type
626 …This function allows a `Ceed` context to set a delegate `Ceed` context for a given type of `Ceed` …
627 All backend implementations default to the delegate `Ceed` context for this object.
628 …For example, `CeedSetObjectDelegate(ceed, delegate, "Basis")` uses delegate implementations for al…
630 @param[in,out] ceed `Ceed` context to set delegate of
631 @param[in] delegate `Ceed` context to use for delegation
634 @return An error code: 0 - success, otherwise - failure
638 int CeedSetObjectDelegate(Ceed ceed, Ceed delegate, const char *obj_name) { in CeedSetObjectDelegate() argument
639 CeedInt count = ceed->obj_delegate_count; in CeedSetObjectDelegate()
643 CeedCall(CeedRealloc(count + 1, &ceed->obj_delegates)); in CeedSetObjectDelegate()
645 CeedCall(CeedCalloc(1, &ceed->obj_delegates)); in CeedSetObjectDelegate()
647 ceed->obj_delegate_count++; in CeedSetObjectDelegate()
650 CeedCall(CeedReferenceCopy(delegate, &ceed->obj_delegates[count].delegate)); in CeedSetObjectDelegate()
651 CeedCall(CeedStringAllocCopy(obj_name, &ceed->obj_delegates[count].obj_name)); in CeedSetObjectDelegate()
654 delegate->parent = ceed; in CeedSetObjectDelegate()
659 @brief Get the fallback `Ceed` for `CeedOperator`
661 @param[in] ceed `Ceed` context
662 @param[out] fallback_ceed Variable to store fallback `Ceed`
664 @return An error code: 0 - success, otherwise - failure
668 int CeedGetOperatorFallbackCeed(Ceed ceed, Ceed *fallback_ceed) { in CeedGetOperatorFallbackCeed() argument
669 if (ceed->op_fallback_ceed) { in CeedGetOperatorFallbackCeed()
670 CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "---------- Ceed Fallback ----------\n"); in CeedGetOperatorFallbackCeed()
671 …CeedDebug(ceed, "Falling back from Ceed with backend %s at address %p to Ceed with backend %s at a… in CeedGetOperatorFallbackCeed()
672 ceed->op_fallback_ceed->resource, ceed->op_fallback_ceed); in CeedGetOperatorFallbackCeed()
676 if (ceed->op_fallback_ceed) CeedCall(CeedReferenceCopy(ceed->op_fallback_ceed, fallback_ceed)); in CeedGetOperatorFallbackCeed()
685 @param[in,out] ceed `Ceed` context
686 @param[in] fallback_ceed `Ceed` context to create fallback operators
688 @return An error code: 0 - success, otherwise - failure
692 int CeedSetOperatorFallbackCeed(Ceed ceed, Ceed fallback_ceed) { in CeedSetOperatorFallbackCeed() argument
693 CeedCall(CeedReferenceCopy(fallback_ceed, &ceed->op_fallback_ceed)); in CeedSetOperatorFallbackCeed()
694 fallback_ceed->parent = ceed; in CeedSetOperatorFallbackCeed()
699 @brief Flag `Ceed` context as deterministic
701 @param[in] ceed `Ceed` to flag as deterministic
704 @return An error code: 0 - success, otherwise - failure
708 int CeedSetDeterministic(Ceed ceed, bool is_deterministic) { in CeedSetDeterministic() argument
709 ceed->is_deterministic = is_deterministic; in CeedSetDeterministic()
716 This function is used for a backend to set the function associated with the Ceed objects.
717 …n(ceed, "Ceed", ceed, "VectorCreate", BackendVectorCreate)` sets the backend implementation of @re…
718 Note, the prefix 'Ceed' is not required for the object type ("Basis" vs "CeedBasis").
720 @param[in] ceed `Ceed` context for error handling
721 @param[in] type Type of Ceed object to set function for
722 @param[out] object Ceed object to set function for
726 @return An error code: 0 - success, otherwise - failure
730 int CeedSetBackendFunctionImpl(Ceed ceed, const char *type, void *object, const char *func_name, vo… in CeedSetBackendFunctionImpl() argument
734 if (strcmp(type, "Ceed")) strncat(lookup_name, "Ceed", CEED_MAX_RESOURCE_LEN); in CeedSetBackendFunctionImpl()
739 for (CeedInt i = 0; ceed->f_offsets[i].func_name; i++) { in CeedSetBackendFunctionImpl()
740 if (!strcmp(ceed->f_offsets[i].func_name, lookup_name)) { in CeedSetBackendFunctionImpl()
741 size_t offset = ceed->f_offsets[i].offset; in CeedSetBackendFunctionImpl()
750 …return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Requested function '%s' was not found for CEED obj… in CeedSetBackendFunctionImpl()
755 @brief Retrieve backend data for a `Ceed` context
757 @param[in] ceed `Ceed` context to retrieve data of
760 @return An error code: 0 - success, otherwise - failure
764 int CeedGetData(Ceed ceed, void *data) { in CeedGetData() argument
765 *(void **)data = ceed->data; in CeedGetData()
770 @brief Set backend data for a `Ceed` context
772 @param[in,out] ceed `Ceed` context to set data of
775 @return An error code: 0 - success, otherwise - failure
779 int CeedSetData(Ceed ceed, void *data) { in CeedSetData() argument
780 ceed->data = data; in CeedSetData()
785 @brief Increment the reference counter for a `Ceed` context
787 @param[in,out] ceed `Ceed` context to increment the reference counter
789 @return An error code: 0 - success, otherwise - failure
793 int CeedReference(Ceed ceed) { in CeedReference() argument
794 CeedCall(CeedObjectReference((CeedObject)ceed)); in CeedReference()
799 …@brief Computes the current memory usage of the work vectors in a `Ceed` context and prints to deb…
801 @param[in] ceed `Ceed` context
804 @return An error code: 0 - success, otherwise - failure
808 int CeedGetWorkVectorMemoryUsage(Ceed ceed, CeedScalar *usage_mb) { in CeedGetWorkVectorMemoryUsage() argument
809 if (!ceed->VectorCreate) { in CeedGetWorkVectorMemoryUsage()
810 Ceed delegate; in CeedGetWorkVectorMemoryUsage()
812 CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Vector")); in CeedGetWorkVectorMemoryUsage()
813 CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement VectorCreate"); in CeedGetWorkVectorMemoryUsage()
819 if (ceed->work_vectors) { in CeedGetWorkVectorMemoryUsage()
820 for (CeedInt i = 0; i < ceed->work_vectors->num_vecs; i++) { in CeedGetWorkVectorMemoryUsage()
822 CeedCall(CeedVectorGetLength(ceed->work_vectors->vecs[i], &vec_len)); in CeedGetWorkVectorMemoryUsage()
825 *usage_mb *= sizeof(CeedScalar) * 1e-6; in CeedGetWorkVectorMemoryUsage()
826 …CeedDebug(ceed, "Resource {%s}: Work vectors memory usage: %" CeedInt_FMT " vectors, %g MB\n", cee… in CeedGetWorkVectorMemoryUsage()
833 @brief Clear inactive work vectors in a `Ceed` context below a minimum length.
835 @param[in,out] ceed `Ceed` context
838 @return An error code: 0 - success, otherwise - failure
842 int CeedClearWorkVectors(Ceed ceed, CeedSize min_len) { in CeedClearWorkVectors() argument
843 if (!ceed->VectorCreate) { in CeedClearWorkVectors()
844 Ceed delegate; in CeedClearWorkVectors()
846 CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Vector")); in CeedClearWorkVectors()
847 CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement VectorCreate"); in CeedClearWorkVectors()
852 if (!ceed->work_vectors) return CEED_ERROR_SUCCESS; in CeedClearWorkVectors()
853 for (CeedInt i = 0; i < ceed->work_vectors->num_vecs; i++) { in CeedClearWorkVectors()
854 if (ceed->work_vectors->is_in_use[i]) continue; in CeedClearWorkVectors()
856 CeedCall(CeedVectorGetLength(ceed->work_vectors->vecs[i], &vec_len)); in CeedClearWorkVectors()
858 // Note: increase ref_count to prevent Ceed destructor from triggering in CeedClearWorkVectors()
859 CeedCall(CeedObjectReference((CeedObject)ceed)); in CeedClearWorkVectors()
860 CeedCall(CeedObjectReference((CeedObject)ceed)); in CeedClearWorkVectors()
861 CeedCall(CeedVectorDestroy(&ceed->work_vectors->vecs[i])); in CeedClearWorkVectors()
863 CeedObjectDereference((CeedObject)ceed); in CeedClearWorkVectors()
864 ceed->work_vectors->num_vecs--; in CeedClearWorkVectors()
865 if (ceed->work_vectors->num_vecs > 0) { in CeedClearWorkVectors()
866ceed->work_vectors->vecs[i] = ceed->work_vectors->vecs[ceed->work_… in CeedClearWorkVectors()
867ceed->work_vectors->is_in_use[i] = ceed->work_vectors->is_in_use[ceed->… in CeedClearWorkVectors()
868 ceed->work_vectors->is_in_use[ceed->work_vectors->num_vecs] = false; in CeedClearWorkVectors()
869 i--; in CeedClearWorkVectors()
877 @brief Get a `CeedVector` for scratch work from a `Ceed` context.
881 @param[in] ceed `Ceed` context
885 @return An error code: 0 - success, otherwise - failure
889 int CeedGetWorkVector(Ceed ceed, CeedSize len, CeedVector *vec) { in CeedGetWorkVector() argument
893 if (!ceed->VectorCreate) { in CeedGetWorkVector()
894 Ceed delegate; in CeedGetWorkVector()
896 CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Vector")); in CeedGetWorkVector()
897 CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement VectorCreate"); in CeedGetWorkVector()
903 if (!ceed->work_vectors) CeedCall(CeedWorkVectorsCreate(ceed)); in CeedGetWorkVector()
906 for (i = 0; i < ceed->work_vectors->num_vecs; i++) { in CeedGetWorkVector()
907 if (!ceed->work_vectors->is_in_use[i]) { in CeedGetWorkVector()
910 CeedCall(CeedVectorGetLength(ceed->work_vectors->vecs[i], &work_len)); in CeedGetWorkVector()
915 if (i == ceed->work_vectors->num_vecs) { in CeedGetWorkVector()
916 if (ceed->work_vectors->max_vecs == 0) { in CeedGetWorkVector()
917 ceed->work_vectors->max_vecs = 1; in CeedGetWorkVector()
918 CeedCall(CeedCalloc(ceed->work_vectors->max_vecs, &ceed->work_vectors->vecs)); in CeedGetWorkVector()
919 CeedCall(CeedCalloc(ceed->work_vectors->max_vecs, &ceed->work_vectors->is_in_use)); in CeedGetWorkVector()
920 } else if (ceed->work_vectors->max_vecs == i) { in CeedGetWorkVector()
921 ceed->work_vectors->max_vecs *= 2; in CeedGetWorkVector()
922 CeedCall(CeedRealloc(ceed->work_vectors->max_vecs, &ceed->work_vectors->vecs)); in CeedGetWorkVector()
923 CeedCall(CeedRealloc(ceed->work_vectors->max_vecs, &ceed->work_vectors->is_in_use)); in CeedGetWorkVector()
925 ceed->work_vectors->num_vecs++; in CeedGetWorkVector()
926 CeedCallBackend(CeedVectorCreate(ceed, len, &ceed->work_vectors->vecs[i])); in CeedGetWorkVector()
927 // Note: ref_count manipulation to prevent a ref-loop in CeedGetWorkVector()
928 CeedObjectDereference((CeedObject)ceed); in CeedGetWorkVector()
929 if (ceed->is_debug) CeedGetWorkVectorMemoryUsage(ceed, &usage_mb); in CeedGetWorkVector()
932 ceed->work_vectors->is_in_use[i] = true; in CeedGetWorkVector()
934 CeedCall(CeedVectorReferenceCopy(ceed->work_vectors->vecs[i], vec)); in CeedGetWorkVector()
936 CeedCall(CeedObjectReference((CeedObject)ceed)); in CeedGetWorkVector()
941 @brief Restore a `CeedVector` for scratch work from a `Ceed` context from @ref CeedGetWorkVector()
943 @param[in] ceed `Ceed` context
946 @return An error code: 0 - success, otherwise - failure
950 int CeedRestoreWorkVector(Ceed ceed, CeedVector *vec) { in CeedRestoreWorkVector() argument
951 if (!ceed->VectorCreate) { in CeedRestoreWorkVector()
952 Ceed delegate; in CeedRestoreWorkVector()
954 CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Vector")); in CeedRestoreWorkVector()
955 CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement VectorCreate"); in CeedRestoreWorkVector()
961 for (CeedInt i = 0; i < ceed->work_vectors->num_vecs; i++) { in CeedRestoreWorkVector()
962 if (*vec == ceed->work_vectors->vecs[i]) { in CeedRestoreWorkVector()
963 …CeedCheck(ceed->work_vectors->is_in_use[i], ceed, CEED_ERROR_ACCESS, "Work vector %" CeedSize_FMT … in CeedRestoreWorkVector()
965 ceed->work_vectors->is_in_use[i] = false; in CeedRestoreWorkVector()
966 // Note: reduce ref_count again to prevent a ref-loop in CeedRestoreWorkVector()
967 CeedObjectDereference((CeedObject)ceed); in CeedRestoreWorkVector()
972 return CeedError(ceed, CEED_ERROR_MAJOR, "vec was not checked out via CeedGetWorkVector()"); in CeedRestoreWorkVector()
977 @brief Retrieve list of additional JiT source roots from `Ceed` context.
981 @param[in] ceed `Ceed` context
985 @return An error code: 0 - success, otherwise - failure
989 int CeedGetJitSourceRoots(Ceed ceed, CeedInt *num_source_roots, const char ***jit_source_roots) { in CeedGetJitSourceRoots() argument
990 Ceed ceed_parent; in CeedGetJitSourceRoots()
992 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedGetJitSourceRoots()
993 *num_source_roots = ceed_parent->num_jit_source_roots; in CeedGetJitSourceRoots()
994 *jit_source_roots = (const char **)ceed_parent->jit_source_roots; in CeedGetJitSourceRoots()
995 ceed_parent->num_jit_source_roots_readers++; in CeedGetJitSourceRoots()
1001 @brief Retrieve list of additional Rust source roots from `Ceed` context.
1005 @param[in] ceed `Ceed` context
1009 @return An error code: 0 - success, otherwise - failure
1013 int CeedGetRustSourceRoots(Ceed ceed, CeedInt *num_source_roots, const char ***rust_source_roots) { in CeedGetRustSourceRoots() argument
1014 Ceed ceed_parent; in CeedGetRustSourceRoots()
1016 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedGetRustSourceRoots()
1017 *num_source_roots = ceed_parent->num_rust_source_roots; in CeedGetRustSourceRoots()
1018 *rust_source_roots = (const char **)ceed_parent->rust_source_roots; in CeedGetRustSourceRoots()
1019 ceed_parent->num_rust_source_roots_readers++; in CeedGetRustSourceRoots()
1027 @param[in] ceed `Ceed` context
1030 @return An error code: 0 - success, otherwise - failure
1034 int CeedRestoreJitSourceRoots(Ceed ceed, const char ***jit_source_roots) { in CeedRestoreJitSourceRoots() argument
1035 Ceed ceed_parent; in CeedRestoreJitSourceRoots()
1037 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedRestoreJitSourceRoots()
1039 ceed_parent->num_jit_source_roots_readers--; in CeedRestoreJitSourceRoots()
1047 @param[in] ceed `Ceed` context
1050 @return An error code: 0 - success, otherwise - failure
1054 int CeedRestoreRustSourceRoots(Ceed ceed, const char ***rust_source_roots) { in CeedRestoreRustSourceRoots() argument
1055 Ceed ceed_parent; in CeedRestoreRustSourceRoots()
1057 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedRestoreRustSourceRoots()
1059 ceed_parent->num_rust_source_roots_readers--; in CeedRestoreRustSourceRoots()
1065 @brief Retrieve list of additional JiT defines from `Ceed` context.
1069 @param[in] ceed `Ceed` context
1071 @param[out] jit_defines Strings such as `foo=bar`, used as `-Dfoo=bar` in JiT
1073 @return An error code: 0 - success, otherwise - failure
1077 int CeedGetJitDefines(Ceed ceed, CeedInt *num_jit_defines, const char ***jit_defines) { in CeedGetJitDefines() argument
1078 Ceed ceed_parent; in CeedGetJitDefines()
1080 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedGetJitDefines()
1081 *num_jit_defines = ceed_parent->num_jit_defines; in CeedGetJitDefines()
1082 *jit_defines = (const char **)ceed_parent->jit_defines; in CeedGetJitDefines()
1083 ceed_parent->num_jit_defines_readers++; in CeedGetJitDefines()
1091 @param[in] ceed `Ceed` context
1092 @param[out] jit_defines String such as `foo=bar`, used as `-Dfoo=bar` in JiT
1094 @return An error code: 0 - success, otherwise - failure
1098 int CeedRestoreJitDefines(Ceed ceed, const char ***jit_defines) { in CeedRestoreJitDefines() argument
1099 Ceed ceed_parent; in CeedRestoreJitDefines()
1101 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedRestoreJitDefines()
1103 ceed_parent->num_jit_defines_readers--; in CeedRestoreJitDefines()
1110 /// ----------------------------------------------------------------------------
1111 /// Ceed Public API
1112 /// ----------------------------------------------------------------------------
1117 @brief Get the list of available resource names for `Ceed` contexts
1125 @return An error code: 0 - success, otherwise - failure
1158 @brief Initialize a `Ceed` context to use the specified resource.
1163 @param[out] ceed The library context
1165 @return An error code: 0 - success, otherwise - failure
1171 int CeedInit(const char *resource, Ceed *ceed) { in CeedInit() argument
1223 for (size_t k = 1, last_diag = j - 1; k <= min_len; k++) { in CeedInit()
1225 size_t min_1 = (column[k] < column[k - 1]) ? column[k] + 1 : column[k - 1] + 1; in CeedInit()
1226 size_t min_2 = last_diag + (resource[k - 1] == prefix[j - 1] ? 0 : 1); in CeedInit()
1248 // Setup Ceed in CeedInit()
1249 CeedCall(CeedCalloc(1, ceed)); in CeedInit()
1250 CeedCall(CeedObjectCreate(NULL, CeedView_Object, CeedDestroy_Object, &(*ceed)->obj)); in CeedInit()
1251 CeedCall(CeedCalloc(1, &(*ceed)->jit_source_roots)); in CeedInit()
1252 CeedCall(CeedCalloc(1, &(*ceed)->rust_source_roots)); in CeedInit()
1255 if (!strcmp(ceed_error_handler, "exit")) (*ceed)->Error = CeedErrorExit; in CeedInit()
1256 else if (!strcmp(ceed_error_handler, "store")) (*ceed)->Error = CeedErrorStore; in CeedInit()
1257 else (*ceed)->Error = CeedErrorAbort; in CeedInit()
1258 memcpy((*ceed)->err_msg, "No error message stored", 24); in CeedInit()
1259 (*ceed)->data = NULL; in CeedInit()
1263 CEED_FTABLE_ENTRY(Ceed, Error), in CeedInit()
1264 CEED_FTABLE_ENTRY(Ceed, SetStream), in CeedInit()
1265 CEED_FTABLE_ENTRY(Ceed, GetPreferredMemType), in CeedInit()
1266 CEED_FTABLE_ENTRY(Ceed, Destroy), in CeedInit()
1267 CEED_FTABLE_ENTRY(Ceed, VectorCreate), in CeedInit()
1268 CEED_FTABLE_ENTRY(Ceed, ElemRestrictionCreate), in CeedInit()
1269 CEED_FTABLE_ENTRY(Ceed, ElemRestrictionCreateAtPoints), in CeedInit()
1270 CEED_FTABLE_ENTRY(Ceed, ElemRestrictionCreateBlocked), in CeedInit()
1271 CEED_FTABLE_ENTRY(Ceed, BasisCreateTensorH1), in CeedInit()
1272 CEED_FTABLE_ENTRY(Ceed, BasisCreateH1), in CeedInit()
1273 CEED_FTABLE_ENTRY(Ceed, BasisCreateHdiv), in CeedInit()
1274 CEED_FTABLE_ENTRY(Ceed, BasisCreateHcurl), in CeedInit()
1275 CEED_FTABLE_ENTRY(Ceed, TensorContractCreate), in CeedInit()
1276 CEED_FTABLE_ENTRY(Ceed, QFunctionCreate), in CeedInit()
1277 CEED_FTABLE_ENTRY(Ceed, QFunctionContextCreate), in CeedInit()
1278 CEED_FTABLE_ENTRY(Ceed, OperatorCreate), in CeedInit()
1279 CEED_FTABLE_ENTRY(Ceed, OperatorCreateAtPoints), in CeedInit()
1280 CEED_FTABLE_ENTRY(Ceed, CompositeOperatorCreate), in CeedInit()
1348 {NULL, 0} // End of lookup table - used in SetBackendFunction loop in CeedInit()
1351 CeedCall(CeedCalloc(sizeof(f_offsets), &(*ceed)->f_offsets)); in CeedInit()
1352 memcpy((*ceed)->f_offsets, f_offsets, sizeof(f_offsets)); in CeedInit()
1355 (*ceed)->is_debug = getenv("CEED_DEBUG") || getenv("DEBUG") || getenv("DBG"); in CeedInit()
1358 CeedCall(CeedStringAllocCopy(backends[match_index].prefix, (char **)&(*ceed)->resource)); in CeedInit()
1361 …e: there will always be the default root for every Ceed but all additional paths are added to the … in CeedInit()
1362 CeedCall(CeedAddJitSourceRoot(*ceed, (char *)CeedJitSourceRootDefault)); in CeedInit()
1369 (*ceed)->cuda_compile_with_clang = true; in CeedInit()
1371 (*ceed)->cuda_compile_with_clang = false; in CeedInit()
1375 CeedCall(backends[match_index].init(&resource[match_help], *ceed)); in CeedInit()
1380 @brief Set the GPU stream for a `Ceed` context
1382 @param[in,out] ceed `Ceed` context to set the stream
1385 @return An error code: 0 - success, otherwise - failure
1389 int CeedSetStream(Ceed ceed, void *handle) { in CeedSetStream() argument
1390 CeedCheck(handle, ceed, CEED_ERROR_INCOMPATIBLE, "Stream handle must be non-NULL"); in CeedSetStream()
1391 if (ceed->SetStream) { in CeedSetStream()
1392 CeedCall(ceed->SetStream(ceed, handle)); in CeedSetStream()
1394 Ceed delegate; in CeedSetStream()
1395 CeedCall(CeedGetDelegate(ceed, &delegate)); in CeedSetStream()
1398 else return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support setting stream"); in CeedSetStream()
1405 @brief Copy the pointer to a `Ceed` context.
1409 …*ceed_copy` passed to this function is non-`NULL`, then it is assumed that `*ceed_copy` is a point…
1410 …This `Ceed` context will be destroyed if `*ceed_copy` is the only reference to this `Ceed` context.
1412 @param[in] ceed `Ceed` context to copy reference to
1415 @return An error code: 0 - success, otherwise - failure
1419 int CeedReferenceCopy(Ceed ceed, Ceed *ceed_copy) { in CeedReferenceCopy() argument
1420 CeedCall(CeedReference(ceed)); in CeedReferenceCopy()
1422 *ceed_copy = ceed; in CeedReferenceCopy()
1427 @brief Get the full resource name for a `Ceed` context
1429 @param[in] ceed `Ceed` context to get resource name of
1432 @return An error code: 0 - success, otherwise - failure
1436 int CeedGetResource(Ceed ceed, const char **resource) { in CeedGetResource() argument
1437 *resource = (const char *)ceed->resource; in CeedGetResource()
1442 @brief Return `Ceed` context preferred memory type
1444 @param[in] ceed `Ceed` context to get preferred memory type of
1447 @return An error code: 0 - success, otherwise - failure
1451 int CeedGetPreferredMemType(Ceed ceed, CeedMemType *mem_type) { in CeedGetPreferredMemType() argument
1452 if (ceed->GetPreferredMemType) { in CeedGetPreferredMemType()
1453 CeedCall(ceed->GetPreferredMemType(mem_type)); in CeedGetPreferredMemType()
1455 Ceed delegate; in CeedGetPreferredMemType()
1456 CeedCall(CeedGetDelegate(ceed, &delegate)); in CeedGetPreferredMemType()
1469 @brief Get deterministic status of `Ceed` context
1471 @param[in] ceed `Ceed` context
1474 @return An error code: 0 - success, otherwise - failure
1478 int CeedIsDeterministic(Ceed ceed, bool *is_deterministic) { in CeedIsDeterministic() argument
1479 *is_deterministic = ceed->is_deterministic; in CeedIsDeterministic()
1484 @brief Set additional JiT source root for `Ceed` context
1486 @param[in,out] ceed `Ceed` context
1489 @return An error code: 0 - success, otherwise - failure
1493 int CeedAddJitSourceRoot(Ceed ceed, const char *jit_source_root) { in CeedAddJitSourceRoot() argument
1494 Ceed ceed_parent; in CeedAddJitSourceRoot()
1496 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedAddJitSourceRoot()
1497 …CeedCheck(!ceed_parent->num_jit_source_roots_readers, ceed, CEED_ERROR_ACCESS, "Cannot add JiT sou… in CeedAddJitSourceRoot()
1499 CeedInt index = ceed_parent->num_jit_source_roots; in CeedAddJitSourceRoot()
1502 if (ceed_parent->num_jit_source_roots == ceed_parent->max_jit_source_roots) { in CeedAddJitSourceRoot()
1503 if (ceed_parent->max_jit_source_roots == 0) ceed_parent->max_jit_source_roots = 1; in CeedAddJitSourceRoot()
1504 ceed_parent->max_jit_source_roots *= 2; in CeedAddJitSourceRoot()
1505 CeedCall(CeedRealloc(ceed_parent->max_jit_source_roots, &ceed_parent->jit_source_roots)); in CeedAddJitSourceRoot()
1507 CeedCall(CeedCalloc(path_length + 1, &ceed_parent->jit_source_roots[index])); in CeedAddJitSourceRoot()
1508 memcpy(ceed_parent->jit_source_roots[index], jit_source_root, path_length); in CeedAddJitSourceRoot()
1509 ceed_parent->num_jit_source_roots++; in CeedAddJitSourceRoot()
1515 @brief Set additional Rust source root for `Ceed` context for use in QFunction
1517 @param[in,out] ceed `Ceed` context
1520 @return An error code: 0 - success, otherwise - failure
1524 int CeedAddRustSourceRoot(Ceed ceed, const char *rust_source_root) { in CeedAddRustSourceRoot() argument
1525 Ceed ceed_parent; in CeedAddRustSourceRoot()
1527 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedAddRustSourceRoot()
1528 …CeedCheck(!ceed_parent->num_rust_source_roots_readers, ceed, CEED_ERROR_ACCESS, "Cannot add Rust s… in CeedAddRustSourceRoot()
1530 CeedInt index = ceed_parent->num_rust_source_roots; in CeedAddRustSourceRoot()
1533 if (ceed_parent->num_rust_source_roots == ceed_parent->max_rust_source_roots) { in CeedAddRustSourceRoot()
1534 if (ceed_parent->max_rust_source_roots == 0) ceed_parent->max_rust_source_roots = 1; in CeedAddRustSourceRoot()
1535 ceed_parent->max_rust_source_roots *= 2; in CeedAddRustSourceRoot()
1536 CeedCall(CeedRealloc(ceed_parent->max_rust_source_roots, &ceed_parent->rust_source_roots)); in CeedAddRustSourceRoot()
1538 CeedCall(CeedCalloc(path_length + 1, &ceed_parent->rust_source_roots[index])); in CeedAddRustSourceRoot()
1539 memcpy(ceed_parent->rust_source_roots[index], rust_source_root, path_length); in CeedAddRustSourceRoot()
1540 ceed_parent->num_rust_source_roots++; in CeedAddRustSourceRoot()
1541 ceed_parent->cuda_compile_with_clang = true; in CeedAddRustSourceRoot()
1542 ceed->cuda_compile_with_clang = true; in CeedAddRustSourceRoot()
1548 @brief Set additional JiT compiler define for `Ceed` context
1550 @param[in,out] ceed `Ceed` context
1551 @param[in] jit_define String such as `foo=bar`, used as `-Dfoo=bar` in JiT
1553 @return An error code: 0 - success, otherwise - failure
1557 int CeedAddJitDefine(Ceed ceed, const char *jit_define) { in CeedAddJitDefine() argument
1558 Ceed ceed_parent; in CeedAddJitDefine()
1560 CeedCall(CeedGetParent(ceed, &ceed_parent)); in CeedAddJitDefine()
1561 …CeedCheck(!ceed_parent->num_jit_defines_readers, ceed, CEED_ERROR_ACCESS, "Cannot add JiT define, … in CeedAddJitDefine()
1563 CeedInt index = ceed_parent->num_jit_defines; in CeedAddJitDefine()
1566 if (ceed_parent->num_jit_defines == ceed_parent->max_jit_defines) { in CeedAddJitDefine()
1567 if (ceed_parent->max_jit_defines == 0) ceed_parent->max_jit_defines = 1; in CeedAddJitDefine()
1568 ceed_parent->max_jit_defines *= 2; in CeedAddJitDefine()
1569 CeedCall(CeedRealloc(ceed_parent->max_jit_defines, &ceed_parent->jit_defines)); in CeedAddJitDefine()
1571 CeedCall(CeedCalloc(define_length + 1, &ceed_parent->jit_defines[index])); in CeedAddJitDefine()
1572 memcpy(ceed_parent->jit_defines[index], jit_define, define_length); in CeedAddJitDefine()
1573 ceed_parent->num_jit_defines++; in CeedAddJitDefine()
1581 @param[in] ceed `Ceed` to set the number of view tabs
1584 @return Error code: 0 - success, otherwise - failure
1588 int CeedSetNumViewTabs(Ceed ceed, CeedInt num_tabs) { in CeedSetNumViewTabs() argument
1589 CeedCall(CeedObjectSetNumViewTabs((CeedObject)ceed, num_tabs)); in CeedSetNumViewTabs()
1596 @param[in] ceed `Ceed` to get the number of view tabs
1599 @return Error code: 0 - success, otherwise - failure
1603 int CeedGetNumViewTabs(Ceed ceed, CeedInt *num_tabs) { in CeedGetNumViewTabs() argument
1604 CeedCall(CeedObjectGetNumViewTabs((CeedObject)ceed, num_tabs)); in CeedGetNumViewTabs()
1609 @brief View a `Ceed`
1611 @param[in] ceed `Ceed` to view
1614 @return An error code: 0 - success, otherwise - failure
1618 int CeedView(Ceed ceed, FILE *stream) { in CeedView() argument
1622 CeedCall(CeedGetPreferredMemType(ceed, &mem_type)); in CeedView()
1627 CeedCall(CeedGetNumViewTabs(ceed, &num_tabs)); in CeedView()
1633 "%s Ceed Resource: %s\n" in CeedView()
1635 tabs, tabs, ceed->resource, tabs, CeedMemTypes[mem_type]); in CeedView()
1641 @brief Destroy a `Ceed`
1643 @param[in,out] ceed Address of `Ceed` context to destroy
1645 @return An error code: 0 - success, otherwise - failure
1649 int CeedDestroy(Ceed *ceed) { in CeedDestroy() argument
1650 if (!*ceed || CeedObjectDereference((CeedObject)*ceed) > 0) { in CeedDestroy()
1651 *ceed = NULL; in CeedDestroy()
1655 CeedCheck(!(*ceed)->num_jit_source_roots_readers, *ceed, CEED_ERROR_ACCESS, in CeedDestroy()
1656 "Cannot destroy ceed context, read access for JiT source roots has been granted"); in CeedDestroy()
1657 …CeedCheck(!(*ceed)->num_jit_defines_readers, *ceed, CEED_ERROR_ACCESS, "Cannot add JiT source root… in CeedDestroy()
1659 if ((*ceed)->delegate) CeedCall(CeedDestroy(&(*ceed)->delegate)); in CeedDestroy()
1661 if ((*ceed)->obj_delegate_count > 0) { in CeedDestroy()
1662 for (CeedInt i = 0; i < (*ceed)->obj_delegate_count; i++) { in CeedDestroy()
1663 CeedCall(CeedDestroy(&((*ceed)->obj_delegates[i].delegate))); in CeedDestroy()
1664 CeedCall(CeedFree(&(*ceed)->obj_delegates[i].obj_name)); in CeedDestroy()
1666 CeedCall(CeedFree(&(*ceed)->obj_delegates)); in CeedDestroy()
1669 if ((*ceed)->Destroy) CeedCall((*ceed)->Destroy(*ceed)); in CeedDestroy()
1671 for (CeedInt i = 0; i < (*ceed)->num_jit_source_roots; i++) { in CeedDestroy()
1672 CeedCall(CeedFree(&(*ceed)->jit_source_roots[i])); in CeedDestroy()
1674 CeedCall(CeedFree(&(*ceed)->jit_source_roots)); in CeedDestroy()
1676 for (CeedInt i = 0; i < (*ceed)->num_jit_defines; i++) { in CeedDestroy()
1677 CeedCall(CeedFree(&(*ceed)->jit_defines[i])); in CeedDestroy()
1679 CeedCall(CeedFree(&(*ceed)->jit_defines)); in CeedDestroy()
1681 for (CeedInt i = 0; i < (*ceed)->num_rust_source_roots; i++) { in CeedDestroy()
1682 CeedCall(CeedFree(&(*ceed)->rust_source_roots[i])); in CeedDestroy()
1684 CeedCall(CeedFree(&(*ceed)->rust_source_roots)); in CeedDestroy()
1686 CeedCall(CeedFree(&(*ceed)->f_offsets)); in CeedDestroy()
1687 CeedCall(CeedFree(&(*ceed)->resource)); in CeedDestroy()
1688 CeedCall(CeedDestroy(&(*ceed)->op_fallback_ceed)); in CeedDestroy()
1689 CeedCall(CeedWorkVectorsDestroy(*ceed)); in CeedDestroy()
1690 CeedCall(CeedObjectDestroy_Private(&(*ceed)->obj)); in CeedDestroy()
1691 CeedCall(CeedFree(ceed)); in CeedDestroy()
1696 const char *CeedErrorFormat(Ceed ceed, const char *format, va_list *args) { in CeedErrorFormat() argument
1697 if (ceed->parent) return CeedErrorFormat(ceed->parent, format, args); in CeedErrorFormat()
1698 // Using pointer to va_list for better FFI, but clang-tidy can't verify va_list is initalized in CeedErrorFormat()
1699 vsnprintf(ceed->err_msg, CEED_MAX_RESOURCE_LEN, format, *args); // NOLINT in CeedErrorFormat()
1700 return ceed->err_msg; in CeedErrorFormat()
1707 @return An error code: 0 - success, otherwise - failure
1711 int CeedErrorImpl(Ceed ceed, const char *filename, int lineno, const char *func, int ecode, const c… in CeedErrorImpl() argument
1716 if (ceed) { in CeedErrorImpl()
1717 ret_val = ceed->Error(ceed, filename, lineno, func, ecode, format, &args); in CeedErrorImpl()
1723 ret_val = CeedErrorReturn(ceed, filename, lineno, func, ecode, format, &args); in CeedErrorImpl()
1726 ret_val = CeedErrorAbort(ceed, filename, lineno, func, ecode, format, &args); in CeedErrorImpl()
1739 @return An error code: 0 - success, otherwise - failure
1744 int CeedErrorReturn(Ceed ceed, const char *filename, int line_no, const char *func, int err_code, c… in CeedErrorReturn() argument
1754 @return An error code: 0 - success, otherwise - failure
1759 int CeedErrorStore(Ceed ceed, const char *filename, int line_no, const char *func, int err_code, co… in CeedErrorStore() argument
1760 …if (ceed->parent) return CeedErrorStore(ceed->parent, filename, line_no, func, err_code, format, a… in CeedErrorStore()
1763 …int len = snprintf(ceed->err_msg, CEED_MAX_RESOURCE_LEN, "%s:%d in %s(): ", filename, line_no, fun… in CeedErrorStore()
1764 // Using pointer to va_list for better FFI, but clang-tidy can't verify va_list is initalized in CeedErrorStore()
1765 vsnprintf(ceed->err_msg + len, CEED_MAX_RESOURCE_LEN - len, format, *args); // NOLINT in CeedErrorStore()
1775 @return An error code: 0 - success, otherwise - failure
1780 int CeedErrorAbort(Ceed ceed, const char *filename, int line_no, const char *func, int err_code, co… in CeedErrorAbort() argument
1796 @return An error code: 0 - success, otherwise - failure
1800 int CeedErrorExit(Ceed ceed, const char *filename, int line_no, const char *func, int err_code, con… in CeedErrorExit() argument
1802 // Using pointer to va_list for better FFI, but clang-tidy can't verify va_list is initalized in CeedErrorExit()
1813 …he error handler to @ref CeedErrorReturn(), @ref CeedErrorAbort(), or a user-defined error handler.
1815 @return An error code: 0 - success, otherwise - failure
1819 int CeedSetErrorHandler(Ceed ceed, CeedErrorHandler handler) { in CeedSetErrorHandler() argument
1820 ceed->Error = handler; in CeedSetErrorHandler()
1821 if (ceed->delegate) CeedSetErrorHandler(ceed->delegate, handler); in CeedSetErrorHandler()
1822 …for (CeedInt i = 0; i < ceed->obj_delegate_count; i++) CeedSetErrorHandler(ceed->obj_delegates[i].… in CeedSetErrorHandler()
1831 @param[in] ceed `Ceed` context to retrieve error message
1834 @return An error code: 0 - success, otherwise - failure
1838 int CeedGetErrorMessage(Ceed ceed, const char **err_msg) { in CeedGetErrorMessage() argument
1839 if (ceed->parent) return CeedGetErrorMessage(ceed->parent, err_msg); in CeedGetErrorMessage()
1840 *err_msg = ceed->err_msg; in CeedGetErrorMessage()
1849 @param[in] ceed `Ceed` context to restore error message
1852 @return An error code: 0 - success, otherwise - failure
1856 int CeedResetErrorMessage(Ceed ceed, const char **err_msg) { in CeedResetErrorMessage() argument
1857 if (ceed->parent) return CeedResetErrorMessage(ceed->parent, err_msg); in CeedResetErrorMessage()
1859 memcpy(ceed->err_msg, "No error message stored", 24); in CeedResetErrorMessage()
1867 Non-release versions may contain unstable interfaces.
1876 @return An error code: 0 - success, otherwise - failure
1895 @return An error code: 0 - success, otherwise - failure