如何将Cublas库与CMake CUDA 10.0 Ubuntu 18

时间:2019-01-24 13:14:42

标签: cmake cuda linker cublas

以下代码是关于我的CMakeList文件的,它可以在CUDA 9.2 Ubuntu 14上很好地工作。但是,当我尝试在新服务器上运行它时,出现错误消息。

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
cmake_minimum_required(VERSION 3.0)

project(LMM)
set(DYLD_LIBRARY_PATH /usr/local/include)
find_package(GSL REQUIRED)
find_package(BLAS REQUIRED)
find_package(CUDA)
if (CUDA_FOUND)
    message("CUDA found")
else()
    message("CUDA not found, doing something alternatively")
endif()

include_directories(test_cuda PRIVARE
                    ${GSL_INCLUDE_DIRS}
                    ${BLAS_INCLUDE_DIRS}
                    ${CUDA_INCLUDE_DIRS}
                    ${CUDA_CUBLAS_DIRS}
                    ${PROJECT_SOURCE_DIR})

add_executable(GPU_LMM main.cpp aux.cpp)
target_link_libraries( GPU_LMM  PRIVATE
                        ${GSL_LIBRARY}
                        ${BLAS_LIBRARIES}
                        ${CUDA_LIBRARIES})

日志信息如下。

-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Found GSL: /usr/include (found version "2.4") 
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- A library with BLAS API found.
-- Found CUDA: /usr/local/cuda (found version "10.0") 
CUDA found
-- Configuring done
-- Generating done

但是,当我运行程序时,出现以下错误消息。

aux.cpp:(.text+0x28d1): undefined reference to `cublasSetVector'
aux.cpp:(.text+0x290e): undefined reference to `cublasSetMatrix'
aux.cpp:(.text+0x2942): undefined reference to `cublasSetMatrix'
aux.cpp:(.text+0x2994): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x29e0): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2a32): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2a6c): undefined reference to `cublasSaxpy_v2'
aux.cpp:(.text+0x2b4a): undefined reference to `cublasSetMatrix'
aux.cpp:(.text+0x2bed): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2c3c): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2c7c): undefined reference to `cublasScopy_v2'
aux.cpp:(.text+0x2cb4): undefined reference to `cublasSaxpy_v2'
aux.cpp:(.text+0x2d1e): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2d6a): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2dbc): undefined reference to `cublasSgemv_v2'
aux.cpp:(.text+0x2df6): undefined reference to `cublasSaxpy_v2'
aux.cpp:(.text+0x2e25): undefined reference to `cublasGetVector'
aux.cpp:(.text+0x2e50): undefined reference to `cublasGetVector'

我确保已在服务器上安装了Cublas,因为我可以复制官方的Cublas演示。添加CUDA_CUBLAS_LIBRARIES时,出现以下错误。

-- A library with BLAS API found.
CUDA found
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_device_LIBRARY (ADVANCED)
    linked by target "GPU_LMM" in directory /home/szhangcj/C++/LMM

-- Configuring incomplete, errors occurred!

1 个答案:

答案 0 :(得分:1)

用于最新CMake版本(例如13.0)的脚本FindCUDA.cmake知道,库cublas_device自CUDA 9.2起不再使用,并且该脚本不会搜索该库。

错误消息记录cublas_device库,这意味着您的FindCUDA.cmake脚本太旧,并且不能与最新的CUDA版本一起使用。

要正确使用find_package(CUDA)和最新的CUDA版本,您需要更新CMake。