Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
15d5801f
Commit
15d5801f
authored
Jun 27, 2018
by
Tianqi Chen
Committed by
GitHub
Jun 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PYTHON] Make decorator optional for runtime (#1350)
parent
e00dacb1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
15 deletions
+34
-15
python/tvm/_ffi/base.py
+15
-0
python/tvm/hybrid/api.py
+18
-8
python/tvm/tag.py
+1
-7
No files found.
python/tvm/_ffi/base.py
View file @
15d5801f
...
...
@@ -98,3 +98,18 @@ def c_array(ctype, values):
Created ctypes array
"""
return
(
ctype
*
len
(
values
))(
*
values
)
def
decorate
(
func
,
fwrapped
):
"""A wrapper call of decorator package, differs to call time
Parameters
----------
func : function
The original function
fwrapped : function
The wrapped function
"""
import
decorator
return
decorator
.
decorate
(
func
,
fwrapped
)
python/tvm/hybrid/api.py
View file @
15d5801f
...
...
@@ -2,21 +2,31 @@
from
__future__
import
absolute_import
as
_abs
import
types
import
decorator
from
.._ffi.base
import
decorate
from
.parser
import
parse_python
@decorator.decorator
def
script
(
func
,
*
args
):
"""If the arguments are tvm types, compile it to HalideIR.
O.W. return the python emulated result"""
def
script
(
pyfunc
):
"""Decorate a python function function as hybrid script.
The hybrid function support emulation mode and parsing to
the internal language IR.
Returns
-------
hybrid_func : function
A decorated hybrid script function.
"""
def
wrapped_func
(
func
,
*
args
,
**
kwargs
):
from
.util
import
_enter_hybrid_runtime
,
_restore_runtime
,
_is_tvm_arg_types
if
_is_tvm_arg_types
(
args
):
return
parse
(
func
,
args
)
else
:
intersect
=
_enter_hybrid_runtime
(
func
)
func
(
*
args
)
value
=
func
(
*
args
,
**
kw
args
)
_restore_runtime
(
func
,
intersect
)
return
func
return
value
return
decorate
(
pyfunc
,
wrapped_func
)
def
parse
(
func
,
args
):
...
...
python/tvm/tag.py
View file @
15d5801f
"""Tag class for TVM operators."""
from
._ffi.base
import
_LIB_NAME
try
:
from
decorator
import
decorate
except
ImportError
as
err_msg
:
# Allow decorator to be missing in runtime
if
_LIB_NAME
!=
"libtvm_runtime.so"
:
raise
err_msg
from
._ffi.base
import
decorate
class
TagScope
(
object
):
"""Tag scope object to set tag for operators, working as context
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment