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
we cannot use floating point operations and therefore have to rely on fix point math. Therefore I would like to bring the Q number format (see https://en.wikipedia.org/wiki/Q_(number_format)) into Halide.
The major purpose of this is to reduce the necessary code to do all this nasty bit shifting.
Basically what I want to write later on is something like:
Func input;
input(x, y) = x + y;
QNumber gain1(3, 5); // create a Q3.5 number
gain = 3.5f;
QNumber offset(7, 23); // create a Q7.23 number
offset = 1.3f;
Func gained;
gained(x, y) = input(x, y) * gain1;
Func added;
added(x, y) = gained(x, y) + offset;
Func output;
output(x, y) = added(x, y).to_integer(8, "ceil"); // specify rounding to use
What would be the best way to do this?
I already tried using Halide::Tuple and came out with two major drawbacks:
The bit width of the internal integer expression cannot be changed dynamically. This would be possible if the integer and fractional bits information would be C++ variables (constants for the JIT compiler).
I am not able to determine if the Tuple is a QNumber or any user defined Tuple.
So I would like to write something like: Expr bigger = select(added(x, y) < QNumber(3, 5, 12), 1, 0);
But this is not possible because I have to explicitly cast the added(x, y) to QNumber.
So is there a better approach than using Halide::Tuple?
The text was updated successfully, but these errors were encountered:
StephanHeider
changed the title
How to implement FixPoint abstraction
How to implement fix point number format
Jul 10, 2018
One way could be to use unsigned integers for storing your Q numbers. Then you could write a wrapper class that offers the most common operations on Q numbers (arithmetic, conversions from/to other types, etc.)
Hi,
we cannot use floating point operations and therefore have to rely on fix point math. Therefore I would like to bring the Q number format (see https://en.wikipedia.org/wiki/Q_(number_format)) into Halide.
The major purpose of this is to reduce the necessary code to do all this nasty bit shifting.
Basically what I want to write later on is something like:
What would be the best way to do this?
I already tried using Halide::Tuple and came out with two major drawbacks:
The bit width of the internal integer expression cannot be changed dynamically. This would be possible if the integer and fractional bits information would be C++ variables (constants for the JIT compiler).
I am not able to determine if the Tuple is a QNumber or any user defined Tuple.
So I would like to write something like:
Expr bigger = select(added(x, y) < QNumber(3, 5, 12), 1, 0);
But this is not possible because I have to explicitly cast the added(x, y) to QNumber.
So is there a better approach than using Halide::Tuple?
The text was updated successfully, but these errors were encountered: