From b512cdf0993e725b2496cdb93d02cbb4c05e3b5c Mon Sep 17 00:00:00 2001 From: FBSource/WWW Bot Date: Wed, 19 Aug 2026 12:35:47 -0700 Subject: [PATCH] DCPerf v2-beta : `Rebatch` benchmark memcpy may be optimized out with Clan Reviewed By: excelle08 Differential Revision: D116072200 --- packages/ai_wdl/rebatch/rebatchBench.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/ai_wdl/rebatch/rebatchBench.cpp b/packages/ai_wdl/rebatch/rebatchBench.cpp index 1ab25d1ae..a1143330b 100644 --- a/packages/ai_wdl/rebatch/rebatchBench.cpp +++ b/packages/ai_wdl/rebatch/rebatchBench.cpp @@ -287,8 +287,8 @@ class TensorBatch { * prevent cache effects * 3. Multi-threading - Supports configurable number of worker threads * 4. Prefetching - Optional memory prefetching for improved performance - * 5. Anti-optimization - Uses checksums to prevent compiler from optimizing - * away operations + * 5. Anti-optimization - Uses a compiler barrier to prevent the compiler from + * optimizing away the memcpy operations */ class RebatchBenchmark { public: @@ -360,9 +360,6 @@ class RebatchBenchmark { * 5. Tracks performance statistics */ void workerThread(size_t thread_id) { - // Checksum to prevent compiler from optimizing away memcpy operations - volatile uint64_t checksum = 0; - while (!stop_flag_) { // Allocate a fresh output tensor for this batch char* output = new char[OUTPUT_TENSOR_SIZE]; @@ -438,6 +435,11 @@ class RebatchBenchmark { } } + // The output buffer is never read elsewhere, so force the compiler to + // treat it as observed; otherwise the memcpy operations above can be + // elided as dead stores. + asm volatile("" : : "r,m"(output) : "memory"); + // Update statistics bytes_processed_[thread_id] += totalProcessedBytes; batches_processed_[thread_id]++;