Skip to content

Commit

Permalink
Merge branch 'main' into pers-tflite-greater
Browse files Browse the repository at this point in the history
  • Loading branch information
dchauhan-arm authored Jun 22, 2022
2 parents 1525ac0 + 6ed3ab3 commit c209dc4
Show file tree
Hide file tree
Showing 33 changed files with 815 additions and 181 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions apps/microtvm/reference-vm/base-box-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@

# Extra scripts required to execute on provisioning
# in [platform]/base-box/base_box_provision.sh
COMMON_SCRIPTS = [
"apps/microtvm/reference-vm/base_box_setup_common.sh",
"docker/install/ubuntu_install_core.sh",
"docker/install/ubuntu_install_python.sh",
"docker/utils/apt-install-and-clear.sh",
]

EXTRA_SCRIPTS = {
"arduino": (
"apps/microtvm/reference-vm/base_box_setup_common.sh",
"docker/install/ubuntu_install_core.sh",
"docker/install/ubuntu_install_python.sh",
),
"zephyr": (
"apps/microtvm/reference-vm/base_box_setup_common.sh",
"docker/install/ubuntu_install_core.sh",
"docker/install/ubuntu_install_python.sh",
"arduino": [],
"zephyr": [
"docker/install/ubuntu_init_zephyr_project.sh",
"docker/install/ubuntu_install_zephyr_sdk.sh",
"docker/install/ubuntu_install_cmsis.sh",
),
],
}

PACKER_FILE_NAME = "packer.json"
Expand Down Expand Up @@ -251,7 +251,9 @@ def generate_packer_config(platform, file_path, providers):
repo_root = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], encoding="utf-8"
).strip()
for script in EXTRA_SCRIPTS[platform]:

scripts_to_copy = COMMON_SCRIPTS + EXTRA_SCRIPTS[platform]
for script in scripts_to_copy:
script_path = os.path.join(repo_root, script)
filename = os.path.basename(script_path)
provisioners.append({"type": "file", "source": script_path, "destination": f"~/{filename}"})
Expand Down
16 changes: 9 additions & 7 deletions apps/microtvm/reference-vm/base_box_setup_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
# specific language governing permissions and limitations
# under the License.

set -e
set -x

# Fix network DNS issue
sudo sed -i 's/DNSSEC=yes/DNSSEC=no/' /etc/systemd/resolved.conf
sudo systemctl restart systemd-resolved

sudo cp ~/apt-install-and-clear.sh /usr/local/bin/apt-install-and-clear
rm -f ~/apt-install-and-clear.sh

sudo apt update
sudo apt install -y build-essential
sudo apt-install-and-clear -y build-essential
sudo apt-get --purge remove modemmanager # required to access serial ports.

# Core
sudo ~/ubuntu_install_core.sh
rm -f ~/ubuntu_install_core.sh

sudo apt install -y --no-install-recommends git \
sudo apt-install-and-clear -y --no-install-recommends git \
gperf ccache dfu-util device-tree-compiler xz-utils file \
gcc gcc-multilib g++-multilib libsdl2-dev

Expand All @@ -40,22 +42,22 @@ wget --no-verbose https://apt.kitware.com/keys/kitware-archive-latest.asc
sudo apt-key add kitware-archive-latest.asc
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt update
sudo apt install -y --no-install-recommends \
sudo apt-install-and-clear -y --no-install-recommends \
cmake=3.22.2-0kitware1ubuntu18.04.1 cmake-data=3.22.2-0kitware1ubuntu18.04.1 \

# Python
sudo ~/ubuntu_install_python.sh
rm -f ~/ubuntu_install_python.sh

# Poetry deps
sudo apt install -y python3-venv
sudo apt-install-and-clear -y python3-venv

# TVM deps
# TODO(mehrdadh): replace with ubuntu_install_llvm.sh
sudo apt install -y llvm
sudo apt-install-and-clear -y llvm

