Skip to content

Commit 5d6ec40

Browse files
tmoreau89wweic
authored andcommitted
[VTA][TSIM][Build] Towards TSIM CI testing (apache#3704)
* building TSIM specific library along with fast simulator to quickly switch between dlls * cmake controlled TSIM libraries * always build tsim driver in either simulation modes * build DLLs based on CMAKE flags * updating the jenkinsfile * small restructuring * reducing the cmake flags * update instructions * reverting to 3 flags * update Jenkinsfile * adding new line * enabling TSIM unit and integration tests * fix description * temporarily disabling task_python_vta tests in CPU Build stage * move CPU tests in unit test stage * stage reorg * better make * disabling TSIM tests for now * reverting some restructuring * fix
1 parent 8fb1d77 commit 5d6ec40

File tree

6 files changed

+91
-55
lines changed

6 files changed

+91
-55
lines changed

Jenkinsfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ tvm_runtime = "build/libtvm_runtime.so, build/config.cmake"
4848
tvm_lib = "build/libtvm.so, " + tvm_runtime
4949
// LLVM upstream lib
5050
tvm_multilib = "build/libtvm.so, " +
51-
"build/libvta.so, build/libtvm_topi.so, build/libnnvm_compiler.so, " + tvm_runtime
51+
"build/libvta_tsim.so, " +
52+
"build/libvta_fsim.so, " +
53+
"build/libtvm_topi.so, " +
54+
"build/libnnvm_compiler.so, " + tvm_runtime
5255

5356
// command to start a docker container
5457
docker_run = 'docker/bash.sh'
@@ -188,11 +191,11 @@ stage('Build') {
188191
make(ci_cpu, 'build', '-j4')
189192
pack_lib('cpu', tvm_lib)
190193
timeout(time: max_time, unit: 'MINUTES') {
191-
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_vta.sh"
192194
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_rust.sh"
193195
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_golang.sh"
194196
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_unittest.sh"
195197
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_integration.sh"
198+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_vta.sh"
196199
}
197200
}
198201
}

cmake/config.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,12 @@ set(USE_ANTLR OFF)
140140

141141
# Whether use Relay debug mode
142142
set(USE_RELAY_DEBUG OFF)
143+
144+
# Whether to build fast VTA simulator driver
145+
set(USE_VTA_FSIM ON)
146+
147+
# Whether to build cycle-accurate VTA simulator driver
148+
set(USE_VTA_TSIM ON)
149+
150+
# Whether to build VTA FPGA driver (device side only)
151+
set(USE_VTA_FPGA OFF)

cmake/modules/VTA.cmake

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,61 @@ elseif(PYTHON)
3737

3838
string(REGEX MATCHALL "(^| )-D[A-Za-z0-9_=.]*" VTA_DEFINITIONS "${__vta_defs}")
3939

