Skip to content

Commit

Permalink
Merge pull request #106 from SegmentLinking/more_soa_migrations
Browse files Browse the repository at this point in the history
continuing migration to SoA: update LS, migrate ranges, hits, endcap, modules
  • Loading branch information
slava77 authored Oct 28, 2024
2 parents ccc4bf4 + 48d01f3 commit f8e7884
Show file tree
Hide file tree
Showing 39 changed files with 1,560 additions and 1,656 deletions.
1 change: 0 additions & 1 deletion RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// LST includes
#include "RecoTracker/LSTCore/interface/Module.h"
#include "RecoTracker/LSTCore/interface/alpaka/LST.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand Down
4 changes: 4 additions & 0 deletions RecoTracker/LSTCore/interface/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ namespace lst {

// Defining the constant host device variables right up here
// Currently pixel tracks treated as LSs with 2 double layers (IT layers 1+2 and 3+4) and 4 hits. To be potentially handled better in the future.
struct Params_Modules {
using ArrayU16xMaxConnected = edm::StdArray<uint16_t, max_connected_modules>;
};
struct Params_pLS {
static constexpr int kLayers = 2, kHits = 4;
};
Expand Down Expand Up @@ -120,6 +123,7 @@ namespace lst {
using ArrayUxHits = edm::StdArray<unsigned int, kHits>;
};

using ArrayIx2 = edm::StdArray<int, 2>;
using ArrayUx2 = edm::StdArray<unsigned int, 2>;

} //namespace lst
Expand Down
58 changes: 0 additions & 58 deletions RecoTracker/LSTCore/interface/EndcapGeometryBuffer.h

This file was deleted.

10 changes: 10 additions & 0 deletions RecoTracker/LSTCore/interface/EndcapGeometryDevHostCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef RecoTracker_LSTCore_interface_EndcapGeometryDevHostCollection_h
#define RecoTracker_LSTCore_interface_EndcapGeometryDevHostCollection_h

#include "RecoTracker/LSTCore/interface/EndcapGeometryDevSoA.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"

namespace lst {
using EndcapGeometryDevHostCollection = PortableHostCollection<EndcapGeometryDevSoA>;
} // namespace lst
#endif
18 changes: 18 additions & 0 deletions RecoTracker/LSTCore/interface/EndcapGeometryDevSoA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef RecoTracker_LSTCore_interface_EndcapGeometryDevSoA_h
#define RecoTracker_LSTCore_interface_EndcapGeometryDevSoA_h

#include "DataFormats/SoATemplate/interface/SoALayout.h"
#include "DataFormats/Portable/interface/PortableCollection.h"

namespace lst {

GENERATE_SOA_LAYOUT(EndcapGeometryDevSoALayout, SOA_COLUMN(unsigned int, geoMapDetId), SOA_COLUMN(float, geoMapPhi))

using EndcapGeometryDevSoA = EndcapGeometryDevSoALayout<>;

using EndcapGeometryDev = EndcapGeometryDevSoA::View;
using EndcapGeometryDevConst = EndcapGeometryDevSoA::ConstView;

} // namespace lst

#endif
10 changes: 10 additions & 0 deletions RecoTracker/LSTCore/interface/HitsHostCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef RecoTracker_LSTCore_interface_HitsHostCollection_h
#define RecoTracker_LSTCore_interface_HitsHostCollection_h

#include "RecoTracker/LSTCore/interface/HitsSoA.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"

namespace lst {
using HitsHostCollection = PortableHostMultiCollection<HitsSoA, HitsRangesSoA>;
} // namespace lst
#endif
43 changes: 43 additions & 0 deletions RecoTracker/LSTCore/interface/HitsSoA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef RecoTracker_LSTCore_interface_HitsSoA_h
#define RecoTracker_LSTCore_interface_HitsSoA_h

#include "DataFormats/SoATemplate/interface/SoALayout.h"
#include "DataFormats/Portable/interface/PortableCollection.h"

