Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

APAI-LAB06: On-Device Learning

Material

Assignment: here Slides: here

How to deliver the assignment:

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)


Quickstart

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).

Option A: Your own laptop (devcontainer, recommended)

Requirements: Docker, VSCode and the VSCode Dev Containers extension.

  1. Open a terminal and clone this repository:
git clone https://github.com/EEESlab/APAI26-LAB06-On-Device-Learning
cd APAI26-LAB06-On-Device-Learning/
  1. Open VSCode with code .
  2. On VSCode, click on 'Reopen in container' (the first time, the container image is downloaded, which may take a while).
  3. Open a new terminal in VSCode: the PULP SDK is configured automatically.
  4. 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.

Option B: Lab machines (virtual machine)

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.

  1. 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).
  2. Go to C:/VM_APAI and double-click PULP-box.ova. When VirtualBox opens, click on "Finish"/"Fine".
  3. Once the virtual machine is imported, start it with "Start"/"Avvia".
  4. Log in with username pulp-box and password pulp.
  5. 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.
  6. Drag and drop the extracted lab folder into a subdirectory of the VM home directory (you need write rights there).
  7. Inside the VM, open a terminal and go to the lab folder with cd.
  8. [DO NOT FORGET] Every time you open a new terminal run:
source setup_pulp_sdk.sh
  1. Now you're ready to start!

How to run the code

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. Leave batch_size = 1.
  • To print the loss and the output gradient (Task 2), uncomment the line APP_CFLAGS += -DDEBUG_LOSS in the Makefile. Comment it again afterwards, otherwise the training is profiled together with the printf()s.
  • The code sections to complete or (un)comment are enclosed between EXERCISE N and END OF EXERCISE N comments, where N is the number of the task in the assignment (1 to 5). A task can have several sections, so search the whole project (Ctrl+Shift+F in 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() and print_weights(). Never profile code that contains printf() calls.
  • The training primitives come from PULP-TrainLib, included in lib.

Lab overview

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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages