61 return !(*
this == rhs);
110 const std::vector<std::string> &
namespaces = {},
112 const std::vector<uint8_t> &modifiers = {},
141#define HALIDE_DECLARE_EXTERN_TYPE(TypeType, Type) \
143 struct halide_c_type_to_name<Type> { \
144 static constexpr bool known_type = true; \
145 static halide_cplusplus_type_name name() { \
146 return {halide_cplusplus_type_name::TypeType, #Type}; \
150#define HALIDE_DECLARE_EXTERN_SIMPLE_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Simple, T)
151#define HALIDE_DECLARE_EXTERN_STRUCT_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Struct, T)
152#define HALIDE_DECLARE_EXTERN_CLASS_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Class, T)
153#define HALIDE_DECLARE_EXTERN_UNION_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Union, T)
169#ifdef HALIDE_CPP_COMPILER_HAS_FLOAT16
201 constexpr bool is_ptr = std::is_pointer_v<T>;
202 constexpr bool is_lvalue_reference = std::is_lvalue_reference_v<T>;
203 constexpr bool is_rvalue_reference = std::is_rvalue_reference_v<T>;
205 using TNoRef = std::remove_reference_t<T>;
206 using TNoRefNoPtr = std::remove_pointer_t<TNoRef>;
207 constexpr bool is_function_pointer = std::is_pointer_v<TNoRef> &&
208 std::is_function_v<TNoRefNoPtr>;
211 using TBase = std::conditional_t<is_function_pointer, TNoRef, TNoRefNoPtr>;
212 constexpr bool is_const = std::is_const_v<TBase>;
213 constexpr bool is_volatile = std::is_volatile_v<TBase>;
218 (is_const ?
Const : 0) |
228 using TNonCVBase = std::remove_cv_t<TBase>;
230 static_assert(!(!known_type && !is_ptr),
"Unknown types must be pointers");
260 if (std::is_pointer_v<T> ||
261 std::is_lvalue_reference_v<T> ||
262 std::is_rvalue_reference_v<T>) {
273struct ConstantInterval;
300 return (
bits() + 7) / 8;
315 <<
"Halide only supports vector types with up to 65535 lanes. " <<
lanes <<
" lanes requested.";
317 <<
"Halide only supports types with up to 255 bits. " <<
bits <<
" bits requested.";
484 return type ==
other;
489 return type !=
other;
494 if (type <
other.type) {
562 return UInt(1, lanes);
#define internal_assert(c)
This file declares the routines used by Halide internally in its runtime.
int(* halide_task_t)(void *user_context, int task_number, uint8_t *closure)
Define halide_do_par_for to replace the default thread pool implementation.
halide_type_code_t
Types in the halide type system.
@ halide_type_float
IEEE floating point numbers.
@ halide_type_handle
opaque pointer type (void *)
@ halide_type_bfloat
floating point numbers in the bfloat format
@ halide_type_int
signed integers
@ halide_type_uint
unsigned integers
int(* halide_loop_task_t)(void *user_context, int min, int extent, uint8_t *closure, void *task_parent)
A task representing a serial for loop evaluated over some range.
#define HALIDE_ALWAYS_INLINE
#define HALIDE_DECLARE_EXTERN_STRUCT_TYPE(T)
#define HALIDE_DECLARE_EXTERN_SIMPLE_TYPE(T)
Various utility functions used internally Halide.
std::string extract_namespaces(const std::string &name, std::vector< std::string > &namespaces)
Returns base name and fills in namespaces, outermost one first in vector.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
std::string type_to_c_type(Type type, bool include_space, bool c_plus_plus=true)
Halide type to a C++ type.
Type BFloat(int bits, int lanes=1)
Construct a floating-point type in the bfloat format.
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Type Float(int bits, int lanes=1)
Construct a floating-point type.
@ Internal
Not visible externally, similar to 'static' linkage in C.
Type type_of()
Construct the halide equivalent of a C type.
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Type Handle(int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a handle type.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Type Bool(int lanes=1)
Construct a boolean type.
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
signed __INT32_TYPE__ int32_t
unsigned __INT8_TYPE__ uint8_t
unsigned __INT16_TYPE__ uint16_t
unsigned __INT32_TYPE__ uint32_t
signed __INT16_TYPE__ int16_t
signed __INT8_TYPE__ int8_t
A fragment of Halide syntax.
A class to represent ranges of integers.
Types in the halide type system.
HALIDE_ALWAYS_INLINE halide_type_code_t code() const
Return the underlying data type of an element as an enum value.
Type widen() const
Return Type with the same type code and number of lanes, but with at least twice as many bits.
static constexpr halide_type_code_t Float
Type(halide_type_code_t code, int bits, int lanes, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a runtime representation of a Halide type from: code: The fundamental type from an enum.
Type element_of() const
Produce the scalar type (that of a single element) of this vector type.
bool is_max(uint64_t) const
Check if an integer constant value is the maximum or minimum representable value for this type.
Type with_bits(int new_bits) const
Return Type with same type code and lanes, but new_bits for the number of bits.
HALIDE_ALWAYS_INLINE bool is_int() const
Is this type a signed integer type?
bool can_represent(const Internal::ConstantInterval &in) const
Can this type represent exactly all integer values of some constant integer range?
Expr min() const
Return an expression which is the minimum value of this type.
bool operator!=(const Type &other) const
Compare two types for inequality.
static constexpr halide_type_code_t Int
Aliases for halide_type_code_t values for legacy compatibility and to match the Halide internal C++ s...
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
HALIDE_ALWAYS_INLINE bool is_uint() const
Is this type an unsigned integer type?
HALIDE_ALWAYS_INLINE bool is_bool() const
Is this type boolean (represented as UInt(1))?
Type with_lanes(int new_lanes) const
Return Type with same type code and number of bits, but new_lanes for the number of vector lanes.
HALIDE_ALWAYS_INLINE Type(const halide_type_t &that, const halide_handle_cplusplus_type *handle_type=nullptr)
Type is a wrapper around halide_type_t with more methods for use inside the compiler.
bool operator<(const Type &other) const
Compare ordering of two types so they can be used in certain containers and algorithms.
Type(const Type &that)=default
Trivial copy constructor.
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
HALIDE_ALWAYS_INLINE bool can_overflow_int() const
bool operator!=(const halide_type_t &other) const
Compare two types for inequality.
bool same_handle_type(const Type &other) const
Check that the type name of two handles matches.
HALIDE_ALWAYS_INLINE bool is_int_or_uint() const
Is this type an integer type of any sort?
static constexpr halide_type_code_t BFloat
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type? (lanes() != 1).
HALIDE_ALWAYS_INLINE bool is_bfloat() const
Is this type a floating point type (float or double).
const halide_handle_cplusplus_type * handle_type
Type to be printed when declaring handles of this type.
int bytes() const
The number of bytes required to store a single scalar value of this type.
bool is_max(int64_t) const
bool can_represent(Type other) const
Can this type represent all values of another type?
bool is_min(int64_t) const
bool operator==(const Type &other) const
Compare two types for equality.
HALIDE_ALWAYS_INLINE bool can_overflow() const
static constexpr halide_type_code_t Handle
Type with_code(halide_type_code_t new_code) const
Return Type with same number of bits and lanes, but new_code for a type code.
Type & operator=(const Type &that)=default
Trivial copy assignment operator.
bool can_represent(double x) const
Can this type represent a particular constant?
Type narrow() const
Return Type with the same type code and number of lanes, but with at most half as many bits.
HALIDE_ALWAYS_INLINE bool is_handle() const
Is this type an opaque handle type (void *)
bool can_represent(int64_t x) const
bool is_min(uint64_t) const
bool can_represent(uint64_t x) const
static constexpr halide_type_code_t UInt
bool operator==(const halide_type_t &other) const
Compare two types for equality.
HALIDE_ALWAYS_INLINE bool is_scalar() const
Is this type a scalar type? (lanes() == 1).
Expr max() const
Return an expression which is the maximum value of this type.
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).
Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in s...
The raw representation of an image passed around by generated Halide code.
halide_c_type_to_name is a utility class used to provide a user-extensible way of naming Handle types...
static constexpr bool known_type
static halide_cplusplus_type_name name()
A set of types to represent a C++ function signature.
bool operator<(const halide_cplusplus_type_name &rhs) const
bool operator==(const halide_cplusplus_type_name &rhs) const
enum halide_cplusplus_type_name::CPPTypeType cpp_type_type
halide_cplusplus_type_name(CPPTypeType cpp_type_type, const std::string &name)
bool operator!=(const halide_cplusplus_type_name &rhs) const
CPPTypeType
An enum to indicate whether a C++ type is non-composite, a struct, class, or union.
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
A structure to represent the fully scoped name of a C++ composite type for use in generating function...
ReferenceType reference_type
halide_cplusplus_type_name inner_name
static halide_handle_cplusplus_type make()
ReferenceType
References are separate because they only occur at the outermost level.
halide_handle_cplusplus_type(const halide_cplusplus_type_name &inner_name, const std::vector< std::string > &namespaces={}, const std::vector< halide_cplusplus_type_name > &enclosing_types={}, const std::vector< uint8_t > &modifiers={}, ReferenceType reference_type=NotReference)
std::vector< std::string > namespaces
std::vector< halide_cplusplus_type_name > enclosing_types
Modifier
One set of modifiers on a type.
@ Const
Bitmask flag for "const".
@ Restrict
Bitmask flag for "restrict".
@ FunctionTypedef
Bitmask flag for a function typedef; when this is set, Pointer should also always be set.
@ Volatile
Bitmask flag for "volatile".
@ Pointer
Bitmask flag for a pointer "*".
std::vector< uint8_t > cpp_type_modifiers
Qualifiers and indirections on type. 0 is innermost.
A type traits template to provide a halide_handle_cplusplus_type value from a C++ type.
static HALIDE_ALWAYS_INLINE const halide_handle_cplusplus_type * type_info()
A parallel task to be passed to halide_do_parallel_tasks.
A struct representing a semaphore and a number of items that must be acquired from it.
An opaque struct representing a semaphore.
A runtime tag for a type in the halide type system.
uint8_t bits
The number of bits of precision of a single scalar value of this type.
uint16_t lanes
How many elements in a vector.
uint8_t code
The basic type code: signed integer, unsigned integer, or floating point.