Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parameters.h
Go to the documentation of this file.
1 
16 #pragma once
17 #include <functional>
18 #include <memory>
19 #include <vector>
20 
22 #include "tc/core/utils/memory.h"
23 
24 #include <llvm/ADT/Optional.h>
25 
26 namespace tc {
27 namespace autotune {
28 
29 class ParameterView;
30 
32  public:
33  BoolParameter(const std::string& name);
34  BoolParameter() = default;
37 
38  size_t numberOptions() const;
39  void selectOption(size_t idx);
40  void selectValue(bool val);
41  void fixValue(bool val);
42 
43  void apply(const std::function<void(ParameterView&)>& f);
44 
45  bool value() const;
46 
47  std::string name;
48 
49  private:
50  friend class ParameterView;
51  bool value_;
52  llvm::Optional<bool> fixedValue_;
53 };
54 
56  public:
57  RangeParameter(std::vector<size_t> values, const std::string& name);
59  RangeParameter() = default;
61 
62  size_t numberOptions() const;
63  void selectOption(size_t idx);
64  void selectFromValue(size_t v);
65  void fixValue(size_t v);
66  size_t value() const;
67 
68  void apply(const std::function<void(ParameterView&)>& f);
69 
70  std::string name;
71 
72  private:
73  friend class ParameterView;
74  size_t selected_ = 0;
75  std::vector<size_t> values_;
76  llvm::Optional<size_t> fixedValue_;
77 };
78 
80  public:
83 
84  size_t numberOptions() const;
85  void selectOption(size_t idx);
86  void overwrite(const ParameterView&);
87  bool isForced() const;
88 
89  private:
92 };
93 
95  public:
97 
98  void fromMappingOptions(const SchedulerOptionsView& options);
99  void applyToMappingOptions(SchedulerOptionsView& options) const;
100 
101  void apply(const std::function<void(ParameterView&)>& f);
102  std::vector<ParameterView> collectParameters();
103 
105  // BoolParameter allowSkewing;
106  // BoolParameter positiveOrthant;
107 };
108 
110  protected:
111  void setRange(
112  size_t minDims,
113  size_t maxDims,
114  const std::string& name,
115  std::vector<size_t>& values,
116  const std::string& dimBaseName);
117 
118  public:
119  void apply(const std::function<void(ParameterView&)>& f);
120  std::vector<ParameterView> collectParameters();
122  std::vector<RangeParameter> dims;
123 };
124 
126  public:
127  void setRange(size_t maxDims, std::vector<size_t>& values);
128  void fromMappingOptions(const TilingView& options);
129  void applyToMappingOptions(TilingView& options) const;
130 
133 };
134 
136  public:
137  void setRange(
138  std::vector<size_t>& values,
139  const std::string& dimensionBaseName);
140  void fromMappingOptions(const CudaDimView& options);
141  void applyToMappingOptions(CudaDimView& options) const;
142 
145 };
146 
148 
150  public:
151  void applyToParameters(const std::function<void(ParameterView&)>& f);
152  std::vector<ParameterView> collectParameters();
153 
156  TuningConfiguration(const TuningConfiguration&) = default;
158 
159  void fromMappingOptions(const MappingOptions& options);
160  void applyToMappingOptions(MappingOptions& options) const;
161 
162  void addValidator(std::function<bool(const TuningConfiguration&)> v);
163  bool isValid() const;
164 
165  void fixParameters(const TuningParameterFixer& fixedParams);
166 
167  friend std::ostream& operator<<(
168  std::ostream& os,
169  const TuningConfiguration& conf);
170 
183 
184  private:
185  std::vector<std::function<bool(const TuningConfiguration&)>> validators_;
186 };
187 
189  public:
191  const FusionStrategy& fs);
193  const FusionStrategy& fs);
196  TuningParameterFixer& fixTilingParameters(std::vector<size_t> vals);
197  TuningParameterFixer& fixBlockParameters(std::vector<size_t> vals);
198  TuningParameterFixer& fixGridParameters(std::vector<size_t> vals);
204 
205  private:
206  llvm::Optional<FusionStrategy> outerScheduleFusionStrategy;
207  llvm::Optional<FusionStrategy> intraTileScheduleFusionStrategy;
208  llvm::Optional<bool> fixParametersBeforeScheduling;
209  llvm::Optional<size_t> unrollFactor;
210  llvm::Optional<std::vector<size_t>> tilingParameters;
211  llvm::Optional<std::vector<size_t>> blockParameters;
212  llvm::Optional<std::vector<size_t>> gridParameters;
213  llvm::Optional<bool> tileImperfectlyNested;
214  llvm::Optional<bool> useSharedMemory;
215  llvm::Optional<bool> usePrivateMemory;
216  llvm::Optional<bool> unrollCopyShared;
217  llvm::Optional<bool> matchLibraryCalls;
218 
219  friend class TuningConfiguration;
220 };
221 
222 using TimePoint = std::chrono::high_resolution_clock::time_point;
223 using Duration = std::chrono::high_resolution_clock::duration;
224 
226  public:
228  const TuningConfiguration& config,
229  Duration d = Duration::zero(),
230  bool invalid = false)
231  : configuration(config),
232  runtime(d),
233  invalid(invalid),
234  optionalCompilationHandle(nullptr) {}
235 
237  : configuration(candidate.configuration),
238  runtime(candidate.runtime),
239  invalid(candidate.invalid),
241  candidate.optionalCompilationHandle
242  ? std::unique_ptr<size_t>(
243  new size_t(*candidate.optionalCompilationHandle))
244  : nullptr) {}
245 
247  CandidateConfiguration tmp(candidate);
248  std::swap(tmp, *this);
249  return *this;
250  }
251 
252  friend std::ostream& operator<<(
253  std::ostream& os,
254  const CandidateConfiguration& config) {
255  return os << config.configuration;
256  }
257 
260  bool invalid;
261  std::unique_ptr<size_t> optionalCompilationHandle;
262 };
263 
264 } // namespace autotune
265 } // namespace tc
TuningParameterFixer & fixUnrollFactor(size_t val)
Duration runtime
Definition: parameters.h:259
BoolParameter matchLibraryCalls
Definition: parameters.h:182
llvm::Optional< size_t > unrollFactor
Definition: parameters.h:209
llvm::Optional< bool > usePrivateMemory
Definition: parameters.h:215
BoolParameter unrollCopyShared
Definition: parameters.h:181
TuningParameterFixer & fixMatchLibraryCalls(bool val)
std::vector< size_t > values_
Definition: parameters.h:75
TuningParameterFixer & fixUnrollCopyShared(bool val)
TuningParameterFixer & fixFixParametersBeforeScheduling(bool val)
void setRange(size_t maxDims, std::vector< size_t > &values)
Definition: parameters.h:149
Definition: parameters.h:135
TuningParameterFixer & fixUseSharedMemory(bool val)
TuningParameterFixer & fixIntraTileScheduleFusionStrategy(const FusionStrategy &fs)
Definition: mapping_options.h:120
std::string name
Definition: parameters.h:70
std::chrono::high_resolution_clock::time_point TimePoint
Definition: parameters.h:222
CudaDimParameters blockParams
Definition: parameters.h:175
size_t numberOptions() const
void applyToMappingOptions(TilingView &options) const
std::vector< ParameterView > collectParameters()
void apply(const std::function< void(ParameterView &)> &f)
TuningParameterFixer & fixGridParameters(std::vector< size_t > vals)
llvm::Optional< bool > unrollCopyShared
Definition: parameters.h:216
llvm::Optional< FusionStrategy > outerScheduleFusionStrategy
Definition: parameters.h:206
void selectOption(size_t idx)
Definition: parameters.h:31
void applyToMappingOptions(CudaDimView &options) const
TuningParameterFixer & fixTilingParameters(std::vector< size_t > vals)
void fromMappingOptions(const SchedulerOptionsView &options)
RangeParameter * rangePtr
Definition: parameters.h:90
std::vector< ParameterView > collectParameters()
void apply(const std::function< void(ParameterView &)> &f)
BoolParameter & operator=(const BoolParameter &)
std::unique_ptr< size_t > optionalCompilationHandle
Definition: parameters.h:261
CandidateConfiguration(const TuningConfiguration &config, Duration d=Duration::zero(), bool invalid=false)
Definition: parameters.h:227
SchedulerOptionsParameters intraTileScheduleOptions
Definition: parameters.h:172
std::vector< ParameterView > collectParameters()
void applyToParameters(const std::function< void(ParameterView &)> &f)
std::vector< std::function< bool(const TuningConfiguration &)> > validators_
Definition: parameters.h:185
BoolParameter tileImperfectlyNested
Definition: parameters.h:178
llvm::Optional< bool > matchLibraryCalls
Definition: parameters.h:217
BoolParameter * boolPtr
Definition: parameters.h:91
SchedulerOptionsParameters outerScheduleOptions
Definition: parameters.h:171
TuningParameterFixer & fixUsePrivateMemory(bool val)
void fixParameters(const TuningParameterFixer &fixedParams)
void applyToMappingOptions(MappingOptions &options) const
TuningParameterFixer & fixOuterScheduleFusionStrategy(const FusionStrategy &fs)
Definition: mapping_options.h:336
CudaDimParameters gridParams
Definition: parameters.h:176
llvm::Optional< bool > tileImperfectlyNested
Definition: parameters.h:213
CandidateConfiguration & operator=(const CandidateConfiguration &candidate)
Definition: parameters.h:246
size_t numberOptions() const
size_t selected_
Definition: parameters.h:74
llvm::Optional< bool > fixParametersBeforeScheduling
Definition: parameters.h:208
void fromMappingOptions(const CudaDimView &options)
RangeParameter fusionStrategy
Definition: parameters.h:104
void applyToMappingOptions(SchedulerOptionsView &options) const
Definition: parameters.h:55
bool invalid
Definition: parameters.h:260
TilingParameters tilingParams
Definition: parameters.h:174
llvm::Optional< FusionStrategy > intraTileScheduleFusionStrategy
Definition: parameters.h:207
BoolParameter usePrivateMemory
Definition: parameters.h:180
void addValidator(std::function< bool(const TuningConfiguration &)> v)
TuningParameterFixer & fixTileImperfectlyNested(bool val)
void selectOption(size_t idx)
Definition: parameters.h:188
std::string name
Definition: parameters.h:47
void fromMappingOptions(const MappingOptions &options)
Definition: parameters.h:79
llvm::Optional< std::vector< size_t > > tilingParameters
Definition: parameters.h:210
TuningConfiguration & operator=(const TuningConfiguration &)=default
BoolParameter useSharedMemory
Definition: parameters.h:179
llvm::Optional< bool > fixedValue_
Definition: parameters.h:52
friend std::ostream & operator<<(std::ostream &os, const CandidateConfiguration &config)
Definition: parameters.h:252
friend std::ostream & operator<<(std::ostream &os, const TuningConfiguration &conf)
RangeParameter numberDims
Definition: parameters.h:121
size_t numberOptions() const
llvm::Optional< std::vector< size_t > > blockParameters
Definition: parameters.h:211
Definition: parameters.h:109
Definition: mapping_options.h:222
RangeParameter unrollFactor
Definition: parameters.h:177
bool value_
Definition: parameters.h:51
llvm::Optional< bool > useSharedMemory
Definition: parameters.h:214
void setRange(size_t minDims, size_t maxDims, const std::string &name, std::vector< size_t > &values, const std::string &dimBaseName)
Definition: parameters.h:94
void setRange(std::vector< size_t > &values, const std::string &dimensionBaseName)
llvm::Optional< size_t > fixedValue_
Definition: parameters.h:76
std::chrono::high_resolution_clock::duration Duration
Definition: parameters.h:223
TuningConfiguration configuration
Definition: parameters.h:258
CandidateConfiguration(const CandidateConfiguration &candidate)
Definition: parameters.h:236
Definition: mapping_options.h:278
void apply(const std::function< void(ParameterView &)> &f)
void overwrite(const ParameterView &)
Definition: parameters.h:125
void selectFromValue(size_t v)
void apply(const std::function< void(ParameterView &)> &f)
llvm::Optional< std::vector< size_t > > gridParameters
Definition: parameters.h:212
TuningParameterFixer & fixBlockParameters(std::vector< size_t > vals)
Definition: parameters.h:225
ParameterView(BoolParameter &)
std::vector< RangeParameter > dims
Definition: parameters.h:122
void selectOption(size_t idx)
void fromMappingOptions(const TilingView &options)
BoolParameter fixParametersBeforeScheduling
Definition: parameters.h:173
RangeParameter & operator=(const RangeParameter &)