xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-gen/ceed-cuda-gen-qfunction.c (revision ca7355308a14805110a7d98dabf1f658d5ec16d5)
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 
849aac155SJeremy L Thompson #include <ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
103d576824SJeremy L Thompson #include <cuda_runtime.h>
112b730f8bSJeremy L Thompson 
1249aac155SJeremy 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;
20*ca735530SJeremy L Thompson 
212b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
222b730f8bSJeremy L Thompson   return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
23241a4b83SYohann }
24241a4b83SYohann 
25ab213215SJeremy L Thompson //------------------------------------------------------------------------------
26ab213215SJeremy L Thompson // Destroy QFunction
27ab213215SJeremy L Thompson //------------------------------------------------------------------------------
28241a4b83SYohann static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) {
29241a4b83SYohann   Ceed                    ceed;
30*ca735530SJeremy L Thompson   CeedQFunction_Cuda_gen *data;
31*ca735530SJeremy L Thompson 
32*ca735530SJeremy L Thompson   CeedCallBackend(CeedQFunctionGetData(qf, &data));
332b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
342b730f8bSJeremy L Thompson   CeedCallCuda(ceed, cudaFree(data->d_c));
352b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data->q_function_source));
362b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
37e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
38241a4b83SYohann }
39241a4b83SYohann 
40ab213215SJeremy L Thompson //------------------------------------------------------------------------------
41ab213215SJeremy L Thompson // Create QFunction
42ab213215SJeremy L Thompson //------------------------------------------------------------------------------
43241a4b83SYohann int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) {
44241a4b83SYohann   Ceed                    ceed;
45241a4b83SYohann   CeedQFunction_Cuda_gen *data;
46*ca735530SJeremy L Thompson 
47*ca735530SJeremy L Thompson   CeedQFunctionGetCeed(qf, &ceed);
482b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
492b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionSetData(qf, data));
50241a4b83SYohann 
513d3250a0SJeremy L Thompson   // Read QFunction source
522b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name));
5323d4529eSJeremy L Thompson   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source -----\n");
542b730f8bSJeremy L Thompson   CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source));
5523d4529eSJeremy L Thompson   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source Complete! -----\n");
566574a04fSJeremy L Thompson   CeedCheck(data->q_function_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file");
57241a4b83SYohann 
582b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen));
592b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen));
60e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
61241a4b83SYohann }
629e201c85SYohann 
63ab213215SJeremy L Thompson //------------------------------------------------------------------------------
64