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: HeterogeneousCore/AlpakaCore/README.md
+36-26Lines changed: 36 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,53 +58,52 @@ Note that even if for Event data formats the examples above used `DataFormats` p
58
58
59
59
### Implicit data transfers
60
60
61
-
Both EDProducers and ESProducers make use of implicit data transfers.
61
+
Both EDProducers and ESProducers make use of implicit data transfers. In CPU backends these data transfers are omitted, and the host-side and the "device-side" data products are the same.
62
62
63
-
#### EDProducer
63
+
#### Data copy definitions
64
64
65
-
In EDProducers for each device-side data product a transfer from the device memory space to the host memory space is registered automatically. The data product is copied only if the job has another EDModule that consumes the host-side data product. The framework code to issue the transfer makes use of `cms::alpakatools::CopyToHost` class template that must be specialized along
65
+
The implicit host-to-device and device-to-host copies rely on specialization of `cms::alpakatools::CopyToDevice` and `cms::alpakatools::CopyToHost` class templates, respectively. These have to be specialized along
static auto copyAsync(TQueue& queue, TSrc const& deviceProduct) -> TDst {
74
-
// code to construct TDst object, and launch the asynchronous memcpy from the device of TQueue to the host
73
+
requires alpaka::isQueue<TQueue>
74
+
static auto copyAsync(TQueue& queue, TSrc const& hostProduct) -> TDst {
75
+
// code to construct TDst object, and launch the asynchronous memcpy from the host to the device of TQueue
75
76
return ...;
76
77
}
77
78
};
78
79
}
79
80
```
80
-
Note that the destination (host-side) type `TDst` can be different from or the same as the source (device-side) type `TSrc` as far as the framework is concerned. For example, in the `PortableCollection` model the types are different. The `copyAsync()` member function is easiest to implement as a template over `TQueue`. The framework handles the necessary synchronization between the copy function and the consumer in a non-blocking way.
81
-
82
-
The `CopyToHost` class template is partially specialized for all `PortableCollection` instantiations.
83
-
84
-
#### ESProducer
85
-
86
-
In ESProducers for each host-side data product a transfer from the host memory space to the device memory space (of the backend of the ESProducer) is registered automatically. The data product is copied only if the job has another ESProducer or EDModule that consumes the device-side data product. The framework code to issue makes use of `cms::alpakatools::CopyToDevice` class template that must be specialized along
static auto copyAsync(TQueue& queue, TSrc const& hostProduct) -> TDst {
95
-
// code to construct TDst object, and launch the asynchronous memcpy from the host to the device of TQueue
89
+
requires alpaka::isQueue<TQueue>
90
+
static auto copyAsync(TQueue& queue, TSrc const& deviceProduct) -> TDst {
91
+
// code to construct TDst object, and launch the asynchronous memcpy from the device of TQueue to the host
96
92
return ...;
97
93
}
98
94
};
99
95
}
100
96
```
101
-
Note that the destination (device-side) type `TDst` can be different from or the same as the source (host-side) type `TSrc` as far as the framework is concerned. For example, in the `PortableCollection` model the types are different. The `copyAsync()` member function is easiest to implement as a template over `TQueue`. The framework handles the necessary synchronization between the copy function and the consumer in a non-blocking way.
97
+
respectively.
98
+
99
+
Note that the destination (device-side/host-side) type `TDst` can be different from or the same as the source (host-side/device-side) type `TSrc` as far as the framework is concerned. For example, in the `PortableCollection` model the types are different. The `copyAsync()` member function is easiest to implement as a template over `TQueue`. The framework handles the necessary synchronization between the copy function and the consumer in a non-blocking way.
100
+
101
+
Both `CopyToDevice` and `CopyToHost` class templates are partially specialized for all `PortableObject` and `PortableCollection` instantiations.
102
102
103
-
The `CopyToDevice` class template is partially specialized for all `PortableCollection` instantiations.
104
103
105
-
#### Data products with `memcpy()`ed pointers
104
+
#####Data products with `memcpy()`ed pointers
106
105
107
-
If the data product in question contains pointers to memory elsewhere within the data product, after the `alpaka::memcpy()` calls in the `copyAsync()` those pointers still point to device memory, and need to be updated. **Such data products are generally discouraged.** Nevertheless, such pointers can be updated without any additional synchronization by implementing a `postCopy()` function in the `CopyToHost` specialization along (extending the `CopyToHost` example [above](#edproducer))
106
+
If the data product in question contains pointers to memory elsewhere within the data product, after the `alpaka::memcpy()` calls in the `copyAsync()` those pointers still point to device memory, and need to be updated. **Such data products are generally discouraged.** Nevertheless, such pointers can be updated without any additional synchronization by implementing a `postCopy()` function in the `CopyToHost` specialization along (extending the `CopyToHost` example [above](#data-copy-definitions))
108
107
```cpp
109
108
namespacecms::alpakatools {
110
109
template <>
@@ -121,7 +120,18 @@ namespace cms::alpakatools {
121
120
```
122
121
The `postCopy()` is called after the operations enqueued in the `copyAsync()` have finished. The code in `postCopy()` must be such that the call to `postCopy()` can be omitted on CPU backends.
123
122
124
-
Note that for `CopyToDevice` such `postCopy()` functionality is **not** provided. It should be possible to a issue kernel call (via an intermediate host-side function) from the `CopyToDevice::copyAsync()` function to achieve the same effect.
123
+
Note that for `CopyToDevice` such `postCopy()` functionality is **not** provided. It should be possible to a issue kernel call from the `CopyToDevice::copyAsync()` function to achieve the same effect.
124
+
125
+
126
+
#### EDProducer
127
+
128
+
In EDProducers for each device-side data product a transfer from the device memory space to the host memory space is registered automatically. The data product is copied only if the job has another EDModule that consumes the host-side data product. For each device-side data product a specialization of `cms::alpakatools::CopyToHost` is required to exist.
129
+
130
+
In addition, for each host-side data product a transfer from the host memory space to the device meory space is registered autmatically **if** a `cms::alpakatools::CopyToDevice` specialization exists. The data product is copied only if the job has another EDModule that consumes the device-side data product.
131
+
132
+
#### ESProducer
133
+
134
+
In ESProducers for each host-side data product a transfer from the host memory space to the device memory space (of the backend of the ESProducer) is registered automatically. The data product is copied only if the job has another ESProducer or EDModule that consumes the device-side data product. For each host-side data product a specialization of `cms::alpakatools::CopyToDevice` is required to exist.
125
135
126
136
### `PortableCollection`
127
137
@@ -157,7 +167,7 @@ Note that currently Alpaka-based ESSources are not supported. If you need to pro
157
167
158
168
The Alpaka-based modules have a notion of a _host memory space_ and _device memory space_ for the Event and EventSetup data products. The data products in the host memory space are accessible for non-Alpaka modules, whereas the data products in device memory space are available only for modules of the specific Alpaka backend. The host backend(s) use the host memory space directly.
159
169
160
-
The EDModules get `device::Event` and `device::EventSetup` from the framework, from which data products in both host memory space and device memory space can be accessed. Data products can also be produced to either memory space. For all data products produced in the device memory space an implicit data copy from the device memory space to the host memory space is registered as discussed above. The `device::Event::queue()` returns the Alpaka `Queue` object into which all work in the EDModule must be enqueued.
170
+
The EDModules get `device::Event` and `device::EventSetup` from the framework, from which data products in both host memory space and device memory space can be accessed. Data products can also be produced to either memory space. As discussed [above](#edproducer), for each data product produced into the device memory space an implicit data copy from the device memory space to the host memory space is registered, and for each data produced produced into the host memory space for which `cms::alpakatools::CopyToDevice` is specialized an implicit data copy from the host memory space to the device memory space is registered. The `device::Event::queue()` returns the Alpaka `Queue` object into which all work in the EDModule must be enqueued.
161
171
162
172
The ESProducer can have two different `produce()` function signatures
163
173
* If the function has the usual `TRecord const&` parameter, the function can read an ESProduct from the host memory space, and produce another product into the host memory space. An implicit copy of the data product from the host memory space to the device memory space (of the backend of the ESProducer) is registered as discussed above.
0 commit comments