Poplar and PopLibs
|
A program that runs one of many programs depending on the value of a tensor. More...
#include <Program.hpp>
Public Member Functions | |
Switch (Tensor control, const std::vector< std::pair< std::int32_t, Program > > &cases, const DebugContext &debugContext={}) | |
Construct a switch with the specified set of cases and an empty default case. More... | |
Switch (Tensor control, const std::vector< std::pair< std::int32_t, Program > > &cases, const Program &defaultCaseBody, const DebugContext &debugContext={}) | |
Construct a switch with the specified set of cases and default case. More... | |
Switch (Tensor control, const DebugContext &debugContext={}) | |
Construct a switch with no cases and an empty default case. More... | |
Switch (Tensor control, const Program &defaultCaseBody, const DebugContext &debugContext={}) | |
Construct a switch with no cases and the specified default case. More... | |
Switch & | add (std::int32_t value, const Program &body) |
Add a case with the specified case value and body. More... | |
Static Public Member Functions | |
static Switch | switchWithBoundsChecking (Tensor control, const std::vector< std::pair< std::int32_t, Program > > &cases, const DebugContext &debugContext={}) |
A helper function that causes the default case to throw an error. | |
static Switch | switchWithUnreachableDefault (Tensor control, const DebugContext &debugContext={}) |
This function lets the compiler assume the default case is unreachable. More... | |
A program that runs one of many programs depending on the value of a tensor.
The controlling tensor must be a scalar of type INT or UNSIGNED_INT.
A switch contains of a number of switch cases, each with a case value and a case body and a default case. The case values must be unique. If the value of the controlling tensor matches the case value of a case the corresponding case body is run, otherwise the default case is run.
poplar::program::Switch::Switch | ( | Tensor | control, |
const std::vector< std::pair< std::int32_t, Program > > & | cases, | ||
const DebugContext & | debugContext = {} |
||
) |
Construct a switch with the specified set of cases and an empty default case.
control | The controlling tensor. |
cases | The cases of the switch: value and program to run. |
debugContext | Optional DebugId and program name. |
poplar::program::Switch::Switch | ( | Tensor | control, |
const std::vector< std::pair< std::int32_t, Program > > & | cases, | ||
const Program & | defaultCaseBody, | ||
const DebugContext & | debugContext = {} |
||
) |
Construct a switch with the specified set of cases and default case.
control | The controlling tensor. |
cases | The cases of the switch: value and program to run. |
defaultCaseBody | The body of the default case. |
debugContext | Optional DebugId and program name. |
poplar::program::Switch::Switch | ( | Tensor | control, |
const DebugContext & | debugContext = {} |
||
) |
poplar::program::Switch::Switch | ( | Tensor | control, |
const Program & | defaultCaseBody, | ||
const DebugContext & | debugContext = {} |
||
) |
Add a case with the specified case value and body.
value | The case value. |
body | The case body. |
|
static |
This function lets the compiler assume the default case is unreachable.
If the control value is something other than one of the cases, it results in undefined behaviour (although there is some very minimal error checking at runtime).