From 3b3f6dfc260f9fb0928753dd699435ae5f45cc80 Mon Sep 17 00:00:00 2001 From: James Price Date: Sun, 8 May 2016 19:22:09 +0100 Subject: [PATCH] [SYCL] Implement device list/selection functionality --- SYCLStream.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/SYCLStream.cpp b/SYCLStream.cpp index fc76a82..c6947e7 100644 --- a/SYCLStream.cpp +++ b/SYCLStream.cpp @@ -13,11 +13,20 @@ using namespace cl::sycl; #define WGSIZE 64 +// Cache list of devices +bool cached = false; +std::vector devices; +void getDeviceList(void); + template SYCLStream::SYCLStream(const unsigned int ARRAY_SIZE, const int device_index) { array_size = ARRAY_SIZE; + // Print out device information + std::cout << "Using SYCL device " << getDeviceName(device_index) << std::endl; + std::cout << "Driver: " << getDeviceDriver(device_index) << std::endl; + // Create buffers d_a = new buffer(array_size); d_b = new buffer(array_size); @@ -124,25 +133,78 @@ void SYCLStream::read_arrays(std::vector& a, std::vector& b, std::vecto } } +void getDeviceList(void) +{ + // Get list of platforms + std::vector platforms = platform::get_platforms(); + + // Enumerate devices + for (unsigned i = 0; i < platforms.size(); i++) + { + std::vector plat_devices = platforms[i].get_devices(); + devices.insert(devices.end(), plat_devices.begin(), plat_devices.end()); + } + cached = true; +} + void listDevices(void) { - // TODO: Get actual list of devices - std::cout << std::endl; - std::cout << "Devices:" << std::endl; - std::cout << "0: " << "triSYCL" << std::endl; - std::cout << std::endl; + getDeviceList(); + + // Print device names + if (devices.size() == 0) + { + std::cerr << "No devices found." << std::endl; + } + else + { + std::cout << std::endl; + std::cout << "Devices:" << std::endl; + for (int i = 0; i < devices.size(); i++) + { + std::cout << i << ": " << getDeviceName(i) << std::endl; + } + std::cout << std::endl; + } } std::string getDeviceName(const int device) { - // TODO: Implement properly - return "triSYCL"; + if (!cached) + getDeviceList(); + + std::string name; + cl_device_info info = CL_DEVICE_NAME; + + if (device < devices.size()) + { + name = devices[device].get_info(); + } + else + { + throw std::runtime_error("Error asking for name for non-existant device"); + } + + return name; } std::string getDeviceDriver(const int device) { - // TODO: Implement properly - return "triSCYL"; + if (!cached) + getDeviceList(); + + std::string driver; + + if (device < devices.size()) + { + driver = devices[device].get_info(); + } + else + { + throw std::runtime_error("Error asking for driver for non-existant device"); + } + + return driver; }