c++ - 在 GPU 上使用 X11 时,XShmGetImage 是否会返回主机/设备内存?

标签 c++ linux x11 nvidia gnome

如果 X11 像这样在 GPU 上运行:

Fri Aug  2 23:52:39 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.30       Driver Version: 430.30       CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla M60           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   28C    P8    14W / 150W |    141MiB /  7618MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3255      G   /usr/lib/xorg/Xorg                            57MiB |
|    0      3286      G   /usr/bin/gnome-shell                          81MiB |
+-----------------------------------------------------------------------------+

如果您运行 XShmGetImage(),它会给您一个指向 GPU 内存或主机内存中的内存地址的指针吗?

如果是 GPU,我假设您可以用它在 NVIDIA 卡上执行其他操作,例如 H264 编码该数据。

有没有办法将内存从一个 GPU 内存块复制到另一个 GPU 内存块?

我正在使用 NVENC 库。

最佳答案

阅读MIT Shared Memory extension's文档:

The next step is to create the shared memory segment. This is best done after the creation of the XImage, since you need to make use of the information in that XImage to know how much memory to allocate. To create the segment, you need a call like:

shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777);

这意味着扩展将“共享内存”视为“由 shmget 或等效项返回的内容”。自 shmget is incapable of allocating GPU memory我的回答是 XImage 在主机内存中,而不是设备。

关于c++ - 在 GPU 上使用 X11 时,XShmGetImage 是否会返回主机/设备内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57334841/

相关文章:

c - X11 中的滚轮事件

java - 为什么第一次移动时我的 java gui 是 "jump"?

linux - 如何使用sed从文本文件中获取变量?

c++ - 在线程之间共享资源(文件,互斥体)

每个数据 block 的 linux awk 和 grep 特定行

c++ - 在 C++ 中使用移位器和缓冲区读取二进制文件

x11 - XCB + 记录 x11 扩展示例

c++ - 为什么编译 "std::thread"仿函数需要额外的括号?

c++ - super 可怕的迭代器合法吗?

c++ - C 风格的指针查询到 C++ 类型转换