xref: /libCEED/backends/hip-gen/ceed-hip-gen-qfunction.c (revision 0c9ac183098ed55d0b8f535d4ee42b5752ebbe4d)
1 // Copyright (c) 2017-2022, 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 <hip/hip_runtime.h>
11 
12 #include "../hip/ceed-hip-common.h"
13 #include "ceed-hip-gen.h"
14 
15 //------------------------------------------------------------------------------
16 // Apply QFunction
17 //------------------------------------------------------------------------------
18 static int CeedQFunctionApply_Hip_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 //------------------------------------------------------------------------------
25 static int CeedQFunctionDestroy_Hip_gen(CeedQFunction qf) {
26   CeedQFunction_Hip_gen *data;
27 
28   CeedCallBackend(CeedQFunctionGetData(qf, &data));
29   CeedCallHip(CeedQFunctionReturnCeed(qf), hipFree(data->d_c));
30   CeedCallBackend(CeedFree(&data->qfunction_source));
31   CeedCallBackend(CeedFree(&data));
32   return CEED_ERROR_SUCCESS;
33 }
34 
35 //------------------------------------------------------------------------------
36 // Create QFunction
37 //------------------------------------------------------------------------------
38 int CeedQFunctionCreate_Hip_gen(CeedQFunction qf) {
39   Ceed                   ceed;
40   CeedQFunction_Hip_gen *data;
41 
42   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
43   CeedCallBackend(CeedCalloc(1, &data));
44   CeedCallBackend(CeedQFunctionSetData(qf, data));
45 
46   // Read QFunction source
47   CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name));
48   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source -----\n");
49   CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->qfunction_source));
50   CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source Complete! -----\n");
51   CeedCheck(data->qfunction_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/hip/gen backend requires QFunction source code file");
52 
53   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Hip_gen));
54   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Hip_gen));
55   return CEED_ERROR_SUCCESS;
56 }
57 
58 //------------------------------------------------------------------------------
59