From caa77da759934edc97f5455d82ed45288412a3ad Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 19 Oct 2026 10:07:16 -0500 Subject: [PATCH 1/2] blackwell engine: keep the device and channel open between jobs (omega-mv#575) Measured on the Spark 2026-10-19 (bench/m1/block2_profile.c): of a 38.8 ms omega_gpu_execute job, open_device 7.5 ms, create_channel 19.2 ms, close 11.3 ms; the GPU work under 1 ms. Now the RM client, device and channel persist across jobs; per-job buffers and scratch are still allocated and freed per job and the engine state machine is unchanged. GPFIFO entries are retired at close so the ring never fills. OMEGA_GPU_ENGINE_NO_PERSIST=1 restores one open per job; omega_blackwell_engine_shutdown() closes on demand. The pushbuffer now invalidates the shader caches every launch (clcec0.h 0x021c), as the session path has since cut 1b: with the device kept open the next PROGRAM buffer can reuse the last address and the chip ran stale code; the no-store control in the gb10 chip test caught it (unchanged=0) before this line was added. Chip gate tests/test_omega_gpu_engine_gb10.c --chip: PASS persistent and NO_PERSIST (120 vector runs, no-store control detected). A/B, 65-element vecadd: 37.1 ms median before, 0.78 ms after (block2_persist_ab.csv). Host: sim 343/343 (9 new persistence cases), engine 49/49, backend mutants 107 killed 0 gaps. --- bench/m1/block2_gpu_submit.c | 54 +++++++++++++++++++ bench/m1/block2_profile.c | 45 ++++++++++++++++ src/omega_blackwell_engine.c | 81 ++++++++++++++++++++++++++++- src/omega_blackwell_engine.h | 6 +++ tests/test_omega_blackwell_engine.c | 42 +++++++++++++++ 5 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 bench/m1/block2_gpu_submit.c create mode 100644 bench/m1/block2_profile.c diff --git a/bench/m1/block2_gpu_submit.c b/bench/m1/block2_gpu_submit.c new file mode 100644 index 000000000..f18e773f4 --- /dev/null +++ b/bench/m1/block2_gpu_submit.c @@ -0,0 +1,54 @@ +/* M1 block 2 (omega-mv#575): GPU submit/complete round trip through omega_gpu_execute, + * the full lifecycle Omega runs per job (open, upload, submit, wait, readback, free, close). + * Reports wall per job (p50/p95/p99/max) and thread CPU time per job (the polling cost). + * Usage: block2 --chip [N] ; must run under flock /tmp/aien-gb10.lock. */ +#include +#include +#include +#include +#include +#include "omega_gpu_engine.h" +#include "omega_blackwell_engine.h" +#include "omega_blackwell_encoder.h" + +static double now(clockid_t c){struct timespec t;clock_gettime(c,&t);return t.tv_sec+t.tv_nsec*1e-9;} +static int cmpd(const void*a,const void*b){double x=*(const double*)a,y=*(const double*)b;return xy;} + +static int run_case(const char*label,uint32_t n,int no_store,long N){ + uint8_t code[OMEGA_BW_VECADD_CODE_SIZE];size_t code_bytes=0; + if(omega_blackwell_encode_vecadd(code,sizeof code,&code_bytes)||code_bytes<0x140u){fprintf(stderr,"encode fail\n");return 1;} + if(no_store)memcpy(code+0x120,code+0x130,OMEGA_BW_INSTRUCTION_BYTES); + uint32_t*a=malloc(n*4),*b=malloc(n*4),*out=malloc(n*4),*poison=malloc(n*4); + for(uint32_t i=0;i2?atol(argv[2]):1000; + omega_gpu_engine_set_backend(omega_blackwell_engine_backend()); + printf("case,elements,n_jobs,failed,wall_mean_us,wall_p50_us,wall_p95_us,wall_p99_us,wall_max_us,cpu_mean_us,cpu_over_wall\n"); + int r=0; + r|=run_case("vecadd_no_store",65,1,N); + r|=run_case("vecadd",65,0,N); + r|=run_case("vecadd",4096,0,N); + r|=run_case("vecadd",65537,0,N/4); + return r; +} diff --git a/bench/m1/block2_profile.c b/bench/m1/block2_profile.c new file mode 100644 index 000000000..d9515959c --- /dev/null +++ b/bench/m1/block2_profile.c @@ -0,0 +1,45 @@ +/* M1 block 2 profile (omega-mv#575): time each backend callback of the Blackwell engine + * by wrapping the real backend table. Run under flock /tmp/aien-gb10.lock. */ +#include +#include +#include +#include +#include +#include "omega_gpu_engine.h" +#include "omega_blackwell_engine.h" +#include "omega_blackwell_encoder.h" + +static const OmegaGpuBackend *R; +static double T[16]; static long N[16]; +static const char *NAMES[16]={"open_device","create_channel","alloc","copy_in","fill_poison","build","submit","wait_marker","wait_marker2","wait_release_semaphore","barrier","copy_out","diagnostics","free_buf","close"}; +static double now(void){struct timespec t;clock_gettime(CLOCK_MONOTONIC,&t);return t.tv_sec+t.tv_nsec*1e-9;} +#define W0(i,call) static int w_##i(void*c){double t=now();int r=R->call(R->ctx);T[i]+=now()-t;N[i]++;return r;} +#define W1(i,call,A,a) static int w_##i(void*c,A){double t=now();int r=R->call(R->ctx,a);T[i]+=now()-t;N[i]++;return r;} +W0(0,open_device) W0(1,create_channel) +static int w_2(void*c,int role,size_t b){double t=now();int r=R->alloc(R->ctx,role,b);T[2]+=now()-t;N[2]++;return r;} +static int w_3(void*c,int role,const void*s,size_t b){double t=now();int r=R->copy_in(R->ctx,role,s,b);T[3]+=now()-t;N[3]++;return r;} +static int w_4(void*c,const uint32_t*w,size_t n){double t=now();int r=R->fill_poison(R->ctx,w,n);T[4]+=now()-t;N[4]++;return r;} +static int w_5(void*c,const OmegaGpuJob*j){double t=now();int r=R->build(R->ctx,j);T[5]+=now()-t;N[5]++;return r;} +W0(6,submit) +W1(7,wait_marker,uint64_t ms,ms) W1(8,wait_marker2,uint64_t ms,ms) W1(9,wait_release_semaphore,uint64_t ms,ms) W1(10,barrier,uint64_t ms,ms) +static int w_11(void*c,void*d,size_t b){double t=now();int r=R->copy_out(R->ctx,d,b);T[11]+=now()-t;N[11]++;return r;} +static void w_12(void*c,OmegaGpuBackendDiag*d){double t=now();R->diagnostics(R->ctx,d);T[12]+=now()-t;N[12]++;} +static int w_13(void*c,int role){double t=now();int r=R->free_buf(R->ctx,role);T[13]+=now()-t;N[13]++;return r;} +W0(14,close) + +int main(int argc,char**argv){ + if(argc<2||strcmp(argv[1],"--chip")){puts("NOT_RUN");return 2;} + long NJ=argc>2?atol(argv[2]):50; + R=omega_blackwell_engine_backend(); + OmegaGpuBackend B={0};B.ctx=(void*)1;B.open_device=w_0;B.create_channel=w_1;B.alloc=w_2;B.copy_in=w_3;B.fill_poison=w_4;B.build=w_5;B.submit=w_6;B.wait_marker=w_7;B.wait_marker2=w_8;B.wait_release_semaphore=w_9;B.barrier=w_10;B.copy_out=w_11;B.diagnostics=w_12;B.free_buf=w_13;B.close=w_14; + omega_gpu_engine_set_backend(&B); + uint8_t code[OMEGA_BW_VECADD_CODE_SIZE];size_t cb=0;omega_blackwell_encode_vecadd(code,sizeof code,&cb); + uint32_t n=65,a[65],b[65],out[65],poison[65];for(uint32_t i=0;i #include #include +#include #include #include @@ -94,6 +95,27 @@ typedef struct { static BeCtx g_be; static atomic_flag g_busy = ATOMIC_FLAG_INIT; +/* Persistent device (omega-mv#575, measured 2026-10-19 on the Spark): of 38.8 ms per + * omega_gpu_execute job, open_device took 7.5 ms, create_channel 19.2 ms and close + * 11.3 ms; the work itself (alloc, copy, submit, wait, readback, free) under 1 ms. + * So the RM client, device and channel stay open between jobs. Per-job buffers and + * the scratch are still allocated and freed per job (the engine's state machine is + * unchanged). A full close happens when the driver reports a fault, when + * omega_blackwell_engine_shutdown() is called, or when OMEGA_GPU_ENGINE_NO_PERSIST=1 + * is set in the environment (the old one-open-per-job behaviour, for A/B runs). + * A retained run (uncertain completion) never reaches be_close, as before. */ +/* nvrm_retire lives in physics/nvrm/nvrm.c; the simulated-driver host build + * (tests/fake_m16_native.c) links no nvrm, so the reference is weak there. */ +extern void nvrm_retire(Nvrm *rm, uint32_t upto) __attribute__((weak)); +static int g_dev_open; /* m16_native_open succeeded and was not closed */ +static int g_chan_open; /* m16_native_create_channel succeeded on that device */ + +static int persist_enabled(void) +{ + const char *e = getenv("OMEGA_GPU_ENGINE_NO_PERSIST"); + return !(e && e[0] == '1'); +} + static uint64_t now_ns(void) { struct timespec t; @@ -224,16 +246,31 @@ static const uint32_t BE_SETUP_WORDS[18] = { static int be_open_device(void *ctx) { BeCtx *c = (BeCtx *)ctx; + M16NativeContext keep; + int reuse; int rc; if (atomic_flag_test_and_set(&g_busy)) return -1; /* another run is active; touch nothing */ + reuse = g_dev_open && persist_enabled() && !c->m.rm.faulted; + if (g_dev_open && !reuse) { + /* persistence off, or the driver faulted: close the old device first */ + (void)m16_native_close(&c->m); + g_dev_open = 0; + g_chan_open = 0; + } + keep = c->m; memset(c, 0, sizeof *c); c->native_open = 1; + if (reuse) { + c->m = keep; /* the open device and channel carry over; every per-job field is fresh */ + return 0; + } rc = m16_native_open(&c->m); /* SUB@676f16f line 45 */ if (rc != 0) { c->last_rc = rc; atomic_flag_clear(&g_busy); /* native open already cleaned up after itself (m16_native.c:15-21) */ return rc; } + g_dev_open = 1; return 0; } @@ -242,8 +279,10 @@ static int be_create_channel(void *ctx) BeCtx *c = (BeCtx *)ctx; int rc; begin(c); + if (g_chan_open) return 0; /* persistent channel from an earlier job */ rc = m16_native_create_channel(&c->m); /* SUB@676f16f line 46 */ c->last_rc = rc; + if (rc == 0) g_chan_open = 1; return rc; } @@ -414,6 +453,16 @@ static int be_build(void *ctx, const OmegaGpuJob *job) /* 1. setup words (18) */ pb_copy(c, BE_SETUP_WORDS, 18u); + /* 1b. invalidate the shader instruction, data and constant caches (clcec0.h + * NVCEC0_INVALIDATE_SHADER_CACHES 0x021c). With the device kept open between + * jobs (omega-mv#575) the PROGRAM buffer of the next job can land at the + * address of the last one, and the chip then ran the OLD code from its + * instruction cache: the no-store control in tests/test_omega_gpu_engine_gb10.c + * caught it on the Spark 2026-10-19 (unchanged=0). The session path has done + * this every launch since cut 1b (src/omega_gpu_session.c). */ + pb_put(c, nvrm_mthd(1, OMEGA_BW_MTHD_INVALIDATE_SHADER_CACHES, 1)); + pb_put(c, OMEGA_BW_INVALIDATE_SHADER_CACHES_ALL); + /* 2. driver constant bank upload (224 words by DMA) */ pb_put(c, nvrm_mthd(1, 0x0188, 2)); pb_put(c, (uint32_t)(c->cbank.va >> 32)); @@ -638,17 +687,47 @@ static int be_free_buf(void *ctx, int role) static int be_close(void *ctx) { BeCtx *c = (BeCtx *)ctx; - int rc; + int rc = 0; begin(c); c->hmarker = NULL; c->hmarker2 = NULL; c->hsem = NULL; + if (g_dev_open && persist_enabled() && !c->m.rm.faulted) { + /* Keep the device and channel. The job's GPFIFO entries are complete (the + * engine only reaches close after the completion waits or on a failure before + * submit), so retire them; the ring never fills across jobs. */ + if (nvrm_retire) nvrm_retire(&c->m.rm, c->m.rm.put); + atomic_flag_clear(&g_busy); + return 0; + } rc = m16_native_close(&c->m); /* SUB@676f16f line 225 */ c->last_rc = rc; + g_dev_open = 0; + g_chan_open = 0; atomic_flag_clear(&g_busy); return rc; } +int omega_blackwell_engine_shutdown(void) +{ + BeCtx *c = &g_be; + int rc; + if (atomic_flag_test_and_set(&g_busy)) + return -1; /* a run is active (or retained): leave it */ + if (!g_dev_open) { atomic_flag_clear(&g_busy); return 0; } + rc = m16_native_close(&g_be.m); + g_dev_open = 0; + g_chan_open = 0; + memset(c, 0, sizeof(BeCtx)); + atomic_flag_clear(&g_busy); + return rc; +} + +int omega_blackwell_engine_device_is_open(void) +{ + return g_dev_open; +} + static const OmegaGpuBackend g_backend = { &g_be, be_open_device, diff --git a/src/omega_blackwell_engine.h b/src/omega_blackwell_engine.h index 31948b06a..b2e931f24 100644 --- a/src/omega_blackwell_engine.h +++ b/src/omega_blackwell_engine.h @@ -65,6 +65,12 @@ typedef struct { * the backend's static context; callers must not touch it. */ const OmegaGpuBackend *omega_blackwell_engine_backend(void); +/* The device and channel stay open between jobs (omega-mv#575). This closes them + * when no run is active; returns 0 (closed or nothing open), -1 when a run is + * active or retained. OMEGA_GPU_ENGINE_NO_PERSIST=1 restores one open per job. */ +int omega_blackwell_engine_shutdown(void); +int omega_blackwell_engine_device_is_open(void); + /* Copies the snapshot of the most recent run into *out. Reset at every open. */ void omega_blackwell_engine_run_info(OmegaBlackwellEngineRunInfo *out); diff --git a/tests/test_omega_blackwell_engine.c b/tests/test_omega_blackwell_engine.c index c45ae23da..2fc010651 100644 --- a/tests/test_omega_blackwell_engine.c +++ b/tests/test_omega_blackwell_engine.c @@ -230,6 +230,7 @@ static void make_job(OmegaGpuJob *j) static void begin_case(void) { + (void)omega_blackwell_engine_shutdown(); /* no device carried between cases */ fake_reset(); omega_gpu_engine_test_reset_block(); omega_gpu_engine_set_backend(&g_wrap); @@ -979,8 +980,48 @@ static void case_vector(void) check("sim_vec_works_again", rc == 0 && output_correct(c)); } +/* omega-mv#575: the device and channel stay open between jobs (default). Measured + * on the Spark: open 7.5 ms + channel 19.2 ms + close 11.3 ms of a 38.8 ms job. */ +static void case_persistent_device(void) +{ + int rc1, rc2, rc3, ok1, ok2; + unsetenv("OMEGA_GPU_ENGINE_NO_PERSIST"); + begin_case(); + rc1 = run(); + ok1 = output_correct(outbuf); + memset(outbuf, 0, sizeof outbuf); + rc2 = run(); + ok2 = output_correct(outbuf); + check("sim_persist_two_jobs_ok", rc1 == OMEGA_GPU_ENGINE_OK && ok1 && rc2 == OMEGA_GPU_ENGINE_OK && ok2); + check("sim_persist_one_open_one_channel_no_close", + fk.open_calls == 1 && fk.channel_calls == 1 && fk.close_calls == 0 && fk.device_open == 1); + check("sim_persist_device_reported_open", omega_blackwell_engine_device_is_open() == 1); + check("sim_persist_per_job_buffers_still_freed", fk.free_calls == 2 * 8 && fk.double_free == 0); + check("sim_persist_shutdown_closes", omega_blackwell_engine_shutdown() == 0 && fk.close_calls == 1 && + fk.device_open == 0 && omega_blackwell_engine_device_is_open() == 0); + check("sim_persist_shutdown_idempotent", omega_blackwell_engine_shutdown() == 0 && fk.close_calls == 1); + memset(outbuf, 0, sizeof outbuf); + rc3 = run(); + check("sim_persist_reopens_after_shutdown", rc3 == OMEGA_GPU_ENGINE_OK && output_correct(outbuf) && + fk.open_calls == 2 && fk.channel_calls == 2); + /* a job that fails at submit leaves the next job able to run */ + fk.submit_fail = 1; + rc3 = run(); + check("sim_persist_fault_run_fails", rc3 != OMEGA_GPU_ENGINE_OK); + fk.submit_fail = 0; + memset(outbuf, 0, sizeof outbuf); + rc3 = run(); + check("sim_persist_recovers_after_fault", rc3 == OMEGA_GPU_ENGINE_OK && output_correct(outbuf)); + (void)omega_blackwell_engine_shutdown(); + setenv("OMEGA_GPU_ENGINE_NO_PERSIST", "1", 1); +} + int main(void) { + /* The cases above case_persistent_device() check the one-open-per-job lifecycle + * (opened and closed twice, balanced frees, close unmaps the sync words). They run + * with persistence off; case_persistent_device() then checks the default. */ + setenv("OMEGA_GPU_ENGINE_NO_PERSIST", "1", 1); init_data(); wrap_init(); omega_gpu_engine_test_set_clock(fake_now_ms); @@ -1001,6 +1042,7 @@ int main(void) case_table_guards(); case_close_unmaps_sync_words(); case_vector(); + case_persistent_device(); omega_gpu_engine_set_backend(NULL); omega_gpu_engine_test_reset_block(); From 578c9df7bad86dcd3e54aca1e7f8f278e9a34173 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 30 Oct 2026 09:56:12 -0500 Subject: [PATCH 2/2] gpu engine sim: check the per-launch shader-cache invalidate and the close on a driver fault (omega-mv#575) Two persistence protections had no host check: the INVALIDATE_SHADER_CACHES packet (0x021c, ALL) that stops a kept device running a stale PROGRAM buffer, and the full close when the driver reports a fault. The fake driver gains submit_faults_device (a failed submit also sets rm.faulted); the sim test walks the submitted pushbuffer for exactly one invalidate packet and checks that a faulting job closes the device and the next job opens a fresh one. Mutants killed: invalidate value 0 (1 check), faulted guard dropped (2 checks). --- .crumb | 24 +++++++++---------- src/.crumb | 8 +++---- tests/.crumb | 8 +++---- tests/fake_m16_native.c | 1 + tests/fake_m16_native.h | 1 + tests/test_omega_blackwell_engine.c | 37 +++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/.crumb b/.crumb index f3e51fe46..09fae7f42 100644 --- a/.crumb +++ b/.crumb @@ -72,38 +72,38 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", - "last_commit": "bf54b19fa", + "digest": "feb6478264bf22ff85d95b7f0c54d2dbb0ae24a85455517573e304fa3eeeb8e3", + "last_commit": "caa77da75", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "digest": "62d335692f175721e7803e4688c4d127c03fa0dc71e6c1953f6d6ce937bbde5f", + "last_commit": "caa77da75", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "children_root": "sha256:4557907655fd250719471fde5f94dc3df22eba9771c424a143c4e57a4d819335", + "compiled_at": "2026-10-30T14:56:09Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", + "digest": "sha256:8b37f90421b2735c33c60d8c0850d54fa11a7e2b97b3bae1d739cf9a7436d98a", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "files": 17851, + "generated_at_commit": "caa77da759934edc97f5455d82ed45288412a3ad", + "source_tree": "sha256:35158f9002b82cd89e9c41a9294a2750a24603c63f10ab7592b415972a35d3bc" }, "owner_lane": "", "provenance": { diff --git a/src/.crumb b/src/.crumb index 7c4b83da7..7e30ca1af 100644 --- a/src/.crumb +++ b/src/.crumb @@ -188,14 +188,14 @@ } ], "children_root": "sha256:2f729945214be989a74d7c2064ae4ba3c2deb52ebea3f334b459198a7bd032ed", - "compiled_at": "2026-10-30T02:49:13Z", + "compiled_at": "2026-10-30T14:56:09Z", "compiler": "crumb-compile/1", - "digest": "sha256:aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", + "digest": "sha256:feb6478264bf22ff85d95b7f0c54d2dbb0ae24a85455517573e304fa3eeeb8e3", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 568, - "generated_at_commit": "2cb1ccb5d3c1a1ce1cb94a7a3dd3c221395c4e15", - "source_tree": "sha256:7f1fef46a27e8baf5cf567bb590d417ede3767c5f07e714d0f0812af0645bb4b" + "generated_at_commit": "caa77da759934edc97f5455d82ed45288412a3ad", + "source_tree": "sha256:c4fb00f64bf93366b36abb0244b4955c76605a691da77d27c7c5f81c7391985e" }, "owner_lane": "", "provenance": { diff --git a/tests/.crumb b/tests/.crumb index 5fbfcb29c..775f2f867 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -302,14 +302,14 @@ } ], "children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902", - "compiled_at": "2026-10-30T12:31:50Z", + "compiled_at": "2026-10-30T14:56:09Z", "compiler": "crumb-compile/1", - "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", + "digest": "sha256:62d335692f175721e7803e4688c4d127c03fa0dc71e6c1953f6d6ce937bbde5f", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", "files": 1386, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679" + "generated_at_commit": "caa77da759934edc97f5455d82ed45288412a3ad", + "source_tree": "sha256:8e352af0493d87e9eb9692025cc2e4174e3c5082185c332743b8e03e3d399bae" }, "owner_lane": "", "provenance": { diff --git a/tests/fake_m16_native.c b/tests/fake_m16_native.c index f9ce918fb..54f204c26 100644 --- a/tests/fake_m16_native.c +++ b/tests/fake_m16_native.c @@ -414,6 +414,7 @@ int m16_native_submit_methods(M16NativeContext *ctx, const uint32_t *methods, si if (!ctx || !methods || count == 0) return -1; fk.submit_calls++; logev(FK_EV_SUBMIT, count, 0, 0); + if (fk.submit_fail && fk.submit_faults_device) ctx->rm.faulted = 1; if (!fk.channel_up || fk.submit_fail) return inject(&ctx->rm, -1); /* Like m16_native_enqueue_methods: the words must fit the ring buffer. */ if (count > ctx->pb_mem.size / sizeof(uint32_t) || count > FK_PB_MAX) return inject(&ctx->rm, -1); diff --git a/tests/fake_m16_native.h b/tests/fake_m16_native.h index cc5b4a6bc..cdb48ee87 100644 --- a/tests/fake_m16_native.h +++ b/tests/fake_m16_native.h @@ -98,6 +98,7 @@ typedef struct { int open_fail; int channel_fail; int submit_fail; + int submit_faults_device; /* with submit_fail: the failed submit also sets rm.faulted, as a channel error does */ int close_fail; uint64_t alloc_max; /* largest nvrm_alloc the fake grants, 0 = the default 1 MiB */ int alloc_fail_nth; /* 1-based nvrm_alloc call that misbehaves, 0 = none */ diff --git a/tests/test_omega_blackwell_engine.c b/tests/test_omega_blackwell_engine.c index 2fc010651..5d79271fb 100644 --- a/tests/test_omega_blackwell_engine.c +++ b/tests/test_omega_blackwell_engine.c @@ -980,6 +980,27 @@ static void case_vector(void) check("sim_vec_works_again", rc == 0 && output_correct(c)); } +/* Packets in the last submitted pushbuffer that invalidate all shader caches + * (subchannel 1, method 0x021c, one data word = OMEGA_BW_INVALIDATE_SHADER_CACHES_ALL). + * Walks packet headers like the fake's parser, so a data word never counts as a header. */ +static int pb_shader_invalidates(void) +{ + size_t i = 0; + int hits = 0; + while (i < fk.pb_len) { + uint32_t h = fk.pb[i++]; + uint32_t cnt = (h >> 16) & 0x1fffu; + uint32_t subc = (h >> 13) & 7u; + uint32_t mthd = (h & 0xfffu) << 2; + if (i + cnt > fk.pb_len) return -1; + if (subc == 1u && mthd == OMEGA_BW_MTHD_INVALIDATE_SHADER_CACHES && cnt == 1u && + fk.pb[i] == OMEGA_BW_INVALIDATE_SHADER_CACHES_ALL) + hits++; + i += cnt; + } + return hits; +} + /* omega-mv#575: the device and channel stay open between jobs (default). Measured * on the Spark: open 7.5 ms + channel 19.2 ms + close 11.3 ms of a 38.8 ms job. */ static void case_persistent_device(void) @@ -996,6 +1017,10 @@ static void case_persistent_device(void) check("sim_persist_one_open_one_channel_no_close", fk.open_calls == 1 && fk.channel_calls == 1 && fk.close_calls == 0 && fk.device_open == 1); check("sim_persist_device_reported_open", omega_blackwell_engine_device_is_open() == 1); + /* the PROGRAM buffer of the second job can reuse the first job's address on the kept + * device, so every launch must invalidate the shader caches (the chip ran stale code + * without it, 2026-10-19) */ + check("sim_persist_pushbuffer_invalidates_shader_caches", pb_shader_invalidates() == 1); check("sim_persist_per_job_buffers_still_freed", fk.free_calls == 2 * 8 && fk.double_free == 0); check("sim_persist_shutdown_closes", omega_blackwell_engine_shutdown() == 0 && fk.close_calls == 1 && fk.device_open == 0 && omega_blackwell_engine_device_is_open() == 0); @@ -1012,6 +1037,18 @@ static void case_persistent_device(void) memset(outbuf, 0, sizeof outbuf); rc3 = run(); check("sim_persist_recovers_after_fault", rc3 == OMEGA_GPU_ENGINE_OK && output_correct(outbuf)); + /* a job whose submit faults the driver closes the device; the next job opens a fresh one */ + fk.submit_fail = 1; + fk.submit_faults_device = 1; + rc3 = run(); + check("sim_persist_driver_fault_closes_device", rc3 != OMEGA_GPU_ENGINE_OK && fk.close_calls == 2 && + fk.device_open == 0 && omega_blackwell_engine_device_is_open() == 0); + fk.submit_fail = 0; + fk.submit_faults_device = 0; + memset(outbuf, 0, sizeof outbuf); + rc3 = run(); + check("sim_persist_fresh_open_after_driver_fault", rc3 == OMEGA_GPU_ENGINE_OK && output_correct(outbuf) && + fk.open_calls == 3 && fk.channel_calls == 3); (void)omega_blackwell_engine_shutdown(); setenv("OMEGA_GPU_ENGINE_NO_PERSIST", "1", 1); }