|
| 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 | +__SYCL_INLINE_NAMESPACE(cl) { |
| 15 | +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 | +#define __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(DescType, Desc, ReturnT, InputT, \ |
| 85 | + 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 with_input_return_type = info::DescType::Desc::return_type; \ |
| 95 | + }; |
| 96 | +#include <sycl/info/kernel_device_specific_traits.def> |
| 97 | +#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT |
| 98 | +#undef __SYCL_PARAM_TRAITS_SPEC |
| 99 | +// Need a static_cast here since piDeviceGetInfo can also accept |
| 100 | +// pi_usm_capability_query values. |
| 101 | +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ |
| 102 | + template <> struct PiInfoCode<info::DescType::Desc> { \ |
| 103 | + static constexpr pi_device_info value = \ |
| 104 | + static_cast<pi_device_info>(PiCode); \ |
| 105 | + }; \ |
| 106 | + template <> \ |
| 107 | + struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \ |
| 108 | + using return_type = info::DescType::Desc::return_type; \ |
| 109 | + }; |
| 110 | +#include <sycl/info/device_traits.def> |
| 111 | +#undef __SYCL_PARAM_TRAITS_SPEC |
| 112 | +} // namespace detail |
| 113 | +} // namespace sycl |
| 114 | +} // __SYCL_INLINE_NAMESPACE(cl) |
0 commit comments