Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/omega_matvec.h # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / omega_matvec.h` 107 lines ยท 3859 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef OMEGA_MATVEC_H 18 #define OMEGA_MATVEC_H 19 20 #include "omega_types.h" 21 #include "omega_machine.h" 22 #include "omega_realize.h" 23 #include "omega_verify.h" 24 #include 25 #include 26 #include 27 28 #define MATVEC_MAX_REALIZATIONS 3 29 30 typedef enum { 31 MATVEC_REALIZATION_SCALAR = 0, /* Baseline sequential row/col loop */ 32 MATVEC_REALIZATION_UNROLL2 = 1, /* 2-way inner loop unrolling */ 33 MATVEC_REALIZATION_UNROLL4_DUAL = 2, /* 4-way inner loop unroll with dual accumulators (4-wide Neoverse V2) */ 34 MATVEC_REALIZATION_COUNT = 3 35 } MatVecRealizationKind; 36 37 typedef struct { 38 SemanticId spec_id; 39 char name[64]; 40 uint32_t max_m; 41 uint32_t max_n; 42 } MatVecSemanticSpec; 43 44 typedef struct { 45 MatVecRealizationKind kind; 46 const char *name; 47 RealizationObject realization; 48 SemanticId realization_id; 49 uint32_t unroll_factor; 50 uint32_t accumulators; 51 VerifyReport verify_report; 52 bool is_verified; 53 } MatVecRealization; 54 55 typedef struct { 56 uint32_t m; 57 uint32_t n; 58 uint64_t elapsed_ns; 59 uint64_t cycle_count; 60 double gflops; 61 double bandwidth_gbps; 62 bool numerical_parity; 63 } MatVecBenchmarkMetric; 64 65 typedef struct { 66 MatVecRealizationKind selected_kind; 67 uint64_t benchmark_ns[MATVEC_REALIZATION_COUNT]; 68 double speedup_ratio; 69 bool adapted; 70 } MatVecSelectionDecision; 71 72 typedef struct { 73 MatVecSemanticSpec spec; 74 const OmegaMachineGraph *machine; 75 MatVecRealization realizations[MATVEC_REALIZATION_COUNT]; 76 size_t realization_count; 77 bool is_initialized; 78 } MatVecLivingKernel; 79 80 /* Initialize semantic specification for MatVec operator */ 81 int omega_matvec_spec_init(MatVecSemanticSpec *spec, const char *name, uint32_t max_m, uint32_t max_n); 82 83 /* Initialize living kernel with specification and target machine graph */ 84 int omega_matvec_kernel_init(MatVecLivingKernel *kernel, const MatVecSemanticSpec *spec, const OmegaMachineGraph *mg); 85 86 /* Synthesize a specific realization kind directly into memory */ 87 int omega_matvec_synthesize(MatVecLivingKernel *kernel, MatVecRealizationKind kind, MatVecRealization *out_real); 88 89 /* Reference Oracle implementation: y = A * x (pure semantic calculation) */ 90 void omega_matvec_reference(const uint64_t *A, const uint64_t *x, uint64_t *y, uint32_t M, uint32_t N); 91 92 /* Execute realization on native hardware */ 93 int omega_matvec_exec(const MatVecRealization *real, const uint64_t *A, const uint64_t *x, uint64_t *y, uint32_t M, uint32_t N); 94 95 /* Benchmark a realization over a given dimension regime (M x N) */ 96 int omega_matvec_benchmark(const MatVecRealization *real, uint32_t M, uint32_t N, size_t iterations, MatVecBenchmarkMetric *out_metric); 97 98 /* Living kernel adaptive selection: evaluate regimes and dynamically pick best realization */ 99 int omega_matvec_adapt(MatVecLivingKernel *kernel, uint32_t M, uint32_t N, MatVecSelectionDecision *decision); 100 101 /* Dispatch optimal realization for regime */ 102 int omega_matvec_dispatch(MatVecLivingKernel *kernel, const uint64_t *A, const uint64_t *x, uint64_t *y, uint32_t M, uint32_t N); 103 104 /* Free resources owned by kernel */ 105 void omega_matvec_kernel_destroy(MatVecLivingKernel *kernel); 106 107 #endif /* OMEGA_MATVEC_H */