Skip to content

Refactor MPIPtr cconvert to support Julia 1.14 - #941

Open
nhz2 wants to merge 16 commits into
JuliaParallel:masterfrom
nhz2:nz/cconvert-refactor
Open

Refactor MPIPtr cconvert to support Julia 1.14#941
nhz2 wants to merge 16 commits into
JuliaParallel:masterfrom
nhz2:nz/cconvert-refactor

Conversation

@nhz2

@nhz2 nhz2 commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Alternative to #935

CC @eschnett @giordano @vchuravy

@nhz2
nhz2 marked this pull request as ready for review March 28, 2026 20:00
@eschnett

Copy link
Copy Markdown
Contributor

One of the main features of ccall and its automatic conversion to pointers is that it's GC safe, i.e. that it holds on to the respective Julia objects while a pointer to the object is in use. I didn't follow the logic that you're introducing, but since this kind of error (losing a GC root) is very difficult to diagnose, I want to recommend to add respective comments to the code, stating which part of the machinery is holding on to objects, which functions are called before objects are converted to pointers, and which are called on pointers.

@nhz2

nhz2 commented Mar 29, 2026

Copy link
Copy Markdown
Contributor Author

I've added some comments using Claude Code

@eschnett

Copy link
Copy Markdown
Contributor

Thanks! The description sounds correct, and I like the ASCII art.

@nhz2

nhz2 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Bump

@KristofferC

Copy link
Copy Markdown
Contributor

Bump, would be nice to have this fixed (+ new release if possible).

@giordano

Copy link
Copy Markdown
Member

I believe we'd need some help with the review, none of us is particularly familiar with what's the intended way to go about it. I definitely prefer this kind of approach over #935 because that felt too ad hoc, but the need for CConvWrapper here is also odd.

@lcw

lcw commented Aug 28, 2026

Copy link
Copy Markdown
Member

We need to support OpenAPI as well.

@nhz2

nhz2 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

We need to support OpenAPI as well.

What do you mean by this?

@lcw

lcw commented Aug 28, 2026

Copy link
Copy Markdown
Member

We need to support OpenAPI as well.

What do you mean by this?

I think we might need to change these lines as well

MPI.jl/ext/OneAPIExt.jl

Lines 7 to 21 in 61cc82e

function Base.cconvert(::Type{MPIPtr}, A::oneAPI.oneArray{T}) where T
A
end
function Base.unsafe_convert(::Type{MPIPtr}, X::oneAPI.oneArray{T}) where T
reinterpret(MPIPtr, Base.unsafe_convert(oneAPI.ZePtr{T}, X))
end
# only need to define this for strided arrays: all others can be handled by generic machinery
function Base.unsafe_convert(::Type{MPIPtr}, V::SubArray{T,N,P,I,true}) where {T,N,P<:oneAPI.oneArray,I}
X = parent(V)
pX = Base.unsafe_convert(oneAPI.ZePtr{T}, X)
pV = pX + ((V.offset1 + V.stride1) - first(LinearIndices(X)))*sizeof(T)
return reinterpret(MPIPtr, pV)
end

@nhz2
nhz2 marked this pull request as draft September 1, 2026 00:22
@nhz2
nhz2 marked this pull request as ready for review September 1, 2026 03:46
@nhz2

nhz2 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

I've updated OneAPIExt.jl and added an intermediate pointer type trait function mpi_ptr_type.

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.

5 participants