Skip to content

Commit

Permalink
Fixing a bug in the ExecutionKernel
Browse files Browse the repository at this point in the history
  • Loading branch information
JOOpdenhoevel committed Aug 8, 2021
1 parent 0265d8e commit 370b794
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion StencilStream/ExecutionKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ExecutionKernel
stencil_buffer[stage],
UID(grid_width, grid_height));

if (stage < n_generations)
if (i_generation + stage < n_generations)
{
value = trans_func(stencil);
}
Expand Down
9 changes: 2 additions & 7 deletions StencilStream/StencilExecutor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ class StencilExecutor
for (uindex_t i = 0; i < n_passes; i++)
{
Grid output_grid = input_grid.make_output_grid();
uindex_t n_generations_per_pass = pipeline_length;
if (i == n_passes - 1 && n_generations % pipeline_length != 0)
{
n_generations_per_pass = n_generations % pipeline_length;
}

for (uindex_t c = 0; c < input_grid.get_tile_range().c; c++)
{
Expand All @@ -129,7 +124,7 @@ class StencilExecutor
{ cgh.single_task(ExecutionKernelImpl(
trans_func,
i_generation,
n_generations_per_pass,
n_generations,
c * tile_width,
r * tile_height,
grid_width,
Expand All @@ -145,7 +140,7 @@ class StencilExecutor
}
}
input_grid = output_grid;
i_generation += n_generations_per_pass;
i_generation += std::min(n_generations - i_generation, pipeline_length);
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/src/units/ExecutionKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,36 @@ TEST_CASE("Halo values inside the pipeline are handled correctly", "[ExecutionKe
}

REQUIRE(in_pipe::empty());
REQUIRE(out_pipe::empty());
}

TEST_CASE("Incomplete Pipeline with i_generation != 0", "[ExecutionKernel]")
{
using Cell = uint8_t;
auto trans_func = [](Stencil<Cell, 1> const &stencil) {
return stencil[ID(0,0)] + 1;
};

using in_pipe = HostPipe<class IncompletePipelineInPipeID, Cell>;
using out_pipe = HostPipe<class IncompletePipelineOutPipeID, Cell>;
using TestExecutionKernel = ExecutionKernel<decltype(trans_func), Cell, 1, 16, 64, 64, in_pipe, out_pipe>;

for (int c = -16; c < 16+64; c++) {
for (int r = -16; r < 16+64; r++) {
in_pipe::write(0);
}
}

TestExecutionKernel kernel(trans_func, 16, 20, 0, 0, 64, 64, 0);
kernel.operator()();

REQUIRE(in_pipe::empty());

for (int c = 0; c < 64; c++) {
for (int r = 0; r < 64; r++) {
REQUIRE(out_pipe::read() == 4);
}
}

REQUIRE(out_pipe::empty());
}

0 comments on commit 370b794

Please sign in to comment.