# ONNX deps
sudo apt install -y protobuf-compiler libprotoc-dev
sudo apt-install-and-clear -y protobuf-compiler libprotoc-dev

# Poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <assert.h>
#include <float.h>
#include <kernel.h>
#include <power/reboot.h>
#include <stdio.h>
#include <string.h>
#include <sys/reboot.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/crt/logging.h>
#include <tvm/runtime/crt/stack_allocator.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
#include <drivers/uart.h>
#include <fatal.h>
#include <kernel.h>
#include <power/reboot.h>
#include <random/rand32.h>
#include <stdio.h>
#include <sys/printk.h>
#include <sys/reboot.h>
#include <sys/ring_buffer.h>
#include <tvm/runtime/crt/logging.h>
#include <tvm/runtime/crt/microtvm_rpc_server.h>
Expand Down
6 changes: 6 additions & 0 deletions docker/Dockerfile.ci_qemu
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,11 @@ RUN bash /install/ubuntu_install_ethosu_driver_stack.sh
COPY install/ubuntu_install_vela.sh /install/ubuntu_install_vela.sh
RUN bash /install/ubuntu_install_vela.sh

#Install CSI-NN2
COPY install/ubuntu_download_csinn2_compute_lib.sh /install/ubuntu_download_csinn2_compute_lib.sh
RUN bash /install/ubuntu_download_csinn2_compute_lib.sh

# Update PATH
ENV PATH /opt/arm/gcc-arm-none-eabi/bin:/opt/arm/FVP_Corstone_SSE-300/models/Linux64_GCC-6.4:$PATH
ENV PATH /opt/csi-nn2/csi-nn2/tools/gcc-toolchain/bin:$PATH
ENV PATH /opt/csi-nn2/csi-nn2/tools/qemu/bin:$PATH
41 changes: 41 additions & 0 deletions docker/install/ubuntu_download_csinn2_compute_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# 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.

set -e

install_path="/opt/csi-nn2"

# Clone CSI-NN2 Compute Library source code
git clone --depth 1 --branch 1.12.2 https://github.com/T-head-Semi/csi-nn2.git ${install_path}

# download cross-compiler when not building natively.
# riscv gcc toolchain will be downloaded to "/path/csi-nn2/tools/gcc-toolchain".
cd ${install_path}
./script/download_toolchain.sh

# download custom QEMU to "/path/csi-nn2/tools/qemu".
./script/download_qemu.sh

# build csinn2 lib for x86 and c906
# lib will be installed in /path/csi-nn2/install
# for x86
make -j4; cd x86_build; make install; cd -
# for c906
mkdir -p riscv_build; cd riscv_build
cmake ../ -DBUILD_RISCV=ON; make -j4; make install; cd -

3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ This folder contains the source of TVM's documentation, hosted at https://tvm.ap
# work on most environments (e.g. MacOS).
export TVM_TUTORIAL_EXEC_PATTERN=none

