Class PrimType#

Inheritance Relationships#

Base Type#

Class Documentation#

class PrimType : public tvm::Type#

Public Types

using ContainerType = PrimTypeObj#

Public Functions

explicit PrimType(DLDataType dtype)#

Construct from a raw DLPack dtype.

Parameters:

dtype – The corresponding DLPack dtype.

PrimType(DLDataTypeCode code, int bits, int lanes = 1)#

Construct from DLPack dtype fields.

Parameters:
  • code – The DLPack dtype code.

  • bits – The scalar bit width.

  • lanes – The fixed lane count.

inline DLDataTypeCode code() const#
Returns:

The DLPack dtype code.

inline int32_t bits() const#
Returns:

The scalar bit width.

inline int32_t lanes() const#

Note

Throws on scalable vector types, where the encoded lane field stores a vscale factor.

Returns:

The fixed lane count.

inline bool MatchesElementType(DLDataTypeCode code, int bits) const#

Check the scalar element code and bit width.

Note

Lane count and scalable-vector encoding are intentionally ignored.

template<typename ...Codes>
inline bool MatchesCode(Codes... codes) const#

Check whether the dtype code matches any of the provided DLPack codes.

Note

Bit width and lanes are intentionally ignored.

inline bool IsScalar() const#

Whether this type is a scalar, excluding fixed and scalable vectors.

inline bool IsVoid() const#

Whether this type is the void sentinel handle(0, 0).

inline bool IsScalableVector() const#

Whether this type is a scalable vector.

inline bool IsFixedLengthVector() const#

Whether this type is a fixed-length vector.

inline size_t StorageBytes() const#

Return the number of bytes needed to store one value of this type.

This uses the same packed sub-byte dtype sizing rule as runtime tensors. Scalable vector types have no compile-time storage size and are rejected.

inline PrimType WithCode(DLDataTypeCode code) const#

Return the same type with a different dtype code, preserving bits and lanes.

inline PrimType WithBits(int bits) const#

Return the same type with a different scalar bit width, preserving code and lanes.

inline PrimType WithLanes(int lanes) const#

Return the same scalar element type with a fixed lane count.

inline int32_t VScaleFactor() const#
Returns:

The vscale factor encoded in a scalable vector type.

inline explicit PrimType(::tvm::ffi::UnsafeInit tag)#
inline __PtrType operator->() const#
inline __PtrType get() const#

Public Static Functions

static PrimType Int(int bits, int lanes = 1)#

Construct a signed integer type with fixed lanes.

static PrimType UInt(int bits, int lanes = 1)#

Construct an unsigned integer type with fixed lanes.

static PrimType Float(int bits, int lanes = 1)#

Construct a floating-point type with fixed lanes.

static PrimType BFloat(int bits, int lanes = 1)#

Construct a bfloat type with fixed lanes.

static PrimType Bool(int lanes = 1)#

Construct a boolean type with fixed lanes.

static PrimType Void()#

Construct the void sentinel type, encoded as handle(0, 0).

static PrimType ScalableVector(DLDataTypeCode code, int bits, int lanes)#

Construct a scalable vector type.

Parameters:
  • code – The DLPack dtype code.

  • bits – The scalar bit width.

  • lanes – The positive vscale factor to encode in the DLPack lane field.