Skip to content

Commit

Permalink
migrate modules to SoATemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Oct 25, 2024
1 parent 5e2bf7b commit 043dfe0
Show file tree
Hide file tree
Showing 21 changed files with 802 additions and 875 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
3 changes: 3 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
29 changes: 21 additions & 8 deletions RecoTracker/LSTCore/interface/LSTESData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "RecoTracker/LSTCore/interface/Constants.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometryDevSoA.h"
#include "RecoTracker/LSTCore/interface/Module.h"
#include "RecoTracker/LSTCore/interface/ModulesSoA.h"
#include "RecoTracker/LSTCore/interface/PixelMap.h"

#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h"
Expand All @@ -19,22 +19,22 @@ namespace lst {
uint16_t nLowerModules;
unsigned int nPixels;
unsigned int nEndCapMap;
ModulesBuffer<TDev> modulesBuffers;
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,
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),
modules(std::move(modulesIn)),
endcapGeometry(std::move(endcapGeometryIn)),
pixelMapping(pixelMappingIn) {}
};
Expand All @@ -57,22 +57,35 @@ namespace cms::alpakatools {
}
};

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 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(deviceModules),
std::move(deviceEndcapGeometry),
srcData.pixelMapping);
}
Expand Down
227 changes: 0 additions & 227 deletions RecoTracker/LSTCore/interface/Module.h

This file was deleted.

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

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

namespace lst {

enum SubDet { InnerPixel = 0, Barrel = 5, Endcap = 4 };

enum Side { NegZ = 1, PosZ = 2, Center = 3 };

enum ModuleType { PS, TwoS, PixelModule };

enum ModuleLayerType { Pixel, Strip, InnerPixelLayer };

GENERATE_SOA_LAYOUT(ModulesSoALayout,
SOA_COLUMN(unsigned int, detIds),
SOA_COLUMN(Params_Modules::ArrayU16xMaxConnected, moduleMap),
SOA_COLUMN(unsigned int, mapdetId),
SOA_COLUMN(uint16_t, mapIdx),
SOA_COLUMN(uint16_t, nConnectedModules),
SOA_COLUMN(float, drdzs),
SOA_COLUMN(float, dxdys),
SOA_SCALAR(uint16_t, nModules),
SOA_SCALAR(uint16_t, nLowerModules),
SOA_COLUMN(uint16_t, partnerModuleIndices),
SOA_COLUMN(short, layers),
SOA_COLUMN(short, rings),
SOA_COLUMN(short, modules),
SOA_COLUMN(short, rods),
SOA_COLUMN(short, subdets),
SOA_COLUMN(short, sides),
SOA_COLUMN(float, eta),
SOA_COLUMN(float, r),
SOA_COLUMN(bool, isInverted),
SOA_COLUMN(bool, isLower),
SOA_COLUMN(bool, isAnchor),
SOA_COLUMN(ModuleType, moduleType),
SOA_COLUMN(ModuleLayerType, moduleLayerType),
SOA_COLUMN(int, lstLayers))

GENERATE_SOA_LAYOUT(ModulesPixelSoALayout, SOA_COLUMN(unsigned int, connectedPixels))

using ModulesSoA = ModulesSoALayout<>;
using ModulesPixelSoA = ModulesPixelSoALayout<>;

using Modules = ModulesSoA::View;
using ModulesConst = ModulesSoA::ConstView;
using ModulesPixel = ModulesPixelSoA::View;
using ModulesPixelConst = ModulesPixelSoA::ConstView;

using ModulesHostCollection = PortableHostMultiCollection<ModulesSoA, ModulesPixelSoA>;

} // namespace lst

#endif
12 changes: 12 additions & 0 deletions RecoTracker/LSTCore/interface/alpaka/ModulesDeviceCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_ModulesDeviceCollection_h
#define RecoTracker_LSTCore_interface_alpaka_ModulesDeviceCollection_h

#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"

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

namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
using ModulesDeviceCollection = PortableCollection2<ModulesSoA, ModulesPixelSoA>;
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst

#endif
Loading

0 comments on commit 043dfe0

Please sign in to comment.