Halide
Halide::Internal::GeneratorBase Class Referenceabstract

#include <Generator.h>

Inherits Halide::NamesInterface, and Halide::GeneratorContext.

Inherited by Halide::Generator< T >.

Public Member Functions

 ~GeneratorBase () override
 
void set_generator_param_values (const GeneratorParamsMap &params)
 
int natural_vector_size (Halide::Type t) const
 Given a data type, return an estimate of the "natural" vector size for that data type when compiling for the current target. More...
 
template<typename data_t >
int natural_vector_size () const
 Given a data type, return an estimate of the "natural" vector size for that data type when compiling for the current target. More...
 
void emit_cpp_stub (const std::string &stub_file_path)
 
Module build_module (const std::string &function_name="", const LinkageType linkage_type=LinkageType::ExternalPlusMetadata)
 
Module build_gradient_module (const std::string &function_name)
 Build a module that is suitable for using for gradient descent calculation in TensorFlow or PyTorch. More...
 
template<typename... Args>
void set_inputs (const Args &... args)
 set_inputs is a variadic wrapper around set_inputs_vector, which makes usage much simpler in many cases, as it constructs the relevant entries for the vector for you, which is often a bit unintuitive at present. More...
 
Realization realize (std::vector< int32_t > sizes)
 
template<typename... Args, typename std::enable_if< NoRealizations< Args... >::value >::type * = nullptr>
Realization realize (Args &&... args)
 
void realize (Realization r)
 
Pipeline get_pipeline ()
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name, const Type &t, int dimensions)
 
template<typename T , typename std::enable_if< T::has_static_halide_type >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name, int dimensions)
 
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value >::type * = nullptr>
GeneratorOutput< T > * add_output (const std::string &name, const Type &t, int dimensions)
 
template<typename T , typename std::enable_if< T::has_static_halide_type >::type * = nullptr>
GeneratorOutput< T > * add_output (const std::string &name, int dimensions)
 
template<typename... Args>
HALIDE_NO_USER_CODE_INLINE void add_requirement (Expr condition, Args &&... args)
 
void trace_pipeline ()
 
- Public Member Functions inherited from Halide::GeneratorContext
 GeneratorContext (const Target &t, bool auto_schedule=false, const MachineParams &machine_params=MachineParams::generic())
 
virtual ~GeneratorContext ()
 
Target get_target () const
 
bool get_auto_schedule () const
 
MachineParams get_machine_params () const
 
std::shared_ptr< ExternsMapget_externs_map () const
 Generators can register ExternalCode objects onto themselves. More...
 
template<typename T >
std::unique_ptr< T > create () const
 
template<typename T , typename... Args>
std::unique_ptr< T > apply (const Args &... args) const
 

Protected Types

enum  Phase {
  Created, ConfigureCalled, InputsSet, GenerateCalled,
  ScheduleCalled
}
 
template<typename T >
using Input = GeneratorInput< T >
 
template<typename T >
using Output = GeneratorOutput< T >
 
- Protected Types inherited from Halide::NamesInterface
using Expr = Halide::Expr
 
using ExternFuncArgument = Halide::ExternFuncArgument
 
using Func = Halide::Func
 
using GeneratorContext = Halide::GeneratorContext
 
using ImageParam = Halide::ImageParam
 
using LoopLevel = Halide::LoopLevel
 
using MemoryType = Halide::MemoryType
 
using NameMangling = Halide::NameMangling
 
using Pipeline = Halide::Pipeline
 
using PrefetchBoundStrategy = Halide::PrefetchBoundStrategy
 
using RDom = Halide::RDom
 
using RVar = Halide::RVar
 
using TailStrategy = Halide::TailStrategy
 
using Target = Halide::Target
 
using Tuple = Halide::Tuple
 
using Type = Halide::Type
 
using Var = Halide::Var
 
template<typename T >
using GeneratorParam = Halide::GeneratorParam< T >
 
template<typename T = void>
using Buffer = Halide::Buffer< T >
 
template<typename T >
using Param = Halide::Param< T >
 

Protected Member Functions

 GeneratorBase (size_t size, const void *introspection_helper)
 
void set_generator_names (const std::string &registered_name, const std::string &stub_name)
 
void init_from_context (const Halide::GeneratorContext &context) override
 
virtual Pipeline build_pipeline ()=0
 
virtual void call_configure ()=0
 
virtual void call_generate ()=0
 
virtual void call_schedule ()=0
 
void track_parameter_values (bool include_outputs)
 
void pre_build ()
 
void post_build ()
 
void pre_configure ()
 
void post_configure ()
 
void pre_generate ()
 
void post_generate ()
 
void pre_schedule ()
 
void post_schedule ()
 
void check_exact_phase (Phase expected_phase) const
 
void check_min_phase (Phase expected_phase) const
 
void advance_phase (Phase new_phase)
 
- Protected Member Functions inherited from Halide::GeneratorContext
 GeneratorContext ()
 
