Made CMake try to compile a CUDA test project to see if the compiler the user is trying

really supports the version of CUDA we found.
This commit is contained in:
Davis King 2015-10-17 22:51:09 -04:00
parent 681abe787e
commit c5f320e69d
3 changed files with 43 additions and 3 deletions

View File

@ -433,9 +433,20 @@ if (NOT TARGET dlib)
/usr/local/lib
)
mark_as_advanced(cudnn cudnn_include)
if (cudnn)
# make sure cuda is really working by doing a test compile
message(STATUS "Building a CUDA test project to see if your compiler is compatible with CUDA...")
try_compile(cuda_test_compile_worked ${PROJECT_BINARY_DIR}/cuda_test_build
${PROJECT_SOURCE_DIR}/dnn/test_for_cuda cuda_test)
if (NOT cuda_test_compile_worked)
message(STATUS "*** CUDA was found but your compiler failed to compile a simple CUDA program so dlib isn't going to use CUDA.***")
endif()
endif()
endif()
if (CUDA_FOUND AND cudnn AND cudnn_include AND COMPILER_CAN_DO_CPP_11)
if (CUDA_FOUND AND cudnn AND cudnn_include AND COMPILER_CAN_DO_CPP_11 AND cuda_test_compile_worked)
message(STATUS "Found cuDNN: " ${cudnn})
set(source_files ${source_files}
dnn/cuda_dlib.cu
@ -449,10 +460,10 @@ if (NOT TARGET dlib)
set(DLIB_USE_CUDA OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_CUDA)
if (NOT cudnn OR NOT cudnn_include)
message(STATUS "cuDNN NOT FOUND. DLIB WILL NOT USE CUDA.")
message(STATUS "***cuDNN NOT FOUND. DLIB WILL NOT USE CUDA.***")
endif()
if (NOT COMPILER_CAN_DO_CPP_11)
message(STATUS "Dlib CUDA support requires C++11 but your compiler doesn't support it.")
message(STATUS "***Dlib CUDA support requires C++11 but your compiler doesn't support it.***")
endif()
endif()
endif()

View File

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 2.8.4)
project(cuda_test)
find_package(CUDA 7.0 REQUIRED)
set(CUDA_HOST_COMPILATION_CPP ON)
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_30;-std=c++11;-D__STRICT_ANSI__")
cuda_add_library(cuda_test STATIC cuda_test.cu )

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <cuda_runtime.h>
// ------------------------------------------------------------------------------------
__global__ void cuda_add_arrays(const float* a, const float* b, float* out, size_t n)
{
out[0] += a[0]+b[0];
}
void add_arrays()
{
cuda_add_arrays<<<512,512>>>(0,0,0,0);
}
// ------------------------------------------------------------------------------------