Skip to content

Commit c3aebf8

Browse files
committed
Document the PortableObject types
1 parent c52f258 commit c3aebf8

File tree

1 file changed

+67
-6
lines changed

1 file changed

+67
-6
lines changed

DataFormats/Portable/README.md

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,71 @@
1+
## Define portable data formats that wrap a simple C-style `struct` and can be persisted to ROOT files
2+
3+
### `PortableHostObject<T>`
4+
5+
`PortableHostObject<T>` is a class template that wraps a `struct` type `T` and an alpaka host buffer, that owns the
6+
memory where the `struct` is allocated. The content of the `struct` is persistent, while the buffer itself is transient.
7+
Specialisations of this template can be persisted, but requre special ROOT read rules to read the data into an alpaka
8+
memory buffer.
9+
10+
The traditional way to declare these rules would be to add them to the `classes_def.xml` file. This method is described
11+
here for reference, but is deprecated. See below for a simpler method.
12+
For example, to declare the read rules for `portabletest::TestHostObject` based on the `portabletest::TestStruct` `struct`,
13+
one would add to the same `classes_def.xml` file where `portabletest::TestHostObject` is declared:
14+
```xml
15+
<read
16+
sourceClass="portabletest::TestHostObject"
17+
targetClass="portabletest::TestHostObject"
18+
version="[1-]"
19+
source="portabletest::TestStruct* product_;"
20+
target="buffer_,product_"
21+
embed="false">
22+
<![CDATA[
23+
portabletest::TestHostObject::ROOTReadStreamer(newObj, *onfile.product_);
24+
]]>
25+
</read>
26+
```
27+
28+
The recommended way to declare these rules is to create a `classes.cc` file along with `classes.h`, and use the
29+
`SET_PORTABLEHOSTOBJECT_READ_RULES` macro. For example, to declare the rules for `portabletest::TestHostObject` one
30+
would create the file `classes.cc` with the content:
31+
```c++
32+
#include "DataFormats/Portable/interface/PortableHostObjectReadRules.h"
33+
#include "DataFormats/PortableTestObjects/interface/TestHostObject.h"
34+
35+
SET_PORTABLEHOSTOBJECT_READ_RULES(portabletest::TestHostObject);
36+
```
37+
38+
`PortableHostObject<T>` objects can also be read back in "bare ROOT" mode, without any dictionaries.
39+
They have no implicit or explicit references to alpaka (neither as part of the class signature nor as part of its name).
40+
This could make it possible to read them back with different portability solutions in the future.
41+
42+
### `PortableDeviceObject<T, TDev>`
43+
44+
`PortableDeviceObject<T, TDev>` is a class template that wraps a `struct` type `T` and an alpaka device buffer, that
45+
owns the memory where the `struct` is allocated.
46+
To avoid confusion and ODR-violations, the `PortableDeviceObject<T, TDev>` template cannot be used with the `Host`
47+
device type.
48+
Specialisations of this template are transient and cannot be persisted.
49+
50+
### `ALPAKA_ACCELERATOR_NAMESPACE::PortableObject<T>`
51+
52+
`ALPAKA_ACCELERATOR_NAMESPACE::PortableObject<T>` is a template alias that resolves to either
53+
`PortableHostObject<T>` or `PortableDeviceObject<T, ALPAKA_ACCELERATOR_NAMESPACE::Device>`, depending on the
54+
backend.
55+
56+
### `PortableObject<T, TDev>`
57+
58+
`PortableObject<T, TDev>` is an alias template that resolves to `ALPAKA_ACCELERATOR_NAMESPACE::PortableObject<T>`
59+
for the matching device.
60+
61+
162
## Define portable data formats that wrap SoA data structures and can be persisted to ROOT files
263
364
### `PortableHostCollection<T>`
465
566
`PortableHostCollection<T>` is a class template that wraps a SoA type `T` and an alpaka host buffer, which owns the
667
memory where the SoA is allocated. The content of the SoA is persistent, while the buffer itself is transient.
7-
Specialisations of this template can be persisted, but requre specil ROOT read rules to read the data into a single
68+
Specialisations of this template can be persisted, but requre special ROOT read rules to read the data into a single
869
memory buffer.
970
1071
The original way to declare these rules, now deprecated, is to add them to the `classes_def.xml` file. For example,
@@ -24,17 +85,16 @@ would add to the same `classes_def.xml` file where `portabletest::TestHostCollec
2485
```
2586

2687
The new, recommended way to declare these rules is to create a `classes.cc` file along with `classes.h`, and use the
27-
`SET_PORTABLEHOSTCOLLECTION_READ_RULES`. For example, to declare the rules for `portabletest::TestHostCollection` one
28-
would create the file `classes.cc` with the content:
88+
`SET_PORTABLEHOSTCOLLECTION_READ_RULES` macro. For example, to declare the rules for `portabletest::TestHostCollection`
89+
one would create the file `classes.cc` with the content:
2990
```c++
3091
#include "DataFormats/Portable/interface/PortableHostCollectionReadRules.h"
3192
#include "DataFormats/PortableTestObjects/interface/TestHostCollection.h"
3293

3394
SET_PORTABLEHOSTCOLLECTION_READ_RULES(portabletest::TestHostCollection);
3495
```
3596
36-
`PortableHostCollection<T>` can also be read back in "bare ROOT" mode, without any dictionaries.
37-
97+
`PortableHostCollection<T>` collections can also be read back in "bare ROOT" mode, without any dictionaries.
3898
They have no implicit or explicit references to alpaka (neither as part of the class signature nor as part of its name).
3999
This could make it possible to read them back with different portability solutions in the future.
40100
@@ -61,7 +121,8 @@ for the matching device.
61121
## Notes
62122
63123
Modules that are supposed to work with only host types (_e.g._ dealing with de/serialisation, data transfers, _etc._)
64-
should explicitly use the `PortableHostCollection<T>` types.
124+
should explicitly use the `PortableHostObject<T>` and `PortableHostCollection<T>` types.
65125
66126
Modules that implement portable interfaces (_e.g._ producers) should use the generic types based on
127+
`ALPAKA_ACCELERATOR_NAMESPACE::PortableObject<T>` or `PortableObject<T, TDev>`, and
67128
`ALPAKA_ACCELERATOR_NAMESPACE::PortableCollection<T>` or `PortableCollection<T, TDev>`.

0 commit comments

Comments
 (0)