1 /*
2 * Copyright (c) 2007 - 2015 Joseph Gaeddert
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 #include <stdlib.h>
24 #include <sys/resource.h>
25 #include "liquid.h"
26
27 // Helper function to keep code base small
matrixf_linsolve_bench(struct rusage * _start,struct rusage * _finish,unsigned long int * _num_iterations,unsigned int _n)28 void matrixf_linsolve_bench(struct rusage * _start,
29 struct rusage * _finish,
30 unsigned long int * _num_iterations,
31 unsigned int _n)
32 {
33 // normalize number of iterations
34 // time ~ _n ^ 2
35 *_num_iterations /= _n * _n;
36 if (*_num_iterations < 1) *_num_iterations = 1;
37
38 unsigned long int i;
39
40 float A[_n*_n];
41 float b[_n];
42 float x[_n];
43 for (i=0; i<_n*_n; i++)
44 A[i] = randnf();
45 for (i=0; i<_n; i++)
46 b[i] = randnf();
47
48 // start trials
49 getrusage(RUSAGE_SELF, _start);
50 for (i=0; i<(*_num_iterations); i++) {
51 matrixf_linsolve(A,_n,b,x,NULL);
52 matrixf_linsolve(A,_n,b,x,NULL);
53 matrixf_linsolve(A,_n,b,x,NULL);
54 matrixf_linsolve(A,_n,b,x,NULL);
55 }
56 getrusage(RUSAGE_SELF, _finish);
57 *_num_iterations *= 4;
58 }
59
60 #define MATRIXF_LINSOLVE_BENCHMARK_API(N) \
61 ( struct rusage *_start, \
62 struct rusage *_finish, \
63 unsigned long int *_num_iterations) \
64 { matrixf_linsolve_bench(_start, _finish, _num_iterations, N); }
65
66 void benchmark_matrixf_linsolve_n2 MATRIXF_LINSOLVE_BENCHMARK_API(2)
67 void benchmark_matrixf_linsolve_n4 MATRIXF_LINSOLVE_BENCHMARK_API(4)
68 void benchmark_matrixf_linsolve_n8 MATRIXF_LINSOLVE_BENCHMARK_API(8)
69 void benchmark_matrixf_linsolve_n16 MATRIXF_LINSOLVE_BENCHMARK_API(16)
70 void benchmark_matrixf_linsolve_n32 MATRIXF_LINSOLVE_BENCHMARK_API(32)
71 void benchmark_matrixf_linsolve_n64 MATRIXF_LINSOLVE_BENCHMARK_API(64)
72
73