diff --git a/include/itkCudaUtil.h b/include/itkCudaUtil.h index 380e0fe..e7217ce 100644 --- a/include/itkCudaUtil.h +++ b/include/itkCudaUtil.h @@ -55,7 +55,7 @@ GetCudaComputeCapability(int device); int CudaGetAvailableDevices(std::vector & devices); -/** Get the device that has the maximum FLOPS in the current context */ +/** Get the device that has the maximum FLOPS in the current context. The result is cached for future calls. */ int CudaGetMaxFlopsDev(); diff --git a/src/itkCudaUtil.cxx b/src/itkCudaUtil.cxx index bad205b..6f4fcdf 100644 --- a/src/itkCudaUtil.cxx +++ b/src/itkCudaUtil.cxx @@ -69,18 +69,19 @@ CudaGetAvailableDevices(std::vector & devices) } // -// Get the device that has the maximum FLOPS +// Compute the device that has the maximum FLOPS // int -CudaGetMaxFlopsDev() +ComputeMaxFlopsDevice() { std::vector devices; int numAvailableDevices = CudaGetAvailableDevices(devices); + if (numAvailableDevices == 0) { - return -1; } + int max_flops = 0; int max_flops_device = 0; for (int i = 0; i < numAvailableDevices; ++i) @@ -98,6 +99,14 @@ CudaGetMaxFlopsDev() return max_flops_device; } +int +CudaGetMaxFlopsDev() +{ + static const int max_flops_device = ComputeMaxFlopsDevice(); + + return max_flops_device; +} + std::pair GetCudaComputeCapability(int device)