Skip to content

Commit ab67e5f

Browse files
committed
[MetaSchedule][Refactor] Clarify Integration Logic
1 parent 534205b commit ab67e5f

20 files changed

+544
-570
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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_
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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_EXTRACTED_TASK_H_
20+
#define TVM_META_SCHEDULE_EXTRACTED_TASK_H_
21+
22+
#include <tvm/target/target.h>
23+
24+
namespace tvm {
25+
namespace meta_schedule {
26+
27+
/*! \brief A tuning task extracted from the high-level IR */
28+
class ExtractedTaskNode : public runtime::Object {
29+
public:
30+
/*! \brief The name of the task extracted */
31+
String task_name;
32+
/*! \brief The high-level IR */
33+
IRModule mod;
34+
/*! \brief Target */
35+
Target target;
36+
/*! \brief A list of low-level IRs that the high-level IR could potentially dispatch to */
37+
Array<IRModule> dispatched;
38+
/*! \brief Weight of the task */
39+
int weight;
40+
41+
void VisitAttrs(AttrVisitor* v) {
42+
v->Visit("task_name", &task_name);
43+
v->Visit("mod", &mod);
44+
v->Visit("target", &target);
45+
v->Visit("dispatched", &dispatched);
46+
v->Visit("weight", &weight);
47+
}
48+
49+
static constexpr const char* _type_key = "meta_schedule.ExtractedTask";
50+
TVM_DECLARE_FINAL_OBJECT_INFO(ExtractedTaskNode, runtime::Object);
51+
};
52+
53+
/*!
54+
* \brief Managed reference to ExtractedTaskNode
55+
* \sa ExtractedTaskNode
56+
*/
57+
class ExtractedTask : public runtime::ObjectRef {
58+
public:
59+
explicit ExtractedTask(String task_name, IRModule mod, Target target, Array<IRModule> dispatched,
60+
int weight);
61+
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(ExtractedTask, runtime::ObjectRef,
62+
ExtractedTaskNode);
63+
};
64+
65+
} // namespace meta_schedule
66+
} // namespace tvm
67+
68+
#endif // TVM_META_SCHEDULE_EXTRACTED_TASK_H_

include/tvm/meta_schedule/integration.h

Lines changed: 0 additions & 190 deletions
This file was deleted.

python/tvm/meta_schedule/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
cost_model,
2222
database,
2323
feature_extractor,
24-
integration,
2524
mutator,
2625
postproc,
2726
runner,
2827
schedule_rule,
2928
search_strategy,
3029
space_generator,
3130
)
31+
from .apply_history_best import ApplyHistoryBest
32+
from .extracted_task import ExtractedTask
33+
from .relay_integration import extract_task_from_relay
3234
from .search_strategy import MeasureCandidate
3335
from .tune import (
3436
EvolutionarySearchConfig,

0 commit comments

Comments
 (0)