1
+ module ModCompressedLBFGSOperator
1
2
#=
2
3
Compressed LBFGS implementation from:
3
4
REPRESENTATIONS OF QUASI-NEWTON MATRICES AND THEIR USE IN LIMITED MEMORY METHODS
@@ -8,9 +9,21 @@ Implemented by Paul Raynaud (supervised by Dominique Orban)
8
9
=#
9
10
10
11
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
12
24
13
25
export CompressedLBFGSOperator
26
+ export default_matrix_type, default_vector_type
14
27
15
28
"""
16
29
CompressedLBFGSOperator{T, M<:AbstractMatrix{T}, V<:AbstractVector{T}}
@@ -58,10 +71,6 @@ mutable struct CompressedLBFGSOperator{T, M<:AbstractMatrix{T}, V<:AbstractVecto
58
71
sol:: V # mem
59
72
end
60
73
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
-
65
74
function columnshift! (A:: AbstractMatrix{T} ; direction:: Int = - 1 , indicemax:: Int = size (A)[1 ]) where T
66
75
map (i-> view (A,:,i+ direction) .= view (A,:,i), 1 - direction: indicemax)
67
76
return A
78
87
A implementation of a LBFGS operator (forward), representing a `nxn` linear application.
79
88
It considers at most `k` BFGS iterates, and fit the architecture depending if it is launched on a CPU or a GPU.
80
89
"""
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))
82
91
α = (T)(1 )
83
92
k = 0
84
93
Sₖ = M (undef, n, mem)
@@ -203,4 +212,10 @@ function LinearAlgebra.mul!(Bv::V, op::CompressedLBFGSOperator{T,M,V}, v::V) whe
203
212
mul! (Bv, view (op. Sₖ, :, 1 : op. k), view (op. sol, op. k+ 1 : 2 * op. k), - op. α, (T)(- 1 ))
204
213
Bv .+ = op. α .* v
205
214
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