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
omega-mv / evidence / OWN30B-REQUAL-MAIN-710d438c-20261015 / omega457 / fix-variant.diff
| 1 | diff --git a/Makefile b/Makefile |
| 2 | index 6a406f72..455c492b 100644 |
| 3 | --- a/Makefile |
| 4 | +++ b/Makefile |
| 5 | @@ -2462,6 +2462,12 @@ test-gpu-fp8: $(GPU_FP8_TEST) |
| 6 | ./$(GPU_FP8_TEST) --host-only |
| 7 | ./$(GPU_FP8_TEST) --sim |
| 8 | |
| 9 | +# omega #457 (2026-10-15): host rewrite of a GPU-cached buffer must be visible to the next launch. Chip only; the gate |
| 10 | +# is tools/run_gpu_l2_stale_chip.sh. |
| 11 | +GPU_L2_STALE_TEST = $(OUT_DIR)/gpu_l2_stale_test |
| 12 | +$(GPU_L2_STALE_TEST): tests/gpu_l2_stale_test.c src/omega_gpu_fp8_api.h src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a |
| 13 | + $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_l2_stale_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm |
| 14 | + |
| 15 | # OWN-30B cut 8 (2026-10-13): one-launch decode attention (omega_gpu_decode_attn_api.h). test-gpu-decode-attn is |
| 16 | # host-only + simulator; the chip gate is tools/run_gpu_decode_attn_chip.sh. |
| 17 | .PHONY: test-gpu-decode-attn |
| 18 | diff --git a/src/omega_gpu_platform_linux.c b/src/omega_gpu_platform_linux.c |
| 19 | index dc02aab4..620b7137 100644 |
| 20 | --- a/src/omega_gpu_platform_linux.c |
| 21 | +++ b/src/omega_gpu_platform_linux.c |
| 22 | @@ -31,6 +31,8 @@ typedef struct { |
| 23 | OmegaGpuHandleTable t; |
| 24 | NvrmMem mem[OMEGA_GPU_HANDLE_SLOTS]; |
| 25 | uint32_t rights[OMEGA_GPU_HANDLE_SLOTS]; |
| 26 | + uint8_t gpu_cached[OMEGA_GPU_HANDLE_SLOTS]; /* allocated GPU-cached (nvrm_alloc), omega #457 */ |
| 27 | + int l2_inval_pending; /* a host sync into a GPU-cached buffer since the last submission, omega #457 */ |
| 28 | M16NativeContext m16; |
| 29 | OmegaGpuDeviceHandle dev; /* generation 0 = closed */ |
| 30 | OmegaGpuQueueHandle queue; |
| 31 | @@ -157,6 +159,7 @@ static int ref_device_close(void *ctx, OmegaGpuDeviceHandle dev) { |
| 32 | (void)omega_gpu_handles_close(&r->t, i, r->t.generation[i], r->t.kind[i]); |
| 33 | memset(&r->mem[i], 0, sizeof r->mem[i]); |
| 34 | r->rights[i] = 0; |
| 35 | + r->gpu_cached[i] = 0; |
| 36 | } |
| 37 | (void)omega_gpu_handles_close(&r->t, dev.index, dev.generation, OMEGA_GPU_HANDLE_DEVICE); |
| 38 | memset(&r->dev, 0, sizeof r->dev); |
| 39 | @@ -198,6 +201,7 @@ static int ref_dma_alloc(void *ctx, OmegaGpuDeviceHandle dev, const OmegaGpuBuff |
| 40 | } |
| 41 | r->mem[idx] = m; |
| 42 | r->rights[idx] = desc->rights; |
| 43 | + r->gpu_cached[idx] = (uint8_t)cached; |
| 44 | out->index = idx; out->generation = gen; |
| 45 | cpu->ptr = m.cpu; cpu->len = (size_t)m.size; |
| 46 | gpu->va = m.va; |
| 47 | @@ -218,6 +222,7 @@ static int ref_dma_free(void *ctx, OmegaGpuBufferHandle b) { |
| 48 | (void)omega_gpu_handles_close(&r->t, b.index, b.generation, kind); |
| 49 | memset(&r->mem[b.index], 0, sizeof r->mem[b.index]); |
| 50 | r->rights[b.index] = 0; |
| 51 | + r->gpu_cached[b.index] = 0; |
| 52 | ref_unlock(r); |
| 53 | return OMEGA_GPU_PLAT_OK; |
| 54 | } |
| 55 | @@ -230,18 +235,22 @@ static void barrier(void) { |
| 56 | #endif |
| 57 | } |
| 58 | |
| 59 | -static int ref_sync(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint64_t len, const char *stage) { |
| 60 | +static int ref_sync(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint64_t len, const char *stage, int to_gpu) { |
| 61 | LinuxRef *r = ctx; |
| 62 | ref_lock(r); |
| 63 | int rc = buf_ok(r, b, NULL); |
| 64 | if (rc == OMEGA_GPU_PLAT_OK) rc = range_ok(r, b, off, len); |
| 65 | if (rc != OMEGA_GPU_PLAT_OK) rc = refuse(r, rc, stage); |
| 66 | + /* omega #457 (chip, 2026-10-15): after the host rewrites a GPU-cached buffer the GPU already read, every later launch |
| 67 | + * read the old bytes from L2 (nvos.h:1117 "For system memory this will not be coherent with direct CPU mappings"). |
| 68 | + * The next submission therefore starts with L2_SYSMEM_NCOH_INVALIDATE (ref_queue_submit). */ |
| 69 | + else if (to_gpu && r->gpu_cached[b.index]) r->l2_inval_pending = 1; |
| 70 | ref_unlock(r); |
| 71 | if (rc == OMEGA_GPU_PLAT_OK) barrier(); /* uncached system memory: a full barrier is the whole sync */ |
| 72 | return rc; |
| 73 | } |
| 74 | -static int ref_sync_to_gpu(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint64_t len) { return ref_sync(ctx, b, off, len, "sync_cpu_to_gpu"); } |
| 75 | -static int ref_sync_to_cpu(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint64_t len) { return ref_sync(ctx, b, off, len, "sync_gpu_to_cpu"); } |
| 76 | +static int ref_sync_to_gpu(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint64_t len) { return ref_sync(ctx, b, off, len, "sync_cpu_to_gpu", 1); } |
| 77 | +static int ref_sync_to_cpu(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint64_t len) { return ref_sync(ctx, b, off, len, "sync_gpu_to_cpu", 0); } |
| 78 | |
| 79 | static int ref_poll_word(void *ctx, OmegaGpuBufferHandle b, uint64_t off, uint32_t expected, uint64_t timeout_ms, uint32_t *observed) { |
| 80 | LinuxRef *r = ctx; |
| 81 | @@ -297,8 +306,24 @@ static int ref_queue_submit(void *ctx, OmegaGpuQueueHandle q, const uint32_t *wo |
| 82 | ref_lock(r); |
| 83 | int rc = queue_ok(r, q); |
| 84 | if (rc == OMEGA_GPU_PLAT_OK && (!words || nwords == 0u)) rc = OMEGA_GPU_PLAT_REFUSED_ARGS; |
| 85 | - if (rc == OMEGA_GPU_PLAT_OK && (uint64_t)nwords * 4u > r->m16.pb_mem.size) rc = OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH; |
| 86 | - if (rc == OMEGA_GPU_PLAT_OK && m16_native_submit_methods(&r->m16, words, nwords) != 0) rc = OMEGA_GPU_PLAT_REFUSED_DEVICE; |
| 87 | + /* omega #457: a host sync into a GPU-cached buffer is pending, so this submission starts with |
| 88 | + * MEM_OP_A..D = 0, 0, 0, OPERATION L2_SYSMEM_NCOH_INVALIDATE 0x11 in D bits 31:27 (clc96f.h:30-73), the same |
| 89 | + * method form as the C3 tail's L2_FLUSH_DIRTY. No dirty line is dropped: every earlier submission ended with |
| 90 | + * L2_FLUSH_DIRTY and the host waited for it. */ |
| 91 | + const uint32_t pre = r->l2_inval_pending ? 5u : 0u; |
| 92 | + if (rc == OMEGA_GPU_PLAT_OK && ((uint64_t)nwords + pre) * 4u > r->m16.pb_mem.size) rc = OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH; |
| 93 | + uint32_t *buf = NULL; |
| 94 | + if (rc == OMEGA_GPU_PLAT_OK && pre) { |
| 95 | + buf = malloc(((size_t)nwords + pre) * 4u); |
| 96 | + if (!buf) rc = OMEGA_GPU_PLAT_REFUSED_ARGS; |
| 97 | + else { |
| 98 | + buf[0] = (2u << 28) | (4u << 16) | (0x0028u >> 2); buf[1] = 0; buf[2] = 0; buf[3] = 0; buf[4] = 0x11u << 27; |
| 99 | + memcpy(buf + pre, words, (size_t)nwords * 4u); |
| 100 | + } |
| 101 | + } |
| 102 | + if (rc == OMEGA_GPU_PLAT_OK && m16_native_submit_methods(&r->m16, buf ? buf : words, nwords + pre) != 0) rc = OMEGA_GPU_PLAT_REFUSED_DEVICE; |
| 103 | + if (rc == OMEGA_GPU_PLAT_OK && pre) r->l2_inval_pending = 0; |
| 104 | + free(buf); |
| 105 | if (rc != OMEGA_GPU_PLAT_OK) rc = refuse(r, rc, "submit_methods"); |
| 106 | ref_unlock(r); |
| 107 | return rc; |