我在运行 cudaMemcpy 以从我的 GPU 取回一些数据时遇到了一些问题。cudaErrorString 是“无效参数”,它发生在从设备到主机的 memcpy 上。这是我的隔离代码:
//To render particles out of.
GLfloat* particleRenderData = new GLfloat[particleContainer.size() * 4];
//particlePosBuffer lives on GPU and is used to copy updated particle data
//Back to the OpenGL Buffer.
GLfloat *particlePosBuffer;
cudaStatus = cudaMalloc((void**)&particlePosBuffer, particleContainer.size() * sizeof(GLfloat)* 4);
CUDA_CHECK_STATUS;
//CalcBuffer is our points. CUDA will modify it on GPU.
Point3D *calcBuffer;
cudaStatus = cudaMalloc((void**)&calcBuffer, particleContainer.size() * sizeof(Point3D));
CUDA_CHECK_STATUS;
cudaStatus = cudaMemcpy(calcBuffer, &particleContainer[0], particleContainer.size() * sizeof(Point3D), cudaMemcpyHostToDevice);
CUDA_CHECK_STATUS;
update << <1, 1 >> > (calcBuffer, particlePosBuffer, particleContainer.size(), 1.0);
cudaThreadSynchronize();
cudaStatus = cudaMemcpy(particlePosBuffer, particleRenderData, particleContainer.size() * sizeof(GLfloat)* 4, cudaMemcpyDeviceToHost);
CUDA_CHECK_STATUS;
Run Code Online (Sandbox Code Playgroud)
particleContainer 是 Point3D 类型的向量,是我写的一个类。设备的第一个 memcpy 成功,我比较了主机和设备缓冲区以确保这一点。截至目前,更新可能不是问题。不管有没有它都会出现这个问题。同步也是一样。我尝试了许多不同的方法,包括将particlePosBuffer 和renderData 转换为void*,仅传递引用,以及两者兼而有之。
我在 Visual Studio 2013 中使用 CUDA 6.5。GPU 是 gtx 770,我正在编译 compute_30、sm_30。
我希望有人能帮我解决这个问题,我在这里很受阻。
你这里有问题:
cudaStatus = cudaMemcpy(particlePosBuffer, particleRenderData, particleContainer.size() * sizeof(GLfloat)* 4, cudaMemcpyDeviceToHost);
Run Code Online (Sandbox Code Playgroud)
这旨在从设备到主机的传输。就像memcpy
,第一个参数cudaMemcpy
是永远的目标指针。所以你的前两个参数颠倒了。它应该是这样的:
cudaStatus = cudaMemcpy(particleRenderData, particlePosBuffer, particleContainer.size() * sizeof(GLfloat)* 4, cudaMemcpyDeviceToHost);
Run Code Online (Sandbox Code Playgroud)
particlePosBuffer
是一个设备指针,它是这个操作的源头。
particleRenderData
是一个主机指针,它是这个操作的目的地。
归档时间: |
|
查看次数: |
1282 次 |
最近记录: |