Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest #12

Merged
merged 10 commits into from
Dec 20, 2019
2 changes: 1 addition & 1 deletion src/DistStat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function __init__()
@require CUDAnative="be33ccc6-a3ff-5ff2-a52e-74243cff1e17" begin
include("cuda.jl")
set_device!()
CuArrays.allowscalar(false)
#CuArrays.allowscalar(false)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/distlinalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ end
function LinearAlgebra.mul!(C::AbstractVector{T}, A::Transpose{T, MPIMatrix{T,AT}}, B::AbstractVector{T}) where {T,AT}
localA = get_local(A)
fill!(C, zero(T))
LinearAlgebra.mul!(C[transpose(A).partitioning[Rank()+1][2]], localA, B[transpose(A).partitioning[Rank()+1][1]])
LinearAlgebra.mul!(@view(C[transpose(A).partitioning[Rank()+1][2]]), localA, B[transpose(A).partitioning[Rank()+1][1]])
sync()
Allreduce!(C)
C
Expand Down
37 changes: 37 additions & 0 deletions test/test_aux.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using DistStat, Random, Test, Pkg

type=[Float32,Float64]

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
else
ArrayType = Array
end

for T in type
A=ArrayType{T}(undef,7,10)
A_dist=distribute(A)
fill!(A, 1.0)
fill!(A_dist,1.0)
cols1=A_dist.partitioning[DistStat.Rank()+1][2]

@test isapprox(A_dist.localarray,A[:,cols1])

B=ArrayType{T}(reshape(collect(1:70), 7, 10))
B_dist=distribute(B)
cols2=B_dist.partitioning[DistStat.Rank()+1][2]

@test isapprox(B_dist.localarray,B[:,cols2])

C_dist = MPIArray{T, 2, ArrayType}(undef, 7, 9)
cols3=C_dist.partitioning[DistStat.Rank()+1][2]
randn!(C_dist; seed=0,common_init=true)

C=Array{T}(undef,size(C_dist))
Random.seed!(0)
randn!(C)

@test isapprox(C_dist.localarray, ArrayType{T}(C[:,cols3]))

end
23 changes: 23 additions & 0 deletions test/test_distribute.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Pkg, Test, DistStat

type=[Float64,Float32]

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
else
ArrayType = Array
end

for T in type

data =ArrayType{T}(reshape(collect(1:42),6,7))
data_dist1 = distribute(data)
data_dist2 = distribute(ArrayType{T}(transpose(data)))
cols1=data_dist1.partitioning[DistStat.Rank()+1][2]
cols2=data_dist2.partitioning[DistStat.Rank()+1][2]

@test data_dist1.localarray==data[:,cols1]
@test data_dist2.localarray==(ArrayType{T}(transpose(data)))[:,cols2]

end
24 changes: 24 additions & 0 deletions test/test_dot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using DistStat, Random, Test, LinearAlgebra

type=[Float32,Float64]

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
else
ArrayType = Array
end

for T in type
A=ArrayType{T}(reshape(collect(1:36),4,9))
B=ArrayType{T}(reshape(collect(-7:28),4,9))

A_dist=distribute(A); B_dist=distribute(B)

@test isapprox(LinearAlgebra.dot(A_dist,B_dist),LinearAlgebra.dot(A,B))

A_vec=vec(A); B_vec=vec(B)

@test isapprox(LinearAlgebra.dot(A_dist,B_dist),LinearAlgebra.dot(A_vec,B_vec))

end
39 changes: 39 additions & 0 deletions test/test_mul2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using DistStat, LinearAlgebra, Test, Random

type=[Float32,Float64]

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
else
ArrayType = Array
end

for T in type

A=ArrayType{T}(reshape(collect(1:63),7,9))
B=ArrayType{T}(reshape(collect(-31:31),7,9))
A_dist=distribute(A)
B_dist=distribute(B)
B_distt=distribute(ArrayType{T}(transpose(B)))

C=MPIMatrix{T,ArrayType}(undef,9,9)
cols1=B_dist.partitioning[DistStat.Rank()+1][2]
cols2=B_distt.partitioning[DistStat.Rank()+1][2]

result1=LinearAlgebra.mul!(C,transpose(A),B_dist)
ans1=transpose(A)*B

@test isapprox(result1.localarray, ans1[:,cols1])

result2=LinearAlgebra.mul!(transpose(C),transpose(A_dist),B)
@test isapprox(result2.localarray, ArrayType{T}(transpose(ans1))[:,cols1])


B_vec = ArrayType{T}(collect(1:7))
C_vec = ArrayType{T}(undef, 9)
LinearAlgebra.mul!(C_vec, transpose(A_dist), B_vec)
C_true = transpose(A) * B_vec
@test isapprox(C_vec, C_true)

end
20 changes: 20 additions & 0 deletions test/test_opnorm2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using DistStat, LinearAlgebra, Test

type=[Float32,Float64]

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
else
ArrayType = Array
end

for T in type
A=ArrayType{T}(reshape(collect(1:45),5,9))
A_dist=distribute(A)

@test isapprox(opnorm(A_dist,1),opnorm(A,1))
@test isapprox(opnorm(A_dist,2),opnorm(A,2))
@test isapprox(opnorm(A_dist,Inf),opnorm(A,Inf))

end