繁体   English   中英

Cuda 中的多个 GPU - 以前可以工作的代码,但不再是

[英]Multiple GPUs in Cuda - Working code before, but not any more

我最近遇到了在 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 上初始化并重现问题。

在尝试扩展我当前的应用程序时出现了这个问题,这是一个大型的图像处理算法管道。 此管道可以有多个独立的实例,并且由于内存限制,将需要多张卡。 我对这个问题如此困惑的主要原因是我以前使用过它 - 我有一个几年前运行的 Visual Profile 会话,它显示了我的相同卡片的行为与预期一样。 我知道的唯一区别是它在 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 按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM