Halide 22.0.0 Halide compiler and libraries

Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Halide::Type Struct Reference

Types in the halide type system. More...

`#include <Type.h>`

## Public Member Functions
int | bytes () const
| The number of bytes required to store a single scalar value of this type. More...
| 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. More...
| Type (const Type &that)=default
| Trivial copy constructor. More...
Type & | operator= (const Type &that)=default
| Trivial copy assignment operator. More...
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. More...
HALIDE_ALWAYS_INLINE | operator halide_type_t () const
| Unwrap the runtime halide_type_t for use in runtime calls, etc. More...
HALIDE_ALWAYS_INLINE halide_type_code_t | code () const
| Return the underlying data type of an element as an enum value. More...
HALIDE_ALWAYS_INLINE int | bits () const
| Return the bit size of a single element of this type. More...
HALIDE_ALWAYS_INLINE int | lanes () const
| Return the number of vector elements in this type. More...
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. More...
Type | with_bits (int new_bits) const
| Return Type with same type code and lanes, but new_bits for the number of bits. More...
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. More...
Type | widen () const
| Return Type with the same type code and number of lanes, but with at least twice as many bits. More...
Type | narrow () const
| Return Type with the same type code and number of lanes, but with at most half as many bits. More...
HALIDE_ALWAYS_INLINE bool | is_bool () const
| Is this type boolean (represented as UInt(1))? More...
HALIDE_ALWAYS_INLINE bool | is_vector () const
| Is this type a vector type? (lanes() != 1). More...
HALIDE_ALWAYS_INLINE bool | is_scalar () const
| Is this type a scalar type? (lanes() == 1). More...
HALIDE_ALWAYS_INLINE bool | is_float () const
| Is this type a floating point type (float or double). More...
HALIDE_ALWAYS_INLINE bool | is_bfloat () const
| Is this type a floating point type (float or double). More...
HALIDE_ALWAYS_INLINE bool | is_int () const
| Is this type a signed integer type? More...
HALIDE_ALWAYS_INLINE bool | is_uint () const
| Is this type an unsigned integer type? More...
HALIDE_ALWAYS_INLINE bool | is_int_or_uint () const
| Is this type an integer type of any sort? More...
HALIDE_ALWAYS_INLINE bool | is_handle () const
| Is this type an opaque handle type (void *) More...
HALIDE_ALWAYS_INLINE bool | can_overflow_int () const
HALIDE_ALWAYS_INLINE bool | can_overflow () const
bool | same_handle_type (const Type &other) const
| Check that the type name of two handles matches. More...
bool | operator== (const Type &other) const
| Compare two types for equality. More...
bool | operator!= (const Type &other) const
| Compare two types for inequality. More...
bool | operator== (const halide_type_t &other) const
| Compare two types for equality. More...
bool | operator!= (const halide_type_t &other) const
| Compare two types for inequality. More...
bool | operator< (const Type &other) const
| Compare ordering of two types so they can be used in certain containers and algorithms. More...
Type | element_of () const
| Produce the scalar type (that of a single element) of this vector type. More...
bool | can_represent (Type other) const
| Can this type represent all values of another type? More...
bool | can_represent (const Internal::ConstantInterval &in) const
| Can this type represent exactly all integer values of some constant integer range? More...
bool | can_represent (double x) const
| Can this type represent a particular constant? More...
bool | can_represent (int64_t x) const
bool | can_represent (uint64_t x) const
bool | is_max (uint64_t) const
| Check if an integer constant value is the maximum or minimum representable value for this type. More...
bool | is_max (int64_t) const
bool | is_min (uint64_t) const
bool | is_min (int64_t) const
Expr | max () const
| Return an expression which is the maximum value of this type. More...
Expr | min () const
| Return an expression which is the minimum value of this type. More...

## Public Attributes
const halide_handle_cplusplus_type * | handle_type = nullptr
| Type to be printed when declaring handles of this type. More...

## Static Public Attributes
static constexpr halide_type_code_t | Int = halide_type_int
| Aliases for halide_type_code_t values for legacy compatibility and to match the Halide internal C++ style. More...
static constexpr halide_type_code_t | UInt = halide_type_uint
static constexpr halide_type_code_t | Float = halide_type_float
static constexpr halide_type_code_t | BFloat = halide_type_bfloat
static constexpr halide_type_code_t | Handle = halide_type_handle

## Detailed Description

Types in the halide type system.

They can be ints, unsigned ints, or floats of various bit-widths (the 'bits' field). They can also be vectors of the same (by setting the 'lanes' field to something larger than one). Front-end code shouldn't use vector types. Instead vectorize a function.

Definition at line 281 of file Type.h.

## Constructor & Destructor Documentation

## ◆ Type() [1/4]

Halide::Type::Type | ( |  | ) |
| inline

Definition at line 302 of file Type.h.

Referenced by with_bits(), with_code(), and with_lanes().

## ◆ Type() [2/4]

Halide::Type::Type | ( | halide_type_code_t | code,
|  | int | bits,
|  | int | lanes,
|  | const halide_handle_cplusplus_type * | handle_type = `nullptr`
| ) |  |
| inline

Construct a runtime representation of a Halide type from: code: The fundamental type from an enum.

bits: The bit size of one element. lanes: The number of vector elements in the type.

Definition at line 310 of file Type.h.

References halide_type_t::bits, bits(), halide_type_t::lanes, lanes(), and user_assert.

## ◆ Type() [3/4]

Halide::Type::Type | ( | const Type & | that | ) |
| default

Trivial copy constructor.

## ◆ Type() [4/4]

HALIDE_ALWAYS_INLINE Halide::Type::Type | ( | const halide_type_t & | that,
|  | const halide_handle_cplusplus_type * | handle_type = `nullptr`
| ) |  |
| inline

Type is a wrapper around halide_type_t with more methods for use inside the compiler.

This simply constructs the wrapper around the runtime value.

Definition at line 328 of file Type.h.

## Member Function Documentation

## ◆ bytes()

int Halide::Type::bytes | ( |  | ) | const
| inline

The number of bytes required to store a single scalar value of this type.

Ignores vector lanes.

Definition at line 297 of file Type.h.

References bits().

Referenced by Halide::Internal::HexagonAlignmentAnalyzer::is_aligned().

## ◆ operator=()

Type & Halide::Type::operator= | ( | const Type & | that | ) |
| default

Trivial copy assignment operator.

## ◆ operator halide_type_t()

HALIDE_ALWAYS_INLINE Halide::Type::operator halide_type_t | ( |  | ) | const
| inline

Unwrap the runtime halide_type_t for use in runtime calls, etc.

Representation is exactly equivalent.

Definition at line 335 of file Type.h.

## ◆ code()

HALIDE_ALWAYS_INLINE halide_type_code_t Halide::Type::code | ( |  | ) | const
| inline

Return the underlying data type of an element as an enum value.

Definition at line 341 of file Type.h.

References halide_type_t::code.

Referenced by is_bfloat(), is_bool(), is_float(), is_handle(), is_int(), is_int_or_uint(), is_uint(), operator!=(), operator<(), operator==(), with_bits(), with_code(), and with_lanes().

## ◆ bits()

HALIDE_ALWAYS_INLINE int Halide::Type::bits | ( |  | ) | const
| inline

Return the bit size of a single element of this type.

Definition at line 347 of file Type.h.

References halide_type_t::bits.

Referenced by bytes(), can_overflow_int(), Halide::Internal::Simplify::ExprInfo::cast_to(), Halide::Internal::eliminated_bool_type(), is_bool(), Halide::Internal::Cast::is_reinterpret(), Halide::Internal::IRMatcher::IsInt< A >::make_folded_const(), Halide::Internal::IRMatcher::IsUInt< A >::make_folded_const(), narrow(), Halide::Internal::Simplify::no_overflow_int(), Halide::Internal::Simplify::normalize_constant(), Type(), widen(), with_bits(), with_code(), and with_lanes().

