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