diff --git a/ChangeLog b/ChangeLog index 67005fe..e437901 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ NVIDIA Texture Tools version 2.0.6 * Fix nvzoom option typo by Frank Richter. Fixes issue 81. * Do not use CUDA to compress small mipmaps. Fixes issue 76. * Compute mipmaps of semi-transparent images correctly. + * Shutdown CUDA properly. Fixes issue 83. NVIDIA Texture Tools version 2.0.5 * Fix error in single color compressor. Fixes issue 66. diff --git a/src/nvtt/Compressor.cpp b/src/nvtt/Compressor.cpp index 8c58674..9613fec 100644 --- a/src/nvtt/Compressor.cpp +++ b/src/nvtt/Compressor.cpp @@ -228,6 +228,7 @@ Compressor::Compressor() : m(*new Compressor::Private()) Compressor::~Compressor() { delete &m; + cuda::exit(); } diff --git a/src/nvtt/cuda/CudaCompressDXT.cpp b/src/nvtt/cuda/CudaCompressDXT.cpp index 687df26..c59bedd 100644 --- a/src/nvtt/cuda/CudaCompressDXT.cpp +++ b/src/nvtt/cuda/CudaCompressDXT.cpp @@ -37,7 +37,7 @@ #if defined HAVE_CUDA -#include +#include #endif #include diff --git a/src/nvtt/cuda/CudaUtils.cpp b/src/nvtt/cuda/CudaUtils.cpp index de73f7e..7bb2b09 100644 --- a/src/nvtt/cuda/CudaUtils.cpp +++ b/src/nvtt/cuda/CudaUtils.cpp @@ -84,19 +84,26 @@ static bool isCudaDriverAvailable(int version) if (!nvcuda.isValid()) { + nvDebug("*** CUDA driver not found.\n"); return false; } if (version >= 2000) { void * address = nvcuda.bindSymbol("cuStreamCreate"); - if (address == NULL) return false; + if (address == NULL) { + nvDebug("*** CUDA driver version < 2.0.\n"); + return false; + } } if (version >= 2010) { void * address = nvcuda.bindSymbol("cuModuleLoadDataEx"); - if (address == NULL) return false; + if (address == NULL) { + nvDebug("*** CUDA driver version < 2.1.\n"); + return false; + } } if (version >= 2020) @@ -104,16 +111,23 @@ static bool isCudaDriverAvailable(int version) typedef CUresult (CUDAAPI * PFCU_DRIVERGETVERSION)(int * version); PFCU_DRIVERGETVERSION driverGetVersion = (PFCU_DRIVERGETVERSION)nvcuda.bindSymbol("cuDriverGetVersion"); - if (driverGetVersion == NULL) return false; + if (driverGetVersion == NULL) { + nvDebug("*** CUDA driver version < 2.2.\n"); + return false; + } int driverVersion; - if (driverGetVersion(&driverVersion) != CUDA_SUCCESS) return false; + CUresult err = driverGetVersion(&driverVersion); + if (err != CUDA_SUCCESS) { + nvDebug("*** Error querying driver version: '%s'.\n", cudaGetErrorString((cudaError_t)err)); + return false; + } return driverVersion >= version; } #endif // HAVE_CUDA - return false; + return true; } @@ -121,10 +135,13 @@ static bool isCudaDriverAvailable(int version) bool nv::cuda::isHardwarePresent() { #if defined HAVE_CUDA -#if NV_OS_WIN32 - //if (isWindowsVista()) return false; - //if (isWindowsVista() || !isWow32()) return false; -#endif + // Make sure that CUDA driver matches CUDA runtime. + if (!isCudaDriverAvailable(CUDART_VERSION)) + { + nvDebug("CUDA driver not available for CUDA runtime %d\n", CUDART_VERSION); + return false; + } + int count = deviceCount(); if (count == 1) { @@ -137,16 +154,10 @@ bool nv::cuda::isHardwarePresent() { return false; } - - // Make sure that CUDA driver matches CUDA runtime. - if (!isCudaDriverAvailable(CUDART_VERSION)) - { - return false; - } - - // @@ Make sure that warp size == 32 } + // @@ Make sure that warp size == 32 + return count > 0; #else return false; @@ -205,8 +216,24 @@ bool nv::cuda::setDevice(int i) nvCheck(i < deviceCount()); #if defined HAVE_CUDA cudaError_t result = cudaSetDevice(i); + + if (result != cudaSuccess) { + nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result)); + } + return result == cudaSuccess; #else return false; #endif } + +void nv::cuda::exit() +{ +#if defined HAVE_CUDA + cudaError_t result = cudaThreadExit(); + + if (result != cudaSuccess) { + nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result)); + } +#endif +} diff --git a/src/nvtt/cuda/CudaUtils.h b/src/nvtt/cuda/CudaUtils.h index 6965960..376bbe1 100644 --- a/src/nvtt/cuda/CudaUtils.h +++ b/src/nvtt/cuda/CudaUtils.h @@ -33,6 +33,7 @@ namespace nv int deviceCount(); int getFastestDevice(); bool setDevice(int i); + void exit(); }; } // nv namespace