Skip to content

Commit bdfd8e4

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tir-manual-schedule-api
2 parents c5ff0fe + daa0689 commit bdfd8e4

File tree

13 files changed

+253
-99
lines changed

13 files changed

+253
-99
lines changed

python/tvm/meta_schedule/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""Package `tvm.meta_schedule`. The meta schedule infrastructure."""
18-
from . import arg_info
19-
from . import database
20-
from . import builder
21-
from . import runner
22-
from . import mutator
23-
from . import postproc
24-
from . import schedule_rule
25-
from . import space_generator
26-
from . import search_strategy
27-
from . import integration
28-
from . import feature_extractor
29-
from . import cost_model
30-
from .search_strategy import (
18+
from . import (
19+
arg_info,
20+
builder,
21+
cost_model,
22+
database,
23+
feature_extractor,
24+
integration,
25+
mutator,
26+
postproc,
27+
runner,
28+
schedule_rule,
29+
search_strategy,
30+
space_generator,
31+
)
32+
from .search_strategy import MeasureCandidate
33+
from .tune import (
3134
EvolutionarySearchConfig,
32-
MeasureCandidate,
3335
ReplayFuncConfig,
3436
ReplayTraceConfig,
37+
tune_relay,
38+
tune_te,
39+
tune_tir,
3540
)
36-
from .tune import tune_te, tune_tir, tune_relay
3741
from .tune_context import TuneContext

python/tvm/meta_schedule/search_strategy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
to generate measure candidates.
2121
"""
2222

23-
from .search_strategy import SearchStrategy, PySearchStrategy, MeasureCandidate
24-
from .replay_trace import ReplayTrace, ReplayTraceConfig
25-
from .replay_func import ReplayFunc, ReplayFuncConfig
26-
from .evolutionary_search import EvolutionarySearch, EvolutionarySearchConfig
23+
from .evolutionary_search import EvolutionarySearch
24+
from .replay_func import ReplayFunc
25+
from .replay_trace import ReplayTrace
26+
from .search_strategy import MeasureCandidate, PySearchStrategy, SearchStrategy

python/tvm/meta_schedule/search_strategy/evolutionary_search.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""Evolutionary Search Strategy"""
18-
19-
from typing import NamedTuple
20-
2118
from tvm._ffi import register_object
2219

2320
from .. import _ffi_api
@@ -88,31 +85,3 @@ def __init__(
8885
genetic_max_fail_count,
8986
eps_greedy,
9087
)
91-
92-
93-
class EvolutionarySearchConfig(NamedTuple):
94-
"""Configuration for EvolutionarySearch"""
95-
96-
num_trials_per_iter: int
97-
max_trials_per_task: int
98-
max_trials_global: int
99-
population_size: int = 2048
100-
init_measured_ratio: float = 0.2
101-
init_min_unmeasured: int = 50
102-
genetic_num_iters: int = 4
103-
genetic_mutate_prob: float = 0.85
104-
genetic_max_fail_count: int = 10
105-
eps_greedy: float = 0.05
106-
107-
def create_strategy(self) -> EvolutionarySearch:
108-
return EvolutionarySearch(
109-
num_trials_per_iter=self.num_trials_per_iter,
110-
max_trials_per_task=self.max_trials_per_task,
111-
population_size=self.population_size,
112-
init_measured_ratio=self.init_measured_ratio,
113-
init_min_unmeasured=self.init_min_unmeasured,
114-
genetic_num_iters=self.genetic_num_iters,
115-
genetic_mutate_prob=self.genetic_mutate_prob,
116-
genetic_max_fail_count=self.genetic_max_fail_count,
117-
eps_greedy=self.eps_greedy,
118-
)

python/tvm/meta_schedule/search_strategy/replay_func.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""Replay Trace Search Strategy"""
18-
from typing import NamedTuple
19-
2018
from tvm._ffi import register_object
2119

