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 @@
# 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
#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
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
# Does someone at Kitware actually believe that this policy crap
# might actually make cmake LESS brittle?
# (Probably the same genius who came up the endif(allthesamecrap) syntax)
......@@ -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(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
IF(${CMAKE_C_COMPILER} MATCHES "gcc")
IF(NOT OPENMM_INSTALL_PREFIX)
......@@ -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)
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
# 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)
......@@ -261,9 +265,6 @@ FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
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.
# Java and gccxml are required for API wrappers
FIND_PACKAGE(Java)
......@@ -314,10 +315,27 @@ ADD_SUBDIRECTORY(platforms/reference/tests)
# Which hardware platforms to build
IF(NOT cmv EQUAL "2.4")
FIND_PACKAGE(CUDA QUIET)
ENDIF(NOT cmv EQUAL "2.4")
IF(CUDA_FOUND)
# A bit of tedium because we are using custom FindCUDA files that happen to work...
SET(FINDCUDA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindCUDA")
SET(CUDA_BUILD_CUBIN OFF)
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")
# I wish I was not hardcoding /MD here
......@@ -341,9 +359,9 @@ IF(CUDA_FOUND)
CACHE STRING "Semicolon delimit multiple arguments" FORCE)
ENDIF(NOT HAS_NVCC_FLAG)
ENDIF(MSVC)
ELSE(CUDA_FOUND)
ELSE(FOUND_CUDA)
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)
ADD_SUBDIRECTORY(platforms/cuda)
ENDIF(OPENMM_BUILD_CUDA_LIB)
......@@ -414,3 +432,5 @@ INCLUDE(ApiDoxygen.cmake)
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(examples)
ENDIF(NOT cmv EQUAL "2.4") # This whole file...
This diff is collapsed.
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# The MIT License
#
# 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 converts a file written in makefile syntax into one that can be included
# by CMake.
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})
set(dependency_list "")
foreach(file ${depend_text})
string(REGEX REPLACE "^ +" "" file ${file})
if(NOT IS_DIRECTORY ${file})
# If softlinks start to matter, we should change this to REALPATH. For now we need
# to flatten paths, because nvcc can generate stuff like /bin/../include instead of
# just /include.
get_filename_component(file_absolute "${file}" ABSOLUTE)
list(APPEND dependency_list "${file_absolute}")
endif(NOT IS_DIRECTORY ${file})
endforeach(file)
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")
# 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")
# 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
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# The MIT License
#
# 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.
# 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 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.
# 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.
#######################################################################
# Parses a .cubin file produced by nvcc and reports statistics about the file.
# .cubin Parsing CMake Script
# 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.
string(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
string(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
list(LENGTH file_text len)
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})
FOREACH(line ${file_text})
# Only look at "code { }" blocks.
if(line MATCHES "^code")
IF(line MATCHES "^code")
# 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.
if (${entry} MATCHES "[^g]name = ([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
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 "^_")
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 "^_")
# MESSAGE("Skipping ${entry}")
# SET(skip TRUE)
# ELSE (${entry} MATCHES "^_")
MESSAGE("Kernel: ${entry}")
# ENDIF (${entry} MATCHES "^_")
endif(${entry} MATCHES "[^g]name = ([^ ]+)")
ENDIF(${entry} MATCHES "[^g]name = ([^ ]+)")
# Skip the rest of the block if necessary
if(NOT skip)
IF(NOT skip)
# Registers
if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Registers: ${entry}")
endif()
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 ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Local: ${entry}")
endif()
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 ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Shared: ${entry}")
endif()
if (${entry} MATCHES "^}")
message("")
endif()
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)
ENDIF(NOT skip)
endforeach(entry)
ENDFOREACH(entry)
endif(line MATCHES "^code")
ENDIF(line MATCHES "^code")
endforeach(line)
ENDFOREACH(line)
else()
# message("FOUND NO DEPENDS")
endif()
ELSE(${file_text} MATCHES ".+")
# MESSAGE("FOUND NO DEPENDS")
ENDIF(${file_text} MATCHES ".+")
......@@ -111,6 +111,6 @@ ENDFOREACH(subdir)
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)
###############################################################################
# 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(${FINDCUDA_DIR}/FindCuda.cmake)
# INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK})
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
......
......@@ -4,7 +4,7 @@
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})
# Automatically create tests using files named "Test*.cpp"
......
......@@ -138,6 +138,6 @@ ENDIF(LOG)
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)
# 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)
## ----------------------------------------------------------------------------
# message("CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}")
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
# INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
# message("CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}")
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK})
......
......@@ -4,7 +4,7 @@
SET(OPENMM_BUILD_FREE_ENERGY_PATH ${CMAKE_SOURCE_DIR}/plugins/freeEnergy)
SET(CUDA_NVCC_BUILD_FLAGS "-DCUDPP_STATIC_LIB" )
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
# INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK})
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