Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0785611
merge files
vegaluisjose Apr 10, 2019
a2938f3
move verilator to the right place
vegaluisjose Apr 11, 2019
dd916bc
change name to tsim
vegaluisjose Apr 11, 2019
0d904ca
add default rule to be build and run
vegaluisjose Apr 15, 2019
1b831ec
add README for tsim
vegaluisjose Apr 15, 2019
64fee4a
Update README.md
vegaluisjose Apr 15, 2019
72c0594
add some structural feedback
vegaluisjose Apr 30, 2019
9663cf7
change name of VTASim to VTADPISim
vegaluisjose Apr 30, 2019
ba7cf8e
more renaming
vegaluisjose Apr 30, 2019
ea39789
update comment
vegaluisjose Apr 30, 2019
db5ac08
add license
vegaluisjose Apr 30, 2019
45b5c25
fix indentation
vegaluisjose Apr 30, 2019
433d3cf
add switch for vta-tsim
vegaluisjose Apr 30, 2019
575f23b
add more licenses
vegaluisjose Apr 30, 2019
6b37aba
update readme
vegaluisjose Apr 30, 2019
8efa783
address some of the new feedback
vegaluisjose May 2, 2019
a815a01
add some feedback from cpplint
vegaluisjose May 2, 2019
ee8ea5b
add one more whitespace
vegaluisjose May 2, 2019
0b11f7d
pass pointer so linter is happy
vegaluisjose May 2, 2019
2bd51a9
pass pointer so linter is happy
vegaluisjose May 2, 2019
d2710aa
README moved to vta documentation
vegaluisjose May 2, 2019
5eacd9d
create types for dpi functions, so they can be handle easily
vegaluisjose May 2, 2019
19b1779
fix pointer style
vegaluisjose May 3, 2019
a499b4c
add feedback from docs
vegaluisjose May 4, 2019
c14ab57
parametrize width data and pointers
vegaluisjose May 4, 2019
0d24b77
fix comments
vegaluisjose May 4, 2019
8497eff
fix comment
vegaluisjose May 4, 2019
4db194e
add comment to class
vegaluisjose May 4, 2019
3c553cd
add missing parameters
vegaluisjose May 7, 2019
4409e7c
move README back to tsim example
vegaluisjose May 7, 2019
a047da7
add feedback
vegaluisjose May 7, 2019
35e7ccc
add more comments and remove un-necessary argument in finish
vegaluisjose May 7, 2019
7d531a4
update comments
vegaluisjose May 7, 2019
5d3ca7a
fix cpplint
vegaluisjose May 7, 2019
f098fc1
fix doc
vegaluisjose May 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ set(USE_SORT ON)

# Build ANTLR parser for Relay text format
set(USE_ANTLR OFF)

# Build TSIM for VTA
set(USE_VTA_TSIM OFF)
7 changes: 7 additions & 0 deletions cmake/modules/VTA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ elseif(PYTHON)
find_library(__cma_lib NAMES cma PATH /usr/lib)
target_link_libraries(vta ${__cma_lib})
endif()

if(NOT USE_VTA_TSIM STREQUAL "OFF")
include_directories("vta/include")
file(GLOB RUNTIME_DPI_SRCS vta/src/dpi/module.cc)
list(APPEND RUNTIME_SRCS ${RUNTIME_DPI_SRCS})
endif()

else()
message(STATUS "Cannot found python in env, VTA build is skipped..")
endif()
39 changes: 39 additions & 0 deletions vta/apps/tsim_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

cmake_minimum_required(VERSION 3.2)
project(tsim C CXX)

set(TVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../)
set(VTA_DIR ${TVM_DIR}/vta)

include_directories("${TVM_DIR}/include")
include_directories("${TVM_DIR}/3rdparty/dlpack/include")
include_directories("${TVM_DIR}/3rdparty/dmlc-core/include")
include_directories("${TVM_DIR}/vta/src/dpi")

set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11")

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
set(CMAKE_CXX_FLAGS "-faligned-new ${CMAKE_CXX_FLAGS}")
endif()

# Module rules
include(cmake/modules/tsim.cmake)
include(cmake/modules/driver.cmake)
45 changes: 45 additions & 0 deletions vta/apps/tsim_example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

export PYTHONPATH:=$(PWD)/python:$(PYTHONPATH)

BUILD_DIR = $(shell python python/tsim/config.py --get-build-name)

TVM_DIR = $(abspath ../../../)

TSIM_TARGET = verilog
TSIM_TOP_NAME = TestAccel
TSIM_BUILD_NAME = build

# optional
TSIM_TRACE_NAME = trace.vcd

default: cmake run

.PHONY: cmake

cmake: | $(BUILD_DIR)
cd $(BUILD_DIR) && cmake .. && make

