Skip to content

Commit

Permalink
support custom benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
donggyukim committed May 12, 2018
1 parent 34ecf15 commit 285b67d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
generated-src
outputs
test_run_dir
target
project/target
*.key
*.log
*.swp
*.out
.ivy2
VTile
dump.vcd*
Expand Down
30 changes: 26 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default: compile
base_dir = $(abspath .)
src_dir = $(base_dir)/src/main
gen_dir = $(base_dir)/generated-src
out_dir = $(base_dir)/outputs

SBT = sbt
SBT_FLAGS = -ivy $(base_dir)/.ivy2
Expand All @@ -17,6 +18,7 @@ $(gen_dir)/Tile.v: $(wildcard $(src_dir)/scala/*.scala)

CXXFLAGS += -std=c++11 -Wall -Wno-unused-variable

# compile verilator
VERILATOR = verilator --cc --exe
VERILATOR_FLAGS = --assert -Wno-STMTDLY -O3 --trace \
--top-module Tile -Mdir $(gen_dir)/VTile.csrc \
Expand All @@ -28,16 +30,36 @@ $(base_dir)/VTile: $(gen_dir)/Tile.v $(src_dir)/cc/top.cc $(src_dir)/cc/mm.cc $(

verilator: $(base_dir)/VTile

%.out: $(base_dir)/VTile $(base_dir)/src/test/resources/%.hex
$^ 2> $@
# isa tests + benchmarks with verilator
test_hex_files = $(wildcard $(base_dir)/src/test/resources/*.hex)
test_out_files = $(foreach f,$(test_hex_files),$(patsubst %.hex,%.out,$(out_dir)/$(notdir $f)))

$(test_out_files): $(out_dir)/%.out: $(base_dir)/VTile $(base_dir)/src/test/resources/%.hex
mkdir -p $(out_dir)
$^ $(patsubst %.out,%.vcd,$@) 2> $@

run-tests: $(test_out_files)

# run custom benchamrk
custom_bmark_hex ?= $(base_dir)/custom-bmark/main.hex
custom_bmark_out = $(patsubst %.hex,%.out,$(out_dir)/$(notdir $(custom_bmark_hex)))
$(custom_bmark_hex):
$(MAKE) -C custom-bmark

$(custom_bmark_out): $(base_dir)/VTile $(custom_bmark_hex)
mkdir -p $(out_dir)
$^ $(patsubst %.out,%.vcd,$@) 2> $@

run-custom-bmark: $(custom_bmark_out)

# unit tests + integration tests
test:
$(SBT) $(SBT_FLAGS) test

clean:
rm -rf $(gen_dir) test_run_dir
rm -rf $(gen_dir) $(out_dir) test_run_dir

cleanall: clean
rm -rf target project/target

.PHONY: sbt compile test verilator clean cleanall
.PHONY: sbt compile verilator run-tests run-custom-bmark test clean cleanall
4 changes: 4 additions & 0 deletions custom-bmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
main
*.o
*.hex
*.dump
45 changes: 45 additions & 0 deletions custom-bmark/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
base_dir = $(abspath ..)

# For custom benchmarks
RISCV_TEST_DIR ?= $(base_dir)/riscv-tools-priv1.7/riscv-tests
CUSTOM_BMARK_BIN ?= main
CUSTOM_BMARK_C_SRC ?= main.c syscalls.c
CUSTOM_BMARK_S_SRC ?= add.S crt.S

CUSTOM_BMARK_OBJS := \
$(foreach f,$(CUSTOM_BMARK_C_SRC),$(patsubst %.c,%.o,$f)) \
$(foreach f,$(CUSTOM_BMARK_S_SRC),$(patsubst %.S,%.o,$f))

riscv_bmark_dir = $(RISCV_TEST_DIR)/benchmarks

RISCV_GCC = riscv32-unknown-elf-gcc
RISCV_CFLAGS = -static -std=gnu99 -fno-common -fno-builtin-printf \
-I$(RISCV_TEST_DIR)/env -I$(RISCV_TEST_DIR)/benchmarks/common
RISCV_LDFLAGS = -T $(RISCV_TEST_DIR)/benchmarks/common/test.ld \
-I$(RISCV_TEST_DIR)/env -I$(RISCV_TEST_DIR)/benchmarks/common

VPATH += $(RISCV_TEST_DIR)/benchmarks/common

all: $(CUSTOM_BMARK_BIN) $(CUSTOM_BMARK_BIN).hex $(CUSTOM_BMARK_BIN).dump

%.o: %.c
$(RISCV_GCC) $(RISCV_CFLAGS) -c -o $@ $<

%.o: %.S
$(RISCV_GCC) $(RISCV_CFLAGS) -D__ASSEMBLY__=1 -c -o $@ $<

$(CUSTOM_BMARK_BIN): $(CUSTOM_BMARK_OBJS)
$(RISCV_GCC) $(RISCV_LDFLAGS) -o $@ $^ -nostdlib -nostartfiles -lc -lgcc

%.hex: %
elf2hex 16 32768 $< > $@

%.dump: %
riscv32-unknown-elf-objdump \
--disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data \
$< > $@

clean:
rm -rf *.o $(CUSTOM_BMARK_BIN) $(CUSTOM_BMARK_BIN).hex $(CUSTOM_BMARK_BIN).dump

.PHONY: all clean
9 changes: 9 additions & 0 deletions custom-bmark/add.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.text
.align 2

.globl add
.type add,@function

add:
add a0, a0, a1
ret
6 changes: 6 additions & 0 deletions custom-bmark/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int add(int a, int b);

int main(int argc, char** argv) {
int res = add(3, 2);
return res == 5 ? 0 : -1;
}
2 changes: 1 addition & 1 deletion src/main/cc/top.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main(int argc, char** argv) {
VL_PRINTF("Enabling waves...\n");
tfp = new VerilatedVcdC;
top->trace(tfp, 99); // Trace 99 levels of hierarchy
tfp->open("dump.vcd"); // Open the dump file
tfp->open(argc > 2 ? argv[2] : "dump.vcd"); // Open the dump file
#endif

cout << "Starting simulation!\n";
Expand Down

0 comments on commit 285b67d

Please sign in to comment.