Open emmyb-bu opened 11 months ago
Does https://github.com/JuliaLinearAlgebra/RectangularFullPacked.jl implement what you want?
I believe @bjarthur was working on vector-based packed format linear algebra; I found https://github.com/JaneliaSciComp/SymmetricFormats.jl. I remember that we do have some LAPACK functions available in LinearAlgebra
(#34211, #34320), but we don't have wrapper types.
i was indeed, and yes you found it! please file an issue there if you have problems or suggestions
This is nice. Thank you so much for sharing. I initially became interested in this because I am memory-limited on a GPU for a project, so ideally this would work on the GPU with CUDA.jl. I also would enjoy seeing this implemented in the default LinearAlgebra with appropriate method and in a packed format with pretty-printing, but I understand that this might not happen.
Thanks again!
When working with symmetric, upper-triangular, and lower-triangular matrices in LinearAlgebra, it is necessary to allocate $N^2$ numbers, but there are only at most $N(N+1)/2$ distinct entries. This is in contrast to common Fortran linear algebra packages.
Consider the following code:
For reference,
x
looks like:One can see that
UpperTriangular
andSymmetric
are just wrapping the memory allocated inx
which means that if you don't actually care about the lower-triangular part ofx
, you're unnecessarily storing $N(N-1)/2 = O(N^2/2)$ zeroes! The purpose of these wrappers is so that when some routine from LinearAlgebra is called, the appropriate method optimized for the matrix type is called. In BLAS, LAPACK, and CuBLAS, there are equivalent routines which support a "packed" format which essentially stores the non-zero/necessary entries as a vector in column-major-like form. In this packed format,xut.data
would be stored as[1.0, 2.0, 3.0, ..., 15.0]
. Here are some links to the documentation where some of these functions and features are discussed:I think exposing these routines in LinearAlgebra and CUDA.jl would be useful and improve memory efficiency by a factor of two, approximately. I imagine there might be some new types, like
LowerTriangularPacked
,UpperTriangularPacked
,SymmetricPacked
, whosedata
fields would be the packed format used in these linear algebra routines. Some implementations that might be nice besides the access to the BLAS, LAPACK, and CuBlas routines could be:Matrix
-typed variable likex
and converts it to a packed-type variable by extracting and flattening the appropriate entriesVector
-typed variable in a packed formatxut[i,j]
and access the appropriate linear index in the packed formatI would greatly appreciate it if this were implemented, and I believe it would improve Julia as a whole. Thanks!