-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathfind_controls.hpp
179 lines (150 loc) · 5.66 KB
/
find_controls.hpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*******************************************************************************
*
* MIT License
*
* Copyright (c) 2017 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GUARD_MIOPEN_FIND_CONTROLS_HPP_
#define GUARD_MIOPEN_FIND_CONTROLS_HPP_
#include <miopen/logger.hpp>
#include <miopen/solver_id.hpp>
#include <miopen/miopen.h>
#include <boost/optional.hpp>
#include <ostream>
namespace miopen {
namespace debug {
/// Disable MIOPEN_FIND_ENFORCE. Intended for debugging/testing purposes.
/// Currently used during warm-up phase in MIOpenDriver.
/// WARNING: This switch is not intended for use in multi-threaded applications.
MIOPEN_EXPORT extern bool
FindEnforceDisable; // NOLINT (cppcoreguidelines-avoid-non-const-global-variables)
} // namespace debug
enum class FindEnforceAction
{
First_ = 1, // 0 is returned for non-numeric env.vars.
None = First_,
DbUpdate,
Search,
SearchDbUpdate,
DbClean,
Last_ = DbClean,
Default_ = None,
EnforcedFirst_ = DbUpdate, // This range must be continuous.
EnforcedLast_ = DbClean,
};
class MIOPEN_INTERNALS_EXPORT FindEnforce
{
FindEnforceAction action;
private:
template <class Context>
bool IsEnabled(const Context& context) const
{
return !(context.disable_search_enforce || debug::FindEnforceDisable);
}
public:
FindEnforce();
explicit FindEnforce(FindEnforceAction action_) : action(action_) {}
template <class Context>
bool IsDbClean(const Context& context) const
{
return IsEnabled(context) && action == FindEnforceAction::DbClean;
}
template <class Context>
bool IsSearch(const Context& context) const
{
return IsEnabled(context) &&
(action == FindEnforceAction::Search || action == FindEnforceAction::SearchDbUpdate);
}
template <class Context>
bool IsDbUpdate(const Context& context) const
{
return IsEnabled(context) && (action == FindEnforceAction::DbUpdate ||
action == FindEnforceAction::SearchDbUpdate);
}
template <class Context>
bool IsSomethingEnforced(const Context& context) const
{
return IsEnabled(context) && (FindEnforceAction::EnforcedFirst_ <= action &&
action <= FindEnforceAction::EnforcedLast_);
}
MIOPEN_INTERNALS_EXPORT friend std::ostream& operator<<(std::ostream&, const FindEnforce&);
};
MIOPEN_INTERNALS_EXPORT boost::optional<std::vector<solver::Id>> GetEnvFindOnlySolver();
class MIOPEN_INTERNALS_EXPORT FindMode
{
public:
enum class Values
{
Begin_ = 1, // 0 is returned for non-numeric env.vars.
Normal = miopenConvolutionFindModeNormal,
Fast = miopenConvolutionFindModeFast,
Hybrid = miopenConvolutionFindModeHybrid,
DeprecatedFastHybrid = 4,
DynamicHybrid = miopenConvolutionFindModeDynamicHybrid,
TrustVerify = miopenConvolutionFindModeTrustVerify,
End_,
Default_ = miopenConvolutionFindModeDefault,
};
private:
Values value;
template <class Context>
bool IsEnabled(const Context& context) const
{
if(FindEnforce{}.IsSomethingEnforced(context))
{
MIOPEN_LOG_NQI("MIOPEN_FIND_MODE is set to NORMAL due to MIOPEN_FIND_ENFORCE");
return false;
}
return true;
}
public:
// Todo: remove default value of primitive
FindMode(solver::Primitive primitive = solver::Primitive::Convolution);
Values Get() const { return value; }
void Set(Values const v) { value = v; }
template <class Context>
bool IsFast(const Context& context) const
{
return value == Values::Fast && IsEnabled(context);
}
template <class Context>
bool IsHybrid(const Context& context) const
{
return (value == Values::Hybrid || value == Values::DynamicHybrid ||
value == Values::TrustVerify) &&
IsEnabled(context);
}
template <class Context>
bool IsDynamicHybrid(const Context& context) const
{
return (value == Values::DynamicHybrid || value == Values::TrustVerify) &&
IsEnabled(context);
}
template <class Context>
bool IsTrustVerify(const Context& context) const
{
return value == Values::TrustVerify && IsEnabled(context);
}
MIOPEN_INTERNALS_EXPORT friend std::ostream& operator<<(std::ostream&, const FindMode&);
};
} // namespace miopen
#endif // GUARD_MIOPEN_FIND_CONTROLS_HPP_