Skip to content

Issue 196 - Change Cerr/Cout to LOG4CPLUS #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: SharedDevelopment
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Simulator/Connections/Neuro/ConnGrowth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,6 @@ void ConnGrowth::updateSynapsesWeights()
void ConnGrowth::printRadii() const
{
for (int i = 0; i < radiiSize_; i++) {
cout << "radii[" << i << "] = " << radii_[i] << endl;
LOG4CPLUS_TRACE(consoleLogger_, ("radii[" << i << "] = " << radii_[i] << endl));
}
}
2 changes: 1 addition & 1 deletion Simulator/Connections/Neuro/ConnGrowth.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ template <class Archive> void ConnGrowth::load(Archive &archive, std::uint32_t c

// check to see if serialized data size matches object size
if (radiiSize != radiiSize_ || radiiSize != radiiVector.size()) {
cerr << "Failed deserializing radii. Please verify totalVertices data member." << endl;
LOG4CPLUS_ERROR(fileLogger_, "Failed deserializing radii. Please verify totalVertices data member." << endl);
throw cereal::Exception("Deserialization Error");
}

Expand Down
15 changes: 10 additions & 5 deletions Simulator/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ using namespace std;
/// @returns true if successful, false otherwise.
bool Core::parseCommandLine(string executableName, string cmdLineArguments)
{

// Get the instance of the console logger
log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console"));

ParamContainer cl; // todo: note as third party class.
cl.initOptions(false); // don't allow unknown parameters
cl.setHelpString(string(
Expand All @@ -69,7 +73,7 @@ bool Core::parseCommandLine(string executableName, string cmdLineArguments)
|| (cl.addParam("version", 'v', ParamContainer::novalue,
"output current git commit ID and exit")
!= ParamContainer::errOk)) {
cerr << "Internal error creating command line parser" << endl;
LOG4CPLUS_FATAL(consoleLogger, ("Internal error creating command line parser" << endl));
return false;
}

Expand All @@ -80,7 +84,8 @@ bool Core::parseCommandLine(string executableName, string cmdLineArguments)
}

if (cl["version"].compare("") != 0) {
cout << "Git commit ID: " << GIT_COMMIT_ID << endl;

LOG4CPLUS_TRACE(consoleLogger, ("Git commit ID: " << GIT_COMMIT_ID << endl));
exit(0);
}

Expand Down Expand Up @@ -213,8 +218,8 @@ int Core::runSimulation(string executableName, string cmdLineArguments)
time(&end_time);
double timeElapsed = difftime(end_time, start_time);
double ssps = simulator.getEpochDuration() * simulator.getNumEpochs() / timeElapsed;
cout << "time simulated: " << simulator.getEpochDuration() * simulator.getNumEpochs() << endl;
cout << "time elapsed: " << timeElapsed << endl;
cout << "ssps (simulation seconds / real time seconds): " << ssps << endl;
LOG4CPLUS_TRACE(consoleLogger, "time simulated: " << simulator.getEpochDuration() * simulator.getNumEpochs() << endl);
LOG4CPLUS_TRACE(consoleLogger, "time elapsed: " << timeElapsed << endl);
LOG4CPLUS_TRACE(consoleLogger, "ssps (simulation seconds / real time seconds): " << ssps << endl);
return 0;
}
5 changes: 3 additions & 2 deletions Simulator/Core/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void Model::logSimStep() const
if (pConnGrowth == nullptr)
return;

cout << "format:\ntype,radius,firing rate" << endl;
LOG4CPLUS_TRACE(consoleLogger_, ("format:\ntype,radius,firing rate" << endl));


for (int y = 0; y < Simulator::getInstance().getHeight(); y++) {
stringstream ss;
Expand Down Expand Up @@ -152,7 +153,7 @@ void Model::logSimStep() const
}

ss << endl;
cout << ss.str();
LOG4CPLUS_TRACE(consoleLogger_, ss.str());
}
}

Expand Down
13 changes: 8 additions & 5 deletions Simulator/Core/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool Serializer::deserializeSynapses()

// Checks to see if serialization file exists
if (!memory_in) {
cerr << "The serialization file doesn't exist" << endl;
LOG4CPLUS_ERROR(fileLogger_, "The serialization file doesn't exist" << endl);
return false;
}

