English 中文(简体)
cudaMemcpy在简单拷贝中投掷错误
原标题:cudaMemcpy throwing error during simple copy

Below is a small piece of code that copies 4 elements from an array to the GPU. I really dont understand why cudaMemcpy is throwing an error in this case. Please help

int size = 5;
float *a = (float*)malloc(size * sizeof(float));
a[0] = 1.0;
a[1] = 2.0;
a[2] = 3.0;
a[3] = 4.0;
a[4] = 5.0;

float *g;
cudaMalloc((void**)g, 4 * sizeof(float));
float *tem = a+2;
cudaError_t err = cudaMemcpy(g,a,4 * sizeof(float), cudaMemcpyHostToDevice);
if(err !=0){
    printf("Cudamemcpy threw error
");
    getchar();  
}
最佳回答

我认为,你失去了一个营地:

cudaMalloc((void**)&g, 4 * sizeof(float));

问题回答

暂无回答




相关问题
Why won t OpenCV compile in NVCC?

I am trying to integrate CUDA and openCV in a project. Problem is openCV won t compile when NVCC is used, while a normal c++ project compiles just fine. This seems odd to me, as I thought NVCC ...

error in CUDA compilation

I m getting this error while trying to run sample codes in CUDA SDK. I have CUDA 2.3 and Visual studio 2008 LINK : fatal error LNK1181: cannot open input file cutil32D.lib Any pointers how to ...

CUDA Memory Allocation accessible for both host and device

I m trying to figure out a way to allocate a block of memory that is accessible by both the host (CPU) and device (GPU). Other than using cudaHostAlloc() function to allocate page-locked memory that ...

热门标签