Repository navigation
Start on batched SVD support #567
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: main
Are you sure you want to change the base?
Changes from all commits
c1a82e6
54ad087
124b293
44db5c2
8c60919
df50087
9199a1f
58c17cd
4e008be
1cd5673
ce2a4e6
8e762ea
5f0075c
2d61b0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,7 @@ end | |
| # ----------------------- | ||
| for f! in ( | ||
| :qr_compact!, :qr_full!, :lq_compact!, :lq_full!, | ||
| :eig_full!, :eigh_full!, :svd_compact!, :svd_full!, | ||
| :left_polar!, :right_polar!, | ||
| :eig_full!, :eigh_full!, :left_polar!, :right_polar!, | ||
| ) | ||
| @eval function MAK.$f!(t::AbstractTensorMap, F, alg::AbstractAlgorithm) | ||
| $(f! in (:eig_full!, :eigh_full!) && :(LinearAlgebra.checksquare(t))) | ||
|
|
@@ -56,10 +55,38 @@ for f! in ( | |
| end | ||
| end | ||
|
|
||
| # these have batched versions, use them if the driver supports it | ||
| # which blocks are worth batching, and how to pack them, is decided by MatrixAlgebraKit | ||
| for (f!, bf!) in ((:svd_compact!, :batched_svd_compact!), (:svd_full!, :batched_svd_full!)) | ||
| @eval function MAK.$f!(t::AbstractTensorMap, F, alg::AbstractAlgorithm) | ||
| @timeit_debug GLOBAL_TIMER $(string(f!)) begin | ||
| U, S, Vᴴ = F | ||
| driver = get(alg.kwargs, :driver, MAK.DefaultDriver()) | ||
| cs = collect(union(blocksectors.((t, U, S, Vᴴ))...)) | ||
| if !isempty(cs) && MAK.supports_ragged_batch(MAK.$f!, alg, driver, storagetype(t)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just now noticed that we are passing both
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah no worries, I think we did this to be consistent between all the |
||
| As = [block(t, c) for c in cs] | ||
| Fs = ([block(U, c) for c in cs], [block(S, c) for c in cs], [block(Vᴴ, c) for c in cs]) | ||
| @timeit_debug GLOBAL_TIMER "batched: MatrixAlgebraKit" MAK.$bf!(As, Fs, alg) | ||
| return F | ||
| end | ||
| foreachblock(t, U, S, Vᴴ) do _, (tblock, Fblocks...) | ||
| @timeit_debug GLOBAL_TIMER "dense: MatrixAlgebraKit" begin | ||
| Fblocks′ = $f!(tblock, Fblocks, alg) | ||
| # deal with the case where the output is not in-place | ||
| for (b′, b) in zip(Fblocks′, Fblocks) | ||
| b === b′ || copy!(b, b′) | ||
| end | ||
| end | ||
| return nothing | ||
| end | ||
| return F | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Handle these separately because single output instead of tuple | ||
| for f! in ( | ||
| :qr_null!, :lq_null!, | ||
| :svd_vals!, :eig_vals!, :eigh_vals!, | ||
| :qr_null!, :lq_null!, :eig_vals!, :eigh_vals!, | ||
| :project_hermitian!, :project_antihermitian!, :project_isometric!, | ||
| :exponential!, | ||
| ) | ||
|
|
@@ -79,6 +106,30 @@ for f! in ( | |
| end | ||
| end | ||
|
|
||
| # Handle these separately because single output instead of tuple AND batching is supported | ||
| for (f!, bf!) in ((:svd_vals!, :batched_svd_vals!),) | ||
| @eval function MAK.$f!(t::AbstractTensorMap, S, alg::AbstractAlgorithm) | ||
| @timeit_debug GLOBAL_TIMER $(string(f!)) begin | ||
| driver = get(alg.kwargs, :driver, MAK.DefaultDriver()) | ||
| cs = blocksectors(t) | ||
| if !isempty(cs) && MAK.supports_ragged_batch(MAK.$f!, alg, driver, storagetype(t)) | ||
| As, Ss = last.(blocks(t)), last.(blocks(S)) | ||
| @timeit_debug GLOBAL_TIMER "batched: MatrixAlgebraKit" MAK.$bf!(As, Ss, alg) | ||
| return S | ||
| end | ||
| foreachblock(t, S) do _, (tblock, Sblock) | ||
| @timeit_debug GLOBAL_TIMER "dense: MatrixAlgebraKit" begin | ||
| Sblock′ = $f!(tblock, Sblock, alg) | ||
| # deal with the case where the output is not the same as the input | ||
| Sblock === Sblock′ || copy!(Sblock, Sblock′) | ||
| end | ||
| return nothing | ||
| end | ||
| end | ||
| return S | ||
| end | ||
| end | ||
|
|
||
| # Exponential with Tuple | ||
| function MAK.exponential!((τ, t)::Tuple{E, T}, N, alg::AbstractAlgorithm) where {E <: Number, T <: AbstractTensorMap} | ||
| LinearAlgebra.checksquare(t) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.