Skip to content

Commit

Permalink
[GPU] Remove random tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Sep 13, 2022
1 parent b5c2ea9 commit bcbc6aa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
21 changes: 13 additions & 8 deletions test/gpu/amd.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using LinearAlgebra, SparseArrays, Test
using Krylov, AMDGPU

include("../test_utils.jl")

@testset "AMD -- AMDGPU.jl" begin

@test AMDGPU.functional()
Expand Down Expand Up @@ -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
23 changes: 14 additions & 9 deletions test/gpu/intel.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
21 changes: 13 additions & 8 deletions test/gpu/metal.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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
21 changes: 13 additions & 8 deletions test/gpu/nvidia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

0 comments on commit bcbc6aa

Please sign in to comment.