Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed-point support for different quantization modes and overflow modes #9

Open
seanlatias opened this issue May 14, 2018 · 1 comment

Comments

@seanlatias
Copy link
Collaborator

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.

Commit 1
Commit 2

@chhzh123
Copy link
Member

This feature is useful for the new HeteroCL flow. We will look back later.
cornell-zhang/hcl-dialect#166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants