Skip to content

Commit

Permalink
Feature VLS support and fixes (#38)
Browse files Browse the repository at this point in the history
* Support for very large scale (VLS) networks (test cases and kernel changes)
* Improvements for the PTI tutorial on LEAP
* Fixes for CUDA samples and Linux
* Patches for Github Workflows
  • Loading branch information
larsnm authored Oct 23, 2023
1 parent ae96969 commit e8203ca
Show file tree
Hide file tree
Showing 20 changed files with 394 additions and 173 deletions.
37 changes: 27 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ endif()
option(CARLSIM_PYCARL "Build CARLSIM PyCARL" OFF) # not for CR but SNN
option(CARLSIM_TOOLS "Build CARLSIM Tools" ON) # check for dependecies
option(CARLSIM_TEST "Build CARLSIM Tests" ON) # mandadory for development

option(CARLSIM_VLS_SIZING "Configure CARLsim for VLS Networks" OFF) #

# an option translates to one or more compile definitions assigned to one or multiple targets
# it can be set manually or by a super build customized to a specific profil
Expand Down Expand Up @@ -97,7 +99,7 @@ else()
endif()

# @TODO find permanent home in this file
if(CARLSIM_TEST)
if(CARLSIM_GH_ACTIONS AND CARLSIM_TEST)
target_compile_options(carlsim PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
endif()

Expand Down Expand Up @@ -333,6 +335,13 @@ if(CARLSIM_LN_AXON_PLAST)
endif()
endif()

if(CARLSIM_VLS_SIZING)
target_compile_definitions(carlsim PUBLIC VLS_SIZING)
if(NOT CARLSIM_NO_CUDA)
target_compile_definitions(carlsim-cuda PUBLIC VLS_SIZING)
endif()
endif()


# Includes

Expand All @@ -344,25 +353,33 @@ target_include_directories(carlsim
)

if(NOT CARLSIM_NO_CUDA)
if(NOT DEFINED CARLSIM_CUDA_SAMPLES_INCLUDE_DIR)
if(DEFINED ENV{CARLSIM_CUDA_SAMPLES_INCLUDE_DIR})
SET(CARLSIM_CUDA_SAMPLES_INCLUDE_DIR $ENV{CARLSIM_CUDA_SAMPLES_INCLUDE_DIR} CACHE STRING "CUDA samples set by ENV variable")
elseif(IS_DIRECTORY $ENV{HOME}/cuda-samples/Common)
SET(CARLSIM_CUDA_SAMPLES_INCLUDE_DIR $ENV{HOME}/cuda-samples/Common CACHE STRING "CUDA samples found in home directory")
elseif(MSVC)
SET(CARLSIM_CUDA_SAMPLES_INCLUDE_DIR "C:/ProgramData/NVIDIA Corporation/CUDA Samples/v${CUDA_VERSION_STRING}/common/inc" CACHE STRING "CUDA samples set by default for Windows")
else()
SET(CARLSIM_CUDA_SAMPLES_INCLUDE_DIR ${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc CACHE STRING "CUDA samples set by toolkit")
endif()
endif()
if(NOT IS_DIRECTORY ${CARLSIM_CUDA_SAMPLES_INCLUDE_DIR})
MESSAGE(FATAL_ERROR "CUDA samples not found: ${CARLSIM_CUDA_SAMPLES_INCLUDE_DIR}")
endif()
target_include_directories(carlsim-cuda
PUBLIC
carlsim/kernel/inc
carlsim/interface/inc
carlsim/monitor
${CUDA_INCLUDE_DIRS}
${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc
)
if(MSVC)
target_include_directories(carlsim-cuda
PUBLIC
"C:/ProgramData/NVIDIA Corporation/CUDA Samples/v${CUDA_VERSION_STRING}/common/inc"
)
endif()
${CARLSIM_CUDA_SAMPLES_INCLUDE_DIR}
)
endif()

### Linking ###

if(CARLSIM_TEST)
if(CARLSIM_GH_ACTIONS AND CARLSIM_TEST)
target_link_libraries(carlsim
PUBLIC
gcov
Expand Down
7 changes: 6 additions & 1 deletion carlsim/kernel/inc/snn_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@
// increasing the following numbers will increase the load on constant memory
// until a hard limit is reached, which is given by the datatype of the variable
#ifdef LN_I_CALC_TYPES
// Fix issue: File uses too much global constant data (0x12140 bytes, 0x10000 max)
#ifdef VLS_SIZING
#define MAX_CONN_PER_SNN 32001 // USC 57000 exceeds adressing by int16_t
#define MAX_GRP_PER_SNN 211 // USC 210
#else
// Fix issue: File uses too much global constant data (0x12140 bytes, 0x10000 max)
#define MAX_CONN_PER_SNN 128 // hard limit: 2^16
#define MAX_GRP_PER_SNN 96 // hard limit: 2^16
#endif
#else
#define MAX_CONN_PER_SNN 256 // hard limit: 2^16
#define MAX_GRP_PER_SNN 128 // hard limit: 2^16
Expand Down
6 changes: 6 additions & 0 deletions carlsim/kernel/src/gpu_module/snn_gpu_module.cu
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ __device__ unsigned int spikeCountExtRxD1GPU;

__device__ __constant__ RuntimeData runtimeDataGPU;
__device__ __constant__ NetworkConfigRT networkConfigGPU;

#ifdef VLS_SIZING
__device__ GroupConfigRT groupConfigsGPU[MAX_GRP_PER_SNN];
__device__ ConnectConfigRT connectConfigsGPU[MAX_CONN_PER_SNN];
#else
__device__ __constant__ GroupConfigRT groupConfigsGPU[MAX_GRP_PER_SNN];
__device__ __constant__ ConnectConfigRT connectConfigsGPU[MAX_CONN_PER_SNN];
#endif

#ifdef LN_I_CALC_TYPES
__device__ float d_mulSynFast[MAX_CONN_PER_SNN];
Expand Down
22 changes: 11 additions & 11 deletions carlsim/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ endif()
carlsim-spike-generators
${GTEST_LIBRARIES}
#if(CARLSIM_GH_ACTIONS)
GTest::gtest
gcov
#GTest::gtest
#gcov
#endif()
)

#if(CARLSIM_GH_ACTIONS)
#target_link_libraries(carlsim-tests
# PRIVATE
# GTest::gtest
# gcov
#)
#endif()
if(CARLSIM_GH_ACTIONS)
target_link_libraries(carlsim-tests
PRIVATE
GTest::gtest
gcov
)
endif()



Expand All @@ -77,8 +77,8 @@ if(MSVC)
target_link_options(carlsim-tests PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
endif()

#if(CARLSIM_GH_ACTIONS)
if(CARLSIM_GH_ACTIONS)
target_compile_options(carlsim-tests PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
#endif()
endif()

include(GoogleTest)
26 changes: 13 additions & 13 deletions carlsim/test6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ target_link_libraries(carlsim-tests6
PRIVATE
carlsim-spike-generators
${GTEST_LIBRARIES}
#if(CARLSIM_GH_ACTIONS)
GTest::gtest
gcov
#endif()
# if(CARLSIM_GH_ACTIONS)
# GTest::gtest
# gcov
# endif()
)

#if(CARLSIM_GH_ACTIONS)
# target_link_libraries(carlsim-tests6
# PRIVATE
# GTest::gtest
# gcov
# )
#endif()
if(CARLSIM_GH_ACTIONS)
target_link_libraries(carlsim-tests6
PRIVATE
GTest::gtest
gcov
)
endif()

if(MSVC)
# Fixed Explorer Issue, see Release Notes of GTest Adapter
# Generate Debug Information optimized for sharing and publishing (/DEBUG:FULL)
target_link_options(carlsim-tests6 PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
endif()

#if(CARLSIM_GH_ACTIONS)
if(CARLSIM_GH_ACTIONS)
target_compile_options(carlsim-tests6 PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
#endif()
endif()

include(GoogleTest)
1 change: 1 addition & 0 deletions carlsim/testadv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ find_package(GTest REQUIRED)
multi_runtimes.cpp
stdp_adv.cpp
axonplast2.cpp
nrngrps_limit.cpp
)

#ISSUE: gtest flags gtest death test style lnk1120 unresolved externals
Expand Down
6 changes: 5 additions & 1 deletion carlsim/testadv/axonplast2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class Maze
}

int row(int index) {
#if defined(WIN32) || defined(WIN64)
return trunc(index / columns);
#else
return index / columns;
#endif
}

int column(int index) {
Expand Down Expand Up @@ -1278,4 +1282,4 @@ TEST(axonplast2, updateDelays) {
}
}

#endif
#endif
140 changes: 140 additions & 0 deletions carlsim/testadv/nrngrps_limit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

#include "gtest/gtest.h"
#include "carlsim_tests.h"

#include <carlsim.h>

#include <stopwatch.h>

#include <periodic_spikegen.h>
#include <spikegen_from_vector.h>
#include <interactive_spikegen.h>

#include <vector>

#include <algorithm>
#include <random>
#include <cmath>



// ---------------- CONFIG STATE -------------------

TEST(neurongroups, limit) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";

for (int mode = GPU_MODE; mode >= CPU_MODE; mode--) {

LoggerMode logger = SILENT;
//LoggerMode logger = USER;

bool bSpikeMon = true;

CARLsim sim("nrngrps_limit", mode ? GPU_MODE : CPU_MODE, logger);

// Neurons
int NRNS = 7000; // neurons GB device memory, 210 * 7000 neurons
//int NRNS = 100; // neurons

int g_in = sim.createSpikeGeneratorGroup("in", 1, EXCITATORY_NEURON);

const int GRPS = 210;
//const int GRPS = 10;
//const int GRPS = 310; // expected death

const int CONNS = 32000; // int16 adressing

int g_exc[GRPS];
for (int i = 0; i < GRPS; i++) {
std::string name = "exc" + std::to_string(i);
g_exc[i] = sim.createGroup(name, NRNS, EXCITATORY_NEURON, -1, mode ? GPU_CORES : CPU_CORES);
sim.setNeuronParameters(g_exc[i], 0.02f, 0.2f, -65.0f, 8.0f); // RS
}

// Connections
sim.connect(g_in, g_exc[0], "full", RangeWeight(40), 1.0f, RangeDelay(1), RadiusRF(-1), SYN_FIXED);

// Forward
for (int i = 1; i < GRPS; i++) {
sim.connect(g_exc[i-1], g_exc[i], "one-to-one", RangeWeight(40), 1.0f, RangeDelay(1), RadiusRF(-1), SYN_FIXED);
}

// Full
int g_conn = 0;
for (int i = 0; i < GRPS; i++) {
for (int j = 0; j < GRPS; j++) {
if (j != i - 1 && j != i //ignore recurrent
&& g_conn < CONNS
)
{
auto w = 20.f + 5.0f/GRPS; // normalize avg firing rate
g_conn = sim.connect(g_exc[i], g_exc[j], "one-to-one", RangeWeight(w), 1.0f, RangeDelay(1, 20), RadiusRF(-1), SYN_FIXED);
}
}
}

// Sensory input
std::vector<int> spikeTimes_exc;
int interval = 100; // ms
int iterations = 5;
for (int i = 0; i < iterations; i++) {
spikeTimes_exc.push_back(1 + i*interval);
}

SpikeGeneratorFromVector spkGen_exc(spikeTimes_exc);
sim.setSpikeGenerator(g_in, &spkGen_exc);

// avoid warning setConductances has not been called. Setting simulation mode to CUBA.
sim.setConductances(false);

// ---------------- SETUP STATE -------------------
#ifdef VLS_SIZING
if (GRPS <= 210)
sim.setupNetwork();
else {
EXPECT_DEATH(sim.setupNetwork(), ""); // CUDA error code=1(cudaErrorInvalidValue) "cudaMemcpyToSymbol(groupConfigsGPU,
return;
}
#else
if (GRPS <= 128)
sim.setupNetwork();
else {
EXPECT_DEATH(sim.setupNetwork(), ""); // SEH exception with code 0xc0000005
return;
}
#endif

// generateSETUPStateSTP.h
for (int i = 0; i < GRPS; i++) {
if (bSpikeMon) {
auto sm = sim.setSpikeMonitor(g_exc[i], "DEFAULT");
sm->startRecording();
}
}

// ---------------- RUN STATE -------------------
sim.runNetwork(0, 10, true);

if (bSpikeMon) {
float totalRate = .0f;
int n = 0;
for (int i = 4; i < GRPS; i++) { // forward only
auto sm = sim.getSpikeMonitor(g_exc[i]);
sm->stopRecording();
//auto rate = sm->getMaxFiringRate(); // over all monitors ?
auto rate = sm->getPopMeanFiringRate();
//printf("firing rate exc%02d: %.2f Hz\n", g_exc[i], rate);
auto spikes = sm->getPopNumSpikes();
totalRate += rate;
n++;
}
float avgRate = totalRate / n;
printf("avg firing rate (%s): %.2f Hz\n", mode == GPU_MODE ? "GPU" : "CPU", avgRate);
EXPECT_NEAR(avgRate, 9.0f, 5.0f);
}

}

}


2 changes: 1 addition & 1 deletion doc/CmakeLists.txt → doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ add_subdirectory(source/tutorial/3_plasticity)
add_subdirectory(source/tutorial/4_image_processing)
add_subdirectory(source/tutorial/5_motion_energy)
add_subdirectory(source/tutorial/6_simple_weight_tuner)
#add_subdirectory(source/tutorial/7_pti/src) # pti is built as standalone
add_subdirectory(source/tutorial/7_pti)
add_subdirectory(source/tutorial/8_compartments)
add_subdirectory(source/tutorial/9_dastdp)
1 change: 1 addition & 0 deletions doc/source/tutorial/5_motion_energy/input/.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# put all inputs here
Loading

0 comments on commit e8203ca

Please sign in to comment.