"vscode:/vscode.git/clone" did not exist on "d389e504d64c14e10445426b1f2101d04c6ca180"
Commit 68c89df6 authored by Christopher Bruns's avatar Christopher Bruns
Browse files

Refactored cmake build system to use just one FindCUDA.cmake, under cmake_modules subdirectory,

based on the FindCUDA.cmake that was in the platforms/cuda/cuda-make directory.
Setting of CUDA_NVCC_FLAGS is now in top-level CMakeLists.txt, in case I ever figure out how
to get this working with the cmake 2.8 installed system version of FindCUDA.cmake.
Before this change, there were three separate FindCUDA.cmake areas.  Now there is just one.
parent 6768d049
...@@ -14,15 +14,28 @@ ...@@ -14,15 +14,28 @@
# libOpenMM_static[_d].a # libOpenMM_static[_d].a
#---------------------------------------------------- #----------------------------------------------------
# Don't create a new project name if this is part of a mega-build from the
# parent directory
IF( NOT PROJECT_NAME )
PROJECT (OpenMM)
ENDIF( NOT PROJECT_NAME )
# On Linux it appears that cmake 2.4 does not work with Cuda cmake rules # On Linux it appears that cmake 2.4 does not work with Cuda cmake rules
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
#SET(CMAKE_VERBOSE_MAKEFILE 1) #SET(CMAKE_VERBOSE_MAKEFILE 1)
# CMake 2.4 on dart server only needs to know about Dart
INCLUDE(Dart)
MARK_AS_ADVANCED(DART_ROOT)
# Avoid dart server problem with cmake 2.4 --cmb
set(cmv "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
IF(NOT cmv EQUAL "2.4") # This whole file...
# We have custom cmake modules for FindOpenMM and running python tests # We have custom cmake modules for FindOpenMM and running python tests
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules") SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
# Does someone at Kitware actually believe that this policy crap # Does someone at Kitware actually believe that this policy crap
# might actually make cmake LESS brittle? # might actually make cmake LESS brittle?
# (Probably the same genius who came up the endif(allthesamecrap) syntax) # (Probably the same genius who came up the endif(allthesamecrap) syntax)
...@@ -41,12 +54,6 @@ if(COMMAND cmake_policy) ...@@ -41,12 +54,6 @@ if(COMMAND cmake_policy)
endif(CMAKE_MAJOR_VERSION GREATER 2 OR CMAKE_MINOR_VERSION GREATER 6 OR CMAKE_PATCH_VERSION GREATER 2) endif(CMAKE_MAJOR_VERSION GREATER 2 OR CMAKE_MINOR_VERSION GREATER 6 OR CMAKE_PATCH_VERSION GREATER 2)
endif(COMMAND cmake_policy) endif(COMMAND cmake_policy)
# Don't create a new project name if this is part of a mega-build from the
# parent directory
IF( NOT PROJECT_NAME )
PROJECT (OpenMM)
ENDIF( NOT PROJECT_NAME )
# Where to install # Where to install
IF(${CMAKE_C_COMPILER} MATCHES "gcc") IF(${CMAKE_C_COMPILER} MATCHES "gcc")
IF(NOT OPENMM_INSTALL_PREFIX) IF(NOT OPENMM_INSTALL_PREFIX)
...@@ -69,9 +76,6 @@ IF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) ...@@ -69,9 +76,6 @@ IF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
SET(CMAKE_INSTALL_PREFIX ${OPENMM_INSTALL_PREFIX} CACHE PATH "Where to install OpenMM" FORCE) SET(CMAKE_INSTALL_PREFIX ${OPENMM_INSTALL_PREFIX} CACHE PATH "Where to install OpenMM" FORCE)
ENDIF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) ENDIF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
INCLUDE(Dart)
MARK_AS_ADVANCED(DART_ROOT)
# The source is organized into subdirectories, but we handle them all from # The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS. # this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET(OPENMM_SOURCE_SUBDIRS . openmmapi olla libraries/jama libraries/quern libraries/lepton platforms/reference libraries/validate) SET(OPENMM_SOURCE_SUBDIRS . openmmapi olla libraries/jama libraries/quern libraries/lepton platforms/reference libraries/validate)
...@@ -261,9 +265,6 @@ FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS}) ...@@ -261,9 +265,6 @@ FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include) INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir) ENDFOREACH(subdir)
# Avoid dart server problem with cmake 2.4 --cmb
set(cmv "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
# If API wrappers are being generated, and add them to the build. # If API wrappers are being generated, and add them to the build.
# Java and gccxml are required for API wrappers # Java and gccxml are required for API wrappers
FIND_PACKAGE(Java) FIND_PACKAGE(Java)
...@@ -314,10 +315,27 @@ ADD_SUBDIRECTORY(platforms/reference/tests) ...@@ -314,10 +315,27 @@ ADD_SUBDIRECTORY(platforms/reference/tests)
# Which hardware platforms to build # Which hardware platforms to build
IF(NOT cmv EQUAL "2.4") # A bit of tedium because we are using custom FindCUDA files that happen to work...
FIND_PACKAGE(CUDA QUIET) SET(FINDCUDA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindCUDA")
ENDIF(NOT cmv EQUAL "2.4") SET(CUDA_BUILD_CUBIN OFF)
IF(CUDA_FOUND) FIND_PACKAGE(CUDA QUIET)
IF(FOUND_CUDA)
IF(NOT CUDA_NVCC_FLAGS)
SET(FLAGS "")
# Note that cmake will insert semicolons between these item automatically...
SET(FLAGS ${FLAGS} -gencode arch=compute_11,code=sm_11)
SET(FLAGS ${FLAGS} -gencode arch=compute_13,code=sm_13)
SET(FLAGS ${FLAGS} -gencode arch=compute_20,code=sm_20)
SET(FLAGS ${FLAGS} -use_fast_math)
IF(MSVC)
# Unfortunately the variables CUDA_NVCC_FLAGS_RELEASE and CUDA_NVCC_FLAGS_DEBUG
# appear to be unused, at least in CMake 2.6
# Release /MD linkage
set(FLAGS ${FLAGS} "-Xcompiler \"/MD\"")
ENDIF(MSVC)
SET(CUDA_NVCC_FLAGS "${FLAGS}"
CACHE STRING "Semicolon delimit multiple arguments")
ENDIF(NOT CUDA_NVCC_FLAGS)
SET(OPENMM_BUILD_CUDA_LIB ON CACHE BOOL "Build OpenMMCuda library for Nvidia GPUs") SET(OPENMM_BUILD_CUDA_LIB ON CACHE BOOL "Build OpenMMCuda library for Nvidia GPUs")
# I wish I was not hardcoding /MD here # I wish I was not hardcoding /MD here
...@@ -341,9 +359,9 @@ IF(CUDA_FOUND) ...@@ -341,9 +359,9 @@ IF(CUDA_FOUND)
CACHE STRING "Semicolon delimit multiple arguments" FORCE) CACHE STRING "Semicolon delimit multiple arguments" FORCE)
ENDIF(NOT HAS_NVCC_FLAG) ENDIF(NOT HAS_NVCC_FLAG)
ENDIF(MSVC) ENDIF(MSVC)
ELSE(CUDA_FOUND) ELSE(FOUND_CUDA)
SET(OPENMM_BUILD_CUDA_LIB OFF CACHE BOOL "Build OpenMMCuda library for Nvidia GPUs") SET(OPENMM_BUILD_CUDA_LIB OFF CACHE BOOL "Build OpenMMCuda library for Nvidia GPUs")
ENDIF(CUDA_FOUND) ENDIF(FOUND_CUDA)
IF(OPENMM_BUILD_CUDA_LIB) IF(OPENMM_BUILD_CUDA_LIB)
ADD_SUBDIRECTORY(platforms/cuda) ADD_SUBDIRECTORY(platforms/cuda)
ENDIF(OPENMM_BUILD_CUDA_LIB) ENDIF(OPENMM_BUILD_CUDA_LIB)
...@@ -414,3 +432,5 @@ INCLUDE(ApiDoxygen.cmake) ...@@ -414,3 +432,5 @@ INCLUDE(ApiDoxygen.cmake)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(examples) ADD_SUBDIRECTORY(examples)
ENDIF(NOT cmv EQUAL "2.4") # This whole file...
# - Tools for building CUDA C files: libraries and build dependencies. ###############################################################################
# This script locates the NVIDIA CUDA C tools. It should work on linux, windows, # For more information, please see: http://software.sci.utah.edu
# and mac and should be reasonably up to date with CUDA C releases. #
# # The MIT License
# This script makes use of the standard find_package arguments of <VERSION>, #
# REQUIRED and QUIET. CUDA_FOUND will report if an acceptable version of CUDA # Copyright (c) 2007-2008
# was found. # Scientific Computing and Imaging Institute, University of Utah
# #
# The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if the prefix # License for the specific language governing rights and limitations under
# cannot be determined by the location of nvcc in the system path and REQUIRED # Permission is hereby granted, free of charge, to any person obtaining a
# is specified to find_package(). To use a different installed version of the # copy of this software and associated documentation files (the "Software"),
# toolkit set the environment variable CUDA_BIN_PATH before running cmake # to deal in the Software without restriction, including without limitation
# (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default /usr/local/cuda) # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# or set CUDA_TOOLKIT_ROOT_DIR after configuring. If you change the value of # and/or sell copies of the Software, and to permit persons to whom the
# CUDA_TOOLKIT_ROOT_DIR, various components that depend on the path will be # Software is furnished to do so, subject to the following conditions:
# relocated. #
# # The above copyright notice and this permission notice shall be included
# It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain # in all copies or substantial portions of the Software.
# platforms, or to use a cuda runtime not installed in the default location. In #
# newer versions of the toolkit the cuda library is included with the graphics # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# driver- be sure that the driver version matches what is needed by the cuda # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# runtime version. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# The following variables affect the behavior of the macros in the script (in # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# alphebetical order). Note that any of these flags can be changed multiple # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# times in the same directory before calling CUDA_ADD_EXECUTABLE, # DEALINGS IN THE SOFTWARE.
# CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX or CUDA_WRAP_SRCS. #
# # This script locates the Nvidia Compute Unified Driver Architecture (CUDA)
# CUDA_64_BIT_DEVICE_CODE (Default matches host bit size) # tools. It should work on linux, windows, and mac and should be reasonably
# -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code. # up to date with cuda releases.
# Note that making this different from the host code when generating object #
# or C files from CUDA code just won't work, because size_t gets defined by # The script will prompt the user to specify CUDA_INSTALL_PREFIX if the
# nvcc in the generated source. If you compile to PTX and then load the # prefix cannot be determined by the location of nvcc in the system path. To
# file yourself, you can mix bit sizes between device and host. # use a different installed version of the toolkit set the environment variable
# # CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0
# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON) # instead of the default /usr/local/cuda).
# -- Set to ON if you want the custom build rule to be attached to the source #
# file in Visual Studio. Turn OFF if you add the same cuda file to multiple # Set CUDA_BUILD_TYPE to "Device" or "Emulation" mode.
# targets. # _DEVICEEMU is defined in "Emulation" mode.
# #
# This allows the user to build the target from the CUDA file; however, bad # Set CUDA_BUILD_CUBIN to "ON" or "OFF" to enable and extra compilation pass
# things can happen if the CUDA source file is added to multiple targets. # with the -cubin option in Device mode. The output is parsed and register,
# When performing parallel builds it is possible for the custom build # shared memory usage is printed during build. Default ON.
# command to be run more than once and in parallel causing cryptic build #
# errors. VS runs the rules for every source file in the target, and a # The script creates the following macros:
# source can have only one rule no matter how many projects it is added to. # CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
# When the rule is run from multiple targets race conditions can occur on # -- Sets the directories that should be passed to nvcc
# the generated file. Eventually everything will get built, but if the user # (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
# is unaware of this behavior, there may be confusion. It would be nice if # files.
# this script could detect the reuse of source files across multiple targets #
# and turn the option off for the user, but no good solution could be found. # CUDA_ADD_LIBRARY( cuda_target file0 file1 ... )
# # -- Creates a shared library "cuda_target" which contains all of the source
# CUDA_BUILD_CUBIN (Default OFF) # (*.c, *.cc, etc.) specified and all of the nvcc'ed .cu files specified.
# -- Set to ON to enable and extra compilation pass with the -cubin option in # All of the specified source files and generated .cpp files are compiled
# Device mode. The output is parsed and register, shared memory usage is # using the standard CMake compiler, so the normal INCLUDE_DIRECTORIES,
# printed during build. # LINK_DIRECTORIES, and TARGET_LINK_LIBRARIES can be used to affect their
# # build and link.
# CUDA_BUILD_EMULATION (Default OFF for device mode) #
# -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files # CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... )
# when CUDA_BUILD_EMULATION is TRUE. # -- Same as CUDA_ADD_LIBRARY except that an exectuable is created.
# #
# CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR) # CUDA_COMPILE( cuda_files file0 file1 ... )
# -- Set to the path you wish to have the generated files placed. If it is # -- Returns a list of build commands in the first argument to be used with
# blank output files will be placed in CMAKE_CURRENT_BINARY_DIR. # ADD_LIBRARY or ADD_EXECUTABLE.
# Intermediate files will always be placed in #
# CMAKE_CURRENT_BINARY_DIR/CMakeFiles. # The script defines the following variables:
# #
# CUDA_HOST_COMPILATION_CPP (Default ON) # ( Note CUDA_ADD_* macros setup cuda/cut library dependencies automatically.
# -- Set to OFF for C compilation of host code. # These variables are only needed if a cuda API call must be made from code in
# # a outside library or executable. )
# CUDA_NVCC_FLAGS #
# CUDA_NVCC_FLAGS_<CONFIG> # CUDA_INCLUDE -- Include directory for cuda headers.
# -- Additional NVCC command line arguments. NOTE: multiple arguments must be # CUDA_TARGET_LINK -- Cuda RT library.
# semi-colon delimited (e.g. --compiler-options;-Wall) # CUDA_CUT_INCLUDE -- Include directory for cuda SDK headers (cutil.h).
# # CUDA_CUT_TARGET_LINK -- SDK libraries.
# CUDA_PROPAGATE_HOST_FLAGS (Default ON) # CUDA_NVCC_FLAGS -- Additional NVCC command line arguments. NOTE:
# -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration # multiple arguments must be semi-colon delimited
# dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the # e.g. --compiler-options;-Wall
# host compiler through nvcc's -Xcompiler flag. This helps make the # CUBLAS_TARGET_LINK-- cublas library name.
# generated host code match the rest of the system better. Sometimes # CUFFT_TARGET_LINK -- cubfft library name.
# certain flags give nvcc problems, and this will help you turn the flag #
# propagation off. This does not affect the flags supplied directly to nvcc # The nvcc flag "--host-compilation;c++" should be used if functions declared
# via CUDA_NVCC_FLAGS or through the OPTION flags specified through # as __host__ contain C++ code.
# CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for #
# shared library compilation are not affected by this flag. # It might be necessary to set CUDA_INSTALL_PATH manually on certain platforms,
# # or to use a cuda runtime not installed in the default location. In newer
# CUDA_VERBOSE_BUILD (Default OFF) # versions of the toolkit the cuda library is included with the graphics
# -- Set to ON to see all the commands used when building the CUDA file. When # driver- be sure that the driver version matches what is needed by the cuda
# using a Makefile generator the value defaults to VERBOSE (run make # runtime version.
# VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will #
# always print the output. # -- Abe Stephens SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
# ###############################################################################
# The script creates the following macros (in alphebetical order):
# # FindCuda.cmake
# CUDA_ADD_CUFFT_TO_TARGET( cuda_target ) CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
# -- Adds the cufft library to the target (can be any target). Handles whether
# you are in emulation mode or not. INCLUDE(${FINDCUDA_DIR}/CudaDependency.cmake)
#
# CUDA_ADD_CUBLAS_TO_TARGET( cuda_target ) ###############################################################################
# -- Adds the cublas library to the target (can be any target). Handles ###############################################################################
# whether you are in emulation mode or not. # Locate CUDA, Set Build Type, etc.
# ###############################################################################
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... ###############################################################################
# [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
# -- Creates an executable "cuda_target" which is made up of the files # Parse CUDA build type.
# specified. All of the non CUDA C files are compiled using the standard IF (NOT CUDA_BUILD_TYPE)
# build rules specified by CMAKE and the cuda files are compiled to object SET(CUDA_BUILD_TYPE "Device" CACHE STRING "Cuda build type: Emulation or Device")
# files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is ENDIF(NOT CUDA_BUILD_TYPE)
# added automatically to include_directories(). Standard CMake target calls
# can be used on the target after calling this macro # Emulation if the card isn't present.
# (e.g. set_target_properties and target_link_libraries). IF (CUDA_BUILD_TYPE MATCHES "Emulation")
# # Emulation.
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ... SET(nvcc_flags --device-emulation -D_DEVICEEMU -g)
# [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
# -- Same as CUDA_ADD_EXECUTABLE except that a library is created. # Device present.
# SET(nvcc_flags "")
# CUDA_BUILD_CLEAN_TARGET() ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
# -- Creates a convience target that deletes all the dependency files
# generated. You should make clean after running this target to ensure the SET(CUDA_BUILD_CUBIN TRUE CACHE BOOL "Generate and parse .cubin files in Device mode.")
# dependency files get regenerated. # Don't set CUDA_NVCC_FLAGS here, set them in CMakeLists.txt
# # SET(CUDA_NVCC_FLAGS "--maxrregcount=32;-gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_13,code=sm_13;-use_fast_math;-O0" CACHE STRING "Semi-colon delimit multiple arguments.")
# CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE]
# [OPTIONS ...] ) # Search for the cuda distribution.
# -- Returns a list of generated files from the input source files to be used IF(NOT CUDA_INSTALL_PREFIX)
# with ADD_LIBRARY or ADD_EXECUTABLE. FIND_PATH(CUDA_INSTALL_PREFIX
# NAMES nvcc nvcc.exe
# CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] ) PATHS /usr/local/cuda C:/CUDA
# -- Returns a list of PTX files generated from the input source files. PATH_SUFFIXES bin
# ENV CUDA_BIN_PATH
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... ) DOC "Toolkit location."
# -- Sets the directories that should be passed to nvcc )
# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu IF (CUDA_INSTALL_PREFIX)
# files. STRING(REGEX REPLACE "[/\\\\]?bin[/\\\\]?$" "" CUDA_INSTALL_PREFIX ${CUDA_INSTALL_PREFIX})
# ENDIF(CUDA_INSTALL_PREFIX)
# CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ... IF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
# [STATIC | SHARED | MODULE] [OPTIONS ...] ) MESSAGE(FATAL_ERROR "Specify CUDA_INSTALL_PREFIX")
# -- This is where all the magic happens. CUDA_ADD_EXECUTABLE, ENDIF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
# CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this ENDIF (NOT CUDA_INSTALL_PREFIX)
# function under the hood.
# # CUDA_NVCC
# Given the list of files (file0 file1 ... fileN) this macro generates IF (NOT CUDA_NVCC)
# custom commands that generate either PTX or linkable objects (use "PTX" or FIND_PROGRAM(CUDA_NVCC
# "OBJ" for the format argument to switch). Files that don't end with .cu nvcc
# or have the HEADER_FILE_ONLY property are ignored. PATHS ${CUDA_INSTALL_PREFIX}/bin $ENV{CUDA_BIN_PATH}
# )
# The arguments passed in after OPTIONS are extra command line options to IF(NOT CUDA_NVCC)
# give to nvcc. You can also specify per configuration options by MESSAGE(FATAL_ERROR "Could not find nvcc")
# specifying the name of the configuration followed by the options. General ELSE(NOT CUDA_NVCC)
# options must preceed configuration specific options. Not all MARK_AS_ADVANCED(CUDA_NVCC)
# configurations need to be specified, only the ones provided will be used. ENDIF(NOT CUDA_NVCC)
# ENDIF(NOT CUDA_NVCC)
# OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag"
# DEBUG -g # CUDA_NVCC_INCLUDE_ARGS
# RELEASE --use_fast_math # IF (NOT FOUND_CUDA_NVCC_INCLUDE)
# RELWITHDEBINFO --use_fast_math;-g FIND_PATH(FOUND_CUDA_NVCC_INCLUDE
# MINSIZEREL --use_fast_math device_functions.h # Header included in toolkit
# PATHS ${CUDA_INSTALL_PREFIX}/include
# For certain configurations (namely VS generating object files with $ENV{CUDA_INC_PATH}
# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will )
# be produced for the given cuda file. This is because when you add the
# cuda file to Visual Studio it knows that this file produces an object file IF(NOT FOUND_CUDA_NVCC_INCLUDE)
# and will link in the resulting object file automatically. MESSAGE(FATAL_ERROR "Could not find Cuda headers")
# ELSE(NOT FOUND_CUDA_NVCC_INCLUDE)
# This script will also generate a separate cmake script that is used at # Set the initial include dir.
# build time to invoke nvcc. This is for serveral reasons. SET (CUDA_NVCC_INCLUDE_ARGS "-I"${FOUND_CUDA_NVCC_INCLUDE})
# SET (CUDA_INCLUDE ${FOUND_CUDA_NVCC_INCLUDE})
# 1. nvcc can return negative numbers as return values which confuses
# Visual Studio into thinking that the command succeeded. The script now MARK_AS_ADVANCED(
# checks the error codes and produces errors when there was a problem. FOUND_CUDA_NVCC_INCLUDE
# CUDA_NVCC_INCLUDE_ARGS
# 2. nvcc has been known to not delete incomplete results when it )
# encounters problems. This confuses build systems into thinking the ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# target was generated when in fact an unusable file exists. The script
# now deletes the output files if there was an error. # ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
#
# 3. By putting all the options that affect the build into a file and then
# make the build rule dependent on the file, the output files will be # CUDA_TARGET_LINK
# regenerated when the options change. IF (NOT CUDA_TARGET_LINK)
#
# This script also looks at optional arguments STATIC, SHARED, or MODULE to FIND_LIBRARY(FOUND_CUDART
# determine when to target the object compilation for a shared library. cudart
# BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
# CUDA_ADD_LIBRARY. On some systems special flags are added for building DOC "\"cudart\" library"
# objects intended for shared libraries. A preprocessor macro, )
# <target_name>_EXPORTS is defined when a shared library compilation is
# detected. # Check to see if cudart library was found.
# IF(NOT FOUND_CUDART)
# Flags passed into add_definitions with -D or /D are passed along to nvcc. MESSAGE(FATAL_ERROR "Could not find cudart library (cudart)")
# ENDIF(NOT FOUND_CUDART)
# The script defines the following variables:
# # 1.1 toolkit on linux doesn't appear to have a separate library on
# CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc. # some platforms.
# CUDA_VERSION_MINOR -- The minor version. FIND_LIBRARY(FOUND_CUDA
# CUDA_VERSION cuda
# CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR PATHS ${CUDA_INSTALL_PREFIX}/lib
# DOC "\"cuda\" library (older versions only)."
# CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set). NO_DEFAULT_PATH
# CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the NO_CMAKE_ENVIRONMENT_PATH
# SDK. This script will not directly support finding NO_CMAKE_PATH
# specific libraries or headers, as that isn't NO_SYSTEM_ENVIRONMENT_PATH
# supported by NVIDIA. If you want to change NO_CMAKE_SYSTEM_PATH
# libraries when the path changes see the )
# FindCUDA.cmake script for an example of how to clear
# these variables. There are also examples of how to # Add cuda library to the link line only if it is found.
# use the CUDA_SDK_ROOT_DIR to locate headers or IF (FOUND_CUDA)
# libraries, if you so choose (at your own risk). SET(CUDA_TARGET_LINK ${FOUND_CUDA})
# CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically ENDIF(FOUND_CUDA)
# for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY.
# CUDA_LIBRARIES -- Cuda RT library. # Always add cudart to the link line.
# CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT IF(FOUND_CUDART)
# implementation (alternative to: SET(CUDA_TARGET_LINK
# CUDA_ADD_CUFFT_TO_TARGET macro) ${CUDA_TARGET_LINK} ${FOUND_CUDART}
# CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS )
# implementation (alterative to: MARK_AS_ADVANCED(
# CUDA_ADD_CUBLAS_TO_TARGET macro). CUDA_TARGET_LINK
# CUDA_LIB
# FOUND_CUDA
# James Bigler, NVIDIA Corp (nvidia.com - jbigler) FOUND_CUDART
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html )
# ELSE(FOUND_CUDART)
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. MESSAGE(FATAL_ERROR "Could not find cuda libraries.")
# ENDIF(FOUND_CUDART)
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah ENDIF(NOT CUDA_TARGET_LINK)
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script # CUDA_CUT_INCLUDE
# for the text of the license. IF(NOT CUDA_CUT_INCLUDE)
FIND_PATH(FOUND_CUT_INCLUDE
# The MIT License cutil.h
# PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/common/inc
# License for the specific language governing rights and limitations under ${CUDA_INSTALL_PREFIX}/NVSDK0.2/common/inc
# Permission is hereby granted, free of charge, to any person obtaining a ${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/common/inc
# copy of this software and associated documentation files (the "Software"), $ENV{HOME}/NVIDIA_CUDA_SDK/common/inc
# to deal in the Software without restriction, including without limitation $ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/common/inc
# the rights to use, copy, modify, merge, publish, distribute, sublicense, $ENV{NVSDKCUDA_ROOT}/common/inc
# and/or sell copies of the Software, and to permit persons to whom the DOC "Location of cutil.h"
# Software is furnished to do so, subject to the following conditions: )
# IF(FOUND_CUT_INCLUDE)
# The above copyright notice and this permission notice shall be included SET(CUDA_CUT_INCLUDE ${FOUND_CUT_INCLUDE})
# in all copies or substantial portions of the Software. MARK_AS_ADVANCED(
# FOUND_CUT_INCLUDE
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS )
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ENDIF(FOUND_CUT_INCLUDE)
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ENDIF(NOT CUDA_CUT_INCLUDE)
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # CUDA_CUT_TARGET_LINK
# DEALINGS IN THE SOFTWARE. IF(NOT CUDA_CUT_TARGET_LINK)
# FIND_LIBRARY(FOUND_CUT
############################################################################### cutil
cutil32
# FindCUDA.cmake PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NVSDK0.2/lib
# We need to have at least this version to support the VERSION_LESS argument to 'if' (2.6.2) and unset (2.6.3) ${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/lib
cmake_policy(PUSH) $ENV{HOME}/NVIDIA_CUDA_SDK/lib
cmake_minimum_required(VERSION 2.6.3) $ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/lib
cmake_policy(POP) $ENV{NVSDKCUDA_ROOT}/common/lib
NO_DEFAULT_PATH
# This macro helps us find the location of helper files we will need the full path to NO_CMAKE_ENVIRONMENT_PATH
macro(CUDA_FIND_HELPER_FILE _name _extension) NO_CMAKE_PATH
set(_full_name "${_name}.${_extension}") NO_SYSTEM_ENVIRONMENT_PATH
# CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being NO_CMAKE_SYSTEM_PATH
# processed. Using this variable, we can pull out the current path, and DOC "Location of cutil library"
# provide a way to get access to the other files we need local to here. )
get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) IF(FOUND_CUT)
find_file(CUDA_${_name} ${_full_name} PATHS ${CMAKE_CURRENT_LIST_DIR}/FindCUDA NO_DEFAULT_PATH) SET(CUDA_CUT_TARGET_LINK ${FOUND_CUT})
if(NOT CUDA_${_name}) MARK_AS_ADVANCED(
set(error_message "${_full_name} not found in CMAKE_MODULE_PATH") FOUND_CUT
if(CUDA_FIND_REQUIRED) )
message(FATAL_ERROR "${error_message}") ENDIF(FOUND_CUT)
else(CUDA_FIND_REQUIRED)
if(NOT CUDA_FIND_QUIETLY) # Add variables for cufft and cublas target link
message(STATUS "${error_message}") FIND_LIBRARY(FOUND_CUFFTEMU
endif(NOT CUDA_FIND_QUIETLY) cufftemu
endif(CUDA_FIND_REQUIRED) PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
endif(NOT CUDA_${_name}) DOC "\"cufftemu\" library"
# Set this variable as internal, so the user isn't bugged with it. )
set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE) FIND_LIBRARY(FOUND_CUBLASEMU
endmacro(CUDA_FIND_HELPER_FILE) cublasemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
##################################################################### DOC "\"cublasemu\" library"
## CUDA_INCLUDE_NVCC_DEPENDENCIES )
## FIND_LIBRARY(FOUND_CUFFT
cufft
# So we want to try and include the dependency file if it exists. If PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
# it doesn't exist then we need to create an empty one, so we can DOC "\"cufft\" library"
# include it. )
FIND_LIBRARY(FOUND_CUBLAS
# If it does exist, then we need to check to see if all the files it cublas
# depends on exist. If they don't then we should clear the dependency PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
# file and regenerate it later. This covers the case where a header DOC "\"cublas\" library"
# file has disappeared or moved. )
macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file) IF (CUDA_BUILD_TYPE MATCHES "Emulation")
set(CUDA_NVCC_DEPEND) SET(CUFFT_TARGET_LINK ${FOUND_CUFFTEMU})
set(CUDA_NVCC_DEPEND_REGENERATE FALSE) SET(CUBLAS_TARGET_LINK ${FOUND_CUBLASEMU})
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFT})
# Include the dependency file. Create it first if it doesn't exist . The SET(CUBLAS_TARGET_LINK ${FOUND_CUBLAS})
# INCLUDE puts a dependency that will force CMake to rerun and bring in the ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
# new info when it changes. DO NOT REMOVE THIS (as I did and spent a few
# hours figuring out why it didn't work.
if(NOT EXISTS ${dependency_file})
file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n")
endif() ENDIF(NOT CUDA_CUT_TARGET_LINK)
# Always include this file to force CMake to run again next
# invocation and rebuild the dependencies.
#message("including dependency_file = ${dependency_file}") ###############################################################################
include(${dependency_file}) # Add include directories to pass to the nvcc command.
MACRO(CUDA_INCLUDE_DIRECTORIES)
# Now we need to verify the existence of all the included files FOREACH(dir ${ARGN})
# here. If they aren't there we need to just blank this variable and SET(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS} -I${dir})
# make the file regenerate again. ENDFOREACH(dir ${ARGN})
# if(DEFINED CUDA_NVCC_DEPEND) ENDMACRO(CUDA_INCLUDE_DIRECTORIES)
# message("CUDA_NVCC_DEPEND set")
# else()
# message("CUDA_NVCC_DEPEND NOT set") ##############################################################################
# endif() ##############################################################################
if(CUDA_NVCC_DEPEND) # This helper macro populates the following variables and setups up custom commands and targets to
#message("CUDA_NVCC_DEPEND true") # invoke the nvcc compiler. The compiler is invoked once with -M to generate a dependency file and
foreach(f ${CUDA_NVCC_DEPEND}) # a second time with -cuda to generate a .cpp file
#message("searching for ${f}") # ${target_srcs}
if(NOT EXISTS ${f}) # ${cuda_cu_sources}
#message("file ${f} not found") ##############################################################################
set(CUDA_NVCC_DEPEND_REGENERATE TRUE) ##############################################################################
endif()
endforeach(f) MACRO(CUDA_add_custom_commands cuda_target)
else(CUDA_NVCC_DEPEND)
#message("CUDA_NVCC_DEPEND false") SET(target_srcs "")
# No dependencies, so regenerate the file. SET(cuda_cu_sources "")
set(CUDA_NVCC_DEPEND_REGENERATE TRUE)
endif(CUDA_NVCC_DEPEND) # Iterate over the macro arguments and create custom
# commands for all the .cu files.
#message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}") FOREACH(file ${ARGN})
# No incoming dependencies, so we need to generate them. Make the IF(${file} MATCHES ".*\\.cu$")
# output depend on the dependency file itself, which should cause the
# rule to re-run. # Add a custom target to generate a c file.
if(CUDA_NVCC_DEPEND_REGENERATE) SET(generated_file "${CMAKE_BINARY_DIR}/src/cuda/${file}_${cuda_target}_generated.cpp")
file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") SET(generated_target "${file}_target")
endif(CUDA_NVCC_DEPEND_REGENERATE)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/cuda)
endmacro(CUDA_INCLUDE_NVCC_DEPENDENCIES)
SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/../${file})
###############################################################################
############################################################################### # MESSAGE("${CUDA_NVCC} ${source_file} ${CUDA_NVCC_FLAGS} ${nvcc_flags} -cuda -o ${generated_file} ${CUDA_NVCC_INCLUDE_ARGS}")
# Setup variables' defaults
############################################################################### # Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND
############################################################################### SET(cmake_dependency_file "${generated_file}.depend")
CUDA_INCLUDE_NVCC_DEPENDENCIES(${cmake_dependency_file})
# Allow the user to specify if the device code is supposed to be 32 or 64 bit. SET(NVCC_generated_dependency_file "${generated_file}.NVCC-depend")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON)
else() # Build the NVCC made dependency file
set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF) IF (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
endif() SET(NVCC_generated_cubin_file "${generated_file}.NVCC-cubin.txt")
option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT}) ADD_CUSTOM_COMMAND(
# Attach the build rule to the source file in VS. This option # Generate the .cubin output.
option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON) OUTPUT ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
# Prints out extra information about the cuda file during compilation ARGS ${source_file}
option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF) ${CUDA_NVCC_FLAGS}
${nvcc_flags}
# Set whether we are using emulation or device mode. -DNVCC
option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF) -cubin
-o ${NVCC_generated_cubin_file}
# Where to put the generated output. ${CUDA_NVCC_INCLUDE_ARGS}
set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR")
# Execute the parser script.
# Parse HOST_COMPILATION mode. COMMAND ${CMAKE_COMMAND}
option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON) ARGS
-D input_file="${NVCC_generated_cubin_file}"
# Extra user settable flags -P "${FINDCUDA_DIR}/parse_cubin.cmake"
SET(CUDA_NVCC_FLAGS "-gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_13,code=sm_13;-gencode;arch=compute_20,code=sm_20;-use_fast_math" CACHE STRING "Semi-colon delimit multiple arguments.")
# Propagate the host flags to the host compiler via -Xcompiler # MAIN_DEPENDENCY ${source_file}
option(CUDA_PROPAGATE_HOST_FLAGS "Propage C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON) DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
# Specifies whether the commands used when compiling the .cu file will be printed out.
option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF)
mark_as_advanced( COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC -cubin File: ${NVCC_generated_cubin_file}\n"
CUDA_64_BIT_DEVICE_CODE )
CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ELSE (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
CUDA_GENERATED_OUTPUT_DIR # Depend on something that will exist.
CUDA_HOST_COMPILATION_CPP SET(NVCC_generated_cubin_file "${source_file}")
CUDA_NVCC_FLAGS ENDIF (CUDA_BUILD_TYPE MATCHES "Device"AND CUDA_BUILD_CUBIN)
CUDA_PROPAGATE_HOST_FLAGS
) # Build the NVCC made dependency file
ADD_CUSTOM_COMMAND(
# Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we OUTPUT ${NVCC_generated_dependency_file}
# need to add another entry for the CMAKE_BUILD_TYPE. We also need to add the COMMAND ${CUDA_NVCC}
# standerd set of 4 build types (Debug, MinSizeRel, Release, and RelWithDebInfo) ARGS ${source_file}
# for completeness. We need run this loop in order to accomodate the addition ${CUDA_NVCC_FLAGS}
# of extra configuration types. Duplicate entries will be removed by ${nvcc_flags}
# REMOVE_DUPLICATES. -DNVCC
set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) -M
list(REMOVE_DUPLICATES CUDA_configuration_types) -o ${NVCC_generated_dependency_file}
foreach(config ${CUDA_configuration_types}) ${CUDA_NVCC_INCLUDE_ARGS}
string(TOUPPER ${config} config_upper) # MAIN_DEPENDENCY ${source_file}
set(CUDA_NVCC_FLAGS_${config_upper} "" CACHE STRING "Semi-colon delimit multiple arguments.") DEPENDS ${source_file}
mark_as_advanced(CUDA_NVCC_FLAGS_${config_upper}) DEPENDS ${CUDA_NVCC_DEPEND}
endforeach() COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC Dependency File: ${NVCC_generated_dependency_file}\n"
)
###############################################################################
############################################################################### # Build the CMake readible dependency file
# Locate CUDA, Set Build Type, etc. ADD_CUSTOM_COMMAND(
############################################################################### OUTPUT ${cmake_dependency_file}
############################################################################### COMMAND ${CMAKE_COMMAND}
ARGS
# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed, -D input_file="${NVCC_generated_dependency_file}"
# if they have then clear the cache variables, so that will be detected again. -D output_file="${cmake_dependency_file}"
if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}") -P "${FINDCUDA_DIR}/make2cmake.cmake"
unset(CUDA_NVCC_EXECUTABLE CACHE) MAIN_DEPENDENCY ${NVCC_generated_dependency_file}
unset(CUDA_VERSION CACHE) COMMENT "Converting NVCC dependency to CMake (${cmake_dependency_file})"
unset(CUDA_TOOLKIT_INCLUDE CACHE) )
unset(CUDA_CUDART_LIBRARY CACHE)
unset(CUDA_CUDA_LIBRARY CACHE) ADD_CUSTOM_COMMAND(
unset(CUDA_cublas_LIBRARY CACHE) OUTPUT ${generated_file}
unset(CUDA_cublasemu_LIBRARY CACHE) MAIN_DEPENDENCY ${source_file}
unset(CUDA_cufft_LIBRARY CACHE) DEPENDS ${CUDA_NVCC_DEPEND}
unset(CUDA_cufftemu_LIBRARY CACHE) DEPENDS ${cmake_dependency_file}
endif() DEPENDS ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}") ARGS ${source_file}
# No specific variables to catch. Use this kind of code before calling ${CUDA_NVCC_FLAGS}
# find_package(CUDA) to clean up any variables that may depend on this path. ${nvcc_flags}
${CUDA_NVCC_BUILD_FLAGS}
# unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE) -DNVCC
# unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE) --keep
endif() -cuda -o ${generated_file}
${CUDA_NVCC_INCLUDE_ARGS}
# Search for the cuda distribution. COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC ${source_file}: ${generated_file}\n"
if(NOT CUDA_TOOLKIT_ROOT_DIR) )
# Search in the CUDA_BIN_PATH first. SET(cuda_cu_sources ${cuda_cu_sources} ${source_file})
find_path(CUDA_TOOLKIT_ROOT_DIR
NAMES nvcc nvcc.exe # Add the generated file name to the source list.
PATHS ENV CUDA_BIN_PATH SET(target_srcs ${target_srcs} ${generated_file})
DOC "Toolkit location."
NO_DEFAULT_PATH ELSE(${file} MATCHES ".*\\.cu$")
)
# Now search default paths # Otherwise add the file name to the source list.
find_path(CUDA_TOOLKIT_ROOT_DIR SET(target_srcs ${target_srcs} ${file})
NAMES nvcc nvcc.exe
PATHS /usr/local/bin ENDIF(${file} MATCHES ".*\\.cu$")
/usr/local/cuda/bin ENDFOREACH(file)
DOC "Toolkit location."
) ENDMACRO(CUDA_add_custom_commands)
if (CUDA_TOOLKIT_ROOT_DIR) ###############################################################################
string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) ###############################################################################
# We need to force this back into the cache. # ADD LIBRARY
set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE) ###############################################################################
endif(CUDA_TOOLKIT_ROOT_DIR) ###############################################################################
if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) MACRO(CUDA_ADD_LIBRARY cuda_target)
if(CUDA_FIND_REQUIRED)
message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR") # Create custom commands and targets for each file.
elseif(NOT CUDA_FIND_QUIETLY) CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
message("CUDA_TOOLKIT_ROOT_DIR not found or specified")
endif() # Add the library.
endif (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) ADD_LIBRARY(${cuda_target}
endif (NOT CUDA_TOOLKIT_ROOT_DIR) ${target_srcs}
${cuda_cu_sources}
# CUDA_NVCC_EXECUTABLE )
find_program(CUDA_NVCC_EXECUTABLE
NAMES nvcc TARGET_LINK_LIBRARIES(${cuda_target}
PATHS "${CUDA_TOOLKIT_ROOT_DIR}/bin" ${CUDA_TARGET_LINK}
"${CUDA_TOOLKIT_ROOT_DIR}/bin64" )
ENV CUDA_BIN_PATH
NO_DEFAULT_PATH ENDMACRO(CUDA_ADD_LIBRARY cuda_target)
)
# Search default search paths, after we search our own set of paths.
find_program(CUDA_NVCC_EXECUTABLE nvcc) ###############################################################################
mark_as_advanced(CUDA_NVCC_EXECUTABLE) ###############################################################################
# ADD EXECUTABLE
if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) ###############################################################################
# Compute the version. ###############################################################################
exec_program(${CUDA_NVCC_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE NVCC_OUT) MACRO(CUDA_ADD_EXECUTABLE cuda_target)
string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT}) # Create custom commands and targets for each file.
set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.") CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
mark_as_advanced(CUDA_VERSION)
endif() # Add the library.
ADD_EXECUTABLE(${cuda_target}
# Always set this convenience variable ${target_srcs}
set(CUDA_VERSION_STRING "${CUDA_VERSION}") ${cuda_cu_sources}
)
# Here we need to determine if the version we found is acceptable. We will
# assume that is unless CUDA_FIND_VERSION_EXACT or CUDA_FIND_VERSION is TARGET_LINK_LIBRARIES(${cuda_target}
# specified. The presence of either of these options checks the version ${CUDA_TARGET_LINK}
# string and signals if the version is acceptable or not. )
set(_cuda_version_acceptable TRUE)
#
if(CUDA_FIND_VERSION_EXACT AND NOT CUDA_VERSION VERSION_EQUAL CUDA_FIND_VERSION) ENDMACRO(CUDA_ADD_EXECUTABLE cuda_target)
set(_cuda_version_acceptable FALSE)
endif() ###############################################################################
# ###############################################################################
if(CUDA_FIND_VERSION AND CUDA_VERSION VERSION_LESS CUDA_FIND_VERSION) # ADD EXECUTABLE
set(_cuda_version_acceptable FALSE) ###############################################################################
endif() ###############################################################################
# MACRO(CUDA_COMPILE file_variable)
if(NOT _cuda_version_acceptable)
set(_cuda_error_message "Requested CUDA version ${CUDA_FIND_VERSION}, but found unacceptable version ${CUDA_VERSION}") # Create custom commands and targets for each file.
if(CUDA_FIND_REQUIRED) CUDA_add_custom_commands( cuda_compile ${ARGN} )
message("${_cuda_error_message}")
elseif(NOT CUDA_FIND_QUIETLY) SET(file_variable ${target_srcs} ${cuda_cu_sources})
message("${_cuda_error_message}")
endif() ENDMACRO(CUDA_COMPILE)
endif()
# CUDA_TOOLKIT_INCLUDE
find_path(CUDA_TOOLKIT_INCLUDE
device_functions.h # Header included in toolkit
PATHS "${CUDA_TOOLKIT_ROOT_DIR}/include"
ENV CUDA_INC_PATH
NO_DEFAULT_PATH
)
# Search default search paths, after we search our own set of paths.
find_path(CUDA_TOOLKIT_INCLUDE device_functions.h)
mark_as_advanced(CUDA_TOOLKIT_INCLUDE)
# Set the user list of include dir to nothing to initialize it.
set (CUDA_NVCC_INCLUDE_ARGS_USER "")
set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE})
macro(FIND_LIBRARY_LOCAL_FIRST _var _names _doc)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_cuda_64bit_lib_dir "${CUDA_TOOLKIT_ROOT_DIR}/lib64")
endif()
find_library(${_var}
NAMES ${_names}
PATHS ${_cuda_64bit_lib_dir}
"${CUDA_TOOLKIT_ROOT_DIR}/lib"
ENV CUDA_LIB_PATH
DOC ${_doc}
NO_DEFAULT_PATH
)
# Search default search paths, after we search our own set of paths.
find_library(${_var} NAMES ${_names} DOC ${_doc})
endmacro()
# CUDA_LIBRARIES
find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library")
set(CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY})
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).")
# Add cuda library to the link line only if it is found.
if (CUDA_CUDA_LIBRARY)
set(CUDA_LIBRARIES ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY})
endif(CUDA_CUDA_LIBRARY)
mark_as_advanced(
CUDA_CUDA_LIBRARY
CUDA_CUDART_LIBRARY
)
#######################
# Look for some of the toolkit helper libraries
macro(FIND_CUDA_HELPER_LIBS _name)
find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library")
mark_as_advanced(CUDA_${_name}_LIBRARY)
endmacro(FIND_CUDA_HELPER_LIBS)
# Search for cufft and cublas libraries.
find_cuda_helper_libs(cufftemu)
find_cuda_helper_libs(cublasemu)
find_cuda_helper_libs(cufft)
find_cuda_helper_libs(cublas)
if (CUDA_BUILD_EMULATION)
set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY})
set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY})
else()
set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY})
set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY})
endif()
########################
# Look for the SDK stuff
find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h
"$ENV{NVSDKCUDA_ROOT}"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
"/Developer/GPU\ Computing/C"
)
# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
# environment variables.
set(CUDA_SDK_SEARCH_PATH
"${CUDA_SDK_ROOT_DIR}"
"${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2"
"${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2"
"${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK"
"$ENV{HOME}/NVIDIA_CUDA_SDK"
"$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX"
"/Developer/CUDA"
)
# Example of how to find an include file from the CUDA_SDK_ROOT_DIR
# find_path(CUDA_CUT_INCLUDE_DIR
# cutil.h
# PATHS ${CUDA_SDK_SEARCH_PATH}
# PATH_SUFFIXES "common/inc"
# DOC "Location of cutil.h"
# NO_DEFAULT_PATH
# )
# # Now search system paths
# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
# Example of how to find a library in the CUDA_SDK_ROOT_DIR
# # cutil library is called cutil64 for 64 bit builds on windows. We don't want
# # to get these confused, so we are setting the name based on the word size of
# # the build.
# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(cuda_cutil_name cutil64)
# else(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(cuda_cutil_name cutil32)
# endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
# find_library(CUDA_CUT_LIBRARY
# NAMES cutil ${cuda_cutil_name}
# PATHS ${CUDA_SDK_SEARCH_PATH}
# # The new version of the sdk shows up in common/lib, but the old one is in lib
# PATH_SUFFIXES "common/lib" "lib"
# DOC "Location of cutil library"
# NO_DEFAULT_PATH
# )
# # Now search system paths
# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
# mark_as_advanced(CUDA_CUT_LIBRARY)
# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
#############################
# Check for required components
set(CUDA_FOUND TRUE)
set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL
"This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE)
set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
"This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CUDA DEFAULT_MSG
CUDA_TOOLKIT_ROOT_DIR
CUDA_NVCC_EXECUTABLE
CUDA_INCLUDE_DIRS
CUDA_CUDART_LIBRARY
_cuda_version_acceptable
)
###############################################################################
###############################################################################
# Macros
###############################################################################
###############################################################################
###############################################################################
# Add include directories to pass to the nvcc command.
macro(CUDA_INCLUDE_DIRECTORIES)
foreach(dir ${ARGN})
list(APPEND CUDA_NVCC_INCLUDE_ARGS_USER "-I${dir}")
endforeach(dir ${ARGN})
endmacro(CUDA_INCLUDE_DIRECTORIES)
##############################################################################
cuda_find_helper_file(parse_cubin cmake)
cuda_find_helper_file(make2cmake cmake)
cuda_find_helper_file(run_nvcc cmake)
##############################################################################
# Separate the OPTIONS out from the sources
#
macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options)
set( ${_sources} )
set( ${_cmake_options} )
set( ${_options} )
set( _found_options FALSE )
foreach(arg ${ARGN})
if(arg STREQUAL "OPTIONS")
set( _found_options TRUE )
elseif(
arg STREQUAL "WIN32" OR
arg STREQUAL "MACOSX_BUNDLE" OR
arg STREQUAL "EXCLUDE_FROM_ALL" OR
arg STREQUAL "STATIC" OR
arg STREQUAL "SHARED" OR
arg STREQUAL "MODULE"
)
list(APPEND ${_cmake_options} "${arg}")
else()
if ( _found_options )
list(APPEND ${_options} "${arg}")
else()
# Assume this is a file
list(APPEND ${_sources} "${arg}")
endif()
endif()
endforeach()
endmacro()
##############################################################################
# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix
#
macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix)
set( _found_config )
foreach(arg ${ARGN})
# Determine if we are dealing with a perconfiguration flag
foreach(config ${CUDA_configuration_types})
string(TOUPPER ${config} config_upper)
if (arg STREQUAL "${config_upper}")
set( _found_config _${arg})
# Set arg to nothing to keep it from being processed further
set( arg )
endif()
endforeach()
if ( arg )
list(APPEND ${_option_prefix}${_found_config} "${arg}")
endif()
endforeach()
endmacro()
##############################################################################
# Helper to add the include directory for CUDA only once
function(CUDA_ADD_CUDA_INCLUDE_ONCE)
get_directory_property(_include_directories INCLUDE_DIRECTORIES)
set(_add TRUE)
if(_include_directories)
foreach(dir ${_include_directories})
if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}")
set(_add FALSE)
endif()
endforeach()
endif()
if(_add)
include_directories(${CUDA_INCLUDE_DIRS})
endif()
endfunction()
function(CUDA_BUILD_SHARED_LIBRARY shared_flag)
set(cmake_args ${ARGN})
# If SHARED, MODULE, or STATIC aren't already in the list of arguments, then
# add SHARED or STATIC based on the value of BUILD_SHARED_LIBS.
list(FIND cmake_args SHARED _cuda_found_SHARED)
list(FIND cmake_args MODULE _cuda_found_MODULE)
list(FIND cmake_args STATIC _cuda_found_STATIC)
if( _cuda_found_SHARED GREATER -1 OR
_cuda_found_MODULE GREATER -1 OR
_cuda_found_STATIC GREATER -1)
set(_cuda_build_shared_libs)
else()
if (BUILD_SHARED_LIBS)
set(_cuda_build_shared_libs SHARED)
else()
set(_cuda_build_shared_libs STATIC)
endif()
endif()
set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE)
endfunction()
##############################################################################
# This helper macro populates the following variables and setups up custom
# commands and targets to invoke the nvcc compiler to generate C or PTX source
# dependant upon the format parameter. The compiler is invoked once with -M
# to generate a dependency file and a second time with -cuda or -ptx to generate
# a .cpp or .ptx file.
# INPUT:
# cuda_target - Target name
# format - PTX or OBJ
# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped.
# OPTIONS - Extra options to NVCC
# OUTPUT:
# generated_files - List of generated files
##############################################################################
##############################################################################
macro(CUDA_WRAP_SRCS cuda_target format generated_files)
if( ${format} MATCHES "PTX" )
set( compile_to_ptx ON )
elseif( ${format} MATCHES "OBJ")
set( compile_to_ptx OFF )
else()
message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS: '${format}'. Use OBJ or PTX.")
endif()
# Set up all the command line flags here, so that they can be overriden on a per target basis.
set(nvcc_flags "")
# Emulation if the card isn't present.
if (CUDA_BUILD_EMULATION)
# Emulation.
set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g)
else(CUDA_BUILD_EMULATION)
# Device mode. No flags necessary.
endif(CUDA_BUILD_EMULATION)
if(CUDA_HOST_COMPILATION_CPP)
set(CUDA_C_OR_CXX CXX)
else(CUDA_HOST_COMPILATION_CPP)
set(nvcc_flags ${nvcc_flags} --host-compilation C)
set(CUDA_C_OR_CXX C)
endif(CUDA_HOST_COMPILATION_CPP)
set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION})
if(CUDA_64_BIT_DEVICE_CODE)
set(nvcc_flags ${nvcc_flags} -m64)
else()
set(nvcc_flags ${nvcc_flags} -m32)
endif()
# This needs to be passed in at this stage, because VS needs to fill out the
# value of VCInstallDir from within VS.
if(CMAKE_GENERATOR MATCHES "Visual Studio")
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# Add nvcc flag for 64b Windows
set(ccbin_flags -D "\"CCBIN:PATH=$(VCInstallDir)bin\"" )
endif()
endif()
# Figure out which configure we will use and pass that in as an argument to
# the script. We need to defer the decision until compilation time, because
# for VS projects we won't know if we are making a debug or release build
# until build time.
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set( CUDA_build_configuration "$(ConfigurationName)" )
else()
set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}")
endif()
# Initialize our list of includes with the user ones followed by the CUDA system ones.
set(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS_USER} "-I${CUDA_INCLUDE_DIRS}")
# Get the include directories for this directory and use them for our nvcc command.
get_directory_property(CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES)
if(CUDA_NVCC_INCLUDE_DIRECTORIES)
foreach(dir ${CUDA_NVCC_INCLUDE_DIRECTORIES})
list(APPEND CUDA_NVCC_INCLUDE_ARGS "-I${dir}")
endforeach()
endif()
# Reset these variables
set(CUDA_WRAP_OPTION_NVCC_FLAGS)
foreach(config ${CUDA_configuration_types})
string(TOUPPER ${config} config_upper)
set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper})
endforeach()
CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${ARGN})
CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options})
# Figure out if we are building a shared library. BUILD_SHARED_LIBS is
# respected in CUDA_ADD_LIBRARY.
set(_cuda_build_shared_libs FALSE)
# SHARED, MODULE
list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED)
list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE)
if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1)
set(_cuda_build_shared_libs TRUE)
endif()
# STATIC
list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC)
if(_cuda_found_STATIC GREATER -1)
set(_cuda_build_shared_libs FALSE)
endif()
# CUDA_HOST_FLAGS
if(_cuda_build_shared_libs)
# If we are setting up code for a shared library, then we need to add extra flags for
# compiling objects for shared libraries.
set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS})
else()
set(CUDA_HOST_SHARED_FLAGS)
endif()
# Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We
# always need to set the SHARED_FLAGS, though.
if(CUDA_PROPAGATE_HOST_FLAGS)
set(CUDA_HOST_FLAGS "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})")
else()
set(CUDA_HOST_FLAGS "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})")
endif()
set(CUDA_NVCC_FLAGS_CONFIG "# Build specific configuration flags")
# Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake
foreach(config ${CUDA_configuration_types})
string(TOUPPER ${config} config_upper)
# CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS
# we convert the strings to lists (like we want).
if(CUDA_PROPAGATE_HOST_FLAGS)
# nvcc chokes on -g3, so replace it with -g
if(CMAKE_COMPILER_IS_GNUCC)
string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}")
else()
set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}")
endif()
set(CUDA_HOST_FLAGS "${CUDA_HOST_FLAGS}\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})")
endif()
# Note that if we ever want CUDA_NVCC_FLAGS_<CONFIG> to be string (instead of a list
# like it is currently), we can remove the quotes around the
# ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_<CONFIG> variable.
set(CUDA_NVCC_FLAGS_CONFIG "${CUDA_NVCC_FLAGS_CONFIG}\nset(CUDA_NVCC_FLAGS_${config_upper} \"${CUDA_NVCC_FLAGS_${config_upper}};;${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}}\")")
endforeach()
if(compile_to_ptx)
# Don't use any of the host compilation flags for PTX targets.
set(CUDA_HOST_FLAGS)
set(CUDA_NVCC_FLAGS_CONFIG)
endif()
# Get the list of definitions from the directory property
get_directory_property(CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS)
if(CUDA_NVCC_DEFINITIONS)
foreach(_definition ${CUDA_NVCC_DEFINITIONS})
list(APPEND nvcc_flags "-D${_definition}")
endforeach()
endif()
if(_cuda_build_shared_libs)
list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
endif()
# Determine output directory
if(CUDA_GENERATED_OUTPUT_DIR)
set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}")
else()
set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
endif()
# Reset the output variable
set(_cuda_wrap_generated_files "")
# Iterate over the macro arguments and create custom
# commands for all the .cu files.
foreach(file ${ARGN})
# Ignore any file marked as a HEADER_FILE_ONLY
get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
if(${file} MATCHES ".*\\.cu$" AND NOT _is_header)
# Add a custom target to generate a c or ptx file. ######################
get_filename_component( basename ${file} NAME )
if( compile_to_ptx )
set(generated_file_path "${cuda_compile_output_dir}")
set(generated_file_basename "${cuda_target}_generated_${basename}.ptx")
set(format_flag "-ptx")
file(MAKE_DIRECTORY "${cuda_compile_output_dir}")
else( compile_to_ptx )
set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}")
set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}")
set(format_flag "-c")
endif( compile_to_ptx )
# Set all of our file names. Make sure that whatever filenames that have
# generated_file_path in them get passed in through as a command line
# argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time
# instead of configure time.
set(generated_file "${generated_file_path}/${generated_file_basename}")
set(cmake_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.depend")
set(NVCC_generated_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.NVCC-depend")
set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt")
set(custom_target_script "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.cmake")
# Setup properties for obj files:
if( NOT compile_to_ptx )
set_source_files_properties("${generated_file}"
PROPERTIES
EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked.
)
endif()
# Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path.
get_filename_component(file_path "${file}" PATH)
if(IS_ABSOLUTE "${file_path}")
set(source_file "${file}")
else()
set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
endif()
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND #######
cuda_include_nvcc_dependencies(${cmake_dependency_file})
# Convience string for output ###########################################
if(CUDA_BUILD_EMULATION)
set(cuda_build_type "Emulation")
else(CUDA_BUILD_EMULATION)
set(cuda_build_type "Device")
endif(CUDA_BUILD_EMULATION)
# Build the NVCC made dependency file ###################################
set(build_cubin OFF)
if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
if ( NOT compile_to_ptx )
set ( build_cubin ON )
endif( NOT compile_to_ptx )
endif( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
# Configure the build script
configure_file("${CUDA_run_nvcc}" "${custom_target_script}" @ONLY)
# So if a user specifies the same cuda file as input more than once, you
# can have bad things happen with dependencies. Here we check an option
# to see if this is the behavior they want.
if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE)
set(main_dep MAIN_DEPENDENCY ${source_file})
else()
set(main_dep DEPENDS ${source_file})
endif()
if(CUDA_VERBOSE_BUILD)
set(verbose_output ON)
elseif(CMAKE_GENERATOR MATCHES "Makefiles")
set(verbose_output "$(VERBOSE)")
else()
set(verbose_output OFF)
endif()
# Create up the comment string
file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}")
if(compile_to_ptx)
set(cuda_build_comment_string "Building NVCC ptx file ${generated_file_relative_path}")
else()
set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}")
endif()
# Build the generated file and dependency file ##########################
add_custom_command(
OUTPUT ${generated_file}
# These output files depend on the source_file and the contents of cmake_dependency_file
${main_dep}
DEPENDS ${CUDA_NVCC_DEPEND}
DEPENDS ${custom_target_script}
# Make sure the output directory exists before trying to write to it.
COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}"
COMMAND ${CMAKE_COMMAND} ARGS
-D verbose:BOOL=${verbose_output}
${ccbin_flags}
-D build_configuration:STRING=${CUDA_build_configuration}
-D "generated_file:STRING=${generated_file}"
-D "generated_cubin_file:STRING=${generated_cubin_file}"
-P "${custom_target_script}"
COMMENT "${cuda_build_comment_string}"
)
# Make sure the build system knows the file is generated.
set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
# Don't add the object file to the list of generated files if we are using
# visual studio and we are attaching the build rule to the cuda file. VS
# will add our object file to the linker automatically for us.
set(cuda_add_generated_file TRUE)
if(NOT compile_to_ptx AND CMAKE_GENERATOR MATCHES "Visual Studio" AND CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE)
# Visual Studio 8 crashes when you close the solution when you don't add the object file.
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 8")
#message("Not adding ${generated_file}")
set(cuda_add_generated_file FALSE)
endif()
endif()
if(cuda_add_generated_file)
list(APPEND _cuda_wrap_generated_files ${generated_file})
endif()
# Add the other files that we want cmake to clean on a cleanup ##########
list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}")
list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES)
set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.")
endif(${file} MATCHES ".*\\.cu$" AND NOT _is_header)
endforeach(file)
# Set the return parameter
set(${generated_files} ${_cuda_wrap_generated_files})
endmacro(CUDA_WRAP_SRCS)
###############################################################################
###############################################################################
# ADD LIBRARY
###############################################################################
###############################################################################
macro(CUDA_ADD_LIBRARY cuda_target)
CUDA_ADD_CUDA_INCLUDE_ONCE()
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources}
${_cmake_options} ${_cuda_shared_flag}
OPTIONS ${_options} )
# Add the library.
add_library(${cuda_target} ${_cmake_options}
${_generated_files}
${_sources}
)
target_link_libraries(${cuda_target}
${CUDA_LIBRARIES}
)
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
set_target_properties(${cuda_target}
PROPERTIES
LINKER_LANGUAGE ${CUDA_C_OR_CXX}
)
endmacro(CUDA_ADD_LIBRARY cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
macro(CUDA_ADD_EXECUTABLE cuda_target)
CUDA_ADD_CUDA_INCLUDE_ONCE()
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} )
# Add the library.
add_executable(${cuda_target} ${_cmake_options}
${_generated_files}
${_sources}
)
target_link_libraries(${cuda_target}
${CUDA_LIBRARIES}
)
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
set_target_properties(${cuda_target}
PROPERTIES
LINKER_LANGUAGE ${CUDA_C_OR_CXX}
)
endmacro(CUDA_ADD_EXECUTABLE cuda_target)
###############################################################################
###############################################################################
# CUDA COMPILE
###############################################################################
###############################################################################
macro(CUDA_COMPILE generated_files)
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( cuda_compile OBJ _generated_files ${_sources} ${_cmake_options}
OPTIONS ${_options} )
set( ${generated_files} ${_generated_files})
endmacro(CUDA_COMPILE)
###############################################################################
###############################################################################
# CUDA COMPILE PTX
###############################################################################
###############################################################################
macro(CUDA_COMPILE_PTX generated_files)
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( cuda_compile_ptx PTX _generated_files ${_sources} ${_cmake_options}
OPTIONS ${_options} )
set( ${generated_files} ${_generated_files})
endmacro(CUDA_COMPILE_PTX)
###############################################################################
###############################################################################
# CUDA ADD CUFFT TO TARGET
###############################################################################
###############################################################################
macro(CUDA_ADD_CUFFT_TO_TARGET target)
if (CUDA_BUILD_EMULATION)
target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY})
else()
target_link_libraries(${target} ${CUDA_cufft_LIBRARY})
endif()
endmacro()
###############################################################################
###############################################################################
# CUDA ADD CUBLAS TO TARGET
###############################################################################
###############################################################################
macro(CUDA_ADD_CUBLAS_TO_TARGET target)
if (CUDA_BUILD_EMULATION)
target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY})
else()
target_link_libraries(${target} ${CUDA_cublas_LIBRARY})
endif()
endmacro()
###############################################################################
###############################################################################
# CUDA BUILD CLEAN TARGET
###############################################################################
###############################################################################
macro(CUDA_BUILD_CLEAN_TARGET)
# Call this after you add all your CUDA targets, and you will get a convience
# target. You should also make clean after running this target to get the
# build system to generate all the code again.
set(cuda_clean_target_name clean_cuda_depends)
if (CMAKE_GENERATOR MATCHES "Visual Studio")
string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name)
endif()
add_custom_target(${cuda_clean_target_name}
COMMAND ${CMAKE_COMMAND} -E remove ${CUDA_ADDITIONAL_CLEAN_FILES})
# Clear out the variable, so the next time we configure it will be empty.
# This is useful so that the files won't persist in the list after targets
# have been removed.
set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.")
endmacro(CUDA_BUILD_CLEAN_TARGET)
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html # For more information, please see: http://software.sci.utah.edu
# #
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. # The MIT License
# #
# Copyright (c) 2007-2009 # Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah # Scientific Computing and Imaging Institute, University of Utah
# #
# This code is licensed under the MIT License. See the FindCUDA.cmake script # License for the specific language governing rights and limitations under
# for the text of the license. # Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# The MIT License # to deal in the Software without restriction, including without limitation
# # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# License for the specific language governing rights and limitations under # and/or sell copies of the Software, and to permit persons to whom the
# Permission is hereby granted, free of charge, to any person obtaining a # Software is furnished to do so, subject to the following conditions:
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation # The above copyright notice and this permission notice shall be included
# the rights to use, copy, modify, merge, publish, distribute, sublicense, # in all copies or substantial portions of the Software.
# and/or sell copies of the Software, and to permit persons to whom the #
# Software is furnished to do so, subject to the following conditions: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# The above copyright notice and this permission notice shall be included # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# in all copies or substantial portions of the Software. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # DEALINGS IN THE SOFTWARE.
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # Make2cmake CMake Script
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # Abe Stephens and James Bigler
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # (c) 2007 Scientific Computing and Imaging Institute, University of Utah
# DEALINGS IN THE SOFTWARE. # Note that the REGEX expressions may need to be tweaked for different dependency generators.
#
FILE(READ ${input_file} depend_text)
#######################################################################
# This converts a file written in makefile syntax into one that can be included IF (${depend_text} MATCHES ".+")
# by CMake.
# MESSAGE("FOUND DEPENDS")
file(READ ${input_file} depend_text)
# Remember, four backslashes is escaped to one backslash in the string.
if (${depend_text} MATCHES ".+") STRING(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
# message("FOUND DEPENDS") # This works for the nvcc -M generated dependency files.
STRING(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
# Remember, four backslashes is escaped to one backslash in the string. STRING(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
FOREACH(file ${depend_text})
# This works for the nvcc -M generated dependency files.
string(REGEX REPLACE "^.* : " "" depend_text ${depend_text}) STRING(REGEX REPLACE "^ +" "" file ${file})
string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
# IF (EXISTS ${file})
set(dependency_list "") # MESSAGE("DEPEND = ${file}")
# ELSE (EXISTS ${file})
foreach(file ${depend_text}) # MESSAGE("ERROR = ${file}")
# ENDIF(EXISTS ${file})
string(REGEX REPLACE "^ +" "" file ${file})
SET(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
if(NOT IS_DIRECTORY ${file})
# If softlinks start to matter, we should change this to REALPATH. For now we need ENDFOREACH(file)
# to flatten paths, because nvcc can generate stuff like /bin/../include instead of
# just /include. ELSE(${depend_text} MATCHES ".+")
get_filename_component(file_absolute "${file}" ABSOLUTE) # MESSAGE("FOUND NO DEPENDS")
list(APPEND dependency_list "${file_absolute}") ENDIF(${depend_text} MATCHES ".+")
endif(NOT IS_DIRECTORY ${file})
endforeach(file) FILE(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")
else()
# message("FOUND NO DEPENDS")
endif()
# Remove the duplicate entries and sort them.
list(REMOVE_DUPLICATES dependency_list)
list(SORT dependency_list)
foreach(file ${dependency_list})
set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
endforeach()
file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")
# James Bigler, NVIDIA Corp (nvidia.com - jbigler) # For more information, please see: http://software.sci.utah.edu
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
# #
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. # The MIT License
# #
# Copyright (c) 2007-2009 # Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah # Scientific Computing and Imaging Institute, University of Utah
# #
# This code is licensed under the MIT License. See the FindCUDA.cmake script # License for the specific language governing rights and limitations under
# for the text of the license. # Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# The MIT License # to deal in the Software without restriction, including without limitation
# # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# License for the specific language governing rights and limitations under # and/or sell copies of the Software, and to permit persons to whom the
# Permission is hereby granted, free of charge, to any person obtaining a # Software is furnished to do so, subject to the following conditions:
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # The above copyright notice and this permission notice shall be included
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # in all copies or substantial portions of the Software.
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
####################################################################### # .cubin Parsing CMake Script
# Parses a .cubin file produced by nvcc and reports statistics about the file. # Abe Stephens
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
FILE(READ ${input_file} file_text)
file(READ ${input_file} file_text) IF (${file_text} MATCHES ".+")
if (${file_text} MATCHES ".+")
# Remember, four backslashes is escaped to one backslash in the string. # Remember, four backslashes is escaped to one backslash in the string.
string(REGEX REPLACE ";" "\\\\;" file_text ${file_text}) STRING(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
string(REGEX REPLACE "\ncode" ";code" file_text ${file_text}) STRING(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
list(LENGTH file_text len) LIST(LENGTH file_text len)
foreach(line ${file_text}) FOREACH(line ${file_text})
# Only look at "code { }" blocks. # Only look at "code { }" blocks.
if(line MATCHES "^code") IF(line MATCHES "^code")
# Break into individual lines. # Break into individual lines.
string(REGEX REPLACE "\n" ";" line ${line}) STRING(REGEX REPLACE "\n" ";" line ${line})
foreach(entry ${line}) FOREACH(entry ${line})
# Extract kernel names. # Extract kernel names.
if (${entry} MATCHES "[^g]name = ([^ ]+)") IF (${entry} MATCHES "[^g]name = ([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
# Check to see if the kernel name starts with "_" # Check to see if the kernel name starts with "_"
set(skip FALSE) SET(skip FALSE)
# if (${entry} MATCHES "^_") # IF (${entry} MATCHES "^_")
# Skip the rest of this block. # Skip the rest of this block.
# message("Skipping ${entry}") # MESSAGE("Skipping ${entry}")
# set(skip TRUE) # SET(skip TRUE)
# else (${entry} MATCHES "^_") # ELSE (${entry} MATCHES "^_")
message("Kernel: ${entry}") MESSAGE("Kernel: ${entry}")
# endif (${entry} MATCHES "^_") # ENDIF (${entry} MATCHES "^_")
endif(${entry} MATCHES "[^g]name = ([^ ]+)") ENDIF(${entry} MATCHES "[^g]name = ([^ ]+)")
# Skip the rest of the block if necessary # Skip the rest of the block if necessary
if(NOT skip) IF(NOT skip)
# Registers # Registers
if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)") IF (${entry} MATCHES "reg = ([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry}) STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
message("Registers: ${entry}") MESSAGE("Registers: ${entry}")
endif() ENDIF(${entry} MATCHES "reg = ([^ ]+)")
# Local memory # Local memory
if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)") IF (${entry} MATCHES "lmem = ([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry}) STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
message("Local: ${entry}") MESSAGE("Local: ${entry}")
endif() ENDIF(${entry} MATCHES "lmem = ([^ ]+)")
# Shared memory # Shared memory
if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)") IF (${entry} MATCHES "smem = ([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry}) STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
message("Shared: ${entry}") MESSAGE("Shared: ${entry}")
endif() ENDIF(${entry} MATCHES "smem = ([^ ]+)")
if (${entry} MATCHES "^}") IF (${entry} MATCHES "^}")
message("") MESSAGE("")
endif() ENDIF(${entry} MATCHES "^}")
endif(NOT skip) ENDIF(NOT skip)
endforeach(entry) ENDFOREACH(entry)
endif(line MATCHES "^code") ENDIF(line MATCHES "^code")
endforeach(line) ENDFOREACH(line)
else() ELSE(${file_text} MATCHES ".+")
# message("FOUND NO DEPENDS") # MESSAGE("FOUND NO DEPENDS")
endif() ENDIF(${file_text} MATCHES ".+")
...@@ -111,6 +111,6 @@ ENDFOREACH(subdir) ...@@ -111,6 +111,6 @@ ENDFOREACH(subdir)
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake) # SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake)
SUBDIRS (sharedTarget) SUBDIRS (sharedTarget)
###############################################################################
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007-2008
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# This script locates the Nvidia Compute Unified Driver Architecture (CUDA)
# tools. It should work on linux, windows, and mac and should be reasonably
# up to date with cuda releases.
#
# The script will prompt the user to specify CUDA_INSTALL_PREFIX if the
# prefix cannot be determined by the location of nvcc in the system path. To
# use a different installed version of the toolkit set the environment variable
# CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0
# instead of the default /usr/local/cuda).
#
# Set CUDA_BUILD_TYPE to "Device" or "Emulation" mode.
# _DEVICEEMU is defined in "Emulation" mode.
#
# Set CUDA_BUILD_CUBIN to "ON" or "OFF" to enable and extra compilation pass
# with the -cubin option in Device mode. The output is parsed and register,
# shared memory usage is printed during build. Default ON.
#
# The script creates the following macros:
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
# -- Sets the directories that should be passed to nvcc
# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
# files.
#
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ... )
# -- Creates a shared library "cuda_target" which contains all of the source
# (*.c, *.cc, etc.) specified and all of the nvcc'ed .cu files specified.
# All of the specified source files and generated .cpp files are compiled
# using the standard CMake compiler, so the normal INCLUDE_DIRECTORIES,
# LINK_DIRECTORIES, and TARGET_LINK_LIBRARIES can be used to affect their
# build and link.
#
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... )
# -- Same as CUDA_ADD_LIBRARY except that an exectuable is created.
#
# CUDA_COMPILE( cuda_files file0 file1 ... )
# -- Returns a list of build commands in the first argument to be used with
# ADD_LIBRARY or ADD_EXECUTABLE.
#
# The script defines the following variables:
#
# ( Note CUDA_ADD_* macros setup cuda/cut library dependencies automatically.
# These variables are only needed if a cuda API call must be made from code in
# a outside library or executable. )
#
# CUDA_INCLUDE -- Include directory for cuda headers.
# CUDA_TARGET_LINK -- Cuda RT library.
# CUDA_CUT_INCLUDE -- Include directory for cuda SDK headers (cutil.h).
# CUDA_CUT_TARGET_LINK -- SDK libraries.
# CUDA_NVCC_FLAGS -- Additional NVCC command line arguments. NOTE:
# multiple arguments must be semi-colon delimited
# e.g. --compiler-options;-Wall
# CUBLAS_TARGET_LINK-- cublas library name.
# CUFFT_TARGET_LINK -- cubfft library name.
#
# The nvcc flag "--host-compilation;c++" should be used if functions declared
# as __host__ contain C++ code.
#
# It might be necessary to set CUDA_INSTALL_PATH manually on certain platforms,
# or to use a cuda runtime not installed in the default location. In newer
# versions of the toolkit the cuda library is included with the graphics
# driver- be sure that the driver version matches what is needed by the cuda
# runtime version.
#
# -- Abe Stephens SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
###############################################################################
# FindCuda.cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
INCLUDE(${FINDCUDA_DIR}/CudaDependency.cmake)
###############################################################################
###############################################################################
# Locate CUDA, Set Build Type, etc.
###############################################################################
###############################################################################
# Parse CUDA build type.
IF (NOT CUDA_BUILD_TYPE)
SET(CUDA_BUILD_TYPE "Device" CACHE STRING "Cuda build type: Emulation or Device")
ENDIF(NOT CUDA_BUILD_TYPE)
# Emulation if the card isn't present.
IF (CUDA_BUILD_TYPE MATCHES "Emulation")
# Emulation.
SET(nvcc_flags --device-emulation -D_DEVICEEMU -g)
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
# Device present.
SET(nvcc_flags "")
ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUDA_BUILD_CUBIN TRUE CACHE BOOL "Generate and parse .cubin files in Device mode.")
SET(CUDA_NVCC_FLAGS "--maxrregcount=32;-gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_13,code=sm_13;-use_fast_math;-O0" CACHE STRING "Semi-colon delimit multiple arguments.")
# Search for the cuda distribution.
IF(NOT CUDA_INSTALL_PREFIX)
FIND_PATH(CUDA_INSTALL_PREFIX
NAMES nvcc nvcc.exe
PATHS /usr/local/cuda C:/CUDA
PATH_SUFFIXES bin
ENV CUDA_BIN_PATH
DOC "Toolkit location."
)
IF (CUDA_INSTALL_PREFIX)
STRING(REGEX REPLACE "[/\\\\]?bin[/\\\\]?$" "" CUDA_INSTALL_PREFIX ${CUDA_INSTALL_PREFIX})
ENDIF(CUDA_INSTALL_PREFIX)
IF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
MESSAGE(FATAL_ERROR "Specify CUDA_INSTALL_PREFIX")
ENDIF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
ENDIF (NOT CUDA_INSTALL_PREFIX)
# CUDA_NVCC
IF (NOT CUDA_NVCC)
FIND_PROGRAM(CUDA_NVCC
nvcc
PATHS ${CUDA_INSTALL_PREFIX}/bin $ENV{CUDA_BIN_PATH}
)
IF(NOT CUDA_NVCC)
MESSAGE(FATAL_ERROR "Could not find nvcc")
ELSE(NOT CUDA_NVCC)
MARK_AS_ADVANCED(CUDA_NVCC)
ENDIF(NOT CUDA_NVCC)
ENDIF(NOT CUDA_NVCC)
# CUDA_NVCC_INCLUDE_ARGS
# IF (NOT FOUND_CUDA_NVCC_INCLUDE)
FIND_PATH(FOUND_CUDA_NVCC_INCLUDE
device_functions.h # Header included in toolkit
PATHS ${CUDA_INSTALL_PREFIX}/include
$ENV{CUDA_INC_PATH}
)
IF(NOT FOUND_CUDA_NVCC_INCLUDE)
MESSAGE(FATAL_ERROR "Could not find Cuda headers")
ELSE(NOT FOUND_CUDA_NVCC_INCLUDE)
# Set the initial include dir.
SET (CUDA_NVCC_INCLUDE_ARGS "-I"${FOUND_CUDA_NVCC_INCLUDE})
SET (CUDA_INCLUDE ${FOUND_CUDA_NVCC_INCLUDE})
MARK_AS_ADVANCED(
FOUND_CUDA_NVCC_INCLUDE
CUDA_NVCC_INCLUDE_ARGS
)
ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# CUDA_TARGET_LINK
IF (NOT CUDA_TARGET_LINK)
FIND_LIBRARY(FOUND_CUDART
cudart
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cudart\" library"
)
# Check to see if cudart library was found.
IF(NOT FOUND_CUDART)
MESSAGE(FATAL_ERROR "Could not find cudart library (cudart)")
ENDIF(NOT FOUND_CUDART)
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
FIND_LIBRARY(FOUND_CUDA
cuda
PATHS ${CUDA_INSTALL_PREFIX}/lib
DOC "\"cuda\" library (older versions only)."
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
)
# Add cuda library to the link line only if it is found.
IF (FOUND_CUDA)
SET(CUDA_TARGET_LINK ${FOUND_CUDA})
ENDIF(FOUND_CUDA)
# Always add cudart to the link line.
IF(FOUND_CUDART)
SET(CUDA_TARGET_LINK
${CUDA_TARGET_LINK} ${FOUND_CUDART}
)
MARK_AS_ADVANCED(
CUDA_TARGET_LINK
CUDA_LIB
FOUND_CUDA
FOUND_CUDART
)
ELSE(FOUND_CUDART)
MESSAGE(FATAL_ERROR "Could not find cuda libraries.")
ENDIF(FOUND_CUDART)
ENDIF(NOT CUDA_TARGET_LINK)
# CUDA_CUT_INCLUDE
IF(NOT CUDA_CUT_INCLUDE)
FIND_PATH(FOUND_CUT_INCLUDE
cutil.h
PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/common/inc
${CUDA_INSTALL_PREFIX}/NVSDK0.2/common/inc
${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/common/inc
$ENV{HOME}/NVIDIA_CUDA_SDK/common/inc
$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/common/inc
$ENV{NVSDKCUDA_ROOT}/common/inc
DOC "Location of cutil.h"
)
IF(FOUND_CUT_INCLUDE)
SET(CUDA_CUT_INCLUDE ${FOUND_CUT_INCLUDE})
MARK_AS_ADVANCED(
FOUND_CUT_INCLUDE
)
ENDIF(FOUND_CUT_INCLUDE)
ENDIF(NOT CUDA_CUT_INCLUDE)
# CUDA_CUT_TARGET_LINK
IF(NOT CUDA_CUT_TARGET_LINK)
FIND_LIBRARY(FOUND_CUT
cutil
cutil32
PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/lib
$ENV{HOME}/NVIDIA_CUDA_SDK/lib
$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/lib
$ENV{NVSDKCUDA_ROOT}/common/lib
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
DOC "Location of cutil library"
)
IF(FOUND_CUT)
SET(CUDA_CUT_TARGET_LINK ${FOUND_CUT})
MARK_AS_ADVANCED(
FOUND_CUT
)
ENDIF(FOUND_CUT)
# Add variables for cufft and cublas target link
FIND_LIBRARY(FOUND_CUFFTEMU
cufftemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cufftemu\" library"
)
FIND_LIBRARY(FOUND_CUBLASEMU
cublasemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cublasemu\" library"
)
FIND_LIBRARY(FOUND_CUFFT
cufft
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cufft\" library"
)
FIND_LIBRARY(FOUND_CUBLAS
cublas
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cublas\" library"
)
IF (CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFTEMU})
SET(CUBLAS_TARGET_LINK ${FOUND_CUBLASEMU})
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFT})
SET(CUBLAS_TARGET_LINK ${FOUND_CUBLAS})
ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
ENDIF(NOT CUDA_CUT_TARGET_LINK)
###############################################################################
# Add include directories to pass to the nvcc command.
MACRO(CUDA_INCLUDE_DIRECTORIES)
FOREACH(dir ${ARGN})
SET(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS} -I${dir})
ENDFOREACH(dir ${ARGN})
ENDMACRO(CUDA_INCLUDE_DIRECTORIES)
##############################################################################
##############################################################################
# This helper macro populates the following variables and setups up custom commands and targets to
# invoke the nvcc compiler. The compiler is invoked once with -M to generate a dependency file and
# a second time with -cuda to generate a .cpp file
# ${target_srcs}
# ${cuda_cu_sources}
##############################################################################
##############################################################################
MACRO(CUDA_add_custom_commands cuda_target)
SET(target_srcs "")
SET(cuda_cu_sources "")
# Iterate over the macro arguments and create custom
# commands for all the .cu files.
FOREACH(file ${ARGN})
IF(${file} MATCHES ".*\\.cu$")
# Add a custom target to generate a c file.
SET(generated_file "${CMAKE_BINARY_DIR}/src/cuda/${file}_${cuda_target}_generated.cpp")
SET(generated_target "${file}_target")
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/cuda)
SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/../${file})
# MESSAGE("${CUDA_NVCC} ${source_file} ${CUDA_NVCC_FLAGS} ${nvcc_flags} -cuda -o ${generated_file} ${CUDA_NVCC_INCLUDE_ARGS}")
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND
SET(cmake_dependency_file "${generated_file}.depend")
CUDA_INCLUDE_NVCC_DEPENDENCIES(${cmake_dependency_file})
SET(NVCC_generated_dependency_file "${generated_file}.NVCC-depend")
# Build the NVCC made dependency file
IF (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
SET(NVCC_generated_cubin_file "${generated_file}.NVCC-cubin.txt")
ADD_CUSTOM_COMMAND(
# Generate the .cubin output.
OUTPUT ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-DNVCC
-cubin
-o ${NVCC_generated_cubin_file}
${CUDA_NVCC_INCLUDE_ARGS}
# Execute the parser script.
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_cubin_file}"
-P "${FINDCUDA_DIR}/parse_cubin.cmake"
# MAIN_DEPENDENCY ${source_file}
DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC -cubin File: ${NVCC_generated_cubin_file}\n"
)
ELSE (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
# Depend on something that will exist.
SET(NVCC_generated_cubin_file "${source_file}")
ENDIF (CUDA_BUILD_TYPE MATCHES "Device"AND CUDA_BUILD_CUBIN)
# Build the NVCC made dependency file
ADD_CUSTOM_COMMAND(
OUTPUT ${NVCC_generated_dependency_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-DNVCC
-M
-o ${NVCC_generated_dependency_file}
${CUDA_NVCC_INCLUDE_ARGS}
# MAIN_DEPENDENCY ${source_file}
DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC Dependency File: ${NVCC_generated_dependency_file}\n"
)
# Build the CMake readible dependency file
ADD_CUSTOM_COMMAND(
OUTPUT ${cmake_dependency_file}
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_dependency_file}"
-D output_file="${cmake_dependency_file}"
-P "${FINDCUDA_DIR}/make2cmake.cmake"
MAIN_DEPENDENCY ${NVCC_generated_dependency_file}
COMMENT "Converting NVCC dependency to CMake (${cmake_dependency_file})"
)
ADD_CUSTOM_COMMAND(
OUTPUT ${generated_file}
MAIN_DEPENDENCY ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
DEPENDS ${cmake_dependency_file}
DEPENDS ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
${CUDA_NVCC_BUILD_FLAGS}
-DNVCC
--keep
-cuda -o ${generated_file}
${CUDA_NVCC_INCLUDE_ARGS}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC ${source_file}: ${generated_file}\n"
)
SET(cuda_cu_sources ${cuda_cu_sources} ${source_file})
# Add the generated file name to the source list.
SET(target_srcs ${target_srcs} ${generated_file})
ELSE(${file} MATCHES ".*\\.cu$")
# Otherwise add the file name to the source list.
SET(target_srcs ${target_srcs} ${file})
ENDIF(${file} MATCHES ".*\\.cu$")
ENDFOREACH(file)
ENDMACRO(CUDA_add_custom_commands)
###############################################################################
###############################################################################
# ADD LIBRARY
###############################################################################
###############################################################################
MACRO(CUDA_ADD_LIBRARY cuda_target)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
# Add the library.
ADD_LIBRARY(${cuda_target}
${target_srcs}
${cuda_cu_sources}
)
TARGET_LINK_LIBRARIES(${cuda_target}
${CUDA_TARGET_LINK}
)
ENDMACRO(CUDA_ADD_LIBRARY cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
MACRO(CUDA_ADD_EXECUTABLE cuda_target)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
# Add the library.
ADD_EXECUTABLE(${cuda_target}
${target_srcs}
${cuda_cu_sources}
)
TARGET_LINK_LIBRARIES(${cuda_target}
${CUDA_TARGET_LINK}
)
ENDMACRO(CUDA_ADD_EXECUTABLE cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
MACRO(CUDA_COMPILE file_variable)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( cuda_compile ${ARGN} )
SET(file_variable ${target_srcs} ${cuda_cu_sources})
ENDMACRO(CUDA_COMPILE)
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# Make2cmake CMake Script
# Abe Stephens and James Bigler
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
# Note that the REGEX expressions may need to be tweaked for different dependency generators.
FILE(READ ${input_file} depend_text)
IF (${depend_text} MATCHES ".+")
# MESSAGE("FOUND DEPENDS")
# Remember, four backslashes is escaped to one backslash in the string.
STRING(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
# This works for the nvcc -M generated dependency files.
STRING(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
STRING(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
FOREACH(file ${depend_text})
STRING(REGEX REPLACE "^ +" "" file ${file})
# IF (EXISTS ${file})
# MESSAGE("DEPEND = ${file}")
# ELSE (EXISTS ${file})
# MESSAGE("ERROR = ${file}")
# ENDIF(EXISTS ${file})
SET(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
ENDFOREACH(file)
ELSE(${depend_text} MATCHES ".+")
# MESSAGE("FOUND NO DEPENDS")
ENDIF(${depend_text} MATCHES ".+")
FILE(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# .cubin Parsing CMake Script
# Abe Stephens
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
FILE(READ ${input_file} file_text)
IF (${file_text} MATCHES ".+")
# Remember, four backslashes is escaped to one backslash in the string.
STRING(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
STRING(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
LIST(LENGTH file_text len)
FOREACH(line ${file_text})
# Only look at "code { }" blocks.
IF(line MATCHES "^code")
# Break into individual lines.
STRING(REGEX REPLACE "\n" ";" line ${line})
FOREACH(entry ${line})
# Extract kernel names.
IF (${entry} MATCHES "[^g]name = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
# Check to see if the kernel name starts with "_"
SET(skip FALSE)
# IF (${entry} MATCHES "^_")
# Skip the rest of this block.
# MESSAGE("Skipping ${entry}")
# SET(skip TRUE)
# ELSE (${entry} MATCHES "^_")
MESSAGE("Kernel: ${entry}")
# ENDIF (${entry} MATCHES "^_")
ENDIF(${entry} MATCHES "[^g]name = ([^ ]+)")
# Skip the rest of the block if necessary
IF(NOT skip)
# Registers
IF (${entry} MATCHES "reg = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
MESSAGE("Registers: ${entry}")
ENDIF(${entry} MATCHES "reg = ([^ ]+)")
# Local memory
IF (${entry} MATCHES "lmem = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
MESSAGE("Local: ${entry}")
ENDIF(${entry} MATCHES "lmem = ([^ ]+)")
# Shared memory
IF (${entry} MATCHES "smem = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
MESSAGE("Shared: ${entry}")
ENDIF(${entry} MATCHES "smem = ([^ ]+)")
IF (${entry} MATCHES "^}")
MESSAGE("")
ENDIF(${entry} MATCHES "^}")
ENDIF(NOT skip)
ENDFOREACH(entry)
ENDIF(line MATCHES "^code")
ENDFOREACH(line)
ELSE(${file_text} MATCHES ".+")
# MESSAGE("FOUND NO DEPENDS")
ENDIF(${file_text} MATCHES ".+")
# #
# Include CUDA related files. # Include CUDA related files.
# #
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake) # INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE}) INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK}) LINK_DIRECTORIES(${CUDA_TARGET_LINK})
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS}) FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
ENABLE_TESTING() ENABLE_TESTING()
INCLUDE(${CMAKE_SOURCE_DIR}/platforms/cuda/cuda-cmake/FindCuda.cmake) # INCLUDE(${CMAKE_SOURCE_DIR}/platforms/cuda/cuda-cmake/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE}) INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
# Automatically create tests using files named "Test*.cpp" # Automatically create tests using files named "Test*.cpp"
......
...@@ -138,6 +138,6 @@ ENDIF(LOG) ...@@ -138,6 +138,6 @@ ENDIF(LOG)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake) # SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake)
SUBDIRS (sharedTarget staticTarget) SUBDIRS (sharedTarget staticTarget)
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# This code is based on the Manta swig/python wrapper dependency checking code.
# -- Abe Stephens
#####################################################################
## CUDA_INCLUDE_NVCC_DEPENDENCIES
##
# So we want to try and include the dependency file if it exists. If
# it doesn't exist then we need to create an empty one, so we can
# include it.
# If it does exist, then we need to check to see if all the files it
# depends on exist. If they don't then we should clear the dependency
# file and regenerate it later. This covers the case where a header
# file has disappeared or moved.
MACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file)
SET(CUDA_NVCC_DEPEND)
SET(CUDA_NVCC_DEPEND_REGENERATE)
# Include the dependency file. Create it first if it doesn't exist
# for make files except for IDEs (see below). The INCLUDE puts a
# dependency that will force CMake to rerun and bring in the new info
# when it changes. DO NOT REMOVE THIS (as I did and spent a few hours
# figuring out why it didn't work.
IF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
IF(NOT EXISTS ${dependency_file})
CONFIGURE_FILE(
${FINDCUDA_DIR}/empty.depend.in
${dependency_file} IMMEDIATE)
ENDIF(NOT EXISTS ${dependency_file})
# Always include this file to force CMake to run again next
# invocation and rebuild the dependencies.
INCLUDE(${dependency_file})
ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "make")
# for IDE generators like MS dev only include the depend files
# if they exist. This is to prevent ecessive reloading of
# workspaces after each build. This also means
# that the depends will not be correct until cmake
# is run once after the build has completed once.
# the depend files are created in the wrap tcl/python sections
# when the .xml file is parsed.
INCLUDE(${dependency_file} OPTIONAL)
ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
# Now we need to verify the existence of all the included files
# here. If they aren't there we need to just blank this variable and
# make the file regenerate again.
IF(CUDA_NVCC_DEPEND)
FOREACH(f ${CUDA_NVCC_DEPEND})
IF(EXISTS ${f})
ELSE(EXISTS ${f})
SET(CUDA_NVCC_DEPEND_REGENERATE 1)
ENDIF(EXISTS ${f})
ENDFOREACH(f)
ELSE(CUDA_NVCC_DEPEND)
# No dependencies, so regenerate the file.
SET(CABLE_NVCC_DEPEND_REGENERATE 1)
ENDIF(CUDA_NVCC_DEPEND)
# No incoming dependencies, so we need to generate them. Make the
# output depend on the dependency file itself, which should cause the
# rule to re-run.
IF(CUDA_NVCC_DEPEND_REGENERATE)
SET(CUDA_NVCC_DEPEND ${dependency_file})
# Force CMake to run again next build
CONFIGURE_FILE(
${FINDCUDA_DIR}/empty.depend.in
${dependency_file} IMMEDIATE)
ENDIF(CUDA_NVCC_DEPEND_REGENERATE)
ENDMACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES)
\ No newline at end of file
###############################################################################
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007-2008
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# This script locates the Nvidia Compute Unified Driver Architecture (CUDA)
# tools. It should work on linux, windows, and mac and should be reasonably
# up to date with cuda releases.
#
# The script will prompt the user to specify CUDA_INSTALL_PREFIX if the
# prefix cannot be determined by the location of nvcc in the system path. To
# use a different installed version of the toolkit set the environment variable
# CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0
# instead of the default /usr/local/cuda).
#
# Set CUDA_BUILD_TYPE to "Device" or "Emulation" mode.
# _DEVICEEMU is defined in "Emulation" mode.
#
# Set CUDA_BUILD_CUBIN to "ON" or "OFF" to enable and extra compilation pass
# with the -cubin option in Device mode. The output is parsed and register,
# shared memory usage is printed during build. Default ON.
#
# The script creates the following macros:
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
# -- Sets the directories that should be passed to nvcc
# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
# files.
#
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ... )
# -- Creates a shared library "cuda_target" which contains all of the source
# (*.c, *.cc, etc.) specified and all of the nvcc'ed .cu files specified.
# All of the specified source files and generated .cpp files are compiled
# using the standard CMake compiler, so the normal INCLUDE_DIRECTORIES,
# LINK_DIRECTORIES, and TARGET_LINK_LIBRARIES can be used to affect their
# build and link.
#
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... )
# -- Same as CUDA_ADD_LIBRARY except that an exectuable is created.
#
# CUDA_COMPILE( cuda_files file0 file1 ... )
# -- Returns a list of build commands in the first argument to be used with
# ADD_LIBRARY or ADD_EXECUTABLE.
#
# The script defines the following variables:
#
# ( Note CUDA_ADD_* macros setup cuda/cut library dependencies automatically.
# These variables are only needed if a cuda API call must be made from code in
# a outside library or executable. )
#
# CUDA_INCLUDE -- Include directory for cuda headers.
# CUDA_TARGET_LINK -- Cuda RT library.
# CUDA_CUT_INCLUDE -- Include directory for cuda SDK headers (cutil.h).
# CUDA_CUT_TARGET_LINK -- SDK libraries.
# CUDA_NVCC_FLAGS -- Additional NVCC command line arguments. NOTE:
# multiple arguments must be semi-colon delimited
# e.g. --compiler-options;-Wall
# CUBLAS_TARGET_LINK-- cublas library name.
# CUFFT_TARGET_LINK -- cubfft library name.
#
# The nvcc flag "--host-compilation;c++" should be used if functions declared
# as __host__ contain C++ code.
#
# It might be necessary to set CUDA_INSTALL_PATH manually on certain platforms,
# or to use a cuda runtime not installed in the default location. In newer
# versions of the toolkit the cuda library is included with the graphics
# driver- be sure that the driver version matches what is needed by the cuda
# runtime version.
#
# -- Abe Stephens SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
###############################################################################
# FindCuda.cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
INCLUDE(${FINDCUDA_DIR}/CudaDependency.cmake)
###############################################################################
###############################################################################
# Locate CUDA, Set Build Type, etc.
###############################################################################
###############################################################################
# Parse CUDA build type.
IF (NOT CUDA_BUILD_TYPE)
SET(CUDA_BUILD_TYPE "Device" CACHE STRING "Cuda build type: Emulation or Device")
ENDIF(NOT CUDA_BUILD_TYPE)
# Emulation if the card isn't present.
IF (CUDA_BUILD_TYPE MATCHES "Emulation")
# Emulation.
SET(nvcc_flags --device-emulation -D_DEVICEEMU -g)
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
# Device present.
SET(nvcc_flags "")
ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUDA_BUILD_CUBIN TRUE CACHE BOOL "Generate and parse .cubin files in Device mode.")
SET(CUDA_NVCC_FLAGS "--maxrregcount=32;-gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_13,code=sm_13;-use_fast_math;-O0" CACHE STRING "Semi-colon delimit multiple arguments.")
# Search for the cuda distribution.
IF(NOT CUDA_INSTALL_PREFIX)
FIND_PATH(CUDA_INSTALL_PREFIX
NAMES nvcc nvcc.exe
PATHS /usr/local/cuda C:/CUDA
PATH_SUFFIXES bin
ENV CUDA_BIN_PATH
DOC "Toolkit location."
)
IF (CUDA_INSTALL_PREFIX)
STRING(REGEX REPLACE "[/\\\\]?bin[/\\\\]?$" "" CUDA_INSTALL_PREFIX ${CUDA_INSTALL_PREFIX})
ENDIF(CUDA_INSTALL_PREFIX)
IF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
MESSAGE(FATAL_ERROR "Specify CUDA_INSTALL_PREFIX")
ENDIF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
ENDIF (NOT CUDA_INSTALL_PREFIX)
# CUDA_NVCC
IF (NOT CUDA_NVCC)
FIND_PROGRAM(CUDA_NVCC
nvcc
PATHS ${CUDA_INSTALL_PREFIX}/bin $ENV{CUDA_BIN_PATH}
)
IF(NOT CUDA_NVCC)
MESSAGE(FATAL_ERROR "Could not find nvcc")
ELSE(NOT CUDA_NVCC)
MARK_AS_ADVANCED(CUDA_NVCC)
ENDIF(NOT CUDA_NVCC)
ENDIF(NOT CUDA_NVCC)
# CUDA_NVCC_INCLUDE_ARGS
# IF (NOT FOUND_CUDA_NVCC_INCLUDE)
FIND_PATH(FOUND_CUDA_NVCC_INCLUDE
device_functions.h # Header included in toolkit
PATHS ${CUDA_INSTALL_PREFIX}/include
$ENV{CUDA_INC_PATH}
)
IF(NOT FOUND_CUDA_NVCC_INCLUDE)
MESSAGE(FATAL_ERROR "Could not find Cuda headers")
ELSE(NOT FOUND_CUDA_NVCC_INCLUDE)
# Set the initial include dir.
SET (CUDA_NVCC_INCLUDE_ARGS "-I"${FOUND_CUDA_NVCC_INCLUDE})
SET (CUDA_INCLUDE ${FOUND_CUDA_NVCC_INCLUDE})
MARK_AS_ADVANCED(
FOUND_CUDA_NVCC_INCLUDE
CUDA_NVCC_INCLUDE_ARGS
)
ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
# CUDA_TARGET_LINK
IF (NOT CUDA_TARGET_LINK)
FIND_LIBRARY(FOUND_CUDART
cudart
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cudart\" library"
)
# Check to see if cudart library was found.
IF(NOT FOUND_CUDART)
MESSAGE(FATAL_ERROR "Could not find cudart library (cudart)")
ENDIF(NOT FOUND_CUDART)
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
FIND_LIBRARY(FOUND_CUDA
cuda
PATHS ${CUDA_INSTALL_PREFIX}/lib
DOC "\"cuda\" library (older versions only)."
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
)
# Add cuda library to the link line only if it is found.
IF (FOUND_CUDA)
SET(CUDA_TARGET_LINK ${FOUND_CUDA})
ENDIF(FOUND_CUDA)
# Always add cudart to the link line.
IF(FOUND_CUDART)
SET(CUDA_TARGET_LINK
${CUDA_TARGET_LINK} ${FOUND_CUDART}
)
MARK_AS_ADVANCED(
CUDA_TARGET_LINK
CUDA_LIB
FOUND_CUDA
FOUND_CUDART
)
ELSE(FOUND_CUDART)
MESSAGE(FATAL_ERROR "Could not find cuda libraries.")
ENDIF(FOUND_CUDART)
ENDIF(NOT CUDA_TARGET_LINK)
# CUDA_CUT_INCLUDE
IF(NOT CUDA_CUT_INCLUDE)
FIND_PATH(FOUND_CUT_INCLUDE
cutil.h
PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/common/inc
${CUDA_INSTALL_PREFIX}/NVSDK0.2/common/inc
${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/common/inc
$ENV{HOME}/NVIDIA_CUDA_SDK/common/inc
$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/common/inc
$ENV{NVSDKCUDA_ROOT}/common/inc
DOC "Location of cutil.h"
)
IF(FOUND_CUT_INCLUDE)
SET(CUDA_CUT_INCLUDE ${FOUND_CUT_INCLUDE})
MARK_AS_ADVANCED(
FOUND_CUT_INCLUDE
)
ENDIF(FOUND_CUT_INCLUDE)
ENDIF(NOT CUDA_CUT_INCLUDE)
# CUDA_CUT_TARGET_LINK
IF(NOT CUDA_CUT_TARGET_LINK)
FIND_LIBRARY(FOUND_CUT
cutil
cutil32
PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NVSDK0.2/lib
${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/lib
$ENV{HOME}/NVIDIA_CUDA_SDK/lib
$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/lib
$ENV{NVSDKCUDA_ROOT}/common/lib
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
DOC "Location of cutil library"
)
IF(FOUND_CUT)
SET(CUDA_CUT_TARGET_LINK ${FOUND_CUT})
MARK_AS_ADVANCED(
FOUND_CUT
)
ENDIF(FOUND_CUT)
# Add variables for cufft and cublas target link
FIND_LIBRARY(FOUND_CUFFTEMU
cufftemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cufftemu\" library"
)
FIND_LIBRARY(FOUND_CUBLASEMU
cublasemu
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cublasemu\" library"
)
FIND_LIBRARY(FOUND_CUFFT
cufft
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cufft\" library"
)
FIND_LIBRARY(FOUND_CUBLAS
cublas
PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
DOC "\"cublas\" library"
)
IF (CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFTEMU})
SET(CUBLAS_TARGET_LINK ${FOUND_CUBLASEMU})
ELSE(CUDA_BUILD_TYPE MATCHES "Emulation")
SET(CUFFT_TARGET_LINK ${FOUND_CUFFT})
SET(CUBLAS_TARGET_LINK ${FOUND_CUBLAS})
ENDIF(CUDA_BUILD_TYPE MATCHES "Emulation")
ENDIF(NOT CUDA_CUT_TARGET_LINK)
###############################################################################
# Add include directories to pass to the nvcc command.
MACRO(CUDA_INCLUDE_DIRECTORIES)
FOREACH(dir ${ARGN})
SET(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS} -I${dir})
ENDFOREACH(dir ${ARGN})
ENDMACRO(CUDA_INCLUDE_DIRECTORIES)
##############################################################################
##############################################################################
# This helper macro populates the following variables and setups up custom commands and targets to
# invoke the nvcc compiler. The compiler is invoked once with -M to generate a dependency file and
# a second time with -cuda to generate a .cpp file
# ${target_srcs}
# ${cuda_cu_sources}
##############################################################################
##############################################################################
MACRO(CUDA_add_custom_commands cuda_target)
SET(target_srcs "")
SET(cuda_cu_sources "")
# Iterate over the macro arguments and create custom
# commands for all the .cu files.
FOREACH(file ${ARGN})
IF(${file} MATCHES ".*\\.cu$")
# Add a custom target to generate a c file.
SET(generated_file "${CMAKE_BINARY_DIR}/src/cuda/${file}_${cuda_target}_generated.cpp")
SET(generated_target "${file}_target")
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/cuda)
SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/../${file})
# MESSAGE("${CUDA_NVCC} ${source_file} ${CUDA_NVCC_FLAGS} ${nvcc_flags} -cuda -o ${generated_file} ${CUDA_NVCC_INCLUDE_ARGS}")
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND
SET(cmake_dependency_file "${generated_file}.depend")
CUDA_INCLUDE_NVCC_DEPENDENCIES(${cmake_dependency_file})
SET(NVCC_generated_dependency_file "${generated_file}.NVCC-depend")
# Build the NVCC made dependency file
IF (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
SET(NVCC_generated_cubin_file "${generated_file}.NVCC-cubin.txt")
ADD_CUSTOM_COMMAND(
# Generate the .cubin output.
OUTPUT ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-DNVCC
-cubin
-o ${NVCC_generated_cubin_file}
${CUDA_NVCC_INCLUDE_ARGS}
# Execute the parser script.
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_cubin_file}"
-P "${FINDCUDA_DIR}/parse_cubin.cmake"
# MAIN_DEPENDENCY ${source_file}
DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC -cubin File: ${NVCC_generated_cubin_file}\n"
)
ELSE (CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
# Depend on something that will exist.
SET(NVCC_generated_cubin_file "${source_file}")
ENDIF (CUDA_BUILD_TYPE MATCHES "Device"AND CUDA_BUILD_CUBIN)
# Build the NVCC made dependency file
ADD_CUSTOM_COMMAND(
OUTPUT ${NVCC_generated_dependency_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-DNVCC
-M
-o ${NVCC_generated_dependency_file}
${CUDA_NVCC_INCLUDE_ARGS}
# MAIN_DEPENDENCY ${source_file}
DEPENDS ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC Dependency File: ${NVCC_generated_dependency_file}\n"
)
# Build the CMake readible dependency file
ADD_CUSTOM_COMMAND(
OUTPUT ${cmake_dependency_file}
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_dependency_file}"
-D output_file="${cmake_dependency_file}"
-P "${FINDCUDA_DIR}/make2cmake.cmake"
MAIN_DEPENDENCY ${NVCC_generated_dependency_file}
COMMENT "Converting NVCC dependency to CMake (${cmake_dependency_file})"
)
ADD_CUSTOM_COMMAND(
OUTPUT ${generated_file}
MAIN_DEPENDENCY ${source_file}
DEPENDS ${CUDA_NVCC_DEPEND}
DEPENDS ${cmake_dependency_file}
DEPENDS ${NVCC_generated_cubin_file}
COMMAND ${CUDA_NVCC}
ARGS ${source_file}
${CUDA_NVCC_FLAGS}
${nvcc_flags}
${CUDA_NVCC_BUILD_FLAGS}
-DNVCC
--keep
-cuda -o ${generated_file}
${CUDA_NVCC_INCLUDE_ARGS}
COMMENT "Building (${CUDA_BUILD_TYPE}) NVCC ${source_file}: ${generated_file}\n"
)
SET(cuda_cu_sources ${cuda_cu_sources} ${source_file})
# Add the generated file name to the source list.
SET(target_srcs ${target_srcs} ${generated_file})
ELSE(${file} MATCHES ".*\\.cu$")
# Otherwise add the file name to the source list.
SET(target_srcs ${target_srcs} ${file})
ENDIF(${file} MATCHES ".*\\.cu$")
ENDFOREACH(file)
ENDMACRO(CUDA_add_custom_commands)
###############################################################################
###############################################################################
# ADD LIBRARY
###############################################################################
###############################################################################
MACRO(CUDA_ADD_LIBRARY cuda_target)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
# Add the library.
ADD_LIBRARY(${cuda_target}
${target_srcs}
${cuda_cu_sources}
)
TARGET_LINK_LIBRARIES(${cuda_target}
${CUDA_TARGET_LINK}
)
ENDMACRO(CUDA_ADD_LIBRARY cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
MACRO(CUDA_ADD_EXECUTABLE cuda_target)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
# Add the library.
ADD_EXECUTABLE(${cuda_target}
${target_srcs}
${cuda_cu_sources}
)
TARGET_LINK_LIBRARIES(${cuda_target}
${CUDA_TARGET_LINK}
)
ENDMACRO(CUDA_ADD_EXECUTABLE cuda_target)
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
MACRO(CUDA_COMPILE file_variable)
# Create custom commands and targets for each file.
CUDA_add_custom_commands( cuda_compile ${ARGN} )
SET(file_variable ${target_srcs} ${cuda_cu_sources})
ENDMACRO(CUDA_COMPILE)
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# Make2cmake CMake Script
# Abe Stephens and James Bigler
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
# Note that the REGEX expressions may need to be tweaked for different dependency generators.
FILE(READ ${input_file} depend_text)
IF (${depend_text} MATCHES ".+")
# MESSAGE("FOUND DEPENDS")
# Remember, four backslashes is escaped to one backslash in the string.
STRING(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
# This works for the nvcc -M generated dependency files.
STRING(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
STRING(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
FOREACH(file ${depend_text})
STRING(REGEX REPLACE "^ +" "" file ${file})
# IF (EXISTS ${file})
# MESSAGE("DEPEND = ${file}")
# ELSE (EXISTS ${file})
# MESSAGE("ERROR = ${file}")
# ENDIF(EXISTS ${file})
SET(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
ENDFOREACH(file)
ELSE(${depend_text} MATCHES ".+")
# MESSAGE("FOUND NO DEPENDS")
ENDIF(${depend_text} MATCHES ".+")
FILE(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")
# For more information, please see: http://software.sci.utah.edu
#
# The MIT License
#
# Copyright (c) 2007
# Scientific Computing and Imaging Institute, University of Utah
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# .cubin Parsing CMake Script
# Abe Stephens
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
FILE(READ ${input_file} file_text)
IF (${file_text} MATCHES ".+")
# Remember, four backslashes is escaped to one backslash in the string.
STRING(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
STRING(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
LIST(LENGTH file_text len)
FOREACH(line ${file_text})
# Only look at "code { }" blocks.
IF(line MATCHES "^code")
# Break into individual lines.
STRING(REGEX REPLACE "\n" ";" line ${line})
FOREACH(entry ${line})
# Extract kernel names.
IF (${entry} MATCHES "[^g]name = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
# Check to see if the kernel name starts with "_"
SET(skip FALSE)
# IF (${entry} MATCHES "^_")
# Skip the rest of this block.
# MESSAGE("Skipping ${entry}")
# SET(skip TRUE)
# ELSE (${entry} MATCHES "^_")
MESSAGE("Kernel: ${entry}")
# ENDIF (${entry} MATCHES "^_")
ENDIF(${entry} MATCHES "[^g]name = ([^ ]+)")
# Skip the rest of the block if necessary
IF(NOT skip)
# Registers
IF (${entry} MATCHES "reg = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
MESSAGE("Registers: ${entry}")
ENDIF(${entry} MATCHES "reg = ([^ ]+)")
# Local memory
IF (${entry} MATCHES "lmem = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
MESSAGE("Local: ${entry}")
ENDIF(${entry} MATCHES "lmem = ([^ ]+)")
# Shared memory
IF (${entry} MATCHES "smem = ([^ ]+)")
STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
MESSAGE("Shared: ${entry}")
ENDIF(${entry} MATCHES "smem = ([^ ]+)")
IF (${entry} MATCHES "^}")
MESSAGE("")
ENDIF(${entry} MATCHES "^}")
ENDIF(NOT skip)
ENDFOREACH(entry)
ENDIF(line MATCHES "^code")
ENDFOREACH(line)
ELSE(${file_text} MATCHES ".+")
# MESSAGE("FOUND NO DEPENDS")
ENDIF(${file_text} MATCHES ".+")
...@@ -36,7 +36,7 @@ ENDIF(LOG) ...@@ -36,7 +36,7 @@ ENDIF(LOG)
## ---------------------------------------------------------------------------- ## ----------------------------------------------------------------------------
# message("CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}") # message("CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}")
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake) # INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
# message("CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}") # message("CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}")
INCLUDE_DIRECTORIES(${CUDA_INCLUDE}) INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK}) LINK_DIRECTORIES(${CUDA_TARGET_LINK})
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
SET(OPENMM_BUILD_FREE_ENERGY_PATH ${CMAKE_SOURCE_DIR}/plugins/freeEnergy) SET(OPENMM_BUILD_FREE_ENERGY_PATH ${CMAKE_SOURCE_DIR}/plugins/freeEnergy)
SET(CUDA_NVCC_BUILD_FLAGS "-DCUDPP_STATIC_LIB" ) SET(CUDA_NVCC_BUILD_FLAGS "-DCUDPP_STATIC_LIB" )
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake) # INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE}) INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK}) LINK_DIRECTORIES(${CUDA_TARGET_LINK})
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS}) FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment