2013-08-01 8 views
2

주어진 CUDA 장치에 디스플레이가 연결되어 있는지 여부를 결정해야합니다. 이 작업을 수행하는 CUDA 기능을 알지 못합니다.Linux에서 연결된 디스플레이 수를 GPU로 가져 오는 방법은 무엇입니까?

Windows에서 NVAPI를 사용하여 연결된 디스플레이 수와 각 장치의 PCI 버스/슬롯 ID를 얻을 수 있습니다. 후자를 사용하면 일치하는 CUDA 장치를 찾을 수 있습니다 (cudaGetDeviceProperties 호출).

NVAPI를 사용할 수없는 Linux에서 어떻게 동일한 작업을 수행 할 수 있습니까?

기술적으로, 내가 필요한 것은 다음과 같은 코드를 리눅스 대안은 다음과 같습니다

NvAPI_Initialize(); 

NvPhysicalGpuHandle gpuHandles[64]; 
NvU32 numOfGPUs; 
NvAPI_EnumPhysicalGPUs(gpuHandles, &numOfGPUs); 

for (int i = 0; i < numOfGPUs; i++) 
{ 
    NvU32 connected_displays = 0; 
    NvU32 busId = 0; 
    NvU32 busSlotId = 0; 

    NvAPI_GPU_GetConnectedDisplayIds(gpuHandles[i], NULL, &connected_displays, NULL); 
    NvAPI_GPU_GetBusId(gpuHandles[i], &busId); 
    NvAPI_GPU_GetBusSlotId(gpuHandles[i], &busSlotId); 

    printf("Current device: %d\n", i); 
    printf("Number of connected displays: %u\n", connected_displays); 
    printf("Bus id: %u\tBus slot id: %u\n", busId, busSlotId); 
} 

NvAPI_Unload(); 
+0

아마도 'lsof' 명령을 사용하십시오. '/ proc /'아래 깊은 것. –

+0

monito가 cuda로 켜고 끌 수 있는지 감지 할 수 있습니까? 아이디가 생겼을 때베이스가되면 다른 기능을 호출 할 수 있습니다 ...!? – alap

+0

@ Laszlo-AndrasZsurzsa 나는 그것이 cuda 나 GPU와 관련이 없다고 생각합니다. – hthms

답변

6

리눅스에서 가장 유사한 접근 방식 인 NVCtrl API를 사용하는 것입니다 무엇을 nvidia-settings, 리눅스 NVIDIA 제어판 응용 프로그램, 제공합니다.

nvidia 설정 소스 패키지를 다운로드하는 방법은 Linux 드라이버 릴리스 노트에 설명되어 있습니다. 특히 특정 드라이버 버전에 대한 다양한 패키지를 찾을 수 있습니다. here

드라이버 버전에 가장 가까운 패키지를 선택하십시오.

nvidia 설정 소스를 다운로드하고 압축을 풀면 samples 디렉토리가 있습니다. 이 디렉토리에는 원하는 프레임 워크가있는 샘플 프로그램이 있습니다. 특히 nv-control-targets.c을 살펴보십시오. 이 파일에서 다음 함수는 당신이 원하는 것을 할 것입니다 : 몇 가지 준비/설정 기능뿐만 아니라 실행해야합니다 그 프로그램 (nv-control-targets.c)의 상단에 호출이 있다는 것을

/* Connected Display Devices on GPU */ 

    ret = XNVCTRLQueryTargetAttribute(dpy, 
             NV_CTRL_TARGET_TYPE_GPU, 
             gpu, // target_id 
             0, // display_mask 
             NV_CTRL_CONNECTED_DISPLAYS, 
             &display_devices); 
    if (!ret) { 
     fprintf(stderr, "Failed to query connected displays\n"); 
     return 1; 
    } 
    printf(" Display Device Mask (Connected) : 0x%08x\n", 
      display_devices); 

참고.

NVML (nvidia-smi는 NVML을 기반으로 함)에 GPU가 디스플레이를 호스팅하는지 여부를 알려주는 기능 (디스플레이 모드)이 있지만 그게 세분성을 제공하는지 잘 모르겠습니다. 네가 원해.

사실, 질문을 다시 읽으면 원하는대로 NVML 표시 모드로 충분할 수 있습니다. API 문서 here을 참조하면, p46 :

7.10.2.10 nvmlReturn_t DECLDIR nvmlDeviceGetDisplayMode (nvmlDevice_t device, nvmlEnableState_t 
display) 
Retrieves the display mode for the device. 
For Tesla ™and Quadro ®products from the Fermi and Kepler families. 
This method indicates whether a physical display is currently connected to the device. 
See nvmlEnableState_t for details on allowed modes. 
Parameters: 
device The identifier of the target device 
display Reference in which to return the display mode 
Returns: 
• NVML_SUCCESS if display has been set 
• NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized 
• NVML_ERROR_INVALID_ARGUMENT if device is invalid or display is NULL 
• NVML_ERROR_NOT_SUPPORTED if the device does not support this feature 
+1

cudaDevAttrKernelExecTimeout은 보통 꽤 좋은 가이드입니다. tiemout이 있으면 X11이 장치를 관리하고 있음을 의미합니다. – talonmies

+0

방법 2는 Tesla 및 Quadro 전용이므로 불행히도 사용할 수 없습니다. 방법 1 잘 작동하지만 X 서버가 실행되고 원격 터미널 통해 컴퓨터에서 사용할 수있는 것 같습니다. – hthms

+0

방법 1의 경우 X 서버 사용 권한 문제로 인해 실행 중일 수 있습니다. 루트 사용자로 응용 프로그램을 실행하고 있습니까? –