From cd112e21337765567499957b8ef72e99d900d2db Mon Sep 17 00:00:00 2001 From: castano Date: Mon, 27 Oct 2008 09:17:09 +0000 Subject: [PATCH] Merge fixes from trunk. Prevent CUDA dll mismatches. --- src/nvtt/cuda/CudaUtils.cpp | 54 ++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/nvtt/cuda/CudaUtils.cpp b/src/nvtt/cuda/CudaUtils.cpp index cd84cf1..fcf2a97 100644 --- a/src/nvtt/cuda/CudaUtils.cpp +++ b/src/nvtt/cuda/CudaUtils.cpp @@ -22,6 +22,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #include +#include #include "CudaUtils.h" #if defined HAVE_CUDA @@ -52,23 +53,52 @@ static bool isWow32() { LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process"); - BOOL bIsWow64 = FALSE; + BOOL bIsWow64 = FALSE; - if (NULL != fnIsWow64Process) - { - if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) - { + if (NULL != fnIsWow64Process) + { + if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) + { // Assume 32 bits. - return true; - } - } + return true; + } + } - return !bIsWow64; + return !bIsWow64; } #endif +static bool isCudaDriverAvailable(uint version) +{ +#if NV_OS_WIN32 + Library nvcuda("nvcuda.dll"); +#else + Library nvcuda(NV_LIBRARY_NAME("cuda")); +#endif + + if (!nvcuda.isValid()) + { + return false; + } + + if (version > 2000) + { + void * address = nvcuda.bindSymbol("cuStreamCreate"); + if (address == NULL) return false; + } + + if (version > 2010) + { + void * address = nvcuda.bindSymbol("cuLoadDataEx"); + if (address == NULL) return false; + } + + return true; +} + + /// Determine if CUDA is available. bool nv::cuda::isHardwarePresent() { @@ -90,6 +120,12 @@ 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 }