diff --git a/software/Makefile b/software/Makefile index 573ca08..8cbeb9e 100644 --- a/software/Makefile +++ b/software/Makefile @@ -29,14 +29,15 @@ ARCH = rv64imafdc ABI = lp64d ARCHFLAGS = -march=$(ARCH) -mabi=$(ABI) -# rv64gcv_zfh_zvfh (not $(ARCH)): ucie-vec-memcpy.c's RVV kernel needs the -# vector extension. Kept separate so it doesn't force V onto every program. +# rv64gcv_zfh_zvfh (not $(ARCH)): the RVV kernels in ucie-vec-memcpy.c and +# multihart-vec-amo.c need the vector extension. Kept separate so it doesn't +# force V onto every program. VEC_ARCHFLAGS = -march=rv64gcv_zfh_zvfh -mabi=$(ABI) CFLAGS = -std=gnu99 -O2 -fno-common -fno-builtin-printf -Wall -specs=htif_nano.specs -Iinclude LDFLAGS = -specs=htif_nano.specs -PROGRAMS = hello hello0 hello1 router ring-hello ucie-loopback ucie-digital-loopback tacit-always tacit-dma ucie-vec-memcpy +PROGRAMS = hello hello0 hello1 router ring-hello ucie-loopback ucie-digital-loopback tacit-always tacit-dma ucie-vec-memcpy multihart-vec-amo clock-div .DEFAULT_GOAL := default @@ -59,6 +60,31 @@ ucie-vec-memcpy.o: ucie-vec-memcpy.c ucie-vec-memcpy.riscv: ucie-vec-memcpy.o $(GCC) $(LDFLAGS) $(VEC_ARCHFLAGS) $< -o $@ +multihart-vec-amo.o: multihart-vec-amo.c + $(GCC) $(CFLAGS) $(VEC_ARCHFLAGS) -c $< -o $@ + +multihart-vec-amo.riscv: multihart-vec-amo.o + $(GCC) $(LDFLAGS) $(VEC_ARCHFLAGS) $< -o $@ + +# saturn-vectors' MX vector benchmarks, built here so nothing is written into +# that submodule. Same flags and bare-metal runtime (crt.S, syscalls.c, test.ld) +# as its benchmarks/Makefile, against its data.S. A copy in saturn-benchmarks/ +# replaces upstream's main.c (vec-mx-matmul, whose check cannot fail upstream). +SATURN_BENCH = $(REPO_ROOT)/saturn-vectors/benchmarks +SATURN_PROGRAMS = vec-mx-binary vec-mx-unary vec-mx-matmul +SATURN_CFLAGS = -DPREALLOCATE=1 -mcmodel=medany -static -O2 -g -ffast-math -fno-common \ + -fno-builtin-printf -fno-tree-loop-distribute-patterns -march=rv64gcv_zfh_zvfh -mabi=$(ABI) -std=gnu99 +SATURN_LDFLAGS = -static -nostdlib -nostartfiles -lm -lgcc -T $(SATURN_BENCH)/common/test.ld +SATURN_COMMON = $(wildcard $(SATURN_BENCH)/common/*.c $(SATURN_BENCH)/common/*.S $(SATURN_BENCH)/common/ara/*.c) +saturn_main = $(firstword $(wildcard saturn-benchmarks/$(1).c) $(SATURN_BENCH)/$(1)/main.c) + +define saturn_template +$(1).riscv: $(call saturn_main,$(1)) $(SATURN_BENCH)/$(1)/data.S $(wildcard $(SATURN_BENCH)/common/*) + $$(GCC) -I$(SATURN_BENCH)/env -I$(SATURN_BENCH)/common -I$(SATURN_BENCH)/$(1) $$(SATURN_CFLAGS) \ + -o $$@ $(call saturn_main,$(1)) $(SATURN_BENCH)/$(1)/data.S $$(SATURN_COMMON) $$(SATURN_LDFLAGS) +endef +$(foreach b,$(SATURN_PROGRAMS),$(eval $(call saturn_template,$(b)))) + %.dump: %.riscv $(OBJDUMP) -D $< > $@ @@ -81,8 +107,8 @@ clean: rm -f *.riscv *.o *.dump .PHONY: default -default: $(addsuffix .riscv, $(PROGRAMS)) +default: $(addsuffix .riscv, $(PROGRAMS) $(SATURN_PROGRAMS)) .PHONY: dumps -dumps: $(addsuffix .dump, $(PROGRAMS)) +dumps: $(addsuffix .dump, $(PROGRAMS) $(SATURN_PROGRAMS)) diff --git a/software/clock-div.c b/software/clock-div.c new file mode 100644 index 0000000..cf56956 --- /dev/null +++ b/software/clock-div.c @@ -0,0 +1,202 @@ +// Programs the clock dividers in clk-div-ctrl@120000 and checks that every +// hart keeps working, and that its clock really changed, after each change. +// +// Divider registers (8 bits each). A value v divides io.clock by v + 1; 0 passes +// it through undivided (testchipip ClockDivideOrPass): +// 0x120000 uncore (sbus/mbus/cbus/pbus/fbus/d2d) +// 0x120004 ShuttleTile 0 (hart 0) +// 0x120008 ShuttleTile 1 (hart 1) +// 0x12000c RocketTile (hart 2) +// 0x120010 clock_tap output (checked by the harness's period monitor) +// +// Each hart measures its core clock against the CLINT's mtime. mtime advances +// once every 1000 uncore cycles (timebase 500 kHz at the 500 MHz uncore), so +// for core clock io/(t) and uncore clock io/(u) a hart sees +// mcycle per mtime tick = 1000 * u / t. +// After each change every hart runs a small memory self-check. Hart 0 drives +// the sequence and is the only hart that prints (over HTIF, which does not +// depend on the uncore clock, unlike the UART). + +#include +#include +#include +#include "mmio.h" + +#define NHARTS 3 +#define CLKDIV_BASE 0x120000UL +#define CLKDIV_UNCORE (CLKDIV_BASE + 0x00) +#define CLKDIV_TILE(h) (CLKDIV_BASE + 0x04 + 4 * (h)) +#define CLKDIV_TAP (CLKDIV_BASE + 0x10) +#define CLINT_MTIME 0x200bff8UL + +#define CYCLES_PER_TICK 1000 // undivided core cycles per mtime tick +#define MEASURE_TICKS 4 +#define TOLERANCE_PCT 10 +#define ACK_TIMEOUT_TICKS 2000 +#define BUF_WORDS 1024 // 8 KiB per hart + +#define LINE __attribute__((aligned(64))) + +typedef struct { + uint8_t uncore, tile[NHARTS], tap; // divide ratios (1 = undivided) +} clk_config_t; + +static const clk_config_t configs[] = { + {1, {1, 1, 1}, 1}, + // uncore alone + {2, {1, 1, 1}, 2}, + {3, {1, 1, 1}, 3}, + {7, {1, 1, 1}, 7}, + // one tile at a time + {1, {2, 1, 1}, 1}, + {1, {1, 3, 1}, 1}, + {1, {1, 1, 7}, 1}, + // mixed + {1, {2, 3, 7}, 2}, + {3, {7, 2, 3}, 3}, + {2, {3, 7, 2}, 7}, + // back to undivided + {1, {1, 1, 1}, 1}, +}; +#define NCONFIGS (sizeof(configs) / sizeof(configs[0])) + +static volatile uint64_t epoch LINE; +static struct { + volatile uint64_t ack; // epoch this hart last finished + volatile uint64_t cycles_per_tick; // measured + volatile uint64_t errors; // self-check mismatches +} LINE status[NHARTS]; +static uint64_t buf[NHARTS][BUF_WORDS] LINE; + +static inline uint64_t mtime(void) { return reg_read64(CLINT_MTIME); } + +static uint64_t measure_cycles_per_tick(void) +{ + uint64_t t = mtime(); + while (mtime() == t) ; // align to a tick edge + uint64_t c0 = read_csr(mcycle); + uint64_t t0 = mtime(); + while (mtime() < t0 + MEASURE_TICKS) ; + uint64_t c1 = read_csr(mcycle); + uint64_t t1 = mtime(); + return (c1 - c0) / (t1 - t0); +} + +static uint64_t self_check(unsigned h, uint64_t e) +{ + uint64_t seed = 0x9e3779b97f4a7c15ull * (e + 1) + h; + uint64_t errors = 0; + for (int i = 0; i < BUF_WORDS; i++) + buf[h][i] = seed ^ ((uint64_t)i * 0x100000001b3ull); + asm volatile("fence" ::: "memory"); + // Read back in reverse, then a dependent checksum, so it is not just store + // forwarding of the last few lines. + for (int i = BUF_WORDS - 1; i >= 0; i--) + if (buf[h][i] != (seed ^ ((uint64_t)i * 0x100000001b3ull))) + errors++; + uint64_t sum = 0, want = 0; + for (int i = 0; i < BUF_WORDS; i++) { + sum = (sum << 1 | sum >> 63) ^ buf[h][i]; + want = (want << 1 | want >> 63) ^ (seed ^ ((uint64_t)i * 0x100000001b3ull)); + } + return errors + (sum != want); +} + +static void run_round(unsigned h, uint64_t e) +{ + status[h].cycles_per_tick = measure_cycles_per_tick(); + status[h].errors = self_check(h, e); + asm volatile("fence" ::: "memory"); + status[h].ack = e; +} + +void __main(void) +{ + unsigned h = read_csr(mhartid); + uint64_t seen = 0; + if (h >= NHARTS) for (;;) asm volatile("wfi"); + for (;;) { + uint64_t e = epoch; + if (e != seen) { + asm volatile("fence" ::: "memory"); + run_round(h, e); + seen = e; + } + } +} + +// Writes the dividers for c and returns the number of registers that did not +// read back what was written. +static int program(const clk_config_t *c) +{ + int fails = 0; + reg_write32(CLKDIV_UNCORE, c->uncore - 1); + for (int h = 0; h < NHARTS; h++) + reg_write32(CLKDIV_TILE(h), c->tile[h] - 1); + reg_write32(CLKDIV_TAP, c->tap - 1); + // Read back each register; the read also orders the writes before the + // measurement starts. + if (reg_read32(CLKDIV_UNCORE) != (uint32_t)(c->uncore - 1)) { + printf("FAIL: uncore divider readback\n"); + fails++; + } + for (int h = 0; h < NHARTS; h++) { + if (reg_read32(CLKDIV_TILE(h)) != (uint32_t)(c->tile[h] - 1)) { + printf("FAIL: tile %d divider readback\n", h); + fails++; + } + } + if (reg_read32(CLKDIV_TAP) != (uint32_t)(c->tap - 1)) { + printf("FAIL: tap divider readback\n"); + fails++; + } + // Let the divisor synchronizers and the in-flight divided period settle. + uint64_t t = mtime(); + while (mtime() < t + 2) ; + return fails; +} + +int main(void) +{ + int fails = 0; + for (int h = 0; h < NHARTS; h++) status[h].ack = 0; + epoch = 0; + asm volatile("fence" ::: "memory"); + + for (unsigned n = 0; n < NCONFIGS; n++) { + const clk_config_t *c = &configs[n]; + uint64_t e = n + 1; + printf("clock-div config %u: uncore /%u, tiles /%u /%u /%u, tap /%u\n", n, c->uncore, + c->tile[0], c->tile[1], c->tile[2], c->tap); + fails += program(c); + + asm volatile("fence" ::: "memory"); + epoch = e; + asm volatile("fence" ::: "memory"); + run_round(0, e); + + uint64_t t0 = mtime(); + for (int h = 1; h < NHARTS; h++) { + while (status[h].ack != e && mtime() - t0 < ACK_TIMEOUT_TICKS) ; + } + asm volatile("fence" ::: "memory"); + + for (int h = 0; h < NHARTS; h++) { + uint64_t want = (uint64_t)CYCLES_PER_TICK * c->uncore / c->tile[h]; + uint64_t got = status[h].cycles_per_tick; + int ok = status[h].ack == e && status[h].errors == 0 && + got * 100 >= want * (100 - TOLERANCE_PCT) && + got * 100 <= want * (100 + TOLERANCE_PCT); + printf(" hart %d: %lu cycles/tick (want %lu), self-check errors %lu, ack %lu: %s\n", h, got, + want, status[h].errors, status[h].ack, ok ? "ok" : "FAIL"); + fails += !ok; + } + } + + if (fails) { + printf("clock-div: %d checks FAILED\n", fails); + return 1; + } + printf("clock-div: all checks passed\n"); + return 0; +} diff --git a/software/multihart-vec-amo.c b/software/multihart-vec-amo.c new file mode 100644 index 0000000..d307b81 --- /dev/null +++ b/software/multihart-vec-amo.c @@ -0,0 +1,422 @@ +// Runs on all three Iris harts at once: +// hart 0, hart 1: ShuttleTile (marchid 34), Saturn with the OPU/MX datapath +// hart 2: RocketTile (marchid 1), Saturn "DMA" vector unit +// +// Part 1: every hart runs the same RVV kernel (integer MAC, widening add, +// strided load, compare + popcount, reduction, FP32 FMA) on its own buffers in +// DRAM and checks it against a scalar reference. Hart 2 exercises Rocket's +// vector unit specifically. +// +// Part 2: all three harts contend on DRAM (L2-backed) cache lines with AMOs +// (add.d/add.w/or/max/xor/swap) and LR/SC (64- and 32-bit; the 32-bit LR/SC +// shares a line with an AMO counter), then hart 0 checks every final value. +// +// Hart 0 runs main() and is the only hart that prints or exits; harts 1 and 2 +// enter __main() (libgloss-htif's secondary-hart entry) and report through +// shared memory. Every wait is bounded, so a hang becomes a nonzero exit. + +#include +#include +#include +#include +#include + +#define NHARTS 3 +#define ROCKET_HART 2 +#define MARCHID_SHUTTLE 34 +#define MARCHID_ROCKET 1 + +#define N 203 // odd, so every strip-mined loop ends on a partial vector +#define AMO_ITERS 64 +#define GO_MAGIC 0x5a5a1234u +#define DONE_MAGIC 0xd0e0000000000000ull +#define TIMEOUT_CYCLES 20000000ull +#define LRSC_MAX_RETRIES 100000 + +#define LINE __attribute__((aligned(64))) + +// --------------------------------------------------------------------------- +// Shared state. Every field that more than one hart writes sits on its own +// 64-byte line, except lrsc32, which deliberately shares amo_add64's line so +// AMOs and LR/SC from different harts hit the same line. +// --------------------------------------------------------------------------- +static volatile uint32_t go LINE; +static volatile uint64_t arrive LINE; +static volatile uint64_t done_count LINE; + +static struct { + volatile uint64_t amo_add64; + volatile uint32_t lrsc32; +} line_a LINE; +static volatile uint32_t amo_add32 LINE; +static volatile uint64_t amo_or LINE; +static volatile int64_t amo_max LINE; +static volatile uint32_t amo_xor LINE; +static volatile uint64_t amo_swap LINE; +static volatile uint64_t lrsc64 LINE; + +typedef struct { + volatile uint64_t marchid; + volatile uint64_t misa; + volatile uint64_t vlenb; + volatile uint64_t vec_errors; + volatile uint64_t first_bad; // check id << 32 | element index + volatile uint64_t swap_sum; // sum of the values amoswap returned + volatile uint64_t lrsc_retries; // worst-case SC failures for one update + volatile uint64_t lrsc_fail; // an LR/SC loop gave up + volatile uint64_t done; // DONE_MAGIC | hartid when the hart finishes +} LINE hart_result_t; +static hart_result_t result[NHARTS]; + +// Per-hart vector buffers, each hart on its own lines. +static int32_t va[NHARTS][N] LINE; +static int32_t vb[NHARTS][N] LINE; +static int32_t vc[NHARTS][N] LINE; +static int32_t vmac_out[NHARTS][N] LINE; +static uint8_t vu8a[NHARTS][N] LINE; +static uint8_t vu8b[NHARTS][N] LINE; +static uint16_t vwadd_out[NHARTS][N] LINE; +static int32_t vstrided_src[NHARTS][2 * N] LINE; +static int32_t vstrided_out[NHARTS][N] LINE; +static float vfx[NHARTS][N] LINE; +static float vfy[NHARTS][N] LINE; +static uint64_t vred_out[NHARTS] LINE; +static uint64_t vcpop_out[NHARTS] LINE; + +static inline uint64_t hartid(void) { return read_csr(mhartid); } +static inline uint64_t cycles(void) { return read_csr(mcycle); } + +// --------------------------------------------------------------------------- +// Part 1: vector kernel and its scalar reference +// --------------------------------------------------------------------------- + +static void init_vectors(unsigned h) +{ + uint32_t x = 0x9e3779b9u * (h + 1); + for (int i = 0; i < N; i++) { + x = x * 1664525u + 1013904223u; + va[h][i] = (int32_t)(x >> 7) - (1 << 23); + vb[h][i] = (int32_t)((x >> 3) & 0xffff) - 0x8000; + vc[h][i] = (int32_t)(x ^ (h << 28)); + vu8a[h][i] = (uint8_t)(x >> 11); + vu8b[h][i] = (uint8_t)(x >> 19); + // Small integers: every FP32 product and sum below is exact. + vfx[h][i] = (float)((int)(x % 37) - 18); + vfy[h][i] = (float)((int)((x >> 8) % 23) - 11); + vmac_out[h][i] = 0; + vwadd_out[h][i] = 0; + vstrided_out[h][i] = 0; + } + for (int i = 0; i < 2 * N; i++) + vstrided_src[h][i] = (int32_t)(0x1000 * h + 3 * i + 7); +} + +static void run_vector_kernel(unsigned h) +{ + // vmacc: out = a * b + c (e32, LMUL=2) + for (size_t i = 0, vl; i < N; i += vl) { + vl = __riscv_vsetvl_e32m2(N - i); + vint32m2_t a = __riscv_vle32_v_i32m2(&va[h][i], vl); + vint32m2_t b = __riscv_vle32_v_i32m2(&vb[h][i], vl); + vint32m2_t c = __riscv_vle32_v_i32m2(&vc[h][i], vl); + c = __riscv_vmacc_vv_i32m2(c, a, b, vl); + __riscv_vse32_v_i32m2(&vmac_out[h][i], c, vl); + } + // vwaddu: u8 + u8 -> u16 (e8 -> e16 widening) + for (size_t i = 0, vl; i < N; i += vl) { + vl = __riscv_vsetvl_e8m1(N - i); + vuint8m1_t a = __riscv_vle8_v_u8m1(&vu8a[h][i], vl); + vuint8m1_t b = __riscv_vle8_v_u8m1(&vu8b[h][i], vl); + __riscv_vse16_v_u16m2(&vwadd_out[h][i], __riscv_vwaddu_vv_u16m2(a, b, vl), vl); + } + // vlse32: every other element of the strided source + for (size_t i = 0, vl; i < N; i += vl) { + vl = __riscv_vsetvl_e32m1(N - i); + vint32m1_t s = __riscv_vlse32_v_i32m1(&vstrided_src[h][2 * i], 2 * sizeof(int32_t), vl); + __riscv_vse32_v_i32m1(&vstrided_out[h][i], s, vl); + } + // vredsum of (a ^ b), and vcpop of (a < b) + uint64_t red = 0, pop = 0; + for (size_t i = 0, vl; i < N; i += vl) { + vl = __riscv_vsetvl_e32m4(N - i); + vint32m4_t a = __riscv_vle32_v_i32m4(&va[h][i], vl); + vint32m4_t b = __riscv_vle32_v_i32m4(&vb[h][i], vl); + vint32m4_t x = __riscv_vxor_vv_i32m4(a, b, vl); + vint32m1_t acc = __riscv_vmv_s_x_i32m1(0, 1); + acc = __riscv_vredsum_vs_i32m4_i32m1(x, acc, vl); + red += (uint32_t)__riscv_vmv_x_s_i32m1_i32(acc); + vbool8_t lt = __riscv_vmslt_vv_i32m4_b8(a, b, vl); + pop += __riscv_vcpop_m_b8(lt, vl); + } + vred_out[h] = red; + vcpop_out[h] = pop; + // vfmacc: y = 3 * x + y (FP32, LMUL=1) + for (size_t i = 0, vl; i < N; i += vl) { + vl = __riscv_vsetvl_e32m1(N - i); + vfloat32m1_t x = __riscv_vle32_v_f32m1(&vfx[h][i], vl); + vfloat32m1_t y = __riscv_vle32_v_f32m1(&vfy[h][i], vl); + y = __riscv_vfmacc_vf_f32m1(y, 3.0f, x, vl); + __riscv_vse32_v_f32m1(&vfy[h][i], y, vl); + } + asm volatile("fence" ::: "memory"); +} + +// The reference must stay scalar: keep GCC from auto-vectorizing it. +#define SCALAR __attribute__((noinline, optimize("no-tree-vectorize", "no-tree-slp-vectorize"))) + +static SCALAR void note_error(unsigned h, uint64_t check, uint64_t idx) +{ + if (result[h].vec_errors++ == 0) + result[h].first_bad = (check << 32) | idx; +} + +static SCALAR uint64_t f32_bits(float f) +{ + union { float f; uint32_t u; } c = { .f = f }; + return c.u; +} + +// Recomputes the expected values from init_vectors' generator, so it never +// reads an input the kernel could have clobbered. +static SCALAR void check_vectors(unsigned h) +{ + uint32_t x = 0x9e3779b9u * (h + 1); + uint32_t red = 0; + uint64_t pop = 0; + for (int i = 0; i < N; i++) { + x = x * 1664525u + 1013904223u; + int32_t a = (int32_t)(x >> 7) - (1 << 23); + int32_t b = (int32_t)((x >> 3) & 0xffff) - 0x8000; + int32_t c = (int32_t)(x ^ (h << 28)); + uint8_t u8a = (uint8_t)(x >> 11); + uint8_t u8b = (uint8_t)(x >> 19); + float fx = (float)((int)(x % 37) - 18); + float fy = (float)((int)((x >> 8) % 23) - 11); + + if ((uint32_t)vmac_out[h][i] != (uint32_t)a * (uint32_t)b + (uint32_t)c) + note_error(h, 1, i); + if (vwadd_out[h][i] != (uint16_t)u8a + (uint16_t)u8b) + note_error(h, 2, i); + if (vstrided_out[h][i] != (int32_t)(0x1000 * h + 3 * (2 * i) + 7)) + note_error(h, 3, i); + if (f32_bits(vfy[h][i]) != f32_bits(3.0f * fx + fy)) + note_error(h, 5, i); + red += (uint32_t)(a ^ b); + pop += a < b; + } + // The kernel sums per-strip 32-bit reductions into 64 bits; compare mod 2^32. + if ((uint32_t)vred_out[h] != red) + note_error(h, 4, 0); + if (vcpop_out[h] != pop) + note_error(h, 6, 0); +} + +// --------------------------------------------------------------------------- +// Part 2: AMOs and LR/SC +// --------------------------------------------------------------------------- + +static inline uint64_t amoadd_d(volatile uint64_t *p, uint64_t v) +{ + uint64_t old; + asm volatile("amoadd.d.aqrl %0, %2, (%1)" : "=r"(old) : "r"(p), "r"(v) : "memory"); + return old; +} + +static inline uint32_t amoadd_w(volatile uint32_t *p, uint32_t v) +{ + uint32_t old; + asm volatile("amoadd.w %0, %2, (%1)" : "=r"(old) : "r"(p), "r"(v) : "memory"); + return old; +} + +static inline void amoor_d(volatile uint64_t *p, uint64_t v) +{ + asm volatile("amoor.d zero, %1, (%0)" : : "r"(p), "r"(v) : "memory"); +} + +static inline void amomax_d(volatile int64_t *p, int64_t v) +{ + asm volatile("amomax.d zero, %1, (%0)" : : "r"(p), "r"(v) : "memory"); +} + +static inline void amoxor_w(volatile uint32_t *p, uint32_t v) +{ + asm volatile("amoxor.w zero, %1, (%0)" : : "r"(p), "r"(v) : "memory"); +} + +static inline uint64_t amoswap_d(volatile uint64_t *p, uint64_t v) +{ + uint64_t old; + asm volatile("amoswap.d.aq %0, %2, (%1)" : "=r"(old) : "r"(p), "r"(v) : "memory"); + return old; +} + +// Adds v with an LR/SC loop. Returns the number of failed SCs, or -1 if it +// gave up after LRSC_MAX_RETRIES. +static inline int64_t lrsc_add_d(volatile uint64_t *p, uint64_t v) +{ + for (int64_t tries = 0; tries < LRSC_MAX_RETRIES; tries++) { + uint64_t old, fail; + asm volatile( + "lr.d.aq %0, (%2)\n" + "add %0, %0, %3\n" + "sc.d.rl %1, %0, (%2)\n" + : "=&r"(old), "=&r"(fail) + : "r"(p), "r"(v) + : "memory"); + if (fail == 0) return tries; + } + return -1; +} + +static inline int64_t lrsc_add_w(volatile uint32_t *p, uint32_t v) +{ + for (int64_t tries = 0; tries < LRSC_MAX_RETRIES; tries++) { + uint64_t old, fail; + asm volatile( + "lr.w.aq %0, (%2)\n" + "addw %0, %0, %3\n" + "sc.w.rl %1, %0, (%2)\n" + : "=&r"(old), "=&r"(fail) + : "r"(p), "r"(v) + : "memory"); + if (fail == 0) return tries; + } + return -1; +} + +static uint64_t swap_value(unsigned h, unsigned i) { return ((uint64_t)(h + 1) << 32) | (i + 1); } +static uint32_t xor_value(unsigned h, unsigned i) { return 0x9e3779b9u * (h * AMO_ITERS + i + 1); } + +static void run_amo(unsigned h) +{ + // Start barrier, so the harts really contend. + amoadd_d(&arrive, 1); + uint64_t t0 = cycles(); + while (arrive < NHARTS) { + if (cycles() - t0 > TIMEOUT_CYCLES) { result[h].lrsc_fail = 2; return; } + } + + uint64_t swap_sum = 0, worst = 0; + for (unsigned i = 0; i < AMO_ITERS; i++) { + amoadd_d(&line_a.amo_add64, 1); + int64_t r = lrsc_add_w(&line_a.lrsc32, 1); + if (r < 0) { result[h].lrsc_fail = 1; break; } + if ((uint64_t)r > worst) worst = r; + amoadd_w(&amo_add32, 3); + amoor_d(&amo_or, 1ull << (h * 16 + (i & 15))); + amomax_d(&amo_max, (int64_t)(h * 1000 + i) - 500); + amoxor_w(&amo_xor, xor_value(h, i)); + swap_sum += amoswap_d(&amo_swap, swap_value(h, i)); + r = lrsc_add_d(&lrsc64, (uint64_t)h + 1); + if (r < 0) { result[h].lrsc_fail = 1; break; } + if ((uint64_t)r > worst) worst = r; + } + result[h].swap_sum = swap_sum; + result[h].lrsc_retries = worst; +} + +// --------------------------------------------------------------------------- +// Per-hart body and hart 0's checker +// --------------------------------------------------------------------------- + +static void hart_body(unsigned h) +{ + result[h].marchid = read_csr(marchid); + result[h].misa = read_csr(misa); + result[h].vlenb = read_csr(vlenb); + init_vectors(h); + asm volatile("fence" ::: "memory"); + run_vector_kernel(h); + check_vectors(h); + run_amo(h); + asm volatile("fence" ::: "memory"); + result[h].done = DONE_MAGIC | h; + amoadd_d(&done_count, 1); +} + +void __main(void) +{ + unsigned h = hartid(); + if (h >= NHARTS) { for (;;) asm volatile("wfi"); } + while (go != GO_MAGIC) ; + asm volatile("fence" ::: "memory"); + hart_body(h); + for (;;) asm volatile("wfi"); +} + +static int fails = 0; +#define CHECK(cond, ...) do { if (!(cond)) { printf("FAIL: " __VA_ARGS__); printf("\n"); fails++; } } while (0) + +int main(void) +{ + // BSS is zero, but be explicit: these are the values the checks assume. + arrive = 0; + done_count = 0; + line_a.amo_add64 = 0; + line_a.lrsc32 = 0; + amo_add32 = 0; + amo_or = 0; + amo_max = -1000000; + amo_xor = 0; + amo_swap = 0x5555; + lrsc64 = 0; + for (int h = 0; h < NHARTS; h++) { + result[h].vec_errors = 0; + result[h].lrsc_fail = 0; + result[h].done = 0; + } + asm volatile("fence" ::: "memory"); + go = GO_MAGIC; + asm volatile("fence" ::: "memory"); + + hart_body(0); + + uint64_t t0 = cycles(); + while (done_count < NHARTS) { + if (cycles() - t0 > TIMEOUT_CYCLES) break; + } + asm volatile("fence" ::: "memory"); + + for (int h = 0; h < NHARTS; h++) { + uint64_t want_arch = h == ROCKET_HART ? MARCHID_ROCKET : MARCHID_SHUTTLE; + printf("hart %d: marchid=%lu misa=0x%lx vlenb=%lu vec_errors=%lu lrsc_worst_retries=%lu done=0x%lx\n", + h, result[h].marchid, result[h].misa, result[h].vlenb, result[h].vec_errors, + result[h].lrsc_retries, result[h].done); + CHECK(result[h].done == (DONE_MAGIC | h), "hart %d did not finish", h); + CHECK(result[h].marchid == want_arch, "hart %d marchid %lu, want %lu", h, result[h].marchid, want_arch); + CHECK(result[h].misa & (1ull << ('V' - 'A')), "hart %d misa has no V", h); + CHECK(result[h].vec_errors == 0, "hart %d: %lu vector mismatches, first check %lu index %lu", h, + result[h].vec_errors, result[h].first_bad >> 32, result[h].first_bad & 0xffffffff); + CHECK(result[h].lrsc_fail == 0, "hart %d LR/SC or barrier gave up (%lu)", h, result[h].lrsc_fail); + } + + uint64_t want_or = 0, swap_written = 0x5555, swap_returned = 0; + uint32_t want_xor = 0; + for (unsigned h = 0; h < NHARTS; h++) { + want_or |= 0xffffull << (h * 16); + for (unsigned i = 0; i < AMO_ITERS; i++) { + want_xor ^= xor_value(h, i); + swap_written += swap_value(h, i); + } + swap_returned += result[h].swap_sum; + } + printf("amo_add64=%lu lrsc32=%u amo_add32=%u amo_or=0x%lx amo_max=%ld amo_xor=0x%x lrsc64=%lu\n", + line_a.amo_add64, line_a.lrsc32, amo_add32, amo_or, amo_max, amo_xor, lrsc64); + CHECK(line_a.amo_add64 == NHARTS * AMO_ITERS, "amo_add64"); + CHECK(line_a.lrsc32 == NHARTS * AMO_ITERS, "lrsc32"); + CHECK(amo_add32 == 3 * NHARTS * AMO_ITERS, "amo_add32"); + CHECK(amo_or == want_or, "amo_or want 0x%lx", want_or); + CHECK(amo_max == (int64_t)((NHARTS - 1) * 1000 + AMO_ITERS - 1) - 500, "amo_max"); + CHECK(amo_xor == want_xor, "amo_xor want 0x%x", want_xor); + // Every value swapped in is either returned to some hart or still there. + CHECK(swap_returned + amo_swap == swap_written, "amo_swap conservation"); + CHECK(lrsc64 == (uint64_t)AMO_ITERS * (1 + 2 + 3), "lrsc64"); + + if (fails) { + printf("multihart-vec-amo: %d checks FAILED\n", fails); + return 1; + } + printf("multihart-vec-amo: all checks passed\n"); + return 0; +} diff --git a/software/saturn-benchmarks/vec-mx-matmul.c b/software/saturn-benchmarks/vec-mx-matmul.c new file mode 100644 index 0000000..d737c19 --- /dev/null +++ b/software/saturn-benchmarks/vec-mx-matmul.c @@ -0,0 +1,112 @@ +// Copy of saturn-vectors/benchmarks/vec-mx-matmul/main.c (saturn-vectors +// 4956f75) with its result check fixed. Upstream's CHECK_TEST prints "Test +// failed" on a mismatch but main still returns 0, so it cannot fail. +// saturn-vectors is upstream code and is not edited from this repo; drop this +// copy once the fix lands there. ../Makefile builds it against saturn-vectors' +// data.S and benchmark runtime. + +#include +#include +#include +#include "rvv_mx.h" + +extern size_t M; +extern size_t N; +extern size_t K; +size_t avl; +size_t vl; + +#define TEST_DATA(type, name, otype) \ + extern type name ## _a[] __attribute__((aligned(64))); \ + extern type name ## _b[] __attribute__((aligned(64))); \ + extern otype name ## _c[] __attribute__((aligned(64))); \ + extern type name ## _at[] __attribute__((aligned(64))); \ + extern type name ## _bt[] __attribute__((aligned(64))); \ + extern otype name ## _out[] __attribute__((aligned(64)));; + +#define TEST_VECTOR_OUTER(name, isew, osew, ealt, ivle, ovse) \ + printf("Testing " #name "\n"); \ + avl = N; \ + { \ + size_t n = 0; \ + while (n < N) { \ + VSETVLI_ALTFMT(vl, avl, isew, LMUL_M1, ealt); \ + for (size_t m = 0; m < M; m += 8) { \ + VSETVLI_ALTFMT_X0(vl * 16, osew, LMUL_M8, 0); \ + asm volatile("vmv.v.x v16, x0"); \ + asm volatile("vmv.v.x v24, x0"); \ + for (size_t k = 0; k < K; k ++) { \ + VSETVLI_ALTFMT_X0(vl, isew, LMUL_M1, ealt); \ + asm volatile(ivle " v0, (%0)" : : "r"(name ## _b + n + (k * N))); \ + asm volatile("vmv.v.x v8, %0" : : "r"(name ## _a[k + (m + 0) * K])); \ + asm volatile("vmv.v.x v9, %0" : : "r"(name ## _a[k + (m + 1) * K])); \ + asm volatile("vmv.v.x v10, %0" : : "r"(name ## _a[k + (m + 2) * K])); \ + asm volatile("vmv.v.x v11, %0" : : "r"(name ## _a[k + (m + 3) * K])); \ + asm volatile("vmv.v.x v12, %0" : : "r"(name ## _a[k + (m + 4) * K])); \ + asm volatile("vmv.v.x v13, %0" : : "r"(name ## _a[k + (m + 5) * K])); \ + asm volatile("vmv.v.x v14, %0" : : "r"(name ## _a[k + (m + 6) * K])); \ + asm volatile("vmv.v.x v15, %0" : : "r"(name ## _a[k + (m + 7) * K])); \ + asm volatile("vfwmacc.vv v16, v8, v0"); \ + asm volatile("vfwmacc.vv v18, v9, v0"); \ + asm volatile("vfwmacc.vv v20, v10, v0"); \ + asm volatile("vfwmacc.vv v22, v11, v0"); \ + asm volatile("vfwmacc.vv v24, v12, v0"); \ + asm volatile("vfwmacc.vv v26, v13, v0"); \ + asm volatile("vfwmacc.vv v28, v14, v0"); \ + asm volatile("vfwmacc.vv v30, v15, v0"); \ + } \ + VSETVLI_ALTFMT_X0(vl, osew, LMUL_M2, 0); \ + asm volatile(ovse " v16, (%0)" : : "r"(name ## _out + n + ((m + 0) * N))); \ + asm volatile(ovse " v18, (%0)" : : "r"(name ## _out + n + ((m + 1) * N))); \ + asm volatile(ovse " v20, (%0)" : : "r"(name ## _out + n + ((m + 2) * N))); \ + asm volatile(ovse " v22, (%0)" : : "r"(name ## _out + n + ((m + 3) * N))); \ + asm volatile(ovse " v24, (%0)" : : "r"(name ## _out + n + ((m + 4) * N))); \ + asm volatile(ovse " v26, (%0)" : : "r"(name ## _out + n + ((m + 5) * N))); \ + asm volatile(ovse " v28, (%0)" : : "r"(name ## _out + n + ((m + 6) * N))); \ + asm volatile(ovse " v30, (%0)" : : "r"(name ## _out + n + ((m + 7) * N))); \ + } \ + avl -= vl; \ + n += vl; \ + } \ + } + +#define CLEAR_OUT(name, osew) \ + memset(name ## _out, 0, M * N * osew); + +// Mismatching elements across all tests; main fails if any. Only the first few +// are printed. +static int mismatches = 0; + +#define CHECK_TEST(name) \ + for (size_t m = 0; m < M; m ++) { \ + for (size_t n = 0; n < N; n ++) { \ + uint64_t expected = name ## _c[n + (m * N)]; \ + uint64_t result = name ## _out[n + (m * N)]; \ + if (expected != result) { \ + if (mismatches++ < 8) { \ + printf("Test failed\n"); \ + printf("m = %d, n = %d, exp = %x, res = %x\n", (int)m, (int)n, (unsigned)expected, (unsigned)result); \ + } \ + } \ + } \ + } + +TEST_DATA(uint8_t, e4m3, uint16_t) +TEST_DATA(uint8_t, e5m2, uint16_t) + +int main() { + + TEST_VECTOR_OUTER(e4m3, SEW_E8, SEW_E16, 0, "vle8.v", "vse16.v") + CHECK_TEST(e4m3) + TEST_VECTOR_OUTER(e5m2, SEW_E8, SEW_E16, 1, "vle8.v", "vse16.v") + CHECK_TEST(e5m2) + + if (mismatches) { + printf("%d mismatches, FAILED\n", mismatches); + return 1; + } + + printf("All tests passed\n"); + + return 0; +} \ No newline at end of file diff --git a/software/ucie-vec-memcpy.c b/software/ucie-vec-memcpy.c index afef76d..bd3e436 100644 --- a/software/ucie-vec-memcpy.c +++ b/software/ucie-vec-memcpy.c @@ -1,7 +1,7 @@ // two-chip UCIe RVV memcpy test // -// hart 0 is the Shuttle/OPU core -// hart 1 is the Rocket tile with Saturn DMA +// harts 0 and 1 are the Shuttle/OPU cores +// hart 2 is the Rocket tile with Saturn DMA // BENCH_HART_ID picks which hart runs this test #include @@ -24,10 +24,11 @@ #define COPY_BYTES 256 #endif -// Which hart runs the test. Hart 1 is the Saturn-DMA-only rocket tile added -// by IrisConfig's "Saturn DMA" line. Tunable: -DBENCH_HART_ID=. +// Which hart runs the test. Hart 2 is the Saturn-DMA-only rocket tile added +// by IrisConfig's "Saturn DMA" line (the two ShuttleTiles are harts 0 and 1). +// Tunable: -DBENCH_HART_ID=. #ifndef BENCH_HART_ID -#define BENCH_HART_ID 1 +#define BENCH_HART_ID 2 #endif // Aligned to the 32-byte beat so the natural-alignment path is exercised. diff --git a/test/src/IrisSpec.scala b/test/src/IrisSpec.scala index e0e6b0e..829a304 100644 --- a/test/src/IrisSpec.scala +++ b/test/src/IrisSpec.scala @@ -62,18 +62,53 @@ class ClockSourceAtFreqMHz(val freqMHz: Double) ) } +/** Prints a clock's period whenever it settles on a new value: after three + * consecutive posedge-to-posedge intervals of the same length, and only if + * that length differs from the last one printed. Tests grep the log for the + * ` period ns` lines. + */ +class ClockPeriodMonitor(name: String) + extends BlackBox(Map("NAME" -> StringParam(name))) + with HasBlackBoxInline { + val io = IO(new Bundle { val clk = Input(Clock()) }) + setInline( + "ClockPeriodMonitor.sv", + """module ClockPeriodMonitor #(parameter string NAME = "clock") (input clk); + | timeunit 1ns/1ps; + | realtime last = 0.0, period = 0.0, reported = 0.0; + | integer stable = 0; + | always @(posedge clk) begin + | if (last > 0.0) begin + | if ($realtime - last == period) stable = stable + 1; + | else stable = 0; + | period = $realtime - last; + | if (stable >= 3 && period != reported) begin + | $display("[ClockPeriodMonitor] %s period %0.3f ns (at %0.3f ns)", NAME, period, $realtime); + | reported = period; + | end + | end + | last = $realtime; + | end + |endmodule + |""".stripMargin + ) +} + class SimTop( nChips: Int, binaryPaths: Seq[Path], plusArgs: Seq[Seq[String]] = Seq.empty, fast: Boolean = false, serialTLFreqMHz: Option[Double] = None, - memTrafficMonitor: Boolean = false // experiments only, see IrisExperiments.scala + memTrafficMonitor: Boolean = false, // experiments only, see IrisExperiments.scala + clockTapMonitor: Boolean = false )(implicit p: Parameters ) extends RawModule { val driver = Module(new TestDriver) - val harness = Module(new TestHarness(nChips, binaryPaths, plusArgs, fast, serialTLFreqMHz)) + val harness = Module( + new TestHarness(nChips, binaryPaths, plusArgs, fast, serialTLFreqMHz, clockTapMonitor) + ) if (memTrafficMonitor) Module(new MemTrafficMonitor) harness.io.reset := driver.reset driver.success := harness.io.success @@ -132,13 +167,17 @@ class TestDriver extends ExtModule { * clock for the serial-TL link and the off-chip memory model behind it. None * keeps the link on the 500 MHz chip clock; on silicon it is an external * clock, typically much slower than the core. + * @param clockTapMonitor + * attach a [[ClockPeriodMonitor]] to each chip's `clock_tap` output, which + * is otherwise left unconnected. */ class TestHarness( nChips: Int, binaryPaths: Seq[Path], plusArgs: Seq[Seq[String]] = Seq.empty, fast: Boolean = false, - serialTLFreqMHz: Option[Double] = None + serialTLFreqMHz: Option[Double] = None, + clockTapMonitor: Boolean = false )(implicit p: Parameters ) extends RawModule { @@ -236,6 +275,10 @@ class TestHarness( SimTSI.connect(ram.io.tsi.map(_.viewAs[TSIIO]), serialTLClock, io.reset, binaryPath, allPlusArgs) } } + if (clockTapMonitor) { + Module(new ClockPeriodMonitor(s"chip$chipId clock_tap")).io.clk := chiptop.clock_tap + } + val chipSuccessReg = withReset(io.reset.asAsyncReset)(RegInit(false.B)) when(dtm_success || success) { chipSuccessReg := true.B } chipSuccesses(chipId) := chipSuccessReg @@ -552,6 +595,121 @@ class IrisSpec extends AnyFunSpec { serialTLFreqMHz = Some(100) ) } + + it("should boot hello.riscv over TSI on the tapeout serial TL") { + // The tethered boot path as built: tapeout config (16b serial TL, no TL + // monitors), link at 100 MHz, and no +loadmem -- SimTSI writes the + // program into memory over the link, then raises hart 0's MSIP. + implicit val p = new IrisConfig(sim = false) + val workDir = Utils.buildRoot / "Iris_should_boot_hello_riscv_over_tsi_tapeout_serial_tl" + + val simLog = Utils.simulateTopWithBinaries( + workDir, + nChips = 1, + binaryPaths = Seq(Utils.root / "software/hello.riscv"), + serialTLFreqMHz = Some(100) + ) + assert(!os.read(workDir / "sim" / "simulate.sh").contains("+loadmem")) + Utils.assertLogContains(simLog, "Hello world chip") + } + + it("should run a vector kernel on every hart and contend with AMOs and LR/SC") { + // Harts 0 and 1 are the ShuttleTiles, hart 2 is Rocket (the program checks + // marchid). Each runs a self-checking RVV kernel, then all three hammer + // shared DRAM lines with AMOs and LR/SC; hart 0 checks the final values. + implicit val p = new IrisConfig(sim = true) + val workDir = Utils.buildRoot / "Iris_should_run_multihart_vec_amo" + + val simLog = Utils.simulateTopWithBinaries( + workDir, + nChips = 1, + binaryPaths = Seq(Utils.root / "software/multihart-vec-amo.riscv"), + fast = true + ) + Utils.assertLogContains(simLog, "multihart-vec-amo: all checks passed") + } + + it("should keep running with the clock dividers programmed") { + // clock-div.riscv steps the uncore and per-tile dividers through /2, /3 + // and /7, one at a time and mixed; each hart measures its clock against + // mtime and runs a memory self-check after every change. It also sets + // the clock_tap divider, whose output period the harness measures. + implicit val p = new IrisConfig(sim = true) + val workDir = Utils.buildRoot / "Iris_should_run_clock_div" + + val simLog = Utils.simulateTopWithBinaries( + workDir, + nChips = 1, + binaryPaths = Seq(Utils.root / "software/clock-div.riscv"), + fast = true, + clockTapMonitor = true + ) + Utils.assertLogContains( + simLog, + "clock-div: all checks passed", + // 500 MHz chip clock: undivided, then /2, /3, /7. + "chip0 clock_tap period 2.000 ns", + "chip0 clock_tap period 4.000 ns", + "chip0 clock_tap period 6.000 ns", + "chip0 clock_tap period 14.000 ns" + ) + } + + it("should run MX and fp8 vector benchmarks") { + // saturn-vectors' MX vector benchmarks as software/Makefile builds them, + // with a fixed copy of vec-mx-matmul, whose check cannot fail upstream + // (see software/saturn-benchmarks/). The fp8 GEMM, vme-fp8-gemm, checks + // itself and runs under "should run vme- benchmark binaries". + // Runs every benchmark, then fails with the list of those that failed. + // + // vec-fp8 is left out: at LMUL=8 its `vfmul.vv v3, v2, v1` and + // `vmsne.vv v24, v3, v2` name register groups that are not multiples of + // 8 (reserved encodings), it never uses b (v8) or c (v16), and it reads + // its verdict from v24 rather than the vredor result, so its + // "Correct"/"Incorrect" says nothing about the hardware (on Iris it + // prints "Incorrect" and exits 1). Add it back once it is fixed. + implicit val p = new IrisConfig(sim = true) + val benchmarkDir = Utils.root / "software" + val failures = + Seq("vec-mx-binary", "vec-mx-unary", "vec-mx-matmul").flatMap { + name => + val workDir = Utils.buildRoot / s"Iris_should_run_$name" + scala.util + .Try( + Utils.simulateTopWithBinaries( + workDir, + nChips = 1, + binaryPaths = Seq(benchmarkDir / s"$name.riscv"), + fast = true + ) + ) + .failed + .toOption + .map(e => s"$name: ${e.getMessage}") + } + assert(failures.isEmpty, failures.mkString("\n")) + } + + it("should run hello.riscv with X-propagation") { + // VCS -xprop=tmerge. The RANDOMIZE_* defines still apply, so registers + // and memories start from random values rather than X; what xprop adds is + // that an X reaching an if/case condition (e.g. from an undriven or + // invalid signal) propagates instead of silently taking one branch. + // Without RANDOMIZE_REG_INIT/MEM_INIT it stops at 21 ns: the chip's UART + // txd is X while the chip is still in reset, and testchipip's + // UARTAdapter, out of reset sooner, asserts on the X it samples. + implicit val p = new IrisConfig(sim = true) + val workDir = Utils.buildRoot / "Iris_should_run_hello_riscv_xprop" + + val simLog = Utils.simulateTopWithBinaries( + workDir, + nChips = 1, + binaryPaths = Seq(Utils.root / "software/hello.riscv"), + fast = true, + xprop = true + ) + Utils.assertLogContains(simLog, "Hello world chip") + } } describe("IrisDryRun") { diff --git a/test/src/Utils.scala b/test/src/Utils.scala index 673492e..2967585 100644 --- a/test/src/Utils.scala +++ b/test/src/Utils.scala @@ -64,10 +64,14 @@ script -e -f -c "./simulation >(spike-dasm > simulation.out)" simu sourceFilesList: Path, incDirs: Seq[Path] = Seq.empty, loadmem: Option[Path] = None, - debug: Boolean = false + debug: Boolean = false, + xprop: Boolean = false ) = { val dramsim_ini = root / "testchipip" / "src" / "main" / "resources" / "dramsim2_ini" val debugCompileFlags = if (debug) " +define+DEBUG -debug_access+all -kdb -lca" else "" + // X-propagation: `if`/`case` on an X condition merges both branches + // (T-merge) instead of taking the else/default branch. + val xpropCompileFlags = if (xprop) " -xprop=tmerge" else "" val debugRuntimeFlag = if (debug) " +fsdbfile=waveform.fsdb" else "" os.makeDir.all(path / os.up) os.write.over( @@ -87,7 +91,7 @@ vcs \\ +define+layer$$Verification$$Assert$$Temporal \\ +define+layer$$Verification$$Assume$$Temporal \\ +define+layer$$Verification$$Cover$$Temporal \\ - +define+VCS +define+FSDB +define+RANDOMIZE_MEM_INIT +define+RANDOMIZE_REG_INIT +define+RANDOMIZE_GARBAGE_ASSIGN +define+RANDOMIZE_INVALID_ASSIGN$debugCompileFlags \\ + +define+VCS +define+FSDB +define+RANDOMIZE_MEM_INIT +define+RANDOMIZE_REG_INIT +define+RANDOMIZE_GARBAGE_ASSIGN +define+RANDOMIZE_INVALID_ASSIGN$debugCompileFlags$xpropCompileFlags \\ -o simulation -Mdir=vcs-sources script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_dir=${dramsim_ini.toString}${loadmem.map(p => s" +loadmem=${p.toString}").getOrElse("")}$debugRuntimeFlag +permissive-off placeholder-binary >(spike-dasm > simulation.out)" simulation.log """ @@ -116,8 +120,10 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d fast: Boolean = false, debug: Boolean = false, serialTLFreqMHz: Option[Double] = None, - memTrafficMonitor: Boolean = false - )(implicit p: Parameters) = { + memTrafficMonitor: Boolean = false, + clockTapMonitor: Boolean = false, + xprop: Boolean = false + )(implicit p: Parameters): Path = { binaryPaths.zipWithIndex.foreach { case (path, i) => assert( os.exists(path), @@ -135,7 +141,7 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d os.makeDir.all(artifactsDir) ChiselStage.emitSystemVerilogFile( - new SimTop(nChips, binaryPaths, plusArgs, fast, serialTLFreqMHz, memTrafficMonitor), + new SimTop(nChips, binaryPaths, plusArgs, fast, serialTLFreqMHz, memTrafficMonitor, clockTapMonitor), args = Array( "--target-dir", sourceDir.toString @@ -157,7 +163,8 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d sourceFilesList, incDirs = os.walk(sourceDir).filter(os.isDir) ++ Seq(sourceDir), loadmem = if (fast) Some(binaryPaths(0)) else None, - debug = debug + debug = debug, + xprop = xprop ) os.proc( @@ -178,5 +185,16 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d s"simulation log reports \"$f\"" ) + s"; see ${simDir / "simulation.log"}" ) + simDir / "simulation.log" + } + + /** Asserts that a passing simulation's log contains each of `lines`, e.g. a + * program's own pass message, so a test cannot pass by a path that skips it. + */ + def assertLogContains(simLog: Path, lines: String*): Unit = { + val log = os.read(simLog) + lines.foreach { l => + assert(log.contains(l), s"simulation log does not contain \"$l\"; see $simLog") + } } }