cd docs
make html
```

4. Run an HTTP server and visit http://localhost:8000 in your browser

```bash
cd docs/_build/html && python3 -m http.server
cd _build/html && python3 -m http.server
```

## Only Execute Specified Tutorials
Expand Down
13 changes: 7 additions & 6 deletions gallery/how_to/work_with_microtvm/micro_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,20 @@
import urllib.request

# Download datasets
os.makedirs(f"{FOLDER}/downloads")
os.makedirs(f"{FOLDER}/images")
urllib.request.urlretrieve(
"http://ai.stanford.edu/~jkrause/car196/cars_train.tgz", f"{FOLDER}/images/target.tgz"
"https://data.deepai.org/stanfordcars.zip", f"{FOLDER}/downloads/target.zip"
)
urllib.request.urlretrieve(
"http://images.cocodataset.org/zips/val2017.zip", f"{FOLDER}/images/random.zip"
"http://images.cocodataset.org/zips/val2017.zip", f"{FOLDER}/downloads/random.zip"
)

# Extract them and rename their folders
shutil.unpack_archive(f"{FOLDER}/images/target.tgz", f"{FOLDER}/images")
shutil.unpack_archive(f"{FOLDER}/images/random.zip", f"{FOLDER}/images")
shutil.move(f"{FOLDER}/images/cars_train", f"{FOLDER}/images/target")
shutil.move(f"{FOLDER}/images/val2017", f"{FOLDER}/images/random")
shutil.unpack_archive(f"{FOLDER}/downloads/target.zip", f"{FOLDER}/downloads")
shutil.unpack_archive(f"{FOLDER}/downloads/random.zip", f"{FOLDER}/downloads")
shutil.move(f"{FOLDER}/downloads/cars_train/cars_train", f"{FOLDER}/images/target")
shutil.move(f"{FOLDER}/downloads/val2017", f"{FOLDER}/images/random")

######################################################################
# Loading the Data
Expand Down
18 changes: 12 additions & 6 deletions include/tvm/relay/attrs/nn.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ struct Conv2DAttrs : public tvm::AttrsNode<Conv2DAttrs> {
tvm::String data_layout;
tvm::String kernel_layout;
tvm::String out_layout;
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
DataType out_dtype;

TVM_DECLARE_ATTRS(Conv2DAttrs, "relay.attrs.Conv2DAttrs") {
Expand Down Expand Up @@ -217,7 +218,8 @@ struct Conv2DWinogradAttrs : public tvm::AttrsNode<Conv2DWinogradAttrs> {
tvm::String data_layout;
tvm::String kernel_layout;
tvm::String out_layout;
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
DataType out_dtype;

TVM_DECLARE_ATTRS(Conv2DWinogradAttrs, "relay.attrs.Conv2DWinogradAttrs") {
Expand Down Expand Up @@ -308,7 +310,8 @@ struct Conv3DAttrs : public tvm::AttrsNode<Conv3DAttrs> {
tvm::String data_layout;
tvm::String kernel_layout;
tvm::String out_layout;
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
DataType out_dtype;

TVM_DECLARE_ATTRS(Conv3DAttrs, "relay.attrs.Conv3DAttrs") {
Expand Down Expand Up @@ -1049,7 +1052,8 @@ struct MatmulAttrs : public tvm::AttrsNode<MatmulAttrs> {
DataType out_dtype;
bool transpose_a;
bool transpose_b;
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights

TVM_DECLARE_ATTRS(MatmulAttrs, "relay.attrs.MatmulAttrs") {
TVM_ATTR_FIELD(units).describe("Number of hidden units of the dense transformation.");
Expand All @@ -1072,7 +1076,8 @@ struct MatmulAttrs : public tvm::AttrsNode<MatmulAttrs> {
/*! \brief Attributes for dense operator */
struct DenseAttrs : public tvm::AttrsNode<DenseAttrs> {
IndexExpr units;
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
DataType out_dtype;

TVM_DECLARE_ATTRS(DenseAttrs, "relay.attrs.DenseAttrs") {
Expand Down Expand Up @@ -1109,7 +1114,8 @@ struct BatchMatmulAttrs : public tvm::AttrsNode<BatchMatmulAttrs> {
DataType out_dtype;
bool transpose_a;
bool transpose_b;
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights

TVM_DECLARE_ATTRS(BatchMatmulAttrs, "relay.attrs.BatchMatmulAttrs") {
// use 0 bits to indicate none.
Expand Down
13 changes: 12 additions & 1 deletion include/tvm/tir/index_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,19 @@ class IndexMapNode : public Object {
v->Visit("final_indices", &final_indices);
}

static constexpr const char* _type_key = "tir.IndexMap";
bool SEqualReduce(const IndexMapNode* other, SEqualReducer equal) const {
return equal.DefEqual(initial_indices, other->initial_indices) &&
equal(final_indices, other->final_indices);
}

void SHashReduce(SHashReducer hash_reduce) const {
hash_reduce.DefHash(initial_indices);
hash_reduce(final_indices);
}

static constexpr const char* _type_key = "tir.IndexMap";
static constexpr const bool _type_has_method_sequal_reduce = true;
static constexpr const bool _type_has_method_shash_reduce = true;
TVM_DECLARE_FINAL_OBJECT_INFO(IndexMapNode, Object);
};

Expand Down
2 changes: 1 addition & 1 deletion jenkins/Jenkinsfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import org.jenkinsci.plugins.pipeline.modeldefinition.Utils

// NOTE: these lines are scanned by docker/dev_common.sh. Please update the regex as needed. -->
ci_lint = 'tlcpack/ci-lint:20220513-055910-fa834f67e'
ci_gpu = 'tlcpack/ci-gpu:20220606-055910-bf4b8f5c7'
ci_gpu = 'tlcpack/ci-gpu:20220619-055908-9bba7580b'
ci_cpu = 'tlcpack/ci-cpu:20220519-055908-ddfa1da69'
ci_wasm = 'tlcpack/ci-wasm:20220513-055910-fa834f67e'
ci_i386 = 'tlcpack/ci-i386:20220513-055910-fa834f67e'
Expand Down
6 changes: 1 addition & 5 deletions python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,11 +1443,7 @@ def convert_less_equal(self, op):

def convert_equal(self, op):
"""Convert TFLite EQUAL"""
if self.is_quantized(op):
raise tvm.error.OpNotImplemented(
"TFlite quantized EQUAL operator is not supported yet."
)
return self._convert_elemwise(_op.equal, op)
return self._convert_elemwise(_op.equal, op, self.is_quantized(op))

def convert_not_equal(self, op):
"""Convert TFLite NOT_EQUAL"""
Expand Down
16 changes: 9 additions & 7 deletions python/tvm/runtime/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def export_library(self, file_name, fcompile=None, addons=None, workspace_dir=No
files = addons if addons else []
is_system_lib = False
has_c_module = False
llvm_target_triple = None
llvm_target_string = None
for index, module in enumerate(modules):
if fcompile is not None and hasattr(fcompile, "object_format"):
if module.type_key == "c":
Expand Down Expand Up @@ -475,25 +475,27 @@ def export_library(self, file_name, fcompile=None, addons=None, workspace_dir=No
is_system_lib = (
module.type_key == "llvm" and module.get_function("__tvm_is_system_module")()
)
llvm_target_triple = (
module.type_key == "llvm" and module.get_function("_get_target_triple")()
llvm_target_string = (
module.type_key == "llvm" and module.get_function("_get_target_string")()
)
if not fcompile:
if file_name.endswith(".tar"):
fcompile = _tar.tar
else:
fcompile = _cc.create_shared

if llvm_target_triple is None and hasattr(fcompile, "get_target_triple"):
llvm_target_triple = fcompile.get_target_triple()
if llvm_target_string is None and hasattr(fcompile, "get_target_triple"):
triple = fcompile.get_target_triple()
assert triple, "Target triple should not be empty"
llvm_target_string = "llvm -mtriple " + triple

if getattr(fcompile, "need_system_lib", False) and not is_system_lib:
raise ValueError("%s need --system-lib option" % str(fcompile))

if self.imported_modules:
if enabled("llvm") and llvm_target_triple:
if enabled("llvm") and llvm_target_string:
path_obj = os.path.join(workspace_dir, f"devc.{object_format}")
m = _ffi_api.ModulePackImportsToLLVM(self, is_system_lib, llvm_target_triple)
m = _ffi_api.ModulePackImportsToLLVM(self, is_system_lib, llvm_target_string)
m.save(path_obj)
files.append(path_obj)
else:
Expand Down
Loading

0 comments on commit c209dc4

Please sign in to comment.