Skip to content

Commit d83edd4

Browse files
committed
[SYCL] Fix platform selection in opencl-aot
Before picking a matched platform name, ensure the device type also matches. This fixes a mismatch issue that was caused by an identical supported platform name for CPU and GPU. Only iterate through available platforms. When the error message is non-empty, always return CLErr, so that the message is shown. Signed-off-by: Dmitri Mokhov <[email protected]>
1 parent 86acff3 commit d83edd4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

opencl-aot/source/utils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ getOpenCLPlatform(DeviceType Type) {
179179
std::string PlatformName;
180180

181181
const cl_uint MaxPlatformsCount = 10;
182-
std::array<cl_platform_id, MaxPlatformsCount> Platforms{};
182+
std::vector<cl_platform_id> Platforms(MaxPlatformsCount);
183183

184184
cl_uint PlatformsCount = 0;
185185
CLErr =
@@ -190,6 +190,7 @@ getOpenCLPlatform(DeviceType Type) {
190190
formatCLError("Failed to retrieve OpenCL platform IDs", CLErr), CLErr);
191191
}
192192

193+
Platforms.resize(PlatformsCount);
193194
for (const auto &Platform : Platforms) {
194195
size_t PlatformNameLength = 0;
195196
CLErr = clGetPlatformInfo(Platform, CL_PLATFORM_NAME, 0, nullptr,
@@ -220,7 +221,8 @@ getOpenCLPlatform(DeviceType Type) {
220221
auto Result =
221222
std::find(SupportedPlatformNames.begin(), SupportedPlatformNames.end(),
222223
PlatformNameOnLoopIteration);
223-
if (Result != SupportedPlatformNames.end()) {
224+
if (Result != SupportedPlatformNames.end() && // name match
225+
!clFailed(std::get<2>(getOpenCLDevice(Platform, Type)))) { // type match
224226
PlatformId = Platform;
225227
PlatformName = PlatformNameOnLoopIteration;
226228
break;
@@ -240,6 +242,7 @@ getOpenCLPlatform(DeviceType Type) {
240242
DeviceTypesToSupportedPlatformNames[Type]) {
241243
ErrorMessage += " " + SupportedPlatformName + '\n';
242244
}
245+
CLErr = OPENCL_AOT_DEVICE_ID_IS_EMPTY;
243246
}
244247

245248
return std::make_tuple(PlatformId, PlatformName, ErrorMessage, CLErr);

0 commit comments

Comments
 (0)