1+ module ModCompressedLBFGSOperator
12#=
23Compressed 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
1011using 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
1325export 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
5972end
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-
6574function 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
7887A implementation of a LBFGS operator (forward), representing a `nxn` linear application.
7988It 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
0 commit comments