ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_npu_blob.h File Reference

.npub linkable-blob container for a Vela-compiled Ethos-U55 model More...

#include <stdint.h>
Include dependency graph for ra8_npu_blob.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ra8_npu_blob_ident_t : uint32_t {
  k_ra8_npu_blob_magic = 0x3155504EU ,
  k_ra8_npu_blob_version = 1U
}
 Container magic marker and format version. More...
enum  ra8_npu_blob_word_t : uint32_t {
  k_ra8_npu_blob_word_magic = 0U ,
  k_ra8_npu_blob_word_version = 1U ,
  k_ra8_npu_blob_word_total_bytes = 2U ,
  k_ra8_npu_blob_word_region_count = 3U ,
  k_ra8_npu_blob_word_cmd_offset = 4U ,
  k_ra8_npu_blob_word_cmd_bytes = 5U ,
  k_ra8_npu_blob_word_accel = 6U ,
  k_ra8_npu_blob_word_checksum = 7U ,
  k_ra8_npu_blob_header_words = 8U
}
 Word indices of the fixed .npub header (little-endian 32-bit words). More...
enum  ra8_npu_blob_rdesc_t : uint32_t {
  k_ra8_npu_blob_rdesc_role = 0U ,
  k_ra8_npu_blob_rdesc_flags = 1U ,
  k_ra8_npu_blob_rdesc_size = 2U ,
  k_ra8_npu_blob_rdesc_data_offset = 3U ,
  k_ra8_npu_blob_region_words = 4U
}
 Word indices of one region descriptor in the region table. More...
enum  ra8_npu_blob_size_t : uint32_t {
  k_ra8_npu_blob_header_bytes = 32U ,
  k_ra8_npu_blob_region_desc_bytes = 16U ,
  k_ra8_npu_blob_word_bytes = 4U ,
  k_ra8_npu_blob_arena_align = 16U
}
 Fixed byte sizes derived from the word counts. More...
enum  ra8_npu_blob_role_t : uint32_t {
  k_ra8_npu_blob_role_weights = 0U ,
  k_ra8_npu_blob_role_scratch = 1U ,
  k_ra8_npu_blob_role_input = 2U ,
  k_ra8_npu_blob_role_output = 3U ,
  k_ra8_npu_blob_role_other = 4U
}
 Role a region plays in the model's tensor arena layout. More...
enum  ra8_npu_blob_rflag_t : uint32_t { k_ra8_npu_blob_rflag_baked = 0x1U }
 Region descriptor flag bits. More...
enum  ra8_npu_blob_accel_t : uint32_t { k_ra8_npu_blob_accel_ethos_u55_256 = 256U }
 Vela accelerator configuration recorded in the header (informational). More...
enum  ra8_npu_blob_fnv_t : uint32_t {
  k_ra8_npu_blob_fnv_offset = 0x811C9DC5U ,
  k_ra8_npu_blob_fnv_prime = 0x01000193U
}
 FNV-1a 32-bit constants for the payload checksum. More...

Functions

static uint32_t ra8_npu_blob_read_word (const uint8_t *buf, uint32_t byte_off)
 Read one little-endian 32-bit word from a .npub byte buffer.

Detailed Description

.npub linkable-blob container for a Vela-compiled Ethos-U55 model

