Halide
Halide Namespace Reference

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

Namespaces

 BoundaryConditions
 namespace to hold functions for imposing boundary conditions on Halide Funcs.
 
 ConciseCasts
 
 IntegerDivideTable
 Built-in images used for fast_integer_divide below.
 
 Internal
 
 PyTorch
 
 Runtime
 

Classes

struct  Argument
 A struct representing an argument to a halide-generated function. More...
 
struct  ArgumentEstimates
 
struct  AutoSchedulerResults
 
struct  bfloat16_t
 Class that provides a type that implements half precision floating point using the bfloat16 format. More...
 
class  Buffer
 A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer. More...
 
struct  CompileError
 An error that occurs while compiling a Halide pipeline that Halide attributes to a user error. More...
 
class  CompileTimeErrorReporter
 CompileTimeErrorReporter is used at compile time (not runtime) when an error or warning is generated by Halide. More...
 
class  CostModel
 
struct  CustomLoweringPass
 A custom lowering pass. More...
 
class  DefaultCostModel
 
class  Derivative
 Helper structure storing the adjoints Func. More...
 
struct  Error
 A base class for Halide errors. More...
 
struct  Expr
 A fragment of Halide syntax. More...
 
struct  ExprCompare
 This lets you use an Expr as a key in a map of the form map<Expr, Foo, ExprCompare> More...
 
class  ExternalCode
 
struct  ExternCFunction
 
struct  ExternFuncArgument
 An argument to an extern-defined Func. More...
 
struct  ExternSignature
 
struct  float16_t
 Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in software. More...
 
class  Func
 A halide function. More...
 
class  FuncRef
 A fragment of front-end syntax of the form f(x, y, z), where x, y, z are Vars or Exprs. More...
 
class  FuncTupleElementRef
 A fragment of front-end syntax of the form f(x, y, z)[index], where x, y, z are Vars or Exprs. More...
 
struct  FuseLoopLevel
 
class  Generator
 
class  GeneratorContext
 GeneratorContext is a base class that is used when using Generators (or Stubs) directly; it is used to allow the outer context (typically, either a Generator or "top-level" code) to specify certain information to the inner context to ensure that inner and outer Generators are compiled in a compatible way. More...
 
class  GeneratorInput
 
class  GeneratorOutput
 
class  GeneratorParam
 GeneratorParam is a templated class that can be used to modify the behavior of the Generator at code-generation time. More...
 
class  ImageParam
 An Image parameter to a halide pipeline. More...
 
struct  ImplicitVar
 
struct  InternalError
 An error that occurs while compiling a Halide pipeline that Halide attributes to an internal compiler bug, or to an invalid use of Halide's internals. More...
 
struct  JITExtern
 
class  LoopLevel
 A reference to a site in a Halide statement at the top of the body of a particular for loop. More...
 
struct  MachineParams
 A struct representing the machine parameters to generate the auto-scheduled code for. More...
 
class  Module
 A halide module. More...
 
class  NamesInterface
 
class  OutputImageParam
 A handle on the output buffer of a pipeline. More...
 
class  Param
 A scalar parameter to a halide pipeline. More...
 
class  ParamMap
 
class  Pipeline
 A class representing a Halide pipeline. More...
 
struct  Range
 A single-dimensional span. More...
 
class  RDom
 A multi-dimensional domain over which to iterate. More...
 
class  Realization
 A Realization is a vector of references to existing Buffer objects. More...
 
struct  RuntimeError
 An error that occurs while running a JIT-compiled Halide pipeline. More...
 
class  RVar
 A reduction variable represents a single dimension of a reduction domain (RDom). More...
 
class  SimdOpCheckTest
 
class  Stage
 A single definition of a Func. More...
 
struct  Target
 A struct representing a target machine and os to generate code for. More...
 
struct  Task
 
struct  TestResult
 
class  Tuple
 Create a small array of Exprs for defining and calling functions with multiple outputs. More...
 
struct  Type
 Types in the halide type system. More...
 
class  Var
 A Halide variable, to be used when defining functions. More...
 
struct  VarOrRVar
 A class that can represent Vars or RVars. More...
 

Typedefs

typedef std::vector< RangeRegion
 A multi-dimensional box. More...
 
typedef Stage ScheduleHandle
 
using ModuleFactory = std::function< Module(const std::string &fn_name, const Target &target)>
 
using CompilerLoggerFactory = std::function< std::unique_ptr< Internal::CompilerLogger >(const std::string &fn_name, const Target &target)>
 
using AutoSchedulerFn = std::function< void(const Pipeline &, const Target &, const MachineParams &, AutoSchedulerResults *outputs)>
 

Enumerations

enum  DeviceAPI {
  DeviceAPI::None, DeviceAPI::Host, DeviceAPI::Default_GPU, DeviceAPI::CUDA,
  DeviceAPI::OpenCL, DeviceAPI::GLSL, DeviceAPI::OpenGLCompute, DeviceAPI::Metal,
  DeviceAPI::Hexagon, DeviceAPI::HexagonDma, DeviceAPI::D3D12Compute
}
 An enum describing a type of device API. More...
 
enum  MemoryType {
  MemoryType::Auto, MemoryType::Heap, MemoryType::Stack, MemoryType::Register,
  MemoryType::GPUShared, MemoryType::LockedCache, MemoryType::VTCM
}
 An enum describing different address spaces to be used with Func::store_in. More...
 
enum  NameMangling { NameMangling::Default, NameMangling::C, NameMangling::CPlusPlus }
 An enum to specify calling convention for extern stages. More...
 
enum  Output {
  Output::assembly, Output::bitcode, Output::c_header, Output::c_source,
  Output::compiler_log, Output::cpp_stub, Output::featurization, Output::llvm_assembly,
  Output::object, Output::python_extension, Output::pytorch_wrapper, Output::registration,
  Output::schedule, Output::static_library, Output::stmt, Output::stmt_html
}
 Enums specifying various kinds of outputs that can be produced from a Halide Pipeline. More...
 
enum  LinkageType { LinkageType::External, LinkageType::ExternalPlusMetadata, LinkageType::Internal }
 Type of linkage a function in a lowered Halide module can have. More...
 
enum  StmtOutputFormat { Text, HTML }
 Used to determine if the output printed to file should be as a normal string or as an HTML file which can be opened in a browerser and manipulated via JS and CSS. More...
 
enum  PrefetchBoundStrategy { PrefetchBoundStrategy::Clamp, PrefetchBoundStrategy::GuardWithIf, PrefetchBoundStrategy::NonFaulting }
 Different ways to handle accesses outside the original extents in a prefetch. More...
 
enum  TailStrategy { TailStrategy::RoundUp, TailStrategy::GuardWithIf, TailStrategy::ShiftInwards, TailStrategy::Auto }
 Different ways to handle a tail case in a split when the factor does not provably divide the extent. More...
 
enum  LoopAlignStrategy { LoopAlignStrategy::AlignStart, LoopAlignStrategy::AlignEnd, LoopAlignStrategy::NoAlign, LoopAlignStrategy::Auto }
 Different ways to handle the case when the start/end of the loops of stages computed with (fused) are not aligned. More...
 

Functions

std::unique_ptr< DefaultCostModelmake_default_cost_model (const std::string &weights_in_dir="", const std::string &weights_out_dir="", bool randomize_weights=false)
 
std::unique_ptr< llvm::Module > codegen_llvm (const Module &module, llvm::LLVMContext &context)
 Given a Halide module, generate an llvm::Module. More...
 
std::ostream & operator<< (std::ostream &stream, const Expr &)
 Emit an expression on an output stream (such as std::cout) in human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const Type &)
 Emit a halide type on an output stream (such as std::cout) in human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const Module &)
 Emit a halide Module on an output stream (such as std::cout) in human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const Target &)
 Emit a halide Target in a human readable form. More...
 
Derivative propagate_adjoints (const Func &output, const Func &adjoint, const Region &output_bounds)
 Given a Func and a corresponding adjoint, (back)propagate the adjoint to all dependent Funcs, buffers, and parameters. More...
 
Derivative propagate_adjoints (const Func &output, const Buffer< float > &adjoint)
 Given a Func and a corresponding adjoint buffer, (back)propagate the adjoint to all dependent Funcs, buffers, and parameters. More...
 
Derivative propagate_adjoints (const Func &output)
 Given a scalar Func with size 1, (back)propagate the gradient to all dependent Funcs, buffers, and parameters. More...
 
const halide_device_interface_tget_device_interface_for_device_api (DeviceAPI d, const Target &t=get_jit_target_from_environment(), const char *error_site=nullptr)
 Gets the appropriate halide_device_interface_t * for a DeviceAPI. More...
 
DeviceAPI get_default_device_api_for_target (const Target &t)
 Get the specific DeviceAPI that Halide would select when presented with DeviceAPI::Default_GPU for a given target. More...
 
bool host_supports_target_device (const Target &t)
 This attempts to sniff whether a given Target (and its implied DeviceAPI) is usable on the current host. More...
 
bool exceptions_enabled ()
 Query whether Halide was compiled with exceptions. More...
 
void set_custom_compile_time_error_reporter (CompileTimeErrorReporter *error_reporter)
 The default error reporter logs to stderr, then throws an exception (if HALIDE_WITH_EXCEPTIONS) or calls abort (if not). More...
 
Expr fast_integer_divide (Expr numerator, Expr denominator)
 Integer division by small values can be done exactly as multiplies and shifts. More...
 
Expr fast_integer_modulo (Expr numerator, Expr denominator)
 Use the fast integer division tables to implement a modulo operation via the Euclidean identity: ab = a - (a/b)*b. More...
 
Expr min (const FuncRef &a, const FuncRef &b)
 Explicit overloads of min and max for FuncRef. More...
 
Expr max (const FuncRef &a, const FuncRef &b)
 
template<typename T >
HALIDE_NO_USER_CODE_INLINEevaluate (const Expr &e)
 JIT-Compile and run enough code to evaluate a Halide expression. More...
 
template<typename First , typename... Rest>
HALIDE_NO_USER_CODE_INLINE void evaluate (Tuple t, First first, Rest &&... rest)
 JIT-compile and run enough code to evaluate a Halide Tuple. More...
 
template<typename T >
HALIDE_NO_USER_CODE_INLINEevaluate_may_gpu (const Expr &e)
 JIT-Compile and run enough code to evaluate a Halide expression. More...
 
template<typename First , typename... Rest>
HALIDE_NO_USER_CODE_INLINE void evaluate_may_gpu (Tuple t, First first, Rest &&... rest)
 JIT-compile and run enough code to evaluate a Halide Tuple. More...
 
template<typename Other , typename T >
auto operator+ (const Other &a, const GeneratorParam< T > &b) -> decltype(a+(T) b)
 Addition between GeneratorParam<T> and any type that supports operator+ with T. More...
 
template<typename Other , typename T >
auto operator+ (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a+b)
 
template<typename Other , typename T >
auto operator- (const Other &a, const GeneratorParam< T > &b) -> decltype(a -(T) b)
 Subtraction between GeneratorParam<T> and any type that supports operator- with T. More...
 
template<typename Other , typename T >
auto operator- (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a - b)
 
template<typename Other , typename T >
auto operator* (const Other &a, const GeneratorParam< T > &b) -> decltype(a *(T) b)
 Multiplication between GeneratorParam<T> and any type that supports operator* with T. More...
 
template<typename Other , typename T >
auto operator* (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a *b)
 
template<typename Other , typename T >
auto operator/ (const Other &a, const GeneratorParam< T > &b) -> decltype(a/(T) b)
 Division between GeneratorParam<T> and any type that supports operator/ with T. More...
 
template<typename Other , typename T >
auto operator/ (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a/b)
 
template<typename Other , typename T >
auto operator% (const Other &a, const GeneratorParam< T > &b) -> decltype(a %(T) b)
 Modulo between GeneratorParam<T> and any type that supports operator% with T. More...
 
