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 / tests / gpu_session_probe.c

72 lines · 3650 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/* gpu_session_probe: FB-1 cut 4b flake investigation (first-call device-open failure).
18 *
19 * One fresh process = one sample: open the shared device through the API's own
20 * path (omega_gpu_ex2_f32 on 128 values is the smallest launch there is), report
21 * the stage that failed (with the driver's own text) or the open time, exit 0/1.
22 *
23 * ./gpu_session_probe [--label L] [--calls N] [--hold-ms M]
24 * --calls N launches after the first (default 1); keeps the device busy for an overlap test
25 * --hold-ms M sleep M ms with the device open before exit (overlap window for a second probe)
26 *
27 * Output (one line, Astra's SNAP shape; every unknown says so):
28 * PROBE label=L pid=P rc=OK|CHIP_FAIL|... stage="..." first_call_ms=F open_ms=O calls_ok=K/N opens=1
29 * Never run outside the heavy queue (tools/probe_gpu_open.sh).
30 */
31#include "omega_gpu_elementwise_api.h"
32#include "omega_gpu_session.h"
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <time.h>
37#include <unistd.h>
38
39static double now_ms(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec * 1e3 + t.tv_nsec / 1e6; }
40
41int main(int argc, char **argv) {
42 const char *label = "probe"; int calls = 1, hold_ms = 0;
43 for (int i = 1; i < argc; i++) {
44 if (strcmp(argv[i], "--label") == 0 && i + 1 < argc) label = argv[++i];
45 else if (strcmp(argv[i], "--calls") == 0 && i + 1 < argc) calls = atoi(argv[++i]);
46 else if (strcmp(argv[i], "--hold-ms") == 0 && i + 1 < argc) hold_ms = atoi(argv[++i]);
47 else { fprintf(stderr, "unknown flag %s\n", argv[i]); return 2; }
48 }
49 float x[128], y[128];
50 for (int i = 0; i < 128; i++) { x[i] = (float)i / 16.0f - 4.0f; y[i] = 0.0f; }
51 OmegaGpuEwInfo info; memset(&info, 0, sizeof info);
52 double t0 = now_ms();
53 int rc = omega_gpu_ex2_f32(128, x, y, &info);
54 double first_ms = now_ms() - t0;
55 int ok = 0;
56 if (rc == OMEGA_GPU_EW_OK) {
57 /* negative control on the result itself: 2^0 must be 1 (x[64] = 0) */
58 if (y[64] < 0.999f || y[64] > 1.001f) { rc = OMEGA_GPU_EW_UNWRITTEN; omega_gpu_session_set_error("probe: 2^0 != 1"); }
59 else ok = 1;
60 }
61 int more_ok = 0;
62 for (int i = 1; i < calls && ok; i++) if (omega_gpu_ex2_f32(128, x, y, &info) == OMEGA_GPU_EW_OK) more_ok++;
63 if (hold_ms > 0) usleep((useconds_t)hold_ms * 1000u);
64 const char *stage = omega_gpu_elementwise_last_error();
65 printf("PROBE label=%s pid=%d rc=%s stage=\"%s\" first_call_ms=%.1f chip_us=%.1f calls_ok=%d/%d opens=%u%s\n",
66 label, (int)getpid(), omega_gpu_elementwise_rc_name(rc), stage[0] ? stage : "-", first_ms,
67 info.elapsed_ns / 1e3, ok + more_ok, calls, omega_gpu_session_open_count(),
68 rc == OMEGA_GPU_EW_OK && !stage[0] ? "" : (rc == OMEGA_GPU_EW_OK ? " note=stage_text_from_earlier_failure" : ""));
69 fflush(stdout);
70 omega_gpu_session_close(); /* the explicit close is part of what the next process sees */
71 return ok ? 0 : 1;
72}