diff --git a/openbr/plugins/cuda/copyfrom.cpp b/openbr/plugins/cuda/copyfrom.cpp index 682e9da..aada3c2 100644 --- a/openbr/plugins/cuda/copyfrom.cpp +++ b/openbr/plugins/cuda/copyfrom.cpp @@ -10,8 +10,7 @@ using namespace cv; // extern CUDA declaration namespace br { namespace cuda { namespace cudacopyfrom { - //template void wrapper(void* src, T* out, int rows, int cols) { - void wrapper(void* src, float* out, const int rows, const int cols); + template void wrapper(void* src, T* out, int rows, int cols); }}} namespace br @@ -32,26 +31,21 @@ private: int cols = *((int*)dataPtr[2]); int type = *((int*)dataPtr[3]); - if (type != CV_32FC1) { - cout << "ERR: Invalid data type!" << endl; - return; - } - - cout << "cudaMemPtr: " << cudaMemPtr << endl; - cout << "rows: " << rows << endl; - cout << "cols: " << cols << endl; - cout << "type: " << type << endl; - Mat dstMat = Mat(rows, cols, type); - br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr(), rows, cols); + switch(type) { + case CV_32FC1: + br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr(), rows, cols); + break; + case CV_8UC1: + br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr(), rows, cols); + break; + default: + cout << "ERR: Invalid image format" << endl; + break; + } dst = dstMat; cout << "CUDACopyFrom End" << endl; - - cout << "DST Data" << endl; - cout << "rows: " << dstMat.rows << endl; - cout << "cols: " << dstMat.cols << endl; - cout << "type: " << dstMat.type() << endl; } }; diff --git a/openbr/plugins/cuda/copyfrom.cu b/openbr/plugins/cuda/copyfrom.cu index 2b93f4b..2a85f93 100644 --- a/openbr/plugins/cuda/copyfrom.cu +++ b/openbr/plugins/cuda/copyfrom.cu @@ -1,7 +1,9 @@ namespace br { namespace cuda { namespace cudacopyfrom { - //template void wrapper(void* src, T* out, int rows, int cols) { - void wrapper(void* src, float* dst, const int rows, const int cols) { - cudaMemcpy(dst, src, rows*cols*sizeof(float), cudaMemcpyDeviceToHost); + template void wrapper(void* src, T* dst, int rows, int cols) { + cudaMemcpy(dst, src, rows*cols*sizeof(T), cudaMemcpyDeviceToHost); cudaFree(src); } + + template void wrapper(void*, float*, int, int); + template void wrapper(void*, unsigned char*, int, int); }}} diff --git a/openbr/plugins/cuda/copyto.cpp b/openbr/plugins/cuda/copyto.cpp index 3e8cd48..7288553 100644 --- a/openbr/plugins/cuda/copyto.cpp +++ b/openbr/plugins/cuda/copyto.cpp @@ -11,9 +11,7 @@ using namespace cv; extern string type2str(int type); namespace br { namespace cuda { namespace cudacopyto { - //template - //void wrapper(const T* in, void** out, const int rows, const int cols); - void wrapper(const unsigned char* in, void** out, const int rows, const int cols); + template void wrapper(const T* in, void** out, const int rows, const int cols); }}} namespace br @@ -31,11 +29,10 @@ private: void* cudaMemPtr; switch(srcMat.type()) { - //case CV_32FC1: - // br::cuda::cudacopyfrom::wrapper(srcMat.ptr(), &cudaMemPtr, rows, cols); - // break; + case CV_32FC1: + br::cuda::cudacopyto::wrapper(srcMat.ptr(), &cudaMemPtr, rows, cols); + break; case CV_8UC1: - //br::cuda::cudacopyfrom::wrapper(srcMat.ptr(), &cudaMemPtr, rows, cols); br::cuda::cudacopyto::wrapper(srcMat.ptr(), &cudaMemPtr, rows, cols); break; default: diff --git a/openbr/plugins/cuda/copyto.cu b/openbr/plugins/cuda/copyto.cu index c4885a4..feecb83 100644 --- a/openbr/plugins/cuda/copyto.cu +++ b/openbr/plugins/cuda/copyto.cu @@ -1,8 +1,9 @@ namespace br { namespace cuda { namespace cudacopyto { - //template - //void wrapper(const T* in, void** out, const int rows, const int cols) { - void wrapper(const unsigned char* in, void** out, const int rows, const int cols) { - cudaMalloc(out, rows*cols*sizeof(unsigned char)); - cudaMemcpy(*out, in, rows*cols*sizeof(unsigned char), cudaMemcpyHostToDevice); + template void wrapper(const T* in, void** out, const int rows, const int cols) { + cudaMalloc(out, rows*cols*sizeof(T)); + cudaMemcpy(*out, in, rows*cols*sizeof(T), cudaMemcpyHostToDevice); } + + template void wrapper(const float* in, void** out, const int rows, const int cols); + template void wrapper(const unsigned char* in, void** out, const int rows, const int cols); }}}