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 2021/12/21 09:52:30 UTC
[GitHub] [tvm] qsqqsqqsq opened a new pull request #9784: [Runtime] Extend generic func with get_packed_func() interface
qsqqsqqsq opened a new pull request #9784:
URL: https://github.com/apache/tvm/pull/9784
This PR add get_packed_func interface to GenericFunc. This interface is used to get the packed function specified for the current target. As a third-party user, we can use this interface along with python context manager to temporary override op strategy with our own device strategy.
We can create temporary stratey registry as below:
```python
with TempOpStrategy("nn.conv2d", "cuda", general_strategy):
lib = relay.build(...)
```
We save the current strategy function when TempOpStrategy init and register the strategy funcion back when TempOpStrtegy exit.
```python
class TempOpStrategy(object):
def __init__(self, op_name, target, fstrategy):
generic_fstrategy = relay.op.get(op_name).get_attr("FTVMStrategy")
self.op_name = op_name
self.target = target
with tvm.target.Target(target) as target_obj:
self.origin_func = generic_fstrategy.get_packed_func()
for tgt_key in target_obj.keys:
generic_fstrategy.register(fstrategy, tgt_key, allow_override=True)
def __enter__(self):
return self
def __exit__(self, typ, value, traceback):
generic_fstrategies = relay.op.get(name).get_attr("FTVMStrategy")
with tvm.target.Target(self.target) as target_obj:
for tgt_key in target_obj.keys:
generic_fstrategies.register(self.origin_func, tgt_key, allow_override=True)
```
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] qsqqsqqsq commented on a change in pull request #9784: [Runtime] Extend generic func with get_packed_func() interface
Posted by GitBox <gi...@apache.org>.
qsqqsqqsq commented on a change in pull request #9784:
URL: https://github.com/apache/tvm/pull/9784#discussion_r775826008
##########
File path: tests/python/unittest/test_target_target.py
##########
@@ -63,22 +63,77 @@ def test_all_targets_device_type_verify():
def test_target_dispatch():
with tvm.target.cuda():
assert mygeneric(1) == 3
+ assert mygeneric.get_packed_func()(1) == 3
with tvm.target.rocm():
assert mygeneric(1) == 4
+ assert mygeneric.get_packed_func()(1) == 4
with tvm.target.Target("cuda"):
assert mygeneric(1) == 3
+ assert mygeneric.get_packed_func()(1) == 3
with tvm.target.arm_cpu():
assert mygeneric(1) == 11
+ assert mygeneric.get_packed_func()(1) == 11
with tvm.target.Target("metal"):
assert mygeneric(1) == 3
+ assert mygeneric.get_packed_func()(1) == 3
assert tvm.target.Target.current() is None
+@tvm.target.override_native_generic_func("test_target_temp_strategy")
+def target_generic(data):
+ # default generic function
+ return data + 1
+
+
+@target_generic.register(["cuda", "gpu"])
+def target_cuda_func(data):
+ return data + 2
+
+
+def temp_target_cuda_func(data):
+ return data + 3
+
+
+def test_target_temp_strategy():
Review comment:
I add a test_target_temp_strategy case to illustrate the usecase of get_packed_func() interface.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] qsqqsqqsq commented on pull request #9784: [Runtime] Extend generic func with get_packed_func() interface
Posted by GitBox <gi...@apache.org>.
qsqqsqqsq commented on pull request #9784:
URL: https://github.com/apache/tvm/pull/9784#issuecomment-1001317724
> @Hzfengsy generic_fstrategy will change after generic_fstrategy.register. So I can't find a way to backup the generic_fstrategy properly.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Hzfengsy commented on pull request #9784: [Runtime] Extend generic func with get_packed_func() interface
Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on pull request #9784:
URL: https://github.com/apache/tvm/pull/9784#issuecomment-999354011
Can we direct backup `generic_fstrategy` and recover it during `__exit__`?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Hzfengsy merged pull request #9784: [Runtime] Extend generic func with get_packed_func() interface
Posted by GitBox <gi...@apache.org>.
Hzfengsy merged pull request #9784:
URL: https://github.com/apache/tvm/pull/9784
--
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org