Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:21

0001 #include <type_traits>
0002 
0003 #include <alpaka/alpaka.hpp>
0004 
0005 #include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsDevice.h"
0006 #include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h"
0007 #include "DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h"
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/traits.h"
0010 #include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
0011 
0012 #include "Hits_test.h"
0013 
0014 using namespace alpaka;
0015 
0016 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0017 
0018   using namespace cms::alpakatools;
0019   namespace testTrackingRecHitSoA {
0020 
0021     template <typename TrackerTraits>
0022     struct TestFillKernel {
0023       template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>>
0024       ALPAKA_FN_ACC void operator()(TAcc const& acc, TrackingRecHitSoAView<TrackerTraits> soa) const {
0025         const uint32_t i(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc)[0u]);
0026         const uint32_t j(alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u]);
0027 
0028         if (cms::alpakatools::once_per_grid(acc)) {
0029           soa.offsetBPIX2() = 22;
0030           soa[10].xLocal() = 1.11;
0031         }
0032 
0033         soa[i].iphi() = i % 10;
0034         soa.hitsLayerStart()[j] = j;
0035       }
0036     };
0037 
0038     template <typename TrackerTraits>
0039     struct ShowKernel {
0040       template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>>
0041       ALPAKA_FN_ACC void operator()(TAcc const& acc, TrackingRecHitSoAConstView<TrackerTraits> soa) const {
0042         if (cms::alpakatools::once_per_grid(acc)) {
0043           printf("nbins = %d\n", soa.phiBinner().nbins());
0044           printf("offsetBPIX = %d\n", soa.offsetBPIX2());
0045           printf("nHits = %d\n", soa.metadata().size());
0046           //printf("hitsModuleStart[28] = %d\n", soa[28].hitsModuleStart());
0047         }
0048 
0049         // can be increased to soa.nHits() for debugging
0050         for (uint32_t i : cms::alpakatools::uniform_elements(acc, 10)) {
0051           printf("iPhi %d -> %d\n", i, soa[i].iphi());
0052         }
0053       }
0054     };
0055 
0056     template <typename TrackerTraits>
0057     void runKernels(TrackingRecHitSoAView<TrackerTraits>& view, Queue& queue) {
0058       uint32_t items = 64;
0059       uint32_t groups = divide_up_by(view.metadata().size(), items);
0060       auto workDiv = make_workdiv<Acc1D>(groups, items);
0061       alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel<TrackerTraits>{}, view);
0062       alpaka::exec<Acc1D>(queue, workDiv, ShowKernel<TrackerTraits>{}, view);
0063     }
0064 
0065     template void runKernels<pixelTopology::Phase1>(TrackingRecHitSoAView<pixelTopology::Phase1>& view, Queue& queue);
0066     template void runKernels<pixelTopology::Phase2>(TrackingRecHitSoAView<pixelTopology::Phase2>& view, Queue& queue);
0067 
0068   }  // namespace testTrackingRecHitSoA
0069 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE