[GitHub] [incubator-tvm] mbrookhart opened a new pull request #5612: Fix Topological Order calculation for DFPattern Language

2020-05-17 Thread GitBox


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


   @comaniac It was a bug in topological sort for the patterns, memoization 
wasn't quite applied correctly. Fixed it, added this as a test, and put a check 
for null pointers in the pass.
   
   Thanks for checking out the language and [filing the 
bug](https://github.com/apache/incubator-tvm/issues/5605) when you ran into an 
issue! Please let me know if I can help with anything else.



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] roastduck commented on a change in pull request #5600: [TOPI] Improve CUDA softmax scheduling

2020-05-17 Thread GitBox


roastduck commented on a change in pull request #5600:
URL: https://github.com/apache/incubator-tvm/pull/5600#discussion_r426379145



##
File path: src/tir/transforms/lower_warp_memory.cc
##
@@ -213,9 +213,13 @@ class WarpAccessRewriter : protected StmtExprMutator {
 alloc_size *= op->dtype.lanes();
 std::tie(warp_index_, width_) = WarpIndexFinder(warp_size_).Find(op->body);
 warp_coeff_ = WarpStoreCoeffFinder(buffer_, warp_index_, 
analyzer_).Find(op->body);
-CHECK_EQ(alloc_size % (width_ * warp_coeff_), 0)
-<< "Warp memory must be multiple of the extent of threadIdx.x";
-warp_group_ = alloc_size / (width_ * warp_coeff_);
+
+// Align the local memory size. The number of elements may not
+// be a multiple of width_ * warp_coeff_; round it up.
+int factor = width_ * warp_coeff_;
+warp_group_ = (alloc_size + (factor - 1)) / factor;
+alloc_size = warp_group_ * factor;
+

Review comment:
   Sorry I misunderstood these lines. I thought it was dealing with 
sub-warp logic. Then there will be no problem.





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] wpan11nv commented on a change in pull request #5600: [TOPI] Improve CUDA softmax scheduling

2020-05-17 Thread GitBox


wpan11nv commented on a change in pull request #5600:
URL: https://github.com/apache/incubator-tvm/pull/5600#discussion_r426370564



##
File path: src/tir/transforms/lower_warp_memory.cc
##
@@ -213,9 +213,13 @@ class WarpAccessRewriter : protected StmtExprMutator {
 alloc_size *= op->dtype.lanes();
 std::tie(warp_index_, width_) = WarpIndexFinder(warp_size_).Find(op->body);
 warp_coeff_ = WarpStoreCoeffFinder(buffer_, warp_index_, 
analyzer_).Find(op->body);
-CHECK_EQ(alloc_size % (width_ * warp_coeff_), 0)
-<< "Warp memory must be multiple of the extent of threadIdx.x";
-warp_group_ = alloc_size / (width_ * warp_coeff_);
+
+// Align the local memory size. The number of elements may not
+// be a multiple of width_ * warp_coeff_; round it up.
+int factor = width_ * warp_coeff_;
+warp_group_ = (alloc_size + (factor - 1)) / factor;
+alloc_size = warp_group_ * factor;
+

Review comment:
   Looks like this is a sub-warp related, and I am not following it 
closely. CUDA __shfl_sync does not support non-power of 2 width. So your 
example may not be supported.  It would be helpful if we have a legal example 
that would be broken by this patch. 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] mbrookhart commented on issue #5605: [BUG] Pattern Reeriter Seg Fault

2020-05-17 Thread GitBox


mbrookhart commented on issue #5605:
URL: https://github.com/apache/incubator-tvm/issues/5605#issuecomment-629943475


   Thanks, @comaniac! Just saw this, I'll reproduce and produce a fix first 
thing tomorrow.



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 a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


junrushao1994 commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426366620



##
File path: tests/scripts/task_python_frontend.sh
##
@@ -26,6 +26,7 @@ export OMP_NUM_THREADS=1
 
 find . -type f -path "*.pyc" | xargs rm -f
 
+ulimit -s 819600

Review comment:
   This is super helpful! Thanks Zhi!





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] roastduck commented on a change in pull request #5600: [TOPI] Improve CUDA softmax scheduling

2020-05-17 Thread GitBox


roastduck commented on a change in pull request #5600:
URL: https://github.com/apache/incubator-tvm/pull/5600#discussion_r426361872



