feat(v4): Phase 7 Task 3 -- the inference engine and Loop #7 in each node's heartbeat cycle (#189)

v4/system/inference.c: v3's inference_engine.c and its Q48.16 arithmetic ported to the bit, no C library --
the variance, the window width (Levene), the decay slope (log-linear regression), the run with its 5%
early exit. v4/tests/test_inference.c links v3's own and compares them: POST's fixed cases, 20000 random
multiply/log pairs, 400 random trajectories (make -C v4 inference; in make -C v4 test). In each node's
cycle every 1000 ticks (HEARTBEAT_INFERENCE_FREQUENCY), once the window is warm: the trajectory from the
window's words' heat, the width and slope applied unless it exits early, then Loop #7 -- the heartrate
slower when stable, faster when not, within 1/4..4x; Hera's re-arms the kernel's heartbeat
(heartbeat_set_adaptive_period_ns), as v3's Hera. L8 reads its outcome. Test first: test_mesh_boot.c 72
checks, 80 on. amd64 PASS, 163 s. Not pushed (held to the end of Phase 7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-13 23:59:18 +00:00
parent d09eee9a08
commit 6d954ac279
13 changed files with 434 additions and 14 deletions
+15 -1
View File
@@ -38,6 +38,7 @@
#include "v4/blocks.h"
#include "v4/fabric.h"
#include "v4/manage.h"
#include "v4/inference.h"
#define V4_MESH_HERA 10 /* Hera's number, as the host mesh numbers her */
#define V4_MESH_CONSOLE 1 /* the console's number as a sender, and her port to it */
@@ -111,6 +112,13 @@ typedef struct {
#define HEARTBEAT_CHECK_FREQUENCY 256
#endif
#define V4_MESH_CHECK_FREQUENCY ((uint32_t)HEARTBEAT_CHECK_FREQUENCY)
#ifndef HEARTBEAT_INFERENCE_FREQUENCY
#define HEARTBEAT_INFERENCE_FREQUENCY 1000 /* Kconfig.heartbeat, as v3's */
#endif
#ifndef HEARTBEAT_TICK_NS
#define HEARTBEAT_TICK_NS 10000ULL
#endif
#define V4_MESH_INFERENCE_EVERY ((uint64_t)HEARTBEAT_INFERENCE_FREQUENCY)
/* L8, the Jacquard selector (v3's ssm_jacquard.c and compudynamics.c, #188: 64 cards, L7 always on): a card's
* gates are ((card & 0x3F) << 1) | L7, in v3's SSM_CFG_* bits. Applied as card_bits() -- not as v3's
@@ -164,9 +172,13 @@ typedef struct {
/* L8 and the gates it sets that the other loops read: l1_cache .. l4_pipelining above, and these */
uint8_t l5_window_inference, l6_decay_inference, l7_adaptive_heartrate;
v4_mesh_l8 l8;
/* inference (v3's last_inference_outputs): did it run at the last tick, and exit early */
/* inference (Loops #5 and #6, v4/inference.h), every V4_MESH_INFERENCE_EVERY ticks: its outputs (v3's
* last_inference_outputs), the tick of its last full run, its counts; and Loop #7, the heartrate it sets */
v4_inference_out inference;
uint64_t last_inference_tick;
uint8_t inference_early_exited;
uint64_t inference_runs, inference_early_exits;
uint64_t tick_target_ns; /* v3's tick_target_ns: HEARTBEAT_TICK_NS, a quarter to four times it */
} v4_mesh_physics;
typedef struct v4_mesh v4_mesh;
@@ -203,6 +215,8 @@ struct v4_mesh {
v4_mesh_account *accounts;
unsigned char *is_word;
v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */
/* Loop #7 on Hera: the kernel's heartbeat period, re-armed (v3: heartbeat_set_adaptive_period_ns; may be 0) */
void (*heartrate)(void *self, uint64_t kernel_period_ns);
/* memory for a word's transition counters, zeroed, and given back (pipelining; may be 0: none recorded) */
void *(*alloc)(void *self, unsigned long bytes);
void (*release)(void *self, void *p);