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.h> // for pi_device_info
12 
13 #include <type_traits> // for true_type
14 
15 // FIXME: .def files included to this file use all sorts of SYCL objects like
16 // id, range, traits, etc. We have to include some headers before including .def
17 // files.
18 #include <sycl/aspects.hpp>
19 #include <sycl/id.hpp>
20 #include <sycl/info/info_desc.hpp>
21 
22 namespace sycl {
23 inline namespace _V1 {
24 namespace detail {
25 template <typename T> struct PiInfoCode;
26 template <typename T> struct is_platform_info_desc : std::false_type {};
27 template <typename T> struct is_context_info_desc : std::false_type {};
28 template <typename T> struct is_device_info_desc : std::false_type {};
29 template <typename T> struct is_queue_info_desc : std::false_type {};
30 template <typename T> struct is_kernel_info_desc : std::false_type {};
31 template <typename T>
32 struct is_kernel_device_specific_info_desc : std::false_type {};
33 template <typename T> struct is_event_info_desc : std::false_type {};
34 template <typename T> struct is_event_profiling_info_desc : std::false_type {};
35 // Normally we would just use std::enable_if to limit valid get_info template
36 // arguments. However, there is a mangling mismatch of
37 // "std::enable_if<is*_desc::value>::type" between gcc clang (it appears that
38 // gcc lacks a E terminator for unresolved-qualifier-level sequence). As a
39 // workaround, we use return_type alias from is_*info_desc that doesn't run into
40 // the same problem.
41 // TODO remove once this gcc/clang discrepancy is resolved
42 
43 template <typename T> struct is_backend_info_desc : std::false_type {};
44 // Similar approach to limit valid get_backend_info template argument
45 
46 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
47  template <> struct PiInfoCode<info::DescType::Desc> { \
48  static constexpr pi_##DescType##_info value = PiCode; \
49  }; \
50  template <> \
51  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
52  using return_type = info::DescType::Desc::return_type; \
53  };
54 #include <sycl/info/context_traits.def>
55 #include <sycl/info/event_traits.def>
56 #include <sycl/info/kernel_traits.def>
57 #include <sycl/info/platform_traits.def>
58 #include <sycl/info/queue_traits.def>
59 #undef __SYCL_PARAM_TRAITS_SPEC
60 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
61  template <> struct PiInfoCode<info::DescType::Desc> { \
62  static constexpr pi_profiling_info value = PiCode; \
63  }; \
64  template <> \
65  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
66  using return_type = info::DescType::Desc::return_type; \
67  };
68 #include <sycl/info/event_profiling_traits.def>
69 #undef __SYCL_PARAM_TRAITS_SPEC
70 
71 template <typename Param> struct IsSubGroupInfo : std::false_type {};
72 template <>
73 struct IsSubGroupInfo<info::kernel_device_specific::max_num_sub_groups>
74  : std::true_type {};
75 template <>
76 struct IsSubGroupInfo<info::kernel_device_specific::compile_num_sub_groups>
77  : std::true_type {};
78 template <>
79 struct IsSubGroupInfo<info::kernel_device_specific::max_sub_group_size>
80  : std::true_type {};
81 template <>
82 struct IsSubGroupInfo<info::kernel_device_specific::compile_sub_group_size>
83  : std::true_type {};
84 
85 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
86  template <> struct PiInfoCode<info::DescType::Desc> { \
87  static constexpr \
88  typename std::conditional<IsSubGroupInfo<info::DescType::Desc>::value, \
89  pi_kernel_sub_group_info, \
90  pi_kernel_group_info>::type value = PiCode; \
91  }; \
92  template <> \
93  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
94  using return_type = info::DescType::Desc::return_type; \
95  };
96 #include <sycl/info/kernel_device_specific_traits.def>
97 #undef __SYCL_PARAM_TRAITS_SPEC
98 // Need a static_cast here since piDeviceGetInfo can also accept
99 // pi_usm_capability_query values.
100 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
101  template <> struct PiInfoCode<info::DescType::Desc> { \
102  static constexpr pi_device_info value = \
103  static_cast<pi_device_info>(PiCode); \
104  }; \
105  template <> \
106  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
107  using return_type = info::DescType::Desc::return_type; \
108  };
109 #define __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(DescType, Desc, ReturnT, PiCode) \
110  __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode)
111 
112 #include <sycl/info/device_traits.def>
113 
114 #undef __SYCL_PARAM_TRAITS_SPEC
115 #undef __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED
116 
117 #define __SYCL_PARAM_TRAITS_SPEC(Namespace, DescType, Desc, ReturnT, PiCode) \
118  template <> struct PiInfoCode<Namespace::info::DescType::Desc> { \
119  static constexpr pi_device_info value = \
120  static_cast<pi_device_info>(PiCode); \
121  }; \
122  template <> \
123  struct is_##DescType##_info_desc<Namespace::info::DescType::Desc> \
124  : std::true_type { \
125  using return_type = Namespace::info::DescType::Desc::return_type; \
126  };
127 #include <sycl/info/ext_codeplay_device_traits.def>
128 #include <sycl/info/ext_intel_device_traits.def>
129 #include <sycl/info/ext_oneapi_device_traits.def>
130 #undef __SYCL_PARAM_TRAITS_SPEC
131 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
132  template <> \
133  struct is_backend_info_desc<info::DescType::Desc> : std::true_type { \
134  using return_type = info::DescType::Desc::return_type; \
135  };
136 #include <sycl/info/sycl_backend_traits.def>
137 #undef __SYCL_PARAM_TRAITS_SPEC
138 
139 } // namespace detail
140 } // namespace _V1
141 } // namespace sycl
Definition: access.hpp:18