xref: /libCEED/backends/sycl/ceed-sycl-common.hpp (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 #ifndef CEED_SYCL_COMMON_HPP
9 #define CEED_SYCL_COMMON_HPP
10 
11 #include <ceed/backend.h>
12 #include <ceed/jit-source/sycl/sycl-types.h>
13 
14 #include <sycl/sycl.hpp>
15 #include <type_traits>
16 
17 #define CeedCallSycl(ceed, ...)                               \
18   do {                                                        \
19     try {                                                     \
20       __VA_ARGS__;                                            \
21     } catch (sycl::exception const &e) {                      \
22       return CeedError((ceed), CEED_ERROR_BACKEND, e.what()); \
23     }                                                         \
24   } while (0);
25 
26 using CeedBackendFunction = int (*)();
27 
28 template <typename R, class... Args>
29 int CeedSetBackendFunctionCpp(Ceed ceed, const char *type, void *object, const char *fname, R (*f)(Args...)) {
30   static_assert(std::is_same_v<int, R>, "Ceed backend functions must return int");
31   // Kris: this is potentially undefined behavior by C++ standards
32   auto *bf = reinterpret_cast<CeedBackendFunction>(f);
33   return CeedSetBackendFunction(ceed, type, object, fname, bf);
34 }
35 
36 typedef struct {
37   sycl::context sycl_context;
38   sycl::device  sycl_device;
39   sycl::queue   sycl_queue;
40 } Ceed_Sycl;
41 
42 CEED_INTERN int CeedInit_Sycl(Ceed ceed, const char *resource);
43 
44 CEED_INTERN int CeedDestroy_Sycl(Ceed ceed);
45 
46 CEED_INTERN int CeedSetStream_Sycl(Ceed ceed, void *handle);
47 
48 #endif  // CEED_SYCL_COMMON_HPP
49