|
| 1 | +# Parallel Processing in Finch |
| 2 | + |
| 3 | +## Modelling the Architecture |
| 4 | + |
| 5 | +Finch uses a simple, hierarchical representation of devices and tasks to model |
| 6 | +different kind of parallel processing. An [`AbstractDevice`](@ref) is a physical or |
| 7 | +virtual device on which we can execute tasks, which may each be represented by |
| 8 | +an [`AbstractTask`](@ref). |
| 9 | + |
| 10 | +```@docs |
| 11 | +AbstractTask |
| 12 | +AbstractDevice |
| 13 | +``` |
| 14 | + |
| 15 | +The current task in a compilation context can be queried with |
| 16 | +[`get_task`](@ref). Each device has a set of numbered child |
| 17 | +tasks, and each task has a parent task. |
| 18 | + |
| 19 | +```@docs |
| 20 | +get_num_tasks |
| 21 | +get_task_num |
| 22 | +get_device |
| 23 | +get_parent_task |
| 24 | +``` |
| 25 | + |
| 26 | +## Data Movement |
| 27 | + |
| 28 | +Before entering a parallel loop, a tensor may reside on a single task, or |
| 29 | +represent a single view of data distributed across multiple tasks, or represent |
| 30 | +multiple separate tensors local to multiple tasks. A tensor's data must be |
| 31 | +resident in the current task to process operations on that tensor, such as loops |
| 32 | +over the indices, accesses to the tensor, or `declare`, `freeze`, or `thaw`. |
| 33 | +Upon entering a parallel loop, we must transfer the tensor to the tasks |
| 34 | +where it is needed. Upon exiting the parallel loop, we may need to combine |
| 35 | +the data from multiple tasks into a single tensor. |
| 36 | + |
| 37 | +There are two cases, depending on whether the tensor is declared outside the |
| 38 | +parallel loop or is a temporary tensor declared within the parallel loop. |
| 39 | + |
| 40 | +If the tensor is a temporary tensor declared within the parallel loop, we call |
| 41 | +`bcast` to broadcast the tensor to all tasks. |
| 42 | + |
| 43 | +If the tensor is declared outside the parallel loop, we call `scatter` to |
| 44 | +send it to the tasks where it is needed. Note that if the tensor is in `read` mode, |
| 45 | +`scatter` may simply `bcast` the entire tensor to all tasks. If the device has global |
| 46 | +memory, `scatter` may also be a no-op. When the parallel loop is exited, we call |
| 47 | +`gather` to reconcile the data from multiple tasks back into a single tensor. |
| 48 | + |
| 49 | +Each of these operations begins with a `_send` variant on one task, and |
| 50 | +finishes with a `_recv` variant on the recieving task. |
| 51 | + |
| 52 | +```@docs |
| 53 | +bcast |
| 54 | +bcast_send |
| 55 | +bcast_recv |
| 56 | +scatter |
| 57 | +scatter_send |
| 58 | +scatter_recv |
| 59 | +gather |
| 60 | +gather_send |
| 61 | +gather_recv |
| 62 | +``` |
0 commit comments