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