-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Hybrid Script] Inter-function call supported! #2287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
af19f15
add a test case of value index
e37734f
fix python2/3 incompat
0b3b0ab
fix floordiv
bf05905
fix floordiv
88c2c27
init codegen hybrid
3f4cb1f
refactor out func call
9972c21
remove comments
67dcd49
continue working...
a88d378
cleanup stash
ff0bb81
more friendly user hints
d3e99d1
fix lint
18a30a9
add boolop test; inter-func call supported?
b6036b4
add boolop test; inter-func call supported?
208b4cf
fix lint
6cb3953
get rid of hybrid codegen
9f1571a
quick fix?!
d182d2c
fix review?
ce28aa9
still do not know why load crashes
1c54380
fix runtime import error
2460558
we do not need int32
f0dad1e
fix the string thing...
16965c7
fix gpu thing
36ae4a3
Merge branch 'inter-call' of github.com:were/tvm into inter-call
2215d94
fix lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Intrinsics of TVM-Python Hybrid Script for Python compilation time | ||
| semantic support.""" | ||
|
|
||
| from .. import api as _api | ||
| from .. import expr as _expr | ||
| from .. import make as _make | ||
| from ..container import Array | ||
| from .. import ir_pass | ||
| from ..stmt import For | ||
| from .util import _internal_assert | ||
|
|
||
| #pylint: disable=redefined-builtin | ||
|
|
||
| LOOP_INTRIN = { | ||
| 'range' : For.Serial, | ||
| 'unroll' : For.Unrolled, | ||
| 'parallel' : For.Parallel, | ||
| 'vectorize': For.Vectorized, | ||
| } | ||
|
|
||
| def _range(annotation, args): | ||
| """Handling TVM loop types""" | ||
| n = len(args) | ||
| if n == 1: | ||
| low, ext = _api.const(0, dtype='int32'), args[0] | ||
were marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else: | ||
| _internal_assert(n == 2, "A loop intrinsic should only have 1 or 2 arguments!") | ||
| low, ext = args[0], args[1] | ||
were marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not ir_pass.Equal(low, _api.const(0, dtype='int32')): | ||
| ext = ext - low | ||
| for_type = LOOP_INTRIN[annotation] | ||
| iter_var = None | ||
| return iter_var, low, ext, for_type | ||
|
|
||
|
|
||
| range = unroll = vectorize = parallel = _range #pylint: disable=invalid-name | ||
|
|
||
|
|
||
| def bind(func_id, args): | ||
were marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Handling TVM thread binding""" | ||
| _internal_assert(func_id == "bind", "This function cannot be directly invoked!") | ||
were marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _internal_assert(len(args) == 2, "A loop bind should only have 2 arguments!") | ||
| _internal_assert(isinstance(args[0], str), \ | ||
| "A loop bind's first argument should be a string!") | ||
| iter_var = _api.thread_axis(args[0]) | ||
| low, ext = _api.const(0), args[1] | ||
| for_type = None | ||
| return iter_var, low, ext, for_type | ||
|
|
||
|
|
||
| def _math_intrin(func_id, args): | ||
| from .. import intrin | ||
| return getattr(intrin, func_id)(*args) | ||
|
|
||
| sqrt = log = exp = tanh = sigmoid = power = popcount = _math_intrin #pylint: disable=invalid-name | ||
|
|
||
|
|
||
| def _min_max(func_id, args): | ||
| _internal_assert(len(args) == 2, "Max/Min function should have 2 elements") | ||
| return getattr(_make, func_id.title())(args[0], args[1]) | ||
|
|
||
|
|
||
| min = max = _min_max #pylint: disable=invalid-name | ||
|
|
||
|
|
||
| def _allocate_tensor(func_id, args): | ||
| """Handling TVM tensor allocation. | ||
| You may refer hybrid.intrin.allocate for more details.""" | ||
| n = len(args) | ||
were marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _internal_assert(isinstance(_api.convert(args[0]), Array), \ | ||
| "allocate's first argument should be a tuple of shape!") | ||
| shape = args[0] | ||
| for i in shape: | ||
| _internal_assert(isinstance(i, _expr.Expr), "The shape should be an expression") | ||
| if n > 1: | ||
| _internal_assert(isinstance(args[1], str), | ||
| "The data type should be an str") | ||
| _internal_assert(args[1].startswith('int') or args[1].startswith('float'), \ | ||
| "The data type should be either int or float!") | ||
| dtype = args[1] | ||
| else: | ||
| dtype = 'float32' | ||
were marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if n > 2: | ||
| _internal_assert(isinstance(args[2], str), \ | ||
| "The data scope should be an string") | ||
| _internal_assert(func_id != 'output_tensor', "Output tensor cannot specify scope") | ||
| scope = args[2] | ||
| else: | ||
| scope = 'global' if func_id != 'output_tensor' else 'output' | ||
| return (shape, dtype, scope) | ||
|
|
||
| output_tensor = allocate = _allocate_tensor #pylint: disable=invalid-name | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.