-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplenonlinearsolve in cuda kernels
- Loading branch information
Showing
12 changed files
with
219 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
@testitem "Solving on CUDA" tags=[:cuda] begin | ||
using StaticArrays, CUDA, SimpleNonlinearSolve | ||
|
||
if CUDA.functional() | ||
CUDA.allowscalar(false) | ||
|
||
f(u, p) = u .* u .- 2 | ||
f!(du, u, p) = (du .= u .* u .- 2) | ||
|
||
@testset "$(nameof(typeof(alg)))" for alg in ( | ||
SimpleNewtonRaphson(), | ||
SimpleDFSane(), | ||
SimpleTrustRegion(), | ||
SimpleTrustRegion(; nlsolve_update_rule = Val(true)), | ||
SimpleBroyden(), | ||
SimpleLimitedMemoryBroyden(), | ||
SimpleKlement(), | ||
SimpleHalley(), | ||
SimpleBroyden(; linesearch = Val(true)), | ||
SimpleLimitedMemoryBroyden(; linesearch = Val(true)) | ||
) | ||
# Static Arrays | ||
u0 = @SVector[1.0f0, 1.0f0] | ||
probN = NonlinearProblem{false}(f, u0) | ||
sol = solve(probN, alg; abstol = 1.0f-6) | ||
@test SciMLBase.successful_retcode(sol) | ||
@test maximum(abs, sol.resid) ≤ 1.0f-6 | ||
|
||
# Regular Arrays | ||
u0 = [1.0, 1.0] | ||
probN = NonlinearProblem{false}(f, u0) | ||
sol = solve(probN, alg; abstol = 1.0f-6) | ||
@test SciMLBase.successful_retcode(sol) | ||
@test maximum(abs, sol.resid) ≤ 1.0f-6 | ||
|
||
# Regular Arrays Inplace | ||
if !(alg isa SimpleHalley) | ||
u0 = [1.0, 1.0] | ||
probN = NonlinearProblem{true}(f!, u0) | ||
sol = solve(probN, alg; abstol = 1.0f-6) | ||
@test SciMLBase.successful_retcode(sol) | ||
@test maximum(abs, sol.resid) ≤ 1.0f-6 | ||
end | ||
end | ||
end | ||
end | ||
|
||
@testitem "CUDA Kernel Launch Test" tags=[:cuda] begin | ||
using StaticArrays, CUDA, SimpleNonlinearSolve | ||
using NonlinearSolveBase: ImmutableNonlinearProblem | ||
|
||
if CUDA.functional() | ||
CUDA.allowscalar(false) | ||
|
||
f(u, p) = u .* u .- p | ||
|
||
function kernel_function(prob, alg) | ||
solve(prob, alg) | ||
return nothing | ||
end | ||
|
||
@testset for u0 in (1.0f0, @SVector[1.0f0, 1.0f0]) | ||
prob = convert(ImmutableNonlinearProblem, NonlinearProblem{false}(f, u0, 2.0f0)) | ||
|
||
@testset "$(nameof(typeof(alg)))" for alg in ( | ||
SimpleNewtonRaphson(), | ||
SimpleDFSane(), | ||
SimpleTrustRegion(), | ||
SimpleTrustRegion(; nlsolve_update_rule = Val(true)), | ||
SimpleBroyden(), | ||
SimpleLimitedMemoryBroyden(), | ||
SimpleKlement(), | ||
SimpleHalley(), | ||
SimpleBroyden(; linesearch = Val(true)), | ||
SimpleLimitedMemoryBroyden(; linesearch = Val(true)) | ||
) | ||
@test begin | ||
try | ||
@cuda kernel_function(prob, alg) | ||
@info "Successfully launched kernel for $(alg)." | ||
true | ||
catch err | ||
@error "Kernel Launch failed for $(alg)." | ||
false | ||
end | ||
end broken=(alg isa SimpleHalley && u0 isa StaticArray) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.