Skip to content

Commit

Permalink
Make lu results have same storage mode as input (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd authored Sep 30, 2024
1 parent 8652754 commit 3bbda32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/mps/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ LinearAlgebra.ipiv2perm(v::MtlVector{T}, maxi::Integer) where T =
encode!(cbuf, kernel, descriptor)
end

P = MtlMatrix{UInt32}(undef, 1, min(N, M))
P = similar(A, UInt32, 1, min(N, M))
status = MtlArray{MPSMatrixDecompositionStatus}(undef)

commitAndContinue!(cmdbuf) do cbuf
Expand All @@ -137,7 +137,7 @@ LinearAlgebra.ipiv2perm(v::MtlVector{T}, maxi::Integer) where T =
encode!(cbuf, kernel, mps_at, mps_at, mps_p, status)
end

B = MtlMatrix{T}(undef, M, N)
B = similar(A, M, N)

commit!(cmdbuf) do cbuf
mps_b = MPSMatrix(B)
Expand Down Expand Up @@ -186,7 +186,7 @@ end
encode!(cbuf, kernel, descriptor)
end

P = MtlMatrix{UInt32}(undef, 1, min(N, M))
P = similar(A, UInt32, 1, min(N, M))
status = MtlArray{MPSMatrixDecompositionStatus}(undef)

commitAndContinue!(cmdbuf) do cbuf
Expand Down
8 changes: 8 additions & 0 deletions test/mps/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ end
end
end

using Metal: storagemode
@testset "decompositions" begin
A = MtlMatrix(rand(Float32, 1024, 1024))
lua = lu(A)
Expand All @@ -211,6 +212,13 @@ end

A = MtlMatrix{Float32}([1 2; 0 0])
@test_throws SingularException lu(A)

altStorage = Metal.DefaultStorageMode != Metal.PrivateStorage ? Metal.PrivateStorage : Metal.SharedStorage
A = MtlMatrix{Float32,altStorage}(rand(Float32, 1024, 1024))
lua = lu(A)
@test storagemode(lua.factors) == storagemode(lua.ipiv) == storagemode(A)
lua = lu!(A)
@test storagemode(lua.factors) == storagemode(lua.ipiv) == storagemode(A)
end

using .MPS: MPSMatrixSoftMax, MPSMatrixLogSoftMax
Expand Down

0 comments on commit 3bbda32

Please sign in to comment.