This file is indexed.

/usr/include/faust/dsp/dsp-bench.h is in faust-common 0.9.95~repack1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/************************************************************************
    FAUST Architecture File
    Copyright (C) 2016 GRAME, Centre National de Creation Musicale
    ---------------------------------------------------------------------
    This Architecture section is free software; you can redistribute it
    and/or modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 3 of
    the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; If not, see <http://www.gnu.org/licenses/>.

    EXCEPTION : As a special exception, you may create a larger work
    that contains this FAUST architecture section and distribute
    that work under terms of your choice, so long as this FAUST
    architecture section is not modified.
 
************************************************************************/

#ifndef __dsp_bench__
#define __dsp_bench__

#include <limits.h>
#include <sys/time.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <string.h>

#include "faust/dsp/dsp.h"

// Handle 32/64 bits int size issues
#ifdef __x86_64__
    #define uint32 unsigned int
    #define uint64 unsigned long int
    #define int32 int
    #define int64 long int
#else
    #define uint32 unsigned int
    #define uint64 unsigned long long int
    #define int32 int
    #define int64 long long int
#endif

/*
    A class to do do timing measurements
*/

class time_bench {
    
    protected:
    
        int fMeasure;
        int fMeasureCount;
        int fSkip;
    
        // These values are used to determine the number of clocks in a second
        uint64 fFirstRDTSC;
        uint64 fLastRDTSC;
    
        // These tables contains the last fMeasureCount in clocks
        uint64* fStarts;
        uint64* fStops;
    
        struct timeval fTv1;
        struct timeval fTv2;
    
        /**
         * Returns the number of clock cycles elapsed since the last reset of the processor
         */
        inline uint64 rdtsc(void)
        {
            union {
                uint32 i32[2];
                uint64 i64;
            } count;
            
            __asm__ __volatile__("rdtsc" : "=a" (count.i32[0]), "=d" (count.i32[1]));
            return count.i64;
        }

        /**
         * return the number of RDTSC clocks per seconds
         */
        double rdtscpersec()
        {
            // If the environment variable CLOCKSPERSEC is defined
            // we use it instead of our own measurement
            char* str = getenv("CLOCKSPERSEC");
            if (str) {
                int64 cps = (int64)atoll(str);
                if (cps > 1000000000) {
                    return cps;
                }
            }
            
            return double(fLastRDTSC - fFirstRDTSC)
                / (((double(fTv2.tv_sec) * 1000000 + double(fTv2.tv_usec)) - (double(fTv1.tv_sec) * 1000000 + double(fTv1.tv_usec)))
                / 1000000);
        }
  
        /**
         * Converts a duration, expressed in RDTSC clocks, into seconds
         */
        double rdtsc2sec(uint64 clk)
        {
            return double(clk) / rdtscpersec();
        }
        
        double rdtsc2sec(double clk)
        {
            return clk / rdtscpersec();
        }
    
        /**
         * Converts RDTSC clocks into Megabytes/seconds according to the
         * number of frames processed during the period, the number of channels
         * and 4 bytes samples.
         */
        double megapersec(int frames, int chans, uint64 clk)
        {
            return double(frames) * double(chans) * 4 / double(1024 * 1024 * rdtsc2sec(clk));
        }
        
        /**
         * Compute the mean value of a vector of measures
         */
        uint64 meanValue(std::vector<uint64>::const_iterator a, std::vector<uint64>::const_iterator b)
        {
            uint64 r = 0;
            unsigned int n = 0;
            while (a != b) { r += *a++; n++; }
            return (n > 0) ? r/n : 0;
        }
  
    public:
    
        time_bench(int count, int skip)
        {
            fSkip = skip;
            fMeasureCount = count;
            fMeasure = 0;
            fFirstRDTSC = 0;
            fLastRDTSC = 0;
            fStarts = new uint64[fMeasureCount];
            fStops = new uint64[fMeasureCount];
        }
    
        virtual ~time_bench()
        {
            delete [] fStarts;
            delete [] fStops;
        }
    
        void startMeasure() { fStarts[fMeasure % fMeasureCount] = rdtsc(); }
    
        void stopMeasure() { fStops[fMeasure % fMeasureCount] = rdtsc(); fMeasure++; }
        
        void openMeasure()
        {
            struct timezone tz;
            gettimeofday(&fTv1, &tz);
            fFirstRDTSC = rdtsc();
            fMeasure = 0;
        }
        
        void closeMeasure()
        {
            struct timezone tz;
            gettimeofday(&fTv2, &tz);
            fLastRDTSC = rdtsc();
        }
    
        double measureDurationUsec()
        {
            return ((double(fTv2.tv_sec) * 1000000 + double(fTv2.tv_usec)) - (double(fTv1.tv_sec) * 1000000 + double(fTv1.tv_usec)));
        }
    
        /**
         *  Returns best estimation.
         */
        double getStats(int bsize, int ichans, int ochans)
        {
            //std::cout << "getStats fMeasure = " << fMeasure << " fMeasureCount = " << fMeasureCount << std::endl;
            
            assert(fMeasure > fMeasureCount);
            std::vector<uint64> V(fMeasureCount);
            
            for (int i = 0; i < fMeasureCount; i++) {
                V[i] = fStops[i] - fStarts[i];
            }
            
            sort(V.begin(), V.end());
            
            // Mean of 10 best values (gives relatively stable results)
            uint64 meavalx = meanValue(V.begin(), V.begin() + 10);
            return megapersec(bsize, ichans + ochans, meavalx);
        }

