Skip to content

Commit

Permalink
[VTA][Refactor] Introducing VTA_HW_PATH for easier migration (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoreau89 authored and Trevor Morris committed Apr 16, 2020
1 parent 0dbfa14 commit 5fc478b
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 134 deletions.
4 changes: 4 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ stage('Build') {
echo set\\(CMAKE_CXX_COMPILER g++\\) >> config.cmake
echo set\\(CMAKE_CXX_FLAGS -Werror\\) >> config.cmake
echo set\\(HIDE_PRIVATE_SYMBOLS ON\\) >> config.cmake
echo set\\(USE_VTA_TSIM ON\\) >> config.cmake
echo set\\(USE_VTA_FSIM ON\\) >> config.cmake
"""
make(ci_cpu, 'build', '-j4')
pack_lib('cpu', tvm_lib)
Expand Down Expand Up @@ -240,6 +242,8 @@ stage('Build') {
echo set\\(USE_LLVM llvm-config-4.0\\) >> config.cmake
echo set\\(CMAKE_CXX_COMPILER g++\\) >> config.cmake
echo set\\(CMAKE_CXX_FLAGS -Werror\\) >> config.cmake
echo set\\(USE_VTA_TSIM ON\\) >> config.cmake
echo set\\(USE_VTA_FSIM ON\\) >> config.cmake
"""
make(ci_i386, 'build', '-j4')
pack_lib('i386', tvm_multilib)
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ifndef DLPACK_PATH
DLPACK_PATH = $(ROOTDIR)/3rdparty/dlpack
endif

ifndef VTA_HW_PATH
VTA_HW_PATH = $(ROOTDIR)/vta/vta-hw
endif

INCLUDE_FLAGS = -Iinclude -I$(DLPACK_PATH)/include -I$(DMLC_CORE_PATH)/include
PKG_CFLAGS = -std=c++11 -Wall -O2 $(INCLUDE_FLAGS) -fPIC
PKG_LDFLAGS =
Expand Down Expand Up @@ -81,7 +85,7 @@ jnilint:
python3 3rdparty/dmlc-core/scripts/lint.py tvm4j-jni cpp jvm/native/src

scalalint:
make -C vta/vta-hw/hardware/chisel lint
make -C $(VTA_HW_PATH)/hardware/chisel lint

lint: cpplint pylint jnilint scalalint

Expand Down
2 changes: 1 addition & 1 deletion apps/vta_rpc/start_rpc_server_to_tracker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
PROJROOT="$( cd "$( dirname '${BASH_SOURCE[0]}' )/../../" && pwd )"

# Derive target specified by vta_config.json
VTA_CONFIG=${PROJROOT}/vta/vta-hw/config/vta_config.py
VTA_CONFIG=${VTA_HW_PATH}/config/vta_config.py
TARGET=$(python ${VTA_CONFIG} --target)

export PYTHONPATH=${PYTHONPATH}:${PROJROOT}/python:${PROJROOT}/vta/python
Expand Down
4 changes: 2 additions & 2 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ set(USE_ANTLR OFF)
set(USE_RELAY_DEBUG OFF)

# Whether to build fast VTA simulator driver
set(USE_VTA_FSIM ON)
set(USE_VTA_FSIM OFF)

# Whether to build cycle-accurate VTA simulator driver
set(USE_VTA_TSIM ON)
set(USE_VTA_TSIM OFF)

# Whether to build VTA FPGA driver (device side only)
set(USE_VTA_FPGA OFF)
Expand Down
38 changes: 20 additions & 18 deletions cmake/modules/VTA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
# CMake Build rules for VTA
find_program(PYTHON NAMES python python3 python3.6)

# VTA sources directory
set(VTA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vta/vta-hw)
# Throw error if VTA_HW_PATH is not set
if(NOT DEFINED ENV{VTA_HW_PATH})
set(ENV{VTA_HW_PATH} vta/vta-hw)
endif()

if(MSVC)
message(STATUS "VTA build is skipped in Windows..")
elseif(PYTHON)
set(VTA_CONFIG ${PYTHON} ${VTA_DIR}/config/vta_config.py)
set(VTA_CONFIG ${PYTHON} $ENV{VTA_HW_PATH}/config/vta_config.py)

if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/vta_config.json)
message(STATUS "Use VTA config " ${CMAKE_CURRENT_BINARY_DIR}/vta_config.json)
set(VTA_CONFIG ${PYTHON} ${VTA_DIR}/config/vta_config.py
set(VTA_CONFIG ${PYTHON} $ENV{VTA_HW_PATH}/config/vta_config.py
--use-cfg=${CMAKE_CURRENT_BINARY_DIR}/vta_config.json)
endif()

Expand All @@ -43,14 +45,14 @@ elseif(PYTHON)
# Fast simulator driver build
if(USE_VTA_FSIM)
# Add fsim driver sources
file(GLOB FSIM_RUNTIME_SRCS ${VTA_DIR}/src/*.cc)
file(GLOB FSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/*.cc)
file(GLOB FSIM_RUNTIME_SRCS vta/runtime/*.cc)
list(APPEND FSIM_RUNTIME_SRCS ${VTA_DIR}/src/sim/sim_driver.cc)
list(APPEND FSIM_RUNTIME_SRCS ${VTA_DIR}/src/sim/sim_tlpp.cc)
list(APPEND FSIM_RUNTIME_SRCS ${VTA_DIR}/src/vmem/virtual_memory.cc)
list(APPEND FSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/sim/sim_driver.cc)
list(APPEND FSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/sim/sim_tlpp.cc)
list(APPEND FSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/vmem/virtual_memory.cc)
# Target lib: vta_fsim
add_library(vta_fsim SHARED ${FSIM_RUNTIME_SRCS})
target_include_directories(vta_fsim PUBLIC ${VTA_DIR}/include)
target_include_directories(vta_fsim PUBLIC $ENV{VTA_HW_PATH}/include)
foreach(__def ${VTA_DEFINITIONS})
string(SUBSTRING ${__def} 3 -1 __strip_def)
target_compile_definitions(vta_fsim PUBLIC ${__strip_def})
Expand All @@ -64,14 +66,14 @@ elseif(PYTHON)
# Cycle accurate simulator driver build
if(USE_VTA_TSIM)
# Add tsim driver sources
file(GLOB TSIM_RUNTIME_SRCS ${VTA_DIR}/src/*.cc)
file(GLOB TSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/*.cc)
file(GLOB TSIM_RUNTIME_SRCS vta/runtime/*.cc)
list(APPEND TSIM_RUNTIME_SRCS ${VTA_DIR}/src/tsim/tsim_driver.cc)
list(APPEND TSIM_RUNTIME_SRCS ${VTA_DIR}/src/dpi/module.cc)
list(APPEND TSIM_RUNTIME_SRCS ${VTA_DIR}/src/vmem/virtual_memory.cc)
list(APPEND TSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/tsim/tsim_driver.cc)
list(APPEND TSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/dpi/module.cc)
list(APPEND TSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/vmem/virtual_memory.cc)
# Target lib: vta_tsim
add_library(vta_tsim SHARED ${TSIM_RUNTIME_SRCS})
target_include_directories(vta_tsim PUBLIC ${VTA_DIR}/include)
target_include_directories(vta_tsim PUBLIC $ENV{VTA_HW_PATH}/include)
foreach(__def ${VTA_DEFINITIONS})
string(SUBSTRING ${__def} 3 -1 __strip_def)
target_compile_definitions(vta_tsim PUBLIC ${__strip_def})
Expand All @@ -83,15 +85,15 @@ elseif(PYTHON)

# VTA FPGA driver sources
if(USE_VTA_FPGA)
file(GLOB FPGA_RUNTIME_SRCS ${VTA_HW_DIR}/src/*.cc)
file(GLOB FPGA_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/*.cc)
# Rules for Zynq-class FPGAs with pynq OS support (see pynq.io)
if(${VTA_TARGET} STREQUAL "pynq" OR
${VTA_TARGET} STREQUAL "ultra96")
list(APPEND FPGA_RUNTIME_SRCS ${VTA_HW_DIR}/src/pynq/pynq_driver.cc)
list(APPEND FPGA_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/pynq/pynq_driver.cc)
# Rules for Pynq v2.4
find_library(__cma_lib NAMES cma PATH /usr/lib)
elseif(${VTA_TARGET} STREQUAL "de10nano") # DE10-Nano rules
file(GLOB FPGA_RUNTIME_SRCS ${VTA_HW_DIR}/src/de10nano/*.cc ${VTA_HW_DIR}/src/*.cc)
file(GLOB FPGA_RUNTIME_SRCS $ENV{VTA_HW_PATH}/src/de10nano/*.cc $ENV{VTA_HW_PATH}/src/*.cc)
endif()
# Target lib: vta
add_library(vta SHARED ${FPGA_RUNTIME_SRCS})
Expand All @@ -105,7 +107,7 @@ elseif(PYTHON)
target_link_libraries(vta ${__cma_lib})
elseif(${VTA_TARGET} STREQUAL "de10nano") # DE10-Nano rules
#target_compile_definitions(vta PUBLIC VTA_MAX_XFER=2097152) # (1<<21)
target_include_directories(vta PUBLIC ${VTA_HW_DIR}/src/de10nano)
target_include_directories(vta PUBLIC $ENV{VTA_HW_PATH}/src/de10nano)
target_include_directories(vta PUBLIC 3rdparty)
target_include_directories(vta PUBLIC
"/usr/local/intelFPGA_lite/18.1/embedded/ds-5/sw/gcc/arm-linux-gnueabihf/include")
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.

INPUT = include/tvm topi/include/topi vta/vta-hw/include/vta
INPUT = include/tvm topi/include/topi

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
20 changes: 16 additions & 4 deletions docs/vta/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,22 @@ We present three installation guides, each extending on the previous one:
You need [TVM installed](https://docs.tvm.ai/install/index.html) on your machine.
For a quick and easy start, use the pre-built [TVM Docker image](https://docs.tvm.ai/install/docker.html).

The VTA simulator library is built by default with TVM.
Add the VTA library to your python path to run the VTA examples.
You'll need to set the following paths to use VTA:
```bash
export TVM_PATH=<path to TVM root>
export VTA_HW_PATH=$TVM_PATH/vta/vta-hw
```

The VTA functional simulation library needs to be enabled when building TVM.
```bash
cd <tvm-root>
mkdir build
cp cmake/config.cmake build/.
echo 'set(USE_VTA_FSIM ON)' >> build/config.cmake
cd build && cmake .. && make -j4
```

Add the VTA python library to your python path to run the VTA examples.

```bash
export PYTHONPATH=/path/to/vta/python:${PYTHONPATH}
Expand Down Expand Up @@ -118,8 +132,6 @@ ssh xilinx@192.168.2.99
cd /home/xilinx/tvm
mkdir build
cp cmake/config.cmake build/.
echo 'set(USE_VTA_FSIM OFF)' >> build/config.cmake
echo 'set(USE_VTA_TSIM OFF)' >> build/config.cmake
echo 'set(USE_VTA_FPGA ON)' >> build/config.cmake
# Copy pynq specific configuration
cp vta/vta-hw/config/pynq_sample.json vta/vta-hw/config/vta_config.json
Expand Down
10 changes: 6 additions & 4 deletions tests/scripts/task_python_vta_fsim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
set -e
set -u

export PYTHONPATH=python:vta/python:topi/python
export TVM_PATH=.
export PYTHONPATH=${TVM_PATH}/python:${TVM_PATH}/vta/python:${TVM_PATH}/topi/python
export VTA_HW_PATH=vta/vta-hw

# cleanup pycache
find . -type f -path "*.pyc" | xargs rm -f
Expand All @@ -30,12 +32,12 @@ rm -rf ~/.tvm
make cython3

# Reset default fsim simulation
cp vta/vta-hw/config/fsim_sample.json vta/vta-hw/config/vta_config.json
cp ${VTA_HW_PATH}/config/fsim_sample.json ${VTA_HW_PATH}/config/vta_config.json

# Run unit tests in functional/fast simulator
echo "Running unittest in fsim..."
python3 -m pytest -v vta/tests/python/unittest
python3 -m pytest -v ${TVM_PATH}/vta/tests/python/unittest

# Run unit tests in functional/fast simulator
echo "Running integration test in fsim..."
python3 -m pytest -v vta/tests/python/integration
python3 -m pytest -v ${TVM_PATH}/vta/tests/python/integration
24 changes: 13 additions & 11 deletions tests/scripts/task_python_vta_tsim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
set -e
set -u

export PYTHONPATH=python:vta/python:topi/python
export TVM_PATH=.
export PYTHONPATH=${TVM_PATH}/python:${TVM_PATH}/vta/python:${TVM_PATH}/topi/python
export VTA_HW_PATH=vta/vta-hw

# cleanup pycache
find . -type f -path "*.pyc" | xargs rm -f
Expand All @@ -30,30 +32,30 @@ rm -rf ~/.tvm
make cython3

# Set default VTA config to use TSIM cycle accurate sim
cp vta/vta-hw/config/tsim_sample.json vta/vta-hw/config/vta_config.json
cp ${VTA_HW_PATH}/config/tsim_sample.json ${VTA_HW_PATH}/config/vta_config.json

# Build and run the TSIM apps (disable until refactor is complete)
# echo "Test the TSIM apps..."
# make -C vta/vta-hw/apps/tsim_example/ run_verilog
# make -C vta/vta-hw/apps/tsim_example/ run_chisel
# make -C vta/vta-hw/apps/gemm/ default
# make -C ${VTA_HW_PATH}/apps/tsim_example/ run_verilog
# make -C ${VTA_HW_PATH}/apps/tsim_example/ run_chisel
# make -C ${VTA_HW_PATH}/apps/gemm/ default

# Check style of scala code
echo "Check style of scala code..."
make -C vta/vta-hw/hardware/chisel lint
make -C ${VTA_HW_PATH}/hardware/chisel lint

# Build VTA chisel design and verilator simulator
echo "Building VTA chisel design..."
make -C vta/vta-hw/hardware/chisel cleanall
make -C vta/vta-hw/hardware/chisel USE_THREADS=0 lib
make -C ${VTA_HW_PATH}/hardware/chisel cleanall
make -C ${VTA_HW_PATH}/hardware/chisel USE_THREADS=0 lib

# Run unit tests in cycle accurate simulator
echo "Running unittest in tsim..."
python3 -m pytest -v vta/tests/python/unittest
python3 -m pytest -v ${TVM_PATH}/vta/tests/python/unittest

# Run unit tests in cycle accurate simulator
echo "Running integration test in tsim..."
python3 -m pytest -v vta/tests/python/integration
python3 -m pytest -v ${TVM_PATH}/vta/tests/python/integration

# Reset default fsim simulation
cp vta/vta-hw/config/fsim_sample.json vta/vta-hw/config/vta_config.json
cp ${VTA_HW_PATH}/config/fsim_sample.json ${VTA_HW_PATH}/config/vta_config.json
40 changes: 20 additions & 20 deletions vta/python/vta/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
"""Configurable VTA Hareware Environment scope."""
# pylint: disable=invalid-name
# pylint: disable=invalid-name, exec-used
from __future__ import absolute_import as _abs

import os
Expand All @@ -24,8 +24,21 @@
import tvm
from tvm import te
from . import intrin
from .pkg_config import PkgConfig

def get_vta_hw_path():
"""Get the VTA HW path."""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
vta_hw_default = os.path.abspath(os.path.join(curr_path, "../../vta-hw"))
VTA_HW_PATH = os.getenv('VTA_HW_PATH', vta_hw_default)
return VTA_HW_PATH

def pkg_config(cfg):
"""Returns PkgConfig pkg config object."""
pkg_config_py = os.path.join(get_vta_hw_path(), "config/pkg_config.py")
libpkg = {"__file__": pkg_config_py}
exec(compile(open(pkg_config_py, "rb").read(), pkg_config_py, "exec"), libpkg, libpkg)
PkgConfig = libpkg["PkgConfig"]
return PkgConfig(cfg)

class DevContext(object):
"""Internal development context
Expand Down Expand Up @@ -115,7 +128,7 @@ class Environment(object):
# initialization function
def __init__(self, cfg):
# Produce the derived parameters and update dict
self.pkg = self.pkg_config(cfg)
self.pkg = pkg_config(cfg)
self.__dict__.update(self.pkg.cfg_dict)
# data type width
self.INP_WIDTH = 1 << self.LOG_INP_WIDTH
Expand Down Expand Up @@ -172,12 +185,6 @@ def __enter__(self):
def __exit__(self, ptype, value, trace):
Environment.current = self._last_env

def pkg_config(self, cfg):
"""PkgConfig instance"""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
proj_root = os.path.abspath(os.path.join(curr_path, "../../"))
return PkgConfig(cfg, proj_root)

@property
def cfg_dict(self):
return self.pkg.cfg_dict
Expand Down Expand Up @@ -308,17 +315,10 @@ def coproc_dep_pop(op):

def _init_env():
"""Initialize the default global env"""
curr_path = os.path.dirname(
os.path.abspath(os.path.expanduser(__file__)))
proj_root = os.path.abspath(os.path.join(curr_path, "../../../"))
path_list = [
os.path.join(proj_root, "vta/vta-hw/config/vta_config.json")
]
path_list = [p for p in path_list if os.path.exists(p)]
if not path_list:
raise RuntimeError(
"Error: vta_config.json not found.")
cfg = json.load(open(path_list[0]))
config_path = os.path.join(get_vta_hw_path(), "config/vta_config.json")
if not os.path.exists(config_path):
raise RuntimeError("Cannot find config in %s" % str(config_path))
cfg = json.load(open(config_path))
return Environment(cfg)

Environment.current = _init_env()
5 changes: 2 additions & 3 deletions vta/python/vta/exec/rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
from tvm.contrib import cc
from vta import program_bitstream

from ..environment import get_env
from ..pkg_config import PkgConfig
from ..environment import get_env, pkg_config
from ..libinfo import find_libvta


Expand Down Expand Up @@ -101,7 +100,7 @@ def reconfig_runtime(cfg_json):
raise RuntimeError("Can only reconfig in the beginning of session...")
cfg = json.loads(cfg_json)
cfg["TARGET"] = env.TARGET
pkg = PkgConfig(cfg, proj_root)
pkg = pkg_config(cfg)
# check if the configuration is already the same
if os.path.isfile(cfg_path):
old_cfg = json.loads(open(cfg_path, "r").read())
Expand Down
4 changes: 3 additions & 1 deletion vta/python/vta/libinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import sys
import os

from .environment import get_vta_hw_path

def _get_lib_name(lib_name):
"""Get lib name with extension
Expand Down Expand Up @@ -57,7 +59,7 @@ def find_libvta(lib_vta, optional=False):
"""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
lib_search = [os.path.join(curr_path, "..", "..", "..", "build",)]
lib_search += [os.path.join(curr_path, "..", "..", "vta-hw", "build")]
lib_search += [os.path.join(get_vta_hw_path(), "build")]
lib_name = _get_lib_name(lib_vta)
lib_path = [os.path.join(x, lib_name) for x in lib_search]
lib_found = [x for x in lib_path if os.path.exists(x)]
Expand Down
2 changes: 1 addition & 1 deletion vta/python/vta/testing/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _load_sw():

if env.TARGET == "tsim":
lib_hw = find_libvta("libvta_hw", optional=True)
assert lib_hw # make sure to build vta/vta-hw/hardware/chisel
assert lib_hw # make sure to make in ${VTA_HW_PATH}/hardware/chisel
try:
f = tvm.get_global_func("vta.tsim.init")
m = tvm.runtime.load_module(lib_hw[0], "vta-tsim")
Expand Down
Loading

0 comments on commit 5fc478b

Please sign in to comment.