Skip to content

Commit 5f48fc8

Browse files
author
RAYNAUD Paul (raynaudp)
committed
remove CUDA + add Requires
1 parent f0884c8 commit 5f48fc8

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ uuid = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
33
version = "2.5.1"
44

55
[deps]
6-
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
76
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
87
LDLFactorizations = "40e66cde-538c-5869-a4ad-c39174c6795b"
98
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
109
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
10+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1111
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1212
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
1313

1414
[compat]
15-
CUDA = "3.12.1"
1615
FastClosures = "0.2, 0.3"
1716
LDLFactorizations = "0.9, 0.10"
17+
Requires = "1.3"
1818
TimerOutputs = "^0.5"
1919
julia = "^1.6.0"
2020

src/compressed_lbfgs.jl

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
module ModCompressedLBFGSOperator
12
#=
23
Compressed LBFGS implementation from:
34
REPRESENTATIONS OF QUASI-NEWTON MATRICES AND THEIR USE IN LIMITED MEMORY METHODS
@@ -8,9 +9,21 @@ Implemented by Paul Raynaud (supervised by Dominique Orban)
89
=#
910

1011
using LinearAlgebra, LinearAlgebra.BLAS
11-
using CUDA
12+
using Requires
13+
14+
default_matrix_type(; T::DataType=Float64) = Matrix{T}
15+
default_vector_type(; T::DataType=Float64) = Vector{T}
16+
17+
@init begin
18+
@require CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" begin
19+
default_matrix_type(; T::DataType=Float64) = CUDA.CuMatrix{T}
20+
default_vector_type(; T::DataType=Float64) = CUDA.CuVector{T}
21+
end
22+
# this scheme may be extended to other GPU modules
23+
end
1224

1325
export CompressedLBFGSOperator
26+
export default_matrix_type, default_vector_type
1427

1528
"""
1629
CompressedLBFGSOperator{T, M<:AbstractMatrix{T}, V<:AbstractVector{T}}
@@ -58,10 +71,6 @@ mutable struct CompressedLBFGSOperator{T, M<:AbstractMatrix{T}, V<:AbstractVecto
5871
sol::V # mem
5972
end
6073

61-
default_gpu() = CUDA.functional() ? true : false
62-
default_matrix_type(gpu::Bool; T::DataType=Float64) = gpu ? CuMatrix{T} : Matrix{T}
63-
default_vector_type(gpu::Bool; T::DataType=Float64) = gpu ? CuVector{T} : Vector{T}
64-
6574
function columnshift!(A::AbstractMatrix{T}; direction::Int=-1, indicemax::Int=size(A)[1]) where T
6675
map(i-> view(A,:,i+direction) .= view(A,:,i), 1-direction:indicemax)
6776
return A
@@ -78,7 +87,7 @@ end
7887
A implementation of a LBFGS operator (forward), representing a `nxn` linear application.
7988
It considers at most `k` BFGS iterates, and fit the architecture depending if it is launched on a CPU or a GPU.
8089
"""
81-
function CompressedLBFGSOperator(n::Int; mem::Int=5, T=Float64, gpu=default_gpu(), M=default_matrix_type(gpu; T), V=default_vector_type(gpu; T))
90+
function CompressedLBFGSOperator(n::Int; mem::Int=5, T=Float64, M=default_matrix_type(; T), V=default_vector_type(; T))
8291
α = (T)(1)
8392
k = 0
8493
Sₖ = M(undef, n, mem)
@@ -203,4 +212,10 @@ function LinearAlgebra.mul!(Bv::V, op::CompressedLBFGSOperator{T,M,V}, v::V) whe
203212
mul!(Bv, view(op.Sₖ, :, 1:op.k), view(op.sol, op.k+1:2*op.k), - op.α, (T)(-1))
204213
Bv .+= op.α .* v
205214
return Bv
206-
end
215+
end
216+
217+
end
218+
219+
using ..ModCompressedLBFGSOperator
220+
export CompressedLBFGSOperator
221+
export default_matrix_type, default_vector_type

test/gpu/nvidia.jl

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ using LinearOperators, CUDA, CUDA.CUSPARSE, CUDA.CUSOLVER
1414
y = M * v
1515
@test y isa CuVector{Float32}
1616
end
17+
18+
include("../test_clbfgs.jl")

test/test_clbfgs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
n=100
44
n=5
55
lbfgs = CompressedLBFGSOperator(n) # m=5
6-
V = LinearOperators.default_vector_type(LinearOperators.default_gpu())
6+
V = LinearOperators.default_vector_type()
77
Bv = V(rand(n))
88
s = V(rand(n))
99
mul!(Bv, lbfgs, s) # warm-up

0 commit comments

Comments
 (0)