Skip to content

Commit a3367bf

Browse files
Katharine Hyattkshyatt
authored andcommitted
Fix a lot of typos and add the strided_batched methods
1 parent 621a8ec commit a3367bf

2 files changed

Lines changed: 185 additions & 10 deletions

File tree

‎ext/MatrixAlgebraKitAMDGPUExt/yarocsolver.jl‎

Lines changed: 182 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
14431443
function heevd_batched!(
14441444
A::AbstractVector{<:StridedROCMatrix{$elty}},
14451445
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), length(A)),
1446-
V::StridedROCMatrix{$elty} = similar(first(A), $elty, size(first(A))..., length(A));
1446+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(first(A))..., length(A));
14471447
uplo::Char = 'U',
14481448
check::Bool = CHECK_LIBRARY_CALLS[],
14491449
)
@@ -1460,11 +1460,11 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
14601460
lda = max(1, stride(first(A), 2))
14611461
ldw = max(1, stride(W, 2))
14621462
dh = rocBLAS.handle()
1463-
work = ROCMatix{$relty}(undef, n, batch_size)
1463+
work = ROCMatrix{$relty}(undef, n, batch_size)
14641464
dev_info = ROCVector{Cint}(undef, batch_size)
14651465
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
14661466
pA = ROCVector(map(pointer, A))
1467-
$heevd(dh, jobz, roc_uplo, n, pA, lda, W, ldw, work, n, dev_info, batch_size)
1467+
$heevd_batched(dh, jobz, roc_uplo, n, pA, lda, W, ldw, work, n, dev_info, batch_size)
14681468

14691469
if check
14701470
foreach(chkargsok ∘ BlasInt, collect(dev_info))
@@ -1478,7 +1478,7 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
14781478
function heev_batched!(
14791479
A::AbstractVector{<:StridedROCMatrix{$elty}},
14801480
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), length(A)),
1481-
V::StridedROCMatrix{$elty} = similar(first(A), $elty, size(first(A))..., length(A));
1481+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(first(A))..., length(A));
14821482
uplo::Char = 'U',
14831483
check::Bool = CHECK_LIBRARY_CALLS[],
14841484
)
@@ -1499,7 +1499,7 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
14991499
dev_info = ROCVector{Cint}(undef, batch_size)
15001500
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
15011501
pA = ROCVector(map(pointer, A))
1502-
$heev(dh, jobz, roc_uplo, n, pA, lda, W, ldw, work, n, dev_info, batch_size)
1502+
$heev_batched(dh, jobz, roc_uplo, n, pA, lda, W, ldw, work, n, dev_info, batch_size)
15031503

15041504
if check
15051505
foreach(chkargsok ∘ BlasInt, collect(dev_info))
@@ -1513,7 +1513,7 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15131513
function heevx_batched!(
15141514
A::AbstractVector{<:StridedROCMatrix{$elty}},
15151515
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), length(A)),
1516-
V::StridedROCMatrix{$elty} = similar(first(A), $elty, size(first(A))..., length(A));
1516+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(first(A))..., length(A));
15171517
uplo::Char = 'U',
15181518
check::Bool = CHECK_LIBRARY_CALLS[],
15191519
kwargs...
@@ -1547,13 +1547,13 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15471547
end
15481548
dh = rocBLAS.handle()
15491549
abstol = -one($relty)
1550-
nev = ROCVector{Cint}(undef, 1)
1550+
nev = ROCVector{Cint}(undef, batch_size)
15511551
ldv = max(1, stride(V, 2))
15521552
ifail = ROCMatrix{Cint}(undef, n, batch_size)
15531553
dev_info = ROCVector{Cint}(undef, batch_size)
15541554
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
15551555
pA = ROCVector(map(pointer, A))
1556-
$heevx(dh, jobz, range, roc_uplo, n, pA, lda, vl, vu, il, iu, abstol, nev, W, ldw, V, ldv, ifail, n, dev_info, batch_size)
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)
15571557

