From eac782df784f1f10a1e864139f22233247ea36e6 Mon Sep 17 00:00:00 2001 From: DepthDeluxe Date: Thu, 31 Mar 2016 11:12:47 -0400 Subject: [PATCH] removed MatManager from master because it isn't ready --- openbr/core/cuda/MatManager.cu | 116 -------------------------------------------------------------------------------------------------------------------- openbr/core/cuda/MatManager.hpp | 39 --------------------------------------- 2 files changed, 0 insertions(+), 155 deletions(-) delete mode 100644 openbr/core/cuda/MatManager.cu delete mode 100644 openbr/core/cuda/MatManager.hpp diff --git a/openbr/core/cuda/MatManager.cu b/openbr/core/cuda/MatManager.cu deleted file mode 100644 index 4823249..0000000 --- a/openbr/core/cuda/MatManager.cu +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include - -#include - -#include "MatManager.hpp" - -using namespace cv; -using namespace cv::gpu; - -namespace br { namespace cuda { - MatManager::MatManager(int num) { - _numMats = num; - - // initialize the an array of Mats - _mats = (uint8_t**)malloc(num * sizeof(uint8_t*)); - _matTaken = (bool*)malloc(num * sizeof(bool)); - _matsDimension = (int*)malloc(num * sizeof(int)); - - for (int i=0; i < num; i++) { - cudaMalloc(&_mats[i], 1 * sizeof(uint8_t)); - - // initialize matTaken - _matTaken[i] = false; - - // initialize all mat dimensions to be 1 - _matsDimension[i] = 1; - } - - // initialize the locks - _matTakenLock = new pthread_mutex_t; - pthread_mutex_init(_matTakenLock, NULL); - _matsDimensionLock = new pthread_mutex_t; - pthread_mutex_init(_matsDimensionLock, NULL); - - // initialize the semaphore - _matSemaphore = new sem_t; - sem_init(_matSemaphore, 0, _numMats); - } - - MatManager::matindex MatManager::reserve(Mat &mat) { - int reservedMatIndex = 0; - - sem_wait(_matSemaphore); - pthread_mutex_lock(_matTakenLock); - int i; - for (i=0; i < _numMats; i++) { - if ( !_matTaken[i] ) { - _matTaken[i] = true; - reservedMatIndex = i; - break; - } - } - if (i == _numMats) { - std::cout << "Cannot reserve a mat. Not enough GpuMat resourses\n" << std::endl << std::flush; - } - - pthread_mutex_unlock(_matTakenLock); - - // reallocate if size does not match - pthread_mutex_lock(_matsDimensionLock); - if (_matsDimension[reservedMatIndex] != mat.rows * mat.cols) { - cudaFree(_mats[reservedMatIndex]); // free the previous memory first - cudaMalloc(&_mats[reservedMatIndex], mat.rows * mat.cols * sizeof(uint8_t)); - // change the dimension of that matrix - _matsDimension[reservedMatIndex] = mat.rows * mat.cols; - - } - pthread_mutex_unlock(_matsDimensionLock); - return reservedMatIndex; - } - - void MatManager::upload(MatManager::matindex reservedMatIndex, Mat& mat) { - // copy the content of the Mat to GPU - uint8_t* reservedMat = _mats[reservedMatIndex]; - cudaMemcpy(reservedMat, mat.ptr(), mat.rows * mat.cols, cudaMemcpyHostToDevice); - } - - void MatManager::download(MatManager::matindex reservedMatIndex, Mat& dstMat) { - // copy the mat data back - int dimension = dstMat.rows * dstMat.cols; - uint8_t* reservedMat = _mats[reservedMatIndex]; - cudaMemcpy(dstMat.ptr(), reservedMat, dimension, cudaMemcpyDeviceToHost); - } - - void MatManager::release(MatManager::matindex reservedMatIndex) { - uint8_t* reservedMat = _mats[reservedMatIndex]; - pthread_mutex_lock(_matTakenLock); - bool foundMatch = false; - for (int i=0; i < _numMats; i++) { - if (reservedMat == _mats[i]) { - _matTaken[i] = false; - foundMatch = true; - } - } - pthread_mutex_unlock(_matTakenLock); - - // return unconditionally if we didn't find a match - if (!foundMatch) { - std::cout << "Reservedmat is not in the _mats array" << std::endl << std::flush; - return; - } - sem_post(_matSemaphore); - } - - MatManager::~MatManager() { - // assume a single thread is destroying the manager - // TODO(colin): add the destroy code - //std::cout << "Start to destroy.." << std::endl << std::flush; - } - - uint8_t* MatManager::get_mat_pointer_from_index(MatManager::matindex matIndex) { - return _mats[matIndex]; - } - -}} diff --git a/openbr/core/cuda/MatManager.hpp b/openbr/core/cuda/MatManager.hpp deleted file mode 100644 index e58ad42..0000000 --- a/openbr/core/cuda/MatManager.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -NOTES -Mat reservations should return a handle instead of a pointer -*/ - -#include -#include - -#include -#include - -using namespace cv; -using namespace cv::gpu; - -namespace br { namespace cuda { - class MatManager { - private: - int _numMats; - uint8_t** _mats; // holds all the mats - bool* _matTaken; // holds whether or not they are taken - int* _matsDimension; // holds the dimension of the Mats - - pthread_mutex_t* _matTakenLock; // lock for matTaken table - pthread_mutex_t* _matsDimensionLock; // lock for _matsDimension table and _mats table - sem_t* _matSemaphore; - - public: - typedef int matindex; - MatManager(int num); - - int reserve(Mat &mat); - void upload(matindex reservedMatIndex, Mat& mat); - void download(matindex reservedMatIndex, Mat& dstMat); - void release(matindex matIndex); - uint8_t* get_mat_pointer_from_index(matindex matIndex); - - ~MatManager(); - }; -}} -- libgit2 0.21.4