xref: /libCEED/rust/libceed-sys/c-src/backends/hip-ref/ceed-hip-ref-restriction.c (revision b3d03e38aa94038a8b9805419605106d8c381b6f)
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.
30d0321e0SJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
50d0321e0SJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
70d0321e0SJeremy L Thompson 
849aac155SJeremy L Thompson #include <ceed.h>
90d0321e0SJeremy L Thompson #include <ceed/backend.h>
10437930d1SJeremy L Thompson #include <ceed/jit-tools.h>
110d0321e0SJeremy L Thompson #include <stdbool.h>
120d0321e0SJeremy L Thompson #include <stddef.h>
1344d7a66cSJeremy L Thompson #include <string.h>
14c85e8640SSebastian Grimberg #include <hip/hip_runtime.h>
152b730f8bSJeremy L Thompson 
1649aac155SJeremy L Thompson #include "../hip/ceed-hip-common.h"
170d0321e0SJeremy L Thompson #include "../hip/ceed-hip-compile.h"
182b730f8bSJeremy L Thompson #include "ceed-hip-ref.h"
190d0321e0SJeremy L Thompson 
200d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
21dce49693SSebastian Grimberg // Core apply restriction code
220d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
23dce49693SSebastian Grimberg static inline int CeedElemRestrictionApply_Hip_Core(CeedElemRestriction rstr, CeedTransposeMode t_mode, bool use_signs, bool use_orients,
24dce49693SSebastian Grimberg                                                     CeedVector u, CeedVector v, CeedRequest *request) {
250d0321e0SJeremy L Thompson   Ceed                     ceed;
26437930d1SJeremy L Thompson   CeedInt                  num_elem, elem_size;
27dce49693SSebastian Grimberg   CeedRestrictionType      rstr_type;
280d0321e0SJeremy L Thompson   const CeedScalar        *d_u;
290d0321e0SJeremy L Thompson   CeedScalar              *d_v;
30b7453713SJeremy L Thompson   CeedElemRestriction_Hip *impl;
31b7453713SJeremy L Thompson   hipFunction_t            kernel;
32b7453713SJeremy L Thompson 
33dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl));
34dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetCeed(rstr, &ceed));
35dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetNumElements(rstr, &num_elem));
36dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetElementSize(rstr, &elem_size));
37dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetType(rstr, &rstr_type));
38b7453713SJeremy L Thompson   const CeedInt num_nodes = impl->num_nodes;
39b7453713SJeremy L Thompson 
40b7453713SJeremy L Thompson   // Get vectors
412b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorGetArrayRead(u, CEED_MEM_DEVICE, &d_u));
42437930d1SJeremy L Thompson   if (t_mode == CEED_TRANSPOSE) {
430d0321e0SJeremy L Thompson     // Sum into for transpose mode, e-vec to l-vec
442b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetArray(v, CEED_MEM_DEVICE, &d_v));
450d0321e0SJeremy L Thompson   } else {
460d0321e0SJeremy L Thompson     // Overwrite for notranspose mode, l-vec to e-vec
472b730f8bSJeremy L Thompson     CeedCallBackend(CeedVectorGetArrayWrite(v, CEED_MEM_DEVICE, &d_v));
480d0321e0SJeremy L Thompson   }
490d0321e0SJeremy L Thompson 
500d0321e0SJeremy L Thompson   // Restrict
51437930d1SJeremy L Thompson   if (t_mode == CEED_NOTRANSPOSE) {
520d0321e0SJeremy L Thompson     // L-vector -> E-vector
53dce49693SSebastian Grimberg     const CeedInt block_size = elem_size < 256 ? (elem_size > 64 ? elem_size : 64) : 256;
54dce49693SSebastian Grimberg     const CeedInt grid       = CeedDivUpInt(num_nodes, block_size);
5558549094SSebastian Grimberg 
56dce49693SSebastian Grimberg     switch (rstr_type) {
57dce49693SSebastian Grimberg       case CEED_RESTRICTION_STRIDED: {
58437930d1SJeremy L Thompson         kernel       = impl->StridedNoTranspose;
59437930d1SJeremy L Thompson         void *args[] = {&num_elem, &d_u, &d_v};
6058549094SSebastian Grimberg 
61dce49693SSebastian Grimberg         CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
62dce49693SSebastian Grimberg       } break;
63dce49693SSebastian Grimberg       case CEED_RESTRICTION_STANDARD: {
64dce49693SSebastian Grimberg         kernel       = impl->OffsetNoTranspose;
65dce49693SSebastian Grimberg         void *args[] = {&num_elem, &impl->d_ind, &d_u, &d_v};
66dce49693SSebastian Grimberg 
67dce49693SSebastian Grimberg         CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
68dce49693SSebastian Grimberg       } break;
69dce49693SSebastian Grimberg       case CEED_RESTRICTION_ORIENTED: {
70dce49693SSebastian Grimberg         if (use_signs) {
71dce49693SSebastian Grimberg           kernel       = impl->OrientedNoTranspose;
72dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &impl->d_orients, &d_u, &d_v};
73dce49693SSebastian Grimberg 
74dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
75dce49693SSebastian Grimberg         } else {
76dce49693SSebastian Grimberg           kernel       = impl->OffsetNoTranspose;
77dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &d_u, &d_v};
78dce49693SSebastian Grimberg 
79dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
80dce49693SSebastian Grimberg         }
81dce49693SSebastian Grimberg       } break;
82dce49693SSebastian Grimberg       case CEED_RESTRICTION_CURL_ORIENTED: {
83dce49693SSebastian Grimberg         if (use_signs && use_orients) {
84dce49693SSebastian Grimberg           kernel       = impl->CurlOrientedNoTranspose;
85dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &impl->d_curl_orients, &d_u, &d_v};
86dce49693SSebastian Grimberg 
87dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
88dce49693SSebastian Grimberg         } else if (use_orients) {
89dce49693SSebastian Grimberg           kernel       = impl->CurlOrientedUnsignedNoTranspose;
90dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &impl->d_curl_orients, &d_u, &d_v};
91dce49693SSebastian Grimberg 
92dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
93dce49693SSebastian Grimberg         } else {
94dce49693SSebastian Grimberg           kernel       = impl->OffsetNoTranspose;
95dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &d_u, &d_v};
96dce49693SSebastian Grimberg 
97dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
98dce49693SSebastian Grimberg         }
99dce49693SSebastian Grimberg       } break;
100*b3d03e38SSebastian Grimberg       case CEED_RESTRICTION_POINTS: {
101*b3d03e38SSebastian Grimberg         // LCOV_EXCL_START
102*b3d03e38SSebastian Grimberg         return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement restriction CeedElemRestrictionAtPoints");
103*b3d03e38SSebastian Grimberg         // LCOV_EXCL_STOP
104*b3d03e38SSebastian Grimberg       } break;
1050d0321e0SJeremy L Thompson     }
1060d0321e0SJeremy L Thompson   } else {
1070d0321e0SJeremy L Thompson     // E-vector -> L-vector
108dce49693SSebastian Grimberg     const CeedInt block_size = 64;
109dce49693SSebastian Grimberg     const CeedInt grid       = CeedDivUpInt(num_nodes, block_size);
110b7453713SJeremy L Thompson 
111dce49693SSebastian Grimberg     switch (rstr_type) {
112dce49693SSebastian Grimberg       case CEED_RESTRICTION_STRIDED: {
113dce49693SSebastian Grimberg         kernel       = impl->StridedTranspose;
114dce49693SSebastian Grimberg         void *args[] = {&num_elem, &d_u, &d_v};
115dce49693SSebastian Grimberg 
116dce49693SSebastian Grimberg         CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
117dce49693SSebastian Grimberg       } break;
118dce49693SSebastian Grimberg       case CEED_RESTRICTION_STANDARD: {
11958549094SSebastian Grimberg         if (impl->OffsetTranspose) {
120437930d1SJeremy L Thompson           kernel       = impl->OffsetTranspose;
12158549094SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &d_u, &d_v};
12258549094SSebastian Grimberg 
123dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
1240d0321e0SJeremy L Thompson         } else {
12558549094SSebastian Grimberg           kernel       = impl->OffsetTransposeDet;
12658549094SSebastian Grimberg           void *args[] = {&impl->d_l_vec_indices, &impl->d_t_indices, &impl->d_t_offsets, &d_u, &d_v};
12758549094SSebastian Grimberg 
128dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
12958549094SSebastian Grimberg         }
130dce49693SSebastian Grimberg       } break;
131dce49693SSebastian Grimberg       case CEED_RESTRICTION_ORIENTED: {
132dce49693SSebastian Grimberg         if (use_signs) {
133dce49693SSebastian Grimberg           kernel       = impl->OrientedTranspose;
134dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &impl->d_orients, &d_u, &d_v};
13558549094SSebastian Grimberg 
136dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
137dce49693SSebastian Grimberg         } else {
138dce49693SSebastian Grimberg           if (impl->OffsetTranspose) {
139dce49693SSebastian Grimberg             kernel       = impl->OffsetTranspose;
140dce49693SSebastian Grimberg             void *args[] = {&num_elem, &impl->d_ind, &d_u, &d_v};
141dce49693SSebastian Grimberg 
142dce49693SSebastian Grimberg             CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
143dce49693SSebastian Grimberg           } else {
144dce49693SSebastian Grimberg             kernel       = impl->OffsetTransposeDet;
145dce49693SSebastian Grimberg             void *args[] = {&impl->d_l_vec_indices, &impl->d_t_indices, &impl->d_t_offsets, &d_u, &d_v};
146dce49693SSebastian Grimberg 
147dce49693SSebastian Grimberg             CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
148dce49693SSebastian Grimberg           }
149dce49693SSebastian Grimberg         }
150dce49693SSebastian Grimberg       } break;
151dce49693SSebastian Grimberg       case CEED_RESTRICTION_CURL_ORIENTED: {
152dce49693SSebastian Grimberg         if (use_signs && use_orients) {
153dce49693SSebastian Grimberg           kernel       = impl->CurlOrientedTranspose;
154dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &impl->d_curl_orients, &d_u, &d_v};
155dce49693SSebastian Grimberg 
156dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
157dce49693SSebastian Grimberg         } else if (use_orients) {
158dce49693SSebastian Grimberg           kernel       = impl->CurlOrientedUnsignedTranspose;
159dce49693SSebastian Grimberg           void *args[] = {&num_elem, &impl->d_ind, &impl->d_curl_orients, &d_u, &d_v};
160dce49693SSebastian Grimberg 
161dce49693SSebastian Grimberg           CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
162dce49693SSebastian Grimberg         } else {
163dce49693SSebastian Grimberg           if (impl->OffsetTranspose) {
164dce49693SSebastian Grimberg             kernel       = impl->OffsetTranspose;
165dce49693SSebastian Grimberg             void *args[] = {&num_elem, &impl->d_ind, &d_u, &d_v};
166dce49693SSebastian Grimberg 
167dce49693SSebastian Grimberg             CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
168dce49693SSebastian Grimberg           } else {
169dce49693SSebastian Grimberg             kernel       = impl->OffsetTransposeDet;
170dce49693SSebastian Grimberg             void *args[] = {&impl->d_l_vec_indices, &impl->d_t_indices, &impl->d_t_offsets, &d_u, &d_v};
171dce49693SSebastian Grimberg 
172dce49693SSebastian Grimberg             CeedCallBackend(CeedRunKernel_Hip(ceed, kernel, grid, block_size, args));
173dce49693SSebastian Grimberg           }
174dce49693SSebastian Grimberg         }
175dce49693SSebastian Grimberg       } break;
176*b3d03e38SSebastian Grimberg       case CEED_RESTRICTION_POINTS: {
177*b3d03e38SSebastian Grimberg         // LCOV_EXCL_START
178*b3d03e38SSebastian Grimberg         return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement restriction CeedElemRestrictionAtPoints");
179*b3d03e38SSebastian Grimberg         // LCOV_EXCL_STOP
180*b3d03e38SSebastian Grimberg       } break;
1810d0321e0SJeremy L Thompson     }
1820d0321e0SJeremy L Thompson   }
1830d0321e0SJeremy L Thompson 
1842b730f8bSJeremy L Thompson   if (request != CEED_REQUEST_IMMEDIATE && request != CEED_REQUEST_ORDERED) *request = NULL;
1850d0321e0SJeremy L Thompson 
1860d0321e0SJeremy L Thompson   // Restore arrays
1872b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArrayRead(u, &d_u));
1882b730f8bSJeremy L Thompson   CeedCallBackend(CeedVectorRestoreArray(v, &d_v));
1890d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1900d0321e0SJeremy L Thompson }
1910d0321e0SJeremy L Thompson 
1920d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
193dce49693SSebastian Grimberg // Apply restriction
194dce49693SSebastian Grimberg //------------------------------------------------------------------------------
195dce49693SSebastian Grimberg static int CeedElemRestrictionApply_Hip(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedVector u, CeedVector v, CeedRequest *request) {
196dce49693SSebastian Grimberg   return CeedElemRestrictionApply_Hip_Core(rstr, t_mode, true, true, u, v, request);
197dce49693SSebastian Grimberg }
198dce49693SSebastian Grimberg 
199dce49693SSebastian Grimberg //------------------------------------------------------------------------------
200dce49693SSebastian Grimberg // Apply unsigned restriction
201dce49693SSebastian Grimberg //------------------------------------------------------------------------------
202dce49693SSebastian Grimberg static int CeedElemRestrictionApplyUnsigned_Hip(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedVector u, CeedVector v,
203dce49693SSebastian Grimberg                                                 CeedRequest *request) {
204dce49693SSebastian Grimberg   return CeedElemRestrictionApply_Hip_Core(rstr, t_mode, false, true, u, v, request);
205dce49693SSebastian Grimberg }
206dce49693SSebastian Grimberg 
207dce49693SSebastian Grimberg //------------------------------------------------------------------------------
208dce49693SSebastian Grimberg // Apply unoriented restriction
209dce49693SSebastian Grimberg //------------------------------------------------------------------------------
210dce49693SSebastian Grimberg static int CeedElemRestrictionApplyUnoriented_Hip(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedVector u, CeedVector v,
211dce49693SSebastian Grimberg                                                   CeedRequest *request) {
212dce49693SSebastian Grimberg   return CeedElemRestrictionApply_Hip_Core(rstr, t_mode, false, false, u, v, request);
213dce49693SSebastian Grimberg }
214dce49693SSebastian Grimberg 
215dce49693SSebastian Grimberg //------------------------------------------------------------------------------
2160d0321e0SJeremy L Thompson // Get offsets
2170d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
218472941f0SJeremy L Thompson static int CeedElemRestrictionGetOffsets_Hip(CeedElemRestriction rstr, CeedMemType mem_type, const CeedInt **offsets) {
2190d0321e0SJeremy L Thompson   CeedElemRestriction_Hip *impl;
2200d0321e0SJeremy L Thompson 
221b7453713SJeremy L Thompson   CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl));
222472941f0SJeremy L Thompson   switch (mem_type) {
2230d0321e0SJeremy L Thompson     case CEED_MEM_HOST:
2240d0321e0SJeremy L Thompson       *offsets = impl->h_ind;
2250d0321e0SJeremy L Thompson       break;
2260d0321e0SJeremy L Thompson     case CEED_MEM_DEVICE:
2270d0321e0SJeremy L Thompson       *offsets = impl->d_ind;
2280d0321e0SJeremy L Thompson       break;
2290d0321e0SJeremy L Thompson   }
2300d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2310d0321e0SJeremy L Thompson }
2320d0321e0SJeremy L Thompson 
2330d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
234dce49693SSebastian Grimberg // Get orientations
235dce49693SSebastian Grimberg //------------------------------------------------------------------------------
236dce49693SSebastian Grimberg static int CeedElemRestrictionGetOrientations_Hip(CeedElemRestriction rstr, CeedMemType mem_type, const bool **orients) {
237dce49693SSebastian Grimberg   CeedElemRestriction_Hip *impl;
238dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl));
239dce49693SSebastian Grimberg 
240dce49693SSebastian Grimberg   switch (mem_type) {
241dce49693SSebastian Grimberg     case CEED_MEM_HOST:
242dce49693SSebastian Grimberg       *orients = impl->h_orients;
243dce49693SSebastian Grimberg       break;
244dce49693SSebastian Grimberg     case CEED_MEM_DEVICE:
245dce49693SSebastian Grimberg       *orients = impl->d_orients;
246dce49693SSebastian Grimberg       break;
247dce49693SSebastian Grimberg   }
248dce49693SSebastian Grimberg   return CEED_ERROR_SUCCESS;
249dce49693SSebastian Grimberg }
250dce49693SSebastian Grimberg 
251dce49693SSebastian Grimberg //------------------------------------------------------------------------------
252dce49693SSebastian Grimberg // Get curl-conforming orientations
253dce49693SSebastian Grimberg //------------------------------------------------------------------------------
254dce49693SSebastian Grimberg static int CeedElemRestrictionGetCurlOrientations_Hip(CeedElemRestriction rstr, CeedMemType mem_type, const CeedInt8 **curl_orients) {
255dce49693SSebastian Grimberg   CeedElemRestriction_Hip *impl;
256dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl));
257dce49693SSebastian Grimberg 
258dce49693SSebastian Grimberg   switch (mem_type) {
259dce49693SSebastian Grimberg     case CEED_MEM_HOST:
260dce49693SSebastian Grimberg       *curl_orients = impl->h_curl_orients;
261dce49693SSebastian Grimberg       break;
262dce49693SSebastian Grimberg     case CEED_MEM_DEVICE:
263dce49693SSebastian Grimberg       *curl_orients = impl->d_curl_orients;
264dce49693SSebastian Grimberg       break;
265dce49693SSebastian Grimberg   }
266dce49693SSebastian Grimberg   return CEED_ERROR_SUCCESS;
267dce49693SSebastian Grimberg }
268dce49693SSebastian Grimberg 
269dce49693SSebastian Grimberg //------------------------------------------------------------------------------
2700d0321e0SJeremy L Thompson // Destroy restriction
2710d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
272dce49693SSebastian Grimberg static int CeedElemRestrictionDestroy_Hip(CeedElemRestriction rstr) {
2730d0321e0SJeremy L Thompson   Ceed                     ceed;
274b7453713SJeremy L Thompson   CeedElemRestriction_Hip *impl;
275b7453713SJeremy L Thompson 
276dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl));
277dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetCeed(rstr, &ceed));
2782b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipModuleUnload(impl->module));
2792b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&impl->h_ind_allocated));
2802b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(impl->d_ind_allocated));
2812b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(impl->d_t_offsets));
2822b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(impl->d_t_indices));
2832b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipFree(impl->d_l_vec_indices));
284dce49693SSebastian Grimberg   CeedCallBackend(CeedFree(&impl->h_orients_allocated));
285dce49693SSebastian Grimberg   CeedCallHip(ceed, hipFree(impl->d_orients_allocated));
286dce49693SSebastian Grimberg   CeedCallBackend(CeedFree(&impl->h_curl_orients_allocated));
287dce49693SSebastian Grimberg   CeedCallHip(ceed, hipFree(impl->d_curl_orients_allocated));
2882b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&impl));
2890d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2900d0321e0SJeremy L Thompson }
2910d0321e0SJeremy L Thompson 
2920d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
2930d0321e0SJeremy L Thompson // Create transpose offsets and indices
2940d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
295dce49693SSebastian Grimberg static int CeedElemRestrictionOffset_Hip(const CeedElemRestriction rstr, const CeedInt *indices) {
2960d0321e0SJeremy L Thompson   Ceed                     ceed;
297b7453713SJeremy L Thompson   bool                    *is_node;
298e79b91d9SJeremy L Thompson   CeedSize                 l_size;
299dce49693SSebastian Grimberg   CeedInt                  num_elem, elem_size, num_comp, num_nodes = 0;
300dce49693SSebastian Grimberg   CeedInt                 *ind_to_offset, *l_vec_indices, *t_offsets, *t_indices;
301b7453713SJeremy L Thompson   CeedElemRestriction_Hip *impl;
302b7453713SJeremy L Thompson 
303dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetCeed(rstr, &ceed));
304dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetData(rstr, &impl));
305dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetNumElements(rstr, &num_elem));
306dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetElementSize(rstr, &elem_size));
307dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetLVectorSize(rstr, &l_size));
308dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetNumComponents(rstr, &num_comp));
309b7453713SJeremy L Thompson   const CeedInt size_indices = num_elem * elem_size;
3100d0321e0SJeremy L Thompson 
311437930d1SJeremy L Thompson   // Count num_nodes
3122b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(l_size, &is_node));
313dce49693SSebastian Grimberg 
3142b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < size_indices; i++) is_node[indices[i]] = 1;
3152b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < l_size; i++) num_nodes += is_node[i];
316437930d1SJeremy L Thompson   impl->num_nodes = num_nodes;
3170d0321e0SJeremy L Thompson 
3180d0321e0SJeremy L Thompson   // L-vector offsets array
3192b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(l_size, &ind_to_offset));
3202b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(num_nodes, &l_vec_indices));
321b7453713SJeremy L Thompson   for (CeedInt i = 0, j = 0; i < l_size; i++) {
322437930d1SJeremy L Thompson     if (is_node[i]) {
323437930d1SJeremy L Thompson       l_vec_indices[j] = i;
3240d0321e0SJeremy L Thompson       ind_to_offset[i] = j++;
3250d0321e0SJeremy L Thompson     }
3262b730f8bSJeremy L Thompson   }
3272b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&is_node));
3280d0321e0SJeremy L Thompson 
3290d0321e0SJeremy L Thompson   // Compute transpose offsets and indices
330437930d1SJeremy L Thompson   const CeedInt size_offsets = num_nodes + 1;
331b7453713SJeremy L Thompson 
3322b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(size_offsets, &t_offsets));
3332b730f8bSJeremy L Thompson   CeedCallBackend(CeedMalloc(size_indices, &t_indices));
3340d0321e0SJeremy L Thompson   // Count node multiplicity
3352b730f8bSJeremy L Thompson   for (CeedInt e = 0; e < num_elem; ++e) {
3362b730f8bSJeremy L Thompson     for (CeedInt i = 0; i < elem_size; ++i) ++t_offsets[ind_to_offset[indices[elem_size * e + i]] + 1];
3372b730f8bSJeremy L Thompson   }
3380d0321e0SJeremy L Thompson   // Convert to running sum
3392b730f8bSJeremy L Thompson   for (CeedInt i = 1; i < size_offsets; ++i) t_offsets[i] += t_offsets[i - 1];
3400d0321e0SJeremy L Thompson   // List all E-vec indices associated with L-vec node
341437930d1SJeremy L Thompson   for (CeedInt e = 0; e < num_elem; ++e) {
342437930d1SJeremy L Thompson     for (CeedInt i = 0; i < elem_size; ++i) {
343437930d1SJeremy L Thompson       const CeedInt lid = elem_size * e + i;
3440d0321e0SJeremy L Thompson       const CeedInt gid = indices[lid];
345b7453713SJeremy L Thompson 
346437930d1SJeremy L Thompson       t_indices[t_offsets[ind_to_offset[gid]]++] = lid;
3470d0321e0SJeremy L Thompson     }
3480d0321e0SJeremy L Thompson   }
3490d0321e0SJeremy L Thompson   // Reset running sum
3502b730f8bSJeremy L Thompson   for (int i = size_offsets - 1; i > 0; --i) t_offsets[i] = t_offsets[i - 1];
351437930d1SJeremy L Thompson   t_offsets[0] = 0;
3520d0321e0SJeremy L Thompson 
3530d0321e0SJeremy L Thompson   // Copy data to device
3540d0321e0SJeremy L Thompson   // -- L-vector indices
3552b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&impl->d_l_vec_indices, num_nodes * sizeof(CeedInt)));
3562b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(impl->d_l_vec_indices, l_vec_indices, num_nodes * sizeof(CeedInt), hipMemcpyHostToDevice));
3570d0321e0SJeremy L Thompson   // -- Transpose offsets
3582b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&impl->d_t_offsets, size_offsets * sizeof(CeedInt)));
3592b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(impl->d_t_offsets, t_offsets, size_offsets * sizeof(CeedInt), hipMemcpyHostToDevice));
3600d0321e0SJeremy L Thompson   // -- Transpose indices
3612b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMalloc((void **)&impl->d_t_indices, size_indices * sizeof(CeedInt)));
3622b730f8bSJeremy L Thompson   CeedCallHip(ceed, hipMemcpy(impl->d_t_indices, t_indices, size_indices * sizeof(CeedInt), hipMemcpyHostToDevice));
3630d0321e0SJeremy L Thompson 
3640d0321e0SJeremy L Thompson   // Cleanup
3652b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&ind_to_offset));
3662b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&l_vec_indices));
3672b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&t_offsets));
3682b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&t_indices));
3690d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3700d0321e0SJeremy L Thompson }
3710d0321e0SJeremy L Thompson 
3720d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
3730d0321e0SJeremy L Thompson // Create restriction
3740d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
375fcbe8c06SSebastian Grimberg int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
376dce49693SSebastian Grimberg                                   const CeedInt8 *curl_orients, CeedElemRestriction rstr) {
377b7453713SJeremy L Thompson   Ceed                     ceed, ceed_parent;
378dce49693SSebastian Grimberg   bool                     is_deterministic;
379b7453713SJeremy L Thompson   CeedInt                  num_elem, num_comp, elem_size, comp_stride = 1;
380b7453713SJeremy L Thompson   CeedRestrictionType      rstr_type;
381dce49693SSebastian Grimberg   char                    *restriction_kernel_path, *restriction_kernel_source;
3820d0321e0SJeremy L Thompson   CeedElemRestriction_Hip *impl;
383b7453713SJeremy L Thompson 
384dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetCeed(rstr, &ceed));
385ca735530SJeremy L Thompson   CeedCallBackend(CeedGetParent(ceed, &ceed_parent));
386ca735530SJeremy L Thompson   CeedCallBackend(CeedIsDeterministic(ceed_parent, &is_deterministic));
387dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetNumElements(rstr, &num_elem));
388dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetNumComponents(rstr, &num_comp));
389dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetElementSize(rstr, &elem_size));
390dce49693SSebastian Grimberg   const CeedInt size       = num_elem * elem_size;
391437930d1SJeremy L Thompson   CeedInt       strides[3] = {1, size, elem_size};
392b7453713SJeremy L Thompson   CeedInt       layout[3]  = {1, elem_size * num_elem, elem_size};
3930d0321e0SJeremy L Thompson 
3940d0321e0SJeremy L Thompson   // Stride data
395dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionGetType(rstr, &rstr_type));
396dce49693SSebastian Grimberg   if (rstr_type == CEED_RESTRICTION_STRIDED) {
397437930d1SJeremy L Thompson     bool has_backend_strides;
398b7453713SJeremy L Thompson 
399dce49693SSebastian Grimberg     CeedCallBackend(CeedElemRestrictionHasBackendStrides(rstr, &has_backend_strides));
400437930d1SJeremy L Thompson     if (!has_backend_strides) {
401dce49693SSebastian Grimberg       CeedCallBackend(CeedElemRestrictionGetStrides(rstr, &strides));
4020d0321e0SJeremy L Thompson     }
4030d0321e0SJeremy L Thompson   } else {
404dce49693SSebastian Grimberg     CeedCallBackend(CeedElemRestrictionGetCompStride(rstr, &comp_stride));
4050d0321e0SJeremy L Thompson   }
4060d0321e0SJeremy L Thompson 
407dce49693SSebastian Grimberg   CeedCallBackend(CeedCalloc(1, &impl));
408dce49693SSebastian Grimberg   impl->num_nodes                = size;
4090d0321e0SJeremy L Thompson   impl->h_ind                    = NULL;
4100d0321e0SJeremy L Thompson   impl->h_ind_allocated          = NULL;
4110d0321e0SJeremy L Thompson   impl->d_ind                    = NULL;
4120d0321e0SJeremy L Thompson   impl->d_ind_allocated          = NULL;
413437930d1SJeremy L Thompson   impl->d_t_indices              = NULL;
414437930d1SJeremy L Thompson   impl->d_t_offsets              = NULL;
415dce49693SSebastian Grimberg   impl->h_orients                = NULL;
416dce49693SSebastian Grimberg   impl->h_orients_allocated      = NULL;
417dce49693SSebastian Grimberg   impl->d_orients                = NULL;
418dce49693SSebastian Grimberg   impl->d_orients_allocated      = NULL;
419dce49693SSebastian Grimberg   impl->h_curl_orients           = NULL;
420dce49693SSebastian Grimberg   impl->h_curl_orients_allocated = NULL;
421dce49693SSebastian Grimberg   impl->d_curl_orients           = NULL;
422dce49693SSebastian Grimberg   impl->d_curl_orients_allocated = NULL;
423dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionSetData(rstr, impl));
424dce49693SSebastian Grimberg   CeedCallBackend(CeedElemRestrictionSetELayout(rstr, layout));
4250d0321e0SJeremy L Thompson 
426dce49693SSebastian Grimberg   // Set up device offset/orientation arrays
427dce49693SSebastian Grimberg   if (rstr_type != CEED_RESTRICTION_STRIDED) {
428472941f0SJeremy L Thompson     switch (mem_type) {
4296574a04fSJeremy L Thompson       case CEED_MEM_HOST: {
430472941f0SJeremy L Thompson         switch (copy_mode) {
4310d0321e0SJeremy L Thompson           case CEED_OWN_POINTER:
4320d0321e0SJeremy L Thompson             impl->h_ind_allocated = (CeedInt *)indices;
4330d0321e0SJeremy L Thompson             impl->h_ind           = (CeedInt *)indices;
4340d0321e0SJeremy L Thompson             break;
4350d0321e0SJeremy L Thompson           case CEED_USE_POINTER:
4360d0321e0SJeremy L Thompson             impl->h_ind = (CeedInt *)indices;
4370d0321e0SJeremy L Thompson             break;
4380d0321e0SJeremy L Thompson           case CEED_COPY_VALUES:
439dce49693SSebastian Grimberg             CeedCallBackend(CeedMalloc(size, &impl->h_ind_allocated));
440dce49693SSebastian Grimberg             memcpy(impl->h_ind_allocated, indices, size * sizeof(CeedInt));
44144d7a66cSJeremy L Thompson             impl->h_ind = impl->h_ind_allocated;
4420d0321e0SJeremy L Thompson             break;
4430d0321e0SJeremy L Thompson         }
4442b730f8bSJeremy L Thompson         CeedCallHip(ceed, hipMalloc((void **)&impl->d_ind, size * sizeof(CeedInt)));
4450d0321e0SJeremy L Thompson         impl->d_ind_allocated = impl->d_ind;  // We own the device memory
4462b730f8bSJeremy L Thompson         CeedCallHip(ceed, hipMemcpy(impl->d_ind, indices, size * sizeof(CeedInt), hipMemcpyHostToDevice));
447dce49693SSebastian Grimberg         if (is_deterministic) CeedCallBackend(CeedElemRestrictionOffset_Hip(rstr, indices));
448dce49693SSebastian Grimberg       } break;
4496574a04fSJeremy L Thompson       case CEED_MEM_DEVICE: {
450472941f0SJeremy L Thompson         switch (copy_mode) {
4510d0321e0SJeremy L Thompson           case CEED_COPY_VALUES:
4522b730f8bSJeremy L Thompson             CeedCallHip(ceed, hipMalloc((void **)&impl->d_ind, size * sizeof(CeedInt)));
4530d0321e0SJeremy L Thompson             impl->d_ind_allocated = impl->d_ind;  // We own the device memory
4542b730f8bSJeremy L Thompson             CeedCallHip(ceed, hipMemcpy(impl->d_ind, indices, size * sizeof(CeedInt), hipMemcpyDeviceToDevice));
4550d0321e0SJeremy L Thompson             break;
4560d0321e0SJeremy L Thompson           case CEED_OWN_POINTER:
4570d0321e0SJeremy L Thompson             impl->d_ind           = (CeedInt *)indices;
4580d0321e0SJeremy L Thompson             impl->d_ind_allocated = impl->d_ind;
4590d0321e0SJeremy L Thompson             break;
4600d0321e0SJeremy L Thompson           case CEED_USE_POINTER:
4610d0321e0SJeremy L Thompson             impl->d_ind = (CeedInt *)indices;
4626574a04fSJeremy L Thompson             break;
4636574a04fSJeremy L Thompson         }
464dce49693SSebastian Grimberg         CeedCallBackend(CeedMalloc(size, &impl->h_ind_allocated));
465dce49693SSebastian Grimberg         CeedCallHip(ceed, hipMemcpy(impl->h_ind_allocated, impl->d_ind, size * sizeof(CeedInt), hipMemcpyDeviceToHost));
466dce49693SSebastian Grimberg         impl->h_ind = impl->h_ind_allocated;
467dce49693SSebastian Grimberg         if (is_deterministic) CeedCallBackend(CeedElemRestrictionOffset_Hip(rstr, indices));
468dce49693SSebastian Grimberg       } break;
469dce49693SSebastian Grimberg     }
470dce49693SSebastian Grimberg 
471dce49693SSebastian Grimberg     // Orientation data
472dce49693SSebastian Grimberg     if (rstr_type == CEED_RESTRICTION_ORIENTED) {
473dce49693SSebastian Grimberg       switch (mem_type) {
474dce49693SSebastian Grimberg         case CEED_MEM_HOST: {
475dce49693SSebastian Grimberg           switch (copy_mode) {
476dce49693SSebastian Grimberg             case CEED_OWN_POINTER:
477dce49693SSebastian Grimberg               impl->h_orients_allocated = (bool *)orients;
478dce49693SSebastian Grimberg               impl->h_orients           = (bool *)orients;
479dce49693SSebastian Grimberg               break;
480dce49693SSebastian Grimberg             case CEED_USE_POINTER:
481dce49693SSebastian Grimberg               impl->h_orients = (bool *)orients;
482dce49693SSebastian Grimberg               break;
483dce49693SSebastian Grimberg             case CEED_COPY_VALUES:
484dce49693SSebastian Grimberg               CeedCallBackend(CeedMalloc(size, &impl->h_orients_allocated));
485dce49693SSebastian Grimberg               memcpy(impl->h_orients_allocated, orients, size * sizeof(bool));
486dce49693SSebastian Grimberg               impl->h_orients = impl->h_orients_allocated;
487dce49693SSebastian Grimberg               break;
488dce49693SSebastian Grimberg           }
489dce49693SSebastian Grimberg           CeedCallHip(ceed, hipMalloc((void **)&impl->d_orients, size * sizeof(bool)));
490dce49693SSebastian Grimberg           impl->d_orients_allocated = impl->d_orients;  // We own the device memory
491dce49693SSebastian Grimberg           CeedCallHip(ceed, hipMemcpy(impl->d_orients, orients, size * sizeof(bool), hipMemcpyHostToDevice));
492dce49693SSebastian Grimberg         } break;
493dce49693SSebastian Grimberg         case CEED_MEM_DEVICE: {
494dce49693SSebastian Grimberg           switch (copy_mode) {
495dce49693SSebastian Grimberg             case CEED_COPY_VALUES:
496dce49693SSebastian Grimberg               CeedCallHip(ceed, hipMalloc((void **)&impl->d_orients, size * sizeof(bool)));
497dce49693SSebastian Grimberg               impl->d_orients_allocated = impl->d_orients;  // We own the device memory
498dce49693SSebastian Grimberg               CeedCallHip(ceed, hipMemcpy(impl->d_orients, orients, size * sizeof(bool), hipMemcpyDeviceToDevice));
499dce49693SSebastian Grimberg               break;
500dce49693SSebastian Grimberg             case CEED_OWN_POINTER:
501dce49693SSebastian Grimberg               impl->d_orients           = (bool *)orients;
502dce49693SSebastian Grimberg               impl->d_orients_allocated = impl->d_orients;
503dce49693SSebastian Grimberg               break;
504dce49693SSebastian Grimberg             case CEED_USE_POINTER:
505dce49693SSebastian Grimberg               impl->d_orients = (bool *)orients;
506dce49693SSebastian Grimberg               break;
507dce49693SSebastian Grimberg           }
508dce49693SSebastian Grimberg           CeedCallBackend(CeedMalloc(size, &impl->h_orients_allocated));
509dce49693SSebastian Grimberg           CeedCallHip(ceed, hipMemcpy(impl->h_orients_allocated, impl->d_orients, size * sizeof(bool), hipMemcpyDeviceToHost));
510dce49693SSebastian Grimberg           impl->h_orients = impl->h_orients_allocated;
511dce49693SSebastian Grimberg         } break;
512dce49693SSebastian Grimberg       }
513dce49693SSebastian Grimberg     } else if (rstr_type == CEED_RESTRICTION_CURL_ORIENTED) {
514dce49693SSebastian Grimberg       switch (mem_type) {
515dce49693SSebastian Grimberg         case CEED_MEM_HOST: {
516dce49693SSebastian Grimberg           switch (copy_mode) {
517dce49693SSebastian Grimberg             case CEED_OWN_POINTER:
518dce49693SSebastian Grimberg               impl->h_curl_orients_allocated = (CeedInt8 *)curl_orients;
519dce49693SSebastian Grimberg               impl->h_curl_orients           = (CeedInt8 *)curl_orients;
520dce49693SSebastian Grimberg               break;
521dce49693SSebastian Grimberg             case CEED_USE_POINTER:
522dce49693SSebastian Grimberg               impl->h_curl_orients = (CeedInt8 *)curl_orients;
523dce49693SSebastian Grimberg               break;
524dce49693SSebastian Grimberg             case CEED_COPY_VALUES:
525dce49693SSebastian Grimberg               CeedCallBackend(CeedMalloc(3 * size, &impl->h_curl_orients_allocated));
526dce49693SSebastian Grimberg               memcpy(impl->h_curl_orients_allocated, curl_orients, 3 * size * sizeof(CeedInt8));
527dce49693SSebastian Grimberg               impl->h_curl_orients = impl->h_curl_orients_allocated;
528dce49693SSebastian Grimberg               break;
529dce49693SSebastian Grimberg           }
530dce49693SSebastian Grimberg           CeedCallHip(ceed, hipMalloc((void **)&impl->d_curl_orients, 3 * size * sizeof(CeedInt8)));
531dce49693SSebastian Grimberg           impl->d_curl_orients_allocated = impl->d_curl_orients;  // We own the device memory
532dce49693SSebastian Grimberg           CeedCallHip(ceed, hipMemcpy(impl->d_curl_orients, curl_orients, 3 * size * sizeof(CeedInt8), hipMemcpyHostToDevice));
533dce49693SSebastian Grimberg         } break;
534dce49693SSebastian Grimberg         case CEED_MEM_DEVICE: {
535dce49693SSebastian Grimberg           switch (copy_mode) {
536dce49693SSebastian Grimberg             case CEED_COPY_VALUES:
537dce49693SSebastian Grimberg               CeedCallHip(ceed, hipMalloc((void **)&impl->d_curl_orients, 3 * size * sizeof(CeedInt8)));
538dce49693SSebastian Grimberg               impl->d_curl_orients_allocated = impl->d_curl_orients;  // We own the device memory
539dce49693SSebastian Grimberg               CeedCallHip(ceed, hipMemcpy(impl->d_curl_orients, curl_orients, 3 * size * sizeof(CeedInt8), hipMemcpyDeviceToDevice));
540dce49693SSebastian Grimberg               break;
541dce49693SSebastian Grimberg             case CEED_OWN_POINTER:
542dce49693SSebastian Grimberg               impl->d_curl_orients           = (CeedInt8 *)curl_orients;
543dce49693SSebastian Grimberg               impl->d_curl_orients_allocated = impl->d_curl_orients;
544dce49693SSebastian Grimberg               break;
545dce49693SSebastian Grimberg             case CEED_USE_POINTER:
546dce49693SSebastian Grimberg               impl->d_curl_orients = (CeedInt8 *)curl_orients;
547dce49693SSebastian Grimberg               break;
548dce49693SSebastian Grimberg           }
549dce49693SSebastian Grimberg           CeedCallBackend(CeedMalloc(3 * size, &impl->h_curl_orients_allocated));
550dce49693SSebastian Grimberg           CeedCallHip(ceed, hipMemcpy(impl->h_curl_orients_allocated, impl->d_curl_orients, 3 * size * sizeof(CeedInt8), hipMemcpyDeviceToHost));
551dce49693SSebastian Grimberg           impl->h_curl_orients = impl->h_curl_orients_allocated;
552dce49693SSebastian Grimberg         } break;
553dce49693SSebastian Grimberg       }
554dce49693SSebastian Grimberg     }
5550d0321e0SJeremy L Thompson   }
5560d0321e0SJeremy L Thompson 
5570d0321e0SJeremy L Thompson   // Compile HIP kernels
5582b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetJitAbsolutePath(ceed, "ceed/jit-source/hip/hip-ref-restriction.h", &restriction_kernel_path));
55923d4529eSJeremy L Thompson   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Restriction Kernel Source -----\n");
5602b730f8bSJeremy L Thompson   CeedCallBackend(CeedLoadSourceToBuffer(ceed, restriction_kernel_path, &restriction_kernel_source));
56123d4529eSJeremy L Thompson   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading Restriction Kernel Source Complete! -----\n");
562dce49693SSebastian Grimberg   CeedCallBackend(CeedCompile_Hip(ceed, restriction_kernel_source, &impl->module, 8, "RSTR_ELEM_SIZE", elem_size, "RSTR_NUM_ELEM", num_elem,
563dce49693SSebastian Grimberg                                   "RSTR_NUM_COMP", num_comp, "RSTR_NUM_NODES", impl->num_nodes, "RSTR_COMP_STRIDE", comp_stride, "RSTR_STRIDE_NODES",
564dce49693SSebastian Grimberg                                   strides[0], "RSTR_STRIDE_COMP", strides[1], "RSTR_STRIDE_ELEM", strides[2]));
565eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "StridedNoTranspose", &impl->StridedNoTranspose));
566eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "StridedTranspose", &impl->StridedTranspose));
56758549094SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "OffsetNoTranspose", &impl->OffsetNoTranspose));
56858549094SSebastian Grimberg   if (!is_deterministic) {
569eb7e6cafSJeremy L Thompson     CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "OffsetTranspose", &impl->OffsetTranspose));
57058549094SSebastian Grimberg   } else {
57158549094SSebastian Grimberg     CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "OffsetTransposeDet", &impl->OffsetTransposeDet));
57258549094SSebastian Grimberg   }
573dce49693SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "OrientedNoTranspose", &impl->OrientedNoTranspose));
574dce49693SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "OrientedTranspose", &impl->OrientedTranspose));
575dce49693SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "CurlOrientedNoTranspose", &impl->CurlOrientedNoTranspose));
576dce49693SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "CurlOrientedUnsignedNoTranspose", &impl->CurlOrientedUnsignedNoTranspose));
577dce49693SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "CurlOrientedTranspose", &impl->CurlOrientedTranspose));
578dce49693SSebastian Grimberg   CeedCallBackend(CeedGetKernel_Hip(ceed, impl->module, "CurlOrientedUnsignedTranspose", &impl->CurlOrientedUnsignedTranspose));
5792b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&restriction_kernel_path));
5802b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&restriction_kernel_source));
5810d0321e0SJeremy L Thompson 
5820d0321e0SJeremy L Thompson   // Register backend functions
583dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "Apply", CeedElemRestrictionApply_Hip));
584dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "ApplyUnsigned", CeedElemRestrictionApplyUnsigned_Hip));
585dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "ApplyUnoriented", CeedElemRestrictionApplyUnoriented_Hip));
586dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetOffsets", CeedElemRestrictionGetOffsets_Hip));
587dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetOrientations", CeedElemRestrictionGetOrientations_Hip));
588dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "GetCurlOrientations", CeedElemRestrictionGetCurlOrientations_Hip));
589dce49693SSebastian Grimberg   CeedCallBackend(CeedSetBackendFunction(ceed, "ElemRestriction", rstr, "Destroy", CeedElemRestrictionDestroy_Hip));
5900d0321e0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5910d0321e0SJeremy L Thompson }
5920d0321e0SJeremy L Thompson 
5930d0321e0SJeremy L Thompson //------------------------------------------------------------------------------
594