15581558
if check
15591559
foreach(chkargsok ∘ BlasInt, collect(dev_info))
@@ -1590,7 +1590,180 @@ for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
15901590
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
15911591
roc_sort = sort == 'N' ? rocSOLVER.rocblas_esort_none : rocSOLVER.rocblas_esort_ascending
15921592
pA = ROCVector(map(pointer, A))
1593-
$heevj(dh, roc_sort, jobz, roc_uplo, n, pA, lda, tol, residual, max_sweeps, n_sweeps, W, ldw, dev_info, batch_size)
1593+
$heevj_batched(dh, roc_sort, jobz, roc_uplo, n, pA, lda, tol, residual, max_sweeps, n_sweeps, W, ldw, dev_info, batch_size)
1594+
1595+
if check
1596+
foreach(chkargsok ∘ BlasInt, collect(dev_info))
1597+
end
1598+
1599+
if jobz == rocSOLVER.rocblas_evect_original && V !== A
1600+
copy!(V, A)
1601+
end
1602+
return W, V
1603+
end
1604+
end
1605+
end
1606+
1607+
for (heevd_batched, heev_batched, heevx_batched, heevj_batched, elty, relty) in
1608+
(
1609+
(:(rocSOLVER.rocsolver_ssyevd_strided_batched), :(rocSOLVER.rocsolver_ssyev_strided_batched), :(rocSOLVER.rocsolver_ssyevx_strided_batched), :(rocSOLVER.rocsolver_ssyevj_strided_batched), :Float32, :Float32),
1610+
(:(rocSOLVER.rocsolver_dsyevd_strided_batched), :(rocSOLVER.rocsolver_dsyev_strided_batched), :(rocSOLVER.rocsolver_dsyevx_strided_batched), :(rocSOLVER.rocsolver_dsyevj_strided_batched), :Float64, :Float64),
1611+
(:(rocSOLVER.rocsolver_cheevd_strided_batched), :(rocSOLVER.rocsolver_cheev_strided_batched), :(rocSOLVER.rocsolver_cheevx_strided_batched), :(rocSOLVER.rocsolver_cheevj_strided_batched), :ComplexF32, :Float32),
1612+
(:(rocSOLVER.rocsolver_zheevd_strided_batched), :(rocSOLVER.rocsolver_zheev_strided_batched), :(rocSOLVER.rocsolver_zheevx_strided_batched), :(rocSOLVER.rocsolver_zheevj_strided_batched), :ComplexF64, :Float64),
1613+
)
1614+
@eval begin
1615+
function heevd_strided_batched!(
1616+
A::StridedROCArray{$elty, 3},
1617+
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), size(A, 3)),
1618+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(A)...);
1619+
uplo::Char = 'U',
1620+
check::Bool = CHECK_LIBRARY_CALLS[],
1621+
)
1622+
chkuplo(uplo)
1623+
m, n, batch_size = size(A)
1624+
m == n || throw(DimensionMismatch("A must be square in its first two dimensions"))
1625+
size(W) == (n, batch_size) || throw(DimensionMismatch("size mismatch between A and W"))
1626+
if length(V) == 0
1627+
jobz = rocSOLVER.rocblas_evect_none
1628+
else
1629+
size(V) == size(A) || throw(DimensionMismatch("size mismatch between A and V"))
1630+
jobz = rocSOLVER.rocblas_evect_original
1631+
end
1632+
lda = max(1, stride(A, 2))
1633+
strideA = max(1, stride(A, 3))
1634+
ldw = max(1, stride(W, 2))
1635+
dh = rocBLAS.handle()
1636+
work = ROCMatrix{$relty}(undef, n, batch_size)
1637+
dev_info = ROCVector{Cint}(undef, batch_size)
1638+
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
1639+
$heevd_batched(dh, jobz, roc_uplo, n, A, lda, strideA, W, ldw, work, n, dev_info, batch_size)
1640+
1641+
if check
1642+
foreach(chkargsok ∘ BlasInt, collect(dev_info))
1643+
end
1644+
1645+
if jobz == rocSOLVER.rocblas_evect_original && V !== A
1646+
copy!(V, A)
1647+
end
1648+
return W, V
1649+
end
1650+
function heev_strided_batched!(
1651+
A::StridedROCArray{$elty, 3},
1652+
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), size(A, 3)),
1653+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(A)...);
1654+
uplo::Char = 'U',
1655+
check::Bool = CHECK_LIBRARY_CALLS[],
1656+
)
1657+
chkuplo(uplo)
1658+
m, n, batch_size = size(A)
1659+
m == n || throw(DimensionMismatch("A must be square in its first two dimensions"))
1660+
size(W) == (n, batch_size) || throw(DimensionMismatch("size mismatch between A and W"))
1661+
if length(V) == 0
1662+
jobz = rocSOLVER.rocblas_evect_none
1663+
else
1664+
size(V) == size(A) || throw(DimensionMismatch("size mismatch between A and V"))
1665+
jobz = rocSOLVER.rocblas_evect_original
1666+
end
1667+
lda = max(1, stride(A, 2))
1668+
strideA = max(1, stride(A, 3))
1669+
ldw = max(1, stride(W, 2))
1670+
dh = rocBLAS.handle()
1671+
work = ROCMatrix{$relty}(undef, n, batch_size)
1672+
dev_info = ROCVector{Cint}(undef, batch_size)
1673+
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
1674+
$heev_batched(dh, jobz, roc_uplo, n, A, lda, strideA, W, ldw, work, n, dev_info, batch_size)
1675+
1676+
if check
1677+
foreach(chkargsok ∘ BlasInt, collect(dev_info))
1678+
end
1679+
1680+
if jobz == rocSOLVER.rocblas_evect_original && V !== A
1681+
copy!(V, A)
1682+
end
1683+
return W, V
1684+
end
1685+
function heevx_strided_batched!(
1686+
A::StridedROCArray{$elty, 3},
1687+
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), size(A, 3)),
1688+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(A)...);
1689+
uplo::Char = 'U',
1690+
check::Bool = CHECK_LIBRARY_CALLS[],
1691+
kwargs...
1692+
)
1693+
chkuplo(uplo)
1694+
m, n, batch_size = size(A)
1695+
m == n || throw(DimensionMismatch("A must be square in its first two dimensions"))
1696+
size(W) == (n, batch_size) || throw(DimensionMismatch("size mismatch between A and W"))
1697+
lda = max(1, stride(A, 2))
1698+
strideA = max(1, stride(A, 3))
1699+
ldw = max(1, stride(W, 2))
1700+
if haskey(kwargs, :irange)
1701+
il = first(kwargs[:irange])
1702+
iu = last(kwargs[:irange])
1703+
vl = vu = zero($relty)
1704+
range = rocSOLVER.rocblas_erange_index
1705+
elseif haskey(kwargs, :vl) || haskey(kwargs, :vu)
1706+
vl = convert($relty, get(kwargs, :vl, -Inf))
1707+
vu = convert($relty, get(kwargs, :vu, +Inf))
1708+
il = iu = 0
1709+
range = rocSOLVER.rocblas_erange_value
1710+
else
1711+
il = iu = 0
1712+
vl = vu = zero($relty)
1713+
range = rocSOLVER.rocblas_erange_all
1714+
end
1715+
if length(V) == 0
1716+
jobz = rocSOLVER.rocblas_evect_none
1717+
else
1718+
size(V) == (n, n, batch_size) || throw(DimensionMismatch("size mismatch between A and V"))
1719+
jobz = rocSOLVER.rocblas_evect_original
1720+
end
1721+
dh = rocBLAS.handle()
1722+
abstol = -one($relty)
1723+
nev = ROCVector{Cint}(undef, batch_size)
1724+
ldv = max(1, stride(V, 2))
1725+
strideV = max(1, stride(V, 3))
1726+
ifail = ROCMatrix{Cint}(undef, n, batch_size)
1727+
dev_info = ROCVector{Cint}(undef, batch_size)
1728+
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
1729+
$heevx_batched(dh, jobz, range, roc_uplo, n, A, lda, strideA, vl, vu, il, iu, abstol, nev, W, ldw, V, ldv, strideV, ifail, n, dev_info, batch_size)
1730+
1731+
if check
1732+
foreach(chkargsok ∘ BlasInt, collect(dev_info))
1733+
end
1734+
m = collect(nev)
1735+
return W, V, m
1736+
end
1737+
function heevj_strided_batched!(
1738+
A::StridedROCArray{$elty, 3},
1739+
W::StridedROCMatrix{$relty} = similar(first(A), $relty, size(first(A), 1), size(A, 3)),
1740+
V::StridedROCArray{$elty, 3} = similar(first(A), $elty, size(A)...);
1741+
uplo::Char = 'U',
1742+
tol::$relty = eps($relty),
1743+
max_sweeps::Int = 100,
1744+
sort::Char = 'N',
1745+
check::Bool = CHECK_LIBRARY_CALLS[],
1746+
)
1747+
chkuplo(uplo)
1748+
m, n, batch_size = size(A)
1749+
m == n || throw(DimensionMismatch("A must be square in its first two dimensions"))
1750+
size(W) == (n, batch_size) || throw(DimensionMismatch("size mismatch between A and W"))
1751+
if length(V) == 0
1752+
jobz = rocSOLVER.rocblas_evect_none
1753+
else
1754+
size(V) == size(A) || throw(DimensionMismatch("size mismatch between A and V"))
1755+
jobz = rocSOLVER.rocblas_evect_original
1756+
end
1757+
lda = max(1, stride(A, 2))
1758+
strideA = max(1, stride(A, 3))
1759+
ldw = max(1, stride(W, 2))
1760+
dh = rocBLAS.handle()
1761+
dev_info = ROCVector{Cint}(undef, batch_size)
1762+
residual = ROCVector{$relty}(undef, batch_size)
1763+
n_sweeps = ROCVector{Cint}(undef, batch_size)
1764+
roc_uplo = convert(rocSOLVER.rocblas_fill, uplo)
1765+
roc_sort = sort == 'N' ? rocSOLVER.rocblas_esort_none : rocSOLVER.rocblas_esort_ascending
1766+
$heevj_batched(dh, roc_sort, jobz, roc_uplo, n, A, lda, strideA, tol, residual, max_sweeps, n_sweeps, W, ldw, dev_info, batch_size)
15941767

15951768
if check
15961769
foreach(chkargsok ∘ BlasInt, collect(dev_info))

‎src/implementations/batched_eigh.jl‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ function initialize_output(::typeof(batched_eigh_vals!), A::AbstractArray{T, 3},
9292
return similar(A, real(eltype(A)), (n, batch_size))
9393
end
9494

95-
for f! in (:heevj_batched!, :heev_batched!)
95+
for f! in (:heevj_batched!, :heev_batched!, :heevd_batched!, :heevx_batched!)
9696
@eval $f!(driver::Driver, args...) = throw(ArgumentError("$driver does not provide $($(f!))"))
9797
end
9898

9999
for (f, f_lapack!, Alg) in (
100100
(:qr_iteration, :heev_batched!, :QRIteration),
101101
(:jacobi, :heevj_batched!, :Jacobi),
102+
(:bisection, :heevx_batched!, :Bisection),
103+
(:divideandconquer, :heevd_batched!, :DivideAndConquer),
102104
)
103105
eigh_full_f! = Symbol(:batched_eigh_full_, f, :!)
104106
eigh_vals_f! = Symbol(:batched_eigh_vals_, f, :!)

0 commit comments

Comments
 (0)