SciML / AutoOffload.jl

Automatic GPU, TPU, FPGA, Xeon Phi, Multithreaded, Distributed, etc. offloading for scientific machine learning (SciML) and differential equations
https://benchmarks.sciml.ai/
MIT License
35 stars 4 forks source link

Some timing tests #8

Open ChrisRackauckas opened 4 years ago

ChrisRackauckas commented 4 years ago
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 commented 4 years ago

offloadtimes sparseoffloadtimes