-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCMakeLists.txt
419 lines (343 loc) · 16.5 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
cmake_minimum_required(VERSION 3.12)
############################################################################################
#CONDITIONAL FLAG(to run simulation on CPU or GPU)
#
#For GPU : For CPU:
#set(ENABLE_CUDA YES) set(ENABLE_CUDA NO)
#
#You can also pass this flag when running cmake from the command line like this:
#
#cmake..- D ENABLE_CUDA = YES
#
#"YES" / GPU choice only available if CUDA library is installed and the GPU is CUDA capable.
############################################################################################
if(NOT ENABLE_CUDA)
set(ENABLE_CUDA NO)
endif()
#CONDITIONAL FLAG to turn on the performance metrics
if(NOT PERFORMANCE_METRICS)
set(PERFORMANCE_METRICS NO)
endif()
#CONDITIONAL FLAG to turn on the Gprof profiler( \
# Gprof is a performance analysis tool for Unix applications)
#Steps to run Gprof
#Step 01 : set(GPROF YES) below
#Step 02 : Compile and run the simulation on CPU or GPU as usual
#Step 03 : Run the generated gmon.out file from the build directory and save the output in an txt \
# file to improve readability \
#If using CPU - "~/Graphitti/build$ gprof cgraphitti gmon.out > analysis_test.txt"
#If using GPU - "~/Graphitti/build$ gprof ggraphitti gmon.out > analysis_test.txt"
if(NOT GPROF)
set(GPROF NO)
endif()
#Creates the Graphitti project with the correct languages, depending on if using GPU or not
#If using CUDA, also verify the CUDA package and set the required CUDA variables
if(ENABLE_CUDA)
message("\n----Generating Makefile for Graphitti GPU version----")
project(Graphitti LANGUAGES CXX CUDA C)
#Verify CUDA package is present
find_Package(CUDA REQUIRED)
#Set the USE_GPU preprocessor macro so that GPU code will be compiled.
add_compile_definitions(USE_GPU)
#Specify the CUDA architecture / gencode that will be targeted
### Set gencode and architecture variables to the correct values for your specific NVIDIA hardware
set(CMAKE_CUDA_ARCHITECTURES 37)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode=arch=compute_37,code=sm_37)
else()
message("\n----Generating Makefile for Graphitti CPU version----")
project(Graphitti LANGUAGES CXX C)
endif()
#Setting the base version to C++ 11
set(CMAKE_CXX_STANDARD 17)
#set(DEBUG_MODE YES) for debugging, no optimization
#set(DEBUG_MODE NO) for production code, -O3 optimization enabled
set(DEBUG_MODE NO)
if(PERFORMANCE_METRICS)
message("-- Setting PEREFORMANCE_METRICS: ON")
add_definitions(-DPERFORMANCE_METRICS)
endif()
if(GPROF)
message("-- Setting GPROF: ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif()
#HDF5 Support, finds HDF5 package for C and C++ and links the hdf5 libraries to the executable \
# later in the file.
find_package(HDF5 COMPONENTS C CXX)
if (HDF5_FOUND)
message("-- HDF5 version ${HDF5_VERSION} located. HDF5 recorders are available.")
link_directories( ${HDF5_LIBRARY_DIRS} )
include_directories( ${HDF5_INCLUDE_DIRS} )
add_compile_definitions(HDF5)
else()
message("-- HDF5 library was not located. Please only use XML recorders.")
endif()
#Find boost graph library
find_package(Boost REQUIRED COMPONENTS graph)
#Get git commit ID
#Change to "git rev-parse --short HEAD" for short commit ID
execute_process(
COMMAND
git rev-parse HEAD
OUTPUT_VARIABLE GIT_COMMIT_ID )
#GIT_COMMIT_ID has trailing whitespaces
string(REGEX REPLACE "\n$" "" GIT_COMMIT_ID "${GIT_COMMIT_ID}")
#Save GIT_COMMIT_ID to config.h, which is included in Core.cpp
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_BINARY_DIR}/config.h
@ONLY )
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_VERBOSE_MAKEFILE TRUE)
#Setting the location of the executable to be in the top \
# - level directory.This helps when using file paths during
#runtime.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
#Set extra warning flags
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if (NOT DEBUG_MODE)
message("-- Setting Optimization flag: O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
#define TIXML_USE_STL as a preproccersser macro to use the C++ standard library with TinyXML
add_compile_definitions(TIXML_USE_STL)
message("-- Setting Compile Definition: TIMXL_USE_STL")
#Used to define file paths for #include definitions.For example, you can write:
# #include "Simulator.h"
#rather than:
# #include "Simulator/Core/Simulator.h"
#if the file path "Simulator/Core" is in the following statement.
include_directories(
../Graphitti
Simulator
Simulator/Connections
Simulator/Connections/Neuro
Simulator/Connections/NG911
Simulator/Core
Simulator/Core/FunctionNodes
Simulator/Edges
Simulator/Edges/Neuro
Simulator/Edges/NG911
Simulator/Layouts
Simulator/Layouts/Neuro
Simulator/Layouts/NG911
Simulator/Recorders
Simulator/Recorders/Neuro
Simulator/Recorders/NG911
Simulator/Vertices
Simulator/Vertices/Neuro
Simulator/Vertices/NG911
Simulator/Utils
Simulator/Utils/Matrix
Simulator/Utils/RNG
Testing
ThirdParty
ThirdParty/cereal
ThirdParty/TinyXPath
ThirdParty/log4cplus-2.0.7/include)
if(ENABLE_CUDA)
set(cuda_sources Simulator/Edges/Neuro/AllSynapsesDeviceFuncs_d.cpp
Simulator/Vertices/Neuro/AllVerticesDeviceFuncs_d.cpp
Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp
Simulator/Edges/Neuro/AllSTDPSynapses_d.cpp
Simulator/Edges/Neuro/AllDSSynapses_d.cpp
Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp
Simulator/Vertices/Neuro/AllLIFNeurons_d.cpp
Simulator/Vertices/Neuro/AllIZHNeurons_d.cpp
Simulator/Vertices/Neuro/AllIFNeurons_d.cpp
Simulator/Vertices/Neuro/AllSpikingNeurons_d.cpp
Simulator/Connections/Neuro/ConnGrowth_d.cpp )
set_source_files_properties(${cuda_sources} PROPERTIES LANGUAGE CUDA)
endif()
#Collect source files and create libraries
#Libraries containing.cpp files compiled as CUDA.cu files should be created as STATIC to ensure \
#proper linking
#Create Connections library
file(GLOB_RECURSE Connections_Source Simulator/Connections/*.cpp Simulator/Connections/*.h)
if(ENABLE_CUDA)
add_library(Connections STATIC ${Connections_Source} ${cuda_sources})
else()
list(REMOVE_ITEM Connections_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Connections/Neuro/ConnGrowth_d.cpp")
add_library(Connections STATIC ${Connections_Source})
endif()
# Create Vertices library
file(GLOB_RECURSE Vertices_Source Simulator/Vertices/*.cpp Simulator/Vertices/*.h)
if(ENABLE_CUDA)
add_library(Vertices SHARED ${Vertices_Source} ${cuda_sources})
else()
list(REMOVE_ITEM Vertices_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Vertices/Neuro/AllVerticesDeviceFuncs.h")
list(REMOVE_ITEM Vertices_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Vertices/Neuro/AllVerticesDeviceFuncs_d.cpp")
list(REMOVE_ITEM Vertices_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Vertices/Neuro/AllLIFNeurons_d.cpp")
list(REMOVE_ITEM Vertices_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Vertices/Neuro/AllIZHNeurons_d.cpp")
list(REMOVE_ITEM Vertices_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Vertices/Neuro/AllIFNeurons_d.cpp")
list(REMOVE_ITEM Vertices_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Vertices/Neuro/AllSpikingNeurons_d.cpp")
add_library(Vertices STATIC ${Vertices_Source})
endif()
# Create Edges library
file(GLOB_RECURSE Edges_Source Simulator/Edges/*.cpp Simulator/Edges/*.h)
if(ENABLE_CUDA)
add_library(Edges SHARED ${Edges_Source} ${cuda_sources})
else()
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllSynapsesDeviceFuncs.h")
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllSynapsesDeviceFuncs_d.cpp")
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllSynapsesDeviceFuncs_d_Growth.cpp")
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp")
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllSTDPSynapses_d.cpp")
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllDSSynapses_d.cpp")
list(REMOVE_ITEM Edges_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp")
add_library(Edges STATIC ${Edges_Source})
endif()
# The Vertices library has a dependency on the Edges library
target_link_libraries(Vertices Edges)
# Create Layouts Library
file(GLOB_RECURSE Layouts_Source Simulator/Layouts/*.cpp Simulator/Layouts/*.h)
add_library(Layouts ${Layouts_Source})
# Create FunctionNodes library
file(GLOB FunctionNodes_Source Simulator/Core/FunctionNodes/*.cpp Simulator/Core/FunctionNodes/*.h)
add_library(FunctionNodes ${FunctionNodes_Source})
# Create Core library
file(GLOB Core_Source Simulator/Core/*.cpp Simulator/Core/*.h)
# Remove Graphitti_Main from the list of files, don't want 'main' in the library
list(REMOVE_ITEM Core_Source "${CMAKE_CURRENT_SOURCE_DIR}/Graphitti_Main.cpp")
# add_library(Core STATIC ${Core_Source})
if(ENABLE_CUDA)
set(cudaCore_sources Simulator/Core/GPUModel.cpp)
set_source_files_properties(${cudaCore_sources} PROPERTIES LANGUAGE CUDA)
add_library(Core STATIC ${Core_Source} ${cudaCore_sources})
else()
list(REMOVE_ITEM Core_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Core/GPUModel.cpp")
add_library(Core STATIC ${Core_Source})
endif()
# Create Recorders library
file(GLOB_RECURSE Recorders_Source Simulator/Recorders/*.cpp Simulator/Recorders/*.h)
add_library(Recorders ${Recorders_Source})
# Create Matrix library
file(GLOB Matrix_Source Simulator/Utils/Matrix/*.cpp Simulator/Utils/*.h)
# Remove these files from the library as they won't compile
list(REMOVE_ITEM Matrix_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/Matrix/MatrixFactory.h")
list(REMOVE_ITEM Matrix_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/Matrix/MatrixFactory.cpp")
add_library(Matrix ${Matrix_Source})
# Create RNG library
file(GLOB RNG_Source Simulator/Utils/RNG/*.cpp Simulator/Utils/RNG/*.h Simulator/Utils/RNG/*.cu)
# Remove demo from file list as it contains a main and it will cause compilation errors
list(REMOVE_ITEM RNG_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/RNG/MersenneTwister_demo.cu")
add_library(RNG STATIC ${RNG_Source})
# Create Utils library
file(GLOB Utils_Source Simulator/Utils/*.cpp Simulator/Utils/*.h)
list(REMOVE_ITEM Utils_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/Factory.cpp")
add_library(Utils ${Utils_Source})
# Used to locate and run other CMakeLists.txt files from Third Party resources for further compilation of the project.
add_subdirectory(ThirdParty)
# Googletest subdirectories support
add_subdirectory(Testing/lib/googletest-master)
include_directories(Testing/lib/GoogleTest/googletest-master/googletest/include)
# Set CUDA_SEPERABLE_COMPILATION to ON for all libraries that contain .cpp files with device functions compiled as CUDA files
if(ENABLE_CUDA)
set_property(TARGET Edges PROPERTY CUDA_STANDARD 17)
set_property(TARGET Vertices PROPERTY CUDA_STANDARD 17)
# Enables CUDA code in these libraries to be compiled into separate object files and then linked together
set_property(TARGET Edges PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_property(TARGET Vertices PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_property(TARGET Core PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_property(TARGET Connections PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_property(TARGET RNG PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_property(TARGET Utils PROPERTY CUDA_SEPARABLE_COMPILATION ON)
endif()
# Link all libraries created in the project's subdirectories into a combined library.
add_library(combinedLib INTERFACE)
target_link_libraries(combinedLib INTERFACE
# Simulator
Core
Connections
Edges
Layouts
Recorders
Vertices
FunctionNodes
# Utils
Utils
RNG
Matrix
# ThirdParty
TinyXPath
log4cplus
paramcontainer
Boost::graph)
# Link HDF5 package libraries if to the combined library.
if (HDF5_FOUND)
target_link_libraries(combinedLib INTERFACE ${HDF5_LIBRARIES})
endif()
# ------ SIMULATOR EXECUTABLE -------
# Add all files that aren't in a library and are needed to run
if(ENABLE_CUDA)
# Add the ggraphitti GPU executable
add_executable(ggraphitti Simulator/Core/Graphitti_Main.cpp)
# Link the combined library into the 'graphitti' executable.
target_link_libraries(ggraphitti combinedLib)
else()
# Add the cgraphitti CPU executable
add_executable(cgraphitti Simulator/Core/Graphitti_Main.cpp)
# Link the combined library into the 'graphitti' executable.
target_link_libraries(cgraphitti combinedLib)
endif()
# ------ TESTS EXECUTABLE ------
# Add the file that contains main (RunTests.cpp) and all test files. GoogleTest will only recognize them if they are
# included in the executable.
add_executable(tests
Testing/RunTests.cpp
Testing/UnitTesting/OperationManagerTests.cpp
Testing/UnitTesting/EdgeIndexMapTests.cpp
Testing/UnitTesting/FunctionNodeTests.cpp
Testing/UnitTesting/SimulatorTests.cpp
Testing/UnitTesting/OperationManagerTestingClass.h
Testing/UnitTesting/VerticesFactoryTests.cpp
Testing/UnitTesting/ConnectionsFactoryTests.cpp
Testing/UnitTesting/EdgesFactoryTests.cpp
Testing/UnitTesting/LayoutFactoryTests.cpp
Testing/UnitTesting/RecorderFactoryTests.cpp
Testing/UnitTesting/InputManagerTests.cpp
Testing/UnitTesting/RNGFactoryTests.cpp
Testing/UnitTesting/GraphManagerTests.cpp
Testing/Utils/ParameterManagerTests.cpp
Testing/Utils/CircularBufferTests.cpp
Testing/UnitTesting/EventBufferTests.cpp
Testing/UnitTesting/XmlRecorderTests.cpp
Testing/UnitTesting/Hdf5RecorderTests.cpp)
# Links the Googletest framework with the testing executable
target_link_libraries(tests gtest gtest_main)
# Link the combined library into the 'tests' executable.
target_link_libraries(tests combinedLib)
# add_executable(serialTest
# Testing/RunTests.cpp
# Testing/UnitTesting/SerializationTests.cpp)
# # Links the Googletest framework with the serialTest executable
# target_link_libraries(serialTest gtest gtest_main)
# # Link the combined library into the 'serialTest' executable.
# target_link_libraries(serialTest combinedLib)
# add_executable(deserialTest
# Testing/RunTests.cpp
# Testing/UnitTesting/DeserializationTests.cpp)
# # Links the Googletest framework with the deserialTest executable
# target_link_libraries(deserialTest gtest gtest_main)
# # Link the combined library into the 'deserialTest' executable.
# target_link_libraries(deserialTest combinedLib)
# add_executable(serialFileAccessTest
# Testing/RunTests.cpp
# Testing/UnitTesting/SerializationFileAccessTest.cpp)
# # Links the Googletest framework with the serialFileAccessTest executable
# target_link_libraries(serialFileAccessTest gtest gtest_main)
# # Link the combined library into the 'serialFileAccessTest' executable.
# target_link_libraries(serialFileAccessTest combinedLib)
add_executable(serialFileAccessTest
Testing/RunTests.cpp
Testing/UnitTesting/SerializationFileAccessTest.cpp)
# Links the Googletest framework with the serialFileAccessTest executable
target_link_libraries(serialFileAccessTest gtest gtest_main)
# Link the combined library into the 'serialFileAccessTest' executable.
target_link_libraries(serialFileAccessTest combinedLib)
# Clear ENABLE_CUDA, PERFORMANCE_METRICS and GPROF from the cache so it's reset for subsequent builds
unset(ENABLE_CUDA CACHE)
unset(PERFORMANCE_METRICS CACHE)
unset(GPROF CACHE)