Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:22

0001 /**
0002 storch_test.cc : CPU tests of storch.h CUDA code using "mocking" with srngcpu.h
0003 =================================================================================
0004 
0005 Standalone compile and run with::
0006 
0007    ~/opticks/sysrap/tests/storch_test.sh 
0008 
0009 HMM: not standalone anymore, currently using libSysrap
0010 
0011 **/
0012 #include <numeric>
0013 #include <vector>
0014 #include <cstdlib>
0015 
0016 #include "srngcpu.h"
0017 using RNG = srngcpu ; 
0018 
0019 #include "scuda.h"
0020 #include "squad.h"
0021 #include "sphoton.h"
0022 #include "storch.h"
0023 #include "SEvent.hh"
0024 
0025 #include "NPFold.h"
0026 
0027 
0028 struct storch_test
0029 {
0030     static void union_cast(); 
0031     static void ref_cast(); 
0032     static NP* make_torch_photon( const NP* gs, const NP* se );   
0033     static NPFold* generate();
0034 };
0035 
0036 void storch_test::union_cast()
0037 {
0038     {
0039         qtorch qt ; 
0040         qt.q.zero() ; 
0041         qt.q.q0.u.x = 101 ; 
0042         storch& t = qt.t ;  // when going down from union type to subtype can just use the union member without casting
0043         std::cout <<  t.desc() << std::endl ; 
0044     }
0045     {
0046         quad6 gs ; 
0047         gs.zero(); 
0048         gs.q0.u.x = 202 ; 
0049         storch& t = (storch&)gs ;   // bolshy : simply cast across from one of the union-ed types to the other 
0050         std::cout <<  "t.gentype " << t.gentype << std::endl ; 
0051     }
0052     {
0053         quad6 gs ; 
0054         gs.zero(); 
0055         gs.q0.u.x = 303 ; 
0056         storch& t = (storch&)gs ;   // simply casting between union types
0057         std::cout <<  t.desc() << std::endl ; 
0058     }
0059 }
0060 
0061 void storch_test::ref_cast()
0062 {
0063     float4 a = make_float4( 1.f, 2.f, 3.f, 4.f ); 
0064     const float3& b = (const float3&)a ; 
0065     const float2& c = (const float2&)a ; 
0066     const float3& d = (const float3&)a.x ; 
0067     std::cout << " a " << a << std::endl ;   
0068     std::cout << " b " << b << std::endl ;   
0069     std::cout << " c " << c << std::endl ;   
0070     std::cout << " d " << d << std::endl ;   
0071 }
0072 
0073 
0074 
0075 
0076 
0077 
0078 NP* storch_test::make_torch_photon( const NP* gs, const NP* se )
0079 {
0080     std::cout << "[storch_test::make_torch_photon" << std::endl ;
0081     const quad6* gg = (quad6*)gs->bytes() ;  
0082     const int*   seed = (int*)se->bytes() ;  
0083 
0084     RNG rng ; 
0085 
0086     int tot_photon = se->shape[0] ; 
0087     NP* ph = NP::Make<float>( tot_photon, 4, 4); 
0088     sphoton* pp = (sphoton*)ph->bytes() ; 
0089 
0090     for(int i=0 ; i < tot_photon ; i++ )
0091     {
0092         unsigned photon_id = i ; 
0093         unsigned genstep_id = seed[photon_id] ; 
0094 
0095         sphoton& p = pp[photon_id] ; 
0096         const quad6& g = gg[genstep_id] ;  
0097         
0098         storch::generate(p, rng, g, photon_id, genstep_id ); 
0099          
0100         if(i % 100 == 0) std::cout << std::setw(6) << i << " : " << p.descBase() << std::endl;  
0101     }
0102     std::cout << "]storch_test::make_torch_photon" << std::endl ;
0103     return ph ; 
0104 }
0105 
0106 NPFold* storch_test::generate()
0107 {
0108     std::cout << "[storch_test::generate" << std::endl ;
0109     NP* gs = SEvent::MakeTorchGenstep(); 
0110     NP* se = SEvent::MakeSeed(gs) ; 
0111     NP* ph = make_torch_photon(gs, se); 
0112 
0113     NPFold* fold = new NPFold ; 
0114     fold->add( "gs", gs ); 
0115     fold->add( "se", se ); 
0116     fold->add( "ph", ph ); 
0117     std::cout << "]storch_test::generate" << std::endl ;
0118     return fold ; 
0119 }
0120 
0121 int main(int argc, char** argv)
0122 {
0123     /*
0124     storch_test::union_cast(); 
0125     storch_test::ref_cast(); 
0126     */
0127 
0128     NPFold* fold = storch_test::generate(); 
0129     fold->save("$FOLD"); 
0130 
0131     return 0 ; 
0132 }
0133