File: faustbench

package info (click to toggle)
faust 2.79.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 397,496 kB
  • sloc: cpp: 278,433; ansic: 116,164; javascript: 18,529; vhdl: 14,052; sh: 13,884; java: 5,900; objc: 3,852; python: 3,222; makefile: 2,655; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 110; tcl: 26
file content (338 lines) | stat: -rwxr-xr-x 14,311 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

#####################################################################
#                                                                   #
#               Bench several versions of a Faust DSP program       #
#               usign different compilation options                 #
#               (c) Grame, 2020-2023                                #
#                                                                   #
#####################################################################

. faustpath

FILES=""
IOS="0"
DOUBLE="0"
OPTIONS=""
LIBS=""
TESTS="all"
RUN=1
BUFFER_SIZE=512
CONTROL=false
OPT=-1
NOTRACE=false
GENERIC=false
SOURCE=false
US="0"
DS="0"
FILTER="0"

# Set default value for CXX
if [ "$CXX" = "" ]; then
    CXX=g++
fi

while [ $1 ]
do
    p=$1

    if [ $p = "-help" ] || [ $p = "-h" ]; then
        echo "faustbench [-notrace] [-control] [-generic] [-ios] [-single] [-fast] [-run <num>] [-bs <frames>] [-source] [-double] [-opt <level(0..3|-1)>] [-us <factor>] [-ds <factor>] [-filter <filter(0..4)>] [additional Faust options (-vec -vs 8...)] foo.dsp"
        echo "Use '-notrace' to only generate the best compilation parameters"
        echo "Use '-control' to update all controllers with random values at each cycle"
        echo "Use '-generic' to compile for a generic processor, otherwise -march=native will be used"
        echo "Use '-ios' to generate an iOS project"
        echo "Use '-single' to only execute the one test (scalar by default)"
        echo "Use '-fast' to only execute some tests"
        echo "Use '-run <num>' to execute each test <num> times"
        echo "Use '-bs <frames>' to set the buffer-size in frames"
        echo "Use '-source' to keep the intermediate source folder and exit"
        echo "Use '-double' to compile DSP in double and set FAUSTFLOAT to double"
        echo "Use '-opt <level (0..3|-1)>' to pass an optimisation level to C++ (-1 means 'maximal level =-Ofast for now' but may change in the future)"
        echo "Use '-us <factor>' to upsample the DSP by a factor"
        echo "Use '-ds <factor>' to downsample the DSP by a factor"
        echo "Use '-filter <filter>' for upsampling or downsampling [0..4]"
        echo ""
        echo "Use 'export CXX=/path/to/compiler' before running faustbench to change the C++ compiler"
        echo "Use 'export CXXFLAGS=options' before running faustbench to change the C++ compiler options"
        exit
    fi

    if [ "$p" = "-ios" ]; then
        IOS="1"
    elif [ "$p" = "-notrace" ]; then
        NOTRACE=true
    elif [ "$p" = "-control" ]; then
        CONTROL=true
    elif [ "$p" = "-generic" ]; then
        GENERIC=true
    elif [ "$p" = "-fast" ]; then
        TESTS="fast"
    elif [ "$p" = "-single" ]; then
        TESTS="single"
    elif [ "$p" = "-run" ]; then
        shift
        RUN=$1
    elif [ "$p" = "-bs" ]; then
        shift
        BUFFER_SIZE=$1
    elif [ "$p" = "-source" ]; then
        SOURCE=true
    elif [ "$p" = "-opt" ]; then
        shift
        OPT=$1
    elif [ $p = "-us" ]; then
        shift
        US=$1
    elif [ $p = "-ds" ]; then
        shift
        DS=$1
    elif [ $p = "-filter" ]; then
        shift
        FILTER=$1
    elif [ "$p" = "-double" ]; then
        DOUBLE="1"
        OPTIONS="$OPTIONS $p"
    elif [[ -f "$p" ]]; then
        FILES="$FILES $p"
    elif [ ${p:0:1} = "-" ]; then
        OPTIONS="$OPTIONS $p"
    else
        OPTIONS="$OPTIONS $p"
    fi

shift

done

# Set default value for CXXFLAGS
if [ "$CXXFLAGS" = "" ]; then
    if $GENERIC; then
        if [ $OPT = -1 ]; then
            CXXFLAGS="-Ofast"
        else
            CXXFLAGS="-O$OPT"
        fi
    else
        if [ $OPT = -1 ]; then
            # -march=native does not work yet on M1
            if [ $(uname) == Darwin ] && [ $(uname -p) == arm ]; then
                CXXFLAGS="-Ofast"
            else 
                CXXFLAGS="-Ofast -march=native"
            fi
        else
            # -march=native does not work yet on M1
            if [ $(uname) == Darwin ] && [ $(uname -p) == arm ]; then
                CXXFLAGS="-O$OPT"
            else 
                CXXFLAGS="-O$OPT -march=native"
            fi
        fi
    fi
fi

if [[ $(uname) == Darwin ]]; then
    LIBS=-lc++
    CXXFLAGS+=" -fbracket-depth=512"
fi

if ! $NOTRACE ; then
    echo "Selected compiler is $CXX with CXXFLAGS = $CXXFLAGS"
fi

for p in $FILES; do

    CUR=$(pwd)
    f=$(basename "$p")
    SRCDIR=$(dirname "$p")
    dspName="${f%.dsp}"

    # creates a temporary dir
    TDR=$(mktemp -d faust.XXX)
    TMP="$TDR/${f%.dsp}"
    mkdir "$TMP"

    # creates and compile multiple DSP bench tool
    if [ "$OPTIONS" != "" ]; then
        if ! $NOTRACE ; then
            echo "Compiled with additional options :$OPTIONS"
        fi
    fi

    if [ $TESTS == "all" ]; then

        faust -cn dsp_scal $OPTIONS "$SRCDIR/$f" -o "$TMP/dsp_scal.h"
        faust -cn dsp_scal_exp10 $OPTIONS -exp10 "$SRCDIR/$f" -o "$TMP/dsp_scal_exp10.h"
        faust -cn dsp_scal_mcd0 $OPTIONS -mcd 0 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd0.h"
        faust -cn dsp_scal_mcd2 $OPTIONS -mcd 2 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd2.h"
        faust -cn dsp_scal_mcd8 $OPTIONS -mcd 8 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd8.h"
        faust -cn dsp_scal_mcd16 $OPTIONS -mcd 16 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd16.h"
        faust -cn dsp_scal_mcd32 $OPTIONS -mcd 32 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd32.h"
        faust -cn dsp_scal_mcd64 $OPTIONS -mcd 64 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd64.h"
        faust -cn dsp_scal_os $OPTIONS -os "$SRCDIR/$f" -o "$TMP/dsp_scal_os.h"

        faust -cn dsp_vec0_4 $OPTIONS -vec -lv 0 -vs 4 "$SRCDIR/$f" -o "$TMP/dsp_vec0_4.h"
        faust -cn dsp_vec0_8 $OPTIONS -vec -lv 0 -vs 8 "$SRCDIR/$f" -o "$TMP/dsp_vec0_8.h"
        faust -cn dsp_vec0_16 $OPTIONS -vec -lv 0 -vs 16 "$SRCDIR/$f" -o "$TMP/dsp_vec0_16.h"
        faust -cn dsp_vec0_32 $OPTIONS -vec -lv 0 -vs 32 "$SRCDIR/$f" -o "$TMP/dsp_vec0_32.h"
        faust -cn dsp_vec0_64 $OPTIONS -vec -lv 0 -vs 64 "$SRCDIR/$f" -o "$TMP/dsp_vec0_64.h"
        faust -cn dsp_vec0_128 $OPTIONS -vec -lv 0 -vs 128 "$SRCDIR/$f" -o "$TMP/dsp_vec0_128.h"
        faust -cn dsp_vec0_256 $OPTIONS -vec -lv 0 -vs 256 "$SRCDIR/$f" -o "$TMP/dsp_vec0_256.h"
        faust -cn dsp_vec0_512 $OPTIONS -vec -lv 0 -vs 512 "$SRCDIR/$f" -o "$TMP/dsp_vec0_512.h"
        
        faust -cn dsp_vec0_fun_4 $OPTIONS -vec -fun -lv 0 -vs 4 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_4.h"
        faust -cn dsp_vec0_fun_8 $OPTIONS -vec -fun -lv 0 -vs 8 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_8.h"
        faust -cn dsp_vec0_fun_16 $OPTIONS -vec -fun -lv 0 -vs 16 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_16.h"
        faust -cn dsp_vec0_fun_32 $OPTIONS -vec -fun -lv 0 -vs 32 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_32.h"
        faust -cn dsp_vec0_fun_64 $OPTIONS -vec -fun -lv 0 -vs 64 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_64.h"
        faust -cn dsp_vec0_fun_128 $OPTIONS -vec -fun -lv 0 -vs 128 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_128.h"
        faust -cn dsp_vec0_fun_256 $OPTIONS -vec -fun -lv 0 -vs 256 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_256.h"
        faust -cn dsp_vec0_fun_512 $OPTIONS -vec -fun -lv 0 -vs 512 "$SRCDIR/$f" -o "$TMP/dsp_vec0_fun_512.h"

        faust -cn dsp_vec0g_4 $OPTIONS -vec -lv 0 -vs 4 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_4.h"
        faust -cn dsp_vec0g_8 $OPTIONS -vec -lv 0 -vs 8 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_8.h"
        faust -cn dsp_vec0g_16 $OPTIONS -vec -lv 0 -vs 16 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_16.h"
        faust -cn dsp_vec0g_32 $OPTIONS -vec -lv 0 -vs 32 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_32.h"
        faust -cn dsp_vec0g_64 $OPTIONS -vec -lv 0 -vs 64 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_64.h"
        faust -cn dsp_vec0g_128 $OPTIONS -vec -lv 0 -vs 128 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_128.h"
        faust -cn dsp_vec0g_256 $OPTIONS -vec -lv 0 -vs 256 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_256.h"
        faust -cn dsp_vec0g_512 $OPTIONS -vec -lv 0 -vs 512 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_512.h"

        faust -cn dsp_vec1_4 $OPTIONS -vec -lv 1 -vs 4 "$SRCDIR/$f" -o "$TMP/dsp_vec1_4.h"
        faust -cn dsp_vec1_8 $OPTIONS -vec -lv 1 -vs 8 "$SRCDIR/$f" -o "$TMP/dsp_vec1_8.h"
        faust -cn dsp_vec1_16 $OPTIONS -vec -lv 1 -vs 16 "$SRCDIR/$f" -o "$TMP/dsp_vec1_16.h"
        faust -cn dsp_vec1_32 $OPTIONS -vec -lv 1 -vs 32 "$SRCDIR/$f" -o "$TMP/dsp_vec1_32.h"
        faust -cn dsp_vec1_64 $OPTIONS -vec -lv 1 -vs 64 "$SRCDIR/$f" -o "$TMP/dsp_vec1_64.h"
        faust -cn dsp_vec1_128 $OPTIONS -vec -lv 1 -vs 128 "$SRCDIR/$f" -o "$TMP/dsp_vec1_128.h"
        faust -cn dsp_vec1_256 $OPTIONS -vec -lv 1 -vs 256 "$SRCDIR/$f" -o "$TMP/dsp_vec1_256.h"
        faust -cn dsp_vec1_512 $OPTIONS -vec -lv 1 -vs 512 "$SRCDIR/$f" -o "$TMP/dsp_vec1_512.h"

        faust -cn dsp_vec1g_4 $OPTIONS -vec -lv 1 -vs 4 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_4.h"
        faust -cn dsp_vec1g_8 $OPTIONS -vec -lv 1 -vs 8 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_8.h"
        faust -cn dsp_vec1g_16 $OPTIONS -vec -lv 1 -vs 16 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_16.h"
        faust -cn dsp_vec1g_32 $OPTIONS -vec -lv 1 -vs 32 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_32.h"
        faust -cn dsp_vec1g_64 $OPTIONS -vec -lv 1 -vs 64 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_64.h"
        faust -cn dsp_vec1g_128 $OPTIONS -vec -lv 1 -vs 128 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_128.h"
        faust -cn dsp_vec1g_256 $OPTIONS -vec -lv 1 -vs 256 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_256.h"
        faust -cn dsp_vec1g_512 $OPTIONS -vec -lv 1 -vs 512 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_512.h"

    elif [ $TESTS == "fast" ]; then

        faust -cn dsp_scal $OPTIONS "$SRCDIR/$f" -o "$TMP/dsp_scal.h"
        faust -cn dsp_scal_exp10 $OPTIONS -exp10 "$SRCDIR/$f" -o "$TMP/dsp_scal_exp10.h"
        faust -cn dsp_scal_mcd0 $OPTIONS -mcd 0 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd0.h"
        faust -cn dsp_scal_mcd8 $OPTIONS -mcd 8 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd8.h"
        faust -cn dsp_scal_mcd32 $OPTIONS -mcd 32 "$SRCDIR/$f" -o "$TMP/dsp_scal_mcd32.h"
        faust -cn dsp_scal_os $OPTIONS -os "$SRCDIR/$f" -o "$TMP/dsp_scal_os.h"
        
        faust -cn dsp_vec0_32 $OPTIONS -vec -lv 0 -vs 32 "$SRCDIR/$f" -o "$TMP/dsp_vec0_32.h"
        faust -cn dsp_vec0g_32 $OPTIONS -vec -lv 0 -vs 32 -g "$SRCDIR/$f" -o "$TMP/dsp_vec0g_32.h"
        faust -cn dsp_vec1_32 $OPTIONS -vec -lv 1 -vs 32 "$SRCDIR/$f" -o "$TMP/dsp_vec1_32.h"
        faust -cn dsp_vec1g_32 $OPTIONS -vec -lv 1 -vs 32 -g "$SRCDIR/$f" -o "$TMP/dsp_vec1g_32.h"

    elif [ $TESTS == "single" ]; then
        faust -cn dsp_scal $OPTIONS "$SRCDIR/$f" -o "$TMP/dsp_scal.h"
    fi
  
    if [ $IOS == "1" ]; then
        echo "Files generated for iOS project in $TMP"
       
        # Create config file
        echo -n >> "$TMP/Config.h"
         
        # float of double mode
        if [ $DOUBLE == "1" ]; then
            echo "#define FAUSTFLOAT double" >> "$TMP/Config.h"
        else
            echo "#define FAUSTFLOAT float" >> "$TMP/Config.h"
        fi
        # which tests to compile
        if [ $TESTS == "all" ]; then
            echo "#define ALL_TESTS" >> "$TMP/Config.h"
        elif [ $TESTS == "fast" ]; then
             echo "#define FAST_TESTS" >> "$TMP/Config.h"
        elif [ $TESTS == "single" ]; then
            echo "#define SINGLE_TESTS" >> "$TMP/Config.h"
        fi
        # additional options
        echo "#define OPTIONS string(\"$OPTIONS\")" >> "$TMP/Config.h"
        # add info for UP/DS + filter adapter
        echo "#define DOWN_SAMPLING $DS" >> "$TMP/Config.h"
        echo "#define UP_SAMPLING $US" >> "$TMP/Config.h"
        echo "#define FILTER_TYPE $FILTER" >> "$TMP/Config.h"
   
        cat "$TMP/Config.h" "$FAUSTLIB/faustbench.cpp" > "$TMP/faustbench.cpp"
        cp -r $FAUSTLIB/iOS-bench/* $TMP
        exit
    fi

    cd "$TMP"

    # Create config file
    echo -n >> Config
    if [ $DOUBLE == "1" ]; then
        echo "#define FAUSTFLOAT double" >> Config
    else
        echo "#define FAUSTFLOAT float" >> Config
    fi
    # additional options
    echo "#define OPTIONS string(\"$OPTIONS\")" >> Config
    cat Config "$FAUSTLIB/faustbench.cpp" > "faustbench.cpp"

    # keep sources
    if $SOURCE ; then 
        # create Makefile
        echo "$dspName:" > Makefile
        echo -n -e '\t' >> Makefile
        if [ $TESTS == "all" ]; then
            echo "$CXX $CXXFLAGS -std=c++11 -I `faust -includedir` -DALL_TESTS faustbench.cpp $LIBS -o $dspName" >> Makefile
        elif [ $TESTS == "fast" ]; then
            echo "$CXX $CXXFLAGS -std=c++11 -I `faust -includedir` -DFAST_TESTS faustbench.cpp $LIBS -o $dspName" >> Makefile
        elif [ $TESTS == "single" ]; then
            echo "$CXX $CXXFLAGS -std=c++11 -I `faust -includedir` -DSINGLE_TESTS faustbench.cpp $LIBS -o $dspName" >> Makefile
        fi
        echo -e '\n' >> Makefile
        echo "clean:" >> Makefile
        echo -n -e '\t' >> Makefile
        echo "rm $dspName" >> Makefile

        # copy and rename final folder
        cd ../
        cp -R $dspName ../
        cd ../
        # cleanup
        rm -rf $TDR
        exit
    else
        # compile
        if [ $TESTS == "all" ]; then
            $CXX $CXXFLAGS -std=c++11 -I `faust -includedir` -DALL_TESTS faustbench.cpp $LIBS -o $dspName
        elif [ $TESTS == "fast" ]; then
            $CXX $CXXFLAGS -std=c++11 -I `faust -includedir` -DFAST_TESTS faustbench.cpp $LIBS -o $dspName
        elif [ $TESTS == "single" ]; then
            $CXX $CXXFLAGS -std=c++11 -I `faust -includedir` -DSINGLE_TESTS faustbench.cpp $LIBS -o $dspName
        fi

        # run bench
        cd ../../
        if $NOTRACE; then
            if $CONTROL; then
                ./$TDR/$dspName/$dspName -notrace -control -run $RUN -bs $BUFFER_SIZE -ds $DS -us $US -filter $FILTER
            else
                ./$TDR/$dspName/$dspName -notrace -run $RUN -bs $BUFFER_SIZE -ds $DS -us $US -filter $FILTER
            fi
        else
            if $CONTROL; then
                ./$TDR/$dspName/$dspName -control -run $RUN -bs $BUFFER_SIZE -ds $DS -us $US -filter $FILTER
            else
                ./$TDR/$dspName/$dspName -run $RUN -bs $BUFFER_SIZE -ds $DS -us $US -filter $FILTER
            fi
        fi

        # cleanup
        rm -rf $TDR
    fi

done