xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-gen/ceed-cuda-gen-qfunction.c (revision 49aac155e7a09736f56fb3abac0f57dab29f7cbf)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3241a4b83SYohann //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5241a4b83SYohann //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7241a4b83SYohann 
8*49aac155SJeremy L Thompson #include <ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
103d576824SJeremy L Thompson #include <cuda_runtime.h>
112b730f8bSJeremy L Thompson 
12*49aac155SJeremy L Thompson #include "../cuda/ceed-cuda-common.h"
13241a4b83SYohann #include "ceed-cuda-gen.h"
14241a4b83SYohann 
15ab213215SJeremy L Thompson //------------------------------------------------------------------------------
16ab213215SJeremy L Thompson // Apply QFunction
17ab213215SJeremy L Thompson //------------------------------------------------------------------------------
182b730f8bSJeremy L Thompson static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) {
19241a4b83SYohann   Ceed ceed;
202b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
212b730f8bSJeremy L Thompson   return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
22241a4b83SYohann }
23241a4b83SYohann 
24ab213215SJeremy L Thompson //------------------------------------------------------------------------------
25ab213215SJeremy L Thompson // Destroy QFunction
26ab213215SJeremy L Thompson //------------------------------------------------------------------------------
27241a4b83SYohann static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) {
28241a4b83SYohann   CeedQFunction_Cuda_gen *data;
292b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetData(qf, &data));
30241a4b83SYohann   Ceed ceed;
312b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
322b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaFree(data->d_c));
332b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data->q_function_source));
342b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
35e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
36241a4b83SYohann }
37241a4b83SYohann 
38ab213215SJeremy L Thompson //------------------------------------------------------------------------------
39ab213215SJeremy L Thompson // Create QFunction
40ab213215SJeremy L Thompson //------------------------------------------------------------------------------
41241a4b83SYohann int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) {
42241a4b83SYohann   Ceed ceed;
43241a4b83SYohann   CeedQFunctionGetCeed(qf, &ceed);
44241a4b83SYohann   CeedQFunction_Cuda_gen *data;
452b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
462b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionSetData(qf, data));
47241a4b83SYohann 
483d3250a0SJeremy L Thompson   // Read QFunction source
492b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name));
5046dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n");
512b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source));
5246dc0734SJeremy L Thompson   CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n");
532b730f8bSJeremy L Thompson   if (!data->q_function_source) {
543d3250a0SJeremy L Thompson     // LCOV_EXCL_START
552b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file");
563d3250a0SJeremy L Thompson     // LCOV_EXCL_STOP
572b730f8bSJeremy L Thompson   }
58241a4b83SYohann 
592b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen));
602b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen));
61e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
62241a4b83SYohann }
639e201c85SYohann 
64ab213215SJeremy L Thompson //------------------------------------------------------------------------------
65