From 6d571bebee8f711b836e08672615e43345dbf2dd Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 15:40:37 -0800 Subject: [PATCH 01/12] common: rename the __assert macro to VX_ASSERT -- EL9 (glibc 2.34) debug builds compile again util.h defines a two-argument __assert macro. Double-underscore names are reserved for the implementation, and glibc uses this one: its declares `extern void __assert (const char *, const char *, int)`, and in glibc 2.34 (RHEL/EL9) that declaration is not guarded, so every inclusion of / repeats it. In a debug build (no NDEBUG) any translation unit that includes after util.h then expands glibc's declaration through the macro and fails: "macro "__assert" passed 3 arguments, but takes just 2". Measured on master 2496be342 on EL9 with every runtime driver built with DEBUG=1 (make -k): 39 translation units fail (simx 33, rtlsim 2, xrt 2, opae 2), through our own headers (sim/common/simobject.h, sw/common/ smallfunc.h, sw/common/mem_alloc.h, ...) and two third-party paths (ramulator's spdlog in dram_sim.cpp, Verilator's verilated_vpi.h in dpi_float.cpp). 38 product files include or , so reordering includes would have to cover every one of them, and any new after util.h would break again. debug:demo-5 (simx --debug=1) and debug:demo-4 (xrtsim --debug=1) fail to build on EL9. CI's runner (ubuntu-22.04, glibc 2.35) is not affected: debug:demo-5 passes there. This is a host-portability fix, like #537's EL9 fixes. Behaviour is unchanged: the same always-on check, the same message, the same cold out-of-line report and abort. Every use is renamed (11 files). Co-Authored-By: Claude Opus 5.5 --- sim/common/fixed_vector.h | 12 ++++---- sim/common/simobject.h | 58 ++++++++++++++++++------------------- sim/simx/cta_dispatcher.cpp | 4 +-- sim/simx/mem/cache.cpp | 26 ++++++++--------- sim/simx/mem/mmu.cpp | 2 +- sim/simx/mem/ptw.cpp | 8 ++--- sim/simx/mem/tlb_l2.cpp | 2 +- sim/simx/processor.cpp | 2 +- sw/common/ringqueue.h | 10 +++---- sw/common/smallfunc.h | 2 +- sw/common/util.h | 2 +- 11 files changed, 64 insertions(+), 64 deletions(-) diff --git a/sim/common/fixed_vector.h b/sim/common/fixed_vector.h index 76799e1a45..c8164a453b 100644 --- a/sim/common/fixed_vector.h +++ b/sim/common/fixed_vector.h @@ -46,7 +46,7 @@ class FixedVector { } FixedVector(std::initializer_list init) : size_(0) { - __assert(init.size() <= N, "FixedVector: capacity " << N << " exceeded"); + VX_ASSERT(init.size() <= N, "FixedVector: capacity " << N << " exceeded"); for (auto& v : init) { data_[size_++] = v; } @@ -69,11 +69,11 @@ class FixedVector { const_reference operator[](size_type i) const { return data_[i]; } reference at(size_type i) { - __assert(i < size_, "FixedVector: index " << i << " out of range " << size_); + VX_ASSERT(i < size_, "FixedVector: index " << i << " out of range " << size_); return data_[i]; } const_reference at(size_type i) const { - __assert(i < size_, "FixedVector: index " << i << " out of range " << size_); + VX_ASSERT(i < size_, "FixedVector: index " << i << " out of range " << size_); return data_[i]; } @@ -83,7 +83,7 @@ class FixedVector { const_reference back() const { return data_[size_ - 1]; } void assign(size_type n, const T& value) { - __assert(n <= N, "FixedVector: capacity " << N << " exceeded"); + VX_ASSERT(n <= N, "FixedVector: capacity " << N << " exceeded"); for (size_type i = 0; i < n; ++i) { data_[i] = value; } @@ -91,7 +91,7 @@ class FixedVector { } void resize(size_type n, const T& value = T{}) { - __assert(n <= N, "FixedVector: capacity " << N << " exceeded"); + VX_ASSERT(n <= N, "FixedVector: capacity " << N << " exceeded"); for (size_type i = size_; i < n; ++i) { data_[i] = value; } @@ -99,7 +99,7 @@ class FixedVector { } void push_back(const T& value) { - __assert(size_ < N, "FixedVector: capacity " << N << " exceeded"); + VX_ASSERT(size_ < N, "FixedVector: capacity " << N << " exceeded"); data_[size_++] = value; } diff --git a/sim/common/simobject.h b/sim/common/simobject.h index caaa063b3d..490ca333ae 100644 --- a/sim/common/simobject.h +++ b/sim/common/simobject.h @@ -218,10 +218,10 @@ class SimPlatform { // kernel's cross-domain latencies are physical. void set_quantum(uint32_t cycles) { if constexpr (kSimFunctional) { - __assert(!mt_init_done_, "the quantum is fixed once execution starts"); + VX_ASSERT(!mt_init_done_, "the quantum is fixed once execution starts"); quantum_ = std::max(1u, cycles); } else { - __assert(cycles <= 1, "a synchronization quantum requires the functional kernel"); + VX_ASSERT(cycles <= 1, "a synchronization quantum requires the functional kernel"); } } @@ -335,7 +335,7 @@ class SimPlatform { } __attribute__((noinline)) Domain& domain_grow(uint32_t d) { - __assert(!workers_started_, "domain created during parallel execution"); + VX_ASSERT(!workers_started_, "domain created during parallel execution"); while (domains_.size() <= d) { domains_.push_back(std::make_unique()); domains_.back()->id = uint32_t(domains_.size() - 1); @@ -480,7 +480,7 @@ class SimPlatform { // Elaboration or serial execution only: parallel workers find every lane // materialized by init_mt. __attribute__((noinline)) CrossLane& cross_lane_grow(uint32_t target, uint32_t lane) { - __assert(!workers_started_, "cross-domain lane created during parallel execution"); + VX_ASSERT(!workers_started_, "cross-domain lane created during parallel execution"); if (mail_.size() <= target) { mail_.resize(target + 1); } @@ -639,7 +639,7 @@ class SimPlatform { tl_exec_domain_ = HOST_DOMAIN; tl_exec_task_ = nullptr; if (sync_stop_fn_(sync_stop_arg_, busy)) { - __assert(!busy, "run_until: stop() returned true on a busy cycle"); + VX_ASSERT(!busy, "run_until: stop() returned true on a busy cycle"); sync_stop_.store(true, std::memory_order_release); return; } @@ -796,7 +796,7 @@ class SimPlatform { inline SimTask::SimTask() : domain_(SimPlatform::instance().build_domain()) {} __attribute__((always_inline)) inline void SimPlatform::wake_at(SimTask* task, uint64_t cycle) { - __assert(task->scan_domain_ != nullptr, "a timed wake-up needs a task in a scan"); + VX_ASSERT(task->scan_domain_ != nullptr, "a timed wake-up needs a task in a scan"); auto& dom = *static_cast(task->scan_domain_); if (cycle <= dom.now) { *task->word_ |= task->bit_; @@ -847,26 +847,26 @@ class SimEventLink { // Sender end: wire to the receiving end. void bind(SimEventLink* sink) { - __assert(sink != nullptr, "bind target is null"); - __assert(sink_ == nullptr && !handler_, "link end already bound"); + VX_ASSERT(sink != nullptr, "bind target is null"); + VX_ASSERT(sink_ == nullptr && !handler_, "link end already bound"); sink_ = sink; } // Receiver end: the member-function handler invoked on delivery. template void bind(Impl* obj, void (Impl::*handler)(const Msg&)) { - __assert(obj != nullptr, "handler object is null"); - __assert(sink_ == nullptr && !handler_, "link end already bound"); + VX_ASSERT(obj != nullptr, "handler object is null"); + VX_ASSERT(sink_ == nullptr && !handler_, "link end already bound"); handler_ = [obj, handler](const Msg& msg) { (obj->*handler)(msg); }; } void send(const Msg& msg, uint64_t delay = 1) { - __assert(delay >= 1, "event link delivery requires a registered delay"); + VX_ASSERT(delay >= 1, "event link delivery requires a registered delay"); auto* ep = this; while (ep->sink_ != nullptr) { ep = ep->sink_; } - __assert(!!ep->handler_, "event link has no bound handler"); + VX_ASSERT(!!ep->handler_, "event link has no bound handler"); SimPlatform::instance().cross_call(ep->domain_, [ep, msg, delay]() { if (delay > 1) { ep->send(msg, delay - 1); // re-issued from the receiver's own context @@ -900,7 +900,7 @@ class DelayRing { explicit DelayRing(uint32_t capacity) : capacity_(capacity) , slots_(new Slot[capacity]) { - __assert(capacity > 0, "a port needs a capacity"); + VX_ASSERT(capacity > 0, "a port needs a capacity"); } DelayRing(const DelayRing&) = delete; DelayRing& operator=(const DelayRing&) = delete; @@ -930,7 +930,7 @@ class DelayRing { template void insert(P&& pkt, uint64_t ready) { if (size_ == capacity_) { - __assert(kSimFunctional, "port overflow"); + VX_ASSERT(kSimFunctional, "port overflow"); this->grow(); } uint32_t i = size_; @@ -967,7 +967,7 @@ class DelayRing { // Functional kernel: no back-pressure, so a port doubles when it fills; a // feedback loop that outruns its reader fails at the high-water mark. __attribute__((noinline)) void grow() { - __assert(capacity_ < (1u << 20), "functional port high-water exceeded"); + VX_ASSERT(capacity_ < (1u << 20), "functional port high-water exceeded"); std::unique_ptr slots(new Slot[capacity_ * 2]); for (uint32_t i = 0; i < size_; ++i) { auto& src = slots_[this->wrap(head_ + i)]; @@ -1108,7 +1108,7 @@ class SimPortInBase { SimPortInBase(SimObjectBase* owner, ServeFn serve) : owner_(owner) { if (serve != nullptr) { - __assert(!owner->ticks_, "a unit with on_tick() reads its ports itself: SimPortIn{this, capacity}"); + VX_ASSERT(!owner->ticks_, "a unit with on_tick() reads its ports itself: SimPortIn{this, capacity}"); entry_.reset(new Entry()); entry_->in = this; entry_->serve = serve; @@ -1116,7 +1116,7 @@ class SimPortInBase { owner->handlers_.push_back(this); reader_ = entry_.get(); } else { - __assert(owner->ticks_, "a port without a handler is read by the unit's on_tick()"); + VX_ASSERT(owner->ticks_, "a port without a handler is read by the unit's on_tick()"); owner->plain_.push_back(this); reader_ = owner; } @@ -1212,13 +1212,13 @@ class SimPortIn final : public SimPortInBase { bool empty() const { return ring_.head_ready() > *clock_; } const T& peek() const { - __assert(!this->empty(), "port is empty"); + VX_ASSERT(!this->empty(), "port is empty"); return ring_.front(); } /// Take the oldest visible packet. T pop() { - __assert(!this->empty(), "port is empty"); + VX_ASSERT(!this->empty(), "port is empty"); T pkt(std::move(ring_.front())); this->remove(); return pkt; @@ -1338,7 +1338,7 @@ class SimPortIn final : public SimPortInBase { return; } } - __assert(num_waiters_ < kMaxWaiters, "too many producers waiting on one port"); + VX_ASSERT(num_waiters_ < kMaxWaiters, "too many producers waiting on one port"); waiters_[num_waiters_++] = waiter; } @@ -1354,7 +1354,7 @@ class SimPortIn final : public SimPortInBase { auto& platform = SimPlatform::instance(); uint32_t domain = reader_->domain(); if (platform.is_cross_exec(domain)) { - __assert(latency >= 1, "a cross-domain send needs a registered latency"); + VX_ASSERT(latency >= 1, "a cross-domain send needs a registered latency"); if constexpr (sizeof(T) <= 128) { platform.cross_call(domain, [this, p = std::move(pkt), latency]() { this->arrive(T(p), latency - 1); @@ -1366,7 +1366,7 @@ class SimPortIn final : public SimPortInBase { } return; } - __assert(this->has_room(), "send on a full port"); + VX_ASSERT(this->has_room(), "send on a full port"); uint64_t ready = *clock_ + latency; ++*inflight_; ring_.insert(std::move(pkt), ready); @@ -1431,8 +1431,8 @@ class SimPortOut final : public SimPortOutBase { /// Bind to a reader. `latency` is the one send(pkt) uses. void bind(SimPortIn* sink, uint32_t latency = 1) { - __assert(sink != nullptr, "bind target is null"); - __assert(sink_ == nullptr, "output already bound"); + VX_ASSERT(sink != nullptr, "bind target is null"); + VX_ASSERT(sink_ == nullptr, "output already bound"); sink_ = sink; latency_ = latency; } @@ -1508,10 +1508,10 @@ class SimPortOut final : public SimPortOutBase { } __attribute__((noinline, cold)) void resolve_first() const { - __assert(sink_ != nullptr, "send on an unbound output"); + VX_ASSERT(sink_ != nullptr, "send on an unbound output"); SimPortIn* in = sink_; while (in->fwd_ != nullptr) { - __assert(in->fwd_->sink_ != nullptr, "a wire to an unbound output"); + VX_ASSERT(in->fwd_->sink_ != nullptr, "a wire to an unbound output"); in = in->fwd_->sink_; } if (in->conv_) { @@ -1796,7 +1796,7 @@ void SimPlatform::run_until(Stop&& stop) { } while (!stop()); return; } - __assert(!run_active_, "run_until() is not reentrant"); + VX_ASSERT(!run_active_, "run_until() is not reentrant"); using StopFn = std::remove_reference_t; run_stop_ = [](void* arg) -> bool { return (*static_cast(arg))(); }; run_stop_arg_ = const_cast(static_cast(&stop)); @@ -1823,8 +1823,8 @@ void SimPlatform::run_until(Stop&& stop, const std::vector& voters, Busy&& } while (!stop(false)); return; } - __assert(!run_active_ && !sync_active_, "run_until() is not reentrant"); - __assert(stripe_domains_[0].front()->id == 0, "thread 0 owns the uncore domain"); + VX_ASSERT(!run_active_ && !sync_active_, "run_until() is not reentrant"); + VX_ASSERT(stripe_domains_[0].front()->id == 0, "thread 0 owns the uncore domain"); if (sync_progress_ == nullptr) { this->sync_init_graph(); } diff --git a/sim/simx/cta_dispatcher.cpp b/sim/simx/cta_dispatcher.cpp index 51befb9d0a..6c558da436 100644 --- a/sim/simx/cta_dispatcher.cpp +++ b/sim/simx/cta_dispatcher.cpp @@ -208,9 +208,9 @@ uint32_t CtaDispatcher::step(const WarpMask& active_warps, uint32_t* wids, cta_w } // A member's cluster rank is its slot modulo the cluster size, and slot 0 // is the only one granted beyond the kernel's capacity. - __assert(is_single || !next.is_first_of_cluster || (base % k) == 0, + VX_ASSERT(is_single || !next.is_first_of_cluster || (base % k) == 0, "cluster window at slot " << base << " is not aligned to its size " << k); - __assert(base == 0 || stride == 0 || (uint64_t(base) + 1) * stride <= lmem_capacity_, + VX_ASSERT(base == 0 || stride == 0 || (uint64_t(base) + 1) * stride <= lmem_capacity_, "slot " << base << " is outside the capacity for a " << stride << "-byte CTA"); // A new launch is a new context: every slot owes the startup again. Keyed on diff --git a/sim/simx/mem/cache.cpp b/sim/simx/mem/cache.cpp index ae9622aec4..cc4bbda360 100644 --- a/sim/simx/mem/cache.cpp +++ b/sim/simx/mem/cache.cpp @@ -839,7 +839,7 @@ class CacheBank : public SimObject { return; } // the two walks share the sector cursor - __assert(!token_flushing_, "flush walk started during a flush-token walk"); + VX_ASSERT(!token_flushing_, "flush walk started during a flush-token walk"); flushing_ = true; flush_set_idx_ = 0; flush_way_idx_ = 0; @@ -854,7 +854,7 @@ class CacheBank : public SimObject { // A flush token's walk: one entry per cycle, every set (every way of a // write-back cache), writing back dirty data and invalidating the lines. void token_flush_begin(bool skip) { - __assert(!flushing_, "flush-token walk started during a flush walk"); + VX_ASSERT(!flushing_, "flush-token walk started during a flush walk"); token_flushing_ = true; token_flush_skip_ = skip; token_flush_idx_ = 0; @@ -2313,7 +2313,7 @@ class CacheBank : public SimObject { } uint32_t set_id = params_.addr_set_id(fill.addr); auto it = std::find(pipe_fill_sets_.begin(), pipe_fill_sets_.end(), set_id); - __assert(it != pipe_fill_sets_.end(), "in-pipe fill mirror underflow"); + VX_ASSERT(it != pipe_fill_sets_.end(), "in-pipe fill mirror underflow"); pipe_fill_sets_.erase(it); } @@ -2424,7 +2424,7 @@ class CachePortArb : public SimObject { , merge_line_(merge_line) , skid_(skid) { - __assert(merge_group_ <= 1 || (merge_group_ <= 64 && ispow2(merge_group_) && (num_inputs % merge_group_) == 0), + VX_ASSERT(merge_group_ <= 1 || (merge_group_ <= 64 && ispow2(merge_group_) && (num_inputs % merge_group_) == 0), "a read-merge group must be a power of two of at most 64 dividing the ports"); tree_stage_.reserve(levels_.size()); for (auto slices : levels_) { @@ -2750,7 +2750,7 @@ class CachePortArb : public SimObject { auto req = ReqIn.at(i).peek(); uint64_t mask = (merge_group_ > 1) ? merged.at(i) : 0; uint64_t tag = (((uint64_t(req.tag) << this->merge_bits()) | mask) << lg2_inputs_) | i; - __assert((tag >> 32) == 0, "cache bank tag overflow"); + VX_ASSERT((tag >> 32) == 0, "cache bank tag overflow"); req.tag = uint32_t(tag); req.merged_tags = this->merged_tags(i, mask); auto& offer = offers_.at(b); @@ -2772,7 +2772,7 @@ class CachePortArb : public SimObject { offer.held = false; return; } - __assert(offer.valid, "bank took a request the arbiter did not offer"); + VX_ASSERT(offer.valid, "bank took a request the arbiter did not offer"); this->release_ports(b); } @@ -2849,7 +2849,7 @@ class CachePortArb : public SimObject { } } uint64_t tag = (((uint64_t(req.tag) << this->merge_bits()) | mask) << lg2_inputs_) | i; - __assert((tag >> 32) == 0, "cache bank tag overflow"); + VX_ASSERT((tag >> 32) == 0, "cache bank tag overflow"); req.tag = uint32_t(tag); this->put(0, k, b, req, delay_); ReqIn.at(i).pop(); @@ -3040,8 +3040,8 @@ class CacheRspMcast : public SimObject { , join_rr_(num_outputs, slices_ - 1) , tree_stage_(this, (slices_ > 1) ? num_outputs * slices_ : 0, 2) { - __assert(num_outputs <= 64 && merge_group < 64, "the read-merge response network takes at most 64 ports"); - __assert(arb_tree_levels(num_banks).size() <= 1, "the read-merge response network takes one tree level"); + VX_ASSERT(num_outputs <= 64 && merge_group < 64, "the read-merge response network takes at most 64 ports"); + VX_ASSERT(arb_tree_levels(num_banks).size() <= 1, "the read-merge response network takes one tree level"); // A bank's response queue and each tree slice are skid buffers: a slot // the arbiter frees takes a new response from the next cycle. for (auto& in : RspIn) { @@ -3118,7 +3118,7 @@ class CacheRspMcast : public SimObject { uint32_t lane_tag = rsp.tag; rsp.tag >>= (lg2_outputs_ + merge_group_); if (merge_line_ && o != (lane_tag & ((1u << lg2_outputs_) - 1))) { - __assert(rsp.merged_tags, "a line-merged response lost its merged tags"); + VX_ASSERT(rsp.merged_tags, "a line-merged response lost its merged tags"); rsp.tag = rsp.merged_tags->at(o % merge_group_); } if (try_put(o, sl, rsp)) { @@ -3252,14 +3252,14 @@ class Cache::Impl { uint32_t mem_net_delay = omega_stages(num_banks, config_.mem_ports) - 1; uint32_t mem_net_extra = (mem_net_delay > mem_arb_delay) ? (mem_net_delay - mem_arb_delay) : 0; uint32_t mem_arb_rsp_delay = (num_banks != config_.mem_ports) ? (mem_arb_delay + mem_net_extra) : 0; - __assert(num_banks >= config_.mem_ports, "a cache needs a bank per memory port"); + VX_ASSERT(num_banks >= config_.mem_ports, "a cache needs a bank per memory port"); // A memory response reaches its bank through the port's response queue, // when there is one, and a response network registered at every level. // The taps carry what the bank arbiter's response delay does not. uint32_t mem_rsp_regs = omega_stages(config_.mem_ports, num_banks) + (config_.mem_rsp_queue ? 1 : 0); uint32_t mem_rsp_credit = mem_arb_rsp_delay + (config_.mem_rsp_slice ? 1 : 0); - __assert(mem_rsp_regs >= mem_rsp_credit, "memory response path shorter than its arbiter"); + VX_ASSERT(mem_rsp_regs >= mem_rsp_credit, "memory response path shorter than its arbiter"); uint32_t tap_delay = mem_rsp_regs - mem_rsp_credit; // flush-token taps, ticking after the arbiters that feed them and before @@ -3330,7 +3330,7 @@ class Cache::Impl { }; if (port_arb_->merge_bits() != 0) { // one buffered arbiter per core port over the bank lanes - __assert(config_.core_out_buf, "read merging needs a registered core-response port"); + VX_ASSERT(config_.core_out_buf, "read merging needs a registered core-response port"); core_rsp_delay_ = 1; } else if (config_.core_out_buf) { bank_core_xbar_ = MemCrossBar::Create(sname, ArbiterType::RoundRobin, config_.num_inputs, num_banks, bank_sel, 0, 0); diff --git a/sim/simx/mem/mmu.cpp b/sim/simx/mem/mmu.cpp index f7f26805d0..5689dc7443 100644 --- a/sim/simx/mem/mmu.cpp +++ b/sim/simx/mem/mmu.cpp @@ -327,7 +327,7 @@ void Mmu::on_tick() { const TlbRsp& rsp = TlbFillIn.peek(); int id = (int)rsp.slot; // Dropping a fill would leave its parked requests waiting forever. - __assert(id >= 0 && id < (int)mshr_.size() && mshr_[id].valid, + VX_ASSERT(id >= 0 && id < (int)mshr_.size() && mshr_[id].valid, "TLB fill does not match an outstanding miss"); if (!rsp.fault) { tlb_.fill(mshr_[id].vpn, rsp.ppn, rsp.flags, rsp.level); diff --git a/sim/simx/mem/ptw.cpp b/sim/simx/mem/ptw.cpp index 7d62a4fb64..6108d6ed92 100644 --- a/sim/simx/mem/ptw.cpp +++ b/sim/simx/mem/ptw.cpp @@ -139,7 +139,7 @@ void Ptw::on_tick() { uint32_t wid = rsp.tag; // A PTE response that matches no waiting walker cannot be recovered: // the walker it belonged to would wait forever and hang the launch. - __assert(wid < walkers_.size() && walkers_[wid].state == W_WAIT, + VX_ASSERT(wid < walkers_.size() && walkers_[wid].state == W_WAIT, "PTE response does not match a waiting walker"); on_pte_response(walkers_[wid], rsp); MemRspIn.pop(); @@ -212,7 +212,7 @@ void Ptw::on_tick() { if (!ReqIn.empty()) { // Without a root there is nothing to walk and the request would sit // here forever, stalling the miss station that owns it. - __assert(satp_ != nullptr, "walk requested before the page-table root was set"); + VX_ASSERT(satp_ != nullptr, "walk requested before the page-table root was set"); for (auto& w : walkers_) { if (w.state != W_IDLE) { continue; @@ -264,7 +264,7 @@ void PtwMux::on_tick() { if (!RspIn.empty()) { TlbRsp rsp = RspIn.peek(); uint32_t input = rsp.slot >> SLOT_BITS; - __assert(input < num_inputs_, "PtwMux fill routes to a missing input"); + VX_ASSERT(input < num_inputs_, "PtwMux fill routes to a missing input"); if (!RspOut.at(input).full()) { rsp.slot &= (1u << SLOT_BITS) - 1; RspOut.at(input).send(rsp, 1); @@ -282,7 +282,7 @@ void PtwMux::on_tick() { continue; } TlbReq req = ReqIn.at(g).peek(); - __assert(req.slot < (1u << SLOT_BITS), "L2-TLB slot overflows the mux id space"); + VX_ASSERT(req.slot < (1u << SLOT_BITS), "L2-TLB slot overflows the mux id space"); req.slot |= g << SLOT_BITS; // report_only fills nothing; encoding is harmless ReqOut.send(req, 1); ReqIn.at(g).pop(); diff --git a/sim/simx/mem/tlb_l2.cpp b/sim/simx/mem/tlb_l2.cpp index abb9ab7f07..0997ac65b8 100644 --- a/sim/simx/mem/tlb_l2.cpp +++ b/sim/simx/mem/tlb_l2.cpp @@ -127,7 +127,7 @@ void L2Tlb::on_tick() { const TlbRsp& rsp = PtwRspIn.peek(); uint32_t id = rsp.slot; // Dropping a fill would strand every L1 miss station attached to it. - __assert(id < mshr_.size() && mshr_[id].valid, + VX_ASSERT(id < mshr_.size() && mshr_[id].valid, "walker fill does not match an outstanding entry"); if (!rsp.fault) { fill(mshr_[id].vpn, rsp.ppn, rsp.flags, rsp.level); diff --git a/sim/simx/processor.cpp b/sim/simx/processor.cpp index 53d47acc35..2bbf240dd4 100644 --- a/sim/simx/processor.cpp +++ b/sim/simx/processor.cpp @@ -406,7 +406,7 @@ void ProcessorImpl::cp_mem_read(uint64_t addr, void* dst, uint64_t size) { } void ProcessorImpl::cp_mem_transfer(uint64_t addr, const uint8_t* src, uint8_t* dst, uint64_t size, bool noalloc) { - __assert(cp_llc_port_, "no CP port on the last-level cache"); + VX_ASSERT(cp_llc_port_, "no CP port on the last-level cache"); if (!platform_reset_) { this->reset(); } diff --git a/sw/common/ringqueue.h b/sw/common/ringqueue.h index 399fa12197..a95f1a8fa3 100644 --- a/sw/common/ringqueue.h +++ b/sw/common/ringqueue.h @@ -35,7 +35,7 @@ class RingQueue { explicit RingQueue(uint32_t cap) : capacity_(cap), head_(0), tail_(0), size_(0) { - __assert(capacity_ > 0, "RingQueue: capacity must be > 0"); + VX_ASSERT(capacity_ > 0, "RingQueue: capacity must be > 0"); storage_.reset(new Storage[capacity_]); } @@ -76,26 +76,26 @@ class RingQueue { uint32_t capacity() const { return capacity_; } const T& front() const { - __assert(size_ > 0, "RingQueue: empty"); + VX_ASSERT(size_ > 0, "RingQueue: empty"); return *ptr(head_); } void pop() { - __assert(size_ > 0, "RingQueue: empty"); + VX_ASSERT(size_ > 0, "RingQueue: empty"); ptr(head_)->~T(); head_ = inc(head_); --size_; } void push(const T& v) { - __assert(size_ < capacity_, "RingQueue: full"); + VX_ASSERT(size_ < capacity_, "RingQueue: full"); new (&storage_[tail_]) T(v); tail_ = inc(tail_); ++size_; } void push(T&& v) { - __assert(size_ < capacity_, "RingQueue: full"); + VX_ASSERT(size_ < capacity_, "RingQueue: full"); new (&storage_[tail_]) T(std::move(v)); tail_ = inc(tail_); ++size_; diff --git a/sw/common/smallfunc.h b/sw/common/smallfunc.h index 49738762b5..edd6783204 100644 --- a/sw/common/smallfunc.h +++ b/sw/common/smallfunc.h @@ -93,7 +93,7 @@ class SmallFunction { explicit operator bool() const { return vtbl_ != nullptr; } R operator()(Args... args) const { - __assert(vtbl_ != nullptr, "SmallFunction: call on empty"); + VX_ASSERT(vtbl_ != nullptr, "SmallFunction: call on empty"); return vtbl_->invoke(this, std::forward(args)...); } diff --git a/sw/common/util.h b/sw/common/util.h index 735abae836..5009a29bca 100644 --- a/sw/common/util.h +++ b/sw/common/util.h @@ -33,7 +33,7 @@ void unused(Args &&...) {} // The failure report runs in a cold, out-of-line lambda: a call site keeps // only the test and a call, so small functions that assert stay inlinable. -#define __assert(cond, msg) \ +#define VX_ASSERT(cond, msg) \ if (__builtin_expect(!(cond), 0)) { \ [&, vx_func_ = __func__]() __attribute__((noinline, cold)) { \ std::cerr << "Assertion failed: " << msg << "\n"; \ From a804f0a36d05bb530616e275e3ec2173f25af86c Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 19:06:12 -0800 Subject: [PATCH 02/12] core: order a trap entry's mcause read behind an earlier mcause write; trap_order test Master orders a trap entry or return behind writes to mstatus, mtvec and mepc (the XREG_2 slot in VX_decode, Instr::TRAP_CSRS in SimX decode), from the upstream form of this fix. A handler that reads mcause right after the entry is not covered: the trap entry writes mcause, and the CSR read is not ordered behind it. VX_CSR_MCAUSE joins the trap-CSR set in both models. Trigger test: tests/regression/trap_order, the branch version of trap with a per-round mtvec handler that reads mepc and mcause, and the CI case trap-simd (32 warps, SIMD 4, 8 threads, simx and rtlsim). Without the ordering SimX hung ("ring accepted but nothing executing") at several issue packets per warp. Branch commit: 39193d0e2 (the rest of it is master's). Co-Authored-By: Claude Opus 5.5 --- ci/testcases/regression.yaml | 11 ++ tests/regression/Makefile | 1 + tests/regression/trap_order/Makefile | 16 +++ tests/regression/trap_order/common.h | 15 +++ tests/regression/trap_order/kernel.cpp | 71 ++++++++++++ tests/regression/trap_order/main.cpp | 148 +++++++++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 tests/regression/trap_order/Makefile create mode 100644 tests/regression/trap_order/common.h create mode 100644 tests/regression/trap_order/kernel.cpp create mode 100644 tests/regression/trap_order/main.cpp diff --git a/ci/testcases/regression.yaml b/ci/testcases/regression.yaml index f09c05fdcb..ef1b854724 100644 --- a/ci/testcases/regression.yaml +++ b/ci/testcases/regression.yaml @@ -18,6 +18,17 @@ tests: - rtlsim dir: tests/regression target: run-{driver} +- id: trap-simd + via: blackbox + drivers: + - simx + - rtlsim + app: trap_order + xlen: + - 32 + configs: "-DVX_CFG_NUM_WARPS=32 -DVX_CFG_SIMD_WIDTH=4" + shape: + threads: 8 # Local memory: shared-word reads (one lane to the whole warp, and lanes of # different LSU blocks), partial masks, bank-conflict replays, sub-word loads # and stores, same-word stores, and per-lane order against the lane's own diff --git a/tests/regression/Makefile b/tests/regression/Makefile index fcbe101cdf..618750d441 100644 --- a/tests/regression/Makefile +++ b/tests/regression/Makefile @@ -6,6 +6,7 @@ TESTS := \ minimal trap \ basic demo dogfood dropout dotproduct dotproduct2 mstress io_addr \ arith printf diverge diverge_large diverge_ptrarg sort fence \ + trap_order \ fence_mp ldst_order \ vecadd vecadd_v1 sgemm sgemmx sgemm_v1 conv3 relu sgemv \ sgemm2 sgemm2_v1 madmax mixfu stencil3d raycast bfs jacobi pathfinder \ diff --git a/tests/regression/trap_order/Makefile b/tests/regression/trap_order/Makefile new file mode 100644 index 0000000000..9b99def310 --- /dev/null +++ b/tests/regression/trap_order/Makefile @@ -0,0 +1,16 @@ +ROOT_DIR := $(realpath ../../..) +include $(ROOT_DIR)/config.mk + +PROJECT := trap_order + +SRC_DIR := $(VORTEX_HOME)/tests/regression/$(PROJECT) + +SRCS := $(SRC_DIR)/main.cpp + +VX_SRCS := $(SRC_DIR)/kernel.cpp + +OPTS ?= -n1 + +KERNEL_LIB := vortex2 + +include ../common.mk diff --git a/tests/regression/trap_order/common.h b/tests/regression/trap_order/common.h new file mode 100644 index 0000000000..b8b591e8a5 --- /dev/null +++ b/tests/regression/trap_order/common.h @@ -0,0 +1,15 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include + +// What one trap round records per thread. +#define TRAP_WORDS 3 // site, mepc, mcause | (handler tag << 8) +#define TRAP_ROUNDS 2 + +typedef struct { + uint32_t num_points; + uint64_t dst_addr; +} kernel_arg_t; + +#endif diff --git a/tests/regression/trap_order/kernel.cpp b/tests/regression/trap_order/kernel.cpp new file mode 100644 index 0000000000..2cb544d72e --- /dev/null +++ b/tests/regression/trap_order/kernel.cpp @@ -0,0 +1,71 @@ +#include +#include "common.h" + +// Each round points mtvec at its own handler and traps straight after the +// write, and the handler rewrites mepc right before returning: a trap entry +// that ran ahead of the mtvec write would land in the previous round's handler +// (or the reset vector), and an mret that ran ahead of the mepc write would +// return to the trapping instruction and trap again forever. mtvec is one per +// core and a block fills its core, so the block's barriers keep every warp in +// the same round. +extern "C" void trap_handler_ecall(); +extern "C" void trap_handler_ebreak(); +asm (".p2align 2\n" + "trap_handler_ecall:\n" + " csrr a1, mepc\n" + " csrr a2, mcause\n" + " ori a2, a2, 0x100\n" + " addi t0, a1, 4\n" + " csrw mepc, t0\n" + " mret\n" + ".p2align 2\n" + "trap_handler_ebreak:\n" + " csrr a1, mepc\n" + " csrr a2, mcause\n" + " ori a2, a2, 0x200\n" + " addi t0, a1, 4\n" + " csrw mepc, t0\n" + " mret\n"); + +__kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { + uint32_t gid = blockIdx.x * blockDim.x + threadIdx.x; + bool valid = gid < arg->num_points; + auto dst = (uint32_t*)arg->dst_addr + gid * (TRAP_WORDS * TRAP_ROUNDS); + + uintptr_t saved_mtvec; + asm volatile ("csrr %0, mtvec" : "=r"(saved_mtvec)); + __syncthreads(); + + register uintptr_t site asm("a0"); + register uintptr_t epc asm("a1") = 0; + register uintptr_t cause asm("a2") = 0; + asm volatile ("csrw mtvec, %3\n" + "la a0, 1f\n" + "1: ecall\n" + : "=&r"(site), "+r"(epc), "+r"(cause) + : "r"(&trap_handler_ecall) + : "t0", "memory"); + if (valid) { + dst[0] = site; + dst[1] = epc; + dst[2] = cause; + } + __syncthreads(); + + epc = 0; + cause = 0; + asm volatile ("csrw mtvec, %3\n" + "la a0, 1f\n" + "1: ebreak\n" + : "=&r"(site), "+r"(epc), "+r"(cause) + : "r"(&trap_handler_ebreak) + : "t0", "memory"); + if (valid) { + dst[3] = site; + dst[4] = epc; + dst[5] = cause; + } + __syncthreads(); + + asm volatile ("csrw mtvec, %0" :: "r"(saved_mtvec)); +} diff --git a/tests/regression/trap_order/main.cpp b/tests/regression/trap_order/main.cpp new file mode 100644 index 0000000000..d076f5b939 --- /dev/null +++ b/tests/regression/trap_order/main.cpp @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include +#include "common.h" + +#define RT_CHECK(_expr) \ + do { \ + int _ret = _expr; \ + if (0 == _ret) \ + break; \ + printf("Error: '%s' returned %d!\n", #_expr, (int)_ret); \ + cleanup(); \ + exit(-1); \ + } while (false) + +/////////////////////////////////////////////////////////////////////////////// + +const char* kernel_file = "kernel.vxbin"; +uint32_t count = 0; + +vx_device_h device = nullptr; +vx_buffer_h dst_buffer = nullptr; +vx_queue_h queue = nullptr; +vx_module_h module_ = nullptr; +vx_kernel_h kernel = nullptr; +kernel_arg_t kernel_arg = {}; + +static void show_usage() { + std::cout << "Vortex Test." << std::endl; + std::cout << "Usage: [-k: kernel] [-n threads per hart] [-h: help]" << std::endl; +} + +static void parse_args(int argc, char **argv) { + int c; + while ((c = getopt(argc, argv, "n:k:h")) != -1) { + switch (c) { + case 'n': + count = atoi(optarg); + break; + case 'k': + kernel_file = optarg; + break; + case 'h': + show_usage(); + exit(0); + break; + default: + show_usage(); + exit(-1); + } + } +} + +void cleanup() { + if (device) { + if (dst_buffer) vx_buffer_release(dst_buffer); + if (kernel) vx_kernel_release(kernel); + if (module_) vx_module_release(module_); + if (queue) vx_queue_release(queue); + vx_device_dump_perf(device, stdout); + vx_device_release(device); + } +} + +int main(int argc, char *argv[]) { + parse_args(argc, argv); + if (count == 0) { + count = 1; + } + + std::cout << "open device connection" << std::endl; + RT_CHECK(vx_device_open(0, &device)); + + vx_queue_info_t qi = { sizeof(qi), nullptr, VX_QUEUE_PRIORITY_NORMAL, 0 }; + RT_CHECK(vx_queue_create(device, &qi, &queue)); + + uint64_t num_cores, num_warps, num_threads; + RT_CHECK(vx_device_query(device, VX_CAPS_NUM_CORES, &num_cores)); + RT_CHECK(vx_device_query(device, VX_CAPS_NUM_WARPS, &num_warps)); + RT_CHECK(vx_device_query(device, VX_CAPS_NUM_THREADS, &num_threads)); + + uint32_t num_points = count * num_cores * num_warps * num_threads; + uint32_t num_words = num_points * TRAP_WORDS * TRAP_ROUNDS; + uint32_t buf_size = num_words * sizeof(uint32_t); + std::cout << "number of points: " << num_points << std::endl; + + kernel_arg.num_points = num_points; + RT_CHECK(vx_buffer_create(device, buf_size, VX_MEM_READ_WRITE, &dst_buffer)); + RT_CHECK(vx_buffer_address(dst_buffer, &kernel_arg.dst_addr)); + + std::vector h_dst(num_words, 0xdeadbeef); + RT_CHECK(vx_enqueue_write(queue, dst_buffer, 0, h_dst.data(), buf_size, 0, nullptr, nullptr)); + + RT_CHECK(vx_module_load_file(device, kernel_file, &module_)); + RT_CHECK(vx_module_get_kernel(module_, "main", &kernel)); + + std::cout << "launch kernel" << std::endl; + vx_event_h launch_ev = nullptr, read_ev = nullptr; + { + uint32_t n = num_points; + uint32_t grid_dim[1], block_dim[1]; + RT_CHECK(vx_device_max_occupancy_grid(device, 1, &n, grid_dim, block_dim)); + vx_launch_info_t li = {}; + li.struct_size = sizeof(li); + li.kernel = kernel; + li.args_host = &kernel_arg; + li.args_size = sizeof(kernel_arg); + li.ndim = 1; + li.grid_dim[0] = grid_dim[0]; + li.block_dim[0] = block_dim[0]; + RT_CHECK(vx_enqueue_launch(queue, &li, 0, nullptr, &launch_ev)); + } + RT_CHECK(vx_enqueue_read(queue, h_dst.data(), dst_buffer, 0, buf_size, 1, &launch_ev, &read_ev)); + RT_CHECK(vx_event_wait_value(read_ev, 1, VX_TIMEOUT_INFINITE)); + vx_event_release(read_ev); + vx_event_release(launch_ev); + + std::cout << "verify result" << std::endl; + // ecall enters handler 1 with mcause 11, ebreak handler 2 with mcause 3; + // mepc is the trapping instruction in both. + const uint32_t expected_cause[TRAP_ROUNDS] = {0x100 | 11, 0x200 | 3}; + int errors = 0; + for (uint32_t i = 0; i < num_points; ++i) { + for (uint32_t r = 0; r < TRAP_ROUNDS; ++r) { + const uint32_t* w = &h_dst[(i * TRAP_ROUNDS + r) * TRAP_WORDS]; + if (w[1] != w[0] || w[2] != expected_cause[r]) { + if (errors < 16) { + std::cout << "error at thread #" << std::dec << i << " round " << r << std::hex + << ": site=0x" << w[0] << " mepc=0x" << w[1] + << " cause=0x" << w[2] << " expected 0x" << expected_cause[r] << std::endl; + } + ++errors; + } + } + } + + cleanup(); + + if (errors != 0) { + std::cout << "Found " << std::dec << errors << " errors!" << std::endl; + std::cout << "FAILED!" << std::endl; + return 1; + } + std::cout << "PASSED!" << std::endl; + return 0; +} From 4fbd261c73d84f1d519848e3bee63e2287c106c8 Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 19:06:13 -0800 Subject: [PATCH 03/12] core: a workgroup barrier drains the warp's memory requests, including those waiting at the local memory A workgroup barrier (vx_barrier, vx_barrier_arrive) is also a workgroup-scope memory barrier, but BAR only waited for the LSU schedulers to empty. With 32 or more warps a core has two LSU blocks, and a store still between one block and the L1, or waiting at the local memory's block input (arbitrated across blocks while its write engine is busy), can lose to a load another block issues after the barrier: a peer warp reads the old value. BAR now also waits until the warp's earlier instructions have reached the LSU, every request has left the LSU blocks, and the local memory has taken every request off its block inputs: - RTL: lsu_store_empty (VX_lsu_mem_path, with the local-memory input term) reaches VX_wctl_unit through VX_warp_ctl_if. - SimX: Core::mem_req_drained (lmem switch, coalescer, dcache adapters, the local memory's inputs, the MMU). A barrier arrival now stalls its warp until it executes, like the blocking forms: a younger barrier wait queued behind the arrival deadlocked it (gbar_phase on two cores). Seen as the nondeterministic BVH-build failure of dEQP-VK.ray_query.multiple_ray_queries.compute_shader (warp 0 read warp 5's histogram total through workgroup memory before warp 5's store). Trigger tests: tests/regression/bar_vis (CTA exchange across two LSU blocks, global and workgroup memory, a same-bank variant, and mode 2: stores waiting at the local memory's inputs while the read engine is busy); CI cases bar-vis, bar-vis-shared, bar-vis-bank, bar-vis-lmem-input(-timed), model_parity-bar-vis. Default behaviour: barriers take the drain; rtlsim async_barrier +3.6% cycles, SimX sgemm2 +2.6% (x32). Logic depth (accepted, user decision 2026-12-01): in gpu32_full the barrier unit's store_state_valid and the DXA completion FIFO's used_r go from 11 to 12 levels; the whole-GPU deepest path is unchanged at 29 levels. Branch commits: 41c40eeb3, 4f3f54239, 2a891d488. Co-Authored-By: Claude Opus 5.5 --- ci/testcases/regression.yaml | 65 ++++++++++++++++ hw/rtl/core/VX_compute_slice.sv | 2 + hw/rtl/core/VX_core.sv | 2 + hw/rtl/core/VX_decode.sv | 1 - hw/rtl/core/VX_frontend_xbar.sv | 2 + hw/rtl/core/VX_lsu_mem_path.sv | 12 ++- hw/rtl/core/VX_wctl_unit.sv | 25 ++++-- hw/rtl/interfaces/VX_warp_ctl_if.sv | 8 ++ sim/simx/core.cpp | 37 ++++++++- sim/simx/core.h | 4 + sim/simx/decode.cpp | 2 +- sim/simx/mem/mem_coalescer.h | 3 + sim/simx/sfu_unit.cpp | 37 +++++---- sim/simx/sfu_unit.h | 1 + tests/regression/Makefile | 2 +- tests/regression/bar_vis/Makefile | 16 ++++ tests/regression/bar_vis/common.h | 26 +++++++ tests/regression/bar_vis/kernel.cpp | 95 +++++++++++++++++++++++ tests/regression/bar_vis/main.cpp | 116 ++++++++++++++++++++++++++++ 19 files changed, 428 insertions(+), 28 deletions(-) create mode 100644 tests/regression/bar_vis/Makefile create mode 100644 tests/regression/bar_vis/common.h create mode 100644 tests/regression/bar_vis/kernel.cpp create mode 100644 tests/regression/bar_vis/main.cpp diff --git a/ci/testcases/regression.yaml b/ci/testcases/regression.yaml index ef1b854724..14329c7edb 100644 --- a/ci/testcases/regression.yaml +++ b/ci/testcases/regression.yaml @@ -465,6 +465,71 @@ tests: app: bar_slot_phase shape: warps: 2 +# A CTA barrier orders the workgroup's memory: 32 warps of 4 threads are two +# LSU blocks, and after each barrier a thread reads the word a thread on the +# other block stored before it, with stores to other lines queued ahead. +- id: bar-vis + via: blackbox + drivers: + - simx + - rtlsim + app: bar_vis + shape: + warps: 32 + threads: 4 + args: -r64 -j4 +- id: bar-vis-shared + via: blackbox + drivers: + - simx + - rtlsim + app: bar_vis + shape: + warps: 32 + threads: 4 + args: -r64 -s -j4 +- id: bar-vis-bank + via: blackbox + drivers: + - simx + - rtlsim + app: bar_vis + shape: + warps: 32 + threads: 4 + args: -m1 -r64 -j16 +# A barrier orders workgroup memory against the local memory's inputs: stores +# of a pass per lane wait there for the write engine while the read engine is +# busy, and a read issued after the barrier must not be taken ahead of them. +# The functional kernel's unbounded channels let them queue at the inputs. +- id: bar-vis-lmem-input + via: blackbox + drivers: + - simx + app: bar_vis + configs: -DSIMX_FUNCTIONAL + shape: + warps: 32 + threads: 32 + args: -m2 -r64 -b512 +- id: bar-vis-lmem-input-timed + via: blackbox + drivers: + - simx + - rtlsim + app: bar_vis + shape: + warps: 32 + threads: 4 + args: -m2 -r64 +- id: model_parity-bar-vis + check: model_parity + via: blackbox + app: bar_vis + shape: + warps: 32 + threads: 4 + args: -r256 -j4 - id: vecadd-1 via: blackbox drivers: diff --git a/hw/rtl/core/VX_compute_slice.sv b/hw/rtl/core/VX_compute_slice.sv index c1eb9dcfea..adb27c3252 100644 --- a/hw/rtl/core/VX_compute_slice.sv +++ b/hw/rtl/core/VX_compute_slice.sv @@ -50,6 +50,7 @@ import VX_tcu_pkg::*; input wire [PERF_CTR_BITS-1:0] instret, input wire [`VX_CFG_NUM_WARPS-1:0] active_warps, input wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] all_lsu_sched_empty, + input wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] all_lsu_store_empty, input wire mmu_empty, input cta_bcast_t cta_bcast, `ifdef VX_CFG_VM_ENABLE @@ -243,6 +244,7 @@ import VX_tcu_pkg::*; assign warp_ctl_if.mscratch = dvstack_mscratch[0]; assign warp_ctl_if.warp_pending_alm_empty = pending_alm_empty; assign warp_ctl_if.lsu_sched_empty = all_lsu_sched_empty; + assign warp_ctl_if.lsu_store_empty = all_lsu_store_empty; assign warp_ctl_if.mmu_empty = mmu_empty; assign csr_rd_wid[0] = sched_csr_if.csr_rd_wid; diff --git a/hw/rtl/core/VX_core.sv b/hw/rtl/core/VX_core.sv index d48b7433f7..8143152004 100644 --- a/hw/rtl/core/VX_core.sv +++ b/hw/rtl/core/VX_core.sv @@ -461,6 +461,7 @@ import VX_tcu_pkg::*; .instret (sched_instret), .active_warps (sched_active_warps), .all_lsu_sched_empty (lsu_sched_empty), + .all_lsu_store_empty (lsu_store_empty), .mmu_empty (mmu_empty), .cta_bcast (cta_bcast), `ifdef VX_CFG_VM_ENABLE @@ -559,6 +560,7 @@ import VX_tcu_pkg::*; .instret (sched_instret), .active_warps (sched_active_warps), .lsu_sched_empty (lsu_sched_empty), + .lsu_store_empty (lsu_store_empty), .mmu_empty (mmu_empty), `ifdef VX_CFG_VM_ENABLE .satp (sched_satp), diff --git a/hw/rtl/core/VX_decode.sv b/hw/rtl/core/VX_decode.sv index bcbd63bdf2..12539f0b74 100644 --- a/hw/rtl/core/VX_decode.sv +++ b/hw/rtl/core/VX_decode.sv @@ -854,7 +854,6 @@ module VX_decode import op_type = INST_OP_BITS'(INST_SFU_BAR); op_args.wctl.is_sync_bar = 0; op_args.wctl.is_bar_arrive = ~is_rd_zero; - is_wstall = is_rd_zero; // do not wati on arrival `USED_IREG (rd); `USED_IREG (rs1); `USED_IREG (rs2); diff --git a/hw/rtl/core/VX_frontend_xbar.sv b/hw/rtl/core/VX_frontend_xbar.sv index da281b25e4..f532880424 100644 --- a/hw/rtl/core/VX_frontend_xbar.sv +++ b/hw/rtl/core/VX_frontend_xbar.sv @@ -44,6 +44,7 @@ module VX_frontend_xbar import VX_gpu_pkg::*; ( input wire [PERF_CTR_BITS-1:0] instret, input wire [`VX_CFG_NUM_WARPS-1:0] active_warps, input wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] lsu_sched_empty, + input wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] lsu_store_empty, input wire mmu_empty, `ifdef VX_CFG_VM_ENABLE input wire [`VX_CFG_NUM_SFU_BLOCKS-1:0][`VX_CFG_XLEN-1:0] satp, @@ -202,6 +203,7 @@ module VX_frontend_xbar import VX_gpu_pkg::*; ( assign warp_ctl_if[b].warp_pending_alm_empty[k] = pending_alm_empty[k * BS + b]; end assign warp_ctl_if[b].lsu_sched_empty = lsu_sched_empty; + assign warp_ctl_if[b].lsu_store_empty = lsu_store_empty; assign warp_ctl_if[b].mmu_empty = mmu_empty; assign sched_csr_if[b].cycles = cycles; diff --git a/hw/rtl/core/VX_lsu_mem_path.sv b/hw/rtl/core/VX_lsu_mem_path.sv index 207d2ca0bc..50fdbef38c 100644 --- a/hw/rtl/core/VX_lsu_mem_path.sv +++ b/hw/rtl/core/VX_lsu_mem_path.sv @@ -107,10 +107,15 @@ module VX_lsu_mem_path import VX_gpu_pkg::*; #( // Two terms keep a store visible until it reaches the D-cache port: the // coalescer (or the adapter input without one), and the adapter's request - // buffer. + // buffer. A third keeps a local-memory request visible until the local + // memory takes it into an engine: an engine keeps every write in order + // against every read, but the requests waiting at its block inputs are + // arbitrated across blocks, so a read another block issues after a barrier + // could be taken ahead of a store still waiting there. wire path_empty; wire adapter_empty; - assign store_empty = path_empty && adapter_empty; + wire local_empty; + assign store_empty = path_empty && adapter_empty && local_empty; assign busy = ~sched_empty || ~store_empty; VX_lsu_mem_if #( @@ -134,12 +139,15 @@ module VX_lsu_mem_path import VX_gpu_pkg::*; #( .local_out_if (lmem_if) ); + assign local_empty = ~lmem_if.req_valid; + `else VX_lsu_mem_connect lsu_dcache_connect ( .bus_in_if (lsu_mem_if), .bus_out_if (lsu_dcache_if) ); + assign local_empty = 1'b1; `endif diff --git a/hw/rtl/core/VX_wctl_unit.sv b/hw/rtl/core/VX_wctl_unit.sv index ec0067bc4b..4487a0c5f8 100644 --- a/hw/rtl/core/VX_wctl_unit.sv +++ b/hw/rtl/core/VX_wctl_unit.sv @@ -180,12 +180,21 @@ module VX_wctl_unit import VX_gpu_pkg::*; #( // WSYNC: hold execute until this warp's pipeline is drained (alm_empty=1 // means only WSYNC itself is pending — all prior instructions committed). - wire wsync_drain = execute_if.valid && is_wsync - && !warp_ctl_if.warp_pending_alm_empty[wid_to_sfu_local(execute_if.data.header.wid)]; - - // BAR (vx_barrier or vx_barrier_arrive) drains LSU before continuing. - wire lsu_sched_drained = (& warp_ctl_if.lsu_sched_empty) && warp_ctl_if.mmu_empty; - wire bar_drain = execute_if.valid && is_bar && !lsu_sched_drained; + wire pending_alm_empty = warp_ctl_if.warp_pending_alm_empty[wid_to_sfu_local(execute_if.data.header.wid)]; + wire wsync_drain = execute_if.valid && is_wsync && !pending_alm_empty; + + // BAR (vx_barrier or vx_barrier_arrive) is a workgroup-scope memory barrier + // too: the warp's earlier instructions must have reached the LSU, and every + // request ahead of the barrier must have left the LSU blocks for the L1, + // and been taken by the local memory's engines, which keep a line's + // requests in order (lsu_store_empty covers both). Otherwise a store still + // in one LSU block's path, or waiting at its local-memory input, can lose + // arbitration to a load another block issues after the barrier. + wire mem_drained = pending_alm_empty + && (& warp_ctl_if.lsu_sched_empty) + && (& warp_ctl_if.lsu_store_empty) + && warp_ctl_if.mmu_empty; + wire bar_drain = execute_if.valid && is_bar && !mem_drained; // Barriers, wspawn and warp retirement are core-wide requests to the shared // unit. Only a barrier arrive writes a result, the barrier phase, so it alone @@ -289,7 +298,9 @@ module VX_wctl_unit import VX_gpu_pkg::*; #( end end - assign wsync_valid = wctl_valid && is_wsync; + // A barrier arrival waits only for its own drain, not for the barrier. + assign wsync_valid = wctl_valid && (is_wsync + || (is_bar && execute_if.data.op_args.wctl.is_bar_arrive)); VX_pipe_register #( .DATAW (4 + NW_WIDTH + WCTL_WIDTH), diff --git a/hw/rtl/interfaces/VX_warp_ctl_if.sv b/hw/rtl/interfaces/VX_warp_ctl_if.sv index 26d648a659..2b87365668 100644 --- a/hw/rtl/interfaces/VX_warp_ctl_if.sv +++ b/hw/rtl/interfaces/VX_warp_ctl_if.sv @@ -36,6 +36,12 @@ interface VX_warp_ctl_if import VX_gpu_pkg::*; (); wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] lsu_sched_empty; wire mmu_empty; + // Every LSU block's store path has handed its requests to the L1 and local + // memory, past the last point where two blocks' requests can reorder. BAR + // and FRAG_RELEASE also wait for it, so a peer warp past the barrier, or + // the next fragment's merge, sees this warp's stores. + wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] lsu_store_empty; + // IPDOM stack address and mscratch of the warp at dvstack_wid wire [NW_WIDTH-1:0] dvstack_wid; wire [DV_STACK_SIZEW-1:0] dvstack_ptr; @@ -52,6 +58,7 @@ interface VX_warp_ctl_if import VX_gpu_pkg::*; (); output sjoin, input warp_pending_alm_empty, input lsu_sched_empty, + input lsu_store_empty, input mmu_empty, output dvstack_wid, input dvstack_ptr, @@ -69,6 +76,7 @@ interface VX_warp_ctl_if import VX_gpu_pkg::*; (); input sjoin, output warp_pending_alm_empty, output lsu_sched_empty, + output lsu_store_empty, output mmu_empty, input dvstack_wid, output dvstack_ptr, diff --git a/sim/simx/core.cpp b/sim/simx/core.cpp index 3220dde52b..5df151462d 100644 --- a/sim/simx/core.cpp +++ b/sim/simx/core.cpp @@ -186,7 +186,8 @@ class Core::Impl { // create the memory coalescer, or the lane adapter that replaces it. const bool dcache_coalescing = (VX_CFG_NUM_LSU_LANES > 1) && (DCACHE_WORD_SIZE > LSU_WORD_SIZE); - std::vector lsu_dcache_adapter(VX_CFG_NUM_LSU_BLOCKS); + auto& lsu_dcache_adapter = dcache_adapters_; + lsu_dcache_adapter.resize(VX_CFG_NUM_LSU_BLOCKS); for (uint32_t b = 0; b < VX_CFG_NUM_LSU_BLOCKS; ++b) { snprintf(sname, 100, "%s-coalescer%d", name.c_str(), b); // a batch crosses the coalescer's output register, then the lane @@ -1320,6 +1321,34 @@ class Core::Impl { return std::static_pointer_cast(func_units_.at((int)FUType::LSU))->drained(); } + // No request is on its way from the LSU blocks to the local memory or the + // data cache: the switch, the coalescer or lane adapter and the address + // translation have handed every one over, and the local memory has taken + // every one off its block inputs. What the data cache has accepted and what + // the local memory's engines hold they keep in order per line; the requests + // still waiting at the local memory's inputs are arbitrated across blocks, + // where a later read of another block can be taken ahead of an earlier store. + bool mem_req_drained() const { + for (uint32_t b = 0; b < VX_CFG_NUM_LSU_BLOCKS; ++b) { + if (!lmem_switch_.at(b)->ReqIn.empty() || !mem_coalescers_.at(b)->drained()) { + return false; + } + // size(), not empty(): a request still in flight from the switch counts. + if (local_mem_->ReqIn.at(b).size() != 0) { + return false; + } + if (dcache_adapters_.at(b) && !dcache_adapters_.at(b)->ReqIn.empty()) { + return false; + } + } + #ifdef VX_CFG_VM_ENABLE + if (!dcache_mmu_->empty()) { + return false; + } + #endif + return true; + } + int dcr_read(uint32_t addr, uint32_t tag, uint32_t* value) { // tag arrives as (mpm_class << 6) | mpm_tag_idx after socket strips core_id switch (addr) { @@ -1449,6 +1478,8 @@ class Core::Impl { LocalMem::Ptr local_mem_; std::vector lmem_switch_; std::vector mem_coalescers_; + // Without a coalescer, the per-block lane adapters into the data cache. + std::vector dcache_adapters_; std::vector::Ptr> dcache_flush_bufs_; TxBuffer::Ptr icache_flush_buf_; // Fetch's icache requests and responses, one port per frontend slice. @@ -1587,6 +1618,10 @@ bool Core::running() const { return impl_->running(); } +bool Core::mem_req_drained() const { + return impl_->mem_req_drained(); +} + void Core::resume(uint32_t wid) { impl_->scheduler()->resume(wid); } diff --git a/sim/simx/core.h b/sim/simx/core.h index 60d88f5842..73d1cec312 100644 --- a/sim/simx/core.h +++ b/sim/simx/core.h @@ -111,6 +111,10 @@ class Core : public SimObject { void resume(uint32_t wid); + // Every request has left the LSU blocks' paths to the data cache and the + // local memory's block inputs (a barrier's memory drain). + bool mem_req_drained() const; + uint32_t id() const { return core_id_; } diff --git a/sim/simx/decode.cpp b/sim/simx/decode.cpp index 68f2049370..927ee37310 100644 --- a/sim/simx/decode.cpp +++ b/sim/simx/decode.cpp @@ -1153,7 +1153,7 @@ Instr::Ptr Decoder::decode(uint32_t code, uint64_t uuid, bool fs_off) { instr->set_src_reg(1, rs2, RegType::Integer); wctlArgs.is_sync_bar = 0; wctlArgs.is_bar_arrive = (rd != 0); - instr->set_wstall(rd == 0); // stall on wait, not on arrive + instr->set_wstall(true); break; case 7: // WSYNC instr->set_op_type(WctlType::WSYNC); diff --git a/sim/simx/mem/mem_coalescer.h b/sim/simx/mem/mem_coalescer.h index efaa236cfd..a3891a719c 100644 --- a/sim/simx/mem/mem_coalescer.h +++ b/sim/simx/mem/mem_coalescer.h @@ -52,6 +52,9 @@ class MemCoalescer : public SimObject { const PerfStats& perf_stats() const; + // No request waits to be coalesced or sent on. + bool drained() const { return ReqIn.empty() && !out_round_.valid; } + protected: void on_reset(); void on_tick(); diff --git a/sim/simx/sfu_unit.cpp b/sim/simx/sfu_unit.cpp index f9aa5595ad..a90cd396c8 100644 --- a/sim/simx/sfu_unit.cpp +++ b/sim/simx/sfu_unit.cpp @@ -144,6 +144,15 @@ void SfuUnit::send_out(uint32_t b, instr_trace_t* trace, uint32_t delay, PeClass q.insert(it, OutPe{arrive, pe}); } +// BAR (vx_barrier and vx_barrier_arrive) is also a workgroup-scope memory +// barrier (CUDA __syncthreads, OpenCL barrier(CLK_LOCAL_MEM_FENCE)): the +// warp's earlier instructions must have reached the LSU and every request must +// have left the LSU blocks for the data cache, or been taken in by the local +// memory's engines. +bool SfuUnit::mem_drained(uint32_t wid) const { + return pending_alm_empty_.at(wid) && lsu_drained_ && core_->mem_req_drained(); +} + void SfuUnit::on_tick() { while (!lsu_drained_in.empty()) { lsu_drained_ = lsu_drained_in.peek(); @@ -412,17 +421,17 @@ void SfuUnit::on_tick() { auto& ba = bar_arrive_.at(b); uint64_t now = SimPlatform::instance().cycles(); if (ba.trace != trace) { - if (!lsu_drained_) { - continue; // drain LSU before the barrier - } - ba = BarArrive{trace, now, false, WarpCtl()}; - ba.release_warp = wctl_unit_->process(trace, &ba.ctl); - continue; - } - if (now < ba.sent + 2 || output.full()) { - continue; - } - } + if (!this->mem_drained(trace->wid)) { + continue; + } + ba = BarArrive{trace, now, false, WarpCtl()}; + ba.release_warp = wctl_unit_->process(trace, &ba.ctl); + continue; + } + if (now < ba.sent + 2 || output.full()) { + continue; + } + } #ifdef VX_CFG_EXT_TFU_ENABLE if (std::get_if(&trace->op_type)) { if (output.full()) { @@ -449,16 +458,14 @@ void SfuUnit::on_tick() { continue; // WSYNC has a structural gate: cannot complete until prior insts retire. - // BAR (vx_barrier and vx_barrier_arrive) drains LSU before continuing — - // implements CUDA __syncthreads / OpenCL barrier(CLK_LOCAL_MEM_FENCE) semantic. if (auto wctl_p = std::get_if(&trace->op_type)) { if (trace->eop) { if (*wctl_p == WctlType::WSYNC) { if (!pending_alm_empty_.at(trace->wid)) continue; // wait for the warp's prior instrs to retire } else if (*wctl_p == WctlType::BAR && !bar_arrive) { - if (!lsu_drained_) - continue; // drain LSU before the barrier + if (!this->mem_drained(trace->wid)) + continue; } } } diff --git a/sim/simx/sfu_unit.h b/sim/simx/sfu_unit.h index ae6781f439..0ffd78c3a0 100644 --- a/sim/simx/sfu_unit.h +++ b/sim/simx/sfu_unit.h @@ -148,6 +148,7 @@ class SfuUnit : public FuncUnit { // A WAIT that returns its status releases its warp through sched_unlock_out, // not at commit. void release_wait(instr_trace_t *trace); + bool mem_drained(uint32_t wid) const; // An op that streams its registers to the RTU, one per beat, holds its block // until the last beat: true while it still has an earlier beat to send. bool rtu_beats_pending(uint32_t b, const instr_trace_t *trace, uint32_t beats); diff --git a/tests/regression/Makefile b/tests/regression/Makefile index 618750d441..c1f7abbf95 100644 --- a/tests/regression/Makefile +++ b/tests/regression/Makefile @@ -16,7 +16,7 @@ TESTS := \ sgemm2_dxa sgemm2_tcu sgemm_tcu_wg_dxa sgemm_tcu_wg_sp_dxa \ sgemm2_dxa_mcast sgemm_tcu_wg_dxa_mcast \ dxa_copy dxa_copy_mcast dxa_kmajor_check dxa_lane \ - async_barrier async_gbarrier gbar_phase bar_slot_phase packld wgather wsync quad_lod \ + async_barrier async_gbarrier gbar_phase bar_slot_phase bar_vis packld wgather wsync quad_lod \ occupancy multikernel reopen module_reload module_reloc single_cta \ flush_coherence lazy_fetch sector_merge raw_order cache_ways chase \ vm_test vm_fault vm_stress trap_illegal cp_host_alias wb_drain diff --git a/tests/regression/bar_vis/Makefile b/tests/regression/bar_vis/Makefile new file mode 100644 index 0000000000..3954d68ca2 --- /dev/null +++ b/tests/regression/bar_vis/Makefile @@ -0,0 +1,16 @@ +ROOT_DIR := $(realpath ../../..) +include $(ROOT_DIR)/config.mk + +PROJECT := bar_vis + +SRC_DIR := $(VORTEX_HOME)/tests/regression/$(PROJECT) + +SRCS := $(SRC_DIR)/main.cpp + +VX_SRCS := $(SRC_DIR)/kernel.cpp + +OPTS ?= -r64 + +KERNEL_LIB := vortex2 + +include ../common.mk diff --git a/tests/regression/bar_vis/common.h b/tests/regression/bar_vis/common.h new file mode 100644 index 0000000000..535d620c5a --- /dev/null +++ b/tests/regression/bar_vis/common.h @@ -0,0 +1,26 @@ +// Copyright © 2019-2023 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#include +typedef struct { + uint32_t rounds; + uint32_t shared; // 1: the exchange buffer is workgroup memory, 0: global + uint32_t junk; // stores to other lines each thread makes first + uint32_t mode; // 1: only the even warps store ahead, to the exchange line's bank + // 2: workgroup memory, half the CTA storing a word per warp from + // every lane and warp 0 reading them, the other half reading + uint64_t junk_addr; // uint32[gridDim.x * blockDim.x * 16 * junk] + uint64_t buf_addr; // uint32[2 * blockDim.x] per CTA, then the mode-1 stores + uint64_t err_addr; // uint32[gridDim.x * blockDim.x], stale reads per thread +} kernel_arg_t; diff --git a/tests/regression/bar_vis/kernel.cpp b/tests/regression/bar_vis/kernel.cpp new file mode 100644 index 0000000000..54f123863a --- /dev/null +++ b/tests/regression/bar_vis/kernel.cpp @@ -0,0 +1,95 @@ +// Copyright © 2019-2023 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "common.h" +#include +#include + +// Every round each thread stores its round number, the CTA meets at a barrier, +// and each thread loads the word its lane stored in the neighbouring warp. Warp +// w issues on slice w % ISSUE_WIDTH, so with two LSU blocks that warp is on the +// other one. A load that sees an older round read past a store the barrier +// should have ordered before it. +// Stores to other lines ahead of the exchange (junk) keep the memory path busy +// when the barrier is reached. +// Mode 1 is the barrier exchange with the backlog on one side: only the even +// warps (one LSU block) store ahead of the exchange, 1 KiB apart from their +// exchange line so every store queues for the same data-cache bank, while the +// odd warps that read their words after the barrier find their own port idle. +// Mode 2 is a gather in workgroup memory with stores waiting at the local +// memory's inputs. The first half of the CTA meets at a barrier of its own: +// every lane of a warp stores the warp's word, which takes the local memory a +// pass per lane, so the stores reaching the barrier together wait for the one +// write engine, and after the barrier the first lanes of warp 0 read the word +// of every warp of the half. Meanwhile the other half keeps reading workgroup +// memory, so the read engine is busy when a store waits: the barrier must not +// let warp 0's read be taken ahead of a store still waiting at an input. +__kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { + if (arg->mode == 2) { + const uint32_t tid = threadIdx.x, T = blockDim.x, W = (uint32_t)vx_num_threads(); + const uint32_t warp = tid / W, NW = T / W / 2; + auto buf = reinterpret_cast(__local_mem()); + volatile uint32_t* done = buf + NW; + volatile uint32_t* noise = buf + 2 * NW; // T words + uint32_t stale = 0; + if (warp < NW) { + for (uint32_t r = 1; r <= arg->rounds; ++r) { + buf[warp] = r + warp; + vx_barrier(get_local_group_id(), NW); + if (tid < NW) + stale += (buf[tid] != r + tid) ? 1u : 0u; + vx_barrier(get_local_group_id(), NW); + } + if (tid == 0) + *done = arg->rounds; + } else { + uint32_t sink = 0; + while (*done != arg->rounds) { + for (uint32_t u = 0; u < 8; ++u) + sink += noise[(tid + u * W) % T]; + } + stale = (sink == 0xffffffffu) ? 1u : 0u; // keeps the reads; never true + } + reinterpret_cast(arg->err_addr)[blockIdx.x * T + tid] = stale; + return; + } + const uint32_t tid = threadIdx.x, T = blockDim.x; + uint32_t* buf = arg->shared ? reinterpret_cast(__local_mem()) + : reinterpret_cast(arg->buf_addr) + blockIdx.x * 2 * T; + const uint32_t W = (uint32_t)vx_num_threads(); + const uint32_t peer = tid ^ W; + const bool writer = ((tid / W) & 1u) == 0; + auto junk = reinterpret_cast(arg->junk_addr); + uint32_t stale = 0; + for (uint32_t r = 1; r <= arg->rounds; ++r) { + if (arg->mode == 1) { + if (writer) { + // Past every CTA's exchange words, in whole KiB. + const uintptr_t past = (gridDim.x * 2 * T * 4 + 1023u) & ~uintptr_t(1023); + const uintptr_t line = reinterpret_cast(&buf[tid]) & ~uintptr_t(63); + for (uint32_t j = 0; j < arg->junk; ++j) { + *reinterpret_cast(line + past + 1024u * j) = r + j; + } + } + } else { + for (uint32_t j = 0; j < arg->junk; ++j) { + junk[((blockIdx.x * T + tid) * arg->junk + j) * 16u] = r + j; + } + } + buf[tid] = r; + __syncthreads(); + stale += (buf[peer] != r) ? 1u : 0u; + __syncthreads(); + } + reinterpret_cast(arg->err_addr)[blockIdx.x * T + tid] = stale; +} diff --git a/tests/regression/bar_vis/main.cpp b/tests/regression/bar_vis/main.cpp new file mode 100644 index 0000000000..b6e8b4cf1a --- /dev/null +++ b/tests/regression/bar_vis/main.cpp @@ -0,0 +1,116 @@ +// Copyright © 2019-2023 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include +#include +#include +#include "common.h" + +#define RT_CHECK(_expr) \ + do { \ + int _ret = _expr; \ + if (0 == _ret) \ + break; \ + printf("Error: '%s' returned %d!\n", #_expr, (int)_ret); \ + exit(-1); \ + } while (false) + +int main(int argc, char** argv) { + // A CTA of 128 threads is 32 warps of 4: two LSU blocks. It must hold an even + // number of warps; by default it is the largest such CTA up to 128 threads + // that the device can hold. + uint32_t grid = 1, block = 0, rounds = 64, shared = 0, junk = 0, mode = 0; + int c; + while ((c = getopt(argc, argv, "g:b:r:sj:m:")) != -1) { + switch (c) { + case 'g': grid = atoi(optarg); break; + case 'b': block = atoi(optarg); break; + case 'r': rounds = atoi(optarg); break; + case 's': shared = 1; break; + case 'j': junk = atoi(optarg); break; + case 'm': mode = atoi(optarg); break; + default: return -1; + } + } + vx_device_h dev; + vx_queue_h q; + vx_buffer_h buf, err, jb; + vx_module_h mod; + vx_kernel_h k; + kernel_arg_t arg = {}; + RT_CHECK(vx_device_open(0, &dev)); + if (block == 0) { + uint64_t num_warps, num_threads; + RT_CHECK(vx_device_query(dev, VX_CAPS_NUM_WARPS, &num_warps)); + RT_CHECK(vx_device_query(dev, VX_CAPS_NUM_THREADS, &num_threads)); + const uint64_t pair = 2 * num_threads; + block = (uint32_t)((std::min(128, num_warps * num_threads) / pair) * pair); + if (block == 0) { + printf("bar_vis needs at least two warps per core\nFAILED!\n"); + return 1; + } + } + const uint32_t n = grid * block; + vx_queue_info_t qi = {sizeof(qi), nullptr, VX_QUEUE_PRIORITY_NORMAL, 0}; + RT_CHECK(vx_queue_create(dev, &qi, &q)); + RT_CHECK(vx_buffer_create(dev, (uint64_t)n * 8 + (mode == 1 ? 1024ull * (junk + 2) + n * 8 : 0), VX_MEM_READ_WRITE, &buf)); + RT_CHECK(vx_buffer_create(dev, n * 4, VX_MEM_READ_WRITE, &err)); + RT_CHECK(vx_buffer_address(buf, &arg.buf_addr)); + RT_CHECK(vx_buffer_address(err, &arg.err_addr)); + RT_CHECK(vx_buffer_create(dev, (uint64_t)n * 64 * (junk ? junk : 1), VX_MEM_READ_WRITE, &jb)); + RT_CHECK(vx_buffer_address(jb, &arg.junk_addr)); + arg.junk = junk; + arg.rounds = rounds; + arg.shared = shared; + arg.mode = mode; + std::vector h(2 * n, 0); + RT_CHECK(vx_enqueue_write(q, buf, 0, h.data(), n * 8, 0, nullptr, nullptr)); + RT_CHECK(vx_module_load_file(dev, "kernel.vxbin", &mod)); + RT_CHECK(vx_module_get_kernel(mod, "main", &k)); + vx_launch_info_t li = {}; + li.struct_size = sizeof(li); + li.kernel = k; + li.args_host = &arg; + li.args_size = sizeof(arg); + li.ndim = 1; + li.grid_dim[0] = grid; + li.block_dim[0] = block; + li.lmem_size = (mode == 2) ? block * 4 + 64 * 4 : shared ? block * 8 : 0; + RT_CHECK(vx_enqueue_launch(q, &li, 0, nullptr, nullptr)); + RT_CHECK(vx_queue_finish(q, VX_TIMEOUT_INFINITE)); + RT_CHECK(vx_enqueue_read(q, h.data(), err, 0, n * 4, 0, nullptr, nullptr)); + RT_CHECK(vx_queue_finish(q, VX_TIMEOUT_INFINITE)); + uint64_t stale = 0; + for (uint32_t i = 0; i < n; ++i) { + stale += h[i]; + } + printf("grid=%u block=%u rounds=%u shared=%u junk=%u mode=%u stale_reads=%llu\n", grid, block, rounds, shared, junk, mode, + (unsigned long long)stale); + vx_device_dump_perf(dev, stdout); + vx_buffer_release(buf); + vx_buffer_release(err); + vx_buffer_release(jb); + vx_kernel_release(k); + vx_module_release(mod); + vx_queue_release(q); + vx_device_release(dev); + if (stale != 0) { + printf("Found %llu stale reads!\nFAILED!\n", (unsigned long long)stale); + return 1; + } + printf("PASSED!\n"); + return 0; +} From aa0e23e62bd14b8f8febf751e2b9a7c9f93c633b Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 19:06:13 -0800 Subject: [PATCH 04/12] lsu, simx: a fence follows the block's older requests on every lane and holds the block's input until answered Master sends a fence to the coherence point as a flush token behind the block's earlier requests. Three gaps remain: - RTL: the fence goes out with the warp's thread mask and its lanes' register values as addresses. An inactive lane sends no copy, so a store on that lane's path can still pass the fence. The fence now goes out on every lane at address 0; the block joins every copy's response. SimX's flush token goes out on every LSU lane the same way (it used the lanes of the fence's last packet's thread mask). - SimX: while a fence was out, the LSU still moved the block's later loads and stores into its request queue, where a store commits, so a store retired under the fence. The RTL's fence lock holds the block's input from the fence's request until its response; SimX now does the same. - SimX timing of the fence's walk: the bank spends its quiescent cycle (WAIT1) before the first line and waits for the last line to leave its pipeline (WAIT2) before DONE, and the fence's answer retires through the response buffer and the result arbiter's register, as in the RTL (parity-fence-mp: SimX 13.6% fast before). Trigger tests: tests/regression/fence_mp (modes 3 mirrored pairs, 4 lanes, 5 ports, -r rounds, -g plain guard) with the CI cases fence-mp-1c, fence-mp-mc-l2, fence-mp-mc-l3, fence-mp-lanes (raw dcache set index), fence-mp-ports and parity-fence-mp; tests/regression/vm_test mode 7 (release through a fence while the store parks on a TLB miss) with the CI case vm-release. Design notes: docs/designs/multicache_amo_coherence.md. Default behaviour: fence timing only (fences are rare in the default regression; printf +0.035% SimX cycles at x32). Branch commits: 391092122, c6163b52a, adcdffb21 (the rest of 391092122 is master's). Co-Authored-By: Claude Opus 5.5 --- ci/testcases/isa/amo.yaml | 64 ++++++++ ci/testcases/vm.yaml | 16 ++ docs/designs/multicache_amo_coherence.md | 48 ++++-- hw/rtl/core/VX_lsu_block.sv | 10 +- sim/simx/lsu_unit.cpp | 24 +-- sim/simx/lsu_unit.h | 4 +- sim/simx/mem/cache.cpp | 18 ++- tests/regression/fence_mp/common.h | 78 +++++++-- tests/regression/fence_mp/kernel.cpp | 159 ++++++++++++++++++- tests/regression/fence_mp/main.cpp | 192 ++++++++++++++++++----- tests/regression/vm_test/common.h | 12 ++ tests/regression/vm_test/kernel.cpp | 40 +++++ tests/regression/vm_test/main.cpp | 23 ++- 13 files changed, 603 insertions(+), 85 deletions(-) diff --git a/ci/testcases/isa/amo.yaml b/ci/testcases/isa/amo.yaml index 309c5735e5..75b8f1287d 100644 --- a/ci/testcases/isa/amo.yaml +++ b/ci/testcases/isa/amo.yaml @@ -90,3 +90,67 @@ tests: shape: {cores: 4, l2cache: true, l3cache: true} args: "-n8" tier: full + # Fence-managed visibility of plain data across cores (fence_mp): a store + # published by a fence and an atomic guard must be read back, after the + # consumer's atomic and fence, through a data cache that already held the + # line. The fence drains the issuing core's stores to the LLC and invalidates + # every cache above it; the LLC itself is never flushed by a fence. + - id: fence-mp-1c + touches: [hw/rtl/cache, hw/rtl/core/VX_lsu_block.sv, hw/rtl/VX_gpu_pkg.sv, sim/simx/mem, sim/simx/lsu_unit.cpp, tests/regression/fence_mp] + app: fence_mp + drivers: [simx, rtlsim] + args: "-m3 -r8" + - id: fence-mp-mc-l2 + touches: [hw/rtl/cache, hw/rtl/core/VX_lsu_block.sv, hw/rtl/VX_gpu_pkg.sv, sim/simx/mem, sim/simx/lsu_unit.cpp, tests/regression/fence_mp] + app: fence_mp + drivers: [simx, rtlsim] + shape: {cores: 4, l2cache: true} + args: "-m3 -r8" + - id: fence-mp-mc-l3 + touches: [hw/rtl/cache, hw/rtl/core/VX_lsu_block.sv, hw/rtl/VX_gpu_pkg.sv, sim/simx/mem, sim/simx/lsu_unit.cpp, tests/regression/fence_mp] + app: fence_mp + drivers: [simx, rtlsim] + configs+: "-DVX_CFG_L2_WRITEBACK=0" + shape: {cores: 4, l2cache: true, l3cache: true} + args: "-m3 -r8" + tier: full + # A fence publishes every older store of its warp, whichever thread made it: + # the payload store waits on a lane backed up by misses while the fence, + # from threads whose lanes are free, reaches the data cache first. That + # cache is write-back and not the coherence point, so a store let in after + # its walk stays there; the writer publishes the guard by evicting its line, + # without atomics, which a write-back data cache does not support. + - id: fence-mp-lanes + touches: [hw/rtl/cache, hw/rtl/core/VX_lsu_block.sv, hw/rtl/VX_gpu_pkg.sv, sim/simx/mem, sim/simx/lsu_unit.cpp, tests/regression/fence_mp] + app: fence_mp + drivers: [simx, rtlsim] + # The writer evicts the guard's line with loads at whole-way strides, which + # land in its set only under the raw set index: the hashed one (the + # default since MLP) spreads them over other sets and nothing is evicted. + configs: "-DVX_CFG_DCACHE_WRITEBACK=1 -DVX_CFG_DCACHE_MSHR_SIZE=2 -DVX_CFG_DCACHE_SET_HASH=0" + shape: {cores: 2, l2cache: true} + args: "-m4" + # A fence publishes the stores its data cache sent out on each memory port: + # the payload queues on the second port behind stores to a next-level bank + # that six other cores keep busy, while the reader's read finds its own bank + # free. The addresses assume two data-cache banks, as at XLEN 32. + - id: fence-mp-ports + touches: [hw/rtl/cache, hw/rtl/core/VX_lsu_block.sv, hw/rtl/VX_gpu_pkg.sv, sim/simx/mem, sim/simx/lsu_unit.cpp, tests/regression/fence_mp] + app: fence_mp + drivers: [simx, rtlsim] + xlen: [32] + configs+: "-DVX_CFG_L2_NUM_BANKS=2 -DVX_CFG_L2_MSHR_SIZE=2" + shape: {cores: 8, l2cache: true} + args: "-m5" + # SimX models the fence's drain, walk and pass at each level as the RTL runs + # it. The guard is a plain word here: the retired instructions are fixed + # either way, and the cycles stay those of the fences and the misses they + # cause rather than of the atomics' round trips. + - id: parity-fence-mp + touches: [hw/rtl/cache, hw/rtl/core/VX_lsu_block.sv, hw/rtl/VX_gpu_pkg.sv, sim/simx/mem, sim/simx/lsu_unit.cpp, tests/regression/fence_mp] + check: model_parity + via: blackbox + app: fence_mp + shape: {cores: 2, l2cache: true} + args: "-m3 -r256 -g" + xlen: [32] diff --git a/ci/testcases/vm.yaml b/ci/testcases/vm.yaml index 91c3010bb1..561a6192f5 100644 --- a/ci/testcases/vm.yaml +++ b/ci/testcases/vm.yaml @@ -126,6 +126,22 @@ tests: OPTS: -t1 -n16 -p1 env: VORTEX_RANDOMIZE_VA: 1 +# Release through a fence with no barrier or kernel end after it: the +# writer's page store parks on a TLB miss behind fifteen cold walks (one +# walker, a deep MSHR), and the guard swap behind the fence is a TLB hit. +# Two clusters keep the reader's translation out of the writer's L2 TLB. +- id: vm-release + via: make-run + drivers: + - simx + - rtlsim + dir: tests/regression/vm_test + target: run-{driver} + configs+: -DVX_CFG_EXT_A_ENABLE -DVX_CFG_NUM_CLUSTERS=2 -DVX_CFG_NUM_CORES=1 -DVX_CFG_L3_ENABLE -DVX_CFG_L1_TLB_MSHR_SIZE=16 -DVX_CFG_PTW_NUM_WALKERS=1 + vars: + OPTS: -t7 -n8 -p2048 + env: + VORTEX_RANDOMIZE_VA: 1 - id: vm-drain via: make-run drivers: diff --git a/docs/designs/multicache_amo_coherence.md b/docs/designs/multicache_amo_coherence.md index 2c0d8d8bcf..1655ce74cf 100644 --- a/docs/designs/multicache_amo_coherence.md +++ b/docs/designs/multicache_amo_coherence.md @@ -254,20 +254,33 @@ forwards the token. The shared LLC, the point of coherence, answers it without a walk; a replicated LLC still walks. The fence holds its LSU block until the answer. -So a memory `fence` gives the consumer-side invalidate above the point of -coherence, at the cost of a flush walk of each private level. `fence_mp` -passes data between cores this way on shared and replicated last levels. -`atomic_critical`, which runs plain loads and stores inside a lock, is still -skipped on multi-core configurations. +| step | where | what happens | +|---|---|---| +| issue | LSU | the token goes out on every lane of the block, whatever the thread mask, behind every earlier request of the block (each copy follows the older requests on its own lane), and the block holds until every copy is answered; the MMU holds a copy behind its lane's parked misses | +| drain | every cache it reaches | the cache holds its inputs until the admitted requests reach their banks; each bank drains its pipe, MSHR and memory-side queue, so every older write-through has left it | +| invalidate | every cache above the point of coherence | the banks walk their sets (every way of a write-back cache), writing back dirty lines and clearing every valid bit, and the cache forwards the token, on every memory port once its crossbar is empty | +| pass | the point of coherence | the shared LLC (the L3, the L2 of a single cluster, or the one data cache of a single-core device with no other memory client) answers the token without a walk; a replicated LLC still walks | + +So a fence makes this core's stores visible at the point of coherence and +leaves no stale line in front of it: release and acquire at device scope, as +GPU memory models need. It never writes back the point of coherence itself; +host visibility comes from the kernel-boundary flush (the DCR flush, which +walks every level). On a multi-core device without a shared cache level, the +point of coherence is memory and every data cache is walked. + +A fence that orders only later reads (an acquire: `fence r, rw`, or the fence +after an `.aq` atomic) owes no drain, and one that orders only earlier writes +(a release: `fence rw, w`, or the fence before an `.rl` atomic) owes no +invalidation; their tokens carry the kind (`is_addr_io` with byte enables set +for an acquire, `is_noalloc` for a release) so each level skips the part not +owed. A data cache that is itself the point of coherence drops the `.aq`/`.rl` +fences altogether. A fence ordering only device accesses (`fence ow, ow`, no R or W) sends an **IO** token (`is_flush` with `io`): no level walks; each quiesces and waits until its uncached path is empty, then forwards, so the answer proves the earlier IO writes reached memory. -Programs that share data across cores through plain memory are outside what -is validated. Share through atomics, or through the single shared level. - --- ## 7. Atomics under a deep bank pipeline @@ -334,16 +347,25 @@ Two cases in the suite exist for this design: fails on a design without the self-invalidate (§5.2) or without commit serialization (§5.6). -`atomic_critical` is skipped when `cores > 1` (§6.2). +`atomic_critical` is skipped when `cores > 1` (§6.2): it shares plain data +inside a lock without fences. + +`fence_mp` covers fence-managed visibility (§6.2). In its message-passing +modes (`-m0` fences, `-m1` acquire/release fences, `-m2` `.aq`/`.rl` atomics) +one producer passes data to a consumer on the last core that already holds +stale copies, on shared and replicated last levels (`fence_mp-*` in +`regression.yaml`, with a slow bank 0 for the release cases). In its +publication modes mirrored tasks on every core publish a payload with a plain +store, a fence and an atomic guard (`-m3`), a fence publishes another lane's +store (`-m4`), or the stores a data cache sent out on its other memory port +(`-m5`): `fence-mp-*` in `amo.yaml`, and the `parity-fence-mp` model_parity +case (2 cores, plain-store guard). --- ## 10. Not implemented -- **A dedicated acquire-invalidate** (§6.2) — a consumer-side invalidate that - clears the inner cache's valid bits without the full flush walk, modeled - identically in RTL and SimX, with a regression case for fence-managed - visibility. +- **A flash invalidate** (§6.2) in place of the per-set walk. - **rtlsim coverage of the L2-as-LLC hierarchy.** `mc-l2` runs on SimX only. - **Push coherence** with a directory or snoop filter (§4) — revisit only if a strong cross-core guarantee is ever required. diff --git a/hw/rtl/core/VX_lsu_block.sv b/hw/rtl/core/VX_lsu_block.sv index fe9b7e3480..8758f3e1a8 100644 --- a/hw/rtl/core/VX_lsu_block.sv +++ b/hw/rtl/core/VX_lsu_block.sv @@ -99,11 +99,13 @@ module VX_lsu_block import VX_gpu_pkg::*; #( wire req_is_fence, rsp_is_fence; + // A fence goes out on every lane at address 0, which inactive lanes' + // register values would otherwise decide. wire [NUM_LANES-1:0][`VX_CFG_XLEN-1:0] full_addr; wire [NUM_LANES-1:0][`VX_CFG_XLEN-1:0] lin_addr; for (genvar i = 0; i < NUM_LANES; ++i) begin : g_full_addr VX_lsu_agu lsu_agu ( - .base (execute_if.data.rs1_data[i]), + .base (execute_if.data.rs1_data[i] & {`VX_CFG_XLEN{~req_is_fence}}), .stride (execute_if.data.rs2_data[i]), .offset (execute_if.data.op_args.lsu.offset), .pack (execute_if.data.op_args.lsu.pack), @@ -284,7 +286,11 @@ module VX_lsu_block import VX_gpu_pkg::*; #( && ~(no_rsp_buf_enable && ~no_rsp_buf_ready) && ~fence_lock; - assign mem_req_mask = execute_if.data.header.tmask; + // A fence is sent on every lane, whatever the thread mask: the block's + // older requests travel on all of them, and each copy only follows those + // on its own lane. + assign mem_req_mask = req_is_fence ? {NUM_LANES{1'b1}} + : execute_if.data.header.tmask; `ifdef VX_CFG_EXT_A_ENABLE // AMO MemReq.rw is unconditionally 0: a missing line under SC must // miss-and-return-failure, not write-and-succeed. diff --git a/sim/simx/lsu_unit.cpp b/sim/simx/lsu_unit.cpp index f8f807e899..9c80420097 100644 --- a/sim/simx/lsu_unit.cpp +++ b/sim/simx/lsu_unit.cpp @@ -510,6 +510,12 @@ void LsuUnit::ingest_inputs(uint32_t b, bool queue_room, uint32_t reads_held) { #endif if (input.empty()) return; + // While a fence is out, nothing else of the block enters the request + // queue: the RTL's fence lock holds the block's input from the fence's + // request until its response, so a later store does not commit, and its + // warp does not move on, before the fence is answered. + if (state.fence.locked()) + return; auto trace = input.peek(); // Hold a fence at the input head until req_queue is empty so the // fence becomes the next dispatched item — preserves total @@ -584,8 +590,10 @@ void LsuUnit::send_req(uint32_t b, const LsuReq &req) { } } -// The fence travels to the data cache as a flush token on the lanes of its -// last packet, behind every request the block issued before it. The cache +// The fence travels to the data cache as a flush token behind every request +// the block issued before it. It goes out on every lane, whatever the thread +// mask: the block's older requests travel on all of them, and each copy only +// follows those on its own lane. The cache // answers once it has drained, flushed and invalidated, so the fence holds // the block until the token's response returns. void LsuUnit::send_fence_token(uint32_t b) { @@ -601,15 +609,9 @@ void LsuUnit::send_fence_token(uint32_t b) { lsu_req.flags.flush = 1; lsu_req.flags.fence_op = std::get(trace->instr_ptr->get_args()).fence_op; std::vector lane_entries(VX_CFG_NUM_LSU_LANES); - for (uint32_t t = base; t < VX_CFG_NUM_THREADS; ++t) { - if (trace->tmask.test(t)) { - lsu_req.mask.set(t - base); - lsu_req.tids.at(t - base) = t; - } - } - if (lsu_req.mask.none()) { - lsu_req.mask.set(0); - lsu_req.tids.at(0) = base; + for (uint32_t i = 0; i < VX_CFG_NUM_LSU_LANES; ++i) { + lsu_req.mask.set(i); + lsu_req.tids.at(i) = base + i; } uint32_t count = lsu_req.mask.count(); pending_req_t entry{nullptr, count, true, std::move(lane_entries), IntrLsuArgs{}, false}; diff --git a/sim/simx/lsu_unit.h b/sim/simx/lsu_unit.h index 5f5a4898dd..74b1ffe545 100644 --- a/sim/simx/lsu_unit.h +++ b/sim/simx/lsu_unit.h @@ -66,8 +66,10 @@ class FenceController { bool try_release(SimPortIn& out, bool pending_empty) { if (!locked_) return false; if (!pending_empty) return false; + // the token's answer retires as a load's response does: the response + // buffer, then the result arbiter's register if (out.full()) return false; - out.push(trace_, 1); + out.push(trace_, 2); locked_ = false; trace_ = nullptr; return true; diff --git a/sim/simx/mem/cache.cpp b/sim/simx/mem/cache.cpp index cc4bbda360..ab6eddf9a7 100644 --- a/sim/simx/mem/cache.cpp +++ b/sim/simx/mem/cache.cpp @@ -857,9 +857,9 @@ class CacheBank : public SimObject { VX_ASSERT(!flushing_, "flush-token walk started during a flush walk"); token_flushing_ = true; token_flush_skip_ = skip; + token_flush_quiesced_ = false; token_flush_idx_ = 0; token_flush_settle_ = 0; - token_flush_walking_ = false; flush_sector_idx_ = 0; this->tick_wake(); } @@ -917,8 +917,9 @@ class CacheBank : public SimObject { flush_way_idx_ = 0; flush_sector_idx_ = 0; token_flushing_ = false; + token_flush_quiesced_ = false; + token_flush_settle_ = 0; token_flush_idx_ = 0; - token_flush_walking_ = false; #if VX_CFG_EXT_A_ENABLED amo_unit_.reset(); for (auto &e : amo_passthru_) { @@ -2195,7 +2196,9 @@ class CacheBank : public SimObject { } void processTokenFlush() { - // the bank leaves its write-backs, then signals the end, a cycle each + // after its last line the bank waits for the line to leave its pipeline, + // then for the write-backs to leave the bank, then signals the end, a + // cycle each (the RTL flush sequencer's WAIT2 and DONE) if (token_flush_settle_ != 0) { if (--token_flush_settle_ == 0) { token_flushing_ = false; @@ -2213,9 +2216,10 @@ class CacheBank : public SimObject { token_flush_settle_ = TOKEN_FLUSH_SETTLE; return; } - // the walk starts the cycle after the bank is seen quiet - if (!token_flush_walking_) { - token_flush_walking_ = true; + // the cycle the bank finds itself quiescent (WAIT1) comes before its + // first line + if (!token_flush_quiesced_) { + token_flush_quiesced_ = true; return; } uint32_t ways = config_.write_back ? params_.lines_per_set : 1; @@ -2362,9 +2366,9 @@ class CacheBank : public SimObject { uint32_t flush_sector_idx_; bool token_flushing_; bool token_flush_skip_ = false; + bool token_flush_quiesced_ = false; static constexpr uint32_t TOKEN_FLUSH_SETTLE = 2; uint32_t token_flush_settle_ = 0; - bool token_flush_walking_ = false; uint32_t token_flush_idx_; #if VX_CFG_EXT_A_ENABLED diff --git a/tests/regression/fence_mp/common.h b/tests/regression/fence_mp/common.h index 1b04613e07..2fc8e0ddc3 100644 --- a/tests/regression/fence_mp/common.h +++ b/tests/regression/fence_mp/common.h @@ -3,6 +3,17 @@ #include +// Test modes, selected by kernel_arg_t::mode. +// Message passing from one producer thread to one consumer thread on the last +// core: how the producer publishes the flag and the consumer observes it. +#define MP_FENCE 0 // full fences on both sides +#define MP_ACQ_REL 1 // a release fence before the flag store, an acquire fence after each flag load +#define MP_AMO 2 // the flag swapped in by an amoswap.rl, read by an amoor.aq +// Fence publication across every core and lane. +#define FENCE_MP_PAIRS 3 // mirrored tasks publish to each other, round after round +#define FENCE_MP_LANES 4 // a fence publishes a store another thread of its warp made +#define FENCE_MP_PORTS 5 // a fence publishes stores that left through another memory port + #define FENCE_MP_MAGIC 0x5a5a0000u // The data lives in the even 64-byte lines of its buffer and the flag in an @@ -19,21 +30,62 @@ static inline uint32_t mp_data_words(uint32_t count) { return ((count + MP_LINE_WORDS - 1) / MP_LINE_WORDS) * (2 * MP_LINE_WORDS); } -// How the producer publishes the flag and the consumer observes it. -enum { - MP_FENCE = 0, // full fences on both sides - MP_ACQ_REL = 1, // a release fence before the flag store, an acquire fence after each flag load - MP_AMO = 2 // the flag swapped in by an amoswap.rl, read by an amoor.aq -}; +// Lane mode, one warp a block: rounds of loads the upper lanes send ahead of +// the payload store, the k-th of lane l at line (k * threads + l) * 16 so all +// fall in one data-cache bank (up to 16 banks); the payload, the last lane's +// line a round past them; the guard, a round further, with the lines one cache +// way apart that evict it; and the value stored. +#define LANE_THREADS VX_CFG_NUM_THREADS +#define LANE_FLOOD_ROUNDS 16 +#define LANE_BANK_WORDS (16 * VX_CFG_DCACHE_LINE_SIZE / 4) +#define LANE_ROUND_WORDS (LANE_THREADS * LANE_BANK_WORDS) +#define LANE_PAYLOAD_WORD (LANE_FLOOD_ROUNDS * LANE_ROUND_WORDS + (LANE_THREADS - 1) * LANE_BANK_WORDS) +#define LANE_GUARD_WORD ((LANE_FLOOD_ROUNDS + 1) * LANE_ROUND_WORDS) +#define LANE_CACHE_WAYS VX_CFG_DCACHE_NUM_WAYS +#define LANE_WAY_WORDS (VX_CFG_DCACHE_SIZE / VX_CFG_DCACHE_NUM_WAYS / 4) +#define LANE_BUFFER_WORDS (LANE_GUARD_WORD + (2 * LANE_CACHE_WAYS + 1) * LANE_WAY_WORDS) +#define LANE_PAYLOAD 0x5A5A0001u + +// Port mode, one warp a block, for a data cache with two banks, each on its +// own memory port, below which a cache of lines twice as long has two banks: +// line k of (port, bank) sets the data-cache bank bit to the port and the +// next-level bank bit to the bank. The writer stores PORT_STORE_ROUNDS lines +// a thread, then the payload, once all blocks have had +// PORT_WARMUP_CYCLES to start; the other blocks load PORT_FLOOD_ROUNDS lines +// a thread from the line PORT_FLOOD_LINE on. +#define PORT_THREADS VX_CFG_NUM_THREADS +#define PORT_LINE_OFFSET(port, bank, k) \ + ((k) * 2 * VX_CFG_L2_LINE_SIZE + (bank) * VX_CFG_L2_LINE_SIZE + (port) * VX_CFG_DCACHE_LINE_SIZE) +#define PORT_STORE_ROUNDS 4 +#define PORT_FLOOD_LINE (PORT_STORE_ROUNDS * PORT_THREADS) +#define PORT_FLOOD_ROUNDS 128 +#define PORT_WARMUP_CYCLES 2000 +#define PORT_BUFFER_WORDS(blocks) \ + (PORT_LINE_OFFSET(0, 0, PORT_FLOOD_LINE + ((blocks) - 2) * PORT_THREADS * PORT_FLOOD_ROUNDS) / 4) +#define PORT_PAYLOAD 0x5A5A0100u typedef struct { - uint32_t num_tasks; // threads launched - uint32_t count; // data words passed from producer to consumer - uint32_t spin_limit; // consumer polls before giving up - uint32_t mode; // MP_* - uint64_t data_addr; // count words, zero on entry - uint64_t flag_addr; // one word, zero on entry - uint64_t out_addr; // [0] mismatches, [1] 1 if the consumer timed out, [2] pre-read sum + uint32_t num_tasks; // threads launched + uint32_t mode; + // MP_* + uint32_t count; // data words passed from producer to consumer + uint32_t spin_limit; // consumer polls before giving up + uint64_t data_addr; // count words, zero on entry + uint64_t flag_addr; // one word, zero on entry + uint64_t out_addr; // [0] mismatches, [1] 1 if the consumer timed out, [2] pre-read sum + // FENCE_MP_* + uint32_t rounds; + uint32_t plain_guard; + uint64_t payload_addr; + uint64_t guard_addr; + uint64_t result_addr; + uint64_t flood_addr; } kernel_arg_t; +// The payload word a task publishes in a round: nonzero, so a payload still +// at its cleared value never matches. +static inline uint32_t payload_value(uint32_t round, uint32_t task) { + return (round << 20) + task + 1; +} + #endif diff --git a/tests/regression/fence_mp/kernel.cpp b/tests/regression/fence_mp/kernel.cpp index b552343e02..311fece477 100644 --- a/tests/regression/fence_mp/kernel.cpp +++ b/tests/regression/fence_mp/kernel.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "common.h" // Message passing across cores through plain memory: the producer (the first @@ -41,7 +42,7 @@ static bool observe(volatile uint32_t* flag, uint32_t mode) { } } -__kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { +static void producer_consumer(kernel_arg_t* arg) { uint32_t gid = blockIdx.x * blockDim.x + threadIdx.x; auto data = reinterpret_cast(arg->data_addr); auto flag = reinterpret_cast(arg->flag_addr); @@ -76,3 +77,159 @@ __kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { out[1] = timeout; } } + +// A fence publishes every older store of its warp, whichever thread made it. +// The upper half of block 0's threads load from lines of one data-cache bank +// that miss, so that bank's misses back up, then store a line further: the +// last thread's store, the payload, waits on its lane. The lower half, on +// lanes with nothing ahead of them (a coalescing LSU merges neighbouring +// threads onto one data-cache lane), fences next, stores the guard, +// and evicts the guard's line from its data cache with loads to the same set, +// so the guard reaches the next level with no further fence. Block 1's first +// thread, on another core, waits for the guard and reads the payload: with a +// write-back data cache that the fence did not walk after the store, the +// payload never left the writer's cache. +static void lane_release(kernel_arg_t* arg) { + uint32_t lane = threadIdx.x; + auto base = (volatile uint32_t*)arg->flood_addr; + auto payload = base + LANE_PAYLOAD_WORD; + auto guard = base + LANE_GUARD_WORD; + auto result = (uint32_t*)arg->result_addr; + if (blockIdx.x == 0) { + if (lane >= LANE_THREADS / 2) { + auto flood = base + lane * LANE_BANK_WORDS; + #pragma unroll + for (uint32_t k = 0; k < LANE_FLOOD_ROUNDS; ++k) { + (void)flood[k * LANE_ROUND_WORDS]; + } + flood[LANE_FLOOD_ROUNDS * LANE_ROUND_WORDS] = LANE_PAYLOAD; + } + // after the stores in program order: the paths of an if-else may run in + // either order + if (lane < LANE_THREADS / 2) { + vx_fence(); + guard[0] = 1; + // enough lines to fill the set and then replace every way of it + for (uint32_t w = 1; w <= 2 * LANE_CACHE_WAYS; ++w) { + (void)guard[w * LANE_WAY_WORDS]; + } + } + } else if (blockIdx.x == 1 && lane == 0) { + uint32_t seen = 0; + for (uint32_t i = 0; i < (1u << 12) && !seen; ++i) { + vx_fence(); + seen = guard[0]; + } + vx_fence(); + result[0] = seen; + result[1] = payload[0]; + } +} + +// A fence publishes the stores a data cache with several memory ports sent +// out on all of them. Block 0's threads store to lines that leave its data +// cache through the second memory port: first rounds of lines of the second +// next-level bank, which blocks 2 and up, on other cores, keep busy with +// loads that miss; then the payload, to the first next-level bank, which so +// queues behind those stores on its way. The block then +// fences, and its first thread sets the guard, on a line of the first port +// and bank, with an atomic. Block 1, on its own core, waits for the guard and +// reads the payload with atomics: its read finds the first bank free, so a +// fence that left through the first port only would let it in ahead of the +// payload. +static void port_release(kernel_arg_t* arg) { + uint32_t lane = threadIdx.x; + auto base = (uint8_t*)arg->flood_addr; + auto line = [&](uint32_t port, uint32_t bank, uint32_t k) { + return (uint32_t*)(base + PORT_LINE_OFFSET(port, bank, k)); + }; + auto payload = line(1, 0, 0); + auto guard = line(0, 0, 1); + auto result = (uint32_t*)arg->result_addr; + if (blockIdx.x == 0) { + // a first fence brings the fence's line into the next level; then let + // the loads of the other blocks fill the second next-level bank + vx_fence(); + uint32_t start = csr_read(VX_CSR_MCYCLE); + while (csr_read(VX_CSR_MCYCLE) - start < PORT_WARMUP_CYCLES) {} + #pragma unroll + for (uint32_t j = 0; j < PORT_STORE_ROUNDS; ++j) { + *(volatile uint32_t*)line(1, 1, j * PORT_THREADS + lane) = j; + } + if (lane == PORT_THREADS - 1) { + *(volatile uint32_t*)payload = PORT_PAYLOAD; + } + vx_fence(); + if (lane == 0) { + __atomic_exchange_n(guard, 1u, __ATOMIC_RELAXED); + } + } else if (blockIdx.x == 1) { + if (lane == 0) { + uint32_t seen = 0; + for (uint32_t i = 0; i < (1u << 16) && !seen; ++i) { + seen = __atomic_fetch_add(guard, 0u, __ATOMIC_RELAXED); + } + result[0] = seen; + result[1] = __atomic_fetch_add(payload, 0u, __ATOMIC_RELAXED); + } + } else { + uint32_t first = PORT_FLOOD_LINE + ((blockIdx.x - 2) * PORT_THREADS + lane) * PORT_FLOOD_ROUNDS; + for (uint32_t i = 0; i < PORT_FLOOD_ROUNDS; ++i) { + (void)*(volatile uint32_t*)line(1, 1, first + i); + } + } +} + +// Message passing between mirrored tasks, which land on different cores: each +// round a task publishes its payload word with a plain store, fences, and +// releases its guard word with an atomic; it then reads its partner's guard +// with an atomic, fences, and reads the partner's payload with a plain load, +// which must hold the partner's value if the guard showed the round released. Before publishing, the task +// reads the partner's payload slot, so its data cache holds the line the +// partner is about to write: only a fence that reaches across the caches makes +// the second read see the partner's store. The check is branch-free, so the +// retired instructions do not depend on the interleaving. With plain_guard the +// guard is a plain word too, published and observed through the same fences. +static void mirrored_pairs(kernel_arg_t* arg) { + uint32_t n = arg->num_tasks; + uint32_t gid = blockIdx.x * blockDim.x + threadIdx.x; + if (gid >= n) { + return; + } + uint32_t partner = n - 1 - gid; + auto guard = (uint32_t*)arg->guard_addr; + auto payload = (volatile uint32_t*)arg->payload_addr; + auto result = (uint32_t*)arg->result_addr; + + uint32_t errors = 0, checked = 0; + for (uint32_t r = 0; r < arg->rounds; ++r) { + volatile uint32_t* slot = payload + r * n; + (void)slot[partner]; + slot[gid] = payload_value(r, gid); + vx_fence(); + uint32_t seen; + if (arg->plain_guard) { + ((volatile uint32_t*)guard)[gid] = r + 1; + seen = ((volatile uint32_t*)guard)[partner]; + } else { + __atomic_exchange_n(&guard[gid], r + 1, __ATOMIC_RELAXED); + seen = __atomic_fetch_add(&guard[partner], 0, __ATOMIC_RELAXED); + } + vx_fence(); + uint32_t value = slot[partner]; + uint32_t released = (seen >= r + 1); + checked += released; + errors += released & (value != payload_value(r, partner)); + } + result[2 * gid + 0] = errors; + result[2 * gid + 1] = checked; +} + +__kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { + switch (arg->mode) { + case FENCE_MP_PAIRS: mirrored_pairs(arg); break; + case FENCE_MP_LANES: lane_release(arg); break; + case FENCE_MP_PORTS: port_release(arg); break; + default: producer_consumer(arg); break; + } +} diff --git a/tests/regression/fence_mp/main.cpp b/tests/regression/fence_mp/main.cpp index 78f32f09e3..d7a61a7526 100644 --- a/tests/regression/fence_mp/main.cpp +++ b/tests/regression/fence_mp/main.cpp @@ -15,15 +15,23 @@ exit(-1); \ } while (false) +/////////////////////////////////////////////////////////////////////////////// + const char* kernel_file = "kernel.vxbin"; +uint32_t mode = MP_FENCE; uint32_t count = 64; uint32_t spin_limit = 4096; -uint32_t mode = MP_FENCE; +uint32_t rounds = 8; +bool plain_guard = false; vx_device_h device = nullptr; vx_buffer_h data_buffer = nullptr; vx_buffer_h flag_buffer = nullptr; vx_buffer_h out_buffer = nullptr; +vx_buffer_h payload_buffer = nullptr; +vx_buffer_h guard_buffer = nullptr; +vx_buffer_h result_buffer = nullptr; +vx_buffer_h flood_buffer = nullptr; vx_queue_h queue = nullptr; vx_module_h module_ = nullptr; vx_kernel_h kernel = nullptr; @@ -31,16 +39,20 @@ kernel_arg_t kernel_arg = {}; static void show_usage() { std::cout << "Vortex Test." << std::endl; - std::cout << "Usage: [-k: kernel] [-n words] [-s spin limit] [-m mode: 0 fences, 1 acquire/release fences, 2 .aq/.rl atomics] [-h: help]" << std::endl; + std::cout << "Usage: [-k: kernel] [-m mode: 0 fences, 1 acquire/release fences, 2 .aq/.rl atomics," + << " 3 mirrored pairs, 4 lanes, 5 ports] [-n words] [-s spin limit] [-r rounds]" + << " [-g: plain-store guard] [-h: help]" << std::endl; } static void parse_args(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "n:s:m:k:h")) != -1) { + while ((c = getopt(argc, argv, "m:n:s:r:gk:h")) != -1) { switch (c) { + case 'm': mode = atoi(optarg); break; case 'n': count = atoi(optarg); break; case 's': spin_limit = atoi(optarg); break; - case 'm': mode = atoi(optarg); break; + case 'r': rounds = atoi(optarg); break; + case 'g': plain_guard = true; break; case 'k': kernel_file = optarg; break; case 'h': show_usage(); exit(0); break; default: show_usage(); exit(-1); @@ -50,34 +62,46 @@ static void parse_args(int argc, char **argv) { void cleanup() { if (device) { - if (data_buffer) vx_buffer_release(data_buffer); - if (flag_buffer) vx_buffer_release(flag_buffer); - if (out_buffer) vx_buffer_release(out_buffer); + if (data_buffer) vx_buffer_release(data_buffer); + if (flag_buffer) vx_buffer_release(flag_buffer); + if (out_buffer) vx_buffer_release(out_buffer); + if (payload_buffer) vx_buffer_release(payload_buffer); + if (guard_buffer) vx_buffer_release(guard_buffer); + if (result_buffer) vx_buffer_release(result_buffer); + if (flood_buffer) vx_buffer_release(flood_buffer); if (kernel) vx_kernel_release(kernel); if (module_) vx_module_release(module_); if (queue) vx_queue_release(queue); + vx_device_dump_perf(device, stdout); vx_device_release(device); } } -int main(int argc, char *argv[]) { - parse_args(argc, argv); - - RT_CHECK(vx_device_open(0, &device)); - vx_queue_info_t qi = { sizeof(qi), nullptr, VX_QUEUE_PRIORITY_NORMAL, 0 }; - RT_CHECK(vx_queue_create(device, &qi, &queue)); - - uint64_t num_cores, num_warps, num_threads; - RT_CHECK(vx_device_query(device, VX_CAPS_NUM_CORES, &num_cores)); - RT_CHECK(vx_device_query(device, VX_CAPS_NUM_WARPS, &num_warps)); - RT_CHECK(vx_device_query(device, VX_CAPS_NUM_THREADS, &num_threads)); - // one thread per hardware slot, so producer and consumer are resident together - uint32_t total_threads = num_cores * num_warps * num_threads; +static void launch(uint32_t num_blocks, uint32_t num_threads, vx_event_h* launch_ev) { + uint32_t grid_dim[1], block_dim[1]; + if (num_blocks != 0) { + grid_dim[0] = num_blocks; + block_dim[0] = num_threads; + } else { + uint32_t n = kernel_arg.num_tasks; + RT_CHECK(vx_device_max_occupancy_grid(device, 1, &n, grid_dim, block_dim)); + } + vx_launch_info_t li = {}; + li.struct_size = sizeof(li); + li.kernel = kernel; + li.args_host = &kernel_arg; + li.args_size = sizeof(kernel_arg); + li.ndim = 1; + li.grid_dim[0] = grid_dim[0]; + li.block_dim[0] = block_dim[0]; + RT_CHECK(vx_enqueue_launch(queue, &li, 0, nullptr, launch_ev)); +} +// Producer/consumer message passing: one producer, one consumer on the last core. +static uint64_t run_producer_consumer(uint32_t total_threads) { kernel_arg.num_tasks = total_threads; kernel_arg.count = count; kernel_arg.spin_limit = spin_limit; - kernel_arg.mode = mode; std::vector zeros(mp_data_words(count), 0); std::vector out(4, 0); @@ -99,26 +123,13 @@ int main(int argc, char *argv[]) { RT_CHECK(vx_module_get_kernel(module_, "main", &kernel)); vx_event_h launch_ev = nullptr, read_ev = nullptr; - { - uint32_t n = total_threads; - uint32_t grid_dim[1], block_dim[1]; - RT_CHECK(vx_device_max_occupancy_grid(device, 1, &n, grid_dim, block_dim)); - vx_launch_info_t li = {}; - li.struct_size = sizeof(li); - li.kernel = kernel; - li.args_host = &kernel_arg; - li.args_size = sizeof(kernel_arg); - li.ndim = 1; - li.grid_dim[0] = grid_dim[0]; - li.block_dim[0] = block_dim[0]; - RT_CHECK(vx_enqueue_launch(queue, &li, 0, nullptr, &launch_ev)); - } + launch(0, 0, &launch_ev); RT_CHECK(vx_enqueue_read(queue, out.data(), out_buffer, 0, out_size, 1, &launch_ev, &read_ev)); RT_CHECK(vx_event_wait_value(read_ev, 1, VX_TIMEOUT_INFINITE)); vx_event_release(read_ev); vx_event_release(launch_ev); - int errors = 0; + uint64_t errors = 0; if (out[1] != 0) { std::cout << "consumer timed out waiting for the flag" << std::endl; ++errors; @@ -127,6 +138,115 @@ int main(int argc, char *argv[]) { std::cout << "consumer saw " << std::dec << out[0] << " stale data words" << std::endl; errors += out[0]; } + return errors; +} + +// Fence publication: mirrored pairs on every hardware thread, or a writer +// warp and a reader warp (lanes), plus a flooding warp on every other core +// (ports). +static uint64_t run_publication(uint64_t num_cores, uint32_t total_threads, uint32_t num_threads) { + if (rounds == 0) { + rounds = 1; + } + if ((mode == FENCE_MP_LANES && num_cores < 2) || (mode == FENCE_MP_PORTS && num_cores < 3)) { + std::cout << "Error: mode " << mode << " needs " << (mode == FENCE_MP_LANES ? 2 : 3) << " cores" << std::endl; + cleanup(); + exit(-1); + } + + uint32_t num_blocks = (mode == FENCE_MP_PAIRS) ? 0 : ((mode == FENCE_MP_LANES) ? 2 : num_cores); + uint32_t num_tasks = (mode == FENCE_MP_PAIRS) ? total_threads : num_blocks * num_threads; + uint32_t payload_size = num_tasks * rounds * sizeof(uint32_t); + uint32_t guard_size = num_tasks * sizeof(uint32_t); + uint32_t result_size = 2 * num_tasks * sizeof(uint32_t); + + std::cout << "number of tasks: " << num_tasks << ", rounds: " << rounds + << (plain_guard ? ", plain-store guard" : ", atomic guard") + << ", mode: " << mode << std::endl; + + kernel_arg.num_tasks = num_tasks; + kernel_arg.rounds = rounds; + kernel_arg.plain_guard = plain_guard; + + RT_CHECK(vx_buffer_create(device, payload_size, VX_MEM_READ_WRITE, &payload_buffer)); + RT_CHECK(vx_buffer_address(payload_buffer, &kernel_arg.payload_addr)); + RT_CHECK(vx_buffer_create(device, guard_size, VX_MEM_READ_WRITE, &guard_buffer)); + RT_CHECK(vx_buffer_address(guard_buffer, &kernel_arg.guard_addr)); + RT_CHECK(vx_buffer_create(device, result_size, VX_MEM_WRITE, &result_buffer)); + RT_CHECK(vx_buffer_address(result_buffer, &kernel_arg.result_addr)); + // the write runs in the background, so its source outlives the launch + std::vector flood_zeros; + if (mode != FENCE_MP_PAIRS) { + uint64_t flood_words = (mode == FENCE_MP_LANES) ? LANE_BUFFER_WORDS : PORT_BUFFER_WORDS(num_blocks); + RT_CHECK(vx_buffer_create(device, flood_words * sizeof(uint32_t), VX_MEM_READ_WRITE, &flood_buffer)); + RT_CHECK(vx_buffer_address(flood_buffer, &kernel_arg.flood_addr)); + flood_zeros.assign(flood_words, 0); + RT_CHECK(vx_enqueue_write(queue, flood_buffer, 0, flood_zeros.data(), flood_words * sizeof(uint32_t), 0, nullptr, nullptr)); + } + + std::vector zeros(num_tasks * rounds, 0); + RT_CHECK(vx_enqueue_write(queue, payload_buffer, 0, zeros.data(), payload_size, 0, nullptr, nullptr)); + RT_CHECK(vx_enqueue_write(queue, guard_buffer, 0, zeros.data(), guard_size, 0, nullptr, nullptr)); + + RT_CHECK(vx_module_load_file(device, kernel_file, &module_)); + RT_CHECK(vx_module_get_kernel(module_, "main", &kernel)); + + vx_event_h launch_ev = nullptr, read_ev = nullptr; + launch(num_blocks, num_threads, &launch_ev); + + std::vector h_result(2 * num_tasks); + RT_CHECK(vx_enqueue_read(queue, h_result.data(), result_buffer, 0, result_size, 1, &launch_ev, &read_ev)); + RT_CHECK(vx_event_wait_value(read_ev, 1, VX_TIMEOUT_INFINITE)); + vx_event_release(read_ev); + vx_event_release(launch_ev); + + uint64_t errors = 0, checked = 0; + if (mode == FENCE_MP_LANES || mode == FENCE_MP_PORTS) { + // The reader saw the guard, then the payload. + uint32_t expected = (mode == FENCE_MP_LANES) ? LANE_PAYLOAD : PORT_PAYLOAD; + checked = h_result[0]; + if (h_result[0] != 0 && h_result[1] != expected) { + std::cout << "reader read 0x" << std::hex << h_result[1] << ", expected 0x" + << expected << std::dec << std::endl; + errors = 1; + } + } else for (uint32_t i = 0; i < num_tasks; ++i) { + errors += h_result[2 * i + 0]; + checked += h_result[2 * i + 1]; + if (h_result[2 * i + 0] != 0 && errors <= 8) { + std::cout << "task " << i << ": " << h_result[2 * i + 0] + << " stale payload reads" << std::endl; + } + } + std::cout << "released rounds observed: " << checked << ", stale payloads: " << errors << std::endl; + if (errors == 0 && checked == 0) { + std::cout << "No task observed a released partner; nothing was checked." << std::endl; + errors = 1; + } + return errors; +} + +int main(int argc, char *argv[]) { + parse_args(argc, argv); + if (mode > FENCE_MP_PORTS) { + show_usage(); + return -1; + } + + RT_CHECK(vx_device_open(0, &device)); + vx_queue_info_t qi = { sizeof(qi), nullptr, VX_QUEUE_PRIORITY_NORMAL, 0 }; + RT_CHECK(vx_queue_create(device, &qi, &queue)); + + uint64_t num_cores, num_warps, num_threads; + RT_CHECK(vx_device_query(device, VX_CAPS_NUM_CORES, &num_cores)); + RT_CHECK(vx_device_query(device, VX_CAPS_NUM_WARPS, &num_warps)); + RT_CHECK(vx_device_query(device, VX_CAPS_NUM_THREADS, &num_threads)); + // one thread per hardware slot, so every task is resident at once + uint32_t total_threads = num_cores * num_warps * num_threads; + + kernel_arg.mode = mode; + uint64_t errors = (mode <= MP_AMO) ? run_producer_consumer(total_threads) + : run_publication(num_cores, total_threads, num_threads); cleanup(); diff --git a/tests/regression/vm_test/common.h b/tests/regression/vm_test/common.h index e542489543..bc10015028 100644 --- a/tests/regression/vm_test/common.h +++ b/tests/regression/vm_test/common.h @@ -9,6 +9,18 @@ #define VM_MODE_SUPERPAGE 4 // repeated reads through a superpage-mapped region #define VM_MODE_SP_ORDER 5 // cold-page store, delayed readback, per superpage #define VM_MODE_REUSE 6 // freed pages reused by a larger buffer, then a new one +#define VM_MODE_RELEASE 7 // cold-page store, fence, atomic guard; the partner acquires + +// Release mode: block 0 writes and block 1 reads. The writer's lanes send +// RELEASE_PAD_BURSTS bursts of stores to cold pages ahead of the page store, +// one page per page-table region, so the buffer must span +// RELEASE_REGIONS regions. +#define RELEASE_BLOCK_SIZE 4u +#define RELEASE_PAD_BURSTS 3u +#define RELEASE_REGIONS ((RELEASE_PAD_BURSTS + 1) * RELEASE_BLOCK_SIZE) + +// Pages mapped by one leaf page-table page. +#define VM_REGION_PAGES (VX_VM_PT_SIZE / VX_VM_PTE_SIZE) typedef struct { uint32_t mode; diff --git a/tests/regression/vm_test/kernel.cpp b/tests/regression/vm_test/kernel.cpp index 9e453c4ce9..95eb0bdcff 100644 --- a/tests/regression/vm_test/kernel.cpp +++ b/tests/regression/vm_test/kernel.cpp @@ -47,6 +47,46 @@ __kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { dst[gid] = buf[peer * pages * WORDS_PER_PAGE]; break; } + case VM_MODE_RELEASE: { + // Release and acquire between block 0, the writer, and block 1, whose + // first thread reads; the blocks run in different clusters. The writer + // stores to its page, fences, and sets the guard with an atomic; the + // reader waits for the guard, fences, and reads the page. The guard page + // is translated on both sides up front, and the page on the reader's + // side. The writer's lanes first store to cold pages, one per page-table + // region, and the page store goes out in the last burst, so it parks on a + // TLB miss behind all their walks while the guard swap, a TLB hit, could + // overtake it. No barrier or kernel end comes in between: the fence alone + // must keep the parked store ahead of the guard. + auto guard = reinterpret_cast(arg->aux_addr); + volatile uint32_t* page = buf; + uint32_t lane = threadIdx.x; + (void)__atomic_fetch_add(&guard[0], 0u, __ATOMIC_RELAXED); + if (blockIdx.x == 0) { + vx_fence(); // the guard translation is in before the cold stores go out + #pragma unroll + for (uint32_t r = 0; r < RELEASE_PAD_BURSTS; ++r) { + uint32_t region = 1 + r * RELEASE_BLOCK_SIZE + lane; + page[region * VM_REGION_PAGES * WORDS_PER_PAGE] = region; + } + uint32_t region = (lane == 0) ? 0 : (RELEASE_PAD_BURSTS * RELEASE_BLOCK_SIZE + lane); + page[region * VM_REGION_PAGES * WORDS_PER_PAGE] = (lane == 0) ? 0xAB000000u : region; + vx_fence(); + if (lane == 0) { + __atomic_exchange_n(&guard[0], 1u, __ATOMIC_RELAXED); + } + dst[gid] = 0xAB000000u; + } else if (blockIdx.x == 1 && lane == 0) { + (void)page[0]; + uint32_t seen = 0; + for (uint32_t i = 0; i < 65536 && !seen; ++i) { + seen = __atomic_fetch_add(&guard[0], 0u, __ATOMIC_RELAXED); + } + vx_fence(); + dst[gid] = seen ? page[0] : 0u; + } + break; + } case VM_MODE_DRAIN: { // Trailing store burst to fresh pages with no fence: completion // must not be signaled while any store is still parked on a miss. diff --git a/tests/regression/vm_test/main.cpp b/tests/regression/vm_test/main.cpp index 5a090985a3..019b04cf9b 100644 --- a/tests/regression/vm_test/main.cpp +++ b/tests/regression/vm_test/main.cpp @@ -37,7 +37,7 @@ kernel_arg_t kernel_arg = {}; static void show_usage() { std::cout << "Usage: [-t mode] [-n tasks] [-p pages/task] [-h]" << std::endl; - std::cout << " modes: 0=stride 1=fence 2=drain 3=amo 4=superpage 5=sp_order 6=reuse" << std::endl; + std::cout << " modes: 0=stride 1=fence 2=drain 3=amo 4=superpage 5=sp_order 6=reuse 7=release" << std::endl; } static void parse_args(int argc, char** argv) { @@ -191,6 +191,17 @@ int main(int argc, char* argv[]) { uint32_t max_bx = 1, max_by = 1, max_bz = 1; RT_CHECK(vx_kernel_get_max_block_size(kernel, &max_bx, &max_by, &max_bz)); uint32_t block_x = std::min(num_tasks, max_bx * max_by * max_bz); + // Release mode pairs a writer block with a reader block on another core: + // a block of four threads, so the writer has several lanes. + if (test_mode == VM_MODE_RELEASE) { + if (num_tasks < 2 * RELEASE_BLOCK_SIZE || buf_size < uint64_t(RELEASE_REGIONS) * VM_REGION_PAGES * PAGE_SIZE) { + std::cout << "Error: release mode needs " << 2 * RELEASE_BLOCK_SIZE << " tasks and " + << RELEASE_REGIONS * VM_REGION_PAGES << " pages in all" << std::endl; + cleanup(); + return -1; + } + block_x = RELEASE_BLOCK_SIZE; + } { vx_launch_info_t li = {}; li.struct_size = sizeof(li); @@ -239,6 +250,16 @@ int main(int argc, char* argv[]) { } break; } + case VM_MODE_RELEASE: { + // The reader, block 1's first thread, must have seen the guard and then + // the writer's store. + uint32_t reader = RELEASE_BLOCK_SIZE; + if (dst[reader] != 0xAB000000u) { + printf("*** error: reader read 0x%x, expected 0x%x\n", dst[reader], 0xAB000000u); + ++errors; + } + break; + } case VM_MODE_DRAIN: { // The trailing stores must be visible to the host readback with no // fence: read the working buffer directly. From 7cb8582e2abf30e57154e67061dd526bfb03432f Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 19:06:13 -0800 Subject: [PATCH 05/12] amo: compare-and-swap counters from a nonzero base, global and local memory The local memory switch once rebuilt each lane's request without the AMO compare value, so every compare-and-swap to local memory compared against 0. Master carries the value through (the upstream form of the fix), but the regression's compare-and-swap cases still only ever compare against 0, so they pass either way. cas_counter and cas_counter_lmem count up from a nonzero base with a compare-and-swap of the last observed value: a comparand that does not reach the memory side makes the count fall short. Both failed on the switch without the compare value (SimX). They run under the existing Zacas guard, in the zacas-simd and zacas-simd-lsu1 cases, on simx and rtlsim. Also drops local_mem_switch.cpp's stale note that the RTL has no local-memory AMO path. Branch commit: ab81ab352 (its Vulkan fp64 and atomic_float tests go with the graphics branch). Co-Authored-By: Claude Opus 5.5 --- ci/testcases/isa/amo.yaml | 4 +- docs/designs/atomic_memory_operations.md | 3 +- sim/simx/lsu_unit.cpp | 4 -- tests/regression/amo/common.h | 4 ++ tests/regression/amo/kernel.cpp | 45 +++++++++++++++++++ tests/regression/amo/testcases.h | 56 ++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 7 deletions(-) diff --git a/ci/testcases/isa/amo.yaml b/ci/testcases/isa/amo.yaml index 75b8f1287d..5977ae3a4f 100644 --- a/ci/testcases/isa/amo.yaml +++ b/ci/testcases/isa/amo.yaml @@ -45,7 +45,7 @@ tests: xlen: [32] configs+: "-DVX_CFG_EXT_ZACAS_ENABLE -DVX_CFG_NUM_WARPS=32 -DVX_CFG_SIMD_WIDTH=4 -DVX_CFG_NUM_OPCS=4" shape: {threads: 8} - args: "-n8 -t cas_ladder -t cas_lmem" + args: "-n8 -t cas_ladder -t cas_lmem -t cas_counter -t cas_counter_lmem" # The same with two issue slots sharing one LSU block: the lane dispatcher # must not switch slots between an instruction's SIMD slices. - id: zacas-simd-lsu1 @@ -54,7 +54,7 @@ tests: xlen: [32] configs+: "-DVX_CFG_EXT_ZACAS_ENABLE -DVX_CFG_NUM_WARPS=32 -DVX_CFG_SIMD_WIDTH=4 -DVX_CFG_NUM_LSU_BLOCKS=1" shape: {threads: 8} - args: "-n8 -t cas_ladder -t cas_lmem" + args: "-n8 -t cas_ladder -t cas_lmem -t cas_counter -t cas_counter_lmem" # Write-back D-cache variants (rtlsim only in the legacy suite). - id: wb-dirtybytes0 app: amo diff --git a/docs/designs/atomic_memory_operations.md b/docs/designs/atomic_memory_operations.md index 500aac5ff8..22ca577427 100644 --- a/docs/designs/atomic_memory_operations.md +++ b/docs/designs/atomic_memory_operations.md @@ -427,8 +427,9 @@ is the LLC. | 12 | `self_consistency` | a hart reads back its own atomic through a plain load | | 13, 14 | `amoadd_lmem`, `lrsc_lmem` | cases 0 and 7 on local memory | | 15, 16 | `cas_ladder`, `cas_lmem` | every hart races compare-and-swap for each slot; compiled only with Zacas | +| 17, 18 | `cas_counter`, `cas_counter_lmem` | compare-and-swap increment from a nonzero base | -The `amo` category in [`ci/testcases/amo.yaml`](../../ci/testcases/amo.yaml) +The `amo` suite in [`ci/testcases/isa/amo.yaml`](../../ci/testcases/isa/amo.yaml) runs them on both simulators at both `XLEN`s, with and without Zacas, on a write-back LLC, at 8 threads, and across the 4-core L2 and L2+L3 hierarchies, alongside the `rv32ua` / `rv64ua` ISA conformance tests. diff --git a/sim/simx/lsu_unit.cpp b/sim/simx/lsu_unit.cpp index 9c80420097..87944d7232 100644 --- a/sim/simx/lsu_unit.cpp +++ b/sim/simx/lsu_unit.cpp @@ -569,10 +569,6 @@ void LsuUnit::send_req(uint32_t b, const LsuReq &req) { if (!req.mask.test(i)) { continue; } - // An AMO whose address is Shared is executed by the LMEM bank. The RTL - // has no such path -- its local-memory switch drops the AMO and asserts -- - // so the two models diverge on this op until the hardware path lands, - // and a Shared AMO cannot be run on FPGA. auto &part = (get_addr_type(req.addrs.at(i)) == AddrType::Shared) ? lmem_req : dc_req; part.mask.set(i); part.addrs.at(i) = req.addrs.at(i); diff --git a/tests/regression/amo/common.h b/tests/regression/amo/common.h index f9017a823c..99ce852ade 100644 --- a/tests/regression/amo/common.h +++ b/tests/regression/amo/common.h @@ -13,6 +13,10 @@ #define CAS_LMEM_SLOTS 16 #define CAS_LMEM_GROUP_MARK 0x10000u +// Starting value of the compare-and-swap counters: nonzero, so no comparand a +// swap uses is ever zero. +#define CAS_COUNTER_BASE 0x5a000000u + // Initial word of the local-memory swap chain in the AMO op sweep. #define AMO_OPS_SWAP_INIT 0x5EED5EEDu diff --git a/tests/regression/amo/kernel.cpp b/tests/regression/amo/kernel.cpp index 56ba507fed..84caa87e25 100644 --- a/tests/regression/amo/kernel.cpp +++ b/tests/regression/amo/kernel.cpp @@ -478,8 +478,51 @@ void kernel_cas_lmem(kernel_arg_t* __UNIFORM__ arg) { } per_hart[hid] = wins + ((threadIdx.x == 0) ? CAS_LMEM_GROUP_MARK : 0); } + +// 18) Compare-and-swap increment on global memory. +// The classic lock-free counter: read, then swap in read+1 until no other hart +// intervened. Unlike the ladders, every swap after the first compares against +// a nonzero word the hart observed, and the counter starts from a nonzero +// base, so a comparand that does not reach the memory side is caught: the +// swap would then compare against the wrong word and the count would fall +// short of base + harts * iters. +void kernel_cas_counter(kernel_arg_t* __UNIFORM__ arg) { + auto counter = (uint32_t*)arg->shared_addr; + for (uint32_t i = 0; i < arg->iters; ++i) { + uint32_t expected = __atomic_load_n(counter, __ATOMIC_RELAXED); + while (!__atomic_compare_exchange_n(counter, &expected, expected + 1, 0, + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { + } + } +} + +// 19) Compare-and-swap increment on local memory. +// Test 17 on a group's local-memory word, so the LMEM banks resolve the swap. +// Each group's leader publishes how far its counter moved past the base, and +// the published counts sum to harts * iters whatever the launch shape. +void kernel_cas_counter_lmem(kernel_arg_t* __UNIFORM__ arg) { + auto counter = (uint32_t*)__local_mem(); + auto per_hart = (uint32_t*)arg->per_hart_addr; + if (threadIdx.x == 0) { + *counter = CAS_COUNTER_BASE; + } + __syncthreads(); + + for (uint32_t i = 0; i < arg->iters; ++i) { + uint32_t expected = __atomic_load_n(counter, __ATOMIC_RELAXED); + while (!__atomic_compare_exchange_n(counter, &expected, expected + 1, 0, + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { + } + } + __syncthreads(); + + if (threadIdx.x == 0) { + per_hart[hart_id()] = *counter - CAS_COUNTER_BASE; + } +} #endif + static const PFN_Kernel sc_tests[] = { kernel_amoadd, // 0 kernel_amoor, // 1 @@ -500,6 +543,8 @@ static const PFN_Kernel sc_tests[] = { #if VX_CFG_EXT_ZACAS_ENABLED kernel_cas_ladder, // 16 native compare-and-swap (Zacas amocas) kernel_cas_lmem, // 17 compare-and-swap on local memory (LMEM banks) + kernel_cas_counter, // 18 compare-and-swap increment, nonzero comparands + kernel_cas_counter_lmem, // 19 the same on local memory (LMEM banks) #endif }; diff --git a/tests/regression/amo/testcases.h b/tests/regression/amo/testcases.h index bc3bdb4e7e..08b1e38cc1 100644 --- a/tests/regression/amo/testcases.h +++ b/tests/regression/amo/testcases.h @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include #include "common.h" void cleanup(); @@ -504,6 +506,58 @@ class Test_CAS_LMEM : public ITestCase { } }; +// 17) Compare-and-swap counter on global memory: each hart adds iters by +// read/compare-and-swap retries from a nonzero base, so the final word is +// base + n * iters only if every swap compared against the word it read. +class Test_CAS_COUNTER : public ITestCase { +public: + Test_CAS_COUNTER(TestSuite* s) : ITestCase(s, "cas_counter") {} + void setup(uint32_t, uint32_t* shared, uint32_t*) override { + *shared = CAS_COUNTER_BASE; + } + int verify(uint32_t n, uint32_t iters, + const uint32_t* shared, const uint32_t*) override { + const uint32_t expected = CAS_COUNTER_BASE + n * iters; + if (*shared != expected) { + std::cout << " shared=0x" << std::hex << *shared << " expected=0x" + << expected << std::dec << std::endl; + return 1; + } + return 0; + } +}; + +// 18) Compare-and-swap counter on local memory: per-group counters from the same +// nonzero base; the leaders' published increments sum to n * iters. +class Test_CAS_COUNTER_LMEM : public ITestCase { +public: + Test_CAS_COUNTER_LMEM(TestSuite* s) : ITestCase(s, "cas_counter_lmem") {} + void setup(uint32_t n, uint32_t* /*shared*/, uint32_t* per_hart) override { + for (uint32_t h = 0; h < n; ++h) per_hart[h] = 0; + } + int verify(uint32_t n, uint32_t iters, + const uint32_t* /*shared*/, const uint32_t* per_hart) override { + uint64_t total = 0; + uint32_t groups = 0; + for (uint32_t h = 0; h < n; ++h) { + if (per_hart[h] != 0) { total += per_hart[h]; ++groups; } + } + const uint64_t expected = (uint64_t)n * iters; + if (groups == 0) { + std::cout << " no group published a count -- the kernel did not run" + << std::endl; + return 1; + } + if (total != expected) { + std::cout << " published total=" << total << " expected=" << expected + << " across " << groups << " group(s)" << std::endl; + return 1; + } + return 0; + } +}; + + inline TestSuite::TestSuite(vx_device_h device) : device_(device) { // Test_ATOMIC_CRITICAL needs to know VX_CFG_NUM_THREADS to compute the // expected count; query it from the device caps. @@ -532,6 +586,8 @@ inline TestSuite::TestSuite(vx_device_h device) : device_(device) { // this instruction exists to replace and which does not survive contention. add_test(new Test_CAS_LADDER(this)); add_test(new Test_CAS_LMEM(this)); + add_test(new Test_CAS_COUNTER(this)); + add_test(new Test_CAS_COUNTER_LMEM(this)); #endif } From 9a21c9baa283f0096462c3d6c4e5b16f25cc2183 Mon Sep 17 00:00:00 2001 From: tinebp Date: Thu, 3 Dec 2026 02:15:14 -0800 Subject: [PATCH 06/12] fixup! core: a workgroup barrier drains the warp's memory requests (switch inputs are wires after #574) --- sim/simx/core.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sim/simx/core.cpp b/sim/simx/core.cpp index 5df151462d..ccfbd844c6 100644 --- a/sim/simx/core.cpp +++ b/sim/simx/core.cpp @@ -1330,7 +1330,9 @@ class Core::Impl { // where a later read of another block can be taken ahead of an earlier store. bool mem_req_drained() const { for (uint32_t b = 0; b < VX_CFG_NUM_LSU_BLOCKS; ++b) { - if (!lmem_switch_.at(b)->ReqIn.empty() || !mem_coalescers_.at(b)->drained()) { + // The switch's request inputs are wires: their size is that of the + // port they end in, a request still on its way included. + if (lmem_switch_.at(b)->ReqInDC.size() != 0 || !mem_coalescers_.at(b)->drained()) { return false; } // size(), not empty(): a request still in flight from the switch counts. From bd0f6441b07e64ffa472322eb07dd62f21b30f0b Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 19:06:14 -0800 Subject: [PATCH 07/12] simx/cache: time LLC and passthrough atomics as VX_cache_amo does SimX's cache bank paced atomics differently from the RTL, which broke the model_parity cases on atomics: - SimX held core-request admission (amo_busy_) for every store-bearing LLC atomic from admission to commit, hit or miss, kept one pending writeback (a second commit overwrote it), and had no input ordering guard. It now models VX_cache_amo: commit_busy holds admission only from the S0 of a store-bearing atomic predicted to hit (or a replay) until its result has drained; a writeback queue (AMO_WBQ_SIZE 4, merging per word) drains through the core-request slot; a fill waits while that queue has no room (wbq_full); and the same-line input defer reads a registered MSHR probe (the request's first cycle at the input, and the S0, S1 and following cycle of an atomic that misses). - A non-LLC (passthrough) atomic's response now crosses the bank pipe as a fill (AmoFill) and answers from its replay (AmoRsp), as in the RTL, instead of answering the core in the tick the response arrived. - The LLC's MSHR asserts that no request links behind a pending atomic (amo_ordered_), the RTL's "request linked behind a pending AMO" check, and a full MSHR at enqueue is a named VX_ASSERT instead of a bare abort. amo -n32, SimX / RTL cycles: amoadd_scatter 5011 / 5252 (11740 before); contended amoadd+amoswap 7766 / 7761; the same at a shared L2 within the parity tolerance (6.24% before). Trigger tests: tests/regression/amo amoadd_scatter (atomics over more lines than the dcache holds) and amo_line_burst (bursts into distinct words of cold lines); CI cases parity-amo-contended, parity-amo-contended-l2, parity-amo-scatter (model_parity), which fail the 5% tolerance without this change. Design notes: multicache_amo_coherence.md 5.1. Default behaviour: SimX timing of atomics only (EXT_A is off by default). The RTL half of 6a3b7fc3f is master's. Branch commits: 6ef985b38, 2269c5763, 6a3b7fc3f (SimX), e163ba841. Co-Authored-By: Claude Opus 5.5 --- ci/testcases/isa/amo.yaml | 27 ++ docs/designs/atomic_memory_operations.md | 1 + docs/designs/multicache_amo_coherence.md | 1 + sim/simx/mem/cache.cpp | 322 +++++++++++++++++++---- tests/regression/amo/common.h | 14 + tests/regression/amo/kernel.cpp | 29 ++ tests/regression/amo/main.cpp | 3 +- tests/regression/amo/testcases.h | 55 ++++ 8 files changed, 404 insertions(+), 48 deletions(-) diff --git a/ci/testcases/isa/amo.yaml b/ci/testcases/isa/amo.yaml index 5977ae3a4f..cb866e70a4 100644 --- a/ci/testcases/isa/amo.yaml +++ b/ci/testcases/isa/amo.yaml @@ -35,6 +35,33 @@ tests: configs+: "-DVX_CFG_NUM_LSU_LANES=4" shape: {threads: 8} args: "-n8 -t lrsc_counter -t lrsc_counter_aqrl -t lrsc_lmem" + # Every lane of every warp hammering one word: the LLC bank admits no core + # request from an atomic's admission until its writeback re-enters the bank + # (the commit occupancy), which paces contended atomics at one per five cycles. + - id: parity-amo-contended + check: model_parity + via: blackbox + app: amo + xlen: [32] + args: "-n32 -t amoadd -t amoswap" + # The same at a shared L2 (the LLC, LATENCY 4: two commit-bubble stages more), + # the dcaches passing the atomics through. + - id: parity-amo-contended-l2 + check: model_parity + via: blackbox + app: amo + xlen: [32] + shape: {cores: 4, l2cache: true} + args: "-n32 -t amoadd -t amoswap" + tier: full + # Atomics spread over more lines than the dcache holds: most miss, hold no + # admission at their S0, and commit as replays, which do. + - id: parity-amo-scatter + check: model_parity + via: blackbox + app: amo + xlen: [32] + args: "-n32 -t amoadd_scatter" # Four operand collectors and two SIMD packets per warp (32 warps x 8 threads, # SIMD 4): a three-operand compare-and-swap stalls between its packets on # bank conflicts, and the operand arbiter must keep an instruction's packets diff --git a/docs/designs/atomic_memory_operations.md b/docs/designs/atomic_memory_operations.md index 22ca577427..c8014786e8 100644 --- a/docs/designs/atomic_memory_operations.md +++ b/docs/designs/atomic_memory_operations.md @@ -428,6 +428,7 @@ is the LLC. | 13, 14 | `amoadd_lmem`, `lrsc_lmem` | cases 0 and 7 on local memory | | 15, 16 | `cas_ladder`, `cas_lmem` | every hart races compare-and-swap for each slot; compiled only with Zacas | | 17, 18 | `cas_counter`, `cas_counter_lmem` | compare-and-swap increment from a nonzero base | +| `amoadd_scatter`, `amo_line_burst` | atomics into more lines than the dcache holds; groups of harts adding into distinct words of cold lines | the counts, with missing atomics replaying back to back into the LLC | The `amo` suite in [`ci/testcases/isa/amo.yaml`](../../ci/testcases/isa/amo.yaml) runs them on both simulators at both `XLEN`s, with and without Zacas, on a diff --git a/docs/designs/multicache_amo_coherence.md b/docs/designs/multicache_amo_coherence.md index 1655ce74cf..1bb9f8f741 100644 --- a/docs/designs/multicache_amo_coherence.md +++ b/docs/designs/multicache_amo_coherence.md @@ -316,6 +316,7 @@ At `PIPE_EX = 0` every one of these collapses to the two-stage bank. |---|---|---| | passthrough | MSHR entry + latched result word | a dedicated `AmoProbe` request type and an 8-entry passthrough table | | response routing | MSHR replay | the memory tag space is partitioned: passthrough ids sit above the MSHR ids | +| response timing | the response takes the fill slot and crosses the pipe installing nothing; the entry replays the next cycle and responds at the commit stage | the same: an `AmoFill` pass through the bank pipe, then an `AmoRsp` replay that responds at the pipe head; the table entry stays held until then | | self-invalidate | tag-store `invalidate` | the probe invalidates the addressed sector on a hit | | a dirty copy at the probe | cannot occur — levels above the LLC are write-through | the probe writes it back first | | age ordering | registered MSHR probes | the probe is deferred in `processInputs` while the line has a pending fill | diff --git a/sim/simx/mem/cache.cpp b/sim/simx/mem/cache.cpp index ab6eddf9a7..af6fccf42b 100644 --- a/sim/simx/mem/cache.cpp +++ b/sim/simx/mem/cache.cpp @@ -21,6 +21,7 @@ #endif #include #include +#include #include #include #include @@ -438,7 +439,9 @@ struct bank_req_t { Core = 3, AmoProbe = 4, // non-LLC AMO passthrough: probe-and-invalidate then forward Park = 5, // chain head parked on a partial sector: issues its refetch - AmoWb = 6 // an LLC atomic's result written back through the pipe + AmoWb = 6, // an LLC atomic's result written back through the pipe + AmoFill = 7, // a non-LLC atomic's response crossing the pipe as a fill; installs nothing + AmoRsp = 8 // a non-LLC atomic replayed behind its fill; responds at the pipe head }; uint64_t addr; @@ -484,6 +487,13 @@ struct bank_req_t { // coalesced at admission). uint64_t adm_seq; + // A store-bearing LLC atomic holding core admission from its S0 (the RTL's + // commit_busy): a core request whose sector is resident, or a replay. + bool amo_held; + // An LLC atomic between its S0 and the compute stage, counted against the + // writeback queue's room (the RTL's amo_pipe_cnt). + bool amo_inpipe; + // AMO state. memop_is_atomic(op) classifies the request; the LSU // packs rs2 into data at byte_off, so the cache extracts rhs via // amo_load_word and width via byteen popcount. @@ -511,6 +521,8 @@ struct bank_req_t { amo_cmp = 0; flags = MemFlags{}; adm_seq = 0; + amo_held = false; + amo_inpipe = false; } friend std::ostream &operator<<(std::ostream &os, const bank_req_t &req) { @@ -553,8 +565,9 @@ struct mshr_entry_t { class MSHR { public: - MSHR(uint32_t size) - : entries_(size), ready_reqs_(0), size_(0) {} + // amo_ordered: the LLC, where no request links behind a pending atomic + MSHR(uint32_t size, bool amo_ordered) + : entries_(size), ready_reqs_(0), size_(0), amo_ordered_(amo_ordered) {} uint32_t capacity() const { return entries_.size(); @@ -577,6 +590,27 @@ class MSHR { return (ready_reqs_ != 0); } + // Whether any entry holds an atomic. + bool has_amo() const { + for (const auto &entry : entries_) { + if (entry.bank_req.type != bank_req_t::None && memop_is_atomic(entry.bank_req.op)) { + return true; + } + } + return false; + } + + // Whether an entry holding an atomic is pending on the line (any sector). + bool has_amo_on_line(uint32_t set_id, uint64_t addr_tag) const { + for (const auto &entry : entries_) { + if (entry.bank_req.type != bank_req_t::None && memop_is_atomic(entry.bank_req.op) + && entry.set_id == set_id && entry.addr_tag == addr_tag) { + return true; + } + } + return false; + } + const mshr_entry_t &peek(uint32_t id) const { return entries_.at(id); } @@ -637,6 +671,8 @@ class MSHR { int enqueue(const bank_req_t &bank_req, uint32_t set_id, uint64_t addr_tag, uint32_t sector_id, bool refetch = false) { assert(bank_req.type == bank_req_t::Core); + // the bank defers every request to a line while an atomic to it waits here + assert(!(amo_ordered_ && this->has_amo_on_line(set_id, addr_tag)) && "request linked behind a pending AMO"); for (uint32_t i = 0, n = entries_.size(); i < n; ++i) { auto &entry = entries_.at(i); if (entry.bank_req.type == bank_req_t::None) { @@ -652,7 +688,11 @@ class MSHR { return i; } } - std::abort(); // no free slot found! + // Invariant (release builds too): admission reserves an MSHR entry for every + // request it lets into the pipe, replays riding it included + // (mshr_occupancy_), so a miss always finds a free entry here. + VX_ASSERT(false, "MSHR admission invariant violated: enqueue found all " + << entries_.size() << " entries taken (size " << size_ << ")"); return -1; } @@ -765,6 +805,7 @@ class MSHR { std::vector entries_; uint32_t ready_reqs_; uint32_t size_; + bool amo_ordered_; }; class CacheBank : public SimObject { @@ -802,7 +843,7 @@ class CacheBank : public SimObject { const Cache::Config &config, const params_t ¶ms, uint32_t bank_id) - : SimObject(ctx, name), core_req_in(this, 2), core_rsp_out(this), mem_req_out(this), mem_rsp_in(this, config.mshr_size + AMO_PASSTHRU_CAP), config_(config), params_(params), bank_id_(bank_id), mem_req_delay_(mem_req_delay(config)), sets_(params.sets_per_bank, set_t(params.lines_per_set, params.sectors_per_line)), mshr_(config.mshr_size), pipe_req_(this, std::max(2u, config.latency)), lazy_q_(this, lazyq_size(config)), rand_ctr_(0), adm_seq_ctr_(0) + : SimObject(ctx, name), core_req_in(this, 2), core_rsp_out(this), mem_req_out(this), mem_rsp_in(this, config.mshr_size + AMO_PASSTHRU_CAP), config_(config), params_(params), bank_id_(bank_id), mem_req_delay_(mem_req_delay(config)), sets_(params.sets_per_bank, set_t(params.lines_per_set, params.sectors_per_line)), mshr_(config.mshr_size, config.is_llc), pipe_req_(this, std::max(2u, config.latency)), lazy_q_(this, lazyq_size(config)), rand_ctr_(0), adm_seq_ctr_(0) #if VX_CFG_EXT_A_ENABLED , amo_unit_(__MAX(2u, (uint32_t)VX_CFG_AMO_RS_SIZE)) #endif @@ -873,7 +914,7 @@ class CacheBank : public SimObject { // latency), or an atomic's write-back due. bool busy() const { return mshr_.has_ready_reqs() || fwd_active_ || flushing_ || token_flushing_ - || pending_fill_reqs_ != 0 || amo_wb_pending_; + || pending_fill_reqs_ != 0 || !amo_wbq_.empty() || !amo_rsp_q_.empty(); } void on_reset() { @@ -909,9 +950,14 @@ class CacheBank : public SimObject { chain_sector_ = 0; refetch_hold_ = false; refetch_hold_retry_ = false; - amo_busy_ = false; - amo_wb_pending_ = false; - amo_wb_tick_ = 0; + amo_held_ = 0; + amo_inpipe_ = 0; + amo_wbq_.clear(); + amo_rsp_q_.clear(); + core_admits_ = 0; + core_probe_seen_ = UINT64_MAX; + core_fresh_ = false; + amo_alloc_cycle_ = UINT64_MAX - 2; flushing_ = false; flush_set_idx_ = 0; flush_way_idx_ = 0; @@ -986,6 +1032,13 @@ class CacheBank : public SimObject { // // At most one input fires per tick. All inputs flow through pipe_req_. void processInputs(bool fwd_consumed) { +#if VX_CFG_EXT_A_ENABLED + // The input head's first cycle there (the RTL's fresh_r). + core_fresh_ = !this->core_req_in.empty() && core_probe_seen_ != core_admits_; + if (!this->core_req_in.empty()) { + core_probe_seen_ = core_admits_; + } +#endif // A refetch fill learns whether its sector is still resident at its tag // lookup, the tick after it enters: nothing enters behind it meanwhile, // and its chain then replays, or parks again if the sector was evicted. @@ -1007,6 +1060,22 @@ class CacheBank : public SimObject { return; } +#if VX_CFG_EXT_A_ENABLED + // A passthrough atomic whose response just crossed the pipe as a fill + // replays behind it, like a chain woken by its fill, and answers its + // requester from the pipe head. + if (!amo_rsp_q_.empty() && !fwd_consumed) { + bank_req_t rsp_req; + rsp_req.reset(); + rsp_req.type = bank_req_t::AmoRsp; + rsp_req.mshr_id = amo_rsp_q_.front(); + pipe_req_.push(rsp_req, config_.latency); + amo_rsp_q_.pop_front(); + DT(3, this->name() << " amo-passthru-replay: pid=" << rsp_req.mshr_id); + return; + } +#endif + // 1) replay: one chain entry leaves per tick — when the fill-forward // drain completed the head this tick, this slot goes to new core // requests instead @@ -1028,6 +1097,11 @@ class CacheBank : public SimObject { } bank_req_t bank_req; mshr_.dequeue(&bank_req); +#if VX_CFG_EXT_A_ENABLED + bank_req.amo_held = false; + bank_req.amo_inpipe = false; + this->amo_hold(bank_req, true); +#endif pipe_req_.push(bank_req, config_.latency); DT(3, this->name() << " replay-deq: " << bank_req); return; @@ -1043,11 +1117,17 @@ class CacheBank : public SimObject { bool fill_held = false; uint32_t held_set_id = 0; uint64_t held_addr_tag = 0; - if (!this->mem_rsp_in.empty() && !fwd_active_) { +#if VX_CFG_EXT_A_ENABLED + const bool wbq_full = this->amo_wbq_full(); +#else + const bool wbq_full = false; +#endif + if (!this->mem_rsp_in.empty() && !fwd_active_ && !wbq_full) { auto &mem_rsp = this->mem_rsp_in.peek(); #if VX_CFG_EXT_A_ENABLED - // Non-LLC AMO passthrough response: forward straight to core - // without filling. The original tag was rewritten to + // Non-LLC AMO passthrough response: it takes the fill slot and + // crosses the pipe installing nothing; its entry then replays to + // answer the requester. The original tag was rewritten to // (mshr_capacity + pid) when the bank emitted the request from // the AmoProbe handler — that namespace partition survives // arbiter tag mangling. @@ -1056,14 +1136,15 @@ class CacheBank : public SimObject { uint32_t pid = mem_rsp.tag - amo_passthru_tag_base(); auto &e = amo_passthru_.at(pid); assert(e.valid && "AMO passthru response without entry"); - if (this->core_rsp_out.full()) { - return; // stall - } - MemRsp core_rsp{e.req_tag, e.cid, e.uuid}; - core_rsp.data = mem_rsp.data; - this->core_rsp_out.send(core_rsp); - DT(3, this->name() << " amo-passthru-rsp: " << core_rsp); - e.valid = false; + e.data = mem_rsp.data; + bank_req_t fill_req; + fill_req.reset(); + fill_req.type = bank_req_t::AmoFill; + fill_req.mshr_id = pid; + pipe_req_.push(fill_req, config_.latency); + assert(amo_rsp_q_.size() < AMO_PASSTHRU_CAP); + amo_rsp_q_.push_back(pid); + DT(3, this->name() << " amo-passthru-fill: pid=" << pid); this->mem_rsp_in.pop(); --pending_fill_reqs_; return; @@ -1112,7 +1193,7 @@ class CacheBank : public SimObject { --pending_fill_reqs_; return; } - } else if (!lazy_q_.empty() && !fwd_active_) { + } else if (!lazy_q_.empty() && !fwd_active_ && !wbq_full) { // A data-less fill through the same path, below memory fills in // priority: the allocation of a write-miss root, or the refetch of a // sector every store has covered. @@ -1154,14 +1235,14 @@ class CacheBank : public SimObject { #if VX_CFG_EXT_A_ENABLED // An LLC atomic's result goes back into the line as a synthetic write - // through the core-request slot, one compute cycle after its commit. - if (amo_wb_pending_ && SimPlatform::instance().cycles() >= amo_wb_tick_) { + // through the core-request slot, one compute cycle after its commit, the + // writeback queue's oldest entry first. + if (!amo_wbq_.empty() && SimPlatform::instance().cycles() >= amo_wbq_.front().ready) { bank_req_t wb_req; wb_req.reset(); wb_req.type = bank_req_t::AmoWb; pipe_req_.push(wb_req, config_.latency); - amo_wb_pending_ = false; - amo_busy_ = false; + amo_wbq_.pop_front(); return; } #endif @@ -1169,9 +1250,10 @@ class CacheBank : public SimObject { // 3) core request if (!this->core_req_in.empty()) { #if VX_CFG_EXT_A_ENABLED - // A store-bearing atomic holds new core requests off from its lookup - // until its result is written back. - if (amo_busy_) { + // A store-bearing atomic that hit holds new core requests off from its + // lookup until its result is written back; the ordering guard defers a + // request behind an atomic the MSHR holds. + if (amo_held_ != 0 || !amo_wbq_.empty() || this->amo_input_defer(this->core_req_in.peek().addr)) { return; } #endif @@ -1304,6 +1386,9 @@ class CacheBank : public SimObject { ++perf_stats_.read_misses; } this->core_req_in.pop(); +#if VX_CFG_EXT_A_ENABLED + ++core_admits_; +#endif return; } } @@ -1328,6 +1413,15 @@ class CacheBank : public SimObject { bank_req.byteen = core_req.byteen; bank_req.amo_cmp = core_req.amo_cmp; bank_req.flags = core_req.flags; +#if VX_CFG_EXT_A_ENABLED + { + const bool resident = this->sector_resident(core_req.addr); + this->amo_hold(bank_req, resident); + if (config_.is_llc && memop_is_atomic(core_req.op) && !resident) { + amo_alloc_cycle_ = SimPlatform::instance().cycles(); + } + } +#endif pipe_req_.push(bank_req, config_.latency); DT(3, this->name() << " core-req: " << core_req); // pending_mshr_size_ tracks Core-typed in-flight requests so the @@ -1341,13 +1435,13 @@ class CacheBank : public SimObject { } #if VX_CFG_EXT_A_ENABLED if (is_amo_passthru) ++pending_amo_probes_; - if (is_amo && config_.is_llc && core_req.op != MemOp::AMO_LR) { - amo_busy_ = true; - } #endif if (core_req.is_write()) ++perf_stats_.writes; else ++perf_stats_.reads; this->core_req_in.pop(); +#if VX_CFG_EXT_A_ENABLED + ++core_admits_; +#endif return; } } @@ -1616,13 +1710,11 @@ class CacheBank : public SimObject { amo_unit_.invalidate(line_addr, /*except=*/hid); } - // A stored result is written back into the line through the pipe; without - // a store the commit frees the bank at once. + // A stored result is written back into the line through the pipe, from + // the writeback queue; a result for a word already queued merges into its + // entry. Without a store the commit frees the bank at once. if (do_store) { - amo_wb_pending_ = true; - amo_wb_tick_ = SimPlatform::instance().cycles() + 2; - } else { - amo_busy_ = false; + this->amo_wb_push(bank_req.addr & ~uint64_t(7)); } // Send AMO response. @@ -1708,10 +1800,27 @@ class CacheBank : public SimObject { switch (bank_req.type) { case bank_req_t::None: case bank_req_t::AmoWb: + case bank_req_t::AmoFill: pipe_req_.pop(); return; #if VX_CFG_EXT_A_ENABLED + case bank_req_t::AmoRsp: { + auto &e = amo_passthru_.at(bank_req.mshr_id); + assert(e.valid && "AMO passthru replay without entry"); + if (this->core_rsp_out.full()) { + return; // stall + } + MemRsp core_rsp{e.req_tag, e.cid, e.uuid}; + core_rsp.data = e.data; + this->core_rsp_out.send(core_rsp); + crsp_sent_ = true; + DT(3, this->name() << " amo-passthru-rsp: " << core_rsp); + e = amo_passthru_entry_t{}; + pipe_req_.pop(); + return; + } + case bank_req_t::AmoProbe: { // Non-LLC AMO passthrough. Probe the local line first so any // cached copy doesn't shadow the LLC's view: dirty line → @@ -1866,8 +1975,13 @@ class CacheBank : public SimObject { return; // stall if (mshr_.full()) return; // stall: need a slot to re-track the miss +#if VX_CFG_EXT_A_ENABLED + this->amo_release(bank_req); +#endif bank_req_t refill = bank_req; refill.type = bank_req_t::Core; + refill.amo_held = false; + refill.amo_inpipe = false; const bool refetch = (present_id != -1) && set.lines.at(present_id).sectors.at(sector_id).valid; int mshr_id = mshr_.enqueue(refill, set_id, addr_tag, sector_id, refetch); if (!fill_pending) { @@ -1888,6 +2002,7 @@ class CacheBank : public SimObject { assert(config_.is_llc && "AMO replay reached non-LLC bank"); if (!this->commitAmo(bank_req, set, hit_id, set_id)) return; // stall + this->amo_release(bank_req); if (config_.repl_policy == Cache::PLRU) set.update_lru(hit_id); pipe_req_.pop(); @@ -1991,7 +2106,7 @@ class CacheBank : public SimObject { DT(3, this->name() << " mshr-defer: " << bank_req); } --pending_mshr_size_; - this->pipeLineErase(set_id, addr_tag); + this->pipeLineErase(set_id, addr_tag, bank_req); pipe_req_.pop(); return; } @@ -2003,7 +2118,7 @@ class CacheBank : public SimObject { if (config_.repl_policy == Cache::PLRU) set.update_lru(hit_id); --pending_mshr_size_; - this->pipeLineErase(set_id, addr_tag); + this->pipeLineErase(set_id, addr_tag, bank_req); pipe_req_.pop(); return; } @@ -2140,7 +2255,7 @@ class CacheBank : public SimObject { if (config_.repl_policy == Cache::PLRU) set.update_lru(hit_id); --pending_mshr_size_; - this->pipeLineErase(set_id, addr_tag); + this->pipeLineErase(set_id, addr_tag, bank_req); pipe_req_.pop(); } break; @@ -2158,7 +2273,8 @@ class CacheBank : public SimObject { // store that must merge before its line is walked. if (pending_fill_reqs_ != 0 || pipe_req_.size() != 0 - || !mshr_.empty()) { + || !mshr_.empty() + || !amo_rsp_q_.empty()) { return; } while (flush_set_idx_ < params_.sets_per_bank) { @@ -2209,7 +2325,8 @@ class CacheBank : public SimObject { if (pending_fill_reqs_ != 0 || this->core_req_in.size() != 0 || pipe_req_.size() != 0 - || !mshr_.empty()) { + || !mshr_.empty() + || !amo_rsp_q_.empty()) { return; } if (token_flush_skip_) { @@ -2287,7 +2404,12 @@ class CacheBank : public SimObject { } // The pipe is in order, so the oldest match is the request leaving it. - void pipeLineErase(uint32_t set_id, uint64_t addr_tag) { + void pipeLineErase(uint32_t set_id, uint64_t addr_tag, const bank_req_t& bank_req) { +#if VX_CFG_EXT_A_ENABLED + this->amo_release(bank_req); +#else + __unused(bank_req); +#endif for (auto it = pipe_core_lines_.begin(); it != pipe_core_lines_.end(); ++it) { if (it->set_id == set_id && it->addr_tag == addr_tag) { pipe_core_lines_.erase(it); @@ -2352,9 +2474,113 @@ class CacheBank : public SimObject { uint32_t chain_sector_; bool refetch_hold_; // a refetch fill is at its tag lookup: its chain waits bool refetch_hold_retry_; - bool amo_busy_; // a store-bearing LLC atomic holds core requests off - bool amo_wb_pending_; // its result still has to be written back - uint64_t amo_wb_tick_; // ... from this cycle on + uint32_t amo_held_; // store-bearing LLC atomics holding core requests off + uint32_t amo_inpipe_; // LLC atomics between S0 and the compute stage + // The writeback queue (VX_cache_amo's WBQ): results still to be written + // back, each draining through the core-request slot from `ready` on. + static constexpr uint32_t AMO_WBQ_SIZE = 4; // the RTL's cap for an LLC line + struct amo_wb_entry_t { + uint64_t word; // the 8-byte word + uint64_t ready; // first cycle its drain may take a slot + }; + std::deque amo_wbq_; + // Passthrough-table entries whose response has crossed the pipe as a fill + // and now waits for its replay, oldest first (at most AMO_PASSTHRU_CAP). + std::deque amo_rsp_q_; + // The RTL's same-line ordering guard (req_input_defer) reads a registered + // MSHR probe: in its first cycle at the input a request waits on any atomic + // the MSHR holds, and every request waits while an atomic that misses + // allocates its entry (its S0 and S1 cycles, and the one after, before the + // registered probe shows the entry). Same-line ordering itself is + // the MSHR chain join. + uint64_t core_admits_; // core requests taken off the input + uint64_t core_probe_seen_; // core_admits_ when the head was first seen there + bool core_fresh_; // this cycle is the head's first at the input + uint64_t amo_alloc_cycle_; // admission cycle of the last atomic that misses + +#if VX_CFG_EXT_A_ENABLED + // The RTL's commit_busy holds core admission from the S0 of a store-bearing + // atomic that hits -- a core request whose sector is resident at its lookup, + // or a replay -- until its writeback has re-entered the bank. An atomic that + // misses holds nothing until its replay. Replays themselves are never held. + static bool amo_holds_commit(MemOp op) { + return memop_is_atomic(op) && op != MemOp::AMO_LR; + } + + // Called as an atomic enters the pipe (a core request or a replay); `hit` + // is the S0 tag lookup's prediction. + void amo_hold(bank_req_t& bank_req, bool hit) { + if (!config_.is_llc || !memop_is_atomic(bank_req.op)) { + return; + } + bank_req.amo_inpipe = true; + ++amo_inpipe_; + if (hit && amo_holds_commit(bank_req.op)) { + bank_req.amo_held = true; + ++amo_held_; + } + } + + // Called as an atomic leaves the pipe: committed, or into the MSHR. + void amo_release(const bank_req_t& bank_req) { + if (bank_req.amo_inpipe) { + assert(amo_inpipe_ != 0); + --amo_inpipe_; + } + if (bank_req.amo_held) { + assert(amo_held_ != 0); + --amo_held_; + } + } + + void amo_wb_push(uint64_t word) { + for (const auto& e : amo_wbq_) { + if (e.word == word) { + return; + } + } + assert(amo_wbq_.size() < AMO_WBQ_SIZE); + amo_wbq_.push_back({word, SimPlatform::instance().cycles() + 2}); + } + + bool amo_input_defer(uint64_t addr) const { + if (!config_.is_llc) { + return false; + } + const uint64_t now = SimPlatform::instance().cycles(); + // S0, S1, and the cycle after S1, whose registered MSHR probe cannot + // yet show the entry S1 finalized (the RTL's persist_amo_r) + if (now >= amo_alloc_cycle_ + 1 && now <= amo_alloc_cycle_ + 3) { + return true; + } + // a head still waiting: an atomic pending on its line (the RTL's + // registered probe); a fresh head: an atomic pending anywhere + if (core_fresh_) { + return mshr_.has_amo(); + } + return mshr_.has_amo_on_line(params_.addr_set_id(addr), params_.addr_tag(addr)); + } + + // A fill starts a replay chain that may carry an atomic, so it waits until + // the writeback queue has room for every atomic already in the pipe and one + // more (the RTL's wbq_full); the queue drains meanwhile. + bool amo_wbq_full() const { + return config_.is_llc && (amo_wbq_.size() + amo_inpipe_ + 1) >= AMO_WBQ_SIZE; + } + + // The S0 tag lookup: whether the sector holding `addr` is resident. + bool sector_resident(uint64_t addr) const { + const auto& set = sets_.at(params_.addr_set_id(addr)); + const uint64_t tag = params_.addr_tag(addr); + const uint32_t sector = params_.addr_sector_id(addr); + for (const auto& line : set.lines) { + if (line.tag == tag && sector_hit(line.sectors.at(sector), true)) { + return true; + } + } + return false; + } +#endif #ifdef DBG_MEM_BANK0_WDELAY uint64_t dbg_mem_req_free_ = 0; // the memory queue's next free departure cycle #endif @@ -2376,7 +2602,8 @@ class CacheBank : public SimObject { // Non-LLC AMO passthrough table. When config_.is_llc==false, AMOs // probe-and-invalidate the local line, forward the MemReq downstream, - // and route the response straight to core_rsp_out without a fill. + // and answer the core from a replay behind the response's fill-slot pass, + // installing nothing. An entry stays valid until that replay responds. // Tag namespace is partitioned: fill responses use [0, mshr_capacity), // passthru responses use [mshr_capacity, mshr_capacity + AMO_PASSTHRU_CAP). // Arbiters add bits at the LSB, preserving the partition across the round-trip. @@ -2385,6 +2612,7 @@ class CacheBank : public SimObject { uint64_t req_tag = 0; uint32_t cid = 0; uint64_t uuid = 0; + std::shared_ptr data; // the downstream response, held for the replay }; std::array amo_passthru_; uint32_t amo_passthru_tag_base() const { return mshr_.capacity(); } diff --git a/tests/regression/amo/common.h b/tests/regression/amo/common.h index 99ce852ade..578b9e36a7 100644 --- a/tests/regression/amo/common.h +++ b/tests/regression/amo/common.h @@ -17,6 +17,20 @@ // swap uses is ever zero. #define CAS_COUNTER_BASE 0x5a000000u +// amoadd_scatter: AMO_SCATTER_LINES lines past the per-hart region, more than +// a dcache holds, so most atomics miss. +#define AMO_SCATTER_LINES 1024u +static inline uint32_t amo_scatter_line(uint32_t h, uint32_t i, uint32_t n) { + return (i * n + h * 7u) % AMO_SCATTER_LINES; +} + +// amo_line_burst: in the same region, each group of AMO_BURST_HARTS harts +// adds into one line per iteration, each hart its own word. +#define AMO_BURST_HARTS 16u +static inline uint32_t amo_burst_line(uint32_t i, uint32_t g) { + return (i * 37u + g * 101u + 11u) % AMO_SCATTER_LINES; +} + // Initial word of the local-memory swap chain in the AMO op sweep. #define AMO_OPS_SWAP_INIT 0x5EED5EEDu diff --git a/tests/regression/amo/kernel.cpp b/tests/regression/amo/kernel.cpp index 84caa87e25..c461a2d75b 100644 --- a/tests/regression/amo/kernel.cpp +++ b/tests/regression/amo/kernel.cpp @@ -523,6 +523,33 @@ void kernel_cas_counter_lmem(kernel_arg_t* __UNIFORM__ arg) { #endif +// Scattered atomics: each hart adds into a line of a region larger than the +// dcache, most of them missing. +void kernel_amoadd_scatter(kernel_arg_t* __UNIFORM__ arg) { + auto lines = (uint32_t*)(arg->shared_addr + (uint64_t)arg->num_harts * 64); + const uint32_t hid = hart_id(); + for (uint32_t i = 0; i < arg->iters; ++i) { + __atomic_fetch_add(&lines[amo_scatter_line(hid, i, arg->num_harts) * 16], 1u, + __ATOMIC_RELAXED); + } +} + +// Atomics bursting into cold lines: each group of AMO_BURST_HARTS harts adds +// into one line per iteration, each hart its own word. The atomics that miss +// wait in the line's MSHR entry and replay back to back on its fill, each a +// store-bearing atomic to a distinct word, while other groups' fills arrive +// between them: a stream into the LLC's writeback queue that its drain has to +// keep up with. +void kernel_amo_line_burst(kernel_arg_t* __UNIFORM__ arg) { + auto lines = (uint32_t*)(arg->shared_addr + (uint64_t)arg->num_harts * 64); + const uint32_t hid = hart_id(); + for (uint32_t i = 0; i < arg->iters; ++i) { + __atomic_fetch_add(&lines[amo_burst_line(i, hid / AMO_BURST_HARTS) * 16 + (hid % AMO_BURST_HARTS)], + 1u, __ATOMIC_RELAXED); + } +} + + static const PFN_Kernel sc_tests[] = { kernel_amoadd, // 0 kernel_amoor, // 1 @@ -546,6 +573,8 @@ static const PFN_Kernel sc_tests[] = { kernel_cas_counter, // 18 compare-and-swap increment, nonzero comparands kernel_cas_counter_lmem, // 19 the same on local memory (LMEM banks) #endif + kernel_amoadd_scatter, // atomics spread over more lines than the dcache holds + kernel_amo_line_burst, // atomics to distinct words of cold lines, in bursts }; __kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) { diff --git a/tests/regression/amo/main.cpp b/tests/regression/amo/main.cpp index 7b7d49a306..1d71cdea82 100644 --- a/tests/regression/amo/main.cpp +++ b/tests/regression/amo/main.cpp @@ -89,7 +89,8 @@ int main(int argc, char *argv[]) { // AMOs stay on one bank). self_consistency uses one private 64B line // per hart (shared + hart_id*64) to test issuer self-consistency // WITHOUT false sharing. Size to the larger of the two needs. - const size_t shared_bytes = (size_t)num_harts * 64; + // plus room for the scattered and bursting atomics' lines + const size_t shared_bytes = (size_t)num_harts * 64 + (size_t)AMO_SCATTER_LINES * 64; const size_t per_hart_bytes = num_harts * sizeof(uint32_t); RT_CHECK(vx_buffer_create(device, shared_bytes, VX_MEM_READ_WRITE, &shared_buffer)); diff --git a/tests/regression/amo/testcases.h b/tests/regression/amo/testcases.h index 08b1e38cc1..505644037a 100644 --- a/tests/regression/amo/testcases.h +++ b/tests/regression/amo/testcases.h @@ -558,6 +558,59 @@ class Test_CAS_COUNTER_LMEM : public ITestCase { }; +class Test_AMOADD_SCATTER : public ITestCase { +public: + Test_AMOADD_SCATTER(TestSuite* s) : ITestCase(s, "amoadd_scatter") {} + void setup(uint32_t n, uint32_t* shared, uint32_t*) override { + for (uint32_t l = 0; l < AMO_SCATTER_LINES; ++l) { + shared[n * 16 + l * 16] = 0; + } + } + int verify(uint32_t n, uint32_t iters, const uint32_t* shared, const uint32_t*) override { + std::vector want(AMO_SCATTER_LINES, 0); + for (uint32_t h = 0; h < n; ++h) { + for (uint32_t i = 0; i < iters; ++i) { + ++want[amo_scatter_line(h, i, n)]; + } + } + int errors = 0; + for (uint32_t l = 0; l < AMO_SCATTER_LINES; ++l) { + if (shared[n * 16 + l * 16] != want[l] && errors++ < 4) { + std::cout << " line " << l << "=" << shared[n * 16 + l * 16] + << " expected=" << want[l] << std::endl; + } + } + return errors; + } +}; + +// Each word of the burst lines counts the atomics its harts made. +class Test_AMO_LINE_BURST : public ITestCase { +public: + Test_AMO_LINE_BURST(TestSuite* s) : ITestCase(s, "amo_line_burst") {} + void setup(uint32_t n, uint32_t* shared, uint32_t*) override { + for (uint32_t w = 0; w < AMO_SCATTER_LINES * 16; ++w) { + shared[n * 16 + w] = 0; + } + } + int verify(uint32_t n, uint32_t iters, const uint32_t* shared, const uint32_t*) override { + std::vector want(AMO_SCATTER_LINES * 16, 0); + for (uint32_t i = 0; i < iters; ++i) { + for (uint32_t h = 0; h < n; ++h) { + ++want[amo_burst_line(i, h / AMO_BURST_HARTS) * 16 + (h % AMO_BURST_HARTS)]; + } + } + int errors = 0; + for (uint32_t w = 0; w < AMO_SCATTER_LINES * 16; ++w) { + if (shared[n * 16 + w] != want[w] && errors++ < 4) { + std::cout << " line " << (w / 16) << " word " << (w % 16) << "=" << shared[n * 16 + w] + << " expected=" << want[w] << std::endl; + } + } + return errors; + } +}; + inline TestSuite::TestSuite(vx_device_h device) : device_(device) { // Test_ATOMIC_CRITICAL needs to know VX_CFG_NUM_THREADS to compute the // expected count; query it from the device caps. @@ -589,6 +642,8 @@ inline TestSuite::TestSuite(vx_device_h device) : device_(device) { add_test(new Test_CAS_COUNTER(this)); add_test(new Test_CAS_COUNTER_LMEM(this)); #endif + add_test(new Test_AMOADD_SCATTER(this)); + add_test(new Test_AMO_LINE_BURST(this)); } inline TestSuite::~TestSuite() { From 1d14afb4cb70757b15a93bfce7003686d4db7a31 Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 30 Nov 2026 19:06:14 -0800 Subject: [PATCH 08/12] cache: a write-back bank admits against an exact bound of the writebacks it can still owe (#557 follow-ups) #557 (a write-back bank takes every fill; each pending fill reserves its writeback room in the memory request queue) has two defects: - It caps reads in flight below the MSHR: every pending fill reserves SEC beats, dirty victim or not. core:sgemv-nt16 (rtlsim, perf_gate) goes from 285,869 to 292,363 cycles (+2.27%, same 66,704 instructions). - Its range assert "resv <= MREQ_QUEUE_SIZE + SEC" is a proxy, not an invariant: a 4-core write-back L2 with two sectors per line fires it ("memory request reservation out of range: 19"), first seen in msgpass on xrtsim x64. The bank keeps the reservation and adds an exact bound on the writebacks the queue may still have to take: its occupancy, the evicted dirty sectors not yet queued, the tag store's dirty sectors (VX_cache_tags reports the dirty-store transitions), the writes not yet among them, and the requests in the pipe. Work is held only while both are over their limits. The reservation count is kept as count + last write pop, so the memory side's ready loads one register and the cache DUT's logic depth returns to master's (Beacon cache 13 -> 13 levels). Logic depth in the whole GPU (accepted, user decision 2026-12-01): in gpu32_full's write-back L2 the bank's new resv_alm_full_r sits at 17 levels and pop_r/any_pop_r at 14. Registering the credit would cost an admission cycle on the read stream that sgemv-nt16 measures; the whole-GPU deepest path is unchanged at 29 levels. Per logic_gate entry (CI's v3.0.3 Beacon 4060e3af4; accepted, user decision 2026-12-01): VX_cache_tags' dirty-sector buffers g_dirty ex279/ex280 are new at 12 levels (the fix threshold) in cache, vm, gfx and gfxvm; each entry's deepest path is unchanged (cache 16, vm 21, gfx/gfxvm 19). A registered report would cost a cycle of latency on the dirty-sector count the bound reads. Branch commits: 7ef6630c8, 2fa55dc15, 1eba6cca7. Trigger test: cache:wb_drain-l2-1 (rtlsim, 4 cores, 16 KB L2, two sectors per line). It asserts at cycle 23,289 (x32) / 13,961 (x64) without this change. perf_gate core:sgemv-nt16 rtlsim: 292,363 -> 285,869 cycles. Co-Authored-By: Claude Opus 5.5 --- ci/testcases/cache.yaml | 16 +++ hw/rtl/cache/VX_cache_bank.sv | 233 +++++++++++++++++++++++++++++----- hw/rtl/cache/VX_cache_tags.sv | 54 ++++++++ 3 files changed, 273 insertions(+), 30 deletions(-) diff --git a/ci/testcases/cache.yaml b/ci/testcases/cache.yaml index 5e28875115..e3f48c9006 100644 --- a/ci/testcases/cache.yaml +++ b/ci/testcases/cache.yaml @@ -386,6 +386,22 @@ tests: shape: warps: 32 threads: 32 +# The same stream from four cores into a 16 KB write-back L2 with two sectors +# per line: most fills evict a dirty victim, and a fill that starts a lazy +# chain writes its victim back while the chain holds its reservation. The +# bank's queue room must cover every writeback it has committed to. +- id: wb_drain-l2-1 + via: blackbox + drivers: + - rtlsim + app: wb_drain + configs: -DVX_CFG_L2_SIZE=16384 + args: -n32 + shape: + cores: 4 + warps: 4 + threads: 4 + l2cache: true # Both sectors of one sectored L2 line miss together from different warps and # cores: each must get its own fill, never chain behind the other sector's. - id: sector_merge-1 diff --git a/hw/rtl/cache/VX_cache_bank.sv b/hw/rtl/cache/VX_cache_bank.sv index 9618f78c86..7d94a40561 100644 --- a/hw/rtl/cache/VX_cache_bank.sv +++ b/hw/rtl/cache/VX_cache_bank.sv @@ -472,7 +472,14 @@ module VX_cache_bank import VX_gpu_pkg::*; #( wire init_fire = init_valid; wire replay_fire = replay_valid && replay_ready; wire mem_rsp_fire = mem_rsp_valid && mem_rsp_ready; - wire lazy_fire = lazy_sel && mem_rsp_ready; + // The lazy queue's pop in an LLC without atomics: its fill ready from the + // stall-free grant (the STALL_FREE_GRANTS form, equal without a stall), so + // pipe_stall enters the pop once, at its last gate. An LLC with atomics + // already has that form in mem_rsp_ready. + wire replay_mux_sf = replay_valid && ~fwd_head_ns && ~replay_link_hold_ns; + wire mem_rsp_ready_sf = replay_grant && ~replay_mux_sf && ~fwd_pending && ~replay_link_hold_ns && ~amo_wbq_full + && ~refetch_inflight && ~replay_block; + wire lazy_fire = lazy_sel && (STALL_FREE_GRANTS ? mem_rsp_ready : (mem_rsp_ready_sf && ~pipe_stall)); wire fill_fire = (mem_rsp_valid || lazyq_valid) && mem_rsp_ready; wire park_fire = replay_fire && park_sel; wire flush_fire = flush_valid && flush_ready; @@ -616,6 +623,7 @@ module VX_cache_bank import VX_gpu_pkg::*; #( `UNUSED_VAR (evict_valid_st0) wire [`CS_SECTORS_PER_LINE-1:0] evict_dirty_mask_st0; wire [`CS_TAG_SEL_BITS-1:0] evict_tag_st0; + wire [NUM_WAYS*`CS_SECTORS_PER_LINE-1:0] dirty_set_st1, dirty_clr_wb_st1, dirty_clr_nwb_st1; // A fill into a line that is already resident (a sector refill) must target // the resident way, not a fresh victim, so the new sector lands in the same @@ -727,6 +735,9 @@ module VX_cache_bank import VX_gpu_pkg::*; #( .evict_valid (evict_valid_st0), .evict_dirty_mask (evict_dirty_mask_st0), .evict_tag (evict_tag_st0), + .dirty_set (dirty_set_st1), + .dirty_clr_wb (dirty_clr_wb_st1), + .dirty_clr_nwb (dirty_clr_nwb_st1), .partial_match (partial_match_st0) ); @@ -1605,8 +1616,9 @@ module VX_cache_bank import VX_gpu_pkg::*; #( // fill request on a read/write miss (one sector); multi-beat writeback // on a dirty eviction. The two are mutually exclusive (a writeback is a // fill/flush commit; a fill request is a creq commit). - wire fill_req_push = (do_read_stc || do_write_stc) && ~stC.lk.is_hit && ~stC.lk.mshr_pending - && ~lazy_alloc_stc && ~refetch_loop_stc && ~write_around_stc && ~pipe_stall; + wire fill_req_push_ns = (do_read_stc || do_write_stc) && ~stC.lk.is_hit && ~stC.lk.mshr_pending + && ~lazy_alloc_stc && ~refetch_loop_stc && ~write_around_stc; + wire fill_req_push = fill_req_push_ns && ~pipe_stall; wire wa_req_push = write_around_stc && ~pipe_stall; assign mreq_queue_push = fill_req_push || wa_req_push || wb_beat_accept; assign mreq_queue_addr = is_wb_beat ? wb_mreq_addr : rd_mreq_addr; @@ -1627,16 +1639,19 @@ module VX_cache_bank import VX_gpu_pkg::*; #( // parked head's refetch takes it over: the head cannot wait for room, // since it holds off the fills that free room. if (1) begin : g_mreq_resv - localparam RESV_W = `CLOG2(MREQ_QUEUE_SIZE + SEC + 1) + 1; + // admitted against the exact bound too (below), the reservation may + // pass the queue: it covers every MSHR entry's fill and a held chain + localparam RESV_W = `CLOG2(MREQ_QUEUE_SIZE + SEC * (MSHR_SIZE + 3)) + 1; localparam RESV_LIMIT = MREQ_QUEUE_SIZE - (PIPELINE_STAGES + 1) * SEC; `STATIC_ASSERT(RESV_LIMIT >= 0, ("invalid parameter: memory request queue below the writeback reservation")) - wire root_push = fill_req_push || ((lazy_alloc_stc || refetch_loop_stc) && ~pipe_stall); reg held_r, hold_d, rel_d; + // The cycle's stC events without pipe_stall, which gates all of + // them but the writeback beat and only selects below. // a parked head's refetch is on its chain's reservation - wire fill_resv = root_push && ~park_stc; - wire fill_done = stC.req.valid && stC.req.is_fill && ~stC.req.is_passthru_fill && ~pipe_stall; - wire wr_push = wa_req_push || wb_beat_accept; - wire wr_pop = mreq_queue_pop && mem_req_rw; + wire fill_resv_ns = (fill_req_push_ns || lazy_alloc_stc || refetch_loop_stc) && ~park_stc; + wire fill_done_ns = stC.req.valid && stC.req.is_fill && ~stC.req.is_passthru_fill; + wire wr_push_ns = write_around_stc || wb_beat_accept; + wire wr_pop = mreq_queue_pop && mem_req_rw; // The chain's hold follows chain_partial (same update), less the // park that takes it when it fires (a fill may start the next @@ -1658,41 +1673,197 @@ module VX_cache_bank import VX_gpu_pkg::*; #( end end + // The count is kept as resv_r less the last cycle's write pop + // (pop_r), and its flag as the pair {with, without} that pop: + // memory's ready, which arrives last, then only loads pop_r, and + // the flag is selected by it from registers. reg [RESV_W-1:0] resv_r; - reg resv_alm_full_r; + reg pop_r, resv_af_r, resv_af_pop_r; // registered terms first, so the late stC events only select - wire [RESV_W-1:0] resv_b = resv_r + (hold_d ? RESV_W'(SEC) : RESV_W'(0)) - - (rel_d ? RESV_W'(SEC) : RESV_W'(0)); - // The next count and flag for each of the cycle's possible - // changes, so the late stC events only select. - wire [3:0] resv_ev = {fill_resv, wr_push, fill_done, wr_pop}; - wire [15:0][RESV_W-1:0] resv_by_ev; - wire [15:0] resv_af_by_ev; - for (genvar e = 0; e < 16; ++e) begin : g_resv_ev - localparam integer DELTA = (((e & 8) != 0) ? SEC : 0) + (((e & 4) != 0) ? 1 : 0) - - (((e & 2) != 0) ? SEC : 0) - (((e & 1) != 0) ? 1 : 0); + wire [RESV_W-1:0] resv_b = resv_r - RESV_W'(pop_r) + + (hold_d ? RESV_W'(SEC) : RESV_W'(0)) + - (rel_d ? RESV_W'(SEC) : RESV_W'(0)); + // the next count and its flags for each of the cycle's stC events + wire [7:0][RESV_W+1:0] resv_by_ev; + for (genvar e = 0; e < 8; ++e) begin : g_resv_ev + localparam integer DELTA = (((e & 4) != 0) ? SEC : 0) + (((e & 2) != 0) ? 1 : 0) + - (((e & 1) != 0) ? SEC : 0); localparam integer TH = RESV_LIMIT - DELTA; - assign resv_by_ev[e] = resv_b + RESV_W'(DELTA); + wire af, af_pop; if (TH < 0) begin : g_always - assign resv_af_by_ev[e] = 1'b1; + assign af = 1'b1; end else begin : g_cmp - assign resv_af_by_ev[e] = (resv_b > RESV_W'(TH)); + assign af = (resv_b > RESV_W'(TH)); + end + if (TH + 1 < 0) begin : g_always_pop + assign af_pop = 1'b1; + end else begin : g_cmp_pop + assign af_pop = (resv_b > RESV_W'(TH + 1)); + end + assign resv_by_ev[e] = {resv_b + RESV_W'(DELTA), af, af_pop}; + end + // a stall leaves only the writeback beat + wire [2:0] resv_ev = pipe_stall ? {1'b0, wb_beat_accept, 1'b0} + : {fill_resv_ns, wr_push_ns, fill_done_ns}; + + // The reservation holds every pending fill's SEC beats, dirty victim + // or not. Only a dirty sector writes back, so the queue's pushes to + // come are also bounded by: its occupancy, the evicted dirty sectors + // not yet queued, the tag store's dirty sectors, and the writes not + // yet counted among them (each dirties at most one sector); plus INC + // per request in the pipe and a parked chain's refetch. Work is held + // only while both bounds are over their limits. + // + // Every term is kept in registers a short add or compare apart. The + // queue pushes and the writes come from this cycle's stC events and + // count at once (selected, as the reservation's); the rest only + // shrinks the bound and arrives late. A write counts from its first + // commit until its dirty set reaches the dirty count: its release + // waits as long as the set's path (RELEASE_DELAY), so no sector is + // ever out of both terms. + localparam INC = (LAZY_FETCH != 0) ? 1 : 2; + localparam BOUND_LIMIT = MREQ_QUEUE_SIZE - INC * (PIPELINE_STAGES + 2) - ((LAZY_FETCH != 0) ? 1 : 0); + localparam DS = NUM_WAYS * SEC; + localparam DS_W = `CLOG2(SEC + 1); + localparam DTAG_W = `MAX(`CLOG2(`CS_LINES_PER_BANK * DS + 1) + 1, DS_W + 2); + localparam BND_W = `CLOG2(2 * MREQ_QUEUE_SIZE + MSHR_SIZE + DS + 4) + 2; + localparam DSAT = (BOUND_LIMIT < 0) ? 0 : (BOUND_LIMIT + 1); + localparam RELEASE_DELAY = 4; + + // the tags' registered transitions -> counts -> net change -> count -> saturated. + // One way's dirty bits change per cycle (the hit, fill, flush or + // invalidate way), so the ways fold by sector before the count. + wire [SEC-1:0] dset_sec, dclr_wb_sec, dclr_nwb_sec; + for (genvar s = 0; s < SEC; ++s) begin : g_dsec + wire [NUM_WAYS-1:0] set_w, clr_wb_w, clr_nwb_w; + for (genvar w = 0; w < NUM_WAYS; ++w) begin : g_way + assign set_w[w] = dirty_set_st1[w * SEC + s]; + assign clr_wb_w[w] = dirty_clr_wb_st1[w * SEC + s]; + assign clr_nwb_w[w] = dirty_clr_nwb_st1[w * SEC + s]; + end + assign dset_sec[s] = (| set_w); + assign dclr_wb_sec[s] = (| clr_wb_w); + assign dclr_nwb_sec[s] = (| clr_nwb_w); + end + wire [DS_W-1:0] dset_n, dclr_wb_n, dclr_nwb_n; + VX_popcount #(.N (SEC)) dset_cnt (.data_in (dset_sec), .data_out (dset_n)); + VX_popcount #(.N (SEC)) dclr_wb_cnt (.data_in (dclr_wb_sec), .data_out (dclr_wb_n)); + VX_popcount #(.N (SEC)) dclr_nwb_cnt (.data_in (dclr_nwb_sec), .data_out (dclr_nwb_n)); + reg [DS_W-1:0] nset_r, nwb_r, nnwb_r; + reg [DS_W+1:0] ddelta_r; // signed: sets less clears + reg [DTAG_W-1:0] dtag_r; + reg [BND_W-1:0] dsat_r; + + // the rest of the bound: occupancy + unqueued evicted dirty sectors + uncounted writes + reg any_pop_r, beat_r; + reg [RELEASE_DELAY-1:0] wrel_r; + reg [2:0][DS_W+1:0] bdelta_r; // signed, + 0/1/2: evicted dirty sectors less pops, beats, releases + reg [BND_W-1:0] bnd_r; + reg [2:0] bnd_af_r; // bound + k over its limit, k = 0..2 + reg bnd_alm_full_r; // this cycle's: the bound with its stC events, over its limit + // a write counts from its first commit; it is released by the commit that writes it + wire winc_ns = do_write_stc && ~stC.req.is_replay && ~write_around_stc; + wire wrel_ns = do_write_stc && stC.lk.is_hit; + wire bnd_push_ns = fill_req_push_ns || write_around_stc || wb_beat_accept; + // the next count for 0, 1 or 2 of this cycle's increments: one add each + wire [2:0][BND_W-1:0] bnd_k; + for (genvar k = 0; k < 3; ++k) begin : g_bnd_k + assign bnd_k[k] = bnd_r + {{(BND_W-DS_W-2){bdelta_r[k][DS_W+1]}}, bdelta_r[k]}; + end + // each count of this cycle's stC events (0..2) selects its precomputed next + // value and flag, the stall last + wire bnd_two_ns = bnd_push_ns && winc_ns; + wire bnd_one_ns = bnd_push_ns ^ winc_ns; + wire [BND_W-1:0] bnd_n_ns = bnd_two_ns ? bnd_k[2] : (bnd_one_ns ? bnd_k[1] : bnd_k[0]); + wire [BND_W-1:0] bnd_n_st = wb_beat_accept ? bnd_k[1] : bnd_k[0]; + wire bnd_af_ns = bnd_two_ns ? bnd_af_r[2] : (bnd_one_ns ? bnd_af_r[1] : bnd_af_r[0]); + wire bnd_af_st = wb_beat_accept ? bnd_af_r[1] : bnd_af_r[0]; + + always @(posedge clk) begin + if (reset) begin + resv_r <= '0; + pop_r <= 1'b0; + resv_af_r <= 1'b0; + resv_af_pop_r <= 1'b0; + nset_r <= '0; + nwb_r <= '0; + nnwb_r <= '0; + ddelta_r <= '0; + dtag_r <= '0; + dsat_r <= '0; + any_pop_r <= 1'b0; + beat_r <= 1'b0; + wrel_r <= '0; + bdelta_r <= '0; + bnd_r <= '0; + bnd_af_r <= '0; + bnd_alm_full_r <= 1'b0; + end else begin + {resv_r, resv_af_r, resv_af_pop_r} <= resv_by_ev[resv_ev]; + pop_r <= wr_pop; + // dirty count + nset_r <= dset_n; + nwb_r <= dclr_wb_n; + nnwb_r <= dclr_nwb_n; + ddelta_r <= (DS_W+2)'(nset_r) - (DS_W+2)'(nwb_r) - (DS_W+2)'(nnwb_r); + dtag_r <= dtag_r + {{(DTAG_W-DS_W-2){ddelta_r[DS_W+1]}}, ddelta_r}; + dsat_r <= (dtag_r > DTAG_W'(DSAT)) ? BND_W'(DSAT) : BND_W'(dtag_r); + // the rest of the bound + any_pop_r <= mreq_queue_pop; + beat_r <= wb_beat_accept; + wrel_r <= {wrel_r[RELEASE_DELAY-2:0], wrel_ns && ~pipe_stall}; + for (integer k = 0; k < 3; ++k) begin + bdelta_r[k] <= (DS_W+2)'(nwb_r) - (DS_W+2)'(any_pop_r) - (DS_W+2)'(beat_r) - (DS_W+2)'(wrel_r[RELEASE_DELAY-1]) + (DS_W+2)'(k); + end + bnd_r <= pipe_stall ? bnd_n_st : bnd_n_ns; + bnd_alm_full_r <= pipe_stall ? bnd_af_st : bnd_af_ns; + for (integer k = 0; k < 3; ++k) begin + bnd_af_r[k] <= (BOUND_LIMIT < 0) || ((bnd_r + dsat_r + BND_W'(k)) > BND_W'(BOUND_LIMIT < 0 ? 0 : BOUND_LIMIT)); + end end end - wire [RESV_W-1:0] resv_n = resv_by_ev[resv_ev]; + // both bounds over their limits; the registers' select, as before + assign mreq_resv_alm_full = bnd_alm_full_r && (pop_r ? resv_af_pop_r : resv_af_r); + + `ifndef SYNTHESIS + // Exact counts of the bound's terms: the queue's occupancy, the + // evicted dirty sectors not yet queued, the tag store's dirty sectors + // (the tags check that count against the store itself) and the + // writes still out of it. + integer q_cnt, wbp_cnt, dtag_cnt, wpend_cnt; + integer dtag_hist [2]; always @(posedge clk) begin if (reset) begin - resv_r <= '0; - resv_alm_full_r <= 1'b0; + q_cnt <= 0; + wbp_cnt <= 0; + dtag_cnt <= 0; + wpend_cnt <= 0; + for (integer i = 0; i < 2; ++i) dtag_hist[i] <= 0; end else begin - resv_r <= resv_n; - resv_alm_full_r <= resv_af_by_ev[resv_ev]; + q_cnt <= q_cnt + (mreq_queue_push ? 1 : 0) - (mreq_queue_pop ? 1 : 0); + wbp_cnt <= wbp_cnt + $countones(dirty_clr_wb_st1) - (wb_beat_accept ? 1 : 0); + dtag_cnt <= dtag_cnt + $countones(dirty_set_st1) - $countones(dirty_clr_wb_st1) - $countones(dirty_clr_nwb_st1); + wpend_cnt <= wpend_cnt + ((winc_ns && ~pipe_stall) ? 1 : 0) - ((wrel_ns && ~pipe_stall) ? 1 : 0); + dtag_hist[0] <= dtag_cnt; + dtag_hist[1] <= dtag_hist[0]; end end - assign mreq_resv_alm_full = resv_alm_full_r; + // the queue holds every evicted dirty sector's beat: a fill's + // writeback never waits on memory + `RUNTIME_ASSERT ((q_cnt + wbp_cnt) <= MREQ_QUEUE_SIZE, ("%t: %s memory request queue cannot hold the pending writebacks: queued=%0d, unqueued beats=%0d", $time, INSTANCE_ID, q_cnt, wbp_cnt)) + `RUNTIME_ASSERT (~(is_wb_beat && mreq_queue_full), ("%t: %s writeback beat waits for queue room", $time, INSTANCE_ID)) + `RUNTIME_ASSERT ((wbp_cnt >= 0) && (wpend_cnt >= 0), ("%t: %s bound term below zero: unqueued beats=%0d, pending writes=%0d", $time, INSTANCE_ID, wbp_cnt, wpend_cnt)) + // the counter is the tag store's count, two registers late + `RUNTIME_ASSERT (32'(dtag_r) == dtag_hist[1], ("%t: %s dirty-sector counter %0d disagrees with the tag store's %0d", $time, INSTANCE_ID, dtag_r, dtag_hist[1])) + `RUNTIME_ASSERT (32'(bnd_r) < (1 << (BND_W - 1)), ("%t: %s bound register out of range: %0d", $time, INSTANCE_ID, bnd_r)) + `RUNTIME_ASSERT ((LAZY_FETCH == 0) || pipe_stall || ~(bnd_push_ns && winc_ns), ("%t: %s request pushes and pends a write", $time, INSTANCE_ID)) + `RUNTIME_ASSERT (($countones(dirty_set_st1) == $countones(dset_sec)) && ($countones(dirty_clr_wb_st1) == $countones(dclr_wb_sec)) + && ($countones(dirty_clr_nwb_st1) == $countones(dclr_nwb_sec)), ("%t: %s dirty bits of two ways changed in one cycle", $time, INSTANCE_ID)) + `endif + // a hold is counted before the fill it moves releases, so the // count may lead the reservations by one chain's SEC - `RUNTIME_ASSERT (resv_r <= RESV_W'(MREQ_QUEUE_SIZE + SEC), ("%t: %s memory request reservation out of range: %0d", $time, INSTANCE_ID, resv_r)) + `RUNTIME_ASSERT ((resv_r - RESV_W'(pop_r)) <= RESV_W'(MREQ_QUEUE_SIZE + SEC * (MSHR_SIZE + 3) - 1), ("%t: %s memory request reservation out of range: %0d", $time, INSTANCE_ID, resv_r - RESV_W'(pop_r))) `RUNTIME_ASSERT (~(mreq_queue_push && mreq_queue_full), ("%t: %s memory request queue overflow", $time, INSTANCE_ID)) `RUNTIME_ASSERT (~(park_fire && ~held_r), ("%t: %s parked head without its chain's reservation", $time, INSTANCE_ID)) `RUNTIME_ASSERT (~(park_fire && part_we), ("%t: %s park with a fill or a refetch hold", $time, INSTANCE_ID)) @@ -1741,11 +1912,13 @@ module VX_cache_bank import VX_gpu_pkg::*; #( assign mreq_queue_byteen = (stC.req.rw || is_amo_fwd_st1) ? sec_byteen : {SECTOR_SIZE{1'b1}}; // no fill writes back: the occupancy alone bounds the queue assign mreq_resv_alm_full = mreq_queue_alm_full; + `UNUSED_VAR ({dirty_set_st1, dirty_clr_wb_st1, dirty_clr_nwb_st1}) `UNUSED_VAR ({is_wb_beat, wb_beat_accept, wb_mreq_addr, wb_data_sec, wb_byteen_sec, wb_sector, evict_addr_stc, stC.lk.evict_tag, stC.lk.is_dirty, stC.lk.evict_dirty_mask, write_around_stc}) end end else begin : g_mreq_queue_ro assign mreq_queue_push = (do_read_stc && ~stC.lk.is_hit && ~stC.lk.mshr_pending) && ~pipe_stall; assign mreq_resv_alm_full = mreq_queue_alm_full; + `UNUSED_VAR ({dirty_set_st1, dirty_clr_wb_st1, dirty_clr_nwb_st1}) assign mreq_queue_addr = rd_mreq_addr; assign mreq_queue_rw = 0; assign mreq_queue_data = '0; diff --git a/hw/rtl/cache/VX_cache_tags.sv b/hw/rtl/cache/VX_cache_tags.sv index 27a7e2f6ab..dc84394ec5 100644 --- a/hw/rtl/cache/VX_cache_tags.sv +++ b/hw/rtl/cache/VX_cache_tags.sv @@ -86,6 +86,12 @@ module VX_cache_tags import VX_gpu_pkg::*; #( output wire [`CS_TAG_SEL_BITS-1:0] evict_tag, // the evict way holds a valid sector output wire evict_valid, + // last cycle's dirty-store transitions, per way and sector: sectors set, + // sectors cleared by an evicting fill or a flush (written back), and + // sectors cleared otherwise (a refill's or an invalidate's own sector) + output wire [NUM_WAYS*`CS_SECTORS_PER_LINE-1:0] dirty_set, + output wire [NUM_WAYS*`CS_SECTORS_PER_LINE-1:0] dirty_clr_wb, + output wire [NUM_WAYS*`CS_SECTORS_PER_LINE-1:0] dirty_clr_nwb, // the requested sector is resident but partial (a load/AMO to it refetches) output wire partial_match ); @@ -101,6 +107,7 @@ module VX_cache_tags import VX_gpu_pkg::*; #( wire [NUM_WAYS-1:0][SEC-1:0] read_dirty; wire [NUM_WAYS-1:0][SEC-1:0] read_partial; wire [NUM_WAYS-1:0] partial_hit; + wire [NUM_WAYS*SEC-1:0] dirty_set_c, dirty_clr_wb_c, dirty_clr_nwb_c; assign evict_valid = (| read_valid[evict_way]); @@ -273,11 +280,23 @@ module VX_cache_tags import VX_gpu_pkg::*; #( `BUFFER_EX(rdw_dclr, (same_set ? dclr_oh : {SEC{1'b0}}), ~stall, SEC, 1); `BUFFER_EX(rdw_dclr_all, same_set && dclr_all, ~stall, 1, 1); assign read_dirty[i] = (dirty_rdata[i] & ~rdw_dclr & ~{SEC{rdw_dclr_all}}) | rdw_dset; + + // Transitions against the exact current bits; init rewrites an + // undefined store and is not one. + wire [SEC-1:0] d_we = init ? {SEC{1'b0}} : dirty_wren[i]; + wire [SEC-1:0] d_clr = d_we & ~dirty_wdata[i] & read_dirty[i]; + wire wb_clr = do_flush || (do_fill && ~fill_refill); + assign dirty_set_c[i*SEC +: SEC] = d_we & dirty_wdata[i] & ~read_dirty[i]; + assign dirty_clr_wb_c[i*SEC +: SEC] = wb_clr ? d_clr : {SEC{1'b0}}; + assign dirty_clr_nwb_c[i*SEC +: SEC] = wb_clr ? {SEC{1'b0}} : d_clr; end else begin : g_no_dirty `UNUSED_VAR (do_write) assign dirty_wren[i] = '0; assign dirty_wdata[i] = '0; assign read_dirty[i] = {SEC{1'b0}}; + assign dirty_set_c[i*SEC +: SEC] = '0; + assign dirty_clr_wb_c[i*SEC +: SEC] = '0; + assign dirty_clr_nwb_c[i*SEC +: SEC] = '0; end if (LAZY_FETCH != 0) begin : g_partial @@ -378,11 +397,46 @@ module VX_cache_tags import VX_gpu_pkg::*; #( .wdata (dirty_wdata), .rdata (dirty_rdata) ); + `ifndef SYNTHESIS + // The transition outputs, accumulated, equal the store's dirty count: + // a mirror of the store gives the count from its own contents. + reg [NUM_WAYS*SEC-1:0] dirty_shadow [`CS_LINES_PER_BANK]; + integer dirty_shadow_cnt, dirty_delta_cnt; + always @(posedge clk) begin + if (reset) begin + for (integer l = 0; l < `CS_LINES_PER_BANK; ++l) begin + dirty_shadow[l] <= '0; + end + dirty_shadow_cnt <= 0; + dirty_delta_cnt <= 0; + end else begin + if (dirty_write) begin + dirty_shadow[line_idx] <= (dirty_shadow[line_idx] & ~dirty_wren) | (dirty_wdata & dirty_wren); + dirty_shadow_cnt <= dirty_shadow_cnt + $countones((dirty_shadow[line_idx] & ~dirty_wren) | (dirty_wdata & dirty_wren)) + - $countones(dirty_shadow[line_idx]); + end + dirty_delta_cnt <= dirty_delta_cnt + $countones(dirty_set_c) - $countones(dirty_clr_wb_c) - $countones(dirty_clr_nwb_c); + end + end + `RUNTIME_ASSERT (reset || (dirty_delta_cnt == dirty_shadow_cnt), ("%t: dirty-sector count %0d disagrees with the dirty store's %0d", $time, dirty_delta_cnt, dirty_shadow_cnt)) + `endif end else begin : g_no_dirty_store assign dirty_rdata = '0; `UNUSED_VAR ({dirty_wren, dirty_wdata, dirty_rdata, dirty_write}) end + // The transitions leave registered: they come off the tag compare. + VX_pipe_register #( + .DATAW (3 * NUM_WAYS * SEC), + .RESETW (3 * NUM_WAYS * SEC) + ) dirty_trans ( + .clk (clk), + .reset (reset), + .enable (1'b1), + .data_in ({dirty_set_c, dirty_clr_wb_c, dirty_clr_nwb_c}), + .data_out ({dirty_set, dirty_clr_wb, dirty_clr_nwb}) + ); + if (LAZY_FETCH != 0) begin : g_partial_store VX_dp_ram #( .DATAW (NUM_WAYS * SEC), From af4414785e75c0f259afe5188ec38c916be9b6ee Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Tue, 1 Dec 2026 04:52:15 -0800 Subject: [PATCH 09/12] comments: drop PR numbers and cross-layer names from the bug fixes' comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The misaligned-atomic trap, fence, barrier and LLC-atomic comments named a pull request (#481) or the other layer's internals: SimX comments named RTL modules and signals, and the barrier drain's interface comment named an operation master does not have. They now describe the behaviour only, as docs/coding_guidelines_cpp.md §10 and AGENTS.md §6 require. Comments only. Co-Authored-By: Claude Opus 5.5 --- hw/rtl/interfaces/VX_warp_ctl_if.sv | 3 +-- sim/simx/lsu_unit.cpp | 6 +++--- sim/simx/mem/cache.cpp | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/hw/rtl/interfaces/VX_warp_ctl_if.sv b/hw/rtl/interfaces/VX_warp_ctl_if.sv index 2b87365668..9449f323ca 100644 --- a/hw/rtl/interfaces/VX_warp_ctl_if.sv +++ b/hw/rtl/interfaces/VX_warp_ctl_if.sv @@ -38,8 +38,7 @@ interface VX_warp_ctl_if import VX_gpu_pkg::*; (); // Every LSU block's store path has handed its requests to the L1 and local // memory, past the last point where two blocks' requests can reorder. BAR - // and FRAG_RELEASE also wait for it, so a peer warp past the barrier, or - // the next fragment's merge, sees this warp's stores. + // waits for it, so a peer warp past the barrier sees this warp's stores. wire [`VX_CFG_NUM_LSU_BLOCKS-1:0] lsu_store_empty; // IPDOM stack address and mscratch of the warp at dvstack_wid diff --git a/sim/simx/lsu_unit.cpp b/sim/simx/lsu_unit.cpp index 87944d7232..5013fe7131 100644 --- a/sim/simx/lsu_unit.cpp +++ b/sim/simx/lsu_unit.cpp @@ -511,9 +511,9 @@ void LsuUnit::ingest_inputs(uint32_t b, bool queue_room, uint32_t reads_held) { if (input.empty()) return; // While a fence is out, nothing else of the block enters the request - // queue: the RTL's fence lock holds the block's input from the fence's - // request until its response, so a later store does not commit, and its - // warp does not move on, before the fence is answered. + // queue: the block's input is held from the fence's request until its + // response, so a later store does not commit, and its warp does not move + // on, before the fence is answered. if (state.fence.locked()) return; auto trace = input.peek(); diff --git a/sim/simx/mem/cache.cpp b/sim/simx/mem/cache.cpp index af6fccf42b..3f029992e4 100644 --- a/sim/simx/mem/cache.cpp +++ b/sim/simx/mem/cache.cpp @@ -487,11 +487,11 @@ struct bank_req_t { // coalesced at admission). uint64_t adm_seq; - // A store-bearing LLC atomic holding core admission from its S0 (the RTL's - // commit_busy): a core request whose sector is resident, or a replay. + // A store-bearing LLC atomic holding core admission from its S0: a core + // request whose sector is resident, or a replay. bool amo_held; // An LLC atomic between its S0 and the compute stage, counted against the - // writeback queue's room (the RTL's amo_pipe_cnt). + // writeback queue's room. bool amo_inpipe; // AMO state. memop_is_atomic(op) classifies the request; the LSU @@ -1033,7 +1033,7 @@ class CacheBank : public SimObject { // At most one input fires per tick. All inputs flow through pipe_req_. void processInputs(bool fwd_consumed) { #if VX_CFG_EXT_A_ENABLED - // The input head's first cycle there (the RTL's fresh_r). + // The input head's first cycle there. core_fresh_ = !this->core_req_in.empty() && core_probe_seen_ != core_admits_; if (!this->core_req_in.empty()) { core_probe_seen_ = core_admits_; @@ -2314,7 +2314,7 @@ class CacheBank : public SimObject { void processTokenFlush() { // after its last line the bank waits for the line to leave its pipeline, // then for the write-backs to leave the bank, then signals the end, a - // cycle each (the RTL flush sequencer's WAIT2 and DONE) + // cycle each if (token_flush_settle_ != 0) { if (--token_flush_settle_ == 0) { token_flushing_ = false; @@ -2476,9 +2476,9 @@ class CacheBank : public SimObject { bool refetch_hold_retry_; uint32_t amo_held_; // store-bearing LLC atomics holding core requests off uint32_t amo_inpipe_; // LLC atomics between S0 and the compute stage - // The writeback queue (VX_cache_amo's WBQ): results still to be written + // The atomic writeback queue: results still to be written // back, each draining through the core-request slot from `ready` on. - static constexpr uint32_t AMO_WBQ_SIZE = 4; // the RTL's cap for an LLC line + static constexpr uint32_t AMO_WBQ_SIZE = 4; // the hardware's cap for an LLC line struct amo_wb_entry_t { uint64_t word; // the 8-byte word uint64_t ready; // first cycle its drain may take a slot @@ -2487,7 +2487,7 @@ class CacheBank : public SimObject { // Passthrough-table entries whose response has crossed the pipe as a fill // and now waits for its replay, oldest first (at most AMO_PASSTHRU_CAP). std::deque amo_rsp_q_; - // The RTL's same-line ordering guard (req_input_defer) reads a registered + // The same-line ordering guard reads a registered // MSHR probe: in its first cycle at the input a request waits on any atomic // the MSHR holds, and every request waits while an atomic that misses // allocates its entry (its S0 and S1 cycles, and the one after, before the @@ -2499,7 +2499,7 @@ class CacheBank : public SimObject { uint64_t amo_alloc_cycle_; // admission cycle of the last atomic that misses #if VX_CFG_EXT_A_ENABLED - // The RTL's commit_busy holds core admission from the S0 of a store-bearing + // Core admission is held from the S0 of a store-bearing // atomic that hits -- a core request whose sector is resident at its lookup, // or a replay -- until its writeback has re-entered the bank. An atomic that // misses holds nothing until its replay. Replays themselves are never held. @@ -2549,12 +2549,12 @@ class CacheBank : public SimObject { } const uint64_t now = SimPlatform::instance().cycles(); // S0, S1, and the cycle after S1, whose registered MSHR probe cannot - // yet show the entry S1 finalized (the RTL's persist_amo_r) + // yet show the entry S1 finalized if (now >= amo_alloc_cycle_ + 1 && now <= amo_alloc_cycle_ + 3) { return true; } - // a head still waiting: an atomic pending on its line (the RTL's - // registered probe); a fresh head: an atomic pending anywhere + // a head still waiting: an atomic pending on its line (the registered + // probe); a fresh head: an atomic pending anywhere if (core_fresh_) { return mshr_.has_amo(); } @@ -2563,7 +2563,7 @@ class CacheBank : public SimObject { // A fill starts a replay chain that may carry an atomic, so it waits until // the writeback queue has room for every atomic already in the pipe and one - // more (the RTL's wbq_full); the queue drains meanwhile. + // more; the queue drains meanwhile. bool amo_wbq_full() const { return config_.is_llc && (amo_wbq_.size() + amo_inpipe_ + 1) >= AMO_WBQ_SIZE; } From ef88d97aa112fe4beb5b0eadc9ff1ff89c7d8601 Mon Sep 17 00:00:00 2001 From: tinebp Date: Thu, 3 Dec 2026 02:16:01 -0800 Subject: [PATCH 10/12] fixup! common: rename the __assert macro to VX_ASSERT (uses added by #574) --- sim/simx/core.cpp | 2 +- sim/simx/dxa/dxa_core.cpp | 2 +- sim/simx/raster/raster_core.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sim/simx/core.cpp b/sim/simx/core.cpp index ccfbd844c6..b224f1a6f9 100644 --- a/sim/simx/core.cpp +++ b/sim/simx/core.cpp @@ -981,7 +981,7 @@ class Core::Impl { { bool fl = uop_trace->instr_ptr->get_fu_lock(); bool ful = uop_trace->instr_ptr->get_fu_unlock(); - __assert(fl || ful || issue_lock_owner_.at(iw) == kLockOpen || issue_lock_owner_.at(iw) == w, + VX_ASSERT(fl || ful || issue_lock_owner_.at(iw) == kLockOpen || issue_lock_owner_.at(iw) == w, "continuing uop of a warp that does not hold the issue lock: " << *uop_trace); if (fl && !ful) { issue_lock_owner_.at(iw) = w; diff --git a/sim/simx/dxa/dxa_core.cpp b/sim/simx/dxa/dxa_core.cpp index bcc5d25718..09d3616c85 100644 --- a/sim/simx/dxa/dxa_core.cpp +++ b/sim/simx/dxa/dxa_core.cpp @@ -384,7 +384,7 @@ class DxaCore::Impl { w.desc = descriptors_.at(req.desc_slot); w.smem_stride = w.desc.smem_stride; uint32_t rank = desc_rank(w.desc.meta); - __assert(rank >= 1 && rank <= 5, "invalid DXA rank " << rank << " in descriptor slot " << req.desc_slot); + VX_ASSERT(rank >= 1 && rank <= 5, "invalid DXA rank " << rank << " in descriptor slot " << req.desc_slot); enumerate_work_list(w); assert(!w.work_list.empty()); diff --git a/sim/simx/raster/raster_core.cpp b/sim/simx/raster/raster_core.cpp index 9f03ec538c..97cc5d4b0d 100644 --- a/sim/simx/raster/raster_core.cpp +++ b/sim/simx/raster/raster_core.cpp @@ -1063,9 +1063,9 @@ class RasterCore::Impl { } auto &rsp = ch.peek(); uint32_t p = uint32_t(rsp.tag); - __assert((ez_state_ == EzState::ISSUE || ez_state_ == EzState::WAIT) && p < ez_pix_.size() && ez_outstanding_ != 0, + VX_ASSERT((ez_state_ == EzState::ISSUE || ez_state_ == EzState::WAIT) && p < ez_pix_.size() && ez_outstanding_ != 0, "early-Z depth response for pixel " << p << " with no read outstanding"); - __assert(rsp.data != nullptr, "early-Z depth response for pixel " << p << " carries no data"); + VX_ASSERT(rsp.data != nullptr, "early-Z depth response for pixel " << p << " carries no data"); const EzPixel &px = ez_pix_[p]; uint32_t stored; std::memcpy(&stored, rsp.data->data() + (px.addr & ~kOcacheLineMask), 4); From eb51d2790811a0cbc219c62953cf52f31e81039b Mon Sep 17 00:00:00 2001 From: tinebp Date: Thu, 3 Dec 2026 02:21:38 -0800 Subject: [PATCH 11/12] fixup! core: a workgroup barrier drains (mem_drained outside the RTU block) --- sim/simx/sfu_unit.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sim/simx/sfu_unit.h b/sim/simx/sfu_unit.h index 0ffd78c3a0..9f729c6813 100644 --- a/sim/simx/sfu_unit.h +++ b/sim/simx/sfu_unit.h @@ -144,11 +144,12 @@ class SfuUnit : public FuncUnit { void sync_out(uint32_t b); bool pe_buf_full(uint32_t b, PeClass pe); void send_out(uint32_t b, instr_trace_t* trace, uint32_t delay, PeClass pe); + // A barrier's memory drain: see SfuUnit::mem_drained in sfu_unit.cpp. + bool mem_drained(uint32_t wid) const; #ifdef VX_CFG_EXT_RTU_ENABLE // A WAIT that returns its status releases its warp through sched_unlock_out, // not at commit. void release_wait(instr_trace_t *trace); - bool mem_drained(uint32_t wid) const; // An op that streams its registers to the RTU, one per beat, holds its block // until the last beat: true while it still has an earlier beat to send. bool rtu_beats_pending(uint32_t b, const instr_trace_t *trace, uint32_t beats); From 96ded66bb1acea02eb339fe01d56a71ed421254d Mon Sep 17 00:00:00 2001 From: tinebp Date: Thu, 3 Dec 2026 02:38:35 -0800 Subject: [PATCH 12/12] ci/baselines: logic_gate and perf_gate goldens for the bug fixes Beacon (CI v3.0.3) on cache, vm, gfx and gfxvm records the write-back bank's dirty-sector buffers (g_dirty ex279/ex280) new at 12 levels, accepted on 2026-12-01; each build's deepest path is unchanged (cache 16, vm 21, gfx/gfxvm 19) and the rest of their moves are improvements. core and core_ldst pass and tensor and top_vortex improve on master's goldens, which they keep. perf_gate core:sgemv-nt16 is 285869 cycles again (292363 since #557): the exact write-back bound removes #557's +2.2%. sgemmx-nt16 +1.7%, sgemm2-fp16 -1.9% and wgmma-sparse +1.5% stay within the 2% band on master's goldens. Both recorded by the gates' own --update-baseline(s). Co-Authored-By: Claude Opus 5.5 --- ci/baselines/perf/core.json | 2 +- ci/baselines/synthesis/beacon/core.json | 46 +++++++------- ci/baselines/synthesis/beacon/graphics.json | 66 ++++++++++----------- ci/baselines/synthesis/beacon/vm.json | 31 +++++----- 4 files changed, 74 insertions(+), 71 deletions(-) diff --git a/ci/baselines/perf/core.json b/ci/baselines/perf/core.json index 5ebc6f4b9b..5fd49ae03f 100644 --- a/ci/baselines/perf/core.json +++ b/ci/baselines/perf/core.json @@ -100,7 +100,7 @@ }, "core:sgemv-nt16:rtlsim": { "32": { - "cycles": 292363, + "cycles": 285869, "instrs": 66704 }, "app": "sgemv", diff --git a/ci/baselines/synthesis/beacon/core.json b/ci/baselines/synthesis/beacon/core.json index 43e2913b0f..54edcf8a03 100644 --- a/ci/baselines/synthesis/beacon/core.json +++ b/ci/baselines/synthesis/beacon/core.json @@ -6,60 +6,62 @@ "dut": "cache", "result": { "bram": 36.0, - "build_time_s": 30, - "deep_endpoints": 1340, + "build_time_s": 15, + "deep_endpoints": 1348, "deepest_paths": [ - "16 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_0.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", - "16 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_0.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", - "16 cache/g_cache.cache/g_banks_1.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_1.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", - "16 cache/g_cache.cache/g_banks_1.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_1.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", - "16 cache/g_cache.cache/g_banks_2.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_2.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", - "16 cache/g_cache.cache/g_banks_2.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_2.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", - "16 cache/g_cache.cache/g_banks_3.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_3.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", - "16 cache/g_cache.cache/g_banks_3.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_3.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", - "15 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/g_banks_0.bank/reg_s0/g_pipe.g_partial_reset.pipe_rst.d[0]", - "15 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex187/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/g_banks_0.bank/mshr_pending_size/g_size_gt1.full_r.d[0]" + "16 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_0.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", + "16 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_0.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", + "16 cache/g_cache.cache/g_banks_1.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_1.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", + "16 cache/g_cache.cache/g_banks_1.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_1.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", + "16 cache/g_cache.cache/g_banks_2.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_2.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", + "16 cache/g_cache.cache/g_banks_2.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_2.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", + "16 cache/g_cache.cache/g_banks_3.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_3.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_in_r.d[0]", + "16 cache/g_cache.cache/g_banks_3.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/core_req_xbar/g_multi_inputs.g_multiple_outputs.g_xbar_arbs_3.xbar_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.valid_out_r.d[0]", + "15 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/g_banks_0.bank/reg_s0/g_pipe.g_partial_reset.pipe_rst.d[0]", + "15 cache/g_cache.cache/g_banks_0.bank/cache_tags/g_way_decode_3.__buffer_ex194/g_pipe.g_full_reset.pipe[3] -> cache/g_cache.cache/g_banks_0.bank/mshr_pending_size/g_size_gt1.full_r.d[0]" ], "dsp": 0, - "endpoints": 32677, + "endpoints": 32941, "env": { "beacon": "beacon 4060e3af4", "circt": "CIRCT 90c5fd313", "device": "xcu55c-fsvh2892-2L-e", "xlen": 32 }, - "ff": 33598, + "ff": 33862, "fix_levels": 12, "interfaces": {}, - "lut": 36904, + "lut": 37193, "lutram": 3333, "max_levels": 16, "pred_fmax_mhz": 288.5, - "risk_endpoints": 40, + "risk_endpoints": 72, "tied_bits": 0, "tied_ports": [], "units": { "": 11, "cache/g_cache_cache/core_req_xbar/g_multi_inputs_g_multiple_outputs_g_xbar_arbs_*_xbar_arb/g_input_select_g_arbiter_arbiter/g_round_robin_rr_arbiter": 9, "cache/g_cache_cache/core_req_xbar/g_multi_inputs_g_multiple_outputs_g_xbar_arbs_*_xbar_arb/g_input_select_g_arbiter_g_out_buf_*_out_buf/g_eb2_stream_buffer": 16, - "cache/g_cache_cache/g_banks_*_bank": 9, + "cache/g_cache_cache/g_banks_*_bank": 8, "cache/g_cache_cache/g_banks_*_bank/cache_data": 8, "cache/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 12, "cache/g_cache_cache/g_banks_*_bank/cache_flush": 14, "cache/g_cache_cache/g_banks_*_bank/cache_mshr": 11, "cache/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 9, "cache/g_cache_cache/g_banks_*_bank/cache_repl/g_enable_g_fifo_fifo_store": 9, + "cache/g_cache_cache/g_banks_*_bank/cache_tags/dirty_trans": 9, "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_dirty_store_dirty_store": 9, "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_partial_store_partial_store": 9, - "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 10, - "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex272": 12, - "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex273": 12, - "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex274": 11, + "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 10, + "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex279": 12, + "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex280": 12, + "cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex281": 11, "cache/g_cache_cache/g_banks_*_bank/cache_tags/tag_store": 9, "cache/g_cache_cache/g_banks_*_bank/cache_tags/valid_store": 9, "cache/g_cache_cache/g_banks_*_bank/core_rsp_queue/g_eb2_stream_buffer": 11, "cache/g_cache_cache/g_banks_*_bank/g_amo_amo": 15, "cache/g_cache_cache/g_banks_*_bank/g_amo_amo/g_commit_amo_unit": 9, + "cache/g_cache_cache/g_banks_*_bank/g_amo_amo/g_commit_reg_wb_self": 8, "cache/g_cache_cache/g_banks_*_bank/g_lazy_pipe_reg_lz_s0": 8, "cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue": 8, "cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue/pending_size": 9, @@ -70,7 +72,7 @@ "cache/g_cache_cache/g_banks_*_bank/reg_s1": 11 }, "uram": 0, - "watch_endpoints": 5208, + "watch_endpoints": 5618, "watch_levels": 8 } }, diff --git a/ci/baselines/synthesis/beacon/graphics.json b/ci/baselines/synthesis/beacon/graphics.json index e587036c00..d43e8f699f 100644 --- a/ci/baselines/synthesis/beacon/graphics.json +++ b/ci/baselines/synthesis/beacon/graphics.json @@ -6,7 +6,7 @@ "dut": "gfx", "result": { "bram": 183.5, - "build_time_s": 362, + "build_time_s": 130, "deep_endpoints": 1697, "deepest_paths": [ "19 g_rtu_core_0.rtu_core/scheduler/g_recip_pe.recip_tags/g_shift.g_partial_reset.pipe_free[219] -> g_rtu_core_0.rtu_core/scheduler/g1_idx.d[4]", @@ -21,17 +21,17 @@ "18 g_rtu_core_0.rtu_core/scheduler/g_recip_pe.recip_tags/g_shift.g_partial_reset.pipe_free[219] -> g_rtu_core_0.rtu_core/scheduler/ctx_arbiter/g_model1.reqs_mask.d[31]" ], "dsp": 1140, - "endpoints": 280017, + "endpoints": 280475, "env": { "beacon": "beacon 4060e3af4", "circt": "CIRCT 90c5fd313", "device": "xcu55c-fsvh2892-2L-e", "xlen": 32 }, - "ff": 355381, + "ff": 355856, "fix_levels": 12, "interfaces": {}, - "lut": 305111, + "lut": 305719, "lutram": 18012, "max_levels": 19, "pred_fmax_mhz": 271.1, @@ -122,7 +122,7 @@ "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_repl/g_enable_g_fifo_fifo_store": 8, - "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/tag_store": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/valid_store": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, @@ -131,7 +131,7 @@ "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 9, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, - "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10, "l2cache/g_cache_cache/g_banks_*_bank": 8, @@ -139,18 +139,18 @@ "l2cache/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, "l2cache/g_cache_cache/g_banks_*_bank/cache_repl/g_enable_g_fifo_fifo_store": 9, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/dirty_trans": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_dirty_store_dirty_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_partial_store_partial_store": 9, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex212": 8, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 10, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex272": 11, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex273": 12, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex274": 11, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex219": 8, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 10, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex279": 11, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex280": 12, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex281": 11, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/tag_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/valid_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/g_lazy_pipe_reg_lz_s0": 8, - "l2cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue": 8, - "l2cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue/pending_size": 9, + "l2cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue/pending_size": 8, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue": 8, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue/pending_size": 10, "l2cache/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, @@ -159,18 +159,18 @@ "l2cache/g_cache_cache/g_banks_*_bank/reg_s1": 11, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 10, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 9, - "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 10, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, - "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10 }, "uram": 0, - "watch_endpoints": 16318, + "watch_endpoints": 16484, "watch_levels": 8 } }, @@ -181,7 +181,7 @@ "dut": "gfxvm", "result": { "bram": 183.5, - "build_time_s": 337, + "build_time_s": 135, "deep_endpoints": 1848, "deepest_paths": [ "19 g_rtu_core_0.rtu_core/scheduler/g_recip_pe.recip_tags/g_shift.g_partial_reset.pipe_free[219] -> g_rtu_core_0.rtu_core/scheduler/g1_idx.d[4]", @@ -196,17 +196,17 @@ "18 g_rtu_core_0.rtu_core/scheduler/g_recip_pe.recip_tags/g_shift.g_partial_reset.pipe_free[219] -> g_rtu_core_0.rtu_core/scheduler/ctx_arbiter/g_model1.reqs_mask.d[31]" ], "dsp": 1140, - "endpoints": 294681, + "endpoints": 295139, "env": { "beacon": "beacon 4060e3af4", "circt": "CIRCT 90c5fd313", "device": "xcu55c-fsvh2892-2L-e", "xlen": 32 }, - "ff": 370237, + "ff": 370712, "fix_levels": 12, "interfaces": {}, - "lut": 316445, + "lut": 317054, "lutram": 18450, "max_levels": 19, "pred_fmax_mhz": 255.6, @@ -313,7 +313,7 @@ "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_repl/g_enable_g_fifo_fifo_store": 8, - "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/tag_store": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/valid_store": 8, "graphics/ocache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, @@ -322,27 +322,27 @@ "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 9, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, - "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10, "graphics/rcache/g_cache_wrap_*_cache_wrap/g_cache_cache/mem_req_xbar/g_fallback_xbar_switch/g_passthru_out_buf/g_eb2_stream_buffer": 8, - "l2cache/g_cache_cache/g_banks_*_bank": 9, + "l2cache/g_cache_cache/g_banks_*_bank": 8, "l2cache/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, "l2cache/g_cache_cache/g_banks_*_bank/cache_repl/g_enable_g_fifo_fifo_store": 9, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/dirty_trans": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_dirty_store_dirty_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_partial_store_partial_store": 9, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex212": 8, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 10, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex272": 11, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex273": 12, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex274": 11, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex219": 8, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 10, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex279": 11, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex280": 12, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex281": 11, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/tag_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/valid_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/g_lazy_pipe_reg_lz_s0": 8, - "l2cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue": 8, - "l2cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue/pending_size": 9, + "l2cache/g_cache_cache/g_banks_*_bank/g_lazyq_lazy_queue/pending_size": 8, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue": 8, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue/g_depth_n_dp_ram": 8, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue/pending_size": 10, @@ -352,14 +352,14 @@ "l2cache/g_cache_cache/g_banks_*_bank/reg_s1": 11, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 10, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 9, - "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10, "rtcache/g_cache_wrap_*_cache_wrap/g_cache_cache/mem_req_xbar/g_fallback_xbar_switch/g_passthru_out_buf/g_eb2_stream_buffer": 8, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 10, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, - "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10, "tcache/g_cache_wrap_*_cache_wrap/g_cache_cache/mem_req_xbar/g_fallback_xbar_switch/g_passthru_out_buf/g_eb2_stream_buffer": 8, @@ -370,7 +370,7 @@ "ummu/tlb/mshr/reqpool": 10 }, "uram": 0, - "watch_endpoints": 17682, + "watch_endpoints": 17842, "watch_levels": 8 } }, diff --git a/ci/baselines/synthesis/beacon/vm.json b/ci/baselines/synthesis/beacon/vm.json index fb1c4f6ac0..42f64039eb 100644 --- a/ci/baselines/synthesis/beacon/vm.json +++ b/ci/baselines/synthesis/beacon/vm.json @@ -6,7 +6,7 @@ "dut": "vm", "result": { "bram": 159.0, - "build_time_s": 55, + "build_time_s": 40, "deep_endpoints": 2505, "deepest_paths": [ "21 ptw/rsp_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.buffer_r[30] -> l2tlb/set_mru_r.d[2]", @@ -21,21 +21,21 @@ "21 ptw/rsp_arb/g_input_select.g_arbiter.g_out_buf_0.out_buf/g_eb2.stream_buffer/g_buffer.buffer_r[30] -> l2tlb/set_mru_r.d[19]" ], "dsp": 0, - "endpoints": 156811, + "endpoints": 157295, "env": { "beacon": "beacon 4060e3af4", "circt": "CIRCT 90c5fd313", "device": "xcu55c-fsvh2892-2L-e", "xlen": 32 }, - "ff": 150779, + "ff": 151375, "fix_levels": 12, "interfaces": {}, - "lut": 192510, + "lut": 193082, "lutram": 13996, "max_levels": 21, "pred_fmax_mhz": 251.5, - "risk_endpoints": 594, + "risk_endpoints": 585, "tied_bits": 118, "tied_ports": [ { @@ -73,7 +73,7 @@ "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_bypass_cache_bypass/mem_bus_out_arb/req_arb/g_input_select_g_arbiter_g_out_buf_*_out_buf/g_eb2_stream_buffer": 8, "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/cache_init": 10, "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 9, - "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 10, + "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 10, "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mem_req_queue": 10, "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mem_req_queue/g_depth_n_dp_ram": 10, "g_sockets_*_dcache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mem_req_queue/pending_size": 11, @@ -91,7 +91,7 @@ "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 10, "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr": 10, "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 8, - "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 8, + "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 8, "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/mshr_pending_size": 8, "g_sockets_*_g_immu_icache/g_cache_wrap_*_cache_wrap/g_cache_cache/g_banks_*_bank/reg_s1": 10, "g_sockets_*_g_immu_immu/g_lane_bus_*_req_skid": 11, @@ -101,19 +101,20 @@ "g_sockets_*_g_immu_immu/tlb/mshr/reqpool": 9, "l2cache/g_cache_cache/cache_init": 10, "l2cache/g_cache_cache/core_req_xbar/g_multi_inputs_g_multiple_outputs_g_xbar_arbs_*_xbar_arb/g_input_select_g_arbiter_g_out_buf_*_out_buf/g_eb2_stream_buffer": 15, - "l2cache/g_cache_cache/g_banks_*_bank": 11, + "l2cache/g_cache_cache/g_banks_*_bank": 8, "l2cache/g_cache_cache/g_banks_*_bank/cache_data/g_data_slice_*_data_store": 11, "l2cache/g_cache_cache/g_banks_*_bank/cache_flush": 15, "l2cache/g_cache_cache/g_banks_*_bank/cache_mshr": 11, "l2cache/g_cache_cache/g_banks_*_bank/cache_mshr/mshr_store": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_repl/g_enable_g_fifo_fifo_store": 9, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/dirty_trans": 10, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_dirty_store_dirty_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_partial_store_partial_store": 9, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex212": 8, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex228": 10, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex272": 11, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex273": 12, - "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex274": 11, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex219": 8, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*___buffer_ex235": 10, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex279": 11, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex280": 12, + "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/g_way_decode_*_g_dirty___buffer_ex281": 11, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/tag_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/cache_tags/valid_store": 9, "l2cache/g_cache_cache/g_banks_*_bank/core_rsp_queue/g_eb2_stream_buffer": 11, @@ -126,7 +127,7 @@ "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue": 11, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue/g_depth_n_dp_ram": 10, "l2cache/g_cache_cache/g_banks_*_bank/mem_req_queue/pending_size": 13, - "l2cache/g_cache_cache/g_banks_*_bank/mshr_pending_size": 17, + "l2cache/g_cache_cache/g_banks_*_bank/mshr_pending_size": 16, "l2cache/g_cache_cache/g_banks_*_bank/reg_dat": 10, "l2cache/g_cache_cache/g_banks_*_bank/reg_s0": 15, "l2cache/g_cache_cache/g_banks_*_bank/reg_s1": 12, @@ -145,7 +146,7 @@ "tlb_cluster_arb/g_arb_req_arb/g_input_select_g_arbiter_g_out_buf_*_out_buf/g_eb2_stream_buffer": 10 }, "uram": 0, - "watch_endpoints": 21671, + "watch_endpoints": 21883, "watch_levels": 8 } }