Skip to content

Commit f06ef7a

Browse files
committed
Added support for command-line overrides in tracebasedsim
1 parent 0b3ee67 commit f06ef7a

5 files changed

+82
-43
lines changed

IniReader.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,19 @@ void IniReader::ReadIniFile(string filename, bool isSystemFile)
419419
}
420420
}
421421

422-
void IniReader::OverrideKeys(vector<string> keys, vector<string>values)
422+
void IniReader::OverrideKeys(const OverrideMap *map)
423423
{
424-
if (keys.size() != values.size())
425-
{
426-
ERROR("-o option is messed up");
427-
exit(-1);
428-
}
429-
for (size_t i=0; i<keys.size(); i++)
424+
if (!map)
425+
return;
426+
427+
OverrideIterator it = map->begin();
428+
DEBUG("Key overrides from command line:");
429+
for (it=map->begin(); it != map->end(); it++)
430430
{
431-
IniReader::SetKey(keys[i], values[i]);
431+
string key = it->first;
432+
string value = it->second;
433+
DEBUG("\t'"<< key <<"'->'"<< value<< "'");
434+
IniReader::SetKey(key,value);
432435
}
433436
}
434437

IniReader.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,18 @@
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*********************************************************************************/
3030

31-
32-
33-
34-
35-
36-
37-
3831
#ifndef INIREADER_H
3932
#define INIREADER_H
4033

4134
#include <iostream>
4235
#include <fstream>
4336
#include <sstream>
4437
#include <string>
38+
#include <map>
4539
#include "SystemConfiguration.h"
4640

4741
using namespace std;
4842

49-
// Uhhh, apparently the #name equals "name" -- HOORAY MACROS!
5043
#define DEFINE_UINT_PARAM(name, paramtype) {#name, &name, UINT, paramtype, false}
5144
#define DEFINE_STRING_PARAM(name, paramtype) {#name, &name, STRING, paramtype, false}
5245
#define DEFINE_FLOAT_PARAM(name,paramtype) {#name, &name, FLOAT, paramtype, false}
@@ -70,9 +63,13 @@ typedef struct _configMap
7063

7164
class IniReader
7265
{
66+
7367
public:
68+
typedef std::map<string, string> OverrideMap;
69+
typedef OverrideMap::const_iterator OverrideIterator;
70+
7471
static void SetKey(string key, string value, bool isSystemParam = false, size_t lineNumber = 0);
75-
static void OverrideKeys(vector<string> keys, vector<string> values);
72+
static void OverrideKeys(const OverrideMap *map);
7673
static void ReadIniFile(string filename, bool isSystemParam);
7774
static void InitEnumsFromStrings();
7875
static bool CheckIfAllSet();

MultiChannelMemorySystem.cpp

+20-11
Original file line numberDiff line numberDiff line change
@@ -292,24 +292,33 @@ void MultiChannelMemorySystem::mkdirIfNotExist(string path)
292292
}
293293
}
294294

295-
void MultiChannelMemorySystem::overrideSystemParam(string key, string value)
295+
void MultiChannelMemorySystem::overrideParams(const IniReader::OverrideMap *map)
296296
{
297-
cerr << "Override key " <<key<<"="<<value<<endl;
298-
IniReader::SetKey(key, value, true);
297+
if (!map)
298+
return;
299+
300+
if (map->find("NUM_CHANS") != map->end())
301+
{
302+
//FIXME: override for NUM_CHANS
303+
ERROR("Currently no support for overriding the number of channels; if you need this, send me an email and I can implement it. ");
304+
abort();
305+
}
306+
307+
IniReader::OverrideKeys(map);
299308
}
300309