#include "RecoTracker/LSTCore/interface/Constants.h"

namespace lst {

GENERATE_SOA_LAYOUT(HitsSoALayout,
SOA_COLUMN(float, xs),
SOA_COLUMN(float, ys),
SOA_COLUMN(float, zs),
SOA_COLUMN(uint16_t, moduleIndices),
SOA_COLUMN(unsigned int, idxs),
SOA_COLUMN(unsigned int, detid),
SOA_COLUMN(float, rts),
SOA_COLUMN(float, phis),
SOA_COLUMN(float, etas),
SOA_COLUMN(float, highEdgeXs),
SOA_COLUMN(float, highEdgeYs),
SOA_COLUMN(float, lowEdgeXs),
SOA_COLUMN(float, lowEdgeYs))

GENERATE_SOA_LAYOUT(HitsRangesSoALayout,
SOA_COLUMN(ArrayIx2, hitRanges),
SOA_COLUMN(int, hitRangesLower),
SOA_COLUMN(int, hitRangesUpper),
SOA_COLUMN(int8_t, hitRangesnLower),
SOA_COLUMN(int8_t, hitRangesnUpper))

using HitsSoA = HitsSoALayout<>;
using HitsRangesSoA = HitsRangesSoALayout<>;

using Hits = HitsSoA::View;
using HitsConst = HitsSoA::ConstView;
using HitsRanges = HitsRangesSoA::View;
using HitsRangesConst = HitsRangesSoA::ConstView;

} // namespace lst

#endif
57 changes: 41 additions & 16 deletions RecoTracker/LSTCore/interface/LSTESData.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define RecoTracker_LSTCore_interface_LSTESData_h

#include "RecoTracker/LSTCore/interface/Constants.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometryBuffer.h"
#include "RecoTracker/LSTCore/interface/Module.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometryDevHostCollection.h"
#include "RecoTracker/LSTCore/interface/ModulesHostCollection.h"
#include "RecoTracker/LSTCore/interface/PixelMap.h"

#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h"
Expand All @@ -19,23 +19,23 @@ namespace lst {
uint16_t nLowerModules;
unsigned int nPixels;
unsigned int nEndCapMap;
ModulesBuffer<TDev> modulesBuffers;
EndcapGeometryBuffer<TDev> endcapGeometryBuffers;
std::unique_ptr<const PortableMultiCollection<TDev, ModulesSoA, ModulesPixelSoA>> modules;
std::unique_ptr<const PortableCollection<EndcapGeometryDevSoA, TDev>> endcapGeometry;
std::shared_ptr<const PixelMap> pixelMapping;

LSTESData(uint16_t const& nModulesIn,
uint16_t const& nLowerModulesIn,
unsigned int const& nPixelsIn,
unsigned int const& nEndCapMapIn,
ModulesBuffer<TDev> const& modulesBuffersIn,
EndcapGeometryBuffer<TDev> const& endcapGeometryBuffersIn,
std::unique_ptr<const PortableMultiCollection<TDev, ModulesSoA, ModulesPixelSoA>> modulesIn,
std::unique_ptr<const PortableCollection<EndcapGeometryDevSoA, TDev>> endcapGeometryIn,
std::shared_ptr<const PixelMap> const& pixelMappingIn)
: nModules(nModulesIn),
nLowerModules(nLowerModulesIn),
nPixels(nPixelsIn),
nEndCapMap(nEndCapMapIn),
modulesBuffers(modulesBuffersIn),
endcapGeometryBuffers(endcapGeometryBuffersIn),
modules(std::move(modulesIn)),
endcapGeometry(std::move(endcapGeometryIn)),
pixelMapping(pixelMappingIn) {}
};

Expand All @@ -44,24 +44,49 @@ namespace lst {
} // namespace lst

