|
1 | 1 | # Structure of array (SoA) generation |
2 | 2 |
|
3 | | -The two header files [`SoALayout.h`](SoALayout.h) and [`SoAView.h`](SoAView.h) define preprocessor macros that |
| 3 | +The header file [`SoALayout.h`](SoALayout.h) defines preprocessor macros that |
4 | 4 | allow generating SoA classes. The SoA classes generate multiple, aligned column from a memory buffer. The memory |
5 | 5 | buffer is allocated separately by the user, and can be located in a memory space different from the local one (for |
6 | 6 | example, a SoA located in a GPU device memory can be fully pre-defined on the host and the resulting structure is |
@@ -30,21 +30,18 @@ alignment. |
30 | 30 |
|
31 | 31 | ## View |
32 | 32 |
|
33 | | -`SoAView` is a macro generated templated class allowing access to columns defined in one or multiple `SoALayout`s or |
34 | | -`SoAViews`. The view can be generated in a constant and non-constant flavors. All view flavors provide with the same |
35 | | -interface where scalar elements are accessed with an `operator()`: `soa.scalar()` while columns (Eigen or not) are |
36 | | -accessed via a array of structure (AoS) -like syntax: `soa[index].x()`. The "struct" object returned by `operator[]` |
37 | | -can be used as a shortcut: `auto si = soa[index]; si.z() = si.x() + zi.y();` |
38 | | - |
39 | | -A view can be instanciated by being passed the corresponding layout. |
40 | | - |
41 | 33 | Layout classes also define a `View` and `ConstView` subclass that provide access to each column and |
42 | 34 | scalar of the layout. In addition to those fully parametrized templates, two others levels of parametrization are |
43 | 35 | provided: `ViewTemplate`, `ViewViewTemplateFreeParams` and respectively `ConstViewTemplate`, |
44 | 36 | `ConstViewTemplateFreeParams`. The parametrization of those templates is explained in the [Template |
45 | 37 | parameters section](#template-parameters). |
46 | 38 |
|
47 | | -It is also possible to build a generic `View` or `ConstView` passing from the [Metarecords sublass](#metarecords-subclass). |
| 39 | +The view can be generated in a constant and non-constant flavors. All view flavors provide with the same |
| 40 | +interface where scalar elements are accessed with an `operator()`: `soa.scalar()` while columns (Eigen or not) are |
| 41 | +accessed via a array of structure (AoS) -like syntax: `soa[index].x()`. The "struct" object returned by `operator[]` |
| 42 | +can be used as a shortcut: `auto si = soa[index]; si.z() = si.x() + si.y();` |
| 43 | + |
| 44 | +A view can be instanciated by being passed the corresponding layout or passing from the [Metarecords subclass](#metarecords-subclass). |
48 | 45 | This view can point to data belonging to different SoAs and thus not contiguous in memory. |
49 | 46 |
|
50 | 47 | ## Descriptor |
@@ -199,40 +196,6 @@ AlignedBuffer h_buf (reinterpret_cast<std::byte*>(aligned_alloc(SoA1LayoutAligne |
199 | 196 | SoA1LayoutAligned soaLayout(h_buf.get(), elements); |
200 | 197 | ``` |
201 | 198 |
|
202 | | -A view will derive its column types from one or multiple layouts. The macro generating the view takes a list of layouts or views it |
203 | | -gets is data from as a first parameter, and the selection of the columns the view will give access to as a second parameter. |
204 | | -
|
205 | | -```C++ |
206 | | -// A 1 to 1 view of the layout (except for unsupported types). |
207 | | -GENERATE_SOA_VIEW(SoA1ViewTemplate, |
208 | | - SOA_VIEW_LAYOUT_LIST( |
209 | | - SOA_VIEW_LAYOUT(SoA1Layout, soa1) |
210 | | - ), |
211 | | - SOA_VIEW_VALUE_LIST( |
212 | | - SOA_VIEW_VALUE(soa1, x), |
213 | | - SOA_VIEW_VALUE(soa1, y), |
214 | | - SOA_VIEW_VALUE(soa1, z), |
215 | | - SOA_VIEW_VALUE(soa1, color), |
216 | | - SOA_VIEW_VALUE(soa1, value), |
217 | | - SOA_VIEW_VALUE(soa1, py), |
218 | | - SOA_VIEW_VALUE(soa1, count), |
219 | | - SOA_VIEW_VALUE(soa1, anotherCount), |
220 | | - SOA_VIEW_VALUE(soa1, description), |
221 | | - SOA_VIEW_VALUE(soa1, someNumber) |
222 | | - ) |
223 | | -); |
224 | | -
|
225 | | -using SoA1View = SoA1ViewTemplate<>; |
226 | | -
|
227 | | -SoA1View soaView(soaLayout); |
228 | | -
|
229 | | -for (size_t i=0; i < soaLayout.metadata().size(); ++i) { |
230 | | - auto si = soaView[i]; |
231 | | - si.x() = si.y() = i; |
232 | | - soaView.someNumber() += i; |
233 | | -} |
234 | | -``` |
235 | | - |
236 | 199 | The mutable and const views with the exact same set of columns and their parametrized variants are provided from the layout as: |
237 | 200 |
|
238 | 201 | ```C++ |
|
0 commit comments