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 CeedSyclGetResourceRoot(Ceed ceed, const char *resource, char **resource_root); 43 44 CEED_INTERN int CeedSyclInit(Ceed ceed, const char *resource); 45 46 CEED_INTERN int CeedDestroy_Sycl(Ceed ceed); 47 48 #endif // _ceed_sycl_common_h 49