From f5ba77f4bd7fd99043eb9cf816172ac144a19aa5 Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Thu, 28 Apr 2016 23:20:10 +0100 Subject: [PATCH] List CUDA devices function --- src/CUDAStream.cu | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/CUDAStream.cu b/src/CUDAStream.cu index 3a65f15..2805c1e 100644 --- a/src/CUDAStream.cu +++ b/src/CUDAStream.cu @@ -134,11 +134,35 @@ void CUDAStream::triad() check_error(); } + +template +void CUDAStream::listDevices(void) +{ + // Get number of devices + int count; + cudaGetDeviceCount(&count); + check_error(); + + // Print device names + if (count == 0) + { + std::cout << "No devices found." << std::endl; + } + else + { + std::cout << std::endl; + std::cout << "Devices:" << std::endl; + for (int i = 0; i < count; i++) + { + std::cout << i << ": " << getDeviceName(i) << std::endl; + } + std::cout << std::endl; + } +} + template std::string CUDAStream::getDeviceName(const int device) { - cudaSetDevice(device); - check_error(); cudaDeviceProp props; cudaGetDeviceProperties(&props, device); check_error();