Fix SimpleNonlinearSolve GPU compat without unnecessary @generated#854
Fix SimpleNonlinearSolve GPU compat without unnecessary @generated#854ChrisRackauckas-Claude wants to merge 12 commits intoSciML:masterfrom
Conversation
Removed 'src' from the coverage directories in the pipeline configuration.
SciMLBase.isinplace extracts a type parameter and returns a compile-time constant (true/false). The compiler constant-folds it, so @generated functions are unnecessary for eliminating dead branches. Regular functions with if SciMLBase.isinplace(prob) infer identically. Reverted: incompatible_backend_and_problem, evaluate_f!!, evaluate_f, should_cache_fx, and prepare_jacobian back to regular functions. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Still doesn't work for me locally: using SimpleNonlinearSolve, StaticArrays, CUDA
f(u, p) = u .* u .- p
function kernel_function(prob, alg)
solve(prob, alg)
return nothing
end
nu0 = @SVector[1.0f0, 1.0f0]
sllprob = convert(SimpleNonlinearSolve.ImmutableNonlinearProblem, NonlinearProblem{false}(f, nu0, 2.0f0))
alg = SimpleBroyden(; linesearch = Val(true))
solve(sllprob, SimpleNewtonRaphson(; autodiff = AutoForwardDiff()))
solve(sllprob, alg)
@cuda kernel_function(sllprob, SimpleNewtonRaphson(; autodiff = AutoForwardDiff()))
@cuda kernel_function(sllprob, SimpleDFSane())
@cuda kernel_function(sllprob, SimpleHalley(; autodiff = AutoForwardDiff()))
@cuda kernel_function(sllprob, SimpleLimitedMemoryBroyden(; linesearch = Val(true))) |
|
Hi @ChrisRackauckas with (SciML/SciMLBase.jl#1270) going in this PR should be functional, I tested the above Utkarsh's example and it worked for me without errors but excluded SimpleHalley as it has some other compatibility issues. |
|
First order test failure looks real? |
|
Only one |
|
Seems like a known bug, it has been flagged here (https://github.com/SciML/NonlinearSolve.jl/blob/master/lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl#L412) and it was the common failure on all the first order failures so we can ignore them? |
|
If it was that then the tests would be passing right? |
|
I missed that it was set to broken_test, this is working(I dont exaclty know the reason maybe some upstream fix) and we can set is to test. It passes for me locally |
|
To be more clear this test https://github.com/SciML/NonlinearSolve.jl/blob/master/lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl#L410-L427 was set as a broken test because of a bug, so it threw exception which was flagged as broken and it passed but now it is actually returning a value because of a fix maybe upstream. This correct value is not expected and broken_test is giving error, we should just make it a proper test |
|
Should I raise a different PR? or can we push that here? |
Summary
@generatedfunctionsSciMLBase.isinplaceextracts a type parameter and returns a compile-time constant — the compiler constant-folds it, so@generatedis not needed to eliminate dead branchesNonlinearAliasSpecifierstandardization,get_alias_u0/should_cache_fxhelpers,SimpleHalleyGPU exclusion, Buildkite pipeline updatesSpecifically reverted these back to regular functions:
incompatible_backend_and_problem(was@generated, now regular function — net zero diff vs master)evaluate_f!!(was@generated, now regular function withSciMLBase.isinplace(f))evaluate_f(was@generated, now regular function withSciMLBase.isinplace(prob))should_cache_fx(was@generated, now@inlinefunction)prepare_jacobian(was@generated, now regular function)The
@assertincompute_jacobian!!remains commented out sincethrowis genuinely GPU-incompatible.Addresses @oscardssmith's concern on #809 about compile time impact of
@generatedfunctions.Supersedes #809.
Test plan
🤖 Generated with Claude Code