Commit 699ab0b0d58a813f4625059ca1ee1cc5aedb6b57
1 parent
4e59b2b5
Add kernel function but it's not working
Showing
5 changed files
with
159 additions
and
2 deletions
openbr/plugins/cuda/copyfrom.cpp
| @@ -36,6 +36,9 @@ private: | @@ -36,6 +36,9 @@ private: | ||
| 36 | case CV_8UC1: | 36 | case CV_8UC1: |
| 37 | br::cuda::cudacopyfrom::wrapper(dataPtr[0], dstMat.ptr<unsigned char>(), rows, cols); | 37 | br::cuda::cudacopyfrom::wrapper(dataPtr[0], dstMat.ptr<unsigned char>(), rows, cols); |
| 38 | break; | 38 | break; |
| 39 | + case CV_8UC3: | ||
| 40 | + br::cuda::cudacopyfrom::wrapper(dataPtr[0], dstMat.ptr<unsigned char>(), rows, cols * 3); | ||
| 41 | + break; | ||
| 39 | default: | 42 | default: |
| 40 | cout << "ERR: Invalid image format" << endl; | 43 | cout << "ERR: Invalid image format" << endl; |
| 41 | break; | 44 | break; |
openbr/plugins/cuda/copyto.cpp
| @@ -25,7 +25,10 @@ private: | @@ -25,7 +25,10 @@ private: | ||
| 25 | { | 25 | { |
| 26 | const Mat& srcMat = src.m(); | 26 | const Mat& srcMat = src.m(); |
| 27 | const int rows = srcMat.rows; | 27 | const int rows = srcMat.rows; |
| 28 | - const int cols = srcMat.cols; | 28 | + const int cols = srcMat.cols; |
| 29 | +std::cout << "CopyTo" << std::endl; | ||
| 30 | + std::cout << "rows: " << rows << std::endl; | ||
| 31 | + std::cout << "cols: " << cols << std::endl; | ||
| 29 | 32 | ||
| 30 | // output will be a single pointer to graphics card memory | 33 | // output will be a single pointer to graphics card memory |
| 31 | Mat dstMat = Mat(4, 1, DataType<void*>::type); | 34 | Mat dstMat = Mat(4, 1, DataType<void*>::type); |
| @@ -44,6 +47,9 @@ private: | @@ -44,6 +47,9 @@ private: | ||
| 44 | case CV_8UC1: | 47 | case CV_8UC1: |
| 45 | br::cuda::cudacopyto::wrapper(srcMat.ptr<unsigned char>(), &dstMatData[0], rows, cols); | 48 | br::cuda::cudacopyto::wrapper(srcMat.ptr<unsigned char>(), &dstMatData[0], rows, cols); |
| 46 | break; | 49 | break; |
| 50 | + case CV_8UC3: | ||
| 51 | + br::cuda::cudacopyto::wrapper(srcMat.ptr<unsigned char>(), &dstMatData[0], rows, 3*cols); | ||
| 52 | + break; | ||
| 47 | default: | 53 | default: |
| 48 | cout << "ERR: Invalid image type! " << type2str(srcMat.type()) << endl; | 54 | cout << "ERR: Invalid image type! " << type2str(srcMat.type()) << endl; |
| 49 | return; | 55 | return; |
openbr/plugins/cuda/cudacvt.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
| 2 | + * Copyright 2012 The MITRE Corporation * | ||
| 3 | + * * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| 5 | + * you may not use this file except in compliance with the License. * | ||
| 6 | + * You may obtain a copy of the License at * | ||
| 7 | + * * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| 9 | + * * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software * | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
| 13 | + * See the License for the specific language governing permissions and * | ||
| 14 | + * limitations under the License. * | ||
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
| 16 | + | ||
| 17 | +#include <iostream> | ||
| 18 | +#include <opencv2/imgproc/imgproc.hpp> | ||
| 19 | + | ||
| 20 | +#include <openbr/plugins/openbr_internal.h> | ||
| 21 | +#include <openbr/core/opencvutils.h> | ||
| 22 | +#include <thrust/host_vector.h> | ||
| 23 | +#include <thrust/device_vector.h> | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +using namespace cv; | ||
| 27 | + | ||
| 28 | +namespace br { namespace cuda{ | ||
| 29 | + void cudacvt_wrapper(void* srcPtr, void**dstPtr, int rows, int cols); | ||
| 30 | +}} | ||
| 31 | + | ||
| 32 | +namespace br | ||
| 33 | +{ | ||
| 34 | + | ||
| 35 | +/*! | ||
| 36 | + * \ingroup transforms | ||
| 37 | + * \brief Colorspace conversion. | ||
| 38 | + * \author Li Li \cite Josh Klontz \cite jklontz | ||
| 39 | + */ | ||
| 40 | +class CUDACvtTransform : public UntrainableTransform | ||
| 41 | +{ | ||
| 42 | + Q_OBJECT | ||
| 43 | + Q_ENUMS(ColorSpace) | ||
| 44 | + Q_PROPERTY(ColorSpace colorSpace READ get_colorSpace WRITE set_colorSpace RESET reset_colorSpace STORED false) | ||
| 45 | + Q_PROPERTY(int channel READ get_channel WRITE set_channel RESET reset_channel STORED false) | ||
| 46 | + | ||
| 47 | +public: | ||
| 48 | + enum ColorSpace { Gray = CV_BGR2GRAY, | ||
| 49 | + RGBGray = CV_RGB2GRAY, | ||
| 50 | + HLS = CV_BGR2HLS, | ||
| 51 | + HSV = CV_BGR2HSV, | ||
| 52 | + Lab = CV_BGR2Lab, | ||
| 53 | + Luv = CV_BGR2Luv, | ||
| 54 | + RGB = CV_BGR2RGB, | ||
| 55 | + XYZ = CV_BGR2XYZ, | ||
| 56 | + YCrCb = CV_BGR2YCrCb, | ||
| 57 | + Color = CV_GRAY2BGR }; | ||
| 58 | + | ||
| 59 | +private: | ||
| 60 | + BR_PROPERTY(ColorSpace, colorSpace, Gray) | ||
| 61 | + BR_PROPERTY(int, channel, -1) | ||
| 62 | + | ||
| 63 | + void project(const Template &src, Template &dst) const | ||
| 64 | + { | ||
| 65 | + void* const* srcDataPtr = src.m().ptr<void*>(); | ||
| 66 | + int rows = *((int*) srcDataPtr[1]); | ||
| 67 | + int cols = *((int*) srcDataPtr[2]); | ||
| 68 | + int type = *((int*) srcDataPtr[3]); | ||
| 69 | + std::cout << "CVT" << std::endl; | ||
| 70 | + std::cout << "rows: " << rows << std::endl; | ||
| 71 | + std::cout << "cols: " << cols << std::endl; | ||
| 72 | + | ||
| 73 | + Mat dstMat = Mat(src.m().rows, src.m().cols, CV_8UC1); | ||
| 74 | + void** dstDataPtr = dstMat.ptr<void*>(); | ||
| 75 | + dstDataPtr[1] = srcDataPtr[1]; | ||
| 76 | + dstDataPtr[2] = srcDataPtr[2]; | ||
| 77 | + dstDataPtr[3] = srcDataPtr[3]; | ||
| 78 | + *((int*)dstDataPtr[3]) = CV_8UC1; // not sure if the type of the new mat is the same | ||
| 79 | + | ||
| 80 | + br::cuda::cudacvt_wrapper(srcDataPtr[0], &dstDataPtr[0], rows, cols); | ||
| 81 | + dst = dstMat; | ||
| 82 | + | ||
| 83 | + /* | ||
| 84 | + if (src.m().channels() > 1 || colorSpace == Color) cvtColor(src, dst, colorSpace); | ||
| 85 | + else dst = src; | ||
| 86 | + | ||
| 87 | + if (channel != -1) { | ||
| 88 | + std::vector<Mat> mv; | ||
| 89 | + split(dst, mv); | ||
| 90 | + dst = mv[channel % (int)mv.size()]; | ||
| 91 | + } */ | ||
| 92 | + } | ||
| 93 | +}; | ||
| 94 | + | ||
| 95 | +BR_REGISTER(Transform, CUDACvtTransform) | ||
| 96 | + | ||
| 97 | +} // namespace br | ||
| 98 | + | ||
| 99 | +#include "imgproc/cudacvt.moc" |
openbr/plugins/cuda/cudacvt.cu
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | +#include <iostream> | ||
| 3 | +#include <opencv2/opencv.hpp> | ||
| 4 | +#include <opencv2/gpu/gpu.hpp> | ||
| 5 | +#include "cudadefines.hpp" | ||
| 6 | +#include <opencv2/imgproc/imgproc.hpp> | ||
| 7 | +#include <opencv2/imgproc/imgproc_c.h> | ||
| 8 | +#include <opencv2/highgui/highgui.hpp> | ||
| 9 | +#include <opencv2/highgui/highgui_c.h> | ||
| 10 | + | ||
| 11 | +using namespace std; | ||
| 12 | +using namespace cv; | ||
| 13 | +using namespace cv::gpu; | ||
| 14 | + | ||
| 15 | +namespace br{ namespace cuda { | ||
| 16 | + | ||
| 17 | + __global__ void cudacvt_kernel(uint8_t* srcPtr, uint8_t* dstPtr, int rows, int cols) | ||
| 18 | + { | ||
| 19 | + int rowInd = blockIdx.y*blockDim.y+threadIdx.y; | ||
| 20 | + int colInd = blockIdx.x*blockDim.x+threadIdx.x; | ||
| 21 | + int index = rowInd*cols + colInd; | ||
| 22 | + if (rowInd < 1 || rowInd >= rows-1 || colInd < 1 || colInd >= cols-1) { | ||
| 23 | + if (rowInd >= rows || colInd >= cols) { | ||
| 24 | + return; | ||
| 25 | + } else { | ||
| 26 | + return; | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + dstPtr[index] = 0; | ||
| 31 | + return; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + void cudacvt_wrapper(void* srcPtr, void** dstPtr, int rows, int cols) | ||
| 35 | + { | ||
| 36 | + cudaError_t err; | ||
| 37 | + dim3 threadsPerBlock(8, 8); | ||
| 38 | + dim3 numBlocks(cols/threadsPerBlock.x + 1, | ||
| 39 | + rows/threadsPerBlock.y + 1); | ||
| 40 | + std::cout << "Before malloc" << std::endl; | ||
| 41 | + CUDA_SAFE_MALLOC(dstPtr, rows*cols*sizeof(uint8_t), &err); | ||
| 42 | + std::cout << "After malloc" << std::endl; | ||
| 43 | + | ||
| 44 | + //cudacvt_kernel<<<numBlocks, threadsPerBlock>>>((uint8_t*)srcPtr, (uint8_t*) (*dstPtr), rows, cols); | ||
| 45 | + CUDA_KERNEL_ERR_CHK(&err); | ||
| 46 | + CUDA_SAFE_FREE(srcPtr, &err); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | +}} |
openbr/plugins/cuda/cudadefines.hpp
| @@ -16,7 +16,7 @@ using namespace std; | @@ -16,7 +16,7 @@ using namespace std; | ||
| 16 | cout << pthread_self() << ": CUDA Malloc Error(" << *errPtr << "): " << cudaGetErrorString(*errPtr) << endl; \ | 16 | cout << pthread_self() << ": CUDA Malloc Error(" << *errPtr << "): " << cudaGetErrorString(*errPtr) << endl; \ |
| 17 | throw 0; \ | 17 | throw 0; \ |
| 18 | } \ | 18 | } \ |
| 19 | - /* cout << pthread_self() << ": CUDA Malloc: " << (void*)*(int**)cudaPtrPtr << endl; */; | 19 | + cout << pthread_self() << ": CUDA Malloc: " << (void*)*(int**)cudaPtrPtr << endl; |
| 20 | 20 | ||
| 21 | #define CUDA_SAFE_MEMCPY(dstPtr, srcPtr, count, kind, errPtr) \ | 21 | #define CUDA_SAFE_MEMCPY(dstPtr, srcPtr, count, kind, errPtr) \ |
| 22 | *errPtr = cudaMemcpy(dstPtr, srcPtr, count, kind); \ | 22 | *errPtr = cudaMemcpy(dstPtr, srcPtr, count, kind); \ |