Context::Context(LuxRaysDebugHandler handler, const int openclPlatformIndex, const bool verb) { debugHandler = handler; currentDataSet = NULL; started = false; verbose = verb; // Get the list of devices available on the platform NativeThreadDeviceDescription::AddDeviceDescs(deviceDescriptions); #if !defined(LUXRAYS_DISABLE_OPENCL) // Platform info VECTOR_CLASS<cl::Platform> platforms; cl::Platform::get(&platforms); for (size_t i = 0; i < platforms.size(); ++i) LR_LOG(this, "OpenCL Platform " << i << ": " << platforms[i].getInfo<CL_PLATFORM_VENDOR>().c_str()); if (openclPlatformIndex < 0) { if (platforms.size() > 0) { // Just use all the platforms available for (size_t i = 0; i < platforms.size(); ++i) OpenCLDeviceDescription::AddDeviceDescs( platforms[i], DEVICE_TYPE_OPENCL_ALL, deviceDescriptions); } else LR_LOG(this, "No OpenCL platform available"); } else { if ((platforms.size() == 0) || (openclPlatformIndex >= (int)platforms.size())) throw std::runtime_error("Unable to find an appropriate OpenCL platform"); else { OpenCLDeviceDescription::AddDeviceDescs( platforms[openclPlatformIndex], DEVICE_TYPE_OPENCL_ALL, deviceDescriptions); } } #endif // Print device info for (size_t i = 0; i < deviceDescriptions.size(); ++i) { DeviceDescription *desc = deviceDescriptions[i]; LR_LOG(this, "Device " << i << " name: " << desc->GetName()); LR_LOG(this, "Device " << i << " type: " << DeviceDescription::GetDeviceType(desc->GetType())); LR_LOG(this, "Device " << i << " compute units: " << desc->GetComputeUnits()); LR_LOG(this, "Device " << i << " preferred float vector width: " << desc->GetNativeVectorWidthFloat()); LR_LOG(this, "Device " << i << " max allocable memory: " << desc->GetMaxMemory() / (1024 * 1024) << "MBytes"); LR_LOG(this, "Device " << i << " max allocable memory block size: " << desc->GetMaxMemoryAllocSize() / (1024 * 1024) << "MBytes"); } }
HardwareTreeModel::HardwareTreeModel(MainWindow *w, const vector<DeviceDescription *> &devDescs) : QAbstractItemModel() { win = w; rootItem = new HardwareTreeItem("Hardware"); // OpenCL devices HardwareTreeItem *oclDev = new HardwareTreeItem("OpenCL"); rootItem->appendChild(oclDev); HardwareTreeItem *oclCPUDev = new HardwareTreeItem("CPUs"); oclDev->appendChild(oclCPUDev); HardwareTreeItem *oclGPUDev = new HardwareTreeItem("GPUs and Accelerators"); oclDev->appendChild(oclGPUDev); int index = 0; for (size_t i = 0; i < devDescs.size(); ++i) { DeviceDescription *devDesc = devDescs[i]; if (devDesc->GetType() & DEVICE_TYPE_OPENCL_ALL) { const OpenCLDeviceDescription *odevDesc = (OpenCLDeviceDescription *)devDesc; HardwareTreeItem *newNode = new HardwareTreeItem(index++, odevDesc->GetName().c_str()); stringstream ss; cl::Platform platform = odevDesc->GetOCLDevice().getInfo<CL_DEVICE_PLATFORM>(); ss << "Platform: " << platform.getInfo<CL_PLATFORM_VENDOR>(); newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Platform Version: " << platform.getInfo<CL_PLATFORM_VERSION>(); newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Type: "; switch (odevDesc->GetOCLDevice().getInfo<CL_DEVICE_TYPE>()) { case CL_DEVICE_TYPE_CPU: ss << "CPU"; break; case CL_DEVICE_TYPE_GPU: ss << "GPU"; break; case CL_DEVICE_TYPE_ACCELERATOR: ss << "ACCELERATOR"; break; default: ss << "UNKNOWN"; break; } newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Compute Units: " << odevDesc->GetComputeUnits(); newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Clock: " << odevDesc->GetOCLDevice().getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>() << " MHz"; newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Max. Global Memory: " << (odevDesc->GetMaxMemory() / 1024) << " Kbytes"; newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Local Memory: " << (odevDesc->GetOCLDevice().getInfo<CL_DEVICE_LOCAL_MEM_SIZE>() / 1024) << " Kbytes"; newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); ss.str(""); ss << "Max. Constant Memory: " << (odevDesc->GetOCLDevice().getInfo<CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE>() / 1024) << " Kbytes"; newNode->appendChild(new HardwareTreeItem(ss.str().c_str())); bool isCPU = (odevDesc->GetType() == DEVICE_TYPE_OPENCL_CPU); if (isCPU) { // The default mode is GPU-only newNode->setChecked(false); oclCPUDev->appendChild(newNode); } else { newNode->setChecked(true); oclGPUDev->appendChild(newNode); } deviceSelection.push_back(!isCPU); } } }