Skip to content

Commit

Permalink
vcs: fix dramsim soft load
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokamikami committed Mar 13, 2024
1 parent 1834161 commit 6f695c2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ endif
ifeq ($(WITH_DRAMSIM3),1)
SIM_CXXFLAGS += -I$(DRAMSIM3_HOME)/src
SYSTEM_VAR = $(shell uname -a)
ifeq ($(findstring "Ubuntu",$(SYSTEM_VAR)),)
ifeq ($(shell uname -a | grep -c Ubuntu), 1)
SIM_CXXFLAGS += -DWITH_DRAMSIM3 -DDRAMSIM3_CONFIG=\\\"$(DRAMSIM3_HOME)/configs/XiangShan.ini\\\" -DDRAMSIM3_OUTDIR=\\\"$(BUILD_DIR)\\\"
else
SIM_CXXFLAGS += -DWITH_DRAMSIM3 -DDRAMSIM3_CONFIG=\"$(DRAMSIM3_HOME)/configs/XiangShan.ini\" -DDRAMSIM3_OUTDIR=\"$(BUILD_DIR)\"
Expand Down
5 changes: 5 additions & 0 deletions src/test/csrc/common/ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,12 @@ void dramsim3_step() {

void dramsim3_finish() {
delete dram;
dram = NULL;
}

uint64_t memory_response(bool isWrite) {
if (dram == NULL)
return 0;
auto response = (isWrite) ? dram->check_write_response() : dram->check_read_response();
if (response) {
auto meta = static_cast<dramsim3_meta *>(response->req->meta);
Expand All @@ -464,6 +467,8 @@ uint64_t memory_response(bool isWrite) {
}

bool memory_request(uint64_t address, uint32_t id, bool isWrite) {
if (dram == NULL)
return false;
if (dram->will_accept(address, isWrite)) {
auto req = new CoDRAMRequest();
auto meta = new dramsim3_meta;
Expand Down
31 changes: 28 additions & 3 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ static char *flash_bin_file = NULL;
static bool enable_difftest = true;
static uint64_t max_instrs = 0;
static char *workload_list = NULL;

static char *workload_list_log = NULL;
static char *ckpt_item = NULL;
static uint64_t ckpt_idx = 0;
enum {
SIMV_RUN,
SIMV_DONE,
Expand Down Expand Up @@ -68,7 +70,14 @@ extern "C" void set_diff_ref_so(char *s) {

extern "C" void set_workload_list(char *s) {
workload_list = (char *)malloc(256);
workload_list_log = (char *)malloc(256);
ckpt_item = (char *)malloc(32);
strcpy(workload_list, s);
workload_list_log = strncpy(workload_list_log, workload_list, strlen(workload_list) - 4);
strcat(workload_list_log, "-result.csv");
FILE *fp = fopen(workload_list_log, "w+");
fprintf(fp, "workload,point,Insts,Cycles,ipc\n");
fclose(fp);
printf("set workload list %s \n", workload_list);
}

Expand All @@ -77,7 +86,8 @@ int switch_workload() {
if (fp) {
char name[128];
int num;
if (fscanf(fp, "%s %d", name, &num) == 2) {
int scan_num = fscanf(fp, "%s %d %s %ld", name, &num, ckpt_item, &ckpt_idx);
if (scan_num == 2 || scan_num == 4) {
set_bin_file(name);
set_max_instrs(num);
} else if (feof(fp)) {
Expand Down Expand Up @@ -152,6 +162,14 @@ extern "C" uint8_t simv_step() {
if (max_instrs != 0) { // 0 for no limit
auto trap = difftest[0]->get_trap_event();
if (max_instrs < trap->instrCnt) {
if (ckpt_item != NULL) {
FILE *fp = fopen(workload_list_log, "a");
uint64_t instrCnt = difftest[0]->get_trap_event()->instrCnt;
uint64_t cycleCnt = difftest[0]->get_trap_event()->cycleCnt;
double ipc = (double)instrCnt / cycleCnt;
fprintf(fp, "%s,%ld,%ld,%ld,%lf\n", ckpt_item, ckpt_idx, instrCnt, cycleCnt, ipc);
fclose(fp);
}
eprintf(ANSI_COLOR_GREEN "EXCEEDED MAX INSTR: %ld\n" ANSI_COLOR_RESET, max_instrs);
difftest[0]->display_stats();
return SIMV_DONE;
Expand Down Expand Up @@ -179,8 +197,16 @@ void difftest_deferred_result(uint8_t result) {
}
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT

static uint8_t simv_result = SIMV_RUN;
#ifdef WITH_DRAMSIM3
extern "C" void simv_tick() {
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
if (simv_result == SIMV_FAIL || difftest == NULL)
return;
#else
if (difftest == NULL)
return;
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT
dramsim3_step();
}
#endif
Expand All @@ -196,7 +222,6 @@ void simv_finish() {
simMemory = nullptr;
}

static uint8_t simv_result = SIMV_RUN;
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
extern "C" void simv_nstep(uint8_t step) {
if (simv_result == SIMV_FAIL || difftest == NULL)
Expand Down

0 comments on commit 6f695c2

Please sign in to comment.