Skip to content

Commit

Permalink
adding simple test + full Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvatore Girolamo committed Apr 30, 2021
1 parent 71648c3 commit 5bfe6bd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 43 deletions.
3 changes: 1 addition & 2 deletions examples/empty/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ int main(int argc, char**argv)

gdriver_run();

gdriver_fini();
return 0;
return (gdriver_fini()) ? EXIT_SUCCESS : EXIT_FAILURE;
}
13 changes: 12 additions & 1 deletion examples/generic_driver/gdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ typedef struct sim_descr
void *l2_img_to_copy;
size_t l2_img_to_copy_size;

// counters
uint32_t packets_sent;
uint32_t packets_processed;
} sim_descr_t;

static sim_descr_t sim_state;
Expand Down Expand Up @@ -125,6 +128,7 @@ int make_ec()
}
}


void generate_packets()
{
spin_ec_t ec;
Expand Down Expand Up @@ -155,6 +159,7 @@ void generate_packets()
bool is_last = (pkt_idx + 1 == sim_state.num_packets);
uint32_t delay = (is_last) ? sim_state.message_delay : sim_state.packet_delay;
pspinsim_packet_add(&(sim_state.ec), msg_idx, pkt_buff, pkt_size, l1_pkt_size, is_last, delay, 0);
sim_state.packets_sent++;
}
}

Expand All @@ -169,6 +174,11 @@ void pcie_mst_write_complete(void *user_ptr)
generate_packets();
}

void feedback(uint64_t user_ptr, uint64_t nic_arrival_time, uint64_t pspin_arrival_time, uint64_t feedback_time)
{
sim_state.packets_processed++;
}

/*** interface ***/

