DLDataType#

struct DLDataType#

The data type the tensor can hold. The data type is assumed to follow the native endian-ness. An explicit error message should be raised when attempting to export an array with non-native endianness.

Examples

  • float: type_code = 2, bits = 32, lanes = 1

  • float4(vectorized 4 float): type_code = 2, bits = 32, lanes = 4

  • int8: type_code = 0, bits = 8, lanes = 1

  • std::complex<float>: type_code = 5, bits = 64, lanes = 1

  • bool: type_code = 6, bits = 8, lanes = 1 (as per common array library convention, the underlying storage size of bool is 8 bits)

  • float8_e4m3: type_code = 8, bits = 8, lanes = 1 (packed in memory)

  • float6_e3m2fn: type_code = 16, bits = 6, lanes = 1 (packed in memory)

  • float4_e2m1fn: type_code = 17, bits = 4, lanes = 1 (packed in memory)

When a sub-byte type is packed, DLPack requires the data to be in little bit-endian, i.e., for a packed data set D ((D >> (i * bits)) && bit_mask) stores the i-th element.

Public Members

uint8_t code#

Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint, but the value should be one of DLDataTypeCode enum values.

uint8_t bits#

Number of bits, common choices are 8, 16, 32.

uint16_t lanes#

Number of lanes in the type, used for vector types.