You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HeteroCL now supports basic bit-accurate integers and fixed-point numbers. The way I implement it is to extend Halide's data type. Here we can see that a data type has four attributes: code, bits, lanes, and fracs. The first one represents the data type. Namely, it can be int, uint, float, or handle. Here we only need to focus on int and uint. With bits and fracs, we can now create an (unsigned) integer with total bits bits, where fracs bits are for the fractional number. For example, if fracs is zero, it is a normal bit-accurate integer. Otherwise, it is a fixed-point.
To access these field, you can look into this file. Here, Type is a wrapper for the base Halide data type. Note that in addition to the Type struct on Line 296, I also define two enums for quantization mode and overflow mode. For more details on their meaning, you can check here(Page 640). Currently, the quantization mode and overflow mode are only defined but not used. This is also what you are going to implement. Basically, we need these when we assign a fixed-point number to another one.
For the Python user interface, the wrapper Type is defined here. Namely, in the samples, we are all going to use these to represent a data type. These wrapper data types will be translated to Python string. For a fixed-point data type, it looks like fixed{a}_{b}, where a is for bits and b is for fracs. One example is fixed10_5. What you need to do here is to also include the quantization mode and overflow mode into this representation. You can implement it in any way. It is up to you.
There is another place you need to look at. This file defines the behavior when we take in a Numpy array (Line 157) and when we translate it back (Line 223). For different quantization mode, we will need different behaviors.
Finally, you can check the commit for what I have changed. It would be easier for you to understand. Basically, I don't think you need to go down to LLVM level. But I'm not sure though.
HeteroCL now supports basic bit-accurate integers and fixed-point numbers. The way I implement it is to extend Halide's data type. Here we can see that a data type has four attributes:
code
,bits
,lanes
, andfracs
. The first one represents the data type. Namely, it can beint
,uint
,float
, orhandle
. Here we only need to focus onint
anduint
. Withbits
andfracs
, we can now create an (unsigned) integer with totalbits
bits, wherefracs
bits are for the fractional number. For example, iffracs
is zero, it is a normal bit-accurate integer. Otherwise, it is a fixed-point.To access these field, you can look into this file. Here,
Type
is a wrapper for the base Halide data type. Note that in addition to theType
struct on Line 296, I also define two enums for quantization mode and overflow mode. For more details on their meaning, you can check here(Page 640). Currently, the quantization mode and overflow mode are only defined but not used. This is also what you are going to implement. Basically, we need these when we assign a fixed-point number to another one.For the Python user interface, the wrapper Type is defined here. Namely, in the samples, we are all going to use these to represent a data type. These wrapper data types will be translated to Python
string
. For a fixed-point data type, it looks likefixed{a}_{b}
, wherea
is forbits
andb
is forfracs
. One example isfixed10_5
. What you need to do here is to also include the quantization mode and overflow mode into this representation. You can implement it in any way. It is up to you.There is another place you need to look at. This file defines the behavior when we take in a Numpy array (Line 157) and when we translate it back (Line 223). For different quantization mode, we will need different behaviors.
Finally, you can check the commit for what I have changed. It would be easier for you to understand. Basically, I don't think you need to go down to LLVM level. But I'm not sure though.
Commit 1
Commit 2
The text was updated successfully, but these errors were encountered: