summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-04-03 21:45:18 +0200
committerCedric Nugteren <web@cedricnugteren.nl>2017-04-03 21:45:18 +0200
commit0cebcbcc71d8c2d52b0d339fc75032e189d5946f (patch)
treea1cc3d80027ccc28e17f82114bea350cac4d8264
parenteb1fda2729c4022493aa874e3fe81d2a270085a1 (diff)
Added proper CMake searching for CUDA and cuBLAS
-rw-r--r--CMakeLists.txt17
-rw-r--r--cmake/Modules/FindcuBLAS.cmake82
2 files changed, 88 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9af0b91..0fb04071 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,18 +129,13 @@ if(TUNERS)
endif()
endif()
-# Locates the reference BLAS libraries in case the tests need to be compiled. The "FindclBLAS.cmake"
-# and "FindCBLAS.cmake" are included, "FindCUDA.cmake" is provided by CMake.
+# Locates the reference BLAS libraries in case the tests need to be compiled. The "FindclBLAS.cmake",
+# "FindCBLAS.cmake" and "FindcuBLAS.cmake" are included.
if(CLIENTS OR TESTS)
find_package(clBLAS)
find_package(CBLAS)
- find_package(CUDA QUIET) # for cuBLAS
- if(CUDA_FOUND)
- message(STATUS "CUDA and cuBLAS found")
- else()
- message(STATUS "Could not find cuBLAS as a reference")
- endif()
- if(NOT CLBLAS_FOUND AND NOT CBLAS_FOUND AND NOT CUDA_FOUND)
+ find_package(cuBLAS)
+ if(NOT CLBLAS_FOUND AND NOT CBLAS_FOUND AND NOT CUBLAS_FOUND)
if(TESTS)
message(STATUS "Could NOT find clBLAS nor a CPU BLAS nor cuBLAS, disabling the compilation of the tests")
set(TESTS OFF)
@@ -326,9 +321,9 @@ if(CLIENTS OR TESTS)
add_definitions(" -DCLBLAST_REF_CBLAS")
endif()
endif()
- if(CUDA_FOUND)
+ if(CUBLAS_FOUND)
set(REF_INCLUDES ${REF_INCLUDES} ${CUDA_INCLUDE_DIRS})
- set(REF_LIBRARIES ${REF_LIBRARIES} ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES})
+ set(REF_LIBRARIES ${REF_LIBRARIES} ${CUDA_LIBRARIES} ${CUBLAS_LIBRARIES})
if(MSVC)
add_definitions(" /DCLBLAST_REF_CUBLAS")
else()
diff --git a/cmake/Modules/FindcuBLAS.cmake b/cmake/Modules/FindcuBLAS.cmake
new file mode 100644
index 00000000..e470289b
--- /dev/null
+++ b/cmake/Modules/FindcuBLAS.cmake
@@ -0,0 +1,82 @@
+
+# ==================================================================================================
+# This file is part of the cuBLASt project. The project is licensed under Apache Version 2.0. This
+# project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
+# width of 100 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+#
+# ==================================================================================================
+#
+# Defines the following variables:
+# CUBLAS_FOUND Boolean holding whether or not the cuBLAS library was found
+# CUBLAS_INCLUDE_DIRS The CUDA and cuBLAS include directory
+# CUDA_LIBRARIES The CUDA library
+# CUBLAS_LIBRARIES The cuBLAS library
+#
+# In case CUDA is not installed in the default directory, set the CUDA_ROOT variable to point to
+# the root of cuBLAS, such that 'cublas_v2.h' can be found in $CUDA_ROOT/include. This can either be
+# done using an environmental variable (e.g. export CUDA_ROOT=/path/to/cuBLAS) or using a CMake
+# variable (e.g. cmake -DCUDA_ROOT=/path/to/cuBLAS ..).
+#
+# ==================================================================================================
+
+# Sets the possible install locations
+set(CUBLAS_HINTS
+ ${CUDA_ROOT}
+ $ENV{CUDA_ROOT}
+ $ENV{CUDA_TOOLKIT_ROOT_DIR}
+)
+set(CUBLAS_PATHS
+ /usr
+ /usr/local
+ /usr/local/cuda
+)
+
+# Finds the include directories
+find_path(CUBLAS_INCLUDE_DIRS
+ NAMES cublas_v2.h cuda.h
+ HINTS ${CUBLAS_HINTS}
+ PATH_SUFFIXES include inc include/x86_64 include/x64
+ PATHS ${CUBLAS_PATHS}
+ DOC "cuBLAS include header cublas_v2.h"
+)
+mark_as_advanced(CUBLAS_INCLUDE_DIRS)
+
+# Finds the libraries
+find_library(CUDA_LIBRARIES
+ NAMES cudart
+ HINTS ${CUBLAS_HINTS}
+ PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import
+ PATHS ${CUBLAS_PATHS}
+ DOC "CUDA library"
+)
+mark_as_advanced(CUDA_LIBRARIES)
+find_library(CUBLAS_LIBRARIES
+ NAMES cublas
+ HINTS ${CUBLAS_HINTS}
+ PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import
+ PATHS ${CUBLAS_PATHS}
+ DOC "cuBLAS library"
+)
+mark_as_advanced(CUBLAS_LIBRARIES)
+
+# ==================================================================================================
+
+# Notification messages
+if(NOT CUBLAS_INCLUDE_DIRS)
+ message(STATUS "Could NOT find 'cuBLAS.h', install CUDA/cuBLAS or set CUDA_ROOT")
+endif()
+if(NOT CUDA_LIBRARIES)
+ message(STATUS "Could NOT find CUDA library, install it or set CUDA_ROOT")
+endif()
+if(NOT CUBLAS_LIBRARIES)
+ message(STATUS "Could NOT find cuBLAS library, install it or set CUDA_ROOT")
+endif()
+
+# Determines whether or not cuBLAS was found
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(cuBLAS DEFAULT_MSG CUBLAS_INCLUDE_DIRS CUDA_LIBRARIES CUBLAS_LIBRARIES)
+
+# ==================================================================================================