xref: /libCEED/backends/cuda-gen/ceed-cuda-gen-qfunction.c (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1 // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 #include <ceed.h>
9 #include <ceed/backend.h>
10 #include <cuda_runtime.h>
11 
12 #include "../cuda/ceed-cuda-common.h"
13 #include "ceed-cuda-gen.h"
14 
15 //------------------------------------------------------------------------------
16 // Apply QFunction
17 //------------------------------------------------------------------------------
CeedQFunctionApply_Cuda_gen(CeedQFunction qf,CeedInt Q,CeedVector * U,CeedVector * V)18 static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) {
19   return CeedError(CeedQFunctionReturnCeed(qf), CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
20 }
21 
22 //------------------------------------------------------------------------------
23 // Destroy QFunction
24 //------------------------------------------------------------------------------
CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf)25 static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) {
26   CeedQFunction_Cuda_gen *data;
27 
28   CeedCallBackend(CeedQFunctionGetData(qf, &data));
29   CeedCallCuda(CeedQFunctionReturnCeed(qf), cudaFree(data->d_c));
30   CeedCallBackend(CeedFree(&data));
31   return CEED_ERROR_SUCCESS;
32 }
33 
34 //------------------------------------------------------------------------------
35 // Create QFunction
36 //------------------------------------------------------------------------------
CeedQFunctionCreate_Cuda_gen(CeedQFunction qf)37 int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) {
38   Ceed                    ceed;
39   CeedQFunction_Cuda_gen *data;
40 
41   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
42   CeedCallBackend(CeedCalloc(1, &data));
43   CeedCallBackend(CeedQFunctionSetData(qf, data));
44 
45   CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name));
46 
47   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen));
48   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen));
49   CeedCallBackend(CeedDestroy(&ceed));
50   return CEED_ERROR_SUCCESS;
51 }
52 
53 //------------------------------------------------------------------------------
54