-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Pixel Alpaka Migration: Portable Product [II] #43295
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
Merged
cmsbuild
merged 5 commits into
cms-sw:master
from
PixelTracksAlpaka:alpaka_port_13_1_portable
Nov 24, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
91235b5
Implement PortableObject types
AdrianoDee c52f258
Implement ROOT read rules for PortableHostObject types
fwyzard c3aebf8
Document the PortableObject types
fwyzard f950141
Add a test for writing and reading a PortableTestObject
fwyzard 1066b18
Add alpaka PortableObjects for the beamspot
AdrianoDee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| <use name="clhep"/> | ||
| <use name="rootcore"/> | ||
| <use name="rootsmatrix"/> | ||
| <use name="DataFormats/Common"/> | ||
| <use name="DataFormats/CLHEP"/> | ||
| <use name="DataFormats/GeometrySurface"/> | ||
| <use name="DataFormats/Math"/> | ||
| <use name="rootcore"/> | ||
| <use name="rootsmatrix"/> | ||
| <use name="clhep"/> | ||
| <use name="DataFormats/Portable"/> | ||
| <use name="HeterogeneousCore/AlpakaInterface"/> | ||
| <flags ALPAKA_BACKENDS="!serial"/> | ||
| <export> | ||
| <lib name="1"/> | ||
| </export> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #ifndef DataFormats_BeamSpot_interface_BeamSpotHost_h | ||
| #define DataFormats_BeamSpot_interface_BeamSpotHost_h | ||
|
|
||
| #include "DataFormats/BeamSpot/interface/BeamSpotPOD.h" | ||
| #include "DataFormats/Portable/interface/PortableHostObject.h" | ||
|
|
||
| // simplified representation of the beamspot data, in host memory | ||
| using BeamSpotHost = PortableHostObject<BeamSpotPOD>; | ||
|
|
||
| #endif // DataFormats_BeamSpot_interface_BeamSpotHost_h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||||
| #ifndef DataFormats_BeamSpot_interface_alpaka_BeamSpotDevice_h | ||||||||||||
| #define DataFormats_BeamSpot_interface_alpaka_BeamSpotDevice_h | ||||||||||||
|
|
||||||||||||
| #include "DataFormats/BeamSpot/interface/BeamSpotHost.h" | ||||||||||||
| #include "DataFormats/BeamSpot/interface/BeamSpotPOD.h" | ||||||||||||
| #include "DataFormats/Portable/interface/alpaka/PortableObject.h" | ||||||||||||
| #include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||||||||||||
|
|
||||||||||||
| namespace ALPAKA_ACCELERATOR_NAMESPACE { | ||||||||||||
|
|
||||||||||||
| // simplified representation of the beamspot data, in device global memory | ||||||||||||
| using BeamSpotDevice = PortableObject<BeamSpotPOD>; | ||||||||||||
|
|
||||||||||||
| } // namespace ALPAKA_ACCELERATOR_NAMESPACE | ||||||||||||
|
|
||||||||||||
|
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.
Suggested change
|
||||||||||||
| // check that the portable device collection for the host device is the same as the portable host collection | ||||||||||||
| ASSERT_DEVICE_MATCHES_HOST_COLLECTION(BeamSpotDevice, BeamSpotHost); | ||||||||||||
|
|
||||||||||||
| #endif // DataFormats_BeamSpot_interface_alpaka_BeamSpotDevice_h | ||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "DataFormats/BeamSpot/interface/BeamSpotPOD.h" | ||
| #include "DataFormats/BeamSpot/interface/alpaka/BeamSpotDevice.h" | ||
| #include "DataFormats/Common/interface/DeviceProduct.h" | ||
| #include "DataFormats/Common/interface/Wrapper.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <lcgdict> | ||
| <class name="alpaka_cuda_async::BeamSpotDevice" persistent="false"/> | ||
| <class name="edm::DeviceProduct<alpaka_cuda_async::BeamSpotDevice>" persistent="false"/> | ||
| <class name="edm::Wrapper<edm::DeviceProduct<alpaka_cuda_async::BeamSpotDevice>>" persistent="false"/> | ||
| </lcgdict> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "DataFormats/BeamSpot/interface/BeamSpotPOD.h" | ||
| #include "DataFormats/BeamSpot/interface/alpaka/BeamSpotDevice.h" | ||
| #include "DataFormats/Common/interface/DeviceProduct.h" | ||
| #include "DataFormats/Common/interface/Wrapper.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <lcgdict> | ||
| <class name="alpaka_rocm_async::BeamSpotDevice" persistent="false"/> | ||
| <class name="edm::DeviceProduct<alpaka_rocm_async::BeamSpotDevice>" persistent="false"/> | ||
| <class name="edm::Wrapper<edm::DeviceProduct<alpaka_rocm_async::BeamSpotDevice>>" persistent="false"/> | ||
| </lcgdict> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #include "DataFormats/BeamSpot/interface/BeamSpotHost.h" | ||
| #include "DataFormats/Portable/interface/PortableHostObjectReadRules.h" | ||
|
|
||
| SET_PORTABLEHOSTOBJECT_READ_RULES(BeamSpotHost); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #include "DataFormats/BeamSpot/interface/BeamSpot.h" | ||
| #include "DataFormats/BeamSpot/interface/BeamSpotHost.h" | ||
| #include "DataFormats/BeamSpot/interface/BeamSpotPOD.h" | ||
| #include "DataFormats/Common/interface/Wrapper.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #ifndef DataFormats_Portable_interface_PortableDeviceObject_h | ||
| #define DataFormats_Portable_interface_PortableDeviceObject_h | ||
|
|
||
| #include <cassert> | ||
| #include <optional> | ||
| #include <type_traits> | ||
|
|
||
| #include <alpaka/alpaka.hpp> | ||
|
|
||
| #include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
| #include "HeterogeneousCore/AlpakaInterface/interface/memory.h" | ||
|
|
||
| // generic object in device memory | ||
| template <typename T, typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>> | ||
| class PortableDeviceObject { | ||
| static_assert(not std::is_same_v<TDev, alpaka_common::DevHost>, | ||
| "Use PortableHostObject<T> instead of PortableDeviceObject<T, DevHost>"); | ||
|
|
||
| public: | ||
| using Product = T; | ||
| using Buffer = cms::alpakatools::device_buffer<TDev, Product>; | ||
| using ConstBuffer = cms::alpakatools::const_device_buffer<TDev, Product>; | ||
|
|
||
| PortableDeviceObject() = default; | ||
|
|
||
| PortableDeviceObject(TDev const& device) | ||
| // allocate global device memory | ||
| : buffer_{cms::alpakatools::make_device_buffer<Product>(device)} { | ||
| assert(reinterpret_cast<uintptr_t>(buffer_->data()) % alignof(Product) == 0); | ||
| } | ||
|
|
||
| template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>> | ||
| PortableDeviceObject(TQueue const& queue) | ||
| // allocate global device memory with queue-ordered semantic | ||
| : buffer_{cms::alpakatools::make_device_buffer<Product>(queue)} { | ||
| assert(reinterpret_cast<uintptr_t>(buffer_->data()) % alignof(Product) == 0); | ||
| } | ||
|
|
||
| // non-copyable | ||
| PortableDeviceObject(PortableDeviceObject const&) = delete; | ||
| PortableDeviceObject& operator=(PortableDeviceObject const&) = delete; | ||
|
|
||
| // movable | ||
| PortableDeviceObject(PortableDeviceObject&&) = default; | ||
| PortableDeviceObject& operator=(PortableDeviceObject&&) = default; | ||
|
|
||
| // default destructor | ||
| ~PortableDeviceObject() = default; | ||
|
|
||
| // access the product | ||
| Product& value() { return *buffer_->data(); } | ||
| Product const& value() const { return *buffer_->data(); } | ||
|
|
||
| Product* data() { return buffer_->data(); } | ||
| Product const* data() const { return buffer_->data(); } | ||
|
|
||
| Product& operator*() { return *buffer_->data(); } | ||
| Product const& operator*() const { return *buffer_->data(); } | ||
|
|
||
| Product* operator->() { return buffer_->data(); } | ||
| Product const* operator->() const { return buffer_->data(); } | ||
|
|
||
| // access the buffer | ||
| Buffer buffer() { return *buffer_; } | ||
| ConstBuffer buffer() const { return *buffer_; } | ||
| ConstBuffer const_buffer() const { return *buffer_; } | ||
|
|
||
| private: | ||
| std::optional<Buffer> buffer_; | ||
| }; | ||
|
|
||
| #endif // DataFormats_Portable_interface_PortableDeviceObject_h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #ifndef DataFormats_Portable_interface_PortableHostObject_h | ||
| #define DataFormats_Portable_interface_PortableHostObject_h | ||
|
|
||
| #include <cassert> | ||
| #include <optional> | ||
| #include <type_traits> | ||
|
|
||
| #include <alpaka/alpaka.hpp> | ||
|
|
||
| #include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
| #include "HeterogeneousCore/AlpakaInterface/interface/host.h" | ||
| #include "HeterogeneousCore/AlpakaInterface/interface/memory.h" | ||
|
|
||
| // generic object in host memory | ||
| template <typename T> | ||
| class PortableHostObject { | ||
| public: | ||
| using Product = T; | ||
| using Buffer = cms::alpakatools::host_buffer<Product>; | ||
| using ConstBuffer = cms::alpakatools::const_host_buffer<Product>; | ||
|
|
||
| PortableHostObject() = default; | ||
|
|
||
| PortableHostObject(alpaka_common::DevHost const& host) | ||
| // allocate pageable host memory | ||
| : buffer_{cms::alpakatools::make_host_buffer<Product>()}, product_{buffer_->data()} { | ||
| assert(reinterpret_cast<uintptr_t>(product_) % alignof(Product) == 0); | ||
| } | ||
|
|
||
| template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>> | ||
| PortableHostObject(TQueue const& queue) | ||
| // allocate pinned host memory associated to the given work queue, accessible by the queue's device | ||
| : buffer_{cms::alpakatools::make_host_buffer<Product>(queue)}, product_{buffer_->data()} { | ||
| assert(reinterpret_cast<uintptr_t>(product_) % alignof(Product) == 0); | ||
| } | ||
|
|
||
| // non-copyable | ||
| PortableHostObject(PortableHostObject const&) = delete; | ||
| PortableHostObject& operator=(PortableHostObject const&) = delete; | ||
|
|
||
| // movable | ||
| PortableHostObject(PortableHostObject&&) = default; | ||
| PortableHostObject& operator=(PortableHostObject&&) = default; | ||
|
|
||
| // default destructor | ||
| ~PortableHostObject() = default; | ||
|
|
||
| // access the product | ||
| Product& value() { return *product_; } | ||
| Product const& value() const { return *product_; } | ||
|
|
||
| Product* data() { return product_; } | ||
| Product const* data() const { return product_; } | ||
|
|
||
| Product& operator*() { return *product_; } | ||
| Product const& operator*() const { return *product_; } | ||
|
|
||
| Product* operator->() { return product_; } | ||
| Product const* operator->() const { return product_; } | ||
|
|
||
| // access the buffer | ||
| Buffer buffer() { return *buffer_; } | ||
| ConstBuffer buffer() const { return *buffer_; } | ||
| ConstBuffer const_buffer() const { return *buffer_; } | ||
|
|
||
| // part of the ROOT read streamer | ||
| static void ROOTReadStreamer(PortableHostObject* newObj, Product& product) { | ||
| // destroy the default-constructed object | ||
| newObj->~PortableHostObject(); | ||
| // use the global "host" object returned by cms::alpakatools::host() | ||
| new (newObj) PortableHostObject(cms::alpakatools::host()); | ||
| // copy the data from the on-file object to the new one | ||
| std::memcpy(newObj->product_, &product, sizeof(Product)); | ||
| } | ||
|
|
||
| private: | ||
| std::optional<Buffer> buffer_; //! | ||
| Product* product_; | ||
| }; | ||
|
|
||
| #endif // DataFormats_Portable_interface_PortableHostObject_h |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.