Skip to content

Commit e65841b

Browse files
authored
[SYCL] Fix bug in piDeviceGetInfo for subgroup sizes property. (#2248)
Implement getInfoArray for return type which differs from the type returned by Level Zero API. Otherwise incorrect data is copied to the returned array. Signed-off-by: Artur Gainullin <artur.gainullin@intel.com>
1 parent 68ec253 commit e65841b

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ pi_result getInfoArray(size_t array_length, size_t param_value_size,
114114
array_length * sizeof(T), memcpy);
115115
}
116116

117+
template <typename T, typename RetType>
118+
pi_result getInfoArray(size_t array_length, size_t param_value_size,
119+
void *param_value, size_t *param_value_size_ret,
120+
T *value) {
121+
if (param_value) {
122+
memset(param_value, 0, param_value_size);
123+
for (uint32_t I = 0; I < array_length; I++)
124+
((RetType *)param_value)[I] = (RetType)value[I];
125+
}
126+
if (param_value_size_ret)
127+
*param_value_size_ret = array_length * sizeof(RetType);
128+
return PI_SUCCESS;
129+
}
130+
117131
template <>
118132
pi_result getInfo<const char *>(size_t param_value_size, void *param_value,
119133
size_t *param_value_size_ret,
@@ -1061,9 +1075,10 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
10611075
case PI_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: {
10621076
// ze_device_compute_properties.subGroupSizes is in uint32_t whereas the
10631077
// expected return is size_t datatype. size_t can be 8 bytes of data.
1064-
return getInfoArray(Device->ZeDeviceComputeProperties.numSubGroupSizes,
1065-
ParamValueSize, ParamValue, ParamValueSizeRet,
1066-
Device->ZeDeviceComputeProperties.subGroupSizes);
1078+
return getInfoArray<uint32_t, size_t>(
1079+
Device->ZeDeviceComputeProperties.numSubGroupSizes, ParamValueSize,
1080+
ParamValue, ParamValueSizeRet,
1081+
Device->ZeDeviceComputeProperties.subGroupSizes);
10671082
}
10681083
case PI_DEVICE_INFO_IL_VERSION: {
10691084
// Set to a space separated list of IL version strings of the form
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
3+
4+
//==-- get_subgroup_sizes.cpp - Test for bug fix in subgroup sizes query --==//
5+
//
6+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7+
// See https://llvm.org/LICENSE.txt for license information.
8+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#include <CL/sycl.hpp>
13+
14+
using namespace cl::sycl;
15+
16+
int main() {
17+
queue Q;
18+
auto Dev = Q.get_device();
19+
if (Dev.has_extension("cl_intel_required_subgroup_size")) {
20+
cl::sycl::vector_class<size_t> SubGroupSizes =
21+
Dev.get_info<cl::sycl::info::device::sub_group_sizes>();
22+
cl::sycl::vector_class<size_t>::const_iterator MaxIter =
23+
std::max_element(SubGroupSizes.begin(), SubGroupSizes.end());
24+
int MaxSubGroup_size = *MaxIter;
25+
}
26+
return 0;
27+
}

0 commit comments

Comments
 (0)