Skip to content
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
57 changes: 43 additions & 14 deletions examples/benchmarks/bench_blas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,57 @@

import sys
from time import time
from arrayfire import (array, randu, matmul)
import arrayfire as af

def bench(A, iters = 100):
start = time()
for t in range(iters):
B = af.matmul(A, A)
try:
import numpy as np
except:
np = None


def calc_arrayfire(n):
A = af.randu(n, n)
af.sync()
return (time() - start) / iters

def run(iters):
for t in range(iters):
B = af.matmul(A, A)
af.sync()

return run


def calc_numpy(n):
np.random.seed(1)
A = np.random.rand(n, n).astype(np.float32)

def run(iters):
for t in range(iters):
B = np.dot(A, A)

return run


def bench(calc, iters=100, upto=2048):
_, name = calc.__name__.split("_")
print("Benchmark N x N matrix multiply on %s" % name)

for n in range(128, upto + 128, 128):
run = calc(n)
start = time()
run(iters)
t = (time() - start) / iters
gflops = 2.0 * (n ** 3) / (t * 1E9)
print("Time taken for %4d x %4d: %0.4f Gflops" % (n, n, gflops))


if __name__ == "__main__":

if (len(sys.argv) > 1):
af.set_device(int(sys.argv[1]))

af.info()
print("Benchmark N x N matrix multiply")

for n in range(128, 2048 + 128, 128):
A = af.randu(n, n)
af.sync()

t = bench(A)
gflops = 2.0 * (n**3) / (t * 1E9)
print("Time taken for %4d x %4d: %0.4f Gflops" % (n, n, gflops))
bench(calc_arrayfire)
if np:
bench(calc_numpy, upto=512)
60 changes: 45 additions & 15 deletions examples/benchmarks/bench_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,59 @@

import sys
from time import time
from arrayfire import (array, randu, matmul)
import arrayfire as af

def bench(A, iters = 100):
start = time()
for t in range(iters):
B = af.fft2(A)
try:
import numpy as np
except:
np = None


def calc_arrayfire(n):
A = af.randu(n, n)
af.sync()
return (time() - start) / iters

def run(iters):
for t in range(iters):
B = af.fft2(A)

af.sync()

return run


def calc_numpy(n):
np.random.seed(1)
A = np.random.rand(n, n).astype(np.float32)

def run(iters):
for t in range(iters):
B = np.fft.fft2(A)

return run


def bench(calc, iters=100, upto=13):
_, name = calc.__name__.split("_")
print("Benchmark N x N 2D fft on %s" % name)

for M in range(7, upto):
N = 1 << M
run = calc(N)
start = time()
run(iters)
t = (time() - start) / iters
gflops = (10.0 * N * N * M) / (t * 1E9)
print("Time taken for %4d x %4d: %0.4f Gflops" % (N, N, gflops))


if __name__ == "__main__":

if (len(sys.argv) > 1):
af.set_device(int(sys.argv[1]))

af.info()
print("Benchmark N x N 2D fft")

for M in range(7, 13):
N = 1 << M
A = af.randu(N, N)
af.sync()

t = bench(A)
gflops = (10.0 * N * N * M) / (t * 1E9)
print("Time taken for %4d x %4d: %0.4f Gflops" % (N, N, gflops))
bench(calc_arrayfire)
if np:
bench(calc_numpy, upto=10)