-
Notifications
You must be signed in to change notification settings - Fork 26
Stop pirating eigen and svd functions from LinearAlgebra #147
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
base: master
Are you sure you want to change the base?
Conversation
40223e0
to
752344d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #147 +/- ##
==========================================
- Coverage 91.94% 91.83% -0.11%
==========================================
Files 10 9 -1
Lines 1577 1556 -21
==========================================
- Hits 1450 1429 -21
Misses 127 127 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6ccaab3
to
98ca476
Compare
Please don't do this. My package Ket relies heavily on If your concern is avoiding type piracy, why don't you contribute instead the generic code to |
I don't think it will be a nightmare. Packages that indent to work for a broad range of element type should just call
There are two main reasons why I have prepared this PR.
I don't have an issue with contributing code to LinearAlgebra.jl. I've contributed quite a bit, actually. However, a while back when I started working on generic implementations of the linear algebra functions, we decided to limit the scope of the generic implementations in LinearAlgebra.jl to the linear solvers and delegate the spectral solvers to external modules (mostly but not only this package). Now that LinearAlgebra.jl has moved completely out of the main Julia repo, maybe the decision could be revisited. However, I think it might be nicer to opt in to the generic implementations here in the more transparent way of this PR. As mentioned in the beginning, I don't think it should be too hard to just qualify the calls to |
98ca476
to
dfe2457
Compare
I just published a paper where I needed both generic types and maximal performance for BLAS floats. The point is that when I'm using BLAS floats I want to be faster than any other implementation, and I also need the capability of solving the problem with higher precision. There it's fine to be slower, because there's pretty much nobody who can do it. The situation is similar with the conic solvers I mentioned. The papers that introduce them both benchmark their performance against other solvers, and I don't think they would accept losing performance on BLAS floats for no reason. The solution then wouldn't be to call Sure, Do you mind if I ask people on Slack for their opinion? |
6620fb4
to
602d518
Compare
I just browsed the paper but it wasn't clear to me
Would it be easy for you to make a run based on this PR? It would be an interesting data point.
I don't. It is fine if more people chime in. I can't promise that it will change the end result but I'm open for inputs. |
602d518
to
5ea8fd0
Compare
I'm sorry, I'm not going to benchmark it again, it is a pain in the ass. Furthermore, I don't think there's a point, I don't think generic code can ever be competitive with LAPACK optimized for specific architectures. |
5ea8fd0
to
e74623b
Compare
Instead, define separate unexported functions in the GenericLinearAlgebra module. Hence, users would have to explicitly opt in to using GenericLinearAlgebra. A consequence is that the implementations in this module will be used even for the element types support by LAPACK. Also, delete unused functionality.
e74623b
to
e037d77
Compare
How large, roughly, are the matrices passed to
LAPACK isn't optimized for architectures beyond some blocking sizes that are rarely tuned. It is actually a central point of LAPACK that it doesn't have to be tuned for architectures. The architecture optimizations are delegated to BLAS(3). As mentioned, the implementations here are comparable to the ones from LAPACK wrt performance, e.g. QL algorithm from
|
The size of the matrices vary a lot according to the protocol, but 100 x 100 is a good one to benchmark. I got very different results in my machine, though: julia> @btime GenericLinearAlgebra.eigen!(S) setup = (S = LinearAlgebra.SymTridiagonal(ones(100), 0.2*ones(99)));
444.443 μs (14 allocations: 159.20 KiB)
julia> @btime GenericLinearAlgebra.LAPACK2.steqr!('V', S.dv, S.ev, Matrix(1.0*I, size(S)...)) setup = (S = LinearAlgebra.SymTridiagonal(ones(100), 0.2*ones(99)));
792.057 μs (7 allocations: 79.90 KiB)
julia> @btime LinearAlgebra.eigen!(S) setup = (S = LinearAlgebra.SymTridiagonal(ones(100), 0.2*ones(99)));
328.312 μs (34 allocations: 104.09 KiB) In any case, what matters to me is the complex Hermitian case: julia> @btime GenericLinearAlgebra.eigen!(S) setup = (S = LinearAlgebra.Hermitian(randn(ComplexF64, 100, 100)));
2.423 ms (28 allocations: 323.31 KiB)
julia> @btime LinearAlgebra.eigen!(S) setup = (S = LinearAlgebra.Hermitian(randn(ComplexF64, 100, 100)));
1.359 ms (23 allocations: 394.52 KiB) (I did install the |
When preparing the previous comment, I noticed too annoying sources of overhead which are fixed in #150 and #151. It would be great if you could rerun the timings with the latest master and let me know if your results are more in line with the ones I shared.
I just profiled this one and the majority of the time is spent in
GenericLinearAlgebra.jl/src/eigenSelfAdjoint.jl Lines 521 to 574 in 9e5cb8b
|
With the latest master: julia> @btime GenericLinearAlgebra._eigen!(S) setup = (S = LinearAlgebra.SymTridiagonal(ones(100), 0.2*ones(99)));
328.754 μs (7 allocations: 80.02 KiB)
julia> @btime LinearAlgebra.eigen!(S) setup = (S = LinearAlgebra.SymTridiagonal(ones(100), 0.2*ones(99)));
329.976 μs (34 allocations: 104.09 KiB) Clearly we're not running the same code, since even the number of allocations is different.
That would be great. If the performance is similar I'd much rather use your code, I'll be a happier man the day I don't need to deal with |
Instead, define separate unexported functions in the GenericLinearAlgebra
module. Hence, users would have to explicitly opt in to using
GenericLinearAlgebra. A consequence is that the implementations
in this module will be used even for the element types support by
LAPACK.
Also, delete unused functionality.
Finally, also run the formatter.