-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Ansor][AutoTVM v2.0] Phase 0: Ansor minimum system for auto schedule generating #5962
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
7ee0902
Code migration Start (#1)
jcf94 9fcbf0b
Split transform_step out & Update more UTs (#3)
jcf94 f43e82f
Add search_task, measure and serialization (#4)
jcf94 e0a5ed5
Add MetaTileRewritePolicy (#5)
jcf94 359905a
Basic Python API for State (#6)
jcf94 2032a64
Add Python API: Measure & Task (#7)
jcf94 6b21dc6
Add ansor.auto_schedule() API; First AutoSchedule working version(#8)
jcf94 e52135f
Bug fix & Add python serialization API (#10)
jcf94 1fe6638
Improve code style, python wrapper and test cases (#11)
merrymercy 43d1530
fix unit tests
merrymercy f367d15
Add RPCRunner & OpenCL/CUDA test (#12)
jcf94 2bd6471
rebase to upstream/master
merrymercy c860f2c
Add Ansor basic tutorial (#13)
jcf94 f60d1a6
migrate feature extraction (#14)
merrymercy b839c0f
Add XGBModel & RPCRunnerWarpper (#15)
jcf94 cfe58d7
Migrate workload_registry.py (#16)
merrymercy 143ea45
add task scheduler (#17)
merrymercy ed075c2
Add conv2d cuda tutorial with workload registry (#18)
jcf94 74ec7d0
add tune_test.py (the old tune_wkl.py) (#19)
merrymercy cd0a516
Code refine for tune_test.py & Add a pre load callback (#20)
jcf94 3a24e49
Add python custom sketch rule (#21)
jcf94 a155c1f
Ansor Relay Integration (without layout rewrite) (#22)
minminsun 674027f
Add tune_op_subgraph.py & Some code clean for tune_network.py (#23)
jcf94 2f241ed
add explicit_unroll_max_extent (#25)
merrymercy 18d44b8
Add Index simplification & API update (#26)
jcf94 4ea6712
Update PreLoadMeasuredStates & Some bug fix (#27)
jcf94 6126cdb
Add tensorize step for loop_state (#31)
jcf94 c7364df
State python api update (#33)
jcf94 36cd9ef
kernel layout rewrite (#28)
minminsun 145e61c
[cache flush] port cache flush to ansor (#32)
FrozenGene 2c27816
Improve relay integration (#34)
merrymercy 0794875
Fix xgb error & Simplify dispatcher (#35)
merrymercy a4c4548
Rename "MetaTileRewritePolicy" to "SketchPolicy". (#36)
merrymercy 593a2c7
rebase
merrymercy 53bd591
Migrate all node::make to noderef's construct function (#37)
jcf94 8e53d12
Some lint fix & Recover the double constructor of tvm::PrimExpr (#39)
jcf94 cd5c5ad
Add MutateComputeLocation and MutateParallel in evolutionary search (…
merrymercy 5860191
Improve loop state python API (stage_tensors -> stage_ops) (#41)
merrymercy 14a19cd
ComputeDAG bug fix & Add Custom TensorCore Matmul Example (#42)
jcf94 b012e27
Rever Commits, Start to build minimum Ansor system
jcf94 d6d6b85
Code clean for minimum Ansor system
jcf94 4042cfa
Bug fix & Delete AccessAnalyzer
jcf94 7695def
Delete attachmap & Code clean
jcf94 0c200cd
Doc update
jcf94 9c35e50
Headfile update & Python doc update
jcf94 a015051
clang-format fix
jcf94 6823802
pylint fix
jcf94 a82dbb8
Update
jcf94 ac36c46
Doc update
jcf94 a62b1e0
Update
jcf94 3eac89d
Merge branch 'upstream_master' into upstream_0_new
jcf94 526cf42
Bug fix after code merge to the new master
jcf94 426ec82
clang-format fix
jcf94 907c17c
Update
jcf94 64f8f8d
Update
jcf94 1b16dd4
Update std::vector to Array; Update verbosity setting; Some commemts
jcf94 9fa897b
std::vector->Array & std::string->String
jcf94 f40c7af
Add init_state to ComputeDAG
jcf94 0a24daf
Update
jcf94 a45fd89
Update some unordered_map to Map
jcf94 bfc6663
clang-format fix
jcf94 eb02e77
Comments addressed
jcf94 cb2442f
Lint fix
jcf94 b1ca20c
Update
jcf94 49dbec6
Merge branch 'upstream_master' into upstream_0_new
jcf94 8add768
Update
jcf94 78e5313
Update
jcf94 546abbe
Update
jcf94 d418a57
Update
jcf94 8e1d65d
Update
jcf94 3a67a72
Update
jcf94 28a7b8f
Update
jcf94 1360b1b
Update
jcf94 52afe74
Rename ansor namespace to auto_schedule
jcf94 6a61fb6
Update
jcf94 3a4e5da
Rename ThreadPool to ParallelFor
jcf94 dbe019b
Add parallel_for
jcf94 1f1b878
Remove ThreadPool
jcf94 02fede9
Update python/tvm/auto_schedule/auto_schedule.py
merrymercy eea0989
trigger CI
merrymercy 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 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 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,34 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=unused-import, redefined-builtin | ||
""" Namespace for TVM Auto-scheduler. """ | ||
|
||
from . import compute_dag | ||
from . import measure | ||
from . import measure_record | ||
from . import loop_state | ||
from . import utils | ||
from . import workload_registry | ||
|
||
# Shortcut | ||
from .compute_dag import ComputeDAG | ||
from .auto_schedule import SearchTask, TuningOptions, HardwareParams, \ | ||
auto_schedule, EmptyPolicy | ||
from .measure import MeasureInput, LocalBuilder, LocalRunner | ||
from .measure_record import RecordToFile, RecordReader, load_best, \ | ||
load_records, save_records | ||
from .workload_registry import register_workload, make_workload_key |
This file contains 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,22 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
""" Register FFI APIs from C++ for the namespace tvm.auto_schedule. """ | ||
import tvm._ffi | ||
|
||
|
||
tvm._ffi._init_api("auto_schedule", __name__) |
This file contains 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,194 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
""" | ||
User interface for TVM Auto-scheduler. | ||
|
||
The basic schedule search process for TVM Auto-scheduler is designed to be: | ||
`Program sampling` -> `Performance Tuning`. | ||
|
||
In `Program sampling`, we use some predefined precise or heuristic rules to generate several | ||
initial schedules. Based on these initial starting points, we perform `Performance Tuning` which | ||
uses cost model based evolutionary search to select schedules with the best performance. | ||
|
||
Candidate schedules are measured against the specific hardware target. | ||
""" | ||
|
||
import tvm._ffi | ||
from tvm.runtime import Object | ||
from .measure import LocalBuilder, LocalRunner | ||
from . import _ffi_api | ||
|
||
|
||
@tvm._ffi.register_object("auto_schedule.HardwareParams") | ||
class HardwareParams(Object): | ||
""" The parameters of target hardware used to guide the search policy | ||
|
||
TODO(jcf94): This is considered to be merged with the new Target specification: | ||
https://discuss.tvm.ai/t/rfc-tvm-target-specification/6844 | ||
|
||
Parameters | ||
---------- | ||
num_cores : int | ||
The number of device cores. | ||
vector_unit_bytes : int | ||
The width of vector units in bytes. | ||
cache_line_bytes : int | ||
The size of cache line in bytes. | ||
""" | ||
def __init__(self, num_cores, vector_unit_bytes, cache_line_bytes): | ||
self.__init_handle_by_constructor__(_ffi_api.HardwareParams, num_cores, | ||
vector_unit_bytes, cache_line_bytes) | ||
|
||
|
||
@tvm._ffi.register_object("auto_schedule.SearchTask") | ||
class SearchTask(Object): | ||
""" The computation information and hardware parameters for a specific schedule search task. | ||
|
||
Parameters | ||
---------- | ||
dag : ComputeDAG | ||
The ComputeDAG for the corresponding compute declaration. | ||
workload_key : str | ||
The workload key for the corresponding compute declaration. | ||
target : tvm.target.Target | ||
The target device of this search task. | ||
target_host : Optional[tvm.target.Target] | ||
The target host device of this search task. | ||
hardware_params : Optional[HardwareParams] | ||
Hardware parameters used in this search task. | ||
""" | ||
def __init__(self, dag, workload_key, target, target_host=None, | ||
hardware_params=None): | ||
self.__init_handle_by_constructor__(_ffi_api.SearchTask, dag, | ||
workload_key, target, target_host, | ||
hardware_params) | ||
|
||
|
||
@tvm._ffi.register_object("auto_schedule.SearchPolicy") | ||
class SearchPolicy(Object): | ||
""" The base class of search policies. """ | ||
|
||
|
||
@tvm._ffi.register_object("auto_schedule.EmptyPolicy") | ||
class EmptyPolicy(SearchPolicy): | ||
""" This is an example empty search policy which will always generate | ||
the init state of ComputeDAG. | ||
""" | ||
def __init__(self): | ||
self.__init_handle_by_constructor__(_ffi_api.EmptyPolicy) | ||
|
||
|
||
@tvm._ffi.register_object("auto_schedule.TuningOptions") | ||
class TuningOptions(Object): | ||
""" This controls the options of performance tuning. | ||
|
||
Parameters | ||
---------- | ||
num_measure_trials: int = 0 | ||
The number of measurement trials. | ||
The search policy measures `num_measure_trials` schedules in total and returns the best one | ||
among them. | ||
With `num_measure_trials` == 0, the policy will do the schedule search but won't involve | ||
measurement. This can be used to get a runnable schedule quickly without auto-tuning. | ||
early_stopping: Optional[int] | ||
Stop the tuning early if getting no improvement after n measurements. | ||
num_measures_per_round: int = 64 | ||
The number of schedules to be measured at each search round. | ||
The whole schedule search process will try a total number of `num_measure_trials` in several | ||
rounds. | ||
verbose: int = 1 | ||
Verbosity level. 0 for silent, 1 to output information during schedule search. | ||
builder: Union[ProgramBuilder, str] = 'local' | ||
ProgramBuilder which builds the program. | ||
runner: Union[ProgramRunner, str] = 'local' | ||
ProgramRunner which runs the program and measures time costs. | ||
measure_callbacks: Optional[List[MeasureCallback]] | ||
Callback functions called after each measurement. | ||
Candidates: | ||
- auto_schedule.RecordToFile | ||
pre_search_callbacks: Optional[List[SearchCallback]] | ||
Callback functions called before the search process. | ||
Candidates: | ||
- auto_schedule.PreloadMeasuredStates | ||
- auto_schedule.PreloadCustomSketchRule | ||
TODO(jcf94): Add these implementation in later PRs. | ||
""" | ||
def __init__(self, num_measure_trials=0, early_stopping=None, num_measures_per_round=64, | ||
verbose=1, builder='local', runner='local', measure_callbacks=None, | ||
pre_search_callbacks=None): | ||
if isinstance(builder, str): | ||
if builder == 'local': | ||
builder = LocalBuilder() | ||
else: | ||
raise ValueError("Invalid builder: " + builder) | ||
elif not isinstance(builder, tvm.auto_schedule.measure.ProgramBuilder): | ||
raise ValueError("Invalid builder: " + builder + | ||
" . TuningOptions expects a ProgramBuilder or string.") | ||
|
||
if isinstance(runner, str): | ||
if runner == 'local': | ||
runner = LocalRunner() | ||
else: | ||
raise ValueError("Invalid runner: " + runner) | ||
elif not isinstance(runner, tvm.auto_schedule.measure.ProgramRunner): | ||
raise ValueError("Invalid runner: " + runner + | ||
" . TuningOptions expects a ProgramRunner or string.") | ||
|
||
self.__init_handle_by_constructor__( | ||
_ffi_api.TuningOptions, num_measure_trials, early_stopping if early_stopping else -1, | ||
num_measures_per_round, verbose, builder, runner, measure_callbacks, | ||
pre_search_callbacks) | ||
|
||
|
||
def auto_schedule(task, search_policy='default', tuning_options=None): | ||
""" Do auto scheduling for a computation declaration. | ||
|
||
The task parameter can be a `string` as workload_key, or directly | ||
passing a `SearchTask` as input. | ||
|
||
Parameters | ||
---------- | ||
task : SearchTask | ||
The SearchTask for the computation declaration. | ||
search_policy : Union[SearchPolicy, str] = 'default' | ||
The search policy to be used for schedule search. | ||
tuning_options : Optional[TuningOptions] | ||
Tuning and measurement options. | ||
|
||
Returns | ||
------- | ||
A `te.schedule` and the a list of `te.Tensor` to be used in `tvm.lower` or `tvm.build`. | ||
""" | ||
if not isinstance(task, SearchTask): | ||
raise ValueError("Invalid task: " + task + | ||
" . `auto_schedule.auto_schedule` expects a SearchTask.") | ||
|
||
if isinstance(search_policy, str): | ||
if search_policy == 'default': | ||
# TODO(jcf94): This is an example policy for minimum system, will be upgrated to | ||
# formal search policy later. | ||
search_policy = EmptyPolicy() | ||
else: | ||
raise ValueError("Invalid search policy: " + search_policy) | ||
elif not isinstance(search_policy, SearchPolicy): | ||
raise ValueError("Invalid search policy: " + search_policy + | ||
" . `auto_schedule.auto_schedule` expects a SearchPolicy or a string.") | ||
|
||
sch, tensors = _ffi_api.AutoSchedule(task, search_policy, | ||
tuning_options if tuning_options else TuningOptions()) | ||
return sch, tensors |
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.
should this folder be named auto_scheduler?
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.
The namespace is auto_schedule
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 think @MarisaKirisame means the namespace should be a noun. So auto_scheduler is better.
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.
That also works if we all agree, we can send a followup PR for it.
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.
Sent new PR for namespace renaming: #6059