Project

General

Profile

Statistics
| Branch: | Revision:

root / rgbdslam / external / siftgpu / src / TestWin / speed.cpp @ 9240aaa3

History | View | Annotate | Download (5.32 KB)

1 9240aaa3 Alex
////////////////////////////////////////////////////////////////////////////
2
//        File:                Speed.cpp
3
//        Author:                Changchang Wu
4
//        Description : Evaluate the speed of SiftGPU 
5
//
6
//
7
//
8
//        Copyright (c) 2007 University of North Carolina at Chapel Hill
9
//        All Rights Reserved
10
//
11
//        Permission to use, copy, modify and distribute this software and its
12
//        documentation for educational, research and non-profit purposes, without
13
//        fee, and without a written agreement is hereby granted, provided that the
14
//        above copyright notice and the following paragraph appear in all copies.
15
//        
16
//        The University of North Carolina at Chapel Hill make no representations
17
//        about the suitability of this software for any purpose. It is provided
18
//        'as is' without express or implied warranty. 
19
//
20
//        Please send BUG REPORTS to ccwu@cs.unc.edu
21
//
22
////////////////////////////////////////////////////////////////////////////
23
24
25
#include <stdlib.h>
26
#include <vector>
27
#include <iostream>
28
using std::cout;
29
30
#ifdef _WIN32
31
        //dll import definition for win32
32
        #define SIFTGPU_DLL
33
#endif
34
35
//for windows, the default timing uses timeGetTime, you can define TIMING_BY_CLOCK to use clock()
36
//for other os, the default timing uses gettimeofday, you can define TIMING_BY_CLOCK to use clock()
37
38
#if defined(_WIN32)
39
        #if defined(TIMING_BY_CLOCK)
40
                #include <time.h>
41
        #else
42
                #define WIN32_LEAN_AND_MEAN
43
                #include <windows.h>
44
                #include <mmsystem.h>
45
                #pragma comment(lib, "winmm.lib")
46
        #endif
47
#else
48
        #if defined(TIMING_BY_CLOCK)
49
                #include <time.h>
50
        #else
51
                #include <sys/time.h>
52
        #endif
53
#endif
54
55
56
#include "../SiftGPU/SiftGPU.h"
57
58
//define the marcro bellow to reload image file everytime
59
//#define INCLUDE_DISK_READING_TIME
60
61
//define the macro below to test speed of multi-process mode
62
//#define TEST_MULTI_PROCESS_SIFTGPU
63
64
65
66
#define SIFTGPU_REPEAT 30
67
68
// you should specify the input image and the sift parameter to speed.exe
69
// for example: speed.exe -i 600.pgm  -fo -1
70
// to test CUDA, you first need to recompile SiftGPU with CUDA capability
71
72
int GetMilliSecond(); 
73
74
int main(int argc, char * argv[])
75
{
76
#ifndef TEST_MULTI_PROCESS_SIFTGPU
77
        SiftGPU sift;
78
#else
79
        ComboSiftGPU* combo = CreateRemoteSiftGPU();
80
        SiftGPU& sift = (*combo);
81
#endif
82
        int num;
83
        float timing[10], time_all =0, time_start;
84
85
        //Parse parameters
86
        sift.ParseParam(argc - 1, argv + 1);
87
        sift.SetVerbose(0); 
88
89
        std::cout<<"Initialize and warm up...\n";
90
        //create an OpenGL context for computation
91
        if(sift.CreateContextGL() ==0) return 0;
92
        
93
        if(sift.RunSIFT()==0)        return 0;
94
95
        //image is loaded for only once for this experiment
96
#ifndef TEST_MULTI_PROCESS_SIFTGPU
97
        std::cout<<"Loading image: " << sift._timing[0]*1000 << "ms, "
98
                 <<"Tex initialization: "<<sift._timing[1]*1000 << "ms\n\n"
99
                 <<"Start 2x"<<SIFTGPU_REPEAT<<" repetitions...\n";
100
#ifdef INCLUDE_DISK_READING_TIME
101
    char imagepath[MAX_PATH];
102
    strcpy(imagepath, sift.GetCurrentImagePath()); 
103
#endif
104
#endif
105
106
        //run one more time to get all texture allocated
107
108
        sift.RunSIFT();
109
        num = sift.GetFeatureNum();
110
111
112
        //use no message output mode to get maximum speed.
113
        time_start = (float) GetMilliSecond();
114
        for(int i = 0; i < SIFTGPU_REPEAT; i++)
115
        {
116
#ifdef INCLUDE_DISK_READING_TIME
117
        sift.RunSIFT(imagepath);
118
#else
119
                sift.RunSIFT();
120
#endif
121
                std::cout <<"+";
122
        }
123
        time_all = ((float)GetMilliSecond() - time_start)/1000/SIFTGPU_REPEAT;
124
        std::cout<<"\n"; 
125
126
        //change the timing setting, so that we can get more accurate timing for each steps
127
        //in this mode, the overal speed will be decreased.
128
        sift.SetVerbose(-2); //little trick to disable all output but keep the timing
129
        std::fill(timing, timing + 10, 0.0f);
130
        for(int k = 0; k < SIFTGPU_REPEAT; k++)
131
        {
132
#ifdef INCLUDE_DISK_READING_TIME
133
        sift.RunSIFT(imagepath);
134
#else
135
                sift.RunSIFT();
136
#endif
137
                for(int j = 0; j < 10; j++)                timing[j] += sift._timing[j];
138
                std::cout <<"#";
139
        }
140
        for(int j = 0; j < 10; j++)         timing[j] /= SIFTGPU_REPEAT;
141
142
        std::cout
143
                <<"\n\n****************************************\n"
144
                <<"[Feature Count]:\t" << num << "\n"
145
                <<"[Average Time]:\t\t" << time_all * 1000.0f << "ms\n"
146
                <<"[Average Speed]:\t" << 1.0 / time_all << "hz\n"
147
#ifndef TEST_MULTI_PROCESS_SIFTGPU
148
#ifdef INCLUDE_DISK_READING_TIME
149
                <<"[Load Image File]:\t" << timing[0] * 1000.0f << "ms\n"
150
#endif
151
                <<"[Build Pyramid]:\t" << timing[2] * 1000.0f << "ms\n"
152
                <<"[Detection]:\t\t" << timing[3] * 1000.0f << "ms\n"
153
                <<"[Feature List]:\t\t" << timing[4] * 1000.0f << "ms\n"
154
                <<"[Orientation]:\t\t" << timing[5] * 1000.0f << "ms\n"
155
                <<"[MO Feature List]:\t" << timing[6] * 1000.0f << "ms\n"
156
                <<"[Download Keys]:\t" << timing[7] * 1000.0f << "ms\n"
157
                <<"[Descriptor]:\t\t" << timing[8] * 1000.0f << "ms\n"
158
#endif
159
                <<"****************************************\n";
160
161
#ifdef TEST_MULTI_PROCESS_SIFTGPU
162
        delete combo;
163
#endif
164
        return 0;
165
}
166
167
168
169
int GetMilliSecond()
170
{
171
#if defined(TIMING_BY_CLOCK)
172
        return clock() * 1000 / CLOCKS_PER_SEC;
173
#elif defined(_WIN32)
174
        static int  started = 0;
175
        static int        tstart;
176
        //the resolution of teimGetTime will be changed to 1ms inside SiftGPU
177
        if(started == 0)
178
        {
179
                tstart = timeGetTime();
180
                started = 1;
181
                return 0;
182
        }else
183
        {
184
                return timeGetTime() - tstart;
185
        }
186
#else
187
        static int    started = 0;
188
        static struct timeval tstart;
189
        if(started == 0) 
190
        {
191
                gettimeofday(&tstart, NULL);
192
                started = 1;
193
                return 0;
194
        }else
195
        {        
196
                struct timeval now;
197
                gettimeofday(&now, NULL) ;
198
                return (now.tv_usec - tstart.tv_usec + (now.tv_sec - tstart.tv_sec) * 1000000)/1000;
199
        }
200
#endif
201
}