Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for preloading #104

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# the MAGICK_ROOT variable can be used to pass an alternative installation
# prefix for the GraphicsMagick library.
ifdef MAGICK_ROOT
export MAGICK_ROOT := $(realpath $(MAGICK_ROOT))
endif

SHELL=bash

ifndef PULP_SDK_HOME
Expand Down
2 changes: 1 addition & 1 deletion tools/dpi-models/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VSIM_DETECTED_PATH=$(dir $(shell which vsim))
BUILD_DIR ?= build

CFLAGS += -std=gnu++11 -MMD -MP -O3 -g
CFLAGS += -std=c++11 -MMD -MP -O3 -g

CFLAGS += -I$(INSTALL_DIR)/include -fPIC
LDFLAGS += -L$(INSTALL_DIR)/lib -fPIC -shared -O3 -g -ljson
Expand Down
16 changes: 13 additions & 3 deletions tools/dpi-models/models/camera/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ DPI_MODELS += camera

camera_SRCS = camera/camera.cpp

MAGICK=$(shell pkg-config --exists GraphicsMagick --atleast-version=1.3.23 || echo FAILED)
MAGICK_PKG_CFG_CMD := pkg-config
ifdef MAGICK_ROOT
# MAGICK_ROOT can be set to specify the root directory (containing e.g. /lib/,
# /include/ etc) where GraphicsMagick was installed from source
MAGICK_PKG_CFG_PATH := $(MAGICK_ROOT)/lib/pkgconfig:$(PKG_CONFIG_PATH)
camera_CFLAGS += -Wl,-rpath=$(MAGICK_ROOT)/lib
MAGICK_PKG_CFG_CMD := PKG_CONFIG_PATH=$(MAGICK_PKG_CFG_PATH) pkg-config
endif

MAGICK=$(shell $(MAGICK_PKG_CFG_CMD) --exists GraphicsMagick --atleast-version=1.3.23 || echo FAILED)


ifeq '$(MAGICK)' ''
camera_CFLAGS += $(shell pkg-config GraphicsMagick --cflags)
camera_CFLAGS += $(shell $(MAGICK_PKG_CFG_CMD) GraphicsMagick++ --cflags)
camera_CFLAGS += -D__MAGICK__
camera_LDFLAGS += -lGraphicsMagick++ -lGraphicsMagick
camera_LDFLAGS := $(shell $(MAGICK_PKG_CFG_CMD) GraphicsMagick++ --libs)
#LDFLAGS += $(shell Magick++-config --ldflags)
endif
4 changes: 4 additions & 0 deletions tools/gapy/runner/rtl/chips/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def __init__(self, args, config):
if os.environ.get('QUESTA_CXX') is not None:
self.set_arg('-dpicpppath ' + os.environ.get('QUESTA_CXX'))

if os.environ.get('bootmode') is not None:
if os.environ.get('bootmode') == "preload":
self.set_arg('-gLOAD_L2=PRELOAD')

self.set_arg('-permit_unmatched_virtual_intf')
self.set_arg('+preload_file=efuse_preload.data')
self.set_arg('-gBAUDRATE=115200')
Expand Down
54 changes: 51 additions & 3 deletions tools/gapy/runner/rtl/rtl_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import errors
import argparse
import json_tools as js
import json
try:
import gv.gvsoc
except:
Expand Down Expand Up @@ -152,6 +153,10 @@ def exec(self):
self.__create_symlink(plt_path, 'tcl_files')
self.__create_symlink(plt_path, 'waves')
self.__create_symlink(plt_path, 'models')
try:
self.__create_symlink(plt_path, 'mem.json')
except:
pass
self.__create_symlink(plt_path, 'ips_inputs')

else:
Expand Down Expand Up @@ -213,8 +218,7 @@ def gen_stim_txt(self):
binary = self.config.get_str('runner/boot-loader')

self.gen_stim_slm_64('vectors/stim.txt', [binary])


self.gen_stim_mem('vectors/stim.txt', [binary], )

def __gen_stim_slm(self, filename, width):

Expand All @@ -230,6 +234,38 @@ def __gen_stim_slm(self, filename, width):
file.write('%X_%0*X\n' % (int(key), width*2, self.mem.get(key)))


def __gen_stim_mem(self, filename, mem_dict):

for mem_ in mem_dict.keys():
self.dump(' Generating to file: ' + mem_ + ".mem")

try:
os.makedirs(os.path.dirname(filename))
except:
pass

with open(os.path.dirname(filename) + "/" + mem_ + ".mem", 'w') as file:

file.write("""// memory data file (do not edit the following line - required for mem load use)
// instance=%s
// format=hex addressradix=h dataradix=h version=1.0 wordsperline=1\n""" % (mem_dict[mem_]['instance']))

