In this guide, we will set up the Windows Subsystem for Linux (WSL) and Docker to run TensorRT, a high-performance deep learning inference library. This setup will allow you to leverage the power of your NVIDIA GPU within a Linux environment on Windows.
TensorRT is a high-performance deep learning inference library and software development kit (SDK) developed by NVIDIA. It is designed to optimize deep learning models for deployment on NVIDIA GPUs, providing low-latency and high-throughput inference.
It provides significant speedups for deep learning inference, making it suitable for real-time applications such as autonomous driving, natural language processing, and computer vision. TensorRT supports various deep learning frameworks, including TensorFlow, PyTorch, and ONNX (Open Neural Network Exchange). It can import models from these frameworks and optimize them for deployment.
Before proceeding, ensure that your NVIDIA graphics drivers and necessary libraries are properly installed.
To verify that your NVIDIA drivers are correctly installed, run:
This command will display information about your GPU and the drivers installed. If the command is not found, you may need to install or update your NVIDIA drivers.
For Ubuntu/Debian users, you can check the installed NVIDIA packages with:
This will list all NVIDIA-related packages installed on your system.
Zlib is a compression library that is required by many applications. To check if Zlib is installed, run:
These commands will display the version and installation status of the Zlib library on your system.
cuDNN (CUDA Deep Neural Network library) accelerates deep learning frameworks. You need to manually download and install it if it's not included in your Docker image.
Download cuDNN:
cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar
Install cuDNN:
Extract the tarball and copy the necessary files to their respective directories:
Update your LD_LIBRARY_PATH
to include the CUDA libraries:
Note: Replace /usr/local/cuda/
with your actual CUDA installation path.
Docker is a platform designed to simplify the process of creating, deploying, and running applications by using containerization. Containers allow developers to package an application with all its dependencies and libraries, ensuring it runs consistently across different environments. This eliminates the "it works on my machine" problem and makes deployment more efficient and reliable.
To get started with Docker, you'll need Docker Desktop, a comprehensive solution that includes Docker Engine, Docker CLI, Docker Compose, and other essential tools for container management.
Docker Desktop is available for Windows, macOS, and Linux. It provides a user-friendly interface for managing containers and integrates seamlessly with your operating system.
Download Docker Desktop:
Install Docker Desktop:
Configure Docker Desktop:
Start Docker Desktop:
With Docker Desktop installed, you can now proceed to integrate Docker into your workflow.
This Dockerfile starts with an NVIDIA PyTorch base image and installs ONNX Runtime GPU. It then adds the cuDNN files and sets the necessary environment variables.
Navigate to your working directory and build the image with:
Replace <name>
and <tag>
with your desired image name and tag.
Use Docker Compose to manage and run your Docker containers:
This file defines a service named trt
that uses the previously built image. It configures the container to use NVIDIA GPUs and sets necessary resource limits.
Start your container in detached mode (running in the background) with:
Use -d
for detached mode. For interactive mode, you can use -it
.
To stop and remove the running container, use:
For future use of container, we just need to stop and start it again like this:
First, you need to create an account on Dockerhub. Then you will verify your login:
Then assign a new image name and tag:
Finally push it to your dockerhub space:
This is the image with above configuration (see Dockerfile above) that was pushed to the my dockerhub space with name deeplearning:deployment
. Now this image can be easily pulled with docker pull command:
These commands help manage and inspect environment variables, especially PATH
:
These commands convert the PATH
variable into a more readable format by replacing colons with new lines.
By following this guide, you should be able to set up a robust environment for running TensorRT with Docker on WSL. This approach ensures that all dependencies are properly managed and configured, providing a seamless experience for deep learning inference on your NVIDIA GPU.