Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MetaSchedule]
Union
and OrderedUnion
Database
Following up apache#12520 and apache#12626, this PR introduces two database classes: `UnionDatabase` and `OrderedUnionDatabase`, both of which allow users to organically compose multiple databases together, so that the high-level IR (Relay, Relax) could select the best tuning records according to running time or a preferred order given by users. To each query, `UnionDatabase` returns the best record among all the databases given; Instead, `OrderedUnionDatabase` returns he record from the first database that responds to the query. Used together, users may specify complicated dispatching patterns like below: Examples below demonstrate the usecases of and difference between UnionDatabase and OrderDatabase. Assumption: * db1, db2 do not have tuning records for the target workload. * Each of db3, db4, db5 has tuning records r3, r4, r5 for target workload respectively. ```python #### Case 1. `UnionDatabase`: merged_db = ms.database.UnionDatabase( db1, # no record db2, # no record db3, # has r3 db4 # has r4 ) # returns the better one between r3 and r4 merged_db.query_tuning_record(..., target_workload) ### Case 2. `OrderedUnionDatabase` merged_db = ms.database.OrderedUnionDatabase( db1, # no record db2, # no record db3, # has r3 db4 # has r4 ) # returns r3 merged_db.query_tuning_record(..., target_workload) ### Case 3. Mix-use scenario merged_db = ms.database.UnionDatabase( db1, # no record db2, # no record db3, # has r3 ms.database.OrderedUnionDatabase( # returns r4 db4, # has r4 db5, # has r5 ) ) # returns the better one between r3 and r4 merged_db.query_tuning_record(..., target_workload) ### Case 4. Another mix-use scenario merged_db = ms.database.UnionDatabase( db1, # no record db2, # no record db3, # has r3 ms.database.UnionDatabase( # returns the better one between r4 and r5 db4, # has r4 db5, # has r5 ) ) # returns the best one among r3, r4 and r5 merged_db.query_tuning_record(..., target_workload) ### Case 5. Yet another mix-use scenario merged_db = ms.database.OrderedUnionDatabase( db1, # no record db2, # no record ms.database.UnionDatabase( # returns the better one between r3 and r4 db3, # has r3 db4, # has r4 ) db5, # has r5 ) # returns the better one between r3 and r4 merged_db.query_tuning_record(..., target_workload) ``` Co-authored-by: sunggg <49998730+sunggg@users.noreply.github.com> # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Sat Aug 27 17:36:54 2022 -0700 # # On branch feature/2022-08-27/merged-database # Your branch and 'origin/feature/2022-08-27/merged-database' have diverged, # and have 1 and 1 different commits each, respectively. # (use "git pull" to merge the remote branch into yours) # # Changes to be committed: # modified: include/tvm/meta_schedule/database.h # modified: python/tvm/meta_schedule/database/__init__.py # new file: python/tvm/meta_schedule/database/ordered_union_database.py # new file: python/tvm/meta_schedule/database/union_database.py # modified: src/meta_schedule/database/json_database.cc # new file: src/meta_schedule/database/ordered_union_database.cc # new file: src/meta_schedule/database/union_database.cc # modified: src/meta_schedule/utils.h # modified: tests/python/unittest/test_link_params.py # modified: tests/python/unittest/test_meta_schedule_database.py # # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Sat Aug 27 17:36:54 2022 -0700 # # On branch feature/2022-08-27/merged-database # Your branch and 'origin/feature/2022-08-27/merged-database' have diverged, # and have 1 and 1 different commits each, respectively. # (use "git pull" to merge the remote branch into yours) # # Changes to be committed: # modified: include/tvm/meta_schedule/database.h # modified: python/tvm/meta_schedule/database/__init__.py # new file: python/tvm/meta_schedule/database/ordered_union_database.py # new file: python/tvm/meta_schedule/database/union_database.py # modified: src/meta_schedule/database/json_database.cc # new file: src/meta_schedule/database/ordered_union_database.cc # new file: src/meta_schedule/database/union_database.cc # modified: src/meta_schedule/utils.h # modified: tests/python/unittest/test_link_params.py # modified: tests/python/unittest/test_meta_schedule_database.py # # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Sat Aug 27 17:36:54 2022 -0700 # # On branch feature/2022-08-27/merged-database # Your branch and 'origin/feature/2022-08-27/merged-database' have diverged, # and have 1 and 1 different commits each, respectively. # (use "git pull" to merge the remote branch into yours) # # Changes to be committed: # modified: include/tvm/meta_schedule/database.h # modified: python/tvm/meta_schedule/database/__init__.py # new file: python/tvm/meta_schedule/database/ordered_union_database.py # new file: python/tvm/meta_schedule/database/union_database.py # modified: src/meta_schedule/database/json_database.cc # new file: src/meta_schedule/database/ordered_union_database.cc # new file: src/meta_schedule/database/union_database.cc # modified: src/meta_schedule/utils.h # modified: tests/python/unittest/test_link_params.py # modified: tests/python/unittest/test_meta_schedule_database.py #
- Loading branch information