Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Some timing tests #8

Open
ChrisRackauckas opened this issue Jun 12, 2020 · 1 comment
Open

Some timing tests #8

ChrisRackauckas opened this issue Jun 12, 2020 · 1 comment

Comments

@ChrisRackauckas
Copy link
Member

using CUDAdrv, CuArrays, SparseArrays, LinearAlgebra, BenchmarkTools, Plots

##############
## Dense
##############

function offload_solve(A,b,c)
    Array(cu(A)\cu(b)) + c
end

times = zeros(14,2)

for n in 1:14
    global times
    A = rand(2^n,2^n)
    b = rand(2^n)
    c = rand(2^n)
    times[n,1] = @belapsed $A\$b + $c
    times[n,2] = @belapsed offload_solve($A,$b,$c)
end

plot(2 .^ (1:14), times, lw = 3, yscale=:log10, xlabel = "N",
            ylabel = "Time (s)",
            title = "Linear Solve Offload Benchmarks",
            labels = ["CPU" "AutoOffload GPU"],
            legend = :topleft)
savefig("offloadtimes.png")
acceleration = times[:,1] ./ times[:,2]

plot(2 .^ (1:14), acceleration, lw = 3, yscale=:log10, xlabel = "N",
            ylabel = "Fold Speedup (s)",
            title = "Linear Solve AutoOffload Acceleration",
            legend = :topleft)

###############
## (Biological) Sparse
###############

times = zeros(5,2)

n = 10
A = sprand(2^n,2^n,0.01)
b = rand(2^n)
c = rand(2^n)
@btime A\b + c
@btime offload_solve(A,b,c)

for i in 1:5
    n = i + 9
    global times
    A = sprand(2^n,2^n,0.01)
    b = rand(2^n)
    c = rand(2^n)
    times[i,1] = @belapsed $A\$b + $c
    times[i,2] = @belapsed offload_solve($A,$b,$c)
end

times

plot(2 .^ (10:14), times, lw = 3, yscale=:log10, xlabel = "N",
            ylabel = "Time (s)",
            title = "Sparse Linear Solve Offload Benchmarks",
            labels = ["CPU" "AutoOffload GPU"],
            legend = :topleft)
savefig("sparseoffloadtimes.png")
acceleration = times[:,1] ./ times[:,2]

plot(2 .^ (10:14), acceleration, lw = 3, yscale=:log10, xlabel = "N",
            ylabel = "Fold Speedup (s)",
            title = "Sparse Linear Solve AutoOffload Acceleration",
            legend = :topleft)

##################
## 2D PDE
##################

n = 6
N = 2^n
Mx = sparse(Tridiagonal([1.0 for i in 1:N-1],[-2.0 for i in 1:N],[1.0 for i in 1:N-1]))
My = copy(Mx)
Mx[1,end] = 2.0
Mx[end,1] = 2.0
My[1,end] = 2.0
My[end,1] = 2.0

Ix = SparseMatrixCSC(I,N,N)
Iy = SparseMatrixCSC(I,N,N)
fJ = ones(2,2)
Dz = [1 0
      0 1]
A = kron(Dz,Iy,sparse(Mx)) + kron(Dz,sparse(My),Ix) + kron(fJ,Iy,Ix)
b = rand(size(A,2))
c = copy(b)

@btime A\b + c
@btime offload_solve(A,b,c)
@ChrisRackauckas
Copy link
Member Author

offloadtimes
sparseoffloadtimes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant