Halide 22.0.0 Halide compiler and libraries

CostModel.h
Go to the documentation of this file.
1#ifndef COST_MODEL_H
2#define COST_MODEL_H
3
4#include <string>
5
6#include "FunctionDAG.h"
7#include "HalideBuffer.h"
8#include "PerfectHashMap.h"
9
10// An abstract base class for a cost model.
11 namespace Halide {
12
13 namespace Internal {
14 namespace Autoscheduler {
15
16 typedef PerfectHashMap<FunctionDAG::Node::Stage, ScheduleFeatures> StageMapOfScheduleFeatures;
17
18 struct Anderson2021Params {
19 /** Maximum level of parallelism available. */
20 int parallelism = 16;
21
22 /** Beam size to use in the beam search. Defaults to 32. Use 1 to get a greedy search instead.
23 * Formerly HL_BEAM_SIZE */
24 int beam_size = 32;
25
26 /** percent chance of accepting each state in the beam.
27 * Normalized by the number of decisions made, so 5 would be there's a 5 percent chance of never rejecting any states.
28 * Formerly HL_RANDOM_DROPOUT */
29 int random_dropout = 100;
30
31 /** Random seed used by the random dropout. If 0, use time().
32 * Formerly HL_SEED */
33 int64_t random_dropout_seed = 0;
34
35 /** When training or schedule, read weights from this directory or file.
36 * (If path ends in `.weights` it is written as a single file, otherwise a directory of files.)
37 * Formerly HL_WEIGHTS_DIR */
38 std::string weights_path;
39
40 /** If set to nonzero value: limits the search space to that of Mullapudi et al.
41 * Formerly HL_NO_SUBTILING */
42 int disable_subtiling = 0;
43
44 /** If set to nonzero value, only a random subset of the generated tilings for each stage will be accepted into the beam.
45 * Formerly HL_RANDOMIZE_TILINGS */
46 int randomize_tilings = 0;
47
48 /** Expects a string of four 0/1 values that allow/disallow the following options:
49 * compute root, inline, compute at the block level, compute at the thread level
50 * e.g. 1000 would allow compute root only
51 * Formerly HL_SEARCH_SPACE_OPTIONS */
52 std::string search_space_options = "1111";
53
54 /** If set to nonzero value, run a pre-pass where only compute_root and inline scheduling options are considered.
55 * Formerly HL_FREEZE_INLINE_COMPUTE_ROOT */
56 int freeze_inline_compute_root = 0;
57
58 /** If nonempty, load the initial (partial) schedule from the given file.
59 * Formerly PARTIAL_SCHEDULE */
60 std::string partial_schedule_path;
61
62 /** User-requested specific number of passes. Ignored if 0.
63 * Formerly HL_NUM_PASSES */
64 int num_passes = 0;
65
66 /** TODO: document me
67 * Formerly HL_STACK_FACTOR */
68 double stack_factor = 0.95f;
69
70 /** TODO: document me
71 * Formerly HL_SHARED_MEMORY_LIMIT */
72 int shared_memory_limit_kb = 48;
73
74 /** TODO: document me
75 * Formerly HL_SHARED_MEMORY_SM_LIMIT */
76 int shared_memory_sm_limit_kb = 96;
77
78 /** TODO: document me
79 * Formerly HL_ACTIVE_BLOCK_LIMIT */
80 int active_block_limit = 32;
81
82 /** TODO: document me
83 * Formerly HL_ACTIVE_WARP_LIMIT */
84 int active_warp_limit = 64;
85};
86
87} // namespace Autoscheduler
88} // namespace Internal
89
90 class CostModel {
91 public:
92 virtual ~CostModel() = default;
93
94 // Configure the cost model for the algorithm to be scheduled.
95 virtual void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag,
96 const Internal::Autoscheduler::Anderson2021Params &params) = 0;
97
98 // Enqueue a schedule to be evaluated. Will annotate the value located at cost_ptr when the evaluation takes place.
99 // Note that the dag argument should correspond to the dag specified previously when calling set_pipeline_features.
100 virtual void enqueue(const Internal::Autoscheduler::FunctionDAG &dag,
101 const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats,
102 double *cost_ptr,
103 std::vector<double> *cost_per_stage_ptr) = 0;
104
105 // Evaluate all schedules in the queue.
106 virtual void evaluate_costs() = 0;
107
108 // Discard all schedules in the queue.
109 virtual void reset() = 0;
110};
111
112} // namespace Halide
113
114#endif // COST_MODEL_H
HalideBuffer.h
Defines a Buffer type that wraps from halide_buffer_t and adds functionality, and methods for more co...
PerfectHashMap.h
FunctionDAG.h
Halide::CostModel
Definition: CostModel.h:61
Halide::CostModel::set_pipeline_features
virtual void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag, const Internal::Autoscheduler::Anderson2021Params &params)=0
Halide::CostModel::~CostModel
virtual ~CostModel()=default
Halide::CostModel::enqueue
virtual void enqueue(const Internal::Autoscheduler::FunctionDAG &dag, const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats, double *cost_ptr, std::vector< double > *cost_per_stage_ptr)=0
Halide::CostModel::reset
virtual void reset()=0
Halide::CostModel::evaluate_costs
virtual void evaluate_costs()=0
PerfectHashMap
Definition: PerfectHashMap.h:38
Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures
PerfectHashMap< FunctionDAG::Node::Stage, ScheduleFeatures > StageMapOfScheduleFeatures
Definition: AutoSchedule.h:12
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.
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
Halide::Internal::Autoscheduler::Anderson2021Params
Definition: CostModel.h:18
Halide::Internal::Autoscheduler::Anderson2021Params::random_dropout
int random_dropout
percent chance of accepting each state in the beam.
Definition: CostModel.h:29
Halide::Internal::Autoscheduler::Anderson2021Params::shared_memory_limit_kb
int shared_memory_limit_kb
TODO: document me Formerly HL_SHARED_MEMORY_LIMIT.
Definition: CostModel.h:72
Halide::Internal::Autoscheduler::Anderson2021Params::randomize_tilings
int randomize_tilings
If set to nonzero value, only a random subset of the generated tilings for each stage will be accepte...
Definition: CostModel.h:46
Halide::Internal::Autoscheduler::Anderson2021Params::weights_path
std::string weights_path
When training or schedule, read weights from this directory or file.
Definition: CostModel.h:38
Halide::Internal::Autoscheduler::Anderson2021Params::parallelism
int parallelism
Maximum level of parallelism available.
Definition: CostModel.h:20
Halide::Internal::Autoscheduler::Anderson2021Params::num_passes
int num_passes
User-requested specific number of passes.
Definition: CostModel.h:64
Halide::Internal::Autoscheduler::Anderson2021Params::search_space_options
std::string search_space_options
Expects a string of four 0/1 values that allow/disallow the following options: compute root,...
Definition: CostModel.h:52
Halide::Internal::Autoscheduler::Anderson2021Params::freeze_inline_compute_root
int freeze_inline_compute_root
If set to nonzero value, run a pre-pass where only compute_root and inline scheduling options are con...
Definition: CostModel.h:56
Halide::Internal::Autoscheduler::Anderson2021Params::shared_memory_sm_limit_kb
int shared_memory_sm_limit_kb
TODO: document me Formerly HL_SHARED_MEMORY_SM_LIMIT.
Definition: CostModel.h:76
Halide::Internal::Autoscheduler::Anderson2021Params::stack_factor
double stack_factor
TODO: document me Formerly HL_STACK_FACTOR.
Definition: CostModel.h:68
Halide::Internal::Autoscheduler::Anderson2021Params::random_dropout_seed
int64_t random_dropout_seed
Random seed used by the random dropout.
Definition: CostModel.h:33
Halide::Internal::Autoscheduler::Anderson2021Params::beam_size
int beam_size
Beam size to use in the beam search.
Definition: CostModel.h:24
Halide::Internal::Autoscheduler::Anderson2021Params::disable_subtiling
int disable_subtiling
If set to nonzero value: limits the search space to that of Mullapudi et al.
Definition: CostModel.h:42
Halide::Internal::Autoscheduler::Anderson2021Params::active_block_limit
int active_block_limit
TODO: document me Formerly HL_ACTIVE_BLOCK_LIMIT.
Definition: CostModel.h:80
Halide::Internal::Autoscheduler::Anderson2021Params::partial_schedule_path
std::string partial_schedule_path
If nonempty, load the initial (partial) schedule from the given file.
Definition: CostModel.h:60
Halide::Internal::Autoscheduler::Anderson2021Params::active_warp_limit
int active_warp_limit
TODO: document me Formerly HL_ACTIVE_WARP_LIMIT.
Definition: CostModel.h:84
Halide::Internal::Autoscheduler::FunctionDAG
Definition: FunctionDAG.h:367