$(BUILD_DIR):
mkdir -p $@

run:
python3 tests/python/test_tsim.py | grep PASS

clean:
-rm -rf $(BUILD_DIR)
52 changes: 52 additions & 0 deletions vta/apps/tsim_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# tsim-steps

*TSIM* can be used in both OSX and Linux. `verilator` is used as simulation backend and `sbt` for Chisel3.

## OSX dependencies

```bash
brew install verilator sbt
```

## Linux dependencies

### Add sbt to package manager (Debian-based)

```bash
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
```

### Install both sbt and verilator

```bash
sudo apt install verilator sbt
```

## Setup steps

1. Download repo and build tvm (build instructions [here](https://docs.tvm.ai/install/from_source.html))

```bash
git clone [email protected]:vegaluisjose/tvm.git
git checkout tsim
mkdir build
cp cmake/config.cmake build # enable USE_VTA_TSIM
cd build
cmake ..
make
```

2. Add-by-one Verilog example

```
cd tvm/vta/apps/tsim
make
```

3. Add-by-one Chisel3 example
* Open `tvm/vta/apps/tsim/python/tsim/config.json`
* Change `TARGET` from `verilog` to `chisel`
* Go to `tvm/vta/apps/tsim`
* Run `make`
24 changes: 24 additions & 0 deletions vta/apps/tsim_example/cmake/modules/driver.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

file(GLOB TSIM_SW_SRC src/driver.cc)
add_library(driver SHARED ${TSIM_SW_SRC})
target_include_directories(driver PRIVATE ${VTA_DIR}/include)

if(APPLE)
set_target_properties(driver PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif(APPLE)
152 changes: 152 additions & 0 deletions vta/apps/tsim_example/cmake/modules/tsim.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

if(MSVC)
message(STATUS "TSIM build is skipped in Windows..")
else()
find_program(PYTHON NAMES python python3 python3.6)
find_program(VERILATOR NAMES verilator)

if (VERILATOR AND PYTHON)

if (TSIM_TOP_NAME STREQUAL "")
message(FATAL_ERROR "TSIM_TOP_NAME should be defined")
endif()

if (TSIM_BUILD_NAME STREQUAL "")
message(FATAL_ERROR "TSIM_BUILD_NAME should be defined")
endif()

set(TSIM_CONFIG ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/python/tsim/config.py)

execute_process(COMMAND ${TSIM_CONFIG} --get-target OUTPUT_VARIABLE __TSIM_TARGET)
execute_process(COMMAND ${TSIM_CONFIG} --get-top-name OUTPUT_VARIABLE __TSIM_TOP_NAME)
execute_process(COMMAND ${TSIM_CONFIG} --get-build-name OUTPUT_VARIABLE __TSIM_BUILD_NAME)
execute_process(COMMAND ${TSIM_CONFIG} --get-use-trace OUTPUT_VARIABLE __TSIM_USE_TRACE)
execute_process(COMMAND ${TSIM_CONFIG} --get-trace-name OUTPUT_VARIABLE __TSIM_TRACE_NAME)

string(STRIP ${__TSIM_TARGET} TSIM_TARGET)
string(STRIP ${__TSIM_TOP_NAME} TSIM_TOP_NAME)
string(STRIP ${__TSIM_BUILD_NAME} TSIM_BUILD_NAME)
string(STRIP ${__TSIM_USE_TRACE} TSIM_USE_TRACE)
string(STRIP ${__TSIM_TRACE_NAME} TSIM_TRACE_NAME)

set(TSIM_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${TSIM_BUILD_NAME})

if (TSIM_TARGET STREQUAL "chisel")

find_program(SBT NAMES sbt)

if (SBT)

# Install Chisel VTA package for DPI modules
set(VTA_CHISEL_DIR ${VTA_DIR}/hardware/chisel)

execute_process(WORKING_DIRECTORY ${VTA_CHISEL_DIR}
COMMAND ${SBT} publishLocal RESULT_VARIABLE RETCODE)

if (NOT RETCODE STREQUAL "0")
message(FATAL_ERROR "[TSIM] sbt failed to install VTA scala package")
endif()

# Chisel - Scala to Verilog compilation
set(TSIM_CHISEL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hardware/chisel)
set(CHISEL_TARGET_DIR ${TSIM_BUILD_DIR}/chisel)
set(CHISEL_OPT "test:runMain test.Elaborate --target-dir ${CHISEL_TARGET_DIR} --top-name ${TSIM_TOP_NAME}")

execute_process(WORKING_DIRECTORY ${TSIM_CHISEL_DIR} COMMAND ${SBT} ${CHISEL_OPT} RESULT_VARIABLE RETCODE)

if (NOT RETCODE STREQUAL "0")
message(FATAL_ERROR "[TSIM] sbt failed to compile from Chisel to Verilog.")
endif()

file(GLOB VERILATOR_RTL_SRC ${CHISEL_TARGET_DIR}/*.v)

else()
message(FATAL_ERROR "[TSIM] sbt should be installed for Chisel")
endif() # sbt

elseif (TSIM_TARGET STREQUAL "verilog")

set(VTA_VERILOG_DIR ${VTA_DIR}/hardware/chisel/src/main/resources/verilog)
set(TSIM_VERILOG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hardware/verilog)
file(GLOB VERILATOR_RTL_SRC ${VTA_VERILOG_DIR}/*.v ${TSIM_VERILOG_DIR}/*.v)

else()
message(STATUS "[TSIM] target language can be only verilog or chisel...")
endif() # TSIM_TARGET

if (TSIM_TARGET STREQUAL "chisel" OR TSIM_TARGET STREQUAL "verilog")

# Check if tracing can be enabled
if (NOT TSIM_USE_TRACE STREQUAL "OFF")
message(STATUS "[TSIM] Verilog enable tracing")
else()
message(STATUS "[TSIM] Verilator disable tracing")
endif()

# Verilator - Verilog to C++ compilation
set(VERILATOR_TARGET_DIR ${TSIM_BUILD_DIR}/verilator)
set(VERILATOR_OPT +define+RANDOMIZE_GARBAGE_ASSIGN +define+RANDOMIZE_REG_INIT)
list(APPEND VERILATOR_OPT +define+RANDOMIZE_MEM_INIT --x-assign unique)
list(APPEND VERILATOR_OPT --output-split 20000 --output-split-cfuncs 20000)
list(APPEND VERILATOR_OPT --top-module ${TSIM_TOP_NAME} -Mdir ${VERILATOR_TARGET_DIR})
list(APPEND VERILATOR_OPT --cc ${VERILATOR_RTL_SRC})

if (NOT TSIM_USE_TRACE STREQUAL "OFF")
list(APPEND VERILATOR_OPT --trace)
endif()

execute_process(COMMAND ${VERILATOR} ${VERILATOR_OPT} RESULT_VARIABLE RETCODE)

if (NOT RETCODE STREQUAL "0")
message(FATAL_ERROR "[TSIM] Verilator failed to compile Verilog to C++...")
endif()

# Build shared library (.so)
set(VTA_HW_DPI_DIR ${VTA_DIR}/hardware/dpi)
set(VERILATOR_INC_DIR /usr/local/share/verilator/include)
set(VERILATOR_LIB_SRC ${VERILATOR_INC_DIR}/verilated.cpp ${VERILATOR_INC_DIR}/verilated_dpi.cpp)

if (NOT TSIM_USE_TRACE STREQUAL "OFF")
list(APPEND VERILATOR_LIB_SRC ${VERILATOR_INC_DIR}/verilated_vcd_c.cpp)
endif()

file(GLOB VERILATOR_GEN_SRC ${VERILATOR_TARGET_DIR}/*.cpp)
file(GLOB VERILATOR_SRC ${VTA_HW_DPI_DIR}/tsim_device.cc)
add_library(tsim SHARED ${VERILATOR_LIB_SRC} ${VERILATOR_GEN_SRC} ${VERILATOR_SRC})

set(VERILATOR_DEF VL_TSIM_NAME=V${TSIM_TOP_NAME} VL_PRINTF=printf VM_COVERAGE=0 VM_SC=0)
if (NOT TSIM_USE_TRACE STREQUAL "OFF")
list(APPEND VERILATOR_DEF VM_TRACE=1 TSIM_TRACE_FILE=${TSIM_BUILD_DIR}/${TSIM_TRACE_NAME}.vcd)
else()
list(APPEND VERILATOR_DEF VM_TRACE=0)
endif()
target_compile_definitions(tsim PRIVATE ${VERILATOR_DEF})
target_compile_options(tsim PRIVATE -Wno-sign-compare -include V${TSIM_TOP_NAME}.h)
target_include_directories(tsim PRIVATE ${VERILATOR_TARGET_DIR} ${VERILATOR_INC_DIR} ${VERILATOR_INC_DIR}/vltstd ${VTA_DIR}/include)

if(APPLE)
set_target_properties(tsim PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif(APPLE)

endif() # TSIM_TARGET STREQUAL "chisel" OR TSIM_TARGET STREQUAL "verilog"

else()
message(STATUS "[TSIM] could not find Python or Verilator, build is skipped...")
endif() # VERILATOR
endif() # MSVC
19 changes: 19 additions & 0 deletions vta/apps/tsim_example/hardware/chisel/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

clean:
-rm -rf target project/target project/project
Loading