Can MATLAB tell me which gpu device is the one connected to the display?

조회 수: 7 (최근 30일)
Naor Movshovitz
Naor Movshovitz 2012년 3월 23일
For example, with a GTX590, I have two gpu devices to choose from. Now my theory is that for CUDA kernel performance it might be best to select the device that is not also busy controlling the display. So I guess I am really asking two questions:
1) Is there in fact a performance hit when running a CUDA kernel on a device that is also connected to the main display and rendering my desktop?
2) If so, how can I tell which gpuDevice is which? Thanks, -nuun

답변 (4개)

Konrad Malkowski
Konrad Malkowski 2012년 3월 25일
1. Yes there will be limitations on what can run on GPU that is used for rendering. In particular the CUDA kernels cannot run for more than 2 to 5 seconds on such a card. So if you have a computation that takes longer, you will need to break it down into smaller chunks. As computing each smaller chunk will involve an individual kernel launch, there will be a performance degradation.
2. I think you might be able to determine if a device is powering a screen by checking the KernelExecutionTimeout property of the object returned by the call to gpuDevice.
  댓글 수: 2
Naor Movshovitz
Naor Movshovitz 2012년 3월 26일
Thanks Konrad, this helps a lot. Unfortunately the KernelExecutionTimeout is True for both devices of a GTX590 although only one is connected to a display. This is a read-only property.
Jason Ross
Jason Ross 2012년 3월 26일
See if you can set the one for compute to TCC mode, this may change this property value. You can do this with nvidia-smi

댓글을 달려면 로그인하십시오.


Jason Ross
Jason Ross 2012년 3월 26일
Ways I could think of to determine which device is connected to a monitor. Some of this is a bit of wild conjecture on my part, so take it with a bit of salt:
  • The output of gpuDevice gives the total memory and free memory on the device. In the case of a system that has a card connected and one reserved for compute, the compute resource will have no memory consumed, and the display one will have some memory consumed. This isn't a bullet-proof strategy, though.
  • If you have access to the nvidia-smi utility (I'm not sure if it works for the GTX series of cards -- it says it's only supported on Tesla and some Quadro cards), you can check the driver mode of each GPU. You can get all the syntax from "nvidia-smi -h", but the main command to use is likely "nvidia-smi --query". A card reserved solely for compute will be in "TCC" mode, and one for graphics rendering will be in "WDDM" and can be used for compute and compute. You could parse this output to find out the "best" one to use. This is valid for Windows only -- WDDM mode does not apply on Linux or Mac
  • If you can't use nvidia-smi, in the CUDA SDK there is an example called "deviceQuery" that gets information about the device. It would be possible to look through these fields and build a small executable that returns the "best" one. There might also be something available at this level that tells you if the monitor is connected -- since it has to know to prevent you from turning off WDDM on a card with a monitor connected!
  댓글 수: 1
Naor Movshovitz
Naor Movshovitz 2012년 3월 26일
Thanks Jason.
I will look into the smi technique. The deviceQuery hack might work, but I am not sure how to relate the device index from the CUDA SDK to the device index returned by PCT. It is tempting to just assume that device 0 of the SDK corresponds to device 1 in MATLAB but...
Free memory reported by gpuDevice is the same for both devices, when selected, and NaN for an unselected device. This is slightly suspicious, I agree that the rendering device should be reserving some memory.

댓글을 달려면 로그인하십시오.


Geoff
Geoff 2012년 3월 26일
If you are running Windows, you could write a little MEX script that returns a list of devices and their status from the API call EnumDisplayDevices:
  댓글 수: 3
Geoff
Geoff 2012년 3월 27일
Are you talking about one card with two display outputs, or two cards? In the case of two cards, I would have thought that the DISPLAY_DEVICE structure returned from EnumDisplayDevices would contain enough information (device name, device context, state flags). I usually use EnumDisplayMonitors, but for a different purpose (positioning windows on available monitors), so I haven't tried EnumDisplayDevices. Tempted to try it now =)
Naor Movshovitz
Naor Movshovitz 2012년 3월 28일
Neither. The GTX590 is a dual-core card. That is, one "device", two gpus. And two gpuDevice in ML, but with the same name.

댓글을 달려면 로그인하십시오.


Geoff
Geoff 2012년 3월 27일
Well, I couldn't help myself. I had to try it. Here's the result of running an EnumDisplayDevices test on my machine:
Device: 0
Name = \\.\DISPLAY1
String = NVIDIA GeForce 9800 GT
Flags = active pruned primary
Device: 1
Name = \\.\DISPLAY2
String = NVIDIA GeForce 9800 GT
Flags = active pruned
Device: 2
Name = \\.\DISPLAY3
String = NVIDIA GeForce 9400 GT
Flags =
Device: 3
Name = \\.\DISPLAYV1
String = RDPDD Chained DD
Flags = mirror
Device: 4
Name = \\.\DISPLAYV2
String = RDP Encoder Mirror Driver
Flags = mirror
My machine has one graphics card (the 9800GT) with two outputs (both of which are attached to monitors), and presumably the 9400GT is the on-board graphics.
The code:
/* Output available display devices */
DISPLAY_DEVICEA dd;
dd.cb = sizeof(dd);
DWORD iDevNum = 0;
while( EnumDisplayDevicesA(NULL, iDevNum, &dd, 0) )
{
printf( "Device: %d\n", iDevNum );
printf( " Name = %s\n", dd.DeviceName );
printf( " String = %s\n", dd.DeviceString );
printf( " Flags =" );
if( dd.StateFlags & DISPLAY_DEVICE_ACTIVE ) printf(" active");
if( dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER ) printf(" mirror");
if( dd.StateFlags & DISPLAY_DEVICE_MODESPRUNED ) printf(" pruned");
if( dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE ) printf(" primary");
if( dd.StateFlags & DISPLAY_DEVICE_REMOVABLE ) printf(" removable");
if( dd.StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE ) printf(" vga");
printf( "\n\n" );
iDevNum++;
}
I presume you are looking for the devices that are not mirrored or active.
  댓글 수: 6
Walter Roberson
Walter Roberson 2012년 5월 3일
The mortal editors cannot "unaccept", but the matlabcentral team can.
Randy Souza
Randy Souza 2012년 5월 7일
Hi Naor & Geoff,
I unaccepted this answer, no need to delete it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by