Defines the small, first-party, little-endian container the OFFLINE Vela build step (tools/vela/src/vela_gen.py) emits and the ON-TARGET loader (ra8_npu_loader.c) consumes. A bare-metal target does NOT parse a TFLite flatbuffer at run time; instead the host build step distills a Vela _vela.tflite (the ethos-u custom operator's command stream plus the tensor region layout) into this lean .npub blob, and the loader maps that blob straight into an ra8_npu_job_t for ra8_npu_submit().

Layout (all fields little-endian uint32_t)

+---------------------------------------------------------------+
| [0] magic == ::k_ra8_npu_blob_magic ("NPU1") |
| [1] version == ::k_ra8_npu_blob_version |
| [2] total_bytes (whole blob length) |
| [3] region_count (number of region descriptors) |
| [4] cmd_offset (byte offset to the command stream) |
| [5] cmd_bytes (command-stream length, > 0) |
| [6] accel (::ra8_npu_blob_accel_t, informational) |
| [7] checksum (FNV-1a over every payload byte) |
+---------------------------------------------------------------+
| region table (region_count * ::k_ra8_npu_blob_region_words) |
| each: [role][flags][size][data_offset] |
+---------------------------------------------------------------+
| command stream (cmd_bytes bytes at cmd_offset) |
+---------------------------------------------------------------+
| baked region data blocks (weights / const inputs) |
+---------------------------------------------------------------+
@ k_ra8_npu_blob_header_words
Header field / word count.
@ k_ra8_npu_blob_magic
First word: "NPU1" little-endian.
@ k_ra8_npu_blob_version
Container format version.
ra8_npu_blob_accel_t
Vela accelerator configuration recorded in the header (informational).
@ k_ra8_npu_blob_region_words
Descriptor field / word count.

A region descriptor is either BAKED (its bytes live in the blob at data_offset, e.g. the read-only weight arena) or RUNTIME (allocated by the caller in NPU-visible SRAM, e.g. scratch / output activations). The loader turns BAKED regions into a pointer into the blob and RUNTIME regions into a pointer inside a caller-provided arena; see ra8_npu_loader.h.

Not guarded by RA8_HAS_NPU

This header defines a pure DATA FORMAT (constants + one endianness-safe accessor) and touches no NPU register, so – exactly like ra8_npu_fake_cmd.h – it is deliberately NOT gated behind RA8_HAS_NPU: the host-side generator's companion tests and the ra8_emulator model must be able to include it on a device that is not the RA8P1. The RA8P1-only piece is the loader, which turns a blob into an ra8_npu_job_t.

See also
NPU1 – The .npub Ethos-U55 Model Container – the full NPU1 wire-format specification (rationale, algorithms, worked example, failure modes).
Since
0.1.0

Definition in file ra8_npu_blob.h.

Enumeration Type Documentation

◆ ra8_npu_blob_accel_t

enum ra8_npu_blob_accel_t : uint32_t

Vela accelerator configuration recorded in the header (informational).

The value is the Ethos-U55 MAC-per-cycle SKU Vela targeted. The RA8P1 integrates the 256-MAC/cycle SKU (ethos-u55-256, see ra8_npu_regs.h). The loader does not validate it; it is carried so a consumer can confirm the blob was compiled for the right accelerator.

Invariant
Every value fits a uint32_t.
Since
0.1.0
Enumerator
k_ra8_npu_blob_accel_ethos_u55_256 

ethos-u55-256 (RA8P1 SKU).

Definition at line 208 of file ra8_npu_blob.h.

◆ ra8_npu_blob_fnv_t

enum ra8_npu_blob_fnv_t : uint32_t

FNV-1a 32-bit constants for the payload checksum.

The offline generator and the on-target loader fold every payload byte (offset >= k_ra8_npu_blob_header_bytes) with these constants and compare the result against the header checksum word, so a corrupted blob is rejected rather than executed. FNV-1a is used elsewhere in the NPU stand-in (ra8_emulator, npu_smoke) for the same deterministic-digest reason.

Invariant
Both values are the published FNV-1a 32-bit basis / prime.
Since
0.1.0
Enumerator
k_ra8_npu_blob_fnv_offset 

FNV-1a 32-bit offset basis.

k_ra8_npu_blob_fnv_prime 

FNV-1a 32-bit prime.

Definition at line 226 of file ra8_npu_blob.h.

◆ ra8_npu_blob_ident_t

enum ra8_npu_blob_ident_t : uint32_t

Container magic marker and format version.

k_ra8_npu_blob_magic is the first word of every .npub blob; its four little-endian bytes spell the ASCII tag "NPU1" (0x4E 0x50 0x55 0x31). A loader rejects any buffer whose first word differs, so a truncated or foreign buffer is refused rather than mis-parsed. k_ra8_npu_blob_version is bumped on any incompatible layout change.

Invariant
k_ra8_npu_blob_magic little-endian byte order is 'N','P','U','1'.
See also
ra8_npu_blob_word_t
Since
0.1.0
Enumerator
k_ra8_npu_blob_magic 

First word: "NPU1" little-endian.

k_ra8_npu_blob_version 

Container format version.

Definition at line 83 of file ra8_npu_blob.h.

◆ ra8_npu_blob_rdesc_t

enum ra8_npu_blob_rdesc_t : uint32_t

Word indices of one region descriptor in the region table.

Each descriptor is k_ra8_npu_blob_region_words little-endian words: role (ra8_npu_blob_role_t), flags (ra8_npu_blob_rflag_t), size in bytes, and data_offset – the byte offset of the region's baked bytes when k_ra8_npu_blob_rflag_baked is set, else unused.

Invariant
k_ra8_npu_blob_region_words equals the descriptor field count.
See also
ra8_npu_blob_role_t
Since
0.1.0
Enumerator
k_ra8_npu_blob_rdesc_role 

region role (ra8_npu_blob_role_t).

k_ra8_npu_blob_rdesc_flags 

region flags (ra8_npu_blob_rflag_t).

k_ra8_npu_blob_rdesc_size 

region size in bytes.

k_ra8_npu_blob_rdesc_data_offset 

baked-data byte offset (if baked).

k_ra8_npu_blob_region_words 

Descriptor field / word count.

Definition at line 128 of file ra8_npu_blob.h.

◆ ra8_npu_blob_rflag_t

enum ra8_npu_blob_rflag_t : uint32_t

Region descriptor flag bits.

k_ra8_npu_blob_rflag_baked marks a region whose bytes are present IN the blob at the descriptor's data_offset (e.g. the weight arena); the loader points the region base at those bytes. A region without the flag is RUNTIME: the loader carves it out of the caller-provided arena.

Invariant
k_ra8_npu_blob_rflag_baked is a single set bit.
See also
ra8_npu_blob_rdesc_t
Since
0.1.0
Enumerator
k_ra8_npu_blob_rflag_baked 

Region bytes are baked into the blob.

Definition at line 192 of file ra8_npu_blob.h.

◆ ra8_npu_blob_role_t

enum ra8_npu_blob_role_t : uint32_t

Role a region plays in the model's tensor arena layout.

Vela assigns each BASEPn region a role: the read-only weight/bias arena, the scratch arena, and the input / output activation buffers. The loader does not act on the role beyond reporting it; the command stream references regions by their BASEPn index (their order in the descriptor table), not by this label.

Invariant
Every value fits a uint32_t.
See also
ra8_npu_blob_rflag_t
Since
0.1.0
Enumerator
k_ra8_npu_blob_role_weights 

Read-only weight/bias arena (baked).

k_ra8_npu_blob_role_scratch 

Scratch / working arena (runtime).

k_ra8_npu_blob_role_input 

Input activation tensor.

k_ra8_npu_blob_role_output 

Output activation tensor.

k_ra8_npu_blob_role_other 

Any other region.

Definition at line 171 of file ra8_npu_blob.h.

◆ ra8_npu_blob_size_t

enum ra8_npu_blob_size_t : uint32_t

Fixed byte sizes derived from the word counts.

k_ra8_npu_blob_header_bytes is the header length; the payload the checksum covers begins here. k_ra8_npu_blob_region_desc_bytes is one descriptor's length. k_ra8_npu_blob_arena_align is the alignment the loader applies to each runtime region base within the caller arena (Ethos-U55 tensor arenas are 16-byte aligned).

Invariant
k_ra8_npu_blob_header_bytes == 4 * k_ra8_npu_blob_header_words.
See also
ra8_npu_blob_word_t
Since
0.1.0
Enumerator
k_ra8_npu_blob_header_bytes 

Header length (8 words * 4).

k_ra8_npu_blob_region_desc_bytes 

One region descriptor (4 words * 4).

k_ra8_npu_blob_word_bytes 

Bytes in one little-endian word.

k_ra8_npu_blob_arena_align 

Runtime-region alignment (bytes).

Definition at line 150 of file ra8_npu_blob.h.

◆ ra8_npu_blob_word_t

enum ra8_npu_blob_word_t : uint32_t

Word indices of the fixed .npub header (little-endian 32-bit words).

The header is k_ra8_npu_blob_header_words words long. total_bytes is the whole blob length; region_count counts the region descriptors that follow the header; cmd_offset / cmd_bytes locate the Vela command stream; accel records the Vela accelerator config (informational); checksum is an FNV-1a digest over every payload byte (everything at or beyond k_ra8_npu_blob_header_bytes).

Invariant
k_ra8_npu_blob_header_words equals the number of header fields.
See also
ra8_npu_blob_size_t
Since
0.1.0
Enumerator
k_ra8_npu_blob_word_magic 

magic == k_ra8_npu_blob_magic.

k_ra8_npu_blob_word_version 

format version.

k_ra8_npu_blob_word_total_bytes 

whole blob length in bytes.

k_ra8_npu_blob_word_region_count 

number of region descriptors.

k_ra8_npu_blob_word_cmd_offset 

byte offset to the command stream.

k_ra8_npu_blob_word_cmd_bytes 

command-stream length in bytes.

k_ra8_npu_blob_word_accel 

accelerator config (informational).

k_ra8_npu_blob_word_checksum 

FNV-1a digest over the payload.

k_ra8_npu_blob_header_words 

Header field / word count.

Definition at line 103 of file ra8_npu_blob.h.

Function Documentation

◆ ra8_npu_blob_read_word()

uint32_t ra8_npu_blob_read_word ( const uint8_t * buf,
uint32_t byte_off )
inlinestatic

Read one little-endian 32-bit word from a .npub byte buffer.

Assembles buf[byte_off .. byte_off+3] as a little-endian uint32_t one byte at a time, so the read is both endianness-independent and free of any unaligned-access assumption (the byte buffer may sit at an arbitrary address). This performs a plain memory read of a caller buffer – no hardware register is touched – so it carries no HUM citation.

Parameters
[in]bufBase of the .npub byte buffer (non-NULL, caller-checked).
[in]byte_offByte offset of the word to read; byte_off + 4 must not exceed the buffer length (caller-checked).
Returns
The little-endian 32-bit word at byte_off.
Return values
valueThe assembled word; always defined for an in-bounds offset.
Precondition
buf is non-NULL.
byte_off + 4 is within the buffer length.
Postcondition
No input is modified; the function is pure.
The returned value equals the four bytes read, low byte first.
Note
Re-entrant and thread-safe (reads only, no shared state).
See also
ra8_npu_blob_word_t
Since
0.1.0

Definition at line 257 of file ra8_npu_blob.h.

References k_ra8_npu_blob_word_bytes.

Referenced by internal_npu_vela_cmd_word().