Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DataFormats/EcalDigi/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags EDM_PLUGIN="1"/>
</library>
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsEcalDigiTrivialSerialisationPortable">
<use name="DataFormats/AlpakaCommon"/>
<use name="DataFormats/EcalDigi"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags ALPAKA_BACKENDS="1"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need

  <flags EDM_PLUGIN="1"/>

?

Copy link
Copy Markdown
Contributor Author

@ghyls ghyls Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit the reason it's not there is because I forgot to add it, but technically looks like it doesn't:

 Default  value  is 1 for <package>/<plugins>/BuildFile.xml and 0 for
 all otherBuildFile.xml

I will add it though, thanks. I agree that it's better to have it explicitly.

<flags EDM_PLUGIN="1"/>
</library>
5 changes: 5 additions & 0 deletions DataFormats/EcalDigi/plugins/alpaka/TrivialSerialisation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "DataFormats/EcalDigi/interface/alpaka/EcalDigiDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactoryDevice.h"

DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(EcalDigiDeviceCollection);
8 changes: 8 additions & 0 deletions DataFormats/EcalRecHit/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags EDM_PLUGIN="1"/>
</library>
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsEcalRecHitTrivialSerialisationPortable">
<use name="DataFormats/AlpakaCommon"/>
<use name="DataFormats/EcalRecHit"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags ALPAKA_BACKENDS="1"/>
Copy link
Copy Markdown
Contributor

@fwyzard fwyzard Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<flags EDM_PLUGIN="1"/>

?

And so for all other plugins.

<flags EDM_PLUGIN="1"/>
</library>
5 changes: 5 additions & 0 deletions DataFormats/EcalRecHit/plugins/alpaka/TrivialSerialisation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactoryDevice.h"

DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(EcalUncalibratedRecHitDeviceCollection);
10 changes: 10 additions & 0 deletions DataFormats/HcalRecHit/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags EDM_PLUGIN="1"/>
</library>

<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsHcalRecHitTrivialSerialisationPortable">
<use name="DataFormats/AlpakaCommon"/>
<use name="DataFormats/HcalRecHit"/>
<use name="DataFormats/Portable"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags ALPAKA_BACKENDS="1"/>
<flags EDM_PLUGIN="1"/>
</library>
5 changes: 5 additions & 0 deletions DataFormats/HcalRecHit/plugins/alpaka/TrivialSerialisation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "DataFormats/HcalRecHit/interface/alpaka/HcalRecHitDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactoryDevice.h"

DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(hcal::RecHitDeviceCollection);
9 changes: 9 additions & 0 deletions DataFormats/ParticleFlowReco/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags EDM_PLUGIN="1"/>
</library>

<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsParticleFlowRecoTrivialSerialisationPortable">
<use name="DataFormats/AlpakaCommon"/>
<use name="DataFormats/ParticleFlowReco"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags ALPAKA_BACKENDS="1"/>
<flags EDM_PLUGIN="1"/>
</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Eigen/Core>

#include "DataFormats/ParticleFlowReco/interface/alpaka/PFClusterDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitDeviceCollection.h"
#include "DataFormats/ParticleFlowReco/interface/alpaka/PFRecHitFractionDeviceCollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactoryDevice.h"

DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(reco::PFRecHitDeviceCollection);
DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(reco::PFClusterDeviceCollection);
DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(reco::PFRecHitFractionDeviceCollection);
36 changes: 36 additions & 0 deletions DataFormats/Portable/interface/PortableDeviceCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "DataFormats/Common/interface/Uninitialized.h"
#include "DataFormats/Portable/interface/PortableCollectionCommon.h"
#include "DataFormats/TrivialSerialisation/interface/MemoryCopyTraits.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"

Expand Down Expand Up @@ -146,4 +147,39 @@ class PortableDeviceCollection {
View view_; //!
};

namespace ngt {

// Specialize MemoryCopyTraits for PortableDeviceCollection
template <typename T, typename TDev>
struct MemoryCopyTraits<PortableDeviceCollection<T, TDev>> {
using value_type = PortableDeviceCollection<T, TDev>;

// Properties are the collection size: T::size_type, or std::array<T::size_type, N> for SoABlocks.
using Properties = decltype(std::declval<value_type>()->metadata().size());

static Properties properties(value_type const& object) { return object->metadata().size(); }

template <typename TQueue>
static void initialize(TQueue& queue, value_type& object, Properties const& size)
requires(alpaka::isQueue<TQueue>)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add here a comment along the same lines as PortableHostCollection ?

{
// Replace the default-constructed empty object with one where the buffer
// has been allocated in global device memory
object = value_type(queue, size);
}

static std::vector<std::span<std::byte>> regions(value_type& object) {
std::byte* address = reinterpret_cast<std::byte*>(object.buffer().data());
size_t size = alpaka::getExtentProduct(object.buffer());
return {{address, size}};
}

static std::vector<std::span<const std::byte>> regions(value_type const& object) {
const std::byte* address = reinterpret_cast<const std::byte*>(object.buffer().data());
size_t size = alpaka::getExtentProduct(object.buffer());
return {{address, size}};
}
};
} // namespace ngt

