Skip to content

Commit 16b5ddb

Browse files
committed
more docs
1 parent ca4d908 commit 16b5ddb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/api/python/target.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ tvm.target
22
----------
33
.. automodule:: tvm.target
44

5+
.. autofunction:: tvm.target.generic_func
56

67
.. autoclass:: tvm.target.Target
78
:members:

python/tvm/target.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,38 @@ def __exit__(self, ptype, value, trace):
139139
def generic_func(fdefault):
140140
"""Wrap a target generic function.
141141
142+
Generic function allows registeration of further functions
143+
that can be dispatched on current target context.
144+
If no registered dispatch is matched, the fdefault will be called.
145+
142146
Parameters
143147
----------
144148
fdefault : function
145149
The default function.
150+
151+
Returns
152+
-------
153+
fgeneric : function
154+
A wrapped generic function.
155+
156+
Example
157+
-------
158+
.. code-block:: python
159+
160+
import tvm
161+
# wrap function as target generic
162+
@tvm.target.generic_func
163+
def my_func(a):
164+
return a + 1
165+
# register specialization of my_func under target cuda
166+
@my_func.register("cuda")
167+
def my_func_cuda(a):
168+
return a + 2
169+
# displays 3, because my_func is called
170+
print(my_func(2))
171+
# displays 4, because my_func_cuda is called
172+
with tvm.target.cuda():
173+
print(my_func(2))
146174
"""
147175
dispatch_dict = {}
148176
func_name = fdefault.__name__

0 commit comments

Comments
 (0)