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