base_ = int(mem_dict[mem_]['base'], 16)

for key in sorted(self.mem.keys()):
if not (int(key) >= base_ and int(key) < base_+int(mem_dict[mem_]['length'])):
continue

addr_ = (int(key) - base_) / 4
if not mem_dict[mem_]['interleaving'] == "None":
bank_ = addr_ % int(mem_dict[mem_]['interleaving'])
if bank_ != int(mem_dict[mem_]['interleaving_bank']):
continue
addr_ = addr_ / int(mem_dict[mem_]['interleaving'])

data_ = self.mem.get(key)
file.write('@%x %08x\n' % (addr_, data_))


def __add_mem_word(self, base, size, data, width):

Expand Down Expand Up @@ -311,6 +347,18 @@ def gen_stim_slm_64(self, stim_file, binaries):

self.__gen_stim_slm(stim_file, 8)

def gen_stim_mem(self, stim_file, binaries):

self.__parse_binaries(4, binaries)

try:
with open(self.platform_path + "/mem.json", "r") as fp:
mem_dict = json.load(fp)
except:
mem_dict = None
if mem_dict is not None:
self.__gen_stim_mem(stim_file, mem_dict)


def __process_args(self):
if self.args.gui:
Expand Down Expand Up @@ -407,4 +455,4 @@ def set_cmd_arg(self, arg):
self.cmd_args.append(arg)

