Skip to content

在windows下的linux子系统wsl Ubuntu下驱动mediapipe gpu支持,问题:gpu比cpu慢;内存泄漏 #6180

@xqy-fly

Description

@xqy-fly

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

Ubuntu 24.04LTS

Mobile device if the issue happens on mobile device

No response

Browser and version if the issue happens on browser

No response

Programming Language and version

C++,python

MediaPipe version

0.10.21

Bazel version

7.3.2

Solution

hand_tracking

Android Studio, NDK, SDK versions (if issue is related to building in Android environment)

No response

Xcode & Tulsi version (if issue is related to building for iOS)

No response

Describe the actual behavior

我在windows上的linux子系统wsl2(Ubuntu)中下载安装了CUDA、CUdnn、Tensorflow、opengl等组件,希望可以运行mediapipe的gpu项目

Describe the expected behaviour

我希望可以在wsl中成功运行mediapipe的gpu项目

Standalone code/steps you may have used to try to get what you need

Other info / Complete Logs

首先我在wsl中进行了相关的环境配置,这点我不细说,我只阐述我安装的版本:CUDA-12.5、Cudnn-9.3、bazel-7.3.2、tensorflow-2.20、python3.11、nccl、nvcc、mediapipe-10.21等。

在开始时,我发现通过opengl es 支持mediapipe的gpu实际上比在cpu运行的还慢,gpu内存大概只占用了35%-45%,这应该是因为opengl需要多次地上传内存到Linux和下载回windows,以及反复的虚拟内存转换。

然后,我尝试使用CUDA直接进行内存访问,我按照官方文档的指示,编译命令如下: bazel run -c opt --config=cuda --spawn_strategy=local \
    --define no_aws_support=true --copt -DMESA_EGL_NO_X11_HEADERS \
    mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu 但报错:double free or corruption (out),内存泄漏。
我不知道这该如何解决。以下是我相关环境的验证和配置信息:(mediapipe_gpu) xqy@DESKTOP-A2HORL1:~/mediapipe$ ls /usr/local/cuda-12.5/extras/CUPTI
doc  samples
(mediapipe_gpu) xqy@DESKTOP-A2HORL1:~/mediapipe$ ls /usr/local/cuda-12.5
DOCS      README  compute-sanitizer  extras  include  libnvvp           nvml  share  targets  version.json
EULA.txt  bin     doc                gds     lib64    nsightee_plugins  nvvm  src    tools
(mediapipe_gpu) xqy@DESKTOP-A2HORL1:~/mediapipe$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Jun__6_02:18:23_PDT_2024
Cuda compilation tools, release 12.5, V12.5.82
Build cuda_12.5.r12.5/compiler.34385749_0
(mediapipe_gpu) xqy@DESKTOP-A2HORL1:~/mediapipe$ ls /usr/lib/x86_64-linux-gnu/ | grep libcudnn.so
libcudnn.so
libcudnn.so.9
libcudnn.so.9.3.0
(mediapipe_gpu) xqy@DESKTOP-A2HORL1:~/mediapipe$ glxinfo | grep -i opengl
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 3060)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 25.0.7-0ubuntu0.24.04.2
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 25.0.7-0ubuntu0.24.04.2
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 25.0.7-0ubuntu0.24.04.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
OpenGL ES profile extensions:
(mediapipe_gpu) xqy@DESKTOP-A2HORL1:~/mediapipe$ nvidia-smi
Fri Dec 12 11:42:05 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.95.05              Driver Version: 581.80         CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3060        On  |   00000000:01:00.0  On |                  N/A |
| 52%   38C    P8             18W /  170W |    1350MiB /  12288MiB |     12%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A             460      G   /Xwayland                             N/A      |
+-----------------------------------------------------------------------------------------+   
现在我正在考虑用Vulkan来替换Opengl,或者使用Nsight Systems来检查数据流在内存中的走向

Metadata

Metadata

Assignees

Labels

type:bugBug in the Source Code of MediaPipe Solution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions