2015-07-22 33 views
2

我有一個4GB和12GB gfx卡與CUDA。在我的應用程序中,我使用CUDAfy.NET,當調用GPGPU.TotalMemory屬性時,它顯示了一個非常巨大的值(絕對不正確)。與FreeMemory相同。如何解決這個問題?GPGPU.TotalMemory顯示非常巨大的值

Console.WriteLine("GPU total memory: " + gpu.TotalMemory.ToString()); 
Console.WriteLine("GPU free memory: " + gpu.FreeMemory.ToString()); 

對於4GB存儲卡,TotalMemory顯示18446744072635809792個字節,FreeMemory顯示18446744072628600832個字節。

+2

這看起來像某種32位整數溢出錯誤。你可能應該聯繫開發者讓他們知道這個。 – talonmies

+1

18446744072635809792是'FFFFFFFFC0000000'和18446744072628600832是'FFFFFFFFBF920000',它們看起來像是上半部分的64位整數,表明在@talonmies暗示的地方存在一個錯誤。丟棄上半部分會導致大約3 GB的結果。 –

+0

好吧,我用http://stackoverflow.com/questions/341243/how-can-i-find-the-amount-of-video-ram-installed-through-a-wmi-call(但顯然不得不使用'ulong'變量而不是'int'),它現在顯示正確的內存大小。但是我仍然會嘗試使用適當的CUDAfy函數。 – Val

回答

0

正如talonmies指出的那樣,這必定是CUDAfy中的一個錯誤,導致內存計算錯誤,但我發現了一種不同的方法來獲取信息。 CudafyByExample中的一些示例代碼正在顯示如何做到這一點! 因此,而不是閱讀GPGPU類的屬性gpu.TotalMemory,我必須通過調用CudafyHost.GetDeviceProperties()函數來獲取包含每個設備屬性對象的列表,那麼每個對象將包含我期望每個CUDA顯卡信息:

public static void PrintGpuProperties() // this was copied from CudafyByExample 
{ 
    int i = 0; 

    foreach (GPGPUProperties devicePropsContainer in CudafyHost.GetDeviceProperties(CudafyModes.Target, false)) 
    { 
     Console.WriteLine(" --- General Information for device {0} ---", i); 
     Console.WriteLine("Name: {0}", devicePropsContainer.Name); 
     Console.WriteLine("Platform Name: {0}", devicePropsContainer.PlatformName); 
     Console.WriteLine("Device Id: {0}", devicePropsContainer.DeviceId); 
     Console.WriteLine("Compute capability: {0}.{1}", devicePropsContainer.Capability.Major, devicePropsContainer.Capability.Minor); 
     Console.WriteLine("Clock rate: {0}", devicePropsContainer.ClockRate); 
     Console.WriteLine("Simulated: {0}", devicePropsContainer.IsSimulated); 
     Console.WriteLine(); 

     Console.WriteLine(" --- Memory Information for device {0} ---", i); 
     Console.WriteLine("Total global mem: {0}", devicePropsContainer.TotalMemory); 
     Console.WriteLine("Total constant Mem: {0}", devicePropsContainer.TotalConstantMemory); 
     Console.WriteLine("Max mem pitch: {0}", devicePropsContainer.MemoryPitch); 
     Console.WriteLine("Texture Alignment: {0}", devicePropsContainer.TextureAlignment); 
     Console.WriteLine(); 

     Console.WriteLine(" --- MP Information for device {0} ---", i); 
     Console.WriteLine("Shared mem per mp: {0}", devicePropsContainer.SharedMemoryPerBlock); 
     Console.WriteLine("Registers per mp: {0}", devicePropsContainer.RegistersPerBlock); 
     Console.WriteLine("Threads in warp: {0}", devicePropsContainer.WarpSize); 
     Console.WriteLine("Max threads per block: {0}", devicePropsContainer.MaxThreadsPerBlock); 
     Console.WriteLine("Max thread dimensions: ({0}, {1}, {2})", devicePropsContainer.MaxThreadsSize.x, devicePropsContainer.MaxThreadsSize.y, devicePropsContainer.MaxThreadsSize.z); 
     Console.WriteLine("Max grid dimensions: ({0}, {1}, {2})", devicePropsContainer.MaxGridSize.x, devicePropsContainer.MaxGridSize.y, devicePropsContainer.MaxGridSize.z); 

     Console.WriteLine(); 

     i++; 
    } 
}