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
omega-mv / src / omega_realize_synth.h
| 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_REALIZE_SYNTH_H |
| 18 | #define OMEGA_REALIZE_SYNTH_H |
| 19 | |
| 20 | #include "omega_program.h" |
| 21 | #include "omega_machine.h" |
| 22 | #include "omega_realize.h" |
| 23 | #include "omega_verify.h" |
| 24 | #include <stdbool.h> |
| 25 | #include <stddef.h> |
| 26 | |
| 27 | typedef struct { |
| 28 | const OmegaProgram *program; |
| 29 | const OmegaMachineGraph *machine; |
| 30 | bool optimize_latency; |
| 31 | uint32_t max_unroll_factor; |
| 32 | } RealizationSynthesisTask; |
| 33 | |
| 34 | typedef struct { |
| 35 | bool solved; |
| 36 | RealizationObject realization; |
| 37 | SemanticId realization_id; |
| 38 | uint32_t estimated_cycles; |
| 39 | uint32_t code_bytes_len; |
| 40 | VerifyReport verify_report; |
| 41 | OmegaRealizeSchedule schedule; /* machine-aware choice (never semantic) */ |
| 42 | uint32_t inputs_checked; /* differential inputs where native == semantic */ |
| 43 | char why[192]; /* reason when refused or not verified; empty on success */ |
| 44 | } RealizationSynthesisResult; |
| 45 | |
| 46 | /* Initialize realization synthesis task */ |
| 47 | void omega_realize_task_init(RealizationSynthesisTask *task, |
| 48 | const OmegaProgram *prog, |
| 49 | const OmegaMachineGraph *mg); |
| 50 | |
| 51 | /* Compute cryptographic triple identity: |
| 52 | * REALIZATION_ID = SHA-256(OMG0 | KIND_REALIZATION | profile | SEMANTIC_ID | MACHINE_ID | code_bytes) |
| 53 | */ |
| 54 | int omega_realize_compute_triple_id(const SemanticId *semantic_id, |
| 55 | const SemanticId *machine_id, |
| 56 | const RealizationObject *real, |
| 57 | SemanticId *out_id); |
| 58 | |
| 59 | /* Main machine-aware realization synthesis entrypoint (G_S x G_M -> G_R). |
| 60 | * Compiles task->program's canonical body (spec/program-realization.md): V0 gate -> |
| 61 | * schedule chosen from the MachineGraph -> AArch64 bytes -> triple id -> verification |
| 62 | * (bindings, V0 structural, native-vs-semantic differential, V2). Returns 0 solved; |
| 63 | * -2 refused by the V0 gate (result->why); -3 not verifiable on this host; -1 failed. */ |
| 64 | int omega_synthesize_realization(const RealizationSynthesisTask *task, |
| 65 | RealizationSynthesisResult *result); |
| 66 | |
| 67 | /* Schedule the planner picks for a machine (issue_width >= 4 and >= 16 GPRs: PRELOAD). */ |
| 68 | OmegaRealizeSchedule omega_realize_choose_schedule(const OmegaMachineGraph *mg); |
| 69 | |
| 70 | /* Differential inputs for a program: boundary values of its width + seeded random. */ |
| 71 | #define OMEGA_REALIZE_DIFF_INPUTS 84 |
| 72 | size_t omega_realize_differential_inputs(const OmegaProgram *prog, uint64_t *xs, size_t max); |
| 73 | |
| 74 | /* Verify a machine-bound realization against program + machine: program passes the V0 |
| 75 | * gate; real->semantic_id == program_id; real->machine_id == mg->machine_id (and mg's id |
| 76 | * matches its content); profile; V0 structural incl. the triple REALIZATION_ID over the |
| 77 | * code bytes; native execution == omega_program_eval on every differential input. |
| 78 | * 0 pass; -1 fail (why); -3 not verifiable here (non-AArch64 host). */ |
| 79 | int omega_realization_verify_program(const OmegaProgram *prog, const OmegaMachineGraph *mg, |
| 80 | const RealizationObject *real, uint32_t *out_checked, |
| 81 | char *why, size_t why_len); |
| 82 | |
| 83 | /* Synthesize realization specialized for 4-wide DGX Spark Grace Neoverse V2 pipeline */ |
| 84 | int omega_synthesize_for_dgx_spark(const OmegaProgram *prog, RealizationSynthesisResult *result); |
| 85 | |
| 86 | /* Synthesize realization specialized for 2-wide QEMU virt AArch64 baseline pipeline */ |
| 87 | int omega_synthesize_for_qemu_virt(const OmegaProgram *prog, RealizationSynthesisResult *result); |
| 88 | |
| 89 | #endif /* OMEGA_REALIZE_SYNTH_H */ |