Skip to content

Commit ff2bbb9

Browse files
committed
Fix CSVWriter output for multiple channels
1 parent 4b00b22 commit ff2bbb9

8 files changed

+84
-68
lines changed

CSVWriter.h

+20-2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ namespace DRAMSim {
159159
{
160160
if (!finalized)
161161
{
162+
// cout <<"Adding "<<name<<endl;
162163
fieldNames.push_back(string(name));
163164
}
164165
return *this;
@@ -177,11 +178,22 @@ namespace DRAMSim {
177178
{
178179
if (!finalized)
179180
{
181+
// cout <<"Adding "<<indexedName.str<<endl;
180182
fieldNames.push_back(indexedName.str);
181183
}
182184
return *this;
183185
}
184-
186+
187+
bool isFinalized()
188+
{
189+
// printf("obj=%p", this);
190+
return finalized;
191+
}
192+
193+
ostream &getOutputStream()
194+
{
195+
return output;
196+
}
185197
// Insertion operators for value types
186198
// All of the other types just need to pass through to the underlying
187199
// ofstream, so just write this small wrapper function to make the
@@ -203,9 +215,15 @@ namespace DRAMSim {
203215
ADD_TYPE(uint64_t);
204216
ADD_TYPE(float);
205217
ADD_TYPE(double);
218+
219+
//disable copy constructor and assignment operator
220+
private:
221+
CSVWriter(const CSVWriter &);
222+
CSVWriter &operator=(const CSVWriter &);
223+
206224
}; // class CSVWriter
207225

208226

209-
} // namespace BOBSim
227+
} // namespace DRAMSim
210228

211229
#endif // _CSV_WRITER_H_

MemoryController.cpp

+27-42
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,17 @@
4343

4444
using namespace DRAMSim;
4545

46-
MemoryController::MemoryController(MemorySystem *parent, std::ofstream *outfile, ostream &dramsim_log_) :
46+
MemoryController::MemoryController(MemorySystem *parent, CSVWriter &csvOut_, ostream &dramsim_log_) :
4747
dramsim_log(dramsim_log_),
4848
bankStates(NUM_RANKS, vector<BankState>(NUM_BANKS, dramsim_log)),
4949
commandQueue(bankStates, dramsim_log_),
5050
poppedBusPacket(NULL),
51-
csvOut(*outfile),
51+
csvOut(csvOut_),
5252
totalTransactions(0),
5353
refreshRank(0)
5454
{
5555
//get handle on parent
5656
parentMemorySystem = parent;
57-
if (VIS_FILE_OUTPUT)
58-
{
59-
visDataOut = outfile;
60-
}
6157

6258

6359
//bus related fields
@@ -744,31 +740,6 @@ void MemoryController::update()
744740

745741
commandQueue.step();
746742

747-
//print stats if we're at the end of an epoch
748-
if (currentClockCycle % EPOCH_LENGTH == 0)
749-
{
750-
this->printStats();
751-
752-
totalTransactions = 0;
753-
for (size_t i=0;i<NUM_RANKS;i++)
754-
{
755-
for (size_t j=0; j<NUM_BANKS; j++)
756-
{
757-
//XXX: this means the bank list won't be printed for partial epochs
758-
grandTotalBankAccesses[SEQUENTIAL(i,j)] += totalReadsPerBank[SEQUENTIAL(i,j)] + totalWritesPerBank[SEQUENTIAL(i,j)];
759-
totalReadsPerBank[SEQUENTIAL(i,j)] = 0;
760-
totalWritesPerBank[SEQUENTIAL(i,j)] = 0;
761-
totalEpochLatency[SEQUENTIAL(i,j)] = 0;
762-
}
763-
764-
burstEnergy[i] = 0;
765-
actpreEnergy[i] = 0;
766-
refreshEnergy[i] = 0;
767-
backgroundEnergy[i] = 0;
768-
totalReadsPerRank[i] = 0;
769-
totalWritesPerRank[i] = 0;
770-
}
771-
}
772743
}
773744

774745
bool MemoryController::WillAcceptTransaction()
@@ -791,14 +762,31 @@ bool MemoryController::addTransaction(Transaction *trans)
791762
}
792763
}
793764

