-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
193 lines (156 loc) · 5.72 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# require cmake 2.8.0 for findCUDA.cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
##################
project("accfft")
# The version number.
set (accfft_VERSION_MAJOR 0)
set (accfft_VERSION_MINOR 0)
##################
# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ")
endif()
# Set default install path t o build
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "default install path" FORCE )
endif()
# allow cmake to use custom modules (e.g. FindFFTW)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(FFTW REQUIRED)
find_package(MPI REQUIRED)
find_package(OpenMP REQUIRED)
# Make the include path visible to all targets
INCLUDE_DIRECTORIES (
${accfft_SOURCE_DIR}/include
${accfft_BINARY_DIR}/include
)
# Add OpenMP and FFTW cxx flags to all targets
# FOR PGI COMPILER
#set(OpenMP_C_FLAGS "-lpthread")
#set(OpenMP_CXX_FLAGS "-lpthread")
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 ${OpenMP_C_FLAGS} -I${FFTW_INCLUDES}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 ${OpenMP_CXX_FLAGS} -I${FFTW_INCLUDES}" )
# some default behavior
if(BUILD_SHARED)
set(BUILD_SHARED_LIBS ON)
else()
set(BUILD_SHARED_LIBS OFF)
endif(BUILD_SHARED)
# ###########
# HOST BUILD
# ###########
include(FindMPI)
# set cmake compiler to mpi compiler wrapper found by FindMPI (usually mpicxx)
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
#include_directories(SYSTEM ${MPI_INCLUDE_PATH})
# libaccfft source files list
set(libaccfft_SRCS
src/transpose.cpp
src/accfft.cpp
src/accfftf.cpp
src/accfft_common.cpp
)
# build CPU libaccfft (shared or static ?)
if(BUILD_SHARED_LIBS)
add_library(accfft SHARED ${libaccfft_SRCS})
else(BUILD_SHARED_LIBS)
add_library(accfft STATIC ${libaccfft_SRCS})
endif(BUILD_SHARED_LIBS)
target_link_libraries(accfft ${FFTW_LIB} ${FFTWF_LIB})
# install
install(TARGETS accfft DESTINATION lib)
#install(DIRECTORY accfft DESTINATION include FILES_MATCHING PATTERN "include/*.h include/*.txx")
install (DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.txx")
install (DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.h"
PATTERN "**~" EXCLUDE
PATTERN "*_gpu*" EXCLUDE
PATTERN "*_cuda*" EXCLUDE
)
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
# CPU UTILS BUILD #
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
find_package(PNETCDF QUIET)
if (PNETCDF_FOUND)
set (libaccfft_utils_SRCS ${libaccfft_SRCS}
src/operators.cpp
src/operatorsf.cpp
)
include_directories(${PNETCDF_INCLUDE_DIRS})
add_definitions(-DUSE_PNETCDF)
else()
set (libaccfft_utils_SRCS ${libaccfft_SRCS}
src/operators.cpp
src/operatorsf.cpp
)
endif()
# build CPU libaccfft (shared or static ?)
if(BUILD_SHARED_LIBS)
add_library(accfft_utils SHARED ${libaccfft_utils_SRCS})
else(BUILD_SHARED_LIBS)
add_library(accfft_utils STATIC ${libaccfft_utils_SRCS})
endif(BUILD_SHARED_LIBS)
target_link_libraries(accfft_utils accfft)
install(TARGETS accfft_utils DESTINATION lib)
# ##########
# GPU BUILD
# ##########
if(BUILD_GPU)
find_package(CUDA REQUIRED)
if(NOT CUDA_NVCC_FLAGS)
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_60,code=sm_60)
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_70,code=sm_70)
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_75,code=sm_75)
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_35,code=sm_35)
endif()
list(APPEND CUDA_NVCC_FLAGS --compiler-options -fno-strict-aliasing -lineinfo)
# libaccfft_gpu source files list
set(libaccfft_gpu_SRCS
src/transpose_gpu.cpp
src/transpose_cuda.cu
src/accfft_gpu.cpp
src/accfft_gpuf.cpp
src/accfft_common.cpp
)
# GPU libaccfft_gpu
if(BUILD_SHARED_LIBS)
cuda_add_library(accfft_gpu SHARED ${libaccfft_gpu_SRCS} OPTIONS "-DENABLE_GPU")
else(BUILD_SHARED_LIBS)
cuda_add_library(accfft_gpu STATIC ${libaccfft_gpu_SRCS} OPTIONS "-DENABLE_GPU")
endif(BUILD_SHARED_LIBS)
# the following is necessary so that .cpp sources files passed to
# cuda_add_library get the right compile flags
set_target_properties(accfft_gpu PROPERTIES COMPILE_FLAGS "-DENABLE_GPU")
# install
install(TARGETS accfft_gpu DESTINATION lib)
install (DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN
"*gpu*")
install (DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN
"*cuda*")
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
# GPU UTILS BUILD #
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
set (libaccfft_utils_gpu_SRCS ${libaccfft_gpu_SRCS}
src/operators_gpu.cpp
src/operators_gpuf.cpp
src/operators_cuda.cu
)
# build CPU libaccfft (shared or static ?)
if(BUILD_SHARED_LIBS)
cuda_add_library(accfft_utils_gpu SHARED ${libaccfft_utils_gpu_SRCS} OPTIONS "-DENABLE_GPU")
else(BUILD_SHARED_LIBS)
cuda_add_library(accfft_utils_gpu STATIC ${libaccfft_utils_gpu_SRCS} OPTIONS "-DENABLE_GPU")
endif(BUILD_SHARED_LIBS)
# the following is necessary so that .cpp sources files passed to
# cuda_add_library get the right compile flags
set_target_properties(accfft_utils_gpu PROPERTIES COMPILE_FLAGS "-DENABLE_GPU")
install(TARGETS accfft_utils_gpu DESTINATION lib)
endif(BUILD_GPU)
####################
# EXAMPLES / TESTS #
####################
add_subdirectory(steps/step1 )
add_subdirectory(steps/step2 EXCLUDE_FROM_ALL)
add_subdirectory(steps/step3 EXCLUDE_FROM_ALL )
add_subdirectory(steps/step4 EXCLUDE_FROM_ALL )
add_subdirectory(steps/step5 EXCLUDE_FROM_ALL )