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