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-bridge/blob/main/examples/deepinfer/flops_estimator-omega.patch # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-bridge / examples / deepinfer / flops_estimator-omega.patch` 55 lines ยท 2852 bytes Raw Blame History 1 --- a/csrc/engine/flops_estimator.hpp 2 +++ b/csrc/engine/flops_estimator.hpp 3 @@ -10,6 +10,10 @@ 4 #include 5 #include 6 7 +// floor_prefix, capped_prefix and pairs run the Omega unit flops_pairs.om (aien-dev/omega-bridge 8 +// examples/deepinfer), bound by omega-bridge tools/native into libomega_native. 9 +#include "omega_native.h" 10 + 11 // GEMM coefficients include multiply-add (2 FLOPs) and the FP8-equivalent weight. 12 namespace flops_coef { 13 constexpr int64_t FP4 = 1; 14 @@ -237,23 +241,34 @@ 15 // Sum floor(t / ratio), t=1..n: compressed query-key pairs without a cap. 16 // Used for dense core attention and full-context index attention. 17 static int64_t floor_prefix(int64_t n, int64_t ratio) { 18 - const int64_t blocks = n / ratio; 19 - return blocks * (n + 1) - ratio * blocks * (blocks + 1) / 2; 20 + uint64_t bits = 0; 21 + const uint32_t status = omega2_floor_prefix(&bits, static_cast(n), static_cast(ratio)); 22 + return omega_result(status, bits, "floor_prefix"); 23 } 24 25 // Sum min(floor(t / ratio), cap), t=1..n. 26 // Used for topk/candidate limits and SWA windows (ratio=1). 27 static int64_t capped_prefix(int64_t n, int64_t ratio, int64_t cap) { 28 - const int64_t stop = std::min(n, ratio * cap); 29 - return floor_prefix(stop, ratio) + (n - stop) * cap; 30 + uint64_t bits = 0; 31 + const uint32_t status = 32 + omega2_capped_prefix(&bits, static_cast(n), static_cast(ratio), static_cast(cap)); 33 + return omega_result(status, bits, "capped_prefix"); 34 } 35 36 // Query-key pairs for positions [begin, end), via prefix differences. 37 // Used for full/consumer query ranges; cap=0 means uncapped. 38 static int64_t pairs(int64_t begin, int64_t end, int64_t ratio, int64_t cap = 0) { 39 - if (cap == 0) 40 - return floor_prefix(end, ratio) - floor_prefix(begin, ratio); 41 - return capped_prefix(end, ratio, cap) - capped_prefix(begin, ratio, cap); 42 + uint64_t bits = 0; 43 + const uint32_t status = omega2_pairs(&bits, static_cast(begin), static_cast(end), 44 + static_cast(ratio), static_cast(cap)); 45 + return omega_result(status, bits, "pairs"); 46 + } 47 + 48 + // An Omega status is 0 when done; 1 when a step leaves int64_t (where the former C++ expression was 49 + // undefined behaviour); 9 outside n >= 0, ratio > 0, cap >= 0, 0 <= begin <= end. 50 + static int64_t omega_result(uint32_t status, uint64_t bits, const char *fn) { 51 + TORCH_CHECK(status == OMEGA_OK, fn, ": Omega trap ", status); 52 + return static_cast(bits); 53 } 54 55 std::pair query_ranges(int q, int k, bool is_prompt, int full_len, int swa_valid_start) const {