##
File path: src/tir/transforms/lower_warp_memory.cc
##
@@ -213,9 +213,13 @@ class WarpAccessRewriter : protected StmtExprMutator {
 alloc_size *= op->dtype.lanes();
 std::tie(warp_index_, width_) = WarpIndexFinder(warp_size_).Find(op->body);
 warp_coeff_ = WarpStoreCoeffFinder(buffer_, warp_index_, 
analyzer_).Find(op->body);
-CHECK_EQ(alloc_size % (width_ * warp_coeff_), 0)
-<< "Warp memory must be multiple of the extent of threadIdx.x";
-warp_group_ = alloc_size / (width_ * warp_coeff_);
+
+// Align the local memory size. The number of elements may not
+// be a multiple of width_ * warp_coeff_; round it up.
+int factor = width_ * warp_coeff_;
+warp_group_ = (alloc_size + (factor - 1)) / factor;
+alloc_size = warp_group_ * factor;
+

Review comment:
   > What’s the extent of threadidx.x?
   
   It's 5. Thread 0\~4 are shuffled as a group (say Group 0), and Thread 5\~12 
are another group (say Group 1). If we round up 0\~4 to 0\~7, Thread 5\~7 may 
be both accessed by Group 0 and Group 1, which may cause some problems.
   
   > I think the test case in this PR clearly shows rounding up to the warp 
size is needed.
   
   Yes, it is needed, but maybe not enough.
   
   > As there is no warp level allocation of size n, we allocate n/32 elements 
in each thread. If n is not a multiple of 32, we need to ”over-allocate“ 
slightly and predict the access.
   
   Yes, we need to over-allocate the **buffers**, but should we also 
over-allocate the **threads**? If not, maybe we should properly set the mask of 
`__shlf_sync`.





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] hzfan commented on pull request #5235: [Relay][Fix] i64 support

2020-05-17 Thread GitBox


hzfan commented on pull request #5235:
URL: https://github.com/apache/incubator-tvm/pull/5235#issuecomment-629930317


   @tqchen ok, I will follow up.



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] littlefish0123 opened a new pull request #5611: Fix a typo.

2020-05-17 Thread GitBox


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


   Thanks for contributing to TVM!   Please refer to guideline 
https://tvm.apache.org/docs/contribute/ for useful information and tips. After 
the pull request is submitted, please request code reviews from 
[Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers)
 by @ them in the pull request thread.
   



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] wpan11nv commented on a change in pull request #5600: [TOPI] Improve CUDA softmax scheduling

2020-05-17 Thread GitBox


wpan11nv commented on a change in pull request #5600:
URL: https://github.com/apache/incubator-tvm/pull/5600#discussion_r426350654



##
File path: src/tir/transforms/lower_warp_memory.cc
##
@@ -213,9 +213,13 @@ class WarpAccessRewriter : protected StmtExprMutator {
 alloc_size *= op->dtype.lanes();
 std::tie(warp_index_, width_) = WarpIndexFinder(warp_size_).Find(op->body);
 warp_coeff_ = WarpStoreCoeffFinder(buffer_, warp_index_, 
analyzer_).Find(op->body);
-CHECK_EQ(alloc_size % (width_ * warp_coeff_), 0)
-<< "Warp memory must be multiple of the extent of threadIdx.x";
-warp_group_ = alloc_size / (width_ * warp_coeff_);
+
+// Align the local memory size. The number of elements may not
+// be a multiple of width_ * warp_coeff_; round it up.
+int factor = width_ * warp_coeff_;
+warp_group_ = (alloc_size + (factor - 1)) / factor;
+alloc_size = warp_group_ * factor;
+

Review comment:
   What’s the extent of threadidx.x? I think the test case in this PR 
clearly shows rounding up to the warp size is needed. It is the same as softmax 
failures I have seen. As there is no warp level allocation of size n,  we 
allocate n/32 elements in each thread. If n is not a multiple of 32, we need to 
”over-allocate“ slightly and predict the access.





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] Observer007 opened a new issue #5610: time cost gap between autotvm and running.

2020-05-17 Thread GitBox


Observer007 opened a new issue #5610:
URL: https://github.com/apache/incubator-tvm/issues/5610


   I tune a 1x1 conv with shape 28*128*56*56 and got a time cost gap between 
autotvm tuning log and actual running. The gap is about 0.01-0.05 ms and total 
execute time is 0.7-0.8 ms.
   I used autoTVM tuning and got up to 3800 gflops, but during running with 
best parameters, I just got 3600 gflops.
   The target and other parameters are same during tuning and running. My 
machine is intel clx-8280.
   I used time_evaluation api and read its source code. I find that the call of 
RPC and other target are different. AutoTVM uses rpc and my running uses llvm. 
So is this the case?



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 #5606: [CUDA] Fix codegen for warp shuffle intrinsics

