-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
131 lines (111 loc) · 4.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# CMake
cmake_minimum_required (VERSION 2.6)
set_property( GLOBAL PROPERTY USE_FOLDERS ON )
project(gpu_optimize_storm_drift)
if( NOT CMAKE_CXX_STANDARD )
set( CMAKE_CXX_STANDARD 14 )
endif()
if( MSVC ) # link runtime statically with MSVC
foreach( type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} )
string( TOUPPER ${type} TYPE )
foreach( flags CMAKE_C_FLAGS_${TYPE} CMAKE_CXX_FLAGS_${TYPE} )
get_property( help CACHE ${flags} PROPERTY HELPSTRING )
string( REPLACE "/MD" "/MT" ${flags} "${${flags}}" )
set( ${flags} "${${flags}}" CACHE STRING "${help}" FORCE )
endforeach()
endforeach()
endif()
function( add_launcher target executable arguments working_directory )
if( MSVC12 OR MSVC14 )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${target}.vcxproj.user
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<Project ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
" <PropertyGroup>\n"
" <LocalDebuggerCommand>${executable}</LocalDebuggerCommand>\n"
" <LocalDebuggerCommandArguments>${arguments}</LocalDebuggerCommandArguments>\n"
" <LocalDebuggerWorkingDirectory>${working_directory}</LocalDebuggerWorkingDirectory>\n"
" </PropertyGroup>\n"
"</Project>\n"
)
endif()
endfunction()
find_package( CUDA 8.0 REQUIRED )
set( DEFAULT_CUDA_ARCH All )
set( CUDA_ARCHITECTURES ${DEFAULT_CUDA_ARCH} CACHE STRING
"Auto | Common | All | ... see CUDA_SELECT_NVCC_ARCH_FLAGS(...)" )
if( CUDA_ARCHITECTURES STREQUAL Auto )
set( file ${PROJECT_BINARY_DIR}/detect_cuda_architectures.cpp )
file( WRITE ${file} ""
"#include <cuda_runtime.h>\n"
"#include <cstdio>\n"
"int main()\n"
"{\n"
" int count = 0;\n"
" if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;\n"
" if (count == 0) return -1;\n"
" for (int device = 0; device < count; ++device)\n"
" {\n"
" cudaDeviceProp prop;\n"
" if (cudaSuccess == cudaGetDeviceProperties(&prop, device))\n"
" std::printf(\"%d.%d \", prop.major, prop.minor);\n"
" }\n"
" return 0;\n"
"}\n"
)
try_run( run_result compile_result ${PROJECT_BINARY_DIR} ${file}
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}"
LINK_LIBRARIES ${CUDA_LIBRARIES}
RUN_OUTPUT_VARIABLE architectures
)
if( run_result EQUAL 0 )
string( REPLACE "2.1" "2.1(2.0)" architectures "${architectures}" )
if( CUDA_VERSION VERSION_LESS "7.0" )
string( REGEX REPLACE "3\\.[27]|5\\.[23]|6\\.[01]" "5.2+PTX" architectures "${architectures}" )
elseif( CUDA_VERSION VERSION_LESS "8.0" )
string( REGEX REPLACE "5\\.3|6\\.[01]" "5.3+PTX" architectures "${architectures}" )
endif()
set( CUDA_ARCHITECTURES "${architectures}" )
endif()
elseif( CUDA_ARCHITECTURES STREQUAL All )
# All does not include the latest PTX!
set( CUDA_ARCHITECTURES "3.0" "3.5" "5.0" "5.2" )
if( CUDA_VERSION VERSION_LESS "9.0" )
list( INSERT CUDA_ARCHITECTURES 0 "2.1(2.0)" )
endif()
if( CUDA_VERSION VERSION_GREATER "6.5" )
list( APPEND CUDA_ARCHITECTURES "3.2" "3.7" "5.3" )
endif()
if( CUDA_VERSION VERSION_GREATER "7.5" )
list( APPEND CUDA_ARCHITECTURES "6.0" "6.1" )
endif()
if( CUDA_VERSION VERSION_GREATER "8.0" )
list( APPEND CUDA_ARCHITECTURES "6.2" "7.0" )
endif()
string( APPEND CUDA_ARCHITECTURES "+PTX" )
endif()
message( STATUS "CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES}" )
CUDA_SELECT_NVCC_ARCH_FLAGS( code_generation_flags "${CUDA_ARCHITECTURES}" )
list( APPEND CUDA_NVCC_FLAGS ${code_generation_flags} )
message( STATUS "CUDA_NVCC_FLAGS=${code_generation_flags}" )
set( Headers
gpu_optimize_storm_drift.h
)
set( Sources
gpu_optimize_storm_drift.cpp
gpu_optimize_storm_drift.def
)
set( CudaSources
gpu_optimize_storm_drift.cu
)
source_group("CUDA Source Files" FILES ${CudaSources})
cuda_add_library(gpu_optimize_storm_drift SHARED
${Headers}
${Sources}
${CudaSources}
)
add_subdirectory(examples)
target_link_libraries(gpu_optimize_storm_drift
${CUDA_LIBRARIES}
${CUDA_NVTX_LIBRARY}
)
target_include_directories(gpu_optimize_storm_drift PUBLIC ${CUDA_NVTX_INCLUDE})