diff --git a/test/gpu/amd.jl b/test/gpu/amd.jl index c5dbdd0af..03ada1d4d 100644 --- a/test/gpu/amd.jl +++ b/test/gpu/amd.jl @@ -1,6 +1,8 @@ using LinearAlgebra, SparseArrays, Test using Krylov, AMDGPU +include("../test_utils.jl") + @testset "AMD -- AMDGPU.jl" begin @test AMDGPU.functional() @@ -67,20 +69,23 @@ using Krylov, AMDGPU # end ε = eps(T) - A = rand(FC, n, n) - A = ROCMatrix{FC}(A) - b = rand(FC, n) - b = ROCVector{FC}(b) + atol = √ε + rtol = √ε @testset "GMRES -- $FC" begin + A, b = nonsymmetric_indefinite(FC=FC) + A = ROCMatrix{FC}(A) + b = ROCVector{FC}(b) x, stats = gmres(A, b) - @test norm(b - A * x) ≤ √ε + @test norm(b - A * x) ≤ atol + rtol * norm(b) end @testset "CG -- $FC" begin - C = A * A' - x, stats = cg(C, b) - @test stats.solved + A, b = symmetric_definite(FC=FC) + A = ROCMatrix{FC}(A) + b = ROCVector{FC}(b) + x, stats = cg(A, b) + @test norm(b - A * x) ≤ atol + rtol * norm(b) end end end diff --git a/test/gpu/intel.jl b/test/gpu/intel.jl index 12d9232fd..e6826e9e9 100644 --- a/test/gpu/intel.jl +++ b/test/gpu/intel.jl @@ -1,8 +1,10 @@ using LinearAlgebra, SparseArrays, Test using Krylov, oneAPI -# https://github.com/JuliaGPU/GPUArrays.jl/pull/427 +include("../test_utils.jl") + import Krylov.kdot +# https://github.com/JuliaGPU/GPUArrays.jl/pull/427 function kdot(n :: Integer, x :: oneVector{T}, dx :: Integer, y :: oneVector{T}, dy :: Integer) where T <: Krylov.FloatOrComplex return mapreduce(dot, +, x, y) end @@ -75,20 +77,23 @@ end # end ε = eps(T) - A = rand(FC, n, n) - A = oneMatrix{FC}(A) - b = rand(FC, n) - b = oneVector{FC}(b) + atol = √ε + rtol = √ε @testset "GMRES -- $FC" begin + A, b = nonsymmetric_indefinite(FC=FC) + A = oneMatrix{FC}(A) + b = oneVector{FC}(b) x, stats = gmres(A, b) - @test norm(b - A * x) ≤ √ε + @test norm(b - A * x) ≤ atol + rtol * norm(b) end @testset "CG -- $FC" begin - C = A * A' - x, stats = cg(C, b) - @test stats.solved + A, b = symmetric_definite(FC=FC) + A = oneMatrix{FC}(A) + b = oneVector{FC}(b) + x, stats = cg(A, b) + @test norm(b - A * x) ≤ atol + rtol * norm(b) end end end diff --git a/test/gpu/metal.jl b/test/gpu/metal.jl index 9e7f101d1..774ccc10c 100644 --- a/test/gpu/metal.jl +++ b/test/gpu/metal.jl @@ -1,6 +1,8 @@ using LinearAlgebra, SparseArrays, Test using Krylov, Metal +include("../test_utils.jl") + # https://github.com/JuliaGPU/Metal.jl/pull/48 const MtlVector{T} = MtlArray{T,1} const MtlMatrix{T} = MtlArray{T,2} @@ -79,20 +81,23 @@ end # end ε = eps(T) - A = rand(FC, n, n) - A = MtlMatrix{FC}(A) - b = rand(FC, n) - b = MtlVector{FC}(b) + atol = √ε + rtol = √ε @testset "GMRES -- $FC" begin + A, b = nonsymmetric_indefinite(FC=FC) + A = MtlMatrix{FC}(A) + b = MtlVector{FC}(b) x, stats = gmres(A, b) - @test norm(b - A * x) ≤ √ε + @test norm(b - A * x) ≤ atol + rtol * norm(b) end @testset "CG -- $FC" begin - C = A * A' - x, stats = cg(C, b) - @test stats.solved + A, b = symmetric_definite(FC=FC) + A = MtlMatrix{FC}(A) + b = MtlVector{FC}(b) + x, stats = cg(A, b) + @test norm(b - A * x) ≤ atol + rtol * norm(b) end end end diff --git a/test/gpu/nvidia.jl b/test/gpu/nvidia.jl index 33e0a4ba8..8dfb61b0f 100644 --- a/test/gpu/nvidia.jl +++ b/test/gpu/nvidia.jl @@ -3,6 +3,8 @@ using LinearOperators, Krylov, CUDA, CUDA.CUSPARSE, CUDA.CUSOLVER include("../test_utils.jl") +include("../test_utils.jl") + @testset "Nvidia -- CUDA.jl" begin @test CUDA.functional() @@ -145,20 +147,23 @@ include("../test_utils.jl") end ε = eps(T) - A = rand(FC, n, n) - A = CuMatrix{FC}(A) - b = rand(FC, n) - b = CuVector{FC}(b) + atol = √ε + rtol = √ε @testset "GMRES -- $FC" begin + A, b = nonsymmetric_indefinite(FC=FC) + A = CuMatrix{FC}(A) + b = CuVector{FC}(b) x, stats = gmres(A, b) - @test norm(b - A * x) ≤ √ε + @test norm(b - A * x) ≤ atol + rtol * norm(b) end @testset "CG -- $FC" begin - C = A * A' - x, stats = cg(C, b) - @test stats.solved + A, b = symmetric_definite(FC=FC) + A = CuMatrix{FC}(A) + b = CuVector{FC}(b) + x, stats = cg(A, b) + @test norm(b - A * x) ≤ atol + rtol * norm(b) end end end