Netmodule Routers with AI Features

Goal

This wiki shows how to enable an AI Core DX-M1 chip in the router and use it within an LXC container. It also explains how to set up additional utilities within the container.

The background to this project

Enable the router to run its own AI modules locally, directly on the router, without having to use a hyperscaler. Your own data can be used to train the AI modules because it is not shared with third parties. The entire value chain remains under your control and can be flexibly developed further. Applications include intelligent energy management systems, dynamic traffic control systems, and production management. The AI modules can be trained and fine-tuned for their core tasks to achieve optimal results.


Modules in the router


Prerequisites

  • NetModule NB2800/NB2810 Wireless Router with wireless connection
  • NetModule Software with AI Core DX-M1 Chip Support for NB2800 NB2800 Password for the download: “ai-chip”
  • NetModule Software with AI Core DX-M1 Chip Support for NB2810 NB2810 Password for the download: “ai-chip”
  • Not available for legacy products NB1600, NB2700, NB3700, NB3710

The wiki was tested with router software nrsw-image-2800-0.0.0.0.img and the LXC container with debina 13 armhf (trixie)


1. Installing the Module into the Router Hardware

An adapter is required for the Deepx DX-M1 AI chip to be used with the router. The PCI Express interfaces are implemented as Mini PCIe on the router board. The DX-M1 chip requires a Mini PCIe to M.2 M-key adapter.

The NB2800's circuit board features a DC/DC converter that supplies 3.3 volts to the two Mini-PCIe slots. The maximum output current is 6 amps. A maximum of 12 watts is available for the Mini-PCIe modules. The DX-M1 chip has a maximum power consumption of less than 5 watts.

The module can be installed in slot 1 or 2 on the NB2800.

The DX-M1 chip was inserted into the first slot

To ensure communication between the chip and the router, the module must be configured as Wi-Fi in the BD.

You can check whether the module is present via the router's console.

The module was detected in the router: “02:00.0” (PCI address of the device: Bus 02, Device 00, Function 0).

The device class of the module was correctly identified as “Class 1200” (processing accelerator), i.e., an NPU or AI accelerator

The last entry is generated generically because the name of the hardware is not stored in the lspci/pci.ids database.


2. Setting Up the Router Software on the Router

The first step is to download the software that includes driver support for the DX-M1 chip. To do this, click the link NB2800 or NB2810 to download the appropriate software for the two respective routers.

The password for access is “ai-chip”

Save the downloaded router software to the “/tmp” subdirectory on the router, and then connect to the router via the console using SSH or the Windows program PuTTY.

You can install this image on the router using the command swupdate -fr nrsw-image-2800-0.0.0.0.img.

Next, set up a mobile (WWAN) connection on the router

In this example, I've set it up for a Telekom SIM card.

You can use a ping test to check whether the router can establish an Internet connection via the WWAN connection.


3. Set up the LXC Contianer

Activate the LXC container on the router

In the second step, the image of the LXC container in this case, a Debina 13 (trixie).

The easiest way to do this is to install the whole thing over the Internet. However, the router requires a mobile connection to the Internet.

From a Jenkins server you get the current image for the container

* Jenkins Server Page image-debian / Link

Here you can download a Debian image for various systems and versions.

The armhf tab is important here, and trixie

The image is the “rootfs.tar.xz” which is required. With a right click you can copy the link.

It would be structured like this:

https://jenkins.linuxcontainers.org/view/Images/job/image-debian/architecture=armhf,release=trixie,variant=default/4118/artifact/rootfs.tar.xz

When the “Apply” button is pressed, Debian will be installed.

Set up the LXC container further. A network interface is enabled here.

The container has now also been assigned an IP address.

Always assign a fixed IP address for the LXC container via the DHCP server. The MAC address of the LXC container is 00:FF:AA:00:44:00.

Log in to the LXC container and test whether it can access the Internet.

——

The container is installed and set up. Now you can set up further tools on the container.


Adjust the LXC config so that the USB port can be used in the container

Enable USB administration on the router

When the USB device is plugged in, it is mounted by the router and stored in the system as device part “/dev/sda1“.

In order to release the device in the container, I need to know what kind of device it is: “b” is a block device, major number “8” and minor number “1”.

With this information, we can adjust the LXC configuration so that we have access to the device from within the container.

This change is made directly in the router software. When updating the router software, this entry must be made again because it is not part of the official software.

Add these entries to the end of the config file.

~ $ vi /etc/lxc/guest0/config
                                                           
# Setting up a USB flash drive in the LXC container                                      
lxc.cgroup.devices.allow = b 8:1 rwm                                
lxc.mount.entry = /dev/sda1 /dev/sda1 none bind,optional,create=file            

Simply add these four entries to the LXC configuration file. Please ensure that you fill them in with your own parameters. Restart the router for these changes to take effect.

