|
1 |
| -//==---------- pi.hpp - Plugin Interface for SYCL RT -----------------------==// |
2 |
| -// |
3 |
| -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 |
| -// See https://llvm.org/LICENSE.txt for license information. |
5 |
| -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 |
| -// |
7 |
| -//===----------------------------------------------------------------------===// |
8 |
| - |
9 |
| -// C++ wrapper of extern "C" PI interfaces |
10 |
| -// |
11 |
| -#pragma once |
12 |
| - |
13 |
| -#include <CL/sycl/detail/pi.h> |
14 |
| - |
15 |
| -namespace cl { |
16 |
| -namespace sycl { |
17 |
| -namespace detail { |
18 |
| - |
19 |
| -class pi { |
20 |
| -public: |
21 |
| - using pi_result = ::pi_result; |
22 |
| - using pi_platform = ::pi_platform; |
23 |
| - using pi_device = ::pi_device; |
24 |
| - using pi_device_type = ::pi_device_type; |
25 |
| - using pi_device_binary_type = ::pi_device_binary_type; |
26 |
| - using pi_device_info = ::pi_device_info; |
27 |
| - using pi_program = ::pi_program; |
28 |
| - |
29 |
| - // Convinience macro to have things look compact. |
30 |
| - #define PI_API(pi_api) \ |
31 |
| - static constexpr decltype(::pi_api) * pi_api = &::pi_api; |
32 |
| - |
33 |
| - // Platform |
34 |
| - PI_API(piPlatformsGet) |
35 |
| - PI_API(piPlatformGetInfo) |
36 |
| - // Device |
37 |
| - PI_API(piDevicesGet) |
38 |
| - PI_API(piDeviceGetInfo) |
39 |
| - PI_API(piDevicePartition) |
40 |
| - PI_API(piDeviceRetain) |
41 |
| - PI_API(piDeviceRelease) |
42 |
| - // IR |
43 |
| - PI_API(piextDeviceSelectBinary) |
44 |
| -}; |
45 |
| - |
46 |
| -// Report error and no return (keeps compiler happy about no return statements). |
47 |
| -[[noreturn]] void pi_die(const char *message); |
48 |
| -void pi_assert(bool condition, const char *message = 0); |
49 |
| - |
50 |
| -#define STRINGIZE(x) STRINGIZE2(x) |
51 |
| -#define STRINGIZE2(x) #x |
52 |
| -#define PI_ASSERT(cond, msg) \ |
53 |
| - pi_assert(condition, "assert @ " __FILE__ ":" STRINGIZE(__LINE__) msg); |
54 |
| - |
55 |
| -// This does the call, the trace and the check for no errors. |
56 |
| -// TODO: remove dependency on CHECK_OCL_CODE. |
57 |
| -// TODO: implement a more mature and controllable tracing of PI calls. |
58 |
| -void pi_trace(const char *format, ...); |
59 |
| -#define PI_CALL(pi_call) { \ |
60 |
| - pi_trace("PI ---> %s\n", #pi_call); \ |
61 |
| - auto __result = (pi_call); \ |
62 |
| - pi_trace("PI <--- %d\n", __result); \ |
63 |
| - CHECK_OCL_CODE(__result); \ |
64 |
| -} |
65 |
| - |
66 |
| -// Want all the needed casts be explicit, do not define conversion operators. |
67 |
| -template<class To, class From> |
68 |
| -To pi_cast(From value) { |
69 |
| - // TODO: see if more sanity checks are possible. |
70 |
| - pi_assert(sizeof(From) == sizeof(To)); |
71 |
| - return (To)(value); |
72 |
| -} |
73 |
| - |
74 |
| -} // namespace detail |
75 |
| -} // namespace sycl |
76 |
| -} // namespace cl |
77 |
| - |
| 1 | +//==---------- pi.hpp - Plugin Interface for SYCL RT -----------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +// C++ wrapper of extern "C" PI interfaces |
| 10 | +// |
| 11 | +#pragma once |
| 12 | + |
| 13 | +#include <CL/sycl/detail/pi.h> |
| 14 | + |
| 15 | +namespace cl { |
| 16 | +namespace sycl { |
| 17 | +namespace detail { |
| 18 | + |
| 19 | +class pi { |
| 20 | +public: |
| 21 | + using pi_result = ::pi_result; |
| 22 | + using pi_platform = ::pi_platform; |
| 23 | + using pi_device = ::pi_device; |
| 24 | + using pi_device_type = ::pi_device_type; |
| 25 | + using pi_device_binary_type = ::pi_device_binary_type; |
| 26 | + using pi_device_info = ::pi_device_info; |
| 27 | + using pi_program = ::pi_program; |
| 28 | + |
| 29 | + // Convinience macro to have things look compact. |
| 30 | + #define _PI_API(pi_api) \ |
| 31 | + static constexpr decltype(::pi_api) * pi_api = &::pi_api; |
| 32 | + |
| 33 | + // Platform |
| 34 | + _PI_API(piPlatformsGet) |
| 35 | + _PI_API(piPlatformGetInfo) |
| 36 | + // Device |
| 37 | + _PI_API(piDevicesGet) |
| 38 | + _PI_API(piDeviceGetInfo) |
| 39 | + _PI_API(piDevicePartition) |
| 40 | + _PI_API(piDeviceRetain) |
| 41 | + _PI_API(piDeviceRelease) |
| 42 | + // IR |
| 43 | + _PI_API(piextDeviceSelectBinary) |
| 44 | + |
| 45 | + #undef _PI_API |
| 46 | +}; |
| 47 | + |
| 48 | +// Report error and no return (keeps compiler happy about no return statements). |
| 49 | +[[noreturn]] void pi_die(const char *message); |
| 50 | +void pi_assert(bool condition, const char *message = 0); |
| 51 | + |
| 52 | +#define _PI_STRINGIZE(x) _PI_STRINGIZE2(x) |
| 53 | +#define _PI_STRINGIZE2(x) #x |
| 54 | +#define PI_ASSERT(cond, msg) \ |
| 55 | + pi_assert(condition, "assert @ " __FILE__ ":" _PI_STRINGIZE(__LINE__) msg); |
| 56 | + |
| 57 | +// This does the call, the trace and the check for no errors. |
| 58 | +// TODO: remove dependency on CHECK_OCL_CODE. |
| 59 | +// TODO: implement a more mature and controllable tracing of PI calls. |
| 60 | +void pi_trace(const char *format, ...); |
| 61 | +#define PI_CALL(pi_call) { \ |
| 62 | + pi_trace("PI ---> %s\n", #pi_call); \ |
| 63 | + auto __result = (pi_call); \ |
| 64 | + pi_trace("PI <--- %d\n", __result); \ |
| 65 | + CHECK_OCL_CODE(__result); \ |
| 66 | +} |
| 67 | + |
| 68 | +// Want all the needed casts be explicit, do not define conversion operators. |
| 69 | +template<class To, class From> |
| 70 | +To pi_cast(From value) { |
| 71 | + // TODO: see if more sanity checks are possible. |
| 72 | + pi_assert(sizeof(From) == sizeof(To)); |
| 73 | + return (To)(value); |
| 74 | +} |
| 75 | + |
| 76 | +} // namespace detail |
| 77 | +} // namespace sycl |
| 78 | +} // namespace cl |
| 79 | + |
0 commit comments