## ◆ lanes()

HALIDE_ALWAYS_INLINE int Halide::Type::lanes | ( |  | ) | const
| inline

Return the number of vector elements in this type.

Definition at line 353 of file Type.h.

References halide_type_t::lanes.

Referenced by Halide::ConciseCasts::bf16(), Halide::ConciseCasts::f16(), Halide::ConciseCasts::f32(), Halide::ConciseCasts::f64(), Halide::ConciseCasts::i16(), Halide::ConciseCasts::i16_sat(), Halide::ConciseCasts::i32(), Halide::ConciseCasts::i32_sat(), Halide::ConciseCasts::i64(), Halide::ConciseCasts::i64_sat(), Halide::ConciseCasts::i8(), Halide::ConciseCasts::i8_sat(), is_scalar(), is_vector(), Halide::Internal::IRMatcher::CanProve< A, Prover >::make_folded_const(), Halide::Internal::IRMatcher::IsFloat< A >::make_folded_const(), Halide::Internal::IRMatcher::IsInt< A >::make_folded_const(), Halide::Internal::IRMatcher::IsUInt< A >::make_folded_const(), Halide::Internal::IRMatcher::IsScalar< A >::make_folded_const(), Halide::Internal::IRMatcher::LanesOf< A >::make_folded_const(), Halide::Internal::IRMatcher::VectorReduceOp< A, B, reduce_op >::match(), Halide::Internal::IRMatcher::SliceOp< Vec, Base, Stride, Lanes >::match(), Type(), Halide::ConciseCasts::u16(), Halide::ConciseCasts::u16_sat(), Halide::ConciseCasts::u32(), Halide::ConciseCasts::u32_sat(), Halide::ConciseCasts::u64(), Halide::ConciseCasts::u64_sat(), Halide::ConciseCasts::u8(), Halide::ConciseCasts::u8_sat(), with_bits(), and with_code().

## ◆ with_code()

Type Halide::Type::with_code | ( | halide_type_code_t | new_code | ) | const
| inline

Return Type with same number of bits and lanes, but new_code for a type code.

Definition at line 358 of file Type.h.

References bits(), code(), handle_type, lanes(), and Type().

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

## ◆ with_bits()

Type Halide::Type::with_bits | ( | int | new_bits | ) | const
| inline

Return Type with same type code and lanes, but new_bits for the number of bits.

Definition at line 364 of file Type.h.

References bits(), code(), handle_type, lanes(), and Type().

Referenced by Halide::Internal::eliminated_bool_type(), narrow(), and widen().

## ◆ with_lanes()

Type Halide::Type::with_lanes | ( | int | new_lanes | ) | const
| inline

Return Type with same type code and number of bits, but new_lanes for the number of vector lanes.

Definition at line 371 of file Type.h.

References bits(), code(), handle_type, and Type().

Referenced by element_of().

## ◆ widen()

Type Halide::Type::widen | ( |  | ) | const
| inline

Return Type with the same type code and number of lanes, but with at least twice as many bits.

Definition at line 376 of file Type.h.

References bits(), and with_bits().

Referenced by Halide::Internal::IRMatcher::WidenOp< A >::make(), and Halide::Internal::IRMatcher::WidenOp< A >::match().

## ◆ narrow()

Type Halide::Type::narrow | ( |  | ) | const
| inline

Return Type with the same type code and number of lanes, but with at most half as many bits.

Definition at line 386 of file Type.h.

References bits(), internal_assert, and with_bits().

## ◆ is_bool()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_bool | ( |  | ) | const
| inline

Is this type boolean (represented as UInt(1))?

Definition at line 401 of file Type.h.

References bits(), code(), and UInt.

## ◆ is_vector()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_vector | ( |  | ) | const
| inline

Is this type a vector type? (lanes() != 1).

TODO(abadams): Decide what to do for lanes() == 0.

