Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca27835
bump MatrixAlgebraKit compat to 0.6
lkdvos Oct 27, 2025
a64bb27
update `ishermitian` implementations
lkdvos Oct 27, 2025
3f33eb8
update `isisometric` implementations
lkdvos Oct 27, 2025
fbebae3
add projections
lkdvos Oct 27, 2025
5cdec10
Incremental fixes
kshyatt Nov 14, 2025
37a7eab
orthnull progress
kshyatt Nov 14, 2025
47a3cca
Adjoint factorizations (AD not working)
kshyatt Nov 14, 2025
a1974c0
add missing MAK.
lkdvos Nov 15, 2025
e26ce89
remove `eig(::Adjoint)`
lkdvos Nov 15, 2025
196cee1
add truncation error implementation
lkdvos Nov 15, 2025
4f2bc30
add nullspace truncation specializations
lkdvos Nov 15, 2025
dd3b112
update orth interface in tests
lkdvos Nov 15, 2025
7d20fc3
fix wrong variable
lkdvos Nov 15, 2025
f623bc3
improve adjoint support
lkdvos Nov 15, 2025
8636d67
remove unnecessary left/rightorth functions
lkdvos Nov 15, 2025
a67099f
pass kwargs in isisometri
lkdvos Nov 15, 2025
88ac077
add tests for truncation error
lkdvos Nov 15, 2025
046ee09
more nullspace tests and fixes
lkdvos Nov 15, 2025
bff9b9d
remove unnecessary specialization
lkdvos Nov 15, 2025
7cc9316
add missing argument
lkdvos Nov 15, 2025
12a7826
remove unnecessary specializations
lkdvos Nov 15, 2025
e6b3cee
slight reorganization
lkdvos Nov 15, 2025
fa6fa86
export new functionality
lkdvos Nov 15, 2025
86c31e5
simplify truncationerror implementation
lkdvos Nov 16, 2025
244e6dc
fix testcase
lkdvos Nov 16, 2025
0cf6cbd
refrain from defining left_null functions to avoid ambiguities
lkdvos Nov 16, 2025
110d0fb
fix ad tests
lkdvos Nov 16, 2025
35e79ae
add projection tests
lkdvos Nov 16, 2025
104fde4
temporary AD fixes
lkdvos Nov 16, 2025
75f8d17
try and add back some AD tests
lkdvos Nov 16, 2025
6d3a22d
Start on GPU extensions
kshyatt Oct 7, 2025
6184ca5
Small updates
kshyatt Nov 10, 2025
ae77d20
Add CUDA to factorization testset titles
kshyatt Nov 12, 2025
131fd04
More tests for CUDA
kshyatt Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,37 @@ TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"

[weakdeps]
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[sources]
GPUArrays = {rev = "master", url = "https://github.com/JuliaGPU/GPUArrays.jl"}
AMDGPU = {rev = "master", url = "https://github.com/JuliaGPU/AMDGPU.jl"}
MatrixAlgebraKit = {rev = "ksh/tk2", url = "https://github.com/QuantumKitHub/MatrixAlgebraKit.jl"}

[extensions]
TensorKitAMDGPUExt = "AMDGPU"
TensorKitCUDAExt = ["CUDA", "cuTENSOR"]
TensorKitChainRulesCoreExt = "ChainRulesCore"
TensorKitFiniteDifferencesExt = "FiniteDifferences"

[compat]
AMDGPU = "2"
Adapt = "4"
Aqua = "0.6, 0.7, 0.8"
ArgParse = "1.2.0"
CUDA = "5.9"
ChainRulesCore = "1"
ChainRulesTestUtils = "1"
Combinatorics = "1"
FiniteDifferences = "0.12"
GPUArrays = "11.2.6"
LRUCache = "1.0.2"
LinearAlgebra = "1"
MatrixAlgebraKit = "0.5.0"
MatrixAlgebraKit = "0.6.0"
OhMyThreads = "0.8.0"
PackageExtensionCompat = "1"
Printf = "1"
Expand All @@ -50,21 +64,27 @@ TestExtras = "0.2,0.3"
TupleTools = "1.1"
VectorInterface = "0.4.8, 0.5"
Zygote = "0.7"
cuTENSOR = "2"
julia = "1.10"

