Skip to content

Conversation

@klamike
Copy link
Owner

@klamike klamike commented Dec 26, 2025

@frapac @amontoison What do you think? It saves a bunch of time since we avoid the KKT mul and norm calls. Note this is merging into MadNLP#81

Maybe we can replace it with a cheaper check (like just finite/non-nan solution?) instead.

For reference,

function check_residual!(d::MadNLP.UnreducedKKTVector{T}, solver, p) where T
    opt = solver.opt

    # Check residual
    w = solver._w1
    copyto!(MadNLP.full(w), MadNLP.full(p))
    mul!(w, solver.kkt, d, -one(T), one(T))
    norm_w = norm(MadNLP.full(w), Inf)
    norm_p = norm(MadNLP.full(p), Inf)

    residual_ratio = norm_w / max(one(T), norm_p)
    MadNLP.@debug(
        solver.logger,
        @sprintf("Residual after linear solve: %6.2e", residual_ratio),
    )
    if isnan(residual_ratio) || (opt.check_residual && (residual_ratio > opt.tol_linear_solve))
        throw(MadNLP.SolveException)
    end
    return d
end

@amontoison
Copy link

amontoison commented Dec 29, 2025

@klamike I think we have batch spmv and spmm in CUSPARSE. I interfaced it or reviewed it but it is not documented.
For the norm calls, we can have asynchronous ones, NVIDIA added it in CUDA 12.x.
The current issue is that all operations are blocking so we multiply the elapsed time by the number of batch.

I can work on an operator for batch mul!, I understand quite well the internal of CUSPARSE routines.

References:

PS: I should have used CuSparseArrayCSR in CUDSS...
I didn't remember that we added this type.

@klamike
Copy link
Owner Author

klamike commented Dec 29, 2025

Let's close this then, and keep the check_residual! open on the tracker.

@klamike klamike closed this Dec 29, 2025
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