Optimized Belief Propagation (CPU and GPU)
KernelFilter.cu
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
27 #include "KernelFilterHeader.cuh"
28 #include <cuda_runtime.h>
29 #include <cuda.h>
31 #include "RunImp/UtilityFuncts.h"
32 
37 namespace beliefprop_cuda {
38 
39 //kernel to convert the unsigned int pixels to float pixels in an image when
40 //smoothing is not desired but the pixels need to be converted to floats
41 //the input image is stored as unsigned ints
42 //output filtered image stored in float_image_pixels
44  unsigned int* uint_image_pixels, float* float_image_pixels,
45  unsigned int width_images, unsigned int height_images)
46 {
47  //get x and y indices corresponding to current CUDA thread
48  const unsigned int x_val = blockIdx.x * blockDim.x + threadIdx.x;
49  const unsigned int y_val = blockIdx.y * blockDim.y + threadIdx.y;
50 
51  //make sure that (x_val, y_val) is within image bounds
52  if (beliefprop::WithinImageBounds(x_val, y_val, width_images, height_images)) {
53  //retrieve the float-value of the unsigned int pixel value at the current location
54  float_image_pixels[y_val*width_images + x_val] = (float)uint_image_pixels[y_val*width_images + x_val];;
55  }
56 }
57 
58 //kernel to apply a horizontal filter on each pixel of the image in parallel
59 //input image stored in texture imagePixelsFloatToFilterTexture
60 //output filtered image stored in filtered_image
61 template<BpImData_t T>
62 __global__ void FilterImageAcross(
63  const T* image_to_filter, float* filtered_image,
64  unsigned int width_images, unsigned int height_images,
65  const float* image_filter, unsigned int size_filter)
66 {
67  //get x and y indices corresponding to current CUDA thread
68  const unsigned int x_val = blockIdx.x * blockDim.x + threadIdx.x;
69  const unsigned int y_val = blockIdx.y * blockDim.y + threadIdx.y;
70 
71  //make sure that (x_val, y_val) is within image bounds
72  if (beliefprop::WithinImageBounds(x_val, y_val, width_images, height_images)) {
73  beliefprop::FilterImageAcrossProcessPixel<T>(x_val, y_val, image_to_filter, filtered_image,
74  width_images, height_images, image_filter, size_filter);
75  }
76 }
77 
78 //kernel to apply a vertical filter on each pixel of the image in parallel
79 //input image stored in texture imagePixelsFloatToFilterTexture
80 //output filtered image stored in filtered_image
81 template<BpImData_t T>
82 __global__ void FilterImageVertical(
83  const T* image_to_filter, float* filtered_image,
84  unsigned int width_images, unsigned int height_images,
85  const float* image_filter, unsigned int size_filter)
86 {
87  //get x and y indices corresponding to current CUDA thread
88  const unsigned int x_val = blockIdx.x * blockDim.x + threadIdx.x;
89  const unsigned int y_val = blockIdx.y * blockDim.y + threadIdx.y;
90 
91  //make sure that (x_val, y_val) is within image bounds
92  if (beliefprop::WithinImageBounds(x_val, y_val, width_images, height_images)) {
93  beliefprop::FilterImageVerticalProcessPixel<T>(x_val, y_val, image_to_filter, filtered_image,
94  width_images, height_images, image_filter, size_filter);
95  }
96 }
97 
98 };
Header for the kernel to apply a horizontal/vertical filter to image data.
Functions for smoothing input images that are used in both optimized CPU and CUDA implementations.
Contains namespace with utility functions for implementation.
Namespace to define global kernel functions for parallel belief propagation processing using CUDA.
__global__ void FilterImageAcross(const T *image_to_filter, float *filtered_image, unsigned int width_images, unsigned int height_images, const float *image_filter, unsigned int size_filter)
Kernel to apply a horizontal filter on each pixel of the image in parallel the input image is stored ...
Definition: KernelFilter.cu:62
__global__ void FilterImageVertical(const T *image_to_filter, float *filtered_image, unsigned int width_images, unsigned int height_images, const float *image_filter, unsigned int size_filter)
Kernel to apply a vertical filter on each pixel of the image in parallel the input image is stored as...
Definition: KernelFilter.cu:82
__global__ void convertUnsignedIntImageToFloat(unsigned int *uint_image_pixels, float *float_image_pixels, unsigned int width_images, unsigned int height_images)
Definition: KernelFilter.cu:43
ARCHITECTURE_ADDITION bool WithinImageBounds(unsigned int x_val, unsigned int y_val, unsigned int width, unsigned int height)
Checks if the current point is within the image bounds Assumed that input x/y vals are above zero sin...