chipleap 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. chipleap/__init__.py +3 -0
  2. chipleap/__main__.py +3 -0
  3. chipleap/cli.py +635 -0
  4. chipleap/data/example-spec.yaml +18 -0
  5. chipleap/explore/__init__.py +27 -0
  6. chipleap/explore/engine.py +391 -0
  7. chipleap/explore/moves.py +391 -0
  8. chipleap/explore/score.py +98 -0
  9. chipleap/gen/__init__.py +0 -0
  10. chipleap/gen/bundle.py +185 -0
  11. chipleap/gen/datasheet.py +282 -0
  12. chipleap/gen/rtl/chipleap_accel.sv +998 -0
  13. chipleap/gen/rtl/chipleap_accel_axi.sv +267 -0
  14. chipleap/gen/rtl.py +376 -0
  15. chipleap/gen/sw/chipleap_driver.h.tpl +154 -0
  16. chipleap/gen/tb/stim_gen.cpp +108 -0
  17. chipleap/gen/tb/tb_chipleap.cpp +228 -0
  18. chipleap/gen/tb/tb_chipleap.sv +268 -0
  19. chipleap/gen/tb/tb_chipleap_axi.cpp +304 -0
  20. chipleap/gen/xheep.py +163 -0
  21. chipleap/hw/__init__.py +22 -0
  22. chipleap/hw/cpu.py +103 -0
  23. chipleap/hw/design.py +221 -0
  24. chipleap/hw/liberty.py +268 -0
  25. chipleap/hw/memory.py +180 -0
  26. chipleap/hw/tech.py +275 -0
  27. chipleap/hw/techlib.py +215 -0
  28. chipleap/mcp_server.py +610 -0
  29. chipleap/model/__init__.py +0 -0
  30. chipleap/model/accel.py +344 -0
  31. chipleap/model/bounds.py +115 -0
  32. chipleap/model/evaluate.py +553 -0
  33. chipleap/report/data.py +162 -0
  34. chipleap/report/floorplan.py +192 -0
  35. chipleap/report/html.py +366 -0
  36. chipleap/report/text.py +176 -0
  37. chipleap/spec.py +280 -0
  38. chipleap/verify/__init__.py +0 -0
  39. chipleap/verify/backends.py +114 -0
  40. chipleap/verify/consistency.py +132 -0
  41. chipleap/verify/csynth.py +283 -0
  42. chipleap/verify/hdlsim.py +256 -0
  43. chipleap/verify/innovus.py +97 -0
  44. chipleap/verify/pnr.py +183 -0
  45. chipleap/verify/remote.py +216 -0
  46. chipleap/verify/run.py +373 -0
  47. chipleap/verify/sim.py +233 -0
  48. chipleap/verify/synth.py +185 -0
  49. chipleap/verify/tools.py +160 -0
  50. chipleap/verify/xheep.py +166 -0
  51. chipleap/workload/__init__.py +20 -0
  52. chipleap/workload/graph.py +146 -0
  53. chipleap/workload/llm.py +426 -0
  54. chipleap/workload/ops.py +157 -0
  55. chipleap-0.2.0.dist-info/METADATA +142 -0
  56. chipleap-0.2.0.dist-info/RECORD +59 -0
  57. chipleap-0.2.0.dist-info/WHEEL +4 -0
  58. chipleap-0.2.0.dist-info/entry_points.txt +2 -0
  59. chipleap-0.2.0.dist-info/licenses/LICENSE +21 -0
