#include "Mandel.h" #include "CpuGenerators.h" #include "ClGenerators.h" using mnd::MandelDevice; using mnd::MandelContext; using mnd::Generator; MandelContext mnd::initializeContext(void) { MandelContext context = MandelContext(); return context; } MandelDevice::MandelDevice(void) : floatGenerator{ nullptr }, doubleGenerator{ nullptr } { } mnd::Generator* MandelDevice::getGeneratorFloat(void) const { if (floatGenerator) return floatGenerator.get(); else return nullptr; } mnd::Generator* MandelDevice::getGeneratorDouble(void) const { if (doubleGenerator) return doubleGenerator.get(); else return nullptr; } MandelContext::MandelContext(void) { if (cpuInfo.hasAvx()) { cpuGeneratorFloat = std::make_unique(); cpuGeneratorDouble = std::make_unique(); } else if (cpuInfo.hasSse2()) { cpuGeneratorFloat = std::make_unique(); cpuGeneratorDouble = std::make_unique(); } else { cpuGeneratorFloat = std::make_unique(); cpuGeneratorDouble = std::make_unique(); } cpuGenerator128 = std::make_unique(); devices = createDevices(); } std::vector MandelContext::createDevices(void) { std::vector mandelDevices; std::vector platforms; cl::Platform::get(&platforms); platforms.erase(platforms.begin() + 1); for (auto& platform : platforms) { std::string name = platform.getInfo(); std::string profile = platform.getInfo(); std::string ext = platform.getInfo(); printf("Platform extensions: %s\n", ext.c_str()); printf("Platform: %s, %s\n", name.c_str(), profile.c_str()); std::vector devices; platform.getDevices(CL_DEVICE_TYPE_GPU, &devices); for (auto& device : devices) { //printf("Device: %s\n", device.getInfo().c_str()); //printf("preferred float width: %d\n", device.getInfo()); //printf("vendor: %s\n", device.getInfo().c_str()); std::string extensions = device.getInfo(); auto supportsDouble = extensions.find("cl_khr_fp64") != std::string::npos; printf("Device extensions: %s\n", ext.c_str()); MandelDevice md; printf("clock: %d", device.getInfo()); md.name = device.getInfo(); md.vendor = device.getInfo(); try { md.floatGenerator = std::make_unique(device); } catch (const std::string& err) { printf("err: %s", err.c_str()); } if (supportsDouble) { try { md.doubleGenerator = std::make_unique(device); } catch (const std::string& err) { } } mandelDevices.push_back(std::move(md)); } } return mandelDevices; } const std::string& MandelDevice::getName(void) const { return name; } Generator& MandelContext::getDefaultGenerator(void) { return getCpuGeneratorDouble(); } const std::vector& MandelContext::getDevices(void) { return devices; } Generator& MandelContext::getCpuGeneratorFloat(void) { return *cpuGeneratorFloat; } Generator& MandelContext::getCpuGeneratorDouble(void) { return *cpuGeneratorDouble; } Generator& MandelContext::getCpuGenerator128(void) { return *cpuGenerator128; }