Skip to content

Commit

Permalink
remove all TVMTimeScope
Browse files Browse the repository at this point in the history
  • Loading branch information
junrushao committed Jun 13, 2022
1 parent 4f7f5d4 commit 5e33189
Show file tree
Hide file tree
Showing 23 changed files with 244 additions and 372 deletions.
2 changes: 0 additions & 2 deletions include/tvm/meta_schedule/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define TVM_META_SCHEDULE_BUILDER_H_

#include <tvm/ir/module.h>
#include <tvm/meta_schedule/profiler.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/container/array.h>
#include <tvm/runtime/container/map.h>
Expand Down Expand Up @@ -151,7 +150,6 @@ class PyBuilderNode : public BuilderNode {
}

Array<BuilderResult> Build(const Array<BuilderInput>& build_inputs) final {
TVMTimeScope(PyBuilderNode::Build);
ICHECK(f_build != nullptr) << "PyBuilder's Build method not implemented!";
return f_build(build_inputs);
}
Expand Down
6 changes: 0 additions & 6 deletions include/tvm/meta_schedule/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <tvm/ir/expr.h>
#include <tvm/ir/module.h>
#include <tvm/meta_schedule/arg_info.h>
#include <tvm/meta_schedule/profiler.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/container/array.h>
#include <tvm/runtime/container/string.h>
Expand Down Expand Up @@ -254,32 +253,27 @@ class PyDatabaseNode : public DatabaseNode {
}

bool HasWorkload(const IRModule& mod) final {
TVMTimeScope(PyDatabaseNode::HasWorkload);
ICHECK(f_has_workload != nullptr) << "PyDatabase's HasWorkload method not implemented!";
return f_has_workload(mod);
}

Workload CommitWorkload(const IRModule& mod) final {
TVMTimeScope(PyDatabaseNode::CommitWorkload);
ICHECK(f_commit_workload != nullptr) << "PyDatabase's CommitWorkload method not implemented!";
return f_commit_workload(mod);
}

void CommitTuningRecord(const TuningRecord& record) final {
TVMTimeScope(PyDatabaseNode::CommitTuningRecord);
ICHECK(f_commit_tuning_record != nullptr)
<< "PyDatabase's CommitTuningRecord method not implemented!";
f_commit_tuning_record(record);
}

Array<TuningRecord> GetTopK(const Workload& workload, int top_k) final {
TVMTimeScope(PyDatabaseNode::GetTopK);
ICHECK(f_get_top_k != nullptr) << "PyDatabase's GetTopK method not implemented!";
return f_get_top_k(workload, top_k);
}

int64_t Size() final {
TVMTimeScope(PyDatabaseNode::Size);
ICHECK(f_size != nullptr) << "PyDatabase's Size method not implemented!";
return f_size();
}
Expand Down
2 changes: 0 additions & 2 deletions include/tvm/meta_schedule/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include <utility>
#include <vector>

#define TVMTimeScope(x) ScopedTimer timer = ProfilerNode::TimeScope(#x)