2220
from .. import _ffi_api
@@ -34,7 +32,7 @@ class ReplayFunc(SearchStrategy):
3432
num_trials_per_iter : int
3533
Number of trials per iteration.
3634
max_trials_per_task : int
37-
Total number of trials.
35+
Total number of trials for one task
3836
"""
3937

4038
num_trials_per_iter: int
@@ -51,14 +49,3 @@ def __init__(
5149
num_trials_per_iter,
5250
max_trials_per_task,
5351
)
54-
55-
56-
class ReplayFuncConfig(NamedTuple):
57-
"""Configuration for ReplayFunc"""
58-
59-
num_trials_per_iter: int
60-
max_trials_per_task: int
61-
max_trials_global: int
62-
63-
def create_strategy(self) -> ReplayFunc:
64-
return ReplayFunc(self.num_trials_per_iter, self.max_trials_per_task)

python/tvm/meta_schedule/search_strategy/replay_trace.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""Replay Trace Search Strategy"""
18-
from typing import NamedTuple
19-
2018
from tvm._ffi import register_object
2119

2220
from .. import _ffi_api
@@ -34,7 +32,7 @@ class ReplayTrace(SearchStrategy):
3432
num_trials_per_iter : int
3533
Number of trials per iteration.
3634
max_trials_per_task : int
37-
Total number of trials.
35+
Total number of trials for one task
3836
"""
3937

4038
num_trials_per_iter: int
@@ -47,14 +45,3 @@ def __init__(self, num_trials_per_iter: int, max_trials_per_task: int):
4745
num_trials_per_iter,
4846
max_trials_per_task,
4947
)
50-
51-
52-
class ReplayTraceConfig(NamedTuple):
53-
"""Configuration for ReplayTrace"""
54-
55-
num_trials_per_iter: int
56-
max_trials_per_task: int
57-
max_trials_global: int
58-
59-
def create_strategy(self) -> ReplayTrace:
60-
return ReplayTrace(self.num_trials_per_iter, self.max_trials_per_task)

python/tvm/meta_schedule/tune.py

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# pylint: disable=import-outside-toplevel
1919
import logging
2020
import os.path
21-
from typing import Callable, Dict, List, Optional, Tuple, Union
21+
from typing import Callable, Dict, List, NamedTuple, Optional, Tuple, Union
2222

2323
from tvm._ffi.registry import register_func
2424
from tvm.ir import IRModule, structural_hash
@@ -40,23 +40,14 @@
4040
from .postproc import Postproc
4141
from .runner import LocalRunner, Runner
4242
from .schedule_rule import ScheduleRule
43-
from .search_strategy import (
44-
EvolutionarySearchConfig,
45-
ReplayFuncConfig,
46-
ReplayTraceConfig,
47-
)
43+
from .search_strategy import EvolutionarySearch, ReplayFunc, ReplayTrace
4844
from .space_generator import PostOrderApply, SpaceGenerator
4945
from .task_scheduler import GradientBased, TaskScheduler
5046
from .tune_context import TuneContext
5147
from .utils import autotvm_silencer
5248

5349
logger = logging.getLogger(__name__) # pylint: disable=invalid-name
5450

55-
SearchStrategyConfig = Union[
56-
ReplayFuncConfig,
57-
ReplayTraceConfig,
58-
EvolutionarySearchConfig,
59-
]
6051
FnSpaceGenerator = Callable[[], SpaceGenerator]
6152
FnScheduleRule = Callable[[], List[ScheduleRule]]
6253
FnPostproc = Callable[[], List[Postproc]]
@@ -75,6 +66,107 @@
7566
]
7667

7768

69+
class ReplayFuncConfig(NamedTuple):
70+
"""Configuration for ReplayFunc
71+
72+
Parameters
73+
----------
74+
num_trials_per_iter : int
75+
Number of trials per iteration.
76+
max_trials_per_task : int
77+
Total number of trials for one task
78+
max_trials_global : int
79+
Total number of trials for all tasks in the task scheduler
80+
"""
81+
82+
num_trials_per_iter: int
83+
max_trials_per_task: int
84+
max_trials_global: int
85+
86+
def create_strategy(self) -> ReplayFunc:
87+
return ReplayFunc(self.num_trials_per_iter, self.max_trials_per_task)
88+
89+
90+
class ReplayTraceConfig(NamedTuple):
91+
"""Configuration for ReplayTrace
92+
93+
Parameters
94+
----------
95+
num_trials_per_iter : int
96+
Number of trials per iteration.
97+
max_trials_per_task : int
98+
Total number of trials for one task
99+
max_trials_global : int
100+
Total number of trials for all tasks in the task scheduler
101+
"""
102+
103+
num_trials_per_iter: int
104+
max_trials_per_task: int
105+
max_trials_global: int
106+
107+
def create_strategy(self) -> ReplayTrace:
108+
return ReplayTrace(self.num_trials_per_iter, self.max_trials_per_task)
109+
110+
111+
class EvolutionarySearchConfig(NamedTuple):
112+
"""Configuration for EvolutionarySearch
113+
114+
Parameters
115+
----------
116+
num_trials_per_iter : int
117+
Number of trials per iteration.
118+
max_trials_per_task : int
119+
Total number of trials.
120+
max_trials_global : int
121+
Total number of trials for all tasks in the task scheduler
122+
population_size : int
123+
The initial population of traces from measured samples and randomly generated samples.
124+
init_measured_ratio : int
125+
The ratio of measured samples in the initial population.
126+
init_min_unmeasured : int
127+
The minimal size of unmeasured population in the initial sampling.
128+
genetic_num_iters : int
129+
The number of iterations for genetic algorithm.
130+
genetic_mutate_prob : float
131+
The probability of mutation.
132+
genetic_max_fail_count : int
133+
The maximum number to retry mutation.
134+
eps_greedy : float
135+
The ratio of greedy selected samples in the final picks.
136+
"""
137+
138+
num_trials_per_iter: int
139+
max_trials_per_task: int
140+
max_trials_global: int
141+
population_size: int = 2048
142+
init_measured_ratio: float = 0.2
143+
init_min_unmeasured: int = 50
144+
genetic_num_iters: int = 4
145+
genetic_mutate_prob: float = 0.85
146+
genetic_max_fail_count: int = 10
147+
eps_greedy: float = 0.05
148+
149+
def create_strategy(self) -> EvolutionarySearch:
150+
return EvolutionarySearch(
151+
num_trials_per_iter=self.num_trials_per_iter,
152+
max_trials_per_task=self.max_trials_per_task,
153+
population_size=self.population_size,
154+
init_measured_ratio=self.init_measured_ratio,
155+
init_min_unmeasured=self.init_min_unmeasured,
156+
genetic_num_iters=self.genetic_num_iters,
157+
genetic_mutate_prob=self.genetic_mutate_prob,
158+
genetic_max_fail_count=self.genetic_max_fail_count,
159+
eps_greedy=self.eps_greedy,
160+
)
161+
162+
163+
SearchStrategyConfig = Union[
164+
ReplayFuncConfig,
165+
ReplayTraceConfig,
166+
EvolutionarySearchConfig,
167+
]
168+
169+
78170
class DefaultLLVM:
79171
"""Default tuning configuration for LLVM."""
80172

src/meta_schedule/postproc/rewrite_unbound_block.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ BindType GetBindType(const StmtSRef& block_sref, int* fuse_first_num) {
6161
i_thread_idx = i;
6262
}
6363
}
64+
if (loop->kind != tir::ForKind::kSerial) {
65+
if (i_multi_child == -1) {
66+
i_multi_child = i;
67+
}
68+
}
6469
if (!IsSingleStmt(loop->body)) {
6570
if (i_multi_child == -1) {
6671
i_multi_child = i + 1;

src/runtime/hexagon/hexagon/hexagon_buffer.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,19 @@ class HexagonBuffer {
9494
//! \brief Prevent move assignment.
9595
HexagonBuffer& operator=(HexagonBuffer&&) = delete;
9696

97-
/*! \brief Return data pointer
98-
*
99-
* The return type depends on the buffer being
97+
/*! \brief Return data pointer into the buffer
98+
*
99+
* The returned pointer is intended for use as the runtime value
100+
* corresponding to the `Var BufferNode::data` of a buffer. The
101+
* return type depends on the dimensionality of the buffer being
102+
* accessed, and must be compatible with the usage defined in
103+
* `CodeGenHexagon::CreateBufferPtr`.
104+
*
105+
* For a 1-d buffer, this pointer can be cast to a `T*` and accessed
106+
* as a 1-d array (e.g. `static_cast<int32_t*>(GetPointer())[i]`).
107+
* For a 2-d buffer, this pointer can be cast to a `T**` and
108+
* accessed as a 2-d array
109+
* (e.g. `static_cast<int32_t**>(GetPointer())[i][j]`).
100110
*/
101111
void* GetPointer();
102112

0 commit comments

Comments
 (0)