junrushao commented on code in PR #12628: URL: https://github.com/apache/tvm/pull/12628#discussion_r958077539
########## 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: In fact it's not doable. Consider a case where there could be mocked databases like ScheduleFnDatabase -- 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]
