Halide
DefaultCostModel.h
Go to the documentation of this file.
1 #ifndef DEFAULT_COST_MODEL_H
2 #define DEFAULT_COST_MODEL_H
3 
4 #include "CostModel.h"
5 #include "Weights.h"
6 #include <string>
7 
8 namespace Halide {
9 
10 class DefaultCostModel : public CostModel {
11 private:
12  Internal::Weights weights;
13  Runtime::Buffer<float> schedule_feat_queue, pipeline_feat_queue, costs;
14  Runtime::Buffer<double *> cost_ptrs;
15  int cursor, num_stages, num_cores;
16 
17  const std::string weights_in_path, weights_out_path;
18  const bool randomize_weights;
19 
21  head1_filter_update, head1_bias_update,
22  head2_filter_update, head2_bias_update,
23  conv1_filter_update, conv1_bias_update;
24  int timestep = 0;
25 
26 public:
27  DefaultCostModel(const std::string &weights_in_path,
28  const std::string &weights_out_path,
29  bool randomize_weights)
30  : weights_in_path(weights_in_path),
31  weights_out_path(weights_out_path),
32  randomize_weights(randomize_weights) {
33 
34  load_weights();
35  }
36  ~DefaultCostModel() override = default;
37 
38  // Configure the cost model for the algorithm to be scheduled.
40  const MachineParams &params) override;
41  void set_pipeline_features(const Runtime::Buffer<float> &, int n);
42 
43  // Enqueue a schedule to be evaluated. The second version of this method returns a buffer of
44  // schedule_features that should be filled in by the caller.
47  double *cost_ptr) override;
48  void enqueue(int ns, Runtime::Buffer<float> *schedule_feats, double *cost_ptr);
49 
50  // Evaluate all schedules in the queue.
51  void evaluate_costs() override;
52 
53  // Discard all schedules in the queue.
54  void reset() override;
55 
56  // Update model weights using true measured runtimes.
57  float backprop(const Runtime::Buffer<const float> &true_runtimes, float learning_rate);
58 
59  // Save/Load the model weights to/from disk.
60  void save_weights();
61  void load_weights();
62 };
63 
64 std::unique_ptr<DefaultCostModel> make_default_cost_model(const std::string &weights_in_dir = "",
65  const std::string &weights_out_dir = "",
66  bool randomize_weights = false);
67 } // namespace Halide
68 
69 #endif // DEFAULT_COST_MODEL_H
Halide::MachineParams
A struct representing the machine parameters to generate the auto-scheduled code for.
Definition: Pipeline.h:31
Halide::DefaultCostModel::set_pipeline_features
void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag, const MachineParams &params) override
Halide::DefaultCostModel::enqueue
void enqueue(const Internal::Autoscheduler::FunctionDAG &dag, const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats, double *cost_ptr) override
Halide::Internal::Autoscheduler::FunctionDAG
Definition: FunctionDAG.h:346
Halide::DefaultCostModel::backprop
float backprop(const Runtime::Buffer< const float > &true_runtimes, float learning_rate)
CostModel.h
Halide::DefaultCostModel::reset
void reset() override
Halide::DefaultCostModel::evaluate_costs
void evaluate_costs() override
Halide::make_default_cost_model
std::unique_ptr< DefaultCostModel > make_default_cost_model(const std::string &weights_in_dir="", const std::string &weights_out_dir="", bool randomize_weights=false)
Halide::DefaultCostModel::save_weights
void save_weights()
Halide::DefaultCostModel::DefaultCostModel
DefaultCostModel(const std::string &weights_in_path, const std::string &weights_out_path, bool randomize_weights)
Definition: DefaultCostModel.h:27
Weights.h
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::DefaultCostModel::~DefaultCostModel
~DefaultCostModel() override=default
Halide::CostModel
Definition: CostModel.h:19
Halide::Runtime::Buffer< float >
Halide::DefaultCostModel::load_weights
void load_weights()
Halide::DefaultCostModel
Definition: DefaultCostModel.h:10
PerfectHashMap
Definition: PerfectHashMap.h:38
Halide::Internal::Weights
Definition: Weights.h:15