Skip to content

Commit 87ce3a0

Browse files
committed
Add a zeroInitialise() method to the Portable objects and collections
Add a zeroInitialise() method to the PortableObject and PortableCollection templates that erases the data in the Buffer by writing zeros (bytes containing '\0') to it. On the host, zeroInitialise() can be called without arguments to execute immediately, or with a queue to be run asynchronously. On the device, zeroInitialise() requires a queue and can only be run asynchronously.
1 parent f6e0fc4 commit 87ce3a0

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

DataFormats/Portable/interface/PortableDeviceCollection.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class PortableDeviceCollection {
7070
ConstBuffer buffer() const { return *buffer_; }
7171
ConstBuffer const_buffer() const { return *buffer_; }
7272

73+
// erases the data in the Buffer by writing zeros (bytes containing '\0') to it
74+
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
75+
void zeroInitialise(TQueue&& queue) {
76+
alpaka::memset(std::forward<TQueue>(queue), *buffer_, 0x00);
77+
}
78+
7379
private:
7480
std::optional<Buffer> buffer_; //!
7581
Layout layout_; //
@@ -275,7 +281,13 @@ class PortableDeviceMultiCollection {
275281
ConstBuffer buffer() const { return *buffer_; }
276282
ConstBuffer const_buffer() const { return *buffer_; }
277283

278-
// Extract the sizes array
284+
// erases the data in the Buffer by writing zeros (bytes containing '\0') to it
285+
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
286+
void zeroInitialise(TQueue&& queue) {
287+
alpaka::memset(std::forward<TQueue>(queue), *buffer_, 0x00);
288+
}
289+
290+
// extract the sizes array
279291
SizesArray sizes() const {
280292
SizesArray ret;
281293
portablecollection::constexpr_for<0, members_>([&](auto i) { ret[i] = get<i>().layout_.metadata().size(); });

DataFormats/Portable/interface/PortableDeviceObject.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ class PortableDeviceObject {
5050
// access the product
5151
Product& value() { return *buffer_->data(); }
5252
Product const& value() const { return *buffer_->data(); }
53+
Product const& const_value() const { return *buffer_->data(); }
5354

5455
Product* data() { return buffer_->data(); }
5556
Product const* data() const { return buffer_->data(); }
57+
Product const* const_data() const { return buffer_->data(); }
5658

5759
Product& operator*() { return *buffer_->data(); }
5860
Product const& operator*() const { return *buffer_->data(); }
@@ -65,6 +67,12 @@ class PortableDeviceObject {
6567
ConstBuffer buffer() const { return *buffer_; }
6668
ConstBuffer const_buffer() const { return *buffer_; }
6769

70+
// erases the data in the Buffer by writing zeros (bytes containing '\0') to it
71+
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
72+
void zeroInitialise(TQueue&& queue) {
73+
alpaka::memset(std::forward<TQueue>(queue), *buffer_, 0x00);
74+
}
75+
6876
private:
6977
std::optional<Buffer> buffer_;
7078
};

DataFormats/Portable/interface/PortableHostCollection.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class PortableHostCollection {
6969
ConstBuffer buffer() const { return *buffer_; }
7070
ConstBuffer const_buffer() const { return *buffer_; }
7171

72+
// erases the data in the Buffer by writing zeros (bytes containing '\0') to it
73+
void zeroInitialise() {
74+
std::memset(std::data(*buffer_), 0x00, alpaka::getExtentProduct(*buffer_) * sizeof(std::byte));
75+
}
76+
77+
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
78+
void zeroInitialise(TQueue&& queue) {
79+
alpaka::memset(std::forward<TQueue>(queue), *buffer_, 0x00);
80+
}
81+
7282
// part of the ROOT read streamer
7383
static void ROOTReadStreamer(PortableHostCollection* newObj, Layout& layout) {
7484
// destroy the default-constructed collection
@@ -278,12 +288,23 @@ class PortableHostMultiCollection {
278288
ConstBuffer buffer() const { return *buffer_; }
279289
ConstBuffer const_buffer() const { return *buffer_; }
280290

281-
// Extract the sizes array
291+
// erases the data in the Buffer by writing zeros (bytes containing '\0') to it
292+
void zeroInitialise() {
293+
std::memset(std::data(*buffer_), 0x00, alpaka::getExtentProduct(*buffer_) * sizeof(std::byte));
294+
}
295+
296+
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
297+
void zeroInitialise(TQueue&& queue) {
298+
alpaka::memset(std::forward<TQueue>(queue), *buffer_, 0x00);
299+
}
300+
301+
// extract the sizes array
282302
SizesArray sizes() const {
283303
SizesArray ret;
284304
portablecollection::constexpr_for<0, members_>([&](auto i) { ret[i] = get<i>().layout_.metadata().size(); });
285305
return ret;
286306
}
307+
287308
// part of the ROOT read streamer
288309
static void ROOTReadStreamer(PortableHostMultiCollection* newObj, Implementation& onfileImpl) {
289310
newObj->~PortableHostMultiCollection();

DataFormats/Portable/interface/PortableHostObject.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ class PortableHostObject {
4848
// access the product
4949
Product& value() { return *product_; }
5050
Product const& value() const { return *product_; }
51+
Product const& const_value() const { return *product_; }
5152

5253
Product* data() { return product_; }
5354
Product const* data() const { return product_; }
55+
Product const* const_data() const { return product_; }
5456

5557
Product& operator*() { return *product_; }
5658
Product const& operator*() const { return *product_; }
@@ -63,6 +65,16 @@ class PortableHostObject {
6365
ConstBuffer buffer() const { return *buffer_; }
6466
ConstBuffer const_buffer() const { return *buffer_; }
6567

68+
// erases the data in the Buffer by writing zeros (bytes containing '\0') to it
69+
void zeroInitialise() {
70+
std::memset(std::data(*buffer_), 0x00, alpaka::getExtentProduct(*buffer_) * sizeof(std::byte));
71+
}
72+
73+
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
74+
void zeroInitialise(TQueue&& queue) {
75+
alpaka::memset(std::forward<TQueue>(queue), *buffer_, 0x00);
76+
}
77+
6678
// part of the ROOT read streamer
6779
static void ROOTReadStreamer(PortableHostObject* newObj, Product& product) {
6880
// destroy the default-constructed object

0 commit comments

Comments
 (0)