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 17fc7cf9a0Sjeremylt #include "ceed-memcheck.h" 18fc7cf9a0Sjeremylt 19f10650afSjeremylt //------------------------------------------------------------------------------ 20f10650afSjeremylt // QFunction Apply 21f10650afSjeremylt //------------------------------------------------------------------------------ 22fc7cf9a0Sjeremylt static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, 23fc7cf9a0Sjeremylt CeedVector *U, CeedVector *V) { 24fc7cf9a0Sjeremylt int ierr; 25fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 26*777ff853SJeremy L Thompson ierr = CeedQFunctionGetData(qf, &impl); CeedChk(ierr); 27fc7cf9a0Sjeremylt 28*777ff853SJeremy L Thompson CeedQFunctionContext ctx; 29fc7cf9a0Sjeremylt ierr = CeedQFunctionGetContext(qf, &ctx); CeedChk(ierr); 30*777ff853SJeremy L Thompson void *ctxData = NULL; 31*777ff853SJeremy L Thompson if (ctx) { 32*777ff853SJeremy L Thompson ierr = CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctxData); 33*777ff853SJeremy L Thompson CeedChk(ierr); 34*777ff853SJeremy L Thompson } 35fc7cf9a0Sjeremylt 36692c2638Sjeremylt CeedQFunctionUser f = NULL; 37d4f68153Sjeremylt ierr = CeedQFunctionGetUserFunction(qf, &f); CeedChk(ierr); 38fc7cf9a0Sjeremylt 39fc7cf9a0Sjeremylt CeedInt nIn, nOut; 40fc7cf9a0Sjeremylt ierr = CeedQFunctionGetNumArgs(qf, &nIn, &nOut); CeedChk(ierr); 41fc7cf9a0Sjeremylt 42fc7cf9a0Sjeremylt for (int i = 0; i<nIn; i++) { 43fc7cf9a0Sjeremylt ierr = CeedVectorGetArrayRead(U[i], CEED_MEM_HOST, &impl->inputs[i]); 44fc7cf9a0Sjeremylt CeedChk(ierr); 45fc7cf9a0Sjeremylt } 46fc7cf9a0Sjeremylt for (int i = 0; i<nOut; i++) { 47fc7cf9a0Sjeremylt ierr = CeedVectorGetArray(V[i], CEED_MEM_HOST, &impl->outputs[i]); 48fc7cf9a0Sjeremylt CeedChk(ierr); 49fc7cf9a0Sjeremylt CeedInt len; 50fc7cf9a0Sjeremylt ierr = CeedVectorGetLength(V[i], &len); CeedChk(ierr); 51fc7cf9a0Sjeremylt VALGRIND_MAKE_MEM_UNDEFINED(impl->outputs[i], len); 52fc7cf9a0Sjeremylt } 53fc7cf9a0Sjeremylt 54*777ff853SJeremy L Thompson ierr = f(ctxData, Q, impl->inputs, impl->outputs); CeedChk(ierr); 55fc7cf9a0Sjeremylt 56fc7cf9a0Sjeremylt for (int i = 0; i<nIn; i++) { 57fc7cf9a0Sjeremylt ierr = CeedVectorRestoreArrayRead(U[i], &impl->inputs[i]); CeedChk(ierr); 58fc7cf9a0Sjeremylt } 59fc7cf9a0Sjeremylt for (int i = 0; i<nOut; i++) { 60fc7cf9a0Sjeremylt ierr = CeedVectorRestoreArray(V[i], &impl->outputs[i]); CeedChk(ierr); 61fc7cf9a0Sjeremylt } 62*777ff853SJeremy L Thompson if (ctx) { 63*777ff853SJeremy L Thompson ierr = CeedQFunctionContextRestoreData(ctx, &ctxData); CeedChk(ierr); 64*777ff853SJeremy L Thompson } 65fc7cf9a0Sjeremylt 66fc7cf9a0Sjeremylt return 0; 67fc7cf9a0Sjeremylt } 68fc7cf9a0Sjeremylt 69f10650afSjeremylt //------------------------------------------------------------------------------ 70f10650afSjeremylt // QFunction Destroy 71f10650afSjeremylt //------------------------------------------------------------------------------ 72fc7cf9a0Sjeremylt static int CeedQFunctionDestroy_Memcheck(CeedQFunction qf) { 73fc7cf9a0Sjeremylt int ierr; 74fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 75fc7cf9a0Sjeremylt ierr = CeedQFunctionGetData(qf, (void *)&impl); CeedChk(ierr); 76fc7cf9a0Sjeremylt 77fc7cf9a0Sjeremylt ierr = CeedFree(&impl->inputs); CeedChk(ierr); 78fc7cf9a0Sjeremylt ierr = CeedFree(&impl->outputs); CeedChk(ierr); 79fc7cf9a0Sjeremylt ierr = CeedFree(&impl); CeedChk(ierr); 80fc7cf9a0Sjeremylt 81fc7cf9a0Sjeremylt return 0; 82fc7cf9a0Sjeremylt } 83fc7cf9a0Sjeremylt 84f10650afSjeremylt //------------------------------------------------------------------------------ 85f10650afSjeremylt // QFunction Create 86f10650afSjeremylt //------------------------------------------------------------------------------ 87fc7cf9a0Sjeremylt int CeedQFunctionCreate_Memcheck(CeedQFunction qf) { 88fc7cf9a0Sjeremylt int ierr; 89fc7cf9a0Sjeremylt Ceed ceed; 90fc7cf9a0Sjeremylt ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChk(ierr); 91fc7cf9a0Sjeremylt 92fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 93fc7cf9a0Sjeremylt ierr = CeedCalloc(1, &impl); CeedChk(ierr); 94fc7cf9a0Sjeremylt ierr = CeedCalloc(16, &impl->inputs); CeedChk(ierr); 95fc7cf9a0Sjeremylt ierr = CeedCalloc(16, &impl->outputs); CeedChk(ierr); 96*777ff853SJeremy L Thompson ierr = CeedQFunctionSetData(qf, impl); CeedChk(ierr); 97fc7cf9a0Sjeremylt 98fc7cf9a0Sjeremylt ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", 99fc7cf9a0Sjeremylt CeedQFunctionApply_Memcheck); CeedChk(ierr); 100fc7cf9a0Sjeremylt ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", 101fc7cf9a0Sjeremylt CeedQFunctionDestroy_Memcheck); CeedChk(ierr); 102fc7cf9a0Sjeremylt 103fc7cf9a0Sjeremylt return 0; 104fc7cf9a0Sjeremylt } 105f10650afSjeremylt //------------------------------------------------------------------------------ 106