Author: Hakan Ardo <ha...@debian.org> Branch: extradoc Changeset: r4522:1d7c4e17e6f1 Date: 2012-08-12 10:25 +0200 http://bitbucket.org/pypy/extradoc/changeset/1d7c4e17e6f1/
Log: added SparseMatMult benchmark diff --git a/talk/iwtc11/benchmarks/benchmark.sh b/talk/iwtc11/benchmarks/benchmark.sh --- a/talk/iwtc11/benchmarks/benchmark.sh +++ b/talk/iwtc11/benchmarks/benchmark.sh @@ -18,6 +18,8 @@ ./runner.py -n 5 -c "$* -lstdc++" image/sobel.cc 1000 1000 ./runner.py -n 5 -c "$*" scimark/run_SOR.c 100 32768 ./runner.py -n 5 -c "$*" scimark/run_SOR.c 1000 256 + ./runner.py -n 5 -c "$*" scimark/run_SparseMatMult.c 1000 5000 262144 + ./runner.py -n 5 -c "$*" scimark/run_SparseMatMult.c 100000 1000000 1024 rm a.out else if [ "$1" == "python2.7" ]; then @@ -49,4 +51,6 @@ #$* ./runner.py $EXTRA_OPTS image/sobel.py main NoBorderImagePadded uint8 $* ./runner.py $EXTRA_OPTS scimark.py SOR 100 32768 $* ./runner.py $EXTRA_OPTS scimark.py SOR 1000 256 + $* ./runner.py $EXTRA_OPTS scimark.py SparseMatMult 1000 5000 262144 + $* ./runner.py $EXTRA_OPTS scimark.py SparseMatMult 100000 1000000 1024 fi diff --git a/talk/iwtc11/benchmarks/runner.py b/talk/iwtc11/benchmarks/runner.py --- a/talk/iwtc11/benchmarks/runner.py +++ b/talk/iwtc11/benchmarks/runner.py @@ -29,7 +29,7 @@ except ImportError: pass else: - pypyjit.set_param(trace_limit=200000) + pypyjit.set_param(trace_limit=200000, threshold=1039) if args[0].endswith('.py'): mod = py.path.local(args[0]).pyimport() sys.stderr.write("warming up") diff --git a/talk/iwtc11/benchmarks/scimark.py b/talk/iwtc11/benchmarks/scimark.py --- a/talk/iwtc11/benchmarks/scimark.py +++ b/talk/iwtc11/benchmarks/scimark.py @@ -1,4 +1,5 @@ from convolution.convolution import Array2D +from array import array def SOR_execute(omega, G, num_iterations): for p in xrange(num_iterations): @@ -12,3 +13,35 @@ SOR_execute(1.25, a, cycles) return "SOR(%d, %d)" % (n, cycles) + +def SparseCompRow_matmult(M, y, val, row, col, x, num_iterations): + for reps in xrange(num_iterations): + for r in xrange(M): + sa = 0.0 + for i in xrange(row[r], row[r+1]): + sa += x[ col[i] ] * val[i] + y[r] = sa + +def SparseMatMult(args): + N, nz, cycles = map(int, args) + x = array('d', [0]) * N + y = array('d', [0]) * N + result = 0.0 + nr = nz / N + anz = nr * N + val = array('d', [0]) * anz + col = array('i', [0]) * nz + row = array('i', [0]) * (N + 1) + row[0] = 0 + for r in xrange(N): + rowr = row[r] + step = r / nr + row[r+1] = rowr + nr + if (step < 1): + step = 1 + for i in xrange(nr): + col[rowr + i] = i * step + SparseCompRow_matmult(N, y, val, row, col, x, cycles); + return "SparseMatMult(%d, %d, %d)" % (N, nz, cycles) + + diff --git a/talk/iwtc11/benchmarks/scimark/kernel.c b/talk/iwtc11/benchmarks/scimark/kernel.c --- a/talk/iwtc11/benchmarks/scimark/kernel.c +++ b/talk/iwtc11/benchmarks/scimark/kernel.c @@ -170,6 +170,7 @@ cycles *= 2; } + printf("SparseMatMult: N=%d, nz=%d, cycles=%d\n", N, nz, cycles); /* approx Mflops */ result = SparseCompRow_num_flops(N, nz, cycles) / Stopwatch_read(Q) * 1.0e-6; diff --git a/talk/iwtc11/benchmarks/scimark/run_SparseMatMult.c b/talk/iwtc11/benchmarks/scimark/run_SparseMatMult.c new file mode 100644 --- /dev/null +++ b/talk/iwtc11/benchmarks/scimark/run_SparseMatMult.c @@ -0,0 +1,50 @@ +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> + +#include "SparseCompRow.c" + +int main(int ac, char **av) { + assert(ac==4); + int N = atoi(av[1]); + int nz = atoi(av[2]); + int cycles = atoi(av[3]); + + double *x = (double*) malloc(sizeof(double)*N); //RandomVector(N, R); + double *y = (double*) malloc(sizeof(double)*N); + + double result = 0.0; + + int nr = nz/N; /* average number of nonzeros per row */ + int anz = nr *N; /* _actual_ number of nonzeros */ + + + double *val = (double *) malloc(sizeof(double)*anz); //RandomVector(anz, R); + int *col = (int*) malloc(sizeof(int)*nz); + int *row = (int*) malloc(sizeof(int)*(N+1)); + int r=0; + + row[0] = 0; + for (r=0; r<N; r++) + { + /* initialize elements for row r */ + + int rowr = row[r]; + int step = r/ nr; + int i=0; + + row[r+1] = rowr + nr; + if (step < 1) step = 1; /* take at least unit steps */ + + + for (i=0; i<nr; i++) + col[rowr+i] = i*step; + + } + + SparseCompRow_matmult(N, y, val, row, col, x, cycles); + fprintf(stderr, "SparseMatMult(%d, %d, %d): ", N, nz, cycles); + return 0; +} + + _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit