Type#

struct Type#

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.

Public Functions

inline int bytes() const#

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

Ignores vector lanes.

inline 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.

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

Type(const Type &that) = default#

Trivial copy constructor.

Type &operator=(const Type &that) = default#

Trivial copy assignment operator.

inline Type(halide_type_t that, const halide_handle_cplusplus_type *handle_type = nullptr)#

Construct a (scalar) language Type from an ABI element type.

inline halide_type_t to_abi() const#

Erase this language Type to the ABI/runtime halide_type_t for use in runtime calls, buffer/argument metadata, etc.

This is a checked erasure: the ABI element type has no lanes, so a vector type (lanes >= 2) has no image here and asserts rather than silently dropping its lanes.

inline halide_type_code_t code() const#

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

inline int bits() const#

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

inline int lanes() const#

Return the number of vector elements in this type.

inline 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.

inline Type with_bits(int new_bits) const#

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

inline 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.

inline Type widen() const#

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

inline Type narrow() const#

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

inline const halide_handle_cplusplus_type *handle_type() const#

The externally-owned C++ type metadata for a handle type (null for a plain void * handle or a non-handle type).

Backed by a 4-byte intern index rather than stored inline, so this is now an accessor rather than a public field.

inline bool is_bool() const#

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

inline bool is_vector() const#

Is this type a vector type?

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

inline bool is_scalar() const#

Is this type a scalar type?

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

inline bool is_float() const#

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

inline bool is_bfloat() const#

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

inline bool is_int() const#

Is this type a signed integer type?

inline bool is_uint() const#

Is this type an unsigned integer type?

inline bool is_int_or_uint() const#

Is this type an integer type of any sort?

inline bool is_handle() const#

Is this type an opaque handle type (void *).

bool same_handle_type(const Type &other) const#

Check that the type name of two handles matches.

inline bool operator==(const Type &other) const#

Compare two types for equality.

inline bool operator!=(const Type &other) const#

Compare two types for inequality.

inline bool operator==(const halide_type_t &other) const#

Compare a language type to an ABI element type.

Equal iff this type is a single element (not a vector) with the same code and bits.

inline bool operator!=(const halide_type_t &other) const#

Compare two types for inequality.

inline bool operator<(const Type &other) const#

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

inline Type element_of() const#

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

bool can_represent(Type other) const#

Can this type represent all values of another type?

bool can_represent(const Internal::ConstantInterval &in) const#

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

bool can_represent(double x) const#

Can this type represent a particular constant?

bool is_max(uint64_t) const#

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

Expr max() const#

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

Returns infinity for types which can represent it.

Expr min() const#

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

Returns -infinity for types which can represent it.

Public Static Attributes

static 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.

static int kLanesBits = 8 * sizeof(type_lanes)#

Exposed so code that needs to reason about the maximum representable lanes count (e.g.

overflow checks when combining vectors) can derive it from Type itself instead of hardcoding a width.