chipleap/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """ChipLeap: architecture exploration from workload to RISC-V SoC."""
2
+
3
+ __version__ = "0.2.0"
chipleap/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from chipleap.cli import main
2
+
3
+ raise SystemExit(main())
chipleap/cli.py ADDED
@@ -0,0 +1,635 @@
1
+ """Command-line interface."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import sys
8
+ from importlib import resources
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ from chipleap import __version__
13
+ from chipleap.explore.engine import Candidate, explore
14
+ from chipleap.explore.score import Point, assess
15
+ from chipleap.gen.bundle import load_design, write_bundle
16
+ from chipleap.hw.cpu import CPUS
17
+ from chipleap.hw.design import PLATFORMS, Design, DesignError
18
+ from chipleap.hw.memory import MEMORIES
19
+ from chipleap.hw.tech import TECHNOLOGIES
20
+ from chipleap.model.bounds import requirements
21
+ from chipleap.model.evaluate import evaluate
22
+ from chipleap.report.data import evaluation_dict, explore_dict, requirements_dict
23
+ from chipleap.report.text import format_evaluation, format_explore, format_requirements, num, table
24
+ from chipleap.spec import Spec, SpecError, load_spec, parse_spec
25
+ from chipleap.workload.llm import PRESETS
26
+ from chipleap.workload.ops import Workload
27
+
28
+
29
+ def _print_json(data: Any) -> None:
30
+ print(json.dumps(data, indent=2))
31
+
32
+
33
+ def _spec_from_args(args: argparse.Namespace) -> Spec:
34
+ if getattr(args, "spec", None):
35
+ return load_spec(args.spec)
36
+ if getattr(args, "model", None):
37
+ llm: dict[str, Any] = {"model": args.model}
38
+ for key in ("phase", "context", "prompt", "batch", "weights", "kv"):
39
+ v = getattr(args, key, None)
40
+ if v is not None:
41
+ llm[key] = v
42
+ return parse_spec({"name": args.model, "workload": {"llm": llm}})
43
+ raise SpecError("give a spec file or --model")
44
+
45
+
46
+ def _workload_args(p: argparse.ArgumentParser) -> None:
47
+ p.add_argument("spec", nargs="?", help="spec file (YAML)")
48
+ p.add_argument("-m", "--model", help="LLM preset instead of a spec, e.g. llama-3.2-1b")
49
+ p.add_argument("--phase", choices=("decode", "prefill"))
50
+ p.add_argument("--context", type=int)
51
+ p.add_argument("--prompt", type=int)
52
+ p.add_argument("--batch", type=int)
53
+ p.add_argument("--weights", choices=("int8", "int4", "int2"))
54
+ p.add_argument("--kv", choices=("int8", "int4"))
55
+
56
+
57
+ def cmd_models(args: argparse.Namespace) -> int:
58
+ rows = [
59
+ [
60
+ k,
61
+ a.name,
62
+ f"{a.params / 1e9:.3f}",
63
+ str(a.layers),
64
+ str(a.hidden),
65
+ f"{a.heads}/{a.kv_heads}",
66
+ str(a.vocab),
67
+ ]
68
+ for k, a in PRESETS.items()
69
+ ]
70
+ if args.json:
71
+ _print_json(
72
+ [
73
+ {
74
+ "key": k,
75
+ "name": a.name,
76
+ "params": a.params,
77
+ "layers": a.layers,
78
+ "hidden": a.hidden,
79
+ "heads": a.heads,
80
+ "kv_heads": a.kv_heads,
81
+ "head_dim": a.head_dim,
82
+ "ffn": a.ffn,
83
+ "vocab": a.vocab,
84
+ "tied_embeddings": a.tied_embeddings,
85
+ "source": a.source,
86
+ }
87
+ for k, a in PRESETS.items()
88
+ ]
89
+ )
90
+ return 0
91
+ print(
92
+ table(
93
+ ["key", "model", "params (B)", "layers", "hidden", "heads/kv", "vocab"],
94
+ rows,
95
+ right=(2, 3, 4, 6),
96
+ )
97
+ )
98
+ return 0
99
+
100
+
101
+ def cmd_catalog(args: argparse.Namespace) -> int:
102
+ if args.json:
103
+ _print_json(
104
+ {
105
+ "technologies": {k: t.__dict__ for k, t in TECHNOLOGIES.items()},
106
+ "memories": {k: m.__dict__ for k, m in MEMORIES.items()},
107
+ "cpus": {
108
+ k: {
109
+ "name": c.name,
110
+ "kge": c.kge,
111
+ "cycles_per_mac": c.cycles_per_mac,
112
+ "note": c.note,
113
+ }
114
+ for k, c in CPUS.items()
115
+ },
116
+ }
117
+ )
118
+ return 0
119
+ print("Technologies")
120
+ print(
121
+ table(
122
+ ["key", "name", "MHz max", "I/O MT/s", "int8 MAC pJ", "SRAM pJ/B", "source"],
123
+ [
124
+ [
125
+ k,
126
+ t.name,
127
+ f"{t.max_freq_mhz:g}",
128
+ str(t.max_io_mts),
129
+ f"{t.mac_pj_8x8:.3g}",
130
+ f"{t.sram_pj_per_byte:.3g}",
131
+ "measured" if t.measured else "scaled",
132
+ ]
133
+ for k, t in TECHNOLOGIES.items()
134
+ ],
135
+ right=(2, 3, 4, 5),
136
+ )
137
+ )
138
+ print("\nExternal memories")
139
+ print(
140
+ table(
141
+ ["key", "name", "GB/s peak", "capacity MiB", "pJ/bit", "pins"],
142
+ [
143
+ [
144
+ k,
145
+ m.name,
146
+ f"{m.peak_gbps:.3g}",
147
+ str(m.capacity_mib),
148
+ f"{m.pj_per_bit:g}",
149
+ str(m.pins),
150
+ ]
151
+ for k, m in MEMORIES.items()
152
+ ],
153
+ right=(2, 3, 4, 5),
154
+ )
155
+ )
156
+ print("\nCPUs")
157
+ print(
158
+ table(
159
+ ["key", "name", "kGE", "cycles/MAC int8", "note"],
160
+ [
161
+ [k, c.name, f"{c.kge:g}", f"{c.cycles_per_mac[8]:g}", c.note]
162
+ for k, c in CPUS.items()
163
+ ],
164
+ right=(2, 3),
165
+ )
166
+ )
167
+ return 0
168
+
169
+
170
+ def _workload_summary(w: Workload) -> list[str]:
171
+ mm = w.matmuls
172
+ return [
173
+ w.description,
174
+ f"Parameters: {w.params / 1e9:.4g} B" if w.params else "",
175
+ f"Per step: {w.macs / 1e9:.4g} GMAC, {w.weight_bytes_read / 1e6:.4g} MB of weights "
176
+ f"and {w.kv_bytes_read / 1e6:.4g} MB of KV cache read, {len(mm)} matrix multiplies "
177
+ f"({sum(op.count for op in mm)} jobs).",
178
+ f"Resident: {w.storage.weights / 2**20:.4g} MiB weights, {w.storage.kv / 2**20:.4g} MiB "
179
+ f"KV cache, {w.storage.activations / 1024:.4g} KiB activation scratch.",
180
+ f"Arithmetic intensity: {w.macs / max(1.0, w.weight_bytes_read + w.kv_bytes_read):.3g} "
181
+ "MAC per byte of weights and KV read.",
182
+ ]
183
+
184
+
185
+ def cmd_workload(args: argparse.Namespace) -> int:
186
+ spec = _spec_from_args(args)
187
+ w = spec.workload()
188
+ if args.json:
189
+ _print_json(
190
+ {
191
+ "name": w.name,
192
+ "description": w.description,
193
+ "params": w.params,
194
+ "macs": w.macs,
195
+ "weight_bytes_read": w.weight_bytes_read,
196
+ "kv_bytes_read": w.kv_bytes_read,
197
+ "storage": w.storage.__dict__,
198
+ "ops": [op.__dict__ | {"type": type(op).__name__} for op in w.ops],
199
+ }
200
+ )
201
+ return 0
202
+ print("\n".join(ln for ln in _workload_summary(w) if ln))
203
+ rows = []
204
+ for op in sorted(w.matmuls, key=lambda o: -o.macs):
205
+ rows.append(
206
+ [
207
+ op.name,
208
+ f"{op.m}x{op.k}x{op.n}",
209
+ str(op.count),
210
+ num(op.macs / 1e6),
211
+ num(op.w_bytes / 1e6),
212
+ op.w_kind.value,
213
+ ]
214
+ )
215
+ print()
216
+ print(table(["matmul", "M x K x N", "count", "MMAC", "W MB", "W from"], rows, right=(2, 3, 4)))
217
+ return 0
218
+
219
+
220
+ def cmd_require(args: argparse.Namespace) -> int:
221
+ spec = _spec_from_args(args)
222
+ target = args.throughput or spec.throughput
223
+ if not target:
224
+ raise SpecError("give --throughput or a spec with targets.throughput")
225
+ req = requirements(spec.workload(), target)
226
+ if args.json:
227
+ _print_json(requirements_dict(req))
228
+ else:
229
+ print(format_requirements(req))
230
+ return 0
231
+
232
+
233
+ def _evaluate(spec: Spec, design: Design, weights: str | None) -> Candidate:
234
+ wf = weights or spec.default_weight_format()
235
+ ev = evaluate(spec.workload(wf), design, firmware_kib=spec.firmware_kib)
236
+ point = Point(design, wf)
237
+ return Candidate(point, ev, assess(spec, point, ev), "user")
238
+
239
+
240
+ def cmd_evaluate(args: argparse.Namespace) -> int:
241
+ spec = load_spec(args.spec)
242
+ design, weights = load_design(args.design)
243
+ c = _evaluate(spec, design, args.weights or weights)
244
+ if args.json:
245
+ d = evaluation_dict(c.evaluation)
246
+ d["meets_spec"] = c.assessment.meets
247
+ d["misses"] = list(c.assessment.misses)
248
+ _print_json(d)
249
+ else:
250
+ print(format_evaluation(c.evaluation))
251
+ if c.assessment.misses:
252
+ print("\nAgainst the spec:\n" + "\n".join(f" {m}" for m in c.assessment.misses))
253
+ return 0 if c.assessment.feasible else 2
254
+
255
+
256
+ def _with_platform(spec: Spec, platform: str | None) -> Spec:
257
+ if not platform:
258
+ return spec
259
+ start = spec.start.with_(platform=platform) if spec.start else None
260
+ return spec.with_(platform=platform, start=start)
261
+
262
+
263
+ def cmd_explore(args: argparse.Namespace) -> int:
264
+ spec = _with_platform(load_spec(args.spec), args.platform)
265
+ r = explore(spec, samples=args.samples, seed=args.seed, max_steps=args.steps)
266
+ if args.out:
267
+ out = Path(args.out)
268
+ write_bundle(
269
+ out, r.best.design, weights=r.best.point.weights, spec=spec, candidate=r.best, result=r
270
+ )
271
+ if args.json:
272
+ _print_json(explore_dict(r))
273
+ else:
274
+ print(format_explore(r, verbose=args.verbose))
275
+ if args.out:
276
+ dirs = "rtl/, sw/, tb/" if spec.platform == "standalone" else "xheep/, rtl/, sw/, tb/"
277
+ print(
278
+ f"\nWrote {args.out}/ (report.html, DATASHEET.md, {dirs}). "
279
+ f"Next: chipleap verify {args.out}"
280
+ )
281
+ return 0 if r.best.assessment.feasible else 2
282
+
283
+
284
+ def cmd_generate(args: argparse.Namespace) -> int:
285
+ design, weights = load_design(args.design)
286
+ spec = load_spec(args.spec) if args.spec else None
287
+ cand = _evaluate(spec, design, weights) if spec else None
288
+ if args.name:
289
+ design = design.with_(name=args.name)
290
+ if args.platform:
291
+ design = design.with_(platform=args.platform)
292
+ files = write_bundle(Path(args.out), design, weights=weights, spec=spec, candidate=cand)
293
+ print(f"Wrote {len(files)} files to {args.out}/")
294
+ return 0
295
+
296
+
297
+ def _print_steps(results: list[Any]) -> int:
298
+ failed = 0
299
+ for r in results:
300
+ print(f"{r.name:6s} {r.status.upper():8s} {r.summary}")
301
+ failed += r.status == "fail"
302
+ return 1 if failed else 0
303
+
304
+
305
+ def cmd_verify(args: argparse.Namespace) -> int:
306
+ from chipleap.verify.remote import Remote
307
+ from chipleap.verify.run import verify_bundle
308
+
309
+ steps = tuple(s.strip() for s in args.steps.split(",") if s.strip())
310
+ if "all" in steps:
311
+ # Place and route takes many minutes, so it runs only when asked for.
312
+ steps = ("consistency", "lint", "sim", "synth", "xheep", "pnr")
313
+ remote = Remote.from_env(getattr(args, "remote", None), getattr(args, "remote_setup", None))
314
+ results = verify_bundle(
315
+ Path(args.bundle),
316
+ steps=steps,
317
+ xheep_dir=Path(args.xheep) if args.xheep else None,
318
+ fetch_xheep=args.fetch_xheep,
319
+ cases=args.cases,
320
+ seed=args.seed,
321
+ sim_tool=getattr(args, "sim_tool", "verilator"),
322
+ synth_tool=getattr(args, "synth_tool", "yosys"),
323
+ synth_tech=getattr(args, "synth_tech", "ihp-sg13g2"),
324
+ remote=remote,
325
+ )
326
+ code = _print_steps(results)
327
+ print(f"\nWrote {args.bundle}/verify/VERIFY.md and verify.json")
328
+ return code
329
+
330
+
331
+ def cmd_run(args: argparse.Namespace) -> int:
332
+ code = cmd_explore(args)
333
+ if code != 0 or not args.out:
334
+ return code
335
+ print()
336
+ vargs = argparse.Namespace(
337
+ bundle=args.out,
338
+ steps=args.verify_steps,
339
+ xheep=args.xheep,
340
+ fetch_xheep=args.fetch_xheep,
341
+ cases=0,
342
+ seed=args.seed,
343
+ )
344
+ return cmd_verify(vargs)
345
+
346
+
347
+ def cmd_doctor(args: argparse.Namespace) -> int:
348
+ from chipleap.verify.tools import all_tools, ihp_liberty
349
+ from chipleap.verify.xheep import find_checkout
350
+
351
+ rows = [[t.name, "yes" if t.found else "no", t.version, t.purpose] for t in all_tools()]
352
+ import shutil
353
+
354
+ sv2v = shutil.which("sv2v")
355
+ rows.append(["sv2v", "yes" if sv2v else "no", "", "SystemVerilog front end for older Yosys"])
356
+ lib = ihp_liberty()
357
+ rows.append(
358
+ [
359
+ "IHP SG13G2",
360
+ "yes" if lib else "no",
361
+ "",
362
+ str(lib) if lib else "open PDK for synthesis (set CHIPLEAP_LIBERTY)",
363
+ ]
364
+ )
365
+ co = find_checkout()
366
+ rows.append(
367
+ [
368
+ "X-HEEP",
369
+ "yes" if co else "no",
370
+ "",
371
+ str(co) if co else "checkout for config checks (chipleap verify --fetch-xheep)",
372
+ ]
373
+ )
374
+ from chipleap.verify.remote import Remote, RemoteError
375
+ from chipleap.verify.tools import commercial
376
+
377
+ rows += [[t.name, "yes" if t.found else "no", "", t.purpose] for t in commercial()]
378
+ remote = Remote.from_env(getattr(args, "remote", None), getattr(args, "remote_setup", None))
379
+ if remote is not None:
380
+ tools = commercial()
381
+ try:
382
+ found = remote.which([t.name for t in tools])
383
+ except RemoteError as exc:
384
+ print(table(["tool", "found", "version", "used for"], rows))
385
+ print(f"\n{exc}", file=sys.stderr)
386
+ return 1
387
+ rows += [
388
+ [f"{t.name} @ {remote.host}", "yes" if t.name in found else "no", "", t.purpose]
389
+ for t in tools
390
+ ]
391
+ print(table(["tool", "found", "version", "used for"], rows))
392
+ return 0
393
+
394
+
395
+ def cmd_tech(args: argparse.Namespace) -> int:
396
+ from chipleap.hw import techlib
397
+ from chipleap.hw.tech import user_tech_dir
398
+
399
+ if args.tech_cmd == "list":
400
+ rows = [
401
+ [
402
+ k,
403
+ t.name,
404
+ f"{t.node_nm}",
405
+ "yours" if t.user else ("measured" if t.measured else "scaled"),
406
+ t.host or "",
407
+ ]
408
+ for k, t in TECHNOLOGIES.items()
409
+ ]
410
+ print(table(["key", "name", "nm", "source", "files on"], rows))
411
+ print(f"\nYour technologies live in {user_tech_dir() or '(turned off)'}")
412
+ return 0
413
+ if args.tech_cmd == "remove":
414
+ print(f"Removed {techlib.remove(args.name)}")
415
+ return 0
416
+ tech, basis = techlib.measure(
417
+ args.name,
418
+ args.liberty,
419
+ args.node,
420
+ sram=args.sram_liberty,
421
+ vdd=args.vdd,
422
+ max_mhz=args.max_mhz,
423
+ max_io_mts=args.max_io_mts,
424
+ lef=tuple(args.lef),
425
+ db=args.db,
426
+ host=args.remote,
427
+ name=args.display_name,
428
+ )
429
+ path = techlib.save(tech, force=args.force)
430
+ print(f"Added technology {tech.key!r} ({tech.node_nm} nm, {tech.vdd:g} V) in {path}")
431
+ for what, how in basis.items():
432
+ print(f" {what}: {how}")
433
+ print(
434
+ f"Explore with it: constraints: {{tech: [{tech.key}]}} in a spec, or "
435
+ f"chipleap verify DIR --synth-tool genus --synth-tech {tech.key}"
436
+ )
437
+ return 0
438
+
439
+
440
+ def cmd_init(args: argparse.Namespace) -> int:
441
+ dest = Path(args.path)
442
+ if dest.exists() and not args.force:
443
+ print(f"{dest} exists; use --force to overwrite", file=sys.stderr)
444
+ return 1
445
+ text = resources.files("chipleap").joinpath("data").joinpath("example-spec.yaml").read_text()
446
+ dest.write_text(text)
447
+ print(f"Wrote {dest}. Next: chipleap explore {dest} -o out")
448
+ return 0
449
+
450
+
451
+ def cmd_mcp(args: argparse.Namespace) -> int:
452
+ from chipleap.mcp_server import main as mcp_main
453
+
454
+ mcp_main(log_dir=args.log_dir)
455
+ return 0
456
+
457
+
458
+ def cmd_replay(args: argparse.Namespace) -> int:
459
+ from chipleap.mcp_server import replay
460
+
461
+ ok, total = replay(Path(args.log))
462
+ print(f"Replayed {total} calls: {ok} reproduced exactly, {total - ok} differ")
463
+ return 0 if ok == total else 1
464
+
465
+
466
+ def build_parser() -> argparse.ArgumentParser:
467
+ p = argparse.ArgumentParser(
468
+ prog="chipleap",
469
+ description="Architecture exploration from workload to RISC-V SoC.",
470
+ )
471
+ p.add_argument("--version", action="version", version=f"chipleap {__version__}")
472
+ sub = p.add_subparsers(dest="command", required=True)
473
+
474
+ s = sub.add_parser("models", help="list the LLM presets")
475
+ s.add_argument("--json", action="store_true")
476
+ s.set_defaults(func=cmd_models)
477
+
478
+ s = sub.add_parser("catalog", help="technologies, external memories and CPUs")
479
+ s.add_argument("--json", action="store_true")
480
+ s.set_defaults(func=cmd_catalog)
481
+
482
+ s = sub.add_parser("workload", help="what a workload needs per step")
483
+ _workload_args(s)
484
+ s.add_argument("--json", action="store_true")
485
+ s.set_defaults(func=cmd_workload)
486
+
487
+ s = sub.add_parser("require", help="minimum bandwidth, compute and capacity for a target")
488
+ _workload_args(s)
489
+ s.add_argument("-t", "--throughput", type=float, help="tokens (or units) per second")
490
+ s.add_argument("--json", action="store_true")
491
+ s.set_defaults(func=cmd_require)
492
+
493
+ s = sub.add_parser("evaluate", help="evaluate one design against a spec")
494
+ s.add_argument("spec")
495
+ s.add_argument("design", help="design.yaml or a bundle directory")
496
+ s.add_argument("--weights", choices=("int8", "int4", "int2"))
497
+ s.add_argument("--json", action="store_true")
498
+ s.set_defaults(func=cmd_evaluate)
499
+
500
+ for name, helptext in (
501
+ ("explore", "search the design space and explain the result"),
502
+ ("run", "explore, write the bundle and verify it"),
503
+ ):
504
+ s = sub.add_parser(name, help=helptext)
505
+ s.add_argument("spec")
506
+ s.add_argument("-o", "--out", required=(name == "run"), help="write a bundle here")
507
+ s.add_argument("--samples", type=int, default=2000)
508
+ s.add_argument("--seed", type=int, default=0)
509
+ s.add_argument("--steps", type=int, default=40, help="most agent steps per phase")
510
+ s.add_argument("--json", action="store_true")
511
+ s.add_argument(
512
+ "--platform",
513
+ choices=PLATFORMS,
514
+ help="override the spec: xheep (an X-HEEP SoC) or standalone (AXI4 IP, any host)",
515
+ )
516
+ s.add_argument(
517
+ "-v",
518
+ "--verbose",
519
+ action="store_true",
520
+ help="show the diagnosis and alternatives at every step",
521
+ )
522
+ if name == "run":
523
+ s.add_argument("--verify-steps", default="consistency,lint,sim,synth,xheep")
524
+ s.add_argument("--xheep", help="X-HEEP checkout")
525
+ s.add_argument("--fetch-xheep", action="store_true")
526
+ s.set_defaults(func=cmd_run)
527
+ else:
528
+ s.set_defaults(func=cmd_explore)
529
+
530
+ s = sub.add_parser(
531
+ "generate", help="write the bundle (X-HEEP config, RTL, driver) for a design"
532
+ )
533
+ s.add_argument("design", help="design.yaml or a bundle directory")
534
+ s.add_argument("-o", "--out", required=True)
535
+ s.add_argument("--spec", help="spec, to include predictions in the datasheet")
536
+ s.add_argument("--name", help="rename the design")
537
+ s.add_argument(
538
+ "--platform",
539
+ choices=PLATFORMS,
540
+ help="xheep (X-HEEP SoC) or standalone (the accelerator as AXI4 IP for any host)",
541
+ )
542
+ s.set_defaults(func=cmd_generate)
543
+
544
+ s = sub.add_parser("verify", help="lint, simulate, synthesize and X-HEEP-check a bundle")
545
+ s.add_argument("bundle")
546
+ s.add_argument(
547
+ "--steps",
548
+ default="consistency,lint,sim,synth,xheep",
549
+ help="comma-separated steps; pnr (LibreLane place and route) is opt-in, and all "
550
+ "runs every step",
551
+ )
552
+ s.add_argument("--xheep", help="X-HEEP checkout (default: CHIPLEAP_XHEEP_DIR or the cache)")
553
+ s.add_argument("--fetch-xheep", action="store_true", help="clone the tested X-HEEP commit")
554
+ s.add_argument("--cases", type=int, default=0, help="limit the number of simulation cases")
555
+ s.add_argument("--seed", type=int, default=0)
556
+ s.add_argument(
557
+ "--sim-tool",
558
+ default="verilator",
559
+ choices=["verilator", "xcelium", "vcs", "questa", "verilator-sv"],
560
+ help="simulator: Verilator (default), Cadence Xcelium, Synopsys VCS, Siemens Questa",
561
+ )
562
+ s.add_argument(
563
+ "--synth-tool",
564
+ default="yosys",
565
+ choices=["yosys", "genus", "dc"],
566
+ help="synthesis: Yosys (default), Cadence Genus or Synopsys Design Compiler",
567
+ )
568
+ s.add_argument(
569
+ "--synth-tech",
570
+ default="ihp-sg13g2",
571
+ help="technology whose liberty Genus or Design Compiler maps to (chipleap tech add)",
572
+ )
573
+ s.add_argument("--remote", help="run the simulator and synthesis on this ssh host")
574
+ s.add_argument(
575
+ "--remote-setup",
576
+ help="shell snippet that puts the tools on the path there (CHIPLEAP_REMOTE_SETUP)",
577
+ )
578
+ s.set_defaults(func=cmd_verify)
579
+
580
+ s = sub.add_parser("doctor", help="which tools ChipLeap can use here or on a server")
581
+ s.add_argument("--remote", help="also list the commercial tools on this ssh host")
582
+ s.add_argument("--remote-setup", help="shell snippet that puts the tools on the path there")
583
+ s.set_defaults(func=cmd_doctor)
584
+
585
+ s = sub.add_parser("tech", help="technologies of your own, measured from liberty files")
586
+ tsub = s.add_subparsers(dest="tech_cmd", required=True)
587
+ t = tsub.add_parser("add", help="measure a PDK's liberty files and add it as a technology")
588
+ t.add_argument("name", help="key for the technology, for example mylib40")
589
+ t.add_argument("--liberty", required=True, help="standard-cell liberty (typical corner)")
590
+ t.add_argument("--node", type=int, required=True, help="process node in nm")
591
+ t.add_argument(
592
+ "--sram-liberty", action="append", default=[], help="SRAM macro .lib file or directory"
593
+ )
594
+ t.add_argument("--vdd", type=float, default=0.0, help="supply (default: the library's)")
595
+ t.add_argument("--max-mhz", type=float, default=0.0, help="practical clock")
596
+ t.add_argument("--max-io-mts", type=int, default=0, help="fastest external memory rate")
597
+ t.add_argument("--lef", action="append", default=[], help="technology LEF, then cell LEFs")
598
+ t.add_argument("--db", default="", help="compiled .db for Design Compiler")
599
+ t.add_argument("--remote", default="", help="the files are on this ssh host")
600
+ t.add_argument("--display-name", default="", help="longer name for reports")
601
+ t.add_argument("--force", action="store_true", help="replace an existing file")
602
+ t.set_defaults(func=cmd_tech)
603
+ t = tsub.add_parser("list", help="list technologies, built in and your own")
604
+ t.set_defaults(func=cmd_tech)
605
+ t = tsub.add_parser("remove", help="remove a technology of your own")
606
+ t.add_argument("name")
607
+ t.set_defaults(func=cmd_tech)
608
+
609
+ s = sub.add_parser("init", help="write an example spec")
610
+ s.add_argument("path", nargs="?", default="chipleap.yaml")
611
+ s.add_argument("--force", action="store_true")
612
+ s.set_defaults(func=cmd_init)
613
+
614
+ s = sub.add_parser("mcp", help="run the MCP server on stdio")
615
+ s.add_argument("--log-dir", help="append every tool call to a JSONL run log here")
616
+ s.set_defaults(func=cmd_mcp)
617
+
618
+ s = sub.add_parser("replay", help="re-run the tool calls in an MCP run log and compare")
619
+ s.add_argument("log")
620
+ s.set_defaults(func=cmd_replay)
621
+ return p
622
+
623
+
624
+ def main(argv: list[str] | None = None) -> int:
625
+ parser = build_parser()
626
+ args = parser.parse_args(argv)
627
+ try:
628
+ code: int = args.func(args)
629
+ return code
630
+ except (SpecError, DesignError, KeyError, ValueError) as exc:
631
+ msg = exc.args[0] if exc.args else str(exc)
632
+ print(f"chipleap: {msg}", file=sys.stderr)
633
+ return 2
634
+ except BrokenPipeError:
635
+ return 0
@@ -0,0 +1,18 @@
1
+ name: llama-1b-edge
2
+ description: Llama 3.2 1B answering at reading speed on a battery-powered device.
3
+ workload:
4
+ llm:
5
+ model: llama-3.2-1b
6
+ phase: decode
7
+ context: 1024
8
+ batch: 1
9
+ weights: int4
10
+ kv: int8
11
+ targets:
12
+ throughput: 5 # tokens per second
13
+ constraints:
14
+ area_mm2: 8
15
+ power_mw: 400
16
+ allow:
17
+ weights: [int8, int4]
18
+ objective: energy
@@ -0,0 +1,27 @@
1
+ """Design-space exploration: scoring, moves, the explainable agent and sampling."""
2
+
3
+ from chipleap.explore.engine import (
4
+ Candidate,
5
+ Evaluator,
6
+ ExploreResult,
7
+ Step,
8
+ diagnose,
9
+ explore,
10
+ pareto_front,
11
+ run_agent,
12
+ )
13
+ from chipleap.explore.score import Assessment, Point, assess
14
+
15
+ __all__ = [
16
+ "Assessment",
17
+ "Candidate",
18
+ "Evaluator",
19
+ "ExploreResult",
20
+ "Point",
21
+ "Step",
22
+ "assess",
23
+ "diagnose",
24
+ "explore",
25
+ "pareto_front",
26
+ "run_agent",
27
+ ]