template<typename Other , typename T >
auto operator% (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a % b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator> (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a > b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator< (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a< b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator>= (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a >=b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator<= (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a<=b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator== (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a==b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator!= (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a !=b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator&& (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a &&b)
 
template<typename T >
auto operator&& (const GeneratorParam< T > &a, const GeneratorParam< T > &b) -> decltype((T) a &&(T) b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto operator|| (const GeneratorParam< T > &a, const Other &b) -> decltype((T) a||b)
 
template<typename T >
auto operator|| (const GeneratorParam< T > &a, const GeneratorParam< T > &b) -> decltype((T) a||(T) b)
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto min (const GeneratorParam< T > &a, const Other &b) -> decltype(Internal::GeneratorMinMax::min_forward(a, b))
 
template<typename Other , typename T >
auto 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. More...
 
template<typename Other , typename T >
auto max (const GeneratorParam< T > &a, const Other &b) -> decltype(Internal::GeneratorMinMax::max_forward(a, b))
 
template<typename T >
auto operator! (const GeneratorParam< T > &a) -> decltype(!(T) a)
 Not operator for GeneratorParam. More...
 
Expr sum (Expr, const std::string &s="sum")
 An inline reduction. More...
 
Expr product (Expr, const std::string &s="product")
 
Expr maximum (Expr, const std::string &s="maximum")
 
Expr minimum (Expr, const std::string &s="minimum")
 
Expr sum (const RDom &, Expr, const std::string &s="sum")
 Variants of the inline reduction in which the RDom is stated explicitly. More...
 
Expr product (const RDom &, Expr, const std::string &s="product")
 
Expr maximum (const RDom &, Expr, const std::string &s="maximum")
 
Expr minimum (const RDom &, Expr, const std::string &s="minimum")
 
Tuple argmax (Expr, const std::string &s="argmax")
 Returns an Expr or Tuple representing the coordinates of the point in the RDom which minimizes or maximizes the expression. More...
 
Tuple argmin (Expr, const std::string &s="argmin")
 
Tuple argmax (const RDom &, Expr, const std::string &s="argmax")
 
Tuple argmin (const RDom &, Expr, const std::string &s="argmin")
 
template<typename T >
Expr cast (Expr a)
 Cast an expression to the halide type corresponding to the C++ type T. More...
 
Expr cast (Type t, Expr a)
 Cast an expression to a new type. More...
 
Expr operator+ (Expr a, Expr b)
 Return the sum of two expressions, doing any necessary type coercion using Internal::match_types. More...
 
Expr operator+ (Expr a, int b)
 Add an expression and a constant integer. More...
 
Expr operator+ (int a, Expr b)
 Add a constant integer and an expression. More...
 
Exproperator+= (Expr &a, Expr b)
 Modify the first expression to be the sum of two expressions, without changing its type. More...
 
Expr operator- (Expr a, Expr b)
 Return the difference of two expressions, doing any necessary type coercion using Internal::match_types. More...
 
Expr operator- (Expr a, int b)
 Subtracts a constant integer from an expression. More...
 
Expr operator- (int a, Expr b)
 Subtracts an expression from a constant integer. More...
 
Expr operator- (Expr a)
 Return the negative of the argument. More...
 
Exproperator-= (Expr &a, Expr b)
 Modify the first expression to be the difference of two expressions, without changing its type. More...
 
Expr operator* (Expr a, Expr b)
 Return the product of two expressions, doing any necessary type coercion using Internal::match_types. More...
 
Expr operator* (Expr a, int b)
 Multiply an expression and a constant integer. More...
 
Expr operator* (int a, Expr b)
 Multiply a constant integer and an expression. More...
 
Exproperator*= (Expr &a, Expr b)
 Modify the first expression to be the product of two expressions, without changing its type. More...
 
Expr operator/ (Expr a, Expr b)
 Return the ratio of two expressions, doing any necessary type coercion using Internal::match_types. More...
 
Exproperator/= (Expr &a, Expr b)
 Modify the first expression to be the ratio of two expressions, without changing its type. More...
 
Expr operator/ (Expr a, int b)
 Divides an expression by a constant integer. More...
 
Expr operator/ (int a, Expr b)
 Divides a constant integer by an expression. More...
 
Expr operator% (Expr a, Expr b)
 Return the first argument reduced modulo the second, doing any necessary type coercion using Internal::match_types. More...
 
Expr operator% (Expr a, int b)
 Mods an expression by a constant integer. More...
 
Expr operator% (int a, Expr b)
 Mods a constant integer by an expression. More...
 
Expr operator> (Expr a, Expr b)
 Return a boolean expression that tests whether the first argument is greater than the second, after doing any necessary type coercion using Internal::match_types. More...
 
Expr operator> (Expr a, int b)
 Return a boolean expression that tests whether an expression is greater than a constant integer. More...
 
Expr operator> (int a, Expr b)
 Return a boolean expression that tests whether a constant integer is greater than an expression. More...
 
Expr operator< (Expr a, Expr b)
 Return a boolean expression that tests whether the first argument is less than the second, after doing any necessary type coercion using Internal::match_types. More...
 
Expr operator< (Expr a, int b)
 Return a boolean expression that tests whether an expression is less than a constant integer. More...
 
Expr operator< (int a, Expr b)
 Return a boolean expression that tests whether a constant integer is less than an expression. More...
 
Expr operator<= (Expr a, Expr b)
 Return a boolean expression that tests whether the first argument is less than or equal to the second, after doing any necessary type coercion using Internal::match_types. More...
 
Expr operator<= (Expr a, int b)
 Return a boolean expression that tests whether an expression is less than or equal to a constant integer. More...
 
Expr operator<= (int a, Expr b)
 Return a boolean expression that tests whether a constant integer is less than or equal to an expression. More...
 
Expr operator>= (Expr a, Expr b)
 Return a boolean expression that tests whether the first argument is greater than or equal to the second, after doing any necessary type coercion using Internal::match_types. More...
 
Expr operator>= (const Expr &a, int b)
 Return a boolean expression that tests whether an expression is greater than or equal to a constant integer. More...
 
Expr operator>= (int a, const Expr &b)
 Return a boolean expression that tests whether a constant integer is greater than or equal to an expression. More...
 
Expr operator== (Expr a, Expr b)
 Return a boolean expression that tests whether the first argument is equal to the second, after doing any necessary type coercion using Internal::match_types. More...
 
Expr operator== (Expr a, int b)
 Return a boolean expression that tests whether an expression is equal to a constant integer. More...
 
Expr operator== (int a, Expr b)
 Return a boolean expression that tests whether a constant integer is equal to an expression. More...
 
Expr operator!= (Expr a, Expr b)
 Return a boolean expression that tests whether the first argument is not equal to the second, after doing any necessary type coercion using Internal::match_types. More...
 
Expr operator!= (Expr a, int b)
 Return a boolean expression that tests whether an expression is not equal to a constant integer. More...
 
Expr operator!= (int a, Expr b)
 Return a boolean expression that tests whether a constant integer is not equal to an expression. More...
 
Expr operator&& (Expr a, Expr b)
 Returns the logical and of the two arguments. More...
 
Expr operator&& (Expr a, bool b)
 Logical and of an Expr and a bool. More...
 
Expr operator&& (bool a, Expr b)
 
Expr operator|| (Expr a, Expr b)
 Returns the logical or of the two arguments. More...
 
Expr operator|| (Expr a, bool b)
 Logical or of an Expr and a bool. More...
 
Expr operator|| (bool a, Expr b)
 
Expr operator! (Expr a)
 Returns the logical not the argument. More...
 
Expr max (Expr a, Expr b)
 Returns an expression representing the greater of the two arguments, after doing any necessary type coercion using Internal::match_types. More...
 
Expr max (Expr a, int b)
 Returns an expression representing the greater of an expression and a constant integer. More...
 
Expr max (int a, Expr b)
 Returns an expression representing the greater of a constant integer and an expression. More...
 
Expr max (float a, Expr b)
 
Expr max (Expr a, float b)
 
template<typename A , typename B , typename C , typename... Rest, typename std::enable_if< Halide::Internal::all_are_convertible< Expr, Rest... >::value >::type * = nullptr>
Expr max (A &&a, B &&b, C &&c, Rest &&... rest)
 Returns an expression representing the greater of an expressions vector, after doing any necessary type coersion using Internal::match_types. More...
 
Expr min (Expr a, Expr b)
 
Expr min (Expr a, int b)
 Returns an expression representing the lesser of an expression and a constant integer. More...
 
Expr min (int a, Expr b)
 Returns an expression representing the lesser of a constant integer and an expression. More...
 
Expr min (float a, Expr b)
 
Expr min (Expr a, float b)
 
template<typename A , typename B , typename C , typename... Rest, typename std::enable_if< Halide::Internal::all_are_convertible< Expr, Rest... >::value >::type * = nullptr>
Expr min (A &&a, B &&b, C &&c, Rest &&... rest)
 Returns an expression representing the lesser of an expressions vector, after doing any necessary type coersion using Internal::match_types. More...
 
Expr operator+ (Expr a, float b)
 Operators on floats treats those floats as Exprs. More...
 
Expr operator+ (float a, Expr b)
 
Expr operator- (Expr a, float b)
 
Expr operator- (float a, Expr b)
 
Expr operator* (Expr a, float b)
 
Expr operator* (float a, Expr b)
 
Expr operator/ (Expr a, float b)
 
Expr operator/ (float a, Expr b)
 
Expr operator% (Expr a, float b)
 
Expr operator% (float a, Expr b)
 
Expr operator> (Expr a, float b)
 
Expr operator> (float a, Expr b)
 
Expr operator< (Expr a, float b)
 
Expr operator< (float a, Expr b)
 
Expr operator>= (Expr a, float b)
 
Expr operator>= (float a, Expr b)
 
Expr operator<= (Expr a, float b)
 
Expr operator<= (float a, Expr b)
 
Expr operator== (Expr a, float b)
 
Expr operator== (float a, Expr b)
 
Expr operator!= (Expr a, float b)
 
Expr operator!= (float a, Expr b)
 
Expr clamp (Expr a, const Expr &min_val, const Expr &max_val)
 Clamps an expression to lie within the given bounds. More...
 
Expr abs (Expr a)
 Returns the absolute value of a signed integer or floating-point expression. More...
 
Expr absd (Expr a, Expr b)
 Return the absolute difference between two values. More...
 
Expr select (Expr condition, Expr true_value, Expr false_value)
 Returns an expression similar to the ternary operator in C, except that it always evaluates all arguments. More...
 
template<typename... Args, typename std::enable_if< Halide::Internal::all_are_convertible< Expr, Args... >::value >::type * = nullptr>
Expr select (Expr c0, Expr v0, Expr c1, Expr v1, Args &&... args)
 A multi-way variant of select similar to a switch statement in C, which can accept multiple conditions and values in pairs. More...
 
Tuple tuple_select (const Tuple &condition, const Tuple &true_value, const Tuple &false_value)
 Equivalent of ternary select(), but taking/returning tuples. More...
 
Tuple tuple_select (const Expr &condition, const Tuple &true_value, const Tuple &false_value)
 
template<typename... Args>
Tuple tuple_select (const Tuple &c0, const Tuple &v0, const Tuple &c1, const Tuple &v1, Args &&... args)
 Equivalent of multiway select(), but taking/returning tuples. More...
 
template<typename... Args>
Tuple tuple_select (const Expr &c0, const Tuple &v0, const Expr &c1, const Tuple &v1, Args &&... args)
 
Expr mux (const Expr &id, const std::initializer_list< Expr > &values)
 Oftentimes we want to pack a list of expressions with the same type into a channel dimension, e.g., img(x, y, c) = select(c == 0, 100, // Red c == 1, 50, // Green 25); // Blue This is tedious when the list is long. More...
 
Expr mux (const Expr &id, const std::vector< Expr > &values)
 
Expr mux (const Expr &id, const Tuple &values)
 
Expr sin (Expr x)
 Return the sine of a floating-point expression. More...
 
Expr asin (Expr x)
 Return the arcsine of a floating-point expression. More...
 
Expr cos (Expr x)
 Return the cosine of a floating-point expression. More...
 
Expr acos (Expr x)
 Return the arccosine of a floating-point expression. More...
 
Expr tan (Expr x)
 Return the tangent of a floating-point expression. More...
 
Expr atan (Expr x)
 Return the arctangent of a floating-point expression. More...
 
Expr atan2 (Expr y, Expr x)
 Return the angle of a floating-point gradient. More...
 
Expr sinh (Expr x)
 Return the hyperbolic sine of a floating-point expression. More...
 
Expr asinh (Expr x)
 Return the hyperbolic arcsinhe of a floating-point expression. More...
 
Expr cosh (Expr x)
 Return the hyperbolic cosine of a floating-point expression. More...
 
Expr acosh (Expr x)
 Return the hyperbolic arccosine of a floating-point expression. More...
 
Expr tanh (Expr x)
 Return the hyperbolic tangent of a floating-point expression. More...
 
Expr atanh (Expr x)
 Return the hyperbolic arctangent of a floating-point expression. More...
 
Expr sqrt (Expr x)
 Return the square root of a floating-point expression. More...
 
Expr hypot (const Expr &x, const Expr &y)
 Return the square root of the sum of the squares of two floating-point expressions. More...
 
Expr exp (Expr x)
 Return the exponential of a floating-point expression. More...
 
Expr log (Expr x)
 Return the logarithm of a floating-point expression. More...
 
Expr pow (Expr x, Expr y)
 Return one floating point expression raised to the power of another. More...
 
Expr erf (const Expr &x)
 Evaluate the error function erf. More...
 
Expr fast_sin (const Expr &x)
 Fast vectorizable approximation to some trigonometric functions for Float(32). More...
 
Expr fast_cos (const Expr &x)
 
Expr fast_log (const Expr &x)
 Fast approximate cleanly vectorizable log for Float(32). More...
 
Expr fast_exp (const Expr &x)
 Fast approximate cleanly vectorizable exp for Float(32). More...
 
Expr fast_pow (Expr x, Expr y)
 Fast approximate cleanly vectorizable pow for Float(32). More...
 
Expr fast_inverse (Expr x)
 Fast approximate inverse for Float(32). More...
 
Expr fast_inverse_sqrt (Expr x)
 Fast approximate inverse square root for Float(32). More...
 
Expr floor (Expr x)
 Return the greatest whole number less than or equal to a floating-point expression. More...
 
Expr ceil (Expr x)
 Return the least whole number greater than or equal to a floating-point expression. More...
 
Expr round (Expr x)
 Return the whole number closest to a floating-point expression. More...
 
Expr trunc (Expr x)
 Return the integer part of a floating-point expression. More...
 
Expr is_nan (Expr x)
 Returns true if the argument is a Not a Number (NaN). More...
 
Expr is_inf (Expr x)
 Returns true if the argument is Inf or -Inf. More...
 
Expr is_finite (Expr x)
 Returns true if the argument is a finite value (ie, neither NaN nor Inf). More...
 
Expr fract (const Expr &x)
 Return the fractional part of a floating-point expression. More...
 
Expr reinterpret (Type t, Expr e)
 Reinterpret the bits of one value as another type. More...
 
template<typename T >
Expr reinterpret (Expr e)
 
Expr operator& (Expr x, Expr y)
 Return the bitwise and of two expressions (which need not have the same type). More...
 
Expr operator& (Expr x, int y)
 Return the bitwise and of an expression and an integer. More...
 
Expr operator& (int x, Expr y)
 
Expr operator| (Expr x, Expr y)
 Return the bitwise or of two expressions (which need not have the same type). More...
 
Expr operator| (Expr x, int y)
 Return the bitwise or of an expression and an integer. More...
 
Expr operator| (int x, Expr y)
 
Expr operator^ (Expr x, Expr y)
 Return the bitwise xor of two expressions (which need not have the same type). More...
 
Expr operator^ (Expr x, int y)
 Return the bitwise xor of an expression and an integer. More...
 
Expr operator^ (int x, Expr y)
 
Expr operator~ (Expr x)
 Return the bitwise not of an expression. More...
 
Expr operator<< (Expr x, Expr y)
 Shift the bits of an integer value left. More...
 
Expr operator<< (Expr x, int y)
 
Expr operator>> (Expr x, Expr y)
 Shift the bits of an integer value right. More...
 
Expr operator>> (Expr x, int y)
 
Expr lerp (Expr zero_val, Expr one_val, Expr weight)
 Linear interpolate between the two values according to a weight. More...
 
Expr popcount (Expr x)
 Count the number of set bits in an expression. More...
 
Expr count_leading_zeros (Expr x)
 Count the number of leading zero bits in an expression. More...
 
Expr count_trailing_zeros (Expr x)
 Count the number of trailing zero bits in an expression. More...
 
Expr div_round_to_zero (Expr x, Expr y)
 Divide two integers, rounding towards zero. More...
 
Expr mod_round_to_zero (Expr x, Expr y)
 Compute the remainder of dividing two integers, when division is rounding toward zero. More...
 
Expr random_float (Expr seed=Expr())
 Return a random variable representing a uniformly distributed float in the half-open interval [0.0f, 1.0f). More...
 
Expr random_uint (Expr seed=Expr())
 Return a random variable representing a uniformly distributed unsigned 32-bit integer. More...
 
Expr random_int (Expr seed=Expr())
 Return a random variable representing a uniformly distributed 32-bit integer. More...
 
Expr print (const std::vector< Expr > &values)
 Create an Expr that prints out its value whenever it is evaluated. More...
 
template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr print (Expr a, Args &&... args)
 
Expr print_when (Expr condition, const std::vector< Expr > &values)
 Create an Expr that prints whenever it is evaluated, provided that the condition is true. More...
 
template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr print_when (Expr condition, Expr a, Args &&... args)
 
Expr require (Expr condition, const std::vector< Expr > &values)
 Create an Expr that that guarantees a precondition. More...
 
template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr require (Expr condition, Expr value, Args &&... args)
 
Expr undef (Type t)
 Return an undef value of the given type. More...
 
template<typename T >
Expr undef ()
 
template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr memoize_tag (Expr result, Args &&... args)
 Control the values used in the memoization cache key for memoize. More...
 
Expr likely (Expr e)
 Expressions tagged with this intrinsic are considered to be part of the steady state of some loop with a nasty beginning and end (e.g. More...
 
Expr likely_if_innermost (Expr e)
 Equivalent to likely, but only triggers a loop partitioning if found in an innermost loop. More...
 
template<typename T >
Expr saturating_cast (Expr e)
 Cast an expression to the halide type corresponding to the C++ type T. More...
 
Expr saturating_cast (Type t, Expr e)
 Cast an expression to a new type, clamping to the minimum and maximum values of the result type. More...
 
Expr strict_float (Expr e)
 Makes a best effort attempt to preserve IEEE floating-point semantics in evaluating an expression. More...
 
Expr unsafe_promise_clamped (const Expr &value, const Expr &min, const Expr &max)
 Create an Expr that that promises another Expr is clamped but do not generate code to check the assertion or modify the value. More...
 
std::ostream & operator<< (std::ostream &stream, const DeviceAPI &)
 Emit a halide device api type in human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const MemoryType &)
 Emit a halide memory type in human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const TailStrategy &t)
 Emit a halide tail strategy in human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const LoopLevel &)
 Emit a halide LoopLevel in human-readable form. More...
 
Func lambda (const Expr &e)
 Create a zero-dimensional halide function that returns the given expression. More...
 
Func lambda (const Var &x, const Expr &e)
 Create a 1-D halide function in the first argument that returns the second argument. More...
 
Func lambda (const Var &x, const Var &y, const Expr &e)
 Create a 2-D halide function in the first two arguments that returns the last argument. More...
 
Func lambda (const Var &x, const Var &y, const Var &z, const Expr &e)
 Create a 3-D halide function in the first three arguments that returns the last argument. More...
 
Func lambda (const Var &x, const Var &y, const Var &z, const Var &w, const Expr &e)
 Create a 4-D halide function in the first four arguments that returns the last argument. More...
 
Func lambda (const Var &x, const Var &y, const Var &z, const Var &w, const Var &v, const Expr &e)
 Create a 5-D halide function in the first five arguments that returns the last argument. More...
 
std::unique_ptr< llvm::Module > compile_module_to_llvm_module (const Module &module, llvm::LLVMContext &context)
 Generate an LLVM module. More...
 
std::unique_ptr< llvm::raw_fd_ostream > make_raw_fd_ostream (const std::string &filename)
 Construct an llvm output stream for writing to files. More...
 
void compile_llvm_module_to_object (llvm::Module &module, Internal::LLVMOStream &out)
 Compile an LLVM module to native targets (objects, native assembly). More...
 
void compile_llvm_module_to_assembly (llvm::Module &module, Internal::LLVMOStream &out)
 
void compile_llvm_module_to_llvm_bitcode (llvm::Module &module, Internal::LLVMOStream &out)
 Compile an LLVM module to LLVM targets (bitcode, LLVM assembly). More...
 
void compile_llvm_module_to_llvm_assembly (llvm::Module &module, Internal::LLVMOStream &out)
 
void create_static_library (const std::vector< std::string > &src_files, const Target &target, const std::string &dst_file, bool deterministic=true)
 Concatenate the list of src_files into dst_file, using the appropriate static library format for the given target (e.g., .a or .lib). More...
 
Module link_modules (const std::string &name, const std::vector< Module > &modules)
 Link a set of modules together into one module. More...
 
void compile_standalone_runtime (const std::string &object_filename, Target t)
 Create an object file containing the Halide runtime for a given target. More...
 
std::map< Output, std::string > compile_standalone_runtime (const std::map< Output, std::string > &output_files, Target t)
 Create an object and/or static library file containing the Halide runtime for a given target. More...
 
void compile_multitarget (const std::string &fn_name, const std::map< Output, std::string > &output_files, const std::vector< Target > &targets, const std::vector< std::string > &suffixes, const ModuleFactory &module_factory, const CompilerLoggerFactory &compiler_logger_factory=nullptr)
 
Expr user_context_value ()
 Returns an Expr corresponding to the user context passed to the function (if any). More...
 
std::ostream & operator<< (std::ostream &stream, const RVar &)
 Emit an RVar in a human-readable form. More...
 
std::ostream & operator<< (std::ostream &stream, const RDom &)
 Emit an RDom in a human-readable form. More...
 
Target get_host_target ()
 Return the target corresponding to the host machine. More...
 
Target get_target_from_environment ()
 Return the target that Halide will use. More...
 
Target get_jit_target_from_environment ()
 Return the target that Halide will use for jit-compilation. More...
 
Target::Feature target_feature_for_device_api (DeviceAPI api)
 Get the Target feature corresponding to a DeviceAPI. More...
 
Type Int (int bits, int lanes=1)
 Constructing a signed integer type. More...
 
Type UInt (int bits, int lanes=1)
 Constructing an unsigned integer type. More...
 
Type Float (int bits, int lanes=1)
 Construct a floating-point type. More...
 
Type BFloat (int bits, int lanes=1)
 Construct a floating-point type in the bfloat format. More...
 
Type Bool (int lanes=1)
 Construct a boolean type. More...
 
Type Handle (int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
 Construct a handle type. More...
 
template<typename T >
Type type_of ()
 Construct the halide equivalent of a C type. More...
 
std::string type_to_c_type (Type type, bool include_space, bool c_plus_plus=true)
 Halide type to a C++ type. More...
 
void load_plugin (const std::string &lib_name)
 Load a plugin in the form of a dynamic library (e.g. More...
 

Variables

const int head1_channels = 8
 
const int head1_w = 40
 
const int head1_h = 7
 
const int head2_channels = 24
 
const int head2_w = 39
 
const int conv1_channels = 32
 
const DeviceAPI all_device_apis []
 An array containing all the device apis. More...
 

Detailed Description

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.

Defines methods for manipulating and analyzing boolean expressions.

This file defines the LoopNest, which is our representation of a Halide schedule, and contains methods to generate candidates for scheduling as well as extract a featurization that can be used to cost each candidate.

Typedef Documentation

◆ Region

typedef std::vector<Range> Halide::Region

A multi-dimensional box.

The outer product of the elements

Definition at line 343 of file Expr.h.

◆ ScheduleHandle

Definition at line 462 of file Func.h.

◆ ModuleFactory

using Halide::ModuleFactory = typedef std::function<Module(const std::string &fn_name, const Target &target)>

Definition at line 221 of file Module.h.

◆ CompilerLoggerFactory

using Halide::CompilerLoggerFactory = typedef std::function<std::unique_ptr<Internal::CompilerLogger>(const std::string &fn_name, const Target &target)>

Definition at line 222 of file Module.h.

◆ AutoSchedulerFn

using Halide::AutoSchedulerFn = typedef std::function<void(const Pipeline &, const Target &, const MachineParams &, AutoSchedulerResults *outputs)>

Definition at line 93 of file Pipeline.h.

Enumeration Type Documentation

◆ DeviceAPI

enum Halide::DeviceAPI
strong

An enum describing a type of device API.

Used by schedules, and in the For loop IR node.

Enumerator
None 
Host 

Used to denote for loops that run on the same device as the containing code.

Default_GPU 
CUDA 
OpenCL 
GLSL 
OpenGLCompute 
Metal 
Hexagon 
HexagonDma 
D3D12Compute 

Definition at line 15 of file DeviceAPI.h.

◆ MemoryType

enum Halide::MemoryType
strong

An enum describing different address spaces to be used with Func::store_in.

Enumerator
Auto 

Let Halide select a storage type automatically.

Heap 

Heap/global memory.

Allocated using halide_malloc, or halide_device_malloc

Stack 

Stack memory.

Allocated using alloca. Requires a constant size. Corresponds to per-thread local memory on the GPU. If all accesses are at constant coordinates, may be promoted into the register file at the discretion of the register allocator.

Register 

Register memory.

The allocation should be promoted into the register file. All stores must be at constant coordinates. May be spilled to the stack at the discretion of the register allocator.

GPUShared 

Allocation is stored in GPU shared memory.

Also known as "local" in OpenCL, and "threadgroup" in metal. Can be shared across GPU threads within the same block.

LockedCache 

Allocate Locked Cache Memory to act as local memory.

VTCM 

Vector Tightly Coupled Memory.

HVX (Hexagon) local memory available on v65+. This memory has higher performance and lower power. Ideal for intermediate buffers. Necessary for vgather-vscatter instructions on Hexagon

Definition at line 346 of file Expr.h.

◆ NameMangling

enum Halide::NameMangling
strong

An enum to specify calling convention for extern stages.

Enumerator
Default 

Match whatever is specified in the Target.

No name mangling.

CPlusPlus 

C++ name mangling.

Definition at line 24 of file Function.h.

◆ Output

enum Halide::Output
strong

Enums specifying various kinds of outputs that can be produced from a Halide Pipeline.

Enumerator
assembly 
bitcode 
c_header 
c_source 
compiler_log 
cpp_stub 
featurization 
llvm_assembly 
object 
python_extension 
pytorch_wrapper 
registration 
schedule 
static_library 
stmt 
stmt_html 

Definition at line 28 of file Module.h.

◆ LinkageType

enum Halide::LinkageType
strong

Type of linkage a function in a lowered Halide module can have.

Also controls whether auxiliary functions and metadata are generated.

Enumerator
External 

Visible externally.

ExternalPlusMetadata 

Visible externally. Argument metadata and an argv wrapper are also generated.

Internal 

Not visible externally, similar to 'static' linkage in C.

Definition at line 49 of file Module.h.

◆ StmtOutputFormat

Used to determine if the output printed to file should be as a normal string or as an HTML file which can be opened in a browerser and manipulated via JS and CSS.

Enumerator
Text 
HTML 

Definition at line 61 of file Pipeline.h.

◆ PrefetchBoundStrategy

Different ways to handle accesses outside the original extents in a prefetch.

Enumerator
Clamp 

Clamp the prefetched exprs by intersecting the prefetched region with the original extents.

This may make the exprs of the prefetched region more complicated.

GuardWithIf 

Guard the prefetch with if-guards that ignores the prefetch if any of the prefetched region ever goes beyond the original extents (i.e.

all or nothing).

NonFaulting 

Leave the prefetched exprs as are (no if-guards around the prefetch and no intersecting with the original extents).

This makes the prefetch exprs simpler but this may cause prefetching of region outside the original extents. This is good if prefetch won't fault when accessing region outside the original extents.

Definition at line 16 of file PrefetchDirective.h.

◆ TailStrategy

enum Halide::TailStrategy
strong

Different ways to handle a tail case in a split when the factor does not provably divide the extent.

Enumerator
RoundUp 

Round up the extent to be a multiple of the split factor.

Not legal for RVars, as it would change the meaning of the algorithm. Pros: generates the simplest, fastest code. Cons: if used on a stage that reads from the input or writes to the output, constrains the input or output size to be a multiple of the split factor.

GuardWithIf 

Guard the inner loop with an if statement that prevents evaluation beyond the original extent.

Always legal. The if statement is treated like a boundary condition, and factored out into a loop epilogue if possible. Pros: no redundant re-evaluation; does not constrain input our output sizes. Cons: increases code size due to separate tail-case handling; vectorization will scalarize in the tail case to handle the if statement.

ShiftInwards 

Prevent evaluation beyond the original extent by shifting the tail case inwards, re-evaluating some points near the end.

Only legal for pure variables in pure definitions. If the inner loop is very simple, the tail case is treated like a boundary condition and factored out into an epilogue.

This is a good trade-off between several factors. Like RoundUp, it supports vectorization well, because the inner loop is always a fixed size with no data-dependent branching. It increases code size slightly for inner loops due to the epilogue handling, but not for outer loops (e.g. loops over tiles). If used on a stage that reads from an input or writes to an output, this stategy only requires that the input/output extent be at least the split factor, instead of a multiple of the split factor as with RoundUp.

Auto 

For pure definitions use ShiftInwards.

For pure vars in update definitions use RoundUp. For RVars in update definitions use GuardWithIf.

Definition at line 32 of file Schedule.h.

◆ LoopAlignStrategy

Different ways to handle the case when the start/end of the loops of stages computed with (fused) are not aligned.

Enumerator
AlignStart 

Shift the start of the fused loops to align.

AlignEnd 

Shift the end of the fused loops to align.

NoAlign 

compute_with will make no attempt to align the start/end of the fused loops.

Auto 

By default, LoopAlignStrategy is set to NoAlign.

Definition at line 77 of file Schedule.h.

Function Documentation

◆ make_default_cost_model()

std::unique_ptr<DefaultCostModel> Halide::make_default_cost_model ( const std::string &  weights_in_dir = "",
const std::string &  weights_out_dir = "",
bool  randomize_weights = false 
)

◆ codegen_llvm()

std::unique_ptr<llvm::Module> Halide::codegen_llvm ( const Module module,
llvm::LLVMContext &  context 
)

Given a Halide module, generate an llvm::Module.

◆ operator<<() [1/12]

std::ostream & Halide::operator<< ( std::ostream &  stream,
const Expr  
)

Emit an expression on an output stream (such as std::cout) in human-readable form.

◆ operator<<() [2/12]

std::ostream & Halide::operator<< ( std::ostream &  stream,
const Type  
)

Emit a halide type on an output stream (such as std::cout) in human-readable form.

◆ operator<<() [3/12]

std::ostream & Halide::operator<< ( std::ostream &  stream,
const Module  
)

Emit a halide Module on an output stream (such as std::cout) in human-readable form.

◆ operator<<() [4/12]

std::ostream & Halide::operator<< ( std::ostream &  stream,
const Target  
)

Emit a halide Target in a human readable form.

◆ propagate_adjoints() [1/3]

Derivative Halide::propagate_adjoints ( const Func output,
const Func adjoint,
const Region output_bounds 
)

Given a Func and a corresponding adjoint, (back)propagate the adjoint to all dependent Funcs, buffers, and parameters.

The bounds of output and adjoint need to be specified with pair {min, extent} For each Func the output depends on, and for the pure definition and each update of that Func, it generates a derivative Func stored in the Derivative.

◆ propagate_adjoints() [2/3]

Derivative Halide::propagate_adjoints ( const Func output,
const Buffer< float > &  adjoint 
)

Given a Func and a corresponding adjoint buffer, (back)propagate the adjoint to all dependent Funcs, buffers, and parameters.

For each Func the output depends on, and for the pure definition and each update of that Func, it generates a derivative Func stored in the Derivative.

◆ propagate_adjoints() [3/3]

Derivative Halide::propagate_adjoints ( const Func output)

Given a scalar Func with size 1, (back)propagate the gradient to all dependent Funcs, buffers, and parameters.

For each Func the output depends on, and for the pure definition and each update of that Func, it generates a derivative Func stored in the Derivative.

◆ get_device_interface_for_device_api()

const halide_device_interface_t* Halide::get_device_interface_for_device_api ( DeviceAPI  d,
const Target t = get_jit_target_from_environment(),
const char *  error_site = nullptr 
)

Gets the appropriate halide_device_interface_t * for a DeviceAPI.

If error_site is non-null, e.g. the name of the routine calling get_device_interface_for_device_api, a user_error is reported if the requested device API is not enabled in or supported by the target, Halide has been compiled without this device API, or the device API is None or Host or a bad value. The error_site argument is printed in the error message. If error_site is null, this routine returns nullptr instead of calling user_error.

Referenced by Halide::Buffer< void >::copy_to_device(), Halide::Buffer< void >::device_malloc(), and Halide::Buffer< void >::device_wrap_native().

◆ get_default_device_api_for_target()

DeviceAPI Halide::get_default_device_api_for_target ( const Target t)

Get the specific DeviceAPI that Halide would select when presented with DeviceAPI::Default_GPU for a given target.

If no suitable api is enabled in the target, returns DeviceAPI::Host.

◆ host_supports_target_device()

bool Halide::host_supports_target_device ( const Target t)

This attempts to sniff whether a given Target (and its implied DeviceAPI) is usable on the current host.

If it appears to be usable, return true; if not, return false. Note that a return value of true does not guarantee that future usage of that device will succeed; it is intended mainly as a simple diagnostic to allow early-exit when a desired device is definitely not usable. Also note that this call is NOT threadsafe, as it temporarily redirect various global error-handling hooks in Halide.

Examples
tutorial/lesson_12_using_the_gpu.cpp.

◆ exceptions_enabled()

bool Halide::exceptions_enabled ( )

Query whether Halide was compiled with exceptions.

◆ set_custom_compile_time_error_reporter()

void Halide::set_custom_compile_time_error_reporter ( CompileTimeErrorReporter error_reporter)

The default error reporter logs to stderr, then throws an exception (if HALIDE_WITH_EXCEPTIONS) or calls abort (if not).

This allows customization of that behavior if a more gentle response to error reporting is desired. Note that error_reporter is expected to remain valid across all Halide usage; it is up to the caller to ensure that this is the case (and to do any cleanup necessary).

◆ fast_integer_divide()

Expr Halide::fast_integer_divide ( Expr  numerator,
Expr  denominator 
)

Integer division by small values can be done exactly as multiplies and shifts.

This function does integer division for numerators of various integer types (8, 16, 32 bit signed and unsigned) numerators and uint8 denominators. The type of the result is the type of the numerator. The unsigned version is faster than the signed version, so cast the numerator to an unsigned int if you know it's positive.

If your divisor is compile-time constant, Halide performs a slightly better optimization automatically, so there's no need to use this function (but it won't hurt).

This function vectorizes well on arm, and well on x86 for 16 and 8 bit vectors. For 32-bit vectors on x86 you're better off using native integer division.

Also, this routine treats division by zero as division by

  1. I.e. it interprets the uint8 divisor as a number from 1 to 256 inclusive.

◆ fast_integer_modulo()

Expr Halide::fast_integer_modulo ( Expr  numerator,
Expr  denominator 
)

Use the fast integer division tables to implement a modulo operation via the Euclidean identity: ab = a - (a/b)*b.

◆ min() [1/9]

◆ max() [1/9]

◆ evaluate() [1/2]

template<typename T >
HALIDE_NO_USER_CODE_INLINE T Halide::evaluate ( const Expr e)

JIT-Compile and run enough code to evaluate a Halide expression.

This can be thought of as a scalar version of Func::realize

Definition at line 2485 of file Func.h.

References Halide::Func::realize(), Halide::Expr::type(), and user_assert.

◆ evaluate() [2/2]

template<typename First , typename... Rest>
HALIDE_NO_USER_CODE_INLINE void Halide::evaluate ( Tuple  t,
First  first,
Rest &&...  rest 
)

JIT-compile and run enough code to evaluate a Halide Tuple.

Definition at line 2498 of file Func.h.

References Halide::Internal::assign_results(), Halide::Internal::check_types(), and Halide::Func::realize().

◆ evaluate_may_gpu() [1/2]

template<typename T >
HALIDE_NO_USER_CODE_INLINE T Halide::evaluate_may_gpu ( const Expr e)

JIT-Compile and run enough code to evaluate a Halide expression.

This can be thought of as a scalar version of Func::realize. Can use GPU if jit target from environment specifies one.

Definition at line 2527 of file Func.h.

References Halide::Func::realize(), Halide::Internal::schedule_scalar(), Halide::Expr::type(), and user_assert.

◆ evaluate_may_gpu() [2/2]

template<typename First , typename... Rest>
HALIDE_NO_USER_CODE_INLINE void Halide::evaluate_may_gpu ( Tuple  t,
First  first,
Rest &&...  rest 
)

JIT-compile and run enough code to evaluate a Halide Tuple.

Can use GPU if jit target from environment specifies one.

Definition at line 2543 of file Func.h.

References Halide::Internal::assign_results(), Halide::Internal::check_types(), Halide::Func::realize(), and Halide::Internal::schedule_scalar().

◆ operator+() [1/7]

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.

Returns type of underlying operator+.

Examples
tutorial/lesson_13_tuples.cpp.

Definition at line 1016 of file Generator.h.

◆ operator+() [2/7]

template<typename Other , typename T >
auto Halide::operator+ ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a + b)

Definition at line 1020 of file Generator.h.

◆ operator-() [1/8]

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.

Returns type of underlying operator-.

Definition at line 1029 of file Generator.h.

◆ operator-() [2/8]

template<typename Other , typename T >
auto Halide::operator- ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a - b)

Definition at line 1033 of file Generator.h.

◆ operator*() [1/7]

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.

Returns type of underlying operator*.

Examples
tutorial/lesson_13_tuples.cpp.

Definition at line 1042 of file Generator.h.

◆ operator*() [2/7]

template<typename Other , typename T >
auto Halide::operator* ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a * b)

Definition at line 1046 of file Generator.h.

◆ operator/() [1/7]

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.

Returns type of underlying operator/.

Definition at line 1055 of file Generator.h.

◆ operator/() [2/7]

template<typename Other , typename T >
auto Halide::operator/ ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a / b)

Definition at line 1059 of file Generator.h.

◆ operator%() [1/7]

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.

Returns type of underlying operator%.

Definition at line 1068 of file Generator.h.

◆ operator%() [2/7]

template<typename Other , typename T >
auto Halide::operator% ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a % b)

Definition at line 1072 of file Generator.h.

◆ operator>() [1/7]

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.

Returns type of underlying operator>.

Definition at line 1081 of file Generator.h.

◆ operator>() [2/7]

template<typename Other , typename T >
auto Halide::operator> ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a > b)

Definition at line 1085 of file Generator.h.

◆ operator<() [1/7]

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.

Returns type of underlying operator<.

Definition at line 1094 of file Generator.h.

◆ operator<() [2/7]

template<typename Other , typename T >
auto Halide::operator< ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a < b)

Definition at line 1098 of file Generator.h.

◆ operator>=() [1/7]

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.

Returns type of underlying operator>=.

Definition at line 1107 of file Generator.h.

◆ operator>=() [2/7]

template<typename Other , typename T >
auto Halide::operator>= ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a >= b)

