Aquila  2.0 prealpha
Cognitive Robotics Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tracker.h
Go to the documentation of this file.
1 //##############################################################################################################################################################################################################//
2 //Aquila - An Open-Source GPU-Accelerated Toolkit for Cognitive and Neuro-Robotics Research //
3 // //
4 //Copyright (c) <2012>, Anthony Morse //
5 //All rights reserved. //
6 // //
7 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: //
8 // //
9 // - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. //
10 // - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. //
11 // //
12 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR //
13 //A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT //
14 //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR //
15 //TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
16 // //
17 //The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted //
18 //as representing official policies,either expressed or implied, of the FreeBSD Project. //
19 //##############################################################################################################################################################################################################//
20 
21 #ifndef TRACKER_H
22 #define TRACKER_H
23 
24 #define MAX_GPU_DEVICES 4
25 
26 #include <omp.h>
27 #include <vector>
28 #include <cuda.h>
29 #include <cuda_runtime.h>
30 #include "interface.h"
31 
32 using namespace std;
33 
34 class Tracker : public yarp::os::Thread
35 {
36 public:
37  Tracker(Interface *pInterface);
38 
39 private:
40  Interface *intrfc;
41 
42  cudaDeviceProp deviceInfo[MAX_GPU_DEVICES];
43 
44  int P2P;
45  int debug;
46  int availableGPUs;
47  int requestedGPUs;
48  int simulationMode;
49  int threshold;
50  int gpuDevice[MAX_GPU_DEVICES];
51  int imageFlip;
52  bool GPU;
53 
54  //images
55  ImageOf<PixelRgb> *leftImage;
56  ImageOf<PixelRgb> *rightImage;
57  ImageOf<PixelRgb> oldLeftImage;
58  ImageOf<PixelRgb> oldRightImage;
59  ImageOf<PixelRgb> leftMotionImage;
60  ImageOf<PixelRgb> rightMotionImage;
61 
62  //device memory pointers
63  int *aLeftImage_d;
64  int *bLeftImage_d;
65  int *leftMotionImage_d;
66  int *leftMotionResult_d;
67  int *aRightImage_d;
68  int *bRightImage_d;
69  int *rightMotionImage_d;
70  int *rightMotionResult_d;
71 
72  //host memory pointers
73  int *leftImage_h;
74  int *rightImage_h;
75  int *leftMotionImage_h;
76  int *rightMotionImage_h;
77  int *leftMotionResult_h;
78  int *rightMotionResult_h;
79 
80  void run();
81  bool threadInit();
82 
83  void findMotion(ImageOf<PixelRgb> *image, ImageOf<PixelRgb> *oldImage, ImageOf<PixelRgb> *motionImage, int *imageVector, int*motionImageVector, int *aDeviceImage, int *bDeviceImage, int *motionDeviceImage, int *motionDeviceResult, int *motionResult);
84  void myCopyImage(ImageOf<PixelRgb> *source, ImageOf<PixelRgb> *destination);
85  void myCopyImageToVector(ImageOf<PixelRgb> *source, int *destination, bool direction);
86 
87 public:
89 
90  void initialise();
91  void deinitialise();
92  void printGPUProperties(int deviceID);
93  void printOptions();
94  void printConfiguration();
95 
96  void setSimulationMode(int simulation);
97  void setGPUMode(bool gpuMode);
98  void setDevice(int deviceID);
99  void setDevices(int deviceID[MAX_GPU_DEVICES]);
100  void setDebuggingLevel(int level);
101  void setThreshold(int thresholdValue);
102 
103  int getSimulationMode();
104  int getDevice();
105  int getNumDevices();
106  int getDebuggingLevel();
107  int getThreshold();
108 
109  vector<string> queryGPU();
110 };
111 
112 //GPU kernel wrappers
113 void findMotionOnDevice(int *aImage, int *bImage, int *result, int threshold);
114 void findClustersOnDevice(int *array, int *result);
115 
116 #endif//TRACKER_H