Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-21 07:53:51

0001 #include <iostream>
0002 #include <stdexcept>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include "simphony/sysrap/NP.hh"
0007 #include "simphony/sysrap/sphoton.h"
0008 
0009 #include "simphony/sysrap/config.h"
0010 #include "simphony/sysrap/torch.h"
0011 
0012 using namespace std;
0013 
0014 int main(int argc, char** argv)
0015 {
0016     bool                   use_gpu = false;
0017     constexpr unsigned int seed = 42;
0018     unsigned int           num_photons = 0;
0019 
0020     for (int i = 1; i < argc; i++)
0021     {
0022         string arg = argv[i];
0023         if (arg == "--cpu")
0024         {
0025             use_gpu = false;
0026         }
0027         else if (arg == "--gpu")
0028         {
0029             use_gpu = true;
0030         }
0031         else if (arg == "--num-photons" && i + 1 < argc)
0032         {
0033             num_photons = static_cast<unsigned int>(stoul(argv[++i]));
0034         }
0035         else if (arg == "-h" || arg == "--help")
0036         {
0037             cout << "Usage: simphox [--cpu] [--gpu] [--num-photons N]" << endl;
0038             return EXIT_SUCCESS;
0039         }
0040         else
0041         {
0042             cerr << "Unknown argument: " << arg << endl;
0043             return EXIT_FAILURE;
0044         }
0045     }
0046 
0047     simphony::Config config("dev");
0048 
0049     cout << config.torch.desc() << endl;
0050     cout << "backend " << (use_gpu ? "gpu" : "cpu") << endl;
0051     cout << "seed " << seed << endl;
0052 
0053     vector<sphoton> phs;
0054     if (!use_gpu)
0055     {
0056         phs = generate_photons(config.torch, num_photons, seed);
0057     }
0058     else
0059     {
0060         try
0061         {
0062             phs = generate_photons_gpu(config.torch, num_photons, seed);
0063         }
0064         catch (const exception& err)
0065         {
0066             cerr << "GPU photon generation failed: " << err.what() << endl;
0067             return EXIT_FAILURE;
0068         }
0069     }
0070 
0071     size_t num_floats = phs.size() * 4 * 4;
0072     float* data = reinterpret_cast<float*>(phs.data());
0073     NP*    photons = NP::MakeFromValues<float>(data, num_floats);
0074 
0075     photons->reshape({static_cast<int64_t>(phs.size()), 4, 4});
0076     photons->dump();
0077     photons->save("out/photons.npy");
0078 
0079     return EXIT_SUCCESS;
0080 }