Home /Modules/cpu/epyc-with-ddr2-settings.sleela

epyc-with-ddr2-settings.sleela

lib/cpu/amd-epyc/examples/epyc-with-ddr2-settings.sleela · 192 line(s) · sleela

<< lib/cpu/amd-epyc/examples/epyc-with-ddr2-settings.sleela
   A complete, runnable SLeeLa document: bring up an AMD EPYC (Zen 5 "Turin")
   CPU, give it DDR2 memory settings, and exercise the full set of SLeeLa
   CPU-model terms โ€” the hand-written twin of lib/xlt/examples/epyc-ddr2.xlt:
   
     - DDR2 settings two ways: a real DDR2-800 module AND a DDR2 refresh-cadence
       Dynamite Connector (SLCadenceConnector) in the memory interface's slot;
     - capabilities: native GPU, DMA, and native-RAM enablement;
     - PHYSICAL memory tiers: DDR2 (usual activities) + DDR5 (competency/accuracy)
       with the main program defaulting to the accurate (DDR5) tier; and
     - per-function tier DISPATCH: a usualmem function binds the DDR2 module, an
       accuratemem function binds the DDR5 module (SLMemoryTierPolicy + router).
   
   "DDR2 settings" here means the modeled DDR2 operating point: the DDR2-800
   data rate / CAS of the actual module, and a DDR2 refresh duty cycle imposed
   in the Sleela layer (never the host OS). The CPU runs a real decode loop over
   its own instruction encoding; the memory figures reflect the DDR2 choices. >>
#sleela 2.5
material;
class EpycWithDdr2Settings {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11102;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-16";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 7;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  int result;

  void main() {
    SLComponentCatalog parts = new SLComponentCatalog();
    SLMemoryTierPolicy policy = new SLMemoryTierPolicy();

    < 1) The CPU: a real EPYC SKU (Zen 5 Turin, 64C/128T, rated 5.0 GHz boost). >
    SLAMDEPYC9575F cpu = new SLAMDEPYC9575F();
    < runs at its rated spec clock >
    cpu.configure();
    print("CPU: " + cpu.architecture());
    print("  spec clock = " + cpu.specClockMHz() + " MHz, data=" +
          cpu.dataWidth() + "-bit, regs=" + cpu.registerCount());

