Created
July 19, 2017 22:25
-
-
Save thirdwing/5f93a142cd4221c81a20b88c4a7cd213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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