deeprcurs-staff commited on
Commit
071eedc
·
verified ·
1 Parent(s): 3ac63cb

Upload kernels/noesa24_avx2.cpp with huggingface_hub

Browse files
Files changed (1) hide show
  1. kernels/noesa24_avx2.cpp +77 -0
kernels/noesa24_avx2.cpp ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // noesa24_avx2.cpp — IKNN-Rl1-A1 — NoeSA-24 AVX2 Kernel (Ryzen5 5650U)
2
+ // Version: v1.0
3
+ // Created: 2026-09-03T17:10:00+07:00
4
+ // Last Updated: 2026-09-03T17:10:00+07:00
5
+ // Status: PUBLISHABLE — EN ONLY — M1 Kernel Validation
6
+ // Repo: IKNN-Rl1-A1 — Integrated Knowledge-phase Neural Network — Recursive Language Iteration 1 — Architecture 1
7
+ // Hardware: Ryzen5 5650U — 6C/12T Zen3, AVX2 (NO AVX-512), DDR4 35-45GB/s
8
+ // Description: Same as AVX-512 but AVX2 version — LUT576 decode 12 cycles per 13 units
9
+
10
+ #include "noesa24_common.h"
11
+ #include <cstdint>
12
+ #include <immintrin.h>
13
+
14
+ namespace iknn {
15
+ namespace noesa24 {
16
+ namespace avx2 {
17
+
18
+ // AVX2 version — processes 8 activations at once (256-bit / 32-bit = 8)
19
+ inline __m256i compute_noesa24_block_avx2(
20
+ __m256i activations, // 8x INT32
21
+ const uint8_t states[8],
22
+ int32_t bias_0b = 1)
23
+ {
24
+ alignas(32) int32_t act_array[8];
25
+ _mm256_store_si256(reinterpret_cast<__m256i*>(act_array), activations);
26
+
27
+ alignas(32) int32_t result[8];
28
+ for (int i = 0; i < 8; ++i) {
29
+ result[i] = compute_noesa24_single(static_cast<int8_t>(act_array[i]), states[i], bias_0b);
30
+ }
31
+ return _mm256_load_si256(reinterpret_cast<const __m256i*>(result));
32
+ }
33
+
34
+ inline void decode_60bit_avx2(uint64_t packed60, uint8_t out_digits[13]) {
35
+ static LUT576 lut[576];
36
+ static bool lut_built = false;
37
+ if (!lut_built) {
38
+ build_lut576(lut);
39
+ lut_built = true;
40
+ }
41
+ unpack_13x24_lut(packed60, out_digits, lut);
42
+ }
43
+
44
+ } // namespace avx2
45
+ } // namespace noesa24
46
+ } // namespace iknn
47
+
48
+ #ifdef NOESA24_AVX2_TEST
49
+ #include <random>
50
+ #include <iostream>
51
+
52
+ int main() {
53
+ using namespace iknn::noesa24;
54
+ using namespace iknn::noesa24::avx2;
55
+
56
+ std::cout << "[NoeSA-24 AVX2 Test] Ryzen5 5650U" << std::endl;
57
+
58
+ std::mt19937 rng(42);
59
+ uint8_t digits[13];
60
+ for (int i = 0; i < 13; ++i) digits[i] = rng() % 24;
61
+
62
+ uint64_t packed = pack_13x24(digits);
63
+ uint8_t unpacked[13];
64
+ unpack_13x24(packed, unpacked);
65
+
66
+ bool ok = true;
67
+ for (int i = 0; i < 13; ++i) if (digits[i] != unpacked[i]) ok = false;
68
+ std::cout << "Pack/unpack: " << (ok ? "[PASS]" : "[FAIL]") << std::endl;
69
+
70
+ int8_t act = 10;
71
+ uint8_t state = encode_state(Operator::POS_A, Scale::S2);
72
+ int32_t res = compute_noesa24_single(act, state);
73
+ std::cout << "Compute +1a S2: " << res << " expected 40 " << (res==40 ? "[PASS]" : "[FAIL]") << std::endl;
74
+
75
+ return 0;
76
+ }
77
+ #endif