Skip to content

Commit 3d0f1cd

Browse files
authored
Zero the triangle in one kernel on CuArrays and ROCArrays (#313)
* One kernel for uppertriangular!/lowertriangular! on CuArrays and ROCArrays * Drop the GPU lowertriangular! methods, which no decomposition reaches
1 parent 8fcc601 commit 3d0f1cd

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎ext/MatrixAlgebraKitAMDGPUExt/MatrixAlgebraKitAMDGPUExt.jl‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ end
3535

3636
MatrixAlgebraKit.supports_svd_full(::ROCSOLVER, f::Symbol) = f in (:qr_iteration, :jacobi, :divide_and_conquer, :bisection)
3737

38+
# one kernel for the whole triangle instead of one per column
39+
function MatrixAlgebraKit.uppertriangular!(A::StridedROCMatrix)
40+
m, n = size(A)
41+
A .= ifelse.((1:m) .> transpose(1:n), zero(eltype(A)), A)
42+
return A
43+
end
44+
3845
# rocSOLVER's `gesvd*_batched` functions take the batch as an array
3946
# of device pointers, so a group of equally sized matrices
4047
# doesn't need a copy into a 3D ROCArray.

‎ext/MatrixAlgebraKitCUDAExt/MatrixAlgebraKitCUDAExt.jl‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ end
4242

4343
MatrixAlgebraKit.prefers_ungqr(::CUSOLVER) = true
4444

45+
# one kernel for the whole triangle instead of one per column
46+
function MatrixAlgebraKit.uppertriangular!(A::StridedCuMatrix)
47+
m, n = size(A)
48+
A .= ifelse.((1:m) .> transpose(1:n), zero(eltype(A)), A)
49+
return A
50+
end
51+
4552
MatrixAlgebraKit.supports_svd_full(::CUSOLVER, f::Symbol) = f in (:qr_iteration, :jacobi, :svd_polar)
4653

4754
# `cusolverDnXgesvdjBatched` only accepts matrices up to 32x32

0 commit comments

Comments
 (0)