interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / turing / energy.om

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