namespace cms::alpakatools {

// The templated definition in CMSSW doesn't work when using CPU as the device
template <>
struct CopyToDevice<PortableHostCollection<lst::EndcapGeometryDevSoA>> {
template <typename TQueue>
static auto copyAsync(TQueue& queue, PortableHostCollection<lst::EndcapGeometryDevSoA> const& srcData) {
using TDevice = typename alpaka::trait::DevType<TQueue>::type;
PortableCollection<lst::EndcapGeometryDevSoA, TDevice> dstData(srcData->metadata().size(), queue);
alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
return dstData;
}
};

template <>
struct CopyToDevice<PortableHostMultiCollection<lst::ModulesSoA, lst::ModulesPixelSoA>> {
template <typename TQueue>
static auto copyAsync(TQueue& queue,
PortableHostMultiCollection<lst::ModulesSoA, lst::ModulesPixelSoA> const& srcData) {
using TDevice = typename alpaka::trait::DevType<TQueue>::type;
PortableMultiCollection<TDevice, lst::ModulesSoA, lst::ModulesPixelSoA> dstData(srcData.sizes(), queue);
alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
return dstData;
}
};

template <>
struct CopyToDevice<lst::LSTESData<alpaka_common::DevHost>> {
template <typename TQueue>
static lst::LSTESData<alpaka::Dev<TQueue>> copyAsync(TQueue& queue,
lst::LSTESData<alpaka_common::DevHost> const& srcData) {
auto deviceModulesBuffers =
lst::ModulesBuffer<alpaka::Dev<TQueue>>(alpaka::getDev(queue), srcData.nModules, srcData.nPixels);
deviceModulesBuffers.copyFromSrc(queue, srcData.modulesBuffers);
auto deviceEndcapGeometryBuffers =
lst::EndcapGeometryBuffer<alpaka::Dev<TQueue>>(alpaka::getDev(queue), srcData.nEndCapMap);
deviceEndcapGeometryBuffers.copyFromSrc(queue, srcData.endcapGeometryBuffers);
auto deviceModules =
std::make_unique<PortableMultiCollection<alpaka::Dev<TQueue>, lst::ModulesSoA, lst::ModulesPixelSoA>>(
CopyToDevice<PortableHostMultiCollection<lst::ModulesSoA, lst::ModulesPixelSoA>>::copyAsync(
queue, *srcData.modules));
auto deviceEndcapGeometry = std::make_unique<PortableCollection<lst::EndcapGeometryDevSoA, alpaka::Dev<TQueue>>>(
CopyToDevice<PortableHostCollection<lst::EndcapGeometryDevSoA>>::copyAsync(queue, *srcData.endcapGeometry));

return lst::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
srcData.nLowerModules,
srcData.nPixels,
srcData.nEndCapMap,
std::move(deviceModulesBuffers),
std::move(deviceEndcapGeometryBuffers),
std::move(deviceModules),
std::move(deviceEndcapGeometry),
srcData.pixelMapping);
}
};
Expand Down
10 changes: 10 additions & 0 deletions RecoTracker/LSTCore/interface/MiniDoubletsHostCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef RecoTracker_LSTCore_interface_MiniDoubletsHostCollection_h
#define RecoTracker_LSTCore_interface_MiniDoubletsHostCollection_h

#include "RecoTracker/LSTCore/interface/MiniDoubletsSoA.h"
#include "DataFormats/Portable/interface/PortableHostCollection.h"

namespace lst {
using MiniDoubletsHostCollection = PortableHostMultiCollection<MiniDoubletsSoA, MiniDoubletsOccupancySoA>;
} // namespace lst
#endif
2 changes: 0 additions & 2 deletions RecoTracker/LSTCore/interface/MiniDoubletsSoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ namespace lst {
using MiniDoubletsOccupancy = MiniDoubletsOccupancySoA::View;
using MiniDoubletsOccupancyConst = MiniDoubletsOccupancySoA::ConstView;

using MiniDoubletsHostCollection = PortableHostMultiCollection<MiniDoubletsSoA, MiniDoubletsOccupancySoA>;

} // namespace lst

#endif
Loading

0 comments on commit f8e7884

Please sign in to comment.