speed.cpp
Go to the documentation of this file.
00001 
00002 //      File:           Speed.cpp
00003 //      Author:         Changchang Wu
00004 //      Description : Evaluate the speed of SiftGPU 
00005 //
00006 //
00007 //
00008 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00009 //      All Rights Reserved
00010 //
00011 //      Permission to use, copy, modify and distribute this software and its
00012 //      documentation for educational, research and non-profit purposes, without
00013 //      fee, and without a written agreement is hereby granted, provided that the
00014 //      above copyright notice and the following paragraph appear in all copies.
00015 //      
00016 //      The University of North Carolina at Chapel Hill make no representations
00017 //      about the suitability of this software for any purpose. It is provided
00018 //      'as is' without express or implied warranty. 
00019 //
00020 //      Please send BUG REPORTS to ccwu@cs.unc.edu
00021 //
00023 
00024 
00025 #include <stdlib.h>
00026 #include <vector>
00027 #include <iostream>
00028 using std::cout;
00029 
00030 #ifdef _WIN32
00031         //dll import definition for win32
00032         #define SIFTGPU_DLL
00033 #endif
00034 
00035 //for windows, the default timing uses timeGetTime, you can define TIMING_BY_CLOCK to use clock()
00036 //for other os, the default timing uses gettimeofday, you can define TIMING_BY_CLOCK to use clock()
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 //define the marcro bellow to reload image file everytime
00059 //#define INCLUDE_DISK_READING_TIME
00060 
00061 //define the macro below to test speed of multi-process mode
00062 //#define TEST_MULTI_PROCESS_SIFTGPU
00063 
00064 
00065 
00066 #define SIFTGPU_REPEAT 30
00067 
00068 // you should specify the input image and the sift parameter to speed.exe
00069 // for example: speed.exe -i 600.pgm  -fo -1
00070 // to test CUDA, you first need to recompile SiftGPU with CUDA capability
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         //Parse parameters
00086         sift.ParseParam(argc - 1, argv + 1);
00087         sift.SetVerbose(0); 
00088 
00089         std::cout<<"Initialize and warm up...\n";
00090         //create an OpenGL context for computation
00091         if(sift.CreateContextGL() ==0) return 0;
00092         
00093         if(sift.RunSIFT()==0)   return 0;
00094 
00095         //image is loaded for only once for this experiment
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         //run one more time to get all texture allocated
00107 
00108         sift.RunSIFT();
00109         num = sift.GetFeatureNum();
00110 
00111 
00112         //use no message output mode to get maximum speed.
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         //change the timing setting, so that we can get more accurate timing for each steps
00127         //in this mode, the overal speed will be decreased.
00128         sift.SetVerbose(-2); //little trick to disable all output but keep the timing
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         //the resolution of teimGetTime will be changed to 1ms inside SiftGPU
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


rgbd_registration
Author(s): Ross Kidson
autogenerated on Thu May 23 2013 15:36:53