Halide
Type.h
Go to the documentation of this file.
1 #ifndef HALIDE_TYPE_H
2 #define HALIDE_TYPE_H
3 
4 #include "Error.h"
5 #include "Float16.h"
6 #include "Util.h"
8 #include <cstdint>
9 
10 /** \file
11  * Defines halide types
12  */
13 
14 /** A set of types to represent a C++ function signature. This allows
15  * two things. First, proper prototypes can be provided for Halide
16  * generated functions, giving better compile time type
17  * checking. Second, C++ name mangling can be done to provide link
18  * time type checking for both Halide generated functions and calls
19  * from Halide to external functions.
20  *
21  * These are intended to be constexpr producable.
22  *
23  * halide_handle_traits has to go outside the Halide namespace due to template
24  * resolution rules. TODO(zalman): Do all types need to be in global namespace?
25  */
26 //@{
27 
28 /** A structure to represent the (unscoped) name of a C++ composite type for use
29  * as a single argument (or return value) in a function signature.
30  *
31  * Currently does not support the restrict qualifier, references, or
32  * r-value references. These features cannot be used in extern
33  * function calls from Halide or in the generated function from
34  * Halide, but their applicability seems limited anyway.
35  *
36  * Although this is in the global namespace, it should be considered "Halide Internal"
37  * and subject to change; code outside Halide should avoid referencing it.
38  */
40  /// An enum to indicate whether a C++ type is non-composite, a struct, class, or union
41  enum CPPTypeType {
42  Simple, ///< "int"
43  Struct, ///< "struct Foo"
44  Class, ///< "class Foo"
45  Union, ///< "union Foo"
46  Enum, ///< "enum Foo"
47  } cpp_type_type; // Note: order is reflected in map_to_name table in CPlusPlusMangle.cpp
48 
49  std::string name;
50 
53  }
54 
55  bool operator==(const halide_cplusplus_type_name &rhs) const {
56  return cpp_type_type == rhs.cpp_type_type &&
57  name == rhs.name;
58  }
59 
60  bool operator!=(const halide_cplusplus_type_name &rhs) const {
61  return !(*this == rhs);
62  }
63 
64  bool operator<(const halide_cplusplus_type_name &rhs) const {
65  return cpp_type_type < rhs.cpp_type_type ||
66  (cpp_type_type == rhs.cpp_type_type &&
67  name < rhs.name);
68  }
69 };
70 
71 /** A structure to represent the fully scoped name of a C++ composite
72  * type for use in generating function signatures that use that type.
73  *
74  * This is intended to be a constexpr usable type.
75  *
76  * Although this is in the global namespace, it should be considered "Halide Internal"
77  * and subject to change; code outside Halide should avoid referencing it.
78  */
81  std::vector<std::string> namespaces;
82  std::vector<halide_cplusplus_type_name> enclosing_types;
83 
84  /// One set of modifiers on a type.
85  /// The const/volatile/restrict properties are "inside" the pointer property.
86  enum Modifier : uint8_t {
87  Const = 1 << 0, ///< Bitmask flag for "const"
88  Volatile = 1 << 1, ///< Bitmask flag for "volatile"
89  Restrict = 1 << 2, ///< Bitmask flag for "restrict"
90  Pointer = 1 << 3, ///< Bitmask flag for a pointer "*"
91  FunctionTypedef = 1 << 4, ///< Bitmask flag for a function typedef; when this is set, Pointer should also always be set
92  };
93 
94  /// Qualifiers and indirections on type. 0 is innermost.
95  std::vector<uint8_t> cpp_type_modifiers;
96 
97  /// References are separate because they only occur at the outermost level.
98  /// No modifiers are needed for references as they are not allowed to apply
99  /// to the reference itself. (This isn't true for restrict, but that is a C++
100  /// extension anyway.) If modifiers are needed, the last entry in the above
101  /// array would be the modifers for the reference.
104  LValueReference = 1, // "&"
105  RValueReference = 2, // "&&"
106  };
108 
110  const std::vector<std::string> &namespaces = {},
111  const std::vector<halide_cplusplus_type_name> &enclosing_types = {},
112  const std::vector<uint8_t> &modifiers = {},
117  cpp_type_modifiers(modifiers),
119  }
120 
121  template<typename T>
123 };
124 //@}
125 
126 /** halide_c_type_to_name is a utility class used to provide a user-extensible
127  * way of naming Handle types.
128  *
129  * Although this is in the global namespace, it should be considered "Halide Internal"
130  * and subject to change; code outside Halide should avoid referencing it
131  * directly (use the HALIDE_DECLARE_EXTERN_xxx macros instead).
132  */
133 template<typename T>
135  static constexpr bool known_type = false;
137  return {halide_cplusplus_type_name::Simple, "void"};
138  }
139 };
140 
141 #define HALIDE_DECLARE_EXTERN_TYPE(TypeType, Type) \
142  template<> \
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}; \
147  } \
148  }
149 
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)
154 
178 
179 // You can make arbitrary user-defined types be "Known" using the
180 // macro above. This is useful for making Param<> arguments for
181 // Generators type safe. e.g.,
182 //
183 // struct MyFunStruct { ... };
184 //
185 // ...
186 //
187 // HALIDE_DECLARE_EXTERN_STRUCT_TYPE(MyFunStruct);
188 //
189 // ...
190 //
191 // class MyGenerator : public Generator<MyGenerator> {
192 // Param<const MyFunStruct *> my_struct_ptr;
193 // ...
194 // };
195 
196 template<typename 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;
201 
202  using TNoRef = typename std::remove_reference<T>::type;
203  using TNoRefNoPtr = typename std::remove_pointer<TNoRef>::type;
204  constexpr bool is_function_pointer = std::is_pointer<TNoRef>::value &&
205  std::is_function<TNoRefNoPtr>::value;
206 
207  // Don't remove the pointer-ness from a function pointer.
208  using TBase = typename std::conditional<is_function_pointer, TNoRef, TNoRefNoPtr>::type;
209  constexpr bool is_const = std::is_const<TBase>::value;
210  constexpr bool is_volatile = std::is_volatile<TBase>::value;
211 
212  constexpr uint8_t modifiers = static_cast<uint8_t>(
213  (is_function_pointer ? halide_handle_cplusplus_type::FunctionTypedef : 0) |
216  (is_volatile ? halide_handle_cplusplus_type::Volatile : 0));
217 
218  // clang-format off
220  (is_lvalue_reference ? halide_handle_cplusplus_type::LValueReference :
221  is_rvalue_reference ? halide_handle_cplusplus_type::RValueReference :
223  // clang-format on
224 
225  using TNonCVBase = typename std::remove_cv<TBase>::type;
226  constexpr bool known_type = halide_c_type_to_name<TNonCVBase>::known_type;
227  static_assert(!(!known_type && !is_ptr), "Unknown types must be pointers");
228 
231  {},
232  {},
233  {modifiers},
234  ref_type};
235  // Pull off any namespaces
237  return info;
238 }
239 
240 /** A type traits template to provide a halide_handle_cplusplus_type
241  * value from a C++ type.
242  *
243  * Note the type represented is implicitly a pointer.
244  *
245  * A NULL pointer of type halide_handle_traits represents "void *".
246  * This is chosen for compactness or representation as Type is a very
247  * widely used data structure.
248  *
249  * Although this is in the global namespace, it should be considered "Halide Internal"
250  * and subject to change; code outside Halide should avoid referencing it directly.
251  */
252 template<typename T>
254  // This trait must return a pointer to a global structure. I.e. it should never be freed.
255  // A return value of nullptr here means "void *".
257  if (std::is_pointer<T>::value ||
258  std::is_lvalue_reference<T>::value ||
259  std::is_rvalue_reference<T>::value) {
260  static const halide_handle_cplusplus_type the_info = halide_handle_cplusplus_type::make<T>();
261  return &the_info;
262  }
263  return nullptr;
264  }
265 };
266 
267 namespace Halide {
268 
269 struct Expr;
270 
271 /** Types in the halide type system. They can be ints, unsigned ints,
272  * or floats of various bit-widths (the 'bits' field). They can also
273  * be vectors of the same (by setting the 'lanes' field to something
274  * larger than one). Front-end code shouldn't use vector
275  * types. Instead vectorize a function. */
276 struct Type {
277 private:
278  halide_type_t type;
279 
280 public:
281  /** Aliases for halide_type_code_t values for legacy compatibility
282  * and to match the Halide internal C++ style. */
283  // @{
289  // @}
290 
291  /** The number of bytes required to store a single scalar value of this type. Ignores vector lanes. */
292  int bytes() const {
293  return (bits() + 7) / 8;
294  }
295 
296  // Default ctor initializes everything to predictable-but-unlikely values
298  : type(Handle, 0, 0) {
299  }
300 
301  /** Construct a runtime representation of a Halide type from:
302  * code: The fundamental type from an enum.
303  * bits: The bit size of one element.
304  * lanes: The number of vector elements in the type. */
307  }
308 
309  /** Trivial copy constructor. */
310  Type(const Type &that) = default;
311 
312  /** Trivial copy assignment operator. */
313  Type &operator=(const Type &that) = default;
314 
315  /** Type is a wrapper around halide_type_t with more methods for use
316  * inside the compiler. This simply constructs the wrapper around
317  * the runtime value. */
320  : type(that), handle_type(handle_type) {
321  }
322 
323  /** Unwrap the runtime halide_type_t for use in runtime calls, etc.
324  * Representation is exactly equivalent. */
326  operator halide_type_t() const {
327  return type;
328  }
329 
330  /** Return the underlying data type of an element as an enum value. */
333  return (halide_type_code_t)type.code;
334  }
335 
336  /** Return the bit size of a single element of this type. */
338  int bits() const {
339  return type.bits;
340  }
341 
342  /** Return the number of vector elements in this type. */
344  int lanes() const {
345  return type.lanes;
346  }
347 
348  /** Return Type with same number of bits and lanes, but new_code for a type code. */
350  return Type(new_code, bits(), lanes(),
351  (new_code == code()) ? handle_type : nullptr);
352  }
353 
354  /** Return Type with same type code and lanes, but new_bits for the number of bits. */
355  Type with_bits(int new_bits) const {
356  return Type(code(), new_bits, lanes(),
357  (new_bits == bits()) ? handle_type : nullptr);
358  }
359 
360  /** Return Type with same type code and number of bits,
361  * but new_lanes for the number of vector lanes. */
362  Type with_lanes(int new_lanes) const {
363  return Type(code(), bits(), new_lanes, handle_type);
364  }
365 
366  /** Return Type with the same type code and number of lanes, but with at least twice as many bits. */
367  Type widen() const {
368  if (bits() == 1) {
369  // Widening a 1-bit type should produce an 8-bit type.
370  return with_bits(8);
371  } else {
372  return with_bits(bits() * 2);
373  }
374  }
375 
376  /** Return Type with the same type code and number of lanes, but with at most half as many bits. */
377  Type narrow() const {
378  internal_assert(bits() != 1) << "Attempting to narrow a 1-bit type\n";
379  if (bits() == 8) {
380  // Narrowing an 8-bit type should produce a 1-bit type.
381  return with_bits(1);
382  } else {
383  return with_bits(bits() / 2);
384  }
385  }
386 
387  /** Type to be printed when declaring handles of this type. */
389 
390  /** Is this type boolean (represented as UInt(1))? */
392  bool is_bool() const {
393  return code() == UInt && bits() == 1;
394  }
395 
396  /** Is this type a vector type? (lanes() != 1).
397  * TODO(abadams): Decide what to do for lanes() == 0. */
399  bool is_vector() const {
400  return lanes() != 1;
401  }
402 
403  /** Is this type a scalar type? (lanes() == 1).
404  * TODO(abadams): Decide what to do for lanes() == 0. */
406  bool is_scalar() const {
407  return lanes() == 1;
408  }
409 
410  /** Is this type a floating point type (float or double). */
412  bool is_float() const {
413  return code() == Float || code() == BFloat;
414  }
415 
416  /** Is this type a floating point type (float or double). */
418  bool is_bfloat() const {
419  return code() == BFloat;
420  }
421 
422  /** Is this type a signed integer type? */
424  bool is_int() const {
425  return code() == Int;
426  }
427 
428  /** Is this type an unsigned integer type? */
430  bool is_uint() const {
431  return code() == UInt;
432  }
433 
434  /** Is this type an integer type of any sort? */
436  bool is_int_or_uint() const {
437  return code() == Int || code() == UInt;
438  }
439 
440  /** Is this type an opaque handle type (void *) */
442  bool is_handle() const {
443  return code() == Handle;
444  }
445 
446  // Returns true iff type is a signed integral type where overflow is defined.
448  bool can_overflow_int() const {
449  return is_int() && bits() <= 16;
450  }
451 
452  // Returns true iff type does have a well-defined overflow behavior.
454  bool can_overflow() const {
455  return is_uint() || can_overflow_int();
456  }
457 
458  /** Check that the type name of two handles matches. */
459  bool same_handle_type(const Type &other) const;
460 
461  /** Compare two types for equality */
462  bool operator==(const Type &other) const {
463  return type == other.type && (code() != Handle || same_handle_type(other));
464  }
465 
466  /** Compare two types for inequality */
467  bool operator!=(const Type &other) const {
468  return type != other.type || (code() == Handle && !same_handle_type(other));
469  }
470 
471  /** Compare two types for equality */
472  bool operator==(const halide_type_t &other) const {
473  return type == other;
474  }
475 
476  /** Compare two types for inequality */
477  bool operator!=(const halide_type_t &other) const {
478  return type != other;
479  }
480 
481  /** Compare ordering of two types so they can be used in certain containers and algorithms */
482  bool operator<(const Type &other) const {
483  if (type < other.type) {
484  return true;
485  }
486  if (code() == Handle) {
487  return handle_type < other.handle_type;
488  }
489  return false;
490  }
491 
492  /** Produce the scalar type (that of a single element) of this vector type */
493  Type element_of() const {
494  return with_lanes(1);
495  }
496 
497  /** Can this type represent all values of another type? */
498  bool can_represent(Type other) const;
499 
500  /** Can this type represent a particular constant? */
501  // @{
502  bool can_represent(double x) const;
503  bool can_represent(int64_t x) const;
504  bool can_represent(uint64_t x) const;
505  // @}
506 
507  /** Check if an integer constant value is the maximum or minimum
508  * representable value for this type. */
509  // @{
510  bool is_max(uint64_t) const;
511  bool is_max(int64_t) const;
512  bool is_min(uint64_t) const;
513  bool is_min(int64_t) const;
514  // @}
515 
516  /** Return an expression which is the maximum value of this type.
517  * Returns infinity for types which can represent it. */
518  Expr max() const;
519 
520  /** Return an expression which is the minimum value of this type.
521  * Returns -infinity for types which can represent it. */
522  Expr min() const;
523 };
524 
525 /** Constructing a signed integer type */
526 inline Type Int(int bits, int lanes = 1) {
527  return Type(Type::Int, bits, lanes);
528 }
529 
530 /** Constructing an unsigned integer type */
531 inline Type UInt(int bits, int lanes = 1) {
532  return Type(Type::UInt, bits, lanes);
533 }
534 
535 /** Construct a floating-point type */
536 inline Type Float(int bits, int lanes = 1) {
537  return Type(Type::Float, bits, lanes);
538 }
539 
540 /** Construct a floating-point type in the bfloat format. Only 16-bit currently supported. */
541 inline Type BFloat(int bits, int lanes = 1) {
542  return Type(Type::BFloat, bits, lanes);
543 }
544 
545 /** Construct a boolean type */
546 inline Type Bool(int lanes = 1) {
547  return UInt(1, lanes);
548 }
549 
550 /** Construct a handle type */
551 inline Type Handle(int lanes = 1, const halide_handle_cplusplus_type *handle_type = nullptr) {
552  return Type(Type::Handle, 64, lanes, handle_type);
553 }
554 
555 /** Construct the halide equivalent of a C type */
556 template<typename T>
557 inline Type type_of() {
558  return Type(halide_type_of<T>(), halide_handle_traits<T>::type_info());
559 }
560 
561 /** Halide type to a C++ type */
562 std::string type_to_c_type(Type type, bool include_space, bool c_plus_plus = true);
563 
564 } // namespace Halide
565 
566 #endif
Float16.h
int32_t
signed __INT32_TYPE__ int32_t
Definition: runtime_internal.h:24
halide_handle_cplusplus_type::FunctionTypedef
@ FunctionTypedef
Bitmask flag for a function typedef; when this is set, Pointer should also always be set.
Definition: Type.h:91
Halide::Type::Type
Type()
Definition: Type.h:297
Halide::Type::Type
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.
Definition: Type.h:319
halide_handle_cplusplus_type::cpp_type_modifiers
std::vector< uint8_t > cpp_type_modifiers
Qualifiers and indirections on type. 0 is innermost.
Definition: Type.h:95
Halide::Type::is_bool
HALIDE_ALWAYS_INLINE bool is_bool() const
Is this type boolean (represented as UInt(1))?
Definition: Type.h:392
Halide::Type::operator=
Type & operator=(const Type &that)=default
Trivial copy assignment operator.
halide_handle_cplusplus_type::enclosing_types
std::vector< halide_cplusplus_type_name > enclosing_types
Definition: Type.h:82
internal_assert
#define internal_assert(c)
Definition: Errors.h:19
Error.h
halide_task_t
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.
Definition: HalideRuntime.h:204
halide_type_handle
@ halide_type_handle
opaque pointer type (void *)
Definition: HalideRuntime.h:457
halide_dimension_t
Definition: HalideRuntime.h:1448
halide_c_type_to_name::name
static halide_cplusplus_type_name name()
Definition: Type.h:136
Halide::Type::operator==
bool operator==(const Type &other) const
Compare two types for equality.
Definition: Type.h:462
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition: runtime_internal.h:29
halide_type_bfloat
@ halide_type_bfloat
floating point numbers in the bfloat format
Definition: HalideRuntime.h:458
halide_cplusplus_type_name::operator<
bool operator<(const halide_cplusplus_type_name &rhs) const
Definition: Type.h:64
uint16_t
unsigned __INT16_TYPE__ uint16_t
Definition: runtime_internal.h:27
halide_loop_task_t
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.
Definition: HalideRuntime.h:238
Halide::Type::Float
static const halide_type_code_t Float
Definition: Type.h:286
Halide::Float
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition: Type.h:536
halide_type_float
@ halide_type_float
IEEE floating point numbers.
Definition: HalideRuntime.h:456
halide_handle_cplusplus_type::Const
@ Const
Bitmask flag for "const".
Definition: Type.h:87
halide_handle_cplusplus_type::make
static halide_handle_cplusplus_type make()
Definition: Type.h:197
Halide::Type::bytes
int bytes() const
The number of bytes required to store a single scalar value of this type.
Definition: Type.h:292
Halide::Type::lanes
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
Definition: Type.h:344
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:28
Halide::Type::is_float
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).
Definition: Type.h:412
Halide::Type::is_uint
HALIDE_ALWAYS_INLINE bool is_uint() const
Is this type an unsigned integer type?
Definition: Type.h:430
halide_handle_cplusplus_type::Pointer
@ Pointer
Bitmask flag for a pointer "*".
Definition: Type.h:90
halide_type_t::bits
uint8_t bits
The number of bits of precision of a single scalar value of this type.
Definition: HalideRuntime.h:488
Halide::Internal::IRMatcher::is_const
HALIDE_ALWAYS_INLINE auto is_const(A &&a) noexcept -> IsConst< decltype(pattern_arg(a))>
Definition: IRMatch.h:2309
Halide::Type::same_handle_type
bool same_handle_type(const Type &other) const
Check that the type name of two handles matches.
halide_cplusplus_type_name::Union
@ Union
"union Foo"
Definition: Type.h:45
Halide::Type::element_of
Type element_of() const
Produce the scalar type (that of a single element) of this vector type.
Definition: Type.h:493
Halide::Internal::extract_namespaces
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.
halide_type_t
A runtime tag for a type in the halide type system.
Definition: HalideRuntime.h:476
Halide::Type::operator<
bool operator<(const Type &other) const
Compare ordering of two types so they can be used in certain containers and algorithms.
Definition: Type.h:482
Halide::Type::with_code
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.
Definition: Type.h:349
Halide::Type::can_overflow_int
HALIDE_ALWAYS_INLINE bool can_overflow_int() const
Definition: Type.h:448
halide_cplusplus_type_name::Enum
@ Enum
"enum Foo"
Definition: Type.h:46
HALIDE_DECLARE_EXTERN_SIMPLE_TYPE
#define HALIDE_DECLARE_EXTERN_SIMPLE_TYPE(T)
Definition: Type.h:150
Halide::Type::max
Expr max() const
Return an expression which is the maximum value of this type.
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:23
Halide::Type::Int
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...
Definition: Type.h:284
Halide::Type::is_vector
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type? (lanes() != 1).
Definition: Type.h:399
Halide::Type::is_bfloat
HALIDE_ALWAYS_INLINE bool is_bfloat() const
Is this type a floating point type (float or double).
Definition: Type.h:418
Halide::Type
Types in the halide type system.
Definition: Type.h:276
Halide::Type::with_bits
Type with_bits(int new_bits) const
Return Type with same type code and lanes, but new_bits for the number of bits.
Definition: Type.h:355
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::Type::can_overflow
HALIDE_ALWAYS_INLINE bool can_overflow() const
Definition: Type.h:454
HALIDE_DECLARE_EXTERN_STRUCT_TYPE
#define HALIDE_DECLARE_EXTERN_STRUCT_TYPE(T)
Definition: Type.h:151
halide_handle_cplusplus_type::halide_handle_cplusplus_type
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)
Definition: Type.h:109
Halide::Handle
Type Handle(int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a handle type.
Definition: Type.h:551
Halide::Type::narrow
Type narrow() const
Return Type with the same type code and number of lanes, but with at most half as many bits.
Definition: Type.h:377
Halide::Type::with_lanes
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.
Definition: Type.h:362
halide_handle_cplusplus_type::reference_type
ReferenceType reference_type
Definition: Type.h:107
Halide::Type::operator!=
bool operator!=(const Type &other) const
Compare two types for inequality.
Definition: Type.h:467
Halide::Bool
Type Bool(int lanes=1)
Construct a boolean type.
Definition: Type.h:546
halide_semaphore_acquire_t
A struct representing a semaphore and a number of items that must be acquired from it.
Definition: HalideRuntime.h:223
halide_type_code_t
halide_type_code_t
Types in the halide type system.
Definition: HalideRuntime.h:449
Halide::Type::is_handle
HALIDE_ALWAYS_INLINE bool is_handle() const
Is this type an opaque handle type (void *)
Definition: Type.h:442
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:40
halide_handle_cplusplus_type::namespaces
std::vector< std::string > namespaces
Definition: Type.h:81
Halide::Type::Handle
static const halide_type_code_t Handle
Definition: Type.h:288
Halide::Type::is_int_or_uint
HALIDE_ALWAYS_INLINE bool is_int_or_uint() const
Is this type an integer type of any sort?
Definition: Type.h:436
halide_type_t::lanes
uint16_t lanes
How many elements in a vector.
Definition: HalideRuntime.h:492
Halide::Type::bits
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
Definition: Type.h:338
halide_handle_cplusplus_type::ReferenceType
ReferenceType
References are separate because they only occur at the outermost level.
Definition: Type.h:102
Halide::Type::handle_type
const halide_handle_cplusplus_type * handle_type
Type to be printed when declaring handles of this type.
Definition: Type.h:388
Halide::UInt
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition: Type.h:531
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
Halide::Type::operator==
bool operator==(const halide_type_t &other) const
Compare two types for equality.
Definition: Type.h:472
Halide::Type::UInt
static const halide_type_code_t UInt
Definition: Type.h:285
halide_type_uint
@ halide_type_uint
unsigned integers
Definition: HalideRuntime.h:455
Halide::Type::min
Expr min() const
Return an expression which is the minimum value of this type.
halide_cplusplus_type_name::operator!=
bool operator!=(const halide_cplusplus_type_name &rhs) const
Definition: Type.h:60
Halide::BFloat
Type BFloat(int bits, int lanes=1)
Construct a floating-point type in the bfloat format.
Definition: Type.h:541
halide_handle_cplusplus_type::inner_name
halide_cplusplus_type_name inner_name
Definition: Type.h:80
halide_cplusplus_type_name::Struct
@ Struct
"struct Foo"
Definition: Type.h:43
halide_handle_cplusplus_type::NotReference
@ NotReference
Definition: Type.h:103
Halide::Type::is_min
bool is_min(uint64_t) const
Halide::bfloat16_t
Class that provides a type that implements half precision floating point using the bfloat16 format.
Definition: Float16.h:158
Halide::Type::is_scalar
HALIDE_ALWAYS_INLINE bool is_scalar() const
Is this type a scalar type? (lanes() == 1).
Definition: Type.h:406
Halide::Type::is_max
bool is_max(uint64_t) const
Check if an integer constant value is the maximum or minimum representable value for this type.
halide_c_type_to_name
halide_c_type_to_name is a utility class used to provide a user-extensible way of naming Handle types...
Definition: Type.h:134
halide_cplusplus_type_name::name
std::string name
Definition: Type.h:49
halide_cplusplus_type_name::Class
@ Class
"class Foo"
Definition: Type.h:44
HalideRuntime.h
Halide::Type::Type
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.
Definition: Type.h:305
Halide::Type::is_int
HALIDE_ALWAYS_INLINE bool is_int() const
Is this type a signed integer type?
Definition: Type.h:424
halide_parallel_task_t
A parallel task to be passed to halide_do_parallel_tasks.
Definition: HalideRuntime.h:247
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition: HalideRuntime.h:1490
halide_cplusplus_type_name::operator==
bool operator==(const halide_cplusplus_type_name &rhs) const
Definition: Type.h:55
halide_handle_traits
A type traits template to provide a halide_handle_cplusplus_type value from a C++ type.
Definition: Type.h:253
halide_handle_traits::type_info
static const HALIDE_ALWAYS_INLINE halide_handle_cplusplus_type * type_info()
Definition: Type.h:256
halide_cplusplus_type_name::CPPTypeType
CPPTypeType
An enum to indicate whether a C++ type is non-composite, a struct, class, or union.
Definition: Type.h:41
Halide::type_of
Type type_of()
Construct the halide equivalent of a C type.
Definition: Type.h:557
halide_device_interface_t
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
Definition: HalideRuntime.h:770
halide_handle_cplusplus_type::LValueReference
@ LValueReference
Definition: Type.h:104
halide_handle_cplusplus_type::Restrict
@ Restrict
Bitmask flag for "restrict".
Definition: Type.h:89
halide_handle_cplusplus_type
A structure to represent the fully scoped name of a C++ composite type for use in generating function...
Definition: Type.h:79
int16_t
signed __INT16_TYPE__ int16_t
Definition: runtime_internal.h:26
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:257
halide_type_int
@ halide_type_int
signed integers
Definition: HalideRuntime.h:454
Halide::float16_t
Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in s...
Definition: Float16.h:17
halide_semaphore_t
An opaque struct representing a semaphore.
Definition: HalideRuntime.h:217
halide_handle_cplusplus_type::Volatile
@ Volatile
Bitmask flag for "volatile".
Definition: Type.h:88
halide_cplusplus_type_name::halide_cplusplus_type_name
halide_cplusplus_type_name(CPPTypeType cpp_type_type, const std::string &name)
Definition: Type.h:51
Util.h
halide_c_type_to_name::known_type
static constexpr bool known_type
Definition: Type.h:135
uint32_t
unsigned __INT32_TYPE__ uint32_t
Definition: runtime_internal.h:25
Halide::Type::widen
Type widen() const
Return Type with the same type code and number of lanes, but with at least twice as many bits.
Definition: Type.h:367
halide_cplusplus_type_name
A set of types to represent a C++ function signature.
Definition: Type.h:39
halide_cplusplus_type_name::Simple
@ Simple
"int"
Definition: Type.h:42
halide_cplusplus_type_name::cpp_type_type
enum halide_cplusplus_type_name::CPPTypeType cpp_type_type
Halide::Type::can_represent
bool can_represent(Type other) const
Can this type represent all values of another type?
Halide::type_to_c_type
std::string type_to_c_type(Type type, bool include_space, bool c_plus_plus=true)
Halide type to a C++ type.
halide_filter_metadata_t
Definition: HalideRuntime.h:1734
Halide::Type::code
HALIDE_ALWAYS_INLINE halide_type_code_t code() const
Return the underlying data type of an element as an enum value.
Definition: Type.h:332
Halide::Type::BFloat
static const halide_type_code_t BFloat
Definition: Type.h:287
halide_type_t::code
uint8_t code
The basic type code: signed integer, unsigned integer, or floating point.
Definition: HalideRuntime.h:483
halide_handle_cplusplus_type::Modifier
Modifier
One set of modifiers on a type.
Definition: Type.h:86
halide_handle_cplusplus_type::RValueReference
@ RValueReference
Definition: Type.h:105
Halide::Type::operator!=
bool operator!=(const halide_type_t &other) const
Compare two types for inequality.
Definition: Type.h:477
Halide::Int
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition: Type.h:526