def get_args(self):
return self.plt_args
return self.plt_args
6 changes: 3 additions & 3 deletions tools/gvsoc/common/dpi-wrapper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ DPI_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/dpi/%.o,$(patsubst %.c,$(BUILD_DIR)/dpi

$(BUILD_DIR)/dpi/%.o: %.cpp
@mkdir -p $(basename $@)
g++ $(DPI_CFLAGS) -o $@ -c $<
$(CXX) $(DPI_CFLAGS) -o $@ -c $<

$(BUILD_DIR)/dpi/%.o: %.c
@mkdir -p $(basename $@)
g++ $(DPI_CFLAGS) -o $@ -c $<
$(CXX) $(DPI_CFLAGS) -o $@ -c $<

$(BUILD_DIR)/libgvsocdpi.so: $(DPI_OBJS)
@mkdir -p $(basename $@)
g++ -o $@ $^ $(DPI_LDFLAGS)
$(CXX) -o $@ $^ $(DPI_LDFLAGS)

clean:
rm -rf $(BUILD_DIR)
Expand Down
24 changes: 12 additions & 12 deletions tools/gvsoc/common/engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ifndef VERBOSE
V = @
endif

CC = g++
# CC = g++

CFLAGS += -MMD -MP -O2 -g -fpic -Isrc -std=c++11 -Werror -Wall -I$(INSTALL_DIR)/include

Expand Down Expand Up @@ -53,58 +53,58 @@ endef
$(ENGINE_BUILD_DIR)/%.o: src/%.c
@echo "CXX $<"
@mkdir -p $(basename $@)
$(V)$(CC) $(CFLAGS) -o $@ -c $<
$(V)$(CXX) $(CFLAGS) -o $@ -c $<

$(ENGINE_BUILD_DIR)/%.o: src/%.cpp
@echo "CXX $<"
@mkdir -p $(basename $@)
$(V)$(CC) $(CFLAGS) -o $@ -c $<
$(V)$(CXX) $(CFLAGS) -o $@ -c $<

$(ENGINE_BUILD_DIR)/dbg/%.o: src/%.c
@echo "CXX DBG $<"
@mkdir -p $(basename $@)
$(V)$(CC) $(CFLAGS) $(CFLAGS_DBG) -o $@ -c $<
$(V)$(CXX) $(CFLAGS) $(CFLAGS_DBG) -o $@ -c $<

$(ENGINE_BUILD_DIR)/dbg/%.o: src/%.cpp
@echo "CXX DBG $<"
@mkdir -p $(basename $@)
$(V)$(CC) $(CFLAGS) $(CFLAGS_DBG) -o $@ -c $<
$(V)$(CXX) $(CFLAGS) $(CFLAGS_DBG) -o $@ -c $<

$(ENGINE_BUILD_DIR)/sv/%.o: src/%.c
@echo "CXX SV $<"
@mkdir -p $(basename $@)
$(V)$(CC) $(CFLAGS) $(CFLAGS_SV) -o $@ -c $<
$(V)$(CXX) $(CFLAGS) $(CFLAGS_SV) -o $@ -c $<

$(ENGINE_BUILD_DIR)/sv/%.o: src/%.cpp
@echo "CXX SV $<"
@mkdir -p $(basename $@)
$(V)$(CC) $(CFLAGS) $(CFLAGS_SV) -o $@ -c $<
$(V)$(CXX) $(CFLAGS) $(CFLAGS_SV) -o $@ -c $<

$(ENGINE_BUILD_DIR)/libpulpvp.so: $(VP_OBJS)
@echo "CXX $<"
@mkdir -p $(basename $@)
$(V)$(CC) $^ -o $@ $(LDFLAGS) -shared -ldl -lpthread
$(V)$(CXX) $^ -o $@ $(LDFLAGS) -shared -ldl -lpthread


$(ENGINE_BUILD_DIR)/libpulpvp-debug.so: $(VP_DBG_OBJS)
@echo "CXX DBG $<"
@mkdir -p $(basename $@)
$(V)$(CC) $^ -o $@ $(LDFLAGS) -shared -ldl -lpthread
$(V)$(CXX) $^ -o $@ $(LDFLAGS) -shared -ldl -lpthread

$(ENGINE_BUILD_DIR)/libpulpvp-sv.so: $(VP_SV_OBJS)
@echo "CXX SV $<"
@mkdir -p $(basename $@)
$(V)$(CC) $^ -o $@ $(LDFLAGS) -shared -ldl -lpthread
$(V)$(CXX) $^ -o $@ $(LDFLAGS) -shared -ldl -lpthread

$(ENGINE_BUILD_DIR)/gvsoc_launcher: $(ENGINE_BUILD_DIR)/main.o $(INSTALL_DIR)/lib/libpulpvp.so
@echo "CXX $<"
@mkdir -p `dirname $@`
$(V)$(CC) $(ENGINE_BUILD_DIR)/main.o -o $@ $(LDFLAGS) -lpthread -ldl -lpulpvp
$(V)$(CXX) $(ENGINE_BUILD_DIR)/main.o -o $@ $(LDFLAGS) -lpthread -ldl -lpulpvp

$(ENGINE_BUILD_DIR)/gvsoc_launcher_debug: $(ENGINE_BUILD_DIR)/dbg/main.o $(INSTALL_DIR)/lib/libpulpvp-debug.so
@echo "CXX DBG $<"
@mkdir -p `dirname $@`
$(V)$(CC) $(ENGINE_BUILD_DIR)/dbg/main.o -o $@ $(LDFLAGS) -lpthread -ldl -lpulpvp-debug
$(V)$(CXX) $(ENGINE_BUILD_DIR)/dbg/main.o -o $@ $(LDFLAGS) -lpthread -ldl -lpulpvp-debug


$(foreach file, $(VP_HEADERS), $(eval $(call declareInstallFile,$(file))))
Expand Down
6 changes: 3 additions & 3 deletions tools/gvsoc/common/examples/launcher/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BUILD_DIR ?= $(CURDIR)/build

CC = g++
# CC = g++

CFLAGS += -MMD -MP -O2 -g -std=c++11 -Werror -Wall -I$(INSTALL_DIR)/include
LDFLAGS += -O2 -g -Werror -Wall -L$(INSTALL_DIR)/lib -lpulpvp-debug
Expand All @@ -12,11 +12,11 @@ all: $(BUILD_DIR)/launcher

$(BUILD_DIR)/%.o: %.cpp
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ -c $<
$(CXX) $(CFLAGS) -o $@ -c $<

$(BUILD_DIR)/launcher: $(OBJS)
mkdir -p $(dir $@)
$(CC) $^ -o $@ $(LDFLAGS)
$(CXX) $^ -o $@ $(LDFLAGS)

clean:
rm -rf $(BUILD_DIR)
Expand Down
8 changes: 4 additions & 4 deletions tools/gvsoc/common/launcher/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LAUNCHER_BUILD_DIR = $(ROOT_VP_BUILD_DIR)/launcher
-include $(INSTALL_DIR)/rules/vp_models.mk


CC = g++
# CC = g++

CFLAGS += -MMD -MP -O2 -g -fpic -std=c++11 -Werror -Wall -I$(INSTALL_DIR)/include
LDFLAGS += -O2 -g -shared -Werror -Wall -L$(INSTALL_DIR)/lib -Wl,--whole-archive -ljson -Wl,--no-whole-archive
Expand All @@ -30,15 +30,15 @@ endef

$(LAUNCHER_BUILD_DIR)/%.o: src/%.c
@mkdir -p $(basename $@)
$(CC) $(CFLAGS) -o $@ -c $<
$(CXX) $(CFLAGS) -o $@ -c $<

$(LAUNCHER_BUILD_DIR)/%.o: src/%.cpp
@mkdir -p $(basename $@)
$(CC) $(CFLAGS) -o $@ -c $<
$(CXX) $(CFLAGS) -o $@ -c $<

$(LAUNCHER_BUILD_DIR)/libpulpvplauncher.so: $(LAUNCHER_OBJS)
@mkdir -p $(basename $@)
$(CC) $^ -o $@ $(LDFLAGS)
$(CXX) $^ -o $@ $(LDFLAGS)



Expand Down
2 changes: 1 addition & 1 deletion tools/gvsoc/common/models/cpu/iss/Makefile.sa
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $(BUILD_DIR)/riscy_decoder_gen.cpp: isa_gen/isa_riscv_gen.py isa_gen/isa_gen.py
isa_gen/isa_riscv_gen.py --source-file=$(BUILD_DIR)/riscy_decoder_gen.cpp --header-file=$(BUILD_DIR)/riscy_decoder_gen.hpp

$(BUILD_DIR)/pulp_iss: $(SA_ISS_SRCS)
g++ -o $@ $^ $(SA_ISS_CFLAGS) $(SA_ISS_LDFLAGS)
$(CXX) -o $@ $^ $(SA_ISS_CFLAGS) $(SA_ISS_LDFLAGS)

$(INSTALL_DIR)/bin/pulp_iss: $(BUILD_DIR)/pulp_iss

Expand Down
5 changes: 3 additions & 2 deletions tools/gvsoc/common/vp_models.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ VP_PY_INSTALL_PATH ?= $(INSTALL_DIR)/python

VP_MAKEFILE_LIST = $(addsuffix /Makefile,$(VP_DIRS))

CPP=g++
CC=gcc
# CPP=g++
CPP = $(CXX)
# CC=gcc

ifndef VERBOSE
V = @
Expand Down
7 changes: 6 additions & 1 deletion tools/gvsoc/pulp/models/pulp/ne16/src/ne16_streamin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ void Ne16::constant_setup() {

void Ne16::streamin_setup() {

auto base_addr_streamin = this->outfeat_ptr + (this->i_major*this->FILTER_SIZE*this->w_out*this->k_out + this->j_major*this->FILTER_SIZE*this->k_out + this->k_out_major*this->TP_OUT) * 4;
auto tp = this->depthwise ? this->TP_IN : this->TP_OUT;

auto outfeat_hom_iter = this->FILTER_SIZE * this->outfeat_d2_stride;
auto outfeat_wom_iter = this->FILTER_SIZE * this->outfeat_d1_stride;

auto base_addr_streamin = this->outfeat_ptr + this->i_major*outfeat_hom_iter + this->j_major*outfeat_wom_iter + this->k_out_major*tp*this->quantization_bits/8;

auto k_out_lim = this->depthwise ? 1 :
(this->k_out_major == this->subtile_nb_ko-1 && this->subtile_rem_ko != this->TP_OUT && this->subtile_rem_ko != 0) ? this->subtile_rem_ko : this->TP_OUT;
Expand Down
5 changes: 4 additions & 1 deletion tools/gvsoc/pulp/models/pulp/ne16/src/ne16_streamout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ void Ne16::streamout_setup() {

auto tp = this->depthwise ? this->TP_IN : this->TP_OUT;

auto base_addr_y = this->outfeat_ptr + (this->i_major*this->FILTER_SIZE*this->w_out*this->k_out + this->j_major*this->FILTER_SIZE*this->k_out + this->k_out_major*tp) * this->quantization_bits/8;
auto outfeat_hom_iter = this->FILTER_SIZE * this->outfeat_d2_stride;
auto outfeat_wom_iter = this->FILTER_SIZE * this->outfeat_d1_stride;

auto base_addr_y = this->outfeat_ptr + this->i_major*outfeat_hom_iter + this->j_major*outfeat_wom_iter + this->k_out_major*tp*this->quantization_bits/8;

auto streamout_k_out_lim = !this->depthwise ? this->mv_k_out_lim : (this->k_out_major == this->subtile_nb_ko-1 && this->subtile_rem_ko != this->TP_IN && this->subtile_rem_ko != 0) ? this->subtile_rem_ko : this->TP_IN;
;
Expand Down
4 changes: 2 additions & 2 deletions tools/pulp-debug-bridge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ install:

$(BUILD_DIR)/%.o: %.cpp
@mkdir -p $(basename $@)
g++ $(CFLAGS) -o $@ -c $<
$(CXX) $(CFLAGS) -o $@ -c $<

$(BUILD_DIR)/libpulpdebugbridge.so: $(OBJS)
g++ -o $@ $^ $(LDFLAGS)
$(CXX) -o $@ $^ $(LDFLAGS)

$(INSTALL_DIR)/lib/libpulpdebugbridge.so: $(BUILD_DIR)/libpulpdebugbridge.so
install -D $< $@
Expand Down