00001 /*!@file Demo/test-RunCudaSaliency.C tests the cuda saliency code */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/test-CudaSaliency.C $ 00035 // $Id: test-CudaSaliency.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 00039 #include "Component/ModelManager.H" 00040 #include "CUDA/CudaSaliency.H" 00041 #include "CUDA/CudaPyramidOps.H" 00042 #include "CUDA/CudaShapeOps.H" 00043 #include "CUDA/CudaTransforms.H" 00044 #include "CUDA/CudaPyrBuilder.H" 00045 #include "CUDA/CudaNorm.H" 00046 #include "CUDA/CudaRandom.H" 00047 #include "Image/Image.H" 00048 #include "Image/Pixels.H" 00049 #include "Image/ColorOps.H" 00050 #include "Neuro/NeuroOpts.H" 00051 #include "Raster/Raster.H" 00052 #include "Raster/GenericFrame.H" 00053 #include "Media/FrameSeries.H" 00054 #include "Transport/FrameIstream.H" 00055 #include "Transport/FrameInfo.H" 00056 #include "Transport/FrameOstream.H" 00057 #include "Util/Timer.H" 00058 #include <cuda.h> 00059 00060 #include <signal.h> 00061 #include <stdlib.h> 00062 #include <unistd.h> 00063 00064 00065 // ###################################################################### 00066 int main(const int argc, const char **argv) 00067 { 00068 00069 // instantiate a model manager (for camera input): 00070 ModelManager manager("CudaSaliency Tester"); 00071 00072 // NOTE: make sure you register your OutputFrameSeries with the 00073 // manager before you do your InputFrameSeries, to ensure that 00074 // outputs for the current frame get saved before the next input 00075 // frame is loaded. 00076 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00077 manager.addSubComponent(ofs); 00078 00079 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00080 manager.addSubComponent(ifs); 00081 00082 nub::ref<CudaSaliency> smt(new CudaSaliency(manager)); 00083 manager.addSubComponent(smt); 00084 00085 // Parse command-line: 00086 if (manager.parseCommandLine(argc, argv, "<CudaDev>", 1, 1) == false) return(1); 00087 00088 std::string devArg; 00089 devArg = manager.getExtraArg(0); 00090 MemoryPolicy mp = GLOBAL_DEVICE_MEMORY; 00091 int dev = strtol(devArg.c_str(),NULL,0); 00092 00093 smt->setDevice(mp,dev); 00094 // ###################################################################### 00095 // let's do it! 00096 manager.start(); 00097 ifs->startStream(); 00098 //unsigned int free,total; 00099 00100 while(true) 00101 { 00102 const FrameState is = ifs->updateNext(); 00103 if (is == FRAME_COMPLETE) 00104 break; 00105 00106 GenericFrame input = ifs->readFrame(); 00107 if (!input.initialized()) 00108 break; 00109 00110 const Image<PixRGB<byte> > inimg = input.asRgb(); 00111 //cuMemGetInfo(&free, &total); printf("^^^^ CUDA Mem1 -- free %u, total %u\n",free,total); 00112 smt->doInput(inimg); 00113 //cuMemGetInfo(&free, &total); printf("^^^^ CUDA Mem2 -- free %u, total %u\n",free,total); 00114 00115 const FrameState os = ofs->updateNext(); 00116 Image<float> out = smt->getOutput(); 00117 out = rescaleBilinear(out,inimg.getDims()); 00118 const Image<PixRGB<byte> > colout = inimg + toRGB(out); 00119 GenericFrame output = GenericFrame(colout); 00120 00121 ofs->writeFrame(output, "test", 00122 FrameInfo("cuda saliency frame", SRC_POS)); 00123 printf("input frame number %d\n",ifs->frame()); 00124 if (os == FRAME_FINAL) 00125 break; 00126 //status = seq->evolve(); 00127 } 00128 00129 // get ready to terminate: 00130 manager.stop(); 00131 cuda_invt_allocation_show_stats(1, "final",0); 00132 return 0; 00133 } 00134 00135 00136 // ###################################################################### 00137 /* So things look consistent in everyone's emacs... */ 00138 /* Local Variables: */ 00139 /* indent-tabs-mode: nil */ 00140 /* End: */