Skip to content

3x3 Median filter slow (on GPU) #7302

Answered by abadams
Frontier789 asked this question in Q&A
Discussion options

You must be logged in to vote

I actually published a whole paper on this topic using Halide: https://dl.acm.org/doi/abs/10.1145/3450626.3459773 It includes Halide code in the supplemental material.

First, for a compare and swap you want to use min/max rather than a select: (a, b) = (min(a, b), max(a, b))

Second, you can use a single Func and use update definitions to do the swaps. Use scatter and gather - they let you read and write groups of elements at once, e.g. to sort the elements at positions 1 and 4, you might write something like:

a = f(x, y, 1)
b = f(x, y, 4)
(a, b) = (min(a, b), max(a, b))
f(x, y, scatter(1, 4)) = gather(a, b)

Finally the key to fast medium support (e.g. 9x9) median filters is having each th…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Frontier789
Comment options

Answer selected by Frontier789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants