Commit a2742d604e0ddf394eb03f215f4c0e8b2c878810

Authored by boolli
1 parent 4d228feb

Hide max pointers from user

openbr/plugins/cuda/MatManager.cu
... ... @@ -41,9 +41,9 @@ namespace br { namespace cuda {
41 41 sem_init(_matSemaphore, 0, _numMats);
42 42 }
43 43  
44   - uint8_t* MatManager::reserve(Mat *mat) {
  44 + int MatManager::reserve(Mat *mat) {
45 45 int reservedMatIndex = 0;
46   - std::cout << "Reserving" << std::endl << std::flush;
  46 + //std::cout << "Reserving" << std::endl << std::flush;
47 47  
48 48 sem_wait(_matSemaphore);
49 49 pthread_mutex_lock(_matTakenLock);
... ... @@ -52,7 +52,7 @@ namespace br { namespace cuda {
52 52 if ( !(*_matTaken[i]) ) {
53 53 *_matTaken[i] = true;
54 54 reservedMatIndex = i;
55   - std::cout << "Taking " << i << std::endl << std::flush;
  55 + //std::cout << "Taking " << i << std::endl << std::flush;
56 56 break;
57 57 }
58 58 }
... ... @@ -70,7 +70,7 @@ namespace br { namespace cuda {
70 70 //printSizeChangingMat(reservedMat);
71 71 //reservedMat->release();
72 72 //reservedMat->create(mat->size(), mat->type());
73   - std::cout << "Size mismatch" << std::endl << std::flush;
  73 + //std::cout << "Size mismatch" << std::endl << std::flush;
74 74 // re malloc
75 75 cudaFree(_mats[reservedMatIndex]); // free the previous memory first
76 76 cudaMalloc(&_mats[reservedMatIndex], mat->rows * mat->cols * sizeof(uint8_t));
... ... @@ -79,10 +79,10 @@ namespace br { namespace cuda {
79 79  
80 80 }
81 81 pthread_mutex_unlock(_matsDimensionLock);
82   - return _mats[reservedMatIndex];
  82 + return reservedMatIndex;
83 83 }
84 84  
85   - void MatManager::upload(uint8_t* reservedMat, Mat& mat) {
  85 + void MatManager::upload(int reservedMatIndex, Mat& mat) {
86 86 // upload the image
87 87 /*
88 88 pthread_mutex_lock(_matsDimensionLock);
... ... @@ -91,10 +91,11 @@ namespace br { namespace cuda {
91 91 */
92 92  
93 93 // copy the content of the Mat to GPU
  94 + uint8_t* reservedMat = _mats[reservedMatIndex];
94 95 cudaMemcpy(reservedMat, mat.ptr<uint8_t>(), mat.rows * mat.cols, cudaMemcpyHostToDevice);
95 96 }
96 97  
97   - void MatManager::download(uint8_t* reservedMat, Mat& dstMat) {
  98 + void MatManager::download(int reservedMatIndex, Mat& dstMat) {
98 99 /*
99 100 pthread_mutex_lock(_matsDimensionLock);
100 101 reservedMat->download(dstMat);
... ... @@ -103,10 +104,12 @@ namespace br { namespace cuda {
103 104  
104 105 // copy the mat data back
105 106 int dimension = dstMat.rows * dstMat.cols;
  107 + uint8_t* reservedMat = _mats[reservedMatIndex];
106 108 cudaMemcpy(dstMat.ptr<uint8_t>(), reservedMat, dimension, cudaMemcpyDeviceToHost);
107 109 }
108 110  
109   - void MatManager::release(uint8_t* reservedMat) {
  111 + void MatManager::release(int reservedMatIndex) {
  112 + uint8_t* reservedMat = _mats[reservedMatIndex];
110 113 pthread_mutex_lock(_matTakenLock);
111 114 bool foundMatch = false;
112 115 for (int i=0; i < _numMats; i++) {
... ... @@ -141,7 +144,7 @@ namespace br { namespace cuda {
141 144 MatManager::~MatManager() {
142 145 // assume a single thread is destroying the manager
143 146 // TODO(colin): add the destroy code
144   - std::cout << "Start to destroy.." << std::endl << std::flush;
  147 + //std::cout << "Start to destroy.." << std::endl << std::flush;
145 148 }
146 149  
147 150 /*
... ... @@ -182,5 +185,8 @@ namespace br { namespace cuda {
182 185 std::cout << "can't release mat at address: " << gpuMat << std::endl << std::flush;
183 186 }
184 187 */
  188 + uint8_t* MatManager::get_mat_pointer_from_index(int matIndex) {
  189 + return _mats[matIndex];
  190 + }
185 191  
186 192 }}
... ...
openbr/plugins/cuda/MatManager.hpp
... ... @@ -27,10 +27,11 @@ namespace br { namespace cuda {
27 27 public:
28 28 MatManager(int num);
29 29  
30   - uint8_t* reserve(Mat *mat);
31   - void upload(uint8_t* reservedMat, Mat& mat);
32   - void download(uint8_t* reservedMat, Mat& dstMat);
33   - void release(uint8_t* mat);
  30 + int reserve(Mat *mat);
  31 + void upload(int reservedMatIndex, Mat& mat);
  32 + void download(int reservedMatIndex, Mat& dstMat);
  33 + void release(int matIndex);
  34 + uint8_t* get_mat_pointer_from_index(int matIndex);
34 35  
35 36 ~MatManager();
36 37 //void printMats();
... ...
openbr/plugins/cuda/cudalbp.cpp
... ... @@ -154,8 +154,8 @@ class CUDALBPTransform : public UntrainableTransform
154 154 void project(const Template &src, Template &dst) const
155 155 {
156 156 Mat& m = (Mat&)src.m();
157   - uint8_t* a;
158   - uint8_t* b;
  157 + int a;
  158 + int b;
159 159 a = matManager->reserve(&m);
160 160 // std::cout << "m: " << m.size() << ", " << m.type() << std::endl << std::flush;
161 161 // std::cout << "a: " << a->size() << ", " << a->type() << std::endl << std::flush;
... ... @@ -166,7 +166,9 @@ class CUDALBPTransform : public UntrainableTransform
166 166 //matManager->matchDimensions(b, a);
167 167  
168 168 //std::cout << "Coming to here" << std::endl << std::flush;
169   - br::cuda::cudalbp_wrapper(a, b, lutGpuPtr, m.cols, m.rows, m.step1());
  169 + uint8_t* srcMatPtr = matManager->get_mat_pointer_from_index(a);
  170 + uint8_t* dstMatPtr = matManager->get_mat_pointer_from_index(b);
  171 + br::cuda::cudalbp_wrapper(srcMatPtr, dstMatPtr, lutGpuPtr, m.cols, m.rows, m.step1());
170 172 //std::cout << "Coming out of here" << std::endl << std::flush;
171 173  
172 174 //std::cout << "Start to download" << std::endl << std::flush;
... ... @@ -176,7 +178,7 @@ class CUDALBPTransform : public UntrainableTransform
176 178 // release both the mats
177 179 matManager->release(a);
178 180 matManager->release(b);
179   - std::cout << "finish release" << std::endl << std::flush;
  181 + //std::cout << "finish release" << std::endl << std::flush;
180 182 }
181 183 };
182 184  
... ...