1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 #include <ceed.h> 18 #include <ceed-backend.h> 19 #include <string.h> 20 #include "ceed-ref.h" 21 22 //------------------------------------------------------------------------------ 23 // QFunctionContext Set Data 24 //------------------------------------------------------------------------------ 25 static int CeedQFunctionContextSetData_Ref(CeedQFunctionContext ctx, 26 CeedMemType mtype, 27 CeedCopyMode cmode, CeedScalar *data) { 28 int ierr; 29 CeedQFunctionContext_Ref *impl; 30 ierr = CeedQFunctionContextGetBackendData(ctx, (void *)&impl); 31 CeedChkBackend(ierr); 32 size_t ctxsize; 33 ierr = CeedQFunctionContextGetContextSize(ctx, &ctxsize); CeedChkBackend(ierr); 34 Ceed ceed; 35 ierr = CeedQFunctionContextGetCeed(ctx, &ceed); CeedChkBackend(ierr); 36 37 if (mtype != CEED_MEM_HOST) 38 // LCOV_EXCL_START 39 return CeedError(ceed, CEED_ERROR_BACKEND, "Only MemType = HOST supported"); 40 // LCOV_EXCL_STOP 41 ierr = CeedFree(&impl->data_allocated); CeedChkBackend(ierr); 42 switch (cmode) { 43 case CEED_COPY_VALUES: 44 ierr = CeedMallocArray(1, ctxsize, &impl->data_allocated); CeedChkBackend(ierr); 45 impl->data = impl->data_allocated; 46 memcpy(impl->data, data, ctxsize); 47 break; 48 case CEED_OWN_POINTER: 49 impl->data_allocated = data; 50 impl->data = data; 51 break; 52 case CEED_USE_POINTER: 53 impl->data = data; 54 } 55 return CEED_ERROR_SUCCESS; 56 } 57 58 //------------------------------------------------------------------------------ 59 // QFunctionContext Get Data 60 //------------------------------------------------------------------------------ 61 static int CeedQFunctionContextGetData_Ref(CeedQFunctionContext ctx, 62 CeedMemType mtype, CeedScalar *data) { 63 int ierr; 64 CeedQFunctionContext_Ref *impl; 65 ierr = CeedQFunctionContextGetBackendData(ctx, (void *)&impl); 66 CeedChkBackend(ierr); 67 Ceed ceed; 68 ierr = CeedQFunctionContextGetCeed(ctx, &ceed); CeedChkBackend(ierr); 69 70 if (mtype != CEED_MEM_HOST) 71 // LCOV_EXCL_START 72 return CeedError(ceed, CEED_ERROR_BACKEND, "Can only provide to HOST memory"); 73 // LCOV_EXCL_STOP 74 if (!impl->data) 75 // LCOV_EXCL_START 76 return CeedError(ceed, CEED_ERROR_BACKEND, "No context data set"); 77 // LCOV_EXCL_STOP 78 *(void **)data = impl->data; 79 return CEED_ERROR_SUCCESS; 80 } 81 82 //------------------------------------------------------------------------------ 83 // QFunctionContext Restore Data 84 //------------------------------------------------------------------------------ 85 static int CeedQFunctionContextRestoreData_Ref(CeedQFunctionContext ctx) { 86 return CEED_ERROR_SUCCESS; 87 } 88 89 //------------------------------------------------------------------------------ 90 // QFunctionContext Destroy 91 //------------------------------------------------------------------------------ 92 static int CeedQFunctionContextDestroy_Ref(CeedQFunctionContext ctx) { 93 int ierr; 94 CeedQFunctionContext_Ref *impl; 95 ierr = CeedQFunctionContextGetBackendData(ctx, &impl); CeedChkBackend(ierr); 96 97 ierr = CeedFree(&impl->data_allocated); CeedChkBackend(ierr); 98 ierr = CeedFree(&impl); CeedChkBackend(ierr); 99 return CEED_ERROR_SUCCESS; 100 } 101 102 //------------------------------------------------------------------------------ 103 // QFunctionContext Create 104 //------------------------------------------------------------------------------ 105 int CeedQFunctionContextCreate_Ref(CeedQFunctionContext ctx) { 106 int ierr; 107 CeedQFunctionContext_Ref *impl; 108 Ceed ceed; 109 ierr = CeedQFunctionContextGetCeed(ctx, &ceed); CeedChkBackend(ierr); 110 111 ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "SetData", 112 CeedQFunctionContextSetData_Ref); CeedChkBackend(ierr); 113 ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "GetData", 114 CeedQFunctionContextGetData_Ref); CeedChkBackend(ierr); 115 ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "RestoreData", 116 CeedQFunctionContextRestoreData_Ref); CeedChkBackend(ierr); 117 ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "Destroy", 118 CeedQFunctionContextDestroy_Ref); CeedChkBackend(ierr); 119 ierr = CeedCalloc(1, &impl); CeedChkBackend(ierr); 120 ierr = CeedQFunctionContextSetBackendData(ctx, impl); CeedChkBackend(ierr); 121 return CEED_ERROR_SUCCESS; 122 } 123 //------------------------------------------------------------------------------ 124