tvm
Public Member Functions | Static Public Member Functions | List of all members
tvm::PrimType Class Referencefinal

#include <base_expr.h>

Inheritance diagram for tvm::PrimType:
Collaboration diagram for tvm::PrimType:

Public Member Functions

 PrimType (DLDataType dtype)
 Construct from a raw DLPack dtype. More...
 
 PrimType (DLDataTypeCode code, int bits, int lanes=1)
 Construct from DLPack dtype fields. More...
 
TVM_FFI_INLINE DLDataTypeCode code () const
 
TVM_FFI_INLINE int32_t bits () const
 
TVM_FFI_INLINE int32_t lanes () const
 
TVM_FFI_INLINE bool MatchesElementType (DLDataTypeCode code, int bits) const
 Check the scalar element code and bit width. More...
 
template<typename... Codes>
TVM_FFI_INLINE bool MatchesCode (Codes... codes) const
 Check whether the dtype code matches any of the provided DLPack codes. More...
 
TVM_FFI_INLINE bool IsScalar () const
 Whether this type is a scalar, excluding fixed and scalable vectors. More...
 
TVM_FFI_INLINE bool IsVoid () const
 Whether this type is the void sentinel handle(0, 0). More...
 
TVM_FFI_INLINE bool IsScalableVector () const
 Whether this type is a scalable vector. More...
 
TVM_FFI_INLINE bool IsFixedLengthVector () const
 Whether this type is a fixed-length vector. More...
 
TVM_FFI_INLINE size_t StorageBytes () const
 Return the number of bytes needed to store one value of this type. More...
 
TVM_FFI_INLINE PrimType WithCode (DLDataTypeCode code) const
 Return the same type with a different dtype code, preserving bits and lanes. More...
 
TVM_FFI_INLINE PrimType WithBits (int bits) const
 Return the same type with a different scalar bit width, preserving code and lanes. More...
 
TVM_FFI_INLINE PrimType WithLanes (int lanes) const
 Return the same scalar element type with a fixed lane count. More...
 
TVM_FFI_INLINE int32_t VScaleFactor () const
 
 TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE (PrimType, Type, PrimTypeNode)
 
- Public Member Functions inherited from tvm::Type
bool IsMissing () const
 
 TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE (Type, ffi::ObjectRef, TypeNode)
 

Static Public Member Functions

static PrimType Int (int bits, int lanes=1)
 Construct a signed integer type with fixed lanes. More...
 
static PrimType UInt (int bits, int lanes=1)
 Construct an unsigned integer type with fixed lanes. More...
 
static PrimType Float (int bits, int lanes=1)
 Construct a floating-point type with fixed lanes. More...
 
static PrimType BFloat (int bits, int lanes=1)
 Construct a bfloat type with fixed lanes. More...
 
static PrimType Bool (int lanes=1)
 Construct a boolean type with fixed lanes. More...
 
static PrimType Void ()
 Construct the void sentinel type, encoded as handle(0, 0). More...
 
static PrimType ScalableVector (DLDataTypeCode code, int bits, int lanes)
 Construct a scalable vector type. More...
 
- Static Public Member Functions inherited from tvm::Type
static Type Missing ()
 Sentinel for a type that has not been populated yet. More...
 

Constructor & Destructor Documentation

◆ PrimType() [1/2]

tvm::PrimType::PrimType ( DLDataType  dtype)
explicit

Construct from a raw DLPack dtype.

Parameters
dtypeThe corresponding DLPack dtype.

◆ PrimType() [2/2]

tvm::PrimType::PrimType ( DLDataTypeCode  code,
int  bits,
int  lanes = 1 
)

Construct from DLPack dtype fields.

Parameters
codeThe DLPack dtype code.
bitsThe scalar bit width.
lanesThe fixed lane count.

Member Function Documentation

◆ BFloat()

static PrimType tvm::PrimType::BFloat ( int  bits,
int  lanes = 1 
)
static

Construct a bfloat type with fixed lanes.

◆ bits()

TVM_FFI_INLINE int32_t tvm::PrimType::bits ( ) const
inline
Returns
The scalar bit width.

◆ Bool()

static PrimType tvm::PrimType::Bool ( int  lanes = 1)
static

Construct a boolean type with fixed lanes.

◆ code()

TVM_FFI_INLINE DLDataTypeCode tvm::PrimType::code ( ) const
inline
Returns
The DLPack dtype code.

◆ Float()

static PrimType tvm::PrimType::Float ( int  bits,
int  lanes = 1 
)
static

Construct a floating-point type with fixed lanes.

◆ Int()

static PrimType tvm::PrimType::Int ( int  bits,
int  lanes = 1 
)
static

Construct a signed integer type with fixed lanes.

◆ IsFixedLengthVector()

TVM_FFI_INLINE bool tvm::PrimType::IsFixedLengthVector ( ) const
inline

Whether this type is a fixed-length vector.

◆ IsScalableVector()

TVM_FFI_INLINE bool tvm::PrimType::IsScalableVector ( ) const
inline

Whether this type is a scalable vector.

◆ IsScalar()

TVM_FFI_INLINE bool tvm::PrimType::IsScalar ( ) const
inline

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

◆ IsVoid()

TVM_FFI_INLINE bool tvm::PrimType::IsVoid ( ) const
inline

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

◆ lanes()

TVM_FFI_INLINE int32_t tvm::PrimType::lanes ( ) const
inline
Returns
The fixed lane count.
Note
Throws on scalable vector types, where the encoded lane field stores a vscale factor.

◆ MatchesCode()

template<typename... Codes>
TVM_FFI_INLINE bool tvm::PrimType::MatchesCode ( Codes...  codes) const
inline

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

Note
Bit width and lanes are intentionally ignored.

◆ MatchesElementType()

TVM_FFI_INLINE bool tvm::PrimType::MatchesElementType ( DLDataTypeCode  code,
int  bits 
) const
inline

Check the scalar element code and bit width.

Note
Lane count and scalable-vector encoding are intentionally ignored.

◆ ScalableVector()

static PrimType tvm::PrimType::ScalableVector ( DLDataTypeCode  code,
int  bits,
int  lanes 
)
static

Construct a scalable vector type.

Parameters
codeThe DLPack dtype code.
bitsThe scalar bit width.
lanesThe positive vscale factor to encode in the DLPack lane field.

◆ StorageBytes()

TVM_FFI_INLINE size_t tvm::PrimType::StorageBytes ( ) const
inline

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.

◆ TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE()

tvm::PrimType::TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE ( PrimType  ,
Type  ,
PrimTypeNode   
)

◆ UInt()

static PrimType tvm::PrimType::UInt ( int  bits,
int  lanes = 1 
)
static

Construct an unsigned integer type with fixed lanes.

◆ Void()

static PrimType tvm::PrimType::Void ( )
static

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

◆ VScaleFactor()

TVM_FFI_INLINE int32_t tvm::PrimType::VScaleFactor ( ) const
inline
Returns
The vscale factor encoded in a scalable vector type.

◆ WithBits()

TVM_FFI_INLINE PrimType tvm::PrimType::WithBits ( int  bits) const
inline

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

◆ WithCode()

TVM_FFI_INLINE PrimType tvm::PrimType::WithCode ( DLDataTypeCode  code) const
inline

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

◆ WithLanes()

TVM_FFI_INLINE PrimType tvm::PrimType::WithLanes ( int  lanes) const
inline

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


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