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

update laplace benchmark to use fused dotops #52

Merged
merged 1 commit into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions src/broadcast/BroadcastBenchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
module BroadcastBenchmarks

include(joinpath(dirname(@__FILE__), "..", "utils", "RandUtils.jl"))
include(joinpath("..", "utils", "RandUtils.jl"))
include(joinpath("..", "utils", "CompatUtils.jl"))

using .RandUtils
using .RandUtils, .CompatUtils
using BenchmarkTools
using Compat

const SUITE = BenchmarkGroup()

# work around lack of Compat support for .= (Compat.jl issue #285)
if VERSION < v"0.5.0-dev+5575" #17510
macro dotcompat(ex)
if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.=
:(copy!($(esc(ex.args[1])), $(esc(ex.args[3]))))
else
esc(ex)
end
end
else
macro dotcompat(ex)
esc(ex)
end
end

###########################################################################

g = addgroup!(SUITE, "fusion", ["broadcast!", "array"])
Expand Down
12 changes: 10 additions & 2 deletions src/problem/Laplacian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ using Compat

import Compat: UTF8String, view

include(joinpath("..", "utils", "CompatUtils.jl"))
using .CompatUtils

################################
# Sparse Matrix * Dense Vector #
################################
Expand Down Expand Up @@ -76,7 +79,7 @@ function perf_laplace_iter_vec(N)
Niter = 2^10
dx2 = dy2 = 0.1*0.1
for i = 1:Niter
u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1, 1:N-2] + u[2:N-1, 3:N])*dx2) * (1 / (2*(dx2+dy2)))
@dotcompat u[2:N-1, 2:N-1] .= ((u[1:N-2, 2:N-1] .+ u[3:N, 2:N-1]).*dy2 .+ (u[2:N-1, 1:N-2] .+ u[2:N-1, 3:N]).*dx2) .* (1 / (2*(dx2+dy2)))
end
return u
end
Expand All @@ -86,8 +89,13 @@ function perf_laplace_iter_sub(N)
u[1,:] = 1
Niter = 2^10
dx2 = dy2 = 0.1*0.1
u0 = view(u, 2:N-1, 2:N-1)
u1 = view(u, 1:N-2, 2:N-1)
u2 = view(u, 3:N, 2:N-1)
u3 = view(u, 2:N-1, 1:N-2)
u4 = view(u, 2:N-1, 3:N)
for i = 1:Niter
u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1, 1:N-2) + view(u, 2:N-1, 3:N))*dx2) * (1 / (2*(dx2+dy2)))
@dotcompat u0 .= ((u1 .+ u2).*dy2 .+ (u3 .+ u4).*dx2) .* (1 / (2*(dx2+dy2)))
end
return u
end
Expand Down
16 changes: 2 additions & 14 deletions src/shootout/nbody_vec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@

module NBodyVec

# work around lack of Compat support for .= (Compat.jl issue #285)
if VERSION < v"0.5.0-dev+5575" #17510
macro dotcompat(ex)
if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.=
:(copy!($(esc(ex.args[1])), $(esc(ex.args[3]))))
else
esc(ex)
end
end
else
macro dotcompat(ex)
esc(ex)
end
end
include(joinpath("..", "utils", "CompatUtils.jl"))
using .CompatUtils

# Constants
const solar_mass = 4 * pi * pi
Expand Down
20 changes: 20 additions & 0 deletions src/utils/CompatUtils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module CompatUtils

export @dotcompat

# work around lack of Compat support for .= (Compat.jl issue #285)
if VERSION < v"0.5.0-dev+5575" #17510
macro dotcompat(ex)
if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.=
:(copy!($(esc(ex.args[1])), $(esc(ex.args[3]))))
else
esc(ex)
end
end
else
macro dotcompat(ex)
esc(ex)
end
end

end