Definition at line 408 of file Type.h.

References lanes().

Referenced by Halide::Internal::eliminated_bool_type(), and Halide::Internal::HexagonAlignmentAnalyzer::is_aligned_impl().

## ◆ is_scalar()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_scalar | ( |  | ) | const
| inline

Is this type a scalar type? (lanes() == 1).

TODO(abadams): Decide what to do for lanes() == 0.

Definition at line 415 of file Type.h.

References lanes().

Referenced by Halide::Internal::IRMatcher::IsScalar< A >::make_folded_const(), and Halide::Internal::Simplify::no_overflow_scalar_int().

## ◆ is_float()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_float | ( |  | ) | const
| inline

Is this type a floating point type (float or double).

Definition at line 421 of file Type.h.

References BFloat, code(), and Float.

Referenced by Halide::Internal::div_imp(), Halide::Internal::IRMatcher::IsFloat< A >::make_folded_const(), Halide::Internal::mod_imp(), and Halide::Internal::Simplify::no_overflow().

## ◆ is_bfloat()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_bfloat | ( |  | ) | const
| inline

Is this type a floating point type (float or double).

Definition at line 427 of file Type.h.

References BFloat, and code().

## ◆ is_int()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_int | ( |  | ) | const
| inline

Is this type a signed integer type?

Definition at line 433 of file Type.h.

References code(), and Int.

Referenced by can_overflow_int(), Halide::Internal::Simplify::ExprInfo::cast_to(), Halide::Internal::div_imp(), Halide::Internal::IRMatcher::IsInt< A >::make_folded_const(), Halide::Internal::mod_imp(), Halide::Internal::Simplify::no_overflow_int(), and Halide::Internal::Simplify::normalize_constant().

## ◆ is_uint()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_uint | ( |  | ) | const
| inline

Is this type an unsigned integer type?

Definition at line 439 of file Type.h.

References code(), and UInt.

Referenced by can_overflow(), Halide::Internal::Simplify::ExprInfo::cast_to(), Halide::Internal::IRMatcher::IsUInt< A >::make_folded_const(), and Halide::Internal::Simplify::normalize_constant().

## ◆ is_int_or_uint()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_int_or_uint | ( |  | ) | const
| inline

Is this type an integer type of any sort?

Definition at line 445 of file Type.h.

References code(), Int, and UInt.

Referenced by Halide::SimdOpCheckTest::check_one(), and Halide::Internal::Cast::is_reinterpret().

## ◆ is_handle()

HALIDE_ALWAYS_INLINE bool Halide::Type::is_handle | ( |  | ) | const
| inline

Is this type an opaque handle type (void *)

Definition at line 451 of file Type.h.

References code(), and Handle.

## ◆ can_overflow_int()

HALIDE_ALWAYS_INLINE bool Halide::Type::can_overflow_int | ( |  | ) | const
| inline

Definition at line 457 of file Type.h.

References bits(), and is_int().

Referenced by can_overflow().

## ◆ can_overflow()

HALIDE_ALWAYS_INLINE bool Halide::Type::can_overflow | ( |  | ) | const
| inline

Definition at line 463 of file Type.h.

References can_overflow_int(), and is_uint().

## ◆ same_handle_type()

bool Halide::Type::same_handle_type | ( | const Type & | other | ) | const

Check that the type name of two handles matches.

Referenced by operator!=(), and operator==().

## ◆ operator==() [1/2]

bool Halide::Type::operator== | ( | const Type & | other | ) | const
| inline

Compare two types for equality.

Definition at line 471 of file Type.h.

References code(), Handle, and same_handle_type().

## ◆ operator!=() [1/2]

bool Halide::Type::operator!= | ( | const Type & | other | ) | const
| inline

Compare two types for inequality.

Definition at line 476 of file Type.h.

References code(), Handle, and same_handle_type().

## ◆ operator==() [2/2]

bool Halide::Type::operator== | ( | const halide_type_t & | other | ) | const
| inline

Compare two types for equality.

