1
0

correctly stripe data across memory channels in simulation

This commit is contained in:
Howard Mao 2015-11-02 22:46:52 -08:00
parent ee9195be26
commit ba5a6af05c
6 changed files with 29 additions and 14 deletions

View File

@ -80,7 +80,7 @@ int main(int argc, char** argv)
for (int i = 0; i < N_MEM_CHANNELS; i++) { for (int i = 0; i < N_MEM_CHANNELS; i++) {
mm[i] = dramsim2 ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t); mm[i] = dramsim2 ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t);
try { try {
mm[i]->init(memsz_mb*1024*1024, mem_width, LINE_SIZE); mm[i]->init(memsz_mb*1024*1024 / N_MEM_CHANNELS, mem_width, LINE_SIZE);
} catch (const std::bad_alloc& e) { } catch (const std::bad_alloc& e) {
fprintf(stderr, fprintf(stderr,
"Failed to allocate %ld bytes (%ld MiB) of memory\n" "Failed to allocate %ld bytes (%ld MiB) of memory\n"
@ -88,11 +88,14 @@ int main(int argc, char** argv)
memsz_mb*1024*1024, memsz_mb); memsz_mb*1024*1024, memsz_mb);
exit(-1); exit(-1);
} }
if (loadmem)
load_mem(mm[i]->get_data(), loadmem);
} }
if (loadmem) {
void *mems[N_MEM_CHANNELS];
for (int i = 0; i < N_MEM_CHANNELS; i++)
mems[i] = mm[i]->get_data();
load_mem(mems, loadmem, N_MEM_CHANNELS);
}
// Instantiate HTIF // Instantiate HTIF
htif = new htif_emulator_t(memsz_mb, htif = new htif_emulator_t(memsz_mb,

View File

@ -117,9 +117,10 @@ void mm_magic_t::tick(
cycle++; cycle++;
} }
void load_mem(void* mem, const char* fn) void load_mem(void** mems, const char* fn, int nchannels)
{ {
char* m = (char*)mem; char* m;
ssize_t start = 0;
std::ifstream in(fn); std::ifstream in(fn);
if (!in) if (!in)
{ {
@ -131,8 +132,14 @@ void load_mem(void* mem, const char* fn)
while (std::getline(in, line)) while (std::getline(in, line))
{ {
#define parse_nibble(c) ((c) >= 'a' ? (c)-'a'+10 : (c)-'0') #define parse_nibble(c) ((c) >= 'a' ? (c)-'a'+10 : (c)-'0')
for (ssize_t i = line.length()-2, j = 0; i >= 0; i -= 2, j++) for (ssize_t i = line.length()-2, j = 0; i >= 0; i -= 2, j++) {
m[j] = (parse_nibble(line[i]) << 4) | parse_nibble(line[i+1]); char data = (parse_nibble(line[i]) << 4) | parse_nibble(line[i+1]);
m += line.length()/2; ssize_t addr = start + j;
int channel = (addr / LINE_SIZE) % nchannels;
m = (char *) mems[channel];
addr = (addr / LINE_SIZE / nchannels) * LINE_SIZE + (addr % LINE_SIZE);
m[addr] = data;
}
start += line.length()/2;
} }
} }

View File

@ -148,5 +148,5 @@ class mm_magic_t : public mm_t
uint64_t cycle; uint64_t cycle;
}; };
void load_mem(void* mem, const char* fn); void load_mem(void** mems, const char* fn, int channel);
#endif #endif

View File

@ -159,10 +159,14 @@ void htif_init(
for (int i=0; i<mem_channels; i++) { for (int i=0; i<mem_channels; i++) {
mm[i] = dramsim ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t); mm[i] = dramsim ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t);
mm[i]->init(MEM_SIZE, mw/8, LINE_SIZE); mm[i]->init(MEM_SIZE / mem_channels, mw/8, LINE_SIZE);
}
if (loadmem) if (loadmem) {
load_mem(mm[i]->get_data(), loadmem); void *mems[mem_channels];
for (int i = 0; i < mem_channels; i++)
mems[i] = mm[i]->get_data();
load_mem(mems, loadmem, mem_channels);
} }
vec32* w = vc_4stVectorRef(htif_width); vec32* w = vc_4stVectorRef(htif_width);

View File

@ -55,6 +55,7 @@ $(generated_dir_debug)/consts.$(CONFIG).h: $(generated_dir_debug)/$(MODEL).$(CON
echo "#ifndef __CONST_H__" > $@ echo "#ifndef __CONST_H__" > $@
echo "#define __CONST_H__" >> $@ echo "#define __CONST_H__" >> $@
sed -r 's/\(([A-Za-z0-9_]+),([A-Za-z0-9_]+)\)/#define \1 \2/' $(patsubst %.h,%.prm,$<) >> $@ sed -r 's/\(([A-Za-z0-9_]+),([A-Za-z0-9_]+)\)/#define \1 \2/' $(patsubst %.h,%.prm,$<) >> $@
echo "#define TBFRAG \"$(MODEL).$(CONFIG).tb.cpp\"" >> $@
echo "#endif // __CONST_H__" >> $@ echo "#endif // __CONST_H__" >> $@
emu = emulator-$(MODEL)-$(CONFIG) emu = emulator-$(MODEL)-$(CONFIG)

@ -1 +1 @@
Subproject commit ec5036a6caa9a53c0fcee17dd3b001ba054ac549 Subproject commit f9cc0a33cedb65e772c397473f792c513d8cc81d