Skip to content

Commit

Permalink
move MD creation to correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
GNiendorf committed Jan 28, 2025
1 parent 70a26b1 commit a3fb77d
Showing 1 changed file with 28 additions and 64 deletions.
92 changes: 28 additions & 64 deletions RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,47 +179,6 @@ void LSTEvent::loadPixelSegmentToEvent(std::vector<float> const& ptIn,

pixelModuleIndex_ = pixelMapping_.pixelModuleIndex;

if (!miniDoubletsDC_) {
// Create a view for the element nLowerModules_ inside rangesOccupancy->miniDoubletModuleOccupancy
auto rangesOccupancy = rangesDC_->view();
auto dst_view_miniDoubletModuleOccupancy =
cms::alpakatools::make_device_view(queue_, rangesOccupancy.miniDoubletModuleOccupancy()[pixelModuleIndex_]);

// Create a host buffer for a value to be passed to the device
auto pixelMaxMDs_buf_h = cms::alpakatools::make_host_buffer<int>(queue_);
*pixelMaxMDs_buf_h.data() = n_max_pixel_md_per_modules;

alpaka::memcpy(queue_, dst_view_miniDoubletModuleOccupancy, pixelMaxMDs_buf_h);

WorkDiv1D const createMDArrayRangesGPU_workDiv = createWorkDiv<Vec1D>({1}, {1024}, {1});

alpaka::exec<Acc1D>(queue_,
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
hitsDC_->const_view<HitsRangesSoA>(),
rangesDC_->view(),
ptCut_);

auto nTotalMDs_buf_h = cms::alpakatools::make_host_buffer<unsigned int>(queue_);
auto nTotalMDs_buf_d = cms::alpakatools::make_device_view(queue_, rangesOccupancy.nTotalMDs());
alpaka::memcpy(queue_, nTotalMDs_buf_h, nTotalMDs_buf_d);
alpaka::wait(queue_); // wait to get the data before manipulation

*nTotalMDs_buf_h.data() += n_max_pixel_md_per_modules;
unsigned int nTotalMDs = *nTotalMDs_buf_h.data();

std::array<int, 2> const mds_sizes{{static_cast<int>(nTotalMDs), static_cast<int>(nLowerModules_ + 1)}};
miniDoubletsDC_.emplace(mds_sizes, queue_);

auto mdsOccupancy = miniDoubletsDC_->view<MiniDoubletsOccupancySoA>();
auto nMDs_view = cms::alpakatools::make_device_view(queue_, mdsOccupancy.nMDs(), mdsOccupancy.metadata().size());
auto totOccupancyMDs_view =
cms::alpakatools::make_device_view(queue_, mdsOccupancy.totOccupancyMDs(), mdsOccupancy.metadata().size());
alpaka::memset(queue_, nMDs_view, 0u);
alpaka::memset(queue_, totOccupancyMDs_view, 0u);
}

pixelSegmentsDC_.emplace(n_max_pixel_segments_per_module, queue_);

PixelSegments pixelSegments = pixelSegmentsDC_->view();
Expand Down Expand Up @@ -278,36 +237,41 @@ void LSTEvent::createPixelSegmentToEvent(std::vector<unsigned int> hitIndices0,
}

void LSTEvent::createMiniDoublets() {
// Create a view for the element nLowerModules_ inside rangesOccupancy->miniDoubletModuleOccupancy
auto rangesOccupancy = rangesDC_->view();
auto dst_view_miniDoubletModuleOccupancy =
cms::alpakatools::make_device_view(queue_, rangesOccupancy.miniDoubletModuleOccupancy()[nLowerModules_]);
if (!miniDoubletsDC_) {
// Create a view for the element nLowerModules_ inside rangesOccupancy->miniDoubletModuleOccupancy
auto rangesOccupancy = rangesDC_->view();
auto dst_view_miniDoubletModuleOccupancy =
cms::alpakatools::make_device_view(queue_, rangesOccupancy.miniDoubletModuleOccupancy()[nLowerModules_]);

// Create a host buffer for a value to be passed to the device
auto pixelMaxMDs_buf_h = cms::alpakatools::make_host_buffer<int>(queue_);
*pixelMaxMDs_buf_h.data() = n_max_pixel_md_per_modules;
// Create a host buffer for a value to be passed to the device
auto pixelMaxMDs_buf_h = cms::alpakatools::make_host_buffer<int>(queue_);
*pixelMaxMDs_buf_h.data() = n_max_pixel_md_per_modules;

alpaka::memcpy(queue_, dst_view_miniDoubletModuleOccupancy, pixelMaxMDs_buf_h);
alpaka::memcpy(queue_, dst_view_miniDoubletModuleOccupancy, pixelMaxMDs_buf_h);

WorkDiv1D const createMDArrayRangesGPU_workDiv = createWorkDiv<Vec1D>({1}, {1024}, {1});
auto dst_view_miniDoubletModuleOccupancyPix =
cms::alpakatools::make_device_view(queue_, rangesOccupancy.miniDoubletModuleOccupancy()[pixelModuleIndex_]);

alpaka::exec<Acc1D>(queue_,
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
hitsDC_->const_view<HitsRangesSoA>(),
rangesDC_->view(),
ptCut_);
alpaka::memcpy(queue_, dst_view_miniDoubletModuleOccupancyPix, pixelMaxMDs_buf_h);

WorkDiv1D const createMDArrayRangesGPU_workDiv = createWorkDiv<Vec1D>({1}, {1024}, {1});

alpaka::exec<Acc1D>(queue_,
createMDArrayRangesGPU_workDiv,
CreateMDArrayRangesGPU{},
modules_.const_view<ModulesSoA>(),
hitsDC_->const_view<HitsRangesSoA>(),
rangesDC_->view(),
ptCut_);

auto nTotalMDs_buf_h = cms::alpakatools::make_host_buffer<unsigned int>(queue_);
auto nTotalMDs_buf_d = cms::alpakatools::make_device_view(queue_, rangesOccupancy.nTotalMDs());
alpaka::memcpy(queue_, nTotalMDs_buf_h, nTotalMDs_buf_d);
alpaka::wait(queue_); // wait to get the data before manipulation
auto nTotalMDs_buf_h = cms::alpakatools::make_host_buffer<unsigned int>(queue_);
auto nTotalMDs_buf_d = cms::alpakatools::make_device_view(queue_, rangesOccupancy.nTotalMDs());
alpaka::memcpy(queue_, nTotalMDs_buf_h, nTotalMDs_buf_d);
alpaka::wait(queue_); // wait to get the data before manipulation

*nTotalMDs_buf_h.data() += n_max_pixel_md_per_modules;
unsigned int nTotalMDs = *nTotalMDs_buf_h.data();
*nTotalMDs_buf_h.data() += n_max_pixel_md_per_modules;
unsigned int nTotalMDs = *nTotalMDs_buf_h.data();

if (!miniDoubletsDC_) {
std::array<int, 2> const mds_sizes{{static_cast<int>(nTotalMDs), static_cast<int>(nLowerModules_ + 1)}};
miniDoubletsDC_.emplace(mds_sizes, queue_);

Expand Down

0 comments on commit a3fb77d

Please sign in to comment.