Halide
Halide::Internal::GeneratorBase Class Referenceabstract

#include <Generator.h>

Inherits Halide::NamesInterface, and Halide::Internal::AbstractGenerator.

Inherited by Halide::Generator< T >.

Public Member Functions

 ~GeneratorBase () override
 
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...
 
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)
 
void add_requirement (const Expr &condition, const std::vector< Expr > &error_args)
 
template<typename... Args, typename = typename std::enable_if<Internal::all_are_printable_args<Args...>::value>::type>
HALIDE_NO_USER_CODE_INLINE void add_requirement (const Expr &condition, Args &&...error_args)
 
void trace_pipeline ()
 
std::string name () override
 Return the name of this Generator. More...
 
GeneratorContext context () const override
 Return the Target and autoscheduler info that this Generator was created with. More...
 
std::vector< ArgInfoarginfos () override
 Return a list of all the ArgInfos for this generator. More...
 
void set_generatorparam_value (const std::string &name, const std::string &value) override
 Set the value for a specific GeneratorParam for an AbstractGenerator instance. More...
 
void set_generatorparam_value (const std::string &name, const LoopLevel &loop_level) override
 
std::vector< Parameterinput_parameter (const std::string &name) override
 Given the name of an input, return the Parameter(s) for that input. More...
 
std::vector< Funcoutput_func (const std::string &name) override
 Given the name of an output, return the Func(s) for that output. More...
 
void bind_input (const std::string &name, const std::vector< Parameter > &v) override
 Rebind a specified Input to refer to the given piece of IR, replacing the default ImageParam / Param in place for that Input. More...
 
void bind_input (const std::string &name, const std::vector< Func > &v) override
 
void bind_input (const std::string &name, const std::vector< Expr > &v) override
 
bool emit_cpp_stub (const std::string &stub_file_path) override
 Emit a Generator Stub (.stub.h) file to the given path. More...
 
 GeneratorBase (const GeneratorBase &)=delete
 
GeneratorBaseoperator= (const GeneratorBase &)=delete
 
 GeneratorBase (GeneratorBase &&that)=delete
 
GeneratorBaseoperator= (GeneratorBase &&that)=delete
 
- Public Member Functions inherited from Halide::Internal::AbstractGenerator
virtual ~AbstractGenerator ()=default
 
virtual Pipeline build_pipeline ()=0
 Build and return the Pipeline for this AbstractGenerator. More...
 
Module build_module (const std::string &function_name="")
 Call generate() and produce a Module for the result. More...
 
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...
 
Callable compile_to_callable (const JITHandlers *jit_handlers=nullptr, const std::map< std::string, JITExtern > *jit_externs=nullptr)
 JIT the AbstractGenerator into a Callable (using the currently-set Target) and return it. More...
 
void set_generatorparam_values (const GeneratorParamsMap &m)
 

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)
 
virtual void init_from_context (const Halide::GeneratorContext &context)
 
virtual void call_configure ()=0
 
virtual void call_generate ()=0
 
virtual void call_schedule ()=0
 
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 using_autoscheduler () const
 

Protected Attributes

enum Halide::Internal::GeneratorBase::Phase Created
 
GeneratorParam< Targettarget {"target", Target()}
 
GeneratorParam_AutoSchedulerParams autoscheduler_
 

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

Member Typedef Documentation

◆ Input

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

Definition at line 3425 of file Generator.h.

◆ Output

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

Definition at line 3428 of file Generator.h.

Member Enumeration Documentation

◆ Phase

Enumerator
Created 
ConfigureCalled 
InputsSet 
GenerateCalled 
ScheduleCalled 

Definition at line 3433 of file Generator.h.

Constructor & Destructor Documentation

◆ ~GeneratorBase()

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

◆ 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

◆ 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 3150 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 3157 of file Generator.h.

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

◆ 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 3172 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 3181 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 3189 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 3194 of file Generator.h.

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

◆ get_pipeline()

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

Referenced by realize(), and trace_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 3208 of file Generator.h.

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

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

References check_exact_phase(), ConfigureCalled, and name().

◆ add_requirement() [1/2]

void Halide::Internal::GeneratorBase::add_requirement ( const Expr condition,
const std::vector< Expr > &  error_args 
)

Referenced by add_requirement().

◆ add_requirement() [2/2]

template<typename... Args, typename = typename std::enable_if<Internal::all_are_printable_args<Args...>::value>::type>
HALIDE_NO_USER_CODE_INLINE void Halide::Internal::GeneratorBase::add_requirement ( const Expr condition,
Args &&...  error_args 
)
inline

Definition at line 3340 of file Generator.h.

References add_requirement(), and Halide::Internal::collect_print_args().

◆ trace_pipeline()

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

Definition at line 3346 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()

virtual void Halide::Internal::GeneratorBase::init_from_context ( const Halide::GeneratorContext context)
protectedvirtual