std::shared_ptr< Internal::ValueTrackerget_value_tracker () const
 
 GeneratorContext (const GeneratorContext &)=delete
 
void operator= (const GeneratorContext &)=delete
 
 GeneratorContext (GeneratorContext &&)=delete
 
void operator= (GeneratorContext &&)=delete
 

Protected Attributes

enum Halide::Internal::GeneratorBase::Phase Created
 
- Protected Attributes inherited from Halide::GeneratorContext
GeneratorParam< Targettarget
 
GeneratorParam< bool > auto_schedule
 
GeneratorParam< MachineParamsmachine_params
 
std::shared_ptr< ExternsMapexterns_map
 
std::shared_ptr< Internal::ValueTrackervalue_tracker
 

Additional Inherited Members

- Public Types inherited from Halide::GeneratorContext
using ExternsMap = std::map< std::string, ExternalCode >
 
- Static Protected Member Functions inherited from Halide::NamesInterface
template<typename T >
static Expr cast (Expr e)
 
static Expr cast (Halide::Type t, Expr e)
 
static Type Bool (int lanes=1)
 
static Type Float (int bits, int lanes=1)
 
static Type Int (int bits, int lanes=1)
 
static Type UInt (int bits, int lanes=1)
 

Detailed Description

Definition at line 3054 of file Generator.h.

Member Typedef Documentation

◆ Input

template<typename T >
using Halide::Internal::GeneratorBase::Input = GeneratorInput<T>
protected

Definition at line 3233 of file Generator.h.

◆ Output

template<typename T >
using Halide::Internal::GeneratorBase::Output = GeneratorOutput<T>
protected

Definition at line 3236 of file Generator.h.

Member Enumeration Documentation

◆ Phase

Enumerator
Created 
ConfigureCalled 
InputsSet 
GenerateCalled 
ScheduleCalled 

Definition at line 3241 of file Generator.h.

Constructor & Destructor Documentation

◆ ~GeneratorBase()

Halide::Internal::GeneratorBase::~GeneratorBase ( )
override

◆ GeneratorBase()

Halide::Internal::GeneratorBase::GeneratorBase ( size_t  size,
const void *  introspection_helper 
)
protected

Member Function Documentation

◆ set_generator_param_values()

void Halide::Internal::GeneratorBase::set_generator_param_values ( const GeneratorParamsMap params)

◆ natural_vector_size() [1/2]

int Halide::Internal::GeneratorBase::natural_vector_size ( Halide::Type  t) const
inline

Given a data type, return an estimate of the "natural" vector size for that data type when compiling for the current target.

Definition at line 3062 of file Generator.h.

References Halide::GeneratorContext::get_target(), and Halide::Target::natural_vector_size().

◆ natural_vector_size() [2/2]

template<typename data_t >
int Halide::Internal::GeneratorBase::natural_vector_size ( ) const
inline

Given a data type, return an estimate of the "natural" vector size for that data type when compiling for the current target.

Definition at line 3069 of file Generator.h.

References Halide::GeneratorContext::get_target(), and Halide::Target::natural_vector_size().

◆ emit_cpp_stub()

void Halide::Internal::GeneratorBase::emit_cpp_stub ( const std::string &  stub_file_path)

◆ build_module()

Module Halide::Internal::GeneratorBase::build_module ( const std::string &  function_name = "",
const LinkageType  linkage_type = LinkageType::ExternalPlusMetadata 
)

◆ build_gradient_module()

Module Halide::Internal::GeneratorBase::build_gradient_module ( const std::string &  function_name)

Build a module that is suitable for using for gradient descent calculation in TensorFlow or PyTorch.

Essentially:

  • A new Pipeline is synthesized from the current Generator (according to the rules below)
  • The new Pipeline is autoscheduled (if autoscheduling is requested, but it would be odd not to do so)
  • The Pipeline is compiled to a Module and returned

The new Pipeline is adjoint to the original; it has:

  • All the same inputs as the original, in the same order
  • Followed by one grad-input for each original output
  • Followed by one output for each unique pairing of original-output + original-input. (For the common case of just one original-output, this amounts to being one output for each original-input.)

◆ set_inputs()

template<typename... Args>
void Halide::Internal::GeneratorBase::set_inputs ( const Args &...  args)
inline

set_inputs is a variadic wrapper around set_inputs_vector, which makes usage much simpler in many cases, as it constructs the relevant entries for the vector for you, which is often a bit unintuitive at present.

The arguments are passed in Input<>-declaration-order, and the types must be compatible. Array inputs are passed as std::vector<> of the relevant type.

Note: at present, scalar input types must match exactly, i.e., for Input<uint8_t>, you must pass an argument that is actually uint8_t; an argument that is int-that-will-fit-in-uint8 will assert-fail at Halide compile time.

Definition at line 3107 of file Generator.h.

References Halide::Internal::GeneratorParamInfo::inputs(), and user_assert.

