Skip to content

Commit

Permalink
Fixed SynDelay project bug, reported by @shailesh210; input spikes we…
Browse files Browse the repository at this point in the history
…re not being written to disk properly, so changed to 'pullInputCurrentSpikesFromDevice()' instead.
  • Loading branch information
jamesturner246 committed Aug 4, 2016
1 parent b0d6cd0 commit 90cfbbe
Showing 1 changed file with 80 additions and 77 deletions.
157 changes: 80 additions & 77 deletions userproject/SynDelay_project/SynDelaySim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,106 +28,109 @@ using namespace std;

SynDelay::SynDelay(bool usingGPU)
{
this->usingGPU = usingGPU;
allocateMem();
initialize();
this->usingGPU = usingGPU;
allocateMem();
initialize();
}

SynDelay::~SynDelay()
{
freeMem();
freeMem();
}

void SynDelay::run(float t)
{
if (usingGPU)
{
if (usingGPU)
{
#ifndef CPU_ONLY
stepTimeGPU();
copyStateFromDevice();
stepTimeGPU();
copyStateFromDevice();
pullInputCurrentSpikesFromDevice();
#endif // CPU_ONLY
}
else
{
stepTimeCPU();
}
}
else
{
stepTimeCPU();
}
}


/*====================================================================
--------------------------- MAIN FUNCTION ----------------------------
====================================================================*/
--------------------------- MAIN FUNCTION ----------------------------
====================================================================*/

int main(int argc, char *argv[])
{
if (argc != 3)
{
cerr << "usage: SynDelaySim <GPU = 1, CPU = 0> <output label>" << endl;
return EXIT_FAILURE;
}
if (argc != 3)
{
cerr << "usage: SynDelaySim <GPU = 1, CPU = 0> <output label>" << endl;
return EXIT_FAILURE;
}

#ifdef CPU_ONLY
if (atoi(argv[1]) == 1)
{
cerr << "Cannot use GPU in a CPU_ONLY binary." << endl;
cerr << "Recompile without CPU_ONLY to run a GPU simulation." << endl;
return EXIT_FAILURE;
}
#endif // CPU_ONLY

SynDelay *sim = new SynDelay(atoi(argv[1]));
CStopWatch *timer = new CStopWatch();
string outLabel = toString(argv[2]);
ofstream fileTime;
ofstream fileV;
ofstream fileStInput;
ofstream fileStInter;
ofstream fileStOutput;
fileTime.open((outLabel + "_time").c_str(), ios::out | ios::app);
fileV.open((outLabel + "_Vm").c_str(), ios::out | ios::trunc);
fileStInput.open((outLabel + "_input_st").c_str(), ios::out | ios::trunc);
fileStInter.open((outLabel + "_inter_st").c_str(), ios::out | ios::trunc);
fileStOutput.open((outLabel + "_output_st").c_str(), ios::out | ios::trunc);
cout << "# DT " << DT << endl;
cout << "# TOTAL_TIME " << TOTAL_TIME << endl;
cout << "# REPORT_TIME " << REPORT_TIME << endl;
cout << "# begin simulating on " << (atoi(argv[1]) ? "GPU" : "CPU") << endl;
timer->startTimer();
for (int i = 0; i < (TOTAL_TIME / DT); i++)
{
sim->run(t);
t += DT;

fileV << t
<< " " << VInput[0]
<< " " << VInter[0]
<< " " << VOutput[0]
<< endl;

for (int i= 0; i < glbSpkCntInput[spkQuePtrInput]; i++) {
fileStInput << t << " " << glbSpkInput[glbSpkShiftInput+i] << endl;
}
for (int i= 0; i < glbSpkCntInter[0]; i++) {
fileStInter << t << " " << glbSpkInter[i] << endl;
}
for (int i= 0; i < glbSpkCntOutput[0]; i++) {
fileStOutput << t << " " << glbSpkOutput[i] << endl;
if (atoi(argv[1]) == 1)
{
cerr << "Cannot use GPU in a CPU_ONLY binary." << endl;
cerr << "Recompile without CPU_ONLY to run a GPU simulation." << endl;
return EXIT_FAILURE;
}
#endif // CPU_ONLY

if ((int) t % (int) REPORT_TIME == 0)
SynDelay *sim = new SynDelay(atoi(argv[1]));
CStopWatch *timer = new CStopWatch();
string outLabel = toString(argv[2]);
ofstream fileTime;
ofstream fileV;
ofstream fileStInput;
ofstream fileStInter;
ofstream fileStOutput;
fileTime.open((outLabel + "_time").c_str(), ios::out | ios::app);
fileV.open((outLabel + "_Vm").c_str(), ios::out | ios::trunc);
fileStInput.open((outLabel + "_input_st").c_str(), ios::out | ios::trunc);
fileStInter.open((outLabel + "_inter_st").c_str(), ios::out | ios::trunc);
fileStOutput.open((outLabel + "_output_st").c_str(), ios::out | ios::trunc);
cout << "# DT " << DT << endl;
cout << "# TOTAL_TIME " << TOTAL_TIME << endl;
cout << "# REPORT_TIME " << REPORT_TIME << endl;
cout << "# begin simulating on " << (atoi(argv[1]) ? "GPU" : "CPU") << endl;
timer->startTimer();
for (int i = 0; i < (TOTAL_TIME / DT); i++)
{
cout << "time " << t << endl;
sim->run(t);

fileV << t
<< " " << VInput[0]
<< " " << VInter[0]
<< " " << VOutput[0]
<< endl;

for (int i= 0; i < glbSpkCntInput[spkQuePtrInput]; i++) {
fileStInput << t << " " << glbSpkInput[glbSpkShiftInput+i] << endl;
}
for (int i= 0; i < glbSpkCntInter[0]; i++) {
fileStInter << t << " " << glbSpkInter[i] << endl;
}
for (int i= 0; i < glbSpkCntOutput[0]; i++) {
fileStOutput << t << " " << glbSpkOutput[i] << endl;
}

if ((int) t % (int) REPORT_TIME == 0)
{
cout << "time " << t << endl;
}
}
}
timer->stopTimer();
cout << "# done in " << timer->getElapsedTime() << " seconds" << endl;
fileTime << timer->getElapsedTime() << endl;
fileTime.close();
fileV.close();

delete sim;
delete timer;
return EXIT_SUCCESS;
timer->stopTimer();
cout << "# done in " << timer->getElapsedTime() << " seconds" << endl;
fileTime << timer->getElapsedTime() << endl;
fileTime.close();
fileV.close();
fileStInput.close();
fileStInter.close();
fileStOutput.close();

delete sim;
delete timer;
return EXIT_SUCCESS;
}

#endif // SYNDELAYSIM_CU

0 comments on commit 90cfbbe

Please sign in to comment.