765+
void MemoryController::resetStats()
766+
{
767+
for (size_t i=0; i<NUM_RANKS; i++)
768+
{
769+
for (size_t j=0; j<NUM_BANKS; j++)
770+
{
771+
//XXX: this means the bank list won't be printed for partial epochs
772+
grandTotalBankAccesses[SEQUENTIAL(i,j)] += totalReadsPerBank[SEQUENTIAL(i,j)] + totalWritesPerBank[SEQUENTIAL(i,j)];
773+
totalReadsPerBank[SEQUENTIAL(i,j)] = 0;
774+
totalWritesPerBank[SEQUENTIAL(i,j)] = 0;
775+
totalEpochLatency[SEQUENTIAL(i,j)] = 0;
776+
}
794777

778+
burstEnergy[i] = 0;
779+
actpreEnergy[i] = 0;
780+
refreshEnergy[i] = 0;
781+
backgroundEnergy[i] = 0;
782+
totalReadsPerRank[i] = 0;
783+
totalWritesPerRank[i] = 0;
784+
}
785+
}
795786
//prints statistics at the end of an epoch or simulation
796787
void MemoryController::printStats(bool finalStats)
797788
{
798789
unsigned myChannel = parentMemorySystem->systemID;
799-
//skip the print on the first cycle, it's pretty useless
800-
if (currentClockCycle == 0)
801-
return;
802790

803791
//if we are not at the end of the epoch, make sure to adjust for the actual number of cycles elapsed
804792

@@ -843,11 +831,6 @@ void MemoryController::printStats(bool finalStats)
843831
PRINTN( " Total Return Transactions : " << totalTransactions );
844832
PRINT( " ("<<totalBytesTransferred <<" bytes) aggregate average bandwidth "<<totalBandwidth<<"GB/s");
845833

846-
// only the first memory channel should print the timestamp
847-
if (VIS_FILE_OUTPUT && myChannel == 0)
848-
{
849-
csvOut << "ms" <<currentClockCycle * tCK * 1E-6;
850-
}
851834
double totalAggregateBandwidth = 0.0;
852835
for (size_t r=0;r<NUM_RANKS;r++)
853836
{
@@ -883,6 +866,7 @@ void MemoryController::printStats(bool finalStats)
883866

884867
if (VIS_FILE_OUTPUT)
885868
{
869+
// cout << "c="<<myChannel<< " r="<<r<<"writing to csv out on cycle "<< currentClockCycle<<endl;
886870
// write the vis file output
887871
csvOut << CSVWriter::IndexedName("Background_Power",myChannel,r) <<backgroundPower[r];
888872
csvOut << CSVWriter::IndexedName("ACT_PRE_Power",myChannel,r) << actprePower[r];
@@ -904,7 +888,6 @@ void MemoryController::printStats(bool finalStats)
904888
{
905889
csvOut << CSVWriter::IndexedName("Aggregate_Bandwidth",myChannel) << totalAggregateBandwidth;
906890
csvOut << CSVWriter::IndexedName("Average_Bandwidth",myChannel) << totalAggregateBandwidth / (NUM_RANKS*NUM_BANKS);
907-
csvOut.finalize();
908891
}
909892

910893
// only print the latency histogram at the end of the simulation since it clogs the output too much to print every epoch
@@ -914,7 +897,7 @@ void MemoryController::printStats(bool finalStats)
914897
PRINT( " [lat] : #");
915898
if (VIS_FILE_OUTPUT)
916899
{
917-
(*visDataOut) << "!!HISTOGRAM_DATA"<<endl;
900+
csvOut.getOutputStream() << "!!HISTOGRAM_DATA"<<endl;
918901
}
919902

920903
map<unsigned,unsigned>::iterator it; //
@@ -923,7 +906,7 @@ void MemoryController::printStats(bool finalStats)
923906
PRINT( " ["<< it->first <<"-"<<it->first+(HISTOGRAM_BIN_SIZE-1)<<"] : "<< it->second );
924907
if (VIS_FILE_OUTPUT)
925908
{
926-
(*visDataOut) << it->first <<"="<< it->second << endl;
909+
csvOut.getOutputStream() << it->first <<"="<< it->second << endl;
927910
}
928911
}
929912
if (currentClockCycle % EPOCH_LENGTH == 0)
@@ -952,6 +935,8 @@ void MemoryController::printStats(bool finalStats)
952935
#ifdef LOG_OUTPUT
953936
dramsim_log.flush();
954937
#endif
938+
939+
resetStats();
955940
}
956941
MemoryController::~MemoryController()
957942
{

MemoryController.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MemoryController : public SimulatorObject
5757

5858
public:
5959
//functions
60-
MemoryController(MemorySystem* ms, std::ofstream *outfile, ostream &dramsim_log_);
60+
MemoryController(MemorySystem* ms, CSVWriter &csvOut_, ostream &dramsim_log_);
6161
virtual ~MemoryController();
6262

6363
bool addTransaction(Transaction *trans);
@@ -67,6 +67,7 @@ class MemoryController : public SimulatorObject
6767
void attachRanks(vector<Rank *> *ranks);
6868
void update();
6969
void printStats(bool finalStats = false);
70+
void resetStats();
7071

7172

7273
//fields
@@ -93,8 +94,7 @@ class MemoryController : public SimulatorObject
9394
vector<Rank *> *ranks;
9495

9596
//output file
96-
std::ofstream *visDataOut;
97-
CSVWriter csvOut;
97+
CSVWriter &csvOut;
9898

9999
// these packets are counting down waiting to be transmitted on the "bus"
100100
BusPacket *outgoingCmdPacket;

MemorySystem.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ namespace DRAMSim {
5252

5353
powerCallBack_t MemorySystem::ReportPower = NULL;
5454

55-
MemorySystem::MemorySystem(unsigned id, unsigned int megsOfMemory, ofstream &visDataOut_, ostream &dramsim_log_) :
55+
MemorySystem::MemorySystem(unsigned id, unsigned int megsOfMemory, CSVWriter &csvOut_, ostream &dramsim_log_) :
5656
dramsim_log(dramsim_log_),
5757
ReturnReadData(NULL),
5858
WriteDataDone(NULL),
5959
systemID(id),
60-
visDataOut(visDataOut_)
60+
csvOut(csvOut_)
6161
{
6262
currentClockCycle = 0;
6363

@@ -128,7 +128,7 @@ MemorySystem::MemorySystem(unsigned id, unsigned int megsOfMemory, ofstream &vis
128128
DEBUG("CH. " <<systemID<<" TOTAL_STORAGE : "<< TOTAL_STORAGE << "MB | "<<NUM_RANKS<<" Ranks | "<< NUM_DEVICES <<" Devices per rank");
129129

130130

131-
memoryController = new MemoryController(this, &visDataOut, dramsim_log);
131+
memoryController = new MemoryController(this, csvOut, dramsim_log);
132132

133133
// TODO: change to other vector constructor?
134134
ranks = new vector<Rank *>();
@@ -198,14 +198,9 @@ bool MemorySystem::addTransaction(Transaction *trans)
198198
}
199199

200200
//prints statistics
201-
void MemorySystem::printStats()
201+
void MemorySystem::printStats(bool finalStats)
202202
{
203-
memoryController->printStats(true);
204-
}
205-
206-
void MemorySystem::printStats(bool)
207-
{
208-
printStats();
203+
memoryController->printStats(finalStats);
209204
}
210205

211206

MemorySystem.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "Rank.h"
4545
#include "Transaction.h"
4646
#include "Callback.h"
47+
#include "CSVWriter.h"
4748
#include <deque>
4849

4950
namespace DRAMSim
@@ -54,13 +55,12 @@ class MemorySystem : public SimulatorObject
5455
ostream &dramsim_log;
5556
public:
5657
//functions
57-
MemorySystem(unsigned id, unsigned megsOfMemory, ofstream &visDataOut, ostream &dramsim_log_);
58+
MemorySystem(unsigned id, unsigned megsOfMemory, CSVWriter &csvOut_, ostream &dramsim_log_);
5859
virtual ~MemorySystem();
5960
void update();
6061
bool addTransaction(Transaction *trans);
6162
bool addTransaction(bool isWrite, uint64_t addr);
62-
void printStats();
63-
void printStats(bool unused);
63+
void printStats(bool finalStats);
6464
bool WillAcceptTransaction();
6565
void RegisterCallbacks(
6666
Callback_t *readDone,
@@ -81,7 +81,7 @@ class MemorySystem : public SimulatorObject
8181
unsigned systemID;
8282

8383
private:
84-
ofstream &visDataOut;
84+
CSVWriter &csvOut;
8585
};
8686
}
8787

MultiChannelMemorySystem.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ MultiChannelMemorySystem::MultiChannelMemorySystem(const string &deviceIniFilena
4747
:megsOfMemory(megsOfMemory_), deviceIniFilename(deviceIniFilename_),
4848
systemIniFilename(systemIniFilename_), traceFilename(traceFilename_),
4949
pwd(pwd_), visFilename(visFilename_),
50-
clockDomainCrosser(new ClockDomain::Callback<MultiChannelMemorySystem, void>(this, &MultiChannelMemorySystem::actual_update))
50+
clockDomainCrosser(new ClockDomain::Callback<MultiChannelMemorySystem, void>(this, &MultiChannelMemorySystem::actual_update)),
51+
csvOut(new CSVWriter(visDataOut))
5152
{
5253
currentClockCycle=0;
5354
if (visFilename)
@@ -93,10 +94,9 @@ MultiChannelMemorySystem::MultiChannelMemorySystem(const string &deviceIniFilena
9394
ERROR("Zero channels");
9495
abort();
9596
}
96-
9797
for (size_t i=0; i<NUM_CHANS; i++)
9898
{
99-
MemorySystem *channel = new MemorySystem(i, megsOfMemory/NUM_CHANS, visDataOut, dramsim_log);
99+
MemorySystem *channel = new MemorySystem(i, megsOfMemory/NUM_CHANS, (*csvOut), dramsim_log);
100100
channels.push_back(channel);
101101
}
102102
// for compatibility with the old marss code which assumed an sg15 part with a
@@ -383,10 +383,22 @@ void MultiChannelMemorySystem::actual_update()
383383
DEBUG("DRAMSim2 Clock Frequency ="<<clockDomainCrosser.clock1<<"Hz, CPU Clock Frequency="<<clockDomainCrosser.clock2<<"Hz");
384384
}
385385

386+
if (currentClockCycle % EPOCH_LENGTH == 0)
387+
{
388+
(*csvOut) << "ms" <<currentClockCycle * tCK * 1E-6;
389+
for (size_t i=0; i<NUM_CHANS; i++)
390+
{
391+
channels[i]->printStats(false);
392+
}
393+
csvOut->finalize();
394+
}
395+
386396
for (size_t i=0; i<NUM_CHANS; i++)
387397
{
388398
channels[i]->update();
389399
}
400+
401+
390402
currentClockCycle++;
391403
}
392404
unsigned MultiChannelMemorySystem::findChannelNumber(uint64_t addr)
@@ -468,13 +480,16 @@ bool MultiChannelMemorySystem::willAcceptTransaction()
468480

469481

470482

471-
void MultiChannelMemorySystem::printStats() {
483+
void MultiChannelMemorySystem::printStats(bool finalStats) {
484+
485+
(*csvOut) << "ms" <<currentClockCycle * tCK * 1E-6;
472486
for (size_t i=0; i<NUM_CHANS; i++)
473487
{
474488
PRINT("==== Channel ["<<i<<"] ====");
475-
channels[i]->printStats();
489+
channels[i]->printStats(finalStats);
476490
PRINT("//// Channel ["<<i<<"] ////");
477491
}
492+
csvOut->finalize();
478493
}
479494
void MultiChannelMemorySystem::RegisterCallbacks(
480495
TransactionCompleteCB *readDone,

MultiChannelMemorySystem.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "MemorySystem.h"
3434
#include "IniReader.h"
3535
#include "ClockDomain.h"
36+
#include "CSVWriter.h"
3637

3738

3839
namespace DRAMSim {
@@ -50,7 +51,7 @@ class MultiChannelMemorySystem : public SimulatorObject
5051
bool willAcceptTransaction();
5152
bool willAcceptTransaction(uint64_t addr);
5253
void update();
53-
void printStats();
54+
void printStats(bool finalStats=false);
5455
ostream &getLogFile();
5556
void RegisterCallbacks(
5657
TransactionCompleteCB *readDone,
@@ -77,6 +78,8 @@ class MultiChannelMemorySystem : public SimulatorObject
7778
ClockDomain::ClockDomainCrosser clockDomainCrosser;
7879
static void mkdirIfNotExist(string path);
7980
static bool fileExists(string path);
81+
CSVWriter *csvOut;
82+
8083

8184
};
8285
}

TraceBasedSim.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ int main(int argc, char **argv)
604604
}
605605

606606
traceFile.close();
607-
(*memorySystem).printStats();
607+
memorySystem->printStats(true);
608608
// make valgrind happy
609609
if (trans)
610610
{

0 commit comments

Comments
 (0)