xref: /libCEED/backends/hip-gen/ceed-hip-gen-qfunction.c (revision db002c03923317a1c3814dcd861330002c00a8ea)
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   Ceed ceed;
20   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
21   return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
22 }
23 
24 //------------------------------------------------------------------------------
25 // Destroy QFunction
26 //------------------------------------------------------------------------------
27 static int CeedQFunctionDestroy_Hip_gen(CeedQFunction qf) {
28   CeedQFunction_Hip_gen *data;
29   CeedCallBackend(CeedQFunctionGetData(qf, &data));
30   Ceed ceed;
31   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
32   CeedCallHip(ceed, hipFree(data->d_c));
33   CeedCallBackend(CeedFree(&data->q_function_source));
34   CeedCallBackend(CeedFree(&data));
35   return CEED_ERROR_SUCCESS;
36 }
37 
38 //------------------------------------------------------------------------------
39 // Create QFunction
40 //------------------------------------------------------------------------------
41 int CeedQFunctionCreate_Hip_gen(CeedQFunction qf) {
42   Ceed ceed;
43   CeedQFunctionGetCeed(qf, &ceed);
44   CeedQFunction_Hip_gen *data;
45   CeedCallBackend(CeedCalloc(1, &data));
46   CeedCallBackend(CeedQFunctionSetData(qf, data));
47 
48   // Read QFunction source
49   CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name));
50   CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n");
51   CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source));
52   CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n");
53   CeedCheck(data->q_function_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/hip/gen backend requires QFunction source code file");
54 
55   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Hip_gen));
56   CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Hip_gen));
57   return CEED_ERROR_SUCCESS;
58 }
59 
60 //------------------------------------------------------------------------------
61