Skip to content

Commit 19318aa

Browse files
committed
Extend the serialisation mechanism to device products
1 parent 6172e86 commit 19318aa

45 files changed

Lines changed: 1787 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DataFormats/Common/interface/DeviceProduct.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ namespace edm {
9999
return *static_cast<M const*>(metadata_.get());
100100
}
101101

102+
T const& product() const { return data_; }
103+
T& product() { return data_; }
104+
102105
private:
103106
std::shared_ptr<DeviceProductMetadataBase const> metadata_; //!
104107
std::type_info const* metadataType_ = nullptr; //!

DataFormats/EcalDigi/plugins/BuildFile.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
<use name="HeterogeneousCore/TrivialSerialisation"/>
44
<flags EDM_PLUGIN="1"/>
55
</library>
6+
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsEcalDigiTrivialSerialisationPortable">
7+
<use name="DataFormats/EcalDigi"/>
8+
<use name="HeterogeneousCore/AlpakaInterface"/>
9+
<use name="HeterogeneousCore/TrivialSerialisation"/>
10+
<flags ALPAKA_BACKENDS="1"></flags>
11+
</library>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "DataFormats/EcalDigi/interface/alpaka/EcalDigiDeviceCollection.h"
2+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
3+
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactory.h"
4+
5+
using namespace ALPAKA_ACCELERATOR_NAMESPACE;
6+
7+
DEFINE_PORTABLE_TRIVIAL_SERIALISER_PLUGIN(EcalDigiDeviceCollection, "EcalDigiDeviceCollection");

DataFormats/EcalRecHit/plugins/BuildFile.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
<use name="HeterogeneousCore/TrivialSerialisation"/>
44
<flags EDM_PLUGIN="1"/>
55
</library>
6+
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsEcalRecHitTrivialSerialisationPortable">
7+
<use name="DataFormats/EcalRecHit"/>
8+
<use name="HeterogeneousCore/AlpakaInterface"/>
9+
<use name="HeterogeneousCore/TrivialSerialisation"/>
10+
<flags ALPAKA_BACKENDS="1"></flags>
11+
</library>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
2+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
3+
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactory.h"
4+
5+
using namespace ALPAKA_ACCELERATOR_NAMESPACE;
6+
7+
DEFINE_PORTABLE_TRIVIAL_SERIALISER_PLUGIN(EcalUncalibratedRecHitDeviceCollection,
8+
"EcalUncalibratedRecHitDeviceCollection");

DataFormats/HcalRecHit/plugins/BuildFile.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
<use name="HeterogeneousCore/TrivialSerialisation"/>
44
<flags EDM_PLUGIN="1"/>
55
</library>
6+
7+
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsHcalRecHitTrivialSerialisationPortable">
8+
<use name="DataFormats/HcalRecHit"/>
9+
<use name="DataFormats/Portable"/>
10+
<use name="HeterogeneousCore/AlpakaInterface"/>
11+
<use name="HeterogeneousCore/TrivialSerialisation"/>
12+
<flags ALPAKA_BACKENDS="1"></flags>
13+
</library>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "DataFormats/HcalRecHit/interface/alpaka/HcalRecHitDeviceCollection.h"
2+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
3+
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactory.h"
4+
5+
DEFINE_PORTABLE_TRIVIAL_SERIALISER_PLUGIN(ALPAKA_ACCELERATOR_NAMESPACE::hcal::RecHitDeviceCollection,
6+
"hcal::RecHitDeviceCollection");

DataFormats/ParticleFlowReco/plugins/BuildFile.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
<use name="HeterogeneousCore/TrivialSerialisation"/>
44
<flags EDM_PLUGIN="1"/>
55
</library>
6+
7+
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsParticleFlowRecoTrivialSerialisationPortable">
8+
<use name="DataFormats/ParticleFlowReco"/>
9+
<use name="HeterogeneousCore/AlpakaInterface"/>
10+
<use name="HeterogeneousCore/TrivialSerialisation"/>
11+
<flags ALPAKA_BACKENDS="1"></flags>
12+
</library>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <Eigen/Core>
2+
3+
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFClusterDeviceCollection.h"
4+
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
5+
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitFractionDeviceCollection.h"
6+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
7+
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactory.h"
8+
9+
DEFINE_PORTABLE_TRIVIAL_SERIALISER_PLUGIN(ALPAKA_ACCELERATOR_NAMESPACE::reco::PFRecHitDeviceCollection,
10+
"reco::PFRecHitDeviceCollection");
11+
12+
DEFINE_PORTABLE_TRIVIAL_SERIALISER_PLUGIN(ALPAKA_ACCELERATOR_NAMESPACE::reco::PFClusterDeviceCollection,
13+
"reco::PFClusterDeviceCollection");
14+
15+
DEFINE_PORTABLE_TRIVIAL_SERIALISER_PLUGIN(ALPAKA_ACCELERATOR_NAMESPACE::reco::PFRecHitFractionDeviceCollection,
16+
"reco::PFRecHitFractionDeviceCollection");

DataFormats/Portable/interface/PortableDeviceCollection.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "DataFormats/Common/interface/Uninitialized.h"
1414
#include "DataFormats/Portable/interface/PortableCollectionCommon.h"
15+
#include "DataFormats/TrivialSerialisation/interface/MemoryCopyTraits.h"
1516
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
1617
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
1718

@@ -159,4 +160,37 @@ class PortableDeviceCollection {
159160
View view_; //!
160161
};
161162

163+
namespace ngt {
164+
165+
// Specialize MemoryCopyTraits for PortableDeviceCollection
166+
template <typename T, typename TDev>
167+
struct MemoryCopyTraits<PortableDeviceCollection<T, TDev>> {
168+
using value_type = PortableDeviceCollection<T, TDev>;
169+
170+
// Properties are the collection size: T::size_type, or std::array<T::size_type, N> for SoABlocks.
171+
using Properties = decltype(std::declval<value_type>()->metadata().size());
172+
173+
static Properties properties(value_type const& object) { return object->metadata().size(); }
174+
175+
template <typename TQueue>
176+
static void initialize(value_type& object, TQueue& queue, Properties const& size)
177+
requires(alpaka::isQueue<TQueue>)
178+
{
179+
object = value_type(queue, size);
180+
}
181+
182+
static std::vector<std::span<std::byte>> regions(value_type& object) {
183+
std::byte* address = reinterpret_cast<std::byte*>(object.buffer().data());
184+
size_t size = alpaka::getExtentProduct(object.buffer());
185+
return {{address, size}};
186+
}
187+
188+
static std::vector<std::span<const std::byte>> regions(value_type const& object) {
189+
const std::byte* address = reinterpret_cast<const std::byte*>(object.buffer().data());
190+
size_t size = alpaka::getExtentProduct(object.buffer());
191+
return {{address, size}};
192+
}
193+
};
194+
} // namespace ngt
195+
162196
#endif // DataFormats_Portable_interface_PortableDeviceCollection_h

0 commit comments

Comments
 (0)