You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/01/13 02:04:08 UTC
[GitHub] [incubator-tvm] zhiics opened a new pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
zhiics opened a new pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693
This PR:
- Unifies the Closure objects used by VM and interpreter. Refactored the interpreter to be able to use the same Closure object.
- Replaces the TupleValue objects with ADT
- Cleans the vmobj code and makes ADT not specific to the vm namespace.
cc @tqchen @jroesch @wweic @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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] tqchen commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-575412152
waiting further comments from @jroesch
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] wweic commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
wweic commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r366596598
##########
File path: python/tvm/container.py
##########
@@ -114,3 +116,56 @@ class LoweredFunc(Object):
MixedFunc = 0
HostFunc = 1
DeviceFunc = 2
+
+
+@register_object
+class ADT(Object):
+ """Algebatic data type(ADT) object.
Review comment:
```suggestion
"""Algebraic data type(ADT) object.
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] wweic commented on issue #4693: [runtime][refactor]
Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
wweic commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-574952009
I'll take a look soon.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367664773
##########
File path: include/tvm/runtime/vm.h
##########
@@ -25,34 +25,48 @@
#define TVM_RUNTIME_VM_H_
#include <tvm/runtime/object.h>
+#include <tvm/runtime/memory.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/runtime/registry.h>
#include <memory>
#include <string>
#include <unordered_map>
+#include <utility>
#include <vector>
namespace tvm {
namespace runtime {
namespace vm {
-/*! \brief An object representing a closure. */
+/*!
+ * \brief An object representing a closure. This object is used by both the
+ * Relay VM and interpreter.
+ */
class ClosureObj : public Object {
public:
- /*! \brief The index into the VM function table. */
+ /*!
+ * \brief The index into the function list. The function could be any
+ * function object that is compatible to a certain runtime, i.e. VM or
+ * interpreter.
+ */
size_t func_index;
/*! \brief The free variables of the closure. */
std::vector<ObjectRef> free_vars;
- static constexpr const uint32_t _type_index = TypeIndex::kVMClosure;
- static constexpr const char* _type_key = "vm.Closure";
Review comment:
Sure. I will change them 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367667871
##########
File path: tests/python/unittest/test_container.py
##########
@@ -0,0 +1,60 @@
+# 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.
+
+import numpy as np
+import tvm
+from tvm import nd, relay
+from tvm import container as _container
+
+
+def test_adt_constructor():
+ arr = nd.array([1, 2, 3])
+ fields = [arr, arr]
+ y = _container.ADT(0, [arr, arr])
+
+ assert len(y) == 2
+ assert isinstance(y, _container.ADT)
+ y[0:1][-1] == arr
+ assert y.tag == 0
+ assert isinstance(arr, nd.NDArray)
+
+
+def test_tuple_object():
+ x = relay.var(
+ 'x',
+ type_annotation=relay.ty.TupleType([
+ relay.ty.TensorType((), 'int32'),
+ relay.ty.TensorType((), 'int32')
+ ]))
+
+ fn = relay.Function([x], relay.expr.TupleGetItem(x, 0))
+ mod = relay.Module.from_expr(fn)
+
+ exe = relay.create_executor(
+ kind="vm", mod=mod, ctx=nd.cpu(), target="llvm")
+ f = exe.evaluate()
+ value_tuple = _container.tuple_object(
+ [nd.array(np.array(11)),
+ nd.array(np.array(12))])
+ # pass an ADT object to evaluate
+ out = f(value_tuple)
+ tvm.testing.assert_allclose(out.asnumpy(), np.array(11))
+
+
+if __name__ == "__main__":
Review comment:
we have one in tests/python/relay/test_vm_object.py I removed the file and added another test.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] icemelon9 commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
icemelon9 commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367784492
##########
File path: python/tvm/relay/backend/vm.py
##########
@@ -23,20 +23,18 @@
import numpy as np
import tvm
-from tvm import autotvm
+from tvm import autotvm, container
from tvm.relay import expr as _expr
from tvm._ffi.runtime_ctypes import TVMByteArray
from tvm._ffi import base as _base
+from tvm._ffi.object import Object
Review comment:
```suggestion
from tvm.object import Object
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367667871
##########
File path: tests/python/unittest/test_container.py
##########
@@ -0,0 +1,60 @@
+# 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.
+
+import numpy as np
+import tvm
+from tvm import nd, relay
+from tvm import container as _container
+
+
+def test_adt_constructor():
+ arr = nd.array([1, 2, 3])
+ fields = [arr, arr]
+ y = _container.ADT(0, [arr, arr])
+
+ assert len(y) == 2
+ assert isinstance(y, _container.ADT)
+ y[0:1][-1] == arr
+ assert y.tag == 0
+ assert isinstance(arr, nd.NDArray)
+
+
+def test_tuple_object():
+ x = relay.var(
+ 'x',
+ type_annotation=relay.ty.TupleType([
+ relay.ty.TensorType((), 'int32'),
+ relay.ty.TensorType((), 'int32')
+ ]))
+
+ fn = relay.Function([x], relay.expr.TupleGetItem(x, 0))
+ mod = relay.Module.from_expr(fn)
+
+ exe = relay.create_executor(
+ kind="vm", mod=mod, ctx=nd.cpu(), target="llvm")
+ f = exe.evaluate()
+ value_tuple = _container.tuple_object(
+ [nd.array(np.array(11)),
+ nd.array(np.array(12))])
+ # pass an ADT object to evaluate
+ out = f(value_tuple)
+ tvm.testing.assert_allclose(out.asnumpy(), np.array(11))
+
+
+if __name__ == "__main__":
Review comment:
we had one in tests/python/relay/test_vm_object.py I removed the file and added another test.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367623856
##########
File path: include/tvm/runtime/container.h
##########
@@ -169,8 +169,8 @@ class ADTObj : public Object, public InplaceArrayBase<ADTObj, ObjectRef> {
uint32_t size;
// The fields of the structure follows directly in memory.
- static constexpr const uint32_t _type_index = TypeIndex::kVMADT;
- static constexpr const char* _type_key = "vm.ADT";
Review comment:
Same comment at below.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r368052016
##########
File path: src/relay/backend/interpreter.cc
##########
@@ -774,6 +751,14 @@ class Interpreter :
// Cache ops that need to be frequently used later to reduce lookup overhead.
const Op& debug_op_;
const Op& shape_of_op_;
+ // The free vars captured by the last closure.
+ std::unordered_map<Closure, std::vector<Var>, ObjectHash, ObjectEqual> closure_captured_vars_;
Review comment:
@MarisaKirisame Are you saying why I used the map here? I was trying to leverage VM Clousre which saves the evaluated values of the captured free vars.
@icemelon9 we can probably have a destructor to clean the allocated closures in the map. Another way is probably just to have a base `ClosureObj` class and let `VMClosureObj` and `InterpreterClosureObj` inherit from it so most of original code here keep unchanged. How do you think?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367625446
##########
File path: tests/python/unittest/test_container.py
##########
@@ -0,0 +1,60 @@
+# 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.
+
+import numpy as np
+import tvm
+from tvm import nd, relay
+from tvm import container as _container
+
+
+def test_adt_constructor():
+ arr = nd.array([1, 2, 3])
+ fields = [arr, arr]
+ y = _container.ADT(0, [arr, arr])
+
+ assert len(y) == 2
+ assert isinstance(y, _container.ADT)
+ y[0:1][-1] == arr
+ assert y.tag == 0
+ assert isinstance(arr, nd.NDArray)
+
+
+def test_tuple_object():
+ x = relay.var(
+ 'x',
+ type_annotation=relay.ty.TupleType([
+ relay.ty.TensorType((), 'int32'),
+ relay.ty.TensorType((), 'int32')
+ ]))
+
+ fn = relay.Function([x], relay.expr.TupleGetItem(x, 0))
+ mod = relay.Module.from_expr(fn)
+
+ exe = relay.create_executor(
+ kind="vm", mod=mod, ctx=nd.cpu(), target="llvm")
+ f = exe.evaluate()
+ value_tuple = _container.tuple_object(
+ [nd.array(np.array(11)),
+ nd.array(np.array(12))])
+ # pass an ADT object to evaluate
+ out = f(value_tuple)
+ tvm.testing.assert_allclose(out.asnumpy(), np.array(11))
+
+
+if __name__ == "__main__":
Review comment:
I believe there were some existing tests for these? can we unify all of them?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] icemelon9 commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
icemelon9 commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367785178
##########
File path: src/relay/backend/interpreter.cc
##########
@@ -774,6 +751,14 @@ class Interpreter :
// Cache ops that need to be frequently used later to reduce lookup overhead.
const Op& debug_op_;
const Op& shape_of_op_;
+ // The free vars captured by the last closure.
+ std::unordered_map<Closure, std::vector<Var>, ObjectHash, ObjectEqual> closure_captured_vars_;
Review comment:
One drawback using `closure_captured_vars_` is the memory leak as it will never be released. I wonder if we should create a separate closure object for interpreter that inherits from `ClosureObj` and stores the captured var expr.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] icemelon9 commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
icemelon9 commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-575918719
Thanks @zhiics @tqchen @wweic @jroesch @MarisaKirisame . This is now merged.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] MarisaKirisame commented on a change in pull
request #4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
MarisaKirisame commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r368000465
##########
File path: src/relay/backend/interpreter.cc
##########
@@ -774,6 +751,14 @@ class Interpreter :
// Cache ops that need to be frequently used later to reduce lookup overhead.
const Op& debug_op_;
const Op& shape_of_op_;
+ // The free vars captured by the last closure.
+ std::unordered_map<Closure, std::vector<Var>, ObjectHash, ObjectEqual> closure_captured_vars_;
Review comment:
wait... what?
closure got it's name because closure store the free variables it need.
Is there any reason for this design? This is just moving the member from inside the closure to a map.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-574328741
ping reviewers.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-575396953
@jroesch @tqchen @wweic comments are addressed. PTAL, 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] icemelon9 commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
icemelon9 commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367785178
##########
File path: src/relay/backend/interpreter.cc
##########
@@ -774,6 +751,14 @@ class Interpreter :
// Cache ops that need to be frequently used later to reduce lookup overhead.
const Op& debug_op_;
const Op& shape_of_op_;
+ // The free vars captured by the last closure.
+ std::unordered_map<Closure, std::vector<Var>, ObjectHash, ObjectEqual> closure_captured_vars_;
Review comment:
One drawback using `closure_captured_vars_` is that the memory leak as it will never be released. I wonder if we should create a separate closure object for interpreter that inherits from `ClosureObj` and stores the captured var expr.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] tqchen commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-574930323
would be great if @wweic can also take a 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367625115
##########
File path: src/runtime/container.cc
##########
@@ -18,46 +18,36 @@
*/
/*!
- * \file src/runtime/vm/object.cc
- * \brief VM related objects.
+ * \file src/runtime/container.cc
+ * \brief Implementation of common POD containers.
Review comment:
```suggestion
* \brief Implementations of common plain old data (POD) containers for use in Relay interpreter and VM.
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367622219
##########
File path: include/tvm/relay/interpreter.h
##########
@@ -25,8 +25,8 @@
* Given a Relay module, and a Relay expression it produces a value.
*
* The interpreter's values are a naive representation of the values that
- * can be produced by a Relay program and are exposed via tvm::Node's
- * system to Python for introspection and debugging.
+ * can be produced by a Relay program and are exposed via tvm's object
Review comment:
```suggestion
* can be produced by a Relay program and are exposed via TVM's object
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] tqchen edited a comment on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-575412152
waiting further comments from @jroesch @wweic
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] icemelon9 merged pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
icemelon9 merged pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] MarisaKirisame commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
MarisaKirisame commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-575880941
Thanks for the change. It now look right.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] icemelon9 commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
icemelon9 commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r368159111
##########
File path: src/relay/backend/interpreter.cc
##########
@@ -774,6 +751,14 @@ class Interpreter :
// Cache ops that need to be frequently used later to reduce lookup overhead.
const Op& debug_op_;
const Op& shape_of_op_;
+ // The free vars captured by the last closure.
+ std::unordered_map<Closure, std::vector<Var>, ObjectHash, ObjectEqual> closure_captured_vars_;
Review comment:
I'm good with the design after the change. @MarisaKirisame Could you 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367665057
##########
File path: src/relay/pass/fold_constant.cc
##########
@@ -187,10 +188,11 @@ class ConstantFolder : public ExprMutator {
<< "invalid dimension after constant eval";
}
return ConstantNode::make(nd_array);
- } else if (const auto* val = value.as<TupleValueNode>()) {
+ } else if (const auto* val = value.as<runtime::ADTObj>()) {
+ runtime::ADT adt = GetRef<runtime::ADT>(val);
Array<Expr> fields;
- for (ObjectRef field : val->fields) {
- fields.push_back(ObjectToExpr(field));
+ for (size_t i = 0; i < adt.size(); ++i) {
Review comment:
because we don't have iterators for ADT object
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367624512
##########
File path: src/relay/pass/fold_constant.cc
##########
@@ -187,10 +188,11 @@ class ConstantFolder : public ExprMutator {
<< "invalid dimension after constant eval";
}
return ConstantNode::make(nd_array);
- } else if (const auto* val = value.as<TupleValueNode>()) {
+ } else if (const auto* val = value.as<runtime::ADTObj>()) {
+ runtime::ADT adt = GetRef<runtime::ADT>(val);
Array<Expr> fields;
- for (ObjectRef field : val->fields) {
- fields.push_back(ObjectToExpr(field));
+ for (size_t i = 0; i < adt.size(); ++i) {
Review comment:
Why explicitly use indices here?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367156258
##########
File path: include/tvm/runtime/common_object.h
##########
@@ -0,0 +1,71 @@
+/*
+ * 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/runtime/common_object.h
+ * \brief The objects that are commonly used by different runtime, i.e. Relay VM
+ * and interpreter.
+ */
+#ifndef TVM_RUNTIME_COMMON_OBJECT_H_
+#define TVM_RUNTIME_COMMON_OBJECT_H_
+
+#include <tvm/runtime/memory.h>
+#include <tvm/runtime/object.h>
+#include <utility>
+#include <vector>
+
+namespace tvm {
+namespace runtime {
+
+/*!
+ * \brief An object representing a closure. This object is used by both the
+ * Relay VM and interpreter.
+ */
+class ClosureObj : public Object {
Review comment:
let us still put is into runtime/vm for now, since it does not hurt for Interpreter to use it and this object can is still not self-contained enough to be seen as a Closure(e.g. it cannot be invoked from c++ side)
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on issue #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on issue #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#issuecomment-575325427
cc @MarisaKirisame and @slyubomirsky
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] jroesch commented on a change in pull request
#4693: [runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r367623644
##########
File path: include/tvm/runtime/vm.h
##########
@@ -25,34 +25,48 @@
#define TVM_RUNTIME_VM_H_
#include <tvm/runtime/object.h>
+#include <tvm/runtime/memory.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/runtime/registry.h>
#include <memory>
#include <string>
#include <unordered_map>
+#include <utility>
#include <vector>
namespace tvm {
namespace runtime {
namespace vm {
-/*! \brief An object representing a closure. */
+/*!
+ * \brief An object representing a closure. This object is used by both the
+ * Relay VM and interpreter.
+ */
class ClosureObj : public Object {
public:
- /*! \brief The index into the VM function table. */
+ /*!
+ * \brief The index into the function list. The function could be any
+ * function object that is compatible to a certain runtime, i.e. VM or
+ * interpreter.
+ */
size_t func_index;
/*! \brief The free variables of the closure. */
std::vector<ObjectRef> free_vars;
- static constexpr const uint32_t _type_index = TypeIndex::kVMClosure;
- static constexpr const char* _type_key = "vm.Closure";
Review comment:
@tqchen and I discussed, we feel like it is probably better to keep the keys namespaced, and eventually move them to the `runtime` namespace?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #4693:
[runtime][refactor] Unify vm and interpreter objects
Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #4693: [runtime][refactor] Unify vm and interpreter objects
URL: https://github.com/apache/incubator-tvm/pull/4693#discussion_r368052016
##########
File path: src/relay/backend/interpreter.cc
##########
@@ -774,6 +751,14 @@ class Interpreter :
// Cache ops that need to be frequently used later to reduce lookup overhead.
const Op& debug_op_;
const Op& shape_of_op_;
+ // The free vars captured by the last closure.
+ std::unordered_map<Closure, std::vector<Var>, ObjectHash, ObjectEqual> closure_captured_vars_;
Review comment:
@MarisaKirisame Are you saying why I used the map here? I was trying to leverage `VMClousre` which saves the evaluated values of the captured free vars.
@icemelon9 we can probably have a destructor to clean the allocated closures in the map. Another way is probably just to have a base `ClosureObj` class and let `VMClosureObj` and `InterpreterClosureObj` inherit from it so most of original code here keep unchanged. How do you think?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services