Skip to content

Commit a1f09f1

Browse files
committed
Report OpenCL error to the user when something fails on OpenCL side
Signed-off-by: Mokhov, Dmitri N <[email protected]>
1 parent 8ade560 commit a1f09f1

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

opencl-aot/source/utils.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ getOpenCLPlatform(DeviceType Type) {
195195
formatCLError("Failed to retrieve OpenCL platform IDs", CLErr), CLErr);
196196
}
197197

198+
std::string ErrorMessage;
198199
for (const auto &Platform : Platforms) {
199200
size_t PlatformNameLength = 0;
200201
CLErr = clGetPlatformInfo(Platform, CL_PLATFORM_NAME, 0, nullptr,
@@ -225,28 +226,31 @@ getOpenCLPlatform(DeviceType Type) {
225226
auto Result =
226227
std::find(SupportedPlatformNames.begin(), SupportedPlatformNames.end(),
227228
PlatformNameOnLoopIteration);
228-
if (Result != SupportedPlatformNames.end() && // name match
229-
!clFailed(std::get<2>(getOpenCLDevice(Platform, Type)))) { // type match
230-
PlatformId = Platform;
231-
PlatformName = PlatformNameOnLoopIteration;
232-
break;
229+
if (Result != SupportedPlatformNames.end()) {
230+
tie(std::ignore, ErrorMessage, CLErr) = getOpenCLDevice(Platform, Type);
231+
if (!clFailed(CLErr)) {
232+
PlatformId = Platform;
233+
PlatformName = PlatformNameOnLoopIteration;
234+
break;
235+
}
233236
}
234237
}
235238

236-
std::string ErrorMessage;
237-
if (PlatformId == nullptr) {
238-
ErrorMessage += "OpenCL platform ID is empty\n";
239-
}
240-
if (PlatformName.empty()) {
241-
ErrorMessage += "OpenCL platform name is empty\n";
242-
}
243-
if (!ErrorMessage.empty()) {
244-
ErrorMessage += "Failed to find any of these OpenCL platforms:\n";
245-
for (const auto &SupportedPlatformName :
246-
DeviceTypesToSupportedPlatformNames[Type]) {
247-
ErrorMessage += " " + SupportedPlatformName + '\n';
239+
if (!clFailed(CLErr)) {
240+
if (PlatformId == nullptr) {
241+
ErrorMessage += "OpenCL platform ID is empty\n";
242+
}
243+
if (PlatformName.empty()) {
244+
ErrorMessage += "OpenCL platform name is empty\n";
245+
}
246+
if (!ErrorMessage.empty()) {
247+
ErrorMessage += "Failed to find any of these OpenCL platforms:\n";
248+
for (const auto &SupportedPlatformName :
249+
DeviceTypesToSupportedPlatformNames[Type]) {
250+
ErrorMessage += " " + SupportedPlatformName + '\n';
251+
}
252+
CLErr = OPENCL_AOT_PLATFORM_NOT_FOUND;
248253
}
249-
CLErr = OPENCL_AOT_PLATFORM_NOT_FOUND;
250254
}
251255

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

0 commit comments

Comments
 (0)