[SYCL] Implement device list/selection functionality
This commit is contained in:
parent
58fa72dee0
commit
3b3f6dfc26
@ -13,11 +13,20 @@ using namespace cl::sycl;
|
|||||||
|
|
||||||
#define WGSIZE 64
|
#define WGSIZE 64
|
||||||
|
|
||||||
|
// Cache list of devices
|
||||||
|
bool cached = false;
|
||||||
|
std::vector<device> devices;
|
||||||
|
void getDeviceList(void);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
SYCLStream<T>::SYCLStream(const unsigned int ARRAY_SIZE, const int device_index)
|
SYCLStream<T>::SYCLStream(const unsigned int ARRAY_SIZE, const int device_index)
|
||||||
{
|
{
|
||||||
array_size = ARRAY_SIZE;
|
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
|
// Create buffers
|
||||||
d_a = new buffer<T>(array_size);
|
d_a = new buffer<T>(array_size);
|
||||||
d_b = new buffer<T>(array_size);
|
d_b = new buffer<T>(array_size);
|
||||||
@ -124,25 +133,78 @@ void SYCLStream<T>::read_arrays(std::vector<T>& a, std::vector<T>& b, std::vecto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getDeviceList(void)
|
||||||
|
{
|
||||||
|
// Get list of platforms
|
||||||
|
std::vector<platform> platforms = platform::get_platforms();
|
||||||
|
|
||||||
|
// Enumerate devices
|
||||||
|
for (unsigned i = 0; i < platforms.size(); i++)
|
||||||
|
{
|
||||||
|
std::vector<device> plat_devices = platforms[i].get_devices();
|
||||||
|
devices.insert(devices.end(), plat_devices.begin(), plat_devices.end());
|
||||||
|
}
|
||||||
|
cached = true;
|
||||||
|
}
|
||||||
|
|
||||||
void listDevices(void)
|
void listDevices(void)
|
||||||
{
|
{
|
||||||
// TODO: Get actual list of devices
|
getDeviceList();
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Devices:" << std::endl;
|
// Print device names
|
||||||
std::cout << "0: " << "triSYCL" << std::endl;
|
if (devices.size() == 0)
|
||||||
std::cout << std::endl;
|
{
|
||||||
|
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)
|
std::string getDeviceName(const int device)
|
||||||
{
|
{
|
||||||
// TODO: Implement properly
|
if (!cached)
|
||||||
return "triSYCL";
|
getDeviceList();
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
cl_device_info info = CL_DEVICE_NAME;
|
||||||
|
|
||||||
|
if (device < devices.size())
|
||||||
|
{
|
||||||
|
name = devices[device].get_info<info::device::name>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Error asking for name for non-existant device");
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getDeviceDriver(const int device)
|
std::string getDeviceDriver(const int device)
|
||||||
{
|
{
|
||||||
// TODO: Implement properly
|
if (!cached)
|
||||||
return "triSCYL";
|
getDeviceList();
|
||||||
|
|
||||||
|
std::string driver;
|
||||||
|
|
||||||
|
if (device < devices.size())
|
||||||
|
{
|
||||||
|
driver = devices[device].get_info<info::device::driver_version>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Error asking for driver for non-existant device");
|
||||||
|
}
|
||||||
|
|
||||||
|
return driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user