-
Notifications
You must be signed in to change notification settings - Fork 60
/
CMakeLists.txt
286 lines (252 loc) · 7.73 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#
# WebGPU Machine Problems 2015
#
# mp0 - Device Query
# mp1 - Vector Addition
# mp2 - Basic Matrix-Matrix Multiplication
# mp3 - Tiled Matrix-Matrix Multiplication
# mp6 - Image Convolution
# mp4 - List Reduction
# mp5 - List Scan
# mp7 - Vector Addition (OpenCL)
# mp11 - Histograms
# mp12 - Vector Addition with Streams
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(libwb)
#
# Settings common to CUDA / OpenCL
#
# Include project header
include_directories(${PROJECT_SOURCE_DIR}/include)
# Set warning levels for host compilation; VS defaults to /W3
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif ()
if (CMAKE_GENERATOR MATCHES "Xcode")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS $(ARCHS_STANDARD))
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS x86_64)
endif ()
#
# Settings for NVidia CUDA-based MPs
#
find_package(CUDA)
if (CUDA_FOUND)
# For some MPs it may be necessary to specify the compute capability of your
# NVidia GPU. In that case, simply uncomment the following two lines that start
# with 'set' and change the value of COMPUTE_CAPABILITY to one of the following
# hardware architectures: Tesla-class '11', '12', or '13'; Fermi-class '20'
# or '21'; Kepler-class '30', '32', '35' or '37'; or Maxwell-class '50' or '52'
set(COMPUTE_CAPABILITY 11)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--gpu-architecture;sm_${COMPUTE_CAPABILITY})
# Select the correct host compiler on OS X
if (APPLE)
if (${CMAKE_SYSTEM_VERSION} VERSION_GREATER 11.0)
# OS X 10.8+
find_program(libwb_CXX_COMPILER NAMES clang PATHS ENV PATH)
if (NOT libwb_CXX_COMPILER)
message(FATAL_ERROR "Could not find host compiler 'clang'")
endif ()
set(CUDA_HOST_COMPILER ${libwb_CXX_COMPILER} CACHE FILEPATH "Host side compiler used by NVCC")
if (CUDA_VERSION VERSION_LESS 7.0)
# CUDA Toolkits 5.5-6.5 are incompatible with LLVM's C++ standard library
set(libwb_STANDARD_LIBRARY -stdlib=libstdc++)
if (CMAKE_GENERATOR MATCHES "Xcode")
set(libwb_XCODE_ATTRIBUTES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY libstdc++)
endif ()
endif ()
endif ()
# Suppress warnings related to the CUDA headers
set(libwb_NVCC_OPTIONS --compiler-options -isystem,${CUDA_INCLUDE_DIRS})
endif ()
# Set additional linker options on UNIX platforms
if (UNIX)
set(libwb_LINK_LIBRARIES -lm)
if (NOT APPLE)
include(CheckLibraryExists)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if (HAVE_CLOCK_GETTIME)
list(APPEND libwb_LINK_LIBRARIES -lrt)
endif ()
endif ()
endif ()
set(EXECUTABLES mp0 mp1 mp2 mp3 mp6 mp4 mp5 mp11 mp12)
foreach (TARGET ${EXECUTABLES})
CUDA_ADD_EXECUTABLE(
${TARGET}
${PROJECT_SOURCE_DIR}/src/${TARGET}.cu
OPTIONS ${libwb_NVCC_OPTIONS}
)
if (DEFINED libwb_STANDARD_LIBRARY)
set_target_properties(
${TARGET}
PROPERTIES
COMPILE_FLAGS ${libwb_STANDARD_LIBRARY}
LINK_FLAGS ${libwb_STANDARD_LIBRARY}
)
endif ()
if (DEFINED libwb_XCODE_ATTRIBUTES)
set_target_properties(
${TARGET}
PROPERTIES ${libwb_XCODE_ATTRIBUTES}
)
endif ()
if (UNIX)
target_link_libraries(
${TARGET}
${libwb_LINK_LIBRARIES}
)
endif ()
endforeach ()
endif ()
#
# Implement a minimal FindOpenCL.cmake
#
find_path(
OpenCL_INCLUDE_DIR
NAMES
OpenCL/cl.h CL/cl.h
PATHS
ENV OPENCL_ROOT
ENV AMDAPPSDKROOT
ENV INTELOCLSDKROOT
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
PATH_SUFFIXES
include
OpenCL/common/inc
)
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
find_library(
OpenCL_LIBRARY
NAMES
OpenCL
PATHS
ENV OPENCL_ROOT
ENV AMDAPPSDKROOT
ENV INTELOCLSDKROOT
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
PATH_SUFFIXES
lib/x86
lib/Win32
)
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(
OpenCL_LIBRARY
NAMES
OpenCL
PATHS
ENV OPENCL_ROOT
ENV AMDAPPSDKROOT
ENV INTELOCLSDKROOT
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
PATH_SUFFIXES
lib/x86_64
lib/x64
)
endif ()
set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
OpenCL
DEFAULT_MSG
OpenCL_LIBRARY
OpenCL_INCLUDE_DIR
)
mark_as_advanced(
OpenCL_INCLUDE_DIR
OpenCL_LIBRARY
)
#
# Settings for OpenCL MPs
#
if (OPENCL_FOUND)
set(libwb_LINK_LIBRARIES ${OpenCL_LIBRARIES})
# Set additional linker options on UNIX platforms
if (UNIX)
list(APPEND libwb_LINK_LIBRARIES -lm)
if (NOT APPLE)
include(CheckLibraryExists)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if (HAVE_CLOCK_GETTIME)
list(APPEND libwb_LINK_LIBRARIES -lrt)
endif ()
endif ()
endif ()
set(TARGET mp7)
add_executable(
${TARGET}
${PROJECT_SOURCE_DIR}/src/${TARGET}.cc
)
target_link_libraries(
${TARGET}
${libwb_LINK_LIBRARIES}
)
if (NOT APPLE)
if (CMAKE_VERSION VERSION_GREATER 2.8.10)
target_include_directories(
${TARGET}
BEFORE
PRIVATE ${OpenCL_INCLUDE_DIRS}
)
else ()
include_directories(BEFORE ${OpenCL_INCLUDE_DIRS})
endif ()
endif ()
endif ()
#
# CTEST TESTING
#
# To test all MPs against the official datasets type 'ctest -V' at the
# terminal; to test a specific MP type 'ctest -L mpX -V'
enable_testing()
if (CUDA_FOUND)
add_test(
NAME mp0
COMMAND mp0
)
set_tests_properties(
mp0
PROPERTIES FAIL_REGULAR_EXPRESSION "No CUDA GPU has been detected"
LABELS mp0
)
# CUDA-based MPs
set(TESTS mp1 mp2 mp3 mp6 mp4 mp5 mp11 mp12)
endif ()
set(DATASETS 9)
# OpenCL-based MPs
if (OPENCL_FOUND)
set(TESTS ${TESTS} mp7)
endif ()
if (CUDA_FOUND OR OPENCL_FOUND)
foreach (TEST ${TESTS})
set(PATH tests/${TEST})
foreach (i RANGE 0 ${DATASETS})
if ("mp1 mp2 mp3 mp12 mp7" MATCHES ${TEST})
set(TEST_FILES ${PATH}/${i}/input0.raw ${PATH}/${i}/input1.raw ${PATH}/${i}/output.raw)
elseif (mp4 STREQUAL ${TEST})
set(TEST_FILES ${PATH}/${i}/input0.raw ${PATH}/${i}/output.raw)
elseif (mp5 STREQUAL ${TEST})
set(TEST_FILES ${PATH}/${i}/input.raw ${PATH}/${i}/output.raw)
elseif (mp6 STREQUAL ${TEST})
set(TEST_FILES ${PATH}/${i}/input0.ppm ${PATH}/${i}/input1.csv ${PATH}/${i}/output.ppm)
elseif (mp11 STREQUAL ${TEST})
set(TEST_FILES ${PATH}/${i}/input.ppm ${PATH}/${i}/output.ppm)
else ()
message(FATAL_ERROR "Unknown test target '${TEST}'")
endif ()
set(TEST_LABEL ${TEST}-${i})
add_test(
NAME ${TEST_LABEL}
COMMAND ${TEST} ${TEST_FILES}
)
set_tests_properties(
${TEST_LABEL}
PROPERTIES PASS_REGULAR_EXPRESSION "Solution is correct"
LABELS ${TEST_LABEL}
)
endforeach ()
endforeach ()
endif ()