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