◆ 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 >.

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

References target.

Referenced by natural_vector_size(), and realize().

◆ using_autoscheduler()

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

◆ name()

std::string Halide::Internal::GeneratorBase::name ( )
overridevirtual

Return the name of this Generator.

(This should always be the name used to register it.)

Implements Halide::Internal::AbstractGenerator.

Referenced by add_input(), and add_output().

◆ context()

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

Return the Target and autoscheduler info that this Generator was created with.

Always legal to call on any AbstractGenerator instance, regardless of what other methods have been called. (All AbstractGenerator instances are expected to be created with immutable values for these, which can't be changed for a given instance after creation. Note that Generator<> based subclasses can customize Target somewhat via init_from_context(); see Generator.h for more info.)

CALL-AFTER: any CALL-BEFORE: any

Implements Halide::Internal::AbstractGenerator.

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

◆ arginfos()

std::vector<ArgInfo> Halide::Internal::GeneratorBase::arginfos ( )
overridevirtual

Return a list of all the ArgInfos for this generator.

The list will be in the order that the input and outputs are declared (possibly interleaved). Any inputs or outputs added by a configure() method will be in the list, at the end, in the order added. All input and output names will be unique within a given Generator instance.

CALL-AFTER: configure() CALL-BEFORE: any

Implements Halide::Internal::AbstractGenerator.

◆ set_generatorparam_value() [1/2]

void Halide::Internal::GeneratorBase::set_generatorparam_value ( const std::string &  name,
const std::string &  value 
)
overridevirtual

Set the value for a specific GeneratorParam for an AbstractGenerator instance.

Names that aren't known generator names should assert-fail.

Values that can't be parsed for the specific GeneratorParam (e.g. passing "foo" where an integer is expected) should assert-fail at some point (either immediately, or when build_pipeline() is called)

This can be called multiple times, but only prior to build_pipeline().

CALL-AFTER: none CALL-BEFORE: build_pipeline

Implements Halide::Internal::AbstractGenerator.

◆ set_generatorparam_value() [2/2]

void Halide::Internal::GeneratorBase::set_generatorparam_value ( const std::string &  name,
const LoopLevel loop_level 
)
overridevirtual

◆ input_parameter()

std::vector<Parameter> Halide::Internal::GeneratorBase::input_parameter ( const std::string &  name)
overridevirtual

Given the name of an input, return the Parameter(s) for that input.

(Most inputs will have exactly one, but inputs that are declared as arrays will have multiple.)

CALL-AFTER: build_pipeline CALL-BEFORE: none

Implements Halide::Internal::AbstractGenerator.

◆ output_func()

std::vector<Func> Halide::Internal::GeneratorBase::output_func ( const std::string &  name)
overridevirtual

Given the name of an output, return the Func(s) for that output.

Most outputs will have exactly one, but outputs that are declared as arrays will have multiple.

Note that outputs with Tuple values are still just a single Func, though they do get realized as multiple Buffers.

Must be called after build_pipeline(), since the output Funcs will be undefined prior to that.

CALL-AFTER: build_pipeline() CALL-BEFORE: none

Implements Halide::Internal::AbstractGenerator.

◆ bind_input() [1/3]

void Halide::Internal::GeneratorBase::bind_input ( const std::string &  name,
const std::vector< Parameter > &  v 
)
overridevirtual

Rebind a specified Input to refer to the given piece of IR, replacing the default ImageParam / Param in place for that Input.

Basic type-checking is done to ensure that inputs are still sane (e.g. types, dimensions, etc must match expectations).

CALL-AFTER: set_generatorparam_value CALL-BEFORE: build_pipeline

Implements Halide::Internal::AbstractGenerator.

◆ bind_input() [2/3]

void Halide::Internal::GeneratorBase::bind_input ( const std::string &  name,
const std::vector< Func > &  v 
)
overridevirtual

◆ bind_input() [3/3]

void Halide::Internal::GeneratorBase::bind_input ( const std::string &  name,
const std::vector< Expr > &  v 
)
overridevirtual

◆ emit_cpp_stub()

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

Emit a Generator Stub (.stub.h) file to the given path.

Not all Generators support this.

If you call this method, you should not call any other AbstractGenerator methods on this instance, before or after this call.

If the Generator is capable of emitting a Stub, do so and return true. (Errors during stub emission should assert-fail rather than returning false.)

If the Generator is not capable of emitting a Stub, do nothing and return false.

CALL-AFTER: none CALL-BEFORE: none

Implements Halide::Internal::AbstractGenerator.

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

Referenced by get_target().

◆ autoscheduler_

GeneratorParam_AutoSchedulerParams Halide::Internal::GeneratorBase::autoscheduler_
protected

Definition at line 3468 of file Generator.h.

Referenced by using_autoscheduler().


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