Adding a NVIDIA Quadro P620 to my Plex VM

I’ve been running Plex in a CentOS 7 VM for over 5 years and it’s been extremely stable, I’ve had no issues, not even one. Currently Plex is hosted on VMware ESXi 7.0.2 host with two 4 vCPUs and 6GB of vRAM and it works well with H264. I’ve decided to re-rip all of my blu-rays and then transcode them to H265 which will give me a better quality file that takes less space than the same file in H264 takes.

When I need to transcode video to sync to a mobile device for a trip or transcode H265 to H264 for devices that don’t support H265 the processor consumes a lot of CPU on the VM. I could just add more vCPUs to the VM but I have a limit on how many vCPUs I have, and there are more efficient ways to transcode video.

I did some research and came up with the Quadro P620 being the most affordable and power efficient (45W) choose with the features I wanted, specifically NVENC /HEVC (H.265) which should future-proof me for a while.

Enable PCI passthrough

Once the card arrived I installed it and booted the server up. In ESXi 7 update 2 you can enabled PCI passthruough without needing to reboot the host, this is a much welcome feature. I use vCenter to edit the host and VM configuration. If you don’t use vCenter you can just use the GUI that’s built into the ESXi host.

Enable passthrough

Install Nvidia drivers

I’m going to install the NVIDIA driver on CentOS 7 using the package manager which will allow for easy updates via yum.

Install some additional dependencies that are required for installing the NVIDIA drivers.

yum install tar bzip2 make automake gcc gcc-c++ pciutils libglvnd-devel vim bind-utils wget yum-utils

Satisfy the external dependency on EPEL for DKMS.

yum install epel-release

Install the CUDA repository public GPG key.

distribution=rhel7

Setup the CUDA network repository.

ARCH=$( /bin/arch )
yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/$distribution/${ARCH}/cuda-$distribution.repo

The NVIDIA driver requires that the kernel headers and development packages for the running version of the kernel be installed at the time of the driver installation, as well whenever the driver is rebuilt. For example, if your system is running kernel version 4.4.0, the 4.4.0 kernel headers and development packages must also be installed. For CentOS 7, ensure that the system has the correct Linux kernel sources from the CentOS repositories:

yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

Update the repository cache and install the driver using the nvidia-driverlatest-dkms meta-package.

yum clean expire-cache
yum install nvidia-driver-latest-dkms

Reboot the VM.

Test Transcode Function

After the VM came backup I logged in and ran the Nvidia tool provided with the drivers to verify things and was greeted with:

nvidia-smi

I got the following error: Unable to determine the device handle for GPU 0000:13:00.0: Unknown Error.

Nvidia don’t allow you to use their non data centre GPUs in VMs, fortunately this issue is easy to fix by editing the VM configuration. Since I have vCenter I used the GUI to solve this problem instead of downloading the VMX file, editing it and re-uploading the VMX file for the VM.

Login to vCenter and right click on the VM then choose Edit Settings. Go to VM Options and expand Advanced.

Click Edit Configuration then click Add Configuration Params. Now enter the below parameters and click ok.
Name: hypervisor.cpuid.v0
Value: FALSE

Boot up the VM. Once the VM came back up I got the output I was expecting from nvidia-smi.

┌──(root💀pms)-[~]
└─# nvidia-smi
Sat Oct 16 16:09:11 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.84       Driver Version: 460.84       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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  Quadro P600         Off  | 00000000:13:00.0 Off |                  N/A |
| 34%   32C    P8    N/A /  N/A |      2MiB /  2000MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

The last thing to do before testing is to make sure Plex is configured to use hardware transcoding:

Login to your Plex Web UI
Under Settings click Transcoder
Click the check-mark Use hardware acceleration when available
Click Save Changes

I then gave things a quick test by plating a H265 TV show in Google Chrome and then re-ran nvidia-smi.

┌──(root💀pms)-[~]
└─# nvidia-smi
Sat Oct 16 16:12:06 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.84       Driver Version: 460.84       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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  Quadro P600         Off  | 00000000:13:00.0 Off |                  N/A |
| 34%   40C    P0    N/A /  N/A |    160MiB /  2000MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      4863      C   ...diaserver/Plex Transcoder      158MiB |
+-----------------------------------------------------------------------------+

Bingo, now Plex is using the NVIDIA GPU to transcode.

A Nividia Quadro P620 can only do 2 simultaneous transcodes, this is a limit imposed by Nvidia but with a nifty script called nvidia-patch. Just run the below commands and enjoy 4 transcodes at the same time.

git clone https://github.com/keylase/nvidia-patch.git
cd nvidia-patch/
bash patch.sh

Leave a Comment