Skip to content

Commit 758bb6d

Browse files
authored
Merge branch 'SharedDevelopment' into LawrenceDevelopment
2 parents f04a112 + 62108e5 commit 758bb6d

File tree

159 files changed

+3466
-3664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+3466
-3664
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
run: ./cgraphitti -c ../Testing/RegressionTesting/configfiles/test-small-911.xml
7777
- name: verify test-small-911
7878
if: always() && steps.tt.conclusion == 'success'
79-
run: diff ../Testing/RegressionTesting/TestOutput/test-small-911-out.xml ../Testing/RegressionTesting/GoodOutput/test-small-911-out.xml
79+
run: diff ../Testing/RegressionTesting/TestOutput/test-small-911-out.xml ../Testing/RegressionTesting/GoodOutput/Cpu/test-small-911-out.xml
8080

8181
- id: tm
8282
name: run test-medium

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ Testing/RegressionTesting/TestOutput/*.xml
9797
Testing/RegressionTesting/TestOutput/*.h5
9898
Testing/UnitTesting/TestOutput/*.xml
9999
Testing/UnitTesting/TestOutput/*.h5
100+
101+
# Machine Specific build script
102+
build.sh

CMakeLists.txt

Lines changed: 152 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ cmake_minimum_required(VERSION 3.12)
88
#
99
#You can also pass this flag when running cmake from the command line like this:
1010
#
11-
#cmake..- D ENABLE_CUDA = YES
11+
#cmake -D ENABLE_CUDA=YES ..
1212
#
1313
#"YES" / GPU choice only available if CUDA library is installed and the GPU is CUDA capable.
1414
############################################################################################
15-
1615
if(NOT ENABLE_CUDA)
1716
set(ENABLE_CUDA NO)
1817
endif()
@@ -22,17 +21,24 @@ if(NOT PERFORMANCE_METRICS)
2221
set(PERFORMANCE_METRICS NO)
2322
endif()
2423

25-
#CONDITIONAL FLAG to turn on the Gprof profiler( \
26-
# Gprof is a performance analysis tool for Unix applications)
27-
#Steps to run Gprof
28-
#Step 01 : set(GPROF YES) below
29-
#Step 02 : Compile and run the simulation on CPU or GPU as usual
30-
#Step 03 : Run the generated gmon.out file from the build directory and save the output in an txt \
31-
# file to improve readability \
32-
#If using CPU - "~/Graphitti/build$ gprof cgraphitti gmon.out > analysis_test.txt"
33-
#If using GPU - "~/Graphitti/build$ gprof ggraphitti gmon.out > analysis_test.txt"
34-
if(NOT GPROF)
35-
set(GPROF NO)
24+
############################################################################################
25+
#CONDITIONAL FLAG to change target architecture for the GPU simulator from the default
26+
#
27+
#You can pass this flag when running cmake from the command line like this, setting TARGET_ARCH \
28+
# to your desired architecture: \
29+
#
30+
#cmake -D ENABLE_CUDA=YES -D TARGET_ARCH=70 ..
31+
#
32+
#"YES" / GPU choice only available if CUDA library is installed and the GPU is CUDA capable.
33+
#If no TARGET_ARCH is passed in then it will default to 37 which is the kepler architecture
34+
############################################################################################
35+
if(NOT DEFINED TARGET_ARCH)
36+
set(TARGET_ARCH 37)
37+
endif()
38+
39+
#CONDITIONAL FLAG to turn on the validation mode
40+
if(NOT VALIDATION_MODE)
41+
set(VALIDATION_MODE NO)
3642
endif()
3743

3844
#Creates the Graphitti project with the correct languages, depending on if using GPU or not
@@ -46,31 +52,112 @@ if(ENABLE_CUDA)
4652
add_compile_definitions(USE_GPU)
4753
#Specify the CUDA architecture / gencode that will be targeted
4854
### Set gencode and architecture variables to the correct values for your specific NVIDIA hardware
49-
set(CMAKE_CUDA_ARCHITECTURES 37)
50-
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode=arch=compute_37,code=sm_37)
55+
set(CMAKE_CUDA_ARCHITECTURES ${TARGET_ARCH})
56+
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode=arch=compute_${TARGET_ARCH},code=sm_${TARGET_ARCH})
57+
message(STATUS "Using CUDA architecture: ${TARGET_ARCH}")
5158

5259
else()
5360
message("\n----Generating Makefile for Graphitti CPU version----")
5461
project(Graphitti LANGUAGES CXX C)
5562
endif()
5663

64+
# -----------------------------------------------------------------------------
65+
# Build Type Configuration
66+
#
67+
# CMake support for different build types controling optimization, debugging and profiling:
68+
#
69+
# - Debug : No optimizations (`-O0`), includes debug symbols (`-g`).
70+
# - Release : Optimized build (`-O3`), removes debug symbols.
71+
# - RelWithDebInfo: Optimized (`-O2`) but keeps debug symbols (`-g`) for profiling.
72+
# - Profiling : Custom build type (defined in this project) that enables:
73+
# - CPU profiling via `-pg` (GPROF)
74+
# - CUDA profiling via `-lineinfo` (for Nsight Compute)
75+
#
76+
# Selecting a Build Type:
77+
# - By default, CMake does NOT set a build type for single-config generators.
78+
# - If no build type is specified, this script defaults to "Release" for performance.
79+
# - You can explicitly set the build type when configuring CMake:
80+
#
81+
# cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug # Debug mode
82+
# cmake -S . -B build -DCMAKE_BUILD_TYPE=Release # Release mode
83+
# cmake -S . -B build -DCMAKE_BUILD_TYPE=Profiling # Profiling mode
84+
#
85+
# If you don't want to pass in the build type flag, you can edit this file and add...
86+
# set(CMAKE_BUILD_TYPE "Debug") or whichever build type you want
87+
# -----------------------------------------------------------------------------
88+
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;Profiling" CACHE STRING "Supported build types" FORCE)
89+
90+
# Ensure single-config generators use a valid default
91+
if(NOT CMAKE_BUILD_TYPE)
92+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the build type." FORCE)
93+
endif()
94+
95+
# Set flags for all build types
96+
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
97+
# We should consider using the -DNDEBUG flag for release code, it disables assert() calls and is higher performance
98+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
99+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
100+
101+
# Define a custom build type: "Profiling"
102+
set(CMAKE_CXX_FLAGS_PROFILING "-pg -O2")
103+
set(CMAKE_EXE_LINKER_FLAGS_PROFILING "-pg")
104+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
105+
106+
# Apply the correct flags based on the selected build type
107+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
108+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
109+
if(ENABLE_CUDA)
110+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -g -G")
111+
endif()
112+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
113+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}")
114+
if(ENABLE_CUDA)
115+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -O3")
116+
endif()
117+
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
118+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
119+
elseif(CMAKE_BUILD_TYPE STREQUAL "Profiling")
120+
message(STATUS "Profiling build enabled: Adding -pg (GPROF)")
121+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_PROFILING}")
122+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_PROFILING}")
123+
if(ENABLE_CUDA)
124+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo")
125+
# set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo -Xptxas=-v")
126+
endif()
127+
endif()
128+
129+
130+
# Gprof is a performance analysis tool for Unix applications)
131+
#Steps to run Gprof
132+
#Step 01 : set build configuration to Profiling ... -DCMAKE_BUILD_TYPE=Profiling
133+
#Step 02 : Compile and run the simulation on CPU or GPU as usual
134+
#Step 03 : Run the generated gmon.out file from the build directory and save the output in an txt \
135+
# file to improve readability \
136+
#If using CPU - "~/Graphitti/build$ gprof cgraphitti gmon.out > analysis_test.txt"
137+
#If using GPU - "~/Graphitti/build$ gprof ggraphitti gmon.out > analysis_test.txt"
138+
139+
140+
# Print build type for verification
141+
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
142+
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
143+
144+
message(STATUS "ENABLE_CUDA: ${ENABLE_CUDA}")
145+
if(ENABLE_CUDA)
146+
message(STATUS "CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")
147+
endif()
148+
149+
57150
#Setting the base version to C++ 17
58151
set(CMAKE_CXX_STANDARD 17)
59152

60-
#set(DEBUG_MODE YES) for debugging, no optimization
61-
#set(DEBUG_MODE NO) for production code, -O3 optimization enabled
62-
set(DEBUG_MODE NO)
63-
64153
if(PERFORMANCE_METRICS)
65154
message("-- Setting PEREFORMANCE_METRICS: ON")
66155
add_definitions(-DPERFORMANCE_METRICS)
67156
endif()
68157

69-
if(GPROF)
70-
message("-- Setting GPROF: ON")
71-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
72-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
73-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
158+
if(VALIDATION_MODE)
159+
message("-- Setting VALIDATION_MODE: ON")
160+
add_definitions(-DVALIDATION_MODE)
74161
endif()
75162

76163
#HDF5 Support, finds HDF5 package for C and C++ and links the hdf5 libraries to the executable \
@@ -117,11 +204,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
117204
#Set extra warning flags
118205
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
119206

120-
if (NOT DEBUG_MODE)
121-
message("-- Setting Optimization flag: O3")
122-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
123-
endif()
124-
125207
#define TIXML_USE_STL as a preproccersser macro to use the C++ standard library with TinyXML
126208
add_compile_definitions(TIXML_USE_STL)
127209
message("-- Setting Compile Definition: TIMXL_USE_STL")
@@ -283,9 +365,33 @@ add_library(RNG STATIC ${RNG_Source})
283365

284366

285367
# Create Utils library
286-
file(GLOB Utils_Source Simulator/Utils/*.cpp Simulator/Utils/*.h)
368+
file(GLOB Utils_Source Simulator/Utils/*.cpp Simulator/Utils/*.h)
287369
list(REMOVE_ITEM Utils_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/Factory.cpp")
288-
add_library(Utils ${Utils_Source})
370+
371+
if(CMAKE_BUILD_TYPE STREQUAL "Profiling")
372+
if(ENABLE_CUDA)
373+
# Find NVTX Library
374+
find_library(NVTX_LIBRARY nvToolsExt)
375+
if(NVTX_LIBRARY)
376+
message(STATUS "Found NVTX: ${NVTX_LIBRARY} included in Profiling")
377+
add_compile_definitions(ENABLE_NVTX)
378+
else()
379+
message(STATUS "NVTX library not found! Not included in Profiling.")
380+
list(REMOVE_ITEM Utils_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/NvtxHelper.cpp")
381+
endif()
382+
endif()
383+
384+
else()
385+
list(REMOVE_ITEM Utils_Source "${CMAKE_CURRENT_SOURCE_DIR}/Simulator/Utils/NvtxHelper.cpp")
386+
endif()
387+
388+
# Always create the Utils library (even if NVTX and CUDA are missing)
389+
add_library(Utils ${Utils_Source})
390+
391+
# Only link NVTX if it was found
392+
if(NVTX_LIBRARY)
393+
target_link_libraries(Utils PRIVATE ${NVTX_LIBRARY})
394+
endif()
289395

290396

291397
# Used to locate and run other CMakeLists.txt files from Third Party resources for further compilation of the project.
@@ -353,6 +459,15 @@ endif()
353459
# ------ TESTS EXECUTABLE ------
354460
# Add the file that contains main (RunTests.cpp) and all test files. GoogleTest will only recognize them if they are
355461
# included in the executable.
462+
target_compile_options(gtest PRIVATE -Wno-error=maybe-uninitialized)
463+
target_compile_options(gtest_main PRIVATE -Wno-error=maybe-uninitialized)
464+
465+
if(ENABLE_CUDA)
466+
set(cuda_TestSources
467+
Testing/UnitTesting/DeviceVectorTests.cpp)
468+
set_source_files_properties(${cuda_TestSources} PROPERTIES LANGUAGE CUDA)
469+
endif()
470+
356471
add_executable(tests
357472
Testing/RunTests.cpp
358473
Testing/UnitTesting/OperationManagerTests.cpp
@@ -372,7 +487,8 @@ add_executable(tests
372487
Testing/Utils/CircularBufferTests.cpp
373488
Testing/UnitTesting/EventBufferTests.cpp
374489
Testing/UnitTesting/XmlRecorderTests.cpp
375-
Testing/UnitTesting/Hdf5RecorderTests.cpp)
490+
Testing/UnitTesting/Hdf5RecorderTests.cpp
491+
Testing/UnitTesting/DeviceVectorTests.cpp)
376492

377493
# Links the Googletest framework with the testing executable
378494
target_link_libraries(tests gtest gtest_main)
@@ -427,3 +543,7 @@ target_link_libraries(serialSecondHalfTest combinedLib)
427543
unset(ENABLE_CUDA CACHE)
428544
unset(PERFORMANCE_METRICS CACHE)
429545
unset(GPROF CACHE)
546+
unset(CMAKE_BUILD_TYPE CACHE)
547+
unset(NVTX_LIBRARY CACHE)
548+
unset(TARGET_ARCH CACHE)
549+
unset(VALIDATION_MODE CACHE)

Contributors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ ChengHao Hsu
7878

7979
Zaina Shaikh
8080

81+
Rimjhim Sudhesh
82+
8183
## 2025
8284
Andrew Madison
8385

86+
Padmanabh Patil
87+
8488
<!-- ---------------------------------------------------------------------------------- -->
8589
# Graduate
8690

Simulator/Connections/Connections.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Connections::Connections()
3838

3939
// Register loadParameters function with Operation Manager
4040
function<void()> loadParamsFunc = bind(&Connections::loadParameters, this);
41-
opsManager.registerOperation(Operations::op::loadParameters, loadParamsFunc);
41+
opsManager.registerOperation(Operations::loadParameters, loadParamsFunc);
4242

4343
// Register registerGraphProperties as Operations registerGraphProperties
4444
function<void()> regGraphPropsFunc = bind(&Connections::registerGraphProperties, this);
@@ -89,17 +89,16 @@ bool Connections::updateConnections(AllVertices &vertices)
8989
}
9090

9191
#if defined(USE_GPU)
92-
void Connections::updateSynapsesWeights(int numVertices, AllVertices &vertices, AllEdges &synapses,
93-
AllSpikingNeuronsDeviceProperties *allVerticesDevice,
94-
AllSpikingSynapsesDeviceProperties *allEdgesDevice,
95-
Layout &layout)
92+
void Connections::updateEdgesWeights(int numVertices, AllVertices &vertices, AllEdges &edges,
93+
AllVerticesDeviceProperties *allVerticesDevice,
94+
AllEdgesDeviceProperties *allEdgesDevice, Layout &layout)
9695
{
9796
}
9897
#else
9998

100-
/// Update the weight of the Synapses in the simulation.
99+
/// Update the weight of the edges in the simulation.
101100
/// Note: Platform Dependent.
102-
void Connections::updateSynapsesWeights()
101+
void Connections::updateEdgesWeights()
103102
{
104103
}
105104
#endif // !USE_GPU

Simulator/Connections/Connections.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#pragma once
2525

2626
#include "AllEdges.h"
27-
#include "AllSpikingNeurons.h"
28-
#include "AllSpikingSynapses.h"
2927
#include "AllVertices.h"
3028
#include "EdgeIndexMap.h"
3129
#include "Layout.h"
@@ -69,7 +67,7 @@ class Connections {
6967

7068
/// Update the connections status in every epoch.
7169
///
72-
/// @param neurons The Neuron list to search from.
70+
/// @param vertices The vertex list to search from.
7371
/// @return true if successful, false otherwise.
7472
virtual bool updateConnections(AllVertices &vertices);
7573

@@ -78,35 +76,36 @@ class Connections {
7876

7977
#if defined(USE_GPU)
8078
public:
81-
/// Update the weight of the Synapses in the simulation.
79+
/// Update the weight of the edges in the simulation.
8280
/// Note: Platform Dependent.
8381
///
8482
/// @param numVertices number of vertices to update.
85-
/// @param neurons the Neuron list to search from.
86-
/// @param synapses the Synapse list to search from.
83+
/// @param vertices the vertex list to search from.
84+
/// @param edges the edge list to search from.
8785
/// @param allVerticesDevice GPU address of the allVertices struct on device memory.
88-
/// @param allEdgesDevice GPU address of the allEdges struct on device memory.
89-
/// @param layout Layout information of the neural network.
90-
virtual void updateSynapsesWeights(int numVertices, AllVertices &vertices, AllEdges &synapses,
91-
AllSpikingNeuronsDeviceProperties *allVerticesDevice,
92-
AllSpikingSynapsesDeviceProperties *allEdgesDevice,
93-
Layout &layout);
86+
/// @param allEdgesDevice GPU address of the allEdges struct on device memory.
87+
/// @param layout Layout information of the graph network.
88+
virtual void updateEdgesWeights(int numVertices, AllVertices &vertices, AllEdges &edges,
89+
AllVerticesDeviceProperties *allVerticesDevice,
90+
AllEdgesDeviceProperties *allEdgesDevice, Layout &layout);
9491
#else
9592
public:
96-
/// Update the weight of the Synapses in the simulation.
93+
/// Update the weight of the edges in the simulation.
9794
/// Note: Platform Dependent.
98-
virtual void updateSynapsesWeights();
95+
virtual void updateEdgesWeights();
9996

10097
#endif // USE_GPU
10198

10299
protected:
103100
unique_ptr<AllEdges> edges_;
101+
/// TODO: Rename to edgeIndexMap_ since this is a base class
104102
unique_ptr<EdgeIndexMap> synapseIndexMap_;
105103

106104
log4cplus::Logger fileLogger_;
107105
log4cplus::Logger edgeLogger_;
108106
};
109107

108+
/// TODO: Rename to synapseIndexMap since this is a base class
110109
/// Cereal serialization method
111110
template <class Archive> void Connections::serialize(Archive &archive)
112111
{

0 commit comments

Comments
 (0)