I have the following code:
#include <cuda.h>
#include <cutil_inline.h>
#include “MersenneTwister.h”
#include “MersenneTwister_kernel.cu”
//ceil(a /b)
extern “C” int iDivUp(int a, int b){
return ((a % b) != 0) ? (a / b + 1) : (a / b);
}
//floor(a / b)
extern “C” int iDivDown(int a, int b){
return a / b;
}
//Align a to nearest higher multiple of b
extern “C” int iAlignUp(int a, int b){
return ((a % b) != 0) ? (a - a % b + b) : a;
}
//Align a to nearest lower multiple of b
extern “C” int iAlignDown(int a, int b){
return a - a % b;
}
const int PATH_N = 24000000;
const int N_PER_RNG = iAlignUp(iDivUp(PATH_N, MT_RNG_COUNT), 2);
int N = 1000;
float *Rand_h;
Rand_h = (float )malloc(Nsizeof(float));
float Rand_d;
error = cudaMalloc((void **) &Rand_d, Nsizeof(float));
if (error != cudaSuccess){
std::cout << “Failed at malloc:Rand_d.\n”;
return 0;
}
error = cudaMemcpy(Rand_d, Rand_h, sizeof(float), cudaMemcpyHostToDevice);
if (error != cudaSuccess){
std::cout << “Failed at memcpy:Rand_d.\n”;
return 0;
}
RandomGPU<<<32, 128>>>(Rand_d, N_PER_RNG);
error = cudaMemcpy(Rand_h, Rand_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
if (error != cudaSuccess){
std::cout << “Failed at memcpy:Rand_h.\n”;
return 0;
}
The code compiles, but when I run it i get the following error:
Failed at memcpy:Rand_h.
Any suggestions or help would be greatly appreciated. Thanks.