Issues linking cublas to library created using cmake,

Hello, I am trying to link the Cublas to another library using CMake however I can’t seem to get it to work. I am consistently getting an error that there is undefined reference to the cublas functions. You can see the code I am using at the base of this post.

Relevant info:

  • CMAKE --version = 3.10
  • CUDA --version = 10.2
  • System =Jetson Nano Developer Kit with the default image

Thanks in advance for any help, have been struggling with this for a few days, if this post would be more suited to another nvidia forum please feel free to move it.

CODE

cmake_minimum_required(VERSION 3.10)
project(CLDL LANGUAGES CUDA CXX )

add_subdirectory(gpu_tests)

add_subdirectory(gtest)

add_subdirectory(ecg_tests)

add_subdirectory(wav_tests)

enable_testing()

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};
-rdc=true;)

add_library(CLDL SHARED
lib/Neuron.cu
lib/Layer.cu
lib/Net.cu)

set_target_properties(
CLDL
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON
POSITION_INDEPENDENT_CODE ON)

target_include_directories(CLDL
PUBLIC
include/)

find_package(Threads)
find_package(CUDA REQUIRED)

target_link_libraries(CLDL curand )
target_link_libraries(CLDL ${CUDA_LIBRARIES})
target_link_libraries(CLDL cublas)
target_link_libraries(CLDL ${CMAKE_THREAD_LIBS_INIT})

Hi,

Please check if the below topic helps:

Thanks.

Hi AastaLLL,

Thanks for your reply, I have tried this solution previously.

When adding:

${CUDA_CUBLAS_LIBRARIES}

I get an error saying:
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 “CLDL” in directory /home/luca/Documents/CLDL-CUDA

I assume this is because it cannot find the cublas library. Just to confirm I am 100% cublas is installed as I have linked it to a project previously in order to test some of the functions, I did this in cmake using the following code (this is one of the subdirectories of the previous cmakelists I posted). I have made the section which links it bold. While this works to link to executables I am required to link Cublas to the library created in the Cmake file (CLDL in this case):

cmake_minimum_required(VERSION 3.10)

project(tests LANGUAGES CUDA CXX C)

add_executable(gpu_testing
gpu_tests.cu
)

add_executable(testing_input_prop
testing_individual_elements_of_gpu_code.cu
)

add_executable(standard_gpu_times
testing_standard_gpu_times.cu
)

target_link_libraries(gpu_testing PRIVATE CLDL)
target_link_libraries(testing_input_prop PRIVATE CLDL)
target_link_libraries(standard_gpu_times -lcublas -lcurand)

set(tests_force_shared_crt ON FORCE)

set_property(
TARGET
gpu_testing
PROPERTY
CUDA_RESOLVE_DEVICE_SYMBOLS ON)

Thanks in advance for any further help that can be offered.

Hi,

Alternatively, does manually setup the variable work?
Thanks.