namespace tvm {
namespace meta_schedule {

Expand Down
4 changes: 0 additions & 4 deletions include/tvm/meta_schedule/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <tvm/ir/expr.h>
#include <tvm/meta_schedule/arg_info.h>
#include <tvm/meta_schedule/profiler.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/container/array.h>
#include <tvm/runtime/container/optional.h>
Expand Down Expand Up @@ -133,7 +132,6 @@ class RunnerFutureNode : public runtime::Object {
* \return A boolean indicating whether the runner has finished.
*/
bool Done() const {
TVMTimeScope(PyRunnerFutureNode::Done);
ICHECK(f_done != nullptr) << "PyRunnerFuture's Done method not implemented!";
return f_done();
}
Expand All @@ -142,7 +140,6 @@ class RunnerFutureNode : public runtime::Object {
* \return The runner's output.
*/
RunnerResult Result() const {
TVMTimeScope(PyRunnerFutureNode::Result);
ICHECK(f_result != nullptr) << "PyRunnerFuture's Result method not implemented!";
return f_result();
}
Expand Down Expand Up @@ -223,7 +220,6 @@ class PyRunnerNode : public RunnerNode {
}

Array<RunnerFuture> Run(Array<RunnerInput> runner_inputs) final {
TVMTimeScope(PyRunner::Run);
ICHECK(f_run != nullptr) << "PyRunner's Run method not implemented!";
return f_run(runner_inputs);
}
Expand Down
53 changes: 21 additions & 32 deletions src/meta_schedule/apply_history_best.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,31 @@ Optional<IRModule> ApplyHistoryBestNode::Query(runtime::String task_name, IRModu
Optional<Array<IRModule>> dispatched) {
IRModule prim_mod;
GlobalVar gv;
{
TVMTimeScope(ApplyHistoryBestNode::Query);
ICHECK(dispatched.defined());
ICHECK_EQ(dispatched.value().size(), 1);
ICHECK(HasOnlyOneFunction<relay::Function>(mod)) << mod;
prim_mod = dispatched.value()[0];
ICHECK(HasOnlyOneFunction<tir::PrimFunc>(prim_mod)) << prim_mod;

// Keep the original func name to be returned later.
gv = GetOnlyOneFunctionKey<tir::PrimFunc>(prim_mod).value();

// Unify func name to make sure it can be found in database
const auto* parse_mod_func = runtime::Registry::Get("tvm.meta_schedule.tune.parse_mod");
ICHECK(parse_mod_func) << "Parse mod function not defined!";
prim_mod = (*parse_mod_func)(prim_mod);
}
ICHECK(dispatched.defined());
ICHECK_EQ(dispatched.value().size(), 1);
ICHECK(HasOnlyOneFunction<relay::Function>(mod)) << mod;
prim_mod = dispatched.value()[0];
ICHECK(HasOnlyOneFunction<tir::PrimFunc>(prim_mod)) << prim_mod;
// Keep the original func name to be returned later.
gv = GetOnlyOneFunctionKey<tir::PrimFunc>(prim_mod).value();
// Unify func name to make sure it can be found in database
const auto* parse_mod_func = runtime::Registry::Get("tvm.meta_schedule.tune.parse_mod");
ICHECK(parse_mod_func) << "Parse mod function not defined!";
prim_mod = (*parse_mod_func)(prim_mod);
if (database->HasWorkload(prim_mod)) {
Array<TuningRecord> records = database->GetTopK(database->CommitWorkload(prim_mod), 1);
{
TVMTimeScope(ApplyHistoryBestNode::Query);
if (records.size() == 1) {
tir::Schedule sch =
tir::Schedule::Traced(records[0]->workload->mod, /*seed=*/-1, /*debug_mask=*/0,
/*error_render_level=*/tir::ScheduleErrorRenderLevel::kNone);
records[0]->trace->ApplyToSchedule(sch, false);
tir::PrimFunc func = GetOnlyOneFunction<tir::PrimFunc>(sch->mod()).value();
// Make sure we return the updated PrimFunc paired with the original func name.
return IRModule({{gv, func}});
}
if (records.size() == 1) {
tir::Schedule sch =
tir::Schedule::Traced(records[0]->workload->mod, /*seed=*/-1, /*debug_mask=*/0,
/*error_render_level=*/tir::ScheduleErrorRenderLevel::kNone);
records[0]->trace->ApplyToSchedule(sch, false);
tir::PrimFunc func = GetOnlyOneFunction<tir::PrimFunc>(sch->mod()).value();
// Make sure we return the updated PrimFunc paired with the original func name.
return IRModule({{gv, func}});
}
}
{
TVMTimeScope(ApplyHistoryBestNode::Query);
TVM_PY_LOG(WARNING, logging_func) << "Cannot find workload: " << task_name;
return NullOpt;
}
TVM_PY_LOG(WARNING, logging_func) << "Cannot find workload: " << task_name;
return NullOpt;
}

TVM_REGISTER_NODE_TYPE(ApplyHistoryBestNode);
Expand Down
4 changes: 0 additions & 4 deletions src/meta_schedule/cost_model/cost_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,23 @@ namespace tvm {
namespace meta_schedule {

void PyCostModelNode::Load(const String& path) {
TVMTimeScope(PyCostModelNode::Load);
ICHECK(f_load != nullptr) << "PyCostModel's Load method not implemented!";
f_load(path);
}

void PyCostModelNode::Save(const String& path) {
TVMTimeScope(PyCostModelNode::Save);
ICHECK(f_save != nullptr) << "PyCostModel's Save method not implemented!";
f_save(path);
}

void PyCostModelNode::Update(const TuneContext& context, const Array<MeasureCandidate>& candidates,
const Array<RunnerResult>& results) {
TVMTimeScope(PyCostModelNode::Update);
ICHECK(f_update != nullptr) << "PyCostModel's Update method not implemented!";
f_update(context, candidates, results);
}

std::vector<double> PyCostModelNode::Predict(const TuneContext& context,
const Array<MeasureCandidate>& candidates) {
TVMTimeScope(PyCostModelNode::Predict);
ICHECK(f_predict != nullptr) << "PyCostModel's Predict method not implemented!";
std::vector<double> result(candidates.size(), 0.0);
f_predict(context, candidates, result.data());
Expand Down
9 changes: 1 addition & 8 deletions src/meta_schedule/database/json_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ class JSONDatabaseNode : public DatabaseNode {

public:
bool HasWorkload(const IRModule& mod) {
TVMTimeScope(JSONDatabaseNode::HasWorkload);
return workloads2idx_.find(Workload(mod, tvm::StructuralHash()(mod))) != workloads2idx_.end();
}

Workload CommitWorkload(const IRModule& mod) {
TVMTimeScope(JSONDatabaseNode::CommitWorkload);
// Try to insert `mod` into `workloads_`
decltype(this->workloads2idx_)::iterator it;
bool inserted = false;
Expand All @@ -131,7 +129,6 @@ class JSONDatabaseNode : public DatabaseNode {
}

void CommitTuningRecord(const TuningRecord& record) {
TVMTimeScope(JSONDatabaseNode::CommitTuningRecord);
this->tuning_records_.insert(record);
JSONFileAppendLine(this->path_tuning_record,
JSONDumps(Array<ObjectRef>{
Expand All @@ -141,7 +138,6 @@ class JSONDatabaseNode : public DatabaseNode {
}

Array<TuningRecord> GetTopK(const Workload& workload, int top_k) {
TVMTimeScope(JSONDatabaseNode::GetTopK);
CHECK_GE(top_k, 0) << "ValueError: top_k must be non-negative";
if (top_k == 0) {
return {};
Expand All @@ -160,10 +156,7 @@ class JSONDatabaseNode : public DatabaseNode {
return results;
}

int64_t Size() {
TVMTimeScope(JSONDatabaseNode::Size);
return tuning_records_.size();
}
int64_t Size() { return tuning_records_.size(); }
};

Database Database::JSONDatabase(String path_workload, String path_tuning_record,
Expand Down
1 change: 0 additions & 1 deletion src/meta_schedule/feature_extractor/feature_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace meta_schedule {

Array<tvm::runtime::NDArray> PyFeatureExtractorNode::ExtractFrom(
const TuneContext& context, const Array<MeasureCandidate>& candidates) {
TVMTimeScope(PyFeatureExtractorNode::ExtractFrom);
ICHECK(f_extract_from != nullptr) << "PyFeatureExtractor's ExtractFrom method not implemented!";
return f_extract_from(context, candidates);
}
Expand Down
1 change: 0 additions & 1 deletion src/meta_schedule/feature_extractor/per_store_feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,6 @@ class PerStoreFeatureNode : public FeatureExtractorNode {

Array<runtime::NDArray> ExtractFrom(const TuneContext& tune_context,
const Array<MeasureCandidate>& candidates) {
TVMTimeScope(PerStoreFeatureNode::ExtractFrom);
bool is_gpu = tune_context->target.value()->kind->name == "cuda";
std::vector<runtime::NDArray> results;
results.resize(candidates.size());
Expand Down
1 change: 0 additions & 1 deletion src/meta_schedule/measure_callback/add_to_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AddToDatabaseNode : public MeasureCallbackNode {
const Array<MeasureCandidate>& measure_candidates,
const Array<BuilderResult>& builder_results,
const Array<RunnerResult>& runner_results) final {
TVMTimeScope(AddToDatabaseNode::Apply);
if (!task_scheduler->database.defined()) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/meta_schedule/measure_callback/echo_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class EchoStatisticsNode : public MeasureCallbackNode {
const Array<MeasureCandidate>& measure_candidates,
const Array<BuilderResult>& builder_results,
const Array<RunnerResult>& runner_results) final {
TVMTimeScope(EchoStatisticsNode::Apply);
if (this->task_info.empty()) {
SetupTaskInfo(task_scheduler->tasks);
}
Expand Down
1 change: 0 additions & 1 deletion src/meta_schedule/measure_callback/measure_callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void PyMeasureCallbackNode::Apply(const TaskScheduler& task_scheduler,
const Array<MeasureCandidate>& measure_candidates, //
const Array<BuilderResult>& builds, //
const Array<RunnerResult>& results) {
TVMTimeScope(PyMeasureCallbackNode::Apply);
ICHECK(f_apply != nullptr) << "PyMeasureCallback's Apply method not implemented!";
return f_apply(task_scheduler, task_id, measure_candidates, builds, results);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class RemoveBuildArtifactNode : public MeasureCallbackNode {
const Array<MeasureCandidate>& measure_candidates,
const Array<BuilderResult>& builder_results,
const Array<RunnerResult>& runner_results) final {
TVMTimeScope(RemoveBuildArtifactNode::Apply);
static const PackedFunc* f_rm = runtime::Registry::Get("meta_schedule.remove_build_dir");
for (const BuilderResult& build_result : builder_results) {
if (Optional<String> path = build_result->artifact_path) {
Expand Down
1 change: 0 additions & 1 deletion src/meta_schedule/measure_callback/update_cost_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class UpdateCostModelNode : public MeasureCallbackNode {
const Array<MeasureCandidate>& measure_candidates,
const Array<BuilderResult>& builder_results,
const Array<RunnerResult>& runner_results) final {
TVMTimeScope(UpdateCostModelNode::Apply);
TuneContext task = task_scheduler->tasks[task_id];
ICHECK(task_scheduler->cost_model.defined()) //
<< "Cost model must be defined for the task scheduler!";
Expand Down

0 comments on commit 5e33189

Please sign in to comment.