Skip to content

Commit

Permalink
added benchmark examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Jul 6, 2018
1 parent 3aad9d9 commit 4709646
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
54 changes: 54 additions & 0 deletions examples/matrix_matrix_multiplication.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using OpenCL, CLBLAS, CLBlast, BenchmarkTools

CLBLAS.setup()

function run_gemm(m::Integer, n::Integer, k::Integer, T=Float32)
srand(12345)
A = rand(T, m, k)
B = rand(T, k, n)
C = rand(T, m, n)
α = rand(T)
β = rand(T)

@printf("\nm = %d, n = %d, k = %d, eltype = %s\n", m, n, k, T)

println("BLAS:")
C_true = copy(C)
LinAlg.BLAS.gemm!('N', 'N', α, A, B, β, C_true)
CC = copy(C)
display(@benchmark LinAlg.BLAS.gemm!($('N'), $('N'), $α, $A, $B, $β, $CC))
println()

for device in cl.devices()
println("-"^70)
@printf("Platform name : %s\n", device[:platform][:name])
@printf("Platform version: %s\n", device[:platform][:version])
@printf("Device name : %s\n", device[:name])
@printf("Device type : %s\n", device[:device_type])
println()

ctx = cl.Context(device)
queue = cl.CmdQueue(ctx)

println("CLBLAS:")
A_cl = cl.CLArray(queue, A)
B_cl = cl.CLArray(queue, B)
C_cl = cl.CLArray(queue, C)
CLBLAS.gemm!('N', 'N', α, A_cl, B_cl, β, C_cl)
@assert cl.to_host(C_cl) C_true
display(@benchmark CLBLAS.gemm!($('N'), $('N'), $α, $A_cl, $B_cl, $β, $C_cl))
println()


println("CLBlast:")
A_cl = cl.CLArray(queue, A)
B_cl = cl.CLArray(queue, B)
C_cl = cl.CLArray(queue, C)
CLBlast.gemm!('N', 'N', α, A_cl, B_cl, β, C_cl)
@assert cl.to_host(C_cl) C_true
display(@benchmark CLBlast.gemm!($('N'), $('N'), $α, $A_cl, $B_cl, $β, $C_cl))
println()
end
end

run_gemm(2^10, 2^10, 2^10, Float32)
53 changes: 53 additions & 0 deletions examples/matrix_vector_multiplication.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using OpenCL, CLBLAS, CLBlast, BenchmarkTools

CLBLAS.setup()

function run_gemv(m::Integer, n::Integer, T=Float32)
srand(12345)
A = rand(T, m, n)
y = rand(T, m)
x = rand(T, n)
α = rand(T)
β = rand(T)

@printf("\nm = %d, n = %d, eltype = %s\n", m, n, T)

println("BLAS:")
y_true = copy(y)
LinAlg.BLAS.gemv!('N', α, A, x, β, y_true)
yy = copy(y)
display(@benchmark LinAlg.BLAS.gemv!($('N'), $α, $A, $x, $β, $yy))
println()

for device in cl.devices()
println("-"^70)
@printf("Platform name : %s\n", device[:platform][:name])
@printf("Platform version: %s\n", device[:platform][:version])
@printf("Device name : %s\n", device[:name])
@printf("Device type : %s\n", device[:device_type])
println()

ctx = cl.Context(device)
queue = cl.CmdQueue(ctx)

println("CLBLAS:")
A_cl = cl.CLArray(queue, A)
y_cl = cl.CLArray(queue, y)
x_cl = cl.CLArray(queue, x)
CLBLAS.gemv!('N', α, A_cl, x_cl, β, y_cl)
@assert cl.to_host(y_cl) y_true
display(@benchmark CLBLAS.gemv!($('N'), $α, $A_cl, $x_cl, $β, $y_cl))
println()

println("CLBlast:")
A_cl = cl.CLArray(queue, A)
y_cl = cl.CLArray(queue, y)
x_cl = cl.CLArray(queue, x)
CLBlast.gemv!('N', α, A_cl, x_cl, β, y_cl)
@assert cl.to_host(y_cl) y_true
display(@benchmark CLBlast.gemv!($('N'), $α, $A_cl, $x_cl, $β, $y_cl))
println()
end
end

run_gemv(2^10, 2^10, Float32)
2 changes: 1 addition & 1 deletion src/L3/gemm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ for (func, elty) in [(:CLBlastSgemm, Float32), (:CLBlastDgemm, Float64),
layout = CLBlastLayoutColMajor

# output event
event::cl.event::cl.Event = cl.Event(C_NULL)
event::cl.Event = cl.Event(C_NULL)

$func(layout, a_transpose, b_transpose,
m, n, ka,
Expand Down

0 comments on commit 4709646

Please sign in to comment.