Skip to content

Commit

Permalink
Try simple transpose + filterHorizontally
Browse files Browse the repository at this point in the history
  • Loading branch information
jwest591 authored and Jon committed Jan 18, 2025
1 parent 83d8373 commit adcd017
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion labs/memory_bound/loop_interchange_2/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include <fstream>
#include <ios>

void transpose(const uint8_t* src, uint8_t* dest, const size_t width, const size_t height)
{
for (size_t r = 0; r < height; ++r) {
for (size_t c = 0; c < width; ++c) {
dest[c*height+r] = src[r*width+c];
}
}
}


// Applies Gaussian blur in independent vertical lines
static void filterVertically(uint8_t *output, const uint8_t *input,
const int width, const int height,
Expand Down Expand Up @@ -129,7 +139,9 @@ void blur(uint8_t *output, const uint8_t *input, const int width,
constexpr int shift = 4;

// A pair of 1-dimensional passes to achieve 2-dimensional transform
filterVertically(temp, input, width, height, kernel, radius, shift);
transpose(input, temp, width, height);
filterHorizontally(output, temp, height, width, kernel, radius, shift);
transpose(output, temp, height, width);
filterHorizontally(output, temp, width, height, kernel, radius, shift);
}

Expand Down

0 comments on commit adcd017

Please sign in to comment.