Skip to content

Commit 7842d05

Browse files
[SYCL][ABI-Break] Add SYCL 2020 kernel_device_specific::max_sub_group_size (#6782)
SYCL 2020 promotes the info::kernel_device_specific::max_sub_group_size query on kernels, but removes the additional argument. This commit adds an overload with no additional argument and deprecates the old variant.
1 parent 1ccfd51 commit 7842d05

File tree

8 files changed

+42
-30
lines changed

8 files changed

+42
-30
lines changed

sycl/include/sycl/detail/info_desc_helpers.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,7 @@ struct IsSubGroupInfo<info::kernel_device_specific::compile_sub_group_size>
8181
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
8282
using return_type = info::DescType::Desc::return_type; \
8383
};
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-
};
9684
#include <sycl/info/kernel_device_specific_traits.def>
97-
#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT
9885
#undef __SYCL_PARAM_TRAITS_SPEC
9986
// Need a static_cast here since piDeviceGetInfo can also accept
10087
// pi_usm_capability_query values.

sycl/include/sycl/info/info_desc.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,8 @@ namespace kernel {
118118
} // namespace kernel
119119

120120
namespace kernel_device_specific {
121-
#define __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(DescType, Desc, ReturnT, InputT, \
122-
PiCode) \
123-
__SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode)
124121
#include <sycl/info/kernel_device_specific_traits.def>
125122
} // namespace kernel_device_specific
126-
#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT
127123

