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 / om / gpu / inkling2 / multistream / serve_ms.om

170 lines · 4586 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Pure Seeded-Omega Fixed-Slot Continuous Batcher HTTP Server for Inkling-2-Mini (N = 8 static KV slots).
3note ZERO heap, ZERO libc, ZERO Python, ZERO CUDA.
4note Replaces the 1-slot `503 server_busy` gate with an N=8 static-slot continuous batcher:
5note - GET /health -> 200 JSON with active_slots / max_slots / free_slots
6note - GET /v1/models -> 200 JSON listing inkling-2-mini
7note - POST /v1/chat/completions -> admits into static slot 0..7, or returns 503 server_busy + Retry-After: 1
8note ONLY when all 8 static KV slots are occupied.
9note Compose after: om/gpu/inkling2/multistream/batcher.om.
10
11global svReqBuf uchar 4096
12global svOutBuf uchar 4096
13
14text sv200Hdr "HTTP/1.1 200 OK\nContent-Type: application/json\nConnection: close\n\n"
15text sv503Full "HTTP/1.1 503 Service Unavailable\nRetry-After: 1\nContent-Type: application/json\nConnection: close\n\n{\"error\":{\"message\":\"all 8 static KV slots are occupied: retry after 1 s\",\"type\":\"server_error\",\"code\":\"server_busy\"}}\n"
16text svModels "{\"object\":\"list\",\"data\":[{\"id\":\"inkling-2-mini\",\"object\":\"model\",\"max_concurrent_streams\":8}]}\n"
17text svHealthPre "{\"status\":\"ok\",\"max_slots\":8,\"active_slots\":"
18text svHealthMid ",\"free_slots\":"
19text svHealthEnd "}\n"
20text svAdmitPre "{\"status\":\"admitted\",\"slot\":"
21text svAdmitEnd ",\"max_slots\":8,\"engine\":\"omega-inkling2-multistream\"}\n"
22text sv404 "HTTP/1.1 404 Not Found\nContent-Type: application/json\nConnection: close\n\n{\"error\":\"not_found\"}\n"
23text svSelfOk "PASS: fixed-slot N=8 HTTP continuous batcher self-test (8 admitted, 9th -> 503 server_busy, retire -> 200 reused)\n"
24text svSelfFail "FAIL: fixed-slot N=8 HTTP continuous batcher self-test step="
25text svNl "\n"
26
27fn svWriteAll fd int buf view uchar * n ulong to bool
28done = ulong 0
29while lt done n bound 4096
30r = write fd buf done sub n done
31if eq r -4
32continue
33end
34if le r 0
35ret false
36end
37done = add done ulong r
38end
39ret true
40end
41
42fn svAppendDst dst edit uchar 4096 pos ulong src view uchar * to ulong
43p = pos
44for i ulong len src bound 512
45if lt p 4096
46put dst p get src i
47p = add p 1
48end
49end
50ret p
51end
52
53fn svAppendU dst edit uchar 4096 pos ulong v ulong to ulong
54tmp = new uchar 32 0
55p = pos
56if eq v 0
57put dst p 48
58ret add p 1
59end
60n = ulong 0
61x = v
62while gt x 0 bound 32
63put tmp n uchar add 48 rem x 10
64x = div x 10
65n = add n 1
66end
67for i ulong n bound 32
68put dst p get tmp sub sub n 1 i
69p = add p 1
70end
71ret p
72end
73
74fn svHandleRequest req view uchar * rlen ulong outBuf edit uchar 4096 outLen edit ulong 1 to ulong
75if lt rlen 12
76p = svAppendDst outBuf 0 sv404
77put outLen 0 p
78ret 404
79end
80c0 = get req 0
81c4 = get req 4
82c5 = get req 5
83note GET /health
84if eq c0 71
85if eq c4 47
86if eq c5 104
87act = get msActiveCnt 0
88remSlots = sub MS_MAX_STREAMS act
89p = svAppendDst outBuf 0 sv200Hdr
90p = svAppendDst outBuf p svHealthPre
91p = svAppendU outBuf p act
92p = svAppendDst outBuf p svHealthMid
93p = svAppendU outBuf p remSlots
94p = svAppendDst outBuf p svHealthEnd
95put outLen 0 p
96ret 200
97end
98note GET /v1/models
99if eq c5 118
100p = svAppendDst outBuf 0 sv200Hdr
101p = svAppendDst outBuf p svModels
102put outLen 0 p
103ret 200
104end
105end
106end
107note POST /v1/chat/completions
108if eq c0 80
109if eq c5 47
110slot = msAdmit 0 64 1
111if lt slot 0
112p = svAppendDst outBuf 0 sv503Full
113put outLen 0 p
114ret 503
115end
116p = svAppendDst outBuf 0 sv200Hdr
117p = svAppendDst outBuf p svAdmitPre
118p = svAppendU outBuf p ulong slot
119p = svAppendDst outBuf p svAdmitEnd
120put outLen 0 p
121ret 200
122end
123end
124p = svAppendDst outBuf 0 sv404
125put outLen 0 p
126ret 404
127end
128
129text svTReqPost "POST /v1/chat/completions HTTP/1.1\nHost: localhost\n\n{}"
130text svTReqHealth "GET /health HTTP/1.1\nHost: localhost\n\n"
131
132fn svRunSelfTest to int
133msInit
134outB = new uchar 4096 0
135outL = new ulong 1 0
136for s ulong 8
137code = svHandleRequest svTReqPost len svTReqPost outB outL
138if ne code 200
139w = write 1 svSelfFail 0 len svSelfFail
140ret 1
141end
142end
143code9 = svHandleRequest svTReqPost len svTReqPost outB outL
144if ne code9 503
145w = write 1 svSelfFail 0 len svSelfFail
146ret 2
147end
148ch = svHandleRequest svTReqHealth len svTReqHealth outB outL
149if ne ch 200
150w = write 1 svSelfFail 0 len svSelfFail
151ret 3
152end
153msRetire 5
154code10 = svHandleRequest svTReqPost len svTReqPost outB outL
155if ne code10 200
156w = write 1 svSelfFail 0 len svSelfFail
157ret 4
158end
159code11 = svHandleRequest svTReqPost len svTReqPost outB outL
160if ne code11 503
161w = write 1 svSelfFail 0 len svSelfFail
162ret 5
163end
164w = write 1 svSelfOk 0 len svSelfOk
165ret 0
166end
167
168fn main to int
169ret svRunSelfTest
170end