Skip to content

Commit

Permalink
Remove the default constructor from PortableCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Dec 5, 2024
1 parent 2838418 commit f729449
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 27 deletions.
4 changes: 3 additions & 1 deletion DataFormats/Common/interface/DeviceProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <cassert>
#include <memory>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"

namespace edm {
class DeviceProductBase {
public:
Expand Down Expand Up @@ -45,7 +47,7 @@ namespace edm {
template <typename T>
class DeviceProduct : public DeviceProductBase {
public:
DeviceProduct() = default;
explicit DeviceProduct(edm::AllocateForOverwrite) : data_{edm::allocateForOverwrite} {}

template <typename M, typename... Args>
explicit DeviceProduct(std::shared_ptr<M> metadata, Args&&... args)
Expand Down
11 changes: 8 additions & 3 deletions DataFormats/Portable/interface/PortableDeviceCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableCollectionCommon.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
#include "DataFormats/Portable/interface/PortableCollectionCommon.h"

// generic SoA-based product in device memory
template <typename T, typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
Expand All @@ -24,7 +25,9 @@ class PortableDeviceCollection {
using Buffer = cms::alpakatools::device_buffer<TDev, std::byte[]>;
using ConstBuffer = cms::alpakatools::const_device_buffer<TDev, std::byte[]>;

PortableDeviceCollection() = default;
PortableDeviceCollection() = delete;

explicit PortableDeviceCollection(edm::AllocateForOverwrite) noexcept {}

PortableDeviceCollection(int32_t elements, TDev const& device)
: buffer_{cms::alpakatools::make_device_buffer<std::byte[]>(device, Layout::computeDataSize(elements))},
Expand Down Expand Up @@ -144,7 +147,9 @@ class PortableDeviceMultiCollection {
}

public:
PortableDeviceMultiCollection() = default;
PortableDeviceMultiCollection() = delete;

explicit PortableDeviceMultiCollection(edm::AllocateForOverwrite) noexcept {};

PortableDeviceMultiCollection(int32_t elements, TDev const& device)
: buffer_{cms::alpakatools::make_device_buffer<std::byte[]>(device, Layout<>::computeDataSize(elements))},
Expand Down
5 changes: 4 additions & 1 deletion DataFormats/Portable/interface/PortableDeviceObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"

Expand All @@ -21,7 +22,9 @@ class PortableDeviceObject {
using Buffer = cms::alpakatools::device_buffer<TDev, Product>;
using ConstBuffer = cms::alpakatools::const_device_buffer<TDev, Product>;

PortableDeviceObject() = default;
PortableDeviceObject() = delete;

PortableDeviceObject(edm::AllocateForOverwrite) {}

PortableDeviceObject(TDev const& device)
// allocate global device memory
Expand Down
11 changes: 8 additions & 3 deletions DataFormats/Portable/interface/PortableHostCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableCollectionCommon.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/host.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
#include "DataFormats/Portable/interface/PortableCollectionCommon.h"

// generic SoA-based product in host memory
template <typename T>
Expand All @@ -21,7 +22,9 @@ class PortableHostCollection {
using Buffer = cms::alpakatools::host_buffer<std::byte[]>;
using ConstBuffer = cms::alpakatools::const_host_buffer<std::byte[]>;

PortableHostCollection() = default;
PortableHostCollection() = delete;

explicit PortableHostCollection(edm::AllocateForOverwrite) noexcept {};

PortableHostCollection(int32_t elements, alpaka_common::DevHost const& host)
// allocate pageable host memory
Expand Down Expand Up @@ -154,7 +157,9 @@ class PortableHostMultiCollection {
}

public:
PortableHostMultiCollection() = default;
PortableHostMultiCollection() = delete;

explicit PortableHostMultiCollection(edm::AllocateForOverwrite) noexcept {};

PortableHostMultiCollection(int32_t elements, alpaka_common::DevHost const& host)
// allocate pageable host memory
Expand Down
5 changes: 4 additions & 1 deletion DataFormats/Portable/interface/PortableHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/host.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
Expand All @@ -19,7 +20,9 @@ class PortableHostObject {
using Buffer = cms::alpakatools::host_buffer<Product>;
using ConstBuffer = cms::alpakatools::const_host_buffer<Product>;

PortableHostObject() = default;
PortableHostObject() = delete;

PortableHostObject(edm::AllocateForOverwrite) noexcept {}

PortableHostObject(alpaka_common::DevHost const& host)
// allocate pageable host memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#define DataFormats_SiPixelClusterSoA_interface_SiPixelClustersDevice_h

#include <cstdint>

#include <alpaka/alpaka.hpp>
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersHost.h"

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersHost.h"
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

template <typename TDev>
class SiPixelClustersDevice : public PortableDeviceCollection<SiPixelClustersSoA, TDev> {
public:
SiPixelClustersDevice() = default;
SiPixelClustersDevice(edm::AllocateForOverwrite) : PortableDeviceCollection<SiPixelClustersSoA, TDev>{edm::allocateForOverwrite} {}

template <typename TQueue>
explicit SiPixelClustersDevice(size_t maxModules, TQueue queue)
Expand Down
6 changes: 4 additions & 2 deletions DataFormats/SiPixelClusterSoA/interface/SiPixelClustersHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
#define DataFormats_SiPixelClusterSoA_interface_SiPixelClustersHost_h

#include <alpaka/alpaka.hpp>
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

// TODO: The class is created via inheritance of the PortableCollection.
// This is generally discouraged, and should be done via composition.
// See: https://github.com/cms-sw/cmssw/pull/40465#discussion_r1067364306
class SiPixelClustersHost : public PortableHostCollection<SiPixelClustersSoA> {
public:
SiPixelClustersHost() = default;
SiPixelClustersHost(edm::AllocateForOverwrite) : PortableHostCollection<SiPixelClustersSoA>{edm::allocateForOverwrite} {}

template <typename TQueue>
explicit SiPixelClustersHost(size_t maxModules, TQueue queue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsSoA.h"
#include "DataFormats/SiPixelRawData/interface/SiPixelErrorCompact.h"
Expand All @@ -14,7 +15,8 @@
template <typename TDev>
class SiPixelDigiErrorsDevice : public PortableDeviceCollection<SiPixelDigiErrorsSoA, TDev> {
public:
SiPixelDigiErrorsDevice() = default;
SiPixelDigiErrorsDevice(edm::AllocateForOverwrite) : PortableDeviceCollection<SiPixelDigiErrorsSoA, TDev>{edm::allocateForOverwrite} {}

template <typename TQueue>
explicit SiPixelDigiErrorsDevice(size_t maxFedWords, TQueue queue)
: PortableDeviceCollection<SiPixelDigiErrorsSoA, TDev>(maxFedWords, queue), maxFedWords_(maxFedWords) {}
Expand Down
4 changes: 3 additions & 1 deletion DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsSoA.h"
#include "DataFormats/SiPixelRawData/interface/SiPixelErrorCompact.h"
Expand All @@ -13,7 +14,8 @@

class SiPixelDigiErrorsHost : public PortableHostCollection<SiPixelDigiErrorsSoA> {
public:
SiPixelDigiErrorsHost() = default;
SiPixelDigiErrorsHost(edm::AllocateForOverwrite) : PortableHostCollection<SiPixelDigiErrorsSoA>{edm::allocateForOverwrite} {}

template <typename TQueue>
explicit SiPixelDigiErrorsHost(int maxFedWords, TQueue queue)
: PortableHostCollection<SiPixelDigiErrorsSoA>(maxFedWords, queue), maxFedWords_(maxFedWords) {}
Expand Down
4 changes: 3 additions & 1 deletion DataFormats/SiPixelDigiSoA/interface/SiPixelDigisDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigisSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

template <typename TDev>
class SiPixelDigisDevice : public PortableDeviceCollection<SiPixelDigisSoA, TDev> {
public:
SiPixelDigisDevice() = default;
SiPixelDigisDevice(edm::AllocateForOverwrite) : PortableDeviceCollection<SiPixelDigisSoA, TDev>{edm::allocateForOverwrite} {}

template <typename TQueue>
explicit SiPixelDigisDevice(size_t maxFedWords, TQueue queue)
: PortableDeviceCollection<SiPixelDigisSoA, TDev>(maxFedWords + 1, queue) {}
Expand Down
4 changes: 3 additions & 1 deletion DataFormats/SiPixelDigiSoA/interface/SiPixelDigisHost.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef DataFormats_SiPixelDigiSoA_interface_SiPixelDigisHost_h
#define DataFormats_SiPixelDigiSoA_interface_SiPixelDigisHost_h

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigisSoA.h"

Expand All @@ -9,7 +10,8 @@
// See: https://github.com/cms-sw/cmssw/pull/40465#discussion_r1067364306
class SiPixelDigisHost : public PortableHostCollection<SiPixelDigisSoA> {
public:
SiPixelDigisHost() = default;
SiPixelDigisHost(edm::AllocateForOverwrite) : PortableHostCollection<SiPixelDigisSoA>{edm::allocateForOverwrite} {}

template <typename TQueue>
explicit SiPixelDigisHost(size_t maxFedWords, TQueue queue)
: PortableHostCollection<SiPixelDigisSoA>(maxFedWords + 1, queue) {}
Expand Down
12 changes: 9 additions & 3 deletions DataFormats/TrackSoA/interface/TracksDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#define DataFormats_Track_interface_TracksDevice_h

#include <cstdint>

#include <alpaka/alpaka.hpp>
#include "DataFormats/TrackSoA/interface/TracksSoA.h"
#include "DataFormats/TrackSoA/interface/TrackDefinitions.h"

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
#include "DataFormats/TrackSoA/interface/TrackDefinitions.h"
#include "DataFormats/TrackSoA/interface/TracksSoA.h"

// TODO: The class is created via inheritance of the PortableCollection.
// This is generally discouraged, and should be done via composition.
Expand All @@ -14,7 +17,10 @@ template <typename TrackerTraits, typename TDev>
class TracksDevice : public PortableDeviceCollection<reco::TrackLayout<TrackerTraits>, TDev> {
public:
static constexpr int32_t S = TrackerTraits::maxNumberOfTuples; //TODO: this could be made configurable at runtime
TracksDevice() = default; // necessary for ROOT dictionaries

TracksDevice(edm::AllocateForOverwrite)
: PortableDeviceCollection<reco::TrackLayout<TrackerTraits>, TDev>{edm::allocateForOverwrite} {
} // necessary for ROOT dictionaries

using PortableDeviceCollection<reco::TrackLayout<TrackerTraits>, TDev>::view;
using PortableDeviceCollection<reco::TrackLayout<TrackerTraits>, TDev>::const_view;
Expand Down
13 changes: 9 additions & 4 deletions DataFormats/TrackSoA/interface/TracksHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#define DataFormats_Track_TracksHost_H

#include <cstdint>

#include <alpaka/alpaka.hpp>
#include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"
#include "DataFormats/TrackSoA/interface/TracksSoA.h"
#include "DataFormats/TrackSoA/interface/TrackDefinitions.h"

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/TrackSoA/interface/TrackDefinitions.h"
#include "DataFormats/TrackSoA/interface/TracksSoA.h"
#include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"

// TODO: The class is created via inheritance of the PortableHostCollection.
// This is generally discouraged, and should be done via composition.
Expand All @@ -15,7 +18,9 @@ template <typename TrackerTraits>
class TracksHost : public PortableHostCollection<reco::TrackLayout<TrackerTraits>> {
public:
static constexpr int32_t S = TrackerTraits::maxNumberOfTuples; //TODO: this could be made configurable at runtime
TracksHost() = default; // Needed for the dictionary; not sure if line above is needed anymore

TracksHost(edm::AllocateForOverwrite)
: PortableHostCollection<reco::TrackLayout<TrackerTraits>>{edm::allocateForOverwrite} {} // necessary for ROOT dictionaries

using PortableHostCollection<reco::TrackLayout<TrackerTraits>>::view;
using PortableHostCollection<reco::TrackLayout<TrackerTraits>>::const_view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsHost.h"
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h"
Expand All @@ -19,7 +20,8 @@ class TrackingRecHitDevice : public PortableDeviceCollection<TrackingRecHitLayou
using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::const_view;
using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::buffer;

TrackingRecHitDevice() = default;
TrackingRecHitDevice(edm::AllocateForOverwrite)
: PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>{edm::allocateForOverwrite} {}

// Constructor which specifies the SoA size, number of BPIX1 hits, and the modules entry points
template <typename TQueue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/Common/interface/AllocateForOverwrite.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Expand All @@ -19,7 +20,7 @@ class TrackingRecHitHost : public PortableHostCollection<TrackingRecHitLayout<Tr
using PortableHostCollection<TrackingRecHitLayout<TrackerTraits>>::const_view;
using PortableHostCollection<TrackingRecHitLayout<TrackerTraits>>::buffer;

TrackingRecHitHost() = default;
TrackingRecHitHost(edm::AllocateForOverwrite) : PortableHostCollection<TrackingRecHitLayout<TrackerTraits>>{edm::allocateForOverwrite} {}

// Constructor which specifies only the SoA size, to be used when copying the results from the device to the host
template <typename TQueue>
Expand Down

0 comments on commit f729449

Please sign in to comment.