/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/src/dict_hw_test.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-15 13:54:56 UTC
  • Revision ID: csa@dside.dyndns.org-20091215135456-0q8p63jwg4dzbf6p
Collection of timing information and fix for a crash in non-matlab mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <sys/stat.h>
7
7
#include <unistd.h>
8
8
 
 
9
#ifdef DICT_HW_MEASURE_TIMINGS
 
10
# include <sys/time.h>
 
11
#endif /* DICT_HW_MEASURE_TIMINGS */
 
12
 
9
13
#include <getopt.h>
10
14
 
11
15
#include <glib.h>
12
16
 
13
17
#include <dict_hw.h>
14
18
 
 
19
#include "helpers.h"
 
20
 
15
21
int matlab_mode = 0;
16
22
 
17
23
typedef enum {
126
132
    float *y;
127
133
 
128
134
    char **images;
 
135
 
 
136
#ifdef DICT_HW_MEASURE_TIMINGS
 
137
    int time[8];
 
138
    struct timeval tv1, tv2, tv3;
 
139
 
 
140
    memset(time, 0, sizeof(time));
 
141
    gettimeofday(&tv1, NULL);
 
142
#endif /* DICT_HW_MEASURE_TIMINGS */
 
143
 
129
144
    
130
145
    int option_index = 0;
131
146
    unsigned char c;
238
253
 
239
254
    dictSetCurrentPoints(ps, x, y);
240
255
 
 
256
#ifdef DICT_HW_MEASURE_TIMINGS
 
257
    gettimeofday(&tv2, NULL);
 
258
    time[0] = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
 
259
#endif /* DICT_HW_MEASURE_TIMINGS */
 
260
 
 
261
 
 
262
#ifdef DICT_HW_MEASURE_TIMINGS
 
263
    gettimeofday(&tv3, NULL);
 
264
#endif /* DICT_HW_MEASURE_TIMINGS */
 
265
 
241
266
    FILE *fx, *fy;
242
267
    if (!matlab_mode) {
243
268
        name = g_strdup_printf("%s/data/validx.dat", argv[optind]);
253
278
        }
254
279
    }
255
280
 
 
281
#ifdef DICT_HW_MEASURE_TIMINGS
 
282
    gettimeofday(&tv2, NULL);
 
283
    time[1] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
 
284
#endif /* DICT_HW_MEASURE_TIMINGS */
 
285
 
 
286
 
256
287
    for (i = 1; i < maximg; i++) {
 
288
#ifndef DICT_HW_MEASURE_TIMINGS
257
289
        printf("%s\n", images[i]);
 
290
#endif /* !DICT_HW_MEASURE_TIMINGS */
258
291
        
259
292
        name = g_strdup_printf("%s/images/%s", argv[optind], images[i]);
 
293
#ifdef DICT_HW_MEASURE_TIMINGS
 
294
        gettimeofday(&tv3, NULL);
 
295
#endif /* DICT_HW_MEASURE_TIMINGS */
260
296
        dictLoadImageFile(ps, name);
 
297
#ifdef DICT_HW_MEASURE_TIMINGS
 
298
        gettimeofday(&tv2, NULL);
 
299
        time[5] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
 
300
#endif /* DICT_HW_MEASURE_TIMINGS */
 
301
 
261
302
        g_free(name);
262
303
        if (matlab_mode) {
263
304
            float *out = res + ncp * (i - 1);
264
305
            dictGetCurrentPoints(ps, out, out + step);
265
306
        } else {
266
307
            dictCompute(ps);
 
308
 
 
309
#ifdef DICT_HW_MEASURE_TIMINGS
 
310
            gettimeofday(&tv3, NULL);
 
311
#endif /* DICT_HW_MEASURE_TIMINGS */
 
312
 
267
313
            for (int j = 0; j < ncp; j++) {
268
314
                fprintf(fx, "% 9.7le\t", res[j]);
269
315
            }
274
320
                fprintf(fy, "% 9.7le\t", out[j]);
275
321
            }
276
322
            fprintf(fy,"\n");
 
323
 
 
324
#ifdef DICT_HW_MEASURE_TIMINGS
 
325
            gettimeofday(&tv2, NULL);
 
326
            time[1] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
 
327
#endif /* DICT_HW_MEASURE_TIMINGS */
277
328
        }
278
329
    }
 
330
 
 
331
#ifdef DICT_HW_MEASURE_TIMINGS
 
332
    gettimeofday(&tv3, NULL);
 
333
#endif /* DICT_HW_MEASURE_TIMINGS */
279
334
    
280
335
    if (matlab_mode) {
281
336
        name = g_strdup_printf("%s/data/validx.dat", argv[optind]);
288
343
        fclose(fy);
289
344
    }
290
345
 
 
346
#ifdef DICT_HW_MEASURE_TIMINGS
 
347
    gettimeofday(&tv2, NULL);
 
348
    time[1] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
 
349
    time[2] = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec) - time[0];
 
350
#endif /* DICT_HW_MEASURE_TIMINGS */
291
351
 
292
352
    for (i = 0; i < allocimg; i++) {
293
353
        g_free(images[i]);
299
359
    free(images);        
300
360
    free(y);
301
361
    free(x);
 
362
 
 
363
#ifdef DICT_HW_MEASURE_TIMINGS
 
364
    gettimeofday(&tv3, NULL);
 
365
    time[3] = (tv3.tv_sec - tv1.tv_sec) * 1000000 + (tv3.tv_usec - tv1.tv_usec);
 
366
    time[4] = (tv3.tv_sec - tv2.tv_sec) * 1000000 + (tv3.tv_usec - tv2.tv_usec);
 
367
    printf("\n");
 
368
    printf("Global timings\n");
 
369
    printf("--------------\n");
 
370
    print_timing("Overall", time[3]);
 
371
    print_timing("Initialization", time[0]);
 
372
    print_timing("Cleanup", time[4]);
 
373
    print_timing("Processing/Full", time[2], maximg - 1);
 
374
    print_timing("Processing/Computations", time[2] - time[1], maximg - 1);
 
375
    print_timing("Processing/Pushing Data", time[5], maximg - 1);
 
376
    print_timing("Processing/Waiting Result", time[2] - time[1] - time[5], maximg - 1);
 
377
    print_timing("Processing/Writeout", time[1], maximg - 1);
 
378
    printf("\n");
 
379
#endif /* DICT_HW_MEASURE_TIMINGS */
 
380
 
302
381
}
 
382