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 <stdint.h>
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, but we don't depend
22  * on C++11 yet. In C++14, it is possible these will be replaced with
23  * introspection/reflection facilities.
24  *
25  * halide_handle_traits has to go outside the Halide namespace due to template
26  * resolution rules. TODO(zalman): Do all types need to be in global namespace?
27  */
28 //@{
29 
30 /** A structure to represent the (unscoped) name of a C++ composite type for use
31  * as a single argument (or return value) in a function signature.
32  *
33  * Currently does not support the restrict qualifier, references, or
34  * r-value references. These features cannot be used in extern
35  * function calls from Halide or in the generated function from
36  * Halide, but their applicability seems limited anyway.
37  *
38  * Although this is in the global namespace, it should be considered "Halide Internal"
39  * and subject to change; code outside Halide should avoid referencing it.
40  */
42  /// An enum to indicate whether a C++ type is non-composite, a struct, class, or union
43  enum CPPTypeType {
44  Simple, ///< "int"
45  Struct, ///< "struct Foo"
46  Class, ///< "class Foo"
47  Union, ///< "union Foo"
48  Enum, ///< "enum Foo"
49  } cpp_type_type; // Note: order is reflected in map_to_name table in CPlusPlusMangle.cpp
50 
51  std::string name;
52 
55  }
56 
57  bool operator==(const halide_cplusplus_type_name &rhs) const {
58  return cpp_type_type == rhs.cpp_type_type &&
59  name == rhs.name;
60  }
61 
62  bool operator!=(const halide_cplusplus_type_name &rhs) const {
63  return !(*this == rhs);
64  }
65 
66  bool operator<(const halide_cplusplus_type_name &rhs) const {
67  return cpp_type_type < rhs.cpp_type_type ||
68  (cpp_type_type == rhs.cpp_type_type &&
69  name < rhs.name);
70  }
71 };
72 
73 /** A structure to represent the fully scoped name of a C++ composite
74  * type for use in generating function signatures that use that type.
75  *
76  * This is intended to be a constexpr usable type, but we don't depend
77  * on C++11 yet. In C++14, it is possible this will be replaced with
78  * introspection/reflection facilities.
79  *
80  * Although this is in the global namespace, it should be considered "Halide Internal"
81  * and subject to change; code outside Halide should avoid referencing it.
82  */
85  std::vector<std::string> namespaces;
86  std::vector<halide_cplusplus_type_name> enclosing_types;
87 
88  /// One set of modifiers on a type.
89  /// The const/volatile/restrict propertises are "inside" the pointer property.
90  enum Modifier : uint8_t {
91  Const = 1 << 0, ///< Bitmask flag for "const"
92  Volatile = 1 << 1, ///< Bitmask flag for "volatile"
93  Restrict = 1 << 2, ///< Bitmask flag for "restrict"
94  Pointer = 1 << 3, ///< Bitmask flag for a pointer "*"
95  };
96 
97  /// Qualifiers and indirections on type. 0 is innermost.
98  std::vector<uint8_t> cpp_type_modifiers;
99 
100  /// References are separate because they only occur at the outermost level.
101  /// No modifiers are needed for references as they are not allowed to apply
102  /// to the reference itself. (This isn't true for restrict, but that is a C++
103  /// extension anyway.) If modifiers are needed, the last entry in the above
104  /// array would be the modifers for the reference.
107  LValueReference = 1, // "&"
108  RValueReference = 2, // "&&"
109  };
111 
113  const std::vector<std::string> &namespaces = {},
114  const std::vector<halide_cplusplus_type_name> &enclosing_types = {},
115  const std::vector<uint8_t> &modifiers = {},
120  cpp_type_modifiers(modifiers),
122  }
123 
124  template<typename T>
125  static const halide_handle_cplusplus_type make();
126 };
127 //@}
128 
129 /** halide_c_type_to_name is a utility class used to provide a user-extensible
130  * way of naming Handle types.
131  *
132  * Although this is in the global namespace, it should be considered "Halide Internal"
133  * and subject to change; code outside Halide should avoid referencing it
134  * directly (use the HALIDE_DECLARE_EXTERN_xxx macros instead).
135  */
136 template<typename T>
138  static constexpr bool known_type = false;
140  return {halide_cplusplus_type_name::Simple, "void"};
141  }
142 };
143 
144 #define HALIDE_DECLARE_EXTERN_TYPE(TypeType, Type) \
145  template<> \
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}; \
150  } \
151  }
152 
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)
157 
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 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;
205 
206  constexpr uint8_t modifiers = static_cast<uint8_t>(
209  (is_volatile ? halide_handle_cplusplus_type::Volatile : 0));
210 
211  // clang-format off
213  (is_lvalue_reference ? halide_handle_cplusplus_type::LValueReference :
214  is_rvalue_reference ? halide_handle_cplusplus_type::RValueReference :
216  // clang-format on
217 
218  using TNonCVBase = typename std::remove_cv<TBase>::type;
219  constexpr bool known_type = halide_c_type_to_name<TNonCVBase>::known_type;
220  static_assert(!(!known_type && !is_ptr), "Unknown types must be pointers");
221 
224  {},
225  {},
226  {modifiers},
227  ref_type};
228  // Pull off any namespaces
230  return info;
231 }
232 
233 /** A type traits template to provide a halide_handle_cplusplus_type
234  * value from a C++ type.
235  *
236  * Note the type represented is implicitly a pointer.
237  *
238  * A NULL pointer of type halide_handle_traits represents "void *".
239  * This is chosen for compactness or representation as Type is a very
240  * widely used data structure.
241  *
242  * Although this is in the global namespace, it should be considered "Halide Internal"
243  * and subject to change; code outside Halide should avoid referencing it directly.
244  */
245 template<typename T>
247  // This trait must return a pointer to a global structure. I.e. it should never be freed.
248  // A return value of nullptr here means "void *".
250  if (std::is_pointer<T>::value ||
251  std::is_lvalue_reference<T>::value ||
252  std::is_rvalue_reference<T>::value) {
253  static const halide_handle_cplusplus_type the_info = halide_handle_cplusplus_type::make<T>();
254  return &the_info;
255  }
256  return nullptr;
257  }
258 };
259 
260 namespace Halide {
261 
262 struct Expr;
263 
264 /** Types in the halide type system. They can be ints, unsigned ints,
265  * or floats of various bit-widths (the 'bits' field). They can also
266  * be vectors of the same (by setting the 'lanes' field to something
267  * larger than one). Front-end code shouldn't use vector
268  * types. Instead vectorize a function. */
269 struct Type {
270 private:
271  halide_type_t type;
272 
273 public:
274  /** Aliases for halide_type_code_t values for legacy compatibility
275  * and to match the Halide internal C++ style. */
276  // @{
282  // @}
283 
284  /** The number of bytes required to store a single scalar value of this type. Ignores vector lanes. */
285  int bytes() const {
286  return (bits() + 7) / 8;
287  }
288 
289  // Default ctor initializes everything to predictable-but-unlikely values
291  : type(Handle, 0, 0), handle_type(nullptr) {
292  }
293 
294  /** Construct a runtime representation of a Halide type from:
295  * code: The fundamental type from an enum.
296  * bits: The bit size of one element.
297  * lanes: The number of vector elements in the type. */
300  }
301 
302  /** Trivial copy constructor. */
303  Type(const Type &that) = default;
304 
305  /** Trivial copy assignment operator. */
306  Type &operator=(const Type &that) = default;
307 
308  /** Type is a wrapper around halide_type_t with more methods for use
309  * inside the compiler. This simply constructs the wrapper around
310  * the runtime value. */
313  : type(that), handle_type(handle_type) {
314  }
315 
316  /** Unwrap the runtime halide_type_t for use in runtime calls, etc.
317  * Representation is exactly equivalent. */
319  operator halide_type_t() const {
320  return type;
321  }
322 
323  /** Return the underlying data type of an element as an enum value. */
326  return (halide_type_code_t)type.code;
327  }
328 
329  /** Return the bit size of a single element of this type. */
331  int bits() const {
332  return type.bits;
333  }
334 
335  /** Return the number of vector elements in this type. */
337  int lanes() const {
338  return type.lanes;
339  }
340 
341  /** Return Type with same number of bits and lanes, but new_code for a type code. */
343  return Type(new_code, bits(), lanes(),
344  (new_code == code()) ? handle_type : nullptr);
345  }
346 
347  /** Return Type with same type code and lanes, but new_bits for the number of bits. */
348  Type with_bits(int new_bits) const {
349  return Type(code(), new_bits, lanes(),
350  (new_bits == bits()) ? handle_type : nullptr);
351  }
352 
353  /** Return Type with same type code and number of bits,
354  * but new_lanes for the number of vector lanes. */
355  Type with_lanes(int new_lanes) const {
356  return Type(code(), bits(), new_lanes, handle_type);
357  }
358 
359  /** Type to be printed when declaring handles of this type. */
361 
362  /** Is this type boolean (represented as UInt(1))? */
364  bool is_bool() const {
365  return code() == UInt && bits() == 1;
366  }
367 
368  /** Is this type a vector type? (lanes() != 1).
369  * TODO(abadams): Decide what to do for lanes() == 0. */
371  bool is_vector() const {
372  return lanes() != 1;
373  }
374 
375  /** Is this type a scalar type? (lanes() == 1).
376  * TODO(abadams): Decide what to do for lanes() == 0. */
378  bool is_scalar() const {
379  return lanes() == 1;
380  }
381 
382  /** Is this type a floating point type (float or double). */
384  bool is_float() const {
385  return code() == Float || code() == BFloat;
386  }
387 
388  /** Is this type a floating point type (float or double). */
390  bool is_bfloat() const {
391  return code() == BFloat;
392  }
393 
394  /** Is this type a signed integer type? */
396  bool is_int() const {
397  return code() == Int;
398  }
399 
400  /** Is this type an unsigned integer type? */
402  bool is_uint() const {
403  return code() == UInt;
404  }
405 
406  /** Is this type an integer type of any sort? */
408  bool is_int_or_uint() const {
409  return code() == Int || code() == UInt;
410  }
411 
412  /** Is this type an opaque handle type (void *) */
414  bool is_handle() const {
415  return code() == Handle;
416  }
417 
418  /** Check that the type name of two handles matches. */
419  bool same_handle_type(const Type &other) const;
420 
421  /** Compare two types for equality */
422  bool operator==(const Type &other) const {
423  return type == other.type && (code() != Handle || same_handle_type(other));
424  }
425 
426  /** Compare two types for inequality */
427  bool operator!=(const Type &other) const {
428  return type != other.type || (code() == Handle && !same_handle_type(other));
429  }
430 
431  /** Compare ordering of two types so they can be used in certain containers and algorithms */
432  bool operator<(const Type &other) const {
433  if (type < other.type) return true;
434  if (code() == Handle) return handle_type < other.handle_type;
435  return false;
436  }
437 
438  /** Produce the scalar type (that of a single element) of this vector type */
439  Type element_of() const {
440  return with_lanes(1);
441  }
442 
443  /** Can this type represent all values of another type? */
444  bool can_represent(Type other) const;
445 
446  /** Can this type represent a particular constant? */
447  // @{
448  bool can_represent(double x) const;
449  bool can_represent(int64_t x) const;
450  bool can_represent(uint64_t x) const;
451  // @}
452 
453  /** Check if an integer constant value is the maximum or minimum
454  * representable value for this type. */
455  // @{
456  bool is_max(uint64_t) const;
457  bool is_max(int64_t) const;
458  bool is_min(uint64_t) const;
459  bool is_min(int64_t) const;
460  // @}
461 
462  /** Return an expression which is the maximum value of this type.
463  * Returns infinity for types which can represent it. */
464  Expr max() const;
465 
466  /** Return an expression which is the minimum value of this type.
467  * Returns -infinity for types which can represent it. */
468  Expr min() const;
469 };
470 
471 /** Constructing a signed integer type */
472 inline Type Int(int bits, int lanes = 1) {
473  return Type(Type::Int, bits, lanes);
474 }
475 
476 /** Constructing an unsigned integer type */
477 inline Type UInt(int bits, int lanes = 1) {
478  return Type(Type::UInt, bits, lanes);
479 }
480 
481 /** Construct a floating-point type */
482 inline Type Float(int bits, int lanes = 1) {
483  return Type(Type::Float, bits, lanes);
484 }
485 
486 /** Construct a floating-point type in the bfloat format. Only 16-bit currently supported. */
487 inline Type BFloat(int bits, int lanes = 1) {
488  return Type(Type::BFloat, bits, lanes);
489 }
490 
491 /** Construct a boolean type */
492 inline Type Bool(int lanes = 1) {
493  return UInt(1, lanes);
494 }
495 
496 /** Construct a handle type */
497 inline Type Handle(int lanes = 1, const halide_handle_cplusplus_type *handle_type = nullptr) {
498  return Type(Type::Handle, 64, lanes, handle_type);
499 }
500 
501 /** Construct the halide equivalent of a C type */
502 template<typename T>
503 inline Type type_of() {
504  return Type(halide_type_of<T>(), halide_handle_traits<T>::type_info());
505 }
506 
507 /** Halide type to a C++ type */
508 std::string type_to_c_type(Type type, bool include_space, bool c_plus_plus = true);
509 
510 } // namespace Halide
511 
512 #endif
Float16.h
int32_t
signed __INT32_TYPE__ int32_t
Definition: runtime_internal.h:20
Halide::Type::Type
Type()
Definition: Type.h:290
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:312
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:98
Halide::Type::is_bool
HALIDE_ALWAYS_INLINE bool is_bool() const
Is this type boolean (represented as UInt(1))?
Definition: Type.h:364
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:86
Error.h
halide_type_handle
@ halide_type_handle
opaque pointer type (void *)
Definition: HalideRuntime.h:407
halide_dimension_t
Definition: HalideRuntime.h:1365
halide_c_type_to_name::name
static halide_cplusplus_type_name name()
Definition: Type.h:139
Halide::Type::operator==
bool operator==(const Type &other) const
Compare two types for equality.
Definition: Type.h:422
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition: runtime_internal.h:25
halide_type_bfloat
@ halide_type_bfloat
floating point numbers in the bfloat format
Definition: HalideRuntime.h:408
halide_cplusplus_type_name::operator<
bool operator<(const halide_cplusplus_type_name &rhs) const
Definition: Type.h:66
uint16_t
unsigned __INT16_TYPE__ uint16_t
Definition: runtime_internal.h:23
Halide::Type::Float
static const halide_type_code_t Float
Definition: Type.h:279
Halide::Float
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition: Type.h:482
halide_type_float
@ halide_type_float
IEEE floating point numbers.
Definition: HalideRuntime.h:406
halide_handle_cplusplus_type::Const
@ Const
Bitmask flag for "const".
Definition: Type.h:91
Halide::Type::bytes
int bytes() const
The number of bytes required to store a single scalar value of this type.
Definition: Type.h:285
Halide::Type::lanes
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
Definition: Type.h:337
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:24
Halide::Type::is_float
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).
Definition: Type.h:384
Halide::Type::is_uint
HALIDE_ALWAYS_INLINE bool is_uint() const
Is this type an unsigned integer type?
Definition: Type.h:402
halide_handle_cplusplus_type::Pointer
@ Pointer
Bitmask flag for a pointer "*".
Definition: Type.h:94
halide_type_t::bits
uint8_t bits
The number of bits of precision of a single scalar value of this type.
Definition: HalideRuntime.h:438
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:47
Halide::Type::element_of
Type element_of() const
Produce the scalar type (that of a single element) of this vector type.
Definition: Type.h:439
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:426
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:432
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:342
halide_cplusplus_type_name::Enum
@ Enum
"enum Foo"
Definition: Type.h:48
HALIDE_DECLARE_EXTERN_SIMPLE_TYPE
#define HALIDE_DECLARE_EXTERN_SIMPLE_TYPE(T)
Definition: Type.h:153
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:19
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:277
Halide::Type::is_vector
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type? (lanes() != 1).
Definition: Type.h:371
Halide::Type::is_bfloat
HALIDE_ALWAYS_INLINE bool is_bfloat() const
Is this type a floating point type (float or double).
Definition: Type.h:390
Halide::Type
Types in the halide type system.
Definition: Type.h:269
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:348
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
halide_handle_cplusplus_type::make
static const halide_handle_cplusplus_type make()
Definition: Type.h:197
HALIDE_DECLARE_EXTERN_STRUCT_TYPE
#define HALIDE_DECLARE_EXTERN_STRUCT_TYPE(T)
Definition: Type.h:154
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:112
Halide::Handle
Type Handle(int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a handle type.
Definition: Type.h:497
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:355
halide_handle_cplusplus_type::reference_type
ReferenceType reference_type
Definition: Type.h:110
Halide::Type::operator!=
bool operator!=(const Type &other) const
Compare two types for inequality.
Definition: Type.h:427
Halide::Bool
Type Bool(int lanes=1)
Construct a boolean type.
Definition: Type.h:492
halide_type_code_t
halide_type_code_t
Types in the halide type system.
Definition: HalideRuntime.h:399
Halide::Type::is_handle
HALIDE_ALWAYS_INLINE bool is_handle() const
Is this type an opaque handle type (void *)
Definition: Type.h:414
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:32
halide_handle_cplusplus_type::namespaces
std::vector< std::string > namespaces
Definition: Type.h:85
Halide::Type::Handle
static const halide_type_code_t Handle
Definition: Type.h:281
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:408
halide_type_t::lanes
uint16_t lanes
How many elements in a vector.
Definition: HalideRuntime.h:442
Halide::Type::bits
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
Definition: Type.h:331
halide_handle_cplusplus_type::ReferenceType
ReferenceType
References are separate because they only occur at the outermost level.
Definition: Type.h:105
Halide::Type::handle_type
const halide_handle_cplusplus_type * handle_type
Type to be printed when declaring handles of this type.
Definition: Type.h:360
Halide::UInt
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition: Type.h:477
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:18
Halide::Type::UInt
static const halide_type_code_t UInt
Definition: Type.h:278
halide_type_uint
@ halide_type_uint
unsigned integers
Definition: HalideRuntime.h:405
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:62
Halide::BFloat
Type BFloat(int bits, int lanes=1)
Construct a floating-point type in the bfloat format.
Definition: Type.h:487
halide_handle_cplusplus_type::inner_name
halide_cplusplus_type_name inner_name
Definition: Type.h:84
halide_cplusplus_type_name::Struct
@ Struct
"struct Foo"
Definition: Type.h:45
halide_handle_cplusplus_type::NotReference
@ NotReference
Definition: Type.h:106
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:142
Halide::Type::is_scalar
HALIDE_ALWAYS_INLINE bool is_scalar() const
Is this type a scalar type? (lanes() == 1).
Definition: Type.h:378
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:137
halide_cplusplus_type_name::name
std::string name
Definition: Type.h:51
halide_cplusplus_type_name::Class
@ Class
"class Foo"
Definition: Type.h:46
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:298
Halide::Internal::IRMatcher::is_const
HALIDE_ALWAYS_INLINE auto is_const(A a) noexcept -> IsConst< decltype(pattern_arg(a))>
Definition: IRMatch.h:2034
Halide::Type::is_int
HALIDE_ALWAYS_INLINE bool is_int() const
Is this type a signed integer type?
Definition: Type.h:396
halide_parallel_task_t
A parallel task to be passed to halide_do_parallel_tasks.
Definition: HalideRuntime.h:197
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition: HalideRuntime.h:1404
halide_cplusplus_type_name::operator==
bool operator==(const halide_cplusplus_type_name &rhs) const
Definition: Type.h:57
halide_handle_traits
A type traits template to provide a halide_handle_cplusplus_type value from a C++ type.
Definition: Type.h:246
halide_handle_traits::type_info
static const HALIDE_ALWAYS_INLINE halide_handle_cplusplus_type * type_info()
Definition: Type.h:249
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:43
Halide::type_of
Type type_of()
Construct the halide equivalent of a C type.
Definition: Type.h:503
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:721
halide_handle_cplusplus_type::LValueReference
@ LValueReference
Definition: Type.h:107
halide_handle_cplusplus_type::Restrict
@ Restrict
Bitmask flag for "restrict".
Definition: Type.h:93
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:83
int16_t
signed __INT16_TYPE__ int16_t
Definition: runtime_internal.h:22
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
halide_type_int
@ halide_type_int
signed integers
Definition: HalideRuntime.h:404
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:167
halide_handle_cplusplus_type::Volatile
@ Volatile
Bitmask flag for "volatile".
Definition: Type.h:92
halide_cplusplus_type_name::halide_cplusplus_type_name
halide_cplusplus_type_name(CPPTypeType cpp_type_type, const std::string &name)
Definition: Type.h:53
Util.h
halide_c_type_to_name::known_type
static constexpr bool known_type
Definition: Type.h:138
uint32_t
unsigned __INT32_TYPE__ uint32_t
Definition: runtime_internal.h:21
halide_cplusplus_type_name
A set of types to represent a C++ function signature.
Definition: Type.h:41
halide_cplusplus_type_name::Simple
@ Simple
"int"
Definition: Type.h:44
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:1629
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:325
Halide::Type::BFloat
static const halide_type_code_t BFloat
Definition: Type.h:280
halide_type_t::code
uint8_t code
The basic type code: signed integer, unsigned integer, or floating point.
Definition: HalideRuntime.h:433
halide_handle_cplusplus_type::Modifier
Modifier
One set of modifiers on a type.
Definition: Type.h:90
halide_handle_cplusplus_type::RValueReference
@ RValueReference
Definition: Type.h:108
Halide::Int
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition: Type.h:472