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 reco::ZVertexSoA data structure
0003    which inherits from Portable{Host}Collection.
0004 
0005    Creates an instance of the class (automatically allocates
0006    memory on device), passes the view of the SoA data to
0007    the 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/VertexSoA/interface/ZVertexDevice.h"
0022 #include "DataFormats/VertexSoA/interface/ZVertexHost.h"
0023 #include "DataFormats/VertexSoA/interface/alpaka/ZVertexSoACollection.h"
0024 #include "FWCore/Utilities/interface/stringize.h"
0025 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0026 #include "HeterogeneousCore/AlpakaInterface/interface/devices.h"
0027 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0028 #include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"
0029 
0030 #include "ZVertexSoA_test.h"
0031 
0032 using namespace ALPAKA_ACCELERATOR_NAMESPACE;
0033 
0034 int main() {
0035   // Get the list of devices on the current platform
0036   auto const& devices = cms::alpakatools::devices<Platform>();
0037   if (devices.empty()) {
0038     std::cerr << "No devices available for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend, "
0039       "the test will be skipped.\n";
0040     exit(EXIT_FAILURE);
0041   }
0042 
0043   // Run the test on each device
0044   for (const auto& device : devices) {
0045     Queue queue(device);
0046 
0047     // Inner scope to deallocate memory before destroying the stream
0048     {
0049       // Instantiate vertices on device. PortableCollection allocates
0050       // SoA on device automatically.
0051       ZVertexSoACollection zvertex_d(queue);
0052       testZVertexSoAT::runKernels(zvertex_d.view(), queue);
0053 
0054       // Instantate vertices on host. This is where the data will be
0055       // copied to from device.
0056       ZVertexHost zvertex_h(queue);
0057       std::cout << zvertex_h.view().metadata().size() << std::endl;
0058       alpaka::memcpy(queue, zvertex_h.buffer(), zvertex_d.const_buffer());
0059       alpaka::wait(queue);
0060 
0061       // Print results
0062       std::cout << "idv\t"
0063                 << "zv\t"
0064                 << "wv\t"
0065                 << "chi2\t"
0066                 << "ptv2\t"
0067                 << "ndof\t"
0068                 << "sortInd\t"
0069                 << "nvFinal\n";
0070 
0071       for (int i = 0; i < 10; ++i) {
0072         std::cout << (int)zvertex_h.view()[i].idv() << '\t' << zvertex_h.view()[i].zv() << '\t'
0073                   << zvertex_h.view()[i].wv() << '\t' << zvertex_h.view()[i].chi2() << '\t'
0074                   << zvertex_h.view()[i].ptv2() << '\t' << (int)zvertex_h.view()[i].ndof() << '\t'
0075                   << (int)zvertex_h.view()[i].sortInd() << '\t' << (int)zvertex_h.view().nvFinal() << '\n';
0076       }
0077     }
0078   }
0079 
0080   return EXIT_SUCCESS;
0081 }