Discussion:
CUDA Kernel for Python Code
2017-05-06 10:24:51 UTC
I am trying to write a CUDA kernel for computing a piece of Python code. I would need to sort the data inside the kernel but since there are no built in functions that would sort the data so I am not sure what would be the best way to implement this. Any suggestions on how to implement it would be appreciated. Feel free to put some sample code or point me to online resources that have a similar problem.

for i in xrange(0,img_size_x-window_size):
for j in xrange(0,img_size_y-window_size):
kernel = img[i:i+window_size,j:j+window_size]
kernel_flat = np.sort(kernel.flatten())
# Calculate the rank
rank = np.where(kernel_flat == img[i,j])[0][0]
img_mod[i,j] = int((rank * 255 )/(window_size_squared))

Thanks
Jerome Kieffer
2017-05-09 07:30:35 UTC
On Sat, 6 May 2017 10:24:51 +0000
I am trying to write a CUDA kernel for computing a piece of Python code. I would need to sort the data inside the kernel but since there are no built in functions that would sort the data so I am not sure what would be the best way to implement this. Any suggestions on how to implement it would be appreciated. Feel free to put some sample code or point me to online resources that have a similar problem.
kernel = img[i:i+window_size,j:j+window_size]
kernel_flat = np.sort(kernel.flatten())
# Calculate the rank
rank = np.where(kernel_flat == img[i,j])[0][0]
img_mod[i,j] = int((rank * 255 )/(window_size_squared))
There are a couple of sort available in parallel, among them the
bitonic-sort is pretty well adapted to this kind of problems.

Your code looks like a median filter. Resources are available on the