Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /**
0002 QRngTest.cc
0003 ============
0004 
0005 TEST=ctor ~/o/qudarap/tests/QRngTest.sh 
0006 
0007 OPTICKS_MAX_PHOTON=M4 ~/o/qudarap/tests/QRngTest.sh
0008 
0009 
0010 **/
0011 
0012 #include "NP.hh"
0013 #include "ssys.h"
0014 #include "spath.h"
0015 
0016 #include "QRng.hh"
0017 #include "OPTICKS_LOG.hh"
0018 
0019 struct QRngTest
0020 {
0021     using ULL = unsigned long long ; 
0022     static constexpr const ULL M = 1000000ull ;
0023 
0024     static constexpr const char* _NUM_EVENT = "QRngTest__NUM_EVENT" ; 
0025     static constexpr const char* _NUM_VALUE = "QRngTest__NUM_VALUE" ; 
0026     static constexpr const char* _SKIPAHEAD = "QRngTest__SKIPAHEAD" ; 
0027 
0028     ULL num_event ; 
0029     ULL num_value ; 
0030     ULL skipahead_event_offset ;  
0031 
0032     QRng qr ;
0033 
0034     QRngTest(); 
0035 
0036 
0037     template <typename T> NP* generate( unsigned num_event, unsigned num_item, unsigned num_value ); 
0038 
0039     int ctor();
0040     int generate();
0041 
0042     static constexpr const char* _NV = "QRngTest__generate_NV" ; 
0043 
0044     int main();
0045     static int Main(int argc, char** argv);
0046 };
0047 
0048 
0049 QRngTest::QRngTest()
0050     :
0051     num_event(ssys::getenvull(_NUM_EVENT, 3ull)), 
0052     num_value(ssys::getenvull(_NUM_VALUE, 16ull)), 
0053     skipahead_event_offset(ssys::getenvull(_SKIPAHEAD, 1ull)),
0054     qr(skipahead_event_offset)  // may load and upload curandState depending on srng<RNG>::UPLOAD_RNG_STATES
0055 {
0056 } 
0057    
0058 int QRngTest::ctor()
0059 {
0060     LOG(info) << qr.desc() ; 
0061     return 0 ; 
0062 }
0063 
0064 /**
0065 QRngTest::generate
0066 --------------------
0067 
0068 num_event
0069 
0070 num_item
0071     eg number of photons within the event
0072 
0073 num_value
0074     number of randoms for the item 
0075 
0076 skipahead_event_offset
0077     would normally be estimate of maximum number of random 
0078     values for the items : setting to 1 allows to check are getting the expected offsets into the sequence
0079 
0080 **/
0081 
0082 template <typename T>
0083 NP* QRngTest::generate( unsigned num_event, unsigned num_item, unsigned num_value )
0084 {
0085     NP* uu = NP::Make<T>( num_event, num_item, num_value );
0086  
0087     for( unsigned ev=0 ; ev < num_event ; ev++)
0088     {
0089         T* target = uu->values<T>() + num_item*num_value*ev ; 
0090         assert(target); 
0091         qr.generate<T>( target, num_item, num_value, ev  );  
0092     }
0093     return uu ; 
0094 }
0095 
0096 
0097 /**
0098 QRngTest::generate
0099 -------------------
0100 
0101 **/
0102 
0103 int QRngTest::generate()
0104 {
0105     unsigned rngmax = qr.rngmax ; // this is G1 1 billiom for Philox 
0106     unsigned M = 1000000u ; 
0107     unsigned num_item = std::min( M, rngmax ); 
0108 
0109     LOG(info) 
0110         << " rngmax " << rngmax 
0111         << " rngmax/M " << rngmax/M 
0112         << " num_item " << num_item
0113         << " num_item/M " << num_item/M
0114         ;
0115 
0116     NP* uu = generate<float>( num_event, num_item, num_value ) ; 
0117 
0118     uu->save("$FOLD/float", QRng::IMPL, "uu.npy" ); 
0119 
0120     return 0 ; 
0121 }
0122 
0123 
0124 int QRngTest::main()
0125 {
0126     const char* TEST = ssys::getenvvar("TEST","generate"); 
0127     bool ALL = strcmp(TEST, "ALL") == 0 ; 
0128 
0129     LOG(info) << "[TEST:" << TEST ; 
0130 
0131     int rc = 0 ; 
0132     if(ALL||strcmp(TEST,"ctor")==0)          rc += ctor(); 
0133     if(ALL||strcmp(TEST,"generate")==0)      rc += generate(); 
0134 
0135     LOG(info) << "]TEST:" << TEST << " rc " << rc  ; 
0136     return rc ; 
0137 }
0138 
0139 
0140 int QRngTest::Main(int argc, char** argv)
0141 {
0142     OPTICKS_LOG(argc, argv); 
0143     QRngTest t ; 
0144     return t.main() ; 
0145 }
0146 
0147 int main(int argc, char** argv){ return QRngTest::Main(argc, argv) ; }   
0148