diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2025-11-24 04:38:39 +0100 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2025-11-24 16:49:04 +0100 |
| commit | a86ef805982aac5f7de5b5f01b3f6de90dd1030d (patch) | |
| tree | 12039c17febedc5ff76ae2d45109f3ac3e4f8462 /salis.py | |
| parent | c8fc429d9e5ed8ab0566729003d60ef41f578807 (diff) | |
New simulations may use random seeds
Diffstat (limited to 'salis.py')
| -rwxr-xr-x | salis.py | 56 |
1 files changed, 33 insertions, 23 deletions
@@ -8,6 +8,7 @@ # JIT compilation allows quick switching between all available executable configurations. import os +import random import shutil import subprocess import sys @@ -40,6 +41,11 @@ new = parsers.add_parser("new", formatter_class=fclass, help="create new simul archs = os.listdir("./arch") uis = os.listdir("./ui") +def iseed(i): + ival = int(i, 0) + if ival < -1: raise ArgumentTypeError("invalid seed value") + return ival + def ipos(i): ival = int(i, 0) if ival < 0: raise ArgumentTypeError("value must be positive integer") @@ -55,31 +61,32 @@ option_keys = ["short", "long", "metavar", "description", "default", "required", # fmt: off option_conf = [ ["A", "anc", "ANC", "ancestor file name without extension, to be compiled on " - "all cores (ANC points to 'ancs/<ARCH>/<ANC>.asm')", None, True, str, [bench, new]], - ["a", "arch", archs, "VM architecture", "dummy", False, str, [bench, new]], - ["b", "steps", "N", "number of steps to run in benchmark", 0x1000000, False, ipos, [bench]], - ["C", "clones", "N", "number of ancestor clones on each core", 1, False, inat, [bench, new]], - ["c", "cores", "N", "number of simulator cores", 2, False, inat, [bench, new]], + "all cores (ANC points to 'ancs/<ARCH>/<ANC>.asm')", None, True, str, [bench, new]], + ["a", "arch", archs, "VM architecture", "dummy", False, str, [bench, new]], + ["b", "steps", "N", "number of steps to run in benchmark", 0x1000000, False, ipos, [bench]], + ["C", "clones", "N", "number of ancestor clones on each core", 1, False, inat, [bench, new]], + ["c", "cores", "N", "number of simulator cores", 2, False, inat, [bench, new]], ["d", "data-push-pow", "POW", "data aggregation interval exponent (interval == 2^POW >= " "thread sync interval); a value of 0 disables data " - "aggregation (requires 'sqlite')", 28, False, ipos, [new]], - ["f", "force", None, "overwrite existing simulation of given name", False, False, bool, [new]], - ["F", "muta-flip", None, "cosmic rays flip bits instead of randomizing whole bytes", False, False, bool, [bench, new]], - ["M", "muta-pow", "POW", "mutator range exponent (range == 2^POW)", 32, False, ipos, [bench, new]], - ["m", "mvec-pow", "POW", "memory vector size exponent (size == 2^POW)", 20, False, ipos, [bench, new]], - ["n", "name", "NAME", "name of new or loaded simulation", "def.sim", False, str, [load, new]], - ["o", "optimized", None, "builds salis binary with optimizations", False, False, bool, [bench, load, new]], + "aggregation (requires 'sqlite')", 28, False, ipos, [new]], + ["f", "force", None, "overwrite existing simulation of given name", False, False, bool, [new]], + ["F", "muta-flip", None, "cosmic rays flip bits instead of randomizing whole bytes", False, False, bool, [bench, new]], + ["M", "muta-pow", "POW", "mutator range exponent (range == 2^POW)", 32, False, ipos, [bench, new]], + ["m", "mvec-pow", "POW", "memory vector size exponent (size == 2^POW)", 20, False, ipos, [bench, new]], + ["n", "name", "NAME", "name of new or loaded simulation", "def.sim", False, str, [load, new]], + ["o", "optimized", None, "builds salis binary with optimizations", False, False, bool, [bench, load, new]], ["p", "pre-cmd", "CMD", "shell command to wrap call to executable (e.g. gdb, " - "valgrind, etc.)", None, False, str, [bench, load, new]], - ["s", "seed", "SEED", "seed value for new simulation", 0, False, ipos, [bench, new]], - ["S", "print-source", None, "print generated C source to stdout and exit", False, False, bool, [bench, load, new]], - ["T", "delete-temp-dir", None, "delete temporary directory on exit", True, False, bool, [bench, load, new]], + "valgrind, etc.)", None, False, str, [bench, load, new]], + ["s", "seed", "SEED", "seed value for new simulation; a value of 0 disables " + "cosmic rays; a value of -1 creates a random seed", 0, False, iseed, [bench, new]], + ["S", "print-source", None, "print generated C source to stdout and exit", False, False, bool, [bench, load, new]], + ["T", "delete-temp-dir", None, "delete temporary directory on exit", True, False, bool, [bench, load, new]], ["t", "thread-gap", "N", "memory gap between cores in bytes (may help reduce cache " - "misses?)", 0x100, False, inat, [bench, load, new]], - ["u", "ui", uis, "user interface", "curses", False, str, [load, new]], - ["x", "compress", None, "compress save files (requires 'zlib')", True, False, bool, [new]], - ["y", "sync-pow", "POW", "core sync interval exponent (interval == 2^POW)", 20, False, ipos, [bench, new]], - ["z", "auto-save-pow", "POW", "auto-save interval exponent (interval == 2^POW)", 36, False, ipos, [new]], + "misses?)", 0x100, False, inat, [bench, load, new]], + ["u", "ui", uis, "user interface", "curses", False, str, [load, new]], + ["x", "compress", None, "compress save files (requires 'zlib')", True, False, bool, [new]], + ["y", "sync-pow", "POW", "core sync interval exponent (interval == 2^POW)", 20, False, ipos, [bench, new]], + ["z", "auto-save-pow", "POW", "auto-save interval exponent (interval == 2^POW)", 36, False, ipos, [new]], ] # fmt: on @@ -225,13 +232,16 @@ inst_mask = "0x7f" ipc_flag = "0x80" mall_flag = "0x80" muta_range = ul_pow(args.muta_pow) -muta_seed = ul_val(args.seed) mvec_size = ul_pow(args.mvec_pow) sync_interval = ul_pow(args.sync_pow) thread_gap = ul_val(args.thread_gap) uint64_half = ul_val(0x8000000000000000) -args.seed = ul_val(args.seed) +if args.seed == -1: + args.seed = ul_val(random.getrandbits(64)) + info("Using random seed", args.seed) +else: + args.seed = ul_val(args.seed) if args.command in ["bench"]: includes.append("stdio.h") |
