Skip to content

Commit

Permalink
Merge pull request #11 from triscale-innov/ff/more-tests
Browse files Browse the repository at this point in the history
More tests
  • Loading branch information
ffevotte authored Apr 20, 2020
2 parents 7819667 + 41c5fa3 commit 8134d67
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 27 deletions.
17 changes: 17 additions & 0 deletions src/overdub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,28 @@ for typ1 in (Float32, Float64)
end
end


# Relatively inefficient, but there should be no need for performance here...

flop(c::Counter) = sum(getfield(c, field) for field in fieldnames(Counter))

import Base: ==, *, show

function Base.show(io::IO, c::Counter)
println(io, "Flop Counter:")
for field in fieldnames(Counter)
println(io, " $field: $(getfield(c, field))")
end
end

function ==(c1::Counter, c2::Counter)
all(getfield(c1, field)==getfield(c2, field) for field in fieldnames(Counter))
end

function *(n::Int, c::Counter)
ret = Counter()
for field in fieldnames(Counter)
setfield!(ret, field, n*getfield(c, field))
end
ret
end
106 changes: 79 additions & 27 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,94 @@ Flop Counter:
end

@testset "@count_ops" begin
let
N = 100
a = 2.5
x = rand(N)
y = Vector{Float64}(undef, N)
@testset "mul+add 64" begin
let N = 100
a = 2.5
x = rand(N)
y = similar(x)

cnt = @count_ops my_axpy!(a, x, y)
@test cnt.add64 == N
@test cnt.mul64 == N
@test GFlops.flop(cnt) == 2*N


m = rand(N, N)
v = rand(N)

cnt = @count_ops(my_prod(m, v))
@test cnt.add64 == N*N
@test cnt.mul64 == N*N
@test GFlops.flop(cnt) == 2*N*N
end
end

@testset "mul+add 32" begin
let N = 100
a = 2.5f0
x = rand(Float32, N)
y = similar(x)

cnt = @count_ops my_axpy!(a, x, y)
@test cnt.add64 == 100
@test cnt.mul64 == 100
@test GFlops.flop(cnt) == 200
cnt = @count_ops my_axpy!(a, x, y)
@test cnt.add32 == N
@test cnt.mul32 == N
@test GFlops.flop(cnt) == 2*N


cnt = @count_ops my_axpy!(pi, $(rand(N)), y)
@test cnt.add64 == 100
@test cnt.mul64 == 100
@test GFlops.flop(cnt) == 200
m = rand(Float32, N, N)
v = rand(Float32, N)

cnt = @count_ops(my_prod(m, v))
@test cnt.add32 == N*N
@test cnt.mul32 == N*N
@test GFlops.flop(cnt) == 2*N*N
end
end

let
N = 100
m = rand(N, N)
v = rand(N)
cnt = @count_ops(my_prod(m, v))
@test cnt.add64 == N*N
@test cnt.mul64 == N*N
@test GFlops.flop(cnt) == 2*N*N
@testset "sqrt" begin
let cnt = @count_ops sqrt(4.2)
@test cnt.sqrt64 == 1
@test GFlops.flop(cnt) == 1
end

let cnt = @count_ops sqrt(4.2f0)
@test cnt.sqrt32 == 1
@test GFlops.flop(cnt) == 1
end
end

let cnt = @count_ops sqrt(4.2)
@test cnt.sqrt64 == 1
@test GFlops.flop(cnt) == 1
@testset "interpolated arguments" begin
let N = 100

T = Float64
cnt = @count_ops my_axpy!(pi, $(rand(T, N)), $(rand(T, N)))
@test cnt.add64 == N
@test cnt.mul64 == N
@test GFlops.flop(cnt) == 2*N

T = Float32
cnt = @count_ops my_axpy!(pi, $(rand(T, N)), $(rand(T, N)))
@test cnt.add32 == N
@test cnt.mul32 == N
@test GFlops.flop(cnt) == 2*N
end
end

let cnt = @count_ops sqrt(4.2f0)
@test cnt.sqrt32 == 1
@test GFlops.flop(cnt) == 1
@testset "broadcast" begin
let N = 100

x = 42.0
cnt1 = @count_ops sin(x)
cnt2 = @count_ops sin.($(fill(x, N)))
@test GFlops.flop(cnt1) != 0
@test cnt2 == N*cnt1

x = 42.0f0
cnt1 = @count_ops sin(x)
cnt2 = @count_ops sin.($(fill(x, N)))
@test GFlops.flop(cnt1) != 0
@test cnt2 == N*cnt1
end
end
end

Expand Down

0 comments on commit 8134d67

Please sign in to comment.