diff --git a/Project.toml b/Project.toml index 6d7ff2964..634629a0b 100644 --- a/Project.toml +++ b/Project.toml @@ -54,7 +54,7 @@ Dictionaries = "0.4" Enzyme = "0.13.216" EnzymeTestUtils = "0.2.8" FiniteDifferences = "0.12" -GPUArrays = "11.4.1" +GPUArrays = "11.4.1, 12.2" LinearAlgebra = "1" MatrixAlgebraKit = "0.6.14" MemoizationKit = "0.1.2" diff --git a/src/factorizations/matrixalgebrakit.jl b/src/factorizations/matrixalgebrakit.jl index ef6e022c2..7a2502dab 100644 --- a/src/factorizations/matrixalgebrakit.jl +++ b/src/factorizations/matrixalgebrakit.jl @@ -63,24 +63,26 @@ for (f!, bf!) in ((:svd_compact!, :batched_svd_compact!), (:svd_full!, :batched_ U, S, Vᴴ = F driver = get(alg.kwargs, :driver, MAK.DefaultDriver()) cs = collect(union(map(blocksectors, (t, U, S, Vᴴ))...)) + # no `return` inside `@timeit_debug`: it lowers to `try/finally`, and multiple + # returns through the `finally` make inference add a spurious `Nothing` if !isempty(cs) && MAK.supports_ragged_batch(MAK.$f!, alg, driver, storagetype(t)) 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′) + else + 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 nothing end - return F end + return F end end @@ -115,15 +117,15 @@ for (f!, bf!) in ((:svd_vals!, :batched_svd_vals!),) 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′) + else + 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 - return nothing end end return S