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/aienux/blob/main/native/kernel/tests/gpu_chan_trace.c # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. 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 `aienux / native / kernel / tests / gpu_chan_trace.c` 121 lines ยท 4997 bytes Raw Blame History 1 /* gpu_chan_trace: the differential trace for the two channel twins (L332 rung 1). 2 * 3 * Runs one fixed script of channel operations on the simulated GB10 (gpu_sim) 4 * and prints, after every operation, its return code, every register access the 5 * simulator logged since the last line, and a hash of the whole simulated memory 6 * (page tables, ring, USERD, instance block, data). Built once with the hand 7 * channel (gpu/gpu_chan.c, L193) and once with the generated one 8 * (gpu/contract/gen/gch_contract.c from gpu/contract/gb10_chan.devc); the two 9 * outputs must be byte-identical (`make gpu-contract-trace`). 10 * The script covers: refused arguments, create, 300 submits across ring wraps 11 * with retires, a full ring, a bad span and address, teardown idle, and teardown 12 * of a hung channel (quarantine). */ 13 #include "gmmu.h" 14 #include "gpu_chan.h" 15 #include "gpu_mem.h" 16 #include "gpu_sim.h" 17 #include 18 #include 19 #include 20 21 #define MEM_BYTES (8u << 20) 22 #define PA_BASE 0x80000000ull 23 #define POOL_PA PA_BASE 24 #define DATA_PA (PA_BASE + 64ull * 4096u) 25 #define VA_BASE 0x0000000200000000ull 26 27 static uint8_t *mem; 28 static struct ck_gsim sim; 29 static struct ck_gpu_regs regs; 30 static struct ck_gmmu_as as; 31 static struct ck_gmem gm; 32 static uint32_t seen; 33 static unsigned step; 34 35 static uint64_t fnv(const uint8_t *p, uint64_t n) 36 { 37 uint64_t h = 0xcbf29ce484222325ull; 38 for (uint64_t i = 0; i < n; i++) 39 h = (h ^ p[i]) * 0x100000001b3ull; 40 return h; 41 } 42 43 static void line(const char *what, int rc) 44 { 45 printf("%04u %-24s rc=%d", step++, what, rc); 46 for (; seen < sim.nlog; seen++) 47 printf(" %c%06x=%08x", sim.log[seen].write ? 'W' : 'R', sim.log[seen].off, sim.log[seen].val); 48 printf(" doorbells=%u mem=%016llx\n", sim.doorbells, (unsigned long long)fnv(mem, MEM_BYTES)); 49 } 50 51 static void fresh(void) 52 { 53 memset(mem, 0xA5, MEM_BYTES); 54 ck_gsim_init(&sim, mem, PA_BASE, MEM_BYTES); 55 regs = ck_gsim_regs(&sim); 56 seen = 0; 57 if (ck_gmmu_as_init(&as, &sim.mem, POOL_PA, 64) != CK_GMMU_OK || ck_gmem_init(&gm, &as, ®s, 10, DATA_PA, 128, VA_BASE) != CK_GMEM_OK) { 58 printf("setup failed\n"); 59 exit(1); 60 } 61 line("setup", 0); 62 } 63 64 int main(void) 65 { 66 mem = malloc(MEM_BYTES); 67 if (!mem) 68 return 1; 69 struct ck_gpu_chan_ops ops = ck_gsim_chan_ops(); 70 struct ck_gpu_chan ch; 71 struct ck_gmem_buf *pb = 0, *sem = 0; 72 char what[64]; 73 74 fresh(); 75 line("create chid>max", ck_gpu_chan_create(&ch, &gm, ®s, &ops, &sim, 0x1000, 1, 16)); 76 line("create runlist=0x7f", ck_gpu_chan_create(&ch, &gm, ®s, &ops, &sim, 3, 0x7F, 16)); 77 line("create entries=24", ck_gpu_chan_create(&ch, &gm, ®s, &ops, &sim, 3, 1, 24)); 78 line("create entries=1", ck_gpu_chan_create(&ch, &gm, ®s, &ops, &sim, 3, 1, 1)); 79 line("create", ck_gpu_chan_create(&ch, &gm, ®s, &ops, &sim, 3, 1, 16)); 80 printf("token=%08x rl=%08x,%08x\n", ch.d.token, ch.d.rl_entry[0], ch.d.rl_entry[1]); 81 line("alloc pb", ck_gmem_alloc(&gm, 8192, CK_GMEM_CACHED, CK_GMEM_GPU_RO, &pb)); 82 line("alloc sem", ck_gmem_alloc(&gm, 4096, CK_GMEM_UNCACHED, CK_GMEM_HOST_POLLED, &sem)); 83 for (uint32_t i = 0; i < 4096; i++) 84 pb->cpu[i] = (uint8_t)(i * 7u); 85 line("submit off=2", ck_gpu_chan_submit(&ch, pb, 2, 4)); 86 line("submit nwords=0", ck_gpu_chan_submit(&ch, pb, 0, 0)); 87 line("submit past end", ck_gpu_chan_submit(&ch, pb, 8188, 2)); 88 line("submit foreign buf", ck_gpu_chan_submit(&ch, (const struct ck_gmem_buf *)&ch, 0, 4)); 89 for (uint32_t i = 0; i < 300; i++) { 90 int rc = ck_gpu_chan_submit(&ch, pb, (i % 64u) * 64u, 1u + i % 16u); 91 snprintf(what, sizeof what, "submit %u", i); 92 line(what, rc); 93 if (rc == CK_GCHAN_EFULL || i % 5u == 4u) { 94 ck_gpu_chan_retire(&ch, ch.put - (i % 3u)); 95 snprintf(what, sizeof what, "retire put=%u ret=%u", ch.put, ch.retired); 96 line(what, 0); 97 } 98 } 99 ck_gpu_chan_retire(&ch, ch.put + 5u); /* past put: ignored */ 100 snprintf(what, sizeof what, "retire past put ret=%u", ch.retired); 101 line(what, 0); 102 struct ck_gmem_buf *extra[2] = {pb, sem}; 103 line("teardown idle", ck_gpu_chan_teardown(&ch, 4, extra, 2)); 104 line("teardown again", ck_gpu_chan_teardown(&ch, 4, extra, 2)); 105 line("submit after close", ck_gpu_chan_submit(&ch, pb, 0, 4)); 106 107 fresh(); 108 line("create (hung run)", ck_gpu_chan_create(&ch, &gm, ®s, &ops, &sim, 7, 2, 8)); 109 pb = sem = 0; 110 line("alloc pb", ck_gmem_alloc(&gm, 4096, CK_GMEM_CACHED, CK_GMEM_GPU_RO, &pb)); 111 for (uint32_t i = 0; i < 9; i++) { 112 snprintf(what, sizeof what, "submit %u", i); 113 line(what, ck_gpu_chan_submit(&ch, pb, 0, 8)); 114 } 115 sim.hang = 1; 116 struct ck_gmem_buf *extra2[1] = {pb}; 117 line("teardown hung", ck_gpu_chan_teardown(&ch, 6, extra2, 1)); 118 printf("quarantined_pages=%u free_pages=%u\n", ck_gmem_count(&gm, CK_GMEM_QUARANTINED), ck_gmem_count(&gm, CK_GMEM_FREE)); 119 free(mem); 120 return 0; 121 }