Skip to content

Instantly share code, notes, and snippets.

@aryan-f
Last active October 17, 2021 17:43
Show Gist options
  • Save aryan-f/7e803bb99aeafcaa6be1ba8eea7a691c to your computer and use it in GitHub Desktop.
Save aryan-f/7e803bb99aeafcaa6be1ba8eea7a691c to your computer and use it in GitHub Desktop.
How to Build MediaPipe Python Package for CUDA on Manjaro

Step 0: Install Bazel 3.7.2: You could build from source. But there was an issue with openjdk that I just didn't bother to look into.

pamac install bazel3-bin

Step 1: Install CUDA and cuDNN. You can find the exact versions TensorFlow supports here here. As of the time of writing this report, if you've installed proprietary drivers when installing the OS, you'll have to run the following commands in Manjaro:

sudo pacman -S cuda cudnn gdb

Once installed, run the following commands to modify envvars:

export PATH=/opt/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/cuda/extras/CUPTI/lib64,/opt/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export TF_CUDA_PATHS=/opt/cuda,/usr/lib,/usr/include
sudo ldconfig

Finally, if the following command produces a log about CUDA Compiler Driver, you should be good to go!

nvcc -V

Step 2: Clone MediaPipe. Make sure there's enough space on the parition for a lot of temporary build files.

git clone https://github.com/google/mediapipe.git
cd mediapipe

Step 3: Install OpenCV and FFmpeg. The latter should come with the OS by default.

sudo pacman -S opencv ffmpeg
pamac install libavresample
pamac install openexr2

Step 4: Copy TensorFlow's CUDA setting from .bazelrc. The said settings are currently here. Drop the following lines at the end of .bazelrc within the mediapipe directory.

# This config refers to building CUDA op kernels with nvcc.
build:cuda --repo_env TF_NEED_CUDA=1
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain
build:cuda --@local_config_cuda//:enable_cuda

Step 5: Install Protobuf and CMake. The former should come preinstalled with the OS.

sudo pacman -S protobuf cmake

Step 6: Install the dependencies in a virtual environment. The most straightforward solution is to go:

virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

I'm using Python 3.9.7 for this experiment.

Step 6: Generate and install MediaPipe. Run the following commands to get a wheel installation file targeted for your system.

python setup.py gen_protos
python setup.py bdist_wheel

That's about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment