-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[CORE][Relay] Swap and remove compile_engine with te_compiler followup of #8775 #9282
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
20 commits
Select commit
Hold shift + click to select a range
7d9d9c9
Remove compile_engine.h for real
jroesch 79d42e5
Fix format
jroesch 65a2943
Fix merge conflicts
mikepapadim efa80c4
RM compile_engine.cc
mikepapadim 4e5840e
Swap compile engine with TECompiler
mikepapadim 0065463
Cleanup on compile engine py leftovers
mikepapadim b1f817a
[WIP] Exposing legacy compile engine capabilities through TE Compiler
mikepapadim e4bd0d8
Swap usages for depreciated compile engine with TE compiler
mikepapadim d9b54eb
Track and replace usages of compile engine refactor them to TE compiler
mikepapadim 13260db
[Docs] Log helper mod
mikepapadim 820689e
Remove depreciated function for lookup compile engine cachce
mikepapadim c85da07
Fix typos
mikepapadim 1ccd14c
Merge branch 'main' of https://github.com/apache/tvm into remove-comp…
mikepapadim b8b9e82
Debug misc cleanups
mikepapadim 62740c5
Register global pass for using te compiler for auto scheduler
mikepapadim cd021b7
Fix tests using the legacy compile engine
mikepapadim 1df8132
Fix broken autotuner tests and minor cleanups
mikepapadim 5100263
Swap compile engine with te_compiler in rst config
mikepapadim 1a53713
PR nits
mikepapadim 3f08424
Fix failed test
mikepapadim 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
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
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
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 |
|---|---|---|
|
|
@@ -15,11 +15,10 @@ | |
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| # pylint: disable=len-as-condition,no-else-return,invalid-name | ||
| """Backend code generation engine.""" | ||
| """TE compiler engine (replacing legacy compile_engine).""" | ||
| from __future__ import absolute_import | ||
|
|
||
| import logging | ||
| import numpy as np | ||
| import tvm | ||
| from tvm import te, autotvm | ||
| from tvm.ir.transform import PassContext | ||
|
|
@@ -31,7 +30,7 @@ | |
| from .. import ty as _ty | ||
| from . import _backend | ||
|
|
||
| logger = logging.getLogger("compile_engine") | ||
| logger = logging.getLogger("te_compiler") | ||
| autotvm_logger = logging.getLogger("autotvm") | ||
|
|
||
| _first_warning = True | ||
|
|
@@ -47,7 +46,7 @@ def __init__(self, outputs, implement): | |
|
|
||
| @tvm._ffi.register_object("relay.CCacheKey") | ||
| class CCacheKey(Object): | ||
| """Key in the CompileEngine. | ||
| """Key in the TE Compiler. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
@@ -64,7 +63,7 @@ def __init__(self, source_func, target): | |
|
|
||
| @tvm._ffi.register_object("relay.CCacheValue") | ||
| class CCacheValue(Object): | ||
| """Value in the CompileEngine, including usage statistics.""" | ||
| """Value in the TE Compiler, including usage statistics.""" | ||
|
|
||
|
|
||
| def _get_cache_key(source_func, target): | ||
|
|
@@ -79,24 +78,6 @@ def _get_cache_key(source_func, target): | |
| return source_func | ||
|
|
||
|
|
||
| def get_shape(shape): | ||
| """Convert the shape to correct dtype and vars.""" | ||
| ret = [] | ||
| for dim in shape: | ||
| if isinstance(dim, tvm.tir.IntImm): | ||
| if libinfo()["INDEX_DEFAULT_I64"] == "ON": | ||
| ret.append(dim) | ||
| else: | ||
| val = int(dim) | ||
| assert val <= np.iinfo(np.int32).max | ||
| ret.append(tvm.tir.IntImm("int32", val)) | ||
| elif isinstance(dim, tvm.tir.Any): | ||
| ret.append(te.var("any_dim", "int32")) | ||
| else: | ||
| ret.append(dim) | ||
| return ret | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this replaced with?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, now I see this was just moved. Nevermind |
||
| def get_valid_implementations(op, attrs, inputs, out_type, target): | ||
| """Get all valid implementations from the op strategy. | ||
|
|
||
|
|
@@ -275,6 +256,24 @@ def select_implementation(op, attrs, inputs, out_type, target, use_autotvm=True) | |
| return best_plevel_impl, outputs[best_plevel_impl] | ||
|
|
||
|
|
||
| def get_shape(shape): | ||
| """Convert the shape to correct dtype and vars.""" | ||
| ret = [] | ||
| for dim in shape: | ||
| if isinstance(dim, tvm.tir.IntImm): | ||
| if libinfo()["INDEX_DEFAULT_I64"] == "ON": | ||
| ret.append(dim) | ||
| else: | ||
| val = int(dim) | ||
| assert val <= np.iinfo(np.int32).max | ||
| ret.append(tvm.tir.IntImm("int32", val)) | ||
| elif isinstance(dim, tvm.tir.Any): | ||
| ret.append(te.var("any_dim", "int32")) | ||
| else: | ||
| ret.append(dim) | ||
| return ret | ||
|
|
||
|
|
||
| @tvm._ffi.register_func("relay.backend.lower_call") | ||
| def lower_call(call, inputs, target): | ||
| """Lower the call expression to op implementation and tensor outputs.""" | ||
|
|
@@ -322,12 +321,12 @@ def lower_call(call, inputs, target): | |
| return LoweredOutput(outputs, best_impl) | ||
|
|
||
|
|
||
| @tvm._ffi.register_object("relay.CompileEngine") | ||
| class CompileEngine(Object): | ||
| """CompileEngine to get lowered code.""" | ||
| @tvm._ffi.register_object("relay.TECompiler") | ||
| class TECompiler(Object): | ||
| """TECompiler to get lowered code.""" | ||
|
|
||
| def __init__(self): | ||
| raise RuntimeError("Cannot construct a CompileEngine") | ||
| raise RuntimeError("Cannot construct a TECompiler") | ||
|
|
||
| def lower(self, source_func, target=None, mod_name="default"): | ||
| """Lower a source_func to a CachedFunc. | ||
|
|
@@ -349,7 +348,7 @@ def lower(self, source_func, target=None, mod_name="default"): | |
| try: | ||
| mod_name = mangle_module_name(mod_name) | ||
| key = _get_cache_key(source_func, target) | ||
| return _backend._CompileEngineLower(self, key, mod_name) | ||
| return _backend._TECompilerLower(self, key, mod_name) | ||
| except Exception: | ||
| import traceback | ||
|
|
||
|
|
@@ -360,10 +359,6 @@ def lower(self, source_func, target=None, mod_name="default"): | |
| msg += "--------------------------\n" | ||
| raise RuntimeError(msg) | ||
|
|
||
| def lower_shape_func(self, source_func, target=None): | ||
| key = _get_cache_key(source_func, target) | ||
| return _backend._CompileEngineLowerShapeFunc(self, key) | ||
|
|
||
| def jit(self, source_func, target=None): | ||
| """JIT a source_func to a tvm.runtime.PackedFunc. | ||
|
|
||
|
|
@@ -381,87 +376,30 @@ def jit(self, source_func, target=None): | |
| The result of jited function. | ||
| """ | ||
| key = _get_cache_key(source_func, target) | ||
| return _backend._CompileEngineJIT(self, key) | ||
| return _backend._TECompilerJIT(self, key) | ||
|
|
||
| def clear(self): | ||
| """clear the existing cached functions""" | ||
| _backend._CompileEngineClear(self) | ||
| _backend._TECompilerClear(self) | ||
|
|
||
| def items(self): | ||
| """List items in the cache. | ||
|
|
||
| Returns | ||
| ------- | ||
| item_list : List[Tuple[CCacheKey, CCacheValue]] | ||
| The list of items. | ||
| """ | ||
| res = _backend._CompileEngineListItems(self) | ||
| assert len(res) % 2 == 0 | ||
| return [(res[2 * i], res[2 * i + 1]) for i in range(len(res) // 2)] | ||
|
|
||
| def shape_func_items(self): | ||
| """List items in the shape_func_cache. | ||
|
|
||
| Returns | ||
| ------- | ||
| item_list : List[Tuple[CCacheKey, CCacheValue]] | ||
| The list of shape_func_items. | ||
| """ | ||
| res = _backend._CompileEngineListShapeFuncItems(self) | ||
| res = _backend._TECompilerListItems(self) | ||
| assert len(res) % 2 == 0 | ||
| return [(res[2 * i], res[2 * i + 1]) for i in range(len(res) // 2)] | ||
|
|
||
| def get_current_ccache_key(self): | ||
| return _backend._CompileEngineGetCurrentCCacheKey(self) | ||
|
|
||
| def dump(self): | ||
| """Return a string representation of engine dump. | ||
|
|
||
| Returns | ||
| ------- | ||
| dump : str | ||
| The dumped string representation | ||
| """ | ||
| items = self.items() | ||
| res = "====================================\n" | ||
| res += "CompilerEngine dump, %d items cached\n" % len(items) | ||
| for k, v in items: | ||
| res += "------------------------------------\n" | ||
| res += "target={}\n".format(k.target) | ||
| res += "use_count={}\n".format(v.use_count) | ||
| res += "func_name={}\n".format(v.cached_func.prim_fn_var.name_hint) | ||
| res += "----relay function----\n" | ||
| res += k.source_func.astext() + "\n" | ||
| res += "----tir function----- \n" | ||
| res += "inputs={}\n".format(v.cached_func.inputs) | ||
| res += "outputs={}\n".format(v.cached_func.outputs) | ||
| res += "function: \n" | ||
| res += v.cached_func.funcs.astext() + "\n" | ||
| res += "===================================\n" | ||
| shape_func_items = self.shape_func_items() | ||
| res += "%d shape_func_items cached\n" % len(shape_func_items) | ||
| for k, v in shape_func_items: | ||
| res += "------------------------------------\n" | ||
| res += "target={}\n".format(k.target) | ||
| res += "use_count={}\n".format(v.use_count) | ||
| res += "func_name={}\n".format(v.cached_func.prim_fn_var.name_hint) | ||
| res += "----relay function----\n" | ||
| res += k.source_func.astext() + "\n" | ||
| res += "----tir function----- \n" | ||
| res += "inputs={}\n".format(v.cached_func.inputs) | ||
| res += "outputs={}\n".format(v.cached_func.outputs) | ||
| res += "function: \n" | ||
| res += v.cached_func.funcs.astext() + "\n" | ||
| res += "===================================\n" | ||
| return res | ||
|
|
||
|
|
||
| def get(): | ||
| """Get the global compile engine. | ||
| """Get the global TE Compiler. | ||
|
|
||
| Returns | ||
| ------- | ||
| engine : tvm.relay.backend.CompileEngine | ||
| The compile engine. | ||
| engine : tvm.relay.backend.TECompiler | ||
| The TE Compiler. | ||
| """ | ||
| return _backend._CompileEngineGlobal() | ||
| return _backend._TECompilerGlobal() | ||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize there were so many uses of the dreaded global. Could you please file a JIRA issue to remove them? I suspect simply creating locally would be fine and this has been done just for 'efficiency'. If not we have bigger problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just filled a ticket on it. I did locally for a few test with no issues. So, after this on is merged. I can sent a followup PR unifying all usages.