#endif // DataFormats_Portable_interface_PortableDeviceCollection_h
25 changes: 25 additions & 0 deletions DataFormats/Portable/interface/PortableDeviceObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/Uninitialized.h"
#include "DataFormats/TrivialSerialisation/interface/MemoryCopyTraits.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"

Expand Down Expand Up @@ -80,4 +81,28 @@ class PortableDeviceObject {
std::optional<Buffer> buffer_;
};

namespace ngt {

// Specialize MemoryCopyTraits for PortableDeviceObject
template <typename TDev, typename T>
struct MemoryCopyTraits<PortableDeviceObject<TDev, T>> {
template <typename TQueue>
requires(alpaka::isQueue<TQueue>)
static void initialize(TQueue& queue, PortableDeviceObject<TDev, T>& object) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add here a (corrected) comment along the same lines as PortableHostObject ?

// Replace the default-constructed empty object with one where the
// buffer has been allocated in global device memory
object = PortableDeviceObject<TDev, T>(queue);
}

static std::vector<std::span<std::byte>> regions(PortableDeviceObject<TDev, T>& object) {
return {{reinterpret_cast<std::byte*>(object.data()), sizeof(T)}};
}

static std::vector<std::span<const std::byte>> regions(PortableDeviceObject<TDev, T> const& object) {
return {{reinterpret_cast<std::byte const*>(object.data()), sizeof(T)}};
}
};

} // namespace ngt

