Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ steps:
agents:
queue: "juliagpu"
cuda: "*"
commands: |
unset LD_LIBRARY_PATH
if: build.message !~ /\[skip tests\]/
timeout_in_minutes: 90
matrix:
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ projects = ["test", "docs"]
[compat]
Adapt = "4"
AMDGPU = "2"
CUDA = "5.9"
CUDA = "6"
ChainRulesCore = "1"
Dictionaries = "0.4"
FiniteDifferences = "0.12"
LRUCache = "1.0.2"
LinearAlgebra = "1"
MatrixAlgebraKit = "0.6.5"
Mooncake = "0.5"
MatrixAlgebraKit = "0.6.6"
Mooncake = "0.5.27"
OhMyThreads = "0.8.0"
Printf = "1"
Random = "1"
Expand All @@ -58,5 +58,5 @@ TensorKitSectors = "0.3.7"
TensorOperations = "5.1"
TupleTools = "1.5"
VectorInterface = "0.4.8, 0.5"
cuTENSOR = "2"
cuTENSOR = "6"
julia = "1.10"
6 changes: 3 additions & 3 deletions ext/TensorKitCUDAExt/TensorKitCUDAExt.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module TensorKitCUDAExt

using CUDA, CUDA.CUBLAS, CUDA.CUSOLVER, LinearAlgebra
using CUDA, CUDA.cuBLAS, CUDA.cuSOLVER, CUDA.cuRAND, LinearAlgebra
using CUDA: @allowscalar
using cuTENSOR: cuTENSOR
import CUDA.cuRAND: rand as curand, rand! as curand!, randn as curandn, randn! as curandn!
using Strided: StridedViews
import CUDA: rand as curand, rand! as curand!, randn as curandn, randn! as curandn!
using CUDA.KernelAbstractions: @kernel, @index, get_backend
using CUDA.CUDACore.KernelAbstractions: @kernel, @index, get_backend

using TensorKit
using TensorKit.Factorizations
Expand Down
2 changes: 1 addition & 1 deletion ext/TensorKitCUDAExt/cutensormap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ for f in (:sqrt, :log, :asin, :acos, :acosh, :atanh, :acoth)
end

function TensorKit._add_transform_multi!(tdst::CuTensorMap, tsrc, p, (U, structs_dst, structs_src)::Tuple{<:Array, TD, TS}, buffers, alpha, beta, backend...) where {TD, TS}
return TensorKit._add_transform_multi!(tdst, tsrc, p, (CUDA.Adapt.adapt(CuArray, U), structs_dst, structs_src), buffers, alpha, beta, backend...)
return TensorKit._add_transform_multi!(tdst, tsrc, p, (CUDA.CUDACore.Adapt.adapt(CuArray, U), structs_dst, structs_src), buffers, alpha, beta, backend...)
end
102 changes: 51 additions & 51 deletions test/cuda/factorizations.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Adapt, CUDA, cuTENSOR
using Adapt, CUDA, CUDA.cuRAND, cuTENSOR
using Test, TestExtras
using TensorKit
using LinearAlgebra: LinearAlgebra
Expand All @@ -25,10 +25,10 @@ for V in spacelist
@testset "QR decomposition" begin
for T in eltypes,
t in (
CUDA.rand(T, W, W), CUDA.rand(T, W, W)',
CUDA.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), CUDA.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)')',
CUDA.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5)), CUDA.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, W, W), cuRAND.rand(T, W, W)',
cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)')',
cuRAND.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5)), cuRAND.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

Q, R = @constinferred qr_full(t)
Expand All @@ -54,7 +54,7 @@ for V in spacelist

# empty tensor
for T in eltypes
t = CUDA.rand(T, V1 ⊗ V2, zerospace(V1))
t = cuRAND.rand(T, V1 ⊗ V2, zerospace(V1))

Q, R = @constinferred qr_full(t)
@test Q * R ≈ t
Expand All @@ -80,10 +80,10 @@ for V in spacelist
@testset "LQ decomposition" begin
for T in eltypes,
t in (
CUDA.rand(T, W, W), CUDA.rand(T, W, W)',
CUDA.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), CUDA.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)')',
CUDA.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5)), CUDA.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, W, W), cuRAND.rand(T, W, W)',
cuRAND.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), cuRAND.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)')',
cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5)), cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

L, Q = @constinferred lq_full(t)
Expand All @@ -105,7 +105,7 @@ for V in spacelist

for T in eltypes
# empty tensor
t = CUDA.rand(T, zerospace(V1), V1 ⊗ V2)
t = cuRAND.rand(T, zerospace(V1), V1 ⊗ V2)

L, Q = @constinferred lq_full(t)
@test L * Q ≈ t
Expand All @@ -131,10 +131,10 @@ for V in spacelist
@testset "Polar decomposition" begin
@testset for T in eltypes,
t in (
CUDA.rand(T, W, W),
CUDA.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'),
CUDA.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, W, W),
cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'),
cuRAND.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

@assert domain(t) ≾ codomain(t)
Expand All @@ -150,10 +150,10 @@ for V in spacelist

@testset for T in eltypes,
t in (
CUDA.rand(T, W, W),
CUDA.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'),
CUDA.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, W, W),
cuRAND.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'),
cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

