-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Extend the HeterogeneousCore/TrivialSerialisation mechanism to device products
#50154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"/> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| 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); |
| 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); |
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
||
|
|
@@ -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>) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
||
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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); |
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this need
?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
I will add it though, thanks. I agree that it's better to have it explicitly.