MasterJH5574 commented on code in PR #12628:
URL: https://github.com/apache/tvm/pull/12628#discussion_r957985876
##########
include/tvm/meta_schedule/database.h:
##########
@@ -357,6 +357,18 @@ class Database : public runtime::ObjectRef {
*/
TVM_DLL static Database JSONDatabase(String path_workload, String
path_tuning_record,
bool allow_missing);
+ /*!
+ * \brief Create a database merged from multiple databases.
+ * \param preferred The preferred database. If the preferred database
responses to a query,
+ * all other databases will be ignored.
+ * \param databases The databases to be merged.
+ * \param fallback The fallback databases. If all the databases didn't
answer a query,
+ * the fallback databases will be used.
+ * \return The merged database.
+ */
+ TVM_DLL static Database MergedDatabase(Array<Database, void> preferred,
+ Array<Database, void> databases,
+ Array<Database, void> fallback);
Review Comment:
Just curious, what is the second template parameter `void` used for?
##########
src/meta_schedule/database/merged_database.cc:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+#include "../utils.h"
+
+namespace tvm {
+namespace meta_schedule {
+
+class MergedDatabaseNode : public DatabaseNode {
+ public:
+ Array<Database> preferred;
+ Array<Database> databases;
+ Array<Database> fallback;
+
+ void VisitAttrs(AttrVisitor* v) {
+ v->Visit("preferred", &preferred);
+ v->Visit("databases", &databases);
+ v->Visit("fallback", &fallback);
+ }
+
+ static constexpr const char* _type_key = "meta_schedule.MergedDatabase";
+ TVM_DECLARE_FINAL_OBJECT_INFO(MergedDatabaseNode, DatabaseNode);
+
+ public:
+ Optional<TuningRecord> QueryTuningRecord(const IRModule& mod, const Target&
target,
+ const String& task_name) final {
+ for (const Database& db : preferred) {
+ if (Optional<TuningRecord> record = db->QueryTuningRecord(mod, target,
task_name)) {
+ return record;
+ }
+ }
+ std::vector<TuningRecord> results;
+ results.reserve(databases.size());
+ for (const Database& db : databases) {
+ if (Optional<TuningRecord> record = db->QueryTuningRecord(mod, target,
task_name)) {
+ ICHECK(record.value()->run_secs.defined());
+ results.push_back(record.value());
+ }
+ }
+ std::sort(results.begin(), results.end(), SortTuningRecordByMeanRunSecs());
+ if (!results.empty()) {
+ return results[0];
+ }
+ for (const Database& db : fallback) {
+ if (Optional<TuningRecord> record = db->QueryTuningRecord(mod, target,
task_name)) {
+ return record;
+ }
+ }
+ return NullOpt;
+ }
+
+ bool HasWorkload(const IRModule& mod) final {
+ LOG(FATAL) << "NotImplementedError: MergedDatabase.HasWorkload";
Review Comment:
Hmmmm... At least I think this is doable. Just there isn’t such need?
##########
include/tvm/meta_schedule/database.h:
##########
@@ -357,6 +357,18 @@ class Database : public runtime::ObjectRef {
*/
TVM_DLL static Database JSONDatabase(String path_workload, String
path_tuning_record,
bool allow_missing);
+ /*!
+ * \brief Create a database merged from multiple databases.
+ * \param preferred The preferred database. If the preferred database
responses to a query,
+ * all other databases will be ignored.
+ * \param databases The databases to be merged.
+ * \param fallback The fallback databases. If all the databases didn't
answer a query,
+ * the fallback databases will be used.
Review Comment:
Is there any inclusion hierarchy among the three inputs? From the current
C++ documents, my understanding is that `databases` must contains all databases
in `preferred` and `fallback`. But the documents and example on Python side
obviously doesn’t prove my understanding correct. Would it be a good idea to
tell a bit about their relation?
##########
tests/python/unittest/test_link_params.py:
##########
@@ -412,17 +412,12 @@ def schedule_fn(sch):
return True
return False
- link_params = True
-
Review Comment:
What’s the impact of the PR on this file :eyes:?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]