From 5455f51f6162d13ffc32a4682fb38446cb7f8375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20F=C3=BCrst?= Date: Wed, 24 Jan 2024 03:13:14 +0100 Subject: [PATCH] properly handle more scanb than aggrj threads --- qdp_project/src/Benchmark.cpp | 58 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/qdp_project/src/Benchmark.cpp b/qdp_project/src/Benchmark.cpp index c904e90..453076b 100644 --- a/qdp_project/src/Benchmark.cpp +++ b/qdp_project/src/Benchmark.cpp @@ -72,6 +72,10 @@ constexpr size_t MASK_ELEMENT_SIZE = 16; constexpr size_t MASK_STEP_SIZE = CHUNK_SIZE_ELEMENTS / MASK_ELEMENT_SIZE; static_assert(RUN_COUNT > 0); +static_assert(TC_SCANB <= TC_AGGRJ); +static_assert(TC_AGGRJ % TC_SCANB == 0); +static_assert(WL_SIZE_B % 16 == 0); +static_assert(CHUNK_SIZE_B % 16 == 0); using filter = Filter; using aggregation = Aggregation; @@ -86,34 +90,25 @@ uint64_t* DATA_B_; uint16_t* MASK_A_; uint64_t* DATA_DST_; -template -inline uint64_t get_chunk_index(const size_t gid, const size_t tid, const size_t rid) { - /* - * Calculates Chunk Index as follows: - * group_start = (chunk_count / group_count) * gid - * thread_start = (chunk_count / (group_count * thread_count)) * tid - * run_start = (chunk_count / (group_count * thread_count * run_count)) * rid - * index = group_start + thread_start + run_start - */ - - constexpr size_t TC_x_RC = TC * RUN_COUNT; - constexpr size_t GC_x_TC_x_RC = GROUP_COUNT * TC_x_RC; - - const size_t index = (CHUNK_COUNT * (TC_x_RC * gid + RUN_COUNT * tid + rid)) / GC_x_TC_x_RC; - - return index; +inline uint64_t get_chunk_index(const size_t gid, const size_t rid) { + return gid + GROUP_COUNT * rid; } -inline uint64_t* get_chunk(uint64_t* base, const size_t chunk_index) { - return &base[chunk_index * CHUNK_SIZE_ELEMENTS]; +template +inline uint64_t* get_chunk(uint64_t* base, const size_t chunk_index, const size_t tid) { + uint64_t* chunk_ptr = base + chunk_index * CHUNK_SIZE_ELEMENTS; + return chunk_ptr + tid * (CHUNK_SIZE_ELEMENTS / TC); } -inline uint16_t* get_mask(uint16_t* base, const size_t chunk_index) { - return &base[chunk_index * MASK_STEP_SIZE]; +template +inline uint16_t* get_mask(uint16_t* base, const size_t chunk_index, const size_t tid) { + size_t offset = chunk_index * CHUNK_SIZE_ELEMENTS + tid * (CHUNK_SIZE_ELEMENTS / TC); + return base + (offset / 16); + } void scan_b(size_t gid, size_t tid) { - constexpr size_t split = RUN_COUNT / TC_SCANB; + constexpr size_t split = TC_AGGRJ / TC_SCANB; const size_t start = tid * split; const size_t end = start + split; @@ -121,13 +116,14 @@ void scan_b(size_t gid, size_t tid) { if constexpr (PERFORM_CACHING) { for (size_t i = start; i < end; i++) { - const size_t chunk_index = get_chunk_index(gid, tid, i); - uint64_t* chunk_ptr = get_chunk(DATA_B_, chunk_index); + const size_t chunk_index = get_chunk_index(gid, 0); + uint64_t* chunk_ptr = get_chunk(DATA_B_, chunk_index, i); const auto data = CACHE_.Access(reinterpret_cast(chunk_ptr), CHUNK_SIZE_B / TC_AGGRJ); - sched_yield(); - data->WaitOnCompletion(); + sched_yield(); + + data->WaitOnCompletion(); } } @@ -138,9 +134,9 @@ void scan_a(size_t gid, size_t tid) { LAUNCH_.wait(); for (size_t i = 0; i < RUN_COUNT; i++) { - const size_t chunk_index = get_chunk_index(gid, tid, i); - uint64_t* chunk_ptr = get_chunk(DATA_A_, chunk_index); - uint16_t* mask_ptr = get_mask(MASK_A_, chunk_index); + const size_t chunk_index = get_chunk_index(gid, i); + uint64_t* chunk_ptr = get_chunk(DATA_A_, chunk_index, tid); + uint16_t* mask_ptr = get_mask(MASK_A_, chunk_index, tid); filter::apply_same(mask_ptr, nullptr, chunk_ptr, CMP_A, CHUNK_SIZE_B / TC_SCANA); } @@ -156,9 +152,9 @@ void aggr_j(size_t gid, size_t tid) { BARRIERS_[gid]->arrive_and_wait(); for (size_t i = 0; i < RUN_COUNT; i++) { - const size_t chunk_index = get_chunk_index(gid, tid, i); - uint64_t* chunk_ptr = get_chunk(DATA_B_, chunk_index); - uint16_t* mask_ptr = get_mask(MASK_A_, chunk_index); + const size_t chunk_index = get_chunk_index(gid, i); + uint64_t* chunk_ptr = get_chunk(DATA_B_, chunk_index, tid); + uint16_t* mask_ptr = get_mask(MASK_A_, chunk_index, tid); std::unique_ptr data; uint64_t* data_ptr;