ceed-tensor.c (c360dbdf7be710089f1c988eae047df8591af9a4) ceed-tensor.c (7a982d89c751e293e39d23a7c44a161cef1fcd06)
1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3// 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.

--- 4 unchanged lines hidden (view full) ---

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-impl.h>
18#include <ceed-backend.h>
19
20/// @file
1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3// 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.

--- 4 unchanged lines hidden (view full) ---

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-impl.h>
18#include <ceed-backend.h>
19
20/// @file
21/// Implementation of backend CeedTensorContract interfaces
22///
23/// @addtogroup CeedBasis
21/// Implementation of CeedTensorContract interfaces
22
23/// ----------------------------------------------------------------------------
24/// CeedTensorContract Backend API
25/// ----------------------------------------------------------------------------
26/// @addtogroup CeedBasisBackend
24/// @{
25
26/**
27 @brief Create a CeedTensorContract object for a CeedBasis
28
29 @param ceed A Ceed object where the CeedTensorContract will be created
30 @param basis CeedBasis for which the tensor contraction will be used
31 @param[out] contract Address of the variable where the newly created
32 CeedTensorContract will be stored.
33
34 @return An error code: 0 - success, otherwise - failure
35
27/// @{
28
29/**
30 @brief Create a CeedTensorContract object for a CeedBasis
31
32 @param ceed A Ceed object where the CeedTensorContract will be created
33 @param basis CeedBasis for which the tensor contraction will be used
34 @param[out] contract Address of the variable where the newly created
35 CeedTensorContract will be stored.
36
37 @return An error code: 0 - success, otherwise - failure
38
36 @ref Advanced
39 @ref Backend
37**/
38int CeedTensorContractCreate(Ceed ceed, CeedBasis basis,
39 CeedTensorContract *contract) {
40 int ierr;
41
42 if (!ceed->TensorContractCreate) {
43 Ceed delegate;
44 ierr = CeedGetObjectDelegate(ceed, &delegate, "TensorContract");

--- 11 unchanged lines hidden (view full) ---

56
57 ierr = CeedCalloc(1,contract); CeedChk(ierr);
58
59 (*contract)->ceed = ceed;
60 ceed->refcount++;
61 ierr = ceed->TensorContractCreate(basis, *contract);
62 CeedChk(ierr);
63 return 0;
40**/
41int CeedTensorContractCreate(Ceed ceed, CeedBasis basis,
42 CeedTensorContract *contract) {
43 int ierr;
44
45 if (!ceed->TensorContractCreate) {
46 Ceed delegate;
47 ierr = CeedGetObjectDelegate(ceed, &delegate, "TensorContract");

--- 11 unchanged lines hidden (view full) ---

59
60 ierr = CeedCalloc(1,contract); CeedChk(ierr);
61
62 (*contract)->ceed = ceed;
63 ceed->refcount++;
64 ierr = ceed->TensorContractCreate(basis, *contract);
65 CeedChk(ierr);
66 return 0;
64};
67}
65
66/**
67 @brief Apply tensor contraction
68
69 Contracts on the middle index
70 NOTRANSPOSE: v_ajc = t_jb u_abc
71 TRANSPOSE: v_ajc = t_bj u_abc
72 If add != 0, "=" is replaced by "+="

--- 7 unchanged lines hidden (view full) ---

80 @param tmode Transpose mode for t, \ref CEED_NOTRANSPOSE for t_jb
81 \ref CEED_TRANSPOSE for t_bj
82 @param add Add mode
83 @param[in] u Input array
84 @param[out] v Output array
85
86 @return An error code: 0 - success, otherwise - failure
87
68
69/**
70 @brief Apply tensor contraction
71
72 Contracts on the middle index
73 NOTRANSPOSE: v_ajc = t_jb u_abc
74 TRANSPOSE: v_ajc = t_bj u_abc
75 If add != 0, "=" is replaced by "+="

--- 7 unchanged lines hidden (view full) ---

83 @param tmode Transpose mode for t, \ref CEED_NOTRANSPOSE for t_jb
84 \ref CEED_TRANSPOSE for t_bj
85 @param add Add mode
86 @param[in] u Input array
87 @param[out] v Output array
88
89 @return An error code: 0 - success, otherwise - failure
90
88 @ref Advanced
91 @ref Backend
89**/
90int CeedTensorContractApply(CeedTensorContract contract, CeedInt A, CeedInt B,
91 CeedInt C, CeedInt J, const CeedScalar *restrict t,
92 CeedTransposeMode tmode, const CeedInt add,
93 const CeedScalar *restrict u,
94 CeedScalar *restrict v) {
95 int ierr;
96
97 ierr = contract->Apply(contract, A, B, C, J, t, tmode, add, u, v);
98 CeedChk(ierr);
99 return 0;
92**/
93int CeedTensorContractApply(CeedTensorContract contract, CeedInt A, CeedInt B,
94 CeedInt C, CeedInt J, const CeedScalar *restrict t,
95 CeedTransposeMode tmode, const CeedInt add,
96 const CeedScalar *restrict u,
97 CeedScalar *restrict v) {
98 int ierr;
99
100 ierr = contract->Apply(contract, A, B, C, J, t, tmode, add, u, v);
101 CeedChk(ierr);
102 return 0;
100};
103}
101
102/**
103 @brief Get Ceed associated with a CeedTensorContract
104
105 @param contract CeedTensorContract
106 @param[out] ceed Variable to store Ceed
107
108 @return An error code: 0 - success, otherwise - failure
109
104
105/**
106 @brief Get Ceed associated with a CeedTensorContract
107
108 @param contract CeedTensorContract
109 @param[out] ceed Variable to store Ceed
110
111 @return An error code: 0 - success, otherwise - failure
112
110 @ref Advanced
113 @ref Backend
111**/
112int CeedTensorContractGetCeed(CeedTensorContract contract, Ceed *ceed) {
113 *ceed = contract->ceed;
114 return 0;
114**/
115int CeedTensorContractGetCeed(CeedTensorContract contract, Ceed *ceed) {
116 *ceed = contract->ceed;
117 return 0;
115};
118}
116
117/**
118 @brief Get backend data of a CeedTensorContract
119
120 @param contract CeedTensorContract
121 @param[out] data Variable to store data
122
123 @return An error code: 0 - success, otherwise - failure
124
119
120/**
121 @brief Get backend data of a CeedTensorContract
122
123 @param contract CeedTensorContract
124 @param[out] data Variable to store data
125
126 @return An error code: 0 - success, otherwise - failure
127
125 @ref Advanced
128 @ref Backend
126**/
127int CeedTensorContractGetData(CeedTensorContract contract, void **data) {
128 *data = contract->data;
129 return 0;
130}
131
132/**
133 @brief Set backend data of a CeedTensorContract
134
135 @param[out] contract CeedTensorContract
136 @param data Data to set
137
138 @return An error code: 0 - success, otherwise - failure
139
129**/
130int CeedTensorContractGetData(CeedTensorContract contract, void **data) {
131 *data = contract->data;
132 return 0;
133}
134
135/**
136 @brief Set backend data of a CeedTensorContract
137
138 @param[out] contract CeedTensorContract
139 @param data Data to set
140
141 @return An error code: 0 - success, otherwise - failure
142
140 @ref Advanced
143 @ref Backend
141**/
142int CeedTensorContractSetData(CeedTensorContract contract, void **data) {
143 contract->data = *data;
144 return 0;
145}
146
147/**
148 @brief Destroy a CeedTensorContract
149
150 @param contract CeedTensorContract to destroy
151
152 @return An error code: 0 - success, otherwise - failure
153
144**/
145int CeedTensorContractSetData(CeedTensorContract contract, void **data) {
146 contract->data = *data;
147 return 0;
148}
149
150/**
151 @brief Destroy a CeedTensorContract
152
153 @param contract CeedTensorContract to destroy
154
155 @return An error code: 0 - success, otherwise - failure
156
154 @ref Advanced
157 @ref Backend
155**/
156int CeedTensorContractDestroy(CeedTensorContract *contract) {
157 int ierr;
158
159 if (!*contract || --(*contract)->refcount > 0)
160 return 0;
161 if ((*contract)->Destroy) {
162 ierr = (*contract)->Destroy(*contract); CeedChk(ierr);
163 }
164 ierr = CeedDestroy(&(*contract)->ceed); CeedChk(ierr);
165 ierr = CeedFree(contract); CeedChk(ierr);
166 return 0;
158**/
159int CeedTensorContractDestroy(CeedTensorContract *contract) {
160 int ierr;
161
162 if (!*contract || --(*contract)->refcount > 0)
163 return 0;
164 if ((*contract)->Destroy) {
165 ierr = (*contract)->Destroy(*contract); CeedChk(ierr);
166 }
167 ierr = CeedDestroy(&(*contract)->ceed); CeedChk(ierr);
168 ierr = CeedFree(contract); CeedChk(ierr);
169 return 0;
167};
170}
168
169/// @}
171
172/// @}