1fc7cf9a0Sjeremylt // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2fc7cf9a0Sjeremylt // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3fc7cf9a0Sjeremylt // All Rights reserved. See files LICENSE and NOTICE for details. 4fc7cf9a0Sjeremylt // 5fc7cf9a0Sjeremylt // This file is part of CEED, a collection of benchmarks, miniapps, software 6fc7cf9a0Sjeremylt // libraries and APIs for efficient high-order finite element and spectral 7fc7cf9a0Sjeremylt // element discretizations for exascale applications. For more information and 8fc7cf9a0Sjeremylt // source code availability see http://github.com/ceed. 9fc7cf9a0Sjeremylt // 10fc7cf9a0Sjeremylt // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11fc7cf9a0Sjeremylt // a collaborative effort of two U.S. Department of Energy organizations (Office 12fc7cf9a0Sjeremylt // of Science and the National Nuclear Security Administration) responsible for 13fc7cf9a0Sjeremylt // the planning and preparation of a capable exascale ecosystem, including 14fc7cf9a0Sjeremylt // software, applications, hardware, advanced system engineering and early 15fc7cf9a0Sjeremylt // testbed platforms, in support of the nation's exascale computing imperative. 16fc7cf9a0Sjeremylt 17ec3da8bcSJed Brown #include <ceed/ceed.h> 18ec3da8bcSJed Brown #include <ceed/backend.h> 193d576824SJeremy L Thompson #include <valgrind/memcheck.h> 20fc7cf9a0Sjeremylt #include "ceed-memcheck.h" 21fc7cf9a0Sjeremylt 22f10650afSjeremylt //------------------------------------------------------------------------------ 23f10650afSjeremylt // QFunction Apply 24f10650afSjeremylt //------------------------------------------------------------------------------ 25fc7cf9a0Sjeremylt static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, 26fc7cf9a0Sjeremylt CeedVector *U, CeedVector *V) { 27fc7cf9a0Sjeremylt int ierr; 28fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 29e15f9bd0SJeremy L Thompson ierr = CeedQFunctionGetData(qf, &impl); CeedChkBackend(ierr); 30fc7cf9a0Sjeremylt 31777ff853SJeremy L Thompson CeedQFunctionContext ctx; 32e15f9bd0SJeremy L Thompson ierr = CeedQFunctionGetContext(qf, &ctx); CeedChkBackend(ierr); 33777ff853SJeremy L Thompson void *ctxData = NULL; 34777ff853SJeremy L Thompson if (ctx) { 35777ff853SJeremy L Thompson ierr = CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctxData); 36e15f9bd0SJeremy L Thompson CeedChkBackend(ierr); 37777ff853SJeremy L Thompson } 38fc7cf9a0Sjeremylt 39692c2638Sjeremylt CeedQFunctionUser f = NULL; 40e15f9bd0SJeremy L Thompson ierr = CeedQFunctionGetUserFunction(qf, &f); CeedChkBackend(ierr); 41fc7cf9a0Sjeremylt 42d1d35e2fSjeremylt CeedInt num_in, num_out; 43d1d35e2fSjeremylt ierr = CeedQFunctionGetNumArgs(qf, &num_in, &num_out); CeedChkBackend(ierr); 44fc7cf9a0Sjeremylt 45d1d35e2fSjeremylt for (int i = 0; i<num_in; i++) { 46fc7cf9a0Sjeremylt ierr = CeedVectorGetArrayRead(U[i], CEED_MEM_HOST, &impl->inputs[i]); 47e15f9bd0SJeremy L Thompson CeedChkBackend(ierr); 48fc7cf9a0Sjeremylt } 49d1d35e2fSjeremylt for (int i = 0; i<num_out; i++) { 50fc7cf9a0Sjeremylt ierr = CeedVectorGetArray(V[i], CEED_MEM_HOST, &impl->outputs[i]); 51e15f9bd0SJeremy L Thompson CeedChkBackend(ierr); 52fc7cf9a0Sjeremylt CeedInt len; 53e15f9bd0SJeremy L Thompson ierr = CeedVectorGetLength(V[i], &len); CeedChkBackend(ierr); 54fc7cf9a0Sjeremylt VALGRIND_MAKE_MEM_UNDEFINED(impl->outputs[i], len); 55fc7cf9a0Sjeremylt } 56fc7cf9a0Sjeremylt 57e15f9bd0SJeremy L Thompson ierr = f(ctxData, Q, impl->inputs, impl->outputs); CeedChkBackend(ierr); 58fc7cf9a0Sjeremylt 59d1d35e2fSjeremylt for (int i = 0; i<num_in; i++) { 60e15f9bd0SJeremy L Thompson ierr = CeedVectorRestoreArrayRead(U[i], &impl->inputs[i]); CeedChkBackend(ierr); 61fc7cf9a0Sjeremylt } 62d1d35e2fSjeremylt for (int i = 0; i<num_out; i++) { 63e15f9bd0SJeremy L Thompson ierr = CeedVectorRestoreArray(V[i], &impl->outputs[i]); CeedChkBackend(ierr); 64fc7cf9a0Sjeremylt } 65777ff853SJeremy L Thompson if (ctx) { 66e15f9bd0SJeremy L Thompson ierr = CeedQFunctionContextRestoreData(ctx, &ctxData); CeedChkBackend(ierr); 67777ff853SJeremy L Thompson } 68fc7cf9a0Sjeremylt 69e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 70fc7cf9a0Sjeremylt } 71fc7cf9a0Sjeremylt 72f10650afSjeremylt //------------------------------------------------------------------------------ 73f10650afSjeremylt // QFunction Destroy 74f10650afSjeremylt //------------------------------------------------------------------------------ 75fc7cf9a0Sjeremylt static int CeedQFunctionDestroy_Memcheck(CeedQFunction qf) { 76fc7cf9a0Sjeremylt int ierr; 77fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 78e15f9bd0SJeremy L Thompson ierr = CeedQFunctionGetData(qf, (void *)&impl); CeedChkBackend(ierr); 79fc7cf9a0Sjeremylt 80e15f9bd0SJeremy L Thompson ierr = CeedFree(&impl->inputs); CeedChkBackend(ierr); 81e15f9bd0SJeremy L Thompson ierr = CeedFree(&impl->outputs); CeedChkBackend(ierr); 82e15f9bd0SJeremy L Thompson ierr = CeedFree(&impl); CeedChkBackend(ierr); 83fc7cf9a0Sjeremylt 84e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 85fc7cf9a0Sjeremylt } 86fc7cf9a0Sjeremylt 87f10650afSjeremylt //------------------------------------------------------------------------------ 88f10650afSjeremylt // QFunction Create 89f10650afSjeremylt //------------------------------------------------------------------------------ 90fc7cf9a0Sjeremylt int CeedQFunctionCreate_Memcheck(CeedQFunction qf) { 91fc7cf9a0Sjeremylt int ierr; 92fc7cf9a0Sjeremylt Ceed ceed; 93e15f9bd0SJeremy L Thompson ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr); 94fc7cf9a0Sjeremylt 95fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 96e15f9bd0SJeremy L Thompson ierr = CeedCalloc(1, &impl); CeedChkBackend(ierr); 97*bf4cb664SJeremy L Thompson ierr = CeedCalloc(CEED_FIELD_MAX, &impl->inputs); CeedChkBackend(ierr); 98*bf4cb664SJeremy L Thompson ierr = CeedCalloc(CEED_FIELD_MAX, &impl->outputs); CeedChkBackend(ierr); 99e15f9bd0SJeremy L Thompson ierr = CeedQFunctionSetData(qf, impl); CeedChkBackend(ierr); 100fc7cf9a0Sjeremylt 101fc7cf9a0Sjeremylt ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", 102e15f9bd0SJeremy L Thompson CeedQFunctionApply_Memcheck); CeedChkBackend(ierr); 103fc7cf9a0Sjeremylt ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", 104e15f9bd0SJeremy L Thompson CeedQFunctionDestroy_Memcheck); CeedChkBackend(ierr); 105fc7cf9a0Sjeremylt 106e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 107fc7cf9a0Sjeremylt } 108f10650afSjeremylt //------------------------------------------------------------------------------ 109