Skip to content

Commit

Permalink
Avoided unnecessary memory alloc.
Browse files Browse the repository at this point in the history
  • Loading branch information
simveit committed Dec 17, 2024
1 parent 699476d commit c86b55b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions labs/memory_bound/loop_interchange_2/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ static void filterVertically(uint8_t *output, const uint8_t *input,
}
}

std::unique_ptr<int[]> dot = std::make_unique<int[]>(width * (height - 2 * radius));
// Accum
for (int r = radius; r < height - radius; r++) {
for (int c = 0; c < width; c++) {
int dot = 0;
for (int i = 0; i < radius + 1 + radius; i++) {
dot[(r - radius) * width + c] += input[(r - radius + i) * width + c] * kernel[i];
dot += input[(r - radius + i) * width + c] * kernel[i];
}
// Output
int dotIndex = (r - radius) * width + c;
int value = (dot[dotIndex] + rounding) >> shift;
int value = (dot + rounding) >> shift;
output[r * width + c] = static_cast<uint8_t>(value);
}
}
Expand Down

0 comments on commit c86b55b

Please sign in to comment.