Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
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 namespace Internal {
11 namespace Autoscheduler {
12 struct Adams2019Params;
13} // namespace Autoscheduler
14} // namespace Internal
15
16 class DefaultCostModel : public CostModel {
17 private:
18 Internal::Weights weights;
19 Runtime::Buffer<float> schedule_feat_queue, pipeline_feat_queue, costs;
20 Runtime::Buffer<double *> cost_ptrs;
21 int cursor, num_stages, num_cores;
22
23 const std::string weights_in_path, weights_out_path;
24 const bool randomize_weights;
25
26 Runtime::Buffer<float>
27 head1_filter_update, head1_bias_update,
28 head2_filter_update, head2_bias_update,
29 conv1_filter_update, conv1_bias_update;
30 int timestep = 0;
31
32 public:
33 DefaultCostModel(const std::string &weights_in_path,
34 const std::string &weights_out_path,
35 bool randomize_weights)
36 : weights_in_path(weights_in_path),
37 weights_out_path(weights_out_path),
38 randomize_weights(randomize_weights) {
39
40 load_weights();
41 }
42 ~DefaultCostModel() override = default;
43
44 // Configure the cost model for the algorithm to be scheduled.
45 void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag,
46 const Internal::Autoscheduler::Adams2019Params &params) override;
47 void set_pipeline_features(const Runtime::Buffer<float> &, int n);
48
49 // Enqueue a schedule to be evaluated. The second version of this method returns a buffer of
50 // schedule_features that should be filled in by the caller.
51 void enqueue(const Internal::Autoscheduler::FunctionDAG &dag,
52 const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats,
53 double *cost_ptr) override;
54 void enqueue(int ns, Runtime::Buffer<float> *schedule_feats, double *cost_ptr);
55
56 // Evaluate all schedules in the queue.
57 void evaluate_costs() override;
58
59 // Discard all schedules in the queue.
60 void reset() override;
61
62 // Update model weights using true measured runtimes.
63 float backprop(const Runtime::Buffer<const float> &true_runtimes, float learning_rate);
64
65 // Save/Load the model weights to/from disk.
66 void save_weights();
67 void load_weights();
68};
69
70std::unique_ptr<DefaultCostModel> make_default_cost_model(const std::string &weights_in_dir = "",
71 const std::string &weights_out_dir = "",
72 bool randomize_weights = false);
73} // namespace Halide
74
75#endif // DEFAULT_COST_MODEL_H
CostModel.h
Weights.h
Halide::CostModel
Definition CostModel.h:61
Halide::DefaultCostModel
Definition DefaultCostModel.h:16
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:33
Halide::DefaultCostModel::backprop
float backprop(const Runtime::Buffer< const float > &true_runtimes, float learning_rate)
Halide::DefaultCostModel::set_pipeline_features
void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag, const Internal::Autoscheduler::Adams2019Params &params) override
Halide::DefaultCostModel::load_weights
void load_weights()
Halide::DefaultCostModel::set_pipeline_features
void set_pipeline_features(const Runtime::Buffer< float > &, int n)
Halide::DefaultCostModel::reset
void reset() override
Halide::DefaultCostModel::enqueue
void enqueue(const Internal::Autoscheduler::FunctionDAG &dag, const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats, double *cost_ptr) override
Halide::DefaultCostModel::~DefaultCostModel
~DefaultCostModel() override=default
Halide::DefaultCostModel::enqueue
void enqueue(int ns, Runtime::Buffer< float > *schedule_feats, double *cost_ptr)
Halide::DefaultCostModel::evaluate_costs
void evaluate_costs() override
Halide::Runtime::Buffer
A templated Buffer class that wraps halide_buffer_t and adds functionality.
Definition HalideBuffer.h:222
PerfectHashMap
Definition PerfectHashMap.h:38
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
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::Internal::Autoscheduler::Adams2019Params
Definition CostModel.h:19
Halide::Internal::Autoscheduler::FunctionDAG
Definition FunctionDAG.h:367
Halide::Internal::Weights
Definition Weights.h:15