|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +#ifndef TVM_META_SCHEDULE_APPLY_HISTORY_BEST_H_ |
| 20 | +#define TVM_META_SCHEDULE_APPLY_HISTORY_BEST_H_ |
| 21 | + |
| 22 | +#include <tvm/meta_schedule/database.h> |
| 23 | +#include <tvm/target/target.h> |
| 24 | + |
| 25 | +namespace tvm { |
| 26 | +namespace meta_schedule { |
| 27 | + |
| 28 | +/*! |
| 29 | + * \brief An integration context that allows application of historically best records from a |
| 30 | + * database |
| 31 | + */ |
| 32 | +class ApplyHistoryBestNode : public runtime::Object { |
| 33 | + public: |
| 34 | + /*! \brief The database to be queried from */ |
| 35 | + Database database{nullptr}; |
| 36 | + |
| 37 | + void VisitAttrs(AttrVisitor* v) { v->Visit("database", &database); } |
| 38 | + /*! |
| 39 | + * \brief Query the best entry from the database |
| 40 | + * \param task_name The name of the task to be queried |
| 41 | + * \param mod The module to be queried |
| 42 | + * \param target The target to be queried |
| 43 | + * \param dispatched The IRs after dispatch |
| 44 | + */ |
| 45 | + Optional<IRModule> Query(runtime::String task_name, IRModule mod, Target target, |
| 46 | + Optional<Array<IRModule>> dispatched); |
| 47 | + |
| 48 | + static constexpr const char* _type_key = "meta_schedule.ApplyHistoryBest"; |
| 49 | + TVM_DECLARE_FINAL_OBJECT_INFO(ApplyHistoryBestNode, runtime::Object); |
| 50 | +}; |
| 51 | + |
| 52 | +/*! |
| 53 | + * \brief Managed reference to ApplyHistoryBestNode |
| 54 | + * \sa ApplyHistoryBestNode |
| 55 | + */ |
| 56 | +class ApplyHistoryBest : public runtime::ObjectRef { |
| 57 | + public: |
| 58 | + /*! |
| 59 | + * \brief Constructor |
| 60 | + * \param database The database to be queried from |
| 61 | + */ |
| 62 | + explicit ApplyHistoryBest(Database database); |
| 63 | + /*! |
| 64 | + * \brief The current ApplyHistoryBest in the context |
| 65 | + * \return The ApplyHistoryBest in the current scope. |
| 66 | + */ |
| 67 | + static Optional<ApplyHistoryBest> Current(); |
| 68 | + |
| 69 | + TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(ApplyHistoryBest, runtime::ObjectRef, |
| 70 | + ApplyHistoryBestNode); |
| 71 | + |
| 72 | + protected: |
| 73 | + friend class ApplyHistoryBestInternal; |
| 74 | + /*! \brief Entering the scope of the context manager */ |
| 75 | + void EnterWithScope(); |
| 76 | + /*! \brief Exiting the scope of the context manager */ |
| 77 | + void ExitWithScope(); |
| 78 | +}; |
| 79 | + |
| 80 | +} // namespace meta_schedule |
| 81 | +} // namespace tvm |
| 82 | + |
| 83 | +#endif // TVM_META_SCHEDULE_APPLY_HISTORY_BEST_H_ |
0 commit comments