@assert codomain(t) ≾ domain(t)
Expand All @@ -171,10 +171,10 @@ for V in spacelist
@testset "SVD" begin
for T in eltypes,
t in (
CUDA.rand(T, W, W), CUDA.rand(T, W, W)',
CUDA.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), CUDA.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
CUDA.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), CUDA.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, W, W), cuRAND.rand(T, W, W)',
cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), cuRAND.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
cuRAND.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

u, s, vᴴ = @constinferred svd_full(t)
Expand Down Expand Up @@ -222,8 +222,8 @@ for V in spacelist

# empty tensor
for T in eltypes, t in (
CUDA.rand(T, W, zerospace(V1)),
CUDA.rand(T, zerospace(V1), W),
cuRAND.rand(T, W, zerospace(V1)),
cuRAND.rand(T, zerospace(V1), W),
)
U, S, Vᴴ = @constinferred svd_full(t)
@test U * S * Vᴴ ≈ t
Expand All @@ -239,10 +239,10 @@ for V in spacelist
@testset "truncated SVD" begin
for T in eltypes,
t in (
CUDA.randn(T, W, W), CUDA.randn(T, W, W)',
CUDA.randn(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), CUDA.randn(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
CUDA.randn(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), CUDA.randn(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(CUDA.randn(T, reduceddim(V1)), V1),
cuRAND.randn(T, W, W), cuRAND.randn(T, W, W)',
cuRAND.randn(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), cuRAND.randn(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
cuRAND.randn(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), cuRAND.randn(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.randn(T, reduceddim(V1)), V1),
)

@constinferred normalize!(t)
Expand Down Expand Up @@ -307,10 +307,10 @@ for V in spacelist
@testset "Eigenvalue decomposition" begin
for T in eltypes,
t in (
CUDA.rand(T, V1, V1),
CUDA.rand(T, W, W),
CUDA.rand(T, W, W)',
# DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, V1, V1),
cuRAND.rand(T, W, W),
cuRAND.rand(T, W, W)',
# DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

d, v = @constinferred eig_full(t)
Expand Down Expand Up @@ -367,15 +367,15 @@ for V in spacelist
@testset "Condition number and rank" begin
for T in eltypes,
t in (
CUDA.rand(T, W, W), CUDA.rand(T, W, W)',
CUDA.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), CUDA.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
CUDA.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), CUDA.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, W, W), cuRAND.rand(T, W, W)',
cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'), cuRAND.rand(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
cuRAND.rand(T, (V1 ⊗ V2), (V3 ⊗ V4 ⊗ V5)'), cuRAND.rand(T, (V1 ⊗ V2 ⊗ V3)', (V4 ⊗ V5))',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)

d1, d2 = dim(codomain(t)), dim(domain(t))
r = rank(t)
@test r == min(d1, d2)
@test r min(d1, d2)
@test typeof(r) == typeof(d1)
M = left_null(t)
@test @constinferred(rank(M)) + r ≈ d1
Expand All @@ -387,15 +387,15 @@ for V in spacelist
@test @constinferred(cond(u)) ≈ one(real(T))
@test @constinferred(rank(u)) == dim(V1 ⊗ V2)

t = CUDA.rand(T, zerospace(V1), W)
t = cuRAND.rand(T, zerospace(V1), W)
@test rank(t) == 0
t2 = CUDA.rand(T, zerospace(V1) * zerospace(V2), zerospace(V1) * zerospace(V2))
t2 = cuRAND.rand(T, zerospace(V1) * zerospace(V2), zerospace(V1) * zerospace(V2))
@test rank(t2) == 0
@test cond(t2) == 0.0
end
for T in eltypes, t in (
CUDA.rand(T, W, W),
CUDA.rand(T, W, W)',
cuRAND.rand(T, W, W),
cuRAND.rand(T, W, W)',
)
project_hermitian!(t)
vals = @constinferred LinearAlgebra.eigvals(t)
Expand All @@ -408,10 +408,10 @@ for V in spacelist
@testset "Hermitian projections" begin
for T in eltypes,
t in (
CUDA.rand(T, V1, V1),
CUDA.rand(T, W, W),
CUDA.rand(T, W, W)',
DiagonalTensorMap(CUDA.rand(T, reduceddim(V1)), V1),
cuRAND.rand(T, V1, V1),
cuRAND.rand(T, W, W),
cuRAND.rand(T, W, W)',
DiagonalTensorMap(cuRAND.rand(T, reduceddim(V1)), V1),
)
normalize!(t)
noisefactor = eps(real(T))^(3 / 4)
Expand Down Expand Up @@ -441,10 +441,10 @@ for V in spacelist
@testset "Isometric projections" begin
for T in eltypes,
t in (
CUDA.randn(T, W, W),
CUDA.randn(T, W, W)',
CUDA.randn(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'),
CUDA.randn(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
cuRAND.randn(T, W, W),
cuRAND.randn(T, W, W)',
cuRAND.randn(T, (V1 ⊗ V2 ⊗ V3), (V4 ⊗ V5)'),
cuRAND.randn(T, (V1 ⊗ V2)', (V3 ⊗ V4 ⊗ V5))',
)
t2 = project_isometric(t)
@test isisometric(t2)
Expand All @@ -459,7 +459,7 @@ for V in spacelist

# test that t2 is closer to A then any other isometry
for k in 1:10
δt = CUDA.randn!(similar(t))
δt = cuRAND.randn!(similar(t))
t3 = project_isometric(t + δt / 100)
@test norm(t - t3) > norm(t - t2)
end
Expand Down
Loading
Loading