Loop
The loop functions provide a more flexible interface to the Poplar
Repeat*
classes. They allow you to
specify the start, end and increment values of the count, and also make the
count variable available to the program in the body of the loop.
#include <popops/Loop.hpp>
Functions to provide counted loops of programs.
-
namespace popops
Common functions, such as elementwise and reductions.
Typedefs
Functions
-
poplar::program::Sequence countedLoop(poplar::Graph &graph, std::size_t begin, std::size_t end, size_t step, const CountedLoopBodyType &body, const poplar::DebugContext &debugContext = {})
Create a loop program with constant initial count, increment and end value.
The loop count is passed to the body program.
The program is equivalent to:
for(unsigned i = begin; i != end; i += step){ body; }
- Parameters
graph – The graph the loop program will be added to.
begin – Initial counter value.
end – Counter end value (exclusive).
step – The increment added on each loop pass (must be greater than zero).
body – The loop body program to run on each loop pass.
debugContext – Optional debug information.
- Returns
A program providing the above loop function.
-
poplar::program::Sequence countedLoop(poplar::Graph &graph, std::size_t count, const CountedLoopBodyType &body, const poplar::DebugContext &debugContext = {})
Create a loop program which executes
count
times.The loop count is passed to the body program.
The program is equivalent to:
This is equivalent to poplar::Program::Repeat but with a loop counter that is passed to the body program. (It is actually implemented using poplar::Program::RepeatWhileTrue with a test for the count variable reachingfor(unsigned i = 0; i != count; i += 1){ body; }
count
.)- Parameters
graph – The graph the loop program will be added to.
count – Number of loop iterations to execute.
body – The loop body program to run on each loop pass.
debugContext – Optional debug information.
- Returns
A program providing the above loop function.
-
poplar::Tensor addForLoopCounterVertex(poplar::Graph &graph, const poplar::Tensor &count, const poplar::Tensor &countLimit, int countStep, unsigned tile, poplar::program::Sequence &prog, const poplar::DebugContext &di)
-
poplar::program::Sequence countedForLoop(poplar::Graph &graph, const poplar::Tensor &count, int initialCount, const poplar::Tensor &countLimit, int countStep, const poplar::program::Program &body, const poplar::DebugContext &debugContext = {})
Create a for-loop program with constant initial count and increment, and a tensor as the end value.
The use of a tensor as the loop end value means that the number of iterations can be calculated at run time. The loop count variable
count
is provided by the program that calls the loop program so it can be passed to the body program.The program is equivalent to:
for(unsigned count = initialCount; count != countLimit; count += countStep){ body; }
- Parameters
graph – The graph the loop program will be added to.
count – The loop count tensor, available to the
body
program with element type INT or UNSIGNED_INT. Value initialised by this function.initialCount – Initial counter value.
countLimit – Count limit tensor.
countStep – The increment added to the
count
tensor on each loop pass.body – The loop body program to run on each loop pass.
debugContext – Optional debug information.
- Returns
A program providing the above loop function.
-
poplar::program::Sequence countedForLoop(poplar::Graph &graph, int initialCount, const poplar::Tensor &countLimit, int countStep, const poplar::program::Program &body, const poplar::DebugContext &debugContext = {})
Create a for loop program with constant initial count and increment and a tensor as the end value.
The use of a tensor as the loop end value means that the number of iterations can be calculated at run time. The count tensor is created internally and is not available to the body program.
The program is equivalent to:
for(unsigned count = initialCount; count != countLimit; count += countStep){ body; }
- Parameters
graph – The graph the loop program will be added to.
initialCount – Initial counter value.
countLimit – Count limit tensor.
countStep – The increment added to the
count
tensor on each loop pass.body – The loop body program to run on each loop pass.
debugContext – Optional debug information.
- Returns
A program providing the above loop function
-
poplar::program::Sequence countedLoop(poplar::Graph &graph, std::size_t begin, std::size_t end, size_t step, const CountedLoopBodyType &body, const poplar::DebugContext &debugContext = {})