pulp-platform / snitch_cluster

An energy-efficient RISC-V floating-point compute cluster.
https://pulp-platform.github.io/snitch_cluster/
Apache License 2.0
48 stars 46 forks source link

sw: Fix `snrt_dma_wait` implementation #153

Closed zero9178 closed 2 months ago

zero9178 commented 2 months ago

The previous implementation of snrt_dma_wait was incorrect as it had an infinite loop in the case that tid was the last completed transaction. Looking at the documentation, the snippet in custom_instructions.md shows the correct way of implementing the transaction check (get last completed tid and loop if it's less than the one we are waiting for) except it had its register operands swapped. This PR uses that implementation instead, fixes the small bug in the documentation and changes one of the waits in dma_simple.c to make sure we don't regress either.

zero9178 commented 2 months ago

LGTM. Thanks for the fix!

Thank you! Would you mind merging this for me as well? I do not have commit writes :)

fischeti commented 2 months ago

LGTM. Thanks for the fix!

Thank you! Would you mind merging this for me as well? I do not have commit writes :)

Me neither unfortunately😉 @paulsc96 and @colluca are maintainers of the repository

zero9178 commented 2 months ago

Thanks for the contribution @zero9178 :)

Looking at the PR, it looks like this breaks the way zero-sized transfers are handled (return a transaction ID of -1).

I'm adding a test for these transfers and correcting the condition. Will merge as soon as I get this fixed :)

Thanks good catch I did not consider these. Could these use 0 instead or does the DMA engine return 0 for the very first transaction? Otherwise I'd just change the bltu to blt

colluca commented 2 months ago

Thanks good catch I did not consider these. Could these use 0 instead or does the DMA engine return 0 for the very first transaction? Otherwise I'd just change the bltu to blt

Zero seems to work. But actually the new DMA should support zero-sized transfers, so removing the if condition on the size altogether should work. There seems to be a bug however which I'm currently investigating.

colluca commented 2 months ago

A fix to the DMA bug is provided in https://github.com/pulp-platform/iDMA/pull/50. Till that is merged and a new release of the iDMA is created, we can merge this PR with the zero ID as suggested.