Skip to content

Commit 8f1b4a8

Browse files
Validation mode logging implementation
1 parent 9ab3af6 commit 8f1b4a8

File tree

11 files changed

+127
-35
lines changed

11 files changed

+127
-35
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ if(NOT DEFINED TARGET_ARCH)
3636
set(TARGET_ARCH 37)
3737
endif()
3838

39+
#CONDITIONAL FLAG to turn on the validation mode
40+
if(NOT VALIDATION_MODE)
41+
set(VALIDATION_MODE NO)
42+
endif()
43+
3944
#Creates the Graphitti project with the correct languages, depending on if using GPU or not
4045
#If using CUDA, also verify the CUDA package and set the required CUDA variables
4146
if(ENABLE_CUDA)
@@ -102,7 +107,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
102107
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
103108
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
104109
if(ENABLE_CUDA)
105-
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G")
110+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -g -G")
106111
endif()
107112
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
108113
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}")
@@ -150,6 +155,11 @@ if(PERFORMANCE_METRICS)
150155
add_definitions(-DPERFORMANCE_METRICS)
151156
endif()
152157

158+
if(VALIDATION_MODE)
159+
message("-- Setting VALIDATION_MODE: ON")
160+
add_definitions(-DVALIDATION_MODE)
161+
endif()
162+
153163
#HDF5 Support, finds HDF5 package for C and C++ and links the hdf5 libraries to the executable \
154164
# later in the file.
155165
find_package(HDF5 COMPONENTS C CXX)
@@ -528,4 +538,5 @@ unset(PERFORMANCE_METRICS CACHE)
528538
unset(GPROF CACHE)
529539
unset(CMAKE_BUILD_TYPE CACHE)
530540
unset(NVTX_LIBRARY CACHE)
531-
unset(TARGET_ARCH CACHE)
541+
unset(TARGET_ARCH CACHE)
542+
unset(VALIDATION_MODE CACHE)

Simulator/Core/GPUModel.cpp

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#include "AllVertices.h"
1414
#include "Connections.h"
1515
#include "Global.h"
16-
16+
#ifdef VALIDATION_MODE
17+
#include "AllIFNeurons.h"
18+
#include "OperationManager.h"
19+
#endif
1720
#ifdef PERFORMANCE_METRICS
1821
float g_time;
1922
cudaEvent_t start, stop;
@@ -144,19 +147,21 @@ void GPUModel::advance()
144147
AllVertices &neurons = layout_->getVertices();
145148
AllEdges &synapses = connections_->getEdges();
146149

