interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / examples / deepinfer / flops_pairs.om

41 lines · 1684 bytes Raw Blame History
1note flops_pairs.om: DeepInfer FlopsEstimator::floor_prefix, capped_prefix and pairs in Omega
2note (deepseek-ai/DeepInfer 553741557a57df44a46fb3ab72b6aafeaf945337 csrc/engine/flops_estimator.hpp
3note lines 237-257, Apache-2.0). Each step is the C++ expression's step in the same order, so a
4note step that leaves long traps 1 exactly where the C++ would be undefined behaviour. div truncates
5note toward zero like C++ /. Valid domain (the callers clamp with std::max(0, ...)): n >= 0,
6note ratio > 0, cap >= 0, 0 <= begin <= end; outside it a requires clause traps 9 instead of
7note returning a value. Bound through tools/native as omega2_floor_prefix, omega2_capped_prefix and
8note omega2_pairs (examples/deepinfer/README.md).
9om2
10note sum floor(t / ratio), t = 1 .. n
11export fn floor_prefix n long ratio long to long
12requires ge n 0
13requires gt ratio 0
14blocks = div n ratio
15a = mul blocks add n 1
16b = div mul mul ratio blocks add blocks 1 2
17ret sub a b
18end
19note sum min(floor(t / ratio), cap), t = 1 .. n
20export fn capped_prefix n long ratio long cap long to long
21requires ge n 0
22requires gt ratio 0
23requires ge cap 0
24stop = mul ratio cap
25if lt n stop
26stop = n
27end
28ret add floor_prefix stop ratio mul sub n stop cap
29end
30note query-key pairs for positions [begin, finish) by prefix differences; cap 0 means uncapped
31note (C++ names the second parameter end, which is an Omega keyword)
32export fn pairs begin long finish long ratio long cap long to long
33requires ge begin 0
34requires le begin finish
35requires gt ratio 0
36requires ge cap 0
37if eq cap 0
38ret sub floor_prefix finish ratio floor_prefix begin ratio
39end
40ret sub capped_prefix finish ratio cap capped_prefix begin ratio cap
41end