DPC++ Runtime
Runtime libraries for oneAPI DPC++
info_desc_helpers.hpp
Go to the documentation of this file.
1 //==---- info_desc_helpers.hpp - SYCL information descriptor helpers -------==//
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 #pragma once
10 
11 #include <sycl/detail/pi.hpp>
12 #include <sycl/info/info_desc.hpp>
13 
14 namespace sycl {
16 namespace detail {
17 template <typename T> struct PiInfoCode;
18 template <typename T> struct is_platform_info_desc : std::false_type {};
19 template <typename T> struct is_context_info_desc : std::false_type {};
20 template <typename T> struct is_device_info_desc : std::false_type {};
21 template <typename T> struct is_queue_info_desc : std::false_type {};
22 template <typename T> struct is_kernel_info_desc : std::false_type {};
23 template <typename T>
24 struct is_kernel_device_specific_info_desc : std::false_type {};
25 template <typename T> struct is_event_info_desc : std::false_type {};
26 template <typename T> struct is_event_profiling_info_desc : std::false_type {};
27 // Normally we would just use std::enable_if to limit valid get_info template
28 // arguments. However, there is a mangling mismatch of
29 // "std::enable_if<is*_desc::value>::type" between gcc clang (it appears that
30 // gcc lacks a E terminator for unresolved-qualifier-level sequence). As a
31 // workaround, we use return_type alias from is_*info_desc that doesn't run into
32 // the same problem.
33 // TODO remove once this gcc/clang discrepancy is resolved
34 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
35  template <> struct PiInfoCode<info::DescType::Desc> { \
36  static constexpr pi_##DescType##_info value = PiCode; \
37  }; \
38  template <> \
39  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
40  using return_type = info::DescType::Desc::return_type; \
41  };
42 #include <sycl/info/context_traits.def>
43 #include <sycl/info/event_traits.def>
44 #include <sycl/info/kernel_traits.def>
45 #include <sycl/info/platform_traits.def>
46 #include <sycl/info/queue_traits.def>
47 #undef __SYCL_PARAM_TRAITS_SPEC
48 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
49  template <> struct PiInfoCode<info::DescType::Desc> { \
50  static constexpr pi_profiling_info value = PiCode; \
51  }; \
52  template <> \
53  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
54  using return_type = info::DescType::Desc::return_type; \
55  };
56 #include <sycl/info/event_profiling_traits.def>
57 #undef __SYCL_PARAM_TRAITS_SPEC
58 
59 template <typename Param> struct IsSubGroupInfo : std::false_type {};
60 template <>
61 struct IsSubGroupInfo<info::kernel_device_specific::max_num_sub_groups>
62  : std::true_type {};
63 template <>
64 struct IsSubGroupInfo<info::kernel_device_specific::compile_num_sub_groups>
65  : std::true_type {};
66 template <>
67 struct IsSubGroupInfo<info::kernel_device_specific::max_sub_group_size>
68  : std::true_type {};
69 template <>
70 struct IsSubGroupInfo<info::kernel_device_specific::compile_sub_group_size>
71  : std::true_type {};
72 
73 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
74  template <> struct PiInfoCode<info::DescType::Desc> { \
75  static constexpr \
76  typename std::conditional<IsSubGroupInfo<info::DescType::Desc>::value, \
77  pi_kernel_sub_group_info, \
78  pi_kernel_group_info>::type value = PiCode; \
79  }; \
80  template <> \
81  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
82  using return_type = info::DescType::Desc::return_type; \
83  };
84 #include <sycl/info/kernel_device_specific_traits.def>
85 #undef __SYCL_PARAM_TRAITS_SPEC
86 // Need a static_cast here since piDeviceGetInfo can also accept
87 // pi_usm_capability_query values.
88 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
89  template <> struct PiInfoCode<info::DescType::Desc> { \
90  static constexpr pi_device_info value = \
91  static_cast<pi_device_info>(PiCode); \
92  }; \
93  template <> \
94  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
95  using return_type = info::DescType::Desc::return_type; \
96  };
97 #define __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(DescType, Desc, ReturnT, PiCode) \
98  __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode)
99 
100 #include <sycl/info/device_traits.def>
101 
102 #undef __SYCL_PARAM_TRAITS_SPEC
103 #undef __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED
104 
105 #define __SYCL_PARAM_TRAITS_SPEC(Namespace, DescType, Desc, ReturnT, PiCode) \
106  template <> struct PiInfoCode<Namespace::info::DescType::Desc> { \
107  static constexpr pi_device_info value = \
108  static_cast<pi_device_info>(PiCode); \
109  }; \
110  template <> \
111  struct is_##DescType##_info_desc<Namespace::info::DescType::Desc> \
112  : std::true_type { \
113  using return_type = Namespace::info::DescType::Desc::return_type; \
114  };
115 #include <sycl/info/ext_intel_device_traits.def>
116 #include <sycl/info/ext_oneapi_device_traits.def>
117 #undef __SYCL_PARAM_TRAITS_SPEC
118 
119 } // namespace detail
120 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
121 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
C++ wrapper of extern "C" PI interfaces.