301-
void MultiChannelMemorySystem::overrideSystemParam(string keyValuePair)
310+
void MultiChannelMemorySystem::overrideParam(string key, string value)
302311
{
303-
size_t equalsign=-1;
304-
string overrideKey, overrideVal;
305-
//FIXME: could use some error checks on the string
306-
if ((equalsign = keyValuePair.find_first_of('=')) != string::npos) {
307-
overrideKey = keyValuePair.substr(0,equalsign);
308-
overrideVal = keyValuePair.substr(equalsign+1);
309-
overrideSystemParam(overrideKey, overrideVal);
312+
if (key == "NUM_CHANS")
313+
{
314+
//FIXME: override for NUM_CHANS
315+
ERROR("Currently no support for overriding the number of channels; if you need this, send me an email and I can implement it. ");
316+
abort();
310317
}
318+
IniReader::SetKey(key, value, true);
311319
}
312320

321+
313322
MultiChannelMemorySystem::~MultiChannelMemorySystem()
314323
{
315324
// Should only ever be called on exit, so don't bother to delete stuff, just

MultiChannelMemorySystem.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Transaction.h"
3232
#include "SystemConfiguration.h"
3333
#include "MemorySystem.h"
34+
#include "IniReader.h"
3435

3536

3637
namespace DRAMSim {
@@ -56,8 +57,8 @@ class MultiChannelMemorySystem : public SimulatorObject
5657
void InitOutputFiles(string tracefilename);
5758

5859
// mostly for other simulators
59-
void overrideSystemParam(string key, string value);
60-
void overrideSystemParam(string kvpair);
60+
void overrideParams(const IniReader::OverrideMap *map);
61+
void overrideParam(string key, string value);
6162

6263
//output file
6364
std::ofstream visDataOut;

TraceBasedSim.cpp

+42-13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "MemorySystem.h"
4747
#include "MultiChannelMemorySystem.h"
4848
#include "Transaction.h"
49+
#include "IniReader.h"
4950

5051

5152
using namespace DRAMSim;
@@ -138,13 +139,13 @@ class TransactionReceiver
138139
void usage()
139140
{
140141
cout << "DRAMSim2 Usage: " << endl;
141-
cout << "DRAMSim -t tracefile -s system.ini -d ini/device.ini [-c #] [-p pwd] [-q] [-S 2048] [-n] [-o OPTION_A=1234]" <<endl;
142+
cout << "DRAMSim -t tracefile -s system.ini -d ini/device.ini [-c #] [-p pwd] [-q] [-S 2048] [-n] [-o OPTION_A=1234,tRC=14,tFAW=19]" <<endl;
142143
cout << "\t-t, --tracefile=FILENAME \tspecify a tracefile to run "<<endl;
143144
cout << "\t-s, --systemini=FILENAME \tspecify an ini file that describes the memory system parameters "<<endl;
144145
cout << "\t-d, --deviceini=FILENAME \tspecify an ini file that describes the device-level parameters"<<endl;
145146
cout << "\t-c, --numcycles=# \t\tspecify number of cycles to run the simulation for [default=30] "<<endl;
146147
cout << "\t-q, --quiet \t\t\tflag to suppress simulation output (except final stats) [default=no]"<<endl;
147-
cout << "\t-o, --option=OPTION_A=234\t\t\toverwrite any ini file option from the command line"<<endl;
148+
cout << "\t-o, --option=OPTION_A=234,tFAW=14\t\t\toverwrite any ini file option from the command line"<<endl;
148149
cout << "\t-p, --pwd=DIRECTORY\t\tSet the working directory (i.e. usually DRAMSim directory where ini/ and results/ are)"<<endl;
149150
cout << "\t-S, --size=# \t\t\tSize of the memory system in megabytes [default=2048M]"<<endl;
150151
cout << "\t-n, --notiming \t\t\tDo not use the clock cycle information in the trace file"<<endl;
@@ -331,6 +332,40 @@ void alignTransactionAddress(Transaction &trans)
331332
trans.address >>= throwAwayBits;
332333
trans.address <<= throwAwayBits;
333334
}
335+
336+
/**
337+
* Override options can be specified on the command line as -o key1=value1,key2=value2
338+
* this method should parse the key-value pairs and put them into a map
339+
**/
340+
IniReader::OverrideMap *parseParamOverrides(const string &kv_str)
341+
{
342+
IniReader::OverrideMap *kv_map = new IniReader::OverrideMap();
343+
size_t start = 0, comma=0, equal_sign=0;
344+
// split the commas if they are there
345+
while (1)
346+
{
347+
equal_sign = kv_str.find('=', start);
348+
if (equal_sign == string::npos)
349+
{
350+
break;
351+
}
352+
353+
comma = kv_str.find(',', equal_sign);
354+
if (comma == string::npos)
355+
{
356+
comma = kv_str.length();
357+
}
358+
359+
string key = kv_str.substr(start, equal_sign-start);
360+
string value = kv_str.substr(equal_sign+1, comma-equal_sign-1);
361+
362+
(*kv_map)[key] = value;
363+
start = comma+1;
364+
365+
}
366+
return kv_map;
367+
}
368+
334369
int main(int argc, char **argv)
335370
{
336371
int c;
@@ -341,12 +376,8 @@ int main(int argc, char **argv)
341376
string pwdString;
342377
unsigned megsOfMemory=2048;
343378
bool useClockCycle=true;
344-
345-
bool overrideOpt = false;
346-
string overrideKey = "";
347-
string overrideVal = "";
348-
string tmp = "";
349-
size_t equalsign;
379+
380+
IniReader::OverrideMap *paramOverrides = NULL;
350381

351382
unsigned numCycles=1000;
352383
//getopt stuff
@@ -357,6 +388,7 @@ int main(int argc, char **argv)
357388
{"deviceini", required_argument, 0, 'd'},
358389
{"tracefile", required_argument, 0, 't'},
359390
{"systemini", required_argument, 0, 's'},
391+
360392
{"pwd", required_argument, 0, 'p'},
361393
{"numcycles", required_argument, 0, 'c'},
362394
{"option", required_argument, 0, 'o'},
@@ -415,11 +447,7 @@ int main(int argc, char **argv)
415447
useClockCycle=false;
416448
break;
417449
case 'o':
418-
tmp = string(optarg);
419-
equalsign = tmp.find_first_of('=');
420-
overrideKey = tmp.substr(0,equalsign);
421-
overrideVal = tmp.substr(equalsign+1,tmp.size()-equalsign+1);
422-
overrideOpt = true;
450+
paramOverrides = parseParamOverrides(string(optarg));
423451
break;
424452
case '?':
425453
usage();
@@ -474,6 +502,7 @@ int main(int argc, char **argv)
474502

475503

476504
MultiChannelMemorySystem *memorySystem = new MultiChannelMemorySystem(deviceIniFilename, systemIniFilename, pwdString, traceFileName, megsOfMemory);
505+
memorySystem->overrideParams(paramOverrides);
477506

478507

479508
#ifdef RETURN_TRANSACTIONS

0 commit comments

Comments
 (0)