xref: /libCEED/backends/hip-gen/ceed-hip-gen-operator-build.cpp (revision 74398b5adbecd200ffa32cb282fd0f9b2ec0d708)
15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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.
37d8d0e25Snbeams //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
57d8d0e25Snbeams //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
73d576824SJeremy L Thompson 
87d8d0e25Snbeams #define CEED_DEBUG_COLOR 12
97d8d0e25Snbeams 
1049aac155SJeremy L Thompson #include <ceed.h>
11ec3da8bcSJed Brown #include <ceed/backend.h>
129e201c85SYohann #include <ceed/jit-tools.h>
132b730f8bSJeremy L Thompson 
147d8d0e25Snbeams #include <iostream>
157d8d0e25Snbeams #include <sstream>
162b730f8bSJeremy L Thompson #include <string>
172b730f8bSJeremy L Thompson 
180d0321e0SJeremy L Thompson #include "../hip-ref/ceed-hip-ref.h"
197d8d0e25Snbeams #include "../hip-shared/ceed-hip-shared.h"
20b2165e7aSSebastian Grimberg #include "../hip/ceed-hip-common.h"
217d8d0e25Snbeams #include "../hip/ceed-hip-compile.h"
222b730f8bSJeremy L Thompson #include "ceed-hip-gen.h"
23b3e1519bSnbeams 
2445a787f7SJeremy L Thompson struct FieldReuse_Hip {
2545a787f7SJeremy L Thompson   CeedInt      index;
2645a787f7SJeremy L Thompson   bool         is_input;
2745a787f7SJeremy L Thompson   CeedEvalMode eval_mode;
2845a787f7SJeremy L Thompson };
2945a787f7SJeremy L Thompson 
30b3e1519bSnbeams //------------------------------------------------------------------------------
31b3e1519bSnbeams // Calculate the block size used for launching the operator kernel
32b3e1519bSnbeams //------------------------------------------------------------------------------
332b730f8bSJeremy L Thompson extern "C" int BlockGridCalculate_Hip_gen(const CeedInt dim, const CeedInt num_elem, const CeedInt P_1d, const CeedInt Q_1d, CeedInt *block_sizes) {
343a2968d6SJeremy L Thompson   const CeedInt thread_1d = CeedIntMax(Q_1d, P_1d);
35b3e1519bSnbeams   if (dim == 1) {
363a2968d6SJeremy L Thompson     CeedInt elems_per_block = 64 * thread_1d > 256 ? 256 / thread_1d : 64;
37b7453713SJeremy L Thompson 
389e201c85SYohann     elems_per_block = elems_per_block > 0 ? elems_per_block : 1;
393a2968d6SJeremy L Thompson     block_sizes[0]  = thread_1d;
40b3e1519bSnbeams     block_sizes[1]  = 1;
419e201c85SYohann     block_sizes[2]  = elems_per_block;
42b3e1519bSnbeams   } else if (dim == 2) {
433a2968d6SJeremy L Thompson     const CeedInt elems_per_block = thread_1d < 4 ? 16 : 2;
44b7453713SJeremy L Thompson 
453a2968d6SJeremy L Thompson     block_sizes[0] = thread_1d;
463a2968d6SJeremy L Thompson     block_sizes[1] = thread_1d;
479e201c85SYohann     block_sizes[2] = elems_per_block;
48b3e1519bSnbeams   } else if (dim == 3) {
493a2968d6SJeremy L Thompson     const CeedInt elems_per_block = thread_1d < 6 ? 4 : (thread_1d < 8 ? 2 : 1);
50b7453713SJeremy L Thompson 
513a2968d6SJeremy L Thompson     block_sizes[0] = thread_1d;
523a2968d6SJeremy L Thompson     block_sizes[1] = thread_1d;
539e201c85SYohann     block_sizes[2] = elems_per_block;
54b3e1519bSnbeams   }
55b3e1519bSnbeams   return CEED_ERROR_SUCCESS;
56b3e1519bSnbeams }
57b3e1519bSnbeams 
587d8d0e25Snbeams //------------------------------------------------------------------------------
594b3e95d5SJeremy L Thompson // Determine type of operator
604b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
614b3e95d5SJeremy L Thompson static int CeedOperatorBuildKernelData_Hip_gen(Ceed ceed, CeedInt num_input_fields, CeedOperatorField *op_input_fields,
624b3e95d5SJeremy L Thompson                                                CeedQFunctionField *qf_input_fields, CeedInt num_output_fields, CeedOperatorField *op_output_fields,
63*74398b5aSJeremy L Thompson                                                CeedQFunctionField *qf_output_fields, CeedInt *max_P, CeedInt *max_P_1d, CeedInt *Q, CeedInt *Q_1d,
64*74398b5aSJeremy L Thompson                                                CeedInt *max_dim, bool *is_all_tensor, bool *use_3d_slices) {
65*74398b5aSJeremy L Thompson   // Check if all are tensor
66*74398b5aSJeremy L Thompson   *is_all_tensor = true;
674b3e95d5SJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
684b3e95d5SJeremy L Thompson     CeedBasis basis;
694b3e95d5SJeremy L Thompson 
704b3e95d5SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis));
714b3e95d5SJeremy L Thompson     if (basis != CEED_BASIS_NONE) {
724b3e95d5SJeremy L Thompson       bool is_field_tensor;
734b3e95d5SJeremy L Thompson 
744b3e95d5SJeremy L Thompson       CeedCallBackend(CeedBasisIsTensor(basis, &is_field_tensor));
75*74398b5aSJeremy L Thompson       *is_all_tensor = *is_all_tensor && is_field_tensor;
764b3e95d5SJeremy L Thompson     }
773a2968d6SJeremy L Thompson     CeedCallBackend(CeedBasisDestroy(&basis));
784b3e95d5SJeremy L Thompson   }
794b3e95d5SJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
804b3e95d5SJeremy L Thompson     CeedBasis basis;
814b3e95d5SJeremy L Thompson 
824b3e95d5SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis));
834b3e95d5SJeremy L Thompson     if (basis != CEED_BASIS_NONE) {
844b3e95d5SJeremy L Thompson       bool is_field_tensor;
854b3e95d5SJeremy L Thompson 
864b3e95d5SJeremy L Thompson       CeedCallBackend(CeedBasisIsTensor(basis, &is_field_tensor));
87*74398b5aSJeremy L Thompson       *is_all_tensor = *is_all_tensor && is_field_tensor;
88*74398b5aSJeremy L Thompson     }
89*74398b5aSJeremy L Thompson     CeedCallBackend(CeedBasisDestroy(&basis));
90*74398b5aSJeremy L Thompson   }
91*74398b5aSJeremy L Thompson 
92*74398b5aSJeremy L Thompson   // Find max_P, max_P_1d, Q, and Q_1d
93*74398b5aSJeremy L Thompson   bool is_all_3d = true;
94*74398b5aSJeremy L Thompson 
95*74398b5aSJeremy L Thompson   *max_P    = 0;
96*74398b5aSJeremy L Thompson   *max_P_1d = 0;
97*74398b5aSJeremy L Thompson   *Q        = 0;
98*74398b5aSJeremy L Thompson   *Q_1d     = 0;
99*74398b5aSJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
100*74398b5aSJeremy L Thompson     CeedBasis basis;
101*74398b5aSJeremy L Thompson 
102*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis));
103*74398b5aSJeremy L Thompson     if (basis != CEED_BASIS_NONE) {
104*74398b5aSJeremy L Thompson       bool    is_field_tensor;
105*74398b5aSJeremy L Thompson       CeedInt field_dim = 0, field_P = 0, field_P_1d = 0, field_Q = 0, field_Q_1d = 0;
106*74398b5aSJeremy L Thompson 
107*74398b5aSJeremy L Thompson       // Check if 3D
1084b3e95d5SJeremy L Thompson       CeedCallBackend(CeedBasisGetDimension(basis, &field_dim));
109*74398b5aSJeremy L Thompson       is_all_3d = is_all_3d && (field_dim == 3);
110*74398b5aSJeremy L Thompson       *max_dim  = CeedIntMax(*max_dim, field_dim);
111*74398b5aSJeremy L Thompson 
112*74398b5aSJeremy L Thompson       // Collect P, P_1d, Q, and Q_1d
113*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumNodes(basis, &field_P));
114*74398b5aSJeremy L Thompson       *max_P = CeedIntMax(*max_P, field_P);
115*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisIsTensor(basis, &is_field_tensor));
116*74398b5aSJeremy L Thompson       if (is_field_tensor) {
117*74398b5aSJeremy L Thompson         CeedCallBackend(CeedBasisGetNumNodes1D(basis, &field_P_1d));
118*74398b5aSJeremy L Thompson         *max_P_1d = CeedIntMax(*max_P_1d, field_P_1d);
119*74398b5aSJeremy L Thompson       }
120*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &field_Q));
121*74398b5aSJeremy L Thompson       CeedCheck(*Q == 0 || field_Q == *Q, ceed, CEED_ERROR_BACKEND, "Quadrature spaces must be compatible");
122*74398b5aSJeremy L Thompson       *Q = field_Q;
123*74398b5aSJeremy L Thompson       if (is_field_tensor) {
124*74398b5aSJeremy L Thompson         CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &field_Q_1d));
1254b3e95d5SJeremy L Thompson         CeedCheck(*Q_1d == 0 || field_Q_1d == *Q_1d, ceed, CEED_ERROR_BACKEND, "Quadrature spaces must be compatible");
1264b3e95d5SJeremy L Thompson         *Q_1d = field_Q_1d;
1274b3e95d5SJeremy L Thompson       }
128*74398b5aSJeremy L Thompson     }
129*74398b5aSJeremy L Thompson     CeedCallBackend(CeedBasisDestroy(&basis));
130*74398b5aSJeremy L Thompson   }
131*74398b5aSJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
132*74398b5aSJeremy L Thompson     CeedBasis basis;
133*74398b5aSJeremy L Thompson 
134*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis));
135*74398b5aSJeremy L Thompson     if (basis != CEED_BASIS_NONE) {
136*74398b5aSJeremy L Thompson       bool    is_field_tensor;
137*74398b5aSJeremy L Thompson       CeedInt field_dim = 0, field_P = 0, field_P_1d = 0, field_Q = 0, field_Q_1d = 0;
138*74398b5aSJeremy L Thompson 
139*74398b5aSJeremy L Thompson       // Check if 3D
140*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisGetDimension(basis, &field_dim));
141*74398b5aSJeremy L Thompson       is_all_3d = is_all_3d && (field_dim == 3);
142*74398b5aSJeremy L Thompson       *max_dim  = CeedIntMax(*max_dim, field_dim);
143*74398b5aSJeremy L Thompson 
144*74398b5aSJeremy L Thompson       // Collect P, P_1d, Q, and Q_1d
145*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumNodes(basis, &field_P));
146*74398b5aSJeremy L Thompson       *max_P = CeedIntMax(*max_P, field_P);
147*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisIsTensor(basis, &is_field_tensor));
148*74398b5aSJeremy L Thompson       if (is_field_tensor) {
149*74398b5aSJeremy L Thompson         CeedCallBackend(CeedBasisGetNumNodes1D(basis, &field_P_1d));
150*74398b5aSJeremy L Thompson         *max_P_1d = CeedIntMax(*max_P_1d, field_P_1d);
151*74398b5aSJeremy L Thompson       }
152*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &field_Q));
153*74398b5aSJeremy L Thompson       CeedCheck(*Q == 0 || field_Q == *Q, ceed, CEED_ERROR_BACKEND, "Quadrature spaces must be compatible");
154*74398b5aSJeremy L Thompson       *Q = field_Q;
155*74398b5aSJeremy L Thompson       if (is_field_tensor) {
156*74398b5aSJeremy L Thompson         CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &field_Q_1d));
157*74398b5aSJeremy L Thompson         CeedCheck(*Q_1d == 0 || field_Q_1d == *Q_1d, ceed, CEED_ERROR_BACKEND, "Quadrature spaces must be compatible");
158*74398b5aSJeremy L Thompson         *Q_1d = field_Q_1d;
159*74398b5aSJeremy L Thompson       }
160*74398b5aSJeremy L Thompson     }
1613a2968d6SJeremy L Thompson     CeedCallBackend(CeedBasisDestroy(&basis));
1624b3e95d5SJeremy L Thompson   }
1634b3e95d5SJeremy L Thompson 
1644b3e95d5SJeremy L Thompson   // Only use 3D collocated gradient parallelization strategy when gradient is computed
1654b3e95d5SJeremy L Thompson   *use_3d_slices = false;
166*74398b5aSJeremy L Thompson   if (is_all_3d && *is_all_tensor) {
1674b3e95d5SJeremy L Thompson     bool was_grad_found = false;
1684b3e95d5SJeremy L Thompson 
1694b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
1704b3e95d5SJeremy L Thompson       CeedEvalMode eval_mode;
1714b3e95d5SJeremy L Thompson 
1724b3e95d5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
1734b3e95d5SJeremy L Thompson       if (eval_mode == CEED_EVAL_GRAD) {
1744b3e95d5SJeremy L Thompson         CeedBasis_Hip_shared *basis_data;
1754b3e95d5SJeremy L Thompson         CeedBasis             basis;
1764b3e95d5SJeremy L Thompson 
1774b3e95d5SJeremy L Thompson         CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis));
1784b3e95d5SJeremy L Thompson         CeedCallBackend(CeedBasisGetData(basis, &basis_data));
1794b3e95d5SJeremy L Thompson         *use_3d_slices = basis_data->d_collo_grad_1d && (was_grad_found ? *use_3d_slices : true);
1804b3e95d5SJeremy L Thompson         was_grad_found = true;
1813a2968d6SJeremy L Thompson         CeedCallBackend(CeedBasisDestroy(&basis));
1824b3e95d5SJeremy L Thompson       }
1834b3e95d5SJeremy L Thompson     }
1844b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
1854b3e95d5SJeremy L Thompson       CeedEvalMode eval_mode;
1864b3e95d5SJeremy L Thompson 
1874b3e95d5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
1884b3e95d5SJeremy L Thompson       if (eval_mode == CEED_EVAL_GRAD) {
1894b3e95d5SJeremy L Thompson         CeedBasis_Hip_shared *basis_data;
1904b3e95d5SJeremy L Thompson         CeedBasis             basis;
1914b3e95d5SJeremy L Thompson 
1924b3e95d5SJeremy L Thompson         CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis));
1934b3e95d5SJeremy L Thompson         CeedCallBackend(CeedBasisGetData(basis, &basis_data));
1944b3e95d5SJeremy L Thompson         *use_3d_slices = basis_data->d_collo_grad_1d && (was_grad_found ? *use_3d_slices : true);
1954b3e95d5SJeremy L Thompson         was_grad_found = true;
1963a2968d6SJeremy L Thompson         CeedCallBackend(CeedBasisDestroy(&basis));
1974b3e95d5SJeremy L Thompson       }
1984b3e95d5SJeremy L Thompson     }
1994b3e95d5SJeremy L Thompson   }
2004b3e95d5SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2014b3e95d5SJeremy L Thompson }
2024b3e95d5SJeremy L Thompson 
2034b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
2044b3e95d5SJeremy L Thompson // Setup fields
2054b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
2064b3e95d5SJeremy L Thompson static int CeedOperatorBuildKernelFieldData_Hip_gen(std::ostringstream &code, CeedOperator_Hip_gen *data, CeedInt i, CeedOperatorField op_field,
207*74398b5aSJeremy L Thompson                                                     CeedQFunctionField qf_field, FieldReuse_Hip field_reuse, CeedInt max_dim, CeedInt Q, CeedInt Q_1d,
208*74398b5aSJeremy L Thompson                                                     bool is_input, bool is_all_tensor, bool is_at_points, bool use_3d_slices) {
209*74398b5aSJeremy L Thompson   bool      is_tensor = true;
210*74398b5aSJeremy L Thompson   CeedBasis basis;
211*74398b5aSJeremy L Thompson   CeedCallBackend(CeedOperatorFieldGetBasis(op_field, &basis));
212*74398b5aSJeremy L Thompson   if (basis != CEED_BASIS_NONE) CeedCallBackend(CeedBasisIsTensor(basis, &is_tensor));
213*74398b5aSJeremy L Thompson 
21459fa3f92SJeremy L Thompson   const char           *field_name;
2154b3e95d5SJeremy L Thompson   std::string           var_suffix = (is_input ? "_in_" : "_out_") + std::to_string(i);
2169123fb08SJeremy L Thompson   std::string           P_name = (is_tensor ? "P_1d" : "P") + var_suffix, Q_name = is_tensor ? "Q_1d" : "Q";
2174b3e95d5SJeremy L Thompson   std::string           option_name = (is_input ? "inputs" : "outputs");
2184b3e95d5SJeremy L Thompson   CeedEvalMode          eval_mode   = CEED_EVAL_NONE;
219*74398b5aSJeremy L Thompson   CeedInt               elem_size = 0, num_comp = 0, dim = max_dim, P_1d = 0;
2204b3e95d5SJeremy L Thompson   CeedElemRestriction   elem_rstr;
2214b3e95d5SJeremy L Thompson   CeedBasis_Hip_shared *basis_data;
2224b3e95d5SJeremy L Thompson 
2239ee499e5SJeremy L Thompson   // Field reuse info
22445a787f7SJeremy L Thompson   bool use_previous_field = field_reuse.index != -1;
2259ee499e5SJeremy L Thompson 
22659fa3f92SJeremy L Thompson   CeedCallBackend(CeedOperatorFieldGetName(op_field, &field_name));
22759fa3f92SJeremy L Thompson   code << "  // -- " << (is_input ? "Input" : "Output") << " field " << i << ": " << field_name << "\n";
2284b3e95d5SJeremy L Thompson 
2294b3e95d5SJeremy L Thompson   // Get field data
2304b3e95d5SJeremy L Thompson   CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_field, &elem_rstr));
2314b3e95d5SJeremy L Thompson   if (elem_rstr != CEED_ELEMRESTRICTION_NONE) {
2324b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size));
2334b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp));
2344b3e95d5SJeremy L Thompson   }
2353a2968d6SJeremy L Thompson   CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
2364b3e95d5SJeremy L Thompson   if (basis != CEED_BASIS_NONE) {
2374b3e95d5SJeremy L Thompson     CeedCallBackend(CeedBasisGetData(basis, &basis_data));
238*74398b5aSJeremy L Thompson     CeedCallBackend(CeedBasisGetDimension(basis, &dim));
2399123fb08SJeremy L Thompson     if (is_tensor) CeedCallBackend(CeedBasisGetNumNodes1D(basis, &P_1d));
2409123fb08SJeremy L Thompson     else CeedCallBackend(CeedBasisGetNumNodes(basis, &P_1d));
2414b3e95d5SJeremy L Thompson   }
2424b3e95d5SJeremy L Thompson   CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_field, &eval_mode));
2434b3e95d5SJeremy L Thompson 
2444b3e95d5SJeremy L Thompson   // Set field constants
245*74398b5aSJeremy L Thompson   code << "  const CeedInt dim" << var_suffix << " = " << dim << ";\n";
246*74398b5aSJeremy L Thompson   if (is_tensor && !is_all_tensor) {
247*74398b5aSJeremy L Thompson     CeedInt P = 0;
248*74398b5aSJeremy L Thompson 
249*74398b5aSJeremy L Thompson     CeedCallBackend(CeedBasisGetNumNodes(basis, &P));
250*74398b5aSJeremy L Thompson     code << "  const CeedInt P" << var_suffix << " = " << (basis == CEED_BASIS_NONE ? Q : P) << ";\n";
251*74398b5aSJeremy L Thompson   }
2524b3e95d5SJeremy L Thompson   code << "  const CeedInt " << P_name << " = " << (basis == CEED_BASIS_NONE ? Q_1d : P_1d) << ";\n";
253343e3094SJeremy L Thompson   if (eval_mode != CEED_EVAL_WEIGHT) {
2544b3e95d5SJeremy L Thompson     code << "  const CeedInt num_comp" << var_suffix << " = " << num_comp << ";\n";
2554b3e95d5SJeremy L Thompson   }
2564b3e95d5SJeremy L Thompson 
2574b3e95d5SJeremy L Thompson   // Load basis data
2584b3e95d5SJeremy L Thompson   code << "  // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
2594b3e95d5SJeremy L Thompson   switch (eval_mode) {
2604b3e95d5SJeremy L Thompson     case CEED_EVAL_NONE:
2614b3e95d5SJeremy L Thompson       break;
2624b3e95d5SJeremy L Thompson     case CEED_EVAL_INTERP:
2633a2968d6SJeremy L Thompson       if (is_at_points) {
2643a2968d6SJeremy L Thompson         // AtPoints
2653a2968d6SJeremy L Thompson         if (!basis_data->d_chebyshev_interp_1d) {
2663a2968d6SJeremy L Thompson           CeedSize    interp_bytes;
2673a2968d6SJeremy L Thompson           CeedScalar *chebyshev_interp_1d;
2683a2968d6SJeremy L Thompson 
2693a2968d6SJeremy L Thompson           interp_bytes = P_1d * Q_1d * sizeof(CeedScalar);
2703a2968d6SJeremy L Thompson           CeedCallBackend(CeedCalloc(P_1d * Q_1d, &chebyshev_interp_1d));
2713a2968d6SJeremy L Thompson           CeedCallBackend(CeedBasisGetChebyshevInterp1D(basis, chebyshev_interp_1d));
2723a2968d6SJeremy L Thompson           CeedCallHip(CeedBasisReturnCeed(basis), hipMalloc((void **)&basis_data->d_chebyshev_interp_1d, interp_bytes));
2733a2968d6SJeremy L Thompson           CeedCallHip(CeedBasisReturnCeed(basis),
2743a2968d6SJeremy L Thompson                       hipMemcpy(basis_data->d_chebyshev_interp_1d, chebyshev_interp_1d, interp_bytes, hipMemcpyHostToDevice));
2753a2968d6SJeremy L Thompson           CeedCallBackend(CeedFree(&chebyshev_interp_1d));
2763a2968d6SJeremy L Thompson         }
2773a2968d6SJeremy L Thompson         if (is_input) data->B.inputs[i] = basis_data->d_chebyshev_interp_1d;
2783a2968d6SJeremy L Thompson         else data->B.outputs[i] = basis_data->d_chebyshev_interp_1d;
2793a2968d6SJeremy L Thompson       } else {
2803a2968d6SJeremy L Thompson         // Standard quadrature
2814b3e95d5SJeremy L Thompson         if (is_input) data->B.inputs[i] = basis_data->d_interp_1d;
2824b3e95d5SJeremy L Thompson         else data->B.outputs[i] = basis_data->d_interp_1d;
2833a2968d6SJeremy L Thompson       }
2849ee499e5SJeremy L Thompson       if (use_previous_field) {
28545a787f7SJeremy L Thompson         std::string reuse_var = "s_B" + ((field_reuse.is_input ? "_in_" : "_out_") + std::to_string(field_reuse.index));
2869ee499e5SJeremy L Thompson 
2879ee499e5SJeremy L Thompson         code << "  CeedScalar *s_B" << var_suffix << " = " << reuse_var << ";\n";
2889ee499e5SJeremy L Thompson       } else {
2899123fb08SJeremy L Thompson         code << "  __shared__ CeedScalar s_B" << var_suffix << "[" << P_name << "*" << Q_name << "];\n";
290f815fac9SJeremy L Thompson         code << "  LoadMatrix<" << P_name << ", " << Q_name << ">(data, B." << option_name << "[" << i << "], s_B" << var_suffix << ");\n";
2919ee499e5SJeremy L Thompson       }
2924b3e95d5SJeremy L Thompson       break;
2934b3e95d5SJeremy L Thompson     case CEED_EVAL_GRAD:
2943a2968d6SJeremy L Thompson       if (is_at_points) {
2953a2968d6SJeremy L Thompson         // AtPoints
2963a2968d6SJeremy L Thompson         if (!basis_data->d_chebyshev_interp_1d) {
2973a2968d6SJeremy L Thompson           CeedSize    interp_bytes;
2983a2968d6SJeremy L Thompson           CeedScalar *chebyshev_interp_1d;
2993a2968d6SJeremy L Thompson 
3003a2968d6SJeremy L Thompson           interp_bytes = P_1d * Q_1d * sizeof(CeedScalar);
3013a2968d6SJeremy L Thompson           CeedCallBackend(CeedCalloc(P_1d * Q_1d, &chebyshev_interp_1d));
3023a2968d6SJeremy L Thompson           CeedCallBackend(CeedBasisGetChebyshevInterp1D(basis, chebyshev_interp_1d));
3033a2968d6SJeremy L Thompson           CeedCallHip(CeedBasisReturnCeed(basis), hipMalloc((void **)&basis_data->d_chebyshev_interp_1d, interp_bytes));
3043a2968d6SJeremy L Thompson           CeedCallHip(CeedBasisReturnCeed(basis),
3053a2968d6SJeremy L Thompson                       hipMemcpy(basis_data->d_chebyshev_interp_1d, chebyshev_interp_1d, interp_bytes, hipMemcpyHostToDevice));
3063a2968d6SJeremy L Thompson           CeedCallBackend(CeedFree(&chebyshev_interp_1d));
3073a2968d6SJeremy L Thompson         }
3083a2968d6SJeremy L Thompson         if (is_input) data->B.inputs[i] = basis_data->d_chebyshev_interp_1d;
3093a2968d6SJeremy L Thompson         else data->B.outputs[i] = basis_data->d_chebyshev_interp_1d;
3103a2968d6SJeremy L Thompson       } else {
3113a2968d6SJeremy L Thompson         // Standard quadrature
3124b3e95d5SJeremy L Thompson         if (is_input) data->B.inputs[i] = basis_data->d_interp_1d;
3134b3e95d5SJeremy L Thompson         else data->B.outputs[i] = basis_data->d_interp_1d;
3143a2968d6SJeremy L Thompson       }
3159123fb08SJeremy L Thompson       if (is_tensor) {
3169ee499e5SJeremy L Thompson         if (use_previous_field) {
31745a787f7SJeremy L Thompson           std::string reuse_var = "s_B" + ((field_reuse.is_input ? "_in_" : "_out_") + std::to_string(field_reuse.index));
3189ee499e5SJeremy L Thompson 
3199ee499e5SJeremy L Thompson           code << "  CeedScalar *s_B" << var_suffix << " = " << reuse_var << ";\n";
3209ee499e5SJeremy L Thompson         } else {
3219123fb08SJeremy L Thompson           code << "  __shared__ CeedScalar s_B" << var_suffix << "[" << P_name << "*" << Q_name << "];\n";
322f815fac9SJeremy L Thompson           code << "  LoadMatrix<" << P_name << ", " << Q_name << ">(data, B." << option_name << "[" << i << "], s_B" << var_suffix << ");\n";
3239123fb08SJeremy L Thompson         }
3249ee499e5SJeremy L Thompson       }
3253a2968d6SJeremy L Thompson       if (is_at_points) break;  // No G mat for AtPoints
3264b3e95d5SJeremy L Thompson       if (use_3d_slices) {
3274b3e95d5SJeremy L Thompson         if (is_input) data->G.inputs[i] = basis_data->d_collo_grad_1d;
3284b3e95d5SJeremy L Thompson         else data->G.outputs[i] = basis_data->d_collo_grad_1d;
32945a787f7SJeremy L Thompson         if (use_previous_field && field_reuse.eval_mode == CEED_EVAL_GRAD) {
33045a787f7SJeremy L Thompson           std::string reuse_var = "s_G" + ((field_reuse.is_input ? "_in_" : "_out_") + std::to_string(field_reuse.index));
3319ee499e5SJeremy L Thompson 
3329ee499e5SJeremy L Thompson           code << "  CeedScalar *s_G" << var_suffix << " = " << reuse_var << ";\n";
3339ee499e5SJeremy L Thompson         } else {
3349123fb08SJeremy L Thompson           code << "  __shared__ CeedScalar s_G" << var_suffix << "[" << Q_name << "*" << Q_name << "];\n";
335f815fac9SJeremy L Thompson           code << "  LoadMatrix<" << Q_name << ", " << Q_name << ">(data, G." << option_name << "[" << i << "], s_G" << var_suffix << ");\n";
3369ee499e5SJeremy L Thompson         }
3374b3e95d5SJeremy L Thompson       } else {
3384b3e95d5SJeremy L Thompson         bool has_collo_grad = basis_data->d_collo_grad_1d;
3394b3e95d5SJeremy L Thompson 
3404b3e95d5SJeremy L Thompson         if (is_input) data->G.inputs[i] = has_collo_grad ? basis_data->d_collo_grad_1d : basis_data->d_grad_1d;
3414b3e95d5SJeremy L Thompson         else data->G.outputs[i] = has_collo_grad ? basis_data->d_collo_grad_1d : basis_data->d_grad_1d;
3424b3e95d5SJeremy L Thompson         if (has_collo_grad) {
34345a787f7SJeremy L Thompson           if (use_previous_field && field_reuse.eval_mode == CEED_EVAL_GRAD) {
34445a787f7SJeremy L Thompson             std::string reuse_var = "s_G" + ((field_reuse.is_input ? "_in_" : "_out_") + std::to_string(field_reuse.index));
3459ee499e5SJeremy L Thompson 
3469ee499e5SJeremy L Thompson             code << "  CeedScalar *s_G" << var_suffix << " = " << reuse_var << ";\n";
3479ee499e5SJeremy L Thompson           } else {
3489123fb08SJeremy L Thompson             code << "  __shared__ CeedScalar s_G" << var_suffix << "[" << Q_name << "*" << Q_name << "];\n";
349f815fac9SJeremy L Thompson             code << "  LoadMatrix<" << Q_name << ", " << Q_name << ">(data, G." << option_name << "[" << i << "], s_G" << var_suffix << ");\n";
3509ee499e5SJeremy L Thompson           }
3519ee499e5SJeremy L Thompson         } else {
35245a787f7SJeremy L Thompson           if (use_previous_field && field_reuse.eval_mode == CEED_EVAL_GRAD) {
35345a787f7SJeremy L Thompson             std::string reuse_var = "s_G" + ((field_reuse.is_input ? "_in_" : "_out_") + std::to_string(field_reuse.index));
3549ee499e5SJeremy L Thompson 
3559ee499e5SJeremy L Thompson             code << "  CeedScalar *s_G" << var_suffix << " = " << reuse_var << ";\n";
3564b3e95d5SJeremy L Thompson           } else {
357*74398b5aSJeremy L Thompson             code << "  __shared__ CeedScalar s_G" << var_suffix << "[" << P_name << "*" << Q_name << (is_tensor ? "" : "*dim")
358*74398b5aSJeremy L Thompson                  << (is_tensor ? "" : var_suffix) << "];\n";
359*74398b5aSJeremy L Thompson             code << "  LoadMatrix<" << P_name << ", " << Q_name << (is_tensor ? "" : "*dim") << (is_tensor ? "" : var_suffix) << ">(data, G."
360*74398b5aSJeremy L Thompson                  << option_name << "[" << i << "], s_G" << var_suffix << ");\n";
3614b3e95d5SJeremy L Thompson           }
3624b3e95d5SJeremy L Thompson         }
3639ee499e5SJeremy L Thompson       }
3644b3e95d5SJeremy L Thompson       break;
3654b3e95d5SJeremy L Thompson     case CEED_EVAL_WEIGHT:
3664b3e95d5SJeremy L Thompson       break;  // No action
3674b3e95d5SJeremy L Thompson       // LCOV_EXCL_START
3684b3e95d5SJeremy L Thompson     case CEED_EVAL_DIV:
3694b3e95d5SJeremy L Thompson     case CEED_EVAL_CURL:
3704b3e95d5SJeremy L Thompson       break;  // TODO: Not implemented
3714b3e95d5SJeremy L Thompson               // LCOV_EXCL_STOP
3724b3e95d5SJeremy L Thompson   }
3733a2968d6SJeremy L Thompson   CeedCallBackend(CeedBasisDestroy(&basis));
3744b3e95d5SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3754b3e95d5SJeremy L Thompson }
3764b3e95d5SJeremy L Thompson 
3774b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
3784b3e95d5SJeremy L Thompson // Restriction
3794b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
380*74398b5aSJeremy L Thompson static int CeedOperatorBuildKernelRestriction_Hip_gen(std::ostringstream &code, CeedOperator_Hip_gen *data, CeedInt i, CeedInt field_input_buffer[],
381*74398b5aSJeremy L Thompson                                                       CeedOperatorField op_field, CeedQFunctionField qf_field, CeedInt max_dim, CeedInt Q_1d,
382*74398b5aSJeremy L Thompson                                                       bool is_input, bool is_all_tensor, bool is_at_points, bool use_3d_slices) {
3834b3e95d5SJeremy L Thompson   std::string              var_suffix = (is_input ? "_in_" : "_out_") + std::to_string(i);
384*74398b5aSJeremy L Thompson   std::string              P_name     = (is_all_tensor ? "P_1d" : "P") + var_suffix;
3854b3e95d5SJeremy L Thompson   CeedEvalMode             eval_mode  = CEED_EVAL_NONE;
386*74398b5aSJeremy L Thompson   CeedInt                  elem_size = 0, num_comp = 0;
3874b3e95d5SJeremy L Thompson   CeedSize                 l_size;
388f815fac9SJeremy L Thompson   CeedRestrictionType      rstr_type = CEED_RESTRICTION_STANDARD;
3894b3e95d5SJeremy L Thompson   CeedElemRestriction_Hip *rstr_data;
3904b3e95d5SJeremy L Thompson   CeedElemRestriction      elem_rstr;
3914b3e95d5SJeremy L Thompson 
3924b3e95d5SJeremy L Thompson   // Get field data
3934b3e95d5SJeremy L Thompson   CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_field, &elem_rstr));
3944b3e95d5SJeremy L Thompson   if (elem_rstr != CEED_ELEMRESTRICTION_NONE) {
395f815fac9SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetType(elem_rstr, &rstr_type));
3964b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size));
3974b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp));
3984b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetData(elem_rstr, &rstr_data));
3994b3e95d5SJeremy L Thompson   }
4004b3e95d5SJeremy L Thompson   CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_field, &eval_mode));
4014b3e95d5SJeremy L Thompson 
4024b3e95d5SJeremy L Thompson   // Restriction
4034b3e95d5SJeremy L Thompson   if (is_input) {
4044b3e95d5SJeremy L Thompson     // Input
405e93651e5SJeremy L Thompson     if (field_input_buffer[i] != i) {
406e93651e5SJeremy L Thompson       std::string buffer_name = "r_e_in_" + std::to_string(field_input_buffer[i]);
407e93651e5SJeremy L Thompson 
408e93651e5SJeremy L Thompson       // Restriction was already done for previous input
409e93651e5SJeremy L Thompson       code << "    CeedScalar *r_e" << var_suffix << " = " << buffer_name << ";\n";
4103a2968d6SJeremy L Thompson     } else if (eval_mode != CEED_EVAL_WEIGHT && !((eval_mode == CEED_EVAL_NONE) && use_3d_slices && is_at_points)) {
4113a2968d6SJeremy L Thompson       if (eval_mode == CEED_EVAL_NONE && rstr_type != CEED_RESTRICTION_POINTS) {
412e93651e5SJeremy L Thompson         // No basis action, so r_e_in_* in also r_q_in_* and needs to be allocated
4134b3e95d5SJeremy L Thompson         code << "    CeedScalar r_e" << var_suffix << "[num_comp" << var_suffix << "*" << P_name << "];\n";
4143a2968d6SJeremy L Thompson       } else if (rstr_type != CEED_RESTRICTION_POINTS) {
415e93651e5SJeremy L Thompson         // Otherwise we're using the scratch space
416e93651e5SJeremy L Thompson         code << "    CeedScalar *r_e" << var_suffix << " = r_e_scratch;\n";
417e93651e5SJeremy L Thompson       }
418f815fac9SJeremy L Thompson       switch (rstr_type) {
419f815fac9SJeremy L Thompson         case CEED_RESTRICTION_STANDARD: {
4204b3e95d5SJeremy L Thompson           CeedInt comp_stride;
4214b3e95d5SJeremy L Thompson 
4224b3e95d5SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionGetLVectorSize(elem_rstr, &l_size));
4234b3e95d5SJeremy L Thompson           code << "    const CeedInt l_size" << var_suffix << " = " << l_size << ";\n";
4244b3e95d5SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionGetCompStride(elem_rstr, &comp_stride));
4254b3e95d5SJeremy L Thompson           code << "    // CompStride: " << comp_stride << "\n";
4264b3e95d5SJeremy L Thompson           data->indices.inputs[i] = (CeedInt *)rstr_data->d_offsets;
427*74398b5aSJeremy L Thompson           code << "    ReadLVecStandard" << (is_all_tensor ? max_dim : 1) << "d<num_comp" << var_suffix << ", " << comp_stride << ", " << P_name
4289123fb08SJeremy L Thompson                << ">(data, l_size" << var_suffix << ", elem, indices.inputs[" << i << "], d" << var_suffix << ", r_e" << var_suffix << ");\n";
429f815fac9SJeremy L Thompson           break;
430f815fac9SJeremy L Thompson         }
431f815fac9SJeremy L Thompson         case CEED_RESTRICTION_STRIDED: {
4324b3e95d5SJeremy L Thompson           bool    has_backend_strides;
4334b3e95d5SJeremy L Thompson           CeedInt num_elem;
4344b3e95d5SJeremy L Thompson 
4354b3e95d5SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionHasBackendStrides(elem_rstr, &has_backend_strides));
4364b3e95d5SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionGetNumElements(elem_rstr, &num_elem));
4374b3e95d5SJeremy L Thompson           CeedInt strides[3] = {1, elem_size * num_elem, elem_size};
4384b3e95d5SJeremy L Thompson 
4394b3e95d5SJeremy L Thompson           if (!has_backend_strides) {
4404b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionGetStrides(elem_rstr, strides));
4414b3e95d5SJeremy L Thompson           }
4424b3e95d5SJeremy L Thompson           code << "    // Strides: {" << strides[0] << ", " << strides[1] << ", " << strides[2] << "}\n";
443*74398b5aSJeremy L Thompson           code << "    ReadLVecStrided" << (is_all_tensor ? max_dim : 1) << "d<num_comp" << var_suffix << ", " << P_name << ", " << strides[0] << ", "
4449123fb08SJeremy L Thompson                << strides[1] << ", " << strides[2] << ">(data, elem, d" << var_suffix << ", r_e" << var_suffix << ");\n";
445f815fac9SJeremy L Thompson           break;
446f815fac9SJeremy L Thompson         }
4473a2968d6SJeremy L Thompson         case CEED_RESTRICTION_POINTS: {
4483a2968d6SJeremy L Thompson           CeedInt comp_stride;
4493a2968d6SJeremy L Thompson 
4503a2968d6SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionGetCompStride(elem_rstr, &comp_stride));
4513a2968d6SJeremy L Thompson           code << "    const CeedInt comp_stride" << var_suffix << " = " << comp_stride << ";\n";
4523a2968d6SJeremy L Thompson           data->indices.inputs[i] = (CeedInt *)rstr_data->d_offsets;
4533a2968d6SJeremy L Thompson           break;
4543a2968d6SJeremy L Thompson         }
455f815fac9SJeremy L Thompson         // LCOV_EXCL_START
456f815fac9SJeremy L Thompson         case CEED_RESTRICTION_ORIENTED:
457f815fac9SJeremy L Thompson         case CEED_RESTRICTION_CURL_ORIENTED:
458f815fac9SJeremy L Thompson           break;  // TODO: Not implemented
459f815fac9SJeremy L Thompson                   // LCOV_EXCL_STOP
4604b3e95d5SJeremy L Thompson       }
4614b3e95d5SJeremy L Thompson     }
4624b3e95d5SJeremy L Thompson   } else {
4634b3e95d5SJeremy L Thompson     // Output
464f815fac9SJeremy L Thompson     switch (rstr_type) {
465f815fac9SJeremy L Thompson       case CEED_RESTRICTION_STANDARD: {
4664b3e95d5SJeremy L Thompson         CeedInt comp_stride;
4674b3e95d5SJeremy L Thompson 
4684b3e95d5SJeremy L Thompson         CeedCallBackend(CeedElemRestrictionGetLVectorSize(elem_rstr, &l_size));
4694b3e95d5SJeremy L Thompson         code << "    const CeedInt l_size" << var_suffix << " = " << l_size << ";\n";
4704b3e95d5SJeremy L Thompson         CeedCallBackend(CeedElemRestrictionGetCompStride(elem_rstr, &comp_stride));
4714b3e95d5SJeremy L Thompson         code << "    // CompStride: " << comp_stride << "\n";
4724b3e95d5SJeremy L Thompson         data->indices.outputs[i] = (CeedInt *)rstr_data->d_offsets;
473*74398b5aSJeremy L Thompson         code << "    WriteLVecStandard" << (is_all_tensor ? max_dim : 1) << "d<num_comp" << var_suffix << ", " << comp_stride << ", " << P_name
4749123fb08SJeremy L Thompson              << ">(data, l_size" << var_suffix << ", elem, indices.outputs[" << i << "], r_e" << var_suffix << ", d" << var_suffix << ");\n";
475f815fac9SJeremy L Thompson         break;
476f815fac9SJeremy L Thompson       }
477f815fac9SJeremy L Thompson       case CEED_RESTRICTION_STRIDED: {
4784b3e95d5SJeremy L Thompson         bool    has_backend_strides;
4794b3e95d5SJeremy L Thompson         CeedInt num_elem;
4804b3e95d5SJeremy L Thompson 
4814b3e95d5SJeremy L Thompson         CeedCallBackend(CeedElemRestrictionHasBackendStrides(elem_rstr, &has_backend_strides));
4824b3e95d5SJeremy L Thompson         CeedCallBackend(CeedElemRestrictionGetNumElements(elem_rstr, &num_elem));
4834b3e95d5SJeremy L Thompson         CeedInt strides[3] = {1, elem_size * num_elem, elem_size};
4844b3e95d5SJeremy L Thompson 
4854b3e95d5SJeremy L Thompson         if (!has_backend_strides) {
4864b3e95d5SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionGetStrides(elem_rstr, strides));
4874b3e95d5SJeremy L Thompson         }
4884b3e95d5SJeremy L Thompson         code << "    // Strides: {" << strides[0] << ", " << strides[1] << ", " << strides[2] << "}\n";
489*74398b5aSJeremy L Thompson         code << "    WriteLVecStrided" << (is_all_tensor ? max_dim : 1) << "d<num_comp" << var_suffix << ", " << P_name << ", " << strides[0] << ", "
4909123fb08SJeremy L Thompson              << strides[1] << ", " << strides[2] << ">(data, elem, r_e" << var_suffix << ", d" << var_suffix << ");\n";
491f815fac9SJeremy L Thompson         break;
492f815fac9SJeremy L Thompson       }
4933a2968d6SJeremy L Thompson       case CEED_RESTRICTION_POINTS:
4943a2968d6SJeremy L Thompson         data->indices.outputs[i] = (CeedInt *)rstr_data->d_offsets;
4953a2968d6SJeremy L Thompson         break;
496f815fac9SJeremy L Thompson       // LCOV_EXCL_START
497f815fac9SJeremy L Thompson       case CEED_RESTRICTION_ORIENTED:
498f815fac9SJeremy L Thompson       case CEED_RESTRICTION_CURL_ORIENTED:
499f815fac9SJeremy L Thompson         break;  // TODO: Not implemented
500f815fac9SJeremy L Thompson                 // LCOV_EXCL_STOP
5014b3e95d5SJeremy L Thompson     }
5024b3e95d5SJeremy L Thompson   }
5033a2968d6SJeremy L Thompson   CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
5044b3e95d5SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5054b3e95d5SJeremy L Thompson }
5064b3e95d5SJeremy L Thompson 
5074b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
5084b3e95d5SJeremy L Thompson // Basis
5094b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
510*74398b5aSJeremy L Thompson static int CeedOperatorBuildKernelBasis_Hip_gen(std::ostringstream &code, CeedOperator_Hip_gen *data, CeedInt i, CeedOperatorField op_field,
511*74398b5aSJeremy L Thompson                                                 CeedQFunctionField qf_field, CeedInt max_dim, CeedInt Q_1d, bool is_input, bool is_all_tensor,
5123a2968d6SJeremy L Thompson                                                 bool is_at_points, bool use_3d_slices) {
513*74398b5aSJeremy L Thompson   bool      is_tensor = true;
514*74398b5aSJeremy L Thompson   CeedBasis basis;
515*74398b5aSJeremy L Thompson   CeedCallBackend(CeedOperatorFieldGetBasis(op_field, &basis));
516*74398b5aSJeremy L Thompson   CeedCallBackend(CeedBasisIsTensor(basis, &is_tensor));
517*74398b5aSJeremy L Thompson 
5184b3e95d5SJeremy L Thompson   std::string         var_suffix = (is_input ? "_in_" : "_out_") + std::to_string(i);
5199123fb08SJeremy L Thompson   std::string         P_name = (is_tensor ? "P_1d" : "P") + var_suffix, Q_name = is_tensor ? "Q_1d" : "Q";
5204b3e95d5SJeremy L Thompson   CeedEvalMode        eval_mode = CEED_EVAL_NONE;
521*74398b5aSJeremy L Thompson   CeedInt             dim = max_dim, elem_size = 0, num_comp = 0, P_1d = 0;
5224b3e95d5SJeremy L Thompson   CeedElemRestriction elem_rstr;
5234b3e95d5SJeremy L Thompson 
5244b3e95d5SJeremy L Thompson   // Get field data
5254b3e95d5SJeremy L Thompson   CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_field, &elem_rstr));
5264b3e95d5SJeremy L Thompson   if (elem_rstr != CEED_ELEMRESTRICTION_NONE) {
5274b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size));
5284b3e95d5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp));
5294b3e95d5SJeremy L Thompson   }
5303a2968d6SJeremy L Thompson   CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
5314b3e95d5SJeremy L Thompson   if (basis != CEED_BASIS_NONE) {
532*74398b5aSJeremy L Thompson     CeedCallBackend(CeedBasisGetDimension(basis, &dim));
5339123fb08SJeremy L Thompson     if (is_tensor) CeedCallBackend(CeedBasisGetNumNodes1D(basis, &P_1d));
5349123fb08SJeremy L Thompson     else CeedCallBackend(CeedBasisGetNumNodes(basis, &P_1d));
5354b3e95d5SJeremy L Thompson   }
5364b3e95d5SJeremy L Thompson   CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_field, &eval_mode));
5374b3e95d5SJeremy L Thompson 
5384b3e95d5SJeremy L Thompson   // Basis
5394b3e95d5SJeremy L Thompson   code << "    // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
5404b3e95d5SJeremy L Thompson   if (is_input) {
5414b3e95d5SJeremy L Thompson     switch (eval_mode) {
5424b3e95d5SJeremy L Thompson       case CEED_EVAL_NONE:
5433a2968d6SJeremy L Thompson         if (!use_3d_slices && !is_at_points) {
5444b3e95d5SJeremy L Thompson           code << "    CeedScalar *r_q" << var_suffix << " = r_e" << var_suffix << ";\n";
5454b3e95d5SJeremy L Thompson         }
5464b3e95d5SJeremy L Thompson         break;
5474b3e95d5SJeremy L Thompson       case CEED_EVAL_INTERP:
5483a2968d6SJeremy L Thompson         if (is_at_points) {
5499123fb08SJeremy L Thompson           std::string function_name = (dim == 1 ? "Interp" : "InterpTensor") + std::to_string(dim) + "d";
5509123fb08SJeremy L Thompson 
5519123fb08SJeremy L Thompson           code << "    CeedScalar r_c" << var_suffix << "[num_comp" << var_suffix << "*" << (dim >= 3 ? Q_name : "1") << "];\n";
5526b92dc4bSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", OP_T_1D>(data, r_e" << var_suffix
5536b92dc4bSJeremy L Thompson                << ", s_B" << var_suffix << ", r_c" << var_suffix << ");\n";
5543a2968d6SJeremy L Thompson         } else {
555*74398b5aSJeremy L Thompson           std::string function_name = is_tensor
556*74398b5aSJeremy L Thompson                                           ? ((dim == 1 ? "Interp" : "InterpTensor") + std::to_string(dim) + "d" + (is_all_tensor ? "" : "Flattened"))
557*74398b5aSJeremy L Thompson                                           : "InterpNonTensor";
558*74398b5aSJeremy L Thompson           std::string op_t_1d_name  = (is_all_tensor || !is_tensor) ? "OP_T_1D" : (P_1d > Q_1d ? P_name : Q_name);
5599123fb08SJeremy L Thompson 
560*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*" << (is_all_tensor && (dim >= 3) ? Q_name : "1") << "];\n";
561*74398b5aSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", " << op_t_1d_name << ">(data, r_e"
562*74398b5aSJeremy L Thompson                << var_suffix << ", s_B" << var_suffix << ", r_q" << var_suffix << ");\n";
5633a2968d6SJeremy L Thompson         }
5644b3e95d5SJeremy L Thompson         break;
5654b3e95d5SJeremy L Thompson       case CEED_EVAL_GRAD:
5663a2968d6SJeremy L Thompson         if (is_at_points) {
5679123fb08SJeremy L Thompson           std::string function_name = (dim == 1 ? "Interp" : "InterpTensor") + std::to_string(dim) + "d";
5689123fb08SJeremy L Thompson 
5699123fb08SJeremy L Thompson           code << "    CeedScalar r_c" << var_suffix << "[num_comp" << var_suffix << "*" << (dim >= 3 ? Q_name : "1") << "];\n";
5706b92dc4bSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", OP_T_1D>(data, r_e" << var_suffix
5716b92dc4bSJeremy L Thompson                << ", s_B" << var_suffix << ", r_c" << var_suffix << ");\n";
5723a2968d6SJeremy L Thompson         } else if (use_3d_slices) {
5739123fb08SJeremy L Thompson           std::string function_name = (dim > 1 ? "InterpTensor" : "Interp") + std::to_string(dim) + "d";
5749123fb08SJeremy L Thompson 
5754b3e95d5SJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*" << Q_name << "];\n";
5766b92dc4bSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", OP_T_1D>(data, r_e" << var_suffix
5776b92dc4bSJeremy L Thompson                << ", s_B" << var_suffix << ", r_q" << var_suffix << ");\n";
5789123fb08SJeremy L Thompson         } else if (is_tensor) {
5799123fb08SJeremy L Thompson           bool        is_collocated = dim == 3 && Q_1d >= P_1d;
580*74398b5aSJeremy L Thompson           std::string function_name = (dim == 1 ? "Grad" : (is_collocated ? "GradTensorCollocated" : "GradTensor")) + std::to_string(dim) + "d" +
581*74398b5aSJeremy L Thompson                                       (is_all_tensor ? "" : "Flattened");
582*74398b5aSJeremy L Thompson           std::string op_t_1d_name = is_all_tensor ? "OP_T_1D" : (P_1d > Q_1d ? P_name : Q_name);
5839123fb08SJeremy L Thompson 
584*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "*"
585*74398b5aSJeremy L Thompson                << (is_all_tensor && dim >= 3 ? Q_name : "1") << "];\n";
586*74398b5aSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", " << op_t_1d_name << ">(data, r_e"
587*74398b5aSJeremy L Thompson                << var_suffix << ", s_B" << var_suffix << ", s_G" << var_suffix << ", r_q" << var_suffix << ");\n";
5884b3e95d5SJeremy L Thompson         } else {
5899123fb08SJeremy L Thompson           std::string function_name = "GradNonTensor";
5909123fb08SJeremy L Thompson 
591*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "];\n";
592*74398b5aSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", dim" << var_suffix << ", " << P_name << ", " << Q_name
593*74398b5aSJeremy L Thompson                << ", OP_T_1D>(data, r_e" << var_suffix << ", s_G" << var_suffix << ", r_q" << var_suffix << ");\n";
5944b3e95d5SJeremy L Thompson         }
5954b3e95d5SJeremy L Thompson         break;
5964b3e95d5SJeremy L Thompson       case CEED_EVAL_WEIGHT: {
5973a2968d6SJeremy L Thompson         if (is_at_points) {
5983a2968d6SJeremy L Thompson           code << "    // Nothing to do AtPoints\n";
5993a2968d6SJeremy L Thompson         } else {
6004b3e95d5SJeremy L Thompson           CeedBasis_Hip_shared *basis_data;
601*74398b5aSJeremy L Thompson           std::string           function_name = is_tensor
602*74398b5aSJeremy L Thompson                                                     ? ((dim == 1 ? "Weight" : "WeightTensor") + std::to_string(dim) + "d" + (is_all_tensor ? "" : "Flattened"))
603*74398b5aSJeremy L Thompson                                                     : "WeightNonTensor";
6044b3e95d5SJeremy L Thompson 
605*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[" << (is_all_tensor && (dim >= 3) ? Q_name : "1") << "];\n";
6064b3e95d5SJeremy L Thompson           CeedCallBackend(CeedBasisGetData(basis, &basis_data));
6074b3e95d5SJeremy L Thompson           data->W = basis_data->d_q_weight_1d;
608343e3094SJeremy L Thompson           code << "    " << function_name << "<" << P_name << ", " << Q_name << ">(data, W, r_q" << var_suffix << ");\n";
6093a2968d6SJeremy L Thompson         }
6104b3e95d5SJeremy L Thompson         break;
6114b3e95d5SJeremy L Thompson       }
6124b3e95d5SJeremy L Thompson       // LCOV_EXCL_START
6134b3e95d5SJeremy L Thompson       case CEED_EVAL_DIV:
6144b3e95d5SJeremy L Thompson       case CEED_EVAL_CURL:
6154b3e95d5SJeremy L Thompson         break;  // TODO: Not implemented
6164b3e95d5SJeremy L Thompson                 // LCOV_EXCL_STOP
6174b3e95d5SJeremy L Thompson     }
6184b3e95d5SJeremy L Thompson   } else {
6194b3e95d5SJeremy L Thompson     switch (eval_mode) {
6204b3e95d5SJeremy L Thompson       case CEED_EVAL_NONE:
6214b3e95d5SJeremy L Thompson         code << "    CeedScalar *r_e" << var_suffix << " = r_q" << var_suffix << ";\n";
6224b3e95d5SJeremy L Thompson         break;  // No action
6234b3e95d5SJeremy L Thompson       case CEED_EVAL_INTERP:
624e93651e5SJeremy L Thompson         code << "    CeedScalar *r_e" << var_suffix << " = r_e_scratch;\n";
6253a2968d6SJeremy L Thompson         if (is_at_points) {
6269123fb08SJeremy L Thompson           std::string function_name = (dim == 1 ? "InterpTranspose" : "InterpTransposeTensor") + std::to_string(dim) + "d";
6279123fb08SJeremy L Thompson 
6286b92dc4bSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", OP_T_1D>(data, r_c" << var_suffix
6296b92dc4bSJeremy L Thompson                << ", s_B" << var_suffix << ", r_e" << var_suffix << ");\n";
6303a2968d6SJeremy L Thompson         } else {
6319123fb08SJeremy L Thompson           std::string function_name =
632*74398b5aSJeremy L Thompson               is_tensor ? ((dim == 1 ? "InterpTranspose" : "InterpTransposeTensor") + std::to_string(dim) + "d" + (is_all_tensor ? "" : "Flattened"))
633*74398b5aSJeremy L Thompson                         : "InterpTransposeNonTensor";
634*74398b5aSJeremy L Thompson           std::string op_t_1d_name = (is_all_tensor || !is_tensor) ? "OP_T_1D" : (P_1d > Q_1d ? P_name : Q_name);
6359123fb08SJeremy L Thompson 
636*74398b5aSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", " << op_t_1d_name << ">(data, r_q"
637*74398b5aSJeremy L Thompson                << var_suffix << ", s_B" << var_suffix << ", r_e" << var_suffix << ");\n";
6383a2968d6SJeremy L Thompson         }
6394b3e95d5SJeremy L Thompson         break;
6404b3e95d5SJeremy L Thompson       case CEED_EVAL_GRAD:
641e93651e5SJeremy L Thompson         code << "    CeedScalar *r_e" << var_suffix << " = r_e_scratch;\n";
6423a2968d6SJeremy L Thompson         if (is_at_points) {
6439123fb08SJeremy L Thompson           std::string function_name = (dim == 1 ? "InterpTranspose" : "InterpTransposeTensor") + std::to_string(dim) + "d";
6449123fb08SJeremy L Thompson 
6456b92dc4bSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", OP_T_1D>(data, r_c" << var_suffix
6466b92dc4bSJeremy L Thompson                << ", s_B" << var_suffix << ", r_e" << var_suffix << ");\n";
6473a2968d6SJeremy L Thompson         } else if (use_3d_slices) {
6489123fb08SJeremy L Thompson           std::string function_name = (dim == 1 ? "InterpTranspose" : "InterpTransposeTensor") + std::to_string(dim) + "d";
6499123fb08SJeremy L Thompson 
6506b92dc4bSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", OP_T_1D>(data, r_q" << var_suffix
6516b92dc4bSJeremy L Thompson                << ", s_B" << var_suffix << ", r_e" << var_suffix << ");\n";
6529123fb08SJeremy L Thompson         } else if (is_tensor) {
6539123fb08SJeremy L Thompson           bool        is_collocated = dim == 3 && Q_1d >= P_1d;
654*74398b5aSJeremy L Thompson           std::string function_name = (dim == 1 ? "GradTranspose" : (is_collocated ? "GradTransposeTensorCollocated" : "GradTransposeTensor")) +
655*74398b5aSJeremy L Thompson                                       std::to_string(dim) + "d" + (is_all_tensor ? "" : "Flattened");
656*74398b5aSJeremy L Thompson           std::string op_t_1d_name = is_all_tensor ? "OP_T_1D" : (P_1d > Q_1d ? P_name : Q_name);
6579123fb08SJeremy L Thompson 
658*74398b5aSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", " << P_name << ", " << Q_name << ", " << op_t_1d_name << ">(data, r_q"
659*74398b5aSJeremy L Thompson                << var_suffix << ", s_B" << var_suffix << ", s_G" << var_suffix << ", r_e" << var_suffix << ");\n";
6604b3e95d5SJeremy L Thompson         } else {
6619123fb08SJeremy L Thompson           std::string function_name = "GradTransposeNonTensor";
6629123fb08SJeremy L Thompson 
663*74398b5aSJeremy L Thompson           code << "    " << function_name << "<num_comp" << var_suffix << ", dim" << var_suffix << ", " << P_name << ", " << Q_name
664*74398b5aSJeremy L Thompson                << ", OP_T_1D>(data, r_q" << var_suffix << ", s_G" << var_suffix << ", r_e" << var_suffix << ");\n";
6654b3e95d5SJeremy L Thompson         }
6664b3e95d5SJeremy L Thompson         break;
6674b3e95d5SJeremy L Thompson       // LCOV_EXCL_START
6684b3e95d5SJeremy L Thompson       case CEED_EVAL_WEIGHT:
6694b3e95d5SJeremy L Thompson         break;  // Should not occur
6704b3e95d5SJeremy L Thompson       case CEED_EVAL_DIV:
6714b3e95d5SJeremy L Thompson       case CEED_EVAL_CURL:
6724b3e95d5SJeremy L Thompson         break;  // TODO: Not implemented
6734b3e95d5SJeremy L Thompson                 // LCOV_EXCL_STOP
6744b3e95d5SJeremy L Thompson     }
6754b3e95d5SJeremy L Thompson   }
6763a2968d6SJeremy L Thompson   CeedCallBackend(CeedBasisDestroy(&basis));
6774b3e95d5SJeremy L Thompson   return CEED_ERROR_SUCCESS;
6784b3e95d5SJeremy L Thompson }
6794b3e95d5SJeremy L Thompson 
6804b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
6814b3e95d5SJeremy L Thompson // QFunction
6824b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
683*74398b5aSJeremy L Thompson static int CeedOperatorBuildKernelQFunction_Hip_gen(std::ostringstream &code, CeedOperator_Hip_gen *data, CeedInt max_dim, CeedInt max_num_points,
6843a2968d6SJeremy L Thompson                                                     CeedInt num_input_fields, CeedOperatorField *op_input_fields, CeedQFunctionField *qf_input_fields,
6854b3e95d5SJeremy L Thompson                                                     CeedInt num_output_fields, CeedOperatorField *op_output_fields,
686*74398b5aSJeremy L Thompson                                                     CeedQFunctionField *qf_output_fields, std::string qfunction_name, CeedInt Q_1d,
687*74398b5aSJeremy L Thompson                                                     bool is_all_tensor, bool is_at_points, bool use_3d_slices) {
688*74398b5aSJeremy L Thompson   std::string         Q_name    = is_all_tensor ? "Q_1d" : "Q";
6894b3e95d5SJeremy L Thompson   CeedEvalMode        eval_mode = CEED_EVAL_NONE;
6904b3e95d5SJeremy L Thompson   CeedElemRestriction elem_rstr;
6914b3e95d5SJeremy L Thompson 
6928b97b69aSJeremy L Thompson   // Setup output arrays
6934b3e95d5SJeremy L Thompson   code << "\n    // -- Output field setup\n";
6944b3e95d5SJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
69559fa3f92SJeremy L Thompson     const char *field_name;
6964b3e95d5SJeremy L Thompson     std::string var_suffix = "_out_" + std::to_string(i);
6974b3e95d5SJeremy L Thompson 
69859fa3f92SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
69959fa3f92SJeremy L Thompson     code << "    // ---- Output field " << i << ": " << field_name << "\n";
7004b3e95d5SJeremy L Thompson     CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
7013a2968d6SJeremy L Thompson     switch (eval_mode) {
7023a2968d6SJeremy L Thompson       case CEED_EVAL_NONE:
7033a2968d6SJeremy L Thompson         if (is_at_points) {
7043a2968d6SJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "];\n";
7053a2968d6SJeremy L Thompson         } else {
706*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*" << (is_all_tensor && (max_dim >= 3) ? Q_name : "1")
707*74398b5aSJeremy L Thompson                << "];\n";
7084b3e95d5SJeremy L Thompson         }
7093a2968d6SJeremy L Thompson         break;
7103a2968d6SJeremy L Thompson       case CEED_EVAL_INTERP:
7113a2968d6SJeremy L Thompson         if (is_at_points) {
7123a2968d6SJeremy L Thompson           // Accumulator for point data
713*74398b5aSJeremy L Thompson           code << "    CeedScalar r_c" << var_suffix << "[num_comp" << var_suffix << "*" << (max_dim >= 3 ? Q_name : "1") << "];\n";
714*74398b5aSJeremy L Thompson           code << "    for (CeedInt i = 0; i < num_comp" << var_suffix << "*" << (max_dim >= 3 ? Q_name : "1") << "; i++) {\n";
7153a2968d6SJeremy L Thompson           code << "      r_c" << var_suffix << "[i] = 0.0;\n";
7163a2968d6SJeremy L Thompson           code << "    }\n";
7173a2968d6SJeremy L Thompson         } else {
718*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*" << (is_all_tensor && (max_dim >= 3) ? Q_name : "1")
719*74398b5aSJeremy L Thompson                << "];\n";
7203a2968d6SJeremy L Thompson         }
7213a2968d6SJeremy L Thompson         break;
7223a2968d6SJeremy L Thompson       case CEED_EVAL_GRAD:
7233a2968d6SJeremy L Thompson         if (is_at_points) {
7243a2968d6SJeremy L Thompson           // Accumulator for point data
725*74398b5aSJeremy L Thompson           code << "    CeedScalar r_c" << var_suffix << "[num_comp" << var_suffix << "*" << (max_dim >= 3 ? Q_name : "1") << "*dim" << var_suffix
726*74398b5aSJeremy L Thompson                << "];\n";
727*74398b5aSJeremy L Thompson           code << "    for (CeedInt i = 0; i < num_comp" << var_suffix << "*" << (max_dim >= 3 ? Q_name : "1") << "; i++) {\n";
7283a2968d6SJeremy L Thompson           code << "      r_c" << var_suffix << "[i] = 0.0;\n";
7293a2968d6SJeremy L Thompson           code << "    }\n";
7303a2968d6SJeremy L Thompson         } else if (use_3d_slices) {
7314b3e95d5SJeremy L Thompson           // Accumulator for gradient slices
7324b3e95d5SJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*" << Q_name << "];\n";
7334b3e95d5SJeremy L Thompson           code << "    for (CeedInt i = 0; i < num_comp" << var_suffix << "*" << Q_name << "; i++) {\n";
7344b3e95d5SJeremy L Thompson           code << "      r_q" << var_suffix << "[i] = 0.0;\n";
7354b3e95d5SJeremy L Thompson           code << "    }\n";
7364b3e95d5SJeremy L Thompson         } else {
737*74398b5aSJeremy L Thompson           code << "    CeedScalar r_q" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "*"
738*74398b5aSJeremy L Thompson                << (is_all_tensor && (max_dim >= 3) ? Q_name : "1") << "];\n";
7394b3e95d5SJeremy L Thompson         }
7403a2968d6SJeremy L Thompson         break;
7413a2968d6SJeremy L Thompson       case CEED_EVAL_WEIGHT:
7423a2968d6SJeremy L Thompson         break;
7433a2968d6SJeremy L Thompson         // LCOV_EXCL_START
7443a2968d6SJeremy L Thompson       case CEED_EVAL_DIV:
7453a2968d6SJeremy L Thompson       case CEED_EVAL_CURL:
7463a2968d6SJeremy L Thompson         break;  // TODO: Not implemented
7473a2968d6SJeremy L Thompson                 // LCOV_EXCL_STOP
7484b3e95d5SJeremy L Thompson     }
7494b3e95d5SJeremy L Thompson   }
7504b3e95d5SJeremy L Thompson 
7513a2968d6SJeremy L Thompson   if (is_at_points) {
7523a2968d6SJeremy L Thompson     // We need to handle batches of points
7533a2968d6SJeremy L Thompson     code << "\n    // Note: Using batches of points\n";
7543a2968d6SJeremy L Thompson     code << "    const CeedInt point_loop_bound = (blockDim.x * blockDim.y) * ceil(1.0 * max_num_points / (blockDim.x * blockDim.y));\n\n";
7553a2968d6SJeremy L Thompson     code << "    #pragma unroll\n";
7563a2968d6SJeremy L Thompson     code << "    for (CeedInt i = threadIdx.x + threadIdx.y * blockDim.x; i < point_loop_bound; i += blockDim.x * blockDim.y) {\n";
7573a2968d6SJeremy L Thompson     code << "      const CeedInt p = i % max_num_points;\n\n";
7583a2968d6SJeremy L Thompson 
7593a2968d6SJeremy L Thompson     code << "      // -- Coordinates\n";
760*74398b5aSJeremy L Thompson     code << "      CeedScalar r_x[max_dim];\n";
761*74398b5aSJeremy L Thompson     code << "      ReadPoint<max_dim, coords_comp_stride, max_num_points>(data, elem, p, max_num_points, points.indices, points.coords, r_x);\n\n";
7623a2968d6SJeremy L Thompson 
7633a2968d6SJeremy L Thompson     code << "      // -- Input fields\n";
7643a2968d6SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
76559fa3f92SJeremy L Thompson       const char *field_name;
7663a2968d6SJeremy L Thompson       std::string var_suffix = "_in_" + std::to_string(i);
767f725b54bSJeremy L Thompson       std::string P_name     = "P_1d" + var_suffix;
7683a2968d6SJeremy L Thompson 
76959fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
77059fa3f92SJeremy L Thompson       code << "      // ---- Input field " << i << ": " << field_name << "\n";
7713a2968d6SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
7723a2968d6SJeremy L Thompson       // Basis action
7733a2968d6SJeremy L Thompson       code << "      // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
7743a2968d6SJeremy L Thompson       switch (eval_mode) {
7753a2968d6SJeremy L Thompson         case CEED_EVAL_NONE:
7763a2968d6SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
7773a2968d6SJeremy L Thompson           code << "      ReadPoint<num_comp" << var_suffix << ", comp_stride" << var_suffix
7783a2968d6SJeremy L Thompson                << ", max_num_points>(data, elem, p, max_num_points, indices.inputs[" << i << "], d" << var_suffix << ", r_s" << var_suffix << ");\n";
7793a2968d6SJeremy L Thompson           break;
7803a2968d6SJeremy L Thompson         case CEED_EVAL_INTERP:
7813a2968d6SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
782*74398b5aSJeremy L Thompson           code << "      InterpAtPoints" << max_dim << "d<num_comp" << var_suffix << ", max_num_points, " << P_name << ", " << Q_name
783*74398b5aSJeremy L Thompson                << ">(data, i, r_c" << var_suffix << ", r_x, r_s" << var_suffix << ");\n";
7843a2968d6SJeremy L Thompson           break;
7853a2968d6SJeremy L Thompson         case CEED_EVAL_GRAD:
786*74398b5aSJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "];\n";
787*74398b5aSJeremy L Thompson           code << "      GradAtPoints" << max_dim << "d<num_comp" << var_suffix << ", max_num_points, " << P_name << ", " << Q_name
788*74398b5aSJeremy L Thompson                << ">(data, i, r_c" << var_suffix << ", r_x, r_s" << var_suffix << ");\n";
7893a2968d6SJeremy L Thompson           break;
7903a2968d6SJeremy L Thompson         case CEED_EVAL_WEIGHT:
7913a2968d6SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[1];\n";
7923a2968d6SJeremy L Thompson           code << "      r_s" << var_suffix << "[0] = 1.0;\n";
7933a2968d6SJeremy L Thompson           break;
7943a2968d6SJeremy L Thompson           // LCOV_EXCL_START
7953a2968d6SJeremy L Thompson         case CEED_EVAL_DIV:
7963a2968d6SJeremy L Thompson         case CEED_EVAL_CURL:
7973a2968d6SJeremy L Thompson           break;  // TODO: Not implemented
7983a2968d6SJeremy L Thompson                   // LCOV_EXCL_STOP
7993a2968d6SJeremy L Thompson       }
8003a2968d6SJeremy L Thompson     }
8013a2968d6SJeremy L Thompson     code << "\n      // -- Output fields\n";
8023a2968d6SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
80359fa3f92SJeremy L Thompson       const char *field_name;
8043a2968d6SJeremy L Thompson       std::string var_suffix = "_out_" + std::to_string(i);
8053a2968d6SJeremy L Thompson 
80659fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
80759fa3f92SJeremy L Thompson       code << "      // ---- Output field " << i << ": " << field_name << "\n";
8083a2968d6SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
8093a2968d6SJeremy L Thompson       // Basis action
8103a2968d6SJeremy L Thompson       switch (eval_mode) {
8113a2968d6SJeremy L Thompson         case CEED_EVAL_NONE:
8123a2968d6SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
8133a2968d6SJeremy L Thompson           break;
8143a2968d6SJeremy L Thompson         case CEED_EVAL_INTERP:
8153a2968d6SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
8163a2968d6SJeremy L Thompson           break;
8173a2968d6SJeremy L Thompson         case CEED_EVAL_GRAD:
818*74398b5aSJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "];\n";
8193a2968d6SJeremy L Thompson           break;
8203a2968d6SJeremy L Thompson           // LCOV_EXCL_START
8213a2968d6SJeremy L Thompson         case CEED_EVAL_WEIGHT:
8223a2968d6SJeremy L Thompson           break;  // Should not occur
8233a2968d6SJeremy L Thompson         case CEED_EVAL_DIV:
8243a2968d6SJeremy L Thompson         case CEED_EVAL_CURL:
8253a2968d6SJeremy L Thompson           break;  // TODO: Not implemented
8263a2968d6SJeremy L Thompson                   // LCOV_EXCL_STOP
8273a2968d6SJeremy L Thompson       }
8283a2968d6SJeremy L Thompson     }
8293a2968d6SJeremy L Thompson 
8303a2968d6SJeremy L Thompson   } else if (use_3d_slices) {
8314b3e95d5SJeremy L Thompson     // We treat quadrature points per slice in 3d to save registers
8324b3e95d5SJeremy L Thompson     code << "\n    // Note: Using planes of 3D elements\n";
8334b3e95d5SJeremy L Thompson     code << "    #pragma unroll\n";
8344b3e95d5SJeremy L Thompson     code << "    for (CeedInt q = 0; q < " << Q_name << "; q++) {\n";
8354b3e95d5SJeremy L Thompson     code << "      // -- Input fields\n";
8364b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
83759fa3f92SJeremy L Thompson       const char *field_name;
8384b3e95d5SJeremy L Thompson       std::string var_suffix = "_in_" + std::to_string(i);
8394b3e95d5SJeremy L Thompson 
84059fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
84159fa3f92SJeremy L Thompson       code << "      // ---- Input field " << i << ": " << field_name << "\n";
8424b3e95d5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
8434b3e95d5SJeremy L Thompson       // Basis action
8444b3e95d5SJeremy L Thompson       code << "      // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
8454b3e95d5SJeremy L Thompson       switch (eval_mode) {
8464b3e95d5SJeremy L Thompson         case CEED_EVAL_NONE:
8474b3e95d5SJeremy L Thompson           bool is_strided;
8484b3e95d5SJeremy L Thompson 
8494b3e95d5SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
8504b3e95d5SJeremy L Thompson 
8514b3e95d5SJeremy L Thompson           CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr));
8524b3e95d5SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionIsStrided(elem_rstr, &is_strided));
8534b3e95d5SJeremy L Thompson           if (is_strided) {
8544b3e95d5SJeremy L Thompson             bool    has_backend_strides;
8554b3e95d5SJeremy L Thompson             CeedInt num_elem, elem_size;
8564b3e95d5SJeremy L Thompson 
8574b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size));
8584b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionHasBackendStrides(elem_rstr, &has_backend_strides));
8594b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionGetNumElements(elem_rstr, &num_elem));
8604b3e95d5SJeremy L Thompson             CeedInt strides[3] = {1, elem_size * num_elem, elem_size};
8614b3e95d5SJeremy L Thompson 
8624b3e95d5SJeremy L Thompson             if (!has_backend_strides) {
8634b3e95d5SJeremy L Thompson               CeedCallBackend(CeedElemRestrictionGetStrides(elem_rstr, strides));
8644b3e95d5SJeremy L Thompson             }
8654b3e95d5SJeremy L Thompson             code << "      // Strides: {" << strides[0] << ", " << strides[1] << ", " << strides[2] << "}\n";
866f815fac9SJeremy L Thompson             code << "      ReadEVecSliceStrided3d<num_comp" << var_suffix << ", " << Q_name << ", " << strides[0] << ", " << strides[1] << ", "
8674b3e95d5SJeremy L Thompson                  << strides[2] << ">(data, elem, q, d" << var_suffix << ", r_s" << var_suffix << ");\n";
8684b3e95d5SJeremy L Thompson           } else {
8694b3e95d5SJeremy L Thompson             CeedSize                 l_size = 0;
8704b3e95d5SJeremy L Thompson             CeedInt                  comp_stride;
8714b3e95d5SJeremy L Thompson             CeedElemRestriction_Hip *rstr_data;
8724b3e95d5SJeremy L Thompson 
8734b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionGetLVectorSize(elem_rstr, &l_size));
8744b3e95d5SJeremy L Thompson             code << "      const CeedInt l_size" << var_suffix << " = " << l_size << ";\n";
8754b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionGetCompStride(elem_rstr, &comp_stride));
8764b3e95d5SJeremy L Thompson             code << "      // CompStride: " << comp_stride << "\n";
8774b3e95d5SJeremy L Thompson             CeedCallBackend(CeedElemRestrictionGetData(elem_rstr, &rstr_data));
8784b3e95d5SJeremy L Thompson             data->indices.inputs[i] = (CeedInt *)rstr_data->d_offsets;
879f815fac9SJeremy L Thompson             code << "      ReadEVecSliceStandard3d<num_comp" << var_suffix << ", " << comp_stride << ", " << Q_name << ">(data, l_size" << var_suffix
8804b3e95d5SJeremy L Thompson                  << ", elem, q, indices.inputs[" << i << "], d" << var_suffix << ", r_s" << var_suffix << ");\n";
8814b3e95d5SJeremy L Thompson           }
8829123fb08SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
8834b3e95d5SJeremy L Thompson           break;
8844b3e95d5SJeremy L Thompson         case CEED_EVAL_INTERP:
8854b3e95d5SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
8864b3e95d5SJeremy L Thompson           code << "      for (CeedInt j = 0; j < num_comp" << var_suffix << "; j++) {\n";
8874b3e95d5SJeremy L Thompson           code << "        r_s" << var_suffix << "[j] = r_q" << var_suffix << "[q + j*" << Q_name << "];\n";
8884b3e95d5SJeremy L Thompson           code << "      }\n";
8894b3e95d5SJeremy L Thompson           break;
8904b3e95d5SJeremy L Thompson         case CEED_EVAL_GRAD:
891*74398b5aSJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "];\n";
8926b92dc4bSJeremy L Thompson           code << "      GradColloSlice3d<num_comp" << var_suffix << ", " << Q_name << ", OP_T_1D>(data, q, r_q" << var_suffix << ", s_G"
8936b92dc4bSJeremy L Thompson                << var_suffix << ", r_s" << var_suffix << ");\n";
8944b3e95d5SJeremy L Thompson           break;
8954b3e95d5SJeremy L Thompson         case CEED_EVAL_WEIGHT:
8964b3e95d5SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[1];\n";
8974b3e95d5SJeremy L Thompson           code << "      r_s" << var_suffix << "[0] = r_q" << var_suffix << "[q];\n";
8983a2968d6SJeremy L Thompson           break;
8994b3e95d5SJeremy L Thompson           // LCOV_EXCL_START
9004b3e95d5SJeremy L Thompson         case CEED_EVAL_DIV:
9014b3e95d5SJeremy L Thompson         case CEED_EVAL_CURL:
9024b3e95d5SJeremy L Thompson           break;  // TODO: Not implemented
9034b3e95d5SJeremy L Thompson                   // LCOV_EXCL_STOP
9044b3e95d5SJeremy L Thompson       }
9054b3e95d5SJeremy L Thompson     }
9064b3e95d5SJeremy L Thompson     code << "\n      // -- Output fields\n";
9074b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
90859fa3f92SJeremy L Thompson       const char *field_name;
9094b3e95d5SJeremy L Thompson       std::string var_suffix = "_out_" + std::to_string(i);
9104b3e95d5SJeremy L Thompson 
91159fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
91259fa3f92SJeremy L Thompson       code << "      // ---- Output field " << i << ": " << field_name << "\n";
9134b3e95d5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
9144b3e95d5SJeremy L Thompson       // Basis action
9154b3e95d5SJeremy L Thompson       switch (eval_mode) {
9164b3e95d5SJeremy L Thompson         case CEED_EVAL_NONE:
9174b3e95d5SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
9183a2968d6SJeremy L Thompson           break;
9194b3e95d5SJeremy L Thompson         case CEED_EVAL_INTERP:
9204b3e95d5SJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "];\n";
9214b3e95d5SJeremy L Thompson           break;
9224b3e95d5SJeremy L Thompson         case CEED_EVAL_GRAD:
923*74398b5aSJeremy L Thompson           code << "      CeedScalar r_s" << var_suffix << "[num_comp" << var_suffix << "*dim" << var_suffix << "];\n";
9244b3e95d5SJeremy L Thompson           break;
9254b3e95d5SJeremy L Thompson           // LCOV_EXCL_START
9264b3e95d5SJeremy L Thompson         case CEED_EVAL_WEIGHT:
9274b3e95d5SJeremy L Thompson           break;  // Should not occur
9284b3e95d5SJeremy L Thompson         case CEED_EVAL_DIV:
9294b3e95d5SJeremy L Thompson         case CEED_EVAL_CURL:
9304b3e95d5SJeremy L Thompson           break;  // TODO: Not implemented
9314b3e95d5SJeremy L Thompson                   // LCOV_EXCL_STOP
9324b3e95d5SJeremy L Thompson       }
9334b3e95d5SJeremy L Thompson     }
9344b3e95d5SJeremy L Thompson   } else {
9354b3e95d5SJeremy L Thompson     code << "\n    // Note: Using full elements\n";
9364b3e95d5SJeremy L Thompson     code << "    {\n";
9374b3e95d5SJeremy L Thompson     code << "      // -- Input fields\n";
9384b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
93959fa3f92SJeremy L Thompson       const char *field_name;
94059fa3f92SJeremy L Thompson 
94159fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
94259fa3f92SJeremy L Thompson       code << "      // ---- Input field " << i << ": " << field_name << "\n";
9434b3e95d5SJeremy L Thompson       code << "      CeedScalar *r_s_in_" << i << " = r_q_in_" << i << ";\n";
9444b3e95d5SJeremy L Thompson     }
9454b3e95d5SJeremy L Thompson     code << "      // -- Output fields\n";
9464b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
94759fa3f92SJeremy L Thompson       const char *field_name;
94859fa3f92SJeremy L Thompson 
94959fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
95059fa3f92SJeremy L Thompson       code << "      // ---- Output field " << i << ": " << field_name << "\n";
9514b3e95d5SJeremy L Thompson       code << "      CeedScalar *r_s_out_" << i << " = r_q_out_" << i << ";\n";
9524b3e95d5SJeremy L Thompson     }
9534b3e95d5SJeremy L Thompson   }
9544b3e95d5SJeremy L Thompson 
9554b3e95d5SJeremy L Thompson   // Input and output buffers
9564b3e95d5SJeremy L Thompson   code << "\n      // -- QFunction inputs and outputs\n";
9574b3e95d5SJeremy L Thompson   code << "      // ---- Inputs\n";
9584b3e95d5SJeremy L Thompson   code << "      CeedScalar *inputs[" << CeedIntMax(num_input_fields, 1) << "];\n";
9594b3e95d5SJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
96059fa3f92SJeremy L Thompson     const char *field_name;
96159fa3f92SJeremy L Thompson 
96259fa3f92SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
96359fa3f92SJeremy L Thompson     code << "      // ------ Input field " << i << ": " << field_name << "\n";
9644b3e95d5SJeremy L Thompson     code << "      inputs[" << i << "] = r_s_in_" << i << ";\n";
9654b3e95d5SJeremy L Thompson   }
9664b3e95d5SJeremy L Thompson   code << "      // ---- Outputs\n";
9674b3e95d5SJeremy L Thompson   code << "      CeedScalar *outputs[" << CeedIntMax(num_output_fields, 1) << "];\n";
9684b3e95d5SJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
96959fa3f92SJeremy L Thompson     const char *field_name;
97059fa3f92SJeremy L Thompson 
97159fa3f92SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
97259fa3f92SJeremy L Thompson     code << "      // ------ Output field " << i << ": " << field_name << "\n";
9734b3e95d5SJeremy L Thompson     code << "      outputs[" << i << "] = r_s_out_" << i << ";\n";
9744b3e95d5SJeremy L Thompson   }
9754b3e95d5SJeremy L Thompson 
9764b3e95d5SJeremy L Thompson   // Apply QFunction
9774b3e95d5SJeremy L Thompson   code << "\n      // -- Apply QFunction\n";
9784b3e95d5SJeremy L Thompson   code << "      " << qfunction_name << "(ctx, ";
979*74398b5aSJeremy L Thompson   if (max_dim != 3 || is_at_points || use_3d_slices || !is_all_tensor) {
9804b3e95d5SJeremy L Thompson     code << "1";
9814b3e95d5SJeremy L Thompson   } else {
9829123fb08SJeremy L Thompson     code << Q_name;
9834b3e95d5SJeremy L Thompson   }
9844b3e95d5SJeremy L Thompson   code << ", inputs, outputs);\n";
9854b3e95d5SJeremy L Thompson 
9863a2968d6SJeremy L Thompson   if (is_at_points) {
9873a2968d6SJeremy L Thompson     // Map back to coefficients
9883a2968d6SJeremy L Thompson     code << "\n      // -- Output fields\n";
9893a2968d6SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
99059fa3f92SJeremy L Thompson       const char *field_name;
9913a2968d6SJeremy L Thompson       std::string var_suffix = "_out_" + std::to_string(i);
9923a2968d6SJeremy L Thompson       std::string P_name     = "P_1d" + var_suffix;
9933a2968d6SJeremy L Thompson 
99459fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
99559fa3f92SJeremy L Thompson       code << "      // ---- Output field " << i << ": " << field_name << "\n";
9963a2968d6SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
9973a2968d6SJeremy L Thompson       // Basis action
9983a2968d6SJeremy L Thompson       code << "      // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
9993a2968d6SJeremy L Thompson       switch (eval_mode) {
10003a2968d6SJeremy L Thompson         case CEED_EVAL_NONE: {
10013a2968d6SJeremy L Thompson           CeedInt             comp_stride;
10023a2968d6SJeremy L Thompson           CeedElemRestriction elem_rstr;
10033a2968d6SJeremy L Thompson 
10043a2968d6SJeremy L Thompson           CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr));
10053a2968d6SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionGetCompStride(elem_rstr, &comp_stride));
10063a2968d6SJeremy L Thompson           CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
10073a2968d6SJeremy L Thompson           code << "      const CeedInt comp_stride" << var_suffix << " = " << comp_stride << ";\n";
10083a2968d6SJeremy L Thompson           code << "      WritePoint<num_comp" << var_suffix << ", comp_stride" << var_suffix
10093a2968d6SJeremy L Thompson                << ", max_num_points>(data, elem, i, points.num_per_elem[elem], indices.outputs[" << i << "]"
10103a2968d6SJeremy L Thompson                << ", r_s" << var_suffix << ", d" << var_suffix << ");\n";
10113a2968d6SJeremy L Thompson           break;
10123a2968d6SJeremy L Thompson         }
10133a2968d6SJeremy L Thompson         case CEED_EVAL_INTERP:
10143a2968d6SJeremy L Thompson           code << "      if (i >= points.num_per_elem[elem]) {\n";
10153a2968d6SJeremy L Thompson           code << "        for (CeedInt j = 0; j < num_comp" << var_suffix << "; j++) r_s" << var_suffix << "[j] = 0.0;\n";
10163a2968d6SJeremy L Thompson           code << "      }\n";
1017*74398b5aSJeremy L Thompson           code << "      InterpTransposeAtPoints" << max_dim << "d<num_comp" << var_suffix << ", max_num_points, " << P_name << ", " << Q_name
1018f725b54bSJeremy L Thompson                << ">(data, i, r_s" << var_suffix << ", r_x, r_c" << var_suffix << ");\n";
10193a2968d6SJeremy L Thompson           break;
10203a2968d6SJeremy L Thompson         case CEED_EVAL_GRAD:
10213a2968d6SJeremy L Thompson           code << "      if (i >= points.num_per_elem[elem]) {\n";
1022*74398b5aSJeremy L Thompson           code << "        for (CeedInt j = 0; j < num_comp" << var_suffix << "*dim" << var_suffix << "; j++) r_s" << var_suffix << "[j] = 0.0;\n";
10233a2968d6SJeremy L Thompson           code << "      }\n";
1024*74398b5aSJeremy L Thompson           code << "      GradTransposeAtPoints" << max_dim << "d<num_comp" << var_suffix << ", max_num_points, " << P_name << ", " << Q_name
1025f725b54bSJeremy L Thompson                << ">(data, i, r_s" << var_suffix << ", r_x, r_c" << var_suffix << ");\n";
10263a2968d6SJeremy L Thompson           break;
10273a2968d6SJeremy L Thompson           // LCOV_EXCL_START
10283a2968d6SJeremy L Thompson         case CEED_EVAL_WEIGHT:
10293a2968d6SJeremy L Thompson           break;  // Should not occur
10303a2968d6SJeremy L Thompson         case CEED_EVAL_DIV:
10313a2968d6SJeremy L Thompson         case CEED_EVAL_CURL:
10323a2968d6SJeremy L Thompson           break;  // TODO: Not implemented
10333a2968d6SJeremy L Thompson                   // LCOV_EXCL_STOP
10343a2968d6SJeremy L Thompson       }
10353a2968d6SJeremy L Thompson     }
10363a2968d6SJeremy L Thompson   } else if (use_3d_slices) {
10374b3e95d5SJeremy L Thompson     // Copy or apply transpose grad, if needed
10383a2968d6SJeremy L Thompson     code << "\n      // -- Output fields\n";
10394b3e95d5SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
104059fa3f92SJeremy L Thompson       const char *field_name;
10414b3e95d5SJeremy L Thompson       std::string var_suffix = "_out_" + std::to_string(i);
10424b3e95d5SJeremy L Thompson       std::string P_name     = "P_1d" + var_suffix;
10434b3e95d5SJeremy L Thompson 
104459fa3f92SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
104559fa3f92SJeremy L Thompson       code << "      // ---- Output field " << i << ": " << field_name << "\n";
10464b3e95d5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
10474b3e95d5SJeremy L Thompson       // Basis action
10484b3e95d5SJeremy L Thompson       code << "      // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
10494b3e95d5SJeremy L Thompson       switch (eval_mode) {
10504b3e95d5SJeremy L Thompson         case CEED_EVAL_NONE:
10514b3e95d5SJeremy L Thompson           code << "      for (CeedInt j = 0; j < num_comp" << var_suffix << " ; j++) {\n";
10524b3e95d5SJeremy L Thompson           code << "        r_q" << var_suffix << "[q + j*" << Q_name << "] = r_s" << var_suffix << "[j];\n";
10534b3e95d5SJeremy L Thompson           code << "      }\n";
10543a2968d6SJeremy L Thompson           break;
10554b3e95d5SJeremy L Thompson         case CEED_EVAL_INTERP:
10564b3e95d5SJeremy L Thompson           code << "      for (CeedInt j = 0; j < num_comp" << var_suffix << " ; j++) {\n";
10574b3e95d5SJeremy L Thompson           code << "        r_q" << var_suffix << "[q + j*" << Q_name << "] = r_s" << var_suffix << "[j];\n";
10584b3e95d5SJeremy L Thompson           code << "      }\n";
10594b3e95d5SJeremy L Thompson           break;
10604b3e95d5SJeremy L Thompson         case CEED_EVAL_GRAD:
10616b92dc4bSJeremy L Thompson           code << "      GradColloSliceTranspose3d<num_comp" << var_suffix << ", " << Q_name << ", OP_T_1D>(data, q, r_s" << var_suffix << ", s_G"
1062f815fac9SJeremy L Thompson                << var_suffix << ", r_q" << var_suffix << ");\n";
10634b3e95d5SJeremy L Thompson           break;
10644b3e95d5SJeremy L Thompson           // LCOV_EXCL_START
10654b3e95d5SJeremy L Thompson         case CEED_EVAL_WEIGHT:
10664b3e95d5SJeremy L Thompson           break;  // Should not occur
10674b3e95d5SJeremy L Thompson         case CEED_EVAL_DIV:
10684b3e95d5SJeremy L Thompson         case CEED_EVAL_CURL:
10694b3e95d5SJeremy L Thompson           break;  // TODO: Not implemented
10704b3e95d5SJeremy L Thompson                   // LCOV_EXCL_STOP
10714b3e95d5SJeremy L Thompson       }
10724b3e95d5SJeremy L Thompson     }
10734b3e95d5SJeremy L Thompson   }
10744b3e95d5SJeremy L Thompson   code << "    }\n";
10754b3e95d5SJeremy L Thompson   return CEED_ERROR_SUCCESS;
10764b3e95d5SJeremy L Thompson }
10774b3e95d5SJeremy L Thompson 
10784b3e95d5SJeremy L Thompson //------------------------------------------------------------------------------
10799e201c85SYohann // Build single operator kernel
10807d8d0e25Snbeams //------------------------------------------------------------------------------
10818d12f40eSJeremy L Thompson extern "C" int CeedOperatorBuildKernel_Hip_gen(CeedOperator op, bool *is_good_build) {
1082*74398b5aSJeremy L Thompson   bool                   is_all_tensor = true, is_all_nontensor = true, is_at_points = false, use_3d_slices = false;
10837d8d0e25Snbeams   Ceed                   ceed;
1084*74398b5aSJeremy L Thompson   CeedInt                Q, Q_1d, num_input_fields, num_output_fields, max_dim = 1, max_num_points = 0, coords_comp_stride = 0;
1085b7453713SJeremy L Thompson   CeedQFunctionField    *qf_input_fields, *qf_output_fields;
1086b7453713SJeremy L Thompson   CeedQFunction_Hip_gen *qf_data;
1087b7453713SJeremy L Thompson   CeedQFunction          qf;
1088b7453713SJeremy L Thompson   CeedOperatorField     *op_input_fields, *op_output_fields;
1089b7453713SJeremy L Thompson   CeedOperator_Hip_gen  *data;
10904b3e95d5SJeremy L Thompson   std::ostringstream     code;
10914b3e95d5SJeremy L Thompson 
10928d12f40eSJeremy L Thompson   CeedCallBackend(CeedOperatorGetData(op, &data));
10934b3e95d5SJeremy L Thompson   {
10944b3e95d5SJeremy L Thompson     bool is_setup_done;
1095b7453713SJeremy L Thompson 
1096b7453713SJeremy L Thompson     CeedCallBackend(CeedOperatorIsSetupDone(op, &is_setup_done));
10978d12f40eSJeremy L Thompson     if (is_setup_done) {
10988d12f40eSJeremy L Thompson       *is_good_build = !data->use_fallback;
10998d12f40eSJeremy L Thompson       return CEED_ERROR_SUCCESS;
11008d12f40eSJeremy L Thompson     }
11014b3e95d5SJeremy L Thompson   }
1102b7453713SJeremy L Thompson 
11038d12f40eSJeremy L Thompson   // Check field compatibility
11048d12f40eSJeremy L Thompson   CeedCallBackend(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields));
11058d12f40eSJeremy L Thompson   {
1106*74398b5aSJeremy L Thompson     bool has_shared_bases = true;
11078d12f40eSJeremy L Thompson 
11088d12f40eSJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
11098d12f40eSJeremy L Thompson       CeedBasis basis;
11108d12f40eSJeremy L Thompson 
11118d12f40eSJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis));
11128d12f40eSJeremy L Thompson       if (basis != CEED_BASIS_NONE) {
11138d12f40eSJeremy L Thompson         bool        is_tensor = true;
11148d12f40eSJeremy L Thompson         const char *resource;
11158d12f40eSJeremy L Thompson         char       *resource_root;
11168d12f40eSJeremy L Thompson         Ceed        basis_ceed;
11178d12f40eSJeremy L Thompson 
11188d12f40eSJeremy L Thompson         CeedCallBackend(CeedBasisIsTensor(basis, &is_tensor));
1119c9192acaSJeremy L Thompson         is_all_tensor    = is_all_tensor && is_tensor;
1120c9192acaSJeremy L Thompson         is_all_nontensor = is_all_nontensor && !is_tensor;
11218d12f40eSJeremy L Thompson         CeedCallBackend(CeedBasisGetCeed(basis, &basis_ceed));
11228d12f40eSJeremy L Thompson         CeedCallBackend(CeedGetResource(basis_ceed, &resource));
11238d12f40eSJeremy L Thompson         CeedCallBackend(CeedGetResourceRoot(basis_ceed, resource, ":", &resource_root));
1124c9192acaSJeremy L Thompson         has_shared_bases = has_shared_bases && !strcmp(resource_root, "/gpu/hip/shared");
11258d12f40eSJeremy L Thompson         CeedCallBackend(CeedFree(&resource_root));
11268d12f40eSJeremy L Thompson         CeedCallBackend(CeedDestroy(&basis_ceed));
11278d12f40eSJeremy L Thompson       }
11288d12f40eSJeremy L Thompson       CeedCallBackend(CeedBasisDestroy(&basis));
11298d12f40eSJeremy L Thompson     }
11308d12f40eSJeremy L Thompson 
11318d12f40eSJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
11328d12f40eSJeremy L Thompson       CeedBasis basis;
11338d12f40eSJeremy L Thompson 
11348d12f40eSJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis));
11358d12f40eSJeremy L Thompson       if (basis != CEED_BASIS_NONE) {
11368d12f40eSJeremy L Thompson         bool        is_tensor = true;
11378d12f40eSJeremy L Thompson         const char *resource;
11388d12f40eSJeremy L Thompson         char       *resource_root;
11398d12f40eSJeremy L Thompson         Ceed        basis_ceed;
11408d12f40eSJeremy L Thompson 
11418d12f40eSJeremy L Thompson         CeedCallBackend(CeedBasisIsTensor(basis, &is_tensor));
1142c9192acaSJeremy L Thompson         is_all_tensor    = is_all_tensor && is_tensor;
1143c9192acaSJeremy L Thompson         is_all_nontensor = is_all_nontensor && !is_tensor;
11448d12f40eSJeremy L Thompson 
11458d12f40eSJeremy L Thompson         CeedCallBackend(CeedBasisGetCeed(basis, &basis_ceed));
11468d12f40eSJeremy L Thompson         CeedCallBackend(CeedGetResource(basis_ceed, &resource));
11478d12f40eSJeremy L Thompson         CeedCallBackend(CeedGetResourceRoot(basis_ceed, resource, ":", &resource_root));
1148c9192acaSJeremy L Thompson         has_shared_bases = has_shared_bases && !strcmp(resource_root, "/gpu/hip/shared");
11498d12f40eSJeremy L Thompson         CeedCallBackend(CeedFree(&resource_root));
11508d12f40eSJeremy L Thompson         CeedCallBackend(CeedDestroy(&basis_ceed));
11518d12f40eSJeremy L Thompson       }
11528d12f40eSJeremy L Thompson       CeedCallBackend(CeedBasisDestroy(&basis));
11538d12f40eSJeremy L Thompson     }
11548d12f40eSJeremy L Thompson     // -- Fallback to ref if not all bases are shared
1155*74398b5aSJeremy L Thompson     if (!has_shared_bases) {
11568d12f40eSJeremy L Thompson       *is_good_build = false;
11578d12f40eSJeremy L Thompson       return CEED_ERROR_SUCCESS;
11588d12f40eSJeremy L Thompson     }
11598d12f40eSJeremy L Thompson   }
1160b7453713SJeremy L Thompson   CeedCallBackend(CeedOperatorGetCeed(op, &ceed));
1161b7453713SJeremy L Thompson   CeedCallBackend(CeedOperatorGetQFunction(op, &qf));
1162b7453713SJeremy L Thompson   CeedCallBackend(CeedQFunctionGetData(qf, &qf_data));
1163b7453713SJeremy L Thompson   CeedCallBackend(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields));
11647d8d0e25Snbeams 
11654b3e95d5SJeremy L Thompson   // Get operator data
11663a2968d6SJeremy L Thompson   CeedCallBackend(CeedOperatorIsAtPoints(op, &is_at_points));
1167*74398b5aSJeremy L Thompson   {
1168*74398b5aSJeremy L Thompson     CeedInt max_P, max_P_1d;
1169*74398b5aSJeremy L Thompson 
11704b3e95d5SJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelData_Hip_gen(ceed, num_input_fields, op_input_fields, qf_input_fields, num_output_fields, op_output_fields,
1171*74398b5aSJeremy L Thompson                                                         qf_output_fields, &max_P, &max_P_1d, &Q, &Q_1d, &max_dim, &is_all_tensor, &use_3d_slices));
1172*74398b5aSJeremy L Thompson     data->max_P_1d = is_all_tensor ? max_P_1d : max_P;
1173*74398b5aSJeremy L Thompson   }
1174*74398b5aSJeremy L Thompson   if (max_dim == 0) max_dim = 1;
1175*74398b5aSJeremy L Thompson   data->dim = max_dim;
11763a2968d6SJeremy L Thompson   if (is_at_points) {
11773a2968d6SJeremy L Thompson     CeedElemRestriction_Hip *rstr_data;
11783a2968d6SJeremy L Thompson     CeedElemRestriction      rstr_points = NULL;
11794b3e95d5SJeremy L Thompson 
11803a2968d6SJeremy L Thompson     CeedCallBackend(CeedOperatorAtPointsGetPoints(op, &rstr_points, NULL));
11813a2968d6SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetMaxPointsInElement(rstr_points, &max_num_points));
11823a2968d6SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetCompStride(rstr_points, &coords_comp_stride));
11833a2968d6SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetData(rstr_points, &rstr_data));
11843a2968d6SJeremy L Thompson     data->points.indices = (CeedInt *)rstr_data->d_offsets;
11853a2968d6SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionDestroy(&rstr_points));
11863a2968d6SJeremy L Thompson   }
11873a2968d6SJeremy L Thompson   if (is_at_points) use_3d_slices = false;
11883a2968d6SJeremy L Thompson   if (Q_1d == 0) {
11893a2968d6SJeremy L Thompson     if (is_at_points) Q_1d = max_num_points;
11903a2968d6SJeremy L Thompson     else CeedCallBackend(CeedOperatorGetNumQuadraturePoints(op, &Q_1d));
11914b3e95d5SJeremy L Thompson   }
1192*74398b5aSJeremy L Thompson   if (Q == 0) Q = Q_1d;
1193*74398b5aSJeremy L Thompson   data->Q    = Q;
11944b3e95d5SJeremy L Thompson   data->Q_1d = Q_1d;
11954b3e95d5SJeremy L Thompson 
11960b454692Sjeremylt   // Check for restriction only identity operator
11974b3e95d5SJeremy L Thompson   {
11984b3e95d5SJeremy L Thompson     bool is_identity_qf;
11994b3e95d5SJeremy L Thompson 
12002b730f8bSJeremy L Thompson     CeedCallBackend(CeedQFunctionIsIdentity(qf, &is_identity_qf));
12010b454692Sjeremylt     if (is_identity_qf) {
12029e201c85SYohann       CeedEvalMode eval_mode_in, eval_mode_out;
1203b7453713SJeremy L Thompson 
12042b730f8bSJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[0], &eval_mode_in));
12052b730f8bSJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[0], &eval_mode_out));
12066574a04fSJeremy L Thompson       CeedCheck(eval_mode_in != CEED_EVAL_NONE || eval_mode_out != CEED_EVAL_NONE, ceed, CEED_ERROR_BACKEND,
12076574a04fSJeremy L Thompson                 "Backend does not implement restriction only identity operators");
12080b454692Sjeremylt     }
12094b3e95d5SJeremy L Thompson   }
1210b2165e7aSSebastian Grimberg 
1211b2165e7aSSebastian Grimberg   // Load basis source files
1212*74398b5aSJeremy L Thompson   if (!is_all_tensor) {
12139c25dd66SJeremy L Thompson     code << "// Tensor basis source\n";
12149c25dd66SJeremy L Thompson     code << "#include <ceed/jit-source/hip/hip-shared-basis-tensor-templates.h>\n\n";
1215*74398b5aSJeremy L Thompson   }
1216*74398b5aSJeremy L Thompson   if (!is_all_tensor) {
12179123fb08SJeremy L Thompson     code << "// Non-tensor basis source\n";
12189123fb08SJeremy L Thompson     code << "#include <ceed/jit-source/hip/hip-shared-basis-nontensor-templates.h>\n\n";
12199123fb08SJeremy L Thompson   }
12209123fb08SJeremy L Thompson   if (is_at_points) {
12213a2968d6SJeremy L Thompson     code << "// AtPoints basis source\n";
12223a2968d6SJeremy L Thompson     code << "#include <ceed/jit-source/hip/hip-shared-basis-tensor-at-points-templates.h>\n\n";
12239123fb08SJeremy L Thompson   }
1224*74398b5aSJeremy L Thompson   if (!is_all_tensor && !is_all_nontensor) {
1225*74398b5aSJeremy L Thompson     code << "// Tensor basis source\n";
1226*74398b5aSJeremy L Thompson     code << "#include <ceed/jit-source/hip/hip-shared-basis-tensor-flattened-templates.h>\n\n";
1227*74398b5aSJeremy L Thompson   }
12289c25dd66SJeremy L Thompson   code << "// CodeGen operator source\n";
12299c25dd66SJeremy L Thompson   code << "#include <ceed/jit-source/hip/hip-gen-templates.h>\n\n";
12307d8d0e25Snbeams 
12314b3e95d5SJeremy L Thompson   // Get QFunction name
12324b3e95d5SJeremy L Thompson   std::string qfunction_name(qf_data->qfunction_name);
12334b3e95d5SJeremy L Thompson   std::string operator_name;
12344b3e95d5SJeremy L Thompson 
123509095acaSJeremy L Thompson   operator_name = "CeedKernelHipGenOperator_" + qfunction_name;
12367d8d0e25Snbeams 
12379e201c85SYohann   // Define CEED_Q_VLA
12389e201c85SYohann   code << "\n#undef CEED_Q_VLA\n";
1239*74398b5aSJeremy L Thompson   if (max_dim != 3 || is_at_points || use_3d_slices || !is_all_tensor) {
12409e201c85SYohann     code << "#define CEED_Q_VLA 1\n\n";
12419e201c85SYohann   } else {
12429e201c85SYohann     code << "#define CEED_Q_VLA " << Q_1d << "\n\n";
12439e201c85SYohann   }
12449e201c85SYohann 
12454b3e95d5SJeremy L Thompson   // Add user QFunction source
12464b3e95d5SJeremy L Thompson   {
12479c25dd66SJeremy L Thompson     const char *source_path;
12484b3e95d5SJeremy L Thompson 
12499c25dd66SJeremy L Thompson     CeedCallBackend(CeedQFunctionGetSourcePath(qf, &source_path));
12509c25dd66SJeremy L Thompson     CeedCheck(source_path, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/hip/gen backend requires QFunction source code file");
12519c25dd66SJeremy L Thompson 
12529c25dd66SJeremy L Thompson     code << "// User QFunction source\n";
12539c25dd66SJeremy L Thompson     code << "#include \"" << source_path << "\"\n\n";
12544b3e95d5SJeremy L Thompson   }
12557d8d0e25Snbeams 
12567d8d0e25Snbeams   // Setup
12577d8d0e25Snbeams   code << "\n// -----------------------------------------------------------------------------\n";
12584b3e95d5SJeremy L Thompson   code << "// Operator Kernel\n";
12594b3e95d5SJeremy L Thompson   code << "// \n";
12604b3e95d5SJeremy L Thompson   code << "// d_[in,out]_i:   CeedVector device array\n";
12614b3e95d5SJeremy L Thompson   code << "// r_[in,out]_e_i: Element vector register\n";
12624b3e95d5SJeremy L Thompson   code << "// r_[in,out]_q_i: Quadrature space vector register\n";
12639123fb08SJeremy L Thompson   code << "// r_[in,out]_c_i: AtPoints Chebyshev coefficients register\n";
12644b3e95d5SJeremy L Thompson   code << "// r_[in,out]_s_i: Quadrature space slice vector register\n";
12654b3e95d5SJeremy L Thompson   code << "// \n";
12664b3e95d5SJeremy L Thompson   code << "// s_B_[in,out]_i: Interpolation matrix, shared memory\n";
12674b3e95d5SJeremy L Thompson   code << "// s_G_[in,out]_i: Gradient matrix, shared memory\n";
12684b3e95d5SJeremy L Thompson   code << "// -----------------------------------------------------------------------------\n";
1269b3e1519bSnbeams   code << "\nextern \"C\" __launch_bounds__(BLOCK_SIZE)\n";
12702b730f8bSJeremy L Thompson   code << "__global__ void " << operator_name
12713a2968d6SJeremy L Thompson        << "(CeedInt num_elem, void* ctx, FieldsInt_Hip indices, Fields_Hip fields, Fields_Hip B, Fields_Hip G, CeedScalar* W, Points_Hip points) {\n";
12724b3e95d5SJeremy L Thompson 
12734b3e95d5SJeremy L Thompson   // Scratch buffers
12749e201c85SYohann   for (CeedInt i = 0; i < num_input_fields; i++) {
12754b3e95d5SJeremy L Thompson     CeedEvalMode eval_mode;
12764b3e95d5SJeremy L Thompson 
12772b730f8bSJeremy L Thompson     CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
12789e201c85SYohann     if (eval_mode != CEED_EVAL_WEIGHT) {  // Skip CEED_EVAL_WEIGHT
1279826538b3SJeremy L Thompson       code << "  const CeedScalar *__restrict__ d_in_" << i << " = fields.inputs[" << i << "];\n";
12807d8d0e25Snbeams     }
12817d8d0e25Snbeams   }
12829e201c85SYohann   for (CeedInt i = 0; i < num_output_fields; i++) {
1283826538b3SJeremy L Thompson     code << "  CeedScalar *__restrict__ d_out_" << i << " = fields.outputs[" << i << "];\n";
12847d8d0e25Snbeams   }
12857d8d0e25Snbeams 
1286*74398b5aSJeremy L Thompson   code << " const CeedInt max_dim = " << max_dim << ";\n";
1287*74398b5aSJeremy L Thompson   if (!is_all_tensor) {
1288*74398b5aSJeremy L Thompson     code << "  const CeedInt Q = " << Q << ";\n";
1289*74398b5aSJeremy L Thompson   }
1290*74398b5aSJeremy L Thompson   if (!is_all_nontensor) {
1291*74398b5aSJeremy L Thompson     code << "  const CeedInt Q_1d = " << Q_1d << ";\n";
1292*74398b5aSJeremy L Thompson   }
12933a2968d6SJeremy L Thompson   if (is_at_points) {
12943a2968d6SJeremy L Thompson     code << "  const CeedInt max_num_points = " << max_num_points << ";\n";
12953a2968d6SJeremy L Thompson     code << "  const CeedInt coords_comp_stride = " << coords_comp_stride << ";\n";
12963a2968d6SJeremy L Thompson   }
12977d8d0e25Snbeams 
12984b3e95d5SJeremy L Thompson   // Shared data
12994b3e95d5SJeremy L Thompson   code << "  extern __shared__ CeedScalar slice[];\n";
13009e201c85SYohann   code << "  SharedData_Hip data;\n";
13019e201c85SYohann   code << "  data.t_id_x = threadIdx.x;\n";
13029e201c85SYohann   code << "  data.t_id_y = threadIdx.y;\n";
13039e201c85SYohann   code << "  data.t_id_z = threadIdx.z;\n";
13049e201c85SYohann   code << "  data.t_id  = threadIdx.x + threadIdx.y*blockDim.x + threadIdx.z*blockDim.y*blockDim.x;\n";
1305*74398b5aSJeremy L Thompson   code << "  data.slice = slice + data.t_id_z*OP_T_1D" << ((!is_all_tensor || max_dim == 1) ? "" : "*OP_T_1D") << ";\n";
13067d8d0e25Snbeams 
13079ee499e5SJeremy L Thompson   // -- Determine input mat reuse
130845a787f7SJeremy L Thompson   FieldReuse_Hip input_matrix_reuse[CEED_FIELD_MAX];
13099ee499e5SJeremy L Thompson 
13109ee499e5SJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
131145a787f7SJeremy L Thompson     input_matrix_reuse[i].index = -1;
13129ee499e5SJeremy L Thompson   }
13139ee499e5SJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
1314*74398b5aSJeremy L Thompson     bool         is_tensor = true;
13159ee499e5SJeremy L Thompson     CeedEvalMode eval_mode_i;
13169ee499e5SJeremy L Thompson     CeedBasis    basis_i;
13179ee499e5SJeremy L Thompson 
13189ee499e5SJeremy L Thompson     CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode_i));
13199ee499e5SJeremy L Thompson     if (eval_mode_i == CEED_EVAL_WEIGHT) continue;
13209ee499e5SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[i], &basis_i));
1321*74398b5aSJeremy L Thompson     CeedCallBackend(CeedBasisIsTensor(basis_i, &is_tensor));
132245a787f7SJeremy L Thompson     for (CeedInt j = 0; (input_matrix_reuse[i].index == -1) && (j < i); j++) {
13239ee499e5SJeremy L Thompson       CeedEvalMode eval_mode_j;
13249ee499e5SJeremy L Thompson       CeedBasis    basis_j;
13259ee499e5SJeremy L Thompson 
13269ee499e5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[j], &eval_mode_j));
13279ee499e5SJeremy L Thompson       if (eval_mode_j == CEED_EVAL_WEIGHT) continue;
13289ee499e5SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[j], &basis_j));
13299ee499e5SJeremy L Thompson       if (basis_i == basis_j) {
13309ee499e5SJeremy L Thompson         if (is_tensor) {
133145a787f7SJeremy L Thompson           input_matrix_reuse[i].index     = j;
133245a787f7SJeremy L Thompson           input_matrix_reuse[i].is_input  = true;
133345a787f7SJeremy L Thompson           input_matrix_reuse[i].eval_mode = eval_mode_j;
13349ee499e5SJeremy L Thompson         } else {
13359ee499e5SJeremy L Thompson           // For non-tensor can only re-use with the same eval mode
13369ee499e5SJeremy L Thompson           if (eval_mode_i == eval_mode_j) {
133745a787f7SJeremy L Thompson             input_matrix_reuse[i].index     = j;
133845a787f7SJeremy L Thompson             input_matrix_reuse[i].is_input  = true;
133945a787f7SJeremy L Thompson             input_matrix_reuse[i].eval_mode = eval_mode_j;
13409ee499e5SJeremy L Thompson           }
13419ee499e5SJeremy L Thompson         }
13429ee499e5SJeremy L Thompson       }
13439ee499e5SJeremy L Thompson       CeedCallBackend(CeedBasisDestroy(&basis_j));
13449ee499e5SJeremy L Thompson     }
13459ee499e5SJeremy L Thompson     CeedCallBackend(CeedBasisDestroy(&basis_i));
13469ee499e5SJeremy L Thompson   }
13479ee499e5SJeremy L Thompson 
13489ee499e5SJeremy L Thompson   // -- Determine output mat reuse
134945a787f7SJeremy L Thompson   FieldReuse_Hip output_matrix_reuse[CEED_FIELD_MAX];
13509ee499e5SJeremy L Thompson 
13519ee499e5SJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
135245a787f7SJeremy L Thompson     output_matrix_reuse[i].index = -1;
13539ee499e5SJeremy L Thompson   }
13549ee499e5SJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
1355*74398b5aSJeremy L Thompson     bool         is_tensor = true;
13569ee499e5SJeremy L Thompson     CeedEvalMode eval_mode_i;
13579ee499e5SJeremy L Thompson     CeedBasis    basis_i;
13589ee499e5SJeremy L Thompson 
13599ee499e5SJeremy L Thompson     CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode_i));
13609ee499e5SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[i], &basis_i));
136145a787f7SJeremy L Thompson     for (CeedInt j = 0; (output_matrix_reuse[i].index == -1) && (j < num_input_fields); j++) {
13629ee499e5SJeremy L Thompson       CeedEvalMode eval_mode_j;
13639ee499e5SJeremy L Thompson       CeedBasis    basis_j;
13649ee499e5SJeremy L Thompson 
13659ee499e5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[j], &eval_mode_j));
13669ee499e5SJeremy L Thompson       if (eval_mode_j == CEED_EVAL_WEIGHT) continue;
13679ee499e5SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetBasis(op_input_fields[j], &basis_j));
13689ee499e5SJeremy L Thompson       if (basis_i == basis_j) {
13699ee499e5SJeremy L Thompson         if (is_tensor) {
137045a787f7SJeremy L Thompson           output_matrix_reuse[i].index     = j;
137145a787f7SJeremy L Thompson           output_matrix_reuse[i].is_input  = true;
137245a787f7SJeremy L Thompson           output_matrix_reuse[i].eval_mode = eval_mode_j;
13739ee499e5SJeremy L Thompson         } else {
13749ee499e5SJeremy L Thompson           // For non-tensor can only re-use with the same eval mode
13759ee499e5SJeremy L Thompson           if (eval_mode_i == eval_mode_j) {
137645a787f7SJeremy L Thompson             output_matrix_reuse[i].index     = j;
137745a787f7SJeremy L Thompson             output_matrix_reuse[i].is_input  = true;
137845a787f7SJeremy L Thompson             output_matrix_reuse[i].eval_mode = eval_mode_j;
13799ee499e5SJeremy L Thompson           }
13809ee499e5SJeremy L Thompson         }
13819ee499e5SJeremy L Thompson       }
13829ee499e5SJeremy L Thompson       CeedCallBackend(CeedBasisDestroy(&basis_j));
13839ee499e5SJeremy L Thompson     }
138445a787f7SJeremy L Thompson     for (CeedInt j = 0; (output_matrix_reuse[i].index == -1) && (j < i); j++) {
13859ee499e5SJeremy L Thompson       CeedEvalMode eval_mode_j;
13869ee499e5SJeremy L Thompson       CeedBasis    basis_j;
13879ee499e5SJeremy L Thompson 
13889ee499e5SJeremy L Thompson       CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[j], &eval_mode_j));
13899ee499e5SJeremy L Thompson       if (eval_mode_j == CEED_EVAL_WEIGHT) continue;
13909ee499e5SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetBasis(op_output_fields[j], &basis_j));
1391*74398b5aSJeremy L Thompson       CeedCallBackend(CeedBasisIsTensor(basis_i, &is_tensor));
13929ee499e5SJeremy L Thompson       if (basis_i == basis_j) {
13939ee499e5SJeremy L Thompson         if (is_tensor) {
139445a787f7SJeremy L Thompson           output_matrix_reuse[i].index     = j;
139545a787f7SJeremy L Thompson           output_matrix_reuse[i].is_input  = false;
139645a787f7SJeremy L Thompson           output_matrix_reuse[i].eval_mode = eval_mode_j;
13979ee499e5SJeremy L Thompson         } else {
13989ee499e5SJeremy L Thompson           // For non-tensor can only re-use with the same eval mode
13999ee499e5SJeremy L Thompson           if (eval_mode_i == eval_mode_j) {
140045a787f7SJeremy L Thompson             output_matrix_reuse[i].index     = j;
140145a787f7SJeremy L Thompson             output_matrix_reuse[i].is_input  = false;
140245a787f7SJeremy L Thompson             output_matrix_reuse[i].eval_mode = eval_mode_j;
14039ee499e5SJeremy L Thompson           }
14049ee499e5SJeremy L Thompson         }
14059ee499e5SJeremy L Thompson       }
14069ee499e5SJeremy L Thompson       CeedCallBackend(CeedBasisDestroy(&basis_j));
14079ee499e5SJeremy L Thompson     }
14089ee499e5SJeremy L Thompson     CeedCallBackend(CeedBasisDestroy(&basis_i));
14099ee499e5SJeremy L Thompson   }
14109ee499e5SJeremy L Thompson 
14117d8d0e25Snbeams   // Initialize constants, and matrices B and G
14124b3e95d5SJeremy L Thompson   code << "\n  // Input field constants and basis data\n";
14139e201c85SYohann   for (CeedInt i = 0; i < num_input_fields; i++) {
1414*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelFieldData_Hip_gen(code, data, i, op_input_fields[i], qf_input_fields[i], input_matrix_reuse[i], max_dim, Q,
1415*74398b5aSJeremy L Thompson                                                              Q_1d, true, is_all_tensor, is_at_points, use_3d_slices));
14167d8d0e25Snbeams   }
14174b3e95d5SJeremy L Thompson   code << "\n  // Output field constants and basis data\n";
14189e201c85SYohann   for (CeedInt i = 0; i < num_output_fields; i++) {
1419*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelFieldData_Hip_gen(code, data, i, op_output_fields[i], qf_output_fields[i], output_matrix_reuse[i], max_dim,
1420*74398b5aSJeremy L Thompson                                                              Q, Q_1d, false, is_all_tensor, is_at_points, use_3d_slices));
14214b3e95d5SJeremy L Thompson   }
14227d8d0e25Snbeams 
14234b3e95d5SJeremy L Thompson   // Loop over all elements
14244b3e95d5SJeremy L Thompson   code << "\n  // Element loop\n";
14257d8d0e25Snbeams   code << "  __syncthreads();\n";
14269e201c85SYohann   code << "  for (CeedInt elem = blockIdx.x*blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x*blockDim.z) {\n";
14274b3e95d5SJeremy L Thompson 
1428e93651e5SJeremy L Thompson   // -- Compute minimum buffer space needed
14293a2968d6SJeremy L Thompson   CeedInt max_rstr_buffer_size = 1;
1430e93651e5SJeremy L Thompson 
1431e93651e5SJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
1432e93651e5SJeremy L Thompson     CeedInt             num_comp, elem_size;
1433e93651e5SJeremy L Thompson     CeedElemRestriction elem_rstr;
1434e93651e5SJeremy L Thompson 
1435e93651e5SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &elem_rstr));
1436e93651e5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp));
1437e93651e5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size));
1438*74398b5aSJeremy L Thompson     max_rstr_buffer_size = CeedIntMax(max_rstr_buffer_size, num_comp * (is_all_tensor && (max_dim >= 3) ? elem_size : 1));
1439681d0ea7SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
1440e93651e5SJeremy L Thompson   }
1441e93651e5SJeremy L Thompson   for (CeedInt i = 0; i < num_output_fields; i++) {
1442e93651e5SJeremy L Thompson     CeedInt             num_comp, elem_size;
1443e93651e5SJeremy L Thompson     CeedElemRestriction elem_rstr;
1444e93651e5SJeremy L Thompson 
1445e93651e5SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &elem_rstr));
1446e93651e5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetNumComponents(elem_rstr, &num_comp));
1447e93651e5SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionGetElementSize(elem_rstr, &elem_size));
1448*74398b5aSJeremy L Thompson     max_rstr_buffer_size = CeedIntMax(max_rstr_buffer_size, num_comp * (is_all_tensor && (max_dim >= 3) ? elem_size : 1));
1449681d0ea7SJeremy L Thompson     CeedCallBackend(CeedElemRestrictionDestroy(&elem_rstr));
1450e93651e5SJeremy L Thompson   }
1451e93651e5SJeremy L Thompson   code << "    // Scratch restriction buffer space\n";
1452e93651e5SJeremy L Thompson   code << "    CeedScalar r_e_scratch[" << max_rstr_buffer_size << "];\n";
1453e93651e5SJeremy L Thompson 
1454e93651e5SJeremy L Thompson   // -- Determine best input field processing order
1455e93651e5SJeremy L Thompson   CeedInt field_rstr_in_buffer[CEED_FIELD_MAX], input_field_order[CEED_FIELD_MAX];
1456e93651e5SJeremy L Thompson 
1457e93651e5SJeremy L Thompson   for (CeedInt i = 0; i < num_input_fields; i++) {
1458e93651e5SJeremy L Thompson     field_rstr_in_buffer[i] = -1;
1459e93651e5SJeremy L Thompson     input_field_order[i]    = -1;
1460e93651e5SJeremy L Thompson   }
1461e93651e5SJeremy L Thompson   {
1462e93651e5SJeremy L Thompson     bool    is_ordered[CEED_FIELD_MAX];
1463e93651e5SJeremy L Thompson     CeedInt curr_index = 0;
1464e93651e5SJeremy L Thompson 
1465e93651e5SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) is_ordered[i] = false;
1466e93651e5SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
1467e93651e5SJeremy L Thompson       CeedVector          vec_i;
1468e93651e5SJeremy L Thompson       CeedElemRestriction rstr_i;
1469e93651e5SJeremy L Thompson 
1470e93651e5SJeremy L Thompson       if (is_ordered[i]) continue;
1471e93651e5SJeremy L Thompson       field_rstr_in_buffer[i]       = i;
1472e93651e5SJeremy L Thompson       is_ordered[i]                 = true;
1473e93651e5SJeremy L Thompson       input_field_order[curr_index] = i;
1474e93651e5SJeremy L Thompson       curr_index++;
1475034f99fdSJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i));
1476e93651e5SJeremy L Thompson       if (vec_i == CEED_VECTOR_NONE) continue;  // CEED_EVAL_WEIGHT
1477e93651e5SJeremy L Thompson       CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr_i));
1478e93651e5SJeremy L Thompson       for (CeedInt j = i + 1; j < num_input_fields; j++) {
1479e93651e5SJeremy L Thompson         CeedVector          vec_j;
1480e93651e5SJeremy L Thompson         CeedElemRestriction rstr_j;
1481e93651e5SJeremy L Thompson 
1482e93651e5SJeremy L Thompson         CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[j], &vec_j));
1483e93651e5SJeremy L Thompson         CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[j], &rstr_j));
1484e93651e5SJeremy L Thompson         if (rstr_i == rstr_j && vec_i == vec_j) {
1485e93651e5SJeremy L Thompson           field_rstr_in_buffer[j]       = i;
1486e93651e5SJeremy L Thompson           is_ordered[j]                 = true;
1487e93651e5SJeremy L Thompson           input_field_order[curr_index] = j;
1488e93651e5SJeremy L Thompson           curr_index++;
1489e93651e5SJeremy L Thompson         }
14903a2968d6SJeremy L Thompson         CeedCallBackend(CeedVectorDestroy(&vec_j));
14913a2968d6SJeremy L Thompson         CeedCallBackend(CeedElemRestrictionDestroy(&rstr_j));
1492e93651e5SJeremy L Thompson       }
14933a2968d6SJeremy L Thompson       CeedCallBackend(CeedVectorDestroy(&vec_i));
14943a2968d6SJeremy L Thompson       CeedCallBackend(CeedElemRestrictionDestroy(&rstr_i));
1495e93651e5SJeremy L Thompson     }
1496e93651e5SJeremy L Thompson   }
1497e93651e5SJeremy L Thompson 
14984b3e95d5SJeremy L Thompson   // -- Input restriction and basis
14993a2968d6SJeremy L Thompson   code << "\n    // -- Input field restrictions and basis actions\n";
15009e201c85SYohann   for (CeedInt i = 0; i < num_input_fields; i++) {
150159fa3f92SJeremy L Thompson     const char   *field_name;
150259fa3f92SJeremy L Thompson     const CeedInt f = input_field_order[i];
1503e93651e5SJeremy L Thompson 
150459fa3f92SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[f], &field_name));
150559fa3f92SJeremy L Thompson     code << "    // ---- Input field " << f << ": " << field_name << "\n";
15067d8d0e25Snbeams 
15074b3e95d5SJeremy L Thompson     // ---- Restriction
1508*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelRestriction_Hip_gen(code, data, f, field_rstr_in_buffer, op_input_fields[f], qf_input_fields[f], max_dim,
1509*74398b5aSJeremy L Thompson                                                                Q_1d, true, is_all_tensor, is_at_points, use_3d_slices));
1510b7453713SJeremy L Thompson 
15114b3e95d5SJeremy L Thompson     // ---- Basis action
1512*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelBasis_Hip_gen(code, data, f, op_input_fields[f], qf_input_fields[f], max_dim, Q_1d, true, is_all_tensor,
15139123fb08SJeremy L Thompson                                                          is_at_points, use_3d_slices));
15147d8d0e25Snbeams   }
15157d8d0e25Snbeams 
15164b3e95d5SJeremy L Thompson   // -- Q function
1517*74398b5aSJeremy L Thompson   CeedCallBackend(CeedOperatorBuildKernelQFunction_Hip_gen(code, data, max_dim, max_num_points, num_input_fields, op_input_fields, qf_input_fields,
1518*74398b5aSJeremy L Thompson                                                            num_output_fields, op_output_fields, qf_output_fields, qfunction_name, Q_1d, is_all_tensor,
15199123fb08SJeremy L Thompson                                                            is_at_points, use_3d_slices));
15207d8d0e25Snbeams 
15214b3e95d5SJeremy L Thompson   // -- Output basis and restriction
15224b3e95d5SJeremy L Thompson   code << "\n    // -- Output field basis action and restrictions\n";
15239e201c85SYohann   for (CeedInt i = 0; i < num_output_fields; i++) {
152459fa3f92SJeremy L Thompson     const char *field_name;
152559fa3f92SJeremy L Thompson 
152659fa3f92SJeremy L Thompson     CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
152759fa3f92SJeremy L Thompson     code << "    // ---- Output field " << i << ": " << field_name << "\n";
1528b7453713SJeremy L Thompson 
15294b3e95d5SJeremy L Thompson     // ---- Basis action
1530*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelBasis_Hip_gen(code, data, i, op_output_fields[i], qf_output_fields[i], max_dim, Q_1d, false, is_all_tensor,
15319123fb08SJeremy L Thompson                                                          is_at_points, use_3d_slices));
15327d8d0e25Snbeams 
15334b3e95d5SJeremy L Thompson     // ---- Restriction
1534*74398b5aSJeremy L Thompson     CeedCallBackend(CeedOperatorBuildKernelRestriction_Hip_gen(code, data, i, NULL, op_output_fields[i], qf_output_fields[i], max_dim, Q_1d, false,
1535*74398b5aSJeremy L Thompson                                                                is_all_tensor, is_at_points, use_3d_slices));
15367d8d0e25Snbeams   }
15377d8d0e25Snbeams 
15384b3e95d5SJeremy L Thompson   // Close loop and function
15397d8d0e25Snbeams   code << "  }\n";
15407d8d0e25Snbeams   code << "}\n";
15417d8d0e25Snbeams   code << "// -----------------------------------------------------------------------------\n\n";
15427d8d0e25Snbeams 
1543539ec17dSJeremy L Thompson   CeedInt block_sizes[3] = {0, 0, 0};
15449e201c85SYohann   CeedInt num_elem;
1545b7453713SJeremy L Thompson 
15463a2968d6SJeremy L Thompson   // Compile
15472b730f8bSJeremy L Thompson   CeedCallBackend(CeedOperatorGetNumElements(op, &num_elem));
1548*74398b5aSJeremy L Thompson   CeedCallBackend(BlockGridCalculate_Hip_gen(is_all_tensor ? max_dim : 1, num_elem, data->max_P_1d, is_all_tensor ? Q_1d : Q, block_sizes));
154990c30374SJeremy L Thompson   if (is_at_points) block_sizes[2] = 1;
15508d12f40eSJeremy L Thompson   {
15518d12f40eSJeremy L Thompson     bool is_compile_good = false;
15528d12f40eSJeremy L Thompson 
15536b92dc4bSJeremy L Thompson     CeedCallBackend(CeedTryCompile_Hip(ceed, code.str().c_str(), &is_compile_good, &data->module, 2, "OP_T_1D", block_sizes[0], "BLOCK_SIZE",
15542b730f8bSJeremy L Thompson                                        block_sizes[0] * block_sizes[1] * block_sizes[2]));
15558d12f40eSJeremy L Thompson     if (is_compile_good) {
15568d12f40eSJeremy L Thompson       *is_good_build = true;
1557eb7e6cafSJeremy L Thompson       CeedCallBackend(CeedGetKernel_Hip(ceed, data->module, operator_name.c_str(), &data->op));
15588d12f40eSJeremy L Thompson     } else {
15598d12f40eSJeremy L Thompson       *is_good_build     = false;
15608d12f40eSJeremy L Thompson       data->use_fallback = true;
15618d12f40eSJeremy L Thompson     }
15628d12f40eSJeremy L Thompson   }
15632b730f8bSJeremy L Thompson   CeedCallBackend(CeedOperatorSetSetupDone(op));
15649bc66399SJeremy L Thompson   CeedCallBackend(CeedDestroy(&ceed));
1565c11e12f4SJeremy L Thompson   CeedCallBackend(CeedQFunctionDestroy(&qf));
1566e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
15677d8d0e25Snbeams }
15682a86cc9dSSebastian Grimberg 
15697d8d0e25Snbeams //------------------------------------------------------------------------------
1570