Skip to content

support OpenCL backend#55

Merged
gdalle merged 10 commits into
JuliaDecisionFocusedLearning:mainfrom
simeonschaub:sds/aliasing
Jun 8, 2026
Merged

support OpenCL backend#55
gdalle merged 10 commits into
JuliaDecisionFocusedLearning:mainfrom
simeonschaub:sds/aliasing

Conversation

@simeonschaub

@simeonschaub simeonschaub commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Copying memory to itself causes problems when running with the OpenCL backend where aliased memcopies throw an error. According to the docstring of copy!:

Behavior can be unexpected when any mutated argument shares memory with any other argument.

so this should probably be avoided.

(This doesn't fully fix CoolPDLP.jl on OpenCL.jl, since
adapt(OpenCLBackend(), arr) is not type stable, so the @stable
annotation would need to be removed for perform_conversion)
Implemented

@gdalle

gdalle commented Jun 3, 2026

Copy link
Copy Markdown
Member

Thanks!

  • Can we add tests on the OpenCL backend?
  • How come we even have a self-copy in the first place?

@simeonschaub

simeonschaub commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

Can we add tests on the OpenCL backend?

Sure, I can add some tests using PoCL. Are you fine with removing the @stable requirement for perform_conversion?

How come we even have a self-copy in the first place?

Just above, the logic is:

if restart_stats.restart_from_avg
    sol_cand = sol_avg
else
    sol_cand = sol
end

so iff !restart_stats.restart_from_avg, we get the self-copy

Comment thread src/CoolPDLP.jl Outdated
Comment thread src/components/conversion.jl Outdated
Comment thread test/runtests.jl
@simeonschaub

Copy link
Copy Markdown
Collaborator Author

I had to disable @stable altogether for now. Initially I was just going to mark the relevant methods as @unstable but since that doesn't recursively apply to other functions calling those methods this didn't work. Happy for other suggestions though, I have personally had good experiences with using JET to test the type stability of the main method instances you care about, but it's more manual

@gdalle

gdalle commented Jun 3, 2026

Copy link
Copy Markdown
Member

Perhaps we could just temporarily slap an @unstable on every function that ends up calling the problematic conversion you spotted? There shouldn't be many

@simeonschaub simeonschaub changed the title don't copy! array to itself support OpenCL backend Jun 4, 2026
@simeonschaub

Copy link
Copy Markdown
Collaborator Author

OK, I now added the @unstable annotation only where necessary

@simeonschaub simeonschaub requested a review from gdalle June 4, 2026 08:38
@gdalle

gdalle commented Jun 4, 2026

Copy link
Copy Markdown
Member

The buildkite failure is a red herring (any idea why it happens?).
I'll review today :)

@simeonschaub

Copy link
Copy Markdown
Collaborator Author

Hangs should hopefully be fixed by JuliaGPU/GPUCompiler.jl#830

@simeonschaub simeonschaub force-pushed the sds/aliasing branch 3 times, most recently from 86a1b1d to 257764b Compare June 5, 2026 09:20
@simeonschaub simeonschaub reopened this Jun 8, 2026
@gdalle

gdalle commented Jun 8, 2026

Copy link
Copy Markdown
Member

You can merge from main now

simeonschaub and others added 8 commits June 8, 2026 10:54
This causes problems when running with the OpenCL backend where aliased
memcopies throw an error. According to the docstring of `copy!`:

> Behavior can be unexpected when any mutated argument shares memory with any other argument.

so this should probably be avoided.

(This doesn't fully fix CoolPDLP.jl on OpenCL.jl, since
`adapt(OpenCLBackend(), arr)` is not type stable, so the `@stable`
annotation would need to be removed for `perform_conversion`)

@gdalle gdalle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I gave it some further thought and I don't think it's worth making so many functions @unstable just to accommodate one (rather seldom used) backend. A better option would be to deactivate DispatchDoctor for the OpenCL tests specifically, using e.g. https://github.com/MilesCranmer/DispatchDoctor.jl#-options. What do you think?

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/algorithms/pdlp.jl 100.00% <100.00%> (+8.23%) ⬆️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@simeonschaub

Copy link
Copy Markdown
Collaborator Author

A better option would be to deactivate DispatchDoctor for the OpenCL tests specifically, using e.g. https://github.com/MilesCranmer/DispatchDoctor.jl#-options. What do you think?

I must admit that I am not a big fan of the DispatchDoctor approach in general, since you are trying to make type stability guarantees for generic methods that then end up calling arbitrary code you have no control over and which might have good reasons to not be type stable in all instances. As I said above, I tend to prefer testing method on the exact type signatures that you want to be type stable with JET, which is more manual, but it doesn't break the flexibility multiple dispatch and a dynamic type system gives you in the same way DispatchDoctor does.

That said, this is not my package and this is just my personal opinion, so I am fine going with your proposal for now of disabling DispatchDoctor for the OpenCL tests specifically

@gdalle

gdalle commented Jun 8, 2026

Copy link
Copy Markdown
Member

DispatchDoctor is much easier for developers than JET, which frequently breaks or is overly sensitive and requires manual testing for each function. Let's keep it that way for the time being. Note that, like our OpenCL test suite, downstream users can also disable DispatchDoctor specifically for CoolPDLP if they have purposefully type-unstable routines.

@simeonschaub

Copy link
Copy Markdown
Collaborator Author

OK, I have implemented those changes, does this look good to you?

@gdalle gdalle merged commit 8b3b79d into JuliaDecisionFocusedLearning:main Jun 8, 2026
11 checks passed
@simeonschaub simeonschaub deleted the sds/aliasing branch June 8, 2026 12:08
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.

2 participants