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);