Skip to content

Commit

Permalink
Merge branch 'main' into vc/pytorch_lstm
Browse files Browse the repository at this point in the history
  • Loading branch information
vvchernov authored Jul 12, 2021
2 parents 576651d + 15bdf28 commit 197f49f
Show file tree
Hide file tree
Showing 287 changed files with 12,494 additions and 5,110 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
//

// NOTE: these lines are scanned by docker/dev_common.sh. Please update the regex as needed. -->
ci_lint = "tlcpack/ci-lint:v0.65"
ci_lint = "tlcpack/ci-lint:v0.66"
ci_gpu = "tlcpack/ci-gpu:v0.75"
ci_cpu = "tlcpack/ci-cpu:v0.74"
ci_wasm = "tlcpack/ci-wasm:v0.71"
Expand Down
156 changes: 92 additions & 64 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,89 @@
# specific language governing permissions and limitations
# under the License.


.PHONY: all \
runtime vta cpptest crttest \
lint pylint cpplint scalalint \
doc \
web webclean \
cython cython3 cyclean \
clean

.SECONDEXPANSION:

# Remember the root directory, to be usable by submake invocation.
ROOTDIR = $(CURDIR)
# Specify an alternate output directory relative to ROOTDIR. Default build
OUTPUTDIR = $(if $(OUTDIR), $(OUTDIR), build)

.PHONY: clean all test doc pylint cpplint scalalint lint\
cython cython2 cython3 web runtime vta
# Specify an alternate output directory relative to ROOTDIR. Defaults
# to "build". Can also be a space-separated list of build
# directories, each with a different configuation.
TVM_BUILD_PATH ?= build
TVM_BUILD_PATH := $(abspath $(TVM_BUILD_PATH))

ifndef DMLC_CORE_PATH
DMLC_CORE_PATH = $(ROOTDIR)/3rdparty/dmlc-core
endif
# Allow environment variables for 3rd-party libraries, default to
# packaged version.
DMLC_CORE_PATH ?= $(ROOTDIR)/3rdparty/dmlc-core
DLPACK_PATH ?= $(ROOTDIR)/3rdparty/dlpack
VTA_HW_PATH ?= $(ROOTDIR)/3rdparty/vta-hw

ifndef DLPACK_PATH
DLPACK_PATH = $(ROOTDIR)/3rdparty/dlpack
endif

ifndef VTA_HW_PATH
VTA_HW_PATH = $(ROOTDIR)/3rdparty/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 =

all: $(addsuffix /all,$(TVM_BUILD_PATH))

runtime: $(addsuffix /runtime,$(TVM_BUILD_PATH))
vta: $(addsuffix /vta,$(TVM_BUILD_PATH))
cpptest: $(addsuffix /cpptest,$(TVM_BUILD_PATH))
crttest: $(addsuffix /crttest,$(TVM_BUILD_PATH))

# If there is a config.cmake in the tvm directory, preferentially use
# it. Otherwise, copy the default cmake/config.cmake.
ifeq ($(wildcard config.cmake),config.cmake)
%/config.cmake: | config.cmake
@echo "No config.cmake found in $(TVM_BUILD_PATH), using config.cmake in root tvm directory"
@mkdir -p $(@D)
else
# filter-out used to avoid circular dependency
%/config.cmake: | $$(filter-out %/config.cmake,$(ROOTDIR)/cmake/config.cmake)
@echo "No config.cmake found in $(TVM_BUILD_PATH), using default config.cmake"
@mkdir -p $(@D)
@cp $| $@
endif

all:
@mkdir -p $(OUTPUTDIR) && cd $(OUTPUTDIR) && cmake .. && $(MAKE)

runtime:
@mkdir -p $(OUTPUTDIR) && cd $(OUTPUTDIR) && cmake .. && $(MAKE) runtime
# Cannot use .PHONY with a pattern rule, using FORCE instead. For
# now, force cmake to be re-run with each compile to mimic previous
# behavior. This may be relaxed in the future with the
# CONFIGURE_DEPENDS option for GLOB (requres cmake >= 3.12).
FORCE:
%/CMakeCache.txt: %/config.cmake FORCE
@cd $(@D) && cmake $(ROOTDIR)

vta:
@mkdir -p $(OUTPUTDIR) && cd $(OUTPUTDIR) && cmake .. && $(MAKE) vta

