1777ff853SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2777ff853SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3777ff853SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details. 4777ff853SJeremy L Thompson // 5777ff853SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software 6777ff853SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral 7777ff853SJeremy L Thompson // element discretizations for exascale applications. For more information and 8777ff853SJeremy L Thompson // source code availability see http://github.com/ceed. 9777ff853SJeremy L Thompson // 10777ff853SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11777ff853SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office 12777ff853SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for 13777ff853SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including 14777ff853SJeremy L Thompson // software, applications, hardware, advanced system engineering and early 15777ff853SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative. 16777ff853SJeremy L Thompson 17ec3da8bcSJed Brown #include <ceed/ceed.h> 18ec3da8bcSJed Brown #include <ceed/backend.h> 193d576824SJeremy L Thompson #include <string.h> 20777ff853SJeremy L Thompson #include "ceed-ref.h" 21777ff853SJeremy L Thompson 22777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 23777ff853SJeremy L Thompson // QFunctionContext Set Data 24777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 25777ff853SJeremy L Thompson static int CeedQFunctionContextSetData_Ref(CeedQFunctionContext ctx, 26*d1d35e2fSjeremylt CeedMemType mem_type, CeedCopyMode copy_mode, CeedScalar *data) { 27777ff853SJeremy L Thompson int ierr; 28777ff853SJeremy L Thompson CeedQFunctionContext_Ref *impl; 29e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextGetBackendData(ctx, (void *)&impl); 30e15f9bd0SJeremy L Thompson CeedChkBackend(ierr); 31*d1d35e2fSjeremylt size_t ctx_size; 32*d1d35e2fSjeremylt ierr = CeedQFunctionContextGetContextSize(ctx, &ctx_size); CeedChkBackend(ierr); 33777ff853SJeremy L Thompson Ceed ceed; 34e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextGetCeed(ctx, &ceed); CeedChkBackend(ierr); 35777ff853SJeremy L Thompson 36*d1d35e2fSjeremylt if (mem_type != CEED_MEM_HOST) 37777ff853SJeremy L Thompson // LCOV_EXCL_START 38e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "Only MemType = HOST supported"); 39777ff853SJeremy L Thompson // LCOV_EXCL_STOP 40e15f9bd0SJeremy L Thompson ierr = CeedFree(&impl->data_allocated); CeedChkBackend(ierr); 41*d1d35e2fSjeremylt switch (copy_mode) { 42777ff853SJeremy L Thompson case CEED_COPY_VALUES: 43*d1d35e2fSjeremylt ierr = CeedMallocArray(1, ctx_size, &impl->data_allocated); 44*d1d35e2fSjeremylt CeedChkBackend(ierr); 45777ff853SJeremy L Thompson impl->data = impl->data_allocated; 46*d1d35e2fSjeremylt memcpy(impl->data, data, ctx_size); 47777ff853SJeremy L Thompson break; 48777ff853SJeremy L Thompson case CEED_OWN_POINTER: 49777ff853SJeremy L Thompson impl->data_allocated = data; 50777ff853SJeremy L Thompson impl->data = data; 51777ff853SJeremy L Thompson break; 52777ff853SJeremy L Thompson case CEED_USE_POINTER: 53777ff853SJeremy L Thompson impl->data = data; 54777ff853SJeremy L Thompson } 55e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 56777ff853SJeremy L Thompson } 57777ff853SJeremy L Thompson 58777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 59777ff853SJeremy L Thompson // QFunctionContext Get Data 60777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 61777ff853SJeremy L Thompson static int CeedQFunctionContextGetData_Ref(CeedQFunctionContext ctx, 62*d1d35e2fSjeremylt CeedMemType mem_type, CeedScalar *data) { 63777ff853SJeremy L Thompson int ierr; 64777ff853SJeremy L Thompson CeedQFunctionContext_Ref *impl; 65e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextGetBackendData(ctx, (void *)&impl); 66e15f9bd0SJeremy L Thompson CeedChkBackend(ierr); 67777ff853SJeremy L Thompson Ceed ceed; 68e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextGetCeed(ctx, &ceed); CeedChkBackend(ierr); 69777ff853SJeremy L Thompson 70*d1d35e2fSjeremylt if (mem_type != CEED_MEM_HOST) 71777ff853SJeremy L Thompson // LCOV_EXCL_START 72e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "Can only provide to HOST memory"); 73777ff853SJeremy L Thompson // LCOV_EXCL_STOP 74777ff853SJeremy L Thompson if (!impl->data) 75777ff853SJeremy L Thompson // LCOV_EXCL_START 76e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "No context data set"); 77777ff853SJeremy L Thompson // LCOV_EXCL_STOP 78777ff853SJeremy L Thompson *(void **)data = impl->data; 79e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 80777ff853SJeremy L Thompson } 81777ff853SJeremy L Thompson 82777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 83777ff853SJeremy L Thompson // QFunctionContext Restore Data 84777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 85777ff853SJeremy L Thompson static int CeedQFunctionContextRestoreData_Ref(CeedQFunctionContext ctx) { 86e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 87777ff853SJeremy L Thompson } 88777ff853SJeremy L Thompson 89777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 90777ff853SJeremy L Thompson // QFunctionContext Destroy 91777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 92777ff853SJeremy L Thompson static int CeedQFunctionContextDestroy_Ref(CeedQFunctionContext ctx) { 93777ff853SJeremy L Thompson int ierr; 94777ff853SJeremy L Thompson CeedQFunctionContext_Ref *impl; 95e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextGetBackendData(ctx, &impl); CeedChkBackend(ierr); 96777ff853SJeremy L Thompson 97e15f9bd0SJeremy L Thompson ierr = CeedFree(&impl->data_allocated); CeedChkBackend(ierr); 98e15f9bd0SJeremy L Thompson ierr = CeedFree(&impl); CeedChkBackend(ierr); 99e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 100777ff853SJeremy L Thompson } 101777ff853SJeremy L Thompson 102777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 103777ff853SJeremy L Thompson // QFunctionContext Create 104777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 105777ff853SJeremy L Thompson int CeedQFunctionContextCreate_Ref(CeedQFunctionContext ctx) { 106777ff853SJeremy L Thompson int ierr; 107777ff853SJeremy L Thompson CeedQFunctionContext_Ref *impl; 108777ff853SJeremy L Thompson Ceed ceed; 109e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextGetCeed(ctx, &ceed); CeedChkBackend(ierr); 110777ff853SJeremy L Thompson 111777ff853SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "SetData", 112e15f9bd0SJeremy L Thompson CeedQFunctionContextSetData_Ref); CeedChkBackend(ierr); 113777ff853SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "GetData", 114e15f9bd0SJeremy L Thompson CeedQFunctionContextGetData_Ref); CeedChkBackend(ierr); 115777ff853SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "RestoreData", 116e15f9bd0SJeremy L Thompson CeedQFunctionContextRestoreData_Ref); CeedChkBackend(ierr); 117777ff853SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "QFunctionContext", ctx, "Destroy", 118e15f9bd0SJeremy L Thompson CeedQFunctionContextDestroy_Ref); CeedChkBackend(ierr); 119e15f9bd0SJeremy L Thompson ierr = CeedCalloc(1, &impl); CeedChkBackend(ierr); 120e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextSetBackendData(ctx, impl); CeedChkBackend(ierr); 121e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 122777ff853SJeremy L Thompson } 123777ff853SJeremy L Thompson //------------------------------------------------------------------------------ 124