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 / gpu / turing / energy.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/turing/energy.om: TURING Yield TY-4/TY-5 measured resource interval & conserving energy attribution invariants. |
| 3 | note Converted from src/turing/{ty_energy.h,ty_energy.c}. Fail-closed: checks refuse, never repair. |
| 4 | |
| 5 | fn ty_conf_forge c uint to uint |
| 6 | if or eq c TY_DIRECT eq c TY_COUNTER_DERIVED |
| 7 | ret TY_FORGE_ENERGY_MEASURED |
| 8 | end |
| 9 | if or eq c TY_CAUSAL_RUNTIME or eq c TY_COUNTERFACTUAL eq c TY_MODELLED |
| 10 | ret TY_FORGE_ENERGY_ESTIMATED |
| 11 | end |
| 12 | ret TY_FORGE_ENERGY_NOT_MEASURED |
| 13 | end |
| 14 | |
| 15 | fn ty_windows_overlap t0a ulong t1a ulong t0b ulong t1b ulong to int |
| 16 | if or ge t0a t1a ge t0b t1b |
| 17 | ret 1 |
| 18 | end |
| 19 | if and lt t0a t1b lt t0b t1a |
| 20 | ret 1 |
| 21 | end |
| 22 | ret 0 |
| 23 | end |
| 24 | |
| 25 | fn ty_interval_check iv view TyInterval to uint |
| 26 | if eq get iv sensor_ok 0 |
| 27 | ret TYE_E_SENSOR |
| 28 | end |
| 29 | if or ne get iv wrap_flag 0 lt get iv e1_uj get iv e0_uj |
| 30 | ret TYE_E_WRAP |
| 31 | end |
| 32 | if ge get iv e1_uj TY_WRAP_UJ |
| 33 | ret TYE_E_HEADROOM |
| 34 | end |
| 35 | if lt sub TY_WRAP_UJ get iv e1_uj TY_HEADROOM_MIN_UJ |
| 36 | ret TYE_E_HEADROOM |
| 37 | end |
| 38 | if gt get iv max_gap_ns TY_MAX_GAP_NS |
| 39 | ret TYE_E_SAMPLING_GAP |
| 40 | end |
| 41 | if gt get iv expected_samples uint 0 |
| 42 | if lt mul ulong get iv samples ulong 100 mul ulong get iv expected_samples ulong 90 |
| 43 | ret TYE_E_SAMPLING_GAP |
| 44 | end |
| 45 | end |
| 46 | if eq get iv work_ok 0 |
| 47 | ret TYE_E_PARTIAL_RUN |
| 48 | end |
| 49 | if or ge get iv t0_ns get iv t1_ns ge get iv work_t0_ns get iv work_t1_ns |
| 50 | ret TYE_E_INTERVAL_MISMATCH |
| 51 | end |
| 52 | if or lt get iv work_t0_ns get iv t0_ns gt get iv work_t1_ns get iv t1_ns |
| 53 | ret TYE_E_INTERVAL_MISMATCH |
| 54 | end |
| 55 | dur = sub get iv work_t1_ns get iv work_t0_ns |
| 56 | if gt get iv planned_ns ulong 0 |
| 57 | if lt mul dur ulong 100 mul get iv planned_ns ulong 98 |
| 58 | ret TYE_E_PARTIAL_RUN |
| 59 | end |
| 60 | end |
| 61 | if gt get iv pmu_enabled_ns ulong 0 |
| 62 | if lt mul get iv pmu_running_ns ulong 1000 mul get iv pmu_enabled_ns ulong 999 |
| 63 | ret TYE_E_MULTIPLEXED |
| 64 | end |
| 65 | end |
| 66 | ret TYE_OK |
| 67 | end |
| 68 | |
| 69 | fn ty_attribution_check att view TyAttrib expected_mask uint to uint |
| 70 | np = ulong get att n_part |
| 71 | if or eq np ulong 0 gt np ulong 4 |
| 72 | ret TYE_E_ARG |
| 73 | end |
| 74 | seen = uint 0 |
| 75 | sum = long 0 |
| 76 | unc = get att uncert_uj |
| 77 | for i ulong np bound 4 |
| 78 | sh = get att shares_uj i |
| 79 | if lt sh neg unc |
| 80 | ret TYE_E_NEGATIVE_SHARE |
| 81 | end |
| 82 | pid = get att part_id i |
| 83 | if ge pid uint 4 |
| 84 | ret TYE_E_UNKNOWN_PARTICIPANT |
| 85 | end |
| 86 | bit = shl uint 1 pid |
| 87 | if eq and expected_mask bit uint 0 |
| 88 | ret TYE_E_UNKNOWN_PARTICIPANT |
| 89 | end |
| 90 | if ne and seen bit uint 0 |
| 91 | ret TYE_E_DOUBLE_COUNT |
| 92 | end |
| 93 | seen = or seen bit |
| 94 | sum = add sum sh |
| 95 | end |
| 96 | if ne seen expected_mask |
| 97 | ret TYE_E_MISSING_PARTICIPANT |
| 98 | end |
| 99 | if gt sum add get att measured_uj unc |
| 100 | ret TYE_E_OVER_ALLOCATED |
| 101 | end |
| 102 | ret TYE_OK |
| 103 | end |