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-ref.h" 18 19 //------------------------------------------------------------------------------ 20 // Tensor Contract Apply 21 //------------------------------------------------------------------------------ 22 int CeedTensorContractApply_Ref(CeedTensorContract contract, CeedInt A, 23 CeedInt B, CeedInt C, CeedInt J, 24 const CeedScalar *restrict t, 25 CeedTransposeMode tmode, const CeedInt Add, 26 const CeedScalar *restrict u, 27 CeedScalar *restrict v) { 28 CeedInt tstride0 = B, tstride1 = 1; 29 if (tmode == CEED_TRANSPOSE) { 30 tstride0 = 1; tstride1 = J; 31 } 32 33 if (!Add) 34 for (CeedInt q=0; q<A*J*C; q++) 35 v[q] = (CeedScalar) 0.0; 36 37 for (CeedInt a=0; a<A; a++) 38 for (CeedInt b=0; b<B; b++) 39 for (CeedInt j=0; j<J; j++) { 40 CeedScalar tq = t[j*tstride0 + b*tstride1]; 41 for (CeedInt c=0; c<C; c++) 42 v[(a*J+j)*C+c] += tq * u[(a*B+b)*C+c]; 43 } 44 return 0; 45 } 46 47 //------------------------------------------------------------------------------ 48 // Tensor Contract Destroy 49 //------------------------------------------------------------------------------ 50 static int CeedTensorContractDestroy_Ref(CeedTensorContract contract) { 51 return 0; 52 } 53 54 //------------------------------------------------------------------------------ 55 // Tensor Contract Create 56 //------------------------------------------------------------------------------ 57 int CeedTensorContractCreate_Ref(CeedBasis basis, CeedTensorContract contract) { 58 int ierr; 59 Ceed ceed; 60 ierr = CeedTensorContractGetCeed(contract, &ceed); CeedChk(ierr); 61 62 ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Apply", 63 CeedTensorContractApply_Ref); CeedChk(ierr); 64 ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Destroy", 65 CeedTensorContractDestroy_Ref); CeedChk(ierr); 66 67 return 0; 68 } 69 //------------------------------------------------------------------------------ 70