linux获取显示器信息,如何在Linux上获取连接显示器的数量到gpu?

Linux下最相似的方法是使用NVCtrl API是什么nvidia-settings,Linux的NVIDIA控制面板应用程序,提供。

如何下载nvidia-settings源码包在linux驱动程序发行说明中有记录。具体而言,您可以找到特定驱动程序版本的各种软件包here

选择一个与您的驱动程序版本最接近的软件包。

下载并解压缩nvidia-settings源代码后,您会发现一个samples目录。在那个目录中是一个示例程序,它有你想要的必要框架。具体来看,在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);

注意,有一些准备/设置功能,在那个节目(nv-control-targets.c),其将需要以及执行的最高要求。

在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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值