Skip to content

Instantly share code, notes, and snippets.

@thirdwing
Created July 19, 2017 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thirdwing/5f93a142cd4221c81a20b88c4a7cd213 to your computer and use it in GitHub Desktop.
Save thirdwing/5f93a142cd4221c81a20b88c4a7cd213 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cuda.h>
#include <curand.h>
#include <curand_kernel.h>
using namespace std;
int main() {
curandGenerator_t genGPU;
curandCreateGenerator(&genGPU, CURAND_RNG_PSEUDO_MTGP32);
curandSetPseudoRandomGeneratorSeed(genGPU, 1234ULL);
//curandSetGeneratorOffset(genGPU, 0);
const int n = 10;
double GPU[n];
double* d_GPU;
cudaMalloc(&d_GPU, n*sizeof(float));
curandGenerateUniformDouble(genGPU, d_GPU, n);
cudaMemcpy(GPU, d_GPU, n*sizeof(float), cudaMemcpyDeviceToHost);
double GPU2[n];
double* d_GPU2;
cudaMalloc(&d_GPU2, n*sizeof(float));
//curandSetGeneratorOffset(genGPU, 0);
//curandDestroyGenerator(genGPU);
//curandCreateGenerator(&genGPU, CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(genGPU, 1234ULL);
//curandSetGeneratorOffset(genGPU, 0);
curandGenerateUniformDouble(genGPU, d_GPU2, n);
cudaMemcpy(GPU2, d_GPU2, n*sizeof(float), cudaMemcpyDeviceToHost);
for ( int i = 0; i < n; ++i ) {
cout << GPU[i] << "\t\t" << GPU2[i] << endl;
}
curandDestroyGenerator(genGPU);
cudaFree(d_GPU);
cudaFree(d_GPU2);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment