From 39f608642baf2ffb6589a6a385cdfffdacaff479 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 10 Apr 2023 01:03:59 +0200 Subject: [PATCH] luxmark: catch OpenCL errors like CL_DEVICE_NOT_FOUND when listing devices The application should not crash because there is no OpenCL device. --- src/hardwaretree.cpp | 67 ++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/hardwaretree.cpp b/src/hardwaretree.cpp index 2965fba..07ee9a1 100644 --- a/src/hardwaretree.cpp +++ b/src/hardwaretree.cpp @@ -178,49 +178,54 @@ HardwareTreeModel::HardwareTreeModel(MainWindow *w, const bool useCPU, nativeCPUNode->setChecked(useCPU); nativeDev->appendChild(nativeCPUNode); - // Retrieve the hardware information with LuxCore - const Properties hwDevDescs = GetOpenCLDeviceDescs(); - const vector hwDevDescPrefixs = hwDevDescs.GetAllUniqueSubNames("opencl.device"); - // Build the list of devices bool hasCUDAdevs = false; const bool isOptixAvailable = luxcore::GetPlatformDesc().Get("compile.LUXRAYS_ENABLE_CUDA").Get() && luxcore::GetPlatformDesc().Get("compile.LUXRAYS_ENABLE_OPTIX").Get(); - for (size_t i = 0; i < hwDevDescPrefixs.size(); ++i) { - const string &prefix = hwDevDescPrefixs[i]; - BenchmarkDeviceDescription deviceDesc; + // Retrieve the hardware information with LuxCore + try { + const Properties hwDevDescs = GetOpenCLDeviceDescs(); + const vector hwDevDescPrefixs = hwDevDescs.GetAllUniqueSubNames("opencl.device"); - deviceDesc.deviceName = hwDevDescs.Get(prefix + ".name").Get(); - deviceDesc.platformName = hwDevDescs.Get(prefix + ".platform.name").Get(); - deviceDesc.platformVersion = hwDevDescs.Get(prefix + ".platform.version").Get(); - deviceDesc.deviceType = hwDevDescs.Get(prefix + ".type").Get(); - deviceDesc.units = hwDevDescs.Get(prefix + ".units").Get(); - deviceDesc.clock = hwDevDescs.Get(prefix + ".clock").Get(); - deviceDesc.nativeVectorWidthFloat = hwDevDescs.Get(prefix + ".nativevectorwidthfloat").Get(); - deviceDesc.globalMem = hwDevDescs.Get(prefix + ".maxmemory").Get(); - deviceDesc.localMem = hwDevDescs.Get(prefix + ".localmemory").Get(); - deviceDesc.constantMem = hwDevDescs.Get(prefix + ".constmemory").Get(); + for (size_t i = 0; i < hwDevDescPrefixs.size(); ++i) { + const string &prefix = hwDevDescPrefixs[i]; - deviceDesc.cudaMajorVersion = 0; - deviceDesc.cudaMinorVersion = 0; + BenchmarkDeviceDescription deviceDesc; - deviceDesc.isCUDA = (deviceDesc.deviceType == "CUDA_GPU"); - deviceDesc.isOpenCL = !deviceDesc.isCUDA; - deviceDesc.isOpenCLCPU = deviceDesc.isOpenCL && (deviceDesc.deviceType == "OPENCL_CPU"); + deviceDesc.deviceName = hwDevDescs.Get(prefix + ".name").Get(); + deviceDesc.platformName = hwDevDescs.Get(prefix + ".platform.name").Get(); + deviceDesc.platformVersion = hwDevDescs.Get(prefix + ".platform.version").Get(); + deviceDesc.deviceType = hwDevDescs.Get(prefix + ".type").Get(); + deviceDesc.units = hwDevDescs.Get(prefix + ".units").Get(); + deviceDesc.clock = hwDevDescs.Get(prefix + ".clock").Get(); + deviceDesc.nativeVectorWidthFloat = hwDevDescs.Get(prefix + ".nativevectorwidthfloat").Get(); + deviceDesc.globalMem = hwDevDescs.Get(prefix + ".maxmemory").Get(); + deviceDesc.localMem = hwDevDescs.Get(prefix + ".localmemory").Get(); + deviceDesc.constantMem = hwDevDescs.Get(prefix + ".constmemory").Get(); - if (deviceDesc.isCUDA) { - deviceDesc.cudaMajorVersion = hwDevDescs.Get(prefix + ".cuda.compute.major").Get(); - deviceDesc.cudaMinorVersion = hwDevDescs.Get(prefix + ".cuda.compute.minor").Get(); + deviceDesc.cudaMajorVersion = 0; + deviceDesc.cudaMinorVersion = 0; - stringstream ss; - ss << "CUDA " << deviceDesc.cudaMajorVersion << "." << deviceDesc.cudaMinorVersion; - deviceDesc.platformVersion = ss.str(); - } + deviceDesc.isCUDA = (deviceDesc.deviceType == "CUDA_GPU"); + deviceDesc.isOpenCL = !deviceDesc.isCUDA; + deviceDesc.isOpenCLCPU = deviceDesc.isOpenCL && (deviceDesc.deviceType == "OPENCL_CPU"); - deviceDescs.push_back(deviceDesc); + if (deviceDesc.isCUDA) { + deviceDesc.cudaMajorVersion = hwDevDescs.Get(prefix + ".cuda.compute.major").Get(); + deviceDesc.cudaMinorVersion = hwDevDescs.Get(prefix + ".cuda.compute.minor").Get(); - hasCUDAdevs = hasCUDAdevs || deviceDesc.isCUDA; + stringstream ss; + ss << "CUDA " << deviceDesc.cudaMajorVersion << "." << deviceDesc.cudaMinorVersion; + deviceDesc.platformVersion = ss.str(); + } + + deviceDescs.push_back(deviceDesc); + + hasCUDAdevs = hasCUDAdevs || deviceDesc.isCUDA; + } + } catch (runtime_error &err) { + LM_ERROR("RUNTIME ERROR: " << err.what()); } size_t cudaDeviceIndex = 0;