From 5af78a7d83d4e7b6e0b02d1afc04a5f8f30baebe Mon Sep 17 00:00:00 2001 From: hanjinchi <1104722561@qq.com> Date: Mon, 9 Sep 2024 16:15:54 +0800 Subject: [PATCH 1/2] Simplify the code implementation of parallel_regression and add support for regression testing with data being void. --- util/parallel_regression.hpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/util/parallel_regression.hpp b/util/parallel_regression.hpp index cf245a5..f60ee84 100644 --- a/util/parallel_regression.hpp +++ b/util/parallel_regression.hpp @@ -53,7 +53,7 @@ class DataQueue bool check(uint64_t caddr, const CMDataBase* data){ assert(caddr == addr); std::unique_lock lk(*mtx); - if(data_deque.size() == 0) return true; + if(data_deque.size() == 0 || data->read(0) == 0) return true; for(auto d : data_deque){ if(d.read(0) == data->read(0)) return true; } @@ -72,7 +72,7 @@ class ParallelRegressionSupport template -class ParallelRegressionGen : public RegressionGen, public ParallelRegressionSupport +class ParallelRegressionGen : public RegressionGen { typedef RegressionGen ReT; protected: @@ -107,6 +107,7 @@ class ParallelRegressionGen : public RegressionGen) d.copy(data); act = cache_xact{rw, core, ic, flush, addr, d}; if(flush == 2){ // share instruction flush for(int i = 0; i < NC; i++){ @@ -141,8 +141,8 @@ class ParallelRegressionGen : public RegressionGenwrite(data); } - static void cache_producer(int test_num, ParallelRegressionSupport* pgr){ - pgr->xact_queue_add(test_num); + void cache_producer(int test_num){ + xact_queue_add(test_num); } virtual std::pair get_xact(int core){ @@ -164,10 +164,10 @@ class ParallelRegressionGen : public RegressionGen* core_inst, std::vector* core_data, bool* exit) + void cache_server(int core, std::vector* core_inst, std::vector* core_data, bool* exit) { while(true){ - auto act = prg->get_xact(core); + auto act = get_xact(core); if(*exit && !act.first) break; else if(act.first){ auto [rw, act_core, ic, flush, addr, data] = act.second; @@ -175,26 +175,26 @@ class ParallelRegressionGen : public RegressionGenflush(addr, nullptr); else (*core_inst)[core]->flush(addr, nullptr); if(rw){ - (*core_data)[core]->write(addr, &data, nullptr); - prg->write_dq(addr, &data); + if constexpr (!C_VOID
) { write_dq(addr, &data); (*core_data)[core]->write(addr, &data, nullptr); } + else (*core_data)[core]->write(addr, nullptr, nullptr); } } else if(rw){ - (*core_data)[core]->write(addr, &data, nullptr); - prg->write_dq(addr, &data); + if constexpr (!C_VOID
) { write_dq(addr, &data); (*core_data)[core]->write(addr, &data, nullptr); } + else (*core_data)[core]->write(addr, nullptr, nullptr); }else{ auto rdata = ic ? (*core_inst)[core]->read(addr, nullptr) : (*core_data)[core]->read(addr, nullptr); - prg->check(addr, rdata); + if constexpr (!C_VOID
) check(addr, rdata); } } } } void run(int test_num, std::vector* core_inst, std::vector* core_data){ - std::thread add_thread(cache_producer, test_num, this); + std::thread add_thread(&ParallelRegressionGen::cache_producer, this, test_num); std::vector server_thread; bool exit = false; for(int i = 0; i < NC; i++){ - server_thread.emplace_back(cache_server, i, this, core_inst, core_data, &exit); + server_thread.emplace_back(&ParallelRegressionGen::cache_server, this, i, core_inst, core_data, &exit); } add_thread.join(); exit = true; From 7917a6c65e65770a1561ce1cd6ae1d7d32d0d634 Mon Sep 17 00:00:00 2001 From: hanjinchi <1104722561@qq.com> Date: Mon, 9 Sep 2024 16:31:41 +0800 Subject: [PATCH 2/2] add support for regression testing with data being void --- util/regression.hpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/util/regression.hpp b/util/regression.hpp index f7c56c5..fdca2b2 100644 --- a/util/regression.hpp +++ b/util/regression.hpp @@ -28,7 +28,7 @@ class RegressionGen const unsigned int total; std::vector addr_pool; // random addresses std::unordered_map addr_map; - std::vector
data_pool; // data copy + std::vector data_pool; // data copy std::vector wflag; // whether written std::vector iflag; // belong to instruction @@ -37,7 +37,10 @@ class RegressionGen : gi(703), hasher(1201), total(NC*PAddrN+SAddrN) { addr_pool.resize(total); - data_pool.resize(total); + if constexpr (!C_VOID
) { + data_pool.resize(total); + for(auto &d:data_pool) d = new DT(); + } wflag.resize(total); iflag.resize(total); for(unsigned int i=0; i) for(auto d:data_pool) delete d; + } + unsigned int locality_scale(unsigned int num, unsigned int mod, double rate) { num %= mod; double factor = (double)(num) / mod; @@ -70,7 +77,8 @@ class RegressionGen PAddrN*NC + locality_scale(hasher(gi++), SAddrN, 0.2) : PAddrN*core + locality_scale(hasher(gi++), PAddrN, 0.2) ; uint64_t addr = addr_pool[index]; - DT *data = &(data_pool[index]); + DT *data; + if constexpr (!C_VOID
) data = data_pool[index]; auto ran_num = hasher(gi++); bool rw = 0 == (ran_num & 0x11); // 25% write int flush = TestFlush && (0 == (ran_num & 0x17)) ? 3 : 0; // 25% of write is flush @@ -88,7 +96,7 @@ class RegressionGen } if(rw) { - data->write(0, hasher(gi++), 0xffffffffffffffffull); + if constexpr (!C_VOID
) data->write(0, hasher(gi++), 0xffffffffffffffffull); wflag[index] = true; } @@ -97,9 +105,12 @@ class RegressionGen bool check(uint64_t addr, const CMDataBase *data) { assert(addr_map.count(addr)); - int index = addr_map[addr]; - assert(data_pool[index].read(0) == data->read(0)); - return data_pool[index].read(0) == data->read(0); + if constexpr (!C_VOID
) { + int index = addr_map[addr]; + assert(data_pool[index]->read(0) == data->read(0)); + return data_pool[index]->read(0) == data->read(0); + } else + return true; } bool run(uint64_t TestN, std::vector& core_inst, std::vector& core_data) {