-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MetaSchedule] Developer Ergonomics Enhancement (#11622)
Per discussion with @Kathryn-cat - [x] Move `initialize_with_tune_context` as private API `_initialize_with_tune_context`, and encourage using `TuneContext.initialize` - [x] Instead of using bunch of import statements, encourage using `ms.xxx` as the prefix (e.g. `ms.database.MemoryDatabase`) to organize things better - [x] Move `DefaultLLVM`, `DefaultCUDA` to a separate file and make them more discoverable - [x] Move `DummyDatabase` to `tvm.meta_schedule.database.MemoryDatabase` given it's actually useful - [x] Delegate class members' methods in `TuneContext`, for example, having `TuneContext.generste_design_space` from `TuneContext.space_generator.generste_design_space` Next PR: - Allow using a string `"default"` in `TuneContext` as well as `tune_relay/tir/te` to quickly specify a set of target-specific rules - Add `TuneContext.tune` to allow directly tuning without task scheduler. - Enhance detection of `ScheduleFn` in `TuneContext` to make it easier for users to quickly try out template-driven scheduling on TIR. Co-Authored-By: Kathryn (Jinqi) Chen <[email protected]>
- Loading branch information
1 parent
ec24ae6
commit 6fca5c6
Showing
52 changed files
with
1,111 additions
and
886 deletions.
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
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
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,63 @@ | ||
# 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. | ||
"""A database that stores TuningRecords in memory""" | ||
from typing import List | ||
|
||
from ...ir import IRModule, structural_equal | ||
from ..utils import derived_object | ||
from .database import PyDatabase, TuningRecord, Workload | ||
|
||
|
||
@derived_object | ||
class MemoryDatabase(PyDatabase): | ||
"""An in-memory database based on python list for testing.""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.records = [] | ||
self.workload_reg = [] | ||
|
||
def has_workload(self, mod: IRModule) -> bool: | ||
for workload in self.workload_reg: | ||
if structural_equal(workload.mod, mod): | ||
return True | ||
return False | ||
|
||
def commit_tuning_record(self, record: TuningRecord) -> None: | ||
self.records.append(record) | ||
|
||
def commit_workload(self, mod: IRModule) -> Workload: | ||
for workload in self.workload_reg: | ||
if structural_equal(workload.mod, mod): | ||
return workload | ||
workload = Workload(mod) | ||
self.workload_reg.append(workload) | ||
return workload | ||
|
||
def get_top_k(self, workload: Workload, top_k: int) -> List[TuningRecord]: | ||
return list( | ||
filter( | ||
lambda x: x.workload == workload, | ||
sorted(self.records, key=lambda x: sum(x.run_secs) / len(x.run_secs)), | ||
) | ||
)[: int(top_k)] | ||
|
||
def __len__(self) -> int: | ||
return len(self.records) | ||
|
||
def print_results(self) -> None: | ||
print("\n".join([str(r) for r in self.records])) |
Oops, something went wrong.