Expand All @@ -55,9 +55,9 @@ bool Serializer::deserializeSynapses()
try {
archive(dynamic_cast<AllEdges &>(connections.getEdges()));
} catch (cereal::Exception e) {
cerr << e.what() << endl
LOG4CPLUS_ERROR(fileLogger_, e.what() << endl
<< "Failed to deserialize synapse weights, source vertices, and/or destination vertices."
<< endl;
<< endl);
return false;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ bool Serializer::deserializeSynapses()
try {
archive(dynamic_cast<ConnGrowth &>(connections));
} catch (cereal::Exception e) {
cerr << e.what() << endl << "Failed to deserialize radii." << endl;
LOG4CPLUS_ERROR(fileLogger_, e.what() << endl << "Failed to deserialize radii." << endl);
return false;
}

Expand All @@ -102,10 +102,13 @@ void Serializer::serializeSynapses()
{
Simulator &simulator = Simulator::getInstance();

// Get the instance of the console logger
log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console"));

// We can serialize to a variety of archive file formats. Below, comment out
// all but the two lines that correspond to the desired format.
ofstream memory_out(simulator.getSerializationFileName().c_str());
cout << "PLease find the serialized file in " << simulator.getSerializationFileName().c_str();
LOG4CPLUS_TRACE(consoleLogger, ("PLease find the serialized file in " << simulator.getSerializationFileName().c_str()));

// Options parameter are optional which sets
// 1. Sets the Preceision of floating point number to 30
Expand Down
8 changes: 4 additions & 4 deletions Simulator/Core/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ void Simulator::setup()
{
#ifdef PERFORMANCE_METRICS
// Start overall simulation timer
cerr << "Starting main timer... ";
LOG4CPLUS_ERROR(fileLogger_, "Starting main timer... ");
t_host_initialization_layout = 0.0;
t_host_initialization_connections = 0.0;
t_host_advance = 0.0;
t_host_adjustEdges = 0.0;
timer.start();
cerr << "done." << endl;
LOG4CPLUS_ERROR(fileLogger_, "done." << endl);
#endif
LOG4CPLUS_INFO(fileLogger_, "Initializing models in network... ");
model_->setupSim();
Expand Down Expand Up @@ -181,9 +181,9 @@ void Simulator::simulate()
// Time since start of simulation
double total_time = timer.lap() / 1000000.0;

cout << "\ntotal_time: " << total_time << " seconds" << endl;
LOG4CPLUS_TRACE(consoleLogger_, ("\ntotal_time: " << total_time << " seconds" << endl));
printPerformanceMetrics(total_time, currentEpoch);
cout << endl;
LOG4CPLUS_TRACE(consoleLogger_, endl);
#endif
}
LOG4CPLUS_TRACE(workbenchLogger_, "Complete");
Expand Down
15 changes: 6 additions & 9 deletions Simulator/Edges/AllEdges.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,20 @@ template <class Archive> void AllEdges::load(Archive &archive, std::uint32_t con
// check to see if serialized data sizes matches object sizes
int requiredSize = maxEdgesPerVertex_ * countVertices_;
if (WVectorSize != requiredSize || WVectorSize != WVector.size()) {
cerr
<< "Failed deserializing edge weights. Please verify maxEdgesPerVertex and count_neurons data members in AllEdges class."
<< endl;
LOG4CPLUS_ERROR(fileLogger_, "Failed deserializing edge weights. Please verify maxEdgesPerVertex and count_neurons data members in AllEdges class."
<< endl);
throw cereal::Exception("Deserialization Error");
}
if (sourceVertexLayoutIndexVectorSize != requiredSize
|| sourceVertexLayoutIndexVectorSize != sourceVertexLayoutIndexVector.size()) {
cerr
<< "Failed deserializing source vertices. Please verify maxEdgesPerVertex and count_neurons data members in AllEdges class."
<< endl;
LOG4CPLUS_ERROR(fileLogger_, "Failed deserializing source vertices. Please verify maxEdgesPerVertex and count_neurons data members in AllEdges class."
<< endl);
throw cereal::Exception("Deserialization Error");
}
if (destVertexLayoutIndexVectorSize != requiredSize
|| destVertexLayoutIndexVectorSize != destVertexLayoutIndexVector.size()) {
cerr
<< "Failed deserializing destination vertices. Please verify maxEdgesPerVertex and count_neurons data members in AllEdges class."
<< endl;
LOG4CPLUS_ERROR(fileLogger_, "Failed deserializing destination vertices. Please verify maxEdgesPerVertex and count_neurons data members in AllEdges class."
<< endl);
throw cereal::Exception("Deserialization Error");
}

Expand Down
15 changes: 8 additions & 7 deletions Simulator/Edges/Neuro/AllDSSynapses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ void AllDSSynapses::printSynapsesProps() const
AllSpikingSynapses::printSynapsesProps();
for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) {
if (W_[i] != 0.0) {
cout << "lastSpike[" << i << "] = " << lastSpike_[i];
cout << " r: " << r_[i];
cout << " u: " << u_[i];
cout << " D: " << D_[i];
cout << " U: " << U_[i];
cout << " F: " << F_[i] << endl;

LOG4CPLUS_INFO(consoleLogger, ("lastSpike[" << i << "] = " << lastSpike_[i]));
LOG4CPLUS_INFO(consoleLogger, (" r: " << r_[i]));
LOG4CPLUS_INFO(consoleLogger, (" u: " << u_[i]));
LOG4CPLUS_INFO(consoleLogger, (" D: " << D_[i]));
LOG4CPLUS_INFO(consoleLogger, (" U: " << U_[i]));
LOG4CPLUS_INFO(consoleLogger, (" F: " << F_[i] << endl));
}
}
cout << endl;
LOG4CPLUS_INFO(consoleLogger, endl);
}
45 changes: 23 additions & 22 deletions Simulator/Edges/Neuro/AllDSSynapses_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,34 +305,35 @@ void AllDSSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const

for (int i = 0; i < size; i++) {
if (WPrint[i] != 0.0) {
cout << "GPU W[" << i << "] = " << WPrint[i];
cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i];
cout << " GPU desNeuron: " << destNeuronIndexPrint[i];
cout << " GPU type: " << typePrint[i];
cout << " GPU psr: " << psrPrint[i];
cout << " GPU in_use:" << inUsePrint[i];

cout << " GPU decay: " << decayPrint[i];
cout << " GPU tau: " << tauPrint[i];
cout << " GPU total_delay: " << totalDelayPrint[i];

cout << " GPU lastSpike: " << lastSpikePrint[i];
cout << " GPU r: " << rPrint[i];
cout << " GPU u: " << uPrint[i];
cout << " GPU D: " << DPrint[i];
cout << " GPU U: " << UPrint[i];
cout << " GPU F: " << FPrint[i] << endl;
LOG4CPLUS_INFO(consoleLogger, ("GPU W[" << i << "] = " << WPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU sourNeuron: " << sourceNeuronIndexPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU desNeuron: " << destNeuronIndexPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU type: " << typePrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU psr: " << psrPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU in_use:" << inUsePrint[i]));

LOG4CPLUS_INFO(consoleLogger, (" GPU decay: " << decayPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU tau: " << tauPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU total_delay: " << totalDelayPrint[i]));

LOG4CPLUS_INFO(consoleLogger, (" GPU lastSpike: " << lastSpikePrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU r: " << rPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU u: " << uPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU D: " << DPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU U: " << UPrint[i]));
LOG4CPLUS_INFO(consoleLogger, (" GPU F: " << FPrint[i] << endl));
}
}

for (int i = 0; i < countVertices_; i++) {
cout << "GPU edge_counts:"
<< "neuron[" << i << "]" << synapseCountsPrint[i] << endl;
LOG4CPLUS_INFO(consoleLogger, ("GPU edge_counts:"
<< "neuron[" << i << "]" << synapseCountsPrint[i] << endl));
}

cout << "GPU totalSynapseCount:" << totalSynapseCountPrint << endl;
cout << "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl;
cout << "GPU countVertices_:" << countNeuronsPrint << endl;

LOG4CPLUS_INFO(consoleLogger, ("GPU totalSynapseCount:" << totalSynapseCountPrint << endl));
LOG4CPLUS_INFO(consoleLogger, ("GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl));
LOG4CPLUS_INFO(consoleLogger, ("GPU countVertices_:" << countNeuronsPrint << endl));


// Set countVertices_ to 0 to avoid illegal memory deallocation
Expand Down
13 changes: 7 additions & 6 deletions Simulator/Edges/Neuro/AllDynamicSTDPSynapses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ void AllDynamicSTDPSynapses::printSynapsesProps() const
AllSTDPSynapses::printSynapsesProps();
for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) {
if (W_[i] != 0.0) {
cout << "lastSpike[" << i << "] = " << lastSpike_[i];
cout << " r: " << r_[i];
cout << " u: " << u_[i];
cout << " D: " << D_[i];
cout << " U: " << U_[i];
cout << " F: " << F_[i] << endl;

LOG4CPLUS_TRACE(consoleLogger_, ("lastSpike[" << i << "] = " << lastSpike_[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" r: " << r_[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" u: " << u_[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" D: " << D_[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" U: " << U_[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" F: " << F_[i] << endl));
}
}
}
74 changes: 38 additions & 36 deletions Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,50 +341,52 @@ void AllDynamicSTDPSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const
cudaMemcpy(UPrint, allSynapsesProps.U_, size * sizeof(BGFLOAT), cudaMemcpyDeviceToHost));
HANDLE_ERROR(
cudaMemcpy(FPrint, allSynapsesProps.F_, size * sizeof(BGFLOAT), cudaMemcpyDeviceToHost));

for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) {
if (WPrint[i] != 0.0) {
cout << "GPU W[" << i << "] = " << WPrint[i];
cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i];
cout << " GPU desNeuron: " << destNeuronIndexPrint[i];
cout << " GPU type: " << typePrint[i];
cout << " GPU psr: " << psrPrint[i];
cout << " GPU in_use:" << inUsePrint[i];

cout << " GPU decay: " << decayPrint[i];
cout << " GPU tau: " << tauPrint[i];
cout << " GPU total_delay: " << totalDelayPrint[i];

cout << " GPU total_delayPost: " << totalDelayPostPrint[i];
cout << " GPU tauspost_: " << tauspost_Print[i];
cout << " GPU tauspre_: " << tauspre_Print[i];
cout << " GPU taupos_: " << taupos_Print[i];
cout << " GPU tauneg_: " << tauneg_Print[i];
cout << " GPU STDPgap_: " << STDPgap_Print[i];
cout << " GPU Wex_: " << Wex_Print[i];
cout << " GPU Aneg_: " << Aneg_Print[i];
cout << " GPU Apos_: " << Apos_Print[i];
cout << " GPU mupos_: " << mupos_Print[i];
cout << " GPU muneg_: " << muneg_Print[i];
cout << " GPU useFroemkeDanSTDP_: " << useFroemkeDanSTDP_Print[i];

cout << " GPU lastSpike: " << lastSpikePrint[i];
cout << " GPU r: " << rPrint[i];
cout << " GPU u: " << uPrint[i];
cout << " GPU D: " << DPrint[i];
cout << " GPU U: " << UPrint[i];
cout << " GPU F: " << FPrint[i] << endl;
LOG4CPLUS_TRACE(consoleLogger_, ("GPU W[" << i << "] = " << WPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU sourNeuron: " << sourceNeuronIndexPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU desNeuron: " << destNeuronIndexPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU type: " << typePrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU psr: " << psrPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU in_use:" << inUsePrint[i]));

LOG4CPLUS_TRACE(consoleLogger_, (" GPU decay: " << decayPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU tau: " << tauPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU total_delay: " << totalDelayPrint[i]));

LOG4CPLUS_TRACE(consoleLogger_, (" GPU total_delayPost: " << totalDelayPostPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU tauspost_: " << tauspost_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU tauspre_: " << tauspre_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU taupos_: " << taupos_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU tauneg_: " << tauneg_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU STDPgap_: " << STDPgap_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU Wex_: " << Wex_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU Aneg_: " << Aneg_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU Apos_: " << Apos_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU mupos_: " << mupos_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU muneg_: " << muneg_Print[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU useFroemkeDanSTDP_: " << useFroemkeDanSTDP_Print[i]));

LOG4CPLUS_TRACE(consoleLogger_, (" GPU lastSpike: " << lastSpikePrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU r: " << rPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU u: " << uPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU D: " << DPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU U: " << UPrint[i]));
LOG4CPLUS_TRACE(consoleLogger_, (" GPU F: " << FPrint[i] << endl));
}
}

for (int i = 0; i < countVertices_; i++) {
cout << "GPU edge_counts:"
<< "neuron[" << i << "]" << synapseCountsPrint[i] << endl;
LOG4CPLUS_TRACE(consoleLogger_, ("GPU edge_counts:"
<< "neuron[" << i << "]" << synapseCountsPrint[i] << endl));
}

cout << "GPU totalSynapseCount:" << totalSynapseCountPrint << endl;
cout << "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl;
cout << "GPU countVertices_:" << countNeuronsPrint << endl;
LOG4CPLUS_TRACE(consoleLogger_, ("GPU totalSynapseCount:" << totalSynapseCountPrint << endl));
LOG4CPLUS_TRACE(consoleLogger_, ("GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl));
LOG4CPLUS_TRACE(consoleLogger_, ("GPU countVertices_:" << countNeuronsPrint << endl));




// Set countVertices_ to 0 to avoid illegal memory deallocation
Expand Down
Loading