Skip to content

Commit 7fd3318

Browse files
author
Katharine Hyatt
committed
AMDGPU updates
1 parent 2aa7a8a commit 7fd3318

File tree

7 files changed

+113
-75
lines changed

7 files changed

+113
-75
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"
2727
[sources]
2828
GPUArrays = {rev = "ksh/more_diag", url = "https://github.com/JuliaGPU/GPUArrays.jl"}
2929
MatrixAlgebraKit = {rev = "ksh/tk", url = "https://github.com/QuantumKitHub/MatrixAlgebraKit.jl"}
30+
AMDGPU = {rev = "ksh/diag_norm", url = "https://github.com/JuliaGPU/AMDGPU.jl"}
3031
cuTENSOR = {subdir = "lib/cutensor", url = "https://github.com/JuliaGPU/CUDA.jl"}
3132

3233
[extensions]
@@ -65,6 +66,7 @@ julia = "1.10"
6566

6667
[extras]
6768
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
69+
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
6870
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
6971
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
7072
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -80,4 +82,4 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
8082
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"
8183

8284
[targets]
83-
test = ["Adapt", "Aqua", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "LinearAlgebra", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote"]
85+
test = ["Adapt", "AMDGPU", "Aqua", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "LinearAlgebra", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote"]

ext/TensorKitAMDGPUExt/TensorKitAMDGPUExt.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module TensorKitAMDGPUExt
22

3-
using AMDGPU, AMDGPU.CUBLAS, LinearAlgebra
3+
using AMDGPU, AMDGPU.rocBLAS, LinearAlgebra
44
using AMDGPU: @allowscalar
55
import AMDGPU: rand as rocrand, rand! as rocrand!, randn as rocrandn, randn! as rocrandn!
66

@@ -16,7 +16,7 @@ using Random
1616

1717
include("roctensormap.jl")
1818

19-
const ROCDiagonalTensorMap{T, S} = DiagonalTensorMap{T, S, ROCVector{T, AMDGPU.DeviceMemory}}
19+
const ROCDiagonalTensorMap{T, S} = DiagonalTensorMap{T, S, ROCVector{T, AMDGPU.Mem.HIPBuffer}}
2020

2121
"""
2222
ROCDiagonalTensorMap{T}(undef, domain::S) where {T,S<:IndexSpace}
@@ -44,6 +44,10 @@ function ROCDiagonalTensorMap(data::ROCVector{T}, V::S) where {T, S}
4444
return ROCDiagonalTensorMap{T, S}(data, V)
4545
end
4646

47+
function ROCDiagonalTensorMap(data::Vector{T}, V::S) where {T, S}
48+
return ROCDiagonalTensorMap{T, S}(ROCVector{T}(data), V)
49+
end
50+
4751
function TensorKit.Factorizations.MAK.initialize_output(::typeof(svd_full!), t::ROCDiagonalTensorMap, alg::DiagonalAlgorithm)
4852
V_cod = fuse(codomain(t))
4953
V_dom = fuse(domain(t))

ext/TensorKitAMDGPUExt/roctensormap.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const ROCTensorMap{T,S,N₁,N₂} = TensorMap{T,S,N₁,N₂, ROCVector{T,AMDGPU.DeviceMemory}}
1+
const ROCTensorMap{T,S,N₁,N₂} = TensorMap{T,S,N₁,N₂, ROCVector{T,AMDGPU.Mem.HIPBuffer}}
22
const ROCTensor{T, S, N} = ROCTensorMap{T, S, N, 0}
33

44
const AdjointROCTensorMap{T,S,N₁,N₂} = AdjointTensorMap{T,S,N₁,N₂,ROCTensorMap{T,S,N₁,N₂}}
55

66
function TensorKit.tensormaptype(S::Type{<:IndexSpace}, N₁, N₂, TorA::Type{<:StridedROCArray})
77
if TorA <: ROCArray
8-
return TensorMap{eltype(TorA),S,N₁,N₂,ROCVector{eltype(TorA), AMDGPU.DeviceMemory}}
8+
return TensorMap{eltype(TorA),S,N₁,N₂,ROCVector{eltype(TorA), AMDGPU.Mem.HIPBuffer}}
99
else
1010
throw(ArgumentError("argument $TorA should specify a scalar type (`<:Number`) or a storage type `<:ROCVector{<:Number}`"))
1111
end
@@ -68,6 +68,10 @@ function ROCTensorMap(data::AbstractDict{<:Sector,<:ROCMatrix}, codom::TensorSpa
6868
return ROCTensorMap(data, codom dom)
6969
end
7070

71+
function ROCTensorMap(ts::TensorMap{T, S, N₁, N₂, A}) where {T, S, N₁, N₂, A}
72+
return ROCTensorMap{T, S, N₁, N₂}(ROCArray(ts.data), ts.space)
73+
end
74+
7175
for (fname, felt) in ((:zeros, :zero), (:ones, :one))
7276
@eval begin
7377
function AMDGPU.$fname(codomain::TensorSpace{S},
@@ -87,7 +91,7 @@ for (fname, felt) in ((:zeros, :zero), (:ones, :one))
8791
end
8892
end
8993

90-
for randfun in (:curand, :curandn)
94+
for randfun in (:rocrand, :rocrandn)
9195
randfun! = Symbol(randfun, :!)
9296
@eval begin
9397
# converting `codomain` and `domain` into `HomSpace`
@@ -171,7 +175,7 @@ vi_scalartype(::Type{<:ROCTensorMap{T}}) where {T} = T
171175
vi_scalartype(::Type{<:ROCArray{T}}) where {T} = T
172176

173177
function TensorKit.similarstoragetype(TT::Type{<:ROCTensorMap{TTT,S,N₁,N₂}}, ::Type{T}) where {TTT,T,S,N₁,N₂}
174-
return ROCVector{T, AMDGPU.DeviceMemory}
178+
return ROCVector{T, AMDGPU.Mem.HIPBuffer}
175179
end
176180

177181
function Base.convert(TT::Type{ROCTensorMap{T,S,N₁,N₂}},

src/TensorKit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export left_orth, right_orth, left_null, right_null,
8080
eigh_full!, eigh_full, eigh_trunc!, eigh_trunc, eig_full!, eig_full, eig_trunc!,
8181
eig_trunc,
8282
eigh_vals!, eigh_vals, eig_vals!, eig_vals,
83-
isposdef, isposdef!, ishermitian, isisometry, isunitary, sylvester, rank, cond
83+
isposdef, isposdef!, ishermitian, isisometric, isunitary, sylvester, rank, cond
8484

8585
export braid, braid!, permute, permute!, transpose, transpose!, twist, twist!, repartition,
8686
repartition!

src/factorizations/adjoint.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ function MAK.right_null!(t::AdjointTensorMap, N, alg::AbstractAlgorithm)
2929
return N
3030
end
3131

32-
function MAK.is_left_isometry(t::AdjointTensorMap; kwargs...)
33-
return is_right_isometry(adjoint(t); kwargs...)
32+
function MAK.is_left_isometric(t::AdjointTensorMap; kwargs...)
33+
return is_right_isometric(adjoint(t); kwargs...)
3434
end
35-
function MAK.is_right_isometry(t::AdjointTensorMap; kwargs...)
36-
return is_left_isometry(adjoint(t); kwargs...)
35+
function MAK.is_right_isometric(t::AdjointTensorMap; kwargs...)
36+
return is_left_isometric(adjoint(t); kwargs...)
3737
end
3838

3939
# 2-arg functions

src/factorizations/factorizations.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ include("pullbacks.jl")
3030

3131
TensorKit.one!(A::AbstractMatrix) = MatrixAlgebraKit.one!(A)
3232

33-
function MatrixAlgebraKit.isisometry(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple)
33+
function MatrixAlgebraKit.isisometric(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple)
3434
t = permute(t, (p₁, p₂); copy = false)
35-
return isisometry(t)
35+
return isisometric(t)
3636
end
3737

3838
#------------------------------#
@@ -84,14 +84,14 @@ function LinearAlgebra.isposdef!(t::AbstractTensorMap)
8484
end
8585

8686
# TODO: tolerances are per-block, not global or weighted - does that matter?
87-
function MatrixAlgebraKit.is_left_isometry(t::AbstractTensorMap; kwargs...)
87+
function MatrixAlgebraKit.is_left_isometric(t::AbstractTensorMap; kwargs...)
8888
domain(t) codomain(t) || return false
89-
f((c, b)) = MatrixAlgebraKit.is_left_isometry(b; kwargs...)
89+
f((c, b)) = MatrixAlgebraKit.is_left_isometric(b; kwargs...)
9090
return all(f, blocks(t))
9191
end
92-
function MatrixAlgebraKit.is_right_isometry(t::AbstractTensorMap; kwargs...)
92+
function MatrixAlgebraKit.is_right_isometric(t::AbstractTensorMap; kwargs...)
9393
domain(t) codomain(t) || return false
94-
f((c, b)) = MatrixAlgebraKit.is_right_isometry(b; kwargs...)
94+
f((c, b)) = MatrixAlgebraKit.is_right_isometric(b; kwargs...)
9595
return all(f, blocks(t))
9696
end
9797

0 commit comments

Comments
 (0)