CUDA 5.0 separate compilation of library with cmake

后端 未结 4 1099
情话喂你
情话喂你 2020-12-05 11:59

The buildtime of my cuda library is increasing and so I thought that separate compilation introduced in CUDA 5.0 might help me. I couldn\'t figure out how to achieve separat

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 12:48

    Tested it with nvcc version:

    nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2012 NVIDIA
    Corporation Built on Fri_Sep_21_17:28:58_PDT_2012 Cuda compilation
    tools, release 5.0, V0.2.1221
    

    and svn revision:

    URL: https://gforge.sci.utah.edu/svn/findcuda/trunk
    Repository Root: https://gforge.sci.utah.edu/svn/findcuda
    Repository UUID: 81322f20-870f-0410-845c-a4cd4664c908
    Revision: 1221
    Node Kind: directory
    Schedule: normal
    Last Changed Rev: 1221
    Last Changed Date: 2013-01-28 22:31:07 +0100 (Mon, 28 Jan 2013)
    

    In this example includes following classes:

    • lib.h / lib.cu
    • kernel.h / kernel.cu

    kernel.cu contains a simple CUDA kernel and a class with a public method to call the CUDA kernel. The class lib contains an instance of the class kernel and a method calling the public method of class kernel.

    Following CMakeLists.txt works with this configuration:

    cmake_minimum_required(VERSION 2.6.2)
    
    project(Cuda-project)
    
    set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/cuda" ${CMAKE_MODULE_PATH})
    
    find_package(CUDA QUIET REQUIRED)
    
    set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF)
    
    set(BUILD_SHARED_LIBS ON)
    
    list(APPEND CUDA_NVCC_FLAGS -DBLAH="he he" -DTEST1="this is a test")
    
    CUDA_ADD_LIBRARY(test_lib
      kernel.cu
      lib.cu
      # SHARED
      # STATIC
      OPTIONS -DSTUFF="blah blah"
      RELEASE --use_fast_math -DNDEBUG
      DEBUG -g -DDEBUG
      )
    
    
    INSTALL(FILES lib.h kernel.h
      DESTINATION include)
    INSTALL(FILES "${CMAKE_BINARY_DIR}/libtest_lib.so" 
      DESTINATION lib)
    

提交回复
热议问题