Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Aug 2, 2024
1 parent 0bcb06c commit 14b8bd9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 62 deletions.
6 changes: 4 additions & 2 deletions RecoTracker/LSTCore/interface/LSTESData.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ namespace cms::alpakatools {
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);
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);
auto deviceEndcapGeometryBuffers =
lst::EndcapGeometryBuffer<alpaka::Dev<TQueue>>(alpaka::getDev(queue), srcData.nEndCapMap);
deviceEndcapGeometryBuffers.copyFromSrc(queue, srcData.endcapGeometryBuffers);

return lst::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
Expand Down
39 changes: 25 additions & 14 deletions RecoTracker/LSTCore/src/LSTESData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,36 @@ std::unique_ptr<lst::LSTESData<alpaka_common::DevHost>> lst::loadAndFillESHost()
MapPLStoLayer pLStoLayer;
EndcapGeometry endcapGeometry;
TiltedGeometry tiltedGeometry;
auto pixelMapping = std::make_shared<PixelMap>();
PixelMap pixelMapping;
ModuleConnectionMap moduleConnectionMap;
::loadMapsHost(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap);

auto endcapGeometryBuffers = EndcapGeometryBuffer<alpaka_common::DevHost>(cms::alpakatools::host(), endcapGeometry.nEndCapMap);
std::memcpy(alpaka::getPtrNative(endcapGeometryBuffers.geoMapDetId_buf), endcapGeometry.geoMapDetId_buf.data(), endcapGeometry.nEndCapMap);
std::memcpy(alpaka::getPtrNative(endcapGeometryBuffers.geoMapPhi_buf), endcapGeometry.geoMapPhi_buf.data(), endcapGeometry.nEndCapMap);
auto endcapGeometryBuffers =
EndcapGeometryBuffer<alpaka_common::DevHost>(cms::alpakatools::host(), endcapGeometry.nEndCapMap);
std::memcpy(alpaka::getPtrNative(endcapGeometryBuffers.geoMapDetId_buf),
endcapGeometry.geoMapDetId_buf.data(),
endcapGeometry.nEndCapMap);
std::memcpy(alpaka::getPtrNative(endcapGeometryBuffers.geoMapPhi_buf),
endcapGeometry.geoMapPhi_buf.data(),
endcapGeometry.nEndCapMap);

auto path =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin");
auto modulesBuffers = lst::loadModulesFromFile(pLStoLayer,
path.c_str(),
nModules,
nLowerModules,
nPixels,
pixelMapping.get(),
endcapGeometry,
tiltedGeometry,
moduleConnectionMap);
return std::make_unique<LSTESData<alpaka_common::DevHost>>(
nModules, nLowerModules, nPixels, endcapGeometry.nEndCapMap, std::move(modulesBuffers), std::move(endcapGeometryBuffers), pixelMapping);
path.c_str(),
nModules,
nLowerModules,
nPixels,
pixelMapping,
endcapGeometry,
tiltedGeometry,
moduleConnectionMap);
auto pixelMappingPtr = std::make_shared<PixelMap>(std::move(pixelMapping));
return std::make_unique<LSTESData<alpaka_common::DevHost>>(nModules,
nLowerModules,
nPixels,
endcapGeometry.nEndCapMap,
std::move(modulesBuffers),
std::move(endcapGeometryBuffers),
pixelMappingPtr);
}
21 changes: 10 additions & 11 deletions RecoTracker/LSTCore/src/ModuleMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ namespace lst {
}
};

