Skip to content

SVD not consistently working with ROCArrays #837

Description

@abussy

I have noticed that SVD does not consistently produce correct numerical results with ROCArrays as input. As a result, calculating the condition number of a matrix also fails.

Below is a reproducer. These tests fail more often than not.

using LinearAlgebra
using AMDGPU

cpu = randn(10, 10)
gpu = ROCArray(cpu)

for i in 1:5
    cpu_vals = svd(cpu).S
    gpu_vals = Vector(svd(gpu).S)
    println("Test #$i:")
    println("SVD equal? ", cpu_vals ≈ gpu_vals)
    println("Cond equal? ", cond(cpu) ≈ cond(gpu))
end

I managed to track it down to the LinearAlgebra.LAPACK.gesdd! function being called under the hood. rocSOLVER only implements the generic gesvd!. If I define the following in my code (or the above test), everything works fine:

function LinearAlgebra.LAPACK.gesdd!(jobz::Char, A::AMDGPU.ROCArray{T}) where {T}
    AMDGPU.rocSOLVER.gesvd!(jobz, jobz, A)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions