Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for CUDA.jl v5 #283

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/MadNLPGPU/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 2 additions & 7 deletions lib/MadNLPGPU/test/densekkt_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 9 additions & 7 deletions lib/MadNLPTests/src/Instances/dummy_qp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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])
Expand Down
Loading