From 0ac61725254c90cc7f04410b38c945e10d087b39 Mon Sep 17 00:00:00 2001 From: Iori YONEJI Date: Sat, 14 Feb 2015 01:56:54 +0900 Subject: [PATCH] Add "-memsize" flag to emulator - Allow user to set memory size (in MiB) used by emulator. - if memory is exhausted, warn user about memory shortage. Close #3 --- csrc/emulator.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/csrc/emulator.cc b/csrc/emulator.cc index 3d211163..dd01bfc8 100644 --- a/csrc/emulator.cc +++ b/csrc/emulator.cc @@ -27,12 +27,15 @@ int main(int argc, char** argv) FILE *vcdfile = NULL; bool dramsim2 = false; bool log = false; + uint64_t memsz_mb = MEM_SIZE / (1024*1024); for (int i = 1; i < argc; i++) { std::string arg = argv[i]; if (arg.substr(0, 2) == "-v") vcd = argv[i]+2; + else if (arg.substr(0, 9) == "+memsize=") + memsz_mb = atoll(argv[i]+9); else if (arg.substr(0, 2) == "-s") random_seed = atoi(argv[i]+2); else if (arg == "+dramsim") @@ -65,7 +68,16 @@ int main(int argc, char** argv) // Instantiate and initialize main memory mm_t* mm = dramsim2 ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t); - mm->init(MEM_SIZE, tile.Top__io_mem_resp_bits_data.width()/8, LINE_SIZE); + try { + mm->init(memsz_mb*1024*1024, tile.Top__io_mem_resp_bits_data.width()/8, LINE_SIZE); + } + catch (const std::bad_alloc& e) { + fprintf(stderr, + "Failed to allocate %ld bytes (%ld MiB) of memory\n" + "Set smaller amount of memory using +memsize= (in MiB)\n" , memsz_mb*1024*1024, memsz_mb + ); + exit(-1); + } if (loadmem) load_mem(mm->get_data(), loadmem);