DIY-Viking

If you want something done right…

Frigate – Proxmox – PCI M.2 Coral TPU

My Video Surveillance System of choice is Frigate (especially since version 0.14). Having a Google Coral TPU for object detection is practically mandatory. Running Frigate on Proxmox with an M.2 Coral TPU is not straight forward. I have found a way to get this working. Below is what I did. I also include the steps that did not work, since some of them might have contributed to the final success:

Deactivate “Secure boot” in BIOS.

On the Proxmox node (See the google documentation):

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

apt-get update

apt-get install gasket-dkms libedgetpu1-std

sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"

groupadd apex

adduser $USER apex

lspci -nn | grep 089a

ls /dev/apex_0

This is where I got my first error: “ls: cannot access ‘/dev/apex_0’: No such file or directory”.

Continue:

apt install pve-headers
apt-get install --reinstall gasket-dkms

Here got my second error: “Unable to locate package gasket-dkms”.

Continue:

apt remove gasket-dkms
apt install git
apt install devscripts
apt install dh-dkms
cd /home
git clone https://github.com/google/gasket-driver.git
cd gasket-driver/
debuild -us -uc -tc -b
cd..
dpkg -i gasket-dkms_1.0-18_all.deb
apt update && apt upgrade

Reboot.

Check if the TPU is detected:

lspci -nn | grep 089a
ls /dev/apex_0

If you get “Device 1ac1:089a” and “/dev/apex_0” in return things are looking good.

Type:

nano /etc/default/grub

Change the line GRUB_CMDLINE_LINUX_DEFAULT=”quiet” to:

GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"

Type:

update-grub
nano /etc/modules

Insert:

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

Save and exit. Reboot.

Install Frigate. I’m using the Proxmox Helper Scripts. Install LXC in privileged mode.

Type (Replace <container_id> with Frigate container ID):

nano /etc/pve/lxc/<container_id>.conf

Add on the bottom:

# Added for M.2 Coral TPU
unprivileged: 0
lxc.cgroup2.devices.allow: c 120:* rwm
lxc.mount.entry: /dev/apex_0 dev/apex_0 none bind,optional,create=file 0, 0
lxc.apparmor.profile: unconfined
lxc.mount.auto: cgroup:rw

Restart the Frigate LXC. Add the Coral TPU and Hardware Acceleration in the configuration:

version: 0.14
mqtt:
  enabled: false

ffmpeg:
  hwaccel_args: preset-vaapi

detectors:
  coral:
    type: edgetpu
    device: pci

cameras:
  test:
    ffmpeg:
      inputs:
        - path: /media/frigate/person-bicycle-car-detection.mp4
          input_args: -re -stream_loop -1 -fflags +genpts
          roles:
            - detect
            - rtmp
    detect:
      height: 1080
      width: 1920
      fps: 5
    objects:
      track:
        - person
        - car
        - cat
        - dog
        - bicycle

Look in the log to check that the TPU is detected:

info 2024-12-29 14:57:37 frigate.detectors.plugins.edgetpu_tfl Attempting to load TPU as pci
info 2024-12-29 14:57:37 frigate.app Camera processor started for test: 2187
info 2024-12-29 14:57:37 frigate.app Capture process started for test: 2189
info 2024-12-29 14:57:37 frigate.detectors.plugins.edgetpu_tfl TPU found

I have managed to get this to work on Proxmox version 8.1, 8.2 and 8.3. Hardware: Dell Optiplex i9-9900 CPU @ 3.10GHz and Fujitsu Esprimo i5-8500 CPU @ 3.00GHz.

Honi

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
WordPress Appliance - Powered by TurnKey Linux