cpptest:
@mkdir -p $(OUTPUTDIR) && cd $(OUTPUTDIR) && cmake .. && $(MAKE) cpptest
# Since the pattern stem is already being used for the directory name,
# cannot also have it refer to the command passed to cmake.
# Therefore, explicitly listing out the delegated.
CMAKE_TARGETS = all runtime vta cpptest crttest

crttest:
@mkdir -p $(OUTPUTDIR) && cd $(OUTPUTDIR) && cmake .. && $(MAKE) crttest
define GEN_CMAKE_RULE
%/$(CMAKE_TARGET): %/CMakeCache.txt
@$$(MAKE) -C $$(@D) $(CMAKE_TARGET)
endef
$(foreach CMAKE_TARGET,$(CMAKE_TARGETS),$(eval $(GEN_CMAKE_RULE)))

# EMCC; Web related scripts
EMCC_FLAGS= -std=c++11\
-Oz -s RESERVED_FUNCTION_POINTERS=2 -s MAIN_MODULE=1 -s NO_EXIT_RUNTIME=1\
-s TOTAL_MEMORY=1073741824\
-s EXTRA_EXPORTED_RUNTIME_METHODS="['addFunction','cwrap','getValue','setValue']"\
-s USE_GLFW=3 -s USE_WEBGL2=1 -lglfw\
$(INCLUDE_FLAGS)

web: $(OUTPUTDIR)/libtvm_web_runtime.js $(OUTPUTDIR)/libtvm_web_runtime.bc

$(OUTPUTDIR)/libtvm_web_runtime.bc: web/web_runtime.cc
@mkdir -p $(OUTPUTDIR)/web
@mkdir -p $(@D)
emcc $(EMCC_FLAGS) -MM -MT $(OUTPUTDIR)/libtvm_web_runtime.bc $< >$(OUTPUTDIR)/web/web_runtime.d
emcc $(EMCC_FLAGS) -o $@ web/web_runtime.cc
# Dev tools for formatting, linting, and documenting. NOTE: lint
# scripts that are executed in the CI should be in tests/lint. This
# allows docker/lint.sh to behave similarly to the CI.
format:
./tests/lint/git-clang-format.sh -i origin/main
black .
cd rust && which cargo && cargo fmt --all

$(OUTPUTDIR)/libtvm_web_runtime.js: $(OUTPUTDIR)/libtvm_web_runtime.bc
@mkdir -p $(@D)
emcc $(EMCC_FLAGS) -o $@ $(OUTPUTDIR)/libtvm_web_runtime.bc
lint: cpplint pylint jnilint

# Lint scripts
# NOTE: lint scripts that are executed in the CI should be in tests/lint. This allows docker/lint.sh
# to behave similarly to the CI.
cpplint:
tests/lint/cpplint.sh

Expand All @@ -89,29 +110,36 @@ jnilint:
scalalint:
make -C $(VTA_HW_PATH)/hardware/chisel lint

lint: cpplint pylint jnilint

mypy:
tests/scripts/task_mypy.sh

doc:
doxygen docs/Doxyfile

javadoc:
# build artifact is in jvm/core/target/site/apidocs
cd jvm && mvn javadoc:javadoc -Dnotimestamp=true

# Cython build
cython:
cd python; python3 setup.py build_ext --inplace

cython3:
cython cython3:
cd python; python3 setup.py build_ext --inplace

cyclean:
rm -rf python/tvm/*/*/*.so python/tvm/*/*/*.dylib python/tvm/*/*/*.cpp



# EMCC; Web related scripts
web:
$(MAKE) -C $(ROOTDIR)/web

webclean:
$(MAKE) -C $(ROOTDIR)/web clean


# JVM build rules
INCLUDE_FLAGS = -Iinclude -I$(DLPACK_PATH)/include -I$(DMLC_CORE_PATH)/include
PKG_CFLAGS = -std=c++11 -Wall -O2 $(INCLUDE_FLAGS) -fPIC
PKG_LDFLAGS =

ifeq ($(OS),Windows_NT)
JVM_PKG_PROFILE := windows
SHARED_LIBRARY_SUFFIX := dll
Expand All @@ -126,24 +154,24 @@ else
endif
endif

JVM_TEST_ARGS := $(if $(JVM_TEST_ARGS),$(JVM_TEST_ARGS),-DskipTests -Dcheckstyle.skip=true)
JVM_TEST_ARGS ?= -DskipTests -Dcheckstyle.skip=true