147-
//#ifdef VALIDATION_MODE
148-
// int verts = Simulator::getInstance().getTotalVertices();
149-
// std::vector<float> randNoise_h(verts);
150+
#ifdef VALIDATION_MODE
151+
int verts = Simulator::getInstance().getTotalVertices();
152+
std::vector<float> randNoise_h(verts);
153+
for (int i = verts - 1; i >= 0; i--) {
154+
randNoise_h[i] = (*noiseRNG)();
155+
}
156+
//static int testNumbers = 0;
150157
// for (int i = 0; i < verts; i++) {
151-
// randNoise_h[i] = noiseRNG->rand();
158+
// outFile << "index: " << i << " " << randNoise_h[i] << endl;
152159
// }
153-
// cudaMemcpy(randNoise_d, randNoise_h.data(), verts * sizeof(float), cudaMemcpyHostToDevice);
154-
//#endif // VALIDATION_MODE
155-
156-
//#else VALIDATION_MODE
160+
cudaMemcpy(randNoise_d, randNoise_h.data(), verts * sizeof(float), cudaMemcpyHostToDevice);
161+
#else
157162
normalMTGPU(randNoise_d);
158-
//#endif
159-
163+
#endif
164+
//LOG4CPLUS_DEBUG(vertexLogger_, "Index: " << index << " Vm: " << Vm);
160165
#ifdef PERFORMANCE_METRICS
161166
cudaLapTime(t_gpu_rndGeneration);
162167
cudaStartTimer();
@@ -167,7 +172,43 @@ void GPUModel::advance()
167172
dynamic_cast<AllSpikingNeurons &>(neurons).advanceVertices(connections_->getEdges(),
168173
allVerticesDevice_, allEdgesDevice_,
169174
randNoise_d, synapseIndexMapDevice_);
175+
#ifdef VALIDATION_MODE
176+
//(AllIFNeuronsDeviceProperties *)allVerticesDevice,
177+
log4cplus::Logger vertexLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("vertex"));
178+
std::vector<float> sp_h(verts);
179+
std::vector<float> vm_h(verts);
180+
std::vector<float> Inoise_h(verts);
181+
HANDLE_ERROR(cudaMemcpy(sp_h.data(), allVerticesDevice_->summationPoints_, verts * sizeof(float),
182+
cudaMemcpyDeviceToHost));
183+
HANDLE_ERROR(
184+
cudaMemcpy(sp_h.data(), randNoise_d, verts * sizeof(float), cudaMemcpyDeviceToHost));
185+
HANDLE_ERROR(cudaMemcpy(vm_h.data(), ((AllIFNeuronsDeviceProperties *)(allVerticesDevice_))->Vm_,
186+
verts * sizeof(float), cudaMemcpyDeviceToHost));
187+
HANDLE_ERROR(cudaMemcpy(Inoise_h.data(),
188+
((AllIFNeuronsDeviceProperties *)(allVerticesDevice_))->Inoise_,
189+
verts * sizeof(float), cudaMemcpyDeviceToHost));
190+
HANDLE_ERROR(cudaMemcpy(sp_h.data(), allVerticesDevice_->spValidation_, verts * sizeof(float),
191+
cudaMemcpyDeviceToHost));
170192

193+
for (int i = 0; i < verts; i++) {
194+
LOG4CPLUS_DEBUG(vertexLogger_, "CUDA advance Index[ "
195+
<< i << "] :: Noise = " << randNoise_h[i]
196+
<< "\tVm: " << vm_h[i] << endl
197+
<< "\tsp = " << sp_h[i] << endl
198+
<< "\tInoise = " << Inoise_h[i] << endl);
199+
}
200+
#endif
201+
//LOG4CPLUS_DEBUG(vertexLogger_, "ADVANCE NEURON LIF[" << index << "] :: Noise = " << noise);
202+
//LOG4CPLUS_DEBUG(vertexLogger_, "Index: " << index << " Vm: " << Vm);
203+
// LOG4CPLUS_DEBUG(vertexLogger_, "NEURON[" << index << "] {" << endl
204+
// << "\tVm = " << Vm << endl
205+
// << "\tVthresh = " << Vthresh << endl
206+
// << "\tsummationPoint = " << summationPoint << endl
207+
// << "\tI0 = " << I0 << endl
208+
// << "\tInoise = " << Inoise << endl
209+
// << "\tC1 = " << C1 << endl
210+
// << "\tC2 = " << C2 << endl
211+
// << "}" << endl);
171212
#ifdef PERFORMANCE_METRICS
172213
cudaLapTime(t_gpu_advanceNeurons);
173214
cudaStartTimer();

Simulator/Core/GPUModel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
#include "AllSpikingNeurons.h"
3939
#include "AllSpikingSynapses.h"
4040

41+
#ifdef VALIDATION_MODE
42+
#include <fstream>
43+
#include <iostream>
44+
#endif // VALIDATION_MODE
45+
4146
#ifdef __CUDACC__
4247
#include "Book.h"
4348
#endif

Simulator/Core/Simulator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Simulator::Simulator()
3131

3232
consoleLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console"));
3333
fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file"));
34+
fileLogger_.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
3435
edgeLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("edge"));
3536
workbenchLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("workbench"));
3637

Simulator/Vertices/AllVertices.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ AllVertices::AllVertices() : size_(0)
2525
// Get a copy of the file and vertex logger to use log4cplus macros to print to debug files
2626
fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file"));
2727
vertexLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("vertex"));
28+
vertexLogger_.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
2829
}
2930

3031
/// Setup the internal structure of the class (allocate memories).

