code wiki / (root) / nx_embed_gpu_live_gate.nx

nx_embed_gpu_live_gate.nx source

↩ module page · 85 lines · 3910 B

1// nx_embed_gpu_live_gate.nx -- e4 LIVE gate: the deployed :8033 daemon's /embed must return the 2// BYTE-IDENTICAL Q24 vector for mode "i8" (CPU) and mode "gpu" (resident-weight GPU server via the 3// unix-socket client in serve core). Also asserts the response labels mode:"gpu" and equal ntok. 4// Requires: coder daemon relaunched on the new serve core + gpu_embed_serve --serve up. 5// usage: nx_embed_gpu_live_gate [port] (default 8033) 6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 7import "nx_code_index.nx" 8 9const EGL_PORT_DEFAULT: i64 = 8033 // the deployed coder daemon's /embed port 10const EGL_BODY_CAP: i64 = 4096 // request-body scratch (JSON is well under this) 11const EGL_RESP_CAP: i64 = 65536 // /embed response buffer (Q24 vector + labels) 12const EGL_ERRDUMP: i64 = 300 // bytes of the failing response to echo on RED 13const EGL_I64_BYTES: i64 = 8 // sizeof(i64) -- byte size of one vector element / pointer slot 14const EGL_ERR_POST: i64 = 1 // lb_embed sentinel: /embed POST returned nothing 15const EGL_ERR_PARSE: i64 = 2 // lb_embed sentinel: response vector length != CI_NE 16 17func lb_body(mode: *u8, out: *u8) -> i64 { 18 var o: i64 = 0 19 let head: *u8 = "{\"text\":\"open a file and read all of its bytes\",\"task\":\"nl2code\",\"kind\":\"query\",\"mode\":\"" as *u8 20 var j: i64 = 0 21 while head[j] != (0 as u8) { out[o] = head[j]; o = o + 1; j = j + 1 } 22 j = 0 23 while mode[j] != (0 as u8) { out[o] = mode[j]; o = o + 1; j = j + 1 } 24 let tail: *u8 = "\"}" as *u8 25 j = 0 26 while tail[j] != (0 as u8) { out[o] = tail[j]; o = o + 1; j = j + 1 } 27 out[o] = 0 as u8 28 return o 29} 30 31func lb_embed(port: i64, mode: *u8, vec: *i64, resp: *u8, rescap: i64) -> i64 { 32 let body: *u8 = sys_mmap(EGL_BODY_CAP) as *u8 33 let bl: i64 = lb_body(mode, body) 34 let got: i64 = ci_post_embed(port, body, bl, resp, rescap) 35 if got <= 0 { return 0 - EGL_ERR_POST } 36 let nt: *i64 = sys_mmap(EGL_I64_BYTES) as *i64 37 let cnt: i64 = ci_parse_vec(resp, got, vec, nt) 38 if cnt != CI_NE { return 0 - EGL_ERR_PARSE } 39 return nt[0] 40} 41 42func main(argc: i64, argv: *i64) -> i64 { 43 var port: i64 = EGL_PORT_DEFAULT 44 if argc > 1 { 45 let a1: i64 = argv[1] 46 port = std_atoi(a1 as *u8) 47 } 48 ci_ws("[gpu-live-gate] /embed mode i8 vs gpu equality on 127.0.0.1:" as *u8) 49 std_pdec(port) 50 ci_ws("\n" as *u8) 51 let va: *i64 = sys_mmap(CI_NE * EGL_I64_BYTES) as *i64 52 let vb: *i64 = sys_mmap(CI_NE * EGL_I64_BYTES) as *i64 53 let ra: *u8 = sys_mmap(EGL_RESP_CAP) as *u8 54 let rb: *u8 = sys_mmap(EGL_RESP_CAP) as *u8 55 let t0: i64 = sys_now_ms() 56 let na: i64 = lb_embed(port, "i8" as *u8, va, ra, EGL_RESP_CAP) 57 let t1: i64 = sys_now_ms() 58 let nb: i64 = lb_embed(port, "gpu" as *u8, vb, rb, EGL_RESP_CAP) 59 let t2: i64 = sys_now_ms() 60 ci_kv("[T] ntok_i8" as *u8, na) 61 ci_kv("ntok_gpu" as *u8, nb) 62 ci_kv("ms_i8" as *u8, t1 - t0) 63 ci_kv("ms_gpu" as *u8, t2 - t1) 64 ci_ws("\n" as *u8) 65 if na < 1 { ci_ws("VERDICT RED (i8 arm failed)\n" as *u8); return 1 } 66 if nb < 1 { ci_ws("VERDICT RED (gpu arm failed -- server down? err in resp)\n" as *u8); sys_write(1, rb, EGL_ERRDUMP); return 1 } 67 var mm: i64 = 0 68 var i: i64 = 0 69 while i < CI_NE { if va[i] != vb[i] { mm = mm + 1 } i = i + 1 } 70 var lbl: i64 = 0 71 var rlen: i64 = 0 72 while rb[rlen] != (0 as u8) { rlen = rlen + 1 } 73 if ci_find(rb, rlen, "\"mode\":\"gpu\"" as *u8) >= 0 { lbl = 1 } 74 ci_kv("[T] mismatches" as *u8, mm) 75 ci_kv("gpu_label" as *u8, lbl) 76 ci_ws("\n" as *u8) 77 var green: i64 = 0 78 if na == nb { if mm == 0 { if lbl == 1 { green = 1 } } } 79 if green == 1 { 80 ci_ws("VERDICT GREEN embed-gpu-live (daemon /embed gpu == i8 BYTE-IDENTICAL vec + labeled)\n" as *u8) 81 return 0 82 } 83 ci_ws("VERDICT RED\n" as *u8) 84 return 1 85}