Libre Computer Cottonwood Alta TensorFlow Lite MobileNetV1 Guide

Alta features a 5TOPs INT8 Verisilicon NPU for running tensor and convolution computation for AI based workloads. Tomeu has developed TensorFlow Lite delegate for Mesa to make use of the existing piping for Verisilicon’s Etnaviv IP. The long term goal is to create a NN API HAL frontend that is targeted by TensorFlow Lite and PyTorch Mobile with Gallium as the backend to create dmabufs and command streams for the physical hardware. If you are interested in this work, there is a community at #ml-mainline on OFTC.

Please update your board to the latest firmware. You can setup an NFS environment on Debian with LOON or use our Debian 12 image.

Enable the NPU with the wiring tool:

sudo apt install -y git
git clone https://github.com/libre-computer-project/libretech-wiring-tool.git
cd libretech-wiring-tool
make
sudo ./ldto enable npu
cd ..

Enable APT sources

sed "s/^deb\s/deb-src /" /etc/apt/sources.list > /etc/apt/sources.list.d/src.list
sudo apt update

Install Mesa Build Dependencies

sudo eatmydata apt-get -y build-dep mesa
sudo eatmydata apt -y install meson glslang-tools glslang-dev python3-mako zlib1g-dev flatbuffers-compiler python3-pytest python3-exceptiongroup python3-pip python3-pil

Get Meson > 1.1.0 from Debian

wget FILE_URL #replace FILE_URL with direct link to the deb from the link above
sudo dpkg -i FILE #replace FILE with filename

Build Teflon

git clone https://gitlab.freedesktop.org/tomeu/mesa.git -b teflon-staging --single-branch --depth=1
cd mesa
meson setup build -Dgallium-drivers=etnaviv -Dvulkan-drivers= -Dteflon=true
meson compile -C build

Install TensorFlow Lite

pip3 install --break-system-packages tflite-runtime

Run Teflon Tests

DELEGATE_PATH=build/src/gallium/targets/teflon/libteflon.so python3 -m pytest -v src/gallium/frontends/teflon/tests/test_conv2d.py

Run MobileNetV1

python3 src/gallium/frontends/teflon/tests/classification.py -i ~/tensorflow/assets/grace_hopper.bmp -m src/gallium/frontends/teflon/tests/mobilenet_v1_1.0_224_quant.tflite -l src/gallium/frontends/teflon/tests/labels_mobilenet_quant_v1_224.txt -e build/src/gallium/targets/teflon/libteflon.so

To learn more about AI/neuro computing and how it is applied, here is a list of reading material.

1 Like

When I tried to build mesa, I received some error which was solved by making changes as per this commit on the main repo of mesa

1 Like

The code should be merged into mesa 24.1. Please let us know if there are still problems.

When I enabled NPU it locks up gnome. Any thoughts? Has anyone got this working recently?

It seems the test codes are now only in tomeu’s teflon-tp or other branches.

Gnome will try to use the NPU as a GPU. It’s recommended to use it headless.

Tomeu just made a nearly 2x performance increase in the last week. HEAD is always going to be faster than mesa releases.

@librecomputer
After libteflon.so was built, while I was testing MobileNetV1, I’ve been suffering from these errors:

MESA: error: get_param:40: get-param (1f) failed! -22 (Invalid argument)
MESA: error: get_param:40: get-param (20) failed! -22 (Invalid argument)
MESA: error: get_param:40: get-param (21) failed! -22 (Invalid argument)
MESA: error: get_param:40: get-param (22) failed! -22 (Invalid argument)
MESA: error: get_param:40: get-param (23) failed! -22 (Invalid argument)

Tomeu suspected that the errors are from etnaviv kernel driver without his patches.

Is GitHub - libre-computer-project/libretech-linux: Mainline Linux Fork for Libre Computer your current linux kernel tree? Then your entaviv kernel driver sources are not patched. The patches should be applied to these ones:

  • drivers/gpu/drm/etnaviv/etnaviv_gpu.c
  • drivers/gpu/drm/etnaviv/etnaviv_gpu.h
  • drivers/gpu/drm/etnaviv/etnaviv_hwdb.c
  • include/uapi/drm/etnaviv_drm.h
1 Like

Hi, I just downloaded the Debian 12, headless, performed steps below and after enable npu the tty locked, no way to proceed.

Hi!

sorry for incomplete previous message.

I perfomed action below on fresh headless debian 12 and it just locked after attempt to enable NPU. Is this because the firmware was not updated right. When I updated the firmware it seems my board is not true Alta but Alta-prepod?

git clone GitHub - libre-computer-project/libretech-wiring-tool
cd libretech-wiring-tool
make
sudo ./ldto enable npu

Hi there. I clarified that my Alta is not a pre-pod version but normal 1.0 I believe.
So that is not problem that my screen is frozen after enabling the NPU. Perhaps this is only HDMI blocked, which perhaps for now is fine for me. As soon I connect something to serial port, which should keep communicating even if my HDMI is frozen, right?

Please instruct whether I am right since I am very determined to become active contributor into NPU activities.
Regards,
Nik.

Hi.

I didn’t have such problem while enabling npu, so I might not be any help to you, but if you could connect to Alta anyhow, have you disabled npu and checked if it is disabled by following commands?

sudo ldto disable npu
ldto active

Hi !Thanks for your response! I do not know how to connect to the serial port and if debian 12 uses it for console.

Yes, maybe it would be a good idea try to type the text you suggested, in “blind” mode while the display is not working. Thanks. Also, could you please advise me what OS do you use so you do not have issues with this? I tried many times, even changed images, but all the same result.

I’m using Debian 12 like you.

Did you flash your OS with a bit accurate flashing tool? At first I had login problem with BalenaEtcher and transfered to Win32DiskImager.

I thought you meant ethernet connection when you said serial connection. Hadn’t you enabled sshd before enabling npu?

Hi Charlie, I did not have login problem but I should try that bit accurate approach, I guess. I tried to configure the WIFI as per description on this website but did not have success, so I just used ethernet to get access to internet, since the board works straight without any ethernet configuration. What is SSHD?, I did not do any of that.

I connect to Alta with ssh. So I needed to enable sshd, the ssh server. If you can connect other way, you don’t need sshd. Hope you can use npu as you like to.

Howdy ! Just received my Alta and the board is a beautiful thing, some of the best looking boards I’ve ever seen.
I’m trying to run this guide but it seems that perhaps mesa teflon branch has been changed - there are no tests src/gallium/frontends/teflon/tests, certainly not test_conv2d.py nor classification.py . Is there perhaps another branch this was meant for ?

Anton, I had success using the teflon-tp branch as it includes all of the test files. I don’t believe this branch is being actively updated at this point but it’s a good starting point to verify operation.

The MobileNetV1 model this guide is written for is a classification model. Will the Teflon delegate also work with an Object Detection model like MobileNetV2? Does the model need to be compiled specifically for running with the delegate?