Compare commits

...

4 Commits

Author SHA1 Message Date
Andrew Leech
4837556859
Merge b214c54c07 into daf26f9fc8 2025-11-04 15:32:56 +11:00
Ibrahim Abdelkader
daf26f9fc8
Merge pull request #2909 from kwagyeman/kwabena/fix_nn_caching_issue
Some checks failed
🔎 Check Code Formatting / formatting-check (push) Has been cancelled
🔥 Firmware Build / build-firmware (false, 0, false, DOCKER) (push) Has been cancelled
🔥 Firmware Build / build-firmware (false, 0, true, MPS2_AN500) (push) Has been cancelled
🔥 Firmware Build / build-firmware (false, 0, true, MPS3_AN547) (push) Has been cancelled
🔥 Firmware Build / build-firmware (false, 1, false, OPENMV_N6) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, ARDUINO_GIGA) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, ARDUINO_NANO_33_BLE_SENSE) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, ARDUINO_NANO_RP2040_CONNECT) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, ARDUINO_NICLA_VISION) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, ARDUINO_PORTENTA_H7) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV2) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV3) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV4) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV4P) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMVPT) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV_AE3) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV_N6) (push) Has been cancelled
🔥 Firmware Build / build-firmware (true, 0, false, OPENMV_RT1060) (push) Has been cancelled
🔥 Firmware Build / code-size-report (push) Has been cancelled
🔥 Firmware Build / stable-release (push) Has been cancelled
🔥 Firmware Build / development-release (push) Has been cancelled
lib/stai: Fix STAI NPU memory allocation.
2025-11-02 17:37:09 +02:00
Kwabena W. Agyeman
30da5a062f lib/stai: Fix STAI NPU memory allocation.
The ST Neural ART code generator marks the HyperRAM mpool as cacheable
(CACHEABLE_ON), which causes the NPU stream engines to issue cacheable
accesses. However, the N6 memory subsystem does not support cacheable
accesses to internal memories, only external ones. Because of this,
relocating the HyperRAM region to internal memory results in invalid
access behavior: only base addresses are updated during relocation, not
the cacheable attributes.

In short, buffers generated for HyperRAM must remain in external memory.
Marking HyperRAM as non-cacheable is a possible workaround, but may
reduce performance if buffers are placed in AXI RAM instead.

Forcing the ext_ram_sz allocation to 1MB ensures that the ext_ram_sz
is allocated in SDRAM.
2025-11-01 18:28:22 -07:00
Andrew Leech
b214c54c07 docker: Add git worktree support. 2025-10-16 13:55:00 +11:00
4 changed files with 49 additions and 9 deletions

View File

@ -29,10 +29,8 @@ ENV MAKE_URL="https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz"
RUN wget --no-check-certificate --user-agent="Mozilla/5.0" -O - ${MAKE_URL} | tar --strip-components=1 -xz -C /workspace/make
RUN cd /workspace/make && ./configure && make -j$(nproc)
# Set up directories
WORKDIR /workspace
COPY . .
# Permissive git permissions inside container
ENV HOME=/tmp
RUN git config --global --add safe.directory '*'
ENV PATH="/workspace/gcc/bin:/workspace/llvm/bin:/workspace/cmake/bin:/workspace/make:$PATH"

View File

@ -3,6 +3,27 @@ DOCKER_TAG = latest
CONTAINER_NAME = firmware-container
DOCKERFILE_PATH = Dockerfile
# Detect repository structure
REPO_ROOT := $(shell git rev-parse --show-toplevel)
GIT_DIR := $(shell realpath $$(git rev-parse --git-dir))
GIT_COMMON_DIR := $(shell realpath $$(git rev-parse --git-common-dir))
# Detect worktree: git-dir != git-common-dir
IS_WORKTREE := $(shell [ "$(GIT_DIR)" != "$(GIT_COMMON_DIR)" ] && echo "yes" || echo "no")
# Working directory inside container
WORKDIR = $(REPO_ROOT)
# Volume mounts: always mount repo at actual path
ifeq ($(IS_WORKTREE),yes)
# For worktrees, also mount the main repo (for .git references)
MAIN_REPO_PATH := $(shell dirname $(GIT_COMMON_DIR))
VOLUME_MOUNTS = -v $(MAIN_REPO_PATH)/.git:$(MAIN_REPO_PATH)/.git \
-v $(REPO_ROOT):$(WORKDIR)
else
VOLUME_MOUNTS = -v $(REPO_ROOT):$(WORKDIR)
endif
# Build the Docker image
build-image:
docker build \
@ -15,7 +36,8 @@ build-firmware: build-image
-e TARGET=$(TARGET) \
-e HOST_UID=$(shell id -u) \
-e HOST_GID=$(shell id -g) \
-v $(PWD)/build:/workspace/build \
-w $(WORKDIR) \
$(VOLUME_MOUNTS) \
--name $(CONTAINER_NAME) \
$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) docker/build.sh
@ -23,7 +45,18 @@ build-firmware: build-image
shell:
docker run --rm -it \
-e shell="true" \
-v $(PWD)/build:/workspace/build \
-w $(WORKDIR) \
$(VOLUME_MOUNTS) \
$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) bash
# Debug target to show detected paths
debug-paths:
@echo "IS_WORKTREE: $(IS_WORKTREE)"
@echo "REPO_ROOT: $(REPO_ROOT)"
@echo "GIT_DIR: $(GIT_DIR)"
@echo "GIT_COMMON_DIR: $(GIT_COMMON_DIR)"
@echo "MAIN_REPO_PATH: $(MAIN_REPO_PATH)"
@echo "WORKDIR: $(WORKDIR)"
@echo "VOLUME_MOUNTS: $(VOLUME_MOUNTS)"
.DEFAULT_GOAL := build-firmware

View File

@ -1,7 +1,8 @@
#!/bin/bash
set -e -x
BUILD_DIR=/workspace/build/${TARGET}
OPENMV="$(pwd)"
BUILD_DIR=${OPENMV}/build/${TARGET}
# Update submodules.
git submodule update --init --depth=1
@ -13,4 +14,4 @@ make -j$(nproc) -C lib/micropython/mpy-cross
make -j$(nproc) BUILD=${BUILD_DIR} TARGET=${TARGET} LLVM_PATH=/workspace/llvm/bin
# Fix permissions.
chown -R ${HOST_UID:-1000}:${HOST_GID:-1000} /workspace/build
chown -R ${HOST_UID:-1000}:${HOST_GID:-1000} ${OPENMV}/build

View File

@ -49,6 +49,10 @@
#include "ll_aton_caches_interface.h"
#include "ll_aton_reloc_network.h"
// Due to limitations with the STM32N6 NPU design, the ext_ram_sz memory pool
// must be in external SDRAM and not in internal SRAM. Forcing a minimum of a
// 1MB allocation ensures that the ext_ram_sz buffer ends up in SDRAM.
#define AI_MIN_EXT_RAM_SZ (1048576)
#define AI_RELOC_ALIGNMENT (32)
typedef struct ml_backend_state {
@ -132,6 +136,10 @@ int ml_backend_init_model(py_ml_model_obj_t *model) {
return -1;
}
if (rt.ext_ram_sz) {
rt.ext_ram_sz = OMV_MAX(rt.ext_ram_sz, AI_MIN_EXT_RAM_SZ);
}
// Allocate executable memory.
state->exec_ram_size = OMV_ALIGN_TO(rt.rt_ram_xip, AI_RELOC_ALIGNMENT);
state->exec_ram_addr = m_new(uint8_t, state->exec_ram_size + AI_RELOC_ALIGNMENT);