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/tests/runtime/r15_gpu_load.c # 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 / tests / runtime / r15_gpu_load.c` 149 lines ยท 5853 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 /* 18 * r15_gpu_load.c -- bounded GPU load for SPBM sensor validation (R15 C2). 19 * 20 * Starts the R12 resident seat on GB10 and, for the given number of seconds, 21 * feeds it claims back to back (publish A -> chip add -> B), checking every 22 * result. "idle" mode starts the seat and posts nothing (the seat's own 23 * polling loop only). No power limit, clock or firmware setting is touched. 24 * 25 * r15_gpu_load claims|idle SECONDS 26 * 27 * Prints one JSON line: mode, seconds, claims completed, wrong results. 28 */ 29 #include "runtime/aienos_cap.h" 30 #include "runtime/rx_resident_gpu.h" 31 #include "runtime/rx_world.h" 32 33 #include 34 #include 35 #include 36 #include 37 38 enum { SUBJ_SEAT = 3, SUBJ_EXTERNAL = 100, ISSUER = 3 }; 39 #define RES_A 0x10u 40 #define RES_B 0x20u 41 42 static AienosCapAdmin *g_admin; 43 44 static uint64_t now_ns(void) { 45 struct timespec ts; 46 clock_gettime(CLOCK_MONOTONIC, &ts); 47 return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; 48 } 49 50 static RxCapRef mint(uint32_t subject, uint64_t resource, uint32_t rights) { 51 AienosCapRef office, r = {UINT32_MAX, 0}; 52 aienos_cap_office(g_admin, &office); 53 AienosCapMint m = {ISSUER, subject, resource, rights, 0, {UINT32_MAX, 0}, office}; 54 if (aienos_cap_mint(g_admin, &m, &r) != 0) r = (AienosCapRef){UINT32_MAX, 0}; 55 return (RxCapRef){r.cap_id, r.generation}; 56 } 57 58 static int fn_never(RxCtx *c) { (void)c; return -1; } /* the seat is not a CPU call */ 59 60 static uint64_t field(RxWorld *w, RxObjRef r, uint32_t f) { 61 RxObject o; 62 return rx_world_read(w, r, &o) == RX_OK ? o.field[f] : UINT64_MAX; 63 } 64 65 int main(int argc, char **argv) { 66 if (argc != 3 || (strcmp(argv[1], "claims") && strcmp(argv[1], "idle"))) { 67 fprintf(stderr, "usage: r15_gpu_load claims|idle SECONDS\n"); 68 return 2; 69 } 70 long seconds = atol(argv[2]); 71 if (seconds < 1 || seconds > 60) return 2; 72 int claims = !strcmp(argv[1], "claims"); 73 AienosCapView *view = NULL; 74 static RxWorld w; 75 if (aienos_cap_start(&g_admin, &view) != 0) return 1; 76 if (rx_world_init_native(&w, view, 1, 1u << 20) != RX_OK) return 1; 77 w.external_subject = SUBJ_EXTERNAL; 78 uint64_t zero[RX_MAX_FIELDS] = {0}; 79 RxObjRef A, B; 80 if (rx_world_create(&w, 1, RX_PERSIST_RESIDENT, RES_A, zero, &A) != RX_OK || 81 rx_world_create(&w, 1, RX_PERSIST_RESIDENT, RES_B, zero, &B) != RX_OK || 82 rx_world_attach_physical(&w, A) != RX_OK || rx_world_attach_physical(&w, B) != RX_OK) 83 return 1; 84 RxCapRef in = mint(SUBJ_SEAT, RES_A, RX_RIGHT_READ); 85 RxCapRef out = mint(SUBJ_SEAT, RES_B, RX_RIGHT_READ | RX_RIGHT_WRITE); 86 RxCapRef ext = mint(SUBJ_EXTERNAL, RES_A, RX_RIGHT_WRITE); 87 if (rx_world_bind_capability(&w, A, in) != RX_OK || 88 rx_world_bind_capability(&w, B, out) != RX_OK || rx_world_enable_resident(&w) != RX_OK) 89 return 1; 90 RxResourceBudget b; 91 memset(&b, 0, sizeof b); 92 b.slots = 8; 93 b.memory_bytes = UINT64_MAX; 94 b.energy_budget = UINT64_MAX; 95 b.offered_locality = UINT32_MAX; 96 b.offered_accel = RX_ACCEL_BLACKWELL; 97 b.compute_mask = UINT32_MAX; 98 rx_world_set_resources(&w, &b); 99 RxReactionDesc d; 100 memset(&d, 0, sizeof d); 101 d.name = "resident.seat.add"; 102 d.faculty = RX_FACULTY_AEGIS; 103 d.subject = SUBJ_SEAT; 104 d.priority = RX_PRIO_FOREGROUND; 105 d.fn = fn_never; 106 d.need.accelerator_features = RX_ACCEL_BLACKWELL; 107 d.n_triggers = 1; 108 d.triggers[0] = (RxDep){A, RX_FIELD(0) | RX_FIELD(1)}; 109 d.n_writes = 1; 110 d.writes[0] = (RxDep){B, RX_FIELD(0)}; 111 d.n_caps = 2; 112 d.caps[0] = (RxCapNeed){in, RES_A, RX_RIGHT_READ}; 113 d.caps[1] = (RxCapNeed){out, RES_B, RX_RIGHT_WRITE}; 114 uint32_t seat_id = 0; 115 if (rx_world_add_reaction(&w, &d, &seat_id) != RX_OK) return 1; 116 RxGpuSeat *seat = NULL; 117 if (rx_gpu_seat_begin(&w, &seat) != 0 || !seat) return 1; 118 119 uint64_t done = 0, wrong = 0, start = now_ns(), end = start + (uint64_t)seconds * 1000000000ull; 120 int rc = 0; 121 while (now_ns() < end) { 122 if (!claims) { 123 struct timespec ts = {0, 10000000L}; 124 nanosleep(&ts, NULL); 125 continue; 126 } 127 uint64_t a0 = (done * 2654435761u) & 0x7fffffffu, a1 = (done + 7) & 0x7fffffffu; 128 RxMutation m[2] = {{A, 0, a0}, {A, 1, a1}}; 129 if (rx_world_publish_external(&w, ext, m, 2) <= 0) { rc = 1; break; } 130 uint64_t want = (uint32_t)(a0 + a1), t0 = now_ns(); 131 for (;;) { 132 int arc = rx_resident_accept(&w); 133 if (arc != RX_OK && arc != RX_ERR_NOT_FOUND) { rc = 1; break; } 134 if (rx_world_wait_quiescent(&w, 0) == RX_OK) break; 135 if (now_ns() - t0 > 2000000000ull) { rc = 1; break; } 136 } 137 if (rc) break; 138 if (field(&w, B, 0) != want) wrong++; 139 done++; 140 } 141 uint64_t took = now_ns() - start; 142 (void)rx_resident_shutdown(&w); 143 (void)rx_gpu_seat_finish(seat); 144 printf("{\"mode\":\"%s\",\"seconds\":%.3f,\"claims\":%llu,\"wrong\":%llu,\"error\":%d}\n", 145 argv[1], (double)took / 1e9, (unsigned long long)done, (unsigned long long)wrong, rc); 146 rx_world_destroy(&w); 147 aienos_cap_stop(g_admin, view); 148 return rc || wrong ? 1 : 0; 149 }