63 return !(*
this == rhs);
113 const std::vector<std::string> &
namespaces = {},
115 const std::vector<uint8_t> &modifiers = {},
144 #define HALIDE_DECLARE_EXTERN_TYPE(TypeType, Type) \
146 struct halide_c_type_to_name<Type> { \
147 static constexpr bool known_type = true; \
148 static halide_cplusplus_type_name name() { \
149 return {halide_cplusplus_type_name::TypeType, #Type}; \
153 #define HALIDE_DECLARE_EXTERN_SIMPLE_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Simple, T)
154 #define HALIDE_DECLARE_EXTERN_STRUCT_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Struct, T)
155 #define HALIDE_DECLARE_EXTERN_CLASS_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Class, T)
156 #define HALIDE_DECLARE_EXTERN_UNION_TYPE(T) HALIDE_DECLARE_EXTERN_TYPE(Union, T)
198 constexpr
bool is_ptr = std::is_pointer<T>::value;
199 constexpr
bool is_lvalue_reference = std::is_lvalue_reference<T>::value;
200 constexpr
bool is_rvalue_reference = std::is_rvalue_reference<T>::value;
202 using TBase =
typename std::remove_pointer<typename std::remove_reference<T>::type>::type;
203 constexpr
bool is_const = std::is_const<TBase>::value;
204 constexpr
bool is_volatile = std::is_volatile<TBase>::value;
218 using TNonCVBase =
typename std::remove_cv<TBase>::type;
220 static_assert(!(!known_type && !is_ptr),
"Unknown types must be pointers");
250 if (std::is_pointer<T>::value ||
251 std::is_lvalue_reference<T>::value ||
252 std::is_rvalue_reference<T>::value) {
286 return (
bits() + 7) / 8;
455 if (type < other.type) {
519 return UInt(1, lanes);
This file declares the routines used by Halide internally in its runtime.
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
#define HALIDE_ALWAYS_INLINE
#define HALIDE_DECLARE_EXTERN_STRUCT_TYPE(T)
#define HALIDE_DECLARE_EXTERN_SIMPLE_TYPE(T)
Various utility functions used internally Halide.
HALIDE_ALWAYS_INLINE auto is_const(A &&a) noexcept -> IsConst< decltype(pattern_arg(a))>
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.
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.
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.
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.
static const halide_type_code_t Float
Type widen() const
Return Type with the same type code and number of lanes, but with twice as many bits.
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.
static const halide_type_code_t Int
Aliases for halide_type_code_t values for legacy compatibility and to match the Halide internal C++ s...
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?
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.
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.
static const halide_type_code_t BFloat
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 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 const halide_type_code_t UInt
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
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.
static const halide_type_code_t Handle
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 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
Type & operator=(const Type &that)=default
Trivial copy assignment operator.
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 using the bfloat16 format.
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".
@ 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.
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.