interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / seq_ref.c

78 lines · 3189 bytes Raw Blame History
1/* tests/seq_ref.c -- TEST-ONLY C referee for tests/seq_diff.sh. Never linked into the product.
2 * Runs aienux PR #441 gpu/gsp_seq.c (gsp_seq_run) against gpu/gsp_sim.c for every case on stdin and prints
3 * the trace tests/seq_trace.om prints for gsp/seq.om. Case line (decimal):
4 * name busy budget core corefail nwords end m w0 .. w(m-1)
5 * busy = sim busy_reads, budget = poll_budget, core = 1 supplies the core callback (it fails when the
6 * opcode equals corefail), words past m are 0. A line starting with # is a comment. */
7#include <stdint.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include "gsp_seq.h"
12#include "gsp_sim.h"
13
14struct ctx {
15 struct ck_gpu_regs r;
16 uint32_t fail, ncalls, ops[16], ndelay, us;
17};
18
19static uint32_t rd(void *c, uint32_t a) { struct ctx *x = c; return x->r.rd(x->r.ctx, a); }
20static void wr(void *c, uint32_t a, uint32_t v) { struct ctx *x = c; x->r.wr(x->r.ctx, a, v); }
21static int core(void *c, uint32_t op)
22{
23 struct ctx *x = c;
24 if (x->ncalls < 16) x->ops[x->ncalls] = op;
25 x->ncalls++;
26 return op == x->fail ? -1 : 0;
27}
28static void dly(void *c, uint32_t us) { struct ctx *x = c; x->ndelay++; x->us += us; }
29
30int main(void)
31{
32 static struct ck_gspsim sim;
33 char name[64];
34 while (scanf("%63s", name) == 1) {
35 if (name[0] == '#') {
36 int ch;
37 while ((ch = getchar()) != EOF && ch != '\n') {}
38 continue;
39 }
40 unsigned long long busy, bud, con, fail, nw, end, m;
41 if (scanf("%llu %llu %llu %llu %llu %llu %llu", &busy, &bud, &con, &fail, &nw, &end, &m) != 7) return 2;
42 if (nw > (1u << 20) || m > nw || busy > 0xffffffffu || bud > 0xffffffffu || end > 0xffffffffu) return 2;
43 uint32_t *buf = calloc(nw ? nw : 1, 4);
44 if (!buf) return 2;
45 for (unsigned long long i = 0; i < m; i++) {
46 unsigned long long w;
47 if (scanf("%llu", &w) != 1 || w > 0xffffffffu) return 2;
48 buf[i] = (uint32_t)w;
49 }
50 struct ck_gspsim_cfg cfg;
51 memset(&cfg, 0, sizeof cfg);
52 cfg.busy_reads = (uint32_t)busy;
53 ck_gspsim_init(&sim, &cfg);
54 struct ctx x;
55 memset(&x, 0, sizeof x);
56 x.r = ck_gspsim_regs(&sim);
57 x.fail = (uint32_t)fail;
58 gsp_seq_io io;
59 memset(&io, 0, sizeof io);
60 io.rd = rd;
61 io.wr = wr;
62 io.core = con ? core : NULL;
63 io.delay_us = dly;
64 io.ctx = &x;
65 io.poll_budget = (uint32_t)bud;
66 const char *why = 0;
67 int rc = gsp_seq_run(buf, (uint32_t)nw, (uint32_t)end, &io, &why);
68 printf("== %s rc=%d why=%s delays=%u/%u core=%u ops=", name, rc, why ? why : "-", x.ndelay, x.us, x.ncalls);
69 for (uint32_t i = 0; i < x.ncalls && i < 16; i++) printf("%u,", x.ops[i]);
70 printf(" save=");
71 for (int i = 0; i < GSP_SEQ_REG_SAVE; i++) printf("%#x,", io.save[i]);
72 printf(" nlog=%u violations=%u\n", sim.nlog, sim.violations);
73 for (uint32_t i = 0; i < sim.nlog && i < CK_GSPSIM_LOG_MAX; i++)
74 printf("%c %06x %08x\n", sim.log[i].write ? 'W' : 'R', sim.log[i].off, sim.log[i].val);
75 free(buf);
76 }
77 return 0;
78}