Skip to content

Commit 28a10b6

Browse files
tmoreau89tqchen
authored andcommitted
[REFACTOR] Code base refactoring (apache#5)
1 parent 0979e9a commit 28a10b6

File tree

21 files changed

+2221
-365
lines changed

21 files changed

+2221
-365
lines changed

vta/Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ endif
5454

5555
all: lib/libvta.$(SHARED_LIBRARY_SUFFIX)
5656

57-
SRC = $(wildcard src/*.cc src/*.cc)
58-
ALL_OBJ = $(patsubst %.cc, build/%.o, $(SRC))
59-
ALL_DEP = $(ALL_OBJ)
57+
VTA_LIB_SRC = $(wildcard src/*.cc src/tvm/*.cc)
58+
ifeq ($(TARGET), PYNQ_TARGET)
59+
VTA_LIB_SRC += $(wildcard src/pynq/*.cc)
60+
LDFLAGS += -L/usr/lib -lsds_lib
61+
LDFLAGS += -L/opt/python3.6/lib/python3.6/site-packages/pynq/drivers/ -l:libdma.so
62+
endif
63+
VTA_LIB_OBJ = $(patsubst %.cc, build/%.o, $(VTA_LIB_SRC))
6064

6165
test: $(TEST)
6266

@@ -65,7 +69,7 @@ build/src/%.o: src/%.cc
6569
$(CXX) $(CFLAGS) -MM -MT build/src/$*.o $< >build/src/$*.d
6670
$(CXX) -c $(CFLAGS) -c $< -o $@
6771

68-
lib/libvta.$(SHARED_LIBRARY_SUFFIX): $(ALL_DEP)
72+
lib/libvta.$(SHARED_LIBRARY_SUFFIX): $(VTA_LIB_OBJ)
6973
@mkdir -p $(@D)
7074
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o, $^) $(LDFLAGS)
7175

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
export PYTHONPATH=${PYTHONPATH}:/home/xilinx/tvm/python
3+
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/python3.6/lib/python3.6/site-packages/pynq/drivers/
4+
python -m tvm.exec.rpc_server --load-library /home/xilinx/vta/lib/libvta.so

vta/hardware/vivado/Makefile

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,38 @@
22
ROOTDIR = $(CURDIR)
33
BUILD_DIR = $(ROOTDIR)/build
44
SCRIPT_DIR = $(ROOTDIR)/scripts
5-
SRC_DIR = $(ROOTDIR)/../../src/hardware/hls
5+
SRC_DIR = $(ROOTDIR)/src
66
SIM_DIR = $(ROOTDIR)/sim
7-
TEST_DIR = $(ROOTDIR)/../../src/test
7+
TEST_DIR = $(ROOTDIR)/../../tests/hardware/common
88
INCLUDE_DIR = $(ROOTDIR)/../../include
99

1010
# Executables
1111
VIVADO_HLS = vivado_hls
1212
VIVADO = vivado
1313
HSI = hsi
1414

15-
# Build parameters:
15+
# Include top-level config file
16+
ifndef config
17+
ifneq ("$(wildcard ../../config.mk)", "")
18+
config = ../../config.mk
19+
else
20+
config = ../../make/config.mk
21+
endif
22+
endif
23+
include $(config)
24+
25+
#---------------------
26+
# Compilation parameters
27+
#--------------------
28+
1629
# Number of threads during compilation
1730
NUM_THREADS = 8
31+
1832
# Target Frequency
1933
CLOCK_FREQ = 100
20-
# Log of input width in bits
21-
LOG_INP_WIDTH = 3
22-
# Log of weight width in bits
23-
LOG_WGT_WIDTH = 3
24-
# Log of accum width in bits
25-
LOG_ACC_WIDTH = 5
26-
# Log of output width in bits
27-
LOG_OUT_WIDTH = $(LOG_INP_WIDTH)
28-
# Log of tensor batch size (A in (A,B)x(B,C) matrix multiplication)
29-
LOG_BATCH = 0
30-
# Log of tensor inner block size (B in (A,B)x(B,C) matrix multiplication)
31-
LOG_IN_BLOCK = 4
32-
# Log of tensor outer block size (C in (A,B)x(B,C) matrix multiplication)
33-
LOG_OUT_BLOCK = 4
34-
# Log of uop buffer size in Bytes
35-
LOG_UOP_BUFF_SIZE = 15
36-
# Log of inp buffer size in Bytes
37-
LOG_INP_BUFF_SIZE = 15
38-
# Log of wgt buffer size in Bytes
39-
LOG_WGT_BUFF_SIZE = 15
40-
# Log of acc buffer size in Bytes
41-
LOG_ACC_BUFF_SIZE = 17
42-
# Log of out buffer size in Bytes
43-
LOG_OUT_BUFF_SIZE = $(shell echo "$$(( $(LOG_ACC_BUFF_SIZE)+$(LOG_OUT_WIDTH)-$(LOG_ACC_WIDTH) ))" )
4434

45-
# Derived parameter
46-
# Input width in bits
47-
INP_WIDTH = $(shell echo "$$(( 1 << $(LOG_INP_WIDTH) ))" )
48-
# Weight width in bits
49-
WGT_WIDTH = $(shell echo "$$(( 1 << $(LOG_WGT_WIDTH) ))" )
50-
# Output width in bits
51-
OUT_WIDTH = $(shell echo "$$(( 1 << $(LOG_OUT_WIDTH) ))" )
52-
# Tensor batch size
53-
BATCH = $(shell echo "$$(( 1 << $(LOG_BATCH) ))" )
54-
# Tensor outer block size
55-
IN_BLOCK = $(shell echo "$$(( 1 << $(LOG_IN_BLOCK) ))" )
56-
# Tensor inner block size
57-
OUT_BLOCK = $(shell echo "$$(( 1 << $(LOG_OUT_BLOCK) ))" )
58-
# Uop buffer size in Bytes
59-
UOP_BUFF_SIZE = $(shell echo "$$(( 1 << $(LOG_UOP_BUFF_SIZE) ))" )
60-
# Inp buffer size in Bytes
61-
INP_BUFF_SIZE = $(shell echo "$$(( 1 << $(LOG_INP_BUFF_SIZE) ))" )
62-
# Wgt buffer size in Bytes
63-
WGT_BUFF_SIZE = $(shell echo "$$(( 1 << $(LOG_WGT_BUFF_SIZE) ))" )
64-
# Acc buffer size in Bytes
65-
ACC_BUFF_SIZE = $(shell echo "$$(( 1 << $(LOG_ACC_BUFF_SIZE) ))" )
66-
# Out buffer size in Bytes
67-
OUT_BUFF_SIZE = $(shell echo "$$(( 1 << $(LOG_OUT_BUFF_SIZE) ))" )
35+
# Timing closure compensation (0 for none, 3 for highest)
36+
TIMING_CLOSURE_COMP = 0
6837

6938
# Derive clock target period
7039
TARGET_PER = $(shell echo "$$(( (1000 + $(CLOCK_FREQ) - 1) / $(CLOCK_FREQ) - 0))" )
@@ -85,7 +54,7 @@ ip:
8554
$(VIVADO_HLS) -f $(SCRIPT_DIR)/hls.tcl \
8655
-tclargs $(SRC_DIR) $(SIM_DIR) $(TEST_DIR) $(INCLUDE_DIR) $(TARGET_PER) \
8756
$(LOG_INP_WIDTH) $(LOG_WGT_WIDTH) $(LOG_ACC_WIDTH) $(LOG_OUT_WIDTH) \
88-
$(LOG_BATCH) $(LOG_OUT_BLOCK) $(LOG_IN_BLOCK) \
57+
$(LOG_BATCH) $(LOG_BLOCK_OUT) $(LOG_BLOCK_IN) \
8958
$(LOG_UOP_BUFF_SIZE) $(LOG_INP_BUFF_SIZE) $(LOG_WGT_BUFF_SIZE) \
9059
$(LOG_ACC_BUFF_SIZE) $(LOG_OUT_BUFF_SIZE)
9160

vta/hardware/vivado/scripts/hls.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if { [llength $argv] eq 19 } {
6262
}
6363

6464
# C define flags to pass to compiler
65-
set cflags "-I $include_dir -I $include_dir/hardware/hls \
65+
set cflags "-I $include_dir -I $src_dir -I $test_dir \
6666
-DDEBUG=0 -DLOG_WGT_WIDTH=$wgt_width -DLOG_INP_WIDTH=$inp_width \
6767
-DLOG_ACC_WIDTH=$acc_width -DLOG_OUT_WIDTH=$out_width \
6868
-DLOG_BATCH=$batch -DLOG_BLOCK_OUT=$block_out -DLOG_BLOCK_IN=$block_in \
@@ -127,7 +127,7 @@ open_project vta_sim
127127
set_top vta
128128
add_files $src_dir/vta.cc -cflags $cflags
129129
add_files -tb $sim_dir/vta_test.cc -cflags $cflags
130-
add_files -tb $test_dir/vta_test_lib.cc -cflags $cflags
130+
add_files -tb $test_dir/test_lib.cc -cflags $cflags
131131
open_solution "solution0"
132132
init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out
133133
csim_design -clean

vta/hardware/vivado/sim/vta_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <stdlib.h>
99
#include <iostream>
1010

11-
#include "vta.h"
12-
#include "vta_test_lib.h"
11+
#include "../src/vta.h"
12+
#include "../../../tests/hardware/common/test_lib.h"
1313

1414
int main(void)
1515
{

vta/src/hardware/hls/vta.cc renamed to vta/hardware/vivado/src/vta.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <stdlib.h>
99
#include <string.h>
1010

11-
#include "vta.h"
11+
#include "./vta.h"
1212

1313
void fetch (
1414
uint32_t insn_count,

vta/include/hardware/hls/vta.h renamed to vta/hardware/vivado/src/vta.h

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,88 @@
1111
#include <ap_int.h>
1212
#include <hls_stream.h>
1313

14-
#include "vta_typedefs.h"
15-
#include "vta_params.h"
14+
#include <vta/hw_spec.h>
15+
16+
/* \typedef uop_T Micro-op datatype*/
17+
typedef ap_uint<UOP_WIDTH> uop_T;
18+
19+
/* \typedef inp_T Input datatype*/
20+
typedef ap_int<INP_WIDTH> inp_T;
21+
22+
/* \typedef wgt_T Weight datatype*/
23+
typedef ap_int<WGT_WIDTH> wgt_T;
24+
25+
/* \typedef out_T Output datatype*/
26+
typedef ap_int<OUT_WIDTH> out_T;
27+
28+
/* \typedef acc_T Accumulator datatype*/
29+
typedef ap_int<ACC_WIDTH> acc_T;
30+
31+
/* \typedef mul_T Multiplier output datatype*/
32+
typedef ap_int<WGT_WIDTH+INP_WIDTH+1> mul_T;
33+
34+
/* \typedef sum_T GEMM accumulator datatype*/
35+
typedef ap_int<WGT_WIDTH+INP_WIDTH+LOG_BLOCK_IN+1> sum_T;
36+
37+
/* \typedef inp_vec_T Input vector datatype*/
38+
typedef ap_uint<INP_WIDTH*BLOCK_IN> inp_vec_T;
39+
40+
/* \typedef wgt_vec_T Weight vector datatype*/
41+
typedef ap_uint<WGT_WIDTH*BLOCK_IN> wgt_vec_T;
42+
43+
/* \typedef acc_vec_T Accumulator vector datatype*/
44+
typedef ap_uint<ACC_WIDTH*BLOCK_OUT> acc_vec_T;
45+
46+
/* \typedef out_vec_T Output vector datatype*/
47+
typedef ap_uint<OUT_WIDTH*BLOCK_OUT> out_vec_T;
48+
49+
/* \typedef uop_idx_T Micro-op SRAM index datatype*/
50+
typedef ap_uint<LOG_UOP_BUFF_DEPTH+1> uop_idx_T;
51+
52+
/* \typedef inp_idx_T Input SRAM index datatype*/
53+
typedef ap_uint<LOG_INP_BUFF_DEPTH+1> inp_idx_T;
54+
55+
/* \typedef wgt_idx_T Weight SRAM index datatype*/
56+
typedef ap_uint<LOG_WGT_BUFF_DEPTH+1> wgt_idx_T;
57+
58+
/* \typedef acc_idx_T Accumulator SRAM index datatype*/
59+
typedef ap_uint<LOG_ACC_BUFF_DEPTH+1> acc_idx_T;
60+
61+
/* \typedef opcode_T Opcode datatype*/
62+
typedef ap_uint<OPCODE_BIT_WIDTH> opcode_T;
63+
64+
/* \typedef insn_T Instruction datatype*/
65+
typedef ap_uint<INS_WIDTH> insn_T;
66+
67+
/* \typedef loop_T Loop bound datatype*/
68+
typedef ap_uint<LOOP_ITER_WIDTH> loop_T;
69+
70+
/* \typedef memop_id_T Memory operation ID datatype*/
71+
typedef ap_uint<MEMOP_ID_BIT_WIDTH> memop_id_T;
72+
73+
/* \typedef memop_sram_T Memory operation SRAM index datatype*/
74+
typedef ap_uint<MEMOP_SRAM_ADDR_BIT_WIDTH> memop_sram_T;
75+
76+
/* \typedef memop_dram_T Memory operation DRAM index datatype*/
77+
typedef ap_uint<MEMOP_DRAM_ADDR_BIT_WIDTH> memop_dram_T;
78+
79+
/* \typedef memop_size_T Memory operation range datatype*/
80+
typedef ap_uint<MEMOP_SIZE_BIT_WIDTH> memop_size_T;
81+
82+
/* \typedef memop_stride_T Memory operation stride datatype*/
83+
typedef ap_uint<MEMOP_STRIDE_BIT_WIDTH> memop_stride_T;
84+
85+
/* \typedef memop_pad_T Memory operation pad width datatype*/
86+
typedef ap_uint<MEMOP_PAD_BIT_WIDTH> memop_pad_T;
87+
88+
/* \typedef aluop_opcode_T ALU operation opcode datatype*/
89+
typedef ap_uint<ALU_OPCODE_BIT_WIDTH> aluop_opcode_T;
90+
91+
/* \typedef aluop_opcode_T ALU operation immediate datatype*/
92+
typedef ap_int<ALUOP_IMM_BIT_WIDTH> aluop_imm_T;
93+
94+
/* \typedef aluop_opcode_T ALU operation shift immediate datatype*/
95+
typedef ap_uint<LOG_ACC_WIDTH> aluop_sh_imm_T;
1696

1797
/*!
1898
* \brief Fetch module.

vta/include/hardware/hls/vta_typedefs.h

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)