Skip to content

AC Fixed Tutorial#2

Open
tiwaria1 wants to merge 5 commits intomasterfrom
ac_fixed_tutorial
Open

AC Fixed Tutorial#2
tiwaria1 wants to merge 5 commits intomasterfrom
ac_fixed_tutorial

Conversation

@tiwaria1
Copy link
Owner

@tiwaria1 tiwaria1 commented Oct 6, 2021

Internal review of ac_fixed tutorial. This is a port of the HLS ac_fixed tutorials.

Testing:
[DONE] Linux Local compile
[TODO] Linux Local compile with CMAKE
[TODO] Linux Regtest
[TODO] Windows Local compile with CMAKE
[TODO] Windows Regtest

@tiwaria1 tiwaria1 changed the title Ac fixed tutorial AC Fixed Tutorial Oct 7, 2021
Copy link

@whitepau whitepau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this tutorial as well. I like this method of partitioning different kernels into simple functions.

@@ -0,0 +1,260 @@
# Using the Algorithmic C Fixed Point Data-type 'ac_fixed'

This FPGA tutorial demonstrates how to use the Algorithmic C (AC) Data-type `ac_fixed` and some best practices.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This FPGA tutorial demonstrates how to use the Algorithmic C (AC) Data-type `ac_fixed` and some best practices.
This FPGA tutorial demonstrates how to use the Algorithmic C (AC) datatype `ac_fixed` and some best practices.

I believe the word 'datatype' is not hyphenated.


This FPGA tutorial shows how to use the `ac_fixed` type with some simple examples.

This data-type can be used in place of native floating point types to generate area efficient and optimized designs for the FPGA. For example, operations which do not utilize all of the bits the native types are good candidates for replacement with `ac_fixed` type.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This data-type can be used in place of native floating point types to generate area efficient and optimized designs for the FPGA. For example, operations which do not utilize all of the bits the native types are good candidates for replacement with `ac_fixed` type.
This data-type can be used in place of native floating point types to generate area efficient and optimized designs for the FPGA. Operations which do not utilize the full dynamic range of the native types are good candidates for using `ac_fixed` types. For example: multiplying by a number in the range of `(-1.0, 1.0)`.


This data-type can be used in place of native floating point types to generate area efficient and optimized designs for the FPGA. For example, operations which do not utilize all of the bits the native types are good candidates for replacement with `ac_fixed` type.

This tutorials shows the recommended method for constructing an `ac_fixed` number, some examples of using the fixed point math library functions and how they can be used to reduce the area of the hardware generated by the compiler by trading-off accuracy of the mathematical operations.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This tutorials shows the recommended method for constructing an `ac_fixed` number, some examples of using the fixed point math library functions and how they can be used to reduce the area of the hardware generated by the compiler by trading-off accuracy of the mathematical operations.
This tutorial shows the recommended method for constructing an `ac_fixed` number, some examples of using the fixed point math library functions and how they can be used to reduce the area of the hardware generated by the compiler by trading-off accuracy of the mathematical operations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think that 'trading-off' doesn't need to by hyphenated.

```cpp
ac_fixed<W, I, S> a;
```
Here W specifies the width and S specifies the sign of the number. One of the W bits is used to store the sign information. The second parameter I is an integer that specifies the location of the fixed point relative to the most significant bit.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W and S are parameters and should be monospaced.

```
Here W specifies the width and S specifies the sign of the number. One of the W bits is used to store the sign information. The second parameter I is an integer that specifies the location of the fixed point relative to the most significant bit.

The type also provides two more optional parameters for controlling the overflow and rounding modes. For more details on the type, rounding and overflow modes and the range of values supported with different width parameterization please refer to the file `ac_data_types_ref.pdf`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is ac_data_types_ref.pdf? mention that it's included in this tutorial.

sidenote: do we have permission to distribute it like this?


- Emulation vs Simulation for fixed point math operations

Due to the differences in the internal math implementations, the results from `ac_fixed` math functions in simulation and emulation might not always be bit-accurate. In this example you can observe the difference between emulation and simulation.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this tutorial releases, will simulation be supported? Is this limitation still present in oneAPI? Having a computational difference between emulation and hardware sounds like it will defeat the purpose of emulation :(


1. Input Bit Width and Input Value Range Limits

The fixed-point math functions have bit width and input value range requirements. All bit width and input value range requirements are documented at the top of the ac_fixed_math.hpp file. For example, the `sin_fixed` and `cos_fixed` functions require the integer part's bit width to be 3, and the input value range to be within [-pi, pi].
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The fixed-point math functions have bit width and input value range requirements. All bit width and input value range requirements are documented at the top of the ac_fixed_math.hpp file. For example, the `sin_fixed` and `cos_fixed` functions require the integer part's bit width to be 3, and the input value range to be within [-pi, pi].
The fixed-point math functions have bit width and input value range requirements. All bit width and input value range requirements are documented at the top of the ac_fixed_math.hpp file. For example, the `sin_fixed` and `cos_fixed` functions require the integer part's bit width to be <exactly> 3, and the input value range to be within [-pi, pi].

I assume this is the same as for HLS


2. Return Types

For fixed-point functions, each function has a default return type. Assigning the result to a non-default return type triggers a type conversion and can cause an increase in logic use or a loss of accuracy in your results. All return types are documented at the top of the ac_fixed_math.hpp file. For example, for `sin_fixed` and `cos_fixed`, the input type is `ac_fixed<W, 3, true>`, and the output type is `ac_fixed<W-1, 2, true>`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have not consistently monospaced filenames. Either always, or never.


## Key Concepts
* Constructing an `ac_fixed` from a `float` or `double` value will be much more area intensive than constructing one from another `ac_fixed`.
* The `ac_fixed` math library provides a set of functions for various math operations.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The `ac_fixed` math library provides a set of functions for various math operations.
* The `ac_fixed` math library provides a set of functions for various math operations that are optimized for `ac_fixed` types.


### Include Files

The included header `dpc_common.hpp` is located at `%ONEAPI_ROOT%\dev-utilities\latest\include` on your development system.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason that this uses the Windows path?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants