Unverified Commit bbad7362 by Thierry Moreau Committed by GitHub

[VTA][Refactor] Introducing VTA_HW_PATH for easier migration (#5163)

parent 497d01d3
...@@ -210,6 +210,8 @@ stage('Build') { ...@@ -210,6 +210,8 @@ stage('Build') {
echo set\\(CMAKE_CXX_COMPILER g++\\) >> config.cmake echo set\\(CMAKE_CXX_COMPILER g++\\) >> config.cmake
echo set\\(CMAKE_CXX_FLAGS -Werror\\) >> config.cmake echo set\\(CMAKE_CXX_FLAGS -Werror\\) >> config.cmake
echo set\\(HIDE_PRIVATE_SYMBOLS ON\\) >> 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', '-j2') make(ci_cpu, 'build', '-j2')
pack_lib('cpu', tvm_lib) pack_lib('cpu', tvm_lib)
...@@ -241,6 +243,8 @@ stage('Build') { ...@@ -241,6 +243,8 @@ stage('Build') {
echo set\\(USE_LLVM llvm-config-4.0\\) >> config.cmake echo set\\(USE_LLVM llvm-config-4.0\\) >> config.cmake
echo set\\(CMAKE_CXX_COMPILER g++\\) >> config.cmake echo set\\(CMAKE_CXX_COMPILER g++\\) >> config.cmake
echo set\\(CMAKE_CXX_FLAGS -Werror\\) >> 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', '-j2') make(ci_i386, 'build', '-j2')
pack_lib('i386', tvm_multilib) pack_lib('i386', tvm_multilib)
......
...@@ -28,6 +28,10 @@ ifndef DLPACK_PATH ...@@ -28,6 +28,10 @@ ifndef DLPACK_PATH
DLPACK_PATH = $(ROOTDIR)/3rdparty/dlpack DLPACK_PATH = $(ROOTDIR)/3rdparty/dlpack
endif 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 INCLUDE_FLAGS = -Iinclude -I$(DLPACK_PATH)/include -I$(DMLC_CORE_PATH)/include
PKG_CFLAGS = -std=c++11 -Wall -O2 $(INCLUDE_FLAGS) -fPIC PKG_CFLAGS = -std=c++11 -Wall -O2 $(INCLUDE_FLAGS) -fPIC
PKG_LDFLAGS = PKG_LDFLAGS =
...@@ -81,7 +85,7 @@ jnilint: ...@@ -81,7 +85,7 @@ jnilint:
python3 3rdparty/dmlc-core/scripts/lint.py tvm4j-jni cpp jvm/native/src python3 3rdparty/dmlc-core/scripts/lint.py tvm4j-jni cpp jvm/native/src
scalalint: scalalint:
make -C vta/vta-hw/hardware/chisel lint make -C $(VTA_HW_PATH)/hardware/chisel lint
lint: cpplint pylint jnilint scalalint lint: cpplint pylint jnilint scalalint
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
PROJROOT="$( cd "$( dirname '${BASH_SOURCE[0]}' )/../../" && pwd )" PROJROOT="$( cd "$( dirname '${BASH_SOURCE[0]}' )/../../" && pwd )"
# Derive target specified by vta_config.json # 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) TARGET=$(python ${VTA_CONFIG} --target)
export PYTHONPATH=${PYTHONPATH}:${PROJROOT}/python:${PROJROOT}/vta/python export PYTHONPATH=${PYTHONPATH}:${PROJROOT}/python:${PROJROOT}/vta/python
......
...@@ -191,10 +191,10 @@ set(USE_ANTLR OFF) ...@@ -191,10 +191,10 @@ set(USE_ANTLR OFF)
set(USE_RELAY_DEBUG OFF) set(USE_RELAY_DEBUG OFF)
# Whether to build fast VTA simulator driver # 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 # 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) # Whether to build VTA FPGA driver (device side only)
set(USE_VTA_FPGA OFF) set(USE_VTA_FPGA OFF)
......
...@@ -18,17 +18,19 @@ ...@@ -18,17 +18,19 @@
# CMake Build rules for VTA # CMake Build rules for VTA
find_program(PYTHON NAMES python python3 python3.6) find_program(PYTHON NAMES python python3 python3.6)
# VTA sources directory # Throw error if VTA_HW_PATH is not set
set(VTA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vta/vta-hw) if(NOT DEFINED ENV{VTA_HW_PATH})
set(ENV{VTA_HW_PATH} vta/vta-hw)
endif()
if(MSVC) if(MSVC)
message(STATUS "VTA build is skipped in Windows..") message(STATUS "VTA build is skipped in Windows..")
elseif(PYTHON) 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) if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/vta_config.json)
message(STATUS "Use VTA config " ${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) --use-cfg=${CMAKE_CURRENT_BINARY_DIR}/vta_config.json)
endif() endif()
...@@ -43,14 +45,14 @@ elseif(PYTHON) ...@@ -43,14 +45,14 @@ elseif(PYTHON)
# Fast simulator driver build # Fast simulator driver build
if(USE_VTA_FSIM) if(USE_VTA_FSIM)
# Add fsim driver sources # 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) 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 $ENV{VTA_HW_PATH}/src/sim/sim_driver.cc)
list(APPEND FSIM_RUNTIME_SRCS ${VTA_DIR}/src/sim/sim_tlpp.cc) list(APPEND FSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/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/vmem/virtual_memory.cc)
# Target lib: vta_fsim # Target lib: vta_fsim
add_library(vta_fsim SHARED ${FSIM_RUNTIME_SRCS}) 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}) foreach(__def ${VTA_DEFINITIONS})
string(SUBSTRING ${__def} 3 -1 __strip_def) string(SUBSTRING ${__def} 3 -1 __strip_def)
target_compile_definitions(vta_fsim PUBLIC ${__strip_def}) target_compile_definitions(vta_fsim PUBLIC ${__strip_def})
...@@ -64,14 +66,14 @@ elseif(PYTHON) ...@@ -64,14 +66,14 @@ elseif(PYTHON)
# Cycle accurate simulator driver build # Cycle accurate simulator driver build
if(USE_VTA_TSIM) if(USE_VTA_TSIM)
# Add tsim driver sources # 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) 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 $ENV{VTA_HW_PATH}/src/tsim/tsim_driver.cc)
list(APPEND TSIM_RUNTIME_SRCS ${VTA_DIR}/src/dpi/module.cc) list(APPEND TSIM_RUNTIME_SRCS $ENV{VTA_HW_PATH}/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/vmem/virtual_memory.cc)
# Target lib: vta_tsim # Target lib: vta_tsim
add_library(vta_tsim SHARED ${TSIM_RUNTIME_SRCS}) 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}) foreach(__def ${VTA_DEFINITIONS})
string(SUBSTRING ${__def} 3 -1 __strip_def) string(SUBSTRING ${__def} 3 -1 __strip_def)
target_compile_definitions(vta_tsim PUBLIC ${__strip_def}) target_compile_definitions(vta_tsim PUBLIC ${__strip_def})
...@@ -83,15 +85,15 @@ elseif(PYTHON) ...@@ -83,15 +85,15 @@ elseif(PYTHON)
# VTA FPGA driver sources # VTA FPGA driver sources
if(USE_VTA_FPGA) 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) # Rules for Zynq-class FPGAs with pynq OS support (see pynq.io)
if(${VTA_TARGET} STREQUAL "pynq" OR if(${VTA_TARGET} STREQUAL "pynq" OR
${VTA_TARGET} STREQUAL "ultra96") ${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 # Rules for Pynq v2.4
find_library(__cma_lib NAMES cma PATH /usr/lib) find_library(__cma_lib NAMES cma PATH /usr/lib)
elseif(${VTA_TARGET} STREQUAL "de10nano") # DE10-Nano rules 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() endif()
# Target lib: vta # Target lib: vta
add_library(vta SHARED ${FPGA_RUNTIME_SRCS}) add_library(vta SHARED ${FPGA_RUNTIME_SRCS})
...@@ -105,7 +107,7 @@ elseif(PYTHON) ...@@ -105,7 +107,7 @@ elseif(PYTHON)
target_link_libraries(vta ${__cma_lib}) target_link_libraries(vta ${__cma_lib})
elseif(${VTA_TARGET} STREQUAL "de10nano") # DE10-Nano rules elseif(${VTA_TARGET} STREQUAL "de10nano") # DE10-Nano rules
#target_compile_definitions(vta PUBLIC VTA_MAX_XFER=2097152) # (1<<21) #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 3rdparty)
target_include_directories(vta PUBLIC target_include_directories(vta PUBLIC
"/usr/local/intelFPGA_lite/18.1/embedded/ds-5/sw/gcc/arm-linux-gnueabihf/include") "/usr/local/intelFPGA_lite/18.1/embedded/ds-5/sw/gcc/arm-linux-gnueabihf/include")
......
...@@ -770,7 +770,7 @@ WARN_LOGFILE = ...@@ -770,7 +770,7 @@ WARN_LOGFILE =
# spaces. # spaces.
# Note: If this tag is empty the current directory is searched. # 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 # 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 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
......
...@@ -29,8 +29,22 @@ We present three installation guides, each extending on the previous one: ...@@ -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. 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). 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. You'll need to set the following paths to use VTA:
Add the VTA library to your python path to run the VTA examples. ```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 ```bash
export PYTHONPATH=/path/to/vta/python:${PYTHONPATH} export PYTHONPATH=/path/to/vta/python:${PYTHONPATH}
...@@ -118,8 +132,6 @@ ssh xilinx@192.168.2.99 ...@@ -118,8 +132,6 @@ ssh xilinx@192.168.2.99
cd /home/xilinx/tvm cd /home/xilinx/tvm
mkdir build mkdir build
cp cmake/config.cmake 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 echo 'set(USE_VTA_FPGA ON)' >> build/config.cmake
# Copy pynq specific configuration # Copy pynq specific configuration
cp vta/vta-hw/config/pynq_sample.json vta/vta-hw/config/vta_config.json cp vta/vta-hw/config/pynq_sample.json vta/vta-hw/config/vta_config.json
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
set -e set -e
set -u 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 # cleanup pycache
find . -type f -path "*.pyc" | xargs rm -f find . -type f -path "*.pyc" | xargs rm -f
...@@ -30,12 +32,12 @@ rm -rf ~/.tvm ...@@ -30,12 +32,12 @@ rm -rf ~/.tvm
make cython3 make cython3
# Reset default fsim simulation # 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 # Run unit tests in functional/fast simulator
echo "Running unittest in fsim..." 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 # Run unit tests in functional/fast simulator
echo "Running integration test in fsim..." echo "Running integration test in fsim..."
python3 -m pytest -v vta/tests/python/integration python3 -m pytest -v ${TVM_PATH}/vta/tests/python/integration
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
set -e set -e
set -u 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 # cleanup pycache
find . -type f -path "*.pyc" | xargs rm -f find . -type f -path "*.pyc" | xargs rm -f
...@@ -30,30 +32,30 @@ rm -rf ~/.tvm ...@@ -30,30 +32,30 @@ rm -rf ~/.tvm
make cython3 make cython3
# Set default VTA config to use TSIM cycle accurate sim # 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) # Build and run the TSIM apps (disable until refactor is complete)
# echo "Test the TSIM apps..." # echo "Test the TSIM apps..."
# make -C vta/vta-hw/apps/tsim_example/ run_verilog # make -C ${VTA_HW_PATH}/apps/tsim_example/ run_verilog
# make -C vta/vta-hw/apps/tsim_example/ run_chisel # make -C ${VTA_HW_PATH}/apps/tsim_example/ run_chisel
# make -C vta/vta-hw/apps/gemm/ default # make -C ${VTA_HW_PATH}/apps/gemm/ default
# Check style of scala code # Check style of scala code
echo "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 # Build VTA chisel design and verilator simulator
echo "Building VTA chisel design..." echo "Building VTA chisel design..."
make -C vta/vta-hw/hardware/chisel cleanall make -C ${VTA_HW_PATH}/hardware/chisel cleanall
make -C vta/vta-hw/hardware/chisel USE_THREADS=0 lib make -C ${VTA_HW_PATH}/hardware/chisel USE_THREADS=0 lib
# Run unit tests in cycle accurate simulator # Run unit tests in cycle accurate simulator
echo "Running unittest in tsim..." 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 # Run unit tests in cycle accurate simulator
echo "Running integration test in tsim..." 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 # 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
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
"""Configurable VTA Hareware Environment scope.""" """Configurable VTA Hareware Environment scope."""
# pylint: disable=invalid-name # pylint: disable=invalid-name, exec-used
from __future__ import absolute_import as _abs from __future__ import absolute_import as _abs
import os import os
...@@ -24,8 +24,21 @@ import copy ...@@ -24,8 +24,21 @@ import copy
import tvm import tvm
from tvm import te from tvm import te
from . import intrin 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): class DevContext(object):
"""Internal development context """Internal development context
...@@ -115,7 +128,7 @@ class Environment(object): ...@@ -115,7 +128,7 @@ class Environment(object):
# initialization function # initialization function
def __init__(self, cfg): def __init__(self, cfg):
# Produce the derived parameters and update dict # 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) self.__dict__.update(self.pkg.cfg_dict)
# data type width # data type width
self.INP_WIDTH = 1 << self.LOG_INP_WIDTH self.INP_WIDTH = 1 << self.LOG_INP_WIDTH
...@@ -172,12 +185,6 @@ class Environment(object): ...@@ -172,12 +185,6 @@ class Environment(object):
def __exit__(self, ptype, value, trace): def __exit__(self, ptype, value, trace):
Environment.current = self._last_env 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 @property
def cfg_dict(self): def cfg_dict(self):
return self.pkg.cfg_dict return self.pkg.cfg_dict
...@@ -308,17 +315,10 @@ def coproc_dep_pop(op): ...@@ -308,17 +315,10 @@ def coproc_dep_pop(op):
def _init_env(): def _init_env():
"""Initialize the default global env""" """Initialize the default global env"""
curr_path = os.path.dirname( config_path = os.path.join(get_vta_hw_path(), "config/vta_config.json")
os.path.abspath(os.path.expanduser(__file__))) if not os.path.exists(config_path):
proj_root = os.path.abspath(os.path.join(curr_path, "../../../")) raise RuntimeError("Cannot find config in %s" % str(config_path))
path_list = [ cfg = json.load(open(config_path))
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]))
return Environment(cfg) return Environment(cfg)
Environment.current = _init_env() Environment.current = _init_env()
...@@ -30,8 +30,7 @@ from tvm import rpc ...@@ -30,8 +30,7 @@ from tvm import rpc
from tvm.contrib import cc from tvm.contrib import cc
from vta import program_bitstream from vta import program_bitstream
from ..environment import get_env from ..environment import get_env, pkg_config
from ..pkg_config import PkgConfig
from ..libinfo import find_libvta from ..libinfo import find_libvta
...@@ -101,7 +100,7 @@ def server_start(): ...@@ -101,7 +100,7 @@ def server_start():
raise RuntimeError("Can only reconfig in the beginning of session...") raise RuntimeError("Can only reconfig in the beginning of session...")
cfg = json.loads(cfg_json) cfg = json.loads(cfg_json)
cfg["TARGET"] = env.TARGET cfg["TARGET"] = env.TARGET
pkg = PkgConfig(cfg, proj_root) pkg = pkg_config(cfg)
# check if the configuration is already the same # check if the configuration is already the same
if os.path.isfile(cfg_path): if os.path.isfile(cfg_path):
old_cfg = json.loads(open(cfg_path, "r").read()) old_cfg = json.loads(open(cfg_path, "r").read())
......
...@@ -19,6 +19,8 @@ from __future__ import absolute_import ...@@ -19,6 +19,8 @@ from __future__ import absolute_import
import sys import sys
import os import os
from .environment import get_vta_hw_path
def _get_lib_name(lib_name): def _get_lib_name(lib_name):
"""Get lib name with extension """Get lib name with extension
...@@ -57,7 +59,7 @@ def find_libvta(lib_vta, optional=False): ...@@ -57,7 +59,7 @@ def find_libvta(lib_vta, optional=False):
""" """
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) 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, "..", "..", "..", "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_name = _get_lib_name(lib_vta)
lib_path = [os.path.join(x, lib_name) for x in lib_search] 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)] lib_found = [x for x in lib_path if os.path.exists(x)]
......
...@@ -37,7 +37,7 @@ def _load_sw(): ...@@ -37,7 +37,7 @@ def _load_sw():
if env.TARGET == "tsim": if env.TARGET == "tsim":
lib_hw = find_libvta("libvta_hw", optional=True) 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: try:
f = tvm.get_global_func("vta.tsim.init") f = tvm.get_global_func("vta.tsim.init")
m = tvm.runtime.load_module(lib_hw[0], "vta-tsim") m = tvm.runtime.load_module(lib_hw[0], "vta-tsim")
......
...@@ -18,13 +18,18 @@ ...@@ -18,13 +18,18 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.2)
project(tsim C CXX) project(tsim C CXX)
set(TVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../) if(NOT DEFINED ENV{TVM_PATH})
set(VTA_HW_DIR ${TVM_DIR}/3rdparty/vta-hw) message(ERROR "Make sure to set TVM_PATH in your environment")
endif()
if(NOT DEFINED ENV{VTA_HW_PATH})
message(ERROR "Make sure to set VTA_HW_PATH in your environment")
endif()
include_directories("${TVM_DIR}/include") include_directories("$ENV{TVM_PATH}/include")
include_directories("${TVM_DIR}/3rdparty/dlpack/include") include_directories("$ENV{TVM_PATH}/3rdparty/dlpack/include")
include_directories("${TVM_DIR}/3rdparty/dmlc-core/include") include_directories("$ENV{TVM_PATH}/3rdparty/dmlc-core/include")
include_directories("${VTA_HW_DIR}/src/dpi") include_directories("$ENV{VTA_HW_PATH}/src/dpi")
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden") set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11") set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11")
...@@ -35,11 +40,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND ...@@ -35,11 +40,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
endif() endif()
file(GLOB TSIM_SW_SRC src/driver.cc) file(GLOB TSIM_SW_SRC src/driver.cc)
list(APPEND TSIM_SW_SRC ${VTA_HW_DIR}/src/vmem/virtual_memory.cc) list(APPEND TSIM_SW_SRC $ENV{VTA_HW_PATH}/src/vmem/virtual_memory.cc)
list(APPEND TSIM_SW_SRC ${VTA_HW_DIR}/src/dpi/module.cc) list(APPEND TSIM_SW_SRC $ENV{VTA_HW_PATH}/src/dpi/module.cc)
add_library(sw SHARED ${TSIM_SW_SRC}) add_library(sw SHARED ${TSIM_SW_SRC})
target_include_directories(sw PRIVATE ${VTA_HW_DIR}/include ${VTA_HW_DIR}/src) target_include_directories(sw PRIVATE $ENV{VTA_HW_PATH}/include $ENV{VTA_HW_PATH}/src)
if(APPLE) if(APPLE)
set_target_properties(sw PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") set_target_properties(sw PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
# under the License. # under the License.
export PYTHONPATH:=$(abspath .)/python:$(PYTHONPATH) export PYTHONPATH:=$(abspath .)/python:$(PYTHONPATH)
export PYTHONPATH:=$(abspath .)/../../../../python:$(PYTHONPATH)
BUILD_NAME = build BUILD_NAME = build
build_dir = $(abspath .)/$(BUILD_NAME) build_dir = $(abspath .)/$(BUILD_NAME)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
VTA TSIM Application VTA TSIM Application
====================== ======================
Prior to this application, please take a look at `<tvm-root>/vta/vta-hw/apps/tsim_example` for installation Prior to this application, please take a look at `<vta-hw-root>/apps/tsim_example` for installation
This is an application that performs Bit Serial Multiplication for GEMM utilizing TSIM. This is an application that performs Bit Serial Multiplication for GEMM utilizing TSIM.
**Bit Serial Multiplication for GEMM:** **Bit Serial Multiplication for GEMM:**
...@@ -28,7 +28,7 @@ We approach this operation with slicing and shifting, like how basic multiplicat ...@@ -28,7 +28,7 @@ We approach this operation with slicing and shifting, like how basic multiplicat
We can sufficiently reduce the cycles required to perform a gemm given that the data bit width is small. This GEMM application uses TSIM for future accerlerator prototypes. We can sufficiently reduce the cycles required to perform a gemm given that the data bit width is small. This GEMM application uses TSIM for future accerlerator prototypes.
* Test Chisel3 backend with bit serial GEMM * Test Chisel3 backend with bit serial GEMM
* Go to `<tvm-root>/vta/vta-hw/apps/gemm` * Go to `<vta-hw-root>/apps/gemm`
* Run `make` * Run `make`
* If you have already compiled chisel backend (i.e. ran `make`) * If you have already compiled chisel backend (i.e. ran `make`)
...@@ -36,15 +36,15 @@ We can sufficiently reduce the cycles required to perform a gemm given that the ...@@ -36,15 +36,15 @@ We can sufficiently reduce the cycles required to perform a gemm given that the
* Bit parallel test with another input set, run `make parallel` * Bit parallel test with another input set, run `make parallel`
* Some steps for creating your own custom TSIM application * Some steps for creating your own custom TSIM application
* Go to `<tvm-root>/vta/vta-hw/apps/gemm` * Go to `<vta-hw-root>/apps/gemm`
* Create custom circuit within `./hardware/chisel/src/scala.main/accel/Compute.scala` * Create custom circuit within `./hardware/chisel/src/scala.main/accel/Compute.scala`
* Map the according Registers in `./hardware/chisel/src/scala.main/accel/RegFile.scala` * Map the according Registers in `./hardware/chisel/src/scala.main/accel/RegFile.scala`
* Create your test script * Create your test script
* Map the registers in `./src/driver.cc` and link it with both `RegFile.scala` and the test script * Map the registers in `./src/driver.cc` and link it with both `RegFile.scala` and the test script
* Understanding of `<tvm-root>/vta/vta-hw/apps/tsim_example`, which performs add by one to a vector, is highly encouraged to create a more complex application * Understanding of `<vta-hw-root>/apps/tsim_example`, which performs add by one to a vector, is highly encouraged to create a more complex application
* Some pointers * Some pointers
* Chisel3 tests in `<tvm-root>/vta/vta-hw/apps/gemm/tests/python` * Chisel3 tests in `<vta-hw-root>/apps/gemm/tests/python`
* Chisel3 accelerator backend `<tvm-root>/vta/vta-hw/apps/gemm/hardware/chisel` * Chisel3 accelerator backend `<vta-hw-root>/apps/gemm/hardware/chisel`
* Software C++ driver (backend) that handles the accelerator `<tvm-root>/vta/vta-hw/apps/gemm/src/driver.cc` * Software C++ driver (backend) that handles the accelerator `<vta-hw-root>/apps/gemm/src/driver.cc`
* Software Python driver (frontend) that handles the accelerator `<tvm-root>vtay/vta-hw/apps/gemm/python/accel` * Software Python driver (frontend) that handles the accelerator `<vta-hw-root>/apps/gemm/python/accel`
...@@ -18,13 +18,18 @@ ...@@ -18,13 +18,18 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.2)
project(tsim C CXX) project(tsim C CXX)
set(TVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../) if(NOT DEFINED ENV{TVM_PATH})
set(VTA_HW_DIR ${TVM_DIR}/vta/vta-hw) message(ERROR "Make sure to set TVM_PATH in your environment")
endif()
if(NOT DEFINED ENV{VTA_HW_PATH})
message(ERROR "Make sure to set VTA_HW_PATH in your environment")
endif()
include_directories("${TVM_DIR}/include") include_directories("$ENV{TVM_PATH}/include")
include_directories("${TVM_DIR}/3rdparty/dlpack/include") include_directories("$ENV{TVM_PATH}/3rdparty/dlpack/include")
include_directories("${TVM_DIR}/3rdparty/dmlc-core/include") include_directories("$ENV{TVM_PATH}/3rdparty/dmlc-core/include")
include_directories("${VTA_HW_DIR}/src/dpi") include_directories("$ENV{VTA_HW_PATH}/src/dpi")
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden") set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11") set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11")
...@@ -35,11 +40,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND ...@@ -35,11 +40,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
endif() endif()
file(GLOB TSIM_SW_SRC src/driver.cc) file(GLOB TSIM_SW_SRC src/driver.cc)
list(APPEND TSIM_SW_SRC ${VTA_HW_DIR}/src/vmem/virtual_memory.cc) list(APPEND TSIM_SW_SRC $ENV{VTA_HW_PATH}/src/vmem/virtual_memory.cc)
list(APPEND TSIM_SW_SRC ${VTA_HW_DIR}/src/dpi/module.cc) list(APPEND TSIM_SW_SRC $ENV{VTA_HW_PATH}/src/dpi/module.cc)
add_library(sw SHARED ${TSIM_SW_SRC}) add_library(sw SHARED ${TSIM_SW_SRC})
target_include_directories(sw PRIVATE ${VTA_HW_DIR}/include ${VTA_HW_DIR}/src) target_include_directories(sw PRIVATE $ENV{VTA_HW_PATH}/include $ENV{VTA_HW_PATH}/src)
if(APPLE) if(APPLE)
set_target_properties(sw PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") set_target_properties(sw PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
......
...@@ -72,16 +72,16 @@ The default target language for these two implementations is Verilog. The follow ...@@ -72,16 +72,16 @@ The default target language for these two implementations is Verilog. The follow
how to run both of them: how to run both of them:
* Test Verilog backend * Test Verilog backend
* Go to `<tvm-root>/vta/vta-hw/apps/tsim_example` * Go to `<vta-hw-root>/apps/tsim_example`
* Run `make` * Run `make`
* Test Chisel3 backend * Test Chisel3 backend
* Go to `<tvm-root>/vta/vta-hw/apps/tsim_example` * Go to `<vta-hw-root>/apps/tsim_example`
* Run `make run_chisel` * Run `make run_chisel`
* Some pointers * Some pointers
* Verilog and Chisel3 tests in `<tvm-root>/vta/vta-hw/apps/tsim_example/tests/python` * Verilog and Chisel3 tests in `<vta-hw-root>/apps/tsim_example/tests/python`
* Verilog accelerator backend `<tvm-root>/vta/vta-hw/apps/tsim_example/hardware/verilog` * Verilog accelerator backend `<vta-hw-root>/apps/tsim_example/hardware/verilog`
* Chisel3 accelerator backend `<tvm-root>/vta/vta-hw/apps/tsim_example/hardware/chisel` * Chisel3 accelerator backend `<vta-hw-root>/apps/tsim_example/hardware/chisel`
* Software C++ driver (backend) that handles the accelerator `<tvm-root>/vta/vta-hw/apps/tsim_example/src/driver.cc` * Software C++ driver (backend) that handles the accelerator `<vta-hw-root>/apps/tsim_example/src/driver.cc`
* Software Python driver (frontend) that handles the accelerator `<tvm-root>vtay/vta-hw/apps/tsim_example/python/accel` * Software Python driver (frontend) that handles the accelerator `<vta-hw-root>/apps/tsim_example/python/accel`
...@@ -22,6 +22,22 @@ from __future__ import absolute_import as _abs ...@@ -22,6 +22,22 @@ from __future__ import absolute_import as _abs
import json import json
import glob import glob
import os
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_PATH = os.getenv('VTA_HW_PATH', vta_hw_default)
return VTA_HW_PATH
def get_tvm_path():
"""Get the TVM path."""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
tvm_default = os.path.abspath(os.path.join(curr_path, "../../.."))
TVM_PATH = os.getenv('TVM_PATH', tvm_default)
return TVM_PATH
class PkgConfig(object): class PkgConfig(object):
"""Simple package config tool for VTA. """Simple package config tool for VTA.
...@@ -32,9 +48,6 @@ class PkgConfig(object): ...@@ -32,9 +48,6 @@ class PkgConfig(object):
---------- ----------
cfg : dict cfg : dict
The config dictionary The config dictionary
proj_root : str
Path to the project root
""" """
cfg_keys = [ cfg_keys = [
"TARGET", "TARGET",
...@@ -49,7 +62,7 @@ class PkgConfig(object): ...@@ -49,7 +62,7 @@ class PkgConfig(object):
"LOG_ACC_BUFF_SIZE", "LOG_ACC_BUFF_SIZE",
] ]
def __init__(self, cfg, proj_root): def __init__(self, cfg):
# Derived parameters # Derived parameters
cfg["LOG_BLOCK_IN"] = cfg["LOG_BLOCK"] cfg["LOG_BLOCK_IN"] = cfg["LOG_BLOCK"]
...@@ -63,25 +76,29 @@ class PkgConfig(object): ...@@ -63,25 +76,29 @@ class PkgConfig(object):
# Update cfg now that we've extended it # Update cfg now that we've extended it
self.__dict__.update(cfg) self.__dict__.update(cfg)
# VTA_HW path and TVM_PATH
vta_hw_path = get_vta_hw_path()
tvm_path = get_tvm_path()
# Include path # Include path
self.include_path = [ self.include_path = [
"-I%s/include" % proj_root, "-I%s/include" % tvm_path,
"-I%s/vta/vta-hw/include" % proj_root, "-I%s/include" % vta_hw_path,
"-I%s/3rdparty/dlpack/include" % proj_root, "-I%s/3rdparty/dlpack/include" % tvm_path,
"-I%s/3rdparty/dmlc-core/include" % proj_root "-I%s/3rdparty/dmlc-core/include" % tvm_path
] ]
# List of source files that can be used to build standalone library. # List of source files that can be used to build standalone library.
self.lib_source = [] self.lib_source = []
self.lib_source += glob.glob("%s/vta/vta-hw/src/*.cc" % proj_root) self.lib_source += glob.glob("%s/src/*.cc" % vta_hw_path)
if self.TARGET in ["pynq", "ultra96"]: if self.TARGET in ["pynq", "ultra96"]:
# add pynq drivers for any board that uses pynq driver stack (see pynq.io) # add pynq drivers for any board that uses pynq driver stack (see pynq.io)
self.lib_source += glob.glob("%s/vta/vta-hw/src/pynq/*.cc" % (proj_root)) self.lib_source += glob.glob("%s/src/pynq/*.cc" % vta_hw_path)
elif self.TARGET in ["de10nano"]: elif self.TARGET in ["de10nano"]:
self.lib_source += glob.glob("%s/vta/vta-hw/src/de10nano/*.cc" % (proj_root)) self.lib_source += glob.glob("%s/src/de10nano/*.cc" % vta_hw_path)
self.include_path += [ self.include_path += [
"-I%s/vta/vta-hw/src/de10nano" % proj_root, "-I%s/src/de10nano" % vta_hw_path,
"-I%s/3rdparty" % proj_root "-I%s/3rdparty" % tvm_path
] ]
# Linker flags # Linker flags
......
...@@ -20,15 +20,17 @@ import sys ...@@ -20,15 +20,17 @@ import sys
import json import json
import argparse import argparse
def get_pkg_config(cfg):
"""Get the pkg config object.""" def pkg_config(cfg):
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) """Returns PkgConfig pkg config object."""
proj_root = os.path.abspath(os.path.join(curr_path, "../../../")) pkg_config_py = os.path.join(
pkg_config_py = os.path.join(proj_root, "vta/python/vta/pkg_config.py") os.path.dirname(os.path.abspath(os.path.expanduser(__file__))),
"pkg_config.py"
)
libpkg = {"__file__": pkg_config_py} libpkg = {"__file__": pkg_config_py}
exec(compile(open(pkg_config_py, "rb").read(), pkg_config_py, "exec"), libpkg, libpkg) exec(compile(open(pkg_config_py, "rb").read(), pkg_config_py, "exec"), libpkg, libpkg)
PkgConfig = libpkg["PkgConfig"] PkgConfig = libpkg["PkgConfig"]
return PkgConfig(cfg, proj_root) return PkgConfig(cfg)
def main(): def main():
"""Main funciton""" """Main funciton"""
...@@ -105,20 +107,13 @@ def main(): ...@@ -105,20 +107,13 @@ def main():
parser.print_help() parser.print_help()
return return
curr_path = os.path.dirname( # Path to vta config
os.path.abspath(os.path.expanduser(__file__))) config_path = "vta_config.json"
proj_root = os.path.abspath(os.path.join(curr_path, "../../../")) if not os.path.exists(config_path):
path_list = [ raise RuntimeError("Cannot find config in %s" % str(config_path))
os.path.join(proj_root, "vta/vta-hw/config/vta_config.json") cfg = json.load(open(config_path))
]
if args.use_cfg: pkg = pkg_config(cfg)
path_list = [args.use_cfg]
ok_path_list = [p for p in path_list if os.path.exists(p)]
if not ok_path_list:
raise RuntimeError("Cannot find config in %s" % str(path_list))
cfg = json.load(open(ok_path_list[0]))
pkg = get_pkg_config(cfg)
if args.target: if args.target:
print(pkg.TARGET) print(pkg.TARGET)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment