Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024
00025 #include <stdlib.h>
00026 #include <vector>
00027 #include <iostream>
00028 using std::cout;
00029
00030 #ifdef _WIN32
00031
00032 #define SIFTGPU_DLL
00033 #endif
00034
00035
00036
00037
00038 #if defined(_WIN32)
00039 #if defined(TIMING_BY_CLOCK)
00040 #include <time.h>
00041 #else
00042 #define WIN32_LEAN_AND_MEAN
00043 #include <windows.h>
00044 #include <mmsystem.h>
00045 #pragma comment(lib, "winmm.lib")
00046 #endif
00047 #else
00048 #if defined(TIMING_BY_CLOCK)
00049 #include <time.h>
00050 #else
00051 #include <sys/time.h>
00052 #endif
00053 #endif
00054
00055
00056 #include "../SiftGPU/SiftGPU.h"
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #define SIFTGPU_REPEAT 30
00067
00068
00069
00070
00071
00072 int GetMilliSecond();
00073
00074 int main(int argc, char * argv[])
00075 {
00076 #ifndef TEST_MULTI_PROCESS_SIFTGPU
00077 SiftGPU sift;
00078 #else
00079 ComboSiftGPU* combo = CreateRemoteSiftGPU();
00080 SiftGPU& sift = (*combo);
00081 #endif
00082 int num;
00083 float timing[10], time_all =0, time_start;
00084
00085
00086 sift.ParseParam(argc - 1, argv + 1);
00087 sift.SetVerbose(0);
00088
00089 std::cout<<"Initialize and warm up...\n";
00090
00091 if(sift.CreateContextGL() ==0) return 0;
00092
00093 if(sift.RunSIFT()==0) return 0;
00094
00095
00096 #ifndef TEST_MULTI_PROCESS_SIFTGPU
00097 std::cout<<"Loading image: " << sift._timing[0]*1000 << "ms, "
00098 <<"Tex initialization: "<<sift._timing[1]*1000 << "ms\n\n"
00099 <<"Start 2x"<<SIFTGPU_REPEAT<<" repetitions...\n";
00100 #ifdef INCLUDE_DISK_READING_TIME
00101 char imagepath[MAX_PATH];
00102 strcpy(imagepath, sift.GetCurrentImagePath());
00103 #endif
00104 #endif
00105
00106
00107
00108 sift.RunSIFT();
00109 num = sift.GetFeatureNum();
00110
00111
00112
00113 time_start = (float) GetMilliSecond();
00114 for(int i = 0; i < SIFTGPU_REPEAT; i++)
00115 {
00116 #ifdef INCLUDE_DISK_READING_TIME
00117 sift.RunSIFT(imagepath);
00118 #else
00119 sift.RunSIFT();
00120 #endif
00121 std::cout <<"+";
00122 }
00123 time_all = ((float)GetMilliSecond() - time_start)/1000/SIFTGPU_REPEAT;
00124 std::cout<<"\n";
00125
00126
00127
00128 sift.SetVerbose(-2);
00129 std::fill(timing, timing + 10, 0.0f);
00130 for(int k = 0; k < SIFTGPU_REPEAT; k++)
00131 {
00132 #ifdef INCLUDE_DISK_READING_TIME
00133 sift.RunSIFT(imagepath);
00134 #else
00135 sift.RunSIFT();
00136 #endif
00137 for(int j = 0; j < 10; j++) timing[j] += sift._timing[j];
00138 std::cout <<"#";
00139 }
00140 for(int j = 0; j < 10; j++) timing[j] /= SIFTGPU_REPEAT;
00141
00142 std::cout
00143 <<"\n\n****************************************\n"
00144 <<"[Feature Count]:\t" << num << "\n"
00145 <<"[Average Time]:\t\t" << time_all * 1000.0f << "ms\n"
00146 <<"[Average Speed]:\t" << 1.0 / time_all << "hz\n"
00147 #ifndef TEST_MULTI_PROCESS_SIFTGPU
00148 #ifdef INCLUDE_DISK_READING_TIME
00149 <<"[Load Image File]:\t" << timing[0] * 1000.0f << "ms\n"
00150 #endif
00151 <<"[Build Pyramid]:\t" << timing[2] * 1000.0f << "ms\n"
00152 <<"[Detection]:\t\t" << timing[3] * 1000.0f << "ms\n"
00153 <<"[Feature List]:\t\t" << timing[4] * 1000.0f << "ms\n"
00154 <<"[Orientation]:\t\t" << timing[5] * 1000.0f << "ms\n"
00155 <<"[MO Feature List]:\t" << timing[6] * 1000.0f << "ms\n"
00156 <<"[Download Keys]:\t" << timing[7] * 1000.0f << "ms\n"
00157 <<"[Descriptor]:\t\t" << timing[8] * 1000.0f << "ms\n"
00158 #endif
00159 <<"****************************************\n";
00160
00161 #ifdef TEST_MULTI_PROCESS_SIFTGPU
00162 delete combo;
00163 #endif
00164 return 0;
00165 }
00166
00167
00168
00169 int GetMilliSecond()
00170 {
00171 #if defined(TIMING_BY_CLOCK)
00172 return clock() * 1000 / CLOCKS_PER_SEC;
00173 #elif defined(_WIN32)
00174 static int started = 0;
00175 static int tstart;
00176
00177 if(started == 0)
00178 {
00179 tstart = timeGetTime();
00180 started = 1;
00181 return 0;
00182 }else
00183 {
00184 return timeGetTime() - tstart;
00185 }
00186 #else
00187 static int started = 0;
00188 static struct timeval tstart;
00189 if(started == 0)
00190 {
00191 gettimeofday(&tstart, NULL);
00192 started = 1;
00193 return 0;
00194 }else
00195 {
00196 struct timeval now;
00197 gettimeofday(&now, NULL) ;
00198 return (now.tv_usec - tstart.tv_usec + (now.tv_sec - tstart.tv_sec) * 1000000)/1000;
00199 }
00200 #endif
00201 }