        /**
         * Print the median value (in Megabytes/second) of fMeasureCount throughputs measurements.
         */
        void printStats(const char* applname, int bsize, int ichans, int ochans)
        {
            assert(fMeasure > fMeasureCount);
            std::vector<uint64> V(fMeasureCount);
            
            for (int i = 0; i < fMeasureCount; i++) {
                V[i] = fStops[i] - fStarts[i];
            }
            
            sort(V.begin(), V.end());
            
            // Mean of 10 best values (gives relatively stable results)
            uint64 meaval00 = meanValue(V.begin(), V.begin()+ 5);
            uint64 meaval25 = meanValue(V.begin() + fMeasureCount / 4 - 2, V.begin()+fMeasureCount / 4 + 3);
            uint64 meaval50 = meanValue(V.begin() + fMeasureCount / 2 - 2, V.begin()+fMeasureCount / 2 + 3);
            uint64 meaval75 = meanValue(V.begin() + 3 * fMeasureCount / 4 - 2, V.begin() + 3 * fMeasureCount / 4 + 3);
            uint64 meaval100 = meanValue(V.end() - 5, V.end());
            
            // Printing
            std::cout << applname
            << '\t' << megapersec(bsize, ichans+ochans, meaval00)
            << '\t' << megapersec(bsize, ichans+ochans, meaval25)
            << '\t' << megapersec(bsize, ichans+ochans, meaval50)
            << '\t' << megapersec(bsize, ichans+ochans, meaval75)
            << '\t' << megapersec(bsize, ichans+ochans, meaval100)
            << std::endl;
        }
    
        bool isRunning() { return (fMeasure <= (fMeasureCount + fSkip)); }

};

/*
    A class to measure DSP CPU use.
*/

class measure_dsp : public decorator_dsp {
    
    protected:
    
        FAUSTFLOAT** fInputs;
        FAUSTFLOAT** fOutputs;
        time_bench* fBench;
        int fBufferSize;
    
        void init()
        {
            fInputs = new FAUSTFLOAT*[fDSP->getNumInputs()];
            for (int i = 0; i < fDSP->getNumInputs(); i++) {
                fInputs[i] = new FAUSTFLOAT[fBufferSize];
                memset(fInputs[i], 0, sizeof(FAUSTFLOAT) * fBufferSize);
            }
            fOutputs = new FAUSTFLOAT*[fDSP->getNumOutputs()];
            for (int i = 0; i < fDSP->getNumOutputs(); i++) {
                fOutputs[i] = new FAUSTFLOAT[fBufferSize];
                memset(fOutputs[i], 0, sizeof(FAUSTFLOAT) * fBufferSize);
            }
        }
    
    public:
    
        /**
         * Constructor.
         *
         * @param dsp - the dsp to be measured.
         * @param buffer_size - the buffer size used when calling 'computeAll'
         * @param count - the number of cycles using in 'computeAll'
         * @param skip - ??
         *
         */
        measure_dsp(dsp* dsp, int buffer_size, int count, int skip)
            :decorator_dsp(dsp), fBufferSize(buffer_size)
        {
            init();
            fBench = new time_bench(count, 10);
        }
    
        measure_dsp(dsp* dsp, int buffer_size, double duration_in_sec)
            :decorator_dsp(dsp), fBufferSize(buffer_size)
        {
            init();
            fBench = new time_bench(500, 10);
            measure();
            double duration = fBench->measureDurationUsec();
            int cout = int (500 * (duration_in_sec * 1e6 / duration));
            std::cout << "duration = " << duration << " count = " << cout << std::endl;
            delete fBench;
            fBench = new time_bench(cout, 10);
        }
    
        virtual ~measure_dsp()
        {
            for (int i = 0; i < fDSP->getNumInputs(); i++) {
                delete [] fInputs[i];
            }
            delete [] fInputs;
            for (int i = 0; i < fDSP->getNumOutputs(); i++) {
                delete [] fOutputs[i];
            }
            delete[] fOutputs;
        }
    
        /*
            Measure the duration of the compute call
        */
        virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs)
        {
            fBench->startMeasure();
            fDSP->compute(count, inputs, outputs);
            fBench->stopMeasure();
        }
    
        virtual void compute(double date_usec, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs)
        {
            compute(count, inputs, outputs);
        }
    
        /*
            Measure the duration of 'count' (given in constructor) calls to compute
        */
        void computeAll()
        {
            AVOIDDENORMALS;
            do {
                compute(0, fBufferSize, fInputs, fOutputs);
            } while (fBench->isRunning());
        }
    
        /**
         *  Initialize measure datas
         */
        void openMeasure() { fBench->openMeasure(); }
    
        /**
         *  Terminate measurement
         */
        void closeMeasure() { fBench->closeMeasure(); }
    
    
        double measureDurationUsec()
        {
            return fBench->measureDurationUsec();
        }
    
        void measure()
        {
            openMeasure();
            computeAll();
            closeMeasure();
        }
    
        /**
         *  Returns best estimation
         */
        double getStats()
        {
            return fBench->getStats(fBufferSize, fDSP->getNumInputs(), fDSP->getNumOutputs());
        }
    
        /**
         * Print the median value (in Megabytes/second) of fMeasureCount throughputs measurements
         */
        void printStats(const char* applname)
        {
            fBench->printStats(applname, fBufferSize, fDSP->getNumInputs(), fDSP->getNumOutputs());
        }
    
        bool isRunning() { return fBench->isRunning(); }
    
};

#endif