Definition at line 481 of file Type.h.

## ◆ operator!=() [2/2]

bool Halide::Type::operator!= | ( | const halide_type_t & | other | ) | const
| inline

Compare two types for inequality.

Definition at line 486 of file Type.h.

## ◆ operator<()

bool Halide::Type::operator< | ( | const Type & | other | ) | const
| inline

Compare ordering of two types so they can be used in certain containers and algorithms.

Definition at line 491 of file Type.h.

References code(), Handle, and handle_type.

## ◆ element_of()

Type Halide::Type::element_of | ( |  | ) | const
| inline

Produce the scalar type (that of a single element) of this vector type.

Definition at line 502 of file Type.h.

References with_lanes().

## ◆ can_represent() [1/5]

bool Halide::Type::can_represent | ( | Type | other | ) | const

Can this type represent all values of another type?

Referenced by Halide::Internal::Simplify::ExprInfo::cast_to().

## ◆ can_represent() [2/5]

bool Halide::Type::can_represent | ( | const Internal::ConstantInterval & | in | ) | const

Can this type represent exactly all integer values of some constant integer range?

## ◆ can_represent() [3/5]

bool Halide::Type::can_represent | ( | double | x | ) | const

Can this type represent a particular constant?

## ◆ can_represent() [4/5]

bool Halide::Type::can_represent | ( | int64_t | x | ) | const

## ◆ can_represent() [5/5]

bool Halide::Type::can_represent | ( | uint64_t | x | ) | const

## ◆ is_max() [1/2]

bool Halide::Type::is_max | ( | uint64_t |  | ) | const

Check if an integer constant value is the maximum or minimum representable value for this type.

## ◆ is_max() [2/2]

bool Halide::Type::is_max | ( | int64_t |  | ) | const

## ◆ is_min() [1/2]

bool Halide::Type::is_min | ( | uint64_t |  | ) | const

## ◆ is_min() [2/2]

bool Halide::Type::is_min | ( | int64_t |  | ) | const

## ◆ max()

Expr Halide::Type::max | ( |  | ) | const

Return an expression which is the maximum value of this type.

Returns infinity for types which can represent it.

## ◆ min()

Expr Halide::Type::min | ( |  | ) | const

Return an expression which is the minimum value of this type.

Returns -infinity for types which can represent it.

## Member Data Documentation

## ◆ Int

constexpr halide_type_code_t Halide::Type::Int = halide_type_int
| static constexpr

Aliases for halide_type_code_t values for legacy compatibility and to match the Halide internal C++ style.

Definition at line 289 of file Type.h.

Referenced by Halide::Internal::eliminated_bool_type(), Halide::Int(), is_int(), and is_int_or_uint().

## ◆ UInt

constexpr halide_type_code_t Halide::Type::UInt = halide_type_uint
| static constexpr

Definition at line 290 of file Type.h.

Referenced by is_bool(), is_int_or_uint(), is_uint(), and Halide::UInt().

## ◆ Float

constexpr halide_type_code_t Halide::Type::Float = halide_type_float
| static constexpr

Definition at line 291 of file Type.h.

Referenced by Halide::Float(), and is_float().

## ◆ BFloat

constexpr halide_type_code_t Halide::Type::BFloat = halide_type_bfloat
| static constexpr

Definition at line 292 of file Type.h.

Referenced by Halide::BFloat(), is_bfloat(), and is_float().

## ◆ Handle

constexpr halide_type_code_t Halide::Type::Handle = halide_type_handle
| static constexpr

Definition at line 293 of file Type.h.

Referenced by Halide::Handle(), is_handle(), operator!=(), operator<(), and operator==().

## ◆ handle_type

const halide_handle_cplusplus_type* Halide::Type::handle_type = nullptr

Type to be printed when declaring handles of this type.

Definition at line 397 of file Type.h.

Referenced by operator<(), with_bits(), with_code(), and with_lanes().

The documentation for this struct was generated from the following file:

- src/Type.h