Commit 4d228febb830296517f9b930194869d876ffe23f

Authored by DepthDeluxe
1 parent 0de4de86

fixed pointer bug which caused the crash

openbr/plugins/cuda/MatManager.cu
@@ -15,12 +15,13 @@ namespace br { namespace cuda { @@ -15,12 +15,13 @@ namespace br { namespace cuda {
15 // initialize the an array of Mats 15 // initialize the an array of Mats
16 _mats = (uint8_t**)malloc(num * sizeof(uint8_t*)); 16 _mats = (uint8_t**)malloc(num * sizeof(uint8_t*));
17 _matTaken = (bool**)malloc(num * sizeof(bool*)); 17 _matTaken = (bool**)malloc(num * sizeof(bool*));
18 - _matsDimension = (int**) malloc(num * sizeof(int)); 18 + _matsDimension = (int**)malloc(num * sizeof(int*));
19 19
20 for (int i=0; i < num; i++) { 20 for (int i=0; i < num; i++) {
21 cudaMalloc(&_mats[i], 1 * sizeof(uint8_t)); 21 cudaMalloc(&_mats[i], 1 * sizeof(uint8_t));
22 //_mats[i] = new GpuMat(); 22 //_mats[i] = new GpuMat();
23 23
  24 + // initialize matTaken
24 _matTaken[i] = new bool; 25 _matTaken[i] = new bool;
25 (*_matTaken[i]) = false; 26 (*_matTaken[i]) = false;
26 27
@@ -69,14 +70,14 @@ namespace br { namespace cuda { @@ -69,14 +70,14 @@ namespace br { namespace cuda {
69 //printSizeChangingMat(reservedMat); 70 //printSizeChangingMat(reservedMat);
70 //reservedMat->release(); 71 //reservedMat->release();
71 //reservedMat->create(mat->size(), mat->type()); 72 //reservedMat->create(mat->size(), mat->type());
72 - std::cout << "Size mismatch" << std::endl << std::flush; 73 + std::cout << "Size mismatch" << std::endl << std::flush;
73 // re malloc 74 // re malloc
74 cudaFree(_mats[reservedMatIndex]); // free the previous memory first 75 cudaFree(_mats[reservedMatIndex]); // free the previous memory first
75 cudaMalloc(&_mats[reservedMatIndex], mat->rows * mat->cols * sizeof(uint8_t)); 76 cudaMalloc(&_mats[reservedMatIndex], mat->rows * mat->cols * sizeof(uint8_t));
76 // change the dimension of that matrix 77 // change the dimension of that matrix
77 - *_matsDimension[reservedMatIndex] = mat->rows * mat->cols; 78 + *_matsDimension[reservedMatIndex] = mat->rows * mat->cols;
78 79
79 - } 80 + }
80 pthread_mutex_unlock(_matsDimensionLock); 81 pthread_mutex_unlock(_matsDimensionLock);
81 return _mats[reservedMatIndex]; 82 return _mats[reservedMatIndex];
82 } 83 }
@@ -99,7 +100,7 @@ namespace br { namespace cuda { @@ -99,7 +100,7 @@ namespace br { namespace cuda {
99 reservedMat->download(dstMat); 100 reservedMat->download(dstMat);
100 pthread_mutex_unlock(_matsDimensionLock); 101 pthread_mutex_unlock(_matsDimensionLock);
101 */ 102 */
102 - 103 +
103 // copy the mat data back 104 // copy the mat data back
104 int dimension = dstMat.rows * dstMat.cols; 105 int dimension = dstMat.rows * dstMat.cols;
105 cudaMemcpy(dstMat.ptr<uint8_t>(), reservedMat, dimension, cudaMemcpyDeviceToHost); 106 cudaMemcpy(dstMat.ptr<uint8_t>(), reservedMat, dimension, cudaMemcpyDeviceToHost);
@@ -128,9 +129,9 @@ namespace br { namespace cuda { @@ -128,9 +129,9 @@ namespace br { namespace cuda {
128 int type = reservedMat->type(); 129 int type = reservedMat->type();
129 reservedMat->release(); 130 reservedMat->release();
130 reservedMat->create(size, type); 131 reservedMat->create(size, type);
131 -  
132 132
133 - 133 +
  134 +
134 pthread_mutex_unlock(_matsDimensionLock); 135 pthread_mutex_unlock(_matsDimensionLock);
135 */ 136 */
136 137
openbr/plugins/cuda/MatManager.hpp
  1 +/*
  2 +NOTES
  3 +Mat reservations should return a handle instead of a pointer
  4 +*/
  5 +
1 #include <pthread.h> 6 #include <pthread.h>
2 #include <semaphore.h> 7 #include <semaphore.h>
3 8