| 41 | const unsigned int RNG::s_maxQrngDimensions = 20000; |
| 42 | |
| 43 | RNG::RNG(unsigned long prngSeed, unsigned int qrngDimensions, unsigned int nSamples) |
| 44 | : m_prngSeed(prngSeed) |
| 45 | , m_qrngDimensions(qrngDimensions) |
| 46 | , m_nSamplesBatchTarget(nSamples) |
| 47 | , m_nSamplesRemaining(0) |
| 48 | { |
| 49 | using std::invalid_argument; |
| 50 | using std::runtime_error; |
| 51 | using std::string; |
| 52 | |
| 53 | if (m_prngSeed == 0) { |
| 54 | throw invalid_argument("PRNG seed must be non-zero"); |
| 55 | } |
| 56 | |
| 57 | if (m_qrngDimensions == 0) { |
| 58 | throw invalid_argument("QRNG dimensions must be non-zero"); |
| 59 | } |
| 60 | |
| 61 | if (m_nSamplesBatchTarget == 0) { |
| 62 | throw invalid_argument("RNG batch size must be non-zero"); |
| 63 | } |
| 64 | |
| 65 | if (m_nSamplesBatchTarget < s_maxQrngDimensions) { |
| 66 | throw invalid_argument("RNG batch size must be greater than RNG::s_maxQrngDimensions"); |
| 67 | } |
| 68 | |
| 69 | curandStatus_t curandResult; |
| 70 | cudaError_t cudaResult; |
| 71 | |
| 72 | // Allocate sample array in host mem |
| 73 | m_h_samples = (float *)malloc(m_nSamplesBatchTarget * sizeof(float)); |
| 74 | |
| 75 | if (m_h_samples == NULL) { |
| 76 | throw runtime_error("Could not allocate host memory for RNG::m_h_samples"); |
| 77 | } |
| 78 | |
| 79 | // Allocate sample array in device mem |
| 80 | cudaResult = cudaMalloc((void **)&m_d_samples, m_nSamplesBatchTarget * sizeof(float)); |
| 81 | |
| 82 | if (cudaResult != cudaSuccess) { |
| 83 | string msg("Could not allocate device memory for RNG::m_d_samples: "); |
| 84 | msg += cudaGetErrorString(cudaResult); |
| 85 | throw runtime_error(msg); |
| 86 | } |
| 87 | |
| 88 | // Create the Random Number Generators |
| 89 | curandResult = curandCreateGenerator(&m_prng, CURAND_RNG_PSEUDO_XORWOW); |
| 90 | |
| 91 | if (curandResult != CURAND_STATUS_SUCCESS) { |
| 92 | string msg("Could not create pseudo-random number generator: "); |
| 93 | msg += curandResult; |
| 94 | throw runtime_error(msg); |
| 95 | } |
| 96 | |
| 97 | curandResult = curandCreateGenerator(&m_qrng, CURAND_RNG_QUASI_SOBOL32); |
| 98 | |
| 99 | if (curandResult != CURAND_STATUS_SUCCESS) { |
| 100 | string msg("Could not create quasi-random number generator: "); |
nothing calls this directly
no outgoing calls
no test coverage detected