[incubator-tvm] branch cargo-build updated (f10ab21 -> 1604de7)

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a change to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


 discard f10ab21  Debug segfault from loading Python
 discard b8dcc35  WIP
 discard a9ee3cb  WIP
 discard 49246bf  WIP
 discard 8e295b7  Fix some CR
 discard 1874350  More cleanup
 discard 6828374  Fix the extension code
 discard 04a9779  Format and cleanup
 discard 0cabfdc  Remove type checker
 discard 6e13467  Rust Diagnostics work
 discard 4261461  Fix
 discard eeb86c6  Fix calling
 discard 4cd1bbc  Improve Rust bindings
 discard 20c6a28  Clean up exporting to show off new diagnostics
 discard e0f9801  Fix Linux build
 discard db24553  Update CMake and delete old API
 discard b2b59c2  Borrow code from Egg
 discard 131e40a  Hacking on Rust inside of TVM
 discard cb37856  WIP
 discard 77ba309  Codespan example almost working
 discard 1097cbf  Add initial boilerplate for Rust diagnostic interface.
 add 0ce55cb  [CI] Keras version upgraded from 2.3.1 to 2.4.3 (#6793)
 add 9a32e70  [TVMSCRIPT] Add synr dependency in preparation for tvmscript 
diagnostics overhaul. (#6795)
 add 7196eb8  [BYOC] Allow custom codegens to register their own constant 
updater (#6697)
 add a261454  [AutoScheduler] Relay integration : Task extraction (#6710)
 add 2625866  Fix mutate auto unroll (#6807)
 add 50fc938  [CI] Pin h5py version to < 3.0 to workaround issues with 
TF/Keras (#6808)
 add ceef616  Extract channels from weight shape for conv2d. (#6805)
 add f956c38  [µTVM] Add serial transport, parameterize µTVM Zephyr test, 
run on physical HW (#6789)
 add 616bad2  [CI] Add m6g instance (ARM64) to mainline CI (#6804)
 add 0dc7de5  [CI] Move back Keras to 2.4.3 (#6810)
 add b07ddea  [CI] Update to latest (#6812)
 add 9d506ad  [OBJECT] Update types slots for baseexpr and primexpr (#6814)
 add 883954e  [Rust][Diagnostics] Add initial boilerplate for Rust 
diagnostic interface. (#6656)
 add 73f425d  TF frontend: add softsign op (#6799)
 add 9f9d475  [TENSORFLOW]Sparse2Dense support (#5767)
 add 9c2d68d  [AutoScheduler] New layout rewrite option: Weight 
pre-transpose (#6750)
 add 3222cad  Update stale link to new location (#6819)
 add 6dc8e22  [rust][tvm-graph-rt]: maintain error sources when propagating 
errors, swap Mutex for RwLock (#6815)
 add 01b98c1  Improve AArch64 depthwise convolution through smlal/smlal2 
intrinsic (#6711)
 add 174e21a  [CI] Torch 1.7 update to mainline (#6828)
 add 26b2e16  [TF] Fix a bug in _stridedSlice() (#6829)
 add 896cb10  [CI] remove unused environment var (#6824)
 add 8877ed5  [TVMC] 'tvmc tune' --rpc-tracker and --rpc-tracker fail due 
to argparse misconfiguration (#6822)
 add b4db112  Fix Annotate Target to support freevars(relay.zeros, 
relay.ones etc) of any size (including zero)  (#6826)
 add 4122def  [DOCS] Enable theme with header and footer. (#6834)
 add 9b97b56  Update link (#6838)
 add 6e36fc4  [BYOC] FTVMAnnotateTarget method signature update (#6786)
 add db28544  [CI] Disable flaky tests (#6841)
 add 0c02780  [Relay][Frontend] SparseTensorDenseMatMul support for 
Tensorflow (#6685)
 add 237744d  Register shape functions for some image related ops (#6373)
 add 8370396  [TopHub] Bump the versions (#6837)
 add 6019db2  [Graph memory plan] Support nested tuples (#6809)
 add 5471cd2  [CI] Add python setup script (#6844)
 add 47d9415  Syntax error String::fromwe() should be String::from() (#6846)
 add b8761ed  [AutoScheduler] Bug fix for layout rewrite CI error in i386 
(#6830)
 add 3ff0100  [CI] Add more guidelines about local setup (#6848)
 add 8013a23  [FIX] Add task_ci_python_setup.sh to the arm CI (#6850)
 add c475dff  Update SimplifyInference documentation (#6853)
 add 7291a92  [µTVM] Add virtual machine, test zephyr runtime on real 
hardware (#6703)
 add a4bd5f8  [Rust][IRModule] Flesh out IRModule methods (#6741)
 add 7ee91da  [TOPI] Enable scatter_add on GPU  (#6856)
 add 9ea4bf5  [Relay][Frontend][Onnx] If Operator Support (#6730)
 add b31f4ae  [QNN] Dynamic scale, zero point in qnn.op.dequantize (#6849)
 add d164aac  [TVMSCRIPT] Using diagnostics for TVM Script (#6797)
 add 0469a77  [BYOC] [ACL] ACL Runtime padding workaround (#6724)
 new 35d49bf  Debug segfault from loading Python
 new 1604de7  SciPy causes crashes

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (f10ab21)
\
 N -- N -- N   refs/heads/cargo-build (1604de7)

You should already have received notification emails for all of the O
revisions, and so the following 

[incubator-tvm] 01/02: Debug segfault from loading Python

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 35d49bf279a07aaa92e255bb5d48ae485bda3cdf
Author: Jared Roesch 
AuthorDate: Sun Oct 25 17:26:47 2020 -0700

Debug segfault from loading Python
---
 python/tvm/__init__.py|  2 ++
 python/tvm/relay/__init__.py  |  3 +-
 python/tvm/relay/analysis/__init__.py |  2 +-
 python/tvm/relay/analysis/analysis.py |  6 ++--
 python/tvm/relay/analysis/annotated_regions.py|  2 +-
 python/tvm/relay/analysis/call_graph.py   |  4 +--
 python/tvm/relay/analysis/sparse_dense.py | 15 
 python/tvm/relay/backend/graph_runtime_factory.py |  2 +-
 python/tvm/relay/build_module.py  |  5 ++-
 python/tvm/relay/op/op.py | 43 +++
 python/tvm/relay/transform/__init__.py|  2 +-
 python/tvm/relay/transform/memory_alloc.py|  7 ++--
 python/tvm/relay/transform/transform.py   |  5 +--
 python/tvm/topi/cuda/__init__.py  |  2 --
 python/tvm/topi/cuda/sparse.py|  3 +-
 rust/tvm-rt/src/map.rs| 12 +++
 rust/tvm-rt/src/module.rs | 16 +
 rust/tvm-rt/src/to_function.rs|  1 +
 rust/tvm/Cargo.toml   |  2 +-
 rust/tvm/src/python.rs| 21 ---
 src/runtime/module.cc |  2 +-
 21 files changed, 101 insertions(+), 56 deletions(-)

diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py
index 569e8f0..60f81f4 100644
--- a/python/tvm/__init__.py
+++ b/python/tvm/__init__.py
@@ -67,6 +67,8 @@ from . import support
 # Contrib initializers
 from .contrib import rocm as _rocm, nvcc as _nvcc, sdaccel as _sdaccel
 
+def cleanup():
+_ffi.base._LIB = None
 
 def tvm_wrap_excepthook(exception_hook):
 """Wrap given excepthook with TVM additional work."""
diff --git a/python/tvm/relay/__init__.py b/python/tvm/relay/__init__.py
index cd96ecc..7e6ed4f 100644
--- a/python/tvm/relay/__init__.py
+++ b/python/tvm/relay/__init__.py
@@ -60,8 +60,7 @@ from . import qnn
 from .scope_builder import ScopeBuilder
 
 # Load Memory Passes
-from .transform import memory_alloc
-from .transform import memory_plan
+from .transform import memory_alloc, memory_plan
 
 # Required to traverse large programs
 setrecursionlimit(1)
diff --git a/python/tvm/relay/analysis/__init__.py 
b/python/tvm/relay/analysis/__init__.py
index b4ea7f3..4ea4de7 100644
--- a/python/tvm/relay/analysis/__init__.py
+++ b/python/tvm/relay/analysis/__init__.py
@@ -26,7 +26,7 @@ from .annotated_regions import AnnotatedRegionSet
 from . import call_graph
 from .call_graph import CallGraph
 
-# Feature
+# # Feature
 from . import feature
 from . import sparse_dense
 
diff --git a/python/tvm/relay/analysis/analysis.py 
b/python/tvm/relay/analysis/analysis.py
index 7e49461..48e9ce0 100644
--- a/python/tvm/relay/analysis/analysis.py
+++ b/python/tvm/relay/analysis/analysis.py
@@ -20,9 +20,9 @@
 This file contains the set of passes for Relay, which exposes an interface for
 configuring the passes and scripting them in Python.
 """
-from tvm.ir import IRModule
-from tvm.relay import transform, build_module
-from tvm.runtime.ndarray import cpu
+from ...ir import IRModule
+from ...relay import transform, build_module
+from ...runtime.ndarray import cpu
 
 from . import _ffi_api
 from .feature import Feature
diff --git a/python/tvm/relay/analysis/annotated_regions.py 
b/python/tvm/relay/analysis/annotated_regions.py
index 437b97b..a18ccb9 100644
--- a/python/tvm/relay/analysis/annotated_regions.py
+++ b/python/tvm/relay/analysis/annotated_regions.py
@@ -17,7 +17,7 @@
 # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, 
unused-import
 """Regions used in Relay."""
 
-from tvm.runtime import Object
+from ...runtime import Object
 from . import _ffi_api
 
 
diff --git a/python/tvm/relay/analysis/call_graph.py 
b/python/tvm/relay/analysis/call_graph.py
index 966659a..fd9704d 100644
--- a/python/tvm/relay/analysis/call_graph.py
+++ b/python/tvm/relay/analysis/call_graph.py
@@ -17,8 +17,8 @@
 # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, 
unused-import
 """Call graph used in Relay."""
 
-from tvm.ir import IRModule
-from tvm.runtime import Object
+from ...ir import IRModule
+from ...runtime import Object
 from ..expr import GlobalVar
 from . import _ffi_api
 
diff --git a/python/tvm/relay/analysis/sparse_dense.py 
b/python/tvm/relay/analysis/sparse_dense.py
index d521748..51fab34 100644
--- a/python/tvm/relay/analysis/sparse_dense.py
+++ b/python/tvm/relay/analysis/sparse_dense.py
@@ -22,8 +22,8 @@ to block sparse model
 """
 from collections import namedtuple
 import numpy as np
-import 

[incubator-tvm] 02/02: SciPy causes crashes

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 1604de7f94524c2a79df6aaf50c578a010be9681
Author: Jared Roesch 
AuthorDate: Thu Nov 5 18:52:41 2020 -0800

SciPy causes crashes
---
 python/tvm/relay/frontend/__init__.py  | 3 ---
 python/tvm/relay/frontend/tensorflow.py| 6 --
 python/tvm/topi/testing/conv1d_transpose_ncw_python.py | 3 +--
 python/tvm/topi/testing/conv2d_hwcn_python.py  | 2 +-
 tests/python/topi/python/test_topi_sparse.py   | 2 +-
 5 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/python/tvm/relay/frontend/__init__.py 
b/python/tvm/relay/frontend/__init__.py
index 7e16499..aa8ac4f 100644
--- a/python/tvm/relay/frontend/__init__.py
+++ b/python/tvm/relay/frontend/__init__.py
@@ -20,9 +20,6 @@ Frontends for constructing Relay programs.
 Contains the model importers currently defined
 for Relay.
 """
-
-from __future__ import absolute_import
-
 from .mxnet import from_mxnet
 from .mxnet_qnn_op_utils import quantize_conv_bias_mkldnn_from_var
 from .keras import from_keras
diff --git a/python/tvm/relay/frontend/tensorflow.py 
b/python/tvm/relay/frontend/tensorflow.py
index c6079b4..0283146 100644
--- a/python/tvm/relay/frontend/tensorflow.py
+++ b/python/tvm/relay/frontend/tensorflow.py
@@ -904,10 +904,12 @@ def _batch_matmul():
 
 
 def _sparse_tensor_dense_matmul():
-# Sparse utility from scipy
-from scipy.sparse import csr_matrix
 
 def _impl(inputs, attr, params, mod):
+# Loading this by default causes TVM to not be loadable from other 
languages.
+# Sparse utility from scipy
+from scipy.sparse import csr_matrix
+
 assert len(inputs) == 4, "There should be 4 input tensors"
 
 indices_tensor = _infer_value(inputs[0], params, mod).asnumpy()
diff --git a/python/tvm/topi/testing/conv1d_transpose_ncw_python.py 
b/python/tvm/topi/testing/conv1d_transpose_ncw_python.py
index 85e1410..642908a 100644
--- a/python/tvm/topi/testing/conv1d_transpose_ncw_python.py
+++ b/python/tvm/topi/testing/conv1d_transpose_ncw_python.py
@@ -17,11 +17,9 @@
 # pylint: disable=unused-variable
 """Transposed 1D convolution in python"""
 import numpy as np
-import scipy
 import tvm.topi.testing
 from tvm.topi.nn.utils import get_pad_tuple1d
 
-
 def conv1d_transpose_ncw_python(a_np, w_np, stride, padding, output_padding):
 """Transposed 1D convolution operator in NCW layout.
 
@@ -51,6 +49,7 @@ def conv1d_transpose_ncw_python(a_np, w_np, stride, padding, 
output_padding):
 3-D with shape [batch, out_channel, out_width]
 
 """
+import scipy
 batch, in_c, in_w = a_np.shape
 _, out_c, filter_w = w_np.shape
 opad = output_padding[0]
diff --git a/python/tvm/topi/testing/conv2d_hwcn_python.py 
b/python/tvm/topi/testing/conv2d_hwcn_python.py
index 9ee66df..bcfd921 100644
--- a/python/tvm/topi/testing/conv2d_hwcn_python.py
+++ b/python/tvm/topi/testing/conv2d_hwcn_python.py
@@ -17,7 +17,6 @@
 # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals
 """Convolution in python"""
 import numpy as np
-import scipy.signal
 from tvm.topi.nn.utils import get_pad_tuple
 
 
@@ -45,6 +44,7 @@ def conv2d_hwcn_python(a_np, w_np, stride, padding):
 b_np : np.ndarray
 4-D with shape [out_height, out_width, out_channel, batch]
 """
+import scipy.signal
 in_height, in_width, in_channel, batch = a_np.shape
 kernel_h, kernel_w, _, num_filter = w_np.shape
 if isinstance(stride, int):
diff --git a/tests/python/topi/python/test_topi_sparse.py 
b/tests/python/topi/python/test_topi_sparse.py
index 62f49e2..fb5faf9 100644
--- a/tests/python/topi/python/test_topi_sparse.py
+++ b/tests/python/topi/python/test_topi_sparse.py
@@ -25,7 +25,6 @@ from tvm.topi.utils import get_const_tuple
 import tvm.contrib.sparse as tvmsp
 from collections import namedtuple
 import time
-import scipy.sparse as sp
 import tvm.testing
 
 _sparse_dense_implement = {
@@ -248,6 +247,7 @@ def test_dense():
 
 
 def test_sparse_dense_csr():
+import scipy.sparse as sp
 M, N, K, density = 1, 17, 47, 0.2
 X_np = np.random.randn(M, K).astype("float32")
 W_sp_np = sp.random(N, K, density=density, format="csr", dtype="float32")



[GitHub] [incubator-tvm] siju-samuel opened a new pull request #6861: Update path in arm_compute_lib.rst

2020-11-05 Thread GitBox


siju-samuel opened a new pull request #6861:
URL: https://github.com/apache/incubator-tvm/pull/6861


   Updated correct 
[path](https://github.com/apache/incubator-tvm/blob/main/docker/install/ubuntu_install_arm_compute_lib.sh)
 in readme
   
   @lhutton1 Please help to review and merge.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] joyalbin edited a comment on issue #6857: Not able to compile TVM with Arm Compute library

2020-11-05 Thread GitBox


joyalbin edited a comment on issue #6857:
URL: https://github.com/apache/incubator-tvm/issues/6857#issuecomment-722774459


   Hi All,
   While building TVM with flags USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME and 
USE_ARM_COMPUTE_LIB set to ON, am getting below error:
   
   
![image](https://user-images.githubusercontent.com/1856674/98319564-02470200-2007-11eb-9ad5-0babc9385cbc.png)
   
   @jroesch @lhutton1 @giuseros help me to understand how to use this feature
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] 01/01: Update arm_compute_lib.rst

2020-11-05 Thread sijusamuel
This is an automated email from the ASF dual-hosted git repository.

sijusamuel pushed a commit to branch siju-samuel-patch-1
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 6f1dcc1753ef0b01cdfe75c6fc5f3b81c2a9a951
Author: Siju Samuel 
AuthorDate: Fri Nov 6 08:16:19 2020 +0530

Update arm_compute_lib.rst

Updated correct path in readme
---
 docs/deploy/arm_compute_lib.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/deploy/arm_compute_lib.rst b/docs/deploy/arm_compute_lib.rst
index 5dd0076..a2eaa5f 100644
--- a/docs/deploy/arm_compute_lib.rst
+++ b/docs/deploy/arm_compute_lib.rst
@@ -36,7 +36,7 @@ determine the architecture by looking online.
 
 We recommend two different ways to build and install ACL:
 
-* Use the script located at 
`docker/install/ubuntu_install_arm_compute_library.sh`. You can use this
+* Use the script located at 
`docker/install/ubuntu_install_arm_compute_lib.sh`. You can use this
   script for building ACL from source natively or for cross-compiling the 
library on an x86 machine.
   You may need to change the architecture of the device you wish to compile 
for by altering the
   `target_arch` variable. Binaries will be built from source and installed to 
the location denoted by



[incubator-tvm] branch siju-samuel-patch-1 created (now 6f1dcc1)

2020-11-05 Thread sijusamuel
This is an automated email from the ASF dual-hosted git repository.

sijusamuel pushed a change to branch siju-samuel-patch-1
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


  at 6f1dcc1  Update arm_compute_lib.rst

This branch includes the following new commits:

 new 6f1dcc1  Update arm_compute_lib.rst

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[GitHub] [incubator-tvm] joyalbin commented on issue #6857: Not able to compile TVM with Arm Compute library

2020-11-05 Thread GitBox


joyalbin commented on issue #6857:
URL: https://github.com/apache/incubator-tvm/issues/6857#issuecomment-722774459


   Hi All,
   While building TVM with flags USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME and 
USE_ARM_COMPUTE_LIB set to ON, am getting below error:
   
   
![image](https://user-images.githubusercontent.com/1856674/98319564-02470200-2007-11eb-9ad5-0babc9385cbc.png)
   
   Please help me to understand how to use this feature
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] junrushao1994 commented on pull request #6860: [TIR] Add spans to all ExprNodes

2020-11-05 Thread GitBox


junrushao1994 commented on pull request #6860:
URL: https://github.com/apache/incubator-tvm/pull/6860#issuecomment-722773439


   CC: @spectrometerHBH 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] 04/21: Hacking on Rust inside of TVM

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 131e40afeb4bd89f0b378e0e7d8ad440d017d33a
Author: Jared Roesch 
AuthorDate: Tue Oct 13 15:25:56 2020 -0700

Hacking on Rust inside of TVM
---
 CMakeLists.txt |   1 +
 cmake/modules/RustExt.cmake|  13 +
 rust/Cargo.toml|   1 +
 rust/compiler-ext/Cargo.toml   |  13 +
 rust/compiler-ext/src/lib.rs   |   7 +
 rust/tvm/src/ir/source_map.rs  |   0
 rust/tvm/test.rly  |   2 +
 tests/python/relay/test_type_infer2.py | 419 +
 8 files changed, 456 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index abf2b56..9f82754 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,6 +79,7 @@ tvm_option(USE_ARM_COMPUTE_LIB "Build with Arm Compute 
Library" OFF)
 tvm_option(USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME "Build with Arm Compute Library 
graph runtime" OFF)
 tvm_option(USE_TENSORRT_CODEGEN "Build with TensorRT Codegen support" OFF)
 tvm_option(USE_TENSORRT_RUNTIME "Build with TensorRT runtime" OFF)
+tvm_option(USE_RUST_EXT "Build with Rust based compiler extensions" OFF)
 
 # include directories
 include_directories(${CMAKE_INCLUDE_PATH})
diff --git a/cmake/modules/RustExt.cmake b/cmake/modules/RustExt.cmake
new file mode 100644
index 000..45e46bd
--- /dev/null
+++ b/cmake/modules/RustExt.cmake
@@ -0,0 +1,13 @@
+if(USE_RUST_EXT)
+set(RUST_SRC_DIR "rust")
+set(CARGO_OUT_DIR "rust/target"
+set(COMPILER_EXT_PATH 
"${CARGO_OUT_DIR}/target/release/libcompiler_ext.dylib")
+
+add_custom_command(
+OUTPUT "${COMPILER_EXT_PATH}"
+COMMAND cargo build --release
+MAIN_DEPENDENCY "${RUST_SRC_DIR}"
+WORKING_DIRECTORY "${RUST_SRC_DIR}/compiler-ext")
+
+target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE)
+endif(USE_RUST_EXT)
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 28312a5..7c092d8 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -29,4 +29,5 @@ members = [
"tvm-graph-rt/tests/test_tvm_dso",
"tvm-graph-rt/tests/test_wasm32",
"tvm-graph-rt/tests/test_nn",
+   "compiler-ext",
 ]
diff --git a/rust/compiler-ext/Cargo.toml b/rust/compiler-ext/Cargo.toml
new file mode 100644
index 000..76d10eb
--- /dev/null
+++ b/rust/compiler-ext/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "compiler-ext"
+version = "0.1.0"
+authors = ["Jared Roesch "]
+edition = "2018"
+# TODO(@jroesch): would be cool to figure out how to statically link instead.
+
+[lib]
+crate-type = ["cdylib"]
+
+# See more keys and their definitions at 
https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
new file mode 100644
index 000..31e1bb2
--- /dev/null
+++ b/rust/compiler-ext/src/lib.rs
@@ -0,0 +1,7 @@
+#[cfg(test)]
+mod tests {
+#[test]
+fn it_works() {
+assert_eq!(2 + 2, 4);
+}
+}
diff --git a/rust/tvm/src/ir/source_map.rs b/rust/tvm/src/ir/source_map.rs
new file mode 100644
index 000..e69de29
diff --git a/rust/tvm/test.rly b/rust/tvm/test.rly
new file mode 100644
index 000..d8b7c69
--- /dev/null
+++ b/rust/tvm/test.rly
@@ -0,0 +1,2 @@
+#[version = "0.0.5"]
+fn @main(%x: int32) -> float32 { %x }
diff --git a/tests/python/relay/test_type_infer2.py 
b/tests/python/relay/test_type_infer2.py
new file mode 100644
index 000..6758d96
--- /dev/null
+++ b/tests/python/relay/test_type_infer2.py
@@ -0,0 +1,419 @@
+# 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.
+"""Test that type checker correcly computes types
+   for expressions.
+"""
+import pytest
+import tvm
+
+from tvm import IRModule, te, relay, parser
+from tvm.relay import op, transform, analysis
+from tvm.relay import Any
+
+
+def infer_mod(mod, annotate_spans=True):
+if annotate_spans:
+mod = relay.transform.AnnotateSpans()(mod)
+
+mod = transform.InferType()(mod)
+return mod
+
+
+def infer_expr(expr, annotate_spans=True):
+mod = IRModule.from_expr(expr)
+mod = infer_mod(mod, annotate_spans)
+   

[incubator-tvm] 11/21: Fix

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 4261461974f2fb548d6b48e19fab07d34dd03a51
Author: Jared Roesch 
AuthorDate: Fri Oct 16 02:11:53 2020 -0700

Fix
---
 rust/tvm/src/ir/module.rs | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index 5156e74..11d6c49 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -16,6 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+use std::io::Result as IOResult;
+use std::path::Path;
+
+use thiserror::Error;
+use tvm_macros::Object;
 
 use crate::runtime::array::Array;
 use crate::runtime::function::Result;
@@ -27,15 +32,19 @@ use super::expr::GlobalVar;
 use super::function::BaseFunc;
 use super::source_map::SourceMap;
 
-use std::io::Result as IOResult;
-use std::path::Path;
-
-use tvm_macros::Object;
 
 // TODO(@jroesch): define type
 type TypeData = ObjectRef;
 type GlobalTypeVar = ObjectRef;
 
+#[derive(Error, Debug)]
+pub enum Error {
+#[error("{0}")]
+IO(#[from] std::io::Error),
+#[error("{0}")]
+TVM(#[from] crate::runtime::Error),
+}
+
 #[repr(C)]
 #[derive(Object)]
 #[ref_name = "IRModule"]
@@ -116,19 +125,19 @@ external! {
 // });
 
 impl IRModule {
-pub fn parse(file_name: N, source: S) -> IRModule
+pub fn parse(file_name: N, source: S) -> Result
 where
 N: Into,
 S: Into,
 {
-parse_module(file_name.into(), source.into()).expect("failed to call 
parser")
+parse_module(file_name.into(), source.into())
 }
 
-pub fn parse_file>(file_path: P) -> 
IOResult {
+pub fn parse_file>(file_path: P) -> 
std::result::Result {
 let file_path = file_path.as_ref();
 let file_path_as_str = file_path.to_str().unwrap().to_string();
 let source = std::fs::read_to_string(file_path)?;
-let module = IRModule::parse(file_path_as_str, source);
+let module = IRModule::parse(file_path_as_str, source)?;
 Ok(module)
 }
 



[incubator-tvm] 14/21: Format and cleanup

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 04a9779359380ae383405f5f72a66e79631ee2d5
Author: Jared Roesch 
AuthorDate: Fri Oct 16 16:31:37 2020 -0700

Format and cleanup
---
 python/tvm/ir/diagnostics/__init__.py   |  1 +
 rust/compiler-ext/src/lib.rs|  3 +-
 rust/tvm-rt/src/array.rs| 11 +++--
 rust/tvm-rt/src/errors.rs   |  4 +-
 rust/tvm-rt/src/function.rs |  2 +-
 rust/tvm/src/bin/tyck.rs|  8 +--
 rust/tvm/src/ir/diagnostics/codespan.rs | 87 +++--
 rust/tvm/src/ir/mod.rs  |  2 +-
 rust/tvm/src/ir/module.rs   |  5 +-
 rust/tvm/src/ir/relay/mod.rs|  2 +-
 rust/tvm/src/ir/relay/visitor.rs| 24 -
 rust/tvm/src/ir/source_map.rs   | 13 ++---
 rust/tvm/src/ir/span.rs |  2 +-
 src/ir/expr.cc  | 11 -
 14 files changed, 79 insertions(+), 96 deletions(-)

diff --git a/python/tvm/ir/diagnostics/__init__.py 
b/python/tvm/ir/diagnostics/__init__.py
index 0ad2a7a..3a6402c 100644
--- a/python/tvm/ir/diagnostics/__init__.py
+++ b/python/tvm/ir/diagnostics/__init__.py
@@ -37,6 +37,7 @@ def get_renderer():
 """
 return _ffi_api.GetRenderer()
 
+
 @tvm.register_func("diagnostics.override_renderer")
 def override_renderer(render_func):
 """
diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index c136d06..346f40f 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -36,8 +36,7 @@ tvm::export!(test_fn, test_fn2);
 #[no_mangle]
 fn compiler_ext_initialize() -> i32 {
 let _ = env_logger::try_init();
-tvm_export("rust_ext")
-.expect("failed to initialize Rust compiler_ext");
+tvm_export("rust_ext").expect("failed to initialize Rust compiler_ext");
 log::debug!("done!");
 return 0;
 }
diff --git a/rust/tvm-rt/src/array.rs b/rust/tvm-rt/src/array.rs
index 032ca79..66e32a7 100644
--- a/rust/tvm-rt/src/array.rs
+++ b/rust/tvm-rt/src/array.rs
@@ -18,8 +18,8 @@
  */
 
 use std::convert::{TryFrom, TryInto};
-use std::marker::PhantomData;
 use std::iter::{IntoIterator, Iterator};
+use std::marker::PhantomData;
 
 use crate::errors::Error;
 use crate::object::{IsObjectRef, Object, ObjectPtr, ObjectRef};
@@ -93,8 +93,7 @@ impl Iterator for IntoIter {
 
 fn next( self) -> Option {
 if self.pos < self.size {
-let item = self.array.get(self.pos)
-.expect("should not fail");
+let item = self.array.get(self.pos).expect("should not fail");
 self.pos += 1;
 Some(item)
 } else {
@@ -109,7 +108,11 @@ impl IntoIterator for Array {
 
 fn into_iter(self) -> Self::IntoIter {
 let size = self.len() as isize;
-IntoIter { array: self, pos: 0, size: size }
+IntoIter {
+array: self,
+pos: 0,
+size: size,
+}
 }
 }
 
diff --git a/rust/tvm-rt/src/errors.rs b/rust/tvm-rt/src/errors.rs
index 3de9f3c..31ce385 100644
--- a/rust/tvm-rt/src/errors.rs
+++ b/rust/tvm-rt/src/errors.rs
@@ -68,7 +68,9 @@ pub enum Error {
 Infallible(#[from] std::convert::Infallible),
 #[error("a panic occurred while executing a Rust packed function")]
 Panic,
-#[error("one or more error diagnostics were emitted, please check 
diagnostic render for output.")]
+#[error(
+"one or more error diagnostics were emitted, please check diagnostic 
render for output."
+)]
 DiagnosticError(String),
 #[error("{0}")]
 Raw(String),
diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index 173b60a..4c6f56e 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -128,7 +128,7 @@ impl Function {
 type_codes.as_mut_ptr() as *mut c_int,
 num_args as c_int,
  ret_val as *mut _,
- ret_type_code as *mut _
+ ret_type_code as *mut _,
 )
 };
 
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index 13470e7..e9c2663 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -20,9 +20,11 @@ fn main() -> Result<()> {
 let opt = Opt::from_args();
 println!("{:?}", );
 let _module = match IRModule::parse_file(opt.input) {
-Err(ir::module::Error::TVM(Error::DiagnosticError(_))) => { return 
Ok(()) },
-Err(e) => { return Err(e.into()); },
-Ok(module) => module
+Err(ir::module::Error::TVM(Error::DiagnosticError(_))) => return 
Ok(()),
+Err(e) => {
+return Err(e.into());
+}
+Ok(module) => module,
 };
 
 Ok(())
diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
index 9fc1ee0..9a31691 

[incubator-tvm] 06/21: Update CMake and delete old API

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit db245535a4ea5b8bed3c26a94825d2fcc9b5
Author: Jared Roesch 
AuthorDate: Thu Oct 15 01:03:03 2020 -0700

Update CMake and delete old API
---
 CMakeLists.txt  |   1 +
 cmake/modules/RustExt.cmake |  25 ++-
 include/tvm/parser/source_map.h |   2 -
 rust/compiler-ext/Cargo.toml|   5 +-
 rust/compiler-ext/src/lib.rs| 334 ++--
 rust/tvm-rt/Cargo.toml  |  15 +-
 rust/tvm-sys/Cargo.toml |   1 +
 rust/tvm-sys/build.rs   |   1 +
 rust/tvm/Cargo.toml |  22 ++-
 rust/tvm/src/bin/tyck.rs|   1 -
 rust/tvm/src/ir/diagnostics.rs  |  42 +++--
 rust/tvm/src/ir/mod.rs  |   2 +-
 rust/tvm/src/ir/relay/mod.rs|   3 +-
 rust/tvm/src/ir/source_map.rs   |  61 
 rust/tvm/src/ir/span.rs |  95 +---
 src/ir/expr.cc  |  11 ++
 src/parser/source_map.cc|  11 --
 17 files changed, 237 insertions(+), 395 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f82754..58bb2f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -353,6 +353,7 @@ include(cmake/modules/contrib/ArmComputeLib.cmake)
 include(cmake/modules/contrib/TensorRT.cmake)
 include(cmake/modules/Git.cmake)
 include(cmake/modules/LibInfo.cmake)
+include(cmake/modules/RustExt.cmake)
 
 include(CheckCXXCompilerFlag)
 if(NOT MSVC)
diff --git a/cmake/modules/RustExt.cmake b/cmake/modules/RustExt.cmake
index 45e46bd..2ad726e9 100644
--- a/cmake/modules/RustExt.cmake
+++ b/cmake/modules/RustExt.cmake
@@ -1,7 +1,14 @@
-if(USE_RUST_EXT)
-set(RUST_SRC_DIR "rust")
-set(CARGO_OUT_DIR "rust/target"
-set(COMPILER_EXT_PATH 
"${CARGO_OUT_DIR}/target/release/libcompiler_ext.dylib")
+if(USE_RUST_EXT AND NOT USE_RUST_EXT EQUAL OFF)
+set(RUST_SRC_DIR "${CMAKE_SOURCE_DIR}/rust")
+set(CARGO_OUT_DIR "${CMAKE_SOURCE_DIR}/rust/target")
+
+if(USE_RUST_EXT STREQUAL "STATIC")
+set(COMPILER_EXT_PATH "${CARGO_OUT_DIR}/release/libcompiler_ext.a")
+elseif(USE_RUST_EXT STREQUAL "DYNAMIC")
+set(COMPILER_EXT_PATH "${CARGO_OUT_DIR}/release/libcompiler_ext.so")
+else()
+message(FATAL_ERROR "invalid setting for RUST_EXT")
+endif()
 
 add_custom_command(
 OUTPUT "${COMPILER_EXT_PATH}"
@@ -9,5 +16,11 @@ if(USE_RUST_EXT)
 MAIN_DEPENDENCY "${RUST_SRC_DIR}"
 WORKING_DIRECTORY "${RUST_SRC_DIR}/compiler-ext")
 
-target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE)
-endif(USE_RUST_EXT)
+add_custom_target(rust_ext ALL DEPENDS "${COMPILER_EXT_PATH}")
+
+# TODO(@jroesch, @tkonolige): move this to CMake target
+# target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE)
+list(APPEND TVM_LINKER_LIBS ${COMPILER_EXT_PATH})
+
+add_definitions(-DRUST_COMPILER_EXT=1)
+endif()
diff --git a/include/tvm/parser/source_map.h b/include/tvm/parser/source_map.h
index 424af5c..a160c22 100644
--- a/include/tvm/parser/source_map.h
+++ b/include/tvm/parser/source_map.h
@@ -103,8 +103,6 @@ class SourceMap : public ObjectRef {
 
   TVM_DLL SourceMap() : SourceMap(Map()) {}
 
-  TVM_DLL static SourceMap Global();
-
   void Add(const Source& source);
 
   SourceMapNode* operator->() {
diff --git a/rust/compiler-ext/Cargo.toml b/rust/compiler-ext/Cargo.toml
index 76d10eb..3b13bc5 100644
--- a/rust/compiler-ext/Cargo.toml
+++ b/rust/compiler-ext/Cargo.toml
@@ -6,8 +6,11 @@ edition = "2018"
 # TODO(@jroesch): would be cool to figure out how to statically link instead.
 
 [lib]
-crate-type = ["cdylib"]
+crate-type = ["staticlib", "cdylib"]
 
 # See more keys and their definitions at 
https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+tvm = { path = "../tvm", default-features = false, features = 
["static-linking"] }
+log = "*"
+env_logger = "*"
diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 58bdd0c..3e37d21 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -17,321 +17,19 @@
  * under the License.
  */
 
- use std::os::raw::c_int;
- use tvm::initialize;
- use tvm::ir::{tir, PrimExpr};
- use tvm::runtime::function::register_override;
- use tvm::runtime::map::Map;
- use tvm::runtime::object::{IsObject, IsObjectRef};
- 
- use ordered_float::NotNan;
- 
- mod interval;
- mod math;
- 
- use math::{BoundsMap, Expr, RecExpr};
- use tvm::ir::arith::ConstIntBound;
- use tvm_rt::{ObjectRef, array::Array};
- 
- macro_rules! downcast_match {
- ($id:ident; { $($t:ty => $arm:expr $(,)? )+ , else => $default:expr }) => 
{
- $( if let Ok($id) = $id.downcast_clone::<$t>() { $arm } else )+
- { $default }
- }
- }
- 
- #[derive(Default)]
- struct VarMap {
- vars: Vec<(tvm::ir::tir::Var, egg::Symbol)>,
- objs: Vec,
- }
- 
- impl VarMap {
- // FIXME this should 

[incubator-tvm] 09/21: Improve Rust bindings

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 4cd1bbc79a71873676927c22528f5911e3f4072d
Author: Jared Roesch 
AuthorDate: Thu Oct 15 20:24:43 2020 -0700

Improve Rust bindings
---
 rust/tvm/src/ir/diagnostics/codespan.rs| 131 +
 .../src/ir/{diagnostics.rs => diagnostics/mod.rs}  |  69 +--
 rust/tvm/src/ir/source_map.rs  |   3 +-
 rust/tvm/test.rly  |   3 +-
 src/ir/diagnostic.cc   |   1 +
 5 files changed, 138 insertions(+), 69 deletions(-)

diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
new file mode 100644
index 000..80a8784
--- /dev/null
+++ b/rust/tvm/src/ir/diagnostics/codespan.rs
@@ -0,0 +1,131 @@
+use std::collections::HashMap;
+use std::sync::{Arc, Mutex};
+
+use codespan_reporting::diagnostic::{Diagnostic as CDiagnostic, Label, 
Severity};
+use codespan_reporting::files::SimpleFiles;
+use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
+
+use crate::ir::source_map::*;
+use super::*;
+
+enum StartOrEnd {
+Start,
+End,
+}
+
+enum FileSpanToByteRange {
+AsciiSource,
+Utf8 {
+/// Map character regions which are larger then 1-byte to length.
+lengths: HashMap,
+source: String,
+}
+}
+
+impl FileSpanToByteRange {
+fn new(source: String) -> FileSpanToByteRange {
+let mut last_index = 0;
+let mut is_ascii = true;
+if source.is_ascii() {
+FileSpanToByteRange::AsciiSource
+} else {
+panic!()
+}
+
+// for (index, _) in source.char_indices() {
+// if last_index - 1 != last_index {
+// is_ascii = false;
+// } else {
+// panic!();
+// }
+// last_index = index;
+// }
+}
+}
+
+struct SpanToByteRange {
+map: HashMap
+}
+
+impl SpanToByteRange {
+fn new() -> SpanToByteRange {
+SpanToByteRange { map: HashMap::new() }
+}
+
+pub fn add_source( self, source: Source) {
+let source_name: String = 
source.source_name.name.as_str().expect("foo").into();
+
+if self.map.contains_key(_name) {
+panic!()
+} else {
+let source = source.source.as_str().expect("fpp").into();
+self.map.insert(source_name, FileSpanToByteRange::new(source));
+}
+}
+}
+
+struct ByteRange {
+file_id: FileId,
+start_pos: usize,
+end_pos: usize,
+}
+
+
+pub fn to_diagnostic(diag: super::Diagnostic) -> CDiagnostic {
+let severity = match diag.level {
+DiagnosticLevel::Error => Severity::Error,
+DiagnosticLevel::Warning => Severity::Warning,
+DiagnosticLevel::Note => Severity::Note,
+DiagnosticLevel::Help => Severity::Help,
+DiagnosticLevel::Bug => Severity::Bug,
+};
+
+let file_id = "foo".into(); // diag.span.source_name;
+
+let message: String = diag.message.as_str().unwrap().into();
+let inner_message: String = "expected `String`, found `Nat`".into();
+let diagnostic = CDiagnostic::new(severity)
+.with_message(message)
+.with_code("EXXX")
+.with_labels(vec![
+Label::primary(file_id, 328..331).with_message(inner_message)
+]);
+
+diagnostic
+}
+
+struct DiagnosticState {
+files: SimpleFiles,
+span_map: SpanToByteRange,
+}
+
+impl DiagnosticState {
+fn new() -> DiagnosticState {
+DiagnosticState {
+files: SimpleFiles::new(),
+span_map: SpanToByteRange::new(),
+}
+}
+}
+
+fn renderer(state:  DiagnosticState, diag_ctx: DiagnosticContext) {
+let source_map = diag_ctx.module.source_map.clone();
+for diagnostic in diag_ctx.diagnostics.clone() {
+match source_map.source_map.get(_name) {
+Err(err) => panic!(),
+Ok(source) => state.span_map.add_source(source),
+}
+println!("Diagnostic: {}", diagnostic.message);
+}
+}
+
+pub fn init() -> Result<()> {
+let diag_state = Arc::new(Mutex::new(DiagnosticState::new()));
+let render_fn = move |diag_ctx: DiagnosticContext| {
+// let mut guard = diag_state.lock().unwrap();
+// renderer( *guard, diag_ctx);
+};
+
+override_renderer(Some(render_fn))?;
+Ok(())
+}
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics/mod.rs
similarity index 76%
rename from rust/tvm/src/ir/diagnostics.rs
rename to rust/tvm/src/ir/diagnostics/mod.rs
index 4975a45..fce214a 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics/mod.rs
@@ -18,7 +18,7 @@
  */
 
 use super::module::IRModule;
-use super::span::Span;
+use super::span::*;
 use crate::runtime::function::Result;
 

[incubator-tvm] 16/21: More cleanup

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 187435099c4d80be2c200791e7853f8518f421e1
Author: Jared Roesch 
AuthorDate: Fri Oct 16 16:45:12 2020 -0700

More cleanup
---
 rust/compiler-ext/src/lib.rs | 22 --
 rust/tvm/src/lib.rs  |  7 ---
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 346f40f..5f83f7b 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -18,25 +18,19 @@
  */
 
 use env_logger;
-use tvm;
-use tvm::runtime::function::register_override;
+use tvm::export;
 
-fn test_fn() -> Result<(), tvm::Error> {
-println!("Hello Greg from Rust!");
-Ok(())
+fn diagnostics() -> Result<(), tvm::Error> {
+tvm::ir::diagnostics::codespan::init()
 }
 
-fn test_fn2(message: tvm::runtime::string::String) -> Result<(), tvm::Error> {
-println!("The message: {}", message);
-Ok(())
-}
-
-tvm::export!(test_fn, test_fn2);
+export!(diagnostics);
 
 #[no_mangle]
-fn compiler_ext_initialize() -> i32 {
+extern fn compiler_ext_initialize() -> i32 {
 let _ = env_logger::try_init();
-tvm_export("rust_ext").expect("failed to initialize Rust compiler_ext");
-log::debug!("done!");
+tvm_export("rust_ext")
+.expect("failed to initialize the Rust compiler extensions.");
+log::debug!("Loaded the Rust compiler extension.");
 return 0;
 }
diff --git a/rust/tvm/src/lib.rs b/rust/tvm/src/lib.rs
index d193f09..ec80ece 100644
--- a/rust/tvm/src/lib.rs
+++ b/rust/tvm/src/lib.rs
@@ -50,10 +50,11 @@ pub use runtime::version;
 
 #[macro_export]
 macro_rules! export {
-($($fn_names:expr),*) => {
+($($fn_name:expr),*) => {
 pub fn tvm_export(ns: ) -> Result<(), tvm::Error> {
 $(
-register_override($fn_name, concat!($ns, stringfy!($fn_name)), 
true)?;
+let name = String::from(ns) + ::std::stringify!($fn_name);
+tvm::runtime::function::register_override($fn_name, name, 
true)?;
 )*
 Ok(())
 }
@@ -65,7 +66,7 @@ macro_rules! export_mod {
 ($ns:expr, $($mod_name:expr),*) => {
 pub fn tvm_mod_export() -> Result<(), tvm::Error> {
 $(
-$mod_names::tvm_export($ns)?;
+$mod_name::tvm_export($ns)?;
 )*
 Ok(())
 }



[incubator-tvm] 20/21: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit b8dcc35801e7f0f3c696e0d030b3bd0931127785
Author: Jared Roesch 
AuthorDate: Thu Oct 22 22:18:58 2020 -0700

WIP
---
 rust/tvm-macros/src/external.rs  |   2 +-
 rust/tvm-macros/src/lib.rs   |   3 +-
 rust/tvm-macros/src/object.rs|  23 ++
 rust/tvm-rt/src/object/mod.rs|   9 +--
 rust/tvm-rt/src/object/object_ptr.rs |  16 
 rust/tvm-rt/src/string.rs|   1 +
 rust/tvm-rt/src/value.rs |   1 -
 rust/tvm-sys/src/datatype.rs |   4 +
 rust/tvm/src/ir/module.rs| 152 ---
 rust/tvm/src/ir/relay/mod.rs |  36 +++--
 rust/tvm/src/ir/tir.rs   |  14 
 11 files changed, 218 insertions(+), 43 deletions(-)

diff --git a/rust/tvm-macros/src/external.rs b/rust/tvm-macros/src/external.rs
index 44a242c..51a389b 100644
--- a/rust/tvm-macros/src/external.rs
+++ b/rust/tvm-macros/src/external.rs
@@ -21,7 +21,7 @@ use proc_macro_error::abort;
 use quote::quote;
 use syn::parse::{Parse, ParseStream, Result};
 
-use syn::{Token, FnArg, Signature, Attribute, token::Semi, Visibility, 
Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
+use syn::{FnArg, Signature, Attribute, token::Semi, Visibility, Generics, 
Ident, Lit, Meta, NestedMeta, Pat, ReturnType, Type};
 
 struct ExternalItem {
 attrs: Vec,
diff --git a/rust/tvm-macros/src/lib.rs b/rust/tvm-macros/src/lib.rs
index 32f2839..e563a57 100644
--- a/rust/tvm-macros/src/lib.rs
+++ b/rust/tvm-macros/src/lib.rs
@@ -30,7 +30,8 @@ pub fn import_module(input: TokenStream) -> TokenStream {
 import_module::macro_impl(input)
 }
 
-#[proc_macro_derive(Object, attributes(base, ref_name, type_key))]
+#[proc_macro_error]
+#[proc_macro_derive(Object, attributes(base, ref_name, type_key, no_derive))]
 pub fn macro_impl(input: TokenStream) -> TokenStream {
 // let input = proc_macro2::TokenStream::from(input);
 TokenStream::from(object::macro_impl(input))
diff --git a/rust/tvm-macros/src/object.rs b/rust/tvm-macros/src/object.rs
index ff72d6a..7e6a934 100644
--- a/rust/tvm-macros/src/object.rs
+++ b/rust/tvm-macros/src/object.rs
@@ -36,6 +36,8 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
TokenStream {
 .map(attr_to_str)
 .expect("Failed to get type_key");
 
+let derive = get_attr(_input, "no_derive").map(|_| 
false).unwrap_or(true);
+
 let ref_id = get_attr(_input, "ref_name")
 .map(|a| Ident::new(attr_to_str(a).value().as_str(), 
Span::call_site()))
 .unwrap_or_else(|| {
@@ -185,5 +187,26 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
TokenStream {
 
 expanded.extend(base_tokens);
 
+if derive {
+let derives = quote! {
+impl std::hash::Hash for #ref_id {
+fn hash(, state:  H) {
+self.0.hash(state)
+}
+}
+
+impl std::cmp::PartialEq for #ref_id {
+fn eq(, other: ) -> bool {
+self.0 == other.0
+}
+}
+
+impl std::cmp::Eq for #ref_id {}
+};
+
+
+expanded.extend(derives);
+}
+
 TokenStream::from(expanded)
 }
diff --git a/rust/tvm-rt/src/object/mod.rs b/rust/tvm-rt/src/object/mod.rs
index e48c017..7e6107d 100644
--- a/rust/tvm-rt/src/object/mod.rs
+++ b/rust/tvm-rt/src/object/mod.rs
@@ -90,12 +90,7 @@ external! {
 #[name("ir.DebugPrint")]
 pub fn debug_print(object: ObjectRef) -> CString;
 #[name("node.StructuralHash")]
-fn structural_hash(object: ObjectRef, map_free_vars: bool) -> ObjectRef;
+fn structural_hash(object: ObjectRef, map_free_vars: bool) -> i64;
 #[name("node.StructuralEqual")]
-fn structural_equal(lhs: ObjectRef, rhs: ObjectRef, assert_mode: bool, 
map_free_vars: bool) -> ObjectRef;
+fn structural_equal(lhs: ObjectRef, rhs: ObjectRef, assert_mode: bool, 
map_free_vars: bool) -> bool;
 }
-
-// external! {
-// #[name("ir.TextPrinter")]
-// fn as_text(object: ObjectRef) -> CString;
-// }
diff --git a/rust/tvm-rt/src/object/object_ptr.rs 
b/rust/tvm-rt/src/object/object_ptr.rs
index 77254d2..a923506 100644
--- a/rust/tvm-rt/src/object/object_ptr.rs
+++ b/rust/tvm-rt/src/object/object_ptr.rs
@@ -342,6 +342,22 @@ impl<'a, T: IsObject> TryFrom> for 
ObjectPtr {
 }
 }
 
+impl std::hash::Hash for ObjectPtr {
+fn hash(, state:  H) {
+
state.write_i64(super::structural_hash(ObjectRef(Some(self.clone().upcast())), 
false).unwrap())
+}
+}
+
+impl PartialEq for ObjectPtr {
+fn eq(, other: ) -> bool {
+let lhs = ObjectRef(Some(self.clone().upcast()));
+let rhs = ObjectRef(Some(other.clone().upcast()));
+super::structural_equal(lhs, rhs, false, false).unwrap()
+}
+}
+
+impl Eq for 

[incubator-tvm] 17/21: Fix some CR

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 8e295b79c2e693d7190751532824b463dc9373e5
Author: Jared Roesch 
AuthorDate: Mon Oct 19 19:52:20 2020 -0700

Fix some CR
---
 rust/tvm/src/ir/diagnostics/codespan.rs | 6 --
 rust/tvm/src/lib.rs | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
index 9a31691..54fd336 100644
--- a/rust/tvm/src/ir/diagnostics/codespan.rs
+++ b/rust/tvm/src/ir/diagnostics/codespan.rs
@@ -17,8 +17,10 @@
  * under the License.
  */
 
-/// A TVM diagnostics renderer which uses the Rust `codespan`
-/// library to produce error messages.
+/// A TVM diagnostics renderer which uses the Rust `codespan` library
+/// to produce error messages.
+///
+///
 use std::collections::HashMap;
 use std::sync::{Arc, Mutex};
 
diff --git a/rust/tvm/src/lib.rs b/rust/tvm/src/lib.rs
index ec80ece..7e0682b 100644
--- a/rust/tvm/src/lib.rs
+++ b/rust/tvm/src/lib.rs
@@ -24,7 +24,7 @@
 //! One particular use case is that given optimized deep learning model 
artifacts,
 //! (compiled with TVM) which include a shared library
 //! `lib.so`, `graph.json` and a byte-array `param.params`, one can load them
-//! in Rust idomatically to create a TVM Graph Runtime and
+//! in Rust idiomatically to create a TVM Graph Runtime and
 //! run the model for some inputs and get the
 //! desired predictions *all in Rust*.
 //!
@@ -53,7 +53,7 @@ macro_rules! export {
 ($($fn_name:expr),*) => {
 pub fn tvm_export(ns: ) -> Result<(), tvm::Error> {
 $(
-let name = String::from(ns) + ::std::stringify!($fn_name);
+let name = String::fromwe(ns) + ::std::stringify!($fn_name);
 tvm::runtime::function::register_override($fn_name, name, 
true)?;
 )*
 Ok(())



[incubator-tvm] 03/21: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit cb3785680cb343eb295ea8e0585c87ca42db4323
Author: Jared Roesch 
AuthorDate: Tue Oct 13 11:04:37 2020 -0700

WIP
---
 rust/tvm/src/ir/diagnostics.rs | 78 --
 1 file changed, 37 insertions(+), 41 deletions(-)

diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
index e434d3f..d306185 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -24,7 +24,7 @@
 
 use tvm_macros::{Object, external};
 use super::module::IRModule;
-use crate::runtime::{function::{self, Function, ToFunction, Typed}, 
array::Array, string::String as TString};
+use crate::runtime::{function::{self, Function, ToFunction}, array::Array, 
string::String as TString};
 use crate::runtime::object::{Object, ObjectPtr, ObjectRef};
 use crate::runtime::function::Result;
 use super::span::Span;
@@ -121,42 +121,19 @@ pub struct DiagnosticBuilder {
 //* of compiler diagnostics to std::out and std::err in
 //* a human readable form.
 //*/
-//   class DiagnosticRendererNode : public Object {
-//public:
-// TypedPackedFunc renderer;
-
-// // override attr visitor
-// void VisitAttrs(AttrVisitor* v) {}
-
-// static constexpr const char* _type_key = "DiagnosticRenderer";
-// TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticRendererNode, Object);
-//   };
-
-//   class DiagnosticRenderer : public ObjectRef {
-//public:
-// TVM_DLL DiagnosticRenderer(TypedPackedFunc 
render);
-// TVM_DLL DiagnosticRenderer()
-// : DiagnosticRenderer(TypedPackedFunc()) {}
-
-// void Render(const DiagnosticContext& ctx);
-
-// DiagnosticRendererNode* operator->() {
-//   CHECK(get() != nullptr);
-//   return static_cast(get_mutable());
-// }
-
-// TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DiagnosticRenderer, 
ObjectRef, DiagnosticRendererNode);
-//   };
-
-// @tvm._ffi.register_object("DiagnosticRenderer")
-// class DiagnosticRenderer(Object):
-// """
-// A diagnostic renderer, which given a diagnostic context produces a 
"rendered"
-// form of the diagnostics for either human or computer consumption.
-// """
+#[repr(C)]
+#[derive(Object)]
+#[ref_name = "DiagnosticRenderer"]
+#[type_key = "DiagnosticRenderer"]
+/// A diagnostic renderer, which given a diagnostic context produces a 
"rendered"
+/// form of the diagnostics for either human or computer consumption.
+pub struct DiagnosticRendererNode {
+/// The base type.
+pub base: Object,
+// TODO(@jroesch): we can't easily exposed packed functions due to
+// memory layout
+}
 
-// def __init__(self, render_func):
-// self.__init_handle_by_constructor__(_ffi_api.DiagnosticRenderer, 
render_func)
 
 // def render(self, ctx):
 // """
@@ -168,7 +145,6 @@ pub struct DiagnosticBuilder {
 // The diagnostic context to render.
 // """
 // return _ffi_api.DiagnosticRendererRender(self, ctx
-pub type DiagnosticRenderer = ObjectRef;
 
 #[repr(C)]
 #[derive(Object)]
@@ -227,8 +203,7 @@ impl DiagnosticContext {
 }
 }
 
-// Sets a custom renderer for diagnostics.
-
+// Override the global diagnostics renderer.
 // Params
 // --
 // render_func: Option[Callable[[DiagnosticContext], None]]
@@ -263,6 +238,27 @@ pub mod codespan {
 use codespan_reporting::files::SimpleFiles;
 use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
 
+enum StartOrEnd {
+Start,
+End,
+}
+
+struct SpanToBytes {
+inner: HashMap {
+file_id: FileId,
+start_pos: usize,
+end_pos: usize,
+}
+
+// impl SpanToBytes {
+// fn to_byte_pos(, span: tvm::ir::Span) -> ByteRange {
+
+// }
+// }
+
 pub fn to_diagnostic(diag: super::Diagnostic) -> CDiagnostic {
 let severity = match diag.level {
 DiagnosticLevel::Error => Severity::Error,
@@ -290,9 +286,9 @@ pub mod codespan {
 let mut files: SimpleFiles = SimpleFiles::new();
 let render_fn = move |diag_ctx: DiagnosticContext| {
 // let source_map = diag_ctx.module.source_map;
-for diagnostic in diag_ctx.diagnostics {
+// for diagnostic in diag_ctx.diagnostics {
 
-}
+// }
 panic!("render_fn");
 };
 



[incubator-tvm] 02/21: Codespan example almost working

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 77ba30993a7883c142b05e511e8a5a7a91116b2f
Author: Jared Roesch 
AuthorDate: Fri Oct 9 23:59:51 2020 -0700

Codespan example almost working
---
 rust/tvm-sys/src/packed_func.rs  |   1 +
 rust/tvm/Cargo.toml  |   2 +
 rust/tvm/src/bin/tyck.rs |  24 
 rust/tvm/src/ir/diagnostics.rs   | 121 +--
 rust/tvm/src/ir/relay/visitor.rs |  24 
 5 files changed, 143 insertions(+), 29 deletions(-)

diff --git a/rust/tvm-sys/src/packed_func.rs b/rust/tvm-sys/src/packed_func.rs
index f7b289c..7b8d529 100644
--- a/rust/tvm-sys/src/packed_func.rs
+++ b/rust/tvm-sys/src/packed_func.rs
@@ -101,6 +101,7 @@ macro_rules! TVMPODValue {
 TVMArgTypeCode_kTVMOpaqueHandle => 
Handle($value.v_handle),
 TVMArgTypeCode_kTVMDLTensorHandle => 
ArrayHandle($value.v_handle as TVMArrayHandle),
 TVMArgTypeCode_kTVMObjectHandle => 
ObjectHandle($value.v_handle),
+TVMArgTypeCode_kTVMObjectRValueRefArg => 
ObjectHandle(*($value.v_handle as *mut *mut c_void)),
 TVMArgTypeCode_kTVMModuleHandle => 
ModuleHandle($value.v_handle),
 TVMArgTypeCode_kTVMPackedFuncHandle => 
FuncHandle($value.v_handle),
 TVMArgTypeCode_kTVMNDArrayHandle => 
NDArrayHandle($value.v_handle),
diff --git a/rust/tvm/Cargo.toml b/rust/tvm/Cargo.toml
index 55fc179..71a4b93 100644
--- a/rust/tvm/Cargo.toml
+++ b/rust/tvm/Cargo.toml
@@ -41,6 +41,8 @@ paste = "0.1"
 mashup = "0.1"
 once_cell = "^1.3.1"
 pyo3 = { version = "0.11.1", optional = true }
+codespan-reporting = "0.9.5"
+structopt = { version = "0.3" }
 
 [features]
 default = ["python"]
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
new file mode 100644
index 000..9300412
--- /dev/null
+++ b/rust/tvm/src/bin/tyck.rs
@@ -0,0 +1,24 @@
+use std::path::PathBuf;
+
+use anyhow::Result;
+use structopt::StructOpt;
+
+use tvm::ir::diagnostics::codespan;
+use tvm::ir::IRModule;
+
+
+#[derive(Debug, StructOpt)]
+#[structopt(name = "tyck", about = "Parse and type check a Relay program.")]
+struct Opt {
+/// Input file
+#[structopt(parse(from_os_str))]
+input: PathBuf,
+}
+
+fn main() -> Result<()> {
+codespan::init().expect("Rust based diagnostics");
+let opt = Opt::from_args();
+println!("{:?}", );
+let file = IRModule::parse_file(opt.input)?;
+Ok(())
+}
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
index 799a10c..e434d3f 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -24,13 +24,31 @@
 
 use tvm_macros::{Object, external};
 use super::module::IRModule;
-use crate::runtime::{function::{Function, Typed}, array::Array, string::String 
as TString};
-use crate::runtime::object::{Object, ObjectRef};
+use crate::runtime::{function::{self, Function, ToFunction, Typed}, 
array::Array, string::String as TString};
+use crate::runtime::object::{Object, ObjectPtr, ObjectRef};
 use crate::runtime::function::Result;
 use super::span::Span;
 
 type SourceName = ObjectRef;
 
+// Get the the diagnostic renderer.
+external! {
+#[name("node.ArrayGetItem")]
+fn get_renderer() -> DiagnosticRenderer;
+
+#[name("diagnostics.DiagnosticRenderer")]
+fn diagnostic_renderer(func: Function) -> DiagnosticRenderer;
+
+#[name("diagnostics.Emit")]
+fn emit(ctx: DiagnosticContext, diagnostic: Diagnostic) -> ();
+
+#[name("diagnostics.DiagnosticContextRender")]
+fn diagnostic_context_render(ctx: DiagnosticContext) -> ();
+
+#[name("diagnostics.ClearRenderer")]
+fn clear_renderer() -> ();
+}
+
 /// The diagnostic level, controls the printing of the message.
 #[repr(C)]
 pub enum DiagnosticLevel {
@@ -171,26 +189,20 @@ pub struct DiagnosticContextNode {
 pub renderer: DiagnosticRenderer,
 }
 
-// Get the the diagnostic renderer.
-external! {
-#[name("node.ArrayGetItem")]
-fn get_renderer() -> DiagnosticRenderer;
-
-#[name("diagnostics.DiagnosticRenderer")]
-fn diagnostic_renderer(func: Function) -> DiagnosticRenderer;
-
-#[name("diagnostics.Emit")]
-fn emit(ctx: DiagnosticContext, diagnostic: Diagnostic) -> ();
-
-#[name("diagnostics.DiagnosticContextRender")]
-fn diagnostic_context_render(ctx: DiagnosticContext) -> ();
-}
-
 /// A diagnostic context which records active errors
 /// and contains a renderer.
 impl DiagnosticContext {
-pub fn new(module: IRModule, renderer: DiagnosticRenderer) {
-todo!()
+pub fn new(module: IRModule, render_func: F) -> DiagnosticContext
+where F: Fn(DiagnosticContext) -> () + 'static
+{
+let renderer = diagnostic_renderer(render_func.to_function()).unwrap();
+let node = 

[incubator-tvm] 08/21: Clean up exporting to show off new diagnostics

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 20c6a28606c053fbf9adf1c36c85fd608e63e024
Author: Jared Roesch 
AuthorDate: Thu Oct 15 17:03:00 2020 -0700

Clean up exporting to show off new diagnostics
---
 rust/compiler-ext/src/lib.rs   | 12 ++--
 rust/tvm-rt/src/array.rs   | 32 
 rust/tvm/src/bin/tyck.rs   |  7 ++-
 rust/tvm/src/ir/diagnostics.rs | 10 +-
 rust/tvm/src/ir/mod.rs |  1 +
 rust/tvm/src/ir/module.rs  |  3 +++
 rust/tvm/src/ir/source_map.rs  | 26 +++---
 rust/tvm/src/lib.rs| 24 
 8 files changed, 96 insertions(+), 19 deletions(-)

diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 3e37d21..c136d06 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -22,14 +22,22 @@ use tvm;
 use tvm::runtime::function::register_override;
 
 fn test_fn() -> Result<(), tvm::Error> {
-println!("Hello from Rust!");
+println!("Hello Greg from Rust!");
 Ok(())
 }
 
+fn test_fn2(message: tvm::runtime::string::String) -> Result<(), tvm::Error> {
+println!("The message: {}", message);
+Ok(())
+}
+
+tvm::export!(test_fn, test_fn2);
+
 #[no_mangle]
 fn compiler_ext_initialize() -> i32 {
 let _ = env_logger::try_init();
-register_override(test_fn, "rust_ext.test_fn", true).expect("failed to 
initialize simplifier");
+tvm_export("rust_ext")
+.expect("failed to initialize Rust compiler_ext");
 log::debug!("done!");
 return 0;
 }
diff --git a/rust/tvm-rt/src/array.rs b/rust/tvm-rt/src/array.rs
index 5e19cef..032ca79 100644
--- a/rust/tvm-rt/src/array.rs
+++ b/rust/tvm-rt/src/array.rs
@@ -19,6 +19,7 @@
 
 use std::convert::{TryFrom, TryInto};
 use std::marker::PhantomData;
+use std::iter::{IntoIterator, Iterator};
 
 use crate::errors::Error;
 use crate::object::{IsObjectRef, Object, ObjectPtr, ObjectRef};
@@ -81,6 +82,37 @@ impl Array {
 }
 }
 
+pub struct IntoIter {
+array: Array,
+pos: isize,
+size: isize,
+}
+
+impl Iterator for IntoIter {
+type Item = T;
+
+fn next( self) -> Option {
+if self.pos < self.size {
+let item = self.array.get(self.pos)
+.expect("should not fail");
+self.pos += 1;
+Some(item)
+} else {
+None
+}
+}
+}
+
+impl IntoIterator for Array {
+type Item = T;
+type IntoIter = IntoIter;
+
+fn into_iter(self) -> Self::IntoIter {
+let size = self.len() as isize;
+IntoIter { array: self, pos: 0, size: size }
+}
+}
+
 impl From> for ArgValue<'static> {
 fn from(array: Array) -> ArgValue<'static> {
 array.object.into()
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index b869012..e0c7136 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -18,6 +18,11 @@ fn main() -> Result<()> {
 codespan::init().expect("Rust based diagnostics");
 let opt = Opt::from_args();
 println!("{:?}", );
-let file = IRModule::parse_file(opt.input)?;
+let module = IRModule::parse_file(opt.input)?;
+
+// for (k, v) in module.functions {
+// println!("Function name: {:?}", v);
+// }
+
 Ok(())
 }
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
index b76e43f..4975a45 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -135,6 +135,7 @@ pub struct DiagnosticRendererNode {
 pub base: Object,
 // TODO(@jroesch): we can't easily exposed packed functions due to
 // memory layout
+// missing field here
 }
 
 // def render(self, ctx):
@@ -283,11 +284,10 @@ pub mod codespan {
 pub fn init() -> Result<()> {
 let mut files: SimpleFiles = SimpleFiles::new();
 let render_fn = move |diag_ctx: DiagnosticContext| {
-// let source_map = diag_ctx.module.source_map;
-// for diagnostic in diag_ctx.diagnostics {
-
-// }
-panic!("render_fn");
+let source_map = diag_ctx.module.source_map.clone();
+for diagnostic in diag_ctx.diagnostics.clone() {
+println!("Diagnostic: {}", diagnostic.message);
+}
 };
 
 override_renderer(Some(render_fn))?;
diff --git a/rust/tvm/src/ir/mod.rs b/rust/tvm/src/ir/mod.rs
index 401b6c2..df9bc68 100644
--- a/rust/tvm/src/ir/mod.rs
+++ b/rust/tvm/src/ir/mod.rs
@@ -26,6 +26,7 @@ pub mod module;
 pub mod op;
 pub mod relay;
 pub mod span;
+pub mod source_map;
 pub mod tir;
 pub mod ty;
 
diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index e0444b3..5156e74 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -25,6 +25,7 @@ use crate::runtime::{external, Object, ObjectRef};
 
 use 

[incubator-tvm] branch cargo-build created (now f10ab21)

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a change to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


  at f10ab21  Debug segfault from loading Python

This branch includes the following new commits:

 new 1097cbf  Add initial boilerplate for Rust diagnostic interface.
 new 77ba309  Codespan example almost working
 new cb37856  WIP
 new 131e40a  Hacking on Rust inside of TVM
 new b2b59c2  Borrow code from Egg
 new db24553  Update CMake and delete old API
 new e0f9801  Fix Linux build
 new 20c6a28  Clean up exporting to show off new diagnostics
 new 4cd1bbc  Improve Rust bindings
 new eeb86c6  Fix calling
 new 4261461  Fix
 new 6e13467  Rust Diagnostics work
 new 0cabfdc  Remove type checker
 new 04a9779  Format and cleanup
 new 6828374  Fix the extension code
 new 1874350  More cleanup
 new 8e295b7  Fix some CR
 new 49246bf  WIP
 new a9ee3cb  WIP
 new b8dcc35  WIP
 new f10ab21  Debug segfault from loading Python

The 21 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[incubator-tvm] 12/21: Rust Diagnostics work

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 6e1346748e08255f220c3e6cf72c59a8a3f6ef29
Author: Jared Roesch 
AuthorDate: Fri Oct 16 14:17:01 2020 -0700

Rust Diagnostics work
---
 rust/tvm-rt/src/errors.rs   |  15 
 rust/tvm-rt/src/function.rs |   7 +-
 rust/tvm/src/bin/tyck.rs|  13 ++--
 rust/tvm/src/ir/diagnostics/codespan.rs | 126 ++--
 4 files changed, 117 insertions(+), 44 deletions(-)

diff --git a/rust/tvm-rt/src/errors.rs b/rust/tvm-rt/src/errors.rs
index c884c56..3de9f3c 100644
--- a/rust/tvm-rt/src/errors.rs
+++ b/rust/tvm-rt/src/errors.rs
@@ -68,6 +68,21 @@ pub enum Error {
 Infallible(#[from] std::convert::Infallible),
 #[error("a panic occurred while executing a Rust packed function")]
 Panic,
+#[error("one or more error diagnostics were emitted, please check 
diagnostic render for output.")]
+DiagnosticError(String),
+#[error("{0}")]
+Raw(String),
+}
+
+impl Error {
+pub fn from_raw_tvm(raw: ) -> Error {
+let err_header = raw.find(":").unwrap_or(0);
+let (err_ty, err_content) = raw.split_at(err_header);
+match err_ty {
+"DiagnosticError" => 
Error::DiagnosticError((_content[1..]).into()),
+_ => Error::Raw(raw.into()),
+}
+}
 }
 
 impl Error {
diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index c7aebdd..173b60a 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -133,7 +133,12 @@ impl Function {
 };
 
 if ret_code != 0 {
-return Err(Error::CallFailed(crate::get_last_error().into()));
+let raw_error = crate::get_last_error();
+let error = match Error::from_raw_tvm(raw_error) {
+Error::Raw(string) => Error::CallFailed(string),
+e => e,
+};
+return Err(error);
 }
 
 let rv = RetValue::from_tvm_value(ret_val, ret_type_code as u32);
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index fbab027..13470e7 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -4,7 +4,8 @@ use anyhow::Result;
 use structopt::StructOpt;
 
 use tvm::ir::diagnostics::codespan;
-use tvm::ir::IRModule;
+use tvm::ir::{self, IRModule};
+use tvm::runtime::Error;
 
 #[derive(Debug, StructOpt)]
 #[structopt(name = "tyck", about = "Parse and type check a Relay program.")]
@@ -18,11 +19,11 @@ fn main() -> Result<()> {
 codespan::init().expect("Rust based diagnostics");
 let opt = Opt::from_args();
 println!("{:?}", );
-let module = IRModule::parse_file(opt.input);
-
-// for (k, v) in module.functions {
-// println!("Function name: {:?}", v);
-// }
+let _module = match IRModule::parse_file(opt.input) {
+Err(ir::module::Error::TVM(Error::DiagnosticError(_))) => { return 
Ok(()) },
+Err(e) => { return Err(e.into()); },
+Ok(module) => module
+};
 
 Ok(())
 }
diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
index 80a8784..9fc1ee0 100644
--- a/rust/tvm/src/ir/diagnostics/codespan.rs
+++ b/rust/tvm/src/ir/diagnostics/codespan.rs
@@ -4,6 +4,7 @@ use std::sync::{Arc, Mutex};
 use codespan_reporting::diagnostic::{Diagnostic as CDiagnostic, Label, 
Severity};
 use codespan_reporting::files::SimpleFiles;
 use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
+use codespan_reporting::term::{self, ColorArg};
 
 use crate::ir::source_map::*;
 use super::*;
@@ -13,8 +14,14 @@ enum StartOrEnd {
 End,
 }
 
+struct ByteRange {
+file_id: FileId,
+start_pos: usize,
+end_pos: usize,
+}
+
 enum FileSpanToByteRange {
-AsciiSource,
+AsciiSource(Vec),
 Utf8 {
 /// Map character regions which are larger then 1-byte to length.
 lengths: HashMap,
@@ -27,7 +34,12 @@ impl FileSpanToByteRange {
 let mut last_index = 0;
 let mut is_ascii = true;
 if source.is_ascii() {
-FileSpanToByteRange::AsciiSource
+let line_lengths =
+source
+.lines()
+.map(|line| line.len())
+.collect();
+FileSpanToByteRange::AsciiSource(line_lengths)
 } else {
 panic!()
 }
@@ -41,6 +53,21 @@ impl FileSpanToByteRange {
 // last_index = index;
 // }
 }
+
+fn lookup(, span: ) -> ByteRange {
+use FileSpanToByteRange::*;
+
+let source_name: String = 
span.source_name.name.as_str().unwrap().into();
+
+match self {
+AsciiSource(ref line_lengths) => {
+let start_pos = (_lengths[0..(span.line - 1) as 
usize]).into_iter().sum::() + (span.column) as usize;
+

[incubator-tvm] 13/21: Remove type checker

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 0cabfdcee309b12d8907fc3abe2ba8e8718ecac6
Author: Jared Roesch 
AuthorDate: Fri Oct 16 15:56:10 2020 -0700

Remove type checker
---
 tests/python/relay/test_type_infer2.py | 419 -
 1 file changed, 419 deletions(-)

diff --git a/tests/python/relay/test_type_infer2.py 
b/tests/python/relay/test_type_infer2.py
deleted file mode 100644
index 6758d96..000
--- a/tests/python/relay/test_type_infer2.py
+++ /dev/null
@@ -1,419 +0,0 @@
-# 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.
-"""Test that type checker correcly computes types
-   for expressions.
-"""
-import pytest
-import tvm
-
-from tvm import IRModule, te, relay, parser
-from tvm.relay import op, transform, analysis
-from tvm.relay import Any
-
-
-def infer_mod(mod, annotate_spans=True):
-if annotate_spans:
-mod = relay.transform.AnnotateSpans()(mod)
-
-mod = transform.InferType()(mod)
-return mod
-
-
-def infer_expr(expr, annotate_spans=True):
-mod = IRModule.from_expr(expr)
-mod = infer_mod(mod, annotate_spans)
-mod = transform.InferType()(mod)
-entry = mod["main"]
-return entry if isinstance(expr, relay.Function) else entry.body
-
-
-def assert_has_type(expr, typ, mod=None):
-if not mod:
-mod = tvm.IRModule({})
-
-mod["main"] = expr
-mod = infer_mod(mod)
-checked_expr = mod["main"]
-checked_type = checked_expr.checked_type
-if checked_type != typ:
-raise RuntimeError("Type mismatch %s vs %s" % (checked_type, typ))
-
-
-def initialize_box_adt(mod):
-# initializes simple ADT for tests
-box = relay.GlobalTypeVar("box")
-tv = relay.TypeVar("tv")
-constructor = relay.Constructor("constructor", [tv], box)
-data = relay.TypeData(box, [tv], [constructor])
-mod[box] = data
-return box, constructor
-
-
-def test_monomorphic_let():
-"Program: let %x = 1; %x"
-# TODO(@jroesch): this seems whack.
-sb = relay.ScopeBuilder()
-x = relay.var("x", dtype="float64", shape=())
-x = sb.let("x", relay.const(1.0, "float64"))
-sb.ret(x)
-xchecked = infer_expr(sb.get())
-assert xchecked.checked_type == relay.scalar_type("float64")
-
-
-def test_single_op():
-"Program: fn (%x : float32) { let %t1 = f(%x); %t1 }"
-x = relay.var("x", shape=[])
-func = relay.Function([x], op.log(x))
-ttype = relay.TensorType([], dtype="float32")
-assert_has_type(func, relay.FuncType([ttype], ttype))
-
-
-def test_add_broadcast_op():
-"""
-Program:
-fn (%x: Tensor[(10, 4), float32], %y: Tensor[(5, 10, 1), float32])
--> Tensor[(5, 10, 4), float32] {
-%x + %y
-}
-"""
-x = relay.var("x", shape=(10, 4))
-y = relay.var("y", shape=(5, 10, 1))
-z = x + y
-func = relay.Function([x, y], z)
-t1 = relay.TensorType((10, 4), "float32")
-t2 = relay.TensorType((5, 10, 1), "float32")
-t3 = relay.TensorType((5, 10, 4), "float32")
-expected_ty = relay.FuncType([t1, t2], t3)
-assert_has_type(func, expected_ty)
-
-
-def test_dual_op():
-"""Program:
-fn (%x : Tensor[(10, 10), float32]) {
-  let %t1 = log(x);
-  let %t2 = add(%t1, %x);
-  %t1
-}
-"""
-tp = relay.TensorType((10, 10), "float32")
-x = relay.var("x", tp)
-sb = relay.ScopeBuilder()
-t1 = sb.let("t1", relay.log(x))
-t2 = sb.let("t2", relay.add(t1, x))
-sb.ret(t2)
-f = relay.Function([x], sb.get())
-fchecked = infer_expr(f)
-assert fchecked.checked_type == relay.FuncType([tp], tp)
-
-
-def test_decl():
-"""Program:
-def @f(%x : Tensor[(10, 10), float32]) {
-log(%x)
-}
-"""
-tp = relay.TensorType((10, 10))
-x = relay.var("x", tp)
-f = relay.Function([x], relay.log(x))
-fchecked = infer_expr(f)
-assert fchecked.checked_type == relay.FuncType([tp], tp)
-
-
-def test_recursion():
-"""
-Program:
-   def @f(%n: int32, %data: float32) -> float32 {
-  if (%n == 0) {
-  %data
-  } else {
-  @f(%n - 1, 

[incubator-tvm] 01/21: Add initial boilerplate for Rust diagnostic interface.

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 1097cbf8a23708b7408dfbab7c419e363af57728
Author: Jared Roesch 
AuthorDate: Fri Oct 9 01:18:15 2020 -0700

Add initial boilerplate for Rust diagnostic interface.
---
 python/tvm/ir/diagnostics/__init__.py |   2 +-
 rust/tvm/src/ir/diagnostics.rs| 239 ++
 rust/tvm/src/ir/mod.rs|   1 +
 3 files changed, 241 insertions(+), 1 deletion(-)

diff --git a/python/tvm/ir/diagnostics/__init__.py 
b/python/tvm/ir/diagnostics/__init__.py
index 6503743..0ad2a7a 100644
--- a/python/tvm/ir/diagnostics/__init__.py
+++ b/python/tvm/ir/diagnostics/__init__.py
@@ -37,7 +37,7 @@ def get_renderer():
 """
 return _ffi_api.GetRenderer()
 
-
+@tvm.register_func("diagnostics.override_renderer")
 def override_renderer(render_func):
 """
 Sets a custom renderer for diagnostics.
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
new file mode 100644
index 000..799a10c
--- /dev/null
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -0,0 +1,239 @@
+/*
+ * 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.
+ */
+
+/// The diagnostic interface to TVM, used for reporting and rendering
+/// diagnostic information by the compiler. This module exposes
+/// three key abstractions: a Diagnostic, the DiagnosticContext,
+/// and the DiagnosticRenderer.
+
+use tvm_macros::{Object, external};
+use super::module::IRModule;
+use crate::runtime::{function::{Function, Typed}, array::Array, string::String 
as TString};
+use crate::runtime::object::{Object, ObjectRef};
+use crate::runtime::function::Result;
+use super::span::Span;
+
+type SourceName = ObjectRef;
+
+/// The diagnostic level, controls the printing of the message.
+#[repr(C)]
+pub enum DiagnosticLevel {
+Bug = 10,
+Error = 20,
+Warning = 30,
+Note = 40,
+Help = 50,
+}
+
+/// A compiler diagnostic.
+#[repr(C)]
+#[derive(Object)]
+#[ref_name = "Diagnostic"]
+#[type_key = "Diagnostic"]
+pub struct DiagnosticNode {
+pub base: Object,
+/// The level.
+pub level: DiagnosticLevel,
+/// The span at which to report an error.
+pub span: Span,
+/// The diagnostic message.
+pub message: TString,
+}
+
+impl Diagnostic {
+pub fn new(level: DiagnosticLevel, span: Span, message: TString) {
+todo!()
+}
+
+pub fn bug(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn error(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn warning(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn note(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn help(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+}
+
+/// A wrapper around std::stringstream to build a diagnostic.
+pub struct DiagnosticBuilder {
+/// The level.
+pub level: DiagnosticLevel,
+
+/// The source name.
+pub source_name: SourceName,
+
+/// The span of the diagnostic.
+pub span: Span,
+}
+
+//   /*! \brief Display diagnostics in a given display format.
+//*
+//* A diagnostic renderer is responsible for converting the
+//* raw diagnostics into consumable output.
+//*
+//* For example the terminal renderer will render a sequence
+//* of compiler diagnostics to std::out and std::err in
+//* a human readable form.
+//*/
+//   class DiagnosticRendererNode : public Object {
+//public:
+// TypedPackedFunc renderer;
+
+// // override attr visitor
+// void VisitAttrs(AttrVisitor* v) {}
+
+// static constexpr const char* _type_key = "DiagnosticRenderer";
+// TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticRendererNode, Object);
+//   };
+
+//   class DiagnosticRenderer : public ObjectRef {
+//public:
+// TVM_DLL DiagnosticRenderer(TypedPackedFunc 
render);
+// TVM_DLL DiagnosticRenderer()
+// : DiagnosticRenderer(TypedPackedFunc()) {}
+
+// void Render(const DiagnosticContext& ctx);
+
+// DiagnosticRendererNode* operator->() {
+//   CHECK(get() != nullptr);
+//   return 

[incubator-tvm] 21/21: Debug segfault from loading Python

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit f10ab21e62e7d89c900bf733d6c95eb4026d150a
Author: Jared Roesch 
AuthorDate: Sun Oct 25 17:26:47 2020 -0700

Debug segfault from loading Python
---
 python/tvm/__init__.py|  2 ++
 python/tvm/relay/__init__.py  |  3 +-
 python/tvm/relay/analysis/__init__.py |  2 +-
 python/tvm/relay/analysis/analysis.py |  6 ++--
 python/tvm/relay/analysis/annotated_regions.py|  2 +-
 python/tvm/relay/analysis/call_graph.py   |  4 +--
 python/tvm/relay/analysis/sparse_dense.py | 15 +
 python/tvm/relay/backend/graph_runtime_factory.py |  2 +-
 python/tvm/relay/build_module.py  |  5 ++-
 python/tvm/relay/op/op.py | 40 +++
 python/tvm/relay/transform/__init__.py|  2 +-
 python/tvm/relay/transform/memory_alloc.py|  7 ++--
 python/tvm/relay/transform/transform.py   |  5 +--
 python/tvm/topi/cuda/__init__.py  |  2 --
 python/tvm/topi/cuda/sparse.py|  3 +-
 rust/tvm-rt/src/map.rs| 12 +++
 rust/tvm-rt/src/module.rs | 16 +
 rust/tvm-rt/src/to_function.rs|  1 +
 rust/tvm/Cargo.toml   |  2 +-
 rust/tvm/src/ir/module.rs |  3 --
 rust/tvm/src/ir/relay/mod.rs  |  1 -
 rust/tvm/src/python.rs| 21 +---
 src/runtime/module.cc |  2 +-
 23 files changed, 99 insertions(+), 59 deletions(-)

diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py
index 569e8f0..60f81f4 100644
--- a/python/tvm/__init__.py
+++ b/python/tvm/__init__.py
@@ -67,6 +67,8 @@ from . import support
 # Contrib initializers
 from .contrib import rocm as _rocm, nvcc as _nvcc, sdaccel as _sdaccel
 
+def cleanup():
+_ffi.base._LIB = None
 
 def tvm_wrap_excepthook(exception_hook):
 """Wrap given excepthook with TVM additional work."""
diff --git a/python/tvm/relay/__init__.py b/python/tvm/relay/__init__.py
index cd96ecc..7e6ed4f 100644
--- a/python/tvm/relay/__init__.py
+++ b/python/tvm/relay/__init__.py
@@ -60,8 +60,7 @@ from . import qnn
 from .scope_builder import ScopeBuilder
 
 # Load Memory Passes
-from .transform import memory_alloc
-from .transform import memory_plan
+from .transform import memory_alloc, memory_plan
 
 # Required to traverse large programs
 setrecursionlimit(1)
diff --git a/python/tvm/relay/analysis/__init__.py 
b/python/tvm/relay/analysis/__init__.py
index b4ea7f3..4ea4de7 100644
--- a/python/tvm/relay/analysis/__init__.py
+++ b/python/tvm/relay/analysis/__init__.py
@@ -26,7 +26,7 @@ from .annotated_regions import AnnotatedRegionSet
 from . import call_graph
 from .call_graph import CallGraph
 
-# Feature
+# # Feature
 from . import feature
 from . import sparse_dense
 
diff --git a/python/tvm/relay/analysis/analysis.py 
b/python/tvm/relay/analysis/analysis.py
index 7e49461..48e9ce0 100644
--- a/python/tvm/relay/analysis/analysis.py
+++ b/python/tvm/relay/analysis/analysis.py
@@ -20,9 +20,9 @@
 This file contains the set of passes for Relay, which exposes an interface for
 configuring the passes and scripting them in Python.
 """
-from tvm.ir import IRModule
-from tvm.relay import transform, build_module
-from tvm.runtime.ndarray import cpu
+from ...ir import IRModule
+from ...relay import transform, build_module
+from ...runtime.ndarray import cpu
 
 from . import _ffi_api
 from .feature import Feature
diff --git a/python/tvm/relay/analysis/annotated_regions.py 
b/python/tvm/relay/analysis/annotated_regions.py
index 437b97b..a18ccb9 100644
--- a/python/tvm/relay/analysis/annotated_regions.py
+++ b/python/tvm/relay/analysis/annotated_regions.py
@@ -17,7 +17,7 @@
 # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, 
unused-import
 """Regions used in Relay."""
 
-from tvm.runtime import Object
+from ...runtime import Object
 from . import _ffi_api
 
 
diff --git a/python/tvm/relay/analysis/call_graph.py 
b/python/tvm/relay/analysis/call_graph.py
index 966659a..fd9704d 100644
--- a/python/tvm/relay/analysis/call_graph.py
+++ b/python/tvm/relay/analysis/call_graph.py
@@ -17,8 +17,8 @@
 # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, 
unused-import
 """Call graph used in Relay."""
 
-from tvm.ir import IRModule
-from tvm.runtime import Object
+from ...ir import IRModule
+from ...runtime import Object
 from ..expr import GlobalVar
 from . import _ffi_api
 
diff --git a/python/tvm/relay/analysis/sparse_dense.py 
b/python/tvm/relay/analysis/sparse_dense.py
index d521748..51fab34 100644
--- a/python/tvm/relay/analysis/sparse_dense.py
+++ 

[incubator-tvm] 18/21: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 49246bff342eb59757cecc34a9a9465a2e3c063d
Author: Jared Roesch 
AuthorDate: Wed Oct 21 14:09:37 2020 -0700

WIP
---
 rust/tvm-macros/src/external.rs |  5 ++-
 rust/tvm-macros/src/lib.rs  |  1 +
 rust/tvm/src/ir/module.rs   | 67 +
 3 files changed, 26 insertions(+), 47 deletions(-)

diff --git a/rust/tvm-macros/src/external.rs b/rust/tvm-macros/src/external.rs
index 802d7ae..de8ada3 100644
--- a/rust/tvm-macros/src/external.rs
+++ b/rust/tvm-macros/src/external.rs
@@ -17,6 +17,7 @@
  * under the License.
  */
 use proc_macro2::Span;
+use proc_macro_error::abort;
 use quote::quote;
 use syn::parse::{Parse, ParseStream, Result};
 
@@ -109,7 +110,9 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 .iter()
 .map(|ty_param| match ty_param {
 syn::GenericParam::Type(param) => param.clone(),
-_ => panic!(),
+_ => abort! { ty_param,
+"Only supports type parameters."
+}
 })
 .collect();
 
diff --git a/rust/tvm-macros/src/lib.rs b/rust/tvm-macros/src/lib.rs
index 603e1ce..ab75c92 100644
--- a/rust/tvm-macros/src/lib.rs
+++ b/rust/tvm-macros/src/lib.rs
@@ -35,6 +35,7 @@ pub fn macro_impl(input: TokenStream) -> TokenStream {
 TokenStream::from(object::macro_impl(input))
 }
 
+#[proc_macro_error]
 #[proc_macro]
 pub fn external(input: TokenStream) -> TokenStream {
 external::macro_impl(input)
diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index 443915f..8918bdc 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -63,6 +63,8 @@ external! {
 #[name("parser.ParseExpr")]
 fn parse_expression(file_name: TVMString, source: TVMString) -> IRModule;
 // Module methods
+#[name("ir.Module_Add")]
+fn module_add_def(module: IRModule, type_name: GlobalVar, expr: 
relay::Expr, update: bool) -> ();
 #[name("ir.Module_AddDef")]
 fn module_add_def(module: IRModule, type_name: GlobalTypeVar, type_data: 
TypeData, update: bool) -> ();
 #[name("ir.Module_GetGlobalVar")]
@@ -73,55 +75,28 @@ external! {
 fn module_lookup(module: IRModule, var: GlobalVar) -> BaseFunc;
 #[name("ir.Module_Lookup_str")]
 fn module_lookup_str(module: IRModule, name: TVMString) -> BaseFunc;
+#[name("ir.Module_GetGlobalTypeVars")]
+fn module_get_global_type_vars() -> Array;
+#[name("ir.Module_ContainGlobalVar")]
+fn module_get_global_var(name: TVMString) -> bool;
+#[name("ir.Module_ContainGlobalTypeVar")]
+fn module_get_global_type_var(name: TVMString) -> bool;
+#[name("ir.Module_LookupDef")]
+fn module_lookup_def(module: IRModule, global: GlobalTypeVar) -> TypeDef;
+#[name("ir.Module_LookupDef_str")]
+fn module_lookup_def_str(module: IRModule, global: GlobalTypeVar) -> 
TypeDef;
+#[name("ir.Module_LookupTag")]
+fn module_lookup_tag(module: IRModule, tag: i32) -> Constructor;
+#[name("ir.Module_FromExpr")]
+fn module_from_expr(expr: relay::Expr, funcs: Map, 
types: Map) -> IRModule;
+#[name("ir.Module_Import")]
+fn module_import(module: IRModule, path: TVMString);
+#[name("ir.Module_ImportFromStd")]
+fn module_import_from_std(module: IRModule, path: TVMString);
 }
 
-// TVM_REGISTER_GLOBAL("ir.Module_GetGlobalTypeVars")
-// .set_body_method(::GetGlobalTypeVars);
+// Note: we don't expose update here as update is going to be removed.
 
-// TVM_REGISTER_GLOBAL("ir.Module_ContainGlobalVar")
-// .set_body_method(::ContainGlobalVar);
-
-// TVM_REGISTER_GLOBAL("ir.Module_GetGlobalTypeVar")
-// .set_body_method(::GetGlobalTypeVar);
-
-// TVM_REGISTER_GLOBAL("ir.Module_LookupDef").set_body_typed([](IRModule mod, 
GlobalTypeVar var) {
-//   return mod->LookupTypeDef(var);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_LookupDef_str").set_body_typed([](IRModule 
mod, String var) {
-//   return mod->LookupTypeDef(var);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_LookupTag").set_body_typed([](IRModule mod, 
int32_t tag) {
-//   return mod->LookupTag(tag);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_FromExpr")
-// .set_body_typed([](RelayExpr e, tvm::Map funcs,
-//tvm::Map type_defs) {
-//   return IRModule::FromExpr(e, funcs, type_defs);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_Update").set_body_typed([](IRModule mod, 
IRModule from) {
-//   mod->Update(from);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_UpdateFunction")
-// .set_body_typed([](IRModule mod, GlobalVar gv, BaseFunc func) { 
mod->Update(gv, func); });
-
-// TVM_REGISTER_GLOBAL("ir.Module_Import").set_body_typed([](IRModule mod, 
String path) {
-//   mod->Import(path);
-// });
-
-// 

[incubator-tvm] 15/21: Fix the extension code

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 68283745b9c283db611579205a3b925eb09e9faa
Author: Jared Roesch 
AuthorDate: Fri Oct 16 16:32:13 2020 -0700

Fix the extension code
---
 src/contrib/rust_extension.cc | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/src/contrib/rust_extension.cc b/src/contrib/rust_extension.cc
new file mode 100644
index 000..075cbc6
--- /dev/null
+++ b/src/contrib/rust_extension.cc
@@ -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.
+ */
+
+/*!
+ * \file src/contrib/rust_extension.cc
+ * \brief Expose Rust extensions initialization.
+ */
+#ifdef RUST_COMPILER_EXT
+
+extern "C" {
+  int compiler_ext_initialize();
+  static int test = compiler_ext_initialize();
+}
+
+#endif



[incubator-tvm] 19/21: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit a9ee3cb34c020a4debe75fc9a194303f22d00892
Author: Jared Roesch 
AuthorDate: Thu Oct 22 11:48:34 2020 -0700

WIP
---
 rust/tvm-macros/Cargo.toml  |  2 +-
 rust/tvm-macros/src/external.rs | 43 +
 rust/tvm-macros/src/lib.rs  |  1 +
 rust/tvm-rt/src/object/mod.rs   |  2 +-
 rust/tvm/src/ir/module.rs   | 16 +++
 5 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/rust/tvm-macros/Cargo.toml b/rust/tvm-macros/Cargo.toml
index 63b8472..8e97d3b 100644
--- a/rust/tvm-macros/Cargo.toml
+++ b/rust/tvm-macros/Cargo.toml
@@ -33,5 +33,5 @@ proc-macro = true
 goblin = "^0.2"
 proc-macro2 = "^1.0"
 quote = "^1.0"
-syn = { version = "1.0.17", features = ["full", "extra-traits"] }
+syn = { version = "^1.0", features = ["full", "parsing", "extra-traits"] }
 proc-macro-error = "^1.0"
diff --git a/rust/tvm-macros/src/external.rs b/rust/tvm-macros/src/external.rs
index de8ada3..44a242c 100644
--- a/rust/tvm-macros/src/external.rs
+++ b/rust/tvm-macros/src/external.rs
@@ -21,9 +21,28 @@ use proc_macro_error::abort;
 use quote::quote;
 use syn::parse::{Parse, ParseStream, Result};
 
-use syn::{FnArg, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, 
TraitItemMethod, Type};
+use syn::{Token, FnArg, Signature, Attribute, token::Semi, Visibility, 
Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
+
+struct ExternalItem {
+attrs: Vec,
+visibility: Visibility,
+sig: Signature,
+}
+
+impl Parse for ExternalItem {
+fn parse(input: ParseStream) -> Result {
+let item = ExternalItem {
+attrs: input.call(Attribute::parse_outer)?,
+visibility: input.parse()?,
+sig: input.parse()?,
+};
+let _semi: Semi = input.parse()?;
+Ok(item)
+}
+}
 
 struct External {
+visibility: Visibility,
 tvm_name: String,
 ident: Ident,
 generics: Generics,
@@ -33,7 +52,8 @@ struct External {
 
 impl Parse for External {
 fn parse(input: ParseStream) -> Result {
-let method: TraitItemMethod = input.parse()?;
+let method: ExternalItem = input.parse()?;
+let visibility = method.visibility;
 assert_eq!(method.attrs.len(), 1);
 let sig = method.sig;
 let tvm_name = method.attrs[0].parse_meta()?;
@@ -48,8 +68,7 @@ impl Parse for External {
 }
 _ => panic!(),
 };
-assert_eq!(method.default, None);
-assert!(method.semi_token != None);
+
 let ident = sig.ident;
 let generics = sig.generics;
 let inputs = sig
@@ -61,6 +80,7 @@ impl Parse for External {
 let ret_type = sig.output;
 
 Ok(External {
+visibility,
 tvm_name,
 ident,
 generics,
@@ -99,6 +119,7 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 let mut items = Vec::new();
 
 for external in _input.externs {
+let visibility = 
 let name = 
 let global_name = format!("global_{}", external.ident);
 let global_name = Ident::new(_name, Span::call_site());
@@ -127,15 +148,21 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 let ty: Type = *pat_type.ty.clone();
 (ident, ty)
 }
-_ => panic!(),
+_ =>  abort! { pat_type,
+"Only supports type parameters."
+}
 },
-_ => panic!(),
+pat => abort! {
+pat, "invalid pattern type for function";
+
+note = "{:?} is not allowed here", pat;
+}
 })
 .unzip();
 
 let ret_type = match _type {
 ReturnType::Type(_, rtype) => *rtype.clone(),
-_ => panic!(),
+ReturnType::Default => syn::parse_str::("()").unwrap(),
 };
 
 let global = quote! {
@@ -150,7 +177,7 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 items.push(global);
 
 let wrapper = quote! {
-pub fn #name<#(#ty_params),*>(#(#args : #tys),*) -> 
#result_type<#ret_type> {
+#visibility fn #name<#(#ty_params),*>(#(#args : #tys),*) -> 
#result_type<#ret_type> {
 let func_ref: #tvm_rt_crate::Function = #global_name.clone();
 let func_ref: Box 
#result_type<#ret_type>> = func_ref.into();
 let res: #ret_type = func_ref(#(#args),*)?;
diff --git a/rust/tvm-macros/src/lib.rs b/rust/tvm-macros/src/lib.rs
index ab75c92..32f2839 100644
--- a/rust/tvm-macros/src/lib.rs
+++ 

[incubator-tvm] 10/21: Fix calling

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit eeb86c63d693288f8d406aed6b1b0df6d28e4b07
Author: Jared Roesch 
AuthorDate: Thu Oct 15 21:37:34 2020 -0700

Fix calling
---
 rust/tvm-rt/src/function.rs| 28 +---
 rust/tvm/src/bin/tyck.rs   |  2 +-
 rust/tvm/src/ir/diagnostics/mod.rs |  4 +---
 3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index bae06e9..c7aebdd 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -33,6 +33,7 @@ use std::{
 };
 
 use crate::errors::Error;
+use crate::object::ObjectPtr;
 
 pub use super::to_function::{ToFunction, Typed};
 pub use tvm_sys::{ffi, ArgValue, RetValue};
@@ -120,21 +121,26 @@ impl Function {
 let mut ret_val = ffi::TVMValue { v_int64: 0 };
 let mut ret_type_code = 0i32;
 
-check_call!(ffi::TVMFuncCall(
-self.handle,
-values.as_mut_ptr() as *mut ffi::TVMValue,
-type_codes.as_mut_ptr() as *mut c_int,
-num_args as c_int,
- ret_val as *mut _,
- ret_type_code as *mut _
-));
+let ret_code = unsafe {
+ffi::TVMFuncCall(
+self.handle,
+values.as_mut_ptr() as *mut ffi::TVMValue,
+type_codes.as_mut_ptr() as *mut c_int,
+num_args as c_int,
+ ret_val as *mut _,
+ ret_type_code as *mut _
+)
+};
+
+if ret_code != 0 {
+return Err(Error::CallFailed(crate::get_last_error().into()));
+}
 
 let rv = RetValue::from_tvm_value(ret_val, ret_type_code as u32);
 match rv {
 RetValue::ObjectHandle(object) => {
-let optr = crate::object::ObjectPtr::from_raw(object as 
_).unwrap();
-// println!("after wrapped call: {}", optr.count());
-crate::object::ObjectPtr::leak(optr);
+let optr = ObjectPtr::from_raw(object as _).unwrap();
+ObjectPtr::leak(optr);
 }
 _ => {}
 };
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index e0c7136..fbab027 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -18,7 +18,7 @@ fn main() -> Result<()> {
 codespan::init().expect("Rust based diagnostics");
 let opt = Opt::from_args();
 println!("{:?}", );
-let module = IRModule::parse_file(opt.input)?;
+let module = IRModule::parse_file(opt.input);
 
 // for (k, v) in module.functions {
 // println!("Function name: {:?}", v);
diff --git a/rust/tvm/src/ir/diagnostics/mod.rs 
b/rust/tvm/src/ir/diagnostics/mod.rs
index fce214a..039d1ed 100644
--- a/rust/tvm/src/ir/diagnostics/mod.rs
+++ b/rust/tvm/src/ir/diagnostics/mod.rs
@@ -207,9 +207,7 @@ impl DiagnosticContext {
 }
 }
 
-// Override the global diagnostics renderer.
-// Params
-// --
+/// Override the global diagnostics renderer.
 // render_func: Option[Callable[[DiagnosticContext], None]]
 // If the render_func is None it will remove the current custom renderer
 // and return to default behavior.



[incubator-tvm] 07/21: Fix Linux build

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit e0f980142c3c0ab795de316943079a651743d8d7
Author: Jared Roesch 
AuthorDate: Thu Oct 15 01:42:14 2020 -0700

Fix Linux build
---
 cmake/modules/LLVM.cmake | 7 ++-
 rust/tvm-sys/Cargo.toml  | 2 +-
 rust/tvm-sys/build.rs| 3 +--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/cmake/modules/LLVM.cmake b/cmake/modules/LLVM.cmake
index 5f8ace1..ca4ecd6 100644
--- a/cmake/modules/LLVM.cmake
+++ b/cmake/modules/LLVM.cmake
@@ -16,7 +16,12 @@
 # under the License.
 
 # LLVM rules
-add_definitions(-DDMLC_USE_FOPEN64=0)
+# Due to LLVM debug symbols you can sometimes face linking issues on
+# certain compiler, platform combinations if you don't set NDEBUG.
+#
+# See https://github.com/imageworks/OpenShadingLanguage/issues/1069
+# for more discussion.
+add_definitions(-DDMLC_USE_FOPEN64=0 -DNDEBUG=1)
 
 # Test if ${USE_LLVM} is not an explicit boolean false
 # It may be a boolean or a string
diff --git a/rust/tvm-sys/Cargo.toml b/rust/tvm-sys/Cargo.toml
index c25a5bf..2952aa4 100644
--- a/rust/tvm-sys/Cargo.toml
+++ b/rust/tvm-sys/Cargo.toml
@@ -23,7 +23,7 @@ license = "Apache-2.0"
 edition = "2018"
 
 [features]
-default = ["bindings"]
+default = []
 bindings = []
 
 [dependencies]
diff --git a/rust/tvm-sys/build.rs b/rust/tvm-sys/build.rs
index 2d86c4b..1590234 100644
--- a/rust/tvm-sys/build.rs
+++ b/rust/tvm-sys/build.rs
@@ -60,8 +60,7 @@ fn main() -> Result<()> {
 if cfg!(feature = "bindings") {
 println!("cargo:rerun-if-env-changed=TVM_HOME");
 println!("cargo:rustc-link-lib=dylib=tvm");
-println!("cargo:rustc-link-lib=dylib=llvm-10");
-println!("cargo:rustc-link-search={}/build", tvm_home);
+println!("cargo:rustc-link-search=native={}/build", tvm_home);
 }
 
 // @see rust-bindgen#550 for `blacklist_type`



[incubator-tvm] 05/21: Borrow code from Egg

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit b2b59c229e9b8c2002d8c8cd520748df6b38e074
Author: Jared Roesch 
AuthorDate: Tue Oct 13 15:26:54 2020 -0700

Borrow code from Egg
---
 rust/compiler-ext/src/lib.rs | 344 ++-
 1 file changed, 337 insertions(+), 7 deletions(-)

diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 31e1bb2..58bdd0c 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -1,7 +1,337 @@
-#[cfg(test)]
-mod tests {
-#[test]
-fn it_works() {
-assert_eq!(2 + 2, 4);
-}
-}
+/*
+ * 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.
+ */
+
+ use std::os::raw::c_int;
+ use tvm::initialize;
+ use tvm::ir::{tir, PrimExpr};
+ use tvm::runtime::function::register_override;
+ use tvm::runtime::map::Map;
+ use tvm::runtime::object::{IsObject, IsObjectRef};
+ 
+ use ordered_float::NotNan;
+ 
+ mod interval;
+ mod math;
+ 
+ use math::{BoundsMap, Expr, RecExpr};
+ use tvm::ir::arith::ConstIntBound;
+ use tvm_rt::{ObjectRef, array::Array};
+ 
+ macro_rules! downcast_match {
+ ($id:ident; { $($t:ty => $arm:expr $(,)? )+ , else => $default:expr }) => 
{
+ $( if let Ok($id) = $id.downcast_clone::<$t>() { $arm } else )+
+ { $default }
+ }
+ }
+ 
+ #[derive(Default)]
+ struct VarMap {
+ vars: Vec<(tvm::ir::tir::Var, egg::Symbol)>,
+ objs: Vec,
+ }
+ 
+ impl VarMap {
+ // FIXME this should eventually do the right thing for TVM variables
+ // right now it depends on them having unique names
+ fn make_symbol( self, var: tvm::ir::tir::Var) -> egg::Symbol {
+ let sym = egg::Symbol::from(var.name_hint.as_str().unwrap());
+ for (_, sym2) in  {
+ if sym == *sym2 {
+ return sym;
+ }
+ }
+ 
+ self.vars.push((var, sym));
+ sym
+ }
+ 
+ fn get_symbol(, sym: egg::Symbol) -> tvm::ir::tir::Var {
+ for (v, sym2) in  {
+ if sym == *sym2 {
+ return v.clone();
+ }
+ }
+ panic!("Should have found a var")
+ }
+ 
+ fn push_obj( self, obj: impl IsObjectRef) -> usize {
+ let i = self.objs.len();
+ self.objs.push(obj.upcast());
+ i
+ }
+ 
+ fn get_obj(, i: usize) -> T {
+ self.objs[i].clone().downcast().expect("bad downcast")
+ }
+ }
+ 
+ fn to_egg(vars:  VarMap, prim: ) -> RecExpr {
+ fn build(vars:  VarMap, p: , recexpr:  RecExpr) -> 
egg::Id {
+ macro_rules! r {
+ ($e:expr) => {
+ build(vars, &$e, recexpr)
+ };
+ }
+ 
+ let dt = recexpr.add(Expr::DataType(p.datatype));
+ let e = downcast_match!(p; {
+ tir::Add => Expr::Add([dt, r!(p.a), r!(p.b)]),
+ tir::Sub => Expr::Sub([dt, r!(p.a), r!(p.b)]),
+ tir::Mul => Expr::Mul([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::Div => Expr::Div([dt, r!(p.a), r!(p.b)]),
+ tir::Mod => Expr::Mod([dt, r!(p.a), r!(p.b)]),
+ tir::FloorDiv => Expr::FloorDiv([dt, r!(p.a), r!(p.b)]),
+ tir::FloorMod => Expr::FloorMod([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::Min => Expr::Min([dt, r!(p.a), r!(p.b)]),
+ tir::Max => Expr::Max([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::Ramp => Expr::Ramp([dt, r!(p.start), r!(p.stride), 
recexpr.add(Expr::Int(p.lanes.into()))]),
+ tir::Select => Expr::Select([dt, r!(p.condition), 
r!(p.true_value), r!(p.false_value)]),
+ 
+ tir::Eq => Expr::Equal([dt, r!(p.a), r!(p.b)]),
+ tir::Ne => Expr::NotEqual([dt, r!(p.a), r!(p.b)]),
+ tir::Lt => Expr::Less([dt, r!(p.a), r!(p.b)]),
+ tir::Le => Expr::LessEqual([dt, r!(p.a), r!(p.b)]),
+ tir::Gt => Expr::Greater([dt, r!(p.a), r!(p.b)]),
+ tir::Ge => Expr::GreaterEqual([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::And => Expr::And([dt, r!(p.a), r!(p.b)]),
+ tir::Or => Expr::Or([dt, r!(p.a), r!(p.b)]),
+ tir::Not => 

[incubator-tvm] branch cargo-build updated: Fix

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git


The following commit(s) were added to refs/heads/cargo-build by this push:
 new 83ad4d4  Fix
83ad4d4 is described below

commit 83ad4d443350cc499e8af1fc419d3a694cb5e1f7
Author: Jared Roesch 
AuthorDate: Thu Nov 5 18:05:28 2020 -0800

Fix
---
 python/tvm/relay/backend/graph_runtime_factory.py |  2 +-
 python/tvm/relay/build_module.py  |  5 ++---
 rust/tvm-rt/src/map.rs| 12 
 rust/tvm-rt/src/module.rs | 16 
 rust/tvm-rt/src/to_function.rs|  1 +
 src/runtime/module.cc |  2 +-
 6 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/python/tvm/relay/backend/graph_runtime_factory.py 
b/python/tvm/relay/backend/graph_runtime_factory.py
index 4c6ac47..3427a62 100644
--- a/python/tvm/relay/backend/graph_runtime_factory.py
+++ b/python/tvm/relay/backend/graph_runtime_factory.py
@@ -21,7 +21,7 @@ from tvm._ffi.registry import get_global_func
 from tvm.runtime import ndarray
 
 
-class GraphRuntimeFactoryModule(object):
+class GraphRuntimeFactoryModule:
 """Graph runtime factory module.
 This is a module of graph runtime factory
 
diff --git a/python/tvm/relay/build_module.py b/python/tvm/relay/build_module.py
index e93d654..7e32dea 100644
--- a/python/tvm/relay/build_module.py
+++ b/python/tvm/relay/build_module.py
@@ -187,9 +187,8 @@ class BuildModule(object):
 return ret
 
 @register_func("tvm.relay.build")
-def build1(mod, target=None, target_host=None, params=None, 
mod_name="default"):
-import pdb; pdb.set_trace()
-return build(mod, target, target_host, params, mod_name)
+def _rust_build_module(mod, target=None, target_host=None, params=None, 
mod_name="default"):
+return build(mod, target, target_host, params, mod_name).module
 
 def build(mod, target=None, target_host=None, params=None, mod_name="default"):
 """Helper function that builds a Relay function to run on TVM graph
diff --git a/rust/tvm-rt/src/map.rs b/rust/tvm-rt/src/map.rs
index 721fb1e..ab44e40 100644
--- a/rust/tvm-rt/src/map.rs
+++ b/rust/tvm-rt/src/map.rs
@@ -109,6 +109,18 @@ where
 let oref: ObjectRef = map_get_item(self.object.clone(), key.upcast())?;
 oref.downcast()
 }
+
+pub fn empty() -> Self {
+Self::from_iter(vec![].into_iter())
+}
+
+//(@jroesch): I don't think this is a correct implementation.
+pub fn null() -> Self {
+Map {
+object: ObjectRef::null(),
+_data: PhantomData,
+}
+}
 }
 
 pub struct IntoIter {
diff --git a/rust/tvm-rt/src/module.rs b/rust/tvm-rt/src/module.rs
index c0822a5..18347da 100644
--- a/rust/tvm-rt/src/module.rs
+++ b/rust/tvm-rt/src/module.rs
@@ -30,6 +30,8 @@ use tvm_sys::ffi;
 
 use crate::errors::Error;
 use crate::{errors, function::Function};
+use crate::{String as TString};
+use crate::RetValue;
 
 const ENTRY_FUNC:  = "__tvm_main__";
 
@@ -49,6 +51,9 @@ crate::external! {
 
 #[name("runtime.ModuleLoadFromFile")]
 fn load_from_file(file_name: CString, format: CString) -> Module;
+
+#[name("runtime.ModuleSaveToFile")]
+fn save_to_file(module: ffi::TVMModuleHandle, name: TString, fmt: TString);
 }
 
 impl Module {
@@ -110,6 +115,10 @@ impl Module {
 Ok(module)
 }
 
+pub fn save_to_file(, name: String, fmt: String) -> Result<(), Error> 
{
+save_to_file(self.handle(), name.into(), fmt.into())
+}
+
 /// Checks if a target device is enabled for a module.
 pub fn enabled(, target: ) -> bool {
 let target = CString::new(target).unwrap();
@@ -128,3 +137,10 @@ impl Drop for Module {
 check_call!(ffi::TVMModFree(self.handle));
 }
 }
+
+// impl std::convert::TryFrom for Module {
+// type Error = Error;
+// fn try_from(ret_value: RetValue) -> Result {
+// Ok(Module::new(ret_value.try_into()?))
+// }
+// }
diff --git a/rust/tvm-rt/src/to_function.rs b/rust/tvm-rt/src/to_function.rs
index affd81b..c5ede7d 100644
--- a/rust/tvm-rt/src/to_function.rs
+++ b/rust/tvm-rt/src/to_function.rs
@@ -255,6 +255,7 @@ impl_typed_and_to_function!(2; A, B);
 impl_typed_and_to_function!(3; A, B, C);
 impl_typed_and_to_function!(4; A, B, C, D);
 impl_typed_and_to_function!(5; A, B, C, D, E);
+impl_typed_and_to_function!(6; A, B, C, D, E, G);
 
 #[cfg(test)]
 mod tests {
diff --git a/src/runtime/module.cc b/src/runtime/module.cc
index ac2b60f..af5feab 100644
--- a/src/runtime/module.cc
+++ b/src/runtime/module.cc
@@ -175,7 +175,7 @@ 
TVM_REGISTER_GLOBAL("runtime.ModuleGetTypeKey").set_body_typed([](Module mod) {
 
TVM_REGISTER_GLOBAL("runtime.ModuleLoadFromFile").set_body_typed(Module::LoadFromFile);
 
 TVM_REGISTER_GLOBAL("runtime.ModuleSaveToFile")
-.set_body_typed([](Module mod, 

[GitHub] [incubator-tvm] comaniac commented on pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


comaniac commented on pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#issuecomment-722760931


   Thanks @d-smirnov @lhutton1 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] branch main updated (d164aac -> 0469a77)

2020-11-05 Thread comaniac
This is an automated email from the ASF dual-hosted git repository.

comaniac pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


from d164aac  [TVMSCRIPT] Using diagnostics for TVM Script (#6797)
 add 0469a77  [BYOC] [ACL] ACL Runtime padding workaround (#6724)

No new revisions were added by this update.

Summary of changes:
 python/tvm/relay/op/contrib/arm_compute_lib.py | 42 ---
 src/runtime/contrib/arm_compute_lib/acl_utils.cc   |  1 +
 .../contrib/test_arm_compute_lib/infrastructure.py |  3 +-
 .../contrib/test_arm_compute_lib/test_dense.py | 62 +-
 .../contrib/test_arm_compute_lib/test_maximum.py   |  1 +
 .../contrib/test_arm_compute_lib/test_network.py   |  7 +--
 .../contrib/test_arm_compute_lib/test_pooling.py   | 11 ++--
 .../contrib/test_arm_compute_lib/test_reshape.py   |  5 +-
 8 files changed, 102 insertions(+), 30 deletions(-)



[GitHub] [incubator-tvm] comaniac merged pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


comaniac merged pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige opened a new pull request #6860: [TIR] Add spans to all ExprNodes

2020-11-05 Thread GitBox


tkonolige opened a new pull request #6860:
URL: https://github.com/apache/incubator-tvm/pull/6860


   Add optional spanning information to BaseExprNode. This PR does not fill in 
this spanning information.
   
   @jroesch @junrushao1994 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] junrushao1994 opened a new pull request #6859: [Bugfix][Module] Fix recursive GetFunction in runtime::Module

2020-11-05 Thread GitBox


junrushao1994 opened a new pull request #6859:
URL: https://github.com/apache/incubator-tvm/pull/6859


   This PR fixes a bug that affects the behavior of `ModuleNode::GetFunction` 
when `query_import=True`
   
   CC: @jwfromm @tqchen @icemelon9 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige opened a new pull request #6858: [FIX,RPC] Skip RPC tests when using multiprocessing's spawn method

2020-11-05 Thread GitBox


tkonolige opened a new pull request #6858:
URL: https://github.com/apache/incubator-tvm/pull/6858


   The rpc tests are broken when running under pytest with multiprocessing 
using spawn. I suspect this is because pytest tests each function in a separate 
process and does not import the full module.
   
   @tqchen 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] branch main updated (b31f4ae -> d164aac)

2020-11-05 Thread tqchen
This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


from b31f4ae  [QNN] Dynamic scale, zero point in qnn.op.dequantize (#6849)
 add d164aac  [TVMSCRIPT] Using diagnostics for TVM Script (#6797)

No new revisions were added by this update.

Summary of changes:
 docker/install/ubuntu_install_python_package.sh|   2 +-
 python/setup.py|   2 +-
 python/tvm/script/context_maintainer.py|   4 +-
 python/tvm/script/diagnostics.py   |  54 ++
 python/tvm/script/meta_unparser.py |  31 +-
 python/tvm/script/parser.py| 979 +++--
 python/tvm/script/scope_handler.py |  20 +-
 python/tvm/script/special_stmt.py  |  18 +-
 .../python/unittest/test_tvmscript_error_report.py | 219 +++--
 tests/scripts/task_ci_python_setup.sh  |   2 +-
 10 files changed, 726 insertions(+), 605 deletions(-)
 create mode 100644 python/tvm/script/diagnostics.py



[GitHub] [incubator-tvm] tqchen commented on pull request #6797: [TVMSCRIPT] Using diagnostics for TVM Script

2020-11-05 Thread GitBox


tqchen commented on pull request #6797:
URL: https://github.com/apache/incubator-tvm/pull/6797#issuecomment-722723667


   Thansk @tkonolige @leandron @u99127 @jroesch @junrushao1994 @spectrometerHBH 
!



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tqchen merged pull request #6797: [TVMSCRIPT] Using diagnostics for TVM Script

2020-11-05 Thread GitBox


tqchen merged pull request #6797:
URL: https://github.com/apache/incubator-tvm/pull/6797


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] masahi commented on pull request #6849: [QNN] Dynamic scale, zero point in qnn.op.dequantize

2020-11-05 Thread GitBox


masahi commented on pull request #6849:
URL: https://github.com/apache/incubator-tvm/pull/6849#issuecomment-722722111


   thanks @electriclilies 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] masahi merged pull request #6849: [QNN] Dynamic scale, zero point in qnn.op.dequantize

2020-11-05 Thread GitBox


masahi merged pull request #6849:
URL: https://github.com/apache/incubator-tvm/pull/6849


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] branch main updated (9ea4bf5 -> b31f4ae)

2020-11-05 Thread masahi
This is an automated email from the ASF dual-hosted git repository.

masahi pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


from 9ea4bf5  [Relay][Frontend][Onnx] If Operator Support (#6730)
 add b31f4ae  [QNN] Dynamic scale, zero point in qnn.op.dequantize (#6849)

No new revisions were added by this update.

Summary of changes:
 python/tvm/relay/qnn/op/qnn.py   |  7 +++
 src/relay/qnn/op/dequantize.cc   | 23 +++
 tests/python/relay/test_op_qnn_dequantize.py | 28 
 tests/python/relay/test_op_qnn_quantize.py   | 28 
 4 files changed, 74 insertions(+), 12 deletions(-)



[GitHub] [incubator-tvm] masahi commented on pull request #6730: [Relay][Frontend][Onnx] If Operator Support

2020-11-05 Thread GitBox


masahi commented on pull request #6730:
URL: https://github.com/apache/incubator-tvm/pull/6730#issuecomment-722721307


   thanks @jwfromm @mbrookhart @tmoreau89 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] masahi merged pull request #6730: [Relay][Frontend][Onnx] If Operator Support

2020-11-05 Thread GitBox


masahi merged pull request #6730:
URL: https://github.com/apache/incubator-tvm/pull/6730


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] branch main updated (7ee91da -> 9ea4bf5)

2020-11-05 Thread masahi
This is an automated email from the ASF dual-hosted git repository.

masahi pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


from 7ee91da  [TOPI] Enable scatter_add on GPU  (#6856)
 add 9ea4bf5  [Relay][Frontend][Onnx] If Operator Support (#6730)

No new revisions were added by this update.

Summary of changes:
 python/tvm/relay/frontend/onnx.py  | 44 ++-
 tests/python/frontend/onnx/test_forward.py | 49 +-
 2 files changed, 91 insertions(+), 2 deletions(-)



[GitHub] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518445194



##
File path: python/tvm/relay/op/transform.py
##
@@ -308,28 +308,45 @@ def scatter_add(data, indices, updates, axis):
 return _make.scatter_add(data, indices, updates, axis)
 
 
-def reshape_like(data, shape_like):
-"""Reshapes the input array by the size of another array.
-For an input array with shape ``(d1, d2, ..., dk)``, `reshape_like` 
operation reshapes
-the input array into an output array with the same shape as the second 
input array.
+def reshape_like(data, shape_like, lhs_begin=0, lhs_end=None, rhs_begin=0, 
rhs_end=None):
+"""Reshapes the input tensor by the size of another tensor.

Review comment:
   added





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


tkonolige commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518431122



##
File path: python/tvm/relay/op/transform.py
##
@@ -308,28 +308,45 @@ def scatter_add(data, indices, updates, axis):
 return _make.scatter_add(data, indices, updates, axis)
 
 
-def reshape_like(data, shape_like):
-"""Reshapes the input array by the size of another array.
-For an input array with shape ``(d1, d2, ..., dk)``, `reshape_like` 
operation reshapes
-the input array into an output array with the same shape as the second 
input array.
+def reshape_like(data, shape_like, lhs_begin=0, lhs_end=None, rhs_begin=0, 
rhs_end=None):
+"""Reshapes the input tensor by the size of another tensor.

Review comment:
   Would it be possible to add an example to this?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige commented on pull request #6797: [TVMSCRIPT] Using diagnostics for TVM Script

2020-11-05 Thread GitBox


tkonolige commented on pull request #6797:
URL: https://github.com/apache/incubator-tvm/pull/6797#issuecomment-722699139


   @leandron Does this PR look good to you now? Or are there any other changes 
you would like?



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] jwfromm commented on pull request #6730: [Relay][Frontend][Onnx] If Operator Support

2020-11-05 Thread GitBox


jwfromm commented on pull request #6730:
URL: https://github.com/apache/incubator-tvm/pull/6730#issuecomment-722698486


   @masahi, I ended up removing onnxruntime from the if test for now. Since the 
correct result in this case is very clear, there's not much need to generate 
with onnxruntime. Once we update to a newer ort version I'll switch back.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige commented on pull request #6854: [RELAY,TOPI] Add scatter_nd op

2020-11-05 Thread GitBox


tkonolige commented on pull request #6854:
URL: https://github.com/apache/incubator-tvm/pull/6854#issuecomment-722665085


   @mbrookhart I'd like to work on the cuda implementation separately. I think 
there is a bit of work to do there.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] 03/23: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit cb3785680cb343eb295ea8e0585c87ca42db4323
Author: Jared Roesch 
AuthorDate: Tue Oct 13 11:04:37 2020 -0700

WIP
---
 rust/tvm/src/ir/diagnostics.rs | 78 --
 1 file changed, 37 insertions(+), 41 deletions(-)

diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
index e434d3f..d306185 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -24,7 +24,7 @@
 
 use tvm_macros::{Object, external};
 use super::module::IRModule;
-use crate::runtime::{function::{self, Function, ToFunction, Typed}, 
array::Array, string::String as TString};
+use crate::runtime::{function::{self, Function, ToFunction}, array::Array, 
string::String as TString};
 use crate::runtime::object::{Object, ObjectPtr, ObjectRef};
 use crate::runtime::function::Result;
 use super::span::Span;
@@ -121,42 +121,19 @@ pub struct DiagnosticBuilder {
 //* of compiler diagnostics to std::out and std::err in
 //* a human readable form.
 //*/
-//   class DiagnosticRendererNode : public Object {
-//public:
-// TypedPackedFunc renderer;
-
-// // override attr visitor
-// void VisitAttrs(AttrVisitor* v) {}
-
-// static constexpr const char* _type_key = "DiagnosticRenderer";
-// TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticRendererNode, Object);
-//   };
-
-//   class DiagnosticRenderer : public ObjectRef {
-//public:
-// TVM_DLL DiagnosticRenderer(TypedPackedFunc 
render);
-// TVM_DLL DiagnosticRenderer()
-// : DiagnosticRenderer(TypedPackedFunc()) {}
-
-// void Render(const DiagnosticContext& ctx);
-
-// DiagnosticRendererNode* operator->() {
-//   CHECK(get() != nullptr);
-//   return static_cast(get_mutable());
-// }
-
-// TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DiagnosticRenderer, 
ObjectRef, DiagnosticRendererNode);
-//   };
-
-// @tvm._ffi.register_object("DiagnosticRenderer")
-// class DiagnosticRenderer(Object):
-// """
-// A diagnostic renderer, which given a diagnostic context produces a 
"rendered"
-// form of the diagnostics for either human or computer consumption.
-// """
+#[repr(C)]
+#[derive(Object)]
+#[ref_name = "DiagnosticRenderer"]
+#[type_key = "DiagnosticRenderer"]
+/// A diagnostic renderer, which given a diagnostic context produces a 
"rendered"
+/// form of the diagnostics for either human or computer consumption.
+pub struct DiagnosticRendererNode {
+/// The base type.
+pub base: Object,
+// TODO(@jroesch): we can't easily exposed packed functions due to
+// memory layout
+}
 
-// def __init__(self, render_func):
-// self.__init_handle_by_constructor__(_ffi_api.DiagnosticRenderer, 
render_func)
 
 // def render(self, ctx):
 // """
@@ -168,7 +145,6 @@ pub struct DiagnosticBuilder {
 // The diagnostic context to render.
 // """
 // return _ffi_api.DiagnosticRendererRender(self, ctx
-pub type DiagnosticRenderer = ObjectRef;
 
 #[repr(C)]
 #[derive(Object)]
@@ -227,8 +203,7 @@ impl DiagnosticContext {
 }
 }
 
-// Sets a custom renderer for diagnostics.
-
+// Override the global diagnostics renderer.
 // Params
 // --
 // render_func: Option[Callable[[DiagnosticContext], None]]
@@ -263,6 +238,27 @@ pub mod codespan {
 use codespan_reporting::files::SimpleFiles;
 use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
 
+enum StartOrEnd {
+Start,
+End,
+}
+
+struct SpanToBytes {
+inner: HashMap {
+file_id: FileId,
+start_pos: usize,
+end_pos: usize,
+}
+
+// impl SpanToBytes {
+// fn to_byte_pos(, span: tvm::ir::Span) -> ByteRange {
+
+// }
+// }
+
 pub fn to_diagnostic(diag: super::Diagnostic) -> CDiagnostic {
 let severity = match diag.level {
 DiagnosticLevel::Error => Severity::Error,
@@ -290,9 +286,9 @@ pub mod codespan {
 let mut files: SimpleFiles = SimpleFiles::new();
 let render_fn = move |diag_ctx: DiagnosticContext| {
 // let source_map = diag_ctx.module.source_map;
-for diagnostic in diag_ctx.diagnostics {
+// for diagnostic in diag_ctx.diagnostics {
 
-}
+// }
 panic!("render_fn");
 };
 



[incubator-tvm] 04/23: Hacking on Rust inside of TVM

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 131e40afeb4bd89f0b378e0e7d8ad440d017d33a
Author: Jared Roesch 
AuthorDate: Tue Oct 13 15:25:56 2020 -0700

Hacking on Rust inside of TVM
---
 CMakeLists.txt |   1 +
 cmake/modules/RustExt.cmake|  13 +
 rust/Cargo.toml|   1 +
 rust/compiler-ext/Cargo.toml   |  13 +
 rust/compiler-ext/src/lib.rs   |   7 +
 rust/tvm/src/ir/source_map.rs  |   0
 rust/tvm/test.rly  |   2 +
 tests/python/relay/test_type_infer2.py | 419 +
 8 files changed, 456 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index abf2b56..9f82754 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,6 +79,7 @@ tvm_option(USE_ARM_COMPUTE_LIB "Build with Arm Compute 
Library" OFF)
 tvm_option(USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME "Build with Arm Compute Library 
graph runtime" OFF)
 tvm_option(USE_TENSORRT_CODEGEN "Build with TensorRT Codegen support" OFF)
 tvm_option(USE_TENSORRT_RUNTIME "Build with TensorRT runtime" OFF)
+tvm_option(USE_RUST_EXT "Build with Rust based compiler extensions" OFF)
 
 # include directories
 include_directories(${CMAKE_INCLUDE_PATH})
diff --git a/cmake/modules/RustExt.cmake b/cmake/modules/RustExt.cmake
new file mode 100644
index 000..45e46bd
--- /dev/null
+++ b/cmake/modules/RustExt.cmake
@@ -0,0 +1,13 @@
+if(USE_RUST_EXT)
+set(RUST_SRC_DIR "rust")
+set(CARGO_OUT_DIR "rust/target"
+set(COMPILER_EXT_PATH 
"${CARGO_OUT_DIR}/target/release/libcompiler_ext.dylib")
+
+add_custom_command(
+OUTPUT "${COMPILER_EXT_PATH}"
+COMMAND cargo build --release
+MAIN_DEPENDENCY "${RUST_SRC_DIR}"
+WORKING_DIRECTORY "${RUST_SRC_DIR}/compiler-ext")
+
+target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE)
+endif(USE_RUST_EXT)
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 28312a5..7c092d8 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -29,4 +29,5 @@ members = [
"tvm-graph-rt/tests/test_tvm_dso",
"tvm-graph-rt/tests/test_wasm32",
"tvm-graph-rt/tests/test_nn",
+   "compiler-ext",
 ]
diff --git a/rust/compiler-ext/Cargo.toml b/rust/compiler-ext/Cargo.toml
new file mode 100644
index 000..76d10eb
--- /dev/null
+++ b/rust/compiler-ext/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "compiler-ext"
+version = "0.1.0"
+authors = ["Jared Roesch "]
+edition = "2018"
+# TODO(@jroesch): would be cool to figure out how to statically link instead.
+
+[lib]
+crate-type = ["cdylib"]
+
+# See more keys and their definitions at 
https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
new file mode 100644
index 000..31e1bb2
--- /dev/null
+++ b/rust/compiler-ext/src/lib.rs
@@ -0,0 +1,7 @@
+#[cfg(test)]
+mod tests {
+#[test]
+fn it_works() {
+assert_eq!(2 + 2, 4);
+}
+}
diff --git a/rust/tvm/src/ir/source_map.rs b/rust/tvm/src/ir/source_map.rs
new file mode 100644
index 000..e69de29
diff --git a/rust/tvm/test.rly b/rust/tvm/test.rly
new file mode 100644
index 000..d8b7c69
--- /dev/null
+++ b/rust/tvm/test.rly
@@ -0,0 +1,2 @@
+#[version = "0.0.5"]
+fn @main(%x: int32) -> float32 { %x }
diff --git a/tests/python/relay/test_type_infer2.py 
b/tests/python/relay/test_type_infer2.py
new file mode 100644
index 000..6758d96
--- /dev/null
+++ b/tests/python/relay/test_type_infer2.py
@@ -0,0 +1,419 @@
+# 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.
+"""Test that type checker correcly computes types
+   for expressions.
+"""
+import pytest
+import tvm
+
+from tvm import IRModule, te, relay, parser
+from tvm.relay import op, transform, analysis
+from tvm.relay import Any
+
+
+def infer_mod(mod, annotate_spans=True):
+if annotate_spans:
+mod = relay.transform.AnnotateSpans()(mod)
+
+mod = transform.InferType()(mod)
+return mod
+
+
+def infer_expr(expr, annotate_spans=True):
+mod = IRModule.from_expr(expr)
+mod = infer_mod(mod, annotate_spans)
+   

[incubator-tvm] 12/23: Rust Diagnostics work

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 6e1346748e08255f220c3e6cf72c59a8a3f6ef29
Author: Jared Roesch 
AuthorDate: Fri Oct 16 14:17:01 2020 -0700

Rust Diagnostics work
---
 rust/tvm-rt/src/errors.rs   |  15 
 rust/tvm-rt/src/function.rs |   7 +-
 rust/tvm/src/bin/tyck.rs|  13 ++--
 rust/tvm/src/ir/diagnostics/codespan.rs | 126 ++--
 4 files changed, 117 insertions(+), 44 deletions(-)

diff --git a/rust/tvm-rt/src/errors.rs b/rust/tvm-rt/src/errors.rs
index c884c56..3de9f3c 100644
--- a/rust/tvm-rt/src/errors.rs
+++ b/rust/tvm-rt/src/errors.rs
@@ -68,6 +68,21 @@ pub enum Error {
 Infallible(#[from] std::convert::Infallible),
 #[error("a panic occurred while executing a Rust packed function")]
 Panic,
+#[error("one or more error diagnostics were emitted, please check 
diagnostic render for output.")]
+DiagnosticError(String),
+#[error("{0}")]
+Raw(String),
+}
+
+impl Error {
+pub fn from_raw_tvm(raw: ) -> Error {
+let err_header = raw.find(":").unwrap_or(0);
+let (err_ty, err_content) = raw.split_at(err_header);
+match err_ty {
+"DiagnosticError" => 
Error::DiagnosticError((_content[1..]).into()),
+_ => Error::Raw(raw.into()),
+}
+}
 }
 
 impl Error {
diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index c7aebdd..173b60a 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -133,7 +133,12 @@ impl Function {
 };
 
 if ret_code != 0 {
-return Err(Error::CallFailed(crate::get_last_error().into()));
+let raw_error = crate::get_last_error();
+let error = match Error::from_raw_tvm(raw_error) {
+Error::Raw(string) => Error::CallFailed(string),
+e => e,
+};
+return Err(error);
 }
 
 let rv = RetValue::from_tvm_value(ret_val, ret_type_code as u32);
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index fbab027..13470e7 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -4,7 +4,8 @@ use anyhow::Result;
 use structopt::StructOpt;
 
 use tvm::ir::diagnostics::codespan;
-use tvm::ir::IRModule;
+use tvm::ir::{self, IRModule};
+use tvm::runtime::Error;
 
 #[derive(Debug, StructOpt)]
 #[structopt(name = "tyck", about = "Parse and type check a Relay program.")]
@@ -18,11 +19,11 @@ fn main() -> Result<()> {
 codespan::init().expect("Rust based diagnostics");
 let opt = Opt::from_args();
 println!("{:?}", );
-let module = IRModule::parse_file(opt.input);
-
-// for (k, v) in module.functions {
-// println!("Function name: {:?}", v);
-// }
+let _module = match IRModule::parse_file(opt.input) {
+Err(ir::module::Error::TVM(Error::DiagnosticError(_))) => { return 
Ok(()) },
+Err(e) => { return Err(e.into()); },
+Ok(module) => module
+};
 
 Ok(())
 }
diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
index 80a8784..9fc1ee0 100644
--- a/rust/tvm/src/ir/diagnostics/codespan.rs
+++ b/rust/tvm/src/ir/diagnostics/codespan.rs
@@ -4,6 +4,7 @@ use std::sync::{Arc, Mutex};
 use codespan_reporting::diagnostic::{Diagnostic as CDiagnostic, Label, 
Severity};
 use codespan_reporting::files::SimpleFiles;
 use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
+use codespan_reporting::term::{self, ColorArg};
 
 use crate::ir::source_map::*;
 use super::*;
@@ -13,8 +14,14 @@ enum StartOrEnd {
 End,
 }
 
+struct ByteRange {
+file_id: FileId,
+start_pos: usize,
+end_pos: usize,
+}
+
 enum FileSpanToByteRange {
-AsciiSource,
+AsciiSource(Vec),
 Utf8 {
 /// Map character regions which are larger then 1-byte to length.
 lengths: HashMap,
@@ -27,7 +34,12 @@ impl FileSpanToByteRange {
 let mut last_index = 0;
 let mut is_ascii = true;
 if source.is_ascii() {
-FileSpanToByteRange::AsciiSource
+let line_lengths =
+source
+.lines()
+.map(|line| line.len())
+.collect();
+FileSpanToByteRange::AsciiSource(line_lengths)
 } else {
 panic!()
 }
@@ -41,6 +53,21 @@ impl FileSpanToByteRange {
 // last_index = index;
 // }
 }
+
+fn lookup(, span: ) -> ByteRange {
+use FileSpanToByteRange::*;
+
+let source_name: String = 
span.source_name.name.as_str().unwrap().into();
+
+match self {
+AsciiSource(ref line_lengths) => {
+let start_pos = (_lengths[0..(span.line - 1) as 
usize]).into_iter().sum::() + (span.column) as usize;
+

[incubator-tvm] 17/23: Fix some CR

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 8e295b79c2e693d7190751532824b463dc9373e5
Author: Jared Roesch 
AuthorDate: Mon Oct 19 19:52:20 2020 -0700

Fix some CR
---
 rust/tvm/src/ir/diagnostics/codespan.rs | 6 --
 rust/tvm/src/lib.rs | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
index 9a31691..54fd336 100644
--- a/rust/tvm/src/ir/diagnostics/codespan.rs
+++ b/rust/tvm/src/ir/diagnostics/codespan.rs
@@ -17,8 +17,10 @@
  * under the License.
  */
 
-/// A TVM diagnostics renderer which uses the Rust `codespan`
-/// library to produce error messages.
+/// A TVM diagnostics renderer which uses the Rust `codespan` library
+/// to produce error messages.
+///
+///
 use std::collections::HashMap;
 use std::sync::{Arc, Mutex};
 
diff --git a/rust/tvm/src/lib.rs b/rust/tvm/src/lib.rs
index ec80ece..7e0682b 100644
--- a/rust/tvm/src/lib.rs
+++ b/rust/tvm/src/lib.rs
@@ -24,7 +24,7 @@
 //! One particular use case is that given optimized deep learning model 
artifacts,
 //! (compiled with TVM) which include a shared library
 //! `lib.so`, `graph.json` and a byte-array `param.params`, one can load them
-//! in Rust idomatically to create a TVM Graph Runtime and
+//! in Rust idiomatically to create a TVM Graph Runtime and
 //! run the model for some inputs and get the
 //! desired predictions *all in Rust*.
 //!
@@ -53,7 +53,7 @@ macro_rules! export {
 ($($fn_name:expr),*) => {
 pub fn tvm_export(ns: ) -> Result<(), tvm::Error> {
 $(
-let name = String::from(ns) + ::std::stringify!($fn_name);
+let name = String::fromwe(ns) + ::std::stringify!($fn_name);
 tvm::runtime::function::register_override($fn_name, name, 
true)?;
 )*
 Ok(())



[incubator-tvm] 22/23: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit e8bb83d33e7ad44ff16c72d9de61c2de722d12a8
Author: Jared Roesch 
AuthorDate: Thu Oct 29 15:31:05 2020 -0700

WIP
---
 rust/tvm/src/python.rs | 34 ++
 1 file changed, 6 insertions(+), 28 deletions(-)

diff --git a/rust/tvm/src/python.rs b/rust/tvm/src/python.rs
index 2b2d374..50ce7b0 100644
--- a/rust/tvm/src/python.rs
+++ b/rust/tvm/src/python.rs
@@ -20,20 +20,6 @@
 use pyo3::prelude::*;
 use once_cell::sync::OnceCell;
 
-// static TVM_PYTHON: OnceCell> = OnceCell::new();
-
-// fn initialize() -> Py {
-// TVM_PYTHON.get_or_init(|| {
-// let gil = Python::acquire_gil();
-// let py = gil.python();
-// PyModule::new(py, "__tvm__rust__module__").map_err(|e| {
-// // We can't display Python exceptions via std::fmt::Display,
-// // so print the error here manually.
-// e.print_and_set_sys_last_vars(py);
-// }).expect("failed to initialize the Python interface").into()
-// }).clone()
-// }
-
 /// Load the Python interpreter into the address space.
 ///
 /// This enables the ability for Rust code to call TVM
@@ -53,27 +39,19 @@ pub fn load() -> Result {
 })
 }
 
-fn import_python<'p, 'b: 'p>(py: Python<'p>, to_import: &'b str) -> 
PyResult<&'p PyModule> {
-let imported_mod = py.import(to_import)?;
-PyModule::from_code(py,
-r#"
-import tvm
-from tvm import relay
-tvm.cleanup()
-"#, "blah", "my_mod")?;
-// py_mod.add(to_import, imported_mod)?;
-Ok(imported_mod)
-}
-
 pub fn import(mod_to_import: ) -> PyResult<()> {
 let gil = Python::acquire_gil();
 let py = gil.python();
-// let main_mod = initialize();
-// let main_mod = main_mod.as_ref(py);
 import_python(py, mod_to_import)?;
 Ok(())
 }
 
+fn import_python<'p, 'b: 'p>(py: Python<'p>, to_import: &'b str) -> 
PyResult<&'p PyModule> {
+let imported_mod = py.import(to_import)?;
+Ok(imported_mod)
+}
+
+
 fn load_python_tvm_(py: Python) -> PyResult {
 let imported_mod = import_python(py, "tvm")?;
 let version: String = imported_mod.get("__version__")?.extract()?;



[incubator-tvm] 18/23: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 49246bff342eb59757cecc34a9a9465a2e3c063d
Author: Jared Roesch 
AuthorDate: Wed Oct 21 14:09:37 2020 -0700

WIP
---
 rust/tvm-macros/src/external.rs |  5 ++-
 rust/tvm-macros/src/lib.rs  |  1 +
 rust/tvm/src/ir/module.rs   | 67 +
 3 files changed, 26 insertions(+), 47 deletions(-)

diff --git a/rust/tvm-macros/src/external.rs b/rust/tvm-macros/src/external.rs
index 802d7ae..de8ada3 100644
--- a/rust/tvm-macros/src/external.rs
+++ b/rust/tvm-macros/src/external.rs
@@ -17,6 +17,7 @@
  * under the License.
  */
 use proc_macro2::Span;
+use proc_macro_error::abort;
 use quote::quote;
 use syn::parse::{Parse, ParseStream, Result};
 
@@ -109,7 +110,9 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 .iter()
 .map(|ty_param| match ty_param {
 syn::GenericParam::Type(param) => param.clone(),
-_ => panic!(),
+_ => abort! { ty_param,
+"Only supports type parameters."
+}
 })
 .collect();
 
diff --git a/rust/tvm-macros/src/lib.rs b/rust/tvm-macros/src/lib.rs
index 603e1ce..ab75c92 100644
--- a/rust/tvm-macros/src/lib.rs
+++ b/rust/tvm-macros/src/lib.rs
@@ -35,6 +35,7 @@ pub fn macro_impl(input: TokenStream) -> TokenStream {
 TokenStream::from(object::macro_impl(input))
 }
 
+#[proc_macro_error]
 #[proc_macro]
 pub fn external(input: TokenStream) -> TokenStream {
 external::macro_impl(input)
diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index 443915f..8918bdc 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -63,6 +63,8 @@ external! {
 #[name("parser.ParseExpr")]
 fn parse_expression(file_name: TVMString, source: TVMString) -> IRModule;
 // Module methods
+#[name("ir.Module_Add")]
+fn module_add_def(module: IRModule, type_name: GlobalVar, expr: 
relay::Expr, update: bool) -> ();
 #[name("ir.Module_AddDef")]
 fn module_add_def(module: IRModule, type_name: GlobalTypeVar, type_data: 
TypeData, update: bool) -> ();
 #[name("ir.Module_GetGlobalVar")]
@@ -73,55 +75,28 @@ external! {
 fn module_lookup(module: IRModule, var: GlobalVar) -> BaseFunc;
 #[name("ir.Module_Lookup_str")]
 fn module_lookup_str(module: IRModule, name: TVMString) -> BaseFunc;
+#[name("ir.Module_GetGlobalTypeVars")]
+fn module_get_global_type_vars() -> Array;
+#[name("ir.Module_ContainGlobalVar")]
+fn module_get_global_var(name: TVMString) -> bool;
+#[name("ir.Module_ContainGlobalTypeVar")]
+fn module_get_global_type_var(name: TVMString) -> bool;
+#[name("ir.Module_LookupDef")]
+fn module_lookup_def(module: IRModule, global: GlobalTypeVar) -> TypeDef;
+#[name("ir.Module_LookupDef_str")]
+fn module_lookup_def_str(module: IRModule, global: GlobalTypeVar) -> 
TypeDef;
+#[name("ir.Module_LookupTag")]
+fn module_lookup_tag(module: IRModule, tag: i32) -> Constructor;
+#[name("ir.Module_FromExpr")]
+fn module_from_expr(expr: relay::Expr, funcs: Map, 
types: Map) -> IRModule;
+#[name("ir.Module_Import")]
+fn module_import(module: IRModule, path: TVMString);
+#[name("ir.Module_ImportFromStd")]
+fn module_import_from_std(module: IRModule, path: TVMString);
 }
 
-// TVM_REGISTER_GLOBAL("ir.Module_GetGlobalTypeVars")
-// .set_body_method(::GetGlobalTypeVars);
+// Note: we don't expose update here as update is going to be removed.
 
-// TVM_REGISTER_GLOBAL("ir.Module_ContainGlobalVar")
-// .set_body_method(::ContainGlobalVar);
-
-// TVM_REGISTER_GLOBAL("ir.Module_GetGlobalTypeVar")
-// .set_body_method(::GetGlobalTypeVar);
-
-// TVM_REGISTER_GLOBAL("ir.Module_LookupDef").set_body_typed([](IRModule mod, 
GlobalTypeVar var) {
-//   return mod->LookupTypeDef(var);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_LookupDef_str").set_body_typed([](IRModule 
mod, String var) {
-//   return mod->LookupTypeDef(var);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_LookupTag").set_body_typed([](IRModule mod, 
int32_t tag) {
-//   return mod->LookupTag(tag);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_FromExpr")
-// .set_body_typed([](RelayExpr e, tvm::Map funcs,
-//tvm::Map type_defs) {
-//   return IRModule::FromExpr(e, funcs, type_defs);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_Update").set_body_typed([](IRModule mod, 
IRModule from) {
-//   mod->Update(from);
-// });
-
-// TVM_REGISTER_GLOBAL("ir.Module_UpdateFunction")
-// .set_body_typed([](IRModule mod, GlobalVar gv, BaseFunc func) { 
mod->Update(gv, func); });
-
-// TVM_REGISTER_GLOBAL("ir.Module_Import").set_body_typed([](IRModule mod, 
String path) {
-//   mod->Import(path);
-// });
-
-// 

[incubator-tvm] 19/23: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit a9ee3cb34c020a4debe75fc9a194303f22d00892
Author: Jared Roesch 
AuthorDate: Thu Oct 22 11:48:34 2020 -0700

WIP
---
 rust/tvm-macros/Cargo.toml  |  2 +-
 rust/tvm-macros/src/external.rs | 43 +
 rust/tvm-macros/src/lib.rs  |  1 +
 rust/tvm-rt/src/object/mod.rs   |  2 +-
 rust/tvm/src/ir/module.rs   | 16 +++
 5 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/rust/tvm-macros/Cargo.toml b/rust/tvm-macros/Cargo.toml
index 63b8472..8e97d3b 100644
--- a/rust/tvm-macros/Cargo.toml
+++ b/rust/tvm-macros/Cargo.toml
@@ -33,5 +33,5 @@ proc-macro = true
 goblin = "^0.2"
 proc-macro2 = "^1.0"
 quote = "^1.0"
-syn = { version = "1.0.17", features = ["full", "extra-traits"] }
+syn = { version = "^1.0", features = ["full", "parsing", "extra-traits"] }
 proc-macro-error = "^1.0"
diff --git a/rust/tvm-macros/src/external.rs b/rust/tvm-macros/src/external.rs
index de8ada3..44a242c 100644
--- a/rust/tvm-macros/src/external.rs
+++ b/rust/tvm-macros/src/external.rs
@@ -21,9 +21,28 @@ use proc_macro_error::abort;
 use quote::quote;
 use syn::parse::{Parse, ParseStream, Result};
 
-use syn::{FnArg, Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, 
TraitItemMethod, Type};
+use syn::{Token, FnArg, Signature, Attribute, token::Semi, Visibility, 
Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
+
+struct ExternalItem {
+attrs: Vec,
+visibility: Visibility,
+sig: Signature,
+}
+
+impl Parse for ExternalItem {
+fn parse(input: ParseStream) -> Result {
+let item = ExternalItem {
+attrs: input.call(Attribute::parse_outer)?,
+visibility: input.parse()?,
+sig: input.parse()?,
+};
+let _semi: Semi = input.parse()?;
+Ok(item)
+}
+}
 
 struct External {
+visibility: Visibility,
 tvm_name: String,
 ident: Ident,
 generics: Generics,
@@ -33,7 +52,8 @@ struct External {
 
 impl Parse for External {
 fn parse(input: ParseStream) -> Result {
-let method: TraitItemMethod = input.parse()?;
+let method: ExternalItem = input.parse()?;
+let visibility = method.visibility;
 assert_eq!(method.attrs.len(), 1);
 let sig = method.sig;
 let tvm_name = method.attrs[0].parse_meta()?;
@@ -48,8 +68,7 @@ impl Parse for External {
 }
 _ => panic!(),
 };
-assert_eq!(method.default, None);
-assert!(method.semi_token != None);
+
 let ident = sig.ident;
 let generics = sig.generics;
 let inputs = sig
@@ -61,6 +80,7 @@ impl Parse for External {
 let ret_type = sig.output;
 
 Ok(External {
+visibility,
 tvm_name,
 ident,
 generics,
@@ -99,6 +119,7 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 let mut items = Vec::new();
 
 for external in _input.externs {
+let visibility = 
 let name = 
 let global_name = format!("global_{}", external.ident);
 let global_name = Ident::new(_name, Span::call_site());
@@ -127,15 +148,21 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 let ty: Type = *pat_type.ty.clone();
 (ident, ty)
 }
-_ => panic!(),
+_ =>  abort! { pat_type,
+"Only supports type parameters."
+}
 },
-_ => panic!(),
+pat => abort! {
+pat, "invalid pattern type for function";
+
+note = "{:?} is not allowed here", pat;
+}
 })
 .unzip();
 
 let ret_type = match _type {
 ReturnType::Type(_, rtype) => *rtype.clone(),
-_ => panic!(),
+ReturnType::Default => syn::parse_str::("()").unwrap(),
 };
 
 let global = quote! {
@@ -150,7 +177,7 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
proc_macro::TokenStream {
 items.push(global);
 
 let wrapper = quote! {
-pub fn #name<#(#ty_params),*>(#(#args : #tys),*) -> 
#result_type<#ret_type> {
+#visibility fn #name<#(#ty_params),*>(#(#args : #tys),*) -> 
#result_type<#ret_type> {
 let func_ref: #tvm_rt_crate::Function = #global_name.clone();
 let func_ref: Box 
#result_type<#ret_type>> = func_ref.into();
 let res: #ret_type = func_ref(#(#args),*)?;
diff --git a/rust/tvm-macros/src/lib.rs b/rust/tvm-macros/src/lib.rs
index ab75c92..32f2839 100644
--- a/rust/tvm-macros/src/lib.rs
+++ 

[incubator-tvm] 08/23: Clean up exporting to show off new diagnostics

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 20c6a28606c053fbf9adf1c36c85fd608e63e024
Author: Jared Roesch 
AuthorDate: Thu Oct 15 17:03:00 2020 -0700

Clean up exporting to show off new diagnostics
---
 rust/compiler-ext/src/lib.rs   | 12 ++--
 rust/tvm-rt/src/array.rs   | 32 
 rust/tvm/src/bin/tyck.rs   |  7 ++-
 rust/tvm/src/ir/diagnostics.rs | 10 +-
 rust/tvm/src/ir/mod.rs |  1 +
 rust/tvm/src/ir/module.rs  |  3 +++
 rust/tvm/src/ir/source_map.rs  | 26 +++---
 rust/tvm/src/lib.rs| 24 
 8 files changed, 96 insertions(+), 19 deletions(-)

diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 3e37d21..c136d06 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -22,14 +22,22 @@ use tvm;
 use tvm::runtime::function::register_override;
 
 fn test_fn() -> Result<(), tvm::Error> {
-println!("Hello from Rust!");
+println!("Hello Greg from Rust!");
 Ok(())
 }
 
+fn test_fn2(message: tvm::runtime::string::String) -> Result<(), tvm::Error> {
+println!("The message: {}", message);
+Ok(())
+}
+
+tvm::export!(test_fn, test_fn2);
+
 #[no_mangle]
 fn compiler_ext_initialize() -> i32 {
 let _ = env_logger::try_init();
-register_override(test_fn, "rust_ext.test_fn", true).expect("failed to 
initialize simplifier");
+tvm_export("rust_ext")
+.expect("failed to initialize Rust compiler_ext");
 log::debug!("done!");
 return 0;
 }
diff --git a/rust/tvm-rt/src/array.rs b/rust/tvm-rt/src/array.rs
index 5e19cef..032ca79 100644
--- a/rust/tvm-rt/src/array.rs
+++ b/rust/tvm-rt/src/array.rs
@@ -19,6 +19,7 @@
 
 use std::convert::{TryFrom, TryInto};
 use std::marker::PhantomData;
+use std::iter::{IntoIterator, Iterator};
 
 use crate::errors::Error;
 use crate::object::{IsObjectRef, Object, ObjectPtr, ObjectRef};
@@ -81,6 +82,37 @@ impl Array {
 }
 }
 
+pub struct IntoIter {
+array: Array,
+pos: isize,
+size: isize,
+}
+
+impl Iterator for IntoIter {
+type Item = T;
+
+fn next( self) -> Option {
+if self.pos < self.size {
+let item = self.array.get(self.pos)
+.expect("should not fail");
+self.pos += 1;
+Some(item)
+} else {
+None
+}
+}
+}
+
+impl IntoIterator for Array {
+type Item = T;
+type IntoIter = IntoIter;
+
+fn into_iter(self) -> Self::IntoIter {
+let size = self.len() as isize;
+IntoIter { array: self, pos: 0, size: size }
+}
+}
+
 impl From> for ArgValue<'static> {
 fn from(array: Array) -> ArgValue<'static> {
 array.object.into()
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index b869012..e0c7136 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -18,6 +18,11 @@ fn main() -> Result<()> {
 codespan::init().expect("Rust based diagnostics");
 let opt = Opt::from_args();
 println!("{:?}", );
-let file = IRModule::parse_file(opt.input)?;
+let module = IRModule::parse_file(opt.input)?;
+
+// for (k, v) in module.functions {
+// println!("Function name: {:?}", v);
+// }
+
 Ok(())
 }
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
index b76e43f..4975a45 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -135,6 +135,7 @@ pub struct DiagnosticRendererNode {
 pub base: Object,
 // TODO(@jroesch): we can't easily exposed packed functions due to
 // memory layout
+// missing field here
 }
 
 // def render(self, ctx):
@@ -283,11 +284,10 @@ pub mod codespan {
 pub fn init() -> Result<()> {
 let mut files: SimpleFiles = SimpleFiles::new();
 let render_fn = move |diag_ctx: DiagnosticContext| {
-// let source_map = diag_ctx.module.source_map;
-// for diagnostic in diag_ctx.diagnostics {
-
-// }
-panic!("render_fn");
+let source_map = diag_ctx.module.source_map.clone();
+for diagnostic in diag_ctx.diagnostics.clone() {
+println!("Diagnostic: {}", diagnostic.message);
+}
 };
 
 override_renderer(Some(render_fn))?;
diff --git a/rust/tvm/src/ir/mod.rs b/rust/tvm/src/ir/mod.rs
index 401b6c2..df9bc68 100644
--- a/rust/tvm/src/ir/mod.rs
+++ b/rust/tvm/src/ir/mod.rs
@@ -26,6 +26,7 @@ pub mod module;
 pub mod op;
 pub mod relay;
 pub mod span;
+pub mod source_map;
 pub mod tir;
 pub mod ty;
 
diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index e0444b3..5156e74 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -25,6 +25,7 @@ use crate::runtime::{external, Object, ObjectRef};
 
 use 

[incubator-tvm] 10/23: Fix calling

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit eeb86c63d693288f8d406aed6b1b0df6d28e4b07
Author: Jared Roesch 
AuthorDate: Thu Oct 15 21:37:34 2020 -0700

Fix calling
---
 rust/tvm-rt/src/function.rs| 28 +---
 rust/tvm/src/bin/tyck.rs   |  2 +-
 rust/tvm/src/ir/diagnostics/mod.rs |  4 +---
 3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index bae06e9..c7aebdd 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -33,6 +33,7 @@ use std::{
 };
 
 use crate::errors::Error;
+use crate::object::ObjectPtr;
 
 pub use super::to_function::{ToFunction, Typed};
 pub use tvm_sys::{ffi, ArgValue, RetValue};
@@ -120,21 +121,26 @@ impl Function {
 let mut ret_val = ffi::TVMValue { v_int64: 0 };
 let mut ret_type_code = 0i32;
 
-check_call!(ffi::TVMFuncCall(
-self.handle,
-values.as_mut_ptr() as *mut ffi::TVMValue,
-type_codes.as_mut_ptr() as *mut c_int,
-num_args as c_int,
- ret_val as *mut _,
- ret_type_code as *mut _
-));
+let ret_code = unsafe {
+ffi::TVMFuncCall(
+self.handle,
+values.as_mut_ptr() as *mut ffi::TVMValue,
+type_codes.as_mut_ptr() as *mut c_int,
+num_args as c_int,
+ ret_val as *mut _,
+ ret_type_code as *mut _
+)
+};
+
+if ret_code != 0 {
+return Err(Error::CallFailed(crate::get_last_error().into()));
+}
 
 let rv = RetValue::from_tvm_value(ret_val, ret_type_code as u32);
 match rv {
 RetValue::ObjectHandle(object) => {
-let optr = crate::object::ObjectPtr::from_raw(object as 
_).unwrap();
-// println!("after wrapped call: {}", optr.count());
-crate::object::ObjectPtr::leak(optr);
+let optr = ObjectPtr::from_raw(object as _).unwrap();
+ObjectPtr::leak(optr);
 }
 _ => {}
 };
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index e0c7136..fbab027 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -18,7 +18,7 @@ fn main() -> Result<()> {
 codespan::init().expect("Rust based diagnostics");
 let opt = Opt::from_args();
 println!("{:?}", );
-let module = IRModule::parse_file(opt.input)?;
+let module = IRModule::parse_file(opt.input);
 
 // for (k, v) in module.functions {
 // println!("Function name: {:?}", v);
diff --git a/rust/tvm/src/ir/diagnostics/mod.rs 
b/rust/tvm/src/ir/diagnostics/mod.rs
index fce214a..039d1ed 100644
--- a/rust/tvm/src/ir/diagnostics/mod.rs
+++ b/rust/tvm/src/ir/diagnostics/mod.rs
@@ -207,9 +207,7 @@ impl DiagnosticContext {
 }
 }
 
-// Override the global diagnostics renderer.
-// Params
-// --
+/// Override the global diagnostics renderer.
 // render_func: Option[Callable[[DiagnosticContext], None]]
 // If the render_func is None it will remove the current custom renderer
 // and return to default behavior.



[incubator-tvm] 11/23: Fix

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 4261461974f2fb548d6b48e19fab07d34dd03a51
Author: Jared Roesch 
AuthorDate: Fri Oct 16 02:11:53 2020 -0700

Fix
---
 rust/tvm/src/ir/module.rs | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index 5156e74..11d6c49 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -16,6 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+use std::io::Result as IOResult;
+use std::path::Path;
+
+use thiserror::Error;
+use tvm_macros::Object;
 
 use crate::runtime::array::Array;
 use crate::runtime::function::Result;
@@ -27,15 +32,19 @@ use super::expr::GlobalVar;
 use super::function::BaseFunc;
 use super::source_map::SourceMap;
 
-use std::io::Result as IOResult;
-use std::path::Path;
-
-use tvm_macros::Object;
 
 // TODO(@jroesch): define type
 type TypeData = ObjectRef;
 type GlobalTypeVar = ObjectRef;
 
+#[derive(Error, Debug)]
+pub enum Error {
+#[error("{0}")]
+IO(#[from] std::io::Error),
+#[error("{0}")]
+TVM(#[from] crate::runtime::Error),
+}
+
 #[repr(C)]
 #[derive(Object)]
 #[ref_name = "IRModule"]
@@ -116,19 +125,19 @@ external! {
 // });
 
 impl IRModule {
-pub fn parse(file_name: N, source: S) -> IRModule
+pub fn parse(file_name: N, source: S) -> Result
 where
 N: Into,
 S: Into,
 {
-parse_module(file_name.into(), source.into()).expect("failed to call 
parser")
+parse_module(file_name.into(), source.into())
 }
 
-pub fn parse_file>(file_path: P) -> 
IOResult {
+pub fn parse_file>(file_path: P) -> 
std::result::Result {
 let file_path = file_path.as_ref();
 let file_path_as_str = file_path.to_str().unwrap().to_string();
 let source = std::fs::read_to_string(file_path)?;
-let module = IRModule::parse(file_path_as_str, source);
+let module = IRModule::parse(file_path_as_str, source)?;
 Ok(module)
 }
 



[incubator-tvm] 07/23: Fix Linux build

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit e0f980142c3c0ab795de316943079a651743d8d7
Author: Jared Roesch 
AuthorDate: Thu Oct 15 01:42:14 2020 -0700

Fix Linux build
---
 cmake/modules/LLVM.cmake | 7 ++-
 rust/tvm-sys/Cargo.toml  | 2 +-
 rust/tvm-sys/build.rs| 3 +--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/cmake/modules/LLVM.cmake b/cmake/modules/LLVM.cmake
index 5f8ace1..ca4ecd6 100644
--- a/cmake/modules/LLVM.cmake
+++ b/cmake/modules/LLVM.cmake
@@ -16,7 +16,12 @@
 # under the License.
 
 # LLVM rules
-add_definitions(-DDMLC_USE_FOPEN64=0)
+# Due to LLVM debug symbols you can sometimes face linking issues on
+# certain compiler, platform combinations if you don't set NDEBUG.
+#
+# See https://github.com/imageworks/OpenShadingLanguage/issues/1069
+# for more discussion.
+add_definitions(-DDMLC_USE_FOPEN64=0 -DNDEBUG=1)
 
 # Test if ${USE_LLVM} is not an explicit boolean false
 # It may be a boolean or a string
diff --git a/rust/tvm-sys/Cargo.toml b/rust/tvm-sys/Cargo.toml
index c25a5bf..2952aa4 100644
--- a/rust/tvm-sys/Cargo.toml
+++ b/rust/tvm-sys/Cargo.toml
@@ -23,7 +23,7 @@ license = "Apache-2.0"
 edition = "2018"
 
 [features]
-default = ["bindings"]
+default = []
 bindings = []
 
 [dependencies]
diff --git a/rust/tvm-sys/build.rs b/rust/tvm-sys/build.rs
index 2d86c4b..1590234 100644
--- a/rust/tvm-sys/build.rs
+++ b/rust/tvm-sys/build.rs
@@ -60,8 +60,7 @@ fn main() -> Result<()> {
 if cfg!(feature = "bindings") {
 println!("cargo:rerun-if-env-changed=TVM_HOME");
 println!("cargo:rustc-link-lib=dylib=tvm");
-println!("cargo:rustc-link-lib=dylib=llvm-10");
-println!("cargo:rustc-link-search={}/build", tvm_home);
+println!("cargo:rustc-link-search=native={}/build", tvm_home);
 }
 
 // @see rust-bindgen#550 for `blacklist_type`



[incubator-tvm] 02/23: Codespan example almost working

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 77ba30993a7883c142b05e511e8a5a7a91116b2f
Author: Jared Roesch 
AuthorDate: Fri Oct 9 23:59:51 2020 -0700

Codespan example almost working
---
 rust/tvm-sys/src/packed_func.rs  |   1 +
 rust/tvm/Cargo.toml  |   2 +
 rust/tvm/src/bin/tyck.rs |  24 
 rust/tvm/src/ir/diagnostics.rs   | 121 +--
 rust/tvm/src/ir/relay/visitor.rs |  24 
 5 files changed, 143 insertions(+), 29 deletions(-)

diff --git a/rust/tvm-sys/src/packed_func.rs b/rust/tvm-sys/src/packed_func.rs
index f7b289c..7b8d529 100644
--- a/rust/tvm-sys/src/packed_func.rs
+++ b/rust/tvm-sys/src/packed_func.rs
@@ -101,6 +101,7 @@ macro_rules! TVMPODValue {
 TVMArgTypeCode_kTVMOpaqueHandle => 
Handle($value.v_handle),
 TVMArgTypeCode_kTVMDLTensorHandle => 
ArrayHandle($value.v_handle as TVMArrayHandle),
 TVMArgTypeCode_kTVMObjectHandle => 
ObjectHandle($value.v_handle),
+TVMArgTypeCode_kTVMObjectRValueRefArg => 
ObjectHandle(*($value.v_handle as *mut *mut c_void)),
 TVMArgTypeCode_kTVMModuleHandle => 
ModuleHandle($value.v_handle),
 TVMArgTypeCode_kTVMPackedFuncHandle => 
FuncHandle($value.v_handle),
 TVMArgTypeCode_kTVMNDArrayHandle => 
NDArrayHandle($value.v_handle),
diff --git a/rust/tvm/Cargo.toml b/rust/tvm/Cargo.toml
index 55fc179..71a4b93 100644
--- a/rust/tvm/Cargo.toml
+++ b/rust/tvm/Cargo.toml
@@ -41,6 +41,8 @@ paste = "0.1"
 mashup = "0.1"
 once_cell = "^1.3.1"
 pyo3 = { version = "0.11.1", optional = true }
+codespan-reporting = "0.9.5"
+structopt = { version = "0.3" }
 
 [features]
 default = ["python"]
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
new file mode 100644
index 000..9300412
--- /dev/null
+++ b/rust/tvm/src/bin/tyck.rs
@@ -0,0 +1,24 @@
+use std::path::PathBuf;
+
+use anyhow::Result;
+use structopt::StructOpt;
+
+use tvm::ir::diagnostics::codespan;
+use tvm::ir::IRModule;
+
+
+#[derive(Debug, StructOpt)]
+#[structopt(name = "tyck", about = "Parse and type check a Relay program.")]
+struct Opt {
+/// Input file
+#[structopt(parse(from_os_str))]
+input: PathBuf,
+}
+
+fn main() -> Result<()> {
+codespan::init().expect("Rust based diagnostics");
+let opt = Opt::from_args();
+println!("{:?}", );
+let file = IRModule::parse_file(opt.input)?;
+Ok(())
+}
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
index 799a10c..e434d3f 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -24,13 +24,31 @@
 
 use tvm_macros::{Object, external};
 use super::module::IRModule;
-use crate::runtime::{function::{Function, Typed}, array::Array, string::String 
as TString};
-use crate::runtime::object::{Object, ObjectRef};
+use crate::runtime::{function::{self, Function, ToFunction, Typed}, 
array::Array, string::String as TString};
+use crate::runtime::object::{Object, ObjectPtr, ObjectRef};
 use crate::runtime::function::Result;
 use super::span::Span;
 
 type SourceName = ObjectRef;
 
+// Get the the diagnostic renderer.
+external! {
+#[name("node.ArrayGetItem")]
+fn get_renderer() -> DiagnosticRenderer;
+
+#[name("diagnostics.DiagnosticRenderer")]
+fn diagnostic_renderer(func: Function) -> DiagnosticRenderer;
+
+#[name("diagnostics.Emit")]
+fn emit(ctx: DiagnosticContext, diagnostic: Diagnostic) -> ();
+
+#[name("diagnostics.DiagnosticContextRender")]
+fn diagnostic_context_render(ctx: DiagnosticContext) -> ();
+
+#[name("diagnostics.ClearRenderer")]
+fn clear_renderer() -> ();
+}
+
 /// The diagnostic level, controls the printing of the message.
 #[repr(C)]
 pub enum DiagnosticLevel {
@@ -171,26 +189,20 @@ pub struct DiagnosticContextNode {
 pub renderer: DiagnosticRenderer,
 }
 
-// Get the the diagnostic renderer.
-external! {
-#[name("node.ArrayGetItem")]
-fn get_renderer() -> DiagnosticRenderer;
-
-#[name("diagnostics.DiagnosticRenderer")]
-fn diagnostic_renderer(func: Function) -> DiagnosticRenderer;
-
-#[name("diagnostics.Emit")]
-fn emit(ctx: DiagnosticContext, diagnostic: Diagnostic) -> ();
-
-#[name("diagnostics.DiagnosticContextRender")]
-fn diagnostic_context_render(ctx: DiagnosticContext) -> ();
-}
-
 /// A diagnostic context which records active errors
 /// and contains a renderer.
 impl DiagnosticContext {
-pub fn new(module: IRModule, renderer: DiagnosticRenderer) {
-todo!()
+pub fn new(module: IRModule, render_func: F) -> DiagnosticContext
+where F: Fn(DiagnosticContext) -> () + 'static
+{
+let renderer = diagnostic_renderer(render_func.to_function()).unwrap();
+let node = 

[incubator-tvm] 05/23: Borrow code from Egg

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit b2b59c229e9b8c2002d8c8cd520748df6b38e074
Author: Jared Roesch 
AuthorDate: Tue Oct 13 15:26:54 2020 -0700

Borrow code from Egg
---
 rust/compiler-ext/src/lib.rs | 344 ++-
 1 file changed, 337 insertions(+), 7 deletions(-)

diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 31e1bb2..58bdd0c 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -1,7 +1,337 @@
-#[cfg(test)]
-mod tests {
-#[test]
-fn it_works() {
-assert_eq!(2 + 2, 4);
-}
-}
+/*
+ * 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.
+ */
+
+ use std::os::raw::c_int;
+ use tvm::initialize;
+ use tvm::ir::{tir, PrimExpr};
+ use tvm::runtime::function::register_override;
+ use tvm::runtime::map::Map;
+ use tvm::runtime::object::{IsObject, IsObjectRef};
+ 
+ use ordered_float::NotNan;
+ 
+ mod interval;
+ mod math;
+ 
+ use math::{BoundsMap, Expr, RecExpr};
+ use tvm::ir::arith::ConstIntBound;
+ use tvm_rt::{ObjectRef, array::Array};
+ 
+ macro_rules! downcast_match {
+ ($id:ident; { $($t:ty => $arm:expr $(,)? )+ , else => $default:expr }) => 
{
+ $( if let Ok($id) = $id.downcast_clone::<$t>() { $arm } else )+
+ { $default }
+ }
+ }
+ 
+ #[derive(Default)]
+ struct VarMap {
+ vars: Vec<(tvm::ir::tir::Var, egg::Symbol)>,
+ objs: Vec,
+ }
+ 
+ impl VarMap {
+ // FIXME this should eventually do the right thing for TVM variables
+ // right now it depends on them having unique names
+ fn make_symbol( self, var: tvm::ir::tir::Var) -> egg::Symbol {
+ let sym = egg::Symbol::from(var.name_hint.as_str().unwrap());
+ for (_, sym2) in  {
+ if sym == *sym2 {
+ return sym;
+ }
+ }
+ 
+ self.vars.push((var, sym));
+ sym
+ }
+ 
+ fn get_symbol(, sym: egg::Symbol) -> tvm::ir::tir::Var {
+ for (v, sym2) in  {
+ if sym == *sym2 {
+ return v.clone();
+ }
+ }
+ panic!("Should have found a var")
+ }
+ 
+ fn push_obj( self, obj: impl IsObjectRef) -> usize {
+ let i = self.objs.len();
+ self.objs.push(obj.upcast());
+ i
+ }
+ 
+ fn get_obj(, i: usize) -> T {
+ self.objs[i].clone().downcast().expect("bad downcast")
+ }
+ }
+ 
+ fn to_egg(vars:  VarMap, prim: ) -> RecExpr {
+ fn build(vars:  VarMap, p: , recexpr:  RecExpr) -> 
egg::Id {
+ macro_rules! r {
+ ($e:expr) => {
+ build(vars, &$e, recexpr)
+ };
+ }
+ 
+ let dt = recexpr.add(Expr::DataType(p.datatype));
+ let e = downcast_match!(p; {
+ tir::Add => Expr::Add([dt, r!(p.a), r!(p.b)]),
+ tir::Sub => Expr::Sub([dt, r!(p.a), r!(p.b)]),
+ tir::Mul => Expr::Mul([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::Div => Expr::Div([dt, r!(p.a), r!(p.b)]),
+ tir::Mod => Expr::Mod([dt, r!(p.a), r!(p.b)]),
+ tir::FloorDiv => Expr::FloorDiv([dt, r!(p.a), r!(p.b)]),
+ tir::FloorMod => Expr::FloorMod([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::Min => Expr::Min([dt, r!(p.a), r!(p.b)]),
+ tir::Max => Expr::Max([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::Ramp => Expr::Ramp([dt, r!(p.start), r!(p.stride), 
recexpr.add(Expr::Int(p.lanes.into()))]),
+ tir::Select => Expr::Select([dt, r!(p.condition), 
r!(p.true_value), r!(p.false_value)]),
+ 
+ tir::Eq => Expr::Equal([dt, r!(p.a), r!(p.b)]),
+ tir::Ne => Expr::NotEqual([dt, r!(p.a), r!(p.b)]),
+ tir::Lt => Expr::Less([dt, r!(p.a), r!(p.b)]),
+ tir::Le => Expr::LessEqual([dt, r!(p.a), r!(p.b)]),
+ tir::Gt => Expr::Greater([dt, r!(p.a), r!(p.b)]),
+ tir::Ge => Expr::GreaterEqual([dt, r!(p.a), r!(p.b)]),
+ 
+ tir::And => Expr::And([dt, r!(p.a), r!(p.b)]),
+ tir::Or => Expr::Or([dt, r!(p.a), r!(p.b)]),
+ tir::Not => 

[incubator-tvm] 16/23: More cleanup

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 187435099c4d80be2c200791e7853f8518f421e1
Author: Jared Roesch 
AuthorDate: Fri Oct 16 16:45:12 2020 -0700

More cleanup
---
 rust/compiler-ext/src/lib.rs | 22 --
 rust/tvm/src/lib.rs  |  7 ---
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 346f40f..5f83f7b 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -18,25 +18,19 @@
  */
 
 use env_logger;
-use tvm;
-use tvm::runtime::function::register_override;
+use tvm::export;
 
-fn test_fn() -> Result<(), tvm::Error> {
-println!("Hello Greg from Rust!");
-Ok(())
+fn diagnostics() -> Result<(), tvm::Error> {
+tvm::ir::diagnostics::codespan::init()
 }
 
-fn test_fn2(message: tvm::runtime::string::String) -> Result<(), tvm::Error> {
-println!("The message: {}", message);
-Ok(())
-}
-
-tvm::export!(test_fn, test_fn2);
+export!(diagnostics);
 
 #[no_mangle]
-fn compiler_ext_initialize() -> i32 {
+extern fn compiler_ext_initialize() -> i32 {
 let _ = env_logger::try_init();
-tvm_export("rust_ext").expect("failed to initialize Rust compiler_ext");
-log::debug!("done!");
+tvm_export("rust_ext")
+.expect("failed to initialize the Rust compiler extensions.");
+log::debug!("Loaded the Rust compiler extension.");
 return 0;
 }
diff --git a/rust/tvm/src/lib.rs b/rust/tvm/src/lib.rs
index d193f09..ec80ece 100644
--- a/rust/tvm/src/lib.rs
+++ b/rust/tvm/src/lib.rs
@@ -50,10 +50,11 @@ pub use runtime::version;
 
 #[macro_export]
 macro_rules! export {
-($($fn_names:expr),*) => {
+($($fn_name:expr),*) => {
 pub fn tvm_export(ns: ) -> Result<(), tvm::Error> {
 $(
-register_override($fn_name, concat!($ns, stringfy!($fn_name)), 
true)?;
+let name = String::from(ns) + ::std::stringify!($fn_name);
+tvm::runtime::function::register_override($fn_name, name, 
true)?;
 )*
 Ok(())
 }
@@ -65,7 +66,7 @@ macro_rules! export_mod {
 ($ns:expr, $($mod_name:expr),*) => {
 pub fn tvm_mod_export() -> Result<(), tvm::Error> {
 $(
-$mod_names::tvm_export($ns)?;
+$mod_name::tvm_export($ns)?;
 )*
 Ok(())
 }



[incubator-tvm] 20/23: WIP

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit b8dcc35801e7f0f3c696e0d030b3bd0931127785
Author: Jared Roesch 
AuthorDate: Thu Oct 22 22:18:58 2020 -0700

WIP
---
 rust/tvm-macros/src/external.rs  |   2 +-
 rust/tvm-macros/src/lib.rs   |   3 +-
 rust/tvm-macros/src/object.rs|  23 ++
 rust/tvm-rt/src/object/mod.rs|   9 +--
 rust/tvm-rt/src/object/object_ptr.rs |  16 
 rust/tvm-rt/src/string.rs|   1 +
 rust/tvm-rt/src/value.rs |   1 -
 rust/tvm-sys/src/datatype.rs |   4 +
 rust/tvm/src/ir/module.rs| 152 ---
 rust/tvm/src/ir/relay/mod.rs |  36 +++--
 rust/tvm/src/ir/tir.rs   |  14 
 11 files changed, 218 insertions(+), 43 deletions(-)

diff --git a/rust/tvm-macros/src/external.rs b/rust/tvm-macros/src/external.rs
index 44a242c..51a389b 100644
--- a/rust/tvm-macros/src/external.rs
+++ b/rust/tvm-macros/src/external.rs
@@ -21,7 +21,7 @@ use proc_macro_error::abort;
 use quote::quote;
 use syn::parse::{Parse, ParseStream, Result};
 
-use syn::{Token, FnArg, Signature, Attribute, token::Semi, Visibility, 
Generics, Ident, Lit, Meta, NestedMeta, Pat, ReturnType, TraitItemMethod, Type};
+use syn::{FnArg, Signature, Attribute, token::Semi, Visibility, Generics, 
Ident, Lit, Meta, NestedMeta, Pat, ReturnType, Type};
 
 struct ExternalItem {
 attrs: Vec,
diff --git a/rust/tvm-macros/src/lib.rs b/rust/tvm-macros/src/lib.rs
index 32f2839..e563a57 100644
--- a/rust/tvm-macros/src/lib.rs
+++ b/rust/tvm-macros/src/lib.rs
@@ -30,7 +30,8 @@ pub fn import_module(input: TokenStream) -> TokenStream {
 import_module::macro_impl(input)
 }
 
-#[proc_macro_derive(Object, attributes(base, ref_name, type_key))]
+#[proc_macro_error]
+#[proc_macro_derive(Object, attributes(base, ref_name, type_key, no_derive))]
 pub fn macro_impl(input: TokenStream) -> TokenStream {
 // let input = proc_macro2::TokenStream::from(input);
 TokenStream::from(object::macro_impl(input))
diff --git a/rust/tvm-macros/src/object.rs b/rust/tvm-macros/src/object.rs
index ff72d6a..7e6a934 100644
--- a/rust/tvm-macros/src/object.rs
+++ b/rust/tvm-macros/src/object.rs
@@ -36,6 +36,8 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
TokenStream {
 .map(attr_to_str)
 .expect("Failed to get type_key");
 
+let derive = get_attr(_input, "no_derive").map(|_| 
false).unwrap_or(true);
+
 let ref_id = get_attr(_input, "ref_name")
 .map(|a| Ident::new(attr_to_str(a).value().as_str(), 
Span::call_site()))
 .unwrap_or_else(|| {
@@ -185,5 +187,26 @@ pub fn macro_impl(input: proc_macro::TokenStream) -> 
TokenStream {
 
 expanded.extend(base_tokens);
 
+if derive {
+let derives = quote! {
+impl std::hash::Hash for #ref_id {
+fn hash(, state:  H) {
+self.0.hash(state)
+}
+}
+
+impl std::cmp::PartialEq for #ref_id {
+fn eq(, other: ) -> bool {
+self.0 == other.0
+}
+}
+
+impl std::cmp::Eq for #ref_id {}
+};
+
+
+expanded.extend(derives);
+}
+
 TokenStream::from(expanded)
 }
diff --git a/rust/tvm-rt/src/object/mod.rs b/rust/tvm-rt/src/object/mod.rs
index e48c017..7e6107d 100644
--- a/rust/tvm-rt/src/object/mod.rs
+++ b/rust/tvm-rt/src/object/mod.rs
@@ -90,12 +90,7 @@ external! {
 #[name("ir.DebugPrint")]
 pub fn debug_print(object: ObjectRef) -> CString;
 #[name("node.StructuralHash")]
-fn structural_hash(object: ObjectRef, map_free_vars: bool) -> ObjectRef;
+fn structural_hash(object: ObjectRef, map_free_vars: bool) -> i64;
 #[name("node.StructuralEqual")]
-fn structural_equal(lhs: ObjectRef, rhs: ObjectRef, assert_mode: bool, 
map_free_vars: bool) -> ObjectRef;
+fn structural_equal(lhs: ObjectRef, rhs: ObjectRef, assert_mode: bool, 
map_free_vars: bool) -> bool;
 }
-
-// external! {
-// #[name("ir.TextPrinter")]
-// fn as_text(object: ObjectRef) -> CString;
-// }
diff --git a/rust/tvm-rt/src/object/object_ptr.rs 
b/rust/tvm-rt/src/object/object_ptr.rs
index 77254d2..a923506 100644
--- a/rust/tvm-rt/src/object/object_ptr.rs
+++ b/rust/tvm-rt/src/object/object_ptr.rs
@@ -342,6 +342,22 @@ impl<'a, T: IsObject> TryFrom> for 
ObjectPtr {
 }
 }
 
+impl std::hash::Hash for ObjectPtr {
+fn hash(, state:  H) {
+
state.write_i64(super::structural_hash(ObjectRef(Some(self.clone().upcast())), 
false).unwrap())
+}
+}
+
+impl PartialEq for ObjectPtr {
+fn eq(, other: ) -> bool {
+let lhs = ObjectRef(Some(self.clone().upcast()));
+let rhs = ObjectRef(Some(other.clone().upcast()));
+super::structural_equal(lhs, rhs, false, false).unwrap()
+}
+}
+
+impl Eq for 

[incubator-tvm] 23/23: Post-rebase

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit c9339267bf7ae641a7f9c3678c84cf1ff600959e
Author: Jared Roesch 
AuthorDate: Sat Oct 31 15:39:05 2020 -0700

Post-rebase
---
 rust/tvm/src/ir/module.rs | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index db32ce2..869c5e6 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -34,11 +34,8 @@ use super::function::BaseFunc;
 use super::source_map::SourceMap;
 use super::{ty::GlobalTypeVar, relay};
 
-use tvm_macros::Object;
-
 // TODO(@jroesch): define type
 type TypeData = ObjectRef;
-type GlobalTypeVar = ObjectRef;
 
 #[derive(Error, Debug)]
 pub enum Error {



[incubator-tvm] 13/23: Remove type checker

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 0cabfdcee309b12d8907fc3abe2ba8e8718ecac6
Author: Jared Roesch 
AuthorDate: Fri Oct 16 15:56:10 2020 -0700

Remove type checker
---
 tests/python/relay/test_type_infer2.py | 419 -
 1 file changed, 419 deletions(-)

diff --git a/tests/python/relay/test_type_infer2.py 
b/tests/python/relay/test_type_infer2.py
deleted file mode 100644
index 6758d96..000
--- a/tests/python/relay/test_type_infer2.py
+++ /dev/null
@@ -1,419 +0,0 @@
-# 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.
-"""Test that type checker correcly computes types
-   for expressions.
-"""
-import pytest
-import tvm
-
-from tvm import IRModule, te, relay, parser
-from tvm.relay import op, transform, analysis
-from tvm.relay import Any
-
-
-def infer_mod(mod, annotate_spans=True):
-if annotate_spans:
-mod = relay.transform.AnnotateSpans()(mod)
-
-mod = transform.InferType()(mod)
-return mod
-
-
-def infer_expr(expr, annotate_spans=True):
-mod = IRModule.from_expr(expr)
-mod = infer_mod(mod, annotate_spans)
-mod = transform.InferType()(mod)
-entry = mod["main"]
-return entry if isinstance(expr, relay.Function) else entry.body
-
-
-def assert_has_type(expr, typ, mod=None):
-if not mod:
-mod = tvm.IRModule({})
-
-mod["main"] = expr
-mod = infer_mod(mod)
-checked_expr = mod["main"]
-checked_type = checked_expr.checked_type
-if checked_type != typ:
-raise RuntimeError("Type mismatch %s vs %s" % (checked_type, typ))
-
-
-def initialize_box_adt(mod):
-# initializes simple ADT for tests
-box = relay.GlobalTypeVar("box")
-tv = relay.TypeVar("tv")
-constructor = relay.Constructor("constructor", [tv], box)
-data = relay.TypeData(box, [tv], [constructor])
-mod[box] = data
-return box, constructor
-
-
-def test_monomorphic_let():
-"Program: let %x = 1; %x"
-# TODO(@jroesch): this seems whack.
-sb = relay.ScopeBuilder()
-x = relay.var("x", dtype="float64", shape=())
-x = sb.let("x", relay.const(1.0, "float64"))
-sb.ret(x)
-xchecked = infer_expr(sb.get())
-assert xchecked.checked_type == relay.scalar_type("float64")
-
-
-def test_single_op():
-"Program: fn (%x : float32) { let %t1 = f(%x); %t1 }"
-x = relay.var("x", shape=[])
-func = relay.Function([x], op.log(x))
-ttype = relay.TensorType([], dtype="float32")
-assert_has_type(func, relay.FuncType([ttype], ttype))
-
-
-def test_add_broadcast_op():
-"""
-Program:
-fn (%x: Tensor[(10, 4), float32], %y: Tensor[(5, 10, 1), float32])
--> Tensor[(5, 10, 4), float32] {
-%x + %y
-}
-"""
-x = relay.var("x", shape=(10, 4))
-y = relay.var("y", shape=(5, 10, 1))
-z = x + y
-func = relay.Function([x, y], z)
-t1 = relay.TensorType((10, 4), "float32")
-t2 = relay.TensorType((5, 10, 1), "float32")
-t3 = relay.TensorType((5, 10, 4), "float32")
-expected_ty = relay.FuncType([t1, t2], t3)
-assert_has_type(func, expected_ty)
-
-
-def test_dual_op():
-"""Program:
-fn (%x : Tensor[(10, 10), float32]) {
-  let %t1 = log(x);
-  let %t2 = add(%t1, %x);
-  %t1
-}
-"""
-tp = relay.TensorType((10, 10), "float32")
-x = relay.var("x", tp)
-sb = relay.ScopeBuilder()
-t1 = sb.let("t1", relay.log(x))
-t2 = sb.let("t2", relay.add(t1, x))
-sb.ret(t2)
-f = relay.Function([x], sb.get())
-fchecked = infer_expr(f)
-assert fchecked.checked_type == relay.FuncType([tp], tp)
-
-
-def test_decl():
-"""Program:
-def @f(%x : Tensor[(10, 10), float32]) {
-log(%x)
-}
-"""
-tp = relay.TensorType((10, 10))
-x = relay.var("x", tp)
-f = relay.Function([x], relay.log(x))
-fchecked = infer_expr(f)
-assert fchecked.checked_type == relay.FuncType([tp], tp)
-
-
-def test_recursion():
-"""
-Program:
-   def @f(%n: int32, %data: float32) -> float32 {
-  if (%n == 0) {
-  %data
-  } else {
-  @f(%n - 1, 

[incubator-tvm] 06/23: Update CMake and delete old API

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit db245535a4ea5b8bed3c26a94825d2fcc9b5
Author: Jared Roesch 
AuthorDate: Thu Oct 15 01:03:03 2020 -0700

Update CMake and delete old API
---
 CMakeLists.txt  |   1 +
 cmake/modules/RustExt.cmake |  25 ++-
 include/tvm/parser/source_map.h |   2 -
 rust/compiler-ext/Cargo.toml|   5 +-
 rust/compiler-ext/src/lib.rs| 334 ++--
 rust/tvm-rt/Cargo.toml  |  15 +-
 rust/tvm-sys/Cargo.toml |   1 +
 rust/tvm-sys/build.rs   |   1 +
 rust/tvm/Cargo.toml |  22 ++-
 rust/tvm/src/bin/tyck.rs|   1 -
 rust/tvm/src/ir/diagnostics.rs  |  42 +++--
 rust/tvm/src/ir/mod.rs  |   2 +-
 rust/tvm/src/ir/relay/mod.rs|   3 +-
 rust/tvm/src/ir/source_map.rs   |  61 
 rust/tvm/src/ir/span.rs |  95 +---
 src/ir/expr.cc  |  11 ++
 src/parser/source_map.cc|  11 --
 17 files changed, 237 insertions(+), 395 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f82754..58bb2f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -353,6 +353,7 @@ include(cmake/modules/contrib/ArmComputeLib.cmake)
 include(cmake/modules/contrib/TensorRT.cmake)
 include(cmake/modules/Git.cmake)
 include(cmake/modules/LibInfo.cmake)
+include(cmake/modules/RustExt.cmake)
 
 include(CheckCXXCompilerFlag)
 if(NOT MSVC)
diff --git a/cmake/modules/RustExt.cmake b/cmake/modules/RustExt.cmake
index 45e46bd..2ad726e9 100644
--- a/cmake/modules/RustExt.cmake
+++ b/cmake/modules/RustExt.cmake
@@ -1,7 +1,14 @@
-if(USE_RUST_EXT)
-set(RUST_SRC_DIR "rust")
-set(CARGO_OUT_DIR "rust/target"
-set(COMPILER_EXT_PATH 
"${CARGO_OUT_DIR}/target/release/libcompiler_ext.dylib")
+if(USE_RUST_EXT AND NOT USE_RUST_EXT EQUAL OFF)
+set(RUST_SRC_DIR "${CMAKE_SOURCE_DIR}/rust")
+set(CARGO_OUT_DIR "${CMAKE_SOURCE_DIR}/rust/target")
+
+if(USE_RUST_EXT STREQUAL "STATIC")
+set(COMPILER_EXT_PATH "${CARGO_OUT_DIR}/release/libcompiler_ext.a")
+elseif(USE_RUST_EXT STREQUAL "DYNAMIC")
+set(COMPILER_EXT_PATH "${CARGO_OUT_DIR}/release/libcompiler_ext.so")
+else()
+message(FATAL_ERROR "invalid setting for RUST_EXT")
+endif()
 
 add_custom_command(
 OUTPUT "${COMPILER_EXT_PATH}"
@@ -9,5 +16,11 @@ if(USE_RUST_EXT)
 MAIN_DEPENDENCY "${RUST_SRC_DIR}"
 WORKING_DIRECTORY "${RUST_SRC_DIR}/compiler-ext")
 
-target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE)
-endif(USE_RUST_EXT)
+add_custom_target(rust_ext ALL DEPENDS "${COMPILER_EXT_PATH}")
+
+# TODO(@jroesch, @tkonolige): move this to CMake target
+# target_link_libraries(tvm "${COMPILER_EXT_PATH}" PRIVATE)
+list(APPEND TVM_LINKER_LIBS ${COMPILER_EXT_PATH})
+
+add_definitions(-DRUST_COMPILER_EXT=1)
+endif()
diff --git a/include/tvm/parser/source_map.h b/include/tvm/parser/source_map.h
index 424af5c..a160c22 100644
--- a/include/tvm/parser/source_map.h
+++ b/include/tvm/parser/source_map.h
@@ -103,8 +103,6 @@ class SourceMap : public ObjectRef {
 
   TVM_DLL SourceMap() : SourceMap(Map()) {}
 
-  TVM_DLL static SourceMap Global();
-
   void Add(const Source& source);
 
   SourceMapNode* operator->() {
diff --git a/rust/compiler-ext/Cargo.toml b/rust/compiler-ext/Cargo.toml
index 76d10eb..3b13bc5 100644
--- a/rust/compiler-ext/Cargo.toml
+++ b/rust/compiler-ext/Cargo.toml
@@ -6,8 +6,11 @@ edition = "2018"
 # TODO(@jroesch): would be cool to figure out how to statically link instead.
 
 [lib]
-crate-type = ["cdylib"]
+crate-type = ["staticlib", "cdylib"]
 
 # See more keys and their definitions at 
https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+tvm = { path = "../tvm", default-features = false, features = 
["static-linking"] }
+log = "*"
+env_logger = "*"
diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index 58bdd0c..3e37d21 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -17,321 +17,19 @@
  * under the License.
  */
 
- use std::os::raw::c_int;
- use tvm::initialize;
- use tvm::ir::{tir, PrimExpr};
- use tvm::runtime::function::register_override;
- use tvm::runtime::map::Map;
- use tvm::runtime::object::{IsObject, IsObjectRef};
- 
- use ordered_float::NotNan;
- 
- mod interval;
- mod math;
- 
- use math::{BoundsMap, Expr, RecExpr};
- use tvm::ir::arith::ConstIntBound;
- use tvm_rt::{ObjectRef, array::Array};
- 
- macro_rules! downcast_match {
- ($id:ident; { $($t:ty => $arm:expr $(,)? )+ , else => $default:expr }) => 
{
- $( if let Ok($id) = $id.downcast_clone::<$t>() { $arm } else )+
- { $default }
- }
- }
- 
- #[derive(Default)]
- struct VarMap {
- vars: Vec<(tvm::ir::tir::Var, egg::Symbol)>,
- objs: Vec,
- }
- 
- impl VarMap {
- // FIXME this should 

[incubator-tvm] 09/23: Improve Rust bindings

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 4cd1bbc79a71873676927c22528f5911e3f4072d
Author: Jared Roesch 
AuthorDate: Thu Oct 15 20:24:43 2020 -0700

Improve Rust bindings
---
 rust/tvm/src/ir/diagnostics/codespan.rs| 131 +
 .../src/ir/{diagnostics.rs => diagnostics/mod.rs}  |  69 +--
 rust/tvm/src/ir/source_map.rs  |   3 +-
 rust/tvm/test.rly  |   3 +-
 src/ir/diagnostic.cc   |   1 +
 5 files changed, 138 insertions(+), 69 deletions(-)

diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
new file mode 100644
index 000..80a8784
--- /dev/null
+++ b/rust/tvm/src/ir/diagnostics/codespan.rs
@@ -0,0 +1,131 @@
+use std::collections::HashMap;
+use std::sync::{Arc, Mutex};
+
+use codespan_reporting::diagnostic::{Diagnostic as CDiagnostic, Label, 
Severity};
+use codespan_reporting::files::SimpleFiles;
+use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
+
+use crate::ir::source_map::*;
+use super::*;
+
+enum StartOrEnd {
+Start,
+End,
+}
+
+enum FileSpanToByteRange {
+AsciiSource,
+Utf8 {
+/// Map character regions which are larger then 1-byte to length.
+lengths: HashMap,
+source: String,
+}
+}
+
+impl FileSpanToByteRange {
+fn new(source: String) -> FileSpanToByteRange {
+let mut last_index = 0;
+let mut is_ascii = true;
+if source.is_ascii() {
+FileSpanToByteRange::AsciiSource
+} else {
+panic!()
+}
+
+// for (index, _) in source.char_indices() {
+// if last_index - 1 != last_index {
+// is_ascii = false;
+// } else {
+// panic!();
+// }
+// last_index = index;
+// }
+}
+}
+
+struct SpanToByteRange {
+map: HashMap
+}
+
+impl SpanToByteRange {
+fn new() -> SpanToByteRange {
+SpanToByteRange { map: HashMap::new() }
+}
+
+pub fn add_source( self, source: Source) {
+let source_name: String = 
source.source_name.name.as_str().expect("foo").into();
+
+if self.map.contains_key(_name) {
+panic!()
+} else {
+let source = source.source.as_str().expect("fpp").into();
+self.map.insert(source_name, FileSpanToByteRange::new(source));
+}
+}
+}
+
+struct ByteRange {
+file_id: FileId,
+start_pos: usize,
+end_pos: usize,
+}
+
+
+pub fn to_diagnostic(diag: super::Diagnostic) -> CDiagnostic {
+let severity = match diag.level {
+DiagnosticLevel::Error => Severity::Error,
+DiagnosticLevel::Warning => Severity::Warning,
+DiagnosticLevel::Note => Severity::Note,
+DiagnosticLevel::Help => Severity::Help,
+DiagnosticLevel::Bug => Severity::Bug,
+};
+
+let file_id = "foo".into(); // diag.span.source_name;
+
+let message: String = diag.message.as_str().unwrap().into();
+let inner_message: String = "expected `String`, found `Nat`".into();
+let diagnostic = CDiagnostic::new(severity)
+.with_message(message)
+.with_code("EXXX")
+.with_labels(vec![
+Label::primary(file_id, 328..331).with_message(inner_message)
+]);
+
+diagnostic
+}
+
+struct DiagnosticState {
+files: SimpleFiles,
+span_map: SpanToByteRange,
+}
+
+impl DiagnosticState {
+fn new() -> DiagnosticState {
+DiagnosticState {
+files: SimpleFiles::new(),
+span_map: SpanToByteRange::new(),
+}
+}
+}
+
+fn renderer(state:  DiagnosticState, diag_ctx: DiagnosticContext) {
+let source_map = diag_ctx.module.source_map.clone();
+for diagnostic in diag_ctx.diagnostics.clone() {
+match source_map.source_map.get(_name) {
+Err(err) => panic!(),
+Ok(source) => state.span_map.add_source(source),
+}
+println!("Diagnostic: {}", diagnostic.message);
+}
+}
+
+pub fn init() -> Result<()> {
+let diag_state = Arc::new(Mutex::new(DiagnosticState::new()));
+let render_fn = move |diag_ctx: DiagnosticContext| {
+// let mut guard = diag_state.lock().unwrap();
+// renderer( *guard, diag_ctx);
+};
+
+override_renderer(Some(render_fn))?;
+Ok(())
+}
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics/mod.rs
similarity index 76%
rename from rust/tvm/src/ir/diagnostics.rs
rename to rust/tvm/src/ir/diagnostics/mod.rs
index 4975a45..fce214a 100644
--- a/rust/tvm/src/ir/diagnostics.rs
+++ b/rust/tvm/src/ir/diagnostics/mod.rs
@@ -18,7 +18,7 @@
  */
 
 use super::module::IRModule;
-use super::span::Span;
+use super::span::*;
 use crate::runtime::function::Result;
 

[incubator-tvm] 14/23: Format and cleanup

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 04a9779359380ae383405f5f72a66e79631ee2d5
Author: Jared Roesch 
AuthorDate: Fri Oct 16 16:31:37 2020 -0700

Format and cleanup
---
 python/tvm/ir/diagnostics/__init__.py   |  1 +
 rust/compiler-ext/src/lib.rs|  3 +-
 rust/tvm-rt/src/array.rs| 11 +++--
 rust/tvm-rt/src/errors.rs   |  4 +-
 rust/tvm-rt/src/function.rs |  2 +-
 rust/tvm/src/bin/tyck.rs|  8 +--
 rust/tvm/src/ir/diagnostics/codespan.rs | 87 +++--
 rust/tvm/src/ir/mod.rs  |  2 +-
 rust/tvm/src/ir/module.rs   |  5 +-
 rust/tvm/src/ir/relay/mod.rs|  2 +-
 rust/tvm/src/ir/relay/visitor.rs| 24 -
 rust/tvm/src/ir/source_map.rs   | 13 ++---
 rust/tvm/src/ir/span.rs |  2 +-
 src/ir/expr.cc  | 11 -
 14 files changed, 79 insertions(+), 96 deletions(-)

diff --git a/python/tvm/ir/diagnostics/__init__.py 
b/python/tvm/ir/diagnostics/__init__.py
index 0ad2a7a..3a6402c 100644
--- a/python/tvm/ir/diagnostics/__init__.py
+++ b/python/tvm/ir/diagnostics/__init__.py
@@ -37,6 +37,7 @@ def get_renderer():
 """
 return _ffi_api.GetRenderer()
 
+
 @tvm.register_func("diagnostics.override_renderer")
 def override_renderer(render_func):
 """
diff --git a/rust/compiler-ext/src/lib.rs b/rust/compiler-ext/src/lib.rs
index c136d06..346f40f 100644
--- a/rust/compiler-ext/src/lib.rs
+++ b/rust/compiler-ext/src/lib.rs
@@ -36,8 +36,7 @@ tvm::export!(test_fn, test_fn2);
 #[no_mangle]
 fn compiler_ext_initialize() -> i32 {
 let _ = env_logger::try_init();
-tvm_export("rust_ext")
-.expect("failed to initialize Rust compiler_ext");
+tvm_export("rust_ext").expect("failed to initialize Rust compiler_ext");
 log::debug!("done!");
 return 0;
 }
diff --git a/rust/tvm-rt/src/array.rs b/rust/tvm-rt/src/array.rs
index 032ca79..66e32a7 100644
--- a/rust/tvm-rt/src/array.rs
+++ b/rust/tvm-rt/src/array.rs
@@ -18,8 +18,8 @@
  */
 
 use std::convert::{TryFrom, TryInto};
-use std::marker::PhantomData;
 use std::iter::{IntoIterator, Iterator};
+use std::marker::PhantomData;
 
 use crate::errors::Error;
 use crate::object::{IsObjectRef, Object, ObjectPtr, ObjectRef};
@@ -93,8 +93,7 @@ impl Iterator for IntoIter {
 
 fn next( self) -> Option {
 if self.pos < self.size {
-let item = self.array.get(self.pos)
-.expect("should not fail");
+let item = self.array.get(self.pos).expect("should not fail");
 self.pos += 1;
 Some(item)
 } else {
@@ -109,7 +108,11 @@ impl IntoIterator for Array {
 
 fn into_iter(self) -> Self::IntoIter {
 let size = self.len() as isize;
-IntoIter { array: self, pos: 0, size: size }
+IntoIter {
+array: self,
+pos: 0,
+size: size,
+}
 }
 }
 
diff --git a/rust/tvm-rt/src/errors.rs b/rust/tvm-rt/src/errors.rs
index 3de9f3c..31ce385 100644
--- a/rust/tvm-rt/src/errors.rs
+++ b/rust/tvm-rt/src/errors.rs
@@ -68,7 +68,9 @@ pub enum Error {
 Infallible(#[from] std::convert::Infallible),
 #[error("a panic occurred while executing a Rust packed function")]
 Panic,
-#[error("one or more error diagnostics were emitted, please check 
diagnostic render for output.")]
+#[error(
+"one or more error diagnostics were emitted, please check diagnostic 
render for output."
+)]
 DiagnosticError(String),
 #[error("{0}")]
 Raw(String),
diff --git a/rust/tvm-rt/src/function.rs b/rust/tvm-rt/src/function.rs
index 173b60a..4c6f56e 100644
--- a/rust/tvm-rt/src/function.rs
+++ b/rust/tvm-rt/src/function.rs
@@ -128,7 +128,7 @@ impl Function {
 type_codes.as_mut_ptr() as *mut c_int,
 num_args as c_int,
  ret_val as *mut _,
- ret_type_code as *mut _
+ ret_type_code as *mut _,
 )
 };
 
diff --git a/rust/tvm/src/bin/tyck.rs b/rust/tvm/src/bin/tyck.rs
index 13470e7..e9c2663 100644
--- a/rust/tvm/src/bin/tyck.rs
+++ b/rust/tvm/src/bin/tyck.rs
@@ -20,9 +20,11 @@ fn main() -> Result<()> {
 let opt = Opt::from_args();
 println!("{:?}", );
 let _module = match IRModule::parse_file(opt.input) {
-Err(ir::module::Error::TVM(Error::DiagnosticError(_))) => { return 
Ok(()) },
-Err(e) => { return Err(e.into()); },
-Ok(module) => module
+Err(ir::module::Error::TVM(Error::DiagnosticError(_))) => return 
Ok(()),
+Err(e) => {
+return Err(e.into());
+}
+Ok(module) => module,
 };
 
 Ok(())
diff --git a/rust/tvm/src/ir/diagnostics/codespan.rs 
b/rust/tvm/src/ir/diagnostics/codespan.rs
index 9fc1ee0..9a31691 

[incubator-tvm] 01/23: Add initial boilerplate for Rust diagnostic interface.

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 1097cbf8a23708b7408dfbab7c419e363af57728
Author: Jared Roesch 
AuthorDate: Fri Oct 9 01:18:15 2020 -0700

Add initial boilerplate for Rust diagnostic interface.
---
 python/tvm/ir/diagnostics/__init__.py |   2 +-
 rust/tvm/src/ir/diagnostics.rs| 239 ++
 rust/tvm/src/ir/mod.rs|   1 +
 3 files changed, 241 insertions(+), 1 deletion(-)

diff --git a/python/tvm/ir/diagnostics/__init__.py 
b/python/tvm/ir/diagnostics/__init__.py
index 6503743..0ad2a7a 100644
--- a/python/tvm/ir/diagnostics/__init__.py
+++ b/python/tvm/ir/diagnostics/__init__.py
@@ -37,7 +37,7 @@ def get_renderer():
 """
 return _ffi_api.GetRenderer()
 
-
+@tvm.register_func("diagnostics.override_renderer")
 def override_renderer(render_func):
 """
 Sets a custom renderer for diagnostics.
diff --git a/rust/tvm/src/ir/diagnostics.rs b/rust/tvm/src/ir/diagnostics.rs
new file mode 100644
index 000..799a10c
--- /dev/null
+++ b/rust/tvm/src/ir/diagnostics.rs
@@ -0,0 +1,239 @@
+/*
+ * 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.
+ */
+
+/// The diagnostic interface to TVM, used for reporting and rendering
+/// diagnostic information by the compiler. This module exposes
+/// three key abstractions: a Diagnostic, the DiagnosticContext,
+/// and the DiagnosticRenderer.
+
+use tvm_macros::{Object, external};
+use super::module::IRModule;
+use crate::runtime::{function::{Function, Typed}, array::Array, string::String 
as TString};
+use crate::runtime::object::{Object, ObjectRef};
+use crate::runtime::function::Result;
+use super::span::Span;
+
+type SourceName = ObjectRef;
+
+/// The diagnostic level, controls the printing of the message.
+#[repr(C)]
+pub enum DiagnosticLevel {
+Bug = 10,
+Error = 20,
+Warning = 30,
+Note = 40,
+Help = 50,
+}
+
+/// A compiler diagnostic.
+#[repr(C)]
+#[derive(Object)]
+#[ref_name = "Diagnostic"]
+#[type_key = "Diagnostic"]
+pub struct DiagnosticNode {
+pub base: Object,
+/// The level.
+pub level: DiagnosticLevel,
+/// The span at which to report an error.
+pub span: Span,
+/// The diagnostic message.
+pub message: TString,
+}
+
+impl Diagnostic {
+pub fn new(level: DiagnosticLevel, span: Span, message: TString) {
+todo!()
+}
+
+pub fn bug(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn error(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn warning(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn note(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+
+pub fn help(span: Span) -> DiagnosticBuilder {
+todo!()
+}
+}
+
+/// A wrapper around std::stringstream to build a diagnostic.
+pub struct DiagnosticBuilder {
+/// The level.
+pub level: DiagnosticLevel,
+
+/// The source name.
+pub source_name: SourceName,
+
+/// The span of the diagnostic.
+pub span: Span,
+}
+
+//   /*! \brief Display diagnostics in a given display format.
+//*
+//* A diagnostic renderer is responsible for converting the
+//* raw diagnostics into consumable output.
+//*
+//* For example the terminal renderer will render a sequence
+//* of compiler diagnostics to std::out and std::err in
+//* a human readable form.
+//*/
+//   class DiagnosticRendererNode : public Object {
+//public:
+// TypedPackedFunc renderer;
+
+// // override attr visitor
+// void VisitAttrs(AttrVisitor* v) {}
+
+// static constexpr const char* _type_key = "DiagnosticRenderer";
+// TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticRendererNode, Object);
+//   };
+
+//   class DiagnosticRenderer : public ObjectRef {
+//public:
+// TVM_DLL DiagnosticRenderer(TypedPackedFunc 
render);
+// TVM_DLL DiagnosticRenderer()
+// : DiagnosticRenderer(TypedPackedFunc()) {}
+
+// void Render(const DiagnosticContext& ctx);
+
+// DiagnosticRendererNode* operator->() {
+//   CHECK(get() != nullptr);
+//   return 

[incubator-tvm] branch cargo-build created (now c933926)

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a change to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


  at c933926  Post-rebase

This branch includes the following new commits:

 new 1097cbf  Add initial boilerplate for Rust diagnostic interface.
 new 77ba309  Codespan example almost working
 new cb37856  WIP
 new 131e40a  Hacking on Rust inside of TVM
 new b2b59c2  Borrow code from Egg
 new db24553  Update CMake and delete old API
 new e0f9801  Fix Linux build
 new 20c6a28  Clean up exporting to show off new diagnostics
 new 4cd1bbc  Improve Rust bindings
 new eeb86c6  Fix calling
 new 4261461  Fix
 new 6e13467  Rust Diagnostics work
 new 0cabfdc  Remove type checker
 new 04a9779  Format and cleanup
 new 6828374  Fix the extension code
 new 1874350  More cleanup
 new 8e295b7  Fix some CR
 new 49246bf  WIP
 new a9ee3cb  WIP
 new b8dcc35  WIP
 new 478326c  Debug segfault
 new e8bb83d  WIP
 new c933926  Post-rebase

The 23 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[incubator-tvm] 21/23: Debug segfault

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 478326c8d7c2ccce10b77aa28e4b22bafbfdf877
Author: Jared Roesch 
AuthorDate: Sun Oct 25 17:26:47 2020 -0700

Debug segfault
---
 python/tvm/__init__.py |  2 ++
 python/tvm/relay/__init__.py   |  3 +-
 python/tvm/relay/analysis/__init__.py  |  2 +-
 python/tvm/relay/analysis/analysis.py  |  6 ++--
 python/tvm/relay/analysis/annotated_regions.py |  2 +-
 python/tvm/relay/analysis/call_graph.py|  4 +--
 python/tvm/relay/analysis/sparse_dense.py  | 15 -
 python/tvm/relay/build_module.py   |  6 +++-
 python/tvm/relay/op/op.py  | 40 
 python/tvm/relay/transform/__init__.py |  2 +-
 python/tvm/relay/transform/memory_alloc.py |  7 ++---
 python/tvm/relay/transform/transform.py|  5 +--
 python/tvm/topi/cuda/__init__.py   |  2 --
 python/tvm/topi/cuda/sparse.py |  3 +-
 rust/tvm/Cargo.toml|  2 +-
 rust/tvm/src/ir/relay/mod.rs   |  1 -
 rust/tvm/src/python.rs | 43 +++---
 17 files changed, 91 insertions(+), 54 deletions(-)

diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py
index 569e8f0..60f81f4 100644
--- a/python/tvm/__init__.py
+++ b/python/tvm/__init__.py
@@ -67,6 +67,8 @@ from . import support
 # Contrib initializers
 from .contrib import rocm as _rocm, nvcc as _nvcc, sdaccel as _sdaccel
 
+def cleanup():
+_ffi.base._LIB = None
 
 def tvm_wrap_excepthook(exception_hook):
 """Wrap given excepthook with TVM additional work."""
diff --git a/python/tvm/relay/__init__.py b/python/tvm/relay/__init__.py
index cd96ecc..7e6ed4f 100644
--- a/python/tvm/relay/__init__.py
+++ b/python/tvm/relay/__init__.py
@@ -60,8 +60,7 @@ from . import qnn
 from .scope_builder import ScopeBuilder
 
 # Load Memory Passes
-from .transform import memory_alloc
-from .transform import memory_plan
+from .transform import memory_alloc, memory_plan
 
 # Required to traverse large programs
 setrecursionlimit(1)
diff --git a/python/tvm/relay/analysis/__init__.py 
b/python/tvm/relay/analysis/__init__.py
index b4ea7f3..4ea4de7 100644
--- a/python/tvm/relay/analysis/__init__.py
+++ b/python/tvm/relay/analysis/__init__.py
@@ -26,7 +26,7 @@ from .annotated_regions import AnnotatedRegionSet
 from . import call_graph
 from .call_graph import CallGraph
 
-# Feature
+# # Feature
 from . import feature
 from . import sparse_dense
 
diff --git a/python/tvm/relay/analysis/analysis.py 
b/python/tvm/relay/analysis/analysis.py
index 7e49461..48e9ce0 100644
--- a/python/tvm/relay/analysis/analysis.py
+++ b/python/tvm/relay/analysis/analysis.py
@@ -20,9 +20,9 @@
 This file contains the set of passes for Relay, which exposes an interface for
 configuring the passes and scripting them in Python.
 """
-from tvm.ir import IRModule
-from tvm.relay import transform, build_module
-from tvm.runtime.ndarray import cpu
+from ...ir import IRModule
+from ...relay import transform, build_module
+from ...runtime.ndarray import cpu
 
 from . import _ffi_api
 from .feature import Feature
diff --git a/python/tvm/relay/analysis/annotated_regions.py 
b/python/tvm/relay/analysis/annotated_regions.py
index 437b97b..a18ccb9 100644
--- a/python/tvm/relay/analysis/annotated_regions.py
+++ b/python/tvm/relay/analysis/annotated_regions.py
@@ -17,7 +17,7 @@
 # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, 
unused-import
 """Regions used in Relay."""
 
-from tvm.runtime import Object
+from ...runtime import Object
 from . import _ffi_api
 
 
diff --git a/python/tvm/relay/analysis/call_graph.py 
b/python/tvm/relay/analysis/call_graph.py
index 966659a..fd9704d 100644
--- a/python/tvm/relay/analysis/call_graph.py
+++ b/python/tvm/relay/analysis/call_graph.py
@@ -17,8 +17,8 @@
 # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, 
unused-import
 """Call graph used in Relay."""
 
-from tvm.ir import IRModule
-from tvm.runtime import Object
+from ...ir import IRModule
+from ...runtime import Object
 from ..expr import GlobalVar
 from . import _ffi_api
 
diff --git a/python/tvm/relay/analysis/sparse_dense.py 
b/python/tvm/relay/analysis/sparse_dense.py
index d521748..51fab34 100644
--- a/python/tvm/relay/analysis/sparse_dense.py
+++ b/python/tvm/relay/analysis/sparse_dense.py
@@ -22,8 +22,8 @@ to block sparse model
 """
 from collections import namedtuple
 import numpy as np
-import scipy.sparse as sp
-import tvm
+
+from ... import nd, runtime
 from . import _ffi_api
 
 
@@ -73,6 +73,7 @@ def process_params(expr, params, block_size, 
sparsity_threshold):
 ret : Namedtuple[weight_name: Array[String], weight_shape: 
Array[Array[IntImm]]]
 return names of qualified dense 

[incubator-tvm] 15/23: Fix the extension code

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 68283745b9c283db611579205a3b925eb09e9faa
Author: Jared Roesch 
AuthorDate: Fri Oct 16 16:32:13 2020 -0700

Fix the extension code
---
 src/contrib/rust_extension.cc | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/src/contrib/rust_extension.cc b/src/contrib/rust_extension.cc
new file mode 100644
index 000..075cbc6
--- /dev/null
+++ b/src/contrib/rust_extension.cc
@@ -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.
+ */
+
+/*!
+ * \file src/contrib/rust_extension.cc
+ * \brief Expose Rust extensions initialization.
+ */
+#ifdef RUST_COMPILER_EXT
+
+extern "C" {
+  int compiler_ext_initialize();
+  static int test = compiler_ext_initialize();
+}
+
+#endif



[incubator-tvm] branch main updated (a4bd5f8 -> 7ee91da)

2020-11-05 Thread zhic
This is an automated email from the ASF dual-hosted git repository.

zhic pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


from a4bd5f8  [Rust][IRModule] Flesh out IRModule methods (#6741)
 add 7ee91da  [TOPI] Enable scatter_add on GPU  (#6856)

No new revisions were added by this update.

Summary of changes:
 python/tvm/relay/op/_transform.py |   2 +-
 python/tvm/relay/op/strategy/cuda.py  |  15 ++-
 python/tvm/relay/op/strategy/generic.py   |  15 +--
 python/tvm/topi/cuda/scatter.py   | 133 +-
 tests/python/frontend/pytorch/test_forward.py |  12 +--
 tests/python/relay/test_op_level3.py  |   4 +-
 6 files changed, 139 insertions(+), 42 deletions(-)



[GitHub] [incubator-tvm] zhiics merged pull request #6856: [TOPI] Enable scatter_add on GPU

2020-11-05 Thread GitBox


zhiics merged pull request #6856:
URL: https://github.com/apache/incubator-tvm/pull/6856


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] zhiics commented on pull request #6856: [TOPI] Enable scatter_add on GPU

2020-11-05 Thread GitBox


zhiics commented on pull request #6856:
URL: https://github.com/apache/incubator-tvm/pull/6856#issuecomment-722635543


   Thanks @masahi @mbrookhart @tqchen 



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] altanh commented on pull request #6854: [RELAY,TOPI] Add scatter_nd op

2020-11-05 Thread GitBox


altanh commented on pull request #6854:
URL: https://github.com/apache/incubator-tvm/pull/6854#issuecomment-722618737


   Hmm yeah seems like the gradient unit test is failing, can you investigate? 
Also I recommend reverting the diagnostics error message change, looks like 
there is a unit test that depends on the specific error message.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] jroesch merged pull request #6741: [Rust][IRModule] Flesh out IRModule methods

2020-11-05 Thread GitBox


jroesch merged pull request #6741:
URL: https://github.com/apache/incubator-tvm/pull/6741


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[incubator-tvm] branch main updated (7291a92 -> a4bd5f8)

2020-11-05 Thread jroesch
This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git.


from 7291a92  [µTVM] Add virtual machine, test zephyr runtime on real 
hardware (#6703)
 add a4bd5f8  [Rust][IRModule] Flesh out IRModule methods (#6741)

No new revisions were added by this update.

Summary of changes:
 rust/Cargo.toml|   1 -
 rust/tvm-graph-rt/tests/test_wasm32/Cargo.toml |   2 +-
 rust/tvm-macros/Cargo.toml |   2 +-
 rust/tvm-macros/src/external.rs|  51 +++-
 rust/tvm-macros/src/lib.rs |   5 +-
 rust/tvm-macros/src/object.rs  |  32 ++-
 rust/tvm-rt/src/array.rs   |  15 +-
 rust/tvm-rt/src/map.rs |   2 -
 rust/tvm-rt/src/ndarray.rs |   2 +-
 rust/tvm-rt/src/object/mod.rs  |  12 +-
 rust/tvm-rt/src/object/object_ptr.rs   |  40 ++-
 rust/tvm-rt/src/string.rs  |   3 +-
 rust/tvm-rt/src/value.rs   |   1 -
 rust/tvm-sys/src/datatype.rs   |   4 +
 rust/tvm/src/ir/arith.rs   |   2 +-
 rust/tvm/src/ir/attrs.rs   |   2 +-
 rust/tvm/src/ir/diagnostics/mod.rs |   7 +-
 rust/tvm/src/ir/expr.rs|  14 +-
 rust/tvm/src/ir/function.rs|   2 +-
 rust/tvm/src/ir/module.rs  | 322 -
 rust/tvm/src/ir/op.rs  |   2 +-
 rust/tvm/src/ir/relay/attrs/nn.rs  |  14 +-
 rust/tvm/src/ir/relay/attrs/transform.rs   |   2 +-
 rust/tvm/src/ir/relay/mod.rs   |  97 
 rust/tvm/src/ir/source_map.rs  |   4 +-
 rust/tvm/src/ir/span.rs|   4 +-
 rust/tvm/src/ir/tir.rs |  16 +-
 rust/tvm/src/ir/ty.rs  | 125 +++---
 rust/tvm/src/transform.rs  |   2 +-
 src/ir/module.cc   |   3 +
 tests/scripts/task_rust.sh |   2 +-
 31 files changed, 599 insertions(+), 193 deletions(-)



[GitHub] [incubator-tvm] d-smirnov commented on a change in pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


d-smirnov commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518320817



##
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##
@@ -305,14 +307,41 @@ def max_pool2d(expr):
 typ = args[0].checked_type
 if typ.dtype not in ["float32", "uint8"]:
 return False
-return True
+return not require_padding([*args, expr.checked_type])
+
+
+def require_padding(inputs):
+"""Checks whether supplied data will require padding.
+Most of the operators ACL up to 20.11 uses padded data.
+"""
+
+def _check(shape, dtype):
+"""NEON has 128bits/16bytes per vector"""
+if len(shape) == 0:
+return False
+return (shape[-1] * np.dtype(dtype).itemsize) % 16 != 0
+
+for i in inputs:
+if isinstance(i, (tvm.relay.expr.Var, tvm.relay.expr.Call)):
+if _check(i.checked_type.shape, i.checked_type.dtype):
+return True
+elif isinstance(i, tvm.relay.expr.Constant):
+if _check(i.data.shape, i.data.dtype):
+return True
+elif isinstance(i, tvm.ir.tensor_type.TensorType):
+if _check(i.shape, i.dtype):
+return True
+else:
+raise Exception("Not supported")

Review comment:
   Updated

##
File path: tests/python/contrib/test_arm_compute_lib/test_pooling.py
##
@@ -166,7 +167,12 @@ def test_pooling():
 fp32_dtype = ("float32", -127, 128, 0.001, 0.001)
 uint8_dtype = ("uint8", 0, 255, 1, 0)
 
+# nn.max_pool2d(%arm_compute_lib_11_i0, pool_size=[3, 3], strides=[2, 2], 
padding=[0, 0, 0, 0], layout="NHWC") /* ty=Tensor[(1, 27, 27, 256), float32] */

Review comment:
   Yes. Removed.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


comaniac commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518307901



##
File path: tests/python/contrib/test_arm_compute_lib/test_pooling.py
##
@@ -166,7 +167,12 @@ def test_pooling():
 fp32_dtype = ("float32", -127, 128, 0.001, 0.001)
 uint8_dtype = ("uint8", 0, 255, 1, 0)
 
+# nn.max_pool2d(%arm_compute_lib_11_i0, pool_size=[3, 3], strides=[2, 2], 
padding=[0, 0, 0, 0], layout="NHWC") /* ty=Tensor[(1, 27, 27, 256), float32] */

Review comment:
   Should this be removed?

##
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##
@@ -305,14 +307,41 @@ def max_pool2d(expr):
 typ = args[0].checked_type
 if typ.dtype not in ["float32", "uint8"]:
 return False
-return True
+return not require_padding([*args, expr.checked_type])
+
+
+def require_padding(inputs):
+"""Checks whether supplied data will require padding.
+Most of the operators ACL up to 20.11 uses padded data.
+"""
+
+def _check(shape, dtype):
+"""NEON has 128bits/16bytes per vector"""
+if len(shape) == 0:
+return False
+return (shape[-1] * np.dtype(dtype).itemsize) % 16 != 0
+
+for i in inputs:
+if isinstance(i, (tvm.relay.expr.Var, tvm.relay.expr.Call)):
+if _check(i.checked_type.shape, i.checked_type.dtype):
+return True
+elif isinstance(i, tvm.relay.expr.Constant):
+if _check(i.data.shape, i.data.dtype):
+return True
+elif isinstance(i, tvm.ir.tensor_type.TensorType):
+if _check(i.shape, i.dtype):
+return True
+else:
+raise Exception("Not supported")

Review comment:
   ```suggestion
   raise RuntimeException("Not supported input type: %s"  % type(i))
   ```





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518289598



##
File path: src/relay/op/tensor/transform.cc
##
@@ -641,11 +642,45 @@ bool ReshapeRel(const Array& types, int num_inputs, 
const Attrs& attrs,
   return true;
 }
 
+Array infer_reshape_like(const Array& lhs_shape,
+   const Array& rhs_shape, const 
Attrs& attrs) {
+  const auto* like_attrs = attrs.as();
+  CHECK(!like_attrs->lhs_end.defined() || like_attrs->lhs_end.as())

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518289388



##
File path: tests/python/relay/test_op_level3.py
##
@@ -316,17 +316,36 @@ def test_reshape_like_infer_type():
 zz = run_infer_type(z)
 assert zz.checked_type == relay.TensorType((1, 8, 8), "float32")
 
+# partial reshaping
+x = relay.var("x", relay.TensorType((1, 2, 3, 4), "float32"))
+y = relay.var("y", relay.TensorType((1, 6, 5), "float32"))
+z = relay.reshape_like(x, y, lhs_begin=1, lhs_end=3, rhs_begin=1, 
rhs_end=2)
+zz = run_infer_type(z)
+assert zz.checked_type == relay.TensorType((1, 6, 4), "float32")
+
+# symbolic partial reshaping
+n, c, h, w = te.size_var("n"), 2, 3, te.size_var("w")
+x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
+y = relay.var("y", relay.TensorType((5, 6), "float32"))
+z = relay.var("z", relay.TensorType((4,), "float32"))
+w = relay.reshape_like(x, y, lhs_end=3)
+w = relay.reshape_like(w, z, lhs_begin=2)

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] comaniac commented on pull request #6831: [TVMC] add cl support in tvmc runner

2020-11-05 Thread GitBox


comaniac commented on pull request #6831:
URL: https://github.com/apache/incubator-tvm/pull/6831#issuecomment-722560999


   > I agree we don't need to run _all_ tests as end-to-end, and I can remove 
some overlap, by creating some mocks and checking that calls are made to the 
internal APIs with the right parameters (as you mentioned), but I'd like a few 
to stay - I'll see to get it done, as soon as I can finish a PR I'm working on.
   
   It makes sense to keep a few for reasons and we can discuss on the PR. 
Thanks :)



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518260340



##
File path: src/relay/op/make_op.h
##
@@ -62,6 +62,9 @@ Expr MakeRepeat(Expr data, int repeats, int axis);
 
 Expr MakeReshape(Expr data, Array newshape);
 
+Expr MakeReshapeLike(Expr lhs, Expr rhs, int64_t lhs_begin, Integer lhs_end, 
int64_t rhs_begin,

Review comment:
   I noticed that the Attrs I defined uses `int` and not `int64_t` so I'll 
probably just use `int` since other code mostly uses it.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518257417



##
File path: src/relay/op/make_op.h
##
@@ -62,6 +62,9 @@ Expr MakeRepeat(Expr data, int repeats, int axis);
 
 Expr MakeReshape(Expr data, Array newshape);
 
+Expr MakeReshapeLike(Expr lhs, Expr rhs, int64_t lhs_begin, Integer lhs_end, 
int64_t rhs_begin,

Review comment:
   I did this because the beginning index (in both cases) must always be an 
integer, but the end index can be `None` which means I must use a nullable 
`Integer` wrapper. I could make everything `Integer` and check that beginning 
is always defined. I did feel a bit weird using `int64_t` directly since 
everything else seem to use `int` but the value wrapped by `Integer` is 
`int64_t` so that's why I chose it. 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6831: [TVMC] add cl support in tvmc runner

2020-11-05 Thread GitBox


leandron commented on a change in pull request #6831:
URL: https://github.com/apache/incubator-tvm/pull/6831#discussion_r518256261



##
File path: tests/python/driver/tvmc/conftest.py
##
@@ -70,6 +89,19 @@ def tflite_mobilenet_v1_1_quant(tmpdir_factory):
 return model_file
 
 
+@pytest.fixture(scope="session")
+def tflite_mobilenet_v1_0_25_128(tmpdir_factory):

Review comment:
   Yeah, this could be the first one to check only API calls, using a mock, 
rather than downloading a file and exercising the whole e2e path.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on pull request #6831: [TVMC] add cl support in tvmc runner

2020-11-05 Thread GitBox


leandron commented on pull request #6831:
URL: https://github.com/apache/incubator-tvm/pull/6831#issuecomment-722542931


   > @leandron I realized this issue also applies to some existing tests. Could 
we review the TVMC unit tests again later and make them more precise and 
concise? If we found that the reason to have such tests here is that this is 
never covered else where, it is totally fine to add more unit tests to the 
right place (e.g., codegen, runtime).
   
   I agree we don't need to run *all* tests as end-to-end, and I can remove 
some overlap, by creating some mocks and checking that calls are made to the 
internal APIs with the right parameters (as you mentioned), but I'd like a few 
to stay - I'll see to get it done, as soon as I can finish a PR I'm working on.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige commented on pull request #6854: [RELAY,TOPI] Add scatter_nd op

2020-11-05 Thread GitBox


tkonolige commented on pull request #6854:
URL: https://github.com/apache/incubator-tvm/pull/6854#issuecomment-722540224


   @antinucleon @altanh In this implementation, repeated indices are summed 
instead of having non-deterministic behavior. I put this on the docs for 
`tvm.topi.scatter`, but I should put it somewhere else too?



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige commented on a change in pull request #6854: [RELAY,TOPI] Add scatter_nd op

2020-11-05 Thread GitBox


tkonolige commented on a change in pull request #6854:
URL: https://github.com/apache/incubator-tvm/pull/6854#discussion_r518246356



##
File path: python/tvm/relay/op/transform.py
##
@@ -308,6 +308,30 @@ def scatter_add(data, indices, updates, axis):
 return _make.scatter_add(data, indices, updates, axis)
 
 
+def scatter_nd(data, indices, out_shape):
+"""Scatter values from an array.
+
+See :py:func:`tvm.topi.scatter` for how data is scattered.

Review comment:
   I believe so.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] tkonolige commented on a change in pull request #6854: [RELAY,TOPI] Add scatter_nd op

2020-11-05 Thread GitBox


tkonolige commented on a change in pull request #6854:
URL: https://github.com/apache/incubator-tvm/pull/6854#discussion_r518246012



##
File path: python/tvm/relay/op/_tensor_grad.py
##
@@ -803,3 +805,15 @@ def arange_grad(orig, grad):
 grad_step = cast_like(_sum(grad_step), step)
 
 return [grad_start, grad_stop, grad_step]
+
+
+@register_gradient("gather_nd")
+def gather_nd_grad(orig, grad):
+data, indices = orig.args
+return [scatter_nd(grad, indices, data.checked_type.concrete_shape), 
zeros_like(indices)]
+
+
+# @register_gradient("scatter_nd")

Review comment:
   I'm getting some really weird results when using gather_nd as the 
gradient. Values are like 1e303.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] d-smirnov commented on a change in pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


d-smirnov commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518234666



##
File path: include/tvm/relay/op_attr_types.h
##
@@ -185,6 +185,20 @@ using FTVMLegalize = runtime::TypedPackedFunc& 
args)>;
 
+/*!
+ * \brief Annotates an expression to indicate if an op should be compiled using
+ *  the given compiler/target.
+ *  \param attrs The attribute of the original expr.
+ *  \param args The arguments of the original expr.
+ *  \param out_type The return type of the original expr.
+ *
+ *  \return true if this op should be registered to invoke a specific compiler
+ *  for codegen, otherwise, false.
+ */
+using FTVMAnnotateTarget3 =

Review comment:
   extracted to [#6786](https://github.com/apache/incubator-tvm/pull/6786)





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] d-smirnov commented on a change in pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


d-smirnov commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518232783



##
File path: tests/python/contrib/test_arm_compute_lib/test_dense.py
##
@@ -20,8 +20,8 @@
 
 import tvm
 from tvm import relay
-
-from .infrastructure import (
+from tvm import testing
+from test_arm_compute_lib.infrastructure import (

Review comment:
   I hope so





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] electriclilies commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

2020-11-05 Thread GitBox


electriclilies commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518231059



##
File path: src/relay/op/tensor/transform.cc
##
@@ -641,11 +642,45 @@ bool ReshapeRel(const Array& types, int num_inputs, 
const Attrs& attrs,
   return true;
 }
 
+Array infer_reshape_like(const Array& lhs_shape,
+   const Array& rhs_shape, const 
Attrs& attrs) {
+  const auto* like_attrs = attrs.as();
+  CHECK(!like_attrs->lhs_end.defined() || like_attrs->lhs_end.as())

Review comment:
   Can you add some line breaks in this function? It is a bit difficult to 
read.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] d-smirnov commented on a change in pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


d-smirnov commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518228552



##
File path: tests/python/contrib/test_arm_compute_lib/test_pooling.py
##
@@ -175,7 +181,8 @@ def test_pooling():
 ["nn.avg_pool2d", fp32_dtype, (2, 2), (2, 2), (1, 1), False, False, 
(16, 16, 16)],
 ["nn.avg_pool2d", fp32_dtype, (2, 2), (2, 2), (0, 0), False, True, 
(16, 16, 16)],
 ["nn.avg_pool2d", fp32_dtype, (3, 3), (2, 2), (0, 1), True, False, 
(15, 15, 16)],
-["nn.avg_pool2d", uint8_dtype, (2, 2), (2, 2), (1, 1), False, True, 
(16, 16, 16)],

Review comment:
   Since it is an ACL complaint ("exclude_padding equal false is not 
supported for AVG Pooling with padding on quantized types"), this line is 
likely never worked. 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] electriclilies commented on a change in pull request #6849: [QNN] Dynamic scale, zero point in qnn.op.dequantize

2020-11-05 Thread GitBox


electriclilies commented on a change in pull request #6849:
URL: https://github.com/apache/incubator-tvm/pull/6849#discussion_r518186040



##
File path: tests/python/frontend/pytorch/qnn_test.py
##
@@ -29,6 +29,9 @@
 import tvm
 import tvm.testing
 from tvm import relay
+from tvm.contrib import graph_runtime

Review comment:
   Moved - thanks for pointing that out





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] d-smirnov commented on a change in pull request #6724: [BYOC] [ACL] 20.05 memory corruption temporarely fix

2020-11-05 Thread GitBox


d-smirnov commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518182386



##
File path: tests/python/contrib/test_arm_compute_lib/test_dense.py
##
@@ -323,7 +357,7 @@ def test_codegen_qnn_dense():
 has_bias=composite,
 )
 exp_codegen = _get_expected_codegen(*args, has_bias=composite)
-verify_codegen(func, exp_codegen, 1)
+verify_codegen(func, exp_codegen, acl_partitions, 2 - 2 * 
acl_partitions)

Review comment:
   test was extended to incorporate situations where no acl partition be 
generated

##
File path: tests/python/contrib/test_arm_compute_lib/test_dense.py
##
@@ -215,18 +231,18 @@ def test_codegen_dense():
 np.random.seed(0)
 
 dtype = ["float32"]
-shape = [((1, 128), (16, 128), 16), ((32, 32), (32, 32), 32), ((1, 64), 
(1, 64), 1)]
+shape = [(1, (1, 128), (16, 128), 16), (1, (32, 32), (32, 32), 32), (0, 
(1, 64), (1, 64), 1)]
 composite = [False, True]
 trials = generate_trials([dtype, shape, composite], 3)
 
-for dtype, (shape, weight_shape, units), composite in trials:
+for dtype, (acl_partitions, shape, weight_shape, units), composite in 
trials:
 inputs = {"a"}
 
 args = (shape, weight_shape, units, dtype)
 
 func, params = _get_model(*args, var_names=iter(inputs), 
has_bias=composite)
 exp_codegen = _get_expected_codegen(*args, has_bias=composite)
-verify_codegen(func, exp_codegen, 1)
+verify_codegen(func, exp_codegen, acl_partitions, 1 - acl_partitions)

Review comment:
   test was extended to incorporate situations where no acl partition be 
generated





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




  1   2   >