Referenced by Halide::Generator< T >::apply().

◆ realize() [1/3]

Realization Halide::Internal::GeneratorBase::realize ( std::vector< int32_t sizes)
inline

◆ realize() [2/3]

template<typename... Args, typename std::enable_if< NoRealizations< Args... >::value >::type * = nullptr>
Realization Halide::Internal::GeneratorBase::realize ( Args &&...  args)
inline

◆ realize() [3/3]

void Halide::Internal::GeneratorBase::realize ( Realization  r)
inline

◆ get_pipeline()

Pipeline Halide::Internal::GeneratorBase::get_pipeline ( )

◆ add_input() [1/3]

template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value >::type * = nullptr>
GeneratorInput<T>* Halide::Internal::GeneratorBase::add_input ( const std::string &  name,
const Type t,
int  dimensions 
)
inline

Definition at line 3144 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [2/3]

template<typename T , typename std::enable_if< T::has_static_halide_type >::type * = nullptr>
GeneratorInput<T>* Halide::Internal::GeneratorBase::add_input ( const std::string &  name,
int  dimensions 
)
inline

Definition at line 3156 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [3/3]

template<typename T , typename std::enable_if< std::is_arithmetic< T >::value >::type * = nullptr>
GeneratorInput<T>* Halide::Internal::GeneratorBase::add_input ( const std::string &  name)
inline

Definition at line 3168 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_output() [1/2]

template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value >::type * = nullptr>
GeneratorOutput<T>* Halide::Internal::GeneratorBase::add_output ( const std::string &  name,
const Type t,
int  dimensions 
)
inline

Definition at line 3180 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_output() [2/2]

template<typename T , typename std::enable_if< T::has_static_halide_type >::type * = nullptr>
GeneratorOutput<T>* Halide::Internal::GeneratorBase::add_output ( const std::string &  name,
int  dimensions 
)
inline

Definition at line 3192 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_requirement()

template<typename... Args>
HALIDE_NO_USER_CODE_INLINE void Halide::Internal::GeneratorBase::add_requirement ( Expr  condition,
Args &&...  args 
)
inline

Definition at line 3202 of file Generator.h.

References Halide::Pipeline::add_requirement(), and get_pipeline().

◆ trace_pipeline()

void Halide::Internal::GeneratorBase::trace_pipeline ( )
inline

Definition at line 3206 of file Generator.h.

References get_pipeline(), and Halide::Pipeline::trace_pipeline().

◆ set_generator_names()

void Halide::Internal::GeneratorBase::set_generator_names ( const std::string &  registered_name,
const std::string &  stub_name 
)
protected

◆ init_from_context()

void Halide::Internal::GeneratorBase::init_from_context ( const Halide::GeneratorContext context)
overrideprotectedvirtual

Reimplemented from Halide::GeneratorContext.

◆ build_pipeline()

virtual Pipeline Halide::Internal::GeneratorBase::build_pipeline ( )
protectedpure virtual

Implemented in Halide::Generator< T >.

◆ call_configure()

virtual void Halide::Internal::GeneratorBase::call_configure ( )
protectedpure virtual

Implemented in Halide::Generator< T >.

◆ call_generate()

virtual void Halide::Internal::GeneratorBase::call_generate ( )
protectedpure virtual

Implemented in Halide::Generator< T >.

◆ call_schedule()

virtual void Halide::Internal::GeneratorBase::call_schedule ( )
protectedpure virtual

Implemented in Halide::Generator< T >.

◆ track_parameter_values()

void Halide::Internal::GeneratorBase::track_parameter_values ( bool  include_outputs)
protected

◆ pre_build()

void Halide::Internal::GeneratorBase::pre_build ( )
protected

◆ post_build()

void Halide::Internal::GeneratorBase::post_build ( )
protected

◆ pre_configure()

void Halide::Internal::GeneratorBase::pre_configure ( )
protected

◆ post_configure()

void Halide::Internal::GeneratorBase::post_configure ( )
protected

◆ pre_generate()

void Halide::Internal::GeneratorBase::pre_generate ( )
protected

◆ post_generate()

void Halide::Internal::GeneratorBase::post_generate ( )
protected

◆ pre_schedule()

void Halide::Internal::GeneratorBase::pre_schedule ( )
protected

◆ post_schedule()

void Halide::Internal::GeneratorBase::post_schedule ( )
protected

◆ check_exact_phase()

void Halide::Internal::GeneratorBase::check_exact_phase ( Phase  expected_phase) const
protected

Referenced by add_input(), and add_output().

◆ check_min_phase()

void Halide::Internal::GeneratorBase::check_min_phase ( Phase  expected_phase) const
protected

◆ advance_phase()

void Halide::Internal::GeneratorBase::advance_phase ( Phase  new_phase)
protected

Member Data Documentation

◆ Created

enum Halide::Internal::GeneratorBase::Phase Halide::Internal::GeneratorBase::Created
protected

The documentation for this class was generated from the following file: