Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/nvrm/live_marker_test.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / nvrm / live_marker_test.c` 70 lines · 3929 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* HOST_ONLY: omega_gpu_live_marker (nvrm/nvrm.c) on fake-RM memfd pages mapped through the native client, as 3 * nvrm/submit_test.c maps them. Never nvrm_open(), never a GPU. Checks: the right Nvrm returns its own mapping, 4 * offset and transport context, and the platform's marker poll (plat_wait_ge, a second generated runtime) reads the 5 * word through that context; a foreign Nvrm has no owner for the address and its context refuses the token; NULL rm, 6 * NULL outputs, an out-of-range and a quarantined address are refused with *ctx NULL. */ 7 #include "nvrm.c" 8 #include 9 10 uint32_t omega2_ctx_plat_wait_ge(struct omega_native_context *context, uint64_t *result, uint64_t o_handle, 11 uint64_t o_off, uint64_t o_want, uint64_t o_polls); 12 13 enum { PAGE = 0x10000 }; 14 15 static void *map_page(Nvrm *rm, uintptr_t at) { 16 int fd = memfd_create("cudapp-live-marker-fixture", MFD_CLOEXEC); 17 assert(fd >= 0 && ftruncate(fd, PAGE) == 0); 18 void *p = (void *)at; 19 assert(nvrm_cpu_reserve(rm, at, PAGE) == p); 20 assert(nvrm_cpu_map(rm, fd, PAGE, p) == p); 21 rm->live[rm->live_count] = (NvrmLiveAlloc){.va = at, .size = PAGE, .cpu = p, .cpu_live = 1}; 22 nvrm_mapping_transfer(rm, &rm->live[rm->live_count]); 23 assert(rm->live[rm->live_count].omega_mapping); 24 rm->live_count++; 25 return p; 26 } 27 28 int main(void) { 29 static Nvrm rm, other; 30 uint8_t *page = map_page(&rm, (uintptr_t)UINT64_C(0x7000200000)); 31 uint8_t *opage = map_page(&other, (uintptr_t)UINT64_C(0x7000300000)); 32 assert(rm.omega_context && other.omega_context && rm.omega_context != other.omega_context); 33 34 /* The right context: token, offset and rm's own transport context. */ 35 uint64_t tk = 0, of = 0, r = 0; 36 struct omega_native_context *ctx = NULL; 37 assert(omega_gpu_live_marker(&rm, page + 0x40, &tk, &of, &ctx) == 0); 38 assert(tk == rm.live[0].omega_mapping && of == 0x40 && ctx == rm.omega_context); 39 /* The platform poll reads the marker through it: ready at the value, not ready one past (wrap-aware >=). */ 40 *(volatile uint32_t *)(page + 0x40) = 0x6a5a5a5au; 41 assert(omega2_ctx_plat_wait_ge(ctx, &r, tk, of, 0x6a5a5a5au, 1) == 0 && (int64_t)r == 0); 42 assert(omega2_ctx_plat_wait_ge(ctx, &r, tk, of, 0x6a5a5a5bu, 1) == 0 && (int64_t)r == -1); 43 44 /* A foreign Nvrm owns no mapping at rm's address; its context refuses rm's token. */ 45 uint64_t ftk = 7, fof = 7; 46 ctx = (struct omega_native_context *)&r; 47 errno = 0; 48 assert(omega_gpu_live_marker(&other, page + 0x40, &ftk, &fof, &ctx) == -1 && errno == EFAULT && ctx == NULL); 49 r = 0; 50 assert(omega2_ctx_plat_wait_ge(other.omega_context, &r, tk, 0x40, 0x6a5a5a5au, 1) != 0 || (int64_t)r < 0); 51 /* Each Nvrm answers for its own page only. */ 52 assert(omega_gpu_live_marker(&other, opage + 8, &ftk, &fof, &ctx) == 0); 53 assert(ftk == other.live[0].omega_mapping && fof == 8 && ctx == other.omega_context); 54 55 /* Refusals, *ctx always NULL. */ 56 ctx = (struct omega_native_context *)&r; 57 errno = 0; 58 assert(omega_gpu_live_marker(NULL, page + 0x40, &tk, &of, &ctx) == -1 && errno == EINVAL && ctx == NULL); 59 assert(omega_gpu_live_marker(&rm, page + 0x40, NULL, &of, &ctx) == -1 && errno == EINVAL); 60 assert(omega_gpu_live_marker(&rm, page + 0x40, &tk, &of, NULL) == -1 && errno == EINVAL); 61 ctx = (struct omega_native_context *)&r; 62 assert(omega_gpu_live_marker(&rm, page + PAGE - 2, &tk, &of, &ctx) == -1 && errno == EFAULT && ctx == NULL); 63 rm.live[0].quarantined = 1; 64 ctx = (struct omega_native_context *)&r; 65 assert(omega_gpu_live_marker(&rm, page + 0x40, &tk, &of, &ctx) == -1 && errno == EFAULT && ctx == NULL); 66 rm.live[0].quarantined = 0; 67 68 printf("NVRM LIVE MARKER PASS (own token+offset+context, cross-runtime poll, foreign/NULL/straddle/quarantined refused; HOST_ONLY)\n"); 69 return 0; 70 }