Halide  14.0.0
Halide compiler and libraries
Halide::Internal::GeneratorBase Class Referenceabstract

#include <Generator.h>

Inherits Halide::NamesInterface.

Inherited by Halide::Generator< T >.

Public Member Functions

virtual ~GeneratorBase ()
 
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="", 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_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name, const Type &t, int dimensions)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name, const Type &t, int dimensions)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name, int dimensions)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, Halide::Func >::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>
GeneratorInput< T > * add_input (const std::string &name)
 
template<typename T , typename std::enable_if< std::is_same< T, Expr >::value >::type * = nullptr>
GeneratorInput< T > * add_input (const std::string &name, const Type &type)
 
template<typename T , typename std::enable_if< std::is_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorOutput< T > * add_output (const std::string &name, const Type &t, int dimensions)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorOutput< T > * add_output (const std::string &name, const Type &t, int dimensions)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorOutput< T > * add_output (const std::string &name, int dimensions)
 
template<typename T , typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, Halide::Func >::value >::type * = nullptr>
GeneratorOutput< T > * add_output (const std::string &name)
 
template<typename... Args>
HALIDE_NO_USER_CODE_INLINE void add_requirement (Expr condition, Args &&...args)
 
void trace_pipeline ()
 
GeneratorContext context () const
 
 GeneratorBase (const GeneratorBase &)=delete
 
GeneratorBaseoperator= (const GeneratorBase &)=delete
 
 GeneratorBase (GeneratorBase &&that)=delete
 
GeneratorBaseoperator= (GeneratorBase &&that)=delete
 

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 EvictionKey = Halide::EvictionKey
 
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, int D = -1>
using Buffer = Halide::Buffer< T, D >
 
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)
 
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)
 
void ensure_configure_has_been_called ()
 
Target get_target () const
 
bool get_auto_schedule () const
 
MachineParams get_machine_params () const
 
std::shared_ptr< GeneratorContext::ExternsMapget_externs_map () const
 Generators can register ExternalCode objects onto themselves. More...
 

Protected Attributes

enum Halide::Internal::GeneratorBase::Phase Created
 
GeneratorParam< Targettarget {"target", Target()}
 
GeneratorParam< bool > auto_schedule {"auto_schedule", false}
 
GeneratorParam< MachineParamsmachine_params {"machine_params", MachineParams::generic()}
 

Additional Inherited Members

- 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 3108 of file Generator.h.

Member Typedef Documentation

◆ Input

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

Definition at line 3368 of file Generator.h.

◆ Output

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

Definition at line 3371 of file Generator.h.

Member Enumeration Documentation

◆ Phase

Enumerator
Created 
ConfigureCalled 
InputsSet 
GenerateCalled 
ScheduleCalled 

Definition at line 3376 of file Generator.h.

Constructor & Destructor Documentation

◆ ~GeneratorBase()

virtual Halide::Internal::GeneratorBase::~GeneratorBase ( )
virtual

◆ GeneratorBase() [1/3]

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

◆ GeneratorBase() [2/3]

Halide::Internal::GeneratorBase::GeneratorBase ( const GeneratorBase )
delete

◆ GeneratorBase() [3/3]

Halide::Internal::GeneratorBase::GeneratorBase ( GeneratorBase &&  that)
delete

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 3116 of file Generator.h.

References 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 3123 of file Generator.h.

References 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 = "",
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 3161 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

Definition at line 3170 of file Generator.h.

References get_pipeline(), get_target(), and Halide::Pipeline::realize().

◆ realize() [2/3]

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

Definition at line 3178 of file Generator.h.

References get_pipeline(), get_target(), and Halide::Pipeline::realize().

◆ realize() [3/3]

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

Definition at line 3183 of file Generator.h.

References get_pipeline(), get_target(), and Halide::Pipeline::realize().

◆ get_pipeline()

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

◆ add_input() [1/6]

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

Definition at line 3206 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [2/6]

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

Definition at line 3218 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [3/6]

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

Definition at line 3232 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [4/6]

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

Definition at line 3246 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [5/6]

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 3259 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_input() [6/6]

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

Definition at line 3270 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_output() [1/4]

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

Definition at line 3283 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_output() [2/4]

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

Definition at line 3295 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_output() [3/4]

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

Definition at line 3309 of file Generator.h.

References check_exact_phase(), and ConfigureCalled.

◆ add_output() [4/4]

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

Definition at line 3323 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 3335 of file Generator.h.

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

◆ trace_pipeline()

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

Definition at line 3339 of file Generator.h.

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

◆ context()

GeneratorContext Halide::Internal::GeneratorBase::context ( ) const

◆ 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)
protected

◆ 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

◆ ensure_configure_has_been_called()

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

◆ get_target()

Target Halide::Internal::GeneratorBase::get_target ( ) const
inlineprotected

Definition at line 3409 of file Generator.h.

References target.

Referenced by natural_vector_size(), and realize().

◆ get_auto_schedule()

bool Halide::Internal::GeneratorBase::get_auto_schedule ( ) const
inlineprotected

Definition at line 3412 of file Generator.h.

References auto_schedule.

◆ get_machine_params()

MachineParams Halide::Internal::GeneratorBase::get_machine_params ( ) const
inlineprotected

Definition at line 3415 of file Generator.h.

References machine_params.

◆ get_externs_map()

std::shared_ptr<GeneratorContext::ExternsMap> Halide::Internal::GeneratorBase::get_externs_map ( ) const
inlineprotected

Generators can register ExternalCode objects onto themselves.

The Generator infrastructure will arrange to have this ExternalCode appended to the Module that is finally compiled using the Generator. This allows encapsulating functionality that depends on external libraries or handwritten code for various targets. The name argument should match the name of the ExternalCode block and is used to ensure the same code block is not duplicated in the output. Halide does not do anything other than to compare names for equality. To guarantee uniqueness in public code, we suggest using a Java style inverted domain name followed by organization specific naming. E.g.: com.yoyodyne.overthruster.0719acd19b66df2a9d8d628a8fefba911a0ab2b7

See test/generator/external_code_generator.cpp for example use.

Definition at line 3433 of file Generator.h.

◆ operator=() [1/2]

GeneratorBase& Halide::Internal::GeneratorBase::operator= ( const GeneratorBase )
delete

◆ operator=() [2/2]

GeneratorBase& Halide::Internal::GeneratorBase::operator= ( GeneratorBase &&  that)
delete

Member Data Documentation

◆ Created

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

◆ target

GeneratorParam<Target> Halide::Internal::GeneratorBase::target {"target", Target()}
protected

Definition at line 3438 of file Generator.h.

Referenced by get_target().

◆ auto_schedule

GeneratorParam<bool> Halide::Internal::GeneratorBase::auto_schedule {"auto_schedule", false}
protected

Definition at line 3439 of file Generator.h.

Referenced by get_auto_schedule().

◆ machine_params

GeneratorParam<MachineParams> Halide::Internal::GeneratorBase::machine_params {"machine_params", MachineParams::generic()}
protected

Definition at line 3440 of file Generator.h.

Referenced by get_machine_params().


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