forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostproc.cc
128 lines (114 loc) · 5.02 KB
/
postproc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* 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 {
void PyPostprocNode::InitializeWithTuneContext(const TuneContext& context) {
ICHECK(f_initialize_with_tune_context != nullptr)
<< "PyPostproc's InitializeWithTuneContext method not implemented!";
f_initialize_with_tune_context(context);
}
bool PyPostprocNode::Apply(const tir::Schedule& sch) {
ICHECK(f_apply != nullptr) << "PyPostproc's Apply method not implemented!";
return f_apply(sch);
}
Postproc PyPostprocNode::Clone() const {
ICHECK(f_clone != nullptr) << "PyPostproc's Clone method not implemented!";
return f_clone();
}
Postproc Postproc::PyPostproc(
PyPostprocNode::FInitializeWithTuneContext f_initialize_with_tune_context, //
PyPostprocNode::FApply f_apply, //
PyPostprocNode::FClone f_clone, //
PyPostprocNode::FAsString f_as_string) {
ObjectPtr<PyPostprocNode> n = make_object<PyPostprocNode>();
n->f_initialize_with_tune_context = std::move(f_initialize_with_tune_context);
n->f_apply = std::move(f_apply);
n->f_clone = std::move(f_clone);
n->f_as_string = std::move(f_as_string);
return Postproc(n);
}
Array<Postproc> Postproc::DefaultLLVM() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(),
Postproc::RewriteParallelVectorizeUnroll(),
Postproc::RewriteReductionBlock(),
Postproc::RewriteLayout(),
};
}
Array<Postproc> Postproc::DefaultVNNI() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(), Postproc::RewriteParallelVectorizeUnroll(),
Postproc::RewriteReductionBlock(), Postproc::RewriteTensorize(/*vectorize_init_loop=*/true),
Postproc::RewriteLayout(),
};
}
Array<Postproc> Postproc::DefaultCUDA() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(),
Postproc::RewriteCooperativeFetch(),
Postproc::RewriteUnboundBlock(/*max_threadblocks=*/256),
Postproc::RewriteParallelVectorizeUnroll(),
Postproc::RewriteReductionBlock(),
Postproc::VerifyGPUCode(),
};
}
Array<Postproc> Postproc::DefaultCUDATensorCore() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(),
Postproc::RewriteCooperativeFetch(),
Postproc::RewriteUnboundBlock(/*max_threadblocks=*/256),
Postproc::RewriteParallelVectorizeUnroll(),
Postproc::RewriteReductionBlock(),
Postproc::VerifyGPUCode(),
// RewriteTensorize is relatively expensive and it doesn't affect the validity of a sample, so
// run it only on samples that have passed VerifyGPUCode.
Postproc::RewriteTensorize(/*vectorize_init_loop=*/false),
};
}
Array<Postproc> Postproc::DefaultHexagon() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(), Postproc::RewriteParallelVectorizeUnroll(),
Postproc::RewriteReductionBlock(), Postproc::RewriteLayout(),
Postproc::VerifyVTCMLimit(),
};
}
TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
.set_dispatch<PyPostprocNode>([](const ObjectRef& n, ReprPrinter* p) {
const auto* self = n.as<PyPostprocNode>();
ICHECK(self);
PyPostprocNode::FAsString f_as_string = (*self).f_as_string;
ICHECK(f_as_string != nullptr) << "PyPostproc's AsString method not implemented!";
p->stream << f_as_string();
});
TVM_REGISTER_OBJECT_TYPE(PostprocNode);
TVM_REGISTER_NODE_TYPE(PyPostprocNode);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocInitializeWithTuneContext")
.set_body_method<Postproc>(&PostprocNode::InitializeWithTuneContext);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocApply").set_body_method<Postproc>(&PostprocNode::Apply);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocClone").set_body_method<Postproc>(&PostprocNode::Clone);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocPyPostproc").set_body_typed(Postproc::PyPostproc);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocDefaultLLVM").set_body_typed(Postproc::DefaultLLVM);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocDefaultCUDA").set_body_typed(Postproc::DefaultCUDA);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocDefaultCUDATensorCore")
.set_body_typed(Postproc::DefaultCUDATensorCore);
TVM_REGISTER_GLOBAL("meta_schedule.PostprocDefaultHexagon")
.set_body_typed(Postproc::DefaultHexagon);
} // namespace meta_schedule
} // namespace tvm