Halide 19.0.0
Halide compiler and libraries
|
Generator is a class used to encapsulate the building of Funcs in user pipelines. More...
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "AbstractGenerator.h"
#include "Func.h"
#include "ImageParam.h"
#include "ObjectInstanceRegistry.h"
#include "Target.h"
Go to the source code of this file.
Namespaces | |
namespace | Halide |
This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide's bounds tools to query properties of it. | |
namespace | Halide::Internal |
namespace | Halide::Internal::GeneratorMinMax |
namespace | halide_register_generator |
Macros | |
#define | HALIDE_GENERATOR_PARAM_TYPED_SETTER(TYPE) |
#define | HALIDE_GENERATOR_PARAM_TYPED_SETTER(TYPE) |
#define | HALIDE_FORWARD_METHOD(Class, Method) |
#define | HALIDE_FORWARD_METHOD_CONST(Class, Method) |
#define | _HALIDE_REGISTER_GENERATOR_IMPL(GEN_CLASS_NAME, GEN_REGISTRY_NAME, FULLY_QUALIFIED_STUB_NAME) |
#define | _HALIDE_REGISTER_GENERATOR2(GEN_CLASS_NAME, GEN_REGISTRY_NAME) |
#define | _HALIDE_REGISTER_GENERATOR3(GEN_CLASS_NAME, GEN_REGISTRY_NAME, FULLY_QUALIFIED_STUB_NAME) |
#define | __HALIDE_REGISTER_ARGCOUNT_IMPL(_1, _2, _3, COUNT, ...) |
#define | _HALIDE_REGISTER_ARGCOUNT_IMPL(ARGS) |
#define | _HALIDE_REGISTER_ARGCOUNT(...) |
#define | ___HALIDE_REGISTER_CHOOSER(COUNT) |
#define | __HALIDE_REGISTER_CHOOSER(COUNT) |
#define | _HALIDE_REGISTER_CHOOSER(COUNT) |
#define | _HALIDE_REGISTER_GENERATOR_PASTE(A, B) |
#define | HALIDE_REGISTER_GENERATOR(...) |
#define | HALIDE_REGISTER_GENERATOR_ALIAS(GEN_REGISTRY_NAME, ORIGINAL_REGISTRY_NAME, ...) |
#define | HALIDE_GENERATOR_PYSTUB(GEN_REGISTRY_NAME, MODULE_NAME) |
Typedefs | |
template<typename T > | |
using | Halide::Internal::GeneratorParamImplBase |
template<typename T , typename TBase = typename std::remove_all_extents<T>::type> | |
using | Halide::Internal::GeneratorInputImplBase |
template<typename T , typename TBase = typename std::remove_all_extents<T>::type> | |
using | Halide::Internal::GeneratorOutputImplBase |
using | Halide::Internal::GeneratorFactory = std::function<AbstractGeneratorPtr(const GeneratorContext &context)> |
Enumerations | |
enum class | Halide::Internal::SyntheticParamType { Halide::Internal::Type , Halide::Internal::Dim , Halide::Internal::ArraySize } |
Functions | |
void | Halide::Internal::generator_test () |
std::vector< Expr > | Halide::Internal::parameter_constraints (const Parameter &p) |
template<typename T > | |
HALIDE_NO_USER_CODE_INLINE std::string | Halide::Internal::enum_to_string (const std::map< std::string, T > &enum_map, const T &t) |
template<typename T > | |
T | Halide::Internal::enum_from_string (const std::map< std::string, T > &enum_map, const std::string &s) |
const std::map< std::string, Halide::Type > & | Halide::Internal::get_halide_type_enum_map () |
std::string | Halide::Internal::halide_type_to_enum_string (const Type &t) |
std::string | Halide::Internal::halide_type_to_c_source (const Type &t) |
std::string | Halide::Internal::halide_type_to_c_type (const Type &t) |
const GeneratorFactoryProvider & | Halide::Internal::get_registered_generators () |
Return a GeneratorFactoryProvider that knows about all the currently-registered C++ Generators. | |
int | Halide::Internal::generate_filter_main (int argc, char **argv) |
generate_filter_main() is a convenient wrapper for GeneratorRegistry::create() + compile_to_files(); it can be trivially wrapped by a "real" main() to produce a command-line utility for ahead-of-time filter compilation. | |
int | Halide::Internal::generate_filter_main (int argc, char **argv, const GeneratorFactoryProvider &generator_factory_provider) |
This overload of generate_filter_main lets you provide your own provider for how to enumerate and/or create the generators based on registration name; this is useful if you want to re-use the 'main' logic but avoid the global Generator registry (e.g. | |
template<typename Other , typename T > | |
auto | Halide::operator+ (const Other &a, const GeneratorParam< T > &b) -> decltype(a+(T) b) |
Addition between GeneratorParam<T> and any type that supports operator+ with T. | |
template<typename Other , typename T > | |
auto | Halide::operator+ (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a+b) |
template<typename Other , typename T > | |
auto | Halide::operator- (const Other &a, const GeneratorParam< T > &b) -> decltype(a -(T) b) |
Subtraction between GeneratorParam<T> and any type that supports operator- with T. | |
template<typename Other , typename T > | |
auto | Halide::operator- (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a - b) |
template<typename Other , typename T > | |
auto | Halide::operator* (const Other &a, const GeneratorParam< T > &b) -> decltype(a *(T) b) |
Multiplication between GeneratorParam<T> and any type that supports operator* with T. | |
template<typename Other , typename T > | |
auto | Halide::operator* (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a *b) |
template<typename Other , typename T > | |
auto | Halide::operator/ (const Other &a, const GeneratorParam< T > &b) -> decltype(a/(T) b) |
Division between GeneratorParam<T> and any type that supports operator/ with T. | |
template<typename Other , typename T > | |
auto | Halide::operator/ (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a/b) |
template<typename Other , typename T > | |
auto | Halide::operator% (const Other &a, const GeneratorParam< T > &b) -> decltype(a %(T) b) |
Modulo between GeneratorParam<T> and any type that supports operator% with T. | |
template<typename Other , typename T > | |
auto | Halide::operator% (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a % b) |
template<typename Other , typename T > | |
auto | Halide::operator> (const Other &a, const GeneratorParam< T > &b) -> decltype(a >(T) b) |
Greater than comparison between GeneratorParam<T> and any type that supports operator> with T. | |
template<typename Other , typename T > | |
auto | Halide::operator> (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a > b) |
template<typename Other , typename T > | |
auto | Halide::operator< (const Other &a, const GeneratorParam< T > &b) -> decltype(a<(T) b) |
Less than comparison between GeneratorParam<T> and any type that supports operator< with T. | |
template<typename Other , typename T > | |
auto | Halide::operator< (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a< b) |
template<typename Other , typename T > | |
auto | Halide::operator>= (const Other &a, const GeneratorParam< T > &b) -> decltype(a >=(T) b) |
Greater than or equal comparison between GeneratorParam<T> and any type that supports operator>= with T. | |
template<typename Other , typename T > | |
auto | Halide::operator>= (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a >=b) |
template<typename Other , typename T > | |
auto | Halide::operator<= (const Other &a, const GeneratorParam< T > &b) -> decltype(a<=(T) b) |
Less than or equal comparison between GeneratorParam<T> and any type that supports operator<= with T. | |
template<typename Other , typename T > | |
auto | Halide::operator<= (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a<=b) |
template<typename Other , typename T > | |
auto | Halide::operator== (const Other &a, const GeneratorParam< T > &b) -> decltype(a==(T) b) |
Equality comparison between GeneratorParam<T> and any type that supports operator== with T. | |
template<typename Other , typename T > | |
auto | Halide::operator== (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a==b) |
template<typename Other , typename T > | |
auto | Halide::operator!= (const Other &a, const GeneratorParam< T > &b) -> decltype(a !=(T) b) |
Inequality comparison between between GeneratorParam<T> and any type that supports operator!= with T. | |
template<typename Other , typename T > | |
auto | Halide::operator!= (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a !=b) |
template<typename Other , typename T > | |
auto | Halide::operator&& (const Other &a, const GeneratorParam< T > &b) -> decltype(a &&(T) b) |
Logical and between between GeneratorParam<T> and any type that supports operator&& with T. | |
template<typename Other , typename T > | |
auto | Halide::operator&& (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a &&b) |
template<typename T > | |
auto | Halide::operator&& (const GeneratorParam< T > &a, const GeneratorParam< T > &b) -> decltype((T) a &&(T) b) |
template<typename Other , typename T > | |
auto | Halide::operator|| (const Other &a, const GeneratorParam< T > &b) -> decltype(a||(T) b) |
Logical or between between GeneratorParam<T> and any type that supports operator|| with T. | |
template<typename Other , typename T > | |
auto | Halide::operator|| (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a||b) |
template<typename T > | |
auto | Halide::operator|| (const GeneratorParam< T > &a, const GeneratorParam< T > &b) -> decltype((T) a||(T) b) |
template<typename Other , typename T > | |
auto | Halide::Internal::GeneratorMinMax::min_forward (const Other &a, const GeneratorParam< T > &b) -> decltype(min(a,(T) b)) |
template<typename Other , typename T > | |
auto | Halide::Internal::GeneratorMinMax::min_forward (const GeneratorParam< T > &a, const Other &b) -> decltype(min((T) a, b)) |
template<typename Other , typename T > | |
auto | Halide::Internal::GeneratorMinMax::max_forward (const Other &a, const GeneratorParam< T > &b) -> decltype(max(a,(T) b)) |
template<typename Other , typename T > | |
auto | Halide::Internal::GeneratorMinMax::max_forward (const GeneratorParam< T > &a, const Other &b) -> decltype(max((T) a, b)) |
template<typename Other , typename T > | |
auto | Halide::min (const Other &a, const GeneratorParam< T > &b) -> decltype(Internal::GeneratorMinMax::min_forward(a, b)) |
Compute minimum between GeneratorParam<T> and any type that supports min with T. | |
template<typename Other , typename T > | |
auto | Halide::min (const GeneratorParam< T > &a, const Other &b) -> decltype(Internal::GeneratorMinMax::min_forward(a, b)) |
template<typename Other , typename T > | |
auto | Halide::max (const Other &a, const GeneratorParam< T > &b) -> decltype(Internal::GeneratorMinMax::max_forward(a, b)) |
Compute the maximum value between GeneratorParam<T> and any type that supports max with T. | |
template<typename Other , typename T > | |
auto | Halide::max (const GeneratorParam< T > &a, const Other &b) -> decltype(Internal::GeneratorMinMax::max_forward(a, b)) |
template<typename T > | |
auto | Halide::operator! (const GeneratorParam< T > &a) -> decltype(!(T) a) |
Not operator for GeneratorParam. | |
template<typename T > | |
T | Halide::Internal::parse_scalar (const std::string &value) |
std::vector< Type > | Halide::Internal::parse_halide_type_list (const std::string &types) |
void | Halide::Internal::execute_generator (const ExecuteGeneratorArgs &args) |
Execute a Generator for AOT compilation – this provides the implementation of the command-line Generator interface generate_filter_main() , but with a structured API that is more suitable for calling directly from code (vs command line). | |
Callable | Halide::create_callable_from_generator (const GeneratorContext &context, const std::string &name, const GeneratorParamsMap &generator_params={}) |
Create a Generator from the currently-registered Generators, use it to create a Callable. | |
Callable | Halide::create_callable_from_generator (const Target &target, const std::string &name, const GeneratorParamsMap &generator_params={}) |
Generator is a class used to encapsulate the building of Funcs in user pipelines.
A Generator is agnostic to JIT vs AOT compilation; it can be used for either purpose, but is especially convenient to use for AOT compilation.
A Generator explicitly declares the Inputs and Outputs associated for a given pipeline, and (optionally) separates the code for constructing the outputs from the code from scheduling them. For instance:
Halide can compile a Generator into the correct pipeline by introspecting these values and constructing an appropriate signature based on them.
A Generator provides implementations of two methods:
Inputs can be any C++ scalar type:
An Input<Func> is (essentially) like an ImageParam, except that it may (or may not) not be backed by an actual buffer, and thus has no defined extents.
You can optionally make the type and/or dimensions of Input<Func> unspecified, in which case the value is simply inferred from the actual Funcs passed to them. Of course, if you specify an explicit Type or Dimension, we still require the input Func to match, or a compilation error results.
A Generator must explicitly list the output(s) it produces:
You can specify an output that returns a Tuple by specifying a list of Types:
You can also specify Output<X> for any scalar type (except for Handle types); this is merely syntactic sugar on top of a zero-dimensional Func, but can be quite handy, especially when used with multiple outputs:
As with Input<Func>, you can optionally make the type and/or dimensions of an Output<Func> unspecified; any unspecified types must be resolved via an implicit GeneratorParam in order to use top-level compilation.
You can also declare an array of Input or Output, by using an array type as the type parameter:
You can also leave array size unspecified, with some caveats:
A Generator can also be customized via compile-time parameters (GeneratorParams), which affect code generation.
GeneratorParams, Inputs, and Outputs are (by convention) always public and always declared at the top of the Generator class, in the order
Note that the Inputs and Outputs will appear in the C function call in the order they are declared. All Input<Func> and Output<Func> are represented as halide_buffer_t; all other Input<> are the appropriate C++ scalar type. (GeneratorParams are always referenced by name, not position, so their order is irrelevant.)
All Inputs and Outputs must have explicit names, and all such names must match the regex [A-Za-z][A-Za-z_0-9]* (i.e., essentially a C/C++ variable name, with some extra restrictions on underscore use). By convention, the name should match the member-variable name.
You can dynamically add Inputs and Outputs to your Generator via adding a configure() method; if present, it will be called before generate(). It can examine GeneratorParams but it may not examine predeclared Inputs or Outputs; the only thing it should do is call add_input<>() and/or add_output<>(), or call set_type()/set_dimensions()/set_array_size() on an Input or Output with an unspecified type. Added inputs will be appended (in order) after predeclared Inputs but before any Outputs; added outputs will be appended after predeclared Outputs.
Note that the pointers returned by add_input() and add_output() are owned by the Generator and will remain valid for the Generator's lifetime; user code should not attempt to delete or free them.
All Generators have two GeneratorParams that are implicitly provided by the base class:
GeneratorParam<Target> target{"target", Target()}; GeneratorParam<AutoschedulerParams> autoscheduler{"autoscheduler", {}}
Generators are added to a global registry to simplify AOT build mechanics; this is done by simply using the HALIDE_REGISTER_GENERATOR macro at global scope:
The registered name of the Generator is provided must match the same rules as Input names, above.
Note that the class name of the generated Stub class will match the registered name by default; if you want to vary it (typically, to include namespaces), you can add it as an optional third argument:
Note that a Generator is always executed with a specific Target assigned to it, that you can access via the get_target() method. (You should not use the global get_target_from_environment(), etc. methods provided in Target.h)
(Note that there are older variations of Generator that differ from what's documented above; these are still supported but not described here. See https://github.com/halide/Halide/wiki/Old-Generator-Documentation for more information.)
Definition in file Generator.h.
#define HALIDE_GENERATOR_PARAM_TYPED_SETTER | ( | TYPE | ) |
Definition at line 412 of file Generator.h.
#define HALIDE_GENERATOR_PARAM_TYPED_SETTER | ( | TYPE | ) |
Definition at line 412 of file Generator.h.
#define HALIDE_FORWARD_METHOD | ( | Class, | |
Method ) |
Definition at line 1650 of file Generator.h.
#define HALIDE_FORWARD_METHOD_CONST | ( | Class, | |
Method ) |
Definition at line 1656 of file Generator.h.
#define _HALIDE_REGISTER_GENERATOR_IMPL | ( | GEN_CLASS_NAME, | |
GEN_REGISTRY_NAME, | |||
FULLY_QUALIFIED_STUB_NAME ) |
Definition at line 3991 of file Generator.h.
#define _HALIDE_REGISTER_GENERATOR2 | ( | GEN_CLASS_NAME, | |
GEN_REGISTRY_NAME ) |
Definition at line 4008 of file Generator.h.
#define _HALIDE_REGISTER_GENERATOR3 | ( | GEN_CLASS_NAME, | |
GEN_REGISTRY_NAME, | |||
FULLY_QUALIFIED_STUB_NAME ) |
Definition at line 4011 of file Generator.h.
#define __HALIDE_REGISTER_ARGCOUNT_IMPL | ( | _1, | |
_2, | |||
_3, | |||
COUNT, | |||
... ) |
Definition at line 4017 of file Generator.h.
#define _HALIDE_REGISTER_ARGCOUNT_IMPL | ( | ARGS | ) |
Definition at line 4020 of file Generator.h.
#define _HALIDE_REGISTER_ARGCOUNT | ( | ... | ) |
Definition at line 4023 of file Generator.h.
#define ___HALIDE_REGISTER_CHOOSER | ( | COUNT | ) |
Definition at line 4026 of file Generator.h.
#define __HALIDE_REGISTER_CHOOSER | ( | COUNT | ) |
Definition at line 4029 of file Generator.h.
#define _HALIDE_REGISTER_CHOOSER | ( | COUNT | ) |
Definition at line 4032 of file Generator.h.
#define _HALIDE_REGISTER_GENERATOR_PASTE | ( | A, | |
B ) |
Definition at line 4035 of file Generator.h.
#define HALIDE_REGISTER_GENERATOR | ( | ... | ) |
Definition at line 4038 of file Generator.h.
#define HALIDE_REGISTER_GENERATOR_ALIAS | ( | GEN_REGISTRY_NAME, | |
ORIGINAL_REGISTRY_NAME, | |||
... ) |
Definition at line 4055 of file Generator.h.
#define HALIDE_GENERATOR_PYSTUB | ( | GEN_REGISTRY_NAME, | |
MODULE_NAME ) |
Definition at line 4079 of file Generator.h.