/* GPUrand */ void GPUrand(const GPUtype &OUT) { curandStatus_t status; gpuTYPE_t type = gm->gputype.getType(OUT); gm->gmat->control.cacheClean(); const void *gpuptr = gm->gputype.getGPUptr(OUT); // pointer to GPU memory int numel = gm->gputype.getNumel(OUT); // number of elements int datasize = gm->gputype.getDataSize(OUT); // bytes for each element gen = 0; // implement recovery procedure // try and if error try again // init curand if (curandCreateGenerator(&gen,CURAND_RNG_PSEUDO_DEFAULT)!=CURAND_STATUS_SUCCESS) { mexErrMsgTxt(ERROR_CURAND_INIT); } //if (curandCreateGenerator(&gen,CURAND_RNG_QUASI_DEFAULT)!=CURAND_STATUS_SUCCESS) { // mexErrMsgTxt(ERROR_CURAND_INIT); //} // seed seed++; if (curandSetPseudoRandomGeneratorSeed(gen, time(NULL)+seed)!=CURAND_STATUS_SUCCESS) { mexErrMsgTxt(ERROR_CURAND_SEED); } if (type == gpuFLOAT) { status = curandGenerateUniform(gen, (float *) gpuptr, numel); } else if (type == gpuCFLOAT) { status = curandGenerateUniform(gen, (float *) gpuptr, numel*2); } else if (type == gpuDOUBLE) { status = curandGenerateUniformDouble(gen, (double *) gpuptr, numel); } else if (type == gpuCDOUBLE) { status = curandGenerateUniformDouble(gen, (double *) gpuptr, numel*2); } if (status!=CURAND_STATUS_SUCCESS) { curandDestroyGenerator(gen); mexErrMsgTxt(ERROR_CURAND_GEN); } // destroy if (curandDestroyGenerator(gen)!=CURAND_STATUS_SUCCESS) { mexErrMsgTxt(ERROR_CURAND_DESTROY); } }
inline void prngenerator_cuda<double>::_generate(const uint32_t n, double * output) { // #ifdef _DEBUG // __cudaCheckMemory(); // std::cout << "Generating " << n << " numbers." << std::endl; // #endif CurandSafeCall(curandGenerateUniformDouble (_dev_bulk_prng_engine, output, n)); }
void cuda_rand(void *ptr, int numel, bool dbl) { static bool is_init = false; static curandGenerator_t stream; if (!is_init) { curandCreateGenerator(&stream, CURAND_RNG_PSEUDO_DEFAULT); is_init = true; } if (!dbl) { curandGenerateUniform(stream, (float *)ptr, numel); } else { curandGenerateUniformDouble(stream, (double *)ptr, numel); } return; }