40-
file(GLOB VTA_RUNTIME_SRCS vta/src/*.cc)
41-
# Add sim driver sources
42-
if(${VTA_TARGET} STREQUAL "sim")
43-
file(GLOB __vta_target_srcs vta/src/sim/*.cc)
44-
endif()
45-
# Add tsim driver sources
46-
if(${VTA_TARGET} STREQUAL "tsim")
47-
file(GLOB __vta_target_srcs vta/src/tsim/*.cc)
48-
file(GLOB RUNTIME_DPI_SRCS vta/src/dpi/module.cc)
49-
list(APPEND RUNTIME_SRCS ${RUNTIME_DPI_SRCS})
50-
endif()
51-
# Add pynq driver sources
52-
if(${VTA_TARGET} STREQUAL "pynq" OR ${VTA_TARGET} STREQUAL "ultra96")
53-
file(GLOB __vta_target_srcs vta/src/pynq/*.cc)
40+
# Fast simulator driver build
41+
if(USE_VTA_FSIM)
42+
# Add fsim driver sources
43+
file(GLOB FSIM_RUNTIME_SRCS vta/src/*.cc)
44+
list(APPEND FSIM_RUNTIME_SRCS vta/src/sim/sim_driver.cc)
45+
# Target lib: vta_fsim
46+
add_library(vta_fsim SHARED ${FSIM_RUNTIME_SRCS})
47+
target_include_directories(vta_fsim PUBLIC vta/include)
48+
foreach(__def ${VTA_DEFINITIONS})
49+
string(SUBSTRING ${__def} 3 -1 __strip_def)
50+
target_compile_definitions(vta_fsim PUBLIC ${__strip_def})
51+
endforeach()
52+
include_directories("vta/include")
53+
if(APPLE)
54+
set_target_properties(vta_fsim PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
55+
endif(APPLE)
5456
endif()
55-
list(APPEND VTA_RUNTIME_SRCS ${__vta_target_srcs})
56-
57-
add_library(vta SHARED ${VTA_RUNTIME_SRCS})
5857

59-
target_include_directories(vta PUBLIC vta/include)
60-
61-
foreach(__def ${VTA_DEFINITIONS})
62-
string(SUBSTRING ${__def} 3 -1 __strip_def)
63-
target_compile_definitions(vta PUBLIC ${__strip_def})
64-
endforeach()
65-
66-
# Enable tsim macro
67-
if(${VTA_TARGET} STREQUAL "tsim")
58+
# Cycle accurate simulator driver build
59+
if(USE_VTA_TSIM)
60+
# Add tsim driver sources
61+
file(GLOB TSIM_RUNTIME_SRCS vta/src/*.cc)
62+
list(APPEND TSIM_RUNTIME_SRCS vta/src/tsim/tsim_driver.cc)
63+
list(APPEND TSIM_RUNTIME_SRCS vta/src/dpi/module.cc)
64+
# Target lib: vta_tsim
65+
add_library(vta_tsim SHARED ${TSIM_RUNTIME_SRCS})
66+
target_include_directories(vta_tsim PUBLIC vta/include)
67+
foreach(__def ${VTA_DEFINITIONS})
68+
string(SUBSTRING ${__def} 3 -1 __strip_def)
69+
target_compile_definitions(vta_tsim PUBLIC ${__strip_def})
70+
endforeach()
6871
include_directories("vta/include")
69-
target_compile_definitions(vta PUBLIC USE_TSIM)
72+
# Set USE_TSIM macro
73+
target_compile_definitions(vta_tsim PUBLIC USE_TSIM)
74+
if(APPLE)
75+
set_target_properties(vta_tsim PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
76+
endif(APPLE)
7077
endif()
7178

72-
if(APPLE)
73-
set_target_properties(vta PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
74-
endif(APPLE)
75-
76-
# PYNQ rules for Pynq v2.4
77-
if(${VTA_TARGET} STREQUAL "pynq" OR ${VTA_TARGET} STREQUAL "ultra96")
79+
# VTA FPGA driver sources
80+
if(USE_VTA_FPGA)
81+
file(GLOB FPGA_RUNTIME_SRCS vta/src/*.cc)
82+
# Rules for Zynq-class FPGAs with pynq OS support (see pynq.io)
83+
if(${VTA_TARGET} STREQUAL "pynq" OR
84+
${VTA_TARGET} STREQUAL "ultra96")
85+
file(GLOB FPGA_RUNTIME_SRCS vta/src/pynq/pynq_driver.cc)
86+
endif()
87+
# Target lib: vta
88+
add_library(vta SHARED ${FPGA_RUNTIME_SRCS})
89+
target_include_directories(vta PUBLIC vta/include)
90+
foreach(__def ${VTA_DEFINITIONS})
91+
string(SUBSTRING ${__def} 3 -1 __strip_def)
92+
target_compile_definitions(vta PUBLIC ${__strip_def})
93+
endforeach()
94+
# Rules for Pynq v2.4
7895
find_library(__cma_lib NAMES cma PATH /usr/lib)
7996
target_link_libraries(vta ${__cma_lib})
8097
endif()

docs/vta/install.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ ssh [email protected]
117117
cd /home/xilinx/tvm
118118
mkdir build
119119
cp cmake/config.cmake build/.
120+
echo 'set(USE_VTA_FSIM OFF)' >> build/config.cmake
121+
echo 'set(USE_VTA_TSIM OFF)' >> build/config.cmake
122+
echo 'set(USE_VTA_FPGA ON)' >> build/config.cmake
120123
# Copy pynq specific configuration
121124
cp vta/config/pynq_sample.json vta/config/vta_config.json
122125
cd build

tests/scripts/task_python_vta.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ echo "Running integration test in fsim..."
3636
python3 -m nose -v vta/tests/python/integration
3737

3838
# # Build VTA chisel design and verilator simulator
39-
# cd vta/hardware/chisel/ && make && cd -
39+
# (make -C vta/hardware/chisel/)
4040

4141
# # Set default VTA config to use TSIM cycle accurate sim
4242
# cp vta/config/tsim_sample.json vta/config/vta_config.json
4343

44-
# # Run unit tests in functional/fast simulator
44+
# # Run unit tests in cycle accurate simulator
4545
# echo "Running unittest in tsim..."
4646
# python3 -m nose -v vta/tests/python/unittest
4747

48-
# # Run unit tests in functional/fast simulator
48+
# # Run unit tests in cycle accurate simulator
4949
# echo "Running integration test in tsim..."
5050
# python3 -m nose -v vta/tests/python/integration
5151

vta/python/vta/testing/simulator.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,32 @@
2121
from ..environment import get_env
2222
from ..libinfo import find_libvta
2323

24-
2524
def _load_sw():
26-
"""Load software library, assuming they are simulator."""
27-
lib_sw = find_libvta("libvta", optional=True)
28-
if not lib_sw:
29-
return []
25+
"""Load hardware library for simulator."""
26+
27+
env = get_env()
28+
lib_driver_name = "libvta_tsim" if env.TARGET == "tsim" else "libvta_fsim"
29+
30+
# Load driver library
31+
lib_driver = find_libvta(lib_driver_name, optional=True)
32+
assert lib_driver
3033
try:
31-
return [ctypes.CDLL(lib_sw[0], ctypes.RTLD_GLOBAL)]
34+
libs = [ctypes.CDLL(lib_driver[0], ctypes.RTLD_GLOBAL)]
3235
except OSError:
3336
return []
3437

35-
36-
def _load_all():
37-
"""Load hardware library for tsim."""
38-
lib = _load_sw()
39-
env = get_env()
4038
if env.TARGET == "tsim":
41-
lib = find_libvta("libvta_hw", optional=True)
42-
f = tvm.get_global_func("vta.tsim.init")
43-
m = tvm.module.load(lib[0], "vta-tsim")
44-
f(m)
45-
return lib
39+
lib_hw = find_libvta("libvta_hw", optional=True)
40+
assert lib_hw # make sure to build vta/hardware/chisel
41+
try:
42+
f = tvm.get_global_func("vta.tsim.init")
43+
m = tvm.module.load(lib_hw[0], "vta-tsim")
44+
f(m)
45+
return lib_hw
46+
except OSError:
47+
return []
48+
49+
return libs
4650

4751

4852
def enabled():
@@ -91,4 +95,4 @@ def debug_mode(flag):
9195
tvm.get_global_func("vta.simulator.profiler_debug_mode")(flag)
9296

9397

94-
LIBS = _load_all()
98+
LIBS = _load_sw()

0 commit comments

Comments
 (0)