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-mv/blob/main/src/omega_gpu_moe_plan.h # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / omega_gpu_moe_plan.h` 146 lines ยท 4447 bytes Raw Blame History 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_GPU_MOE_PLAN_H 18 #define OMEGA_GPU_MOE_PLAN_H 19 /* 20 * omega_gpu_moe_plan: Pure-OM-2 persistent MoE request queue + unified single-submit 21 * MoE layer execution planner & PTIMER/traffic instrumentation (om/gpu/moe_plan.om). 22 */ 23 #include 24 #include 25 #include "omega_gpu_fp8_api.h" 26 #include "omega_gpu_cmdlist.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #define OMEGA_MOE_QUEUE_WORDS 512u 33 #define OMEGA_MOE_QUEUE_MAX_CAP 64u 34 #define OMEGA_MOE_PLAN_MAX_OPS 32u 35 36 enum { 37 OMEGA_MOE_ST_EMPTY = 0, 38 OMEGA_MOE_ST_QUEUED = 1, 39 OMEGA_MOE_ST_RUNNING = 2, 40 OMEGA_MOE_ST_DONE = 3, 41 OMEGA_MOE_ST_ERROR = 4 42 }; 43 44 enum { 45 OMEGA_MOP_ROUTER_LOGITS = 1, 46 OMEGA_MOP_ACT_QUANT = 2, 47 OMEGA_MOP_EXPERT_GATEUP_GEMM = 3, 48 OMEGA_MOP_EXPERT_GATEUP_GEMV = 4, 49 OMEGA_MOP_EXPERT_DOWN_GEMM = 5, 50 OMEGA_MOP_EXPERT_DOWN_GEMV = 6, 51 OMEGA_MOP_MOE_COMBINE = 7 52 }; 53 54 enum { 55 OMEGA_MOE_FLAG_ROUTER = 1u << 0, 56 OMEGA_MOE_FLAG_GATEUP = 1u << 1, 57 OMEGA_MOE_FLAG_DOWN = 1u << 2, 58 OMEGA_MOE_FLAG_COMBINE = 1u << 3, 59 OMEGA_MOE_FLAG_USE_QMMA = 1u << 4, 60 OMEGA_MOE_FLAG_OVERLAP_RQ = 1u << 5 61 }; 62 63 typedef struct { 64 uint32_t words[OMEGA_MOE_QUEUE_WORDS]; 65 } OmegaMoeQueue; 66 67 typedef struct { 68 uint32_t op; 69 uint32_t mark_independent; 70 uint32_t arg0; 71 uint32_t arg1; 72 } OmegaMoePlanOp; 73 74 typedef struct { 75 uint32_t tokens; 76 uint32_t hidden; 77 uint32_t inter; 78 uint32_t experts; 79 uint32_t top_k; 80 uint32_t flags; 81 } OmegaMoePlanConfig; 82 83 typedef struct { 84 uint64_t router_bytes; 85 uint64_t gateup_bytes; 86 uint64_t down_bytes; 87 uint64_t combine_bytes; 88 uint64_t total_bytes; 89 } OmegaMoeTraffic; 90 91 typedef struct { 92 OmegaMoePlanConfig cfg; 93 uint32_t distinct_experts; 94 /* Router logits (rl) device buffers */ 95 uint64_t x_va; 96 uint64_t router_wq_va; 97 uint64_t logits_va; 98 /* Grouped FP8 gate_up expert GEMM buffers */ 99 const OmegaGpuFp8Tensor *gateup_t; 100 uint32_t gateup_segs; 101 uint64_t gateup_seg_va; 102 uint64_t gateup_xp_va; 103 uint64_t gateup_y_va; 104 /* Grouped FP8 down expert GEMM buffers */ 105 const OmegaGpuFp8Tensor *down_t; 106 uint32_t down_segs; 107 uint64_t down_seg_va; 108 uint64_t down_xp_va; 109 uint64_t down_y_va; 110 /* Weighted combine (mc) buffers */ 111 uint64_t inv_va; 112 uint64_t wt_va; 113 uint64_t out_va; 114 /* Optional cmdlist barrier (default WFI_DATA) */ 115 OmegaGpuCmdListBarrier barrier; 116 } OmegaGpuMoeExecArgs; 117 118 typedef struct { 119 uint32_t planned_ops; 120 uint32_t launches; 121 uint32_t submits; 122 uint64_t chip_ns; 123 uint64_t host_build_ns; 124 uint64_t stage_ns[OMEGA_MOE_PLAN_MAX_OPS]; 125 uint32_t stage_op[OMEGA_MOE_PLAN_MAX_OPS]; 126 OmegaMoeTraffic traffic; 127 double effective_gbps; 128 } OmegaGpuMoeExecStats; 129 130 /* Pure OM-2 queue state machine wrappers (never abort) */ 131 int omega_moe_queue_init(OmegaMoeQueue *q, uint32_t cap); 132 int omega_moe_queue_enqueue(OmegaMoeQueue *q, uint32_t req_id, uint32_t tokens, uint32_t layer, uint32_t flags, uint32_t *slot_out); 133 int omega_moe_queue_claim_batch(OmegaMoeQueue *q, uint32_t max_tokens, uint32_t out_slots[64], uint32_t *claimed_out); 134 int omega_moe_queue_complete_batch(OmegaMoeQueue *q, uint32_t n, const uint32_t slots[64], uint32_t status); 135 136 /* Pure OM-2 MoE planner & traffic estimator wrappers (never abort) */ 137 int omega_moe_plan_layer(const OmegaMoePlanConfig *cfg, OmegaMoePlanOp out_ops[OMEGA_MOE_PLAN_MAX_OPS], uint32_t *n_ops); 138 int omega_moe_plan_traffic(const OmegaMoePlanConfig *cfg, uint32_t distinct_experts, OmegaMoeTraffic *out); 139 140 /* Execute a unified .om-planned MoE layer in ONE OmegaGpuCmdList PCAS submission with PTIMER stamps. */ 141 int omega_gpu_moe_plan_exec(OmegaGpuCmdList *cl, const OmegaGpuMoeExecArgs *args, OmegaGpuMoeExecStats *stats); 142 143 #ifdef __cplusplus 144 } 145 #endif 146 #endif