Debian Codegraph @

benchmarks/benchmark-fsyrk.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * Written by Clément Pernet <[email protected]>
3 * ========LICENCE========
4 * This file is part of the library FFLAS-FFPACK.
5 *
6 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * ========LICENCE========
20 */
21
22 // declare that the call to openblas_set_numthread will be made here, hence don't do it
23 // everywhere in the call stack
24 #define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1
25
26 #include "fflas-ffpack/fflas-ffpack-config.h"
27 #include <iostream>
28 #include <givaro/modular.h>
29
30 #include "fflas-ffpack/fflas-ffpack.h"
31 #include "fflas-ffpack/utils/timer.h"
32 #include "fflas-ffpack/utils/args-parser.h"
33
34
35 using namespace std;
36 using namespace FFLAS;
37 using namespace FFPACK;
38 int main(int argc, char** argv) {
39
40 #ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS
41 openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS);
42 #endif
43
44 size_t iter = 3;
45 size_t q = 131071;
46 size_t n = 1000;
47 size_t k = 1000;
48 size_t algo = 0;
49 size_t threshold = 64;
50 bool up =true;
51 std::string file = "";
52
53 Argument as[] = {
54 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
55 { 'n', "-n N", "Set the dimension of the matrix C.", TYPE_INT , &n },
56 { 'k', "-k K", "Set the other dimension of the matrix A.", TYPE_INT , &k },
57 { 'u', "-u yes/no", "Updates an upper/lower triangular matrix.", TYPE_BOOL , &up },
58 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
59 { 'a', "-a A", "Set algorithmic variant.", TYPE_INT , &algo },
60 { 't', "-t T", "Set the threshold to the base case.", TYPE_INT , &threshold },
61 END_OF_ARGUMENTS
62 };
63
64 FFLAS::parseArguments(argc,argv,as);
65
66 typedef Givaro::ModularBalanced<double> Field;
67 typedef Field::Element Element;
68
69 Field F(q);
70 Field::Element * A, *C;
71
72 FFLAS::Timer chrono;
73 double time=0.0;
74
75 FFLAS_UPLO uplo = up?FflasUpper:FflasLower;
76 for (size_t i=0;i<=iter;++i){
77 A = fflas_new<Element>(n*k);
78 size_t lda=k;
79 C = fflas_new<Element>(n*n);
80 size_t ldc=n;
81 Field::RandIter G(F);
82 RandomMatrix (F, n, k, A, k, G);
83 RandomTriangularMatrix (F, n,n,uplo, FflasNonUnit, true, C, ldc, G);
84 Field::Element_ptr D = FFLAS::fflas_new(F,k,1);
85 Givaro::GeneralRingNonZeroRandIter<Field,Field::RandIter> nzG (G);
86 std::vector<bool> twoBlocks(k);
87 for (size_t i=0; i<k; i++)
88 nzG.random(D[i]);
89 chrono.clear();
90 if (i) chrono.start();
91 switch (algo){
92 case 0: // fsyrk with no diagonal scaling
93 fsyrk (F, uplo, FflasNoTrans, n, k, F.mOne, A, lda, F.one, C, ldc);
94 break;
95 case 1: // fsyrk with diagonal scaling
96 fsyrk (F, uplo, FflasNoTrans, n, k, F.mOne, A, lda, D, 1, F.one, C, ldc, threshold);
97 break;
98 case 2: // fsyrk with diagonal scaling and 2x2 diagonal blocks
99 fsyrk (F, uplo, FflasNoTrans, n, k, F.one, A, lda, D, 1, twoBlocks, F.zero, C, ldc, threshold);
100 break;
101 case 3: // fsyrk with Strassen and no diagonal scaling
102 {
103 size_t reclevel = 0;
104 size_t dim = n;
105 while(dim > threshold) {reclevel++; dim>>=1;}
106 MMHelper<Field, MMHelperAlgo::Winograd> H(F,reclevel);
107 fsyrk (F, uplo, FflasNoTrans, n, k, F.one, A, lda, F.zero, C, ldc, H);
108 break;
109 }
110 case 4: // cblas_dsyrk
111 cblas_dsyrk (CblasRowMajor, (CBLAS_UPLO) uplo, (CBLAS_TRANSPOSE) FflasNoTrans, n, k, 1.0, A, lda, 0.0, C, ldc);
112 break;
113 case 5: // fsyrk with the classic Divide and conquer algorithm
114 size_t reclevel = 0;
115 size_t dim = n;
116 while(dim > threshold) {reclevel++; dim>>=1;}
117 MMHelper<Field, MMHelperAlgo::DivideAndConquer> H(F,reclevel);
118 fsyrk (F, uplo, FflasNoTrans, n, k, F.one, A, lda, F.zero, C, ldc, H);
119 break;
120 }
121 if (i) chrono.stop();
122
123 time+=chrono.usertime();
124 FFLAS::fflas_delete( A);
125 FFLAS::fflas_delete( C);
126 FFLAS::fflas_delete( D);
127 }
128
129 // -----------
130 // Standard output for benchmark - Alexis Breust 2014/11/14
131 std::cout << "Time: " << time / double(iter)
132 << " Gfops: " << (double(n)/1000.)*(double(n)/1000.)*(double(k)/1000.)/ time * double(iter);
133 FFLAS::writeCommandString(std::cout, as) << std::endl;
134 return 0;
135 }
136 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
137 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s