128124
// A.6 Event information desctiptors
129125
enum class event_command_status : pi_int32 {

sycl/include/sycl/info/kernel_device_specific_traits.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ __SYCL_PARAM_TRAITS_SPEC(kernel_device_specific,
77
__SYCL_PARAM_TRAITS_SPEC(kernel_device_specific, private_mem_size, size_t, PI_KERNEL_GROUP_INFO_PRIVATE_MEM_SIZE)
88
__SYCL_PARAM_TRAITS_SPEC(kernel_device_specific, max_num_sub_groups, uint32_t, PI_KERNEL_MAX_NUM_SUB_GROUPS)
99
__SYCL_PARAM_TRAITS_SPEC(kernel_device_specific, compile_num_sub_groups, uint32_t, PI_KERNEL_COMPILE_NUM_SUB_GROUPS)
10-
__SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(kernel_device_specific, max_sub_group_size,
11-
uint32_t, sycl::range<3>, PI_KERNEL_MAX_SUB_GROUP_SIZE)
10+
__SYCL_PARAM_TRAITS_SPEC(kernel_device_specific, max_sub_group_size, uint32_t, PI_KERNEL_MAX_SUB_GROUP_SIZE)
1211
__SYCL_PARAM_TRAITS_SPEC(kernel_device_specific, compile_sub_group_size, uint32_t, PI_KERNEL_COMPILE_SUB_GROUP_SIZE_INTEL)
1312
__SYCL_PARAM_TRAITS_SPEC(kernel_device_specific, ext_codeplay_num_regs, uint32_t, PI_KERNEL_GROUP_INFO_NUM_REGS)

sycl/include/sycl/kernel.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ class __SYCL_EXPORT kernel {
149149
/// \param WGSize is the work-group size the sub-group size is requested for.
150150
/// \return depends on information being queried.
151151
template <typename Param>
152-
typename detail::is_kernel_device_specific_info_desc<
153-
Param>::with_input_return_type
154-
get_info(const device &Device, const range<3> &WGSize) const;
152+
__SYCL2020_DEPRECATED("Use the overload without the second parameter")
153+
typename detail::is_kernel_device_specific_info_desc<Param>::return_type
154+
get_info(const device &Device, const range<3> &WGSize) const;
155155

156156
private:
157157
/// Constructs a SYCL kernel object from a valid kernel_impl instance.

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <cstring>
2727
#include <limits>
2828
#include <map>
29+
#include <memory>
2930
#include <sstream>
3031
#include <string>
3132
#include <vector>
@@ -860,6 +861,21 @@ pi_result piKernelGetSubGroupInfo(pi_kernel kernel, pi_device device,
860861
(void)param_value_size;
861862
size_t ret_val;
862863
cl_int ret_err;
864+
865+
std::shared_ptr<void> implicit_input_value;
866+
if (param_name == PI_KERNEL_MAX_SUB_GROUP_SIZE && !input_value) {
867+
// OpenCL needs an input value for PI_KERNEL_MAX_SUB_GROUP_SIZE so if no
868+
// value is given we use the max work item sizes of the device to avoid
869+
// truncation of max sub-group size.
870+
implicit_input_value = std::shared_ptr<size_t[]>(new size_t[3]);
871+
pi_result pi_ret_err = piDeviceGetInfo(
872+
device, PI_DEVICE_INFO_MAX_WORK_ITEM_SIZES, 3 * sizeof(size_t),
873+
implicit_input_value.get(), nullptr);
874+
if (pi_ret_err != PI_SUCCESS)
875+
return pi_ret_err;
876+
input_value = implicit_input_value.get();
877+
}
878+
863879
ret_err = cast<pi_result>(clGetKernelSubGroupInfo(
864880
cast<cl_kernel>(kernel), cast<cl_device_id>(device),
865881
cast<cl_kernel_sub_group_info>(param_name), input_value_size, input_value,

sycl/source/detail/kernel_info.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ get_kernel_device_specific_info(RT::PiKernel Kernel, RT::PiDevice Device,
105105
return sycl::range<3>(Result[0], Result[1], Result[2]);
106106
}
107107

108+
// TODO: This is used by a deprecated version of
109+
// info::kernel_device_specific::max_sub_group_size taking an input paramter.
110+
// This should be removed when the deprecated info query is removed.
108111
template <typename Param>
109112
uint32_t get_kernel_device_specific_info_with_input(RT::PiKernel Kernel,
110113
RT::PiDevice Device,
@@ -178,6 +181,13 @@ inline uint32_t get_kernel_device_specific_info_host<
178181
PI_ERROR_INVALID_KERNEL);
179182
}
180183

184+
template <>
185+
inline uint32_t get_kernel_device_specific_info_host<
186+
info::kernel_device_specific::max_sub_group_size>(const sycl::device &) {
187+
throw invalid_object_error("This instance of kernel is a host instance",
188+
PI_ERROR_INVALID_KERNEL);
189+
}
190+
181191
template <>
182192
inline uint32_t get_kernel_device_specific_info_host<
183193
info::kernel_device_specific::compile_num_sub_groups>(

sycl/source/kernel.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,28 @@ kernel::get_info(const device &Dev) const {
5656
return impl->get_info<Param>(Dev);
5757
}
5858

59+
// Deprecated overload for kernel_device_specific::max_sub_group_size taking
60+
// an extra argument.
5961
template <typename Param>
60-
typename detail::is_kernel_device_specific_info_desc<
61-
Param>::with_input_return_type
62+
typename detail::is_kernel_device_specific_info_desc<Param>::return_type
6263
kernel::get_info(const device &Device, const range<3> &WGSize) const {
64+
static_assert(
65+
std::is_same_v<Param, info::kernel_device_specific::max_sub_group_size>,
66+
"Unexpected param for kernel::get_info with range argument.");
6367
return impl->get_info<Param>(Device, WGSize);
6468
}
6569

6670
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
6771
template __SYCL_EXPORT ReturnT kernel::get_info<info::DescType::Desc>( \
6872
const device &) const;
69-
#define __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(DescType, Desc, ReturnT, InputT, \
70-
PiCode) \
71-
template __SYCL_EXPORT ReturnT kernel::get_info<info::DescType::Desc>( \
72-
const device &, const InputT &) const;
7373

7474
#include <sycl/info/kernel_device_specific_traits.def>
7575

7676
#undef __SYCL_PARAM_TRAITS_SPEC
77-
#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT
77+
78+
template __SYCL_EXPORT uint32_t
79+
kernel::get_info<info::kernel_device_specific::max_sub_group_size>(
80+
const device &, const sycl::range<3> &) const;
7881

7982
kernel::kernel(std::shared_ptr<detail::kernel_impl> Impl) : impl(Impl) {}
8083

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,8 @@ _ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific15work_group_size
42824282
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific16global_work_sizeEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE
42834283
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific16private_mem_sizeEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE
42844284
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific18max_num_sub_groupsEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE
4285-
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific18max_sub_group_sizeEEENS0_6detail35is_kernel_device_specific_info_descIT_E22with_input_return_typeERKNS0_6deviceERKNS0_5rangeILi3EEE
4285+
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific18max_sub_group_sizeEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE
4286+
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific18max_sub_group_sizeEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceERKNS0_5rangeILi3EEE
42864287
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific21ext_codeplay_num_regsEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE
42874288
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific22compile_num_sub_groupsEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE
42884289
_ZNK4sycl3_V16kernel8get_infoINS0_4info22kernel_device_specific22compile_sub_group_sizeEEENS0_6detail35is_kernel_device_specific_info_descIT_E11return_typeERKNS0_6deviceE

0 commit comments

Comments
 (0)