Definition at line 1111 of file Generator.h.

◆ operator<=() [1/7]

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.

Returns type of underlying operator<=.

Definition at line 1120 of file Generator.h.

◆ operator<=() [2/7]

template<typename Other , typename T >
auto Halide::operator<= ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a <= b)

Definition at line 1124 of file Generator.h.

◆ operator==() [1/7]

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.

Returns type of underlying operator==.

Definition at line 1133 of file Generator.h.

◆ operator==() [2/7]

template<typename Other , typename T >
auto Halide::operator== ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a == b)

Definition at line 1137 of file Generator.h.

◆ operator!=() [1/7]

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.

Returns type of underlying operator!=.

Definition at line 1146 of file Generator.h.

◆ operator!=() [2/7]

template<typename Other , typename T >
auto Halide::operator!= ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a != b)

Definition at line 1150 of file Generator.h.

◆ operator&&() [1/6]

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.

Returns type of underlying operator&&.

Definition at line 1159 of file Generator.h.

◆ operator&&() [2/6]

template<typename Other , typename T >
auto Halide::operator&& ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a && b)

Definition at line 1163 of file Generator.h.

◆ operator&&() [3/6]

template<typename T >
auto Halide::operator&& ( const GeneratorParam< T > &  a,
const GeneratorParam< T > &  b 
) -> decltype((T)a && (T)b)

