cudaMemGetInfo在GTX 690的两个设备上返回相同数量的可用内存

时间:2013-04-12 08:00:01

标签: memory cuda multi-gpu

在尝试追踪内存使用情况时,我遇到了Geforce GTX 690的问题。一个简单的测试程序:

BOOST_AUTO_TEST_CASE(cudaMemoryTest) {

size_t mem_tot_0 = 0;
size_t mem_free_0 = 0;
size_t mem_tot_1 = 0;
size_t mem_free_1 = 0;

unsigned int mem_size = 100*1000000;

float* h_P = new float[mem_size];
for(size_t i = 0; i < mem_size; i++) {
    h_P[i] = 0.f;
}

cudaSetDevice(0);
cudaDeviceReset();
cudaMemGetInfo  (&mem_free_0, & mem_tot_0);
std::cout<<"Free memory before copy dev 0: "<<mem_free_0<<std::endl;

cudaSetDevice(1);
cudaDeviceReset();
cudaMemGetInfo  (&mem_free_1, &mem_tot_1);
std::cout<<"Free memory before copy dev 1: "<<mem_free_1<<std::endl;

cudaSetDevice(0);
float* P;
cudaMalloc((void**)&P, mem_size*sizeof(float));
cudaMemcpy((void*)P, h_P,  mem_size*sizeof(float), cudaMemcpyHostToDevice);

cudaSetDevice(0);
cudaMemGetInfo(&mem_free_0, & mem_tot_0);
std::cout<<"Free memory after copy  dev 0: "<<mem_free_0<<std::endl;

cudaSetDevice(1);
cudaMemGetInfo(&mem_free_1, &mem_tot_1);
std::cout<<"Free memory after copy dev 1: "<<mem_free_1<<std::endl;

BOOST_CHECK(mem_free_0 != mem_free_1);

cudaError_t err;
err = cudaGetLastError();
if(err!=cudaSuccess)
    std::cout<<"an error occurred"<<std::endl;

cudaSetDevice(0);
destroyMem(P);
delete [] h_P;
}

测试打印出来:

1>  Free memory before copy dev 0: 1733173248
1>  Free memory before copy dev 1: 1688424448
1>  Free memory after copy  dev 0: 1289940992
1>  Free memory after copy dev 1: 1289940992     
CudaUtilsTest.cpp(47): error in "cudaMemoryTest": check mem_free_0 != mem_free_1 failed

问题在于,在分配之后,设备1上的空闲内存量与设备0上的空闲内存量完全相同,这不应该是这种情况,因此问题必须在cudaMemGetInfo和/或cudaSetDevice中。任何人都遇到同样的问题,或者在测试中是否有其他根本错误的人可以指出?

在Windows 7,Visual Studio 2010,Cuda SDK 5.0上运行代码,使用代码生成进行编译:compute_30,sm_30

编辑22.4.2013

我继续尝试这个问题,似乎cudaSetDevice工作正常,可以从cudaGetDevice调用的结果中验证。我在内存分配测试后添加了设备0的重置,并且cudaMemGetInfo返回的可用内存大小似乎对于两个设备都是相同的。我已经在我自己的代码中检查了cuda_error_t的所有返回值,并且所有函数调用都返回cudaSuccess。有没有人遇到与GTX 690类似的问题与上面描述的设置?

最重要的测试代码:

BOOST_AUTO_TEST_CASE(cudaMemoryTest) {
size_t mem_tot_0 = 0;
size_t mem_free_0 = 0;
size_t mem_tot_1 = 0;
size_t mem_free_1 = 0;

int device_num = 0;

unsigned int mem_size = 100*1000000;

float* h_P = new float[mem_size];
for(size_t i = 0; i < mem_size; i++) {
    h_P[i] = 0.f;
}

cudaSetDevice(0);
cudaGetDevice(&device_num);
cudaDeviceReset();
cudaMemGetInfo  (&mem_free_0, & mem_tot_0);
std::cout<<"Free memory before copy dev 0: "<<mem_free_0<<" Device: "<<device_num<<std::endl;
cudaDeviceSynchronize();

cudaSetDevice(1);
cudaGetDevice(&device_num);
cudaDeviceReset();
cudaMemGetInfo  (&mem_free_1, & mem_tot_1);
std::cout<<"Free memory before copy dev 1: "<<mem_free_1<<" Device: "<<device_num<<std::endl;
cudaDeviceSynchronize();

cudaSetDevice(0);
cudaGetDevice(&device_num);
float* P;
cudaMalloc((void**)&P, mem_size*sizeof(float));
cudaMemcpy((void*)P, h_P,  mem_size*sizeof(float), cudaMemcpyHostToDevice);
cudaMemGetInfo(&mem_free_0, & mem_tot_0);
std::cout<<"Free memory after copy  dev 0: "<<mem_free_0<<" Device: "<<device_num<<std::endl;
cudaDeviceSynchronize();

cudaSetDevice(1);
cudaGetDevice(&device_num);
cudaMemGetInfo(&mem_free_1, &mem_tot_1);
std::cout<<"Free memory after copy dev 1: "<<mem_free_1<<" Device: "<<device_num<<std::endl;
cudaDeviceSynchronize();

BOOST_CHECK(mem_free_0 != mem_free_1);

cudaError_t err;
err = cudaGetLastError();
if(err!=cudaSuccess)
    std::cout<<"an error occurred"<<std::endl;

// Reset only device 0 and check both
cudaSetDevice(0);
cudaGetDevice(&device_num);
cudaDeviceReset();
cudaMemGetInfo  (&mem_free_0, & mem_tot_0);
std::cout<<"Free memory after second reset of device 0, dev 0: "<<mem_free_0<<" Device: "<<device_num<<std::endl;
cudaDeviceSynchronize();

cudaSetDevice(1);
cudaGetDevice(&device_num);
cudaMemGetInfo  (&mem_free_1, & mem_tot_1);
std::cout<<"Free memory after second device reset of device 0, dev 1: "<<mem_free_1<<" Device: "<<device_num<<std::endl;
cudaDeviceSynchronize();

delete [] h_P;
    }

测试输出:

1>  Free memory before copy dev 0: 1794379776 Device: 0
1>  Free memory before copy dev 1: 1751728128 Device: 1
1>  Free memory after copy  dev 0: 1351696384 Device: 0
1>  Free memory after copy dev 1: 1351696384 Device: 1
1>  CudaUtilsTest.cpp(353): error in "cudaMemoryTest": check mem_free_0 != mem_free_1 failed
1>  Free memory after second reset of device 0, dev 0: 1751728128 Device: 0
1>  Free memory after second device reset of device 0, dev 1: 1751728128 Device: 1

1 个答案:

答案 0 :(得分:3)

这是通过更改的WDDM驱动程序设置解决的,如下所示:

  

切换&#34;禁用多GPU模式&#34;来自NVIDIA控制面板   &#34; 3D-设置&#34; - &GT; &#34;配置多GPU,环绕,PhysX&#34;。

[此评论作为社区维基条目从评论中添加,以便从CUDA标签的未答复队列中获取问题]