Use Virtuale, upload only the assignment file named as follows: LAB#_APAI_yourname.pdf
Assignment DEADLINE: Sunday 22/11/2026 (end of day, 23:59)
You are encouraged to work on your own laptop using the provided devcontainer (Option A). If that is not possible, you can use the virtual machine available on the lab machines (Option B).
Requirements: Docker, VSCode and the VSCode Dev Containers extension.
- Open a terminal and clone this repository:
git clone https://github.com/EEESlab/APAI26-LAB06-On-Device-Learning
cd APAI26-LAB06-On-Device-Learning/
- Open VSCode with
code . - On VSCode, click on 'Reopen in container' (the first time, the container image is downloaded, which may take a while).
- Open a new terminal in VSCode: the PULP SDK is configured automatically.
- Now you're ready to start!
On Windows, install WSL 2 first, and choose the Windows version of Docker Desktop (even if you work with WSL). If VSCode reports that Docker cannot be found, enable the WSL integration in Docker Desktop (Settings -> Resources -> WSL integration), then Apply & Restart.
The Ubuntu-based virtual machine already contains the PULP SDK and VSCode (used only to edit the code and open terminals), so no Docker container is needed.
- From a browser outside the virtual machine, download the lab zip file from Virtuale (the only website reachable from the lab machines) and extract it (right-click -> Extract).
- Go to
C:/VM_APAIand double-clickPULP-box.ova. When VirtualBox opens, click on "Finish"/"Fine". - Once the virtual machine is imported, start it with "Start"/"Avvia".
- Log in with username
pulp-boxand passwordpulp. - From the VirtualBox top bar, open Machine -> File Manager (left panel: files of the PC, right panel: files of the VM). Enter the login credentials at the bottom of the right panel.
- Drag and drop the extracted lab folder into a subdirectory of the VM home directory (you need write rights there).
- Inside the VM, open a terminal and go to the lab folder with
cd. - [DO NOT FORGET] Every time you open a new terminal run:
source setup_pulp_sdk.sh
- Now you're ready to start!
Run:
make clean get_golden all run
get_golden runs the Golden Model (utils/GM.py, Python/NumPy), which generates the reference data used by the C code: init-defines.h (layer sizes and hyperparameters) and io_data.h (initial weights, input, label and expected output after training). Always include it in the command: the files do not exist before the first run, and they must be regenerated whenever you change GM.py.
Useful notes:
- The training hyperparameters (
learning_rate,epochs) are set at the top of utils/GM.py. Leavebatch_size = 1. - To print the loss and the output gradient (Task 2), uncomment the line
APP_CFLAGS += -DDEBUG_LOSSin the Makefile. Comment it again afterwards, otherwise the training is profiled together with theprintf()s. - The code sections to complete or (un)comment are enclosed between
EXERCISE NandEND OF EXERCISE Ncomments, whereNis the number of the task in the assignment (1 to 5). A task can have several sections, so search the whole project (Ctrl+Shift+Fin VSCode):
| Task | Where |
|---|---|
| 1 - Forward step | net.c: net_step() |
| 2 - Loss function | lib/sources/pulp_losses_fp32.c: pulp_MSELoss() |
| 3 - Backward step | net.c: backward(), net_step(); lib/sources/pulp_linear_fp32.c: weight and input gradients |
| 4 - Weight update | net.c: update_weights(), net_step() |
| 5 - Training | net.c: net_step() |
- net.c also provides helper functions to print the data:
print_input(),print_label(),print_output(),print_gradients()andprint_weights(). Never profile code that containsprintf()calls. - The training primitives come from PULP-TrainLib, included in lib.
You will train a small DNN on a PULP cluster, on a single sample (input and label) generated by the Golden Model:
- Conv2D layer (3x8x8 input, 8 filters 3x3, 8x6x6 output)
- ReLU activation
- Fully-Connected layer (288 inputs, 10 outputs)
Step by step, you will run the forward pass, complete the MSE loss and its gradient, the backward pass, and the weight update, and finally profile a full training loop with the performance counters of stats.h.