Skip to content

Commit

Permalink
trace: Add functionality to parse DMA trace (#71)
Browse files Browse the repository at this point in the history
* trace: Refactor and prepare for DMA trace generation

* bench: Refactor benchmarking utils to use JSON

* docs: Add trace and benchmarking utilities

* trace: Add functionality to parse DMA trace

* target: Align Verilator timescale with Questa

* target: Generate iDMA dependencies
  • Loading branch information
colluca authored Aug 10, 2024
1 parent 96e34a2 commit f0749fd
Show file tree
Hide file tree
Showing 33 changed files with 810 additions and 495 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ jobs:
- name: Build docs
run: make docs

#####################
# Python unit tests #
#####################

pytest:
name: Python unit tests
runs-on: ubuntu-22.04
container:
image: ghcr.io/pulp-platform/snitch_cluster:main
steps:
- uses: actions/checkout@v2
- name: Run pytest
run: pytest

##############################################
# Simulate SW on Snitch Cluster w/ Verilator #
##############################################
Expand All @@ -42,6 +56,7 @@ jobs:
- name: Build Hardware
working-directory: target/snitch_cluster
run: |
pip install -r $(bender path idma)/requirements.txt
make CFG_OVERRIDE=cfg/github-ci.hjson VLT_JOBS=1 bin/snitch_cluster.vlt
- name: Run Tests
working-directory: target/snitch_cluster
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
- name: Generate RTL sources
working-directory: target/snitch_cluster
run: |
pip install -r $(bender path idma)/requirements.txt
make rtl
# For some reason, the checkout is done by a different user,
# than that running `git diff` (root, possibly due to Docker).
Expand Down
17 changes: 13 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ variables:

before_script:
source iis-setup.sh
pip install $($BENDER path idma)/requirements.txt

##############
# Build docs #
Expand All @@ -24,6 +25,14 @@ docs:
script:
- make docs

#####################
# Python unit tests #
#####################

pytest:
script:
- pytest

#################################
# Build Snitch cluster software #
#################################
Expand Down Expand Up @@ -150,7 +159,7 @@ snitch-cluster-mchan-vsim:
# Non-free #
############

nonfree:
script:
- make nonfree
- make elab
# nonfree:
# script:
# - make nonfree
# - make elab
6 changes: 3 additions & 3 deletions Bender.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
dependencies:
- common_cells
axi:
revision: 41859549968db0147062b6c3cdbe4af00080cc09
revision: 4e54ac6766b160217a83a74d5a23af9bbf59e6ee
version: null
source:
Git: https://github.com/pulp-platform/axi
Expand Down Expand Up @@ -71,8 +71,8 @@ packages:
dependencies:
- common_cells
idma:
revision: c12caf59bb482fe44b27361f6924ad346b2d22fe
version: 0.6.3
revision: 0a0c113434aee743923d9e85631de009b4f00847
version: null
source:
Git: https://github.com/pulp-platform/iDMA
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion Bender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
tech_cells_generic: { git: https://github.com/pulp-platform/tech_cells_generic, version: 0.2.11 }
riscv-dbg: { git: https://github.com/pulp-platform/riscv-dbg, version: 0.8.0 }
cluster_icache: { git: https://github.com/pulp-platform/cluster_icache.git, version: 0.1.0 }
idma: { git: https://github.com/pulp-platform/iDMA, version: 0.6.3 }
idma: { git: https://github.com/pulp-platform/iDMA, rev: snitch-tracing }

export_include_dirs:
- hw/reqrsp_interface/include
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
############

NONFREE_REMOTE ?= git@iis-git.ee.ethz.ch:pulp-restricted/snitch-cluster-nonfree.git
NONFREE_COMMIT ?= e30961e20a23a76442da27d2ba07c9fe20f3b575
NONFREE_COMMIT ?= 214380a8c6af4cdd3d53a5b74cfaf462da877be2
NONFREE_DIR = $(ROOT)/nonfree

all: nonfree
Expand Down
1 change: 1 addition & 0 deletions docs/rm/bench/join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: join
1 change: 1 addition & 0 deletions docs/rm/bench/roi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: roi
1 change: 1 addition & 0 deletions docs/rm/bench/visualize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: visualize
1 change: 1 addition & 0 deletions docs/rm/trace/annotate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: annotate
1 change: 1 addition & 0 deletions docs/rm/trace/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: events
4 changes: 4 additions & 0 deletions docs/rm/trace/gen_trace.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<<<<<<< HEAD
::: gen_trace
=======
::: gen_trace
>>>>>>> c744477... trace: Refactor and prepare for DMA trace generation
1 change: 1 addition & 0 deletions hw/snitch_cluster/src/snitch_cc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ module snitch_cc #(
.NumAxInFlight (DMANumAxInFlight),
.DMAReqFifoDepth (DMAReqFifoDepth),
.NumChannels (DMANumChannels),
.DMATracing (1),
.axi_ar_chan_t (axi_ar_chan_t),
.axi_aw_chan_t (axi_aw_chan_t),
.axi_req_t (axi_req_t),
Expand Down
4 changes: 1 addition & 3 deletions iis-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ source .venv/bin/activate
# occurring when the /tmp folder is filled by other processes.
mkdir tmp
TMPDIR=tmp pip install -r python-requirements.txt
TMPDIR=tmp pip install -r $($BENDER path idma)/requirements.txt
rm -rf tmp

# Bender initialization
$BENDER vendor init

# Install spike-dasm
mkdir tools/
cd tools/
Expand Down
7 changes: 7 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ plugins:
paths:
- util/sim
- util/trace
- util/bench
- target/snitch_cluster/util
- macros:
on_error_fail: true
Expand Down Expand Up @@ -67,6 +68,12 @@ nav:
- rm/sim/Elf.md
- Trace Utilities:
- gen_trace.py: rm/trace/gen_trace.md
- annotate.py: rm/trace/annotate.md
- events.py: rm/trace/events.md
- Benchmarking Utilities:
- join.py: rm/bench/join.md
- roi.py: rm/bench/roi.md
- visualize.py: rm/bench/visualize.md
- Snitch Target Utilities:
- run.py: rm/snitch_target_utils/run.md
- build.py: rm/snitch_target_utils/build.md
Expand Down
17 changes: 10 additions & 7 deletions python-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Keep sorted.
bin2coe
dataclasses
editorconfig-checker==2.3.51
Expand All @@ -13,18 +14,20 @@ json5
jsonref
jsonschema
mako
matplotlib
mkdocs-material
progressbar2
tabulate
yamllint
pyyaml
pytablewriter
termcolor
pandas
prettytable
pyelftools
progressbar2
psutil
pyelftools
pyflexfloat
pytablewriter
pytest
pyyaml
tabulate
termcolor
yamllint

-r docs/requirements.txt
-r sw/dnn/requirements.txt
77 changes: 40 additions & 37 deletions target/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ ADDR2LINE ?= $(LLVM_BINROOT)/llvm-addr2line
GENTRACE_PY ?= $(UTIL_DIR)/trace/gen_trace.py
ANNOTATE_PY ?= $(UTIL_DIR)/trace/annotate.py
EVENTS_PY ?= $(UTIL_DIR)/trace/events.py
PERF_CSV_PY ?= $(UTIL_DIR)/trace/perf_csv.py
LAYOUT_EVENTS_PY ?= $(UTIL_DIR)/trace/layout_events.py
EVENTVIS_PY ?= $(UTIL_DIR)/trace/eventvis.py
JOIN_PY ?= $(UTIL_DIR)/bench/join.py
ROI_PY ?= $(UTIL_DIR)/bench/roi.py
VISUALIZE_PY ?= $(UTIL_DIR)/bench/visualize.py

# For some reason `$(VERILATOR_SEPP) which verilator` returns a
# a two-liner with the OS on the first line, hence the tail -n1
Expand All @@ -47,9 +47,8 @@ VLT_ROOT ?= ${VERILATOR_ROOT}
VLT_JOBS ?= $(shell nproc)
VLT_NUM_THREADS ?= 1

MATCH_END := '/+incdir+/ s/$$/\/*\/*/'
MATCH_BGN := 's/+incdir+//g'
SED_SRCS := sed -e ${MATCH_END} -e ${MATCH_BGN}
MATCH_REMOVE := 's/+incdir+\/[^ ]*//g'
SED_SRCS := sed -e ${MATCH_REMOVE}

COMMON_BENDER_FLAGS += -t rtl

Expand Down Expand Up @@ -79,6 +78,7 @@ VLT_SOURCES = $(shell ${BENDER} script flist ${VLT_BENDER} | ${SED_SRCS})
VLT_BUILDDIR := $(abspath work-vlt)
VLT_FESVR = $(VLT_BUILDDIR)/riscv-isa-sim
VLT_FLAGS += --timing
VLT_FLAGS += --timescale 1ns/1ps
VLT_FLAGS += -Wno-BLKANDNBLK
VLT_FLAGS += -Wno-LITENDIAN
VLT_FLAGS += -Wno-CASEINCOMPLETE
Expand Down Expand Up @@ -199,28 +199,34 @@ endef
# Traces #
##########

DASM_TRACES = $(shell (ls $(LOGS_DIR)/trace_hart_*.dasm 2>/dev/null))
TXT_TRACES = $(shell (echo $(DASM_TRACES) | sed 's/\.dasm/\.txt/g'))
PERF_TRACES = $(shell (echo $(DASM_TRACES) | sed 's/trace_hart/hart/g' | sed 's/.dasm/_perf.json/g'))
ANNOTATED_TRACES = $(shell (echo $(DASM_TRACES) | sed 's/\.dasm/\.s/g'))
DIFF_TRACES = $(shell (echo $(DASM_TRACES) | sed 's/\.dasm/\.diff/g'))

GENTRACE_OUTPUTS = $(TXT_TRACES) $(PERF_TRACES)
ANNOTATE_OUTPUTS = $(ANNOTATED_TRACES)
PERF_CSV = $(LOGS_DIR)/perf.csv
EVENT_CSV = $(LOGS_DIR)/event.csv
TRACE_CSV = $(LOGS_DIR)/trace.csv
TRACE_JSON = $(LOGS_DIR)/trace.json

.PHONY: traces annotate perf-csv event-csv layout
traces: $(GENTRACE_OUTPUTS)
annotate: $(ANNOTATE_OUTPUTS)
perf-csv: $(PERF_CSV)
event-csv: $(EVENT_CSV)
layout: $(TRACE_CSV) $(TRACE_JSON)

$(LOGS_DIR)/trace_hart_%.txt $(LOGS_DIR)/hart_%_perf.json: $(LOGS_DIR)/trace_hart_%.dasm $(GENTRACE_PY)
$(DASM) < $< | $(GENTRACE_PY) --permissive -d $(LOGS_DIR)/hart_$*_perf.json > $(LOGS_DIR)/trace_hart_$*.txt
SNITCH_DASM_TRACES = $(shell (ls $(LOGS_DIR)/trace_hart_*.dasm 2>/dev/null))
SNITCH_TXT_TRACES = $(shell (echo $(SNITCH_DASM_TRACES) | sed 's/\.dasm/\.txt/g'))
SNITCH_ANNOTATED_TRACES = $(shell (echo $(SNITCH_DASM_TRACES) | sed 's/\.dasm/\.s/g'))
SNITCH_PERF_DUMPS = $(shell (echo $(SNITCH_DASM_TRACES) | sed 's/trace_hart/hart/g' | sed 's/.dasm/_perf.json/g'))

TXT_TRACES += $(SNITCH_TXT_TRACES)
ANNOTATED_TRACES += $(SNITCH_ANNOTATED_TRACES)
PERF_DUMPS += $(SNITCH_PERF_DUMPS)
JOINT_PERF_DUMP = $(LOGS_DIR)/perf.json
ROI_DUMP = $(LOGS_DIR)/roi.json
VISUAL_TRACE = $(LOGS_DIR)/trace.json

.PHONY: traces annotate visual-trace clean-traces clean-annotate clean-perf clean-visual-trace
traces: $(TXT_TRACES)
annotate: $(ANNOTATED_TRACES)
perf: $(JOINT_PERF_DUMP)
visual-trace: $(VISUAL_TRACE)
clean-traces:
rm -f $(TXT_TRACES)
clean-annotate:
rm -f $(ANNOTATED_TRACES)
clean-perf:
rm -f $(PERF_DUMPS) $(JOINT_PERF_DUMP)
clean-visual-trace:
rm -f $(VISUAL_TRACE)

$(addprefix $(LOGS_DIR)/,trace_hart_%.txt hart_%_perf.json dma_%_perf.json): $(LOGS_DIR)/trace_hart_%.dasm $(GENTRACE_PY)
$(DASM) < $< | $(GENTRACE_PY) --permissive --dma-trace $(SIM_DIR)/dma_trace_$*_00000.log --dump-hart-perf $(LOGS_DIR)/hart_$*_perf.json --dump-dma-perf $(LOGS_DIR)/dma_$*_perf.json -o $(LOGS_DIR)/trace_hart_$*.txt

# Generate source-code interleaved traces for all harts. Reads the binary from
# the logs/.rtlbinary file that is written at start of simulation in the vsim script
Expand All @@ -230,14 +236,11 @@ $(LOGS_DIR)/trace_hart_%.s: $(LOGS_DIR)/trace_hart_%.txt ${ANNOTATE_PY}
$(LOGS_DIR)/trace_hart_%.diff: $(LOGS_DIR)/trace_hart_%.txt ${ANNOTATE_PY}
${ANNOTATE_PY} ${ANNOTATE_FLAGS} -o $@ $(BINARY) $< -d

$(PERF_CSV): $(PERF_TRACES) $(PERF_CSV_PY)
$(PERF_CSV_PY) -o $@ -i $(PERF_TRACES)
$(JOINT_PERF_DUMP): $(PERF_DUMPS) $(JOIN_PY)
$(JOIN_PY) -i $(shell ls $(LOGS_DIR)/*_perf.json) -o $@

$(EVENT_CSV): $(PERF_TRACES) $(PERF_CSV_PY)
$(PERF_CSV_PY) -o $@ -i $(PERF_TRACES) --filter tstart tend
$(ROI_DUMP): $(JOINT_PERF_DUMP) $(ROI_SPEC) $(ROI_PY)
$(ROI_PY) $(JOINT_PERF_DUMP) $(ROI_SPEC) --cfg $(CFG) -o $@

$(TRACE_CSV): $(EVENT_CSV) $(LAYOUT_FILE) $(LAYOUT_EVENTS_PY)
$(LAYOUT_EVENTS_PY) $(LAYOUT_EVENTS_FLAGS) $(EVENT_CSV) $(LAYOUT_FILE) -o $@

$(TRACE_JSON): $(TRACE_CSV) $(EVENTVIS_PY)
$(EVENTVIS_PY) -o $@ $(TRACE_CSV)
$(VISUAL_TRACE): $(ROI_DUMP) $(VISUALIZE_PY)
$(VISUALIZE_PY) $(ROI_DUMP) --traces $(SNITCH_TXT_TRACES) --elf $(BINARY) -o $@
10 changes: 10 additions & 0 deletions target/snitch_cluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,19 @@ include $(ROOT)/target/snitch_cluster/sw.mk
# RTL #
#######

# Include iDMA Makefile to generate prerequisite iDMA sources
include $(shell $(BENDER) path idma)/idma.mk

GENERATED_RTL_SOURCES = $(PERIPH_DIR)/snitch_cluster_peripheral_reg_top.sv
GENERATED_RTL_SOURCES += $(PERIPH_DIR)/snitch_cluster_peripheral_reg_pkg.sv
GENERATED_RTL_SOURCES += $(GENERATED_DIR)/snitch_cluster_wrapper.sv
GENERATED_RTL_SOURCES += $(IDMA_ROOT)/target/rtl/idma_inst64_top.sv
GENERATED_RTL_SOURCES += $(IDMA_ROOT)/target/rtl/include/idma/tracer.svh

# Add dependency on DMA header files
VSIM_SOURCES += $(IDMA_ROOT)/target/rtl/include/idma/tracer.svh
VLT_SOURCES += $(IDMA_ROOT)/target/rtl/include/idma/tracer.svh
VCS_SOURCES += $(IDMA_ROOT)/target/rtl/include/idma/tracer.svh

.PHONY: rtl clean-rtl

Expand Down
Empty file added util/bench/__init__.py
Empty file.
Loading

0 comments on commit f0749fd

Please sign in to comment.