2

I have a 4GB and a 12GB gfx card with CUDA. In my application I use CUDAfy.NET and when calling the GPGPU.TotalMemory property it shows an extremely huge value (definitely incorrect). Same with FreeMemory. How to fix this?

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

For the 4GB card, TotalMemory shows 18446744072635809792 bytes, FreeMemory shows 18446744072628600832 bytes.

talonmies
  • 70,661
  • 34
  • 192
  • 269
Val
  • 1,548
  • 1
  • 20
  • 36
  • 2
    That looks like some sort of 32 bit integer overflow bug. You probably ought to contact the developers let them know about this. – talonmies Jul 22 '15 at 08:17
  • OK, I've used the code from http://stackoverflow.com/questions/341243/how-can-i-find-the-amount-of-video-ram-installed-through-a-wmi-call (but had to use a `ulong` variable instead of `int` obviously) and it shows correct memory size now. But I will still try to use the proper CUDAfy functions. – Val Jul 22 '15 at 10:12
  • Cutting the upper half of the 64-bit integer doesn't give the correct value either. C0000000 in decimal is 3GB and the current card has 4GB (which is correctly displayed by the code from http://stackoverflow.com/questions/341243/how-can-i-find-the-amount-of-video-ram-installed-through-a-wmi-call) – Val Jul 22 '15 at 10:23

1 Answers1

0

As talonmies pointed out, this must be a bug in CUDAfy that causes incorrect memory calculation but I found a different method to get the information. Some example code in CudafyByExample is showing exactly how to do that! So, instead of reading GPGPU class' property gpu.TotalMemory, I have to get a list of objects containing properties for each device by calling the CudafyHost.GetDeviceProperties() function, then each object will contain my desired info for each CUDA graphics card:

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++;
    }
}
Val
  • 1,548
  • 1
  • 20
  • 36