Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002    Simple test for the pixelTrack::TrackSoA data structure
0003    which inherits from PortableDeviceCollection.
0004 
0005    Creates an instance of the class (automatically allocates
0006    memory on device), passes the view of the SoA data to
0007    the CUDA kernels which:
0008    - Fill the SoA with data.
0009    - Verify that the data written is correct.
0010 
0011    Then, the SoA data are copied back to Host, where
0012    a temporary host-side view (tmp_view) is created using
0013    the same Layout to access the data on host and print it.
0014  */
0015 
0016 #include <cstdlib>
0017 #include <unistd.h>
0018 
0019 #include <alpaka/alpaka.hpp>
0020 
0021 #include "DataFormats/TrackSoA/interface/TracksDevice.h"
0022 #include "DataFormats/TrackSoA/interface/TracksHost.h"
0023 #include "DataFormats/TrackSoA/interface/alpaka/TracksSoACollection.h"
0024 #include "FWCore/Utilities/interface/stringize.h"
0025 #include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"
0026 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0027 #include "HeterogeneousCore/AlpakaInterface/interface/devices.h"
0028 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0029 #include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
0030 
0031 #include "TrackSoAHeterogeneous_test.h"
0032 
0033 using namespace ALPAKA_ACCELERATOR_NAMESPACE;
0034 using namespace ALPAKA_ACCELERATOR_NAMESPACE::pixelTrack;
0035 
0036 int main() {
0037   // Get the list of devices on the current platform
0038   auto const& devices = cms::alpakatools::devices<Platform>();
0039   if (devices.empty()) {
0040     std::cerr << "No devices available for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend, "
0041       "the test will be skipped.\n";
0042     exit(EXIT_FAILURE);
0043   }
0044 
0045   // Run the test on each device
0046   for (const auto& device : devices) {
0047     Queue queue(device);
0048 
0049     // Inner scope to deallocate memory before destroying the stream
0050     {
0051       // Instantiate tracks on device. PortableDeviceCollection allocates
0052       // SoA on device automatically.
0053       TracksSoACollection<pixelTopology::Phase1> tracks_d(queue);
0054       testTrackSoA::runKernels<pixelTopology::Phase1>(tracks_d.view(), queue);
0055 
0056       // Instantate tracks on host. This is where the data will be
0057       // copied to from device.
0058       TracksHost<pixelTopology::Phase1> tracks_h(queue);
0059 
0060       std::cout << tracks_h.view().metadata().size() << std::endl;
0061       alpaka::memcpy(queue, tracks_h.buffer(), tracks_d.const_buffer());
0062       alpaka::wait(queue);
0063 
0064       // Print results
0065       std::cout << "pt"
0066                 << "\t"
0067                 << "eta"
0068                 << "\t"
0069                 << "chi2"
0070                 << "\t"
0071                 << "quality"
0072                 << "\t"
0073                 << "nLayers"
0074                 << "\t"
0075                 << "hitIndices off" << std::endl;
0076 
0077       for (int i = 0; i < 10; ++i) {
0078         std::cout << tracks_h.view()[i].pt() << "\t" << tracks_h.view()[i].eta() << "\t" << tracks_h.view()[i].chi2()
0079                   << "\t" << (int)tracks_h.view()[i].quality() << "\t" << (int)tracks_h.view()[i].nLayers() << "\t"
0080                   << tracks_h.view().hitIndices().off[i] << std::endl;
0081       }
0082     }
0083   }
0084 
0085   return EXIT_SUCCESS;
0086 }