2020-05-17 Thread GitBox


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


   



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 master updated: [CUDA] Fix codegen for warp shuffle intrinsics (#5606)

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

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


The following commit(s) were added to refs/heads/master by this push:
 new cb7bd98  [CUDA] Fix codegen for warp shuffle intrinsics (#5606)
cb7bd98 is described below

commit cb7bd986cadea53d6f41143a6ce747224e25aefb
Author: Shizhi Tang 
AuthorDate: Mon May 18 10:55:05 2020 +0800

[CUDA] Fix codegen for warp shuffle intrinsics (#5606)

* fix shfl intrin

* improve test_lower_warp_memory_cuda_half_a_warp
---
 src/target/source/intrin_rule_cuda.cc  |  2 +-
 .../test_tir_transform_lower_warp_memory.py| 26 --
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/target/source/intrin_rule_cuda.cc 
b/src/target/source/intrin_rule_cuda.cc
index 4e4abd9..7ebcfa6 100644
--- a/src/target/source/intrin_rule_cuda.cc
+++ b/src/target/source/intrin_rule_cuda.cc
@@ -116,7 +116,7 @@ static void DispatchCUDAShuffle(const TVMArgs& args, 
TVMRetValue* rv) {
   const CallNode* call = e.as();
   CHECK(call != nullptr);
   CHECK_EQ(call->args.size(), 5);  // mask, value, warp_id, width, warp_size
-  Array cuda_args{{call->args[0], call->args[1], call->args[2]}};
+  Array cuda_args{{call->args[0], call->args[1], call->args[2], 
call->args[3]}};
   const char* name = T()(call->dtype, call->name);
   *rv = CallNode::make(call->dtype, name, cuda_args, CallNode::PureExtern);
 }
diff --git a/tests/python/unittest/test_tir_transform_lower_warp_memory.py 
b/tests/python/unittest/test_tir_transform_lower_warp_memory.py
index bd55377..c3cf289 100644
--- a/tests/python/unittest/test_tir_transform_lower_warp_memory.py
+++ b/tests/python/unittest/test_tir_transform_lower_warp_memory.py
@@ -136,30 +136,32 @@ def test_lower_warp_memory_cuda_half_a_warp():
 print("Skip because gpu does not have fp16 support")
 return
 
-m = 16
-A = te.placeholder((m,), name='A', dtype=dtype)
-B = te.compute((m,), lambda i: A[(i + 1) % m], name='B')
+n, m = 16, 16
+A = te.placeholder((n, m,), name='A', dtype=dtype)
+B = te.compute((n, m,), lambda j, i: A[j, (i + 1) % m], name='B')
 
 cuda_target = tvm.target.create("cuda")
 assert cuda_target.thread_warp_size == 2 * m
 with cuda_target:
 s = te.create_schedule(B.op)
 tx = te.thread_axis("threadIdx.x")
+ty = te.thread_axis("threadIdx.y")
 bx = te.thread_axis("blockIdx.x")
 
 AA = s.cache_read(A, "warp", [B])
-xo, xi = s[B].split(B.op.axis[0], nparts=1)
-s[B].bind(xi, tx)
-s[B].bind(xo, bx)
-s[AA].compute_at(s[B], xo)
-xo, xi = s[AA].split(s[AA].op.axis[0], nparts=1)
-s[AA].bind(xo, bx)
-s[AA].bind(xi, tx)
+y, x = B.op.axis
+z, y = s[B].split(y, nparts=2)
+s[B].bind(x, tx)
+s[B].bind(y, ty)
+s[B].bind(z, bx)
+s[AA].compute_at(s[B], y)
+_, x = AA.op.axis
+s[AA].bind(x, tx)
 
 ctx = tvm.gpu(0)
 func = tvm.build(s, [A, B], "cuda")
-A_np = np.array(list(range(m)), dtype=dtype)
-B_np = np.array(list(range(1, m)) + [0], dtype=dtype)
+A_np = np.array([list(range(i, m + i)) for i in range(n)], 
dtype=dtype)
+B_np = np.array([list(range(1 + i, m + i)) + [i] for i in 
range(n)], dtype=dtype)
 A_nd = tvm.nd.array(A_np, ctx)
 B_nd = tvm.nd.array(np.zeros(B_np.shape, dtype=B_np.dtype), ctx)
 func(A_nd, B_nd)



[GitHub] [incubator-tvm] kazum commented on pull request #5508: [TFLITE]GATHER_ND

2020-05-17 Thread GitBox


kazum commented on pull request #5508:
URL: https://github.com/apache/incubator-tvm/pull/5508#issuecomment-629916785


   Thanks @dhruvaray @siju-samuel @u99127 !



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 master updated: [TFLITE]GATHER_ND (#5508)

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

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


The following commit(s) were added to refs/heads/master by this push:
 new 8a63b7f  [TFLITE]GATHER_ND (#5508)
8a63b7f is described below

commit 8a63b7f37c64d04236e915a30f8df7e0e61ffefa
Author: Dhruva Ray 
AuthorDate: Mon May 18 08:18:17 2020 +0530

[TFLITE]GATHER_ND (#5508)

Signed-off-by: Dhruva Ray 
---
 python/tvm/relay/frontend/tflite.py  | 26 +++
 tests/python/frontend/tflite/test_forward.py | 31 
 2 files changed, 57 insertions(+)

diff --git a/python/tvm/relay/frontend/tflite.py 
b/python/tvm/relay/frontend/tflite.py
index 5a645c6..cb10ce5 100644
--- a/python/tvm/relay/frontend/tflite.py
+++ b/python/tvm/relay/frontend/tflite.py
@@ -86,6 +86,7 @@ class OperatorConverter(object):
 'FLOOR': self.convert_floor,
 'FULLY_CONNECTED': self.convert_fully_connected,
 'GATHER': self.convert_gather,
+'GATHER_ND' : self.convert_gather_nd,
 'GREATER_EQUAL': self.convert_greater_equal,
 'GREATER': self.convert_greater,
 'HARD_SWISH': self.convert_hard_swish,
@@ -1113,6 +1114,31 @@ class OperatorConverter(object):
 out = _op.take(data, indices, axis=axis, mode="fast")
 return out
 
+def convert_gather_nd(self, op):
+"""Method to Convert TFLite GATHER_ND operator"""
+try:
+from tflite.TensorType import TensorType
+except ImportError:
+raise ImportError("The tflite package must be installed")
+
+input_tensors = self.get_input_tensors(op)
+assert len(input_tensors) == 2, "input tensors length should be 2"
+
+for t in input_tensors:
+assert not t.qnn_params, "Quantized input is not expected."
+
+data = self.get_tensor_expr(input_tensors[0])
+indices = self.get_tensor_expr(input_tensors[1])
+
+indices_type = input_tensors[1].tensor.Type()
+assert indices_type in (TensorType.INT32, TensorType.INT64)
+
+indices_dims = len(_infer_shape(indices))
+indices_t = _op.transpose(indices, axes=[-1] + 
list(range(indices_dims-1)))
+
+out = _op.gather_nd(data, indices_t)
+return out
+
 def convert_strided_slice(self, op):
 """Method to Convert TFLite STRIDED_SLICE operator.
NOTE: Eventhough tensorflow supports begin_mask, end_mask, 
ellipsis_mask, new_axis_mask
diff --git a/tests/python/frontend/tflite/test_forward.py 
b/tests/python/frontend/tflite/test_forward.py
index 9963479..2319904 100644
--- a/tests/python/frontend/tflite/test_forward.py
+++ b/tests/python/frontend/tflite/test_forward.py
@@ -355,6 +355,36 @@ def test_forward_gather():
 _test_gather((1, 3, 3), [20, 20], 2, 'float32', quantized, oob=True)
 
 ###
+# Gather_ND
+# -
+
+def _test_gather_nd(data, indices):
+""" One iteration of GATHER_ND """
+with tf.Graph().as_default():
+in_data = tf.placeholder(shape=data.shape, dtype=data.dtype, 
name="data")
+indices_data = tf.placeholder(shape=indices.shape, dtype=indices.dtype,
+name="indices")
+out = tf.gather_nd(in_data, indices_data)
+
+compare_tflite_with_tvm([data, indices], ['data:0', 'indices:0'],
+  [in_data, indices_data], [out])
+
+def test_forward_gather_nd():
+""" GATHER_ND """
+_test_gather_nd(
+np.array([[[1.2, 2.0], [3.1, 4.1]], [[5.1, 6.1], [7.1, 
8.1]]]).astype('float32'),
+np.asarray([[0, 1], [1, 0]]).astype('int32')
+)
+_test_gather_nd(
+np.reshape(np.arange(30), [5, 6]).astype('int32'),
+np.asarray([[1, 2]]).astype('int32')
+)
+_test_gather_nd(
+np.reshape(np.arange(12), [2, 3, 2]).astype('int32'),
+np.asarray([[[0, 0], [0, 1]], [[1, 0], [1, 1]]]).astype('int32')
+)
+
+###
 # StridedSlice
 # 
 
@@ -2217,6 +2247,7 @@ if __name__ == '__main__':
 test_forward_slice()
 test_forward_topk()
 test_forward_gather()
+test_forward_gather_nd()
 test_forward_stridedslice()
 test_forward_depthtospace()
 test_forward_spacetodepth()



[GitHub] [incubator-tvm] kazum merged pull request #5508: [TFLITE]GATHER_ND

2020-05-17 Thread GitBox


kazum merged pull request #5508:
URL: https://github.com/apache/incubator-tvm/pull/5508


   



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] roastduck commented on a change in pull request #5600: [TOPI] Improve CUDA softmax scheduling

2020-05-17 Thread GitBox


roastduck commented on a change in pull request #5600:
URL: https://github.com/apache/incubator-tvm/pull/5600#discussion_r426321509



##
File path: src/tir/transforms/lower_warp_memory.cc
##
@@ -213,9 +213,13 @@ class WarpAccessRewriter : protected StmtExprMutator {
 alloc_size *= op->dtype.lanes();
 std::tie(warp_index_, width_) = WarpIndexFinder(warp_size_).Find(op->body);
 warp_coeff_ = WarpStoreCoeffFinder(buffer_, warp_index_, 
analyzer_).Find(op->body);
-CHECK_EQ(alloc_size % (width_ * warp_coeff_), 0)
-<< "Warp memory must be multiple of the extent of threadIdx.x";
-warp_group_ = alloc_size / (width_ * warp_coeff_);
+
+// Align the local memory size. The number of elements may not
+// be a multiple of width_ * warp_coeff_; round it up.
+int factor = width_ * warp_coeff_;
+warp_group_ = (alloc_size + (factor - 1)) / factor;
+alloc_size = warp_group_ * factor;
+

Review comment:
   Please consider this scenario:
   
   ```
   // bound to threadIdx.y
   for (i = 0; i < 2; i++) {
 // bound to threadIdx.x
 for (j = 0; j < 5; j++) {
   access buffer.warp[(j + 1) % 5]
 }
   }
   ```
   
   Now we are shuffling among Thread 0\~4, and Thread 5\~9. Since we are 
rounding them up to Thread 0\~7 and Thread **5\~12 (seems not right as well)**, 
will there be any conflict between these two group of threads?





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] wpan11nv commented on a change in pull request #5600: [TOPI] Improve CUDA softmax scheduling

2020-05-17 Thread GitBox


wpan11nv commented on a change in pull request #5600:
URL: https://github.com/apache/incubator-tvm/pull/5600#discussion_r426314749



##
File path: src/tir/transforms/lower_warp_memory.cc
##
@@ -213,9 +213,13 @@ class WarpAccessRewriter : protected StmtExprMutator {
 alloc_size *= op->dtype.lanes();
 std::tie(warp_index_, width_) = WarpIndexFinder(warp_size_).Find(op->body);
 warp_coeff_ = WarpStoreCoeffFinder(buffer_, warp_index_, 
analyzer_).Find(op->body);
-CHECK_EQ(alloc_size % (width_ * warp_coeff_), 0)
-<< "Warp memory must be multiple of the extent of threadIdx.x";
-warp_group_ = alloc_size / (width_ * warp_coeff_);
+
+// Align the local memory size. The number of elements may not
+// be a multiple of width_ * warp_coeff_; round it up.
+int factor = width_ * warp_coeff_;
+warp_group_ = (alloc_size + (factor - 1)) / factor;
+alloc_size = warp_group_ * factor;
+

Review comment:
   Added tests. Without this fix, this test will assert. 





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 #5609: [REFACTOR][IR] Streamline ir/op Registry

2020-05-17 Thread GitBox


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


   



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 master updated: [REFACTOR][IR] Streamline ir/op Registry (#5609)

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

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


The following commit(s) were added to refs/heads/master by this push:
 new a8e4471  [REFACTOR][IR] Streamline ir/op Registry (#5609)
a8e4471 is described below

commit a8e44710c6472a2ee5cb66283c7f5e77f4e4ca0d
Author: Tianqi Chen 
AuthorDate: Sun May 17 15:43:11 2020 -0700

[REFACTOR][IR] Streamline ir/op Registry (#5609)

* [REFACTOR][IR] Streamline ir/op Registry

This PR refactors the attrregistry mechanism in the ir/op into
a separate common base. The common base will provide a foundation
for other attr related registries such as target and pass.

We also streamlines the terminology of the registry API.

- Use AttrMap for the column maps returned by the registry
- Use RegEntry to refer to the registry entry.

* Address review comments
---
 docs/dev/relay_add_pass.rst  |   2 +-
 include/tvm/ir/op.h  | 237 ++-
 include/tvm/node/attr_registry_map.h | 132 +
 src/ir/op.cc | 111 +++
 src/node/attr_registry.h | 181 +
 src/relay/analysis/mac_count.cc  |   2 +-
 src/relay/analysis/util.cc   |   2 +-
 src/relay/backend/compile_engine.cc  |   6 +-
 src/relay/ir/dataflow_matcher.cc |   2 +-
 src/relay/transforms/alter_op_layout.cc  |   2 +-
 src/relay/transforms/annotate_target.cc  |   4 +-
 src/relay/transforms/canonicalize_cast.cc|   2 +-
 src/relay/transforms/combine_parallel_op.cc  |   2 +-
 src/relay/transforms/convert_layout.cc   |   2 +-
 src/relay/transforms/eliminate_common_subexpr.cc |   2 +-
 src/relay/transforms/fold_constant.cc|   2 +-
 src/relay/transforms/fold_scale_axis.cc  |   6 +-
 src/relay/transforms/forward_rewrite.cc  |   6 +-
 src/relay/transforms/fuse_ops.cc |   4 +-
 src/relay/transforms/gradient.cc |   6 +-
 src/relay/transforms/infer_layout_util.h |   2 +-
 src/relay/transforms/legalize.cc |   6 +-
 src/relay/transforms/partial_eval.cc |   2 +-
 tests/cpp/relay_build_module_test.cc |   2 +-
 24 files changed, 432 insertions(+), 293 deletions(-)

diff --git a/docs/dev/relay_add_pass.rst b/docs/dev/relay_add_pass.rst
index 8a6f8be..3eb9586 100644
--- a/docs/dev/relay_add_pass.rst
+++ b/docs/dev/relay_add_pass.rst
@@ -292,7 +292,7 @@ pointed to by ``op->index``. The reason we need to check is 
because
 .. code:: c
 
 Expr VisitExpr_(const CallNode* call) final {
-  static auto op_stateful = Op::GetAttr("TOpIsStateful");
+  static auto op_stateful = Op::GetAttrMap("TOpIsStateful");
   Expr res = ExprMutator::VisitExpr_(call);
   call = res.as();
   // We don't constant fold function with zero arguments.
diff --git a/include/tvm/ir/op.h b/include/tvm/ir/op.h
index aeda4fa..f86aeba 100644
--- a/include/tvm/ir/op.h
+++ b/include/tvm/ir/op.h
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -39,10 +40,8 @@
 namespace tvm {
 
 // forward declare name.
-template 
-class OpMap;
-class GenericOpMap;
-class OpRegistry;
+template 
+class OpAttrMap;
 
 // TODO(tvm-team): migrate low-level intrinsics to use Op
 /*!
@@ -126,9 +125,18 @@ class OpNode : public RelayExprNode {
   TVM_DECLARE_FINAL_OBJECT_INFO(OpNode, RelayExprNode);
 
  private:
+  /*! \return the internal attr registry index. */
+  uint32_t AttrRegistryIndex() const { return index_; }
+  /*! \brief repr to be printed in registry*/
+  std::string AttrRegistryName() const { return name; }
+
   // friend class
-  friend class GenericOpMap;
-  friend class OpRegistry;
+  template 
+  friend class AttrRegistryMapContainerMap;
+  template 
+  friend class AttrRegistry;
+  friend class OpRegEntry;
+
   friend bool IsPrimitiveOp(const RelayExpr&);
   // Program internal unique index of operator.
   // Used to help index the program.
@@ -166,19 +174,19 @@ class Op : public RelayExpr {
   inline const OpNode* operator->() const;
   /*!
* \brief Get additional registered attribute about operators.
-   *  If nothing has been registered, an empty OpMap will be returned.
+   *  If nothing has been registered, an empty OpAttrMap will be returned.
* \param attr_name The name of the attribute.
-   * \return An OpMap of specified attr_name.
+   * \return An OpAttrMap of specified attr_name.
* \tparam ValueType The type of the attribute.
*/
   template 
-  inline static OpMap GetAttr(const std::string& attr_name);
+  inline static OpAttrMap GetAttrMap(const std::string& attr_name);
   /*!
-   * \brief Checks if an attr is present in the registry.
+   * \brief Checks if 

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


zhiics commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426308670



##
File path: tests/scripts/task_python_frontend.sh
##
@@ -26,6 +26,7 @@ export OMP_NUM_THREADS=1
 
 find . -type f -path "*.pyc" | xargs rm -f
 
+ulimit -s 819600

Review comment:
   Maybe we can use `Trace` to do this as it takes a `PackedFunc` and 
inserted before and after the invocation of a pass
   
   
https://github.com/apache/incubator-tvm/blob/63f84a11353791ac3f8916cdcf7c2c6e6d45c4fb/src/relay/ir/transform.cc#L118-L135
   
   One unit test is here:
   
   
https://github.com/apache/incubator-tvm/blob/63f84a11353791ac3f8916cdcf7c2c6e6d45c4fb/tests/python/relay/test_pass_manager.py#L528
   
   but I personally haven't tried to used it to evaluate time before





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 commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


tqchen commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426306630



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +190,769 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() { ShrinkBy(size_); }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 
initialization succeeds
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new (write++) 

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


tqchen commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426306457



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +190,769 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() { ShrinkBy(size_); }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 
initialization succeeds
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new (write++) 

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


tqchen commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426306166



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +190,769 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() { ShrinkBy(size_); }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 
initialization succeeds
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new (write++) 

[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


junrushao1994 commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426301796



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +189,764 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() { ShrinkBy(size_); }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 
initialization succeeds
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new 

[GitHub] [incubator-tvm] tqchen commented on pull request #5609: [REFACTOR][IR] Streamline ir/op Registry

2020-05-17 Thread GitBox


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


   @zhiics please take another look



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 commented on pull request #5606: [CUDA] Fix codegen for warp shuffle intrinsics

2020-05-17 Thread GitBox


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


   cc @wpan11nv please also help to review this PR



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 a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


junrushao1994 commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426300967



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +189,759 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() {
+for (ObjectRef* itr = MutableEnd(); size_; --size_) {
+  (--itr)->ObjectRef::~ObjectRef();
+}
+  }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new 

[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


junrushao1994 commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426300643



##
File path: tests/scripts/task_python_frontend.sh
##
@@ -26,6 +26,7 @@ export OMP_NUM_THREADS=1
 
 find . -type f -path "*.pyc" | xargs rm -f
 
+ulimit -s 819600

Review comment:
   Yeah I strongly agree we should use a non-recursive one for a certain 
pass, or probably we should change all passes to non-recursive.
   
   The first pass crashes right now is 
`relay::transform::EliminateCommonSubexpr`.
   
   BTW, @zhiics do you have any ideas how to profile the time cost in each 
pass? Seems that `relay.build` is super slow overall.





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 a change in pull request #5609: [REFACTOR][IR] Streamline ir/op Registry

2020-05-17 Thread GitBox


zhiics commented on a change in pull request #5609:
URL: https://github.com/apache/incubator-tvm/pull/5609#discussion_r426291664



##
File path: include/tvm/node/attr_registry_map.h
##
@@ -0,0 +1,132 @@
+/*
+ * 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 tvm/node/attr_registry_map.h
+ * \brief Attribute map used in registry.
+ */
+#ifndef TVM_NODE_ATTR_REGISTRY_MAP_H_
+#define TVM_NODE_ATTR_REGISTRY_MAP_H_
+
+#include 
+#include 
+
+namespace tvm {
+
+/*!
+ * \brief Generic attribute map.
+ * \tparam KeyType the type of the key.
+ */
+template 
+class GenericAttrRegistryMap {

Review comment:
   How do you think the name `AttrRegistryMapContainer` as it is more like 
container for `AttrRegistryMap`? Generic sounds to me that `AttrRegistryMap` 
would inherit from 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] ANSHUMAN87 commented on pull request #5236: [WIP][TVM][.NET] Introduce TVM.NET project

2020-05-17 Thread GitBox


ANSHUMAN87 commented on pull request #5236:
URL: https://github.com/apache/incubator-tvm/pull/5236#issuecomment-629841268


   @tqchen : Your review comments are handled now. Please check. 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] zhiics commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


zhiics commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426289668



##
File path: tests/scripts/task_python_frontend.sh
##
@@ -26,6 +26,7 @@ export OMP_NUM_THREADS=1
 
 find . -type f -path "*.pyc" | xargs rm -f
 
+ulimit -s 819600

Review comment:
   I am not sure why it this change would reveal the problem either. BTW, 
do you which pass was it? We may want to refactor it to the non-recursive 
version later.





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 #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


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


   I will add cpptest after the main part is finalized :-)



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 a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


junrushao1994 commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426285093



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +189,764 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() { ShrinkBy(size_); }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 
initialization succeeds
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new 

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


tqchen commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426281012



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +189,764 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() { ShrinkBy(size_); }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 
initialization succeeds
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new (write++) 

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


tqchen commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426280655



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +189,758 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() {
+for (ObjectRef* itr = MutableEnd(); size_; --size_) {
+  (--itr)->ObjectRef::~ObjectRef();
+}
+  }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+// To ensure exception safety, size is only incremented after the 

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5585: [Runtime] Introduce runtime::Array

2020-05-17 Thread GitBox


tqchen commented on a change in pull request #5585:
URL: https://github.com/apache/incubator-tvm/pull/5585#discussion_r426280307



##
File path: include/tvm/runtime/container.h
##
@@ -189,6 +189,759 @@ class InplaceArrayBase {
   }
 };
 
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class IterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit IterAdapter(TIter iter) : iter_(iter) {}
+  IterAdapter& operator++() {
+++iter_;
+return *this;
+  }
+  IterAdapter& operator--() {
+--iter_;
+return *this;
+  }
+  IterAdapter& operator++(int) {
+IterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  IterAdapter& operator--(int) {
+IterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+
+  IterAdapter operator+(difference_type offset) const { return 
IterAdapter(iter_ + offset); }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const IterAdapter& rhs) const {
+return iter_ - rhs.iter_;
+  }
+
+  bool operator==(IterAdapter other) const { return iter_ == other.iter_; }
+  bool operator!=(IterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*!
+ * \brief iterator adapter that adapts TIter to return another type.
+ * \tparam Converter a struct that contains converting function
+ * \tparam TIter the content iterator type.
+ */
+template 
+class ReverseIterAdapter {
+ public:
+  using difference_type = typename 
std::iterator_traits::difference_type;
+  using value_type = typename Converter::ResultType;
+  using pointer = typename Converter::ResultType*;
+  using reference = typename Converter::ResultType&;  // NOLINT(*)
+  using iterator_category = typename 
std::iterator_traits::iterator_category;
+
+  explicit ReverseIterAdapter(TIter iter) : iter_(iter) {}
+  ReverseIterAdapter& operator++() {
+--iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator--() {
+++iter_;
+return *this;
+  }
+  ReverseIterAdapter& operator++(int) {
+ReverseIterAdapter copy = *this;
+--iter_;
+return copy;
+  }
+  ReverseIterAdapter& operator--(int) {
+ReverseIterAdapter copy = *this;
+++iter_;
+return copy;
+  }
+  ReverseIterAdapter operator+(difference_type offset) const {
+return ReverseIterAdapter(iter_ - offset);
+  }
+
+  template 
+  typename std::enable_if::value,
+  typename T::difference_type>::type inline
+  operator-(const ReverseIterAdapter& rhs) const {
+return rhs.iter_ - iter_;
+  }
+
+  bool operator==(ReverseIterAdapter other) const { return iter_ == 
other.iter_; }
+  bool operator!=(ReverseIterAdapter other) const { return !(*this == other); }
+  const value_type operator*() const { return Converter::convert(*iter_); }
+
+ private:
+  TIter iter_;
+};
+
+/*! \brief array node content in array */
+class ArrayNode : public Object, public InplaceArrayBase 
{
+ public:
+  /*! \return The size of the array */
+  size_t size() const { return this->size_; }
+
+  /*!
+   * \brief Read i-th element from array.
+   * \param i The index
+   * \return the i-th element.
+   */
+  const ObjectRef at(int64_t i) const { return this->operator[](i); }
+
+  /*! \return begin constant iterator */
+  const ObjectRef* begin() const { return 
static_cast(InplaceArrayBase::AddressOf(0)); }
+
+  /*! \return end constant iterator */
+  const ObjectRef* end() const { return begin() + size_; }
+
+  /*! \brief Release reference to all the elements */
+  void clear() {
+for (ObjectRef* itr = MutableEnd(); size_; --size_) {
+  (--itr)->ObjectRef::~ObjectRef();
+}
+  }
+
+  /*!
+   * \brief Set i-th element of the array in-place
+   * \param i The index
+   * \param item The value to be set
+   */
+  void SetItem(int64_t i, ObjectRef item) { this->operator[](i) = 
std::move(item); }
+
+  /*!
+   * \brief Constructs a container and copy from another
+   * \param cap The capacity of the container
+   * \param from Source of the copy
+   * \return Ref-counted ArrayNode requested
+   */
+  static ObjectPtr CopyFrom(int64_t cap, ArrayNode* from) {
+int64_t size = from->size_;
+CHECK_GE(cap, size) << "ValueError: not enough capacity";
+ObjectPtr p = ArrayNode::Empty(cap);
+ObjectRef* write = p->MutableBegin();
+ObjectRef* read = from->MutableBegin();
+for (int64_t& i = p->size_ = 0; i < size; ++i) {
+  new (write++) 

[GitHub] [incubator-tvm] zhanghaohit edited a comment on pull request #5471: [VTA][Runtime] fix hardcoded VerifyDep step

2020-05-17 Thread GitBox


zhanghaohit edited a comment on pull request #5471:
URL: https://github.com/apache/incubator-tvm/pull/5471#issuecomment-629760906


   > ping @tmoreau89 @zhanghaohit please followup :)
   
   Thanks @tqchen for the reminder. I think this PR depends on this 
[PR](https://github.com/apache/incubator-tvm-vta/pull/8) in VTA repo. 
   @tmoreau89 could you kindly review and what do you suggest? 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] zhanghaohit commented on pull request #5471: [VTA][Runtime] fix hardcoded VerifyDep step

2020-05-17 Thread GitBox


zhanghaohit commented on pull request #5471:
URL: https://github.com/apache/incubator-tvm/pull/5471#issuecomment-629760906


   > ping @tmoreau89 @zhanghaohit please followup :)
   
   Thanks @tqchen for the reminder. I think this PR depends on this 
[PR](https://github.com/apache/incubator-tvm-vta/pull/8) in VTA repo. 
   @tmoreau89 could you kindly review and input your suggestions? 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-vta] zhanghaohit edited a comment on pull request #8: [Hardware][Xilinx] explicitly specify acc dep distance to avoid hidden pitfall

2020-05-17 Thread GitBox


zhanghaohit edited a comment on pull request #8:
URL: https://github.com/apache/incubator-tvm-vta/pull/8#issuecomment-629760035


   > Perhaps one way to look at this is to start with DISTANCE=3 by default. 
And if the II>1 for the GEMM, we issue a warning telling the user to increase 
the distance to 4. The process can repeat until the II of 1 is achieved, and 
the runtime will be informed of the actual distance so proper checks can be 
inserted.
   
   Thanks @tmoreau89 for the advice. 
   
   For this issue, do you suggest to do it manually? For example, we have a 
config (e.g., `ACC_DEP_DISTANCE`) set with a default value (say, 3). If II > 1, 
we just issue a warning message and ask the user to enlarge this config if he 
want to achieve II = 1?



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-vta] zhanghaohit commented on pull request #8: [Hardware][Xilinx] explicitly specify acc dep distance to avoid hidden pitfall

2020-05-17 Thread GitBox


zhanghaohit commented on pull request #8:
URL: https://github.com/apache/incubator-tvm-vta/pull/8#issuecomment-629760035


   > Perhaps one way to look at this is to start with DISTANCE=3 by default. 
And if the II>1 for the GEMM, we issue a warning telling the user to increase 
the distance to 4. The process can repeat until the II of 1 is achieved, and 
the runtime will be informed of the actual distance so proper checks can be 
inserted.
   
   For this issue, do you suggest to do it manually? For example, we have a 
config (e.g., `ACC_DEP_DISTANCE`) set with a default value (say, 3). If II > 1, 
we just issue a warning message and ask the user to enlarge this config if he 
want to achieve II = 1?



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