#endif // DataFormats_Portable_interface_PortableDeviceObject_h
11 changes: 10 additions & 1 deletion DataFormats/Portable/interface/PortableHostCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,17 @@ namespace ngt {
// The properties needed to initialize a new PrortableHostCollection are just its size.
static Properties properties(value_type const& object) { return object->metadata().size(); }

// Replace the default-constructed empty object with one where the buffer has been allocated in pageable system memory.
template <typename TQueue>
requires(alpaka::isQueue<TQueue>)
static void initialize(TQueue& queue, value_type& object, Properties const& size) {
// Replace the default-constructed empty object with one where the buffer
// has been allocated in pinned host memory.
object = value_type(queue, size);
}

static void initialize(value_type& object, Properties const& size) {
// Replace the default-constructed empty object with one where the buffer
// has been allocated in pageable host memory.
object = value_type(cms::alpakatools::host(), size);
}

Expand Down
14 changes: 12 additions & 2 deletions DataFormats/Portable/interface/PortableHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,21 @@ namespace ngt {

template <typename T>
struct MemoryCopyTraits<PortableHostObject<T>> {
// This specialisation requires a initialize() method, but does not need to pass any parameters to it.
// This specialisation requires an initialize() method, but does not need to
// pass any parameters to it.
using Properties = void;

template <typename TQueue>
requires(alpaka::isQueue<TQueue>)
static void initialize(TQueue& queue, PortableHostObject<T>& object) {
// Replace the default-constructed empty object with one where the buffer
// has been allocated in pinned host memory
object = PortableHostObject<T>(queue);
}

static void initialize(PortableHostObject<T>& object) {
// Replace the default-constructed empty object with one where the buffer has been allocated in pageable system memory.
// Replace the default-constructed empty object with one where the buffer
// has been allocated in pageable host memory.
object = PortableHostObject<T>(cms::alpakatools::host());
}

Expand Down
9 changes: 9 additions & 0 deletions DataFormats/PortableTestObjects/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags EDM_PLUGIN="1"/>
</library>

<library file="alpaka/*.cc" name="DataFormatsPortableTestObjectsPluginsAlpaka">
<use name="DataFormats/AlpakaCommon"/>
<use name="DataFormats/PortableTestObjects"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags ALPAKA_BACKENDS="1"/>
<flags EDM_PLUGIN="1"/>
</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "DataFormats/PortableTestObjects/interface/alpaka/TestDeviceCollection.h"
#include "DataFormats/PortableTestObjects/interface/alpaka/TestDeviceObject.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactoryDevice.h"

DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(portabletest::TestDeviceCollection);
DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(portabletest::TestDeviceCollection2);
DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(portabletest::TestDeviceCollection3);
DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(portabletest::TestDeviceObject);
8 changes: 8 additions & 0 deletions DataFormats/TrackSoA/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags EDM_PLUGIN="1"/>
</library>
<library file="alpaka/TrivialSerialisation.cc" name="DataFormatsTrackSoATrivialSerialisationPortable">
<use name="DataFormats/AlpakaCommon"/>
<use name="DataFormats/TrackSoA"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/TrivialSerialisation"/>
<flags ALPAKA_BACKENDS="1"/>
<flags EDM_PLUGIN="1"/>
</library>
5 changes: 5 additions & 0 deletions DataFormats/TrackSoA/plugins/alpaka/TrivialSerialisation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "DataFormats/TrackSoA/interface/alpaka/TracksSoACollection.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/TrivialSerialisation/interface/alpaka/SerialiserFactoryDevice.h"

DEFINE_TRIVIAL_SERIALISER_PLUGIN_DEVICE(reco::TracksSoACollection);
22 changes: 12 additions & 10 deletions DataFormats/TrivialSerialisation/interface/MemoryCopyTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,38 @@ namespace ngt {

// Checks if the properties method is defined
template <typename T>
concept HasTrivialCopyProperties = requires(T const& object) { MemoryCopyTraits<T>::properties(object); };
concept HasTrivialCopyProperties = requires(T const& object) { ngt::MemoryCopyTraits<T>::properties(object); };

// Get the return type of properties(...), if it exists.
template <typename T>
requires HasTrivialCopyProperties<T>
using TrivialCopyProperties = decltype(MemoryCopyTraits<T>::properties(std::declval<T const&>()));
requires ngt::HasTrivialCopyProperties<T>
using TrivialCopyProperties = decltype(ngt::MemoryCopyTraits<T>::properties(std::declval<T const&>()));

// Checks if the declaration of initialize(...) is consistent with the presence or absence of properties.
template <typename T>
concept HasValidInitialize =
// does not have properties(...) and initialize(object) takes a single argument, or
(not HasTrivialCopyProperties<T> and requires(T& object) { MemoryCopyTraits<T>::initialize(object); }) or
(not ngt::HasTrivialCopyProperties<T> and
requires(T& object) { ngt::MemoryCopyTraits<T>::initialize(object); }) or
// does have properties(...) and initialize(object, props) takes two arguments
(HasTrivialCopyProperties<T> and
requires(T& object, TrivialCopyProperties<T> props) { MemoryCopyTraits<T>::initialize(object, props); });
(ngt::HasTrivialCopyProperties<T> and requires(T& object, ngt::TrivialCopyProperties<T> props) {
ngt::MemoryCopyTraits<T>::initialize(object, props);
});

// Checks for const and non const memory regions
template <typename T>
concept HasRegions = requires(T& object, T const& const_object) {
MemoryCopyTraits<T>::regions(object);
MemoryCopyTraits<T>::regions(const_object);
ngt::MemoryCopyTraits<T>::regions(object);
ngt::MemoryCopyTraits<T>::regions(const_object);
};

// Checks if there is a valid specialisation of MemoryCopyTraits for a type T
template <typename T>
concept HasMemoryCopyTraits =
// Has memory regions declared and
(HasRegions<T>) and
(ngt::HasRegions<T>) and
// has either no initialize(...) or a valid one
(not requires { &MemoryCopyTraits<T>::initialize; } or HasValidInitialize<T>);
(not requires { &ngt::MemoryCopyTraits<T>::initialize; } or ngt::HasValidInitialize<T>);

// Checks if finalize(...) is defined
template <typename T>
Expand Down
13 changes: 13 additions & 0 deletions DataFormats/TrivialSerialisation/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@
<use name="catch2"/>
<use name="DataFormats/TrivialSerialisation"/>
</bin>


<bin name="TestDataFormatsTrivialSerialisationPortable" file="alpaka/test_catch2_*.cc,alpaka/test_catch2_*.dev.cc">
<use name="alpaka"/>
<use name="catch2"/>
<use name="Eigen"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/Portable"/>
<use name="DataFormats/PortableTestObjects"/>
<use name="DataFormats/TrivialSerialisation"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<flags ALPAKA_BACKENDS="1"/>
</bin>
Loading