Simulator/Vertices/AllVertices.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ struct AllVerticesDeviceProperties {
155155
/// On the next advance cycle, vertices add the values stored in their corresponding
156156
/// summation points to their Vm and resets the summation points to zero
157157
BGFLOAT *summationPoints_;
158+
#ifdef VALIDATION_MODE
159+
BGFLOAT *spValidation_;
160+
#endif
158161
};
159162
#endif // defined(USE_GPU)
160163

Simulator/Vertices/Neuro/AllIFNeurons_d.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ void AllIFNeurons::allocDeviceStruct(AllIFNeuronsDeviceProperties &allVerticesDe
5050
HANDLE_ERROR(
5151
cudaMalloc((void **)&allVerticesDevice.numStepsInRefractoryPeriod_, count * sizeof(int)));
5252
HANDLE_ERROR(cudaMalloc((void **)&allVerticesDevice.summationPoints_, count * sizeof(BGFLOAT)));
53+
#ifdef VALIDATION_MODE
54+
HANDLE_ERROR(cudaMalloc((void **)&allVerticesDevice.spValidation_, count * sizeof(BGFLOAT)));
55+
#endif
5356
HANDLE_ERROR(cudaMalloc((void **)&allVerticesDevice.spikeHistory_, count * sizeof(uint64_t *)));
5457

5558
uint64_t *pSpikeHistory[count];
@@ -107,6 +110,9 @@ void AllIFNeurons::deleteDeviceStruct(AllIFNeuronsDeviceProperties &allVerticesD
107110
HANDLE_ERROR(cudaFree(allVerticesDevice.hasFired_));
108111
HANDLE_ERROR(cudaFree(allVerticesDevice.numStepsInRefractoryPeriod_));
109112
HANDLE_ERROR(cudaFree(allVerticesDevice.summationPoints_));
113+
#ifdef VALIDATION_MODE
114+
HANDLE_ERROR(cudaFree(allVerticesDevice.spValidation_));
115+
#endif
110116
HANDLE_ERROR(cudaFree(allVerticesDevice.spikeHistory_));
111117
}
112118

Simulator/Vertices/Neuro/AllIZHNeurons.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,27 @@ void AllIZHNeurons::advanceNeuron(int index)
224224
BGFLOAT &u = this->u_[index];
225225

226226
if (nStepsInRefr > 0) {
227-
// is neuron refractory?
227+
// is neuron refractory?
228+
#ifdef VALIDATION_MODE
229+
BGFLOAT noise = (*noiseRNG)();
230+
LOG4CPLUS_DEBUG(vertexLogger_, "REFRACTORY NEURON IZH[" << index << "] :: Noise = " << noise);
231+
#endif
228232
--nStepsInRefr;
229233
} else if (Vm >= Vthresh) {
230-
// should it fire?
234+
// should it fire?
235+
#ifdef VALIDATION_MODE
236+
BGFLOAT noise = (*noiseRNG)();
237+
LOG4CPLUS_DEBUG(vertexLogger_, "FIRE NEURON IZH[" << index << "] :: Noise = " << noise);
238+
#endif
231239
fire(index);
232240
} else {
233241
summationPoint += I0; // add IO
234242
// add noise
235243
BGFLOAT noise = (*noiseRNG)();
236-
// Happens really often, causes drastic slow down
237-
// DEBUG_MID(cout << "ADVANCE NEURON[" << index << "] :: noise = " << noise << endl;)
244+
// Happens really often, causes drastic slow down
245+
#ifdef VALIDATION_MODE
246+
LOG4CPLUS_DEBUG(vertexLogger_, "ADVANCE NEURON IZH[" << index << "] :: Noise = " << noise);
247+
#endif
238248
summationPoint += noise * Inoise; // add noise
239249

240250
BGFLOAT Vint = Vm * 1000;

Simulator/Vertices/Neuro/AllLIFNeurons.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,46 @@ void AllLIFNeurons::advanceNeuron(int index)
3333
int &nStepsInRefr = this->numStepsInRefractoryPeriod_[index];
3434

3535
if (nStepsInRefr > 0) {
36-
// is neuron refractory?
36+
// is neuron refractory?
37+
#ifdef VALIDATION_MODE
38+
BGFLOAT noise = (*noiseRNG)();
39+
LOG4CPLUS_DEBUG(vertexLogger_, "neuron refractory LIF[" << index << "] :: Noise = " << noise);
40+
#endif
3741
--nStepsInRefr;
3842
} else if (Vm >= Vthresh) {
39-
// should it fire?
43+
// should it fire?
44+
#ifdef VALIDATION_MODE
45+
BGFLOAT noise = (*noiseRNG)();
46+
LOG4CPLUS_DEBUG(vertexLogger_, "FIRE NEURON LIF[" << index << "] :: Noise = " << noise);
47+
#endif
4048
fire(index);
4149
} else {
4250
summationPoint += I0; // add IO
4351
// add noise
4452
BGFLOAT noise = (*noiseRNG)();
45-
//LOG4CPLUS_DEBUG(vertexLogger_, "ADVANCE NEURON[" << index << "] :: Noise = " << noise);
53+
#ifdef VALIDATION_MODE
54+
LOG4CPLUS_DEBUG(vertexLogger_, "ADVANCE NEURON LIF[" << index << "] :: Noise = " << noise);
55+
#endif
4656
summationPoint += noise * Inoise; // add noise
4757
Vm = C1 * Vm + C2 * summationPoint; // decay Vm and add inputs
4858
}
49-
// clear synaptic input for next time step
50-
summationPoint = 0;
5159

5260
// Causes a huge slowdown since it's printed so frequently
53-
// LOG4CPLUS_DEBUG(vertexLogger_, "Index: " << index << " Vm: " << Vm);
54-
// LOG4CPLUS_DEBUG(vertexLogger_, "NEURON[" << index << "] {" << endl
55-
// << "\tVm = " << Vm << endl
56-
// << "\tVthresh = " << Vthresh << endl
57-
// << "\tsummationPoint = " << summationPoint << endl
58-
// << "\tI0 = " << I0 << endl
59-
// << "\tInoise = " << Inoise << endl
60-
// << "\tC1 = " << C1 << endl
61-
// << "\tC2 = " << C2 << endl
62-
// << "}" << endl);
61+
#ifdef VALIDATION_MODE
62+
LOG4CPLUS_DEBUG(vertexLogger_, "Index: " << index << " Vm: " << Vm);
63+
LOG4CPLUS_DEBUG(vertexLogger_, "NEURON[" << index << "] {" << endl
64+
<< "\tVm = " << Vm << endl
65+
<< "\tVthresh = " << Vthresh << endl
66+
<< "\tsummationPoint = " << summationPoint << endl
67+
<< "\tI0 = " << I0 << endl
68+
<< "\tInoise = " << Inoise << endl
69+
<< "\tC1 = " << C1 << endl
70+
<< "\tC2 = " << C2 << endl
71+
<< "}" << endl);
72+
#endif
73+
74+
// clear synaptic input for next time step
75+
summationPoint = 0;
6376
}
6477

6578
/// Fire the selected Neuron and calculate the result.

Simulator/Vertices/Neuro/AllLIFNeurons.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class AllLIFNeurons : public AllIFNeurons {
113113
/// @param edgeIndexMapDevice GPU address of the EdgeIndexMap on device memory.
114114
virtual void advanceVertices(AllEdges &synapses, void *allVerticesDevice, void *allEdgesDevice,
115115
float randNoise[], EdgeIndexMapDevice *edgeIndexMapDevice) override;
116-
#else // !defined(USE_GPU)
116+
#else // !defined(USE_GPU)
117117
protected:
118118
/// Helper for #advanceNeuron. Updates state of a single neuron.
119119
///
@@ -124,7 +124,6 @@ class AllLIFNeurons : public AllIFNeurons {
124124
///
125125
/// @param index Index of the neuron to fire.
126126
virtual void fire(int index);
127-
128127
#endif // defined(USE_GPU)
129128
};
130129

0 commit comments

Comments
 (0)