Commit 7f5c5a5ad6d59db09b253e8177d280fce438ed21
1 parent
a2eadb17
added templating for copyto and copyfrom for multiple image types
Showing
4 changed files
with
27 additions
and
33 deletions
openbr/plugins/cuda/copyfrom.cpp
| @@ -10,8 +10,7 @@ using namespace cv; | @@ -10,8 +10,7 @@ using namespace cv; | ||
| 10 | 10 | ||
| 11 | // extern CUDA declaration | 11 | // extern CUDA declaration |
| 12 | namespace br { namespace cuda { namespace cudacopyfrom { | 12 | namespace br { namespace cuda { namespace cudacopyfrom { |
| 13 | - //template <typename T> void wrapper(void* src, T* out, int rows, int cols) { | ||
| 14 | - void wrapper(void* src, float* out, const int rows, const int cols); | 13 | + template <typename T> void wrapper(void* src, T* out, int rows, int cols); |
| 15 | }}} | 14 | }}} |
| 16 | 15 | ||
| 17 | namespace br | 16 | namespace br |
| @@ -32,26 +31,21 @@ private: | @@ -32,26 +31,21 @@ private: | ||
| 32 | int cols = *((int*)dataPtr[2]); | 31 | int cols = *((int*)dataPtr[2]); |
| 33 | int type = *((int*)dataPtr[3]); | 32 | int type = *((int*)dataPtr[3]); |
| 34 | 33 | ||
| 35 | - if (type != CV_32FC1) { | ||
| 36 | - cout << "ERR: Invalid data type!" << endl; | ||
| 37 | - return; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - cout << "cudaMemPtr: " << cudaMemPtr << endl; | ||
| 41 | - cout << "rows: " << rows << endl; | ||
| 42 | - cout << "cols: " << cols << endl; | ||
| 43 | - cout << "type: " << type << endl; | ||
| 44 | - | ||
| 45 | Mat dstMat = Mat(rows, cols, type); | 34 | Mat dstMat = Mat(rows, cols, type); |
| 46 | - br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr<float>(), rows, cols); | 35 | + switch(type) { |
| 36 | + case CV_32FC1: | ||
| 37 | + br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr<float>(), rows, cols); | ||
| 38 | + break; | ||
| 39 | + case CV_8UC1: | ||
| 40 | + br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr<unsigned char>(), rows, cols); | ||
| 41 | + break; | ||
| 42 | + default: | ||
| 43 | + cout << "ERR: Invalid image format" << endl; | ||
| 44 | + break; | ||
| 45 | + } | ||
| 47 | dst = dstMat; | 46 | dst = dstMat; |
| 48 | 47 | ||
| 49 | cout << "CUDACopyFrom End" << endl; | 48 | cout << "CUDACopyFrom End" << endl; |
| 50 | - | ||
| 51 | - cout << "DST Data" << endl; | ||
| 52 | - cout << "rows: " << dstMat.rows << endl; | ||
| 53 | - cout << "cols: " << dstMat.cols << endl; | ||
| 54 | - cout << "type: " << dstMat.type() << endl; | ||
| 55 | } | 49 | } |
| 56 | }; | 50 | }; |
| 57 | 51 |
openbr/plugins/cuda/copyfrom.cu
| 1 | namespace br { namespace cuda { namespace cudacopyfrom { | 1 | namespace br { namespace cuda { namespace cudacopyfrom { |
| 2 | - //template <typename T> void wrapper(void* src, T* out, int rows, int cols) { | ||
| 3 | - void wrapper(void* src, float* dst, const int rows, const int cols) { | ||
| 4 | - cudaMemcpy(dst, src, rows*cols*sizeof(float), cudaMemcpyDeviceToHost); | 2 | + template <typename T> void wrapper(void* src, T* dst, int rows, int cols) { |
| 3 | + cudaMemcpy(dst, src, rows*cols*sizeof(T), cudaMemcpyDeviceToHost); | ||
| 5 | cudaFree(src); | 4 | cudaFree(src); |
| 6 | } | 5 | } |
| 6 | + | ||
| 7 | + template void wrapper(void*, float*, int, int); | ||
| 8 | + template void wrapper(void*, unsigned char*, int, int); | ||
| 7 | }}} | 9 | }}} |
openbr/plugins/cuda/copyto.cpp
| @@ -11,9 +11,7 @@ using namespace cv; | @@ -11,9 +11,7 @@ using namespace cv; | ||
| 11 | extern string type2str(int type); | 11 | extern string type2str(int type); |
| 12 | 12 | ||
| 13 | namespace br { namespace cuda { namespace cudacopyto { | 13 | namespace br { namespace cuda { namespace cudacopyto { |
| 14 | - //template<typename T> | ||
| 15 | - //void wrapper(const T* in, void** out, const int rows, const int cols); | ||
| 16 | - void wrapper(const unsigned char* in, void** out, const int rows, const int cols); | 14 | + template <typename T> void wrapper(const T* in, void** out, const int rows, const int cols); |
| 17 | }}} | 15 | }}} |
| 18 | 16 | ||
| 19 | namespace br | 17 | namespace br |
| @@ -31,11 +29,10 @@ private: | @@ -31,11 +29,10 @@ private: | ||
| 31 | 29 | ||
| 32 | void* cudaMemPtr; | 30 | void* cudaMemPtr; |
| 33 | switch(srcMat.type()) { | 31 | switch(srcMat.type()) { |
| 34 | - //case CV_32FC1: | ||
| 35 | - // br::cuda::cudacopyfrom::wrapper<float>(srcMat.ptr<float>(), &cudaMemPtr, rows, cols); | ||
| 36 | - // break; | 32 | + case CV_32FC1: |
| 33 | + br::cuda::cudacopyto::wrapper(srcMat.ptr<float>(), &cudaMemPtr, rows, cols); | ||
| 34 | + break; | ||
| 37 | case CV_8UC1: | 35 | case CV_8UC1: |
| 38 | - //br::cuda::cudacopyfrom::wrapper<unsigned char>(srcMat.ptr<unsigned char>(), &cudaMemPtr, rows, cols); | ||
| 39 | br::cuda::cudacopyto::wrapper(srcMat.ptr<unsigned char>(), &cudaMemPtr, rows, cols); | 36 | br::cuda::cudacopyto::wrapper(srcMat.ptr<unsigned char>(), &cudaMemPtr, rows, cols); |
| 40 | break; | 37 | break; |
| 41 | default: | 38 | default: |
openbr/plugins/cuda/copyto.cu
| 1 | namespace br { namespace cuda { namespace cudacopyto { | 1 | namespace br { namespace cuda { namespace cudacopyto { |
| 2 | - //template<typename T> | ||
| 3 | - //void wrapper(const T* in, void** out, const int rows, const int cols) { | ||
| 4 | - void wrapper(const unsigned char* in, void** out, const int rows, const int cols) { | ||
| 5 | - cudaMalloc(out, rows*cols*sizeof(unsigned char)); | ||
| 6 | - cudaMemcpy(*out, in, rows*cols*sizeof(unsigned char), cudaMemcpyHostToDevice); | 2 | + template <typename T> void wrapper(const T* in, void** out, const int rows, const int cols) { |
| 3 | + cudaMalloc(out, rows*cols*sizeof(T)); | ||
| 4 | + cudaMemcpy(*out, in, rows*cols*sizeof(T), cudaMemcpyHostToDevice); | ||
| 7 | } | 5 | } |
| 6 | + | ||
| 7 | + template void wrapper(const float* in, void** out, const int rows, const int cols); | ||
| 8 | + template void wrapper(const unsigned char* in, void** out, const int rows, const int cols); | ||
| 8 | }}} | 9 | }}} |