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 19fc7cf9a0Sjeremylt static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, 20fc7cf9a0Sjeremylt CeedVector *U, CeedVector *V) { 21fc7cf9a0Sjeremylt int ierr; 22fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 23fc7cf9a0Sjeremylt ierr = CeedQFunctionGetData(qf, (void *)&impl); CeedChk(ierr); 24fc7cf9a0Sjeremylt 25fc7cf9a0Sjeremylt void *ctx; 26fc7cf9a0Sjeremylt ierr = CeedQFunctionGetContext(qf, &ctx); CeedChk(ierr); 27fc7cf9a0Sjeremylt 28*692c2638Sjeremylt CeedQFunctionUser f = NULL; 29fc7cf9a0Sjeremylt ierr = CeedQFunctionGetUserFunction(qf, (int (**)())&f); CeedChk(ierr); 30fc7cf9a0Sjeremylt 31fc7cf9a0Sjeremylt CeedInt nIn, nOut; 32fc7cf9a0Sjeremylt ierr = CeedQFunctionGetNumArgs(qf, &nIn, &nOut); CeedChk(ierr); 33fc7cf9a0Sjeremylt 34fc7cf9a0Sjeremylt for (int i = 0; i<nIn; i++) { 35fc7cf9a0Sjeremylt ierr = CeedVectorGetArrayRead(U[i], CEED_MEM_HOST, &impl->inputs[i]); 36fc7cf9a0Sjeremylt CeedChk(ierr); 37fc7cf9a0Sjeremylt } 38fc7cf9a0Sjeremylt for (int i = 0; i<nOut; i++) { 39fc7cf9a0Sjeremylt ierr = CeedVectorGetArray(V[i], CEED_MEM_HOST, &impl->outputs[i]); 40fc7cf9a0Sjeremylt CeedChk(ierr); 41fc7cf9a0Sjeremylt CeedInt len; 42fc7cf9a0Sjeremylt ierr = CeedVectorGetLength(V[i], &len); CeedChk(ierr); 43fc7cf9a0Sjeremylt VALGRIND_MAKE_MEM_UNDEFINED(impl->outputs[i], len); 44fc7cf9a0Sjeremylt } 45fc7cf9a0Sjeremylt 46fc7cf9a0Sjeremylt ierr = f(ctx, Q, impl->inputs, impl->outputs); CeedChk(ierr); 47fc7cf9a0Sjeremylt 48fc7cf9a0Sjeremylt for (int i = 0; i<nIn; i++) { 49fc7cf9a0Sjeremylt ierr = CeedVectorRestoreArrayRead(U[i], &impl->inputs[i]); CeedChk(ierr); 50fc7cf9a0Sjeremylt } 51fc7cf9a0Sjeremylt for (int i = 0; i<nOut; i++) { 52fc7cf9a0Sjeremylt ierr = CeedVectorRestoreArray(V[i], &impl->outputs[i]); CeedChk(ierr); 53fc7cf9a0Sjeremylt } 54fc7cf9a0Sjeremylt 55fc7cf9a0Sjeremylt return 0; 56fc7cf9a0Sjeremylt } 57fc7cf9a0Sjeremylt 58fc7cf9a0Sjeremylt static int CeedQFunctionDestroy_Memcheck(CeedQFunction qf) { 59fc7cf9a0Sjeremylt int ierr; 60fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 61fc7cf9a0Sjeremylt ierr = CeedQFunctionGetData(qf, (void *)&impl); CeedChk(ierr); 62fc7cf9a0Sjeremylt 63fc7cf9a0Sjeremylt ierr = CeedFree(&impl->inputs); CeedChk(ierr); 64fc7cf9a0Sjeremylt ierr = CeedFree(&impl->outputs); CeedChk(ierr); 65fc7cf9a0Sjeremylt ierr = CeedFree(&impl); CeedChk(ierr); 66fc7cf9a0Sjeremylt 67fc7cf9a0Sjeremylt return 0; 68fc7cf9a0Sjeremylt } 69fc7cf9a0Sjeremylt 70fc7cf9a0Sjeremylt int CeedQFunctionCreate_Memcheck(CeedQFunction qf) { 71fc7cf9a0Sjeremylt int ierr; 72fc7cf9a0Sjeremylt Ceed ceed; 73fc7cf9a0Sjeremylt ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChk(ierr); 74fc7cf9a0Sjeremylt 75fc7cf9a0Sjeremylt CeedQFunction_Memcheck *impl; 76fc7cf9a0Sjeremylt ierr = CeedCalloc(1, &impl); CeedChk(ierr); 77fc7cf9a0Sjeremylt ierr = CeedCalloc(16, &impl->inputs); CeedChk(ierr); 78fc7cf9a0Sjeremylt ierr = CeedCalloc(16, &impl->outputs); CeedChk(ierr); 79fc7cf9a0Sjeremylt ierr = CeedQFunctionSetData(qf, (void *)&impl); CeedChk(ierr); 80fc7cf9a0Sjeremylt 81fc7cf9a0Sjeremylt ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", 82fc7cf9a0Sjeremylt CeedQFunctionApply_Memcheck); CeedChk(ierr); 83fc7cf9a0Sjeremylt ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", 84fc7cf9a0Sjeremylt CeedQFunctionDestroy_Memcheck); CeedChk(ierr); 85fc7cf9a0Sjeremylt 86fc7cf9a0Sjeremylt return 0; 87fc7cf9a0Sjeremylt } 88