# Built java docs are in jvm/core/target/site/apidocs
javadoc:
(cd $(ROOTDIR)/jvm; \
mvn "javadoc:javadoc" -Dnotimestamp=true)

jvmpkg:
(cd $(ROOTDIR)/jvm; \
mvn clean package -P$(JVM_PKG_PROFILE) -Dcxx="$(CXX)" \
-Dcflags="$(PKG_CFLAGS)" -Dldflags="$(PKG_LDFLAGS)" \
-Dcurrent_libdir="$(ROOTDIR)/$(OUTPUTDIR)" $(JVM_TEST_ARGS))
-Dcurrent_libdir="$(TVM_BUILD_PATH)" $(JVM_TEST_ARGS))

jvminstall:
(cd $(ROOTDIR)/jvm; \
mvn install -P$(JVM_PKG_PROFILE) -Dcxx="$(CXX)" \
-Dcflags="$(PKG_CFLAGS)" -Dldflags="$(PKG_LDFLAGS)" \
-Dcurrent_libdir="$(ROOTDIR)/$(OUTPUTDIR)" $(JVM_TEST_ARGS))
format:
./tests/lint/git-clang-format.sh -i origin/main
black .
cd rust; which cargo && cargo fmt --all; cd ..

-Dcurrent_libdir="$(TVM_BUILD_PATH)" $(JVM_TEST_ARGS))

# clean rule
clean:
@mkdir -p $(OUTPUTDIR) && cd $(OUTPUTDIR) && cmake .. && $(MAKE) clean
# Final cleanup rules, delegate to more specific rules.
clean: cmake_clean cyclean webclean
2 changes: 1 addition & 1 deletion apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ they also serve as examples on how to use TVM in your own project.
- [android_rpc](android_rpc) Android RPC server.
- [benchmark](benchmark) Example end to end compilation benchmarks
- [howto_deploy](howto_deploy) Tutorial on how to deploy TVM with minimum code dependency.
- [wasm_standalone](tvm-standalone) WebAssembly standalone for deep learning framework with TVM runtime.
- [wasm_standalone](wasm-standalone) WebAssembly standalone for deep learning framework with TVM runtime.
1 change: 1 addition & 0 deletions apps/microtvm/reference-vm/zephyr/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Vagrant.configure("2") do |config|
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "on"]
vb.customize ["modifyvm", :id, "--usbxhci", "on"]
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
dirs_to_mount.each do |d|
overrides.vm.synced_folder d.to_s, d.to_s
end
Expand Down
31 changes: 31 additions & 0 deletions apps/microtvm/zephyr/aot_demo/boards/nucleo_l4r5zi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.
#
# This file is specific to the STM32L4R5ZI Nucleo board.

# For intrinsics used by generated optimized operators.
CONFIG_CMSIS_DSP=y

# For AOT runtime which requires lots of function call.
CONFIG_MAIN_STACK_SIZE=3000

# For random number generation.
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

# For debugging.
CONFIG_LED=y
4 changes: 2 additions & 2 deletions apps/microtvm/zephyr/aot_demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define WORKSPACE_SIZE (270 * 1024)

static uint8_t g_aot_memory[WORKSPACE_SIZE];
extern tvm_model_t network;
extern tvm_model_t tvmgen_default_network;
tvm_workspace_t app_workspace;

