xref: /libCEED/backends/sycl-gen/ceed-sycl-gen-qfunction.sycl.cpp (revision e38d11ba071a163e6515191e86d20961b50fdfba)
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/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   Ceed ceed;
21 
22   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
23   return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
24 }
25 
26 //------------------------------------------------------------------------------
27 // Destroy QFunction
28 //------------------------------------------------------------------------------
29 static int CeedQFunctionDestroy_Sycl_gen(CeedQFunction qf) {
30   Ceed                    ceed;
31   Ceed_Sycl              *data;
32   CeedQFunction_Sycl_gen *impl;
33 
34   CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
35   CeedCallBackend(CeedQFunctionGetData(qf, &impl));
36   CeedCallBackend(CeedGetData(ceed, &data));
37 
38   // Wait for all work to finish before freeing memory
39   CeedCallSycl(ceed, data->sycl_queue.wait_and_throw());
40   CeedCallSycl(ceed, sycl::free(impl->d_c, data->sycl_context));
41 
42   CeedCallBackend(CeedFree(&impl->q_function_source));
43   CeedCallBackend(CeedFree(&impl));
44   return CEED_ERROR_SUCCESS;
45 }
46 
47 //------------------------------------------------------------------------------
48 // Create QFunction
49 //------------------------------------------------------------------------------
50 int CeedQFunctionCreate_Sycl_gen(CeedQFunction qf) {
51   Ceed                    ceed;
52   CeedQFunction_Sycl_gen *impl;
53 
54   CeedQFunctionGetCeed(qf, &ceed);
55   CeedCallBackend(CeedCalloc(1, &impl));
56   CeedCallBackend(CeedQFunctionSetData(qf, impl));
57 
58   // Read QFunction source
59   CeedCallBackend(CeedQFunctionGetKernelName(qf, &impl->q_function_name));
60   CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n");
61   CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &impl->q_function_source));
62   CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n");
63   if (!impl->q_function_source) {
64     // LCOV_EXCL_START
65     return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "/gpu/sycl/gen backend requires QFunction source code file");
66     // LCOV_EXCL_STOP
67   }
68 
69   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Sycl_gen));
70   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Sycl_gen));
71   return CEED_ERROR_SUCCESS;
72 }
73 
74 //------------------------------------------------------------------------------
75