PennyLaneAI / catalyst

A JIT compiler for hybrid quantum programs in PennyLane
https://docs.pennylane.ai/projects/catalyst
Apache License 2.0
130 stars 29 forks source link

Add NoFree to __catalyst_inactive_callback && Update Enzyme to version 0.0.130 #898

Closed rmoyard closed 3 months ago

rmoyard commented 3 months ago

Context: Update to use latest Enzyme release. Description of the Change: I added NoFree attribute to the function __catalyst_inactive_callback in order to be compatible with Enzyme changes in this PR https://github.com/EnzymeAD/Enzyme/pull/1687/.

rmoyard commented 3 months ago

[sc-67709]

github-actions[bot] commented 3 months ago

Hello. You may have forgotten to update the changelog! Please edit doc/changelog.md on your branch with:

dime10 commented 3 months ago

What is nofree?

rmoyard commented 3 months ago

From LLVM docs:

This indicates that callee does not free the pointer argument. This is not a valid attribute for return values.
erick-xanadu commented 3 months ago

@rmoyard, just a small correction, nofree as an annotation exists for parameters and functions. The documentation you pointed to is for parameters but you added it to the function. Here is the documentation for the attribute nofree for functions:

nofree

This function attribute indicates that the function does not, directly or transitively, call a memory-deallocation function (free, for example) on a memory allocation which existed before the call.

As a result, uncaptured pointers that are known to be dereferenceable prior to a call to a function with the nofree attribute are still known to be dereferenceable after the call. The capturing condition is necessary in environments where the function might communicate the pointer to another thread which then deallocates the memory. Alternatively, nosync would ensure such communication cannot happen and even captured pointers cannot be freed by the function.

A nofree function is explicitly allowed to free memory which it allocated or (if not nosync) arrange for another thread to free memory on it’s behalf. As a result, perhaps surprisingly, a nofree function can return a pointer to a previously deallocated memory object.