xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-gen/ceed-cuda-gen-qfunction.c (revision 3d3250a08f026bd5a3ff436a992143d30c7d6e16)
1241a4b83SYohann // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2241a4b83SYohann // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3241a4b83SYohann // All Rights reserved. See files LICENSE and NOTICE for details.
4241a4b83SYohann //
5241a4b83SYohann // This file is part of CEED, a collection of benchmarks, miniapps, software
6241a4b83SYohann // libraries and APIs for efficient high-order finite element and spectral
7241a4b83SYohann // element discretizations for exascale applications. For more information and
8241a4b83SYohann // source code availability see http://github.com/ceed.
9241a4b83SYohann //
10241a4b83SYohann // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11241a4b83SYohann // a collaborative effort of two U.S. Department of Energy organizations (Office
12241a4b83SYohann // of Science and the National Nuclear Security Administration) responsible for
13241a4b83SYohann // the planning and preparation of a capable exascale ecosystem, including
14241a4b83SYohann // software, applications, hardware, advanced system engineering and early
15241a4b83SYohann // testbed platforms, in support of the nation's exascale computing imperative.
16241a4b83SYohann 
17ec3da8bcSJed Brown #include <ceed/ceed.h>
18ec3da8bcSJed Brown #include <ceed/backend.h>
193d576824SJeremy L Thompson #include <cuda_runtime.h>
20241a4b83SYohann #include <stdio.h>
213d576824SJeremy L Thompson #include <string.h>
22241a4b83SYohann #include "ceed-cuda-gen.h"
233d576824SJeremy L Thompson #include "../cuda/ceed-cuda.h"
24241a4b83SYohann 
25ab213215SJeremy L Thompson //------------------------------------------------------------------------------
26ab213215SJeremy L Thompson // Apply QFunction
27ab213215SJeremy L Thompson //------------------------------------------------------------------------------
28241a4b83SYohann static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q,
29241a4b83SYohann                                        CeedVector *U, CeedVector *V) {
30241a4b83SYohann   int ierr;
31241a4b83SYohann   Ceed ceed;
32e15f9bd0SJeremy L Thompson   ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr);
33e15f9bd0SJeremy L Thompson   return CeedError(ceed, CEED_ERROR_BACKEND,
34e15f9bd0SJeremy L Thompson                    "Backend does not implement QFunctionApply");
35241a4b83SYohann }
36241a4b83SYohann 
37ab213215SJeremy L Thompson //------------------------------------------------------------------------------
38ab213215SJeremy L Thompson // Destroy QFunction
39ab213215SJeremy L Thompson //------------------------------------------------------------------------------
40241a4b83SYohann static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) {
41241a4b83SYohann   int ierr;
42241a4b83SYohann   CeedQFunction_Cuda_gen *data;
43e15f9bd0SJeremy L Thompson   ierr = CeedQFunctionGetData(qf, &data); CeedChkBackend(ierr);
44241a4b83SYohann   Ceed ceed;
45e15f9bd0SJeremy L Thompson   ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr);
46241a4b83SYohann   ierr = cudaFree(data->d_c); CeedChk_Cu(ceed, ierr);
47e15f9bd0SJeremy L Thompson   ierr = CeedFree(&data->qFunctionSource); CeedChkBackend(ierr);
48e15f9bd0SJeremy L Thompson   ierr = CeedFree(&data); CeedChkBackend(ierr);
49e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
50241a4b83SYohann }
51241a4b83SYohann 
52ab213215SJeremy L Thompson //------------------------------------------------------------------------------
53ab213215SJeremy L Thompson // Create QFunction
54ab213215SJeremy L Thompson //------------------------------------------------------------------------------
55241a4b83SYohann int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) {
56241a4b83SYohann   int ierr;
57241a4b83SYohann   Ceed ceed;
58241a4b83SYohann   CeedQFunctionGetCeed(qf, &ceed);
59241a4b83SYohann   CeedQFunction_Cuda_gen *data;
60e15f9bd0SJeremy L Thompson   ierr = CeedCalloc(1, &data); CeedChkBackend(ierr);
61e15f9bd0SJeremy L Thompson   ierr = CeedQFunctionSetData(qf, data); CeedChkBackend(ierr);
62241a4b83SYohann 
63*3d3250a0SJeremy L Thompson   // Read QFunction source
6443e1b16fSJeremy L Thompson   ierr = CeedQFunctionGetKernelName(qf, &data->qFunctionName);
6543e1b16fSJeremy L Thompson   CeedChkBackend(ierr);
66*3d3250a0SJeremy L Thompson   ierr = CeedQFunctionLoadSourceToBuffer(qf, &data->qFunctionSource);
67*3d3250a0SJeremy L Thompson   CeedChkBackend(ierr);
68*3d3250a0SJeremy L Thompson   if (!data->qFunctionSource)
69*3d3250a0SJeremy L Thompson     // LCOV_EXCL_START
70*3d3250a0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_UNSUPPORTED,
71*3d3250a0SJeremy L Thompson                      "/gpu/cuda/gen backend requires QFunction source code file");
72*3d3250a0SJeremy L Thompson   // LCOV_EXCL_STOP
73241a4b83SYohann 
74241a4b83SYohann   ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply",
75e15f9bd0SJeremy L Thompson                                 CeedQFunctionApply_Cuda_gen); CeedChkBackend(ierr);
76241a4b83SYohann   ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy",
77e15f9bd0SJeremy L Thompson                                 CeedQFunctionDestroy_Cuda_gen); CeedChkBackend(ierr);
78e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
79241a4b83SYohann }
80ab213215SJeremy L Thompson //------------------------------------------------------------------------------
81