// Wakeup sequence used to wake up QEMU on the host.
Expand Down Expand Up @@ -205,7 +205,7 @@ void main(void) {

double elapsed_time = 0;
TVMPlatformTimerStart();
int ret_val = tvm_runtime_run(&network, inputs, outputs);
int ret_val = tvm_runtime_run(&tvmgen_default_network, inputs, outputs);
TVMPlatformTimerStop(&elapsed_time);

if (ret_val != 0) {
Expand Down
6 changes: 6 additions & 0 deletions apps/microtvm/zephyr/aot_demo/src/zephyr_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ uint32_t TVMPlatformWriteSerial(const char* data, uint32_t size) {
void TVMPlatformUARTInit() {
// Claim console device.
g_microtvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
const struct uart_config config = {.baudrate = 115200,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
uart_configure(g_microtvm_uart, &config);
uart_rx_init(&uart_rx_rbuf, g_microtvm_uart);
}
31 changes: 31 additions & 0 deletions apps/microtvm/zephyr/host_driven/boards/nucleo_l4r5zi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.
#
# This file is specific to the STM32L4R5ZI Nucleo board.

# For intrinsics used by generated optimized operators.
CONFIG_CMSIS_DSP=y

# For operations that stack allocates a large float array.
CONFIG_MAIN_STACK_SIZE=1536

# For random number generation.
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

# For debugging.
CONFIG_LED=y
2 changes: 1 addition & 1 deletion cmake/modules/CUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(USE_CUDA)
if(NOT CUDA_FOUND)
message(FATAL_ERROR "Cannot find CUDA, USE_CUDA=" ${USE_CUDA})
endif()
message(STATUS "Build with CUDA support")
message(STATUS "Build with CUDA ${CUDA_VERSION} support")
file(GLOB RUNTIME_CUDA_SRCS src/runtime/cuda/*.cc)
list(APPEND RUNTIME_SRCS ${RUNTIME_CUDA_SRCS})
list(APPEND COMPILER_SRCS src/target/opt/build_cuda_on.cc)
Expand Down
15 changes: 15 additions & 0 deletions cmake/modules/Git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# - GIT_FOUND - true if the command line client was found
# - GIT_EXECUTABLE - path to git command line client
# - TVM_GIT_COMMIT_HASH - The git commit hash found, or "NOT-FOUND" if anything went wrong
# - TVM_GIT_COMMIT_TIME - The git commit time, or "NOT-FOUND" if antything went wrong
find_package(Git QUIET)
if (${GIT_FOUND})
message(STATUS "Git found: ${GIT_EXECUTABLE}")
Expand All @@ -35,7 +36,21 @@ if (${GIT_FOUND})
message(STATUS "Not a git repo")
set(TVM_GIT_COMMIT_HASH "NOT-FOUND")
endif()

execute_process(COMMAND ${GIT_EXECUTABLE} show -s --format=%ci HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE TVM_GIT_COMMIT_TIME
RESULT_VARIABLE _TVM_GIT_RESULT
ERROR_VARIABLE _TVM_GIT_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if (${_TVM_GIT_RESULT} EQUAL 0)
message(STATUS "Found TVM_GIT_COMMIT_TIME=${TVM_GIT_COMMIT_TIME}")
else()
set(TVM_GIT_COMMIT_TIME "NOT-FOUND")
endif()
else()
message(WARNING "Git not found")
set(TVM_GIT_COMMIT_HASH "NOT-FOUND")
set(TVM_GIT_COMMIT_TIME "NOT-FOUND")
endif()
8 changes: 8 additions & 0 deletions cmake/modules/LibInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ function(add_lib_info src_file)
else()
string(STRIP ${TVM_INFO_LLVM_VERSION} TVM_INFO_LLVM_VERSION)
endif()
if (NOT DEFINED CUDA_VERSION)
set(TVM_INFO_CUDA_VERSION "NOT-FOUND")
else()
string(STRIP ${CUDA_VERSION} TVM_INFO_CUDA_VERSION)
endif()

set_property(
SOURCE ${src_file}
APPEND
PROPERTY COMPILE_DEFINITIONS
TVM_INFO_GIT_COMMIT_HASH="${TVM_GIT_COMMIT_HASH}"
TVM_INFO_GIT_COMMIT_TIME="${TVM_GIT_COMMIT_TIME}"
TVM_INFO_USE_CUDA="${USE_CUDA}"
TVM_INFO_USE_OPENCL="${USE_OPENCL}"
TVM_INFO_USE_VULKAN="${USE_VULKAN}"
Expand All @@ -41,6 +48,7 @@ function(add_lib_info src_file)
TVM_INFO_USE_THREADS="${USE_THREADS}"
TVM_INFO_USE_LLVM="${USE_LLVM}"
TVM_INFO_LLVM_VERSION="${TVM_INFO_LLVM_VERSION}"
TVM_INFO_CUDA_VERSION="${TVM_INFO_CUDA_VERSION}"
TVM_INFO_USE_STACKVM_RUNTIME="${USE_STACKVM_RUNTIME}"
TVM_INFO_USE_GRAPH_EXECUTOR="${USE_GRAPH_EXECUTOR}"
TVM_INFO_USE_GRAPH_EXECUTOR_DEBUG="${USE_GRAPH_EXECUTOR_DEBUG}"
Expand Down
Loading

0 comments on commit 197f49f

Please sign in to comment.