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]++;