Skip to content

feat: Reactant compatibility - #135

Draft
gdalle wants to merge 3 commits into
mainfrom
gd/reac
Draft

feat: Reactant compatibility#135
gdalle wants to merge 3 commits into
mainfrom
gd/reac

Conversation

@gdalle

@gdalle gdalle commented Aug 15, 2026

Copy link
Copy Markdown
Member

Experiment made during JuliaCon 2026 hackathon

Right now, Reactant is slower than it should be because we keep XLA from donating any buffers. Open a Reactant issue with the MWE

@simeonschaub simeonschaub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cool! This is not as bad as I feared it would be. We will of course have to figure out how to properly support sparse matrices

(; termination_reltol, time_limit, max_kkt_passes) = params
if batched_all(<=(termination_reltol), relative!!(dest, err))
return OPTIMAL
st = if batched_all(<=(termination_reltol), relative!!(dest, err))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unrelated? I personally don't like var = if ... that much, but maybe that's just me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, unrelated. But when I tried to trace the whole loop instead of just the step!, I had issues with if/else statements like this one which return a non-traceable struct

Comment thread src/problems/milp.jl
Return the number of integer variables in `milp`.
"""
nbvar_int(milp::MILP) = sum(milp.int_var)
nbvar_int(milp::MILP) = sum(identity, milp.int_var)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why? Is this a Reactant bug?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this errors inside Reactant because the integers are traced and so they have no concrete value. It's only used inside printing routines though so not essential

algo = PDHG(
Float32,
Int32,
Matrix;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, you're using a dense matrix! I have been taking a bit with the Reactant people how we could maybe have some basic sparse support. There is https://mlir.llvm.org/docs/Dialects/SparseTensorOps/, but we would need to lower it into cuSPARSE calls ourselves

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Put up EnzymeAD/Reactant.jl#3198, which should enable spmv and spmm support in Reactant

@gdalle

gdalle commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

Apparently we can avoid the worse compilation with donated_args by removing the pointer swap, see #136

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