finn.core.datatype (module)

class finn.core.datatype.DataType(value)

Bases: enum.Enum

Enum class that contains FINN data types to set the quantization annotation. ONNX does not support data types smaller than 8-bit integers, whereas in FINN we are interested in smaller integers down to ternary and bipolar.

Assignment of DataTypes to indices based on following ordering:

  • unsigned to signed

  • fewer to more bits

Currently supported DataTypes:

BINARY = 1
BIPOLAR = 34
FLOAT32 = 68
INT10 = 44
INT11 = 45
INT12 = 46
INT13 = 47
INT14 = 48
INT15 = 49
INT16 = 50
INT17 = 51
INT18 = 52
INT19 = 53
INT2 = 36
INT20 = 54
INT21 = 55
INT22 = 56
INT23 = 57
INT24 = 58
INT25 = 59
INT26 = 60
INT27 = 61
INT28 = 62
INT29 = 63
INT3 = 37
INT30 = 64
INT31 = 65
INT32 = 66
INT4 = 38
INT5 = 39
INT6 = 40
INT64 = 67
INT7 = 41
INT8 = 42
INT9 = 43
TERNARY = 35
UINT10 = 10
UINT11 = 11
UINT12 = 12
UINT13 = 13
UINT14 = 14
UINT15 = 15
UINT16 = 16
UINT17 = 17
UINT18 = 18
UINT19 = 19
UINT2 = 2
UINT20 = 20
UINT21 = 21
UINT22 = 22
UINT23 = 23
UINT24 = 24
UINT25 = 25
UINT26 = 26
UINT27 = 27
UINT28 = 28
UINT29 = 29
UINT3 = 3
UINT30 = 30
UINT31 = 31
UINT32 = 32
UINT4 = 4
UINT5 = 5
UINT6 = 6
UINT64 = 33
UINT7 = 7
UINT8 = 8
UINT9 = 9
allowed(value)

Check whether given value is allowed for this DataType.

  • value (float32): value to be checked

bitwidth()

Returns the number of bits required for this DataType.

get_hls_datatype_str()

Returns the corresponding Vivado HLS datatype name.

get_num_possible_values()

Returns the number of possible values this DataType can take. Only implemented for integer types for now.

get_smallest_possible()

Returns smallest (fewest bits) possible DataType that can represent value. Prefers unsigned integers where possible.

is_integer()

Returns whether this DataType represents integer values only.

max()

Returns the largest possible value allowed by this DataType.

min()

Returns the smallest possible value allowed by this DataType.

signed()

Returns whether this DataType can represent negative numbers.