Commit f58d41a310cb02f6db7bd9d401c65d8bdf17193d
1 parent
728e43f5
Make _matTaken and _matsDimension double pointers to just pointers
Showing
2 changed files
with
15 additions
and
9 deletions
openbr/plugins/cuda/MatManager.cu
| @@ -14,20 +14,26 @@ namespace br { namespace cuda { | @@ -14,20 +14,26 @@ namespace br { namespace cuda { | ||
| 14 | 14 | ||
| 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*)); | ||
| 18 | - _matsDimension = (int**)malloc(num * sizeof(int*)); | 17 | + _matTaken = (bool*)malloc(num * sizeof(bool)); |
| 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 | // initialize matTaken |
| 25 | + /* | ||
| 25 | _matTaken[i] = new bool; | 26 | _matTaken[i] = new bool; |
| 26 | (*_matTaken[i]) = false; | 27 | (*_matTaken[i]) = false; |
| 28 | + */ | ||
| 29 | + _matTaken[i] = false; | ||
| 27 | 30 | ||
| 28 | // initialize all mat dimensions to be 1 | 31 | // initialize all mat dimensions to be 1 |
| 32 | + /* | ||
| 29 | _matsDimension[i] = new int; | 33 | _matsDimension[i] = new int; |
| 30 | (*_matsDimension[i]) = 1; | 34 | (*_matsDimension[i]) = 1; |
| 35 | + */ | ||
| 36 | + _matsDimension[i] = 1; | ||
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | // initialize the locks | 39 | // initialize the locks |
| @@ -49,8 +55,8 @@ namespace br { namespace cuda { | @@ -49,8 +55,8 @@ namespace br { namespace cuda { | ||
| 49 | pthread_mutex_lock(_matTakenLock); | 55 | pthread_mutex_lock(_matTakenLock); |
| 50 | int i; | 56 | int i; |
| 51 | for (i=0; i < _numMats; i++) { | 57 | for (i=0; i < _numMats; i++) { |
| 52 | - if ( !(*_matTaken[i]) ) { | ||
| 53 | - *_matTaken[i] = true; | 58 | + if ( !_matTaken[i] ) { |
| 59 | + _matTaken[i] = true; | ||
| 54 | reservedMatIndex = i; | 60 | reservedMatIndex = i; |
| 55 | //std::cout << "Taking " << i << std::endl << std::flush; | 61 | //std::cout << "Taking " << i << std::endl << std::flush; |
| 56 | break; | 62 | break; |
| @@ -66,11 +72,11 @@ namespace br { namespace cuda { | @@ -66,11 +72,11 @@ namespace br { namespace cuda { | ||
| 66 | 72 | ||
| 67 | // reallocate if size does not match | 73 | // reallocate if size does not match |
| 68 | pthread_mutex_lock(_matsDimensionLock); | 74 | pthread_mutex_lock(_matsDimensionLock); |
| 69 | - if (*_matsDimension[reservedMatIndex] != mat.rows * mat.cols) { | 75 | + if (_matsDimension[reservedMatIndex] != mat.rows * mat.cols) { |
| 70 | cudaFree(_mats[reservedMatIndex]); // free the previous memory first | 76 | cudaFree(_mats[reservedMatIndex]); // free the previous memory first |
| 71 | cudaMalloc(&_mats[reservedMatIndex], mat.rows * mat.cols * sizeof(uint8_t)); | 77 | cudaMalloc(&_mats[reservedMatIndex], mat.rows * mat.cols * sizeof(uint8_t)); |
| 72 | // change the dimension of that matrix | 78 | // change the dimension of that matrix |
| 73 | - *_matsDimension[reservedMatIndex] = mat.rows * mat.cols; | 79 | + _matsDimension[reservedMatIndex] = mat.rows * mat.cols; |
| 74 | 80 | ||
| 75 | } | 81 | } |
| 76 | pthread_mutex_unlock(_matsDimensionLock); | 82 | pthread_mutex_unlock(_matsDimensionLock); |
| @@ -109,7 +115,7 @@ namespace br { namespace cuda { | @@ -109,7 +115,7 @@ namespace br { namespace cuda { | ||
| 109 | bool foundMatch = false; | 115 | bool foundMatch = false; |
| 110 | for (int i=0; i < _numMats; i++) { | 116 | for (int i=0; i < _numMats; i++) { |
| 111 | if (reservedMat == _mats[i]) { | 117 | if (reservedMat == _mats[i]) { |
| 112 | - *_matTaken[i] = false; | 118 | + _matTaken[i] = false; |
| 113 | foundMatch = true; | 119 | foundMatch = true; |
| 114 | } | 120 | } |
| 115 | } | 121 | } |
openbr/plugins/cuda/MatManager.hpp
| @@ -17,8 +17,8 @@ namespace br { namespace cuda { | @@ -17,8 +17,8 @@ namespace br { namespace cuda { | ||
| 17 | private: | 17 | private: |
| 18 | int _numMats; | 18 | int _numMats; |
| 19 | uint8_t** _mats; // holds all the mats | 19 | uint8_t** _mats; // holds all the mats |
| 20 | - bool** _matTaken; // holds whether or not they are taken | ||
| 21 | - int** _matsDimension; // holds the dimension of the Mats | 20 | + bool* _matTaken; // holds whether or not they are taken |
| 21 | + int* _matsDimension; // holds the dimension of the Mats | ||
| 22 | 22 | ||
| 23 | pthread_mutex_t* _matTakenLock; // lock for matTaken table | 23 | pthread_mutex_t* _matTakenLock; // lock for matTaken table |
| 24 | pthread_mutex_t* _matsDimensionLock; // lock for OpenCV upload/download/realloc operations | 24 | pthread_mutex_t* _matsDimensionLock; // lock for OpenCV upload/download/realloc operations |