Skip to content

Commit

Permalink
migrate EndcapGeometry to SoATemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Oct 24, 2024
1 parent 018204d commit 5e2bf7b
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 81 deletions.
58 changes: 0 additions & 58 deletions RecoTracker/LSTCore/interface/EndcapGeometryBuffer.h

This file was deleted.

20 changes: 20 additions & 0 deletions RecoTracker/LSTCore/interface/EndcapGeometryDevSoA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#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;

using EndcapGeometryDevHostCollection = PortableHostCollection<EndcapGeometryDevSoA>;

} // namespace lst

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

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

Expand All @@ -20,22 +20,22 @@ namespace lst {
unsigned int nPixels;
unsigned int nEndCapMap;
ModulesBuffer<TDev> modulesBuffers;
EndcapGeometryBuffer<TDev> endcapGeometryBuffers;
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 PortableCollection<EndcapGeometryDevSoA, TDev>> endcapGeometryIn,
std::shared_ptr<const PixelMap> const& pixelMappingIn)
: nModules(nModulesIn),
nLowerModules(nLowerModulesIn),
nPixels(nPixelsIn),
nEndCapMap(nEndCapMapIn),
modulesBuffers(modulesBuffersIn),
endcapGeometryBuffers(endcapGeometryBuffersIn),
endcapGeometry(std::move(endcapGeometryIn)),
pixelMapping(pixelMappingIn) {}
};

Expand All @@ -44,6 +44,19 @@ 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<lst::LSTESData<alpaka_common::DevHost>> {
template <typename TQueue>
Expand All @@ -52,16 +65,15 @@ namespace cms::alpakatools {
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 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(deviceEndcapGeometry),
srcData.pixelMapping);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef RecoTracker_LSTCore_interface_alpaka_EndcapGeometryDevDeviceCollection_h
#define RecoTracker_LSTCore_interface_alpaka_EndcapGeometryDevDeviceCollection_h

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

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

namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
using EndcapGeometryDevDeviceCollection = PortableCollection<EndcapGeometryDevSoA>;
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst

#endif
10 changes: 5 additions & 5 deletions RecoTracker/LSTCore/src/LSTESData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ std::unique_ptr<lst::LSTESData<alpaka_common::DevHost>> lst::loadAndFillESHost()
ModuleConnectionMap moduleConnectionMap;
::loadMapsHost(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap);

auto endcapGeometryBuffers =
EndcapGeometryBuffer<alpaka_common::DevHost>(cms::alpakatools::host(), endcapGeometry.nEndCapMap);
std::memcpy(endcapGeometryBuffers.geoMapDetId_buf.data(),
auto endcapGeometryDev =
std::make_unique<EndcapGeometryDevHostCollection>(endcapGeometry.nEndCapMap, cms::alpakatools::host());
std::memcpy(endcapGeometryDev->view().geoMapDetId(),
endcapGeometry.geoMapDetId_buf.data(),
endcapGeometry.nEndCapMap * sizeof(unsigned int));
std::memcpy(endcapGeometryBuffers.geoMapPhi_buf.data(),
std::memcpy(endcapGeometryDev->view().geoMapPhi(),
endcapGeometry.geoMapPhi_buf.data(),
endcapGeometry.nEndCapMap * sizeof(float));

Expand All @@ -113,6 +113,6 @@ std::unique_ptr<lst::LSTESData<alpaka_common::DevHost>> lst::loadAndFillESHost()
nPixels,
endcapGeometry.nEndCapMap,
std::move(modulesBuffers),
std::move(endcapGeometryBuffers),
std::move(endcapGeometryDev),
pixelMappingPtr);
}
3 changes: 1 addition & 2 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ void Event::addHitToEvent(std::vector<float> const& x,
TwoS,
nModules_,
nEndCapMap_,
endcapGeometryBuffers_.geoMapDetId_buf.data(),
endcapGeometryBuffers_.geoMapPhi_buf.data(),
endcapGeometry_.const_view(),
*modulesBuffers_.data(),
hitsDC_->view<HitsSoA>(),
hitsDC_->view<HitsOccupancySoA>(),
Expand Down
5 changes: 3 additions & 2 deletions RecoTracker/LSTCore/src/alpaka/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RecoTracker/LSTCore/interface/alpaka/LST.h"
#include "RecoTracker/LSTCore/interface/Module.h"
#include "RecoTracker/LSTCore/interface/alpaka/ObjectRangesDeviceCollection.h"
#include "RecoTracker/LSTCore/interface/alpaka/EndcapGeometryDevDeviceCollection.h"

#include "Hit.h"
#include "Segment.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
const unsigned int nEndCapMap_;
ModulesBuffer<Device> const& modulesBuffers_;
PixelMap const& pixelMapping_;
EndcapGeometryBuffer<Device> const& endcapGeometryBuffers_;
EndcapGeometryDevDeviceCollection const& endcapGeometry_;

public:
// Constructor used for CMSSW integration. Uses an external queue.
Expand All @@ -91,7 +92,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
nEndCapMap_(deviceESData->nEndCapMap),
modulesBuffers_(deviceESData->modulesBuffers),
pixelMapping_(*deviceESData->pixelMapping),
endcapGeometryBuffers_(deviceESData->endcapGeometryBuffers) {
endcapGeometry_(*deviceESData->endcapGeometry) {
initSync(verbose);
}
void resetEventSync(); // synchronizes
Expand Down
13 changes: 7 additions & 6 deletions RecoTracker/LSTCore/src/alpaka/Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
struct HitLoopKernel {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
uint16_t Endcap, // Integer corresponding to endcap in module subdets
uint16_t TwoS, // Integer corresponding to TwoS in moduleType
unsigned int nModules, // Number of modules
unsigned int nEndCapMap, // Number of elements in endcap map
const unsigned int* geoMapDetId, // DetId's from endcap map
const float* geoMapPhi, // Phi values from endcap map
uint16_t Endcap, // Integer corresponding to endcap in module subdets
uint16_t TwoS, // Integer corresponding to TwoS in moduleType
unsigned int nModules, // Number of modules
unsigned int nEndCapMap, // Number of elements in endcap map
EndcapGeometryDevConst endcapGeometry,
Modules modulesInGPU,
Hits hits,
HitsOccupancy hitsOccupancy,
unsigned int nHits) const // Total number of hits in event
{
auto geoMapDetId = endcapGeometry.geoMapDetId(); // DetId's from endcap map
auto geoMapPhi = endcapGeometry.geoMapPhi(); // Phi values from endcap map
auto const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
auto const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);
for (unsigned int ihit = globalThreadIdx[2]; ihit < nHits; ihit += gridThreadExtent[2]) {
Expand Down

0 comments on commit 5e2bf7b

Please sign in to comment.