interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

branch main Branches Tags History

physics-mv / nvrm / submission_visibility_gates.c

77 lines · 3139 bytes Raw Blame History
1/* Real-device regression for CPU-published queue entries and rewritten
2 * command buffers. No CUDA runtime; run under the shared chip queue.
3 * The unfixed allocator stalls on the second submission on GB10.
4 */
5#include "m16_native.h"
6
7#include <inttypes.h>
8#include <stdio.h>
9#include <string.h>
10
11static int run_sequence(int reuse) {
12 M16NativeContext ctx;
13 if (m16_native_open(&ctx) != 0) {
14 fprintf(stderr, "visibility: open failed\n");
15 return 0;
16 }
17 int ok = 0;
18 NvrmMem completion;
19 if (m16_native_create_channel(&ctx) != 0 ||
20 nvrm_alloc_gpu_uncached(&ctx.rm, 4096, &completion) != 0)
21 goto finish;
22 volatile uint32_t *marker = completion.cpu;
23 *marker = 0;
24 __asm__ volatile("dsb sy" ::: "memory");
25 uint32_t count = reuse ? ctx.rm.entries * 2 + 3 : 2;
26 for (uint32_t payload = 1; payload <= count; ++payload) {
27 uint32_t methods[32];
28 int words = m16_native_build_release(methods, completion.va,
29 payload, ctx.rm.compute_class);
30 if (words <= 0) goto finish;
31 if (reuse) {
32 /* Previous use is retired before the next call overwrites slot 0. */
33 if (ctx.rm.put != ctx.rm.retired ||
34 m16_native_enqueue_methods(&ctx, methods, (size_t)words) != 0)
35 goto finish;
36 } else {
37 uint32_t offset = (payload - 1) * 128;
38 memcpy((unsigned char *)ctx.pb_mem.cpu + offset, methods,
39 (size_t)words * sizeof(uint32_t));
40 __asm__ volatile("dsb sy" ::: "memory");
41 if (nvrm_enqueue(&ctx.rm, &ctx.pb_mem, offset, (uint32_t)words) != 0)
42 goto finish;
43 }
44 if (payload == 1) {
45 /* Negative control: no notification, no completed work. */
46 if (m16_native_wait_marker_ge(marker, payload, 5) == 0 || *marker != 0) {
47 fprintf(stderr, "visibility: pre-notification control failed\n");
48 goto finish;
49 }
50 }
51 m16_native_ring_doorbell(&ctx);
52 if (m16_native_wait_marker_ge(marker, payload, 5000) != 0 ||
53 *marker != payload) {
54 fprintf(stderr, "VISIBILITY_FAIL reuse=%d expected=%" PRIu32
55 " observed=%" PRIu32 " put=%" PRIu32 " retired=%" PRIu32 "\n",
56 reuse, payload, *marker, ctx.rm.put, ctx.rm.retired);
57 goto finish;
58 }
59 nvrm_retire(&ctx.rm, ctx.rm.put);
60 }
61 printf("visibility: reuse=%d submissions=%" PRIu32
62 " ring_capacity=%" PRIu32 " final_marker=%" PRIu32 "\n",
63 reuse, count, ctx.rm.entries, *marker);
64 ok = 1;
65finish:
66 /* Tear down the channel before freeing memory, including failure paths. */
67 if (m16_native_close(&ctx) != 0) ok = 0;
68 return ok;
69}
70
71int main(void) {
72 int distinct = run_sequence(0);
73 printf("[%s] SUBMISSION_VISIBILITY_DISTINCT_COMMANDS\n", distinct ? "PASS" : "FAIL");
74 int reuse = run_sequence(1);
75 printf("[%s] SUBMISSION_VISIBILITY_REUSE_AND_RING_WRAP\n", reuse ? "PASS" : "FAIL");
76 return distinct && reuse ? 0 : 1;
77}