Skip to content

Commit d4da568

Browse files
authored
Merge pull request #112 from AdaWorldAPI/claude/teleport-session-setup-wMZfb
feat: SIMD rendering pipeline + VSA 16384 migration + rasterizer intrinsics
2 parents bccc8e3 + 1f224ba commit d4da568

15 files changed

Lines changed: 2619 additions & 50 deletions

src/hpc/arrow_bridge.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub const PLANE_BINARY_BYTES: usize = 2048;
1717
pub const BINARY_BYTES: usize = PLANE_BYTES; // 2048
1818

1919
/// Soaking accumulator length (i8 entries per plane).
20-
pub const SOAKING_DIMS: usize = 10000;
20+
pub const SOAKING_DIMS: usize = 16_384;
2121

22-
/// Sigma attention mask width in bytes (10000-bit mask).
23-
pub const SIGMA_MASK_BYTES: usize = 1250;
22+
/// Sigma attention mask width in bytes (16384-bit mask = 2048 bytes).
23+
pub const SIGMA_MASK_BYTES: usize = 2048;
2424

2525
/// Default soaking dimension count.
26-
pub const DEFAULT_SOAKING_DIM: usize = 10000;
26+
pub const DEFAULT_SOAKING_DIM: usize = 16_384;
2727

2828
/// Schema field names for the bind_nodes_v2 three-plane layout.
2929
pub mod schema {
@@ -266,7 +266,7 @@ pub struct BindNodeV2 {
266266
pub object_soaking: Option<Vec<i8>>,
267267
/// Composite XOR fingerprint: S XOR P XOR O.
268268
pub spo_binary: [u8; PLANE_BINARY_BYTES],
269-
/// 10000-bit attention mask (sigma).
269+
/// 16384-bit attention mask (sigma).
270270
pub sigma_mask: [u8; SIGMA_MASK_BYTES],
271271
/// NARS frequency (u16 fixed-point, 0..65535).
272272
pub nars_frequency: u16,
@@ -572,7 +572,7 @@ impl BindNodeV2 {
572572

573573
/// Convert a Plane accumulator (16384 i8) to a soaking vector (SOAKING_DIMS i8).
574574
///
575-
/// Truncates if the accumulator is longer than SOAKING_DIMS, pads with 0 if shorter.
575+
/// With SOAKING_DIMS = 16384, the copy is one-to-one (no truncation, no padding).
576576
fn acc_to_soaking(acc: &[i8; 16384]) -> Vec<i8> {
577577
let mut soaking = vec![0i8; SOAKING_DIMS];
578578
let copy_len = SOAKING_DIMS.min(acc.len());
@@ -878,8 +878,8 @@ mod tests {
878878
#[test]
879879
fn schema_constants() {
880880
assert_eq!(PLANE_BINARY_BYTES, 2048);
881-
assert_eq!(SOAKING_DIMS, 10000);
882-
assert_eq!(SIGMA_MASK_BYTES, 1250);
881+
assert_eq!(SOAKING_DIMS, 16_384);
882+
assert_eq!(SIGMA_MASK_BYTES, 2048);
883883
}
884884

885885
#[test]
@@ -1140,9 +1140,9 @@ mod tests {
11401140
let (mut s, mut p, mut o) = make_test_planes();
11411141
let node = BindNodeV2::new(&mut s, &mut p, &mut o, "test");
11421142
assert_eq!(node.sigma_mask.len(), SIGMA_MASK_BYTES);
1143-
assert_eq!(node.sigma_mask.len(), 1250);
1144-
// sigma_mask * 8 = 10000 bits
1145-
assert_eq!(node.sigma_mask.len() * 8, 10000);
1143+
assert_eq!(node.sigma_mask.len(), 2048);
1144+
// sigma_mask * 8 = 16384 bits
1145+
assert_eq!(node.sigma_mask.len() * 8, 16_384);
11461146
}
11471147

11481148
#[test]

src/hpc/audio/codec_map.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@
3535
/// what aspect of that codec it captures, and what it replaces.
3636
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3737
pub enum CodecSource {
38+
/// Opus / CELT.
3839
Opus,
40+
/// OpenAI Whisper.
3941
Whisper,
42+
/// MP3.
4043
Mp3,
44+
/// Ogg Vorbis.
4145
OggVorbis,
46+
/// Suno Bark.
4247
Bark,
48+
/// ElevenLabs.
4349
ElevenLabs,
4450
}
4551

@@ -66,11 +72,17 @@ pub enum AudioAspect {
6672

6773
/// Complete provenance record for one primitive.
6874
pub struct Provenance {
75+
/// Name of the primitive in this codebase.
6976
pub our_type: &'static str,
77+
/// Byte size of the primitive (0 = transform/decision, not stored).
7078
pub byte_size: usize,
79+
/// Production codec the primitive was transcoded from.
7180
pub source: CodecSource,
81+
/// Aspect of audio the primitive captures.
7282
pub aspect: AudioAspect,
83+
/// Concept in the source codec that this corresponds to.
7384
pub source_concept: &'static str,
85+
/// What this primitive replaces (in the source codec or a peer).
7486
pub what_it_replaces: &'static str,
7587
}
7688

@@ -212,6 +224,7 @@ pub const PROVENANCE: &[Provenance] = &[
212224
/// Bark tokens: ~128 bytes per frame
213225
/// Ours: 52-69 bytes per frame (complete, including phase + identity)
214226
pub const FRAME_BUDGET: usize = 52;
227+
/// Per-frame byte budget when the TTS RvqFrame (17 bytes) is also carried.
215228
pub const FRAME_BUDGET_WITH_TTS: usize = 69;
216229

217230
/// Codec comparison: bits per second at comparable quality.

src/hpc/audio/modes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ use super::bands;
2727
/// and maps to a Base17 stride for spectral character.
2828
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
2929
pub enum Mode {
30+
/// Ionian (major): W-W-H-W-W-W-H — bright, resolved.
3031
Ionian, // Major: W-W-H-W-W-W-H → bright, resolved
32+
/// Dorian: minor with natural 6th — warm, jazz.
3133
Dorian, // Minor with ♮6: warm, jazz
34+
/// Phrygian: minor with flat 2nd — dark, flamenco.
3235
Phrygian, // Minor with ♭2: dark, flamenco
36+
/// Lydian: major with sharp 4th — dreamy, floating.
3337
Lydian, // Major with ♯4: dreamy, floating
38+
/// Mixolydian: major with flat 7th — dominant, bluesy.
3439
Mixolydian, // Major with ♭7: dominant, bluesy
40+
/// Aeolian (natural minor) — sad, reflective.
3541
Aeolian, // Natural minor: sad, reflective
42+
/// Locrian (diminished) — unstable, tense.
3643
Locrian, // Diminished: unstable, tense
3744
}
3845

src/hpc/audio/phase.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub fn phase_gradient(
128128
/// Together: complete nonverbal vocal characterization in 52 bytes.
129129
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
130130
pub struct PhaseDescriptor {
131+
/// 4-byte packed descriptor (coherence, gradient, entropy, stability).
131132
pub bytes: [u8; 4],
132133
}
133134

src/hpc/audio/voice.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ pub const N_VOICE_CHANNELS: usize = 16;
3232
/// Compression: 16 bytes (vs Bark's 1024-dim semantic token embedding).
3333
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
3434
pub struct VoiceArchetype {
35+
/// 16 i8 voice-identity channels (pitch / resonance / articulation / prosody).
3536
pub channels: [i8; N_VOICE_CHANNELS],
3637
}
3738

3839
impl VoiceArchetype {
40+
/// Serialized size of a VoiceArchetype, in bytes.
3941
pub const BYTE_SIZE: usize = N_VOICE_CHANNELS;
4042

4143
/// Zero archetype (neutral voice).
@@ -177,6 +179,7 @@ impl VoiceArchetype {
177179
/// For a 256-entry codebook: 256 × 16 bytes = 4 KB.
178180
#[derive(Clone, Debug)]
179181
pub struct VoiceCodebook {
182+
/// Voice archetype prototypes; index = codebook ID.
180183
pub entries: Vec<VoiceArchetype>,
181184
}
182185

@@ -245,6 +248,7 @@ pub struct RvqFrame {
245248
}
246249

247250
impl RvqFrame {
251+
/// Serialized size of an RvqFrame, in bytes.
248252
pub const BYTE_SIZE: usize = 17;
249253

250254
/// Serialize to 17 bytes.
@@ -292,20 +296,25 @@ impl RvqFrame {
292296
/// VoiceFrame (21B) is the compressed synthesis frame.
293297
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
294298
pub struct VoiceFrame {
299+
/// Compressed RVQ codes (archetype + coarse + fine).
295300
pub rvq: RvqFrame,
301+
/// Per-frame phase dynamics descriptor.
296302
pub phase: super::phase::PhaseDescriptor,
297303
}
298304

299305
impl VoiceFrame {
306+
/// Serialized size of a VoiceFrame, in bytes (RvqFrame + 4-byte phase).
300307
pub const BYTE_SIZE: usize = RvqFrame::BYTE_SIZE + 4; // 21 bytes
301308

309+
/// Serialize this VoiceFrame to its 21-byte wire representation.
302310
pub fn to_bytes(&self) -> [u8; Self::BYTE_SIZE] {
303311
let mut bytes = [0u8; Self::BYTE_SIZE];
304312
bytes[..17].copy_from_slice(&self.rvq.to_bytes());
305313
bytes[17..21].copy_from_slice(&self.phase.bytes);
306314
bytes
307315
}
308316

317+
/// Deserialize a VoiceFrame from its 21-byte wire representation.
309318
pub fn from_bytes(bytes: &[u8; Self::BYTE_SIZE]) -> Self {
310319
let mut rvq_bytes = [0u8; 17];
311320
rvq_bytes.copy_from_slice(&bytes[..17]);

src/hpc/deepnsm.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,14 @@ pub fn nsm_decompose(text: &str) -> NsmDecomposition {
646646
NsmDecomposition { weights, dominant }
647647
}
648648

649-
/// Encode an NSM decomposition as a 10000-bit binary vector (1250 bytes).
649+
/// Encode an NSM decomposition as a 16384-bit binary vector (2048 bytes).
650650
///
651651
/// For each prime with weight > 0, hash prime_index with blake3 to produce
652652
/// a deterministic bit pattern, then XOR into result for primes whose
653653
/// normalised weight exceeds 0.5 of the max weight (or any nonzero weight
654654
/// when only one prime is present).
655-
pub fn nsm_to_fingerprint(decomp: &NsmDecomposition) -> [u8; 1250] {
656-
let mut result = [0u8; 1250];
655+
pub fn nsm_to_fingerprint(decomp: &NsmDecomposition) -> [u8; 2048] {
656+
let mut result = [0u8; 2048];
657657

658658
let max_w = decomp.weights.iter().cloned().fold(0.0f32, f32::max);
659659
if max_w == 0.0 {
@@ -665,31 +665,27 @@ pub fn nsm_to_fingerprint(decomp: &NsmDecomposition) -> [u8; 1250] {
665665
if w < threshold {
666666
continue;
667667
}
668-
// Hash the prime index to get a deterministic 1250-byte pattern
668+
// Hash the prime index to get a deterministic 2048-byte pattern
669669
let hash_input = (i as u32).to_le_bytes();
670-
let mut pattern = [0u8; 1250];
671-
// Use blake3 in extended-output mode to fill 1250 bytes
670+
let mut pattern = [0u8; 2048];
671+
// Use blake3 in extended-output mode to fill 2048 bytes
672672
let mut hasher = blake3::Hasher::new();
673673
hasher.update(&hash_input);
674674
let mut reader = hasher.finalize_xof();
675675
reader.fill(&mut pattern);
676676

677-
// XOR 1250 bytes via crate::simd::U8x64.
678-
// 1250 = 19×64 (1216) + 34 scalar remainder.
677+
// XOR 2048 bytes via crate::simd::U8x64.
678+
// 2048 = 32×64 exactly (no scalar remainder, SIMD-clean).
679679
{
680680
use crate::simd::U8x64;
681-
let chunks = 1250 / 64; // 19
681+
let chunks = 2048 / 64; // 32
682682
for c in 0..chunks {
683683
let off = c * 64;
684684
let vr = U8x64::from_slice(&result[off..off + 64]);
685685
let vp = U8x64::from_slice(&pattern[off..off + 64]);
686686
let xored = vr ^ vp;
687687
xored.copy_to_slice(&mut result[off..off + 64]);
688688
}
689-
// Scalar remainder (34 bytes).
690-
for j in (chunks * 64)..1250 {
691-
result[j] ^= pattern[j];
692-
}
693689
}
694690
}
695691

0 commit comments

Comments
 (0)