copy; 2017 Boitumelo Ruf. All rights reserved.
Example program performing a 5x5 gaussian blur on a GPU with CUDA. The CUDA kernel expects a cudaTextureObject_t
with 4 bytes per pixel, which hold the color coded in RGBA. It uses an unsigned int to fetch the pixel data from the texture and references each channel as a uchar array of size 4.
For gaussian kernel convolution the image data is stored in a shared array to share between threads within one thread block. After convolving the data is stored into a cudaSurfaceObject_t
, which is a writable address space in texture memory.
On host side the program uses the cv::Mat
container of OpenCV to load, store and visualize the input and output images. The program incoorporates a custom function that uploads the cv::Mat
into a cudaTextureObject_t
and downloads the cudaSurfaceObject_t
into a cv::Mat
.
Note that it is common practise in the context of GPGPU to use a vectorized image data where each pixel holds 4 bytes of image data, i.e. RGBA. Since OpenCV by default uses the BGR format it is required to pretransform the image from BGR to RGBA.
This program is developed and tested on Ubuntu 16.04 with GCC 5.4 and depends on following 3rd party libraries:
- Qt >5.0
- OpenCV >3.0
- CUDA >7.5
- Download or clone repository.
- Copy
src/cuda.pri.tpl
andsrc/opencv.pri.tpl
intosrc/cuda.pri
andsrc/opencv.pri
. - Replace tags
<edit-here>
insrc/cuda.pri
andsrc/opencv.pri
with corresponding information such as version number and root directory of OpenCV and CUDA installations. - Open
CUDA-GrayscaleCvt.pro
with QtCreator or runqmake CUDA-GaussianBlur.pro
. - Build and run with image as command line argument.
CUDA-GaussianBlur ../assets/tsukuba.png
. Build output is located in bin/.
NOTE: You might need to add the path to the .so
files of OpenCV and CUDA to the LD_LIBRARY_PATH (see qmake output) if you want to start the program from the terminal.
Input [Martull et al. (2012)]:
Martull et al. (2012)
Martull, S.; Peris, M. & Fukui, K. "Realistic cg stereo image dataset with ground truth disparity maps", Proceedings of the International Conference on Pattern Recognition (ICPR), 2012, vol. 111, pp. 117-118.