You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/containers.rst
+26-22Lines changed: 26 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,39 +1,40 @@
1
1
Containers
2
2
==========
3
3
4
-
Hydra framework provides one dimensional STL-like vector containers for each supported back-end, aliasing the underlying Thrust types. Beyond this, Hydra implements two native multidimensional containers: ``hydra::multivector`` and ``hydra::multiarray`` .
5
-
In these containers, the data corresponding to each dimension is stored in contiguous memory regions and when the container is traversed, each entry is accessed as
6
-
a ``hydra::tuple``, where each field holds a value corresponding to a dimension. Both classes implement an interface completely compliant with a STL vector and
7
-
also provides constant and non-constant accessors for the single dimensional data. The container
8
-
``hydra::multivector`` is suitable to store data-sets where the dimensions are represented by entries with different POD types. ``hydra::multiarray`` is designed to store data-sets where all dimensions are represented by fields with the same type. Data is always copyable across different back-ends and movable between containers on the same back-end.
9
-
10
-
4
+
Hydra framework provides an one-dimensional STL-like vector container for each supported back-end, aliasing the underlying Thrust types. The framework also implements two native multidimensional containers called hydra::multivector`` and ``hydra::multiarray`` .
5
+
6
+
In these containers, the data corresponding to each dimension is stored in contiguous memory addresses that can be traversed in a CPU/GPU cache friendly way, independently of the other dimensions. In the case of multidimensional containers, when the data is traversed each entry is accessed as
7
+
a ``hydra::tuple`` object, where each field holds a value corresponding to a dimension.
8
+
11
9
One-dimensional containers
12
10
--------------------------
13
11
14
-
Hydra's one-dimensional containers are aliases to the corresponding [Thrust]_ vectors and defined for each supported back-end. They are:
12
+
Hydra's one-dimensional containers are aliases to the corresponding [Thrust]_ vectors and are defined for each supported back-end. They are:
15
13
16
-
1. ``hydra::device::vector`` : storage allocated in the device back-end defined at compile time using the macro ``THRUST_DEVICE_SYSTEM``
17
-
2. ``hydra::host::vector`` : storage allocated in the device back-end defined at compile time using the macro ``THRUST_HOST_SYSTEM``
14
+
1. ``hydra::device::vector`` : storage allocated in the device back-end defined at compile time using the macro ``HYDRA_DEVICE_SYSTEM``
15
+
2. ``hydra::host::vector`` : storage allocated in the device back-end defined at compile time using the macro ``HYDRA_HOST_SYSTEM``
18
16
3. ``hydra::omp::vector`` : storage allocated in the [OpenMP]_ back-end. Usually the CPU memory space.
19
17
4. ``hydra::tbb::vector`` : storage allocated in the [TBB]_ back-end. Usually the CPU memory space.
20
18
5. ``hydra::cuda::vector`` : storage allocated in the [CUDA]_ back-end. The GPU memory space.
21
19
6. ``hydra::cpp::vector`` : storage allocated in the [CPP]_ back-end. Usually the CPU memory
22
20
23
-
The usage of these containers is extensively documented in the [Thrust]_ library.
21
+
The usage of these containers is extensively documented in STL and [Thrust]_ library. Hydra also implements range-semantics for many of these containers.
24
22
25
23
Multi-dimensional containers
26
24
----------------------------
27
25
28
26
Hydra implements two multidimensional containers:``hydra::multivector`` and ``hydra::multiarray``.
29
27
These containers store data using [SoA]_ layout and provides a STL-vector compliant interface.
30
28
31
-
The best way to understand how these containers operates is to visualize them as a table, there each row corresponds to a entry and each column to a dimension. The design of ``hydra::multivector`` and ``hydra::multiarray`` makes possible to iterate over the container to access a complete row
32
-
or to iterate over one or more columns to access only the data of interest in a given entry, without to load the entire row.
29
+
Both classes provides constant and non-constant accessors for the single dimensional data. The container
30
+
``hydra::multivector`` is suitable to store data-sets where the dimensions are represented by entries with different POD types. ``hydra::multiarray`` is designed to store data-sets where all dimensions are represented by fields of the same type. Data is always copyable across different back-ends and movable between containers on the same back-end.
31
+
32
+
The best way to understand how these containers operate is to visualize them as a table, there each row corresponds to a entry and each column to a dimension. The design of ``hydra::multivector`` and ``hydra::multiarray`` makes possible to iterate over the container to access a complete row
33
+
or to iterate over one or more columns to access only the data of interest in a given entry, without loading the entire row.
33
34
34
-
When the user iterates over the whole container, each entry (row) is returned as a ``hydra::tuple``. If the user iterates over one single column, the entries have the type of the column. If two or more columns are accessed, entry's data is returned as again as ``hydra::tuple`` containing only the elements of interest. Hydra's multi-dimensional containers can hold any type of data per dimension, but there is not real gain using these containers for describing dimensions with non-POD data.
35
+
When the user iterates over the whole container, each entry (row) is returned as a ``hydra::tuple``. If the user iterates over one single column, the entries have the type of the column. If two or more columns are accessed, entry's data is returned as again as ``hydra::tuple`` containing only the elements of interest. Hydra's multi-dimensional containers can hold any type of data per dimension, but there is not real gain using these containers for describing dimensions with non-POD or non alignable data.
35
36
36
-
Both containers can store the state of arbitrary objects and perform type conversions on-the-fly, using suitable overloaded iterators and ``push_back()`` methods.
37
+
These containers can store the state of arbitrary objects and perform type conversions on-the-fly, using suitable overloaded iterators and ``push_back()`` methods.
37
38
38
39
39
40
``hydra::multivector``
@@ -70,7 +71,7 @@ this will print in stdout something like it :
70
71
...
71
72
(9, 18, 9.0, 18.0)
72
73
73
-
To access the columns the user needs to deploy ``hydra::placeholders``: _0, _1, _2,...,_99;
74
+
To access the columns the user needs ``hydra::placeholders``: _0, _1, _2,...,_99;
74
75
75
76
.. code-block:: cpp
76
77
:name: multivector-example2
@@ -90,7 +91,8 @@ To access the columns the user needs to deploy ``hydra::placeholders``: _0, _1,
90
91
}
91
92
92
93
for(auto x = mvector.begin(_1, _3);
93
-
x != mvector.end(_1, _3); x++ )
94
+
x != mvector.end(_1, _3); ++x )
95
+
94
96
std::cout << *x << std::endl;
95
97
96
98
now in stdout the user will get:
@@ -120,13 +122,13 @@ It is not necessary to access each field stored in each entry to perform a conve
120
122
mvector.push_back(hydra::make_tuple( i, 2*i, i, 2*i));
for(auto x = mvector.begin(caster); x != mvector.end(caster); x++ )
@@ -142,9 +144,11 @@ stdout will look like:
142
144
...
143
145
((9, 18), (9.0, 18.0))
144
146
147
+
Same effect can be
148
+
145
149
146
150
``hydra::multiarray``
147
-
......................
151
+
.................
148
152
149
153
150
154
``hydra::multiarray`` templates are instantiated passing the type and the number of dimensions via and the back-end where memory will be allocated. The snippet
0 commit comments