inline void fillMapArraysExplicit(ModulesBuffer<alpaka_common::DevHost>& modulesBuf,
ModuleMetaData const& mmd) {
inline void fillMapArraysExplicit(ModulesBuffer<alpaka_common::DevHost>& modulesBuf, ModuleMetaData const& mmd) {
uint16_t* mapIdx = alpaka::getPtrNative(modulesBuf.mapIdx_buf);
unsigned int* mapdetId = alpaka::getPtrNative(modulesBuf.mapdetId_buf);

Expand Down Expand Up @@ -189,14 +188,14 @@ namespace lst {
};

inline ModulesBuffer<alpaka_common::DevHost> loadModulesFromFile(MapPLStoLayer const& pLStoLayer,
const char* moduleMetaDataFilePath,
uint16_t& nModules,
uint16_t& nLowerModules,
unsigned int& nPixels,
PixelMap* pixelMapping,
const EndcapGeometry& endcapGeometry,
const TiltedGeometry& tiltedGeometry,
const ModuleConnectionMap& moduleConnectionMap) {
const char* moduleMetaDataFilePath,
uint16_t& nModules,
uint16_t& nLowerModules,
unsigned int& nPixels,
PixelMap& pixelMapping,
const EndcapGeometry& endcapGeometry,
const TiltedGeometry& tiltedGeometry,
const ModuleConnectionMap& moduleConnectionMap) {
ModuleMetaData mmd;

loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules);
Expand Down Expand Up @@ -327,7 +326,7 @@ namespace lst {
}
}

fillPixelMap(modulesBuf, nModules, nPixels, *pixelMapping, pLStoLayer, mmd);
fillPixelMap(modulesBuf, nModules, nPixels, pixelMapping, pLStoLayer, mmd);

*host_nModules = nModules;
*host_nLowerModules = nLowerModules;
Expand Down
63 changes: 30 additions & 33 deletions RecoTracker/LSTCore/src/alpaka/Event.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,17 @@ void lst::Event<Acc3D>::addHitToEvent(std::vector<float> const& x,
WorkDiv3D const hit_loop_workdiv = createWorkDiv(blocksPerGrid1, threadsPerBlock1, elementsPerThread);

hitLoopKernel hit_loop_kernel;
auto const hit_loop_task(
alpaka::createTaskKernel<Acc3D>(hit_loop_workdiv,
hit_loop_kernel,
Endcap,
TwoS,
nModules_,
nEndCapMap_,
alpaka::getPtrNative(endcapGeometryBuffers_.geoMapDetId_buf),
alpaka::getPtrNative(endcapGeometryBuffers_.geoMapPhi_buf),
*modulesBuffers_.data(),
*hitsInGPU,
nHits));
auto const hit_loop_task(alpaka::createTaskKernel<Acc3D>(hit_loop_workdiv,
hit_loop_kernel,
Endcap,
TwoS,
nModules_,
nEndCapMap_,
alpaka::getPtrNative(endcapGeometryBuffers_.geoMapDetId_buf),
alpaka::getPtrNative(endcapGeometryBuffers_.geoMapPhi_buf),
*modulesBuffers_.data(),
*hitsInGPU,
nHits));

alpaka::enqueue(queue, hit_loop_task);

Expand Down Expand Up @@ -247,7 +246,7 @@ void lst::Event<Acc3D>::addPixelSegmentToEvent(std::vector<unsigned int> const&
}

unsigned int mdSize = 2 * size;
uint16_t pixelModuleIndex = pixelMapping_->pixelModuleIndex;
uint16_t pixelModuleIndex = pixelMapping_.pixelModuleIndex;

if (mdsInGPU == nullptr) {
// Create a view for the element nLowerModules_ inside rangesBuffers->miniDoubletModuleOccupancy
Expand Down Expand Up @@ -820,9 +819,9 @@ void lst::Event<Acc3D>::createPixelTriplets() {
alpaka::wait(queue);

int pixelIndexOffsetPos =
pixelMapping_->connectedPixelsIndex[size_superbins - 1] + pixelMapping_->connectedPixelsSizes[size_superbins - 1];
int pixelIndexOffsetNeg = pixelMapping_->connectedPixelsIndexPos[size_superbins - 1] +
pixelMapping_->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos;
pixelMapping_.connectedPixelsIndex[size_superbins - 1] + pixelMapping_.connectedPixelsSizes[size_superbins - 1];
int pixelIndexOffsetNeg = pixelMapping_.connectedPixelsIndexPos[size_superbins - 1] +
pixelMapping_.connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos;

// TODO: check if a map/reduction to just eligible pLSs would speed up the kernel
// the current selection still leaves a significant fraction of unmatchable pLSs
Expand All @@ -838,19 +837,19 @@ void lst::Event<Acc3D>::createPixelTriplets() {
// Used pixel type to select correct size-index arrays
if (pixelType == 0) {
connectedPixelSize_host[i] =
pixelMapping_->connectedPixelsSizes[superbin]; // number of connected modules to this pixel
auto connectedIdxBase = pixelMapping_->connectedPixelsIndex[superbin];
pixelMapping_.connectedPixelsSizes[superbin]; // number of connected modules to this pixel
auto connectedIdxBase = pixelMapping_.connectedPixelsIndex[superbin];
connectedPixelIndex_host[i] =
connectedIdxBase; // index to get start of connected modules for this superbin in map
} else if (pixelType == 1) {
connectedPixelSize_host[i] =
pixelMapping_->connectedPixelsSizesPos[superbin]; // number of pixel connected modules
auto connectedIdxBase = pixelMapping_->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos;
pixelMapping_.connectedPixelsSizesPos[superbin]; // number of pixel connected modules
auto connectedIdxBase = pixelMapping_.connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos;
connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected pixel modules
} else if (pixelType == 2) {
connectedPixelSize_host[i] =
pixelMapping_->connectedPixelsSizesNeg[superbin]; // number of pixel connected modules
auto connectedIdxBase = pixelMapping_->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg;
pixelMapping_.connectedPixelsSizesNeg[superbin]; // number of pixel connected modules
auto connectedIdxBase = pixelMapping_.connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg;
connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected pixel modules
}
}
Expand Down Expand Up @@ -1052,9 +1051,9 @@ void lst::Event<Acc3D>::createPixelQuintuplets() {
alpaka::wait(queue);

int pixelIndexOffsetPos =
pixelMapping_->connectedPixelsIndex[size_superbins - 1] + pixelMapping_->connectedPixelsSizes[size_superbins - 1];
int pixelIndexOffsetNeg = pixelMapping_->connectedPixelsIndexPos[size_superbins - 1] +
pixelMapping_->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos;
pixelMapping_.connectedPixelsIndex[size_superbins - 1] + pixelMapping_.connectedPixelsSizes[size_superbins - 1];
int pixelIndexOffsetNeg = pixelMapping_.connectedPixelsIndexPos[size_superbins - 1] +
pixelMapping_.connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos;

// Loop over # pLS
for (unsigned int i = 0; i < nInnerSegments; i++) {
Expand All @@ -1068,18 +1067,16 @@ void lst::Event<Acc3D>::createPixelQuintuplets() {
// Used pixel type to select correct size-index arrays
if (pixelType == 0) {
connectedPixelSize_host[i] =
pixelMapping_->connectedPixelsSizes[superbin]; //number of connected modules to this pixel
unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndex[superbin];
pixelMapping_.connectedPixelsSizes[superbin]; //number of connected modules to this pixel
unsigned int connectedIdxBase = pixelMapping_.connectedPixelsIndex[superbin];
connectedPixelIndex_host[i] = connectedIdxBase;
} else if (pixelType == 1) {
connectedPixelSize_host[i] =
pixelMapping_->connectedPixelsSizesPos[superbin]; //number of pixel connected modules
unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos;
connectedPixelSize_host[i] = pixelMapping_.connectedPixelsSizesPos[superbin]; //number of pixel connected modules
unsigned int connectedIdxBase = pixelMapping_.connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos;
connectedPixelIndex_host[i] = connectedIdxBase;
} else if (pixelType == 2) {
connectedPixelSize_host[i] =
pixelMapping_->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules
unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg;
connectedPixelSize_host[i] = pixelMapping_.connectedPixelsSizesNeg[superbin]; //number of pixel connected modules
unsigned int connectedIdxBase = pixelMapping_.connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg;
connectedPixelIndex_host[i] = connectedIdxBase;
}
}
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/LSTCore/src/alpaka/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace lst {
const unsigned int nPixels_;
const unsigned int nEndCapMap_;
ModulesBuffer<Device> const& modulesBuffers_;
std::shared_ptr<const PixelMap> pixelMapping_;
PixelMap const& pixelMapping_;
EndcapGeometryBuffer<Device> const& endcapGeometryBuffers_;

public:
Expand All @@ -103,7 +103,7 @@ namespace lst {
nPixels_(deviceESData->nPixels),
nEndCapMap_(deviceESData->nEndCapMap),
modulesBuffers_(deviceESData->modulesBuffers),
pixelMapping_(deviceESData->pixelMapping),
pixelMapping_(*deviceESData->pixelMapping),
endcapGeometryBuffers_(deviceESData->endcapGeometryBuffers) {
init(verbose);
}
Expand Down

0 comments on commit 14b8bd9

Please sign in to comment.