Loading...
Searching...
No Matches
State.h
Go to the documentation of this file.
#ifndef STATE_H
#define STATE_H
#include "ASLog.h"
#include "Cache.h"
#include "CostModel.h"
#include "DefaultCostModel.h"
#include "Featurization.h"
#include "Halide.h"
#include "LoopNest.h"
#include "PerfectHashMap.h"
#include <map>
#include <utility>
namespace Halide {
namespace Internal {
namespace Autoscheduler {
// A struct representing an intermediate state in the tree search.
// It represents a partial schedule for some pipeline.
struct State {
mutable RefCount ref_count;
// The LoopNest this state corresponds to.
IntrusivePtr<const LoopNest> root;
// The parent that generated this state.
IntrusivePtr<const State> parent;
// Cost of this state, as evaluated by the cost model.
double cost = 0;
// Number of decisions made at this state (used for finding which DAG node to schedule).
int num_decisions_made = 0;
// Penalization is determined based on structural hash during beam search.
bool penalized = false;
// The C++ source code of the generated schedule for this State.
// Computed if `apply_schedule` is called.
string schedule_source;
// The number of times a cost is enqueued into the cost model,
// for all states.
static int cost_calculations;
State() = default;
State(const State &) = delete;
State(State &&) = delete;
void operator=(const State &) = delete;
void operator=(State &&) = delete;
// Compute a structural hash based on depth and num_decisions_made.
// Defers to root->structural_hash().
uint64_t structural_hash(int depth) const;
// Compute the featurization of this state (based on `root`),
// and store features in `features`. Defers to `root->compute_features()`.
void compute_featurization(const FunctionDAG &dag,
const Adams2019Params &params,
StageMap<ScheduleFeatures> *features,
const CachingOptions &cache_options);
// Calls `compute_featurization` and prints those features to `out`.
void save_featurization(const FunctionDAG &dag,
const Adams2019Params &params,
const CachingOptions &cache_options,
std::ostream &out);
// Performs some pruning to decide if this state is worth queuing in
// the cost_model. If it is, calls `cost_model->enqueue` and returns true,
// otherwise sets `cost` equal to a large value and returns false.
bool calculate_cost(const FunctionDAG &dag, const Adams2019Params &params,
CostModel *cost_model, const CachingOptions &cache_options,
int verbosity = 99);
// Make a child copy of this state. The loop nest is const (we
// make mutated copies of it, rather than mutating it), so we can
// continue to point to the same one and so this is a cheap
// operation.
IntrusivePtr<State> make_child() const;
// Generate the successor states to this state.
// If they are not pruned by `calculate_cost()`,
// then calls `accept_child()` on them.
void generate_children(const FunctionDAG &dag,
const Adams2019Params &params,
CostModel *cost_model,
std::function<void(IntrusivePtr<State> &&)> &accept_child,
Cache *cache) const;
// Dumps cost, the `root` LoopNest, and then `schedule_source` to `os`.
void dump(std::ostream &os) const;
// Apply the schedule represented by this state to a Halide
// Pipeline. Also generate source code for the schedule for the
// user to copy-paste to freeze this schedule as permanent artifact.
// Also fills `schedule_source`.
void apply_schedule(const FunctionDAG &dag, const Adams2019Params &params);
};
} // namespace Autoscheduler
} // namespace Internal
} // namespace Halide
#endif // STATE_H
ASLog.h
Cache.h
PerfectHashMap.h
CostModel.h
DefaultCostModel.h
Featurization.h
LoopNest.h
Halide::CostModel
Definition CostModel.h:61
Halide::Internal::RefCount
A class representing a reference count to be used with IntrusivePtr.
Definition IntrusivePtr.h:19
Halide::Internal::Autoscheduler
Definition AutoSchedule.h:10
Halide::Internal::Autoscheduler::StageMap
PerfectHashMap< FunctionDAG::Node::Stage, T > StageMap
Definition LoopNest.h:24
Halide::Internal
Definition AbstractGenerator.h:24
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition runtime_internal.h:23
Halide::Internal::Autoscheduler::Adams2019Params
Definition CostModel.h:19
Halide::Internal::Autoscheduler::Cache
Definition Cache.h:94
Halide::Internal::Autoscheduler::CachingOptions
Definition Cache.h:76
Halide::Internal::Autoscheduler::FunctionDAG
Definition FunctionDAG.h:367
Halide::Internal::Autoscheduler::State::calculate_cost
bool calculate_cost(const FunctionDAG &dag, const Adams2019Params &params, CostModel *cost_model, const CachingOptions &cache_options, int verbosity=99)
Halide::Internal::Autoscheduler::State::generate_children
void generate_children(const FunctionDAG &dag, const Adams2019Params &params, CostModel *cost_model, std::function< void(IntrusivePtr< State > &&)> &accept_child, Cache *cache) const
Halide::Internal::Autoscheduler::State::penalized
bool penalized
Definition State.h:32
Halide::Internal::Autoscheduler::State::dump
void dump(std::ostream &os) const
Halide::Internal::Autoscheduler::State::operator=
void operator=(const State &)=delete
Halide::Internal::Autoscheduler::State::State
State(const State &)=delete
Halide::Internal::Autoscheduler::State::num_decisions_made
int num_decisions_made
Definition State.h:30
Halide::Internal::Autoscheduler::State::parent
IntrusivePtr< const State > parent
Definition State.h:26
Halide::Internal::Autoscheduler::State::operator=
void operator=(State &&)=delete
Halide::Internal::Autoscheduler::State::cost
double cost
Definition State.h:28
Halide::Internal::Autoscheduler::State::schedule_source
string schedule_source
Definition State.h:36
Halide::Internal::Autoscheduler::State::structural_hash
uint64_t structural_hash(int depth) const
Halide::Internal::Autoscheduler::State::root
IntrusivePtr< const LoopNest > root
Definition State.h:24
Halide::Internal::Autoscheduler::State::save_featurization
void save_featurization(const FunctionDAG &dag, const Adams2019Params &params, const CachingOptions &cache_options, std::ostream &out)
Halide::Internal::Autoscheduler::State::apply_schedule
void apply_schedule(const FunctionDAG &dag, const Adams2019Params &params)
Halide::Internal::Autoscheduler::State::compute_featurization
void compute_featurization(const FunctionDAG &dag, const Adams2019Params &params, StageMap< ScheduleFeatures > *features, const CachingOptions &cache_options)
Halide::Internal::Autoscheduler::State::State
State()=default
Halide::Internal::Autoscheduler::State::make_child
IntrusivePtr< State > make_child() const
Halide::Internal::Autoscheduler::State::ref_count
RefCount ref_count
Definition State.h:22
Halide::Internal::Autoscheduler::State::State
State(State &&)=delete
Halide::Internal::Autoscheduler::State::cost_calculations
static int cost_calculations
Definition State.h:40
Halide::Internal::IntrusivePtr
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
Definition IntrusivePtr.h:71