Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #include "SLOG.hh"
0002 #include "QU.hh"
0003 #include "QRng.hh"
0004 #include "QCurandStateMonolithic.hh"
0005 #include "SCurandStateMonolithic.hh"
0006 #include "SLaunchSequence.h"
0007 #include "ssys.h"
0008 
0009 #include "qcurandwrap.h"
0010 #include "curand_kernel.h" 
0011 #include "qrng.h"
0012 
0013 const plog::Severity QCurandStateMonolithic::LEVEL = SLOG::EnvLevel("QCurandStateMonolithic", "DEBUG" ); 
0014 
0015 extern "C" void QCurandStateMonolithic_curand_init(SLaunchSequence* lseq, qcurandwrap<XORWOW>* cs, qcurandwrap<XORWOW>* d_cs) ; 
0016 
0017 QCurandStateMonolithic* QCurandStateMonolithic::Create(){ return Create(ssys::getenvvar(EKEY,"1:0:0")); }
0018 QCurandStateMonolithic* QCurandStateMonolithic::Create(const char* spec)
0019 {
0020     SCurandStateMonolithic scs(spec); 
0021     return new QCurandStateMonolithic(scs); 
0022 }
0023 
0024 QCurandStateMonolithic::QCurandStateMonolithic(const SCurandStateMonolithic& scs_)
0025     :
0026     scs(scs_),
0027     h_cs(new qcurandwrap<XORWOW>  { scs.num, scs.seed, scs.offset , nullptr} ),
0028     cs(new qcurandwrap<XORWOW>    { scs.num, scs.seed, scs.offset , nullptr} ),
0029     d_cs(nullptr),
0030     lseq(new SLaunchSequence(cs->num))
0031 {
0032     init(); 
0033 }
0034 
0035 void QCurandStateMonolithic::init()
0036 {
0037     LOG_IF(info, scs.exists) << "scs.path " << scs.path << " exists already : NOTHING TO DO " ;
0038     if(scs.exists) return ; 
0039 
0040     alloc();
0041     create(); 
0042     download(); 
0043     save(); 
0044 }
0045 
0046 void QCurandStateMonolithic::alloc()
0047 { 
0048     cs->states = QU::device_alloc_zero<XORWOW>(cs->num,"QCurandStateMonolithic::QCurandStateMonolithic") ; 
0049     LOG(info) << "after alloc" ; 
0050     d_cs = QU::UploadArray<qcurandwrap<XORWOW>>(cs, 1, "QCurandStateMonolithic::alloc/qcurandwrap" );    
0051     LOG(info) << "after upload" ; 
0052 }
0053 void QCurandStateMonolithic::create() 
0054 {
0055     QCurandStateMonolithic_curand_init(lseq, cs, d_cs); 
0056     LOG(info) << "after QCurandStateMonolithic_curand_init lseq.desc " << std::endl << lseq->desc() ; 
0057 }
0058 void QCurandStateMonolithic::download() 
0059 {
0060     h_cs->states = (XORWOW*)malloc(sizeof(XORWOW)*cs->num);
0061     QU::copy_device_to_host( h_cs->states, cs->states, cs->num ); 
0062     LOG(info) << "after copy_device_to_host  "  ; 
0063 }
0064 void QCurandStateMonolithic::save() const 
0065 {
0066     QRng::Save( h_cs->states, h_cs->num , scs.path.c_str() ); 
0067     LOG(info) << " saved to scs.path " << scs.path ; 
0068 }
0069 
0070 std::string QCurandStateMonolithic::desc() const 
0071 {
0072     std::stringstream ss ; 
0073     ss << "QCurandStateMonolithic::desc"
0074        << " cs.num " << cs->num 
0075        << " cs.seed " << cs->seed 
0076        << " cs.offset " << cs->offset 
0077        << " cs.states " << cs->states 
0078        << " d_cs " << d_cs 
0079        << " scs.path " << scs.path 
0080        ;
0081     std::string s = ss.str(); 
0082     return s ; 
0083 }
0084