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 "Featurization.h"
7#include "FunctionDAG.h"
8#include "HalideBuffer.h"
9#include "PerfectHashMap.h"
10
11// An abstract base class for a cost model.
12 namespace Halide {
13
14 namespace Internal {
15 namespace Autoscheduler {
16
17 typedef PerfectHashMap<FunctionDAG::Node::Stage, ScheduleFeatures> StageMapOfScheduleFeatures;
18
19 struct Adams2019Params {
20 /** Maximum level of parallelism available. */
21 int parallelism = 16;
22
23 /** Beam size to use in the beam search. Defaults to 32. Use 1 to get a greedy search instead.
24 * Formerly HL_BEAM_SIZE */
25 int beam_size = 32;
26
27 /** percent chance of accepting each state in the beam.
28 * Normalized by the number of decisions made, so 5 would be there's a 5 percent chance of never rejecting any states.
29 * Formerly HL_RANDOM_DROPOUT */
30 int random_dropout = 100;
31
32 /** Random seed used by the random dropout. If 0, use time().
33 * Formerly HL_SEED */
34 int random_dropout_seed = 0;
35
36 /** When training or schedule, read weights from this directory or file.
37 * (If path ends in `.weights` it is written as a single file, otherwise a directory of files.)
38 * Formerly HL_WEIGHTS_DIR */
39 std::string weights_path;
40
41 /** If set to nonzero value: limits the search space to that of Mullapudi et al.
42 * Formerly HL_NO_SUBTILING */
43 int disable_subtiling = 0;
44
45 /** If set to nonzero value: features of possible schedules are always recalculated, and are not cached across passes.
46 * Formerly HL_DISABLE_MEMOIZED_FEATURES */
47 int disable_memoized_features = 0;
48
49 /** If set to nonzero value: tiling sizes are not cached across passes.
50 * Formerly HL_DISABLE_MEMOIZED_BLOCKS */
51 int disable_memoized_blocks = 0;
52
53 /** If >= 0, only consider schedules that allocate at most this much memory (measured in bytes).
54 * Formerly HL_AUTOSCHEDULE_MEMORY_LIMIT */
55 int64_t memory_limit = -1;
56};
57
58} // namespace Autoscheduler
59} // namespace Internal
60
61 class CostModel {
62 public:
63 virtual ~CostModel() = default;
64
65 // Configure the cost model for the algorithm to be scheduled.
66 virtual void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag,
67 const Internal::Autoscheduler::Adams2019Params &params) = 0;
68
69 // Enqueue a schedule to be evaluated. Will annotate the value located at cost_ptr when the evaluation takes place.
70 // Note that the dag argument should correspond to the dag specified previously when calling set_pipeline_features.
71 virtual void enqueue(const Internal::Autoscheduler::FunctionDAG &dag,
72 const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats,
73 double *cost_ptr) = 0;
74
75 // Evaluate all schedules in the queue.
76 virtual void evaluate_costs() = 0;
77
78 // Discard all schedules in the queue.
79 virtual void reset() = 0;
80};
81
82} // namespace Halide
83
84#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
Featurization.h
FunctionDAG.h
Halide::CostModel
Definition: CostModel.h:61
Halide::CostModel::~CostModel
virtual ~CostModel()=default
Halide::CostModel::reset
virtual void reset()=0
Halide::CostModel::enqueue
virtual void enqueue(const Internal::Autoscheduler::FunctionDAG &dag, const Halide::Internal::Autoscheduler::StageMapOfScheduleFeatures &schedule_feats, double *cost_ptr)=0
Halide::CostModel::evaluate_costs
virtual void evaluate_costs()=0
Halide::CostModel::set_pipeline_features
virtual void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag, const Internal::Autoscheduler::Adams2019Params &params)=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::Adams2019Params
Definition: CostModel.h:19
Halide::Internal::Autoscheduler::Adams2019Params::weights_path
std::string weights_path
When training or schedule, read weights from this directory or file.
Definition: CostModel.h:39
Halide::Internal::Autoscheduler::Adams2019Params::disable_memoized_blocks
int disable_memoized_blocks
If set to nonzero value: tiling sizes are not cached across passes.
Definition: CostModel.h:51
Halide::Internal::Autoscheduler::Adams2019Params::random_dropout
int random_dropout
percent chance of accepting each state in the beam.
Definition: CostModel.h:30
Halide::Internal::Autoscheduler::Adams2019Params::disable_subtiling
int disable_subtiling
If set to nonzero value: limits the search space to that of Mullapudi et al.
Definition: CostModel.h:43
Halide::Internal::Autoscheduler::Adams2019Params::beam_size
int beam_size
Beam size to use in the beam search.
Definition: CostModel.h:25
Halide::Internal::Autoscheduler::Adams2019Params::memory_limit
int64_t memory_limit
If >= 0, only consider schedules that allocate at most this much memory (measured in bytes).
Definition: CostModel.h:55
Halide::Internal::Autoscheduler::Adams2019Params::disable_memoized_features
int disable_memoized_features
If set to nonzero value: features of possible schedules are always recalculated, and are not cached a...
Definition: CostModel.h:47
Halide::Internal::Autoscheduler::Adams2019Params::random_dropout_seed
int random_dropout_seed
Random seed used by the random dropout.
Definition: CostModel.h:34
Halide::Internal::Autoscheduler::Adams2019Params::parallelism
int parallelism
Maximum level of parallelism available.
Definition: CostModel.h:21
Halide::Internal::Autoscheduler::FunctionDAG
Definition: FunctionDAG.h:367