[extras]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[targets]
test = ["ArgParse", "Aqua", "Combinatorics", "LinearAlgebra", "TensorOperations", "Test", "TestExtras", "SafeTestsets", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote"]
test = ["ArgParse", "Adapt", "AMDGPU", "Aqua", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "LinearAlgebra", "SafeTestsets", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote"]
109 changes: 109 additions & 0 deletions ext/TensorKitAMDGPUExt/TensorKitAMDGPUExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
module TensorKitAMDGPUExt

using AMDGPU, AMDGPU.rocBLAS, LinearAlgebra
using AMDGPU: @allowscalar
import AMDGPU: rand as rocrand, rand! as rocrand!, randn as rocrandn, randn! as rocrandn!

using TensorKit
import TensorKit.VectorInterface: scalartype as vi_scalartype
using TensorKit.Factorizations
using TensorKit.Strided
using TensorKit.Factorizations: AbstractAlgorithm
using TensorKit: SectorDict, tensormaptype, scalar, similarstoragetype, AdjointTensorMap

using TensorKit.MatrixAlgebraKit

using Random

include("roctensormap.jl")

const ROCDiagonalTensorMap{T, S} = DiagonalTensorMap{T, S, ROCVector{T, AMDGPU.Mem.HIPBuffer}}

"""
ROCDiagonalTensorMap{T}(undef, domain::S) where {T,S<:IndexSpace}
# expert mode: select storage type `A`
DiagonalTensorMap{T,S,A}(undef, domain::S) where {T,S<:IndexSpace,A<:DenseVector{T}}

Construct a `DiagonalTensorMap` with uninitialized data.
"""
function ROCDiagonalTensorMap{T}(::UndefInitializer, V::TensorMapSpace) where {T}
(numin(V) == numout(V) == 1 && domain(V) == codomain(V)) ||
throw(ArgumentError("DiagonalTensorMap requires a space with equal domain and codomain and 2 indices"))
return ROCDiagonalTensorMap{T}(undef, domain(V))
end
function ROCDiagonalTensorMap{T}(::UndefInitializer, V::ProductSpace) where {T}
length(V) == 1 ||
throw(ArgumentError("DiagonalTensorMap requires `numin(d) == numout(d) == 1`"))
return ROCDiagonalTensorMap{T}(undef, only(V))
end
function ROCDiagonalTensorMap{T}(::UndefInitializer, V::S) where {T, S <: IndexSpace}
return ROCDiagonalTensorMap{T, S}(undef, V)
end
ROCDiagonalTensorMap(::UndefInitializer, V::IndexSpace) = ROCDiagonalTensorMap{Float64}(undef, V)

function ROCDiagonalTensorMap(data::ROCVector{T}, V::S) where {T, S}
return ROCDiagonalTensorMap{T, S}(data, V)
end

function ROCDiagonalTensorMap(data::Vector{T}, V::S) where {T, S}
return ROCDiagonalTensorMap{T, S}(ROCVector{T}(data), V)
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(svd_full!), t::ROCDiagonalTensorMap, alg::DiagonalAlgorithm)
V_cod = fuse(codomain(t))
V_dom = fuse(domain(t))
U = similar(t, codomain(t) ← V_cod)
S = ROCDiagonalTensorMap{real(scalartype(t))}(undef, V_cod ← V_dom)
Vᴴ = similar(t, V_dom ← domain(t))
return U, S, Vᴴ
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(svd_vals!), t::ROCTensorMap, alg::AbstractAlgorithm)
V_cod = infimum(fuse(codomain(t)), fuse(domain(t)))
return ROCDiagonalTensorMap{real(scalartype(t))}(undef, V_cod)
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(svd_compact!), t::ROCTensorMap, ::AbstractAlgorithm)
V_cod = V_dom = infimum(fuse(codomain(t)), fuse(domain(t)))
U = similar(t, codomain(t) ← V_cod)
S = ROCDiagonalTensorMap{real(scalartype(t))}(undef, V_cod)
Vᴴ = similar(t, V_dom ← domain(t))
return U, S, Vᴴ
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(eigh_full!), t::ROCTensorMap, ::AbstractAlgorithm)
V_D = fuse(domain(t))
T = real(scalartype(t))
D = ROCDiagonalTensorMap{T}(undef, V_D)
V = similar(t, codomain(t) ← V_D)
return D, V
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(eig_full!), t::ROCTensorMap, ::AbstractAlgorithm)
V_D = fuse(domain(t))
Tc = complex(scalartype(t))
D = ROCDiagonalTensorMap{Tc}(undef, V_D)
V = similar(t, Tc, codomain(t) ← V_D)
return D, V
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(eigh_vals!), t::ROCTensorMap, alg::AbstractAlgorithm)
V_D = fuse(domain(t))
T = real(scalartype(t))
return D = ROCDiagonalTensorMap{Tc}(undef, V_D)
end

function TensorKit.Factorizations.MAK.initialize_output(::typeof(eig_vals!), t::ROCTensorMap, alg::AbstractAlgorithm)
V_D = fuse(domain(t))
Tc = complex(scalartype(t))
return D = ROCDiagonalTensorMap{Tc}(undef, V_D)
end


# TODO
# add VectorInterface extensions for proper AMDGPU promotion
function TensorKit.VectorInterface.promote_add(TA::Type{<:AMDGPU.StridedROCMatrix{Tx}}, TB::Type{<:AMDGPU.StridedROCMatrix{Ty}}, α::Tα = TensorKit.VectorInterface.One(), β::Tβ = TensorKit.VectorInterface.One()) where {Tx, Ty, Tα, Tβ}
return Base.promote_op(add, Tx, Ty, Tα, Tβ)
end

end
Loading
Loading