forked from SciML/SimpleNonlinearSolve.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuda_tests.jl
More file actions
73 lines (62 loc) · 2.54 KB
/
cuda_tests.jl
File metadata and controls
73 lines (62 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@testitem "Solving on GPUs" tags=[:cuda] skip=:(using CUDA; !CUDA.functional()) begin
using StaticArrays, CUDA
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
@testitem "CUDA Kernel Launch Test" tags=[:cuda] skip=:(using CUDA; !CUDA.functional()) timeout=3600 begin
using StaticArrays, CUDA
CUDA.allowscalar(false)
f(u, p) = u .* u .- 2
f!(du, u, p) = du .= u .* u .- 2
function kernel_function(prob, alg)
solve(prob, alg)
return nothing
end
prob = NonlinearProblem{false}(f, @SVector[1.0f0, 1.0f0])
prob = convert(SimpleNonlinearSolve.ImmutableNonlinearProblem, prob)
@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)
end
end