int gdriver_set_packet_fill_callback(fill_packet_fun_t pkt_fill_fun)
Expand Down Expand Up @@ -200,6 +210,7 @@ int gdriver_init(int argc, char **argv, const char *hfile, const char *hh, const
pspinsim_init(argc, argv, &conf);

pspinsim_cb_set_pcie_mst_write_completion(pcie_mst_write_complete);
pspinsim_cb_set_pkt_feedback(feedback);

memset(&sim_state, 0, sizeof(sim_state));

Expand Down Expand Up @@ -258,6 +269,6 @@ int gdriver_run()
int gdriver_fini()
{
if (pspinsim_fini() == SPIN_SUCCESS)
return GDRIVER_OK;
return sim_state.packets_sent == sim_state.packets_processed;
return GDRIVER_ERR;
}
20 changes: 12 additions & 8 deletions examples/generic_driver/gdriver.mk
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
all::
make deploy
make driver
make driver_debug

../generic_driver/gdriver_args.c: ../generic_driver/gdriver_args.ggo
gengetopt -i ../generic_driver/gdriver_args.ggo -F gdriver_args --output-dir=../generic_driver/

driver: driver/driver.c ../generic_driver/gdriver_args.c
driver: driver/driver.c ../generic_driver/gdriver_args.c ../generic_driver/gdriver.c
gcc -std=c99 -I../generic_driver/ -I$(PSPIN_RT)/runtime/include/ -I$(PSPIN_HW)/verilator_model/include driver/driver.c ../generic_driver/gdriver.c ../generic_driver/gdriver_args.c -L$(PSPIN_HW)/verilator_model/lib/ -lpspin -o sim_${SPIN_APP_NAME}

driver_debug: driver/driver.c ../generic_driver/gdriver_args.c
gcc -g -std=c99 -I../generic_driver/ -I$(PSPIN_RT)/runtime/include/ -I$(PSPIN_HW)/verilator_model/include driver/driver.c ../generic_driver/gdriver.c ../generic_driver/gdriver_args.c -L$(PSPIN_HW)/verilator_model/lib/ -lpspin_debug -o sim_${SPIN_APP_NAME}_debug


all::
make deploy
make driver
make driver_debug

clean::
-@rm *.log 2>/dev/null || true
-@rm -r build/ 2>/dev/null || true
-@rm -r waves.vcd 2>/dev/null || true
-@rm sim_${SPIN_APP_NAME} 2>/dev/null || true
-@rm sim_${SPIN_APP_NAME}_debug 2>/dev/null || true
-@rm sim_${SPIN_APP_NAME}_debug 2>/dev/null || true

run::
./sim_${SPIN_APP_NAME}

.PHONY: driver driver_debug clean run
28 changes: 2 additions & 26 deletions hw/verilator_model/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ PSPIN_VERSION ?= undef
VERILATOR_CMD ?= verilator
VERILATOR_CC=$(VERILATOR_BIN)$(VERILATOR_CMD)
TOP_MODULE=pspin_verilator
SIM_EXE_SRCS=src/main.cpp
SIM_LIB_SRCS=src/pspinsim.cpp

TRACE_DEPTH?=6
Expand Down Expand Up @@ -236,39 +235,16 @@ SV_SRCS=../deps/axi/src/axi_pkg.sv \

.PHONY: archive

lib/libpspin_debug.so:
debug:
$(VERILATOR_CC) $(VFLAGS_DEBUG) $(SV_INC) -cc $(SV_SRCS) --top-module $(TOP_MODULE) --build $(SIM_LIB_SRCS) -o pspin
@mkdir -p lib/
$(CXX) $(LIB_DEBUG_FLAGS) -o lib/libpspin_debug.so $(SIM_LIB_SRCS) obj_dir_debug/Vpspin_verilator__ALL.a $(VERILATOR_HOME)/include/verilated.cpp $(VERILATOR_HOME)/include/verilated_vcd_c.cpp

lib/libpspin.so:
release:
$(VERILATOR_CC) $(VFLAGS_RELEASE) $(SV_INC) -cc $(SV_SRCS) --top-module $(TOP_MODULE) --build $(SIM_LIB_SRCS) -o pspin
@mkdir -p lib/
$(CXX) $(LIB_RELEASE_FLAGS) -o lib/libpspin.so $(SIM_LIB_SRCS) obj_dir_release/Vpspin_verilator__ALL.a $(VERILATOR_HOME)/include/verilated.cpp

release: lib/libpspin.so
@mkdir -p bin/
$(CC) $(EXE_RELEASE_FLAGS) $(SIM_EXE_SRCS) -Llib/ -lpspin -o bin/pspin_release

debug: lib/libpspin_debug.so
@mkdir -p bin/
$(CC) $(EXE_DEBUG_FLAGS) $(SIM_EXE_SRCS) -Llib/ -lpspin_debug -o bin/pspin_debug

build-debug: debug
@mkdir -p verilator/
@mkdir -p verilator/bin/
cp start_sim.sh verilator/
cp bin/pspin_debug verilator/bin/
cp -r lib/ verilator/

build-release: release
@mkdir -p verilator/
@mkdir -p verilator/bin/
cp start_sim.sh verilator/
cp bin/pspin_release verilator/bin/
cp -r lib/ verilator/


clean:
@rm -rf obj_dir_debug/ obj_dir_release/ bin/pspin bin/pspin_debug lib/libpspin.so lib/libpspin_debug.so > /dev/null 2> /dev/null

Expand Down
2 changes: 1 addition & 1 deletion hw/verilator_model/src/pspinsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int pspinsim_init(int argc, char **argv, pspin_conf_t *conf)
sim->add_module(*pcie_mst);

//before the reset!
char *slm_files_path = conf->slm_files_path;
const char *slm_files_path = conf->slm_files_path;
if (slm_files_path==NULL) {
char *pspin_hw_env = getenv("PSPIN_HW");
if (pspin_hw_env == NULL) {
Expand Down
28 changes: 23 additions & 5 deletions utils/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.


FROM ubuntu:18.04 as build-hw
WORKDIR /tools
ARG VERILATOR_VERSION=4.100
ARG VERILATOR_VERSION=4.108

RUN apt-get update --assume-yes && \
apt-get install --assume-yes \
wget curl gnupg gnupg2 git
wget curl gnupg gnupg2 git build-essential python gengetopt

# Install Verilator
RUN echo 'deb http://download.opensuse.org/repositories/home:/phiwag:/edatools/xUbuntu_18.04/ /' | tee /etc/apt/sources.list.d/home:phiwag:edatools.list && \
Expand All @@ -28,11 +27,30 @@ RUN echo 'deb http://download.opensuse.org/repositories/home:/phiwag:/edatools/x
apt-get clean ; \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*


# Get RISCV-GCC toolchain
RUN wget spclstorage.inf.ethz.ch/~digirols/pspin/riscv-gcc-ubuntu.tar.gz && \
tar -xvf /tools/riscv-gcc-ubuntu.tar.gz -C /tools && \
chmod 777 -R /tools/riscv-gcc/
chmod 777 -R /tools/riscv-gcc/ && \
rm /tools/riscv-gcc-ubuntu.tar.gz

WORKDIR /home/

# Get repo and configure paths
RUN git clone https://github.com/spcl/pspin.git && \
cd pspin && \
cat sourceme-template.sh | \
sed "s%RISCV_GCC=%RISCV_GCC=/tools/riscv-gcc/bin/%g" | \
sed "s%PSPIN_HW=%PSPIN_HW=/home/pspin/hw/%g" | \
sed "s%PSPIN_RT=%PSPIN_RT=/home/pspin/sw%g" > sourceme.sh && \

# Verilate
RUN export VERILATOR_HOME=/usr/share/verilator/ && \
cd pspin/hw/verilator_model/ && \
make release

# Test
RUN source pspin/sourceme.sh && \
cd pspin/examples/empty && \
make deploy && \
make driver && \
make run

0 comments on commit 5bfe6bd

Please sign in to comment.