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 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
43  template <> struct PiInfoCode<info::DescType::Desc> { \
44  static constexpr pi_##DescType##_info value = PiCode; \
45  }; \
46  template <> \
47  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
48  using return_type = info::DescType::Desc::return_type; \
49  };
50 #include <sycl/info/context_traits.def>
51 #include <sycl/info/event_traits.def>
52 #include <sycl/info/kernel_traits.def>
53 #include <sycl/info/platform_traits.def>
54 #include <sycl/info/queue_traits.def>
55 #undef __SYCL_PARAM_TRAITS_SPEC
56 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
57  template <> struct PiInfoCode<info::DescType::Desc> { \
58  static constexpr pi_profiling_info value = PiCode; \
59  }; \
60  template <> \
61  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
62  using return_type = info::DescType::Desc::return_type; \
63  };
64 #include <sycl/info/event_profiling_traits.def>
65 #undef __SYCL_PARAM_TRAITS_SPEC
66 
67 template <typename Param> struct IsSubGroupInfo : std::false_type {};
68 template <>
69 struct IsSubGroupInfo<info::kernel_device_specific::max_num_sub_groups>
70  : std::true_type {};
71 template <>
72 struct IsSubGroupInfo<info::kernel_device_specific::compile_num_sub_groups>
73  : std::true_type {};
74 template <>
75 struct IsSubGroupInfo<info::kernel_device_specific::max_sub_group_size>
76  : std::true_type {};
77 template <>
78 struct IsSubGroupInfo<info::kernel_device_specific::compile_sub_group_size>
79  : std::true_type {};
80 
81 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
82  template <> struct PiInfoCode<info::DescType::Desc> { \
83  static constexpr \
84  typename std::conditional<IsSubGroupInfo<info::DescType::Desc>::value, \
85  pi_kernel_sub_group_info, \
86  pi_kernel_group_info>::type value = PiCode; \
87  }; \
88  template <> \
89  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
90  using return_type = info::DescType::Desc::return_type; \
91  };
92 #include <sycl/info/kernel_device_specific_traits.def>
93 #undef __SYCL_PARAM_TRAITS_SPEC
94 // Need a static_cast here since piDeviceGetInfo can also accept
95 // pi_usm_capability_query values.
96 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
97  template <> struct PiInfoCode<info::DescType::Desc> { \
98  static constexpr pi_device_info value = \
99  static_cast<pi_device_info>(PiCode); \
100  }; \
101  template <> \
102  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
103  using return_type = info::DescType::Desc::return_type; \
104  };
105 #define __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(DescType, Desc, ReturnT, PiCode) \
106  __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode)
107 
108 #include <sycl/info/device_traits.def>
109 
110 #undef __SYCL_PARAM_TRAITS_SPEC
111 #undef __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED
112 
113 #define __SYCL_PARAM_TRAITS_SPEC(Namespace, DescType, Desc, ReturnT, PiCode) \
114  template <> struct PiInfoCode<Namespace::info::DescType::Desc> { \
115  static constexpr pi_device_info value = \
116  static_cast<pi_device_info>(PiCode); \
117  }; \
118  template <> \
119  struct is_##DescType##_info_desc<Namespace::info::DescType::Desc> \
120  : std::true_type { \
121  using return_type = Namespace::info::DescType::Desc::return_type; \
122  };
123 #include <sycl/info/ext_codeplay_device_traits.def>
124 #include <sycl/info/ext_intel_device_traits.def>
125 #include <sycl/info/ext_oneapi_device_traits.def>
126 #undef __SYCL_PARAM_TRAITS_SPEC
127 
128 } // namespace detail
129 } // namespace _V1
130 } // namespace sycl
Definition: access.hpp:18