| | 34 | Generally, we don't want to copy replicated data — it's a waste of space! We definitely don't want to do it for large data structures, and in particular, we don't want to do it for arrays. After all, that can change the asymptotic work complexity of a program. To keep it simple, we are for the moment focusing on avoiding replicating arrays, as this is were our practical problems are coming from at the moment. (Some cases of replicated scalars are also eliminated by fusion.) |
| | 35 | |
| | 36 | === Repeated segments === |
| | 37 | |
| | 38 | A replicated array results is always represented by a segmented array; more precisely, by a segmented array where a contiguous sequence of segments contains the same data. For example, we have |
| | 39 | {{{ |
| | 40 | replicateP 3 [:1, 2, 3:] = [:[:1, 2, 3:], [:1, 2, 3:], [:1, 2, 3:]:] |
| | 41 | where |
| | 42 | [:[:1, 2, 3:], [:1, 2, 3:], [:1, 2, 3:]:] = ([:3, 3, 3:], [:1, 2, 3, 1, 2, 3, 1, 2, 3:]) |
| | 43 | }}} |
| | 44 | and |
| | 45 | {{{ |
| | 46 | replicateP^ [:2, 3:] [:[:1, 2:], [:3:]:] = [:[:1, 2:], [:1, 2:], [:3:], [:3:], [:3:]:] |
| | 47 | where |
| | 48 | [:[:1, 2:], [:1, 2:], [:3:], [:3:], [:3:]:] = ([:2, 2, 1, 1, 1:], [:1, 2, 1, 2, 3, 3, 3:]) |
| | 49 | }}} |
| | 50 | |
| | 51 | === Collapse repeated segments === |
| | 52 | |
| | 53 | In practice, segments descriptors store more information than just the segment length. They at least additionally store the start position of each segment in the data array. In the conventional representation, an invariant is that the start positions are such that the segments don't overlap. To represent arrays with repeated segments more efficiently, we propose to relax that invariant. Specifically, all start positions of a contiguous sequence of repeated segments are the same; i.e., the segment data is stored only once per sequence of repeated segments. |
| | 54 | |
| | 55 | == Related work == |
| | 56 | |
| | 57 | * The work-efficient vectorisation paper by Prins et al. Their approach only works in a first-order language. |
| | 58 | * Blelloch's work on the space-behaviour of data-parallel programs. |
| | 59 | |
| | 60 | ---- |
| | 61 | |
| | 62 | = OLD MATERIAL = |
| | 63 | |
| | 64 | |
| | 65 | == A plan to fix the problem == |
| | 66 | |