diff --git a/lib/MadNLPGPU/Project.toml b/lib/MadNLPGPU/Project.toml index 9d99df38..212febaa 100644 --- a/lib/MadNLPGPU/Project.toml +++ b/lib/MadNLPGPU/Project.toml @@ -10,7 +10,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6" [compat] -CUDA = "~4" +CUDA = "4, 5" CUSOLVERRF = "0.2" KernelAbstractions = "0.9" MadNLP = "0.7" diff --git a/lib/MadNLPGPU/test/densekkt_gpu.jl b/lib/MadNLPGPU/test/densekkt_gpu.jl index 9c806360..7ea3ff55 100644 --- a/lib/MadNLPGPU/test/densekkt_gpu.jl +++ b/lib/MadNLPGPU/test/densekkt_gpu.jl @@ -3,7 +3,6 @@ using CUDA using MadNLPTests function _compare_gpu_with_cpu(KKTSystem, n, m, ind_fixed) - for (T,tol,atol) in [ (Float32,1e-3,1e-1), (Float64,1e-8,1e-6) @@ -16,13 +15,9 @@ function _compare_gpu_with_cpu(KKTSystem, n, m, ind_fixed) :tol=>tol ) + # Host evaluator nlph = MadNLPTests.DenseDummyQP(zeros(T,n); m=m, fixed_variables=ind_fixed) - - # Some weird issue: there's some non-deterministic behavior in generating the model for the first call - # Not sure where this error is originating, but seems to be resolved in v1.10 - # Here, we call this twice to avoid this error - nlpd = MadNLPTests.DenseDummyQP(CUDA.zeros(T,n); m=m, fixed_variables=CuArray(ind_fixed)) - + # Device evaluator nlpd = MadNLPTests.DenseDummyQP(CUDA.zeros(T,n); m=m, fixed_variables=CuArray(ind_fixed)) # Solve on CPU diff --git a/lib/MadNLPTests/src/Instances/dummy_qp.jl b/lib/MadNLPTests/src/Instances/dummy_qp.jl index 0c3db1cb..27894d70 100644 --- a/lib/MadNLPTests/src/Instances/dummy_qp.jl +++ b/lib/MadNLPTests/src/Instances/dummy_qp.jl @@ -25,7 +25,7 @@ function NLPModels.hess_structure!(qp::DenseDummyQP, I::AbstractVector{T}, J::Ab copyto!(J, qp.hcols) end -function NLPModels.obj(qp::DenseDummyQP, x::AbstractVector) +function NLPModels.obj(qp::DenseDummyQP{T}, x::AbstractVector{T}) where T mul!(qp.buffer, qp.P, x) return 0.5 * dot(x, qp.buffer) + dot(qp.q, x) end @@ -84,9 +84,15 @@ function DenseDummyQP( end Random.seed!(1) + # Generate random values. + # N.B.: we need to allocate the matrix P_ right after the vector + # q_ if we want to obtain a deterministic behavior: the seed is not working + # if we call the function `randn` after allocating vectors on the device. + q_ = randn(n) + P_ = randn(n, n) y0 = fill!(similar(x0, m), zero(T)) - q = copyto!(similar(x0, n), randn(n)) + q = copyto!(similar(x0, n), q_) buffer = similar(x0, n) # Bound constraints @@ -100,7 +106,7 @@ function DenseDummyQP( xl[fixed_variables] .= @view(xu[fixed_variables]) # Build QP problem 0.5 * x' * P * x + q' * x - P = copyto!(similar(x0, n , n), randn(n,n)) + P = copyto!(similar(x0, n , n), P_) P = P*P' # P is symmetric P += T(100.0) * I @@ -109,10 +115,6 @@ function DenseDummyQP( A = fill!(similar(x0, m, n), zero(T)) A[1:m+1:m^2] .= one(T) A[m+1:m+1:m^2+m] .=-one(T) - # for j in 1:m - # A[j, j] = one(T) - # A[j, j+1] = -one(T) - # end nnzh = div(n * (n + 1), 2) hrows = copyto!(similar(x0, Int, nnzh), [i for i in 1:n for j in 1:i])