xref: /libCEED/backends/sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp (revision f174933e42b4d5a2db574b02cd498c160daf12d9)
1 // Copyright (c) 2017-2024, 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/backend.h>
9 #include <ceed/ceed.h>
10 #include <sycl/sycl.hpp>
11 #include <stdio.h>
12 #include <string.h>
13 
14 #include "ceed-sycl-gen.hpp"
15 
16 //------------------------------------------------------------------------------
17 // Apply QFunction
18 //------------------------------------------------------------------------------
19 static int CeedQFunctionApply_Sycl_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) {
20   return CeedError(CeedQFunctionReturnCeed(qf), CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
21 }
22 
23 //------------------------------------------------------------------------------
24 // Destroy QFunction
25 //------------------------------------------------------------------------------
26 static int CeedQFunctionDestroy_Sycl_gen(CeedQFunction qf) {
27   Ceed                    ceed;
28   Ceed_Sycl              *data;
29   CeedQFunction_Sycl_gen *impl;
30 
31   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
32   CeedCallBackend(CeedQFunctionGetData(qf, &impl));
33   CeedCallBackend(CeedGetData(ceed, &data));
34 
35   // Wait for all work to finish before freeing memory
36   CeedCallSycl(ceed, data->sycl_queue.wait_and_throw());
37   CeedCallSycl(ceed, sycl::free(impl->d_c, data->sycl_context));
38 
39   CeedCallBackend(CeedFree(&impl->qfunction_source));
40   CeedCallBackend(CeedFree(&impl));
41   CeedCallBackend(CeedDestroy(&ceed));
42   return CEED_ERROR_SUCCESS;
43 }
44 
45 //------------------------------------------------------------------------------
46 // Create QFunction
47 //------------------------------------------------------------------------------
48 int CeedQFunctionCreate_Sycl_gen(CeedQFunction qf) {
49   Ceed                    ceed;
50   CeedQFunction_Sycl_gen *impl;
51 
52   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
53   CeedCallBackend(CeedCalloc(1, &impl));
54   CeedCallBackend(CeedQFunctionSetData(qf, impl));
55 
56   // Read QFunction source
57   CeedCallBackend(CeedQFunctionGetKernelName(qf, &impl->qfunction_name));
58   CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n");
59   CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &impl->qfunction_source));
60   CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n");
61   CeedCheck(impl->qfunction_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/sycl/gen backend requires QFunction source code file");
62 
63   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Sycl_gen));
64   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Sycl_gen));
65   CeedCallBackend(CeedDestroy(&ceed));
66   return CEED_ERROR_SUCCESS;
67 }
68 
69 //------------------------------------------------------------------------------
70