Skip to content

Commit 9d255c8

Browse files
lkdvosclaude
andcommitted
Fix ROCm pointer-batched eigh wrappers
- pass an array of pointers for Z to syevx_batched instead of the dense V - copy the eigenvectors back from each A[i] into its slice of V - accept a 3D V in heevj_batched! - free the device pointer arrays after each call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent aa29acd commit 9d255c8

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎ext/MatrixAlgebraKitAMDGPUExt/yarocsolver.jl‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,13 +1465,16 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
14651465
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
14661466
pA = ROCVector(map(pointer, A))
14671467
$heevd_batched(dh, jobz, roc_uplo, n, pA, lda, W, ldw, work, n, dev_info, batch_size)
1468+
AMDGPU.unsafe_free!(pA)
14681469

14691470
if check
14701471
foreach(chkargsok ∘ BlasInt, collect(dev_info))
14711472
end
14721473

1473-
if jobz == rocSOLVER.rocblas_evect_original && V !== A
1474-
copy!(V, A)
1474+
if jobz == rocSOLVER.rocblas_evect_original
1475+
for (v, a) in zip(eachslice(V, dims = 3), A)
1476+
copy!(v, a)
1477+
end
14751478
end
14761479
return W, V
14771480
end
@@ -1500,13 +1503,16 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15001503
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
15011504
pA = ROCVector(map(pointer, A))
15021505
$heev_batched(dh, jobz, roc_uplo, n, pA, lda, W, ldw, work, n, dev_info, batch_size)
1506+
AMDGPU.unsafe_free!(pA)
15031507

15041508
if check
15051509
foreach(chkargsok ∘ BlasInt, collect(dev_info))
15061510
end
15071511

1508-
if jobz == rocSOLVER.rocblas_evect_original && V !== A
1509-
copy!(V, A)
1512+
if jobz == rocSOLVER.rocblas_evect_original
1513+
for (v, a) in zip(eachslice(V, dims = 3), A)
1514+
copy!(v, a)
1515+
end
15101516
end
15111517
return W, V
15121518
end
@@ -1553,7 +1559,11 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15531559
dev_info = ROCVector{Cint}(undef, batch_size)
15541560
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
15551561
pA = ROCVector(map(pointer, A))
1556-
$heevx_batched(dh, jobz, range, roc_uplo, n, pA, lda, vl, vu, il, iu, abstol, nev, W, ldw, V, ldv, ifail, n, dev_info, batch_size)
1562+
# `Z` is an array of pointers in the batched (non-strided) API
1563+
pV = ROCVector([pointer(V, (i - 1) * stride(V, 3) + 1) for i in 1:(length(V) == 0 ? 0 : batch_size)])
1564+
$heevx_batched(dh, jobz, range, roc_uplo, n, pA, lda, vl, vu, il, iu, abstol, nev, W, ldw, pV, ldv, ifail, n, dev_info, batch_size)
1565+
AMDGPU.unsafe_free!(pA)
1566+
AMDGPU.unsafe_free!(pV)
15571567

15581568
if check
15591569
foreach(chkargsok ∘ BlasInt, collect(dev_info))
@@ -1564,7 +1574,7 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15641574
function heevj_batched!(
15651575
A::AbstractVector{<:StridedROCMatrix{$elty}},
15661576
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), length(A)),
1567-
V::StridedROCMatrix{$elty} = similar(first(A), $elty, size(first(A))..., length(A));
1577+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(first(A))..., length(A));
15681578
uplo::Char = 'U',
15691579
tol::$relty = eps($relty),
15701580
max_sweeps::Int = 100,
@@ -1591,13 +1601,16 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15911601
roc_sort = sort == 'N' ? rocSOLVER.rocblas_esort_none : rocSOLVER.rocblas_esort_ascending
15921602
pA = ROCVector(map(pointer, A))
15931603
$heevj_batched(dh, roc_sort, jobz, roc_uplo, n, pA, lda, tol, residual, max_sweeps, n_sweeps, W, ldw, dev_info, batch_size)
1604+
AMDGPU.unsafe_free!(pA)
15941605

15951606
if check
15961607
foreach(chkargsok ∘ BlasInt, collect(dev_info))
15971608
end
15981609

1599-
if jobz == rocSOLVER.rocblas_evect_original && V !== A
1600-
copy!(V, A)
1610+
if jobz == rocSOLVER.rocblas_evect_original
1611+
for (v, a) in zip(eachslice(V, dims = 3), A)
1612+
copy!(v, a)
1613+
end
16011614
end
16021615
return W, V
16031616
end

0 commit comments

Comments
 (0)