Introduction

Google Coral Dual EdgeTPU is a Mini PCIE card with two built-in Edge Tensor Processing Units (EdgeTPUs) which provide high performance ML inferencing on a low-power ASIC.

Why would I need an adapter for a Dual Edge TPU?

Coral Dual Edge TPU is one card with two identical TPU cores. Each core has it’s own PCIe interface and motherboard shall have two PCIe busses on m.2 slot to make them both work. There are m.2 E-key to desktop PCIe adapters, but those passively pass one PCIe interface to the card, ie only one TPU core will work.

I got this special adapter to use both TPUs on my systems standard PCIe x1 slot magic-blue-smoke/Dual-Edge-TPU-Adapter

Why do I need to install a kernel module?

The Coral Gasket Driver allows usage of the Coral EdgeTPU on Linux systems. The driver contains two modules:

  • Gasket: Gasket (Google ASIC Software, Kernel Extensions, and Tools) is a top level driver for lightweight communication with Google ASICs.
  • Apex: Apex refers to the EdgeTPU v1

This driver landed in staging of 4.19 Linux Kernel’s device tree and was removed due to discontinued development in Linux Kernel 5.13. Google also publishes DKMS packages for Debian-ish distros. Unfortunately that doesn’t help non-Debian-ish users running kernels without this driver built in and package managers which aren’t deb-based.

The following RPM/DKMS package is based on Google Corals main branch and was build for Fedora 37 and later (rawhide).

Installation

Google Coral’s official driver sources are available at google/gasket-driver and the copr repo fork is available at robertzaage/gasket-driver.

Releases from robertzaage/gasket-driver are built/hosted on Fedora copr.

copr build status

Enable the copr repo and install the driver package.

dnf copr enable robertzaage/gasket-dkms
dnf install gasket-dkms

Check if the driver was installed and loaded successfully.

lsmod | grep -E 'gasket|apex'
apex                   32768  0
gasket                135168  1 apex

Now create a udev rule named e.g. 99-edgetpu-accelerator.rules in /etc/udev/rules.d and insert the following lines:

SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1",
ATTRS{idProduct}=="9302", MODE:="0666", TAG+="systemd"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1a6e",
ATTRS{idProduct}=="089a", MODE:="0666", TAG+="systemd"
SUBSYSTEM=="apex", MODE:="0666", TAG+="systemd"

This rule creates a device unit for Apex and Coral USB devices in systemd. You control this behavior with TAG+="systemd" via the TAG option. If you use systemd services that depend on the presence of a TPU, this can be really useful. Since I use my EdgeTPUs in containers and don’t feel like managing special user groups to access them, MODE:="0666" makes permissions a bit more open.

Next we need to reload our udev rules.

udevadm control --reload-rules && udevadm trigger

Check if both TPUs were added as device units and if they are listed under /dev/apex_n.

systemctl | grep apex
  sys-devices-pci0000:00-0000:00:1c.6-0000:02:00.0-0000:03:03.0-0000:04:00.0-apex-apex_0.device             loaded active plugged   /sys/devices/pci0000:00/0000:00:1c.6/0000:02:00.0/0000:03:03.0/0000:04:00.0/apex/apex_0
  sys-devices-pci0000:00-0000:00:1c.6-0000:02:00.0-0000:03:07.0-0000:05:00.0-apex-apex_1.device             loaded active plugged   /sys/devices/pci0000:00/0000:00:1c.6/0000:02:00.0/0000:03:07.0/0000:05:00.0/apex/apex_1
ls -la /dev/apex_*
crw-rw-rw-. 1 root root 120, 0 Dec 31 21:51 /dev/apex_0
crw-rw-rw-. 1 root root 120, 1 Dec 31 21:51 /dev/apex_1

Congratulations, you can now use your Dual EdgeTPU on Fedora! 🤖