Definition at line 1167 of file Generator.h.

◆ operator||() [1/6]

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.

Returns type of underlying operator||.

Definition at line 1176 of file Generator.h.

◆ operator||() [2/6]

template<typename Other , typename T >
auto Halide::operator|| ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype((T)a || b)

Definition at line 1180 of file Generator.h.

◆ operator||() [3/6]

template<typename T >
auto Halide::operator|| ( const GeneratorParam< T > &  a,
const GeneratorParam< T > &  b 
) -> decltype((T)a || (T)b)

Definition at line 1184 of file Generator.h.

◆ min() [2/9]

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.

Will automatically import std::min. Returns type of underlying min call.

Definition at line 1224 of file Generator.h.

References Halide::Internal::GeneratorMinMax::min_forward().

◆ min() [3/9]

template<typename Other , typename T >
auto Halide::min ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype(Internal::GeneratorMinMax::min_forward(a, b))

Definition at line 1228 of file Generator.h.

References Halide::Internal::GeneratorMinMax::min_forward().

◆ max() [2/9]

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.

Will automatically import std::max. Returns type of underlying max call.

Definition at line 1237 of file Generator.h.

References Halide::Internal::GeneratorMinMax::max_forward().

◆ max() [3/9]

template<typename Other , typename T >
auto Halide::max ( const GeneratorParam< T > &  a,
const Other &  b 
) -> decltype(Internal::GeneratorMinMax::max_forward(a, b))

Definition at line 1241 of file Generator.h.

References Halide::Internal::GeneratorMinMax::max_forward().

◆ operator!() [1/2]

