1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 #include "ceed-memcheck.h" 18 19 static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, 20 CeedVector *U, CeedVector *V) { 21 int ierr; 22 CeedQFunction_Memcheck *impl; 23 ierr = CeedQFunctionGetData(qf, (void *)&impl); CeedChk(ierr); 24 25 void *ctx; 26 ierr = CeedQFunctionGetContext(qf, &ctx); CeedChk(ierr); 27 28 CeedQFunctionUser f = NULL; 29 ierr = CeedQFunctionGetUserFunction(qf, &f); CeedChk(ierr); 30 31 CeedInt nIn, nOut; 32 ierr = CeedQFunctionGetNumArgs(qf, &nIn, &nOut); CeedChk(ierr); 33 34 for (int i = 0; i<nIn; i++) { 35 ierr = CeedVectorGetArrayRead(U[i], CEED_MEM_HOST, &impl->inputs[i]); 36 CeedChk(ierr); 37 } 38 for (int i = 0; i<nOut; i++) { 39 ierr = CeedVectorGetArray(V[i], CEED_MEM_HOST, &impl->outputs[i]); 40 CeedChk(ierr); 41 CeedInt len; 42 ierr = CeedVectorGetLength(V[i], &len); CeedChk(ierr); 43 VALGRIND_MAKE_MEM_UNDEFINED(impl->outputs[i], len); 44 } 45 46 ierr = f(ctx, Q, impl->inputs, impl->outputs); CeedChk(ierr); 47 48 for (int i = 0; i<nIn; i++) { 49 ierr = CeedVectorRestoreArrayRead(U[i], &impl->inputs[i]); CeedChk(ierr); 50 } 51 for (int i = 0; i<nOut; i++) { 52 ierr = CeedVectorRestoreArray(V[i], &impl->outputs[i]); CeedChk(ierr); 53 } 54 55 return 0; 56 } 57 58 static int CeedQFunctionDestroy_Memcheck(CeedQFunction qf) { 59 int ierr; 60 CeedQFunction_Memcheck *impl; 61 ierr = CeedQFunctionGetData(qf, (void *)&impl); CeedChk(ierr); 62 63 ierr = CeedFree(&impl->inputs); CeedChk(ierr); 64 ierr = CeedFree(&impl->outputs); CeedChk(ierr); 65 ierr = CeedFree(&impl); CeedChk(ierr); 66 67 return 0; 68 } 69 70 int CeedQFunctionCreate_Memcheck(CeedQFunction qf) { 71 int ierr; 72 Ceed ceed; 73 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChk(ierr); 74 75 CeedQFunction_Memcheck *impl; 76 ierr = CeedCalloc(1, &impl); CeedChk(ierr); 77 ierr = CeedCalloc(16, &impl->inputs); CeedChk(ierr); 78 ierr = CeedCalloc(16, &impl->outputs); CeedChk(ierr); 79 ierr = CeedQFunctionSetData(qf, (void *)&impl); CeedChk(ierr); 80 81 ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", 82 CeedQFunctionApply_Memcheck); CeedChk(ierr); 83 ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", 84 CeedQFunctionDestroy_Memcheck); CeedChk(ierr); 85 86 return 0; 87 } 88