-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Feature request: Symmetric operation for unsafe_wrap(A, p, dims, own=true)
#41965
Comments
I don't think it is the ownership that a C library would like to take. Instead, the C libraries usually expect a bubble of heap memory in the C world (e.g. allocated by In most cases, C libraries will expose a "free" API for releasing the resources created by themselves. But there are cases where one needs to dive into the C code to figure out the lifetime of certain resources. For example, say, there is a structure called As we know the structure of |
I should say rather than "some" libraries, I know of at least one. SuiteSparse:GraphBLAS for which I would like to do this rather than copying data from Julia. On initialization I pass SuiteSparse:GraphBLAS Concretely I want to take a SparseMatrixCSC, import the underlying 3 vectors to SuiteSparse:GraphBLAS, do some computations and then export the (potentially different, modified using the This can technically be done without any copying (if this were C for instance). Unfortunately right now I have to copy. I do this by The memory is sort of still owned by Julia's garbage collector (indeed any matrices created within SuiteSparse:GraphBLAS will be visible to GC since it will use E: This should probably be a second issue but memory created by |
What's the expected behavior when this Julia vector(dropped the ownership) is keeping being used on the Julia side but the C library would like to |
The GraphBLAS function states that you shouldn't do this, it sets the pointer you give it to NULL, in the hopes you will not access the memory again until explicitly given back.
If I did something like
My hope would be that |
Do you mean the C library will set the Somehow this operation should work like an "atomic" operation, no memory access is allowed until it is finished. |
No, I haven't (yet) integrated that deeply. This is the ccall: This function will set I'd prefer to do this all within Julia. I could create a shim in C, that calls Julia C code and GraphBLAS, which solves pretty much all these problems I think, but I'd like to avoid that. |
I don't believe this operation exists (in previous discussions about implementing a feature it wasn't mentioned) but I'm hoping it can be added:
Some C libraries would like to take ownership of arrays from Julia. In particular SuiteSparse:GraphBLAS would benefit immensely from this operation. The opposite function already exists:
unsafe_wrap(Array, pointer::Ptr{T}, dims; own = true)
What I'd like to request is
unwrap!(Array)
which would give me a pointer to the underlying storage, but importantly relinquish ownership. This would probably only work in cases where the C library which receives ownership is using the Julia memory functions like:jl_free
.It's understandably niche (and possibly unworkable), but would make Julia's interop with at least one C library faster and less memory intensive by avoiding copies.
The text was updated successfully, but these errors were encountered: