13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 32f86a920SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 52f86a920SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 72f86a920SJeremy L Thompson 8ec3da8bcSJed Brown #include <ceed/backend.h> 9*2b730f8bSJeremy L Thompson #include <ceed/ceed.h> 10*2b730f8bSJeremy L Thompson 112f86a920SJeremy L Thompson #include "ceed-ref.h" 122f86a920SJeremy L Thompson 13f10650afSjeremylt //------------------------------------------------------------------------------ 14f10650afSjeremylt // Tensor Contract Apply 15f10650afSjeremylt //------------------------------------------------------------------------------ 16*2b730f8bSJeremy L Thompson static int CeedTensorContractApply_Ref(CeedTensorContract contract, CeedInt A, CeedInt B, CeedInt C, CeedInt J, const CeedScalar *restrict t, 17*2b730f8bSJeremy L Thompson CeedTransposeMode t_mode, const CeedInt add, const CeedScalar *restrict u, CeedScalar *restrict v) { 18d1d35e2fSjeremylt CeedInt t_stride_0 = B, t_stride_1 = 1; 19d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 20*2b730f8bSJeremy L Thompson t_stride_0 = 1; 21*2b730f8bSJeremy L Thompson t_stride_1 = J; 222f86a920SJeremy L Thompson } 232f86a920SJeremy L Thompson 24*2b730f8bSJeremy L Thompson if (!add) { 25*2b730f8bSJeremy L Thompson for (CeedInt q = 0; q < A * J * C; q++) v[q] = (CeedScalar)0.0; 26*2b730f8bSJeremy L Thompson } 272f86a920SJeremy L Thompson 28*2b730f8bSJeremy L Thompson for (CeedInt a = 0; a < A; a++) { 29*2b730f8bSJeremy L Thompson for (CeedInt b = 0; b < B; b++) { 302f86a920SJeremy L Thompson for (CeedInt j = 0; j < J; j++) { 31d1d35e2fSjeremylt CeedScalar tq = t[j * t_stride_0 + b * t_stride_1]; 32*2b730f8bSJeremy L Thompson for (CeedInt c = 0; c < C; c++) v[(a * J + j) * C + c] += tq * u[(a * B + b) * C + c]; 33*2b730f8bSJeremy L Thompson } 34*2b730f8bSJeremy L Thompson } 352f86a920SJeremy L Thompson } 36e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 372f86a920SJeremy L Thompson } 382f86a920SJeremy L Thompson 39f10650afSjeremylt //------------------------------------------------------------------------------ 40f10650afSjeremylt // Tensor Contract Destroy 41f10650afSjeremylt //------------------------------------------------------------------------------ 42*2b730f8bSJeremy L Thompson static int CeedTensorContractDestroy_Ref(CeedTensorContract contract) { return CEED_ERROR_SUCCESS; } 432f86a920SJeremy L Thompson 44f10650afSjeremylt //------------------------------------------------------------------------------ 45f10650afSjeremylt // Tensor Contract Create 46f10650afSjeremylt //------------------------------------------------------------------------------ 47c71e1dcdSjeremylt int CeedTensorContractCreate_Ref(CeedBasis basis, CeedTensorContract contract) { 482f86a920SJeremy L Thompson Ceed ceed; 49*2b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractGetCeed(contract, &ceed)); 502f86a920SJeremy L Thompson 51*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "TensorContract", contract, "Apply", CeedTensorContractApply_Ref)); 52*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "TensorContract", contract, "Destroy", CeedTensorContractDestroy_Ref)); 532f86a920SJeremy L Thompson 54e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 552f86a920SJeremy L Thompson } 56f10650afSjeremylt //------------------------------------------------------------------------------ 57