Skip to content

Commit

Permalink
Make the ZVertex SoA collection run-time sized
Browse files Browse the repository at this point in the history
FIXME the code needs to be updated not to rely on zVertex::MAXVTX, zVertex::MAXTRACKS.
  • Loading branch information
fwyzard committed Sep 5, 2024
1 parent d212a5f commit 410ed35
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 62 deletions.
13 changes: 2 additions & 11 deletions DataFormats/VertexSoA/interface/ZVertexDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@
#include <cstdint>

#include <alpaka/alpaka.hpp>

#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"

template <typename TDev>
class ZVertexDevice : public PortableDeviceMultiCollection<TDev, reco::ZVertexSoA, reco::ZVertexTracksSoA> {
public:
ZVertexDevice() = default; // necessary for ROOT dictionaries

// Constructor which specifies the queue
template <typename TQueue>
explicit ZVertexDevice(TQueue queue)
: PortableDeviceMultiCollection<TDev, reco::ZVertexSoA, reco::ZVertexTracksSoA>(
{{zVertex::MAXVTX, zVertex::MAXTRACKS}}, queue) {}
};
using ZVertexDevice = PortableDeviceMultiCollection<TDev, reco::ZVertexSoA, reco::ZVertexTracksSoA>;

#endif // DataFormats_VertexSoA_interface_ZVertexDevice_h
24 changes: 3 additions & 21 deletions DataFormats/VertexSoA/interface/ZVertexHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,10 @@

#include <alpaka/alpaka.hpp>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

// This alias is needed to call the SET_PORTABLEHOSTMULTICOLLECTION_READ_RULES macro without commas.
using ZVertexHostBase = PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>;

class ZVertexHost : public ZVertexHostBase {
public:
ZVertexHost() = default; // necessary for ROOT dictionaries

// Constructor which specifies the queue
template <typename TQueue>
explicit ZVertexHost(TQueue queue)
: PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>({{zVertex::MAXVTX, zVertex::MAXTRACKS}},
queue) {}

// Constructor which specifies the DevHost
explicit ZVertexHost(alpaka_common::DevHost const& host)
: PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>({{zVertex::MAXVTX, zVertex::MAXTRACKS}},
host) {}
};
using ZVertexHost = PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>;

#endif // DataFormats_VertexSoA_ZVertexHost_H
23 changes: 4 additions & 19 deletions DataFormats/VertexSoA/interface/alpaka/ZVertexSoACollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <cstdint>

#include <alpaka/alpaka.hpp>

#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"
#include "DataFormats/VertexSoA/interface/ZVertexDevice.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

Expand All @@ -19,21 +19,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

} // namespace ALPAKA_ACCELERATOR_NAMESPACE

namespace cms::alpakatools {
template <typename TDevice>
struct CopyToHost<ZVertexDevice<TDevice>> {
template <typename TQueue>
static auto copyAsync(TQueue& queue, ZVertexDevice<TDevice> const& deviceData) {
ZVertexHost hostData(queue);
alpaka::memcpy(queue, hostData.buffer(), deviceData.buffer());
#ifdef GPU_DEBUG
printf("ZVertexSoACollection: I'm copying to host.\n");
#endif
return hostData;
}
};
} // namespace cms::alpakatools

ASSERT_DEVICE_MATCHES_HOST_COLLECTION(ZVertexSoACollection, ZVertexHost);

#endif // DataFormats_VertexSoA_interface_ZVertexSoACollection_h
2 changes: 1 addition & 1 deletion DataFormats/VertexSoA/src/classes.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "DataFormats/Portable/interface/PortableHostCollectionReadRules.h"
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"

SET_PORTABLEHOSTMULTICOLLECTION_READ_RULES(ZVertexHostBase);
SET_PORTABLEHOSTMULTICOLLECTION_READ_RULES(ZVertexHost);
1 change: 0 additions & 1 deletion DataFormats/VertexSoA/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<class name="portablecollection::CollectionLeaf<1, reco::ZVertexTracksLayout<128, false>>"/>

<!-- Collection declaration for dictionary -->
<class name="ZVertexHostBase"/>
<class name="ZVertexHost"/>
<class name="edm::Wrapper<ZVertexHost>" splitLevel="0"/>
</lcgdict>
17 changes: 11 additions & 6 deletions DataFormats/VertexSoA/test/alpaka/ZVertexSoA_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "DataFormats/VertexSoA/interface/ZVertexDevice.h"
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"
#include "DataFormats/VertexSoA/interface/alpaka/ZVertexSoACollection.h"
Expand Down Expand Up @@ -48,15 +49,19 @@ int main() {
{
// Instantiate vertices on device. PortableCollection allocates
// SoA on device automatically.
ZVertexSoACollection zvertex_d(queue);
ZVertexSoACollection zvertex_d({{zVertex::MAXVTX, zVertex::MAXTRACKS}}, queue);
testZVertexSoAT::runKernels(zvertex_d.view(), zvertex_d.view<reco::ZVertexTracksSoA>(), queue);

// Instantate vertices on host. This is where the data will be
// copied to from device.
ZVertexHost zvertex_h(queue);
std::cout << zvertex_h.view().metadata().size() << std::endl;
alpaka::memcpy(queue, zvertex_h.buffer(), zvertex_d.const_buffer());
// If the device is actually the host, use the collection as-is.
// Otherwise, copy the data from the device to the host.
ZVertexHost zvertex_h;
#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
zvertex_h = std::move(zvertex_d);
#else
zvertex_h = cms::alpakatools::CopyToHost<ZVertexSoACollection>::copyAsync(queue, zvertex_d);
#endif
alpaka::wait(queue);
std::cout << zvertex_h.view().metadata().size() << std::endl;

// Print results
std::cout << "idv\t"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/HistoContainer.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <alpaka/alpaka.hpp>

#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/HistoContainer.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <alpaka/alpaka.hpp>

#include "DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h"
#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
#include "RecoTracker/PixelVertexFinding/interface/PixelVertexWorkSpaceLayout.h"
Expand Down Expand Up @@ -132,7 +133,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
#ifdef PIXVERTEX_DEBUG_PRODUCE
std::cout << "producing Vertices on GPU" << std::endl;
#endif // PIXVERTEX_DEBUG_PRODUCE
ZVertexSoACollection vertices(queue);
ZVertexSoACollection vertices({{zVertex::MAXVTX, zVertex::MAXTRACKS}}, queue);

auto soa = vertices.view();
auto trksoa = vertices.view<reco::ZVertexTracksSoA>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// TrackUtilities only included in order to compile SoALayout with Eigen columns
#include "DataFormats/TrackSoA/interface/alpaka/TrackUtilities.h"
#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
Expand Down Expand Up @@ -121,8 +122,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
void runKernels(Queue& queue) {
vertexFinder::PixelVertexWorkSpaceSoADevice ws_d(zVertex::MAXTRACKS, queue);
vertexFinder::PixelVertexWorkSpaceSoAHost ws_h(zVertex::MAXTRACKS, queue);
ZVertexHost vertices_h(queue);
ZVertexSoACollection vertices_d(queue);
ZVertexHost vertices_h({{zVertex::MAXVTX, zVertex::MAXTRACKS}}, queue);
ZVertexSoACollection vertices_d({{zVertex::MAXVTX, zVertex::MAXTRACKS}}, queue);

float eps = 0.1f;
std::array<float, 3> par{{eps, 0.01f, 9.0f}};
Expand Down

0 comments on commit 410ed35

Please sign in to comment.