interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / nvrm / submission_visibility_gates.c

89 lines · 3924 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Real-device regression for CPU-published queue entries and rewritten
3 * command buffers. No CUDA runtime; run under the shared chip queue.
4 * The unfixed allocator stalls on the second submission on GB10.
5 */
6#include "m16_native.h"
7#include "cpu_barrier.h"
8/* The pass/fail predicates (word count, pre-notification control, positive
9 * wait, slot retired before reuse) come from om/engine/eng.om (ops VIS and
10 * REQF, src/omega_eng_gates.h); the C oracle is behind
11 * CUDAPP_MIGRATION_PENDING_C_VISIBILITY. */
12#if defined(CUDAPP_MIGRATION_PENDING_C_VISIBILITY)
13#define ENG_C_PART 1
14#endif
15#include "omega_eng_gates.h"
16#include "omega_fixture_rest.h"
17
18#include <inttypes.h>
19#include <stdio.h>
20#include <string.h>
21
22static int run_sequence(int reuse) {
23 M16NativeContext ctx;
24 if (m16_native_open(&ctx) != 0) {
25 fprintf(stderr, "visibility: open failed\n");
26 return 0;
27 }
28 int ok = 0;
29 NvrmMem completion;
30 if (m16_native_create_channel(&ctx) != 0 ||
31 nvrm_alloc_gpu_uncached(&ctx.rm, 4096, &completion) != 0)
32 goto finish;
33 volatile uint32_t *marker = completion.cpu;
34 *marker = 0;
35 nvrm_cpu_barrier();
36 uint32_t count = (uint32_t)omega_fixture_calc(FR_COUNT, (uint64_t)reuse, ctx.rm.entries, 0);
37 for (uint32_t payload = 1; payload <= count; ++payload) {
38 uint32_t methods[32];
39 int words = m16_native_build_release(methods, completion.va,
40 payload, ctx.rm.compute_class);
41 if (!omega_gate_reqf(OMEGA_REQF_WORDS, words)) goto finish;
42 if (reuse) {
43 /* Previous use is retired before the next call overwrites slot 0. */
44 if (!omega_gate_vis(OMEGA_VIS_RETIRED, ctx.rm.put, ctx.rm.retired, 0u) ||
45 m16_native_enqueue_methods(&ctx, methods, (size_t)words) != 0)
46 goto finish;
47 } else {
48 uint32_t offset = (uint32_t)omega_fixture_calc(FR_OFFSET, payload, 0, 0);
49 memcpy((unsigned char *)ctx.pb_mem.cpu + offset, methods,
50 (size_t)omega_fixture_calc(FR_BYTES, (uint64_t)words, 0, 0));
51 nvrm_cpu_barrier();
52 if (nvrm_enqueue(&ctx.rm, &ctx.pb_mem, offset, (uint32_t)words) != 0)
53 goto finish;
54 }
55 if (payload == 1) {
56 /* Negative control: no notification, no completed work. */
57 int wrc = m16_native_wait_marker_ge(marker, payload, 5);
58 if (!omega_gate_vis(OMEGA_VIS_NEGATIVE, (uint64_t)(int64_t)wrc, *marker, 0u)) {
59 fprintf(stderr, "visibility: pre-notification control failed\n");
60 goto finish;
61 }
62 }
63 m16_native_ring_doorbell(&ctx);
64 int prc = m16_native_wait_marker_ge(marker, payload, 5000);
65 if (!omega_gate_vis(OMEGA_VIS_POSITIVE, (uint64_t)(int64_t)prc, *marker, payload)) {
66 fprintf(stderr, "VISIBILITY_FAIL reuse=%d expected=%" PRIu32
67 " observed=%" PRIu32 " put=%" PRIu32 " retired=%" PRIu32 "\n",
68 reuse, payload, *marker, ctx.rm.put, ctx.rm.retired);
69 goto finish;
70 }
71 nvrm_retire(&ctx.rm, ctx.rm.put);
72 }
73 printf("visibility: reuse=%d submissions=%" PRIu32
74 " ring_capacity=%" PRIu32 " final_marker=%" PRIu32 "\n",
75 reuse, count, ctx.rm.entries, *marker);
76 ok = 1;
77finish:
78 /* Tear down the channel before freeing memory, including failure paths. */
79 if (m16_native_close(&ctx) != 0) ok = 0;
80 return ok;
81}
82
83int main(void) {
84 int distinct = run_sequence(0);
85 printf("[%s] SUBMISSION_VISIBILITY_DISTINCT_COMMANDS\n", distinct ? "PASS" : "FAIL");
86 int reuse = run_sequence(1);
87 printf("[%s] SUBMISSION_VISIBILITY_REUSE_AND_RING_WRAP\n", reuse ? "PASS" : "FAIL");
88 return !omega_fixture_calc(FR_BOTH, (uint64_t)distinct, (uint64_t)reuse, 0);
89}