Now the USB device can be connected to the container and used. The “mkdir” command is used to set up an area in the file system for access.In the second step, change the permissions of the file.

Check whether the rights have been set.

—


Integrating external storage into the container system

The whole thing is integrated via a cron job, so that it is always available when the router is restarted.

Queries with which file system the external storage was formatted.

“”“”“”

First, we create a script file called vi usb_stick.sh

#!/bin/bash
mknod /dev/sda1 b 8 1
sleep 1s
mount /dev/sda1 /mnt/home/data

To test it, you can now simply run this file. Now the whole thing has to be saved as a cron job. To do this, call up the command “crontab -e” and save this line there.

root@LXCNAME:~# crontab -e
@reboot /root/usb_stick.sh

4. Set up the AI Core DX-M1 chip

The driver must be loaded into the router using the “modprobe” command. This is done by typing “done”.

~ $ vi /etc/init.d/done

# The dxrt_driver.ko driver is being loaded
modprobe dxrt_driver 2>/dev/null || sudo insmod /lib/modules/$(uname -r)/extra/rt/dxrt_driver.ko

# LXC continaer restart
/etc/init.d/virt restart

Test this after rebooting the router to see if the interface is present in the router.

In the next step, the interface must be passed to the LXC container.

~ $ vi /etc/lxc/guest0/config

# Allow Access (Device 247)
lxc.cgroup.devices.allow = c 247:0 rwm

# Mount the DXRT device node in the container
lxc.mount.entry = /dev/dxrt0 dev/dxrt0 none bind,create=file 0 0

If the “dxrt0” interface under the LXC container is set to mode “(000),” you must check the settings in lxc config again to make sure they are correct.


The next thing you'll need is the DX-RT runtime software

To do this, you'll need to clone the DX-ALL-SUITE repository using “git”.

The git tool is required for this. The DX-ALL-SUITE repository is then saved to the USB flash drive for further installation

–https://github.com/DEEPX-AI/dx-all-suite.git

export VERSION=v2.4.0
git clone -b ${VERSION} --recurse-submodules https://github.com/DEEPX-AI/dx-all-suite.git

Additional software is required for the installation

You can then proceed with the installation of the DX-RT (runtime software).

Open the file `safe_cast.h` using the `nano` tool.

nano /mnt/home/data/dx-all-suite/dx-runtime/dx_rt/lib/include/dxrt/safe_cast.h

Delete the code block

// For consistency with FromAddr, specify destination type as is (e.g., FromAddr<int*>)

. . .

}

and replace it with this code.

// For consistency with FromAddr, specify destination type as is (e.g., FromAddr<int*>)
    template <typename T_Dest, typename T_Src>
    static inline T_Dest IntegerToPointer(T_Src addr) noexcept {
        static_assert(std::is_pointer<T_Dest>::value, "Error: Destination must be a pointer type");
        static_assert(std::is_integral<T_Src>::value && std::is_unsigned<T_Src>::value,
                      "Error: Source must be an unsigned integral type");

        // On platforms where uintptr_t is narrower than T_Src (e.g. 32-bit targets
        // receiving 64-bit addresses from a protocol/driver struct), make sure no
        // address bits are silently dropped.
        assert(static_cast<T_Src>(static_cast<uintptr_t>(addr)) == addr &&
               "Error: address value does not fit in uintptr_t on this platform");

        return reinterpret_cast<T_Dest>(static_cast<uintptr_t>(addr));  // NOSONAR: S3630
    }

– and replace it with this code.

sed -i 's/uint64_t addr;/uintptr_t addr;/' \
  /mnt/home/data/dx-all-suite/dx-runtime/dx_rt/lib/buffer.cpp

cmake -S . -B build -DPython_EXECUTABLE=/usr/bin/python3 -Donnxruntime_INCLUDE_DIRS=/mnt/home/data/dx-all-suite/dx-nano /mnt/home/data/dx-all-suite/dx-runtime/dx_rt/lib/include/dxrt/safe_cast.hruntime/dx_rt/extern/onnxruntime-win-x64-1.20.1/include -Donnxruntime_LIB_DIRS=/mnt/home/data/dx-all-suite/dx-runtime/dx_rt/extern/onnxruntime-win-x64-1.20.1/lib

cmake --build build -j1

Once it has been successfully installed, you can test it.

Run the CLI command

dxrt-cli --status

——————————————


——————————————

MHz MHz MHz

Now, information from the three NPU cores on the AI chip is displayed.


5. Additional information

* Deepx DX-M1 AI-Chip Webpage DX-M1 Chip

* Deepx DX-M1 Documentation DX-M1 Documentation

* AI-Models for the Chip AI-Models

* Overview DX-M1 Chip Overview

AI Agent for an Energy Management