-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43295 from PixelTracksAlpaka/alpaka_port_13_1_por…
…table Pixel Alpaka Migration: Portable Product [II]
- Loading branch information
Showing
34 changed files
with
699 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 | ||
|
||
// 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 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 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 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 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 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 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 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 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 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 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.