- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用并发 CUDA 时遇到了一些问题。看看附图。内核在标记点启动,即 0.395 秒。然后是一些绿色的 CpuWork。最后,调用 cudaDeviceSynchronize。在 CpuWork 之前启动的内核不会在同步调用之前启动。理想情况下,它应该与 CPU 工作并行运行。
void KdTreeGpu::traceRaysOnGpuAsync(int firstRayIndex, int numRays, int rank, int buffer)
{
int per_block = 128;
int num_blocks = numRays/per_block + (numRays%per_block==0?0:1);
Ray* rays = &this->deviceRayPtr[firstRayIndex];
int* outputHitPanelIds = &this->deviceHitPanelIdPtr[firstRayIndex];
kdTreeTraversal<<<num_blocks, per_block, 0>>>(sceneBoundingBox, rays, deviceNodesPtr, deviceTrianglesListPtr,
firstRayIndex, numRays, rank, rootNodeIndex,
deviceTHitPtr, outputHitPanelIds, deviceReflectionPtr);
CUDA_VALIDATE(cudaMemcpyAsync(resultHitDistances[buffer], deviceTHitPtr, numRays*sizeof(double), cudaMemcpyDeviceToHost));
CUDA_VALIDATE(cudaMemcpyAsync(resultHitPanelIds[buffer], outputHitPanelIds, numRays*sizeof(int), cudaMemcpyDeviceToHost));
CUDA_VALIDATE(cudaMemcpyAsync(resultReflections[buffer], deviceReflectionPtr, numRays*sizeof(Vector3), cudaMemcpyDeviceToHost));
}
memcopies 是异步的。结果缓冲区是这样分配的
unsigned int flag = cudaHostAllocPortable;
CUDA_VALIDATE(cudaHostAlloc(&resultHitPanelIds[0], MAX_RAYS_PER_ITERATION*sizeof(int), flag));
CUDA_VALIDATE(cudaHostAlloc(&resultHitPanelIds[1], MAX_RAYS_PER_ITERATION*sizeof(int), flag));
希望有一个解决方案。尝试了很多东西,包括不在默认流中运行。当我添加 cudaHostAlloc 时,我认识到异步方法返回到 CPU。但是当内核在稍后的 deviceSynchronize 调用之前没有启动时,这无济于事。
resultHitDistances[2]
包含两个分配的内存区域,因此当 0 被 CPU 读取时,GPU 应该将结果放入 1。
谢谢!
编辑:这是调用 traceRaysAsync 的代码。
int numIterations = ceil(float(this->numPrimaryRays) / MAX_RAYS_PER_ITERATION);
int numRaysPrevious = min(MAX_RAYS_PER_ITERATION, this->numPrimaryRays);
nvtxRangePushA("traceRaysOnGpuAsync First");
traceRaysOnGpuAsync(0, numRaysPrevious, rank, 0);
nvtxRangePop();
for(int iteration = 0; iteration < numIterations; iteration++)
{
int rayFrom = (iteration+1)*MAX_RAYS_PER_ITERATION;
int rayTo = min((iteration+2)*MAX_RAYS_PER_ITERATION, this->numPrimaryRays) - 1;
int numRaysIteration = rayTo-rayFrom+1;
// Wait for results to finish and get them
waitForGpu();
// Trace the next iteration asynchronously. This will have data prepared for next iteration
if(numRaysIteration > 0)
{
int nextBuffer = (iteration+1) % 2;
nvtxRangePushA("traceRaysOnGpuAsync Interior");
traceRaysOnGpuAsync(rayFrom, numRaysIteration, rank, nextBuffer);
nvtxRangePop();
}
nvtxRangePushA("CpuWork");
// Store results for current iteration
int rayOffset = iteration*MAX_RAYS_PER_ITERATION;
int buffer = iteration % 2;
for(int i = 0; i < numRaysPrevious; i++)
{
if(this->activeRays[rayOffset+i] && resultHitPanelIds[buffer][i] >= 0)
{
this->activeRays[rayOffset+i] = false;
const TrianglePanelPair & t = this->getTriangle(resultHitPanelIds[buffer][i]);
double hitT = resultHitDistances[buffer][i];
Vector3 reflectedDirection = resultReflections[buffer][i];
Result res = Result(rays[rayOffset+i], hitT, t.panel);
results[rank].push_back(res);
t.panel->incrementIntensity(1.0);
if (t.panel->getParent().absorbtion < 1)
{
numberOfRaysGenerated++;
Ray reflected (res.endPoint() + 0.00001*reflectedDirection, reflectedDirection);
this->newRays[rayOffset+i] = reflected;
this->activeRays[rayOffset+i] = true;
numNewRays++;
}
}
}
numRaysPrevious = numRaysIteration;
nvtxRangePop();
}
最佳答案
这是使用 WDDM 驱动程序模型的 Windows 上的预期行为,其中驱动程序尝试通过尝试批处理内核启动来减轻内核启动开销。尝试在内核调用后直接插入 cudaStreamQuery(0)
,以在批处理满之前触发内核的提前启动。
关于CUDA 内核未在 CudaDeviceSynchronize 之前启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13568805/
我遇到了一个非常奇怪的错误,在运行特定大小的 Heat 2D 模拟时出现“非法内存访问”错误,但如果我运行完全相同的模拟,模拟运行良好,只是元素更少。 是否有增加数组大小会导致此异常的原因?我使用的是
我是 CUDA 的新手,对 cudaEvent 有点困惑。我现在有一个代码示例,如下所示: float elapsedTime; cudaEvent_t start, stop; CUDA_ERR_C
我有以下两个几乎相同的示例代码。 code1.cu 使用 cudaMalloc 和 cudaMemcpy 处理设备/主机变量值交换。 code2.cu使用cudaMallocManaged,因此不需要
什么时候真正需要调用cudaDeviceSynchronize函数? 据我从 CUDA 文档中了解到,CUDA 内核是异步的,因此我们似乎应该在每次内核启动后调用 cudaDeviceSynchron
我正在具有统一内存的 TegraK1 板上实现共轭梯度求解器。我面临的问题是在循环中我必须执行 cudaDeviceSynchronize();两次更新变量,与 TI Keystone-II 相比,这
我最近发现了 cuda-memcheck 的 racecheck 工具,可用于 CUDA 5.0(cuda-memcheck --tool racecheck,请参阅 NVIDIA doc)。该工具可
我在使用并发 CUDA 时遇到了一些问题。看看附图。内核在标记点启动,即 0.395 秒。然后是一些绿色的 CpuWork。最后,调用 cudaDeviceSynchronize。在 CpuWork
我在使用并发 CUDA 时遇到了一些问题。看看附图。内核在标记点启动,即 0.395 秒。然后是一些绿色的 CpuWork。最后,调用 cudaDeviceSynchronize。在 CpuWork
CUDA 版本 10.1。帕斯卡GPU。所有命令都发布到默认流: void * ptr; cudaMalloc(&ptr, ...); launch_kernel>>(ptr); cudaDevice
我用 CUDA 6.5 和 4 x GPU Kepler . 我使用多线程、CUDA 运行时 API 并从不同的 CPU 线程访问 CUDA 上下文(通过使用 OpenMP - 但它并不重要)。 当我
这三个函数有什么区别,尤其是最后两个?图书馆手册说 Note that this function is deprecated because its name does not reflect it
非常感谢您阅读我的帖子。 我正在做 CUDA 工作,但一直收到 cudaDeviceSynchronize() 错误代码 77:cudaErrorIllegalAddress,不知道为什么。我搜索了代
__global__ void helloCUDA(float f) { printf("Hello thread %d, f=%f\n", threadIdx.x, f); } int ma
我是一名优秀的程序员,十分优秀!