template<typename T >
auto Halide::operator! ( const GeneratorParam< T > &  a) -> decltype(!(T)a)

Not operator for GeneratorParam.

Definition at line 1248 of file Generator.h.

◆ sum() [1/2]

Expr Halide::sum ( Expr  ,
const std::string &  s = "sum" 
)

An inline reduction.

This is suitable for convolution-type operations - the reduction will be computed in the innermost loop that it is used in. The argument may contain free or implicit variables, and must refer to some reduction domain. The free variables are still free in the return value, but the reduction domain is captured - the result expression does not refer to a reduction domain and can be used in a pure function definition.

An example using sum :

Func f, g;
Var x;
RDom r(0, 10);
f(x) = x*x;
g(x) = sum(f(x + r));

Here g computes some blur of x, but g is still a pure function. The sum is being computed by an anonymous reduction function that is scheduled innermost within g.

Examples
tutorial/lesson_09_update_definitions.cpp.

Referenced by do_cost_model_schedule().

◆ product() [1/2]

Expr Halide::product ( Expr  ,
const std::string &  s = "product" 
)

◆ maximum() [1/2]

Expr Halide::maximum ( Expr  ,
const std::string &  s = "maximum" 
)

◆ minimum() [1/2]

Expr Halide::minimum ( Expr  ,
const std::string &  s = "minimum" 
)

◆ sum() [2/2]

Expr Halide::sum ( const RDom ,
Expr  ,
const std::string &  s = "sum" 
)

Variants of the inline reduction in which the RDom is stated explicitly.

The expression can refer to multiple RDoms, and only the inner one is captured by the reduction. This allows you to write expressions like:

RDom r1(0, 10), r2(0, 10), r3(0, 10);
Expr e = minimum(r1, product(r2, sum(r3, r1 + r2 + r3)));

◆ product() [2/2]

Expr Halide::product ( const RDom ,
Expr  ,
const std::string &  s = "product" 
)

◆ maximum() [2/2]

Expr Halide::maximum ( const RDom ,
Expr  ,
const std::string &  s = "maximum" 
)

◆ minimum() [2/2]

Expr Halide::minimum ( const RDom ,
Expr  ,
const std::string &  s = "minimum" 
)

◆ argmax() [1/2]

Tuple Halide::argmax ( Expr  ,
const std::string &  s = "argmax" 
)

Returns an Expr or Tuple representing the coordinates of the point in the RDom which minimizes or maximizes the expression.

The expression must refer to some RDom. Also returns the extreme value of the expression as the last element of the tuple.

◆ argmin() [1/2]

Tuple Halide::argmin ( Expr  ,
const std::string &  s = "argmin" 
)

◆ argmax() [2/2]

Tuple Halide::argmax ( const RDom ,
Expr  ,
const std::string &  s = "argmax" 
)

◆ argmin() [2/2]

Tuple Halide::argmin ( const RDom ,
Expr  ,
const std::string &  s = "argmin" 
)

◆ cast() [1/2]

◆ cast() [2/2]

Expr Halide::cast ( Type  t,
Expr  a 
)

Cast an expression to a new type.

◆ operator+() [3/7]

Expr Halide::operator+ ( Expr  a,
Expr  b 
)

Return the sum of two expressions, doing any necessary type coercion using Internal::match_types.

◆ operator+() [4/7]

Expr Halide::operator+ ( Expr  a,
int  b 
)

Add an expression and a constant integer.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator+() [5/7]

Expr Halide::operator+ ( int  a,
Expr  b 
)

Add a constant integer and an expression.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator+=()

Expr& Halide::operator+= ( Expr a,
Expr  b 
)

Modify the first expression to be the sum of two expressions, without changing its type.

This casts the second argument to match the type of the first.

◆ operator-() [3/8]

Expr Halide::operator- ( Expr  a,
Expr  b 
)

Return the difference of two expressions, doing any necessary type coercion using Internal::match_types.

◆ operator-() [4/8]

Expr Halide::operator- ( Expr  a,
int  b 
)

Subtracts a constant integer from an expression.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator-() [5/8]

Expr Halide::operator- ( int  a,
Expr  b 
)

Subtracts an expression from a constant integer.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator-() [6/8]

Expr Halide::operator- ( Expr  a)

Return the negative of the argument.

Does no type casting, so more formally: return that number which when added to the original, yields zero of the same type. For unsigned integers the negative is still an unsigned integer. E.g. in UInt(8), the negative of 56 is 200, because 56 + 200 == 0

◆ operator-=()

Expr& Halide::operator-= ( Expr a,
Expr  b 
)

Modify the first expression to be the difference of two expressions, without changing its type.

This casts the second argument to match the type of the first.

◆ operator*() [3/7]

Expr Halide::operator* ( Expr  a,
Expr  b 
)

Return the product of two expressions, doing any necessary type coercion using Internal::match_types.

◆ operator*() [4/7]

Expr Halide::operator* ( Expr  a,
int  b 
)

Multiply an expression and a constant integer.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator*() [5/7]

Expr Halide::operator* ( int  a,
Expr  b 
)

Multiply a constant integer and an expression.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator*=()

Expr& Halide::operator*= ( Expr a,
Expr  b 
)

Modify the first expression to be the product of two expressions, without changing its type.

This casts the second argument to match the type of the first.

◆ operator/() [3/7]

Expr Halide::operator/ ( Expr  a,
Expr  b 
)

Return the ratio of two expressions, doing any necessary type coercion using Internal::match_types.

Note that integer division in Halide is not the same as integer division in C-like languages in two ways.

First, signed integer division in Halide rounds according to the sign of the denominator. This means towards minus infinity for positive denominators, and towards positive infinity for negative denominators. This is unlike C, which rounds towards zero. This decision ensures that upsampling expressions like f(x/2, y/2) don't have funny discontinuities when x and y cross zero.

Second, division by zero returns zero instead of faulting. For types where overflow is defined behavior, division of the largest negative signed integer by -1 returns the larged negative signed integer for the type (i.e. it wraps). This ensures that a division operation can never have a side-effect, which is helpful in Halide because scheduling directives can expand the domain of computation of a Func, potentially introducing new zero-division.

◆ operator/=()

Expr& Halide::operator/= ( Expr a,
Expr  b 
)

Modify the first expression to be the ratio of two expressions, without changing its type.

This casts the second argument to match the type of the first. Note that signed integer division in Halide rounds towards minus infinity, unlike C, which rounds towards zero.

◆ operator/() [4/7]

Expr Halide::operator/ ( Expr  a,
int  b 
)

Divides an expression by a constant integer.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator/() [5/7]

Expr Halide::operator/ ( int  a,
Expr  b 
)

Divides a constant integer by an expression.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator%() [3/7]

Expr Halide::operator% ( Expr  a,
Expr  b 
)

Return the first argument reduced modulo the second, doing any necessary type coercion using Internal::match_types.

There are two key differences between C-like languages and Halide for the modulo operation, which complement the way division works.

First, the result is never negative, so x % 2 is always zero or one, unlike in C-like languages. x % -2 is equivalent, and is also always zero or one. Second, mod by zero evaluates to zero (unlike in C, where it faults). This makes modulo, like division, a side-effect-free operation.

◆ operator%() [4/7]

Expr Halide::operator% ( Expr  a,
int  b 
)

Mods an expression by a constant integer.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator%() [5/7]

Expr Halide::operator% ( int  a,
Expr  b 
)

Mods a constant integer by an expression.

Coerces the type of the integer to match the type of the expression. Errors if the integer cannot be represented in the type of the expression.

◆ operator>() [3/7]

Expr Halide::operator> ( Expr  a,
Expr  b 
)

Return a boolean expression that tests whether the first argument is greater than the second, after doing any necessary type coercion using Internal::match_types.

◆ operator>() [4/7]

Expr Halide::operator> ( Expr  a,
int  b 
)

Return a boolean expression that tests whether an expression is greater than a constant integer.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator>() [5/7]

Expr Halide::operator> ( int  a,
Expr  b 
)

Return a boolean expression that tests whether a constant integer is greater than an expression.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator<() [3/7]

Expr Halide::operator< ( Expr  a,
Expr  b 
)

Return a boolean expression that tests whether the first argument is less than the second, after doing any necessary type coercion using Internal::match_types.

◆ operator<() [4/7]

Expr Halide::operator< ( Expr  a,
int  b 
)

Return a boolean expression that tests whether an expression is less than a constant integer.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator<() [5/7]

Expr Halide::operator< ( int  a,
Expr  b 
)

Return a boolean expression that tests whether a constant integer is less than an expression.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator<=() [3/7]

Expr Halide::operator<= ( Expr  a,
Expr  b 
)

Return a boolean expression that tests whether the first argument is less than or equal to the second, after doing any necessary type coercion using Internal::match_types.

◆ operator<=() [4/7]

Expr Halide::operator<= ( Expr  a,
int  b 
)

Return a boolean expression that tests whether an expression is less than or equal to a constant integer.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator<=() [5/7]

Expr Halide::operator<= ( int  a,
Expr  b 
)

Return a boolean expression that tests whether a constant integer is less than or equal to an expression.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator>=() [3/7]

Expr Halide::operator>= ( Expr  a,
Expr  b 
)

Return a boolean expression that tests whether the first argument is greater than or equal to the second, after doing any necessary type coercion using Internal::match_types.

◆ operator>=() [4/7]

Expr Halide::operator>= ( const Expr a,
int  b 
)

Return a boolean expression that tests whether an expression is greater than or equal to a constant integer.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator>=() [5/7]

Expr Halide::operator>= ( int  a,
const Expr b 
)

Return a boolean expression that tests whether a constant integer is greater than or equal to an expression.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator==() [3/7]

Expr Halide::operator== ( Expr  a,
Expr  b 
)

Return a boolean expression that tests whether the first argument is equal to the second, after doing any necessary type coercion using Internal::match_types.

◆ operator==() [4/7]

Expr Halide::operator== ( Expr  a,
int  b 
)

Return a boolean expression that tests whether an expression is equal to a constant integer.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator==() [5/7]

Expr Halide::operator== ( int  a,
Expr  b 
)

Return a boolean expression that tests whether a constant integer is equal to an expression.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator!=() [3/7]

Expr Halide::operator!= ( Expr  a,
Expr  b 
)

Return a boolean expression that tests whether the first argument is not equal to the second, after doing any necessary type coercion using Internal::match_types.

◆ operator!=() [4/7]

Expr Halide::operator!= ( Expr  a,
int  b 
)

Return a boolean expression that tests whether an expression is not equal to a constant integer.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator!=() [5/7]

Expr Halide::operator!= ( int  a,
Expr  b 
)

Return a boolean expression that tests whether a constant integer is not equal to an expression.

Coerces the integer to the type of the expression. Errors if the integer is not representable in that type.

◆ operator&&() [4/6]

Expr Halide::operator&& ( Expr  a,
Expr  b 
)

Returns the logical and of the two arguments.

◆ operator&&() [5/6]

Expr Halide::operator&& ( Expr  a,
bool  b 
)

Logical and of an Expr and a bool.

Either returns the Expr or an Expr representing false, depending on the bool.

◆ operator&&() [6/6]

Expr Halide::operator&& ( bool  a,
Expr  b 
)

◆ operator||() [4/6]

Expr Halide::operator|| ( Expr  a,
Expr  b 
)

Returns the logical or of the two arguments.

◆ operator||() [5/6]

Expr Halide::operator|| ( Expr  a,
bool  b 
)

Logical or of an Expr and a bool.

Either returns the Expr or an Expr representing true, depending on the bool.

◆ operator||() [6/6]

Expr Halide::operator|| ( bool  a,
Expr  b 
)

◆ operator!() [2/2]

Expr Halide::operator! ( Expr  a)

Returns the logical not the argument.

◆ max() [4/9]

Expr Halide::max ( Expr  a,
Expr  b 
)

Returns an expression representing the greater of the two arguments, after doing any necessary type coercion using Internal::match_types.

Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4).

◆ max() [5/9]

Expr Halide::max ( Expr  a,
int  b 
)

Returns an expression representing the greater of an expression and a constant integer.

The integer is coerced to the type of the expression. Errors if the integer is not representable as that type. Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4).

◆ max() [6/9]

Expr Halide::max ( int  a,
Expr  b 
)

Returns an expression representing the greater of a constant integer and an expression.

The integer is coerced to the type of the expression. Errors if the integer is not representable as that type. Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4).

◆ max() [7/9]

Expr Halide::max ( float  a,
Expr  b 
)
inline

Definition at line 620 of file IROperator.h.

References max().

◆ max() [8/9]

Expr Halide::max ( Expr  a,
float  b 
)
inline

Definition at line 623 of file IROperator.h.

References max().

◆ max() [9/9]

template<typename A , typename B , typename C , typename... Rest, typename std::enable_if< Halide::Internal::all_are_convertible< Expr, Rest... >::value >::type * = nullptr>
Expr Halide::max ( A &&  a,
B &&  b,
C &&  c,
Rest &&...  rest 
)
inline

Returns an expression representing the greater of an expressions vector, after doing any necessary type coersion using Internal::match_types.

Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4). The expressions are folded from right ie. max(.., max(.., ..)). The arguments can be any mix of types but must all be convertible to Expr.

Definition at line 635 of file IROperator.h.

References max().

◆ min() [4/9]

Expr Halide::min ( Expr  a,
Expr  b 
)

◆ min() [5/9]

Expr Halide::min ( Expr  a,
int  b 
)

Returns an expression representing the lesser of an expression and a constant integer.

The integer is coerced to the type of the expression. Errors if the integer is not representable as that type. Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4).

◆ min() [6/9]

Expr Halide::min ( int  a,
Expr  b 
)

Returns an expression representing the lesser of a constant integer and an expression.

The integer is coerced to the type of the expression. Errors if the integer is not representable as that type. Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4).

◆ min() [7/9]

Expr Halide::min ( float  a,
Expr  b 
)
inline

Definition at line 655 of file IROperator.h.

References min().

◆ min() [8/9]

Expr Halide::min ( Expr  a,
float  b 
)
inline

Definition at line 658 of file IROperator.h.

References min().

◆ min() [9/9]

template<typename A , typename B , typename C , typename... Rest, typename std::enable_if< Halide::Internal::all_are_convertible< Expr, Rest... >::value >::type * = nullptr>
Expr Halide::min ( A &&  a,
B &&  b,
C &&  c,
Rest &&...  rest 
)
inline

Returns an expression representing the lesser of an expressions vector, after doing any necessary type coersion using Internal::match_types.

Vectorizes cleanly on most platforms (with the exception of integer types on x86 without SSE4). The expressions are folded from right ie. min(.., min(.., ..)). The arguments can be any mix of types but must all be convertible to Expr.

Definition at line 670 of file IROperator.h.

References min().

◆ operator+() [6/7]

Expr Halide::operator+ ( Expr  a,
float  b 
)
inline

Operators on floats treats those floats as Exprs.

Making these explicit prevents implicit float->int casts that might otherwise occur.

Definition at line 678 of file IROperator.h.

◆ operator+() [7/7]

Expr Halide::operator+ ( float  a,
Expr  b 
)
inline

Definition at line 681 of file IROperator.h.

◆ operator-() [7/8]

Expr Halide::operator- ( Expr  a,
float  b 
)
inline

Definition at line 684 of file IROperator.h.

◆ operator-() [8/8]

Expr Halide::operator- ( float  a,
Expr  b 
)
inline

Definition at line 687 of file IROperator.h.

◆ operator*() [6/7]

Expr Halide::operator* ( Expr  a,
float  b 
)
inline

Definition at line 690 of file IROperator.h.

◆ operator*() [7/7]

Expr Halide::operator* ( float  a,
Expr  b 
)
inline

Definition at line 693 of file IROperator.h.

◆ operator/() [6/7]

Expr Halide::operator/ ( Expr  a,
float  b 
)
inline

Definition at line 696 of file IROperator.h.

◆ operator/() [7/7]

Expr Halide::operator/ ( float  a,
Expr  b 
)
inline

Definition at line 699 of file IROperator.h.

◆ operator%() [6/7]

Expr Halide::operator% ( Expr  a,
float  b 
)
inline

Definition at line 702 of file IROperator.h.

◆ operator%() [7/7]

Expr Halide::operator% ( float  a,
Expr  b 
)
inline

Definition at line 705 of file IROperator.h.

◆ operator>() [6/7]

Expr Halide::operator> ( Expr  a,
float  b 
)
inline

Definition at line 708 of file IROperator.h.

◆ operator>() [7/7]

Expr Halide::operator> ( float  a,
Expr  b 
)
inline

Definition at line 711 of file IROperator.h.

◆ operator<() [6/7]

Expr Halide::operator< ( Expr  a,
float  b 
)
inline

Definition at line 714 of file IROperator.h.

◆ operator<() [7/7]

Expr Halide::operator< ( float  a,
Expr  b 
)
inline

Definition at line 717 of file IROperator.h.

◆ operator>=() [6/7]

Expr Halide::operator>= ( Expr  a,
float  b 
)
inline

Definition at line 720 of file IROperator.h.

◆ operator>=() [7/7]

Expr Halide::operator>= ( float  a,
Expr  b 
)
inline

Definition at line 723 of file IROperator.h.

◆ operator<=() [6/7]

Expr Halide::operator<= ( Expr  a,
float  b 
)
inline

Definition at line 726 of file IROperator.h.

◆ operator<=() [7/7]

Expr Halide::operator<= ( float  a,
Expr  b 
)
inline

Definition at line 729 of file IROperator.h.

◆ operator==() [6/7]

Expr Halide::operator== ( Expr  a,
float  b 
)
inline

Definition at line 732 of file IROperator.h.

◆ operator==() [7/7]

Expr Halide::operator== ( float  a,
Expr  b 
)
inline

Definition at line 735 of file IROperator.h.

◆ operator!=() [6/7]

Expr Halide::operator!= ( Expr  a,
float  b 
)
inline

Definition at line 738 of file IROperator.h.

◆ operator!=() [7/7]

Expr Halide::operator!= ( float  a,
Expr  b 
)
inline

Definition at line 741 of file IROperator.h.

◆ clamp()

Expr Halide::clamp ( Expr  a,
const Expr min_val,
const Expr max_val 
)

Clamps an expression to lie within the given bounds.

The bounds are type-cast to match the expression. Vectorizes as well as min/max.

Examples
tutorial/lesson_07_multi_stage_pipelines.cpp, tutorial/lesson_09_update_definitions.cpp, and tutorial/lesson_12_using_the_gpu.cpp.

◆ abs()

Expr Halide::abs ( Expr  a)

Returns the absolute value of a signed integer or floating-point expression.

Vectorizes cleanly. Unlike in C, abs of a signed integer returns an unsigned integer of the same bit width. This means that abs of the most negative integer doesn't overflow.

Referenced by Halide::Internal::IRMatcher::fuzz_test_rule(), and Testing::neq().

◆ absd()

Expr Halide::absd ( Expr  a,
Expr  b 
)

Return the absolute difference between two values.

Vectorizes cleanly. Returns an unsigned value of the same bit width. There are various ways to write this yourself, but they contain numerous gotchas and don't always compile to good code, so use this instead.

Referenced by Halide::SimdOpCheckTest::check_one().

◆ select() [1/2]

Expr Halide::select ( Expr  condition,
Expr  true_value,
Expr  false_value 
)

Returns an expression similar to the ternary operator in C, except that it always evaluates all arguments.

If the first argument is true, then return the second, else return the third. Typically vectorizes cleanly, but benefits from SSE41 or newer on x86.

Examples
tutorial/lesson_13_tuples.cpp.

Referenced by select().

◆ select() [2/2]

template<typename... Args, typename std::enable_if< Halide::Internal::all_are_convertible< Expr, Args... >::value >::type * = nullptr>
Expr Halide::select ( Expr  c0,
Expr  v0,
Expr  c1,
Expr  v1,
Args &&...  args 
)
inline

A multi-way variant of select similar to a switch statement in C, which can accept multiple conditions and values in pairs.

Evaluates to the first value for which the condition is true. Returns the final value if all conditions are false.

Definition at line 775 of file IROperator.h.

References select().

◆ tuple_select() [1/4]

Tuple Halide::tuple_select ( const Tuple condition,
const Tuple true_value,
const Tuple false_value 
)

Equivalent of ternary select(), but taking/returning tuples.

If the condition is a Tuple, it must match the size of the true and false Tuples.

Referenced by tuple_select().

◆ tuple_select() [2/4]

Tuple Halide::tuple_select ( const Expr condition,
const Tuple true_value,
const Tuple false_value 
)

◆ tuple_select() [3/4]

template<typename... Args>
Tuple Halide::tuple_select ( const Tuple c0,
const Tuple v0,
const Tuple c1,
const Tuple v1,
Args &&...  args 
)
inline

Equivalent of multiway select(), but taking/returning tuples.

If the condition is a Tuple, it must match the size of the true and false Tuples.

Definition at line 790 of file IROperator.h.

References tuple_select().

◆ tuple_select() [4/4]

template<typename... Args>
Tuple Halide::tuple_select ( const Expr c0,
const Tuple v0,
const Expr c1,
const Tuple v1,
Args &&...  args 
)
inline

Definition at line 795 of file IROperator.h.

References tuple_select().

◆ mux() [1/3]

Expr Halide::mux ( const Expr id,
const std::initializer_list< Expr > &  values 
)

Oftentimes we want to pack a list of expressions with the same type into a channel dimension, e.g., img(x, y, c) = select(c == 0, 100, // Red c == 1, 50, // Green 25); // Blue This is tedious when the list is long.

The following function provide convinent syntax that allow one to write: img(x, y, c) = mux(c, {100, 50, 25});

◆ mux() [2/3]

Expr Halide::mux ( const Expr id,
const std::vector< Expr > &  values 
)

◆ mux() [3/3]

Expr Halide::mux ( const Expr id,
const Tuple values 
)

◆ sin()

Expr Halide::sin ( Expr  x)

Return the sine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

Examples
tutorial/lesson_04_debugging_2.cpp, tutorial/lesson_08_scheduling_2.cpp, tutorial/lesson_13_tuples.cpp, and tutorial/lesson_14_types.cpp.

◆ asin()

Expr Halide::asin ( Expr  x)

Return the arcsine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ cos()

Expr Halide::cos ( Expr  x)

Return the cosine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

Examples
tutorial/lesson_04_debugging_2.cpp, and tutorial/lesson_13_tuples.cpp.

◆ acos()

Expr Halide::acos ( Expr  x)

Return the arccosine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ tan()

Expr Halide::tan ( Expr  x)

Return the tangent of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ atan()

Expr Halide::atan ( Expr  x)

Return the arctangent of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ atan2()

Expr Halide::atan2 ( Expr  y,
Expr  x 
)

Return the angle of a floating-point gradient.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ sinh()

Expr Halide::sinh ( Expr  x)

Return the hyperbolic sine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ asinh()

Expr Halide::asinh ( Expr  x)

Return the hyperbolic arcsinhe of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ cosh()

Expr Halide::cosh ( Expr  x)

Return the hyperbolic cosine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ acosh()

Expr Halide::acosh ( Expr  x)

Return the hyperbolic arccosine of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ tanh()

Expr Halide::tanh ( Expr  x)

Return the hyperbolic tangent of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ atanh()

Expr Halide::atanh ( Expr  x)

Return the hyperbolic arctangent of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Does not vectorize well.

◆ sqrt()

Expr Halide::sqrt ( Expr  x)

Return the square root of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). Typically vectorizes cleanly.

◆ hypot()

Expr Halide::hypot ( const Expr x,
const Expr y 
)

Return the square root of the sum of the squares of two floating-point expressions.

If the argument is not floating-point, it is cast to Float(32). Vectorizes cleanly.

◆ exp()

Expr Halide::exp ( Expr  x)

Return the exponential of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). For Float(64) arguments, this calls the system exp function, and does not vectorize well. For Float(32) arguments, this function is vectorizable, does the right thing for extremely small or extremely large inputs, and is accurate up to the last bit of the mantissa. Vectorizes cleanly.

◆ log()

Expr Halide::log ( Expr  x)

Return the logarithm of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). For Float(64) arguments, this calls the system log function, and does not vectorize well. For Float(32) arguments, this function is vectorizable, does the right thing for inputs <= 0 (returns -inf or nan), and is accurate up to the last bit of the mantissa. Vectorizes cleanly.

◆ pow()

Expr Halide::pow ( Expr  x,
Expr  y 
)

Return one floating point expression raised to the power of another.

The type of the result is given by the type of the first argument. If the first argument is not a floating-point type, it is cast to Float(32). For Float(32), cleanly vectorizable, and accurate up to the last few bits of the mantissa. Gets worse when approaching overflow. Vectorizes cleanly.

Examples
tutorial/lesson_12_using_the_gpu.cpp.

◆ erf()

Expr Halide::erf ( const Expr x)

Evaluate the error function erf.

Only available for Float(32). Accurate up to the last three bits of the mantissa. Vectorizes cleanly.

◆ fast_sin()

Expr Halide::fast_sin ( const Expr x)

Fast vectorizable approximation to some trigonometric functions for Float(32).

Absolute approximation error is less than 1e-5.

◆ fast_cos()

Expr Halide::fast_cos ( const Expr x)

◆ fast_log()

Expr Halide::fast_log ( const Expr x)

Fast approximate cleanly vectorizable log for Float(32).

Returns nonsense for x <= 0.0f. Accurate up to the last 5 bits of the mantissa. Vectorizes cleanly.

◆ fast_exp()

Expr Halide::fast_exp ( const Expr x)

Fast approximate cleanly vectorizable exp for Float(32).

Returns nonsense for inputs that would overflow or underflow. Typically accurate up to the last 5 bits of the mantissa. Gets worse when approaching overflow. Vectorizes cleanly.

◆ fast_pow()

Expr Halide::fast_pow ( Expr  x,
Expr  y 
)

Fast approximate cleanly vectorizable pow for Float(32).

Returns nonsense for x < 0.0f. Accurate up to the last 5 bits of the mantissa for typical exponents. Gets worse when approaching overflow. Vectorizes cleanly.

◆ fast_inverse()

Expr Halide::fast_inverse ( Expr  x)

Fast approximate inverse for Float(32).

Corresponds to the rcpps instruction on x86, and the vrecpe instruction on ARM. Vectorizes cleanly. Note that this can produce slightly different results across different implementations of the same architecture (e.g. AMD vs Intel), even when strict_float is enabled.

◆ fast_inverse_sqrt()

Expr Halide::fast_inverse_sqrt ( Expr  x)

Fast approximate inverse square root for Float(32).

Corresponds to the rsqrtps instruction on x86, and the vrsqrte instruction on ARM. Vectorizes cleanly. Note that this can produce slightly different results across different implementations of the same architecture (e.g. AMD vs Intel), even when strict_float is enabled.

◆ floor()

Expr Halide::floor ( Expr  x)

Return the greatest whole number less than or equal to a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). The return value is still in floating point, despite being a whole number. Vectorizes cleanly.

Referenced by Halide::Internal::mod_imp< double >().

◆ ceil()

Expr Halide::ceil ( Expr  x)

Return the least whole number greater than or equal to a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). The return value is still in floating point, despite being a whole number. Vectorizes cleanly.

◆ round()

Expr Halide::round ( Expr  x)

Return the whole number closest to a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). The return value is still in floating point, despite being a whole number. On ties, we follow IEEE754 conventions and round to the nearest even number. Vectorizes cleanly.

◆ trunc()

Expr Halide::trunc ( Expr  x)

Return the integer part of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). The return value is still in floating point, despite being a whole number. Vectorizes cleanly.

◆ is_nan()

Expr Halide::is_nan ( Expr  x)

Returns true if the argument is a Not a Number (NaN).

Requires a floating point argument. Vectorizes cleanly. Note that the Expr passed in will be evaluated in strict_float mode, regardless of whether strict_float mode is enabled in the current Target.

◆ is_inf()

Expr Halide::is_inf ( Expr  x)

Returns true if the argument is Inf or -Inf.

Requires a floating point argument. Vectorizes cleanly. Note that the Expr passed in will be evaluated in strict_float mode, regardless of whether strict_float mode is enabled in the current Target.

◆ is_finite()

Expr Halide::is_finite ( Expr  x)

Returns true if the argument is a finite value (ie, neither NaN nor Inf).

Requires a floating point argument. Vectorizes cleanly. Note that the Expr passed in will be evaluated in strict_float mode, regardless of whether strict_float mode is enabled in the current Target.

◆ fract()

Expr Halide::fract ( const Expr x)

Return the fractional part of a floating-point expression.

If the argument is not floating-point, it is cast to Float(32). The return value has the same sign as the original expression. Vectorizes cleanly.

◆ reinterpret() [1/2]

Expr Halide::reinterpret ( Type  t,
Expr  e 
)

Reinterpret the bits of one value as another type.

Referenced by reinterpret(), and Halide::Internal::GeneratorInput_Scalar< T >::set_estimate().

◆ reinterpret() [2/2]

template<typename T >
Expr Halide::reinterpret ( Expr  e)

Definition at line 1010 of file IROperator.h.

References reinterpret().

◆ operator&() [1/3]

Expr Halide::operator& ( Expr  x,
Expr  y 
)

Return the bitwise and of two expressions (which need not have the same type).

The result type is the wider of the two expressions. Only integral types are allowed and both expressions must be signed or both must be unsigned.

◆ operator&() [2/3]

Expr Halide::operator& ( Expr  x,
int  y 
)

Return the bitwise and of an expression and an integer.

The type of the result is the type of the expression argument.

◆ operator&() [3/3]

Expr Halide::operator& ( int  x,
Expr  y 
)

◆ operator|() [1/3]

Expr Halide::operator| ( Expr  x,
Expr  y 
)

Return the bitwise or of two expressions (which need not have the same type).

The result type is the wider of the two expressions. Only integral types are allowed and both expressions must be signed or both must be unsigned.

◆ operator|() [2/3]

Expr Halide::operator| ( Expr  x,
int  y 
)

Return the bitwise or of an expression and an integer.

The type of the result is the type of the expression argument.

◆ operator|() [3/3]

Expr Halide::operator| ( int  x,
Expr  y 
)

◆ operator^() [1/3]

Expr Halide::operator^ ( Expr  x,
Expr  y 
)

Return the bitwise xor of two expressions (which need not have the same type).

The result type is the wider of the two expressions. Only integral types are allowed and both expressions must be signed or both must be unsigned.

◆ operator^() [2/3]

Expr Halide::operator^ ( Expr  x,
int  y 
)

Return the bitwise xor of an expression and an integer.

The type of the result is the type of the expression argument.

◆ operator^() [3/3]

Expr Halide::operator^ ( int  x,
Expr  y 
)

◆ operator~()

Expr Halide::operator~ ( Expr  x)

Return the bitwise not of an expression.

◆ operator<<() [5/12]

Expr Halide::operator<< ( Expr  x,
Expr  y 
)

Shift the bits of an integer value left.

This is actually less efficient than multiplying by 2^n, because Halide's optimization passes understand multiplication, and will compile it to shifting. This operator is only for if you really really need bit shifting (e.g. because the exponent is a run-time parameter). The type of the result is equal to the type of the first argument. Both arguments must have integer type.

◆ operator<<() [6/12]

Expr Halide::operator<< ( Expr  x,
int  y 
)

◆ operator>>() [1/2]

Expr Halide::operator>> ( Expr  x,
Expr  y 
)

Shift the bits of an integer value right.

Does sign extension for signed integers. This is less efficient than dividing by a power of two. Halide's definition of division (always round to negative infinity) means that all divisions by powers of two get compiled to bit-shifting, and Halide's optimization routines understand division and can work with it. The type of the result is equal to the type of the first argument. Both arguments must have integer type.

◆ operator>>() [2/2]

Expr Halide::operator>> ( Expr  x,
int  y 
)

◆ lerp()

Expr Halide::lerp ( Expr  zero_val,
Expr  one_val,
Expr  weight 
)

Linear interpolate between the two values according to a weight.

Parameters
zero_valThe result when weight is 0
one_valThe result when weight is 1
weightThe interpolation amount

Both zero_val and one_val must have the same type. All types are supported, including bool.

The weight is treated as its own type and must be float or an unsigned integer type. It is scaled to the bit-size of the type of x and y if they are integer, or converted to float if they are float. Integer weights are converted to float via division by the full-range value of the weight's type. Floating-point weights used to interpolate between integer values must be between 0.0f and 1.0f, and an error may be signaled if it is not provably so. (clamp operators can be added to provide proof. Currently an error is only signalled for constant weights.)

For integer linear interpolation, out of range values cannot be represented. In particular, weights that are conceptually less than 0 or greater than 1.0 are not representable. As such the result is always between x and y (inclusive of course). For lerp with floating-point values and floating-point weight, the full range of a float is valid, however underflow and overflow can still occur.

Ordering is not required between zero_val and one_val: lerp(42, 69, .5f) == lerp(69, 42, .5f) == 56

Results for integer types are for exactly rounded arithmetic. As such, there are cases where 16-bit and float differ because 32-bit floating-point (float) does not have enough precision to produce the exact result. (Likely true for 32-bit integer vs. double-precision floating-point as well.)

At present, double precision and 64-bit integers are not supported.

Generally, lerp will vectorize as if it were an operation on a type twice the bit size of the inferred type for x and y.

Some examples:

// Since Halide does not have direct type delcarations, casts
// below are used to indicate the types of the parameters.
// Such casts not required or expected in actual code where types
// are inferred.
lerp(cast<float>(x), cast<float>(y), cast<float>(w)) ->
x * (1.0f - w) + y * w
lerp(cast<uint8_t>(x), cast<uint8_t>(y), cast<uint8_t>(w)) ->
cast<uint8_t>(cast<uint8_t>(x) * (1.0f - cast<uint8_t>(w) / 255.0f) +
cast<uint8_t>(y) * cast<uint8_t>(w) / 255.0f + .5f)
// Note addition in Halide promoted uint8_t + int8_t to int16_t already,
// the outer cast is added for clarity.
lerp(cast<uint8_t>(x), cast<int8_t>(y), cast<uint8_t>(w)) ->
cast<int16_t>(cast<uint8_t>(x) * (1.0f - cast<uint8_t>(w) / 255.0f) +
cast<int8_t>(y) * cast<uint8_t>(w) / 255.0f + .5f)
lerp(cast<int8_t>(x), cast<int8_t>(y), cast<float>(w)) ->
cast<int8_t>(cast<int8_t>(x) * (1.0f - cast<float>(w)) +
cast<int8_t>(y) * cast<uint8_t>(w))

◆ popcount()

Expr Halide::popcount ( Expr  x)

Count the number of set bits in an expression.

◆ count_leading_zeros()

Expr Halide::count_leading_zeros ( Expr  x)

Count the number of leading zero bits in an expression.

If the expression is zero, the result is the number of bits in the type.

◆ count_trailing_zeros()

Expr Halide::count_trailing_zeros ( Expr  x)

Count the number of trailing zero bits in an expression.

If the expression is zero, the result is the number of bits in the type.

◆ div_round_to_zero()

Expr Halide::div_round_to_zero ( Expr  x,
Expr  y 
)

Divide two integers, rounding towards zero.

This is the typical behavior of most hardware architectures, which differs from Halide's division operator, which is Euclidean (rounds towards -infinity). Will throw a runtime error if y is zero, or if y is -1 and x is the minimum signed integer.

◆ mod_round_to_zero()

Expr Halide::mod_round_to_zero ( Expr  x,
Expr  y 
)

Compute the remainder of dividing two integers, when division is rounding toward zero.

This is the typical behavior of most hardware architectures, which differs from Halide's mod operator, which is Euclidean (produces the remainder when division rounds towards -infinity). Will throw a runtime error if y is zero.

◆ random_float()

Expr Halide::random_float ( Expr  seed = Expr())

Return a random variable representing a uniformly distributed float in the half-open interval [0.0f, 1.0f).

For random numbers of other types, use lerp with a random float as the last parameter.

Optionally takes a seed.

Note that:

Expr x = random_float();
Expr y = x + x;

is very different to

Expr y = random_float() + random_float();

The first doubles a random variable, and the second adds two independent random variables.

A given random variable takes on a unique value that depends deterministically on the pure variables of the function they belong to, the identity of the function itself, and which definition of the function it is used in. They are, however, shared across tuple elements.

This function vectorizes cleanly.

◆ random_uint()

Expr Halide::random_uint ( Expr  seed = Expr())

Return a random variable representing a uniformly distributed unsigned 32-bit integer.

See random_float. Vectorizes cleanly.

◆ random_int()

Expr Halide::random_int ( Expr  seed = Expr())

Return a random variable representing a uniformly distributed 32-bit integer.

See random_float. Vectorizes cleanly.

◆ print() [1/2]

Expr Halide::print ( const std::vector< Expr > &  values)

Create an Expr that prints out its value whenever it is evaluated.

It also prints out everything else in the arguments list, separated by spaces. This can include string literals.

Examples
tutorial/lesson_04_debugging_2.cpp.

Referenced by print().

◆ print() [2/2]

template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr Halide::print ( Expr  a,
Args &&...  args 
)
inline

Definition at line 1220 of file IROperator.h.

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

◆ print_when() [1/2]

Expr Halide::print_when ( Expr  condition,
const std::vector< Expr > &  values 
)

Create an Expr that prints whenever it is evaluated, provided that the condition is true.

Examples
tutorial/lesson_04_debugging_2.cpp.

Referenced by print_when().

◆ print_when() [2/2]

template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr Halide::print_when ( Expr  condition,
Expr  a,
Args &&...  args 
)
inline

Definition at line 1233 of file IROperator.h.

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

◆ require() [1/2]

Expr Halide::require ( Expr  condition,
const std::vector< Expr > &  values 
)

Create an Expr that that guarantees a precondition.

If 'condition' is true, the return value is equal to the first Expr. If 'condition' is false, halide_error() is called, and the return value is arbitrary. Any additional arguments after the first Expr are stringified and passed as a user-facing message to halide_error(), similar to print().

Note that this essentially always inserts a runtime check into the generated code (except when the condition can be proven at compile time); as such, it should be avoided inside inner loops, except for debugging or testing purposes. Note also that it does not vectorize cleanly (vector values will be scalarized for the check).

However, using this to make assertions about (say) input values can be useful, both in terms of correctness and (potentially) in terms of code generation, e.g.

Param<int> p;
Expr y = require(p > 0, p);

will allow the optimizer to assume positive, nonzero values for y.

Referenced by require().

◆ require() [2/2]

template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr Halide::require ( Expr  condition,
Expr  value,
Args &&...  args 
)
inline

Definition at line 1266 of file IROperator.h.

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

◆ undef() [1/2]

Expr Halide::undef ( Type  t)

Return an undef value of the given type.

Halide skips stores that depend on undef values, so you can use this to mean "do not modify this memory location". This is an escape hatch that can be used for several things:

You can define a reduction with no pure step, by setting the pure step to undef. Do this only if you're confident that the update steps are sufficient to correctly fill in the domain.

For a tuple-valued reduction, you can write an update step that only updates some tuple elements.

You can define single-stage pipeline that only has update steps, and depends on the values already in the output buffer.

Use this feature with great caution, as you can use it to load from uninitialized memory.

Referenced by undef().

◆ undef() [2/2]

template<typename T >
Expr Halide::undef ( )
inline

Definition at line 1294 of file IROperator.h.

References undef().

◆ memoize_tag()

template<typename... Args>
HALIDE_NO_USER_CODE_INLINE Expr Halide::memoize_tag ( Expr  result,
Args &&...  args 
)
inline

Control the values used in the memoization cache key for memoize.

Normally parameters and other external dependencies are automatically inferred and added to the cache key. The memoize_tag operator allows computing one expression and using either the computed value, or one or more other expressions in the cache key instead of the parameter dependencies of the computation. The single argument version is completely safe in that the cache key will use the actual computed value – it is difficult or imposible to produce erroneous caching this way. The more-than-one argument version allows generating cache keys that do not uniquely identify the computation and thus can result in caching errors.

A potential use for the single argument version is to handle a floating-point parameter that is quantized to a small integer. Mutliple values of the float will produce the same integer and moving the caching to using the integer for the key is more efficient.

The main use for the more-than-one argument version is to provide cache key information for Handles and ImageParams, which otherwise are not allowed inside compute_cached operations. E.g. when passing a group of parameters to an external array function via a Handle, memoize_tag can be used to isolate the actual values used by that computation. If an ImageParam is a constant image with a persistent digest, memoize_tag can be used to key computations using that image on the digest.

Definition at line 1326 of file IROperator.h.

References Halide::Internal::memoize_tag_helper().

◆ likely()

Expr Halide::likely ( Expr  e)

Expressions tagged with this intrinsic are considered to be part of the steady state of some loop with a nasty beginning and end (e.g.

a boundary condition). When Halide encounters likely intrinsics, it splits the containing loop body into three, and tries to simplify down all conditions that lead to the likely. For example, given the expression: select(x < 1, bar, x > 10, bar, likely(foo)), Halide will split the loop over x into portions where x < 1, 1 <= x <= 10, and x > 10.

You're unlikely to want to call this directly. You probably want to use the boundary condition helpers in the BoundaryConditions namespace instead.

Referenced by Halide::Internal::IRMatcher::Intrin< Args >::make().

◆ likely_if_innermost()

Expr Halide::likely_if_innermost ( Expr  e)

Equivalent to likely, but only triggers a loop partitioning if found in an innermost loop.

Referenced by Halide::Internal::IRMatcher::Intrin< Args >::make().

◆ saturating_cast() [1/2]

template<typename T >
Expr Halide::saturating_cast ( Expr  e)

Cast an expression to the halide type corresponding to the C++ type T.

As part of the cast, clamp to the minimum and maximum values of the result type.

Definition at line 1355 of file IROperator.h.

Referenced by Halide::ConciseCasts::i16_sat(), Halide::ConciseCasts::i32_sat(), Halide::ConciseCasts::i64_sat(), Halide::ConciseCasts::i8_sat(), Halide::ConciseCasts::u16_sat(), Halide::ConciseCasts::u32_sat(), Halide::ConciseCasts::u64_sat(), and Halide::ConciseCasts::u8_sat().

◆ saturating_cast() [2/2]

Expr Halide::saturating_cast ( Type  t,
Expr  e 
)

Cast an expression to a new type, clamping to the minimum and maximum values of the result type.

◆ strict_float()

Expr Halide::strict_float ( Expr  e)

Makes a best effort attempt to preserve IEEE floating-point semantics in evaluating an expression.

May not be implemented for all backends. (E.g. it is difficult to do this for C++ code generation as it depends on the compiler flags used to compile the generated code.

◆ unsafe_promise_clamped()

Expr Halide::unsafe_promise_clamped ( const Expr value,
const Expr min,
const Expr max 
)

Create an Expr that that promises another Expr is clamped but do not generate code to check the assertion or modify the value.

No attempt is made to prove the bound at compile time. (If it is proved false as a result of something else, an error might be generated, but it is also possible the compiler will crash.) The promised bound is used in bounds inference so it will allow satisfying bounds checks as well as possibly aiding optimization.

unsafe_promise_clamped returns its first argument, the Expr 'value'

This is a very easy way to make Halide generate erroneous code if the bound promises is not kept. Use sparingly when there is no other way to convey the information to the compiler and it is required for a valuable optimization.

Unsafe promises can be checked by turning on Target::CheckUnsafePromises. This is intended for debugging only.

◆ operator<<() [7/12]

std::ostream& Halide::operator<< ( std::ostream &  stream,
const DeviceAPI  
)

Emit a halide device api type in human-readable form.

◆ operator<<() [8/12]

std::ostream& Halide::operator<< ( std::ostream &  stream,
const MemoryType  
)

Emit a halide memory type in human-readable form.

◆ operator<<() [9/12]

std::ostream& Halide::operator<< ( std::ostream &  stream,
const TailStrategy t 
)

Emit a halide tail strategy in human-readable form.

◆ operator<<() [10/12]

std::ostream& Halide::operator<< ( std::ostream &  stream,
const LoopLevel  
)

Emit a halide LoopLevel in human-readable form.

◆ lambda() [1/6]

Func Halide::lambda ( const Expr e)
inline

Create a zero-dimensional halide function that returns the given expression.

The function may have more dimensions if the expression contains implicit arguments.

Definition at line 16 of file Lambda.h.

References Halide::Internal::unique_name().

Referenced by Halide::BoundaryConditions::Internal::func_like_to_func().

◆ lambda() [2/6]

Func Halide::lambda ( const Var x,
const Expr e 
)
inline

Create a 1-D halide function in the first argument that returns the second argument.

The function may have more dimensions if the expression contains implicit arguments and the list of Var arguments contains a placeholder ("_").

Definition at line 26 of file Lambda.h.

References Halide::Internal::unique_name().

◆ lambda() [3/6]

Func Halide::lambda ( const Var x,
const Var y,
const Expr e 
)
inline

Create a 2-D halide function in the first two arguments that returns the last argument.

The function may have more dimensions if the expression contains implicit arguments and the list of Var arguments contains a placeholder ("_").

Definition at line 36 of file Lambda.h.

References Halide::Internal::unique_name().

◆ lambda() [4/6]

Func Halide::lambda ( const Var x,
const Var y,
const Var z,
const Expr e 
)
inline

Create a 3-D halide function in the first three arguments that returns the last argument.

The function may have more dimensions if the expression contains implicit arguments and the list of Var arguments contains a placeholder ("_").

Definition at line 46 of file Lambda.h.

References Halide::Internal::unique_name().

◆ lambda() [5/6]

Func Halide::lambda ( const Var x,
const Var y,
const Var z,
const Var w,
const Expr e 
)
inline

Create a 4-D halide function in the first four arguments that returns the last argument.

The function may have more dimensions if the expression contains implicit arguments and the list of Var arguments contains a placeholder ("_").

Definition at line 56 of file Lambda.h.

References Halide::Internal::unique_name().

◆ lambda() [6/6]

Func Halide::lambda ( const Var x,
const Var y,
const Var z,
const Var w,
const Var v,
const Expr e 
)
inline

Create a 5-D halide function in the first five arguments that returns the last argument.

The function may have more dimensions if the expression contains implicit arguments and the list of Var arguments contains a placeholder ("_").

Definition at line 66 of file Lambda.h.

References Halide::Internal::unique_name().

◆ compile_module_to_llvm_module()

std::unique_ptr<llvm::Module> Halide::compile_module_to_llvm_module ( const Module module,
llvm::LLVMContext &  context 
)

Generate an LLVM module.

◆ make_raw_fd_ostream()

std::unique_ptr<llvm::raw_fd_ostream> Halide::make_raw_fd_ostream ( const std::string &  filename)

Construct an llvm output stream for writing to files.

◆ compile_llvm_module_to_object()

void Halide::compile_llvm_module_to_object ( llvm::Module &  module,
Internal::LLVMOStream out 
)

Compile an LLVM module to native targets (objects, native assembly).

◆ compile_llvm_module_to_assembly()

void Halide::compile_llvm_module_to_assembly ( llvm::Module &  module,
Internal::LLVMOStream out 
)

◆ compile_llvm_module_to_llvm_bitcode()

void Halide::compile_llvm_module_to_llvm_bitcode ( llvm::Module &  module,
Internal::LLVMOStream out 
)

Compile an LLVM module to LLVM targets (bitcode, LLVM assembly).

◆ compile_llvm_module_to_llvm_assembly()

void Halide::compile_llvm_module_to_llvm_assembly ( llvm::Module &  module,
Internal::LLVMOStream out 
)

◆ create_static_library()

void Halide::create_static_library ( const std::vector< std::string > &  src_files,
const Target target,
const std::string &  dst_file,
bool  deterministic = true 
)

Concatenate the list of src_files into dst_file, using the appropriate static library format for the given target (e.g., .a or .lib).

If deterministic is true, emit 0 for all GID/UID/timestamps, and 0644 for all modes (equivalent to the ar -D option).

◆ link_modules()

Module Halide::link_modules ( const std::string &  name,
const std::vector< Module > &  modules 
)

Link a set of modules together into one module.

◆ compile_standalone_runtime() [1/2]

void Halide::compile_standalone_runtime ( const std::string &  object_filename,
Target  t 
)

Create an object file containing the Halide runtime for a given target.

For use with Target::NoRuntime. Standalone runtimes are only compatible with pipelines compiled by the same build of Halide used to call this function.

◆ compile_standalone_runtime() [2/2]

std::map<Output, std::string> Halide::compile_standalone_runtime ( const std::map< Output, std::string > &  output_files,
Target  t 
)

Create an object and/or static library file containing the Halide runtime for a given target.

For use with Target::NoRuntime. Standalone runtimes are only compatible with pipelines compiled by the same build of Halide used to call this function. Return a map with just the actual outputs filled in (typically, Output::object and/or Output::static_library).

◆ compile_multitarget()

void Halide::compile_multitarget ( const std::string &  fn_name,
const std::map< Output, std::string > &  output_files,
const std::vector< Target > &  targets,
const std::vector< std::string > &  suffixes,
const ModuleFactory module_factory,
const CompilerLoggerFactory compiler_logger_factory = nullptr 
)

◆ user_context_value()

Expr Halide::user_context_value ( )
inline

Returns an Expr corresponding to the user context passed to the function (if any).

It is rare that this function is necessary (e.g. to pass the user context to an extern function written in C).

Definition at line 295 of file Param.h.

References Handle(), and Halide::Internal::Variable::make().

◆ operator<<() [11/12]

std::ostream& Halide::operator<< ( std::ostream &  stream,
const RVar  
)

Emit an RVar in a human-readable form.

◆ operator<<() [12/12]

std::ostream& Halide::operator<< ( std::ostream &  stream,
const RDom  
)

Emit an RDom in a human-readable form.

◆ get_host_target()

Target Halide::get_host_target ( )

Return the target corresponding to the host machine.

Examples
tutorial/lesson_12_using_the_gpu.cpp.

Referenced by Halide::SimdOpCheckTest::can_run_code().

◆ get_target_from_environment()

Target Halide::get_target_from_environment ( )

Return the target that Halide will use.

If HL_TARGET is set it uses that. Otherwise calls get_host_target

◆ get_jit_target_from_environment()

Target Halide::get_jit_target_from_environment ( )

Return the target that Halide will use for jit-compilation.

If HL_JIT_TARGET is set it uses that. Otherwise calls get_host_target. Throws an error if the architecture, bit width, and OS of the target do not match the host target, so this is only useful for controlling the feature set.

Referenced by Halide::Internal::schedule_scalar().

◆ target_feature_for_device_api()

Target::Feature Halide::target_feature_for_device_api ( DeviceAPI  api)

Get the Target feature corresponding to a DeviceAPI.

For device apis that do not correspond to any single target feature, returns Target::FeatureEnd

◆ Int()

◆ UInt()

◆ Float()

Type Halide::Float ( int  bits,
int  lanes = 1 
)
inline

◆ BFloat()

Type Halide::BFloat ( int  bits,
int  lanes = 1 
)
inline

Construct a floating-point type in the bfloat format.

Only 16-bit currently supported.

Definition at line 487 of file Type.h.

References Halide::Type::BFloat.

◆ Bool()

Type Halide::Bool ( int  lanes = 1)
inline

Construct a boolean type.

Definition at line 492 of file Type.h.

References UInt().

Referenced by Halide::NamesInterface::Bool().

◆ Handle()

Type Halide::Handle ( int  lanes = 1,
const halide_handle_cplusplus_type handle_type = nullptr 
)
inline

Construct a handle type.

Examples
tutorial/lesson_14_types.cpp.

Definition at line 497 of file Type.h.

References Halide::Type::Handle.

Referenced by user_context_value().

◆ type_of()

template<typename T >
Type Halide::type_of ( )
inline

Construct the halide equivalent of a C type.

Definition at line 503 of file Type.h.

◆ type_to_c_type()

std::string Halide::type_to_c_type ( Type  type,
bool  include_space,
bool  c_plus_plus = true 
)

Halide type to a C++ type.

◆ load_plugin()

void Halide::load_plugin ( const std::string &  lib_name)

Load a plugin in the form of a dynamic library (e.g.

for custom autoschedulers). If the string doesn't contain any . characters, the proper prefix and/or suffix for the platform will be added:

foo -> libfoo.so (Linux/OSX/etc – note that .dylib is not supported) foo -> foo.dll (Windows)

otherwise, it is assumed to be an appropriate pathname.

Any error in loading will assert-fail.

Variable Documentation

◆ head1_channels

const int Halide::head1_channels = 8

Definition at line 7 of file NetworkSize.h.

◆ head1_w

const int Halide::head1_w = 40

Definition at line 7 of file NetworkSize.h.

◆ head1_h

const int Halide::head1_h = 7

Definition at line 7 of file NetworkSize.h.

◆ head2_channels

const int Halide::head2_channels = 24

Definition at line 8 of file NetworkSize.h.

◆ head2_w

const int Halide::head2_w = 39

Definition at line 8 of file NetworkSize.h.

◆ conv1_channels

const int Halide::conv1_channels = 32

Definition at line 9 of file NetworkSize.h.

◆ all_device_apis

const DeviceAPI Halide::all_device_apis[]
Initial value:
DeviceAPI::Host,
DeviceAPI::Default_GPU,
DeviceAPI::CUDA,
DeviceAPI::OpenCL,
DeviceAPI::GLSL,
DeviceAPI::OpenGLCompute,
DeviceAPI::Metal,
DeviceAPI::Hexagon,
DeviceAPI::HexagonDma,
DeviceAPI::D3D12Compute}

An array containing all the device apis.

Useful for iterating through them.

Definition at line 31 of file DeviceAPI.h.

Halide::sum
Expr sum(Expr, const std::string &s="sum")
An inline reduction.
Halide::require
Expr require(Expr condition, const std::vector< Expr > &values)
Create an Expr that that guarantees a precondition.
Halide::product
Expr product(Expr, const std::string &s="product")
Halide::random_float
Expr random_float(Expr seed=Expr())
Return a random variable representing a uniformly distributed float in the half-open interval [0....
Message::None
@ None
Definition: sim_protocol.h:6
Halide::lerp
Expr lerp(Expr zero_val, Expr one_val, Expr weight)
Linear interpolate between the two values according to a weight.
Halide::minimum
Expr minimum(Expr, const std::string &s="minimum")