Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/designs/simx_simulator_architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ writeback. Memory: LSU → coalescer → L1 `Cache` → L2/L3 `cache_cluster`
`Memory`. Standalone, `main.cpp` loads an image into `RAM`, programs the
KMU via DCR writes, and ticks `SimPlatform` until `!any_running()`.

### 4.1 Diagnostics: PC profile and launch checkpoints

Two opt-in diagnostics observe a run without changing simulated behaviour:

- **Per-launch PC profile** ([`pc_prof.h`](../../sim/simx/pc_prof.h),
`SIMX_PCPROF=<dir>`). Each core counts per PC the committed instructions, the
threads they ran for and the cycles its warp spent since its previous commit
(warp residence; a warp's first commit in a launch counts one cycle). Each
core owns its table and alone writes it, from its own execution domain; at
the end of each launch the processor merges the tables in host context, with
no lock, and appends them with each PC's instruction word, as the core
fetched it, to `<dir>/pcprof.<pid>.txt`. It only reads commit events.
- **Launch checkpoints** ([`launch_ckpt.h`](../../sim/simx/launch_ckpt.h)). With
`SIMX_CKPT=<dir>` (and `SIMX_CKPT_FROM` / `SIMX_CKPT_TO`) the simx runtime
saves, at the start of each launch in range, the DCR writes the device took
since reset (`<dir>/dcr.log`) and every allocated device page (content
deduplicated across launches in `<dir>/pages.dat`, indexed by
`<dir>/L<index>.idx`), after a system-scope cache flush so memory holds what
the command processor's DMA left in the last-level cache. `simx -C <dir>
-L <index>` replays that launch on any SimX build: it allocates exactly
those pages, replays the DCR writes in order and runs. A checkpoint carries
no cache contents, so the replayed launch starts with empty caches. Launch
indices are the PC profile's.

---

## 5. SST integration
Expand Down
11 changes: 11 additions & 0 deletions sim/common/mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ void RAM::clear() {
last_chunk_ = nullptr;
}

void RAM::for_each_page(const std::function<void(uint64_t addr, const uint8_t* data)>& fn) const {
for (const auto& entry : chunks_) {
for (int i = 0; i < CHUNK_SIZE; ++i) {
const uint8_t* page = entry.second[i];
if (page) {
fn(((entry.first << CHUNK_BITS) | uint64_t(i)) << page_bits_, page);
}
}
}
}

uint64_t RAM::size() const {
uint64_t allocated_pages = 0;
for (const auto& entry : chunks_) {
Expand Down
10 changes: 10 additions & 0 deletions sim/common/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#pragma once

#include <functional>

#include <VX_types.h>
#include <cstdint>
#include <vector>
Expand Down Expand Up @@ -315,6 +317,14 @@ class RAM : public MemDevice {
check_acl_ = enable;
}

// Bytes per page.
uint64_t page_size() const { return uint64_t(1) << page_bits_; }

// Visit every allocated (written) page: its byte address and
// contents (page_size() bytes). A page never written is not visited and
// reads as the sentinel page. (SimX launch checkpoints.)
void for_each_page(const std::function<void(uint64_t addr, const uint8_t* data)>& fn) const;

private:

// `allocate=false` returns a pointer into `zero_page_` for unmapped
Expand Down
89 changes: 88 additions & 1 deletion sim/simx/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "processor_impl.h"
#include "kmu.h"
#include "debug.h"
#include "pc_prof.h"
#ifdef VX_CFG_EXT_TCU_ENABLE
#include "tcu_unit.h"
#endif
Expand Down Expand Up @@ -489,9 +490,15 @@ class Core::Impl {
#endif
gather_holds_.resize(VX_CFG_ISSUE_WIDTH, std::vector<GatherHold>((uint32_t)FUType::Count));

if (PcProf::enabled()) {
pc_prof_ = std::make_unique<PcProfTable>(VX_CFG_NUM_WARPS);
}

this->reset();
}

PcProfTable* pc_prof() const { return pc_prof_.get(); }

void reset() {
for (auto& arb : ibuffer_arbs_) {
arb.reset();
Expand Down Expand Up @@ -520,6 +527,8 @@ class Core::Impl {

std::fill(ibuf_inflight_.begin(), ibuf_inflight_.end(), 0);
std::fill(ibuf_full_r_.begin(), ibuf_full_r_.end(), false);
ibuf_any_full_ = false;
queue_flags_idle_ = false;
std::fill(ibuf_queued_.begin(), ibuf_queued_.end(), 0);
std::fill(ibuf_queue_full_r_.begin(), ibuf_queue_full_r_.end(), false);

Expand All @@ -531,6 +540,13 @@ class Core::Impl {
}

void tick() {
#if !defined(VX_CFG_EXT_C_ENABLE)
if (this->quiescent()) {
this->idle_tick();
return;
}
queue_flags_idle_ = false;
#endif
this->commit();
this->return_dispatch_credits();
this->issue();
Expand Down Expand Up @@ -558,6 +574,60 @@ class Core::Impl {
DPN(2, std::flush);
}

// Nothing resident, in flight, arriving or left to clock in: no warp, CTA,
// fragment wave or spawn to start, no instruction between schedule and
// commit, no instruction fetch or LSU request outstanding, no warp-control,
// branch or barrier message waiting, no dispatch credit to return and no
// instruction-buffer full flag set. A tick then changes nothing but the
// counters idle_tick() advances, as the full one would. (A core with the
// compressed-instruction decompressor, which can hold a refetch of its own,
// always takes the full tick.)
bool quiescent() const {
if (pending_total_ != 0 || pending_ifetches_ != 0 || ibuf_any_full_
|| !scheduler_->settled() || this->running()) {
return false;
}
if (simobject_->branch_ctl_in.size() != 0 || simobject_->warp_ctl_in.size() != 0
|| simobject_->bar_unlock_in.size() != 0 || simobject_->sched_unlock_in.size() != 0
|| simobject_->sched_csr_wr_in.size() != 0) {
return false;
}
for (uint32_t fu = 0; fu < (uint32_t)FUType::Count; ++fu) {
if (dispatchers_.at(fu)->ReleaseOut.size() != 0) {
return false;
}
}
for (uint32_t w = 0; w < VX_CFG_NUM_WARPS; ++w) {
if (ibuf_inflight_[w] != 0) {
return false;
}
}
return true;
}

// The full tick of a quiescent core, as far as it shows: schedule() counts
// the (inactive) warps and an idle cycle, and update_queue_full() re-derives
// the dispatch-queue flags from the unchanged credits. Every other stage
// finds its inputs empty, and busy() is false, so the cycle is not charged.
void idle_tick() {
perf_stats_.ifetch_latency += pending_ifetches_;
perf_stats_.active_warps += scheduler_->active_warps().count();
perf_stats_.stalled_warps += scheduler_->stalled_warps().count();
++perf_stats_.sched_idle;
// The credits do not change while the core is quiescent, so after one
// update the flags hold still.
if (!queue_flags_idle_) {
this->update_queue_full();
queue_flags_idle_ = true;
}
}

bool busy() const {
return scheduler_->active_warps().any()
|| pending_total_ != 0
|| scheduler_->cta_dispatcher()->running();
}

// ----- Pipeline stages (private) -----

// Abort when a warp's staged instruction has not issued for STALL_TIMEOUT
Expand Down Expand Up @@ -630,8 +700,10 @@ class Core::Impl {
if (!any_cand) {
++perf_stats_.sched_idle;
}
ibuf_any_full_ = false;
for (uint32_t w = 0; w < VX_CFG_NUM_WARPS; ++w) {
ibuf_full_r_.at(w) = (ibuf_inflight_.at(w) == VX_CFG_IBUF_SIZE);
ibuf_any_full_ |= ibuf_full_r_.at(w);
ibuf_queue_full_r_.at(w) = (ibuf_queued_.at(w) >= VX_CFG_IBUF_SIZE);
}

Expand Down Expand Up @@ -1263,6 +1335,10 @@ class Core::Impl {
if (trace->eop && trace->instr_ptr->fcsr_writes()) {
scoreboard_->release_fcsr(trace);
}
if (pc_prof_) {
PcProf::commit(pc_prof_.get(), trace->wid, trace->PC, trace->code, (uint32_t)trace->tmask.count(),
trace->eop, SimPlatform::instance().cycles());
}

if (trace->eop) {

Expand Down Expand Up @@ -1339,7 +1415,10 @@ class Core::Impl {
if (local_mem_->ReqIn.at(b).size() != 0) {
return false;
}
if (dcache_adapters_.at(b) && !dcache_adapters_.at(b)->ReqIn.empty()) {
// A single-channel adapter is a pass-through: its input forwards to the
// data cache and holds nothing of its own.
if (dcache_adapters_.at(b) && (DCACHE_CHANNELS > 1)
&& !dcache_adapters_.at(b)->ReqIn.empty()) {
return false;
}
}
Expand Down Expand Up @@ -1552,12 +1631,16 @@ class Core::Impl {

std::vector<uint32_t> ibuf_inflight_;
std::vector<bool> ibuf_full_r_;
bool ibuf_any_full_ = false; // any ibuf_full_r_ set (schedule())
bool queue_flags_idle_ = false; // update_queue_full() since the last full tick
std::vector<uint32_t> ibuf_queued_; // [wid] instructions past the icache, not yet staged
std::vector<bool> ibuf_queue_full_r_; // [wid] full flag from ibuf_queued_, registered
std::vector<uint64_t> last_issue_; // [wid] cycle of the warp's last issue
std::vector<uint64_t> staged_since_; // [wid] cycle the last issued candidate was staged
std::vector<bool> head_staged_; // [wid] the buffer head has left for staging

std::unique_ptr<PcProfTable> pc_prof_; // SIMX_PCPROF only

PoolAllocator<instr_trace_t, 64> trace_pool_;

#ifdef VX_CFG_EXT_C_ENABLE
Expand Down Expand Up @@ -1647,6 +1730,10 @@ const Core::PerfStats& Core::perf_stats() const {
return impl_->perf_stats();
}

PcProfTable* Core::pc_prof() const {
return impl_->pc_prof();
}

int Core::get_exitcode() const {
return impl_->get_exitcode();
}
Expand Down
4 changes: 4 additions & 0 deletions sim/simx/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TcuUnit;
class SfuUnit;
class LocalMem;
class MemCoalescer;
struct PcProfTable;

class Core : public SimObject<Core> {
public:
Expand Down Expand Up @@ -179,6 +180,9 @@ class Core : public SimObject<Core> {
const PerfStats& perf_stats() const;
PerfStats& perf_stats();

// SIMX_PCPROF: this core's PC profile (nullptr when profiling is off)
PcProfTable* pc_prof() const;

int get_exitcode() const;

protected:
Expand Down
6 changes: 6 additions & 0 deletions sim/simx/cta_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class CtaDispatcher : public SimObject<CtaDispatcher> {
return has_cta_ || (bus_in.size() != 0);
}

// Not running, and no warp retirement or CTA completion left to register:
// step() would leave every piece of state as it is.
bool settled() const {
return !this->running() && retiring_.empty() && !cta_done_ && !payload_wait_;
}

protected:
void on_reset();

Expand Down
6 changes: 6 additions & 0 deletions sim/simx/decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,12 @@ Instr::Ptr Decoder::decode(uint32_t code, uint64_t uuid, bool fs_off) {
} break;
#endif
default:
// A unit this build leaves out (TEX funct3 1/5, RASTER 4, OM 3, RTU 6/7;
// misa ext bits 6, 7, 8, 11) decodes nothing: software that emits its
// instruction ignored VX_CAPS_ISA_FLAGS.
std::cerr << "error: custom-1 instruction 0x" << std::hex << code << std::dec
<< " (funct3=" << funct3 << ") is not decoded: its unit is not in this build"
<< std::endl;
std::abort();
}
// FF<->SIMT interface-law structural assertion: every FF
Expand Down
Loading
Loading