-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add support for free-running functions in simulation #53
base: master
Are you sure you want to change the base?
Conversation
I'm currently thinking about using some free-running kernels as well, and this seems like it could be helpful. |
Sorry I dropped the ball on this -- Lucian and I discussed via email, and could not come up with any perfect way to do this. The solution that Lucian proposed probably works in most cases, as the detached freerunning threads will just be killed when the program exists, but it's not very clean. If the program keeps running after the kernel launch, these functions will just sit around. Worse yet, if the kernel is called many times, each launch will create new threads that will run forever. Ideas are welcome! |
This may be off-topic, but what does Even more off-topic (sorry, hard to find good info elsewhere): Do you have experience with using the HLS IP Libraries? |
The important difference in Lucian's PR is to not wait for the freerunning functions before exiting the dataflow sections, as they will never terminate. @quetric I was actually only familiar with free-running functions as kernels, not as dataflow functions -- do they need to have the I've never used the HLS IP libraries, so I can't help you there :-) |
Freerunning functions are entire kernels, yes, and the free-running aspect is obtained by either instructing HLS to use ap_ctrl_none as a control protocol or by using s_axilite control and manually setting the autorestart bit in the registers. Otherwise the code looks the same as a non-freerunning function. My intention with I don't have experience with the HLS IP libs either. |
I see, then |
That's essentially what happens, but in a thread. |
Xilinx HLS IP can be free-running (they self-restart) for example by setting control mode to
ap_ctrl_none
in Vivado/Vitis HLS. This is a relatively common design pattern.I've added an additional simulation macro,
HLSLIB_FREERUNNING_FUNCTION
, which wraps the function in awhile(1)
before launching the thread, such that the function executes repeatedly, emulating the expected real-world behaviour. This works, with a minimal application example such as this:There is a fundamental problem to this approach though which is that we can't expect free-running functions to ever finish. Even if I were to provide a mechanism to interrupt the restarting loop, there isn't any guarantee that the function had not been already restarted by the time the interrupt signal comes, in which case it may be blocking on a stream read. Therefore, I've chosen the simplest approach which is to join only dataflow function threads, which are kept in a separate queue from free-running function threads, which will be killed on program exit.