gpt4 book ai didi

c++ - Cuda 中的多个 GPU - 以前可以工作的代码,但现在不行了

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:05:00 27 4
gpt4 key购买 nike

我最近遇到了在 Cuda 应用程序中使用多个 NVidia GPU 运行时遇到的问题。随附的代码能够在我的 Visual Studio 2013 和 2015(Windows 7、Cuda 9.2、Nvidia 驱动程序 398.26、1xGTX1080 和 1xGTX960)系统中一致地重现该问题。我正在为我的卡(5.2 和 6.1)构建正确的计算能力。

具体来说,在第一个 GPU 初始化后,我无法让第二个 GPU 上的任何函数调用正常工作。错误代码始终是“CudaErrorMemoryAllocation”。它在 Nvidia 分析器以及调试和发布版本中都失败了。我可以按任一顺序在 GPU 上进行初始化并重现问题。

这个问题是在尝试扩展我当前的应用程序时出现的,该应用程序是一个大型图像处理算法流水线。此管道可以有多个独立实例,并且由于内存限制,将需要多张卡。我对这个问题如此困惑的主要原因是我之前已经使用过它 - 我有一个几年前运行的可视化配置文件 session ,它显示我的相同卡片按预期运行。我知道的唯一区别是它在 Cuda 8.0 中。

有什么想法吗?

#include "cuda_runtime.h"
#include "cuda.h"

#include <thread>
#include <conio.h>
#include <iostream>

// Function for each thread to run
void gpuThread(int gpuIdx, bool* result)
{
cudaSetDevice(gpuIdx); // Set gpu index

// Create an int array on CPU
int* hostMemory = new int[1000000];
for (int i = 0; i < 1000000; i++)
hostMemory[i] = i;

// Allocate and copy to GPU
int* gpuMemory;
cudaMalloc(&gpuMemory, 1000000 * sizeof(int));
cudaMemcpy(gpuMemory, hostMemory, 1000000 * sizeof(int), cudaMemcpyHostToDevice);

// Synchronize and check errors
cudaDeviceSynchronize();
cudaError_t error = cudaGetLastError();
if (error != CUDA_SUCCESS)
{
result[0] = false;
return;
}

result[0] = true;
}

int main()
{
bool result1 = false;
bool result2 = false;

std::thread t1(gpuThread, 0, &result1);
std::thread t2(gpuThread, 1, &result2);

t1.join(); // Wait for both threads to complete
t2.join();

if (!result1 || !result2) // Verify our threads returned success
std::cout << "Failed\n";
else
std::cout << "Passed\n";

std::cout << "Press a key to exit!\n";
_getch();

return 0;
}

最佳答案

经过一天的卸载和重新安装程序后,这似乎是 398.26 驱动程序的问题。较新的版本 399.07 按预期工作。

关于c++ - Cuda 中的多个 GPU - 以前可以工作的代码,但现在不行了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52066126/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com