    < 2) DDR2 settings โ€” the actual module: DDR2-800, 64-bit, CL5 (authentic). >
    < 4 GiB DDR2-800 DIMM >
    SLMemoryModule ddr2 = parts.ddr2_800(4096);
    print("RAM: " + ddr2.name() + " (" + ddr2.technologyName() + "), CL" +
          ddr2.cl() + ", peak " + ddr2.peakBandwidthMBs() + " MB/s, first-word " +
          ddr2.firstWordLatencyNs() + " ns");

    < 3) DDR2 settings โ€” the refresh cadence, as a Dynamite Connector plugged >
    < into the memory interface's slot (resolve -> load -> bind timings). >
    SLMemoryInterface iface = new SLMemoryInterface();
    < builds+connects a DDR2 connector >
    iface.configure("EPYC DDR2 interface", ddr2, iface.TECH_DDR2);
    SLCadenceConnector slot = iface.cadenceSlot();
    print("cadence connector '" + slot.referenceId() + "' state = " + slot.state() +
          " (tREFI=" + iface.refreshIntervalNs() + " ns, tRFC=" + iface.refreshTimeNs() + " ns)");
    print("refreshes as: " + iface.refreshesAsName() + ", available duty = " +
          iface.availableDutyPct() + " % (refresh overhead " + iface.refreshOverheadPct() + " %)");

    < 4) Assemble the executor: CPU + the DDR2 module + the DDR2 cadence overlay. >
    < The backing store is the real DDR2 module; the overlay shapes the >
    < observed availability only. >
    SLExecutorBuild build = new SLExecutorBuild();
    build.configure("epyc-9575f-ddr2");
    build.installCpu(cpu);
    < actual DDR2 module (base store) >
    build.installMemory(ddr2);
    < DDR2 refresh cadence (the connector) >
    build.installMemoryInterface(iface);
    < PCIe 5.0 x16 system bus >
    build.installBus(parts.pcieGen5x16());

    < Capabilities (the gpu/dma/nativeram terms): native GPU + DMA on the CPU. >
    < native GPU compute >
    build.enableGPU();
    < DMA bulk engine >
    build.enableDMA();

    < PHYSICAL memory tiers (the memtier/maintier terms): DDR2 for usual >
    < activities, DDR5 for competency/accuracy; main program -> accurate (DDR5). >
    < usual -> DDR2 >
    build.installUsualTier(ddr2);
    < accurate -> DDR5 >
    build.installAccurateTier(parts.ddr5_6400(65536));
    build.setMainTier(policy.TIER_ACCURATE);

    < mounts the real backing stores >
    build.assemble();
    print("assembled '" + build.name() + "', memory BW seen by CPU = " +
          build.memoryBandwidthMBs() + " MB/s, DDR2 overlay active = " +
          build.hasMemoryInterface() + ", GPU=" + build.gpuEnabled() +
          ", DMA=" + build.dmaEnabled() + ", two-tier=" + build.twoTierMemory());

    < 5) Run a short program ON the EPYC CPU, using its own instruction set. >
    < Compute (7 + 5) * 3 = 36 and store it to memory word 100. >
    cpu.reset();
    < code base address (word index) >
    int a = 20;
    < r1 <- 7 >
    cpu.loadProgramWord(a + 0, cpu.encode(cpu.I_LOADI, 1, 7));
    < r2 <- 5 >
    cpu.loadProgramWord(a + 1, cpu.encode(cpu.I_LOADI, 2, 5));
    < r1 <- r1 + r2   (12) >
    cpu.loadProgramWord(a + 2, cpu.encode(cpu.I_ADD,   1, 2));
    < r3 <- 3 >
    cpu.loadProgramWord(a + 3, cpu.encode(cpu.I_LOADI, 3, 3));
    < r1 <- r1 * r3   (36) >
    cpu.loadProgramWord(a + 4, cpu.encode(cpu.I_MUL,   1, 3));
    < mem[100] <- r1 >
    cpu.loadProgramWord(a + 5, cpu.encode(cpu.I_STORE, 1, 100));
    < halt >
    cpu.loadProgramWord(a + 6, cpu.encode(cpu.I_HALT,  0, 0));
    cpu.setEntryPoint(a);
    < step until HALT (budget-bounded) >
    cpu.run(32);

    result = cpu.readMem(100);
    print("program: (7 + 5) * 3 -> r1 = " + cpu.reg(1) + ", mem[100] = " + result +
          ", instructions retired = " + cpu.instructionsRetired() +
          ", halted = " + cpu.isHalted());

    < 6) Memory-tier DISPATCH (the usualmem/accuratemem terms). A program may >
    < flag the whole document (top-level class modifier) or any subset of >
    < methods; each function resolves to the physical tier module it binds. >
    SLProgram prog = new SLProgram();
    prog.configure("epyc-workload", 256);
    < whole-document default: DDR5 >
    prog.setDocumentTier(policy.TIER_ACCURATE);

    < usualmem void logActivity()  -> usual (DDR2) >
    SLVMMethod logActivity = new SLVMMethod();
    logActivity.configure("logActivity", "()V", 0, 3, 0, 1, true, false);
    logActivity.setMemTier(policy.methodTierFromModifiers(policy.MOD_USUALMEM));
    < accuratemem int settleLedger() -> accurate (DDR5) >
    SLVMMethod settleLedger = new SLVMMethod();
    settleLedger.configure("settleLedger", "()I", 3, 5, 0, 2, true, false);
    settleLedger.setMemTier(policy.methodTierFromModifiers(policy.MOD_ACCURATEMEM));

    dispatch(build, prog, policy, logActivity);
    dispatch(build, prog, policy, settleLedger);

    < 7) A/B: disengage the DDR2 cadence to see the module's raw availability. >
    iface.disengage();
    print("overlay off -> effective BW = " + iface.effectiveBandwidthMBs() +
          " MB/s, duty " + iface.availableDutyPct() + " %");
  }

  < Resolve a method's effective tier against the document default and bind it >
  < to the real physical module (usualmem->DDR2, accuratemem->DDR5). >
  void dispatch(SLExecutorBuild build, SLProgram prog, SLMemoryTierPolicy policy, SLVMMethod m) {
    int effective = prog.effectiveTier(m.tier());
    SLMemoryModule mod = build.memoryForTier(effective);
    print("  " + m.methodName() + ": declared=" + policy.tierName(m.tier()) +
          " -> effective=" + policy.tierName(effective) +
          " -> binds " + mod.name() + " (" + mod.technologyName() + ")");
  }
}