[libc-commits] [libc] 2a6d4c5 - [libc][benchmark] Fix wrong BatchSize leading to data not fitting in L1.

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Wed Nov 16 04:55:55 PST 2022


Author: Guillaume Chatelet
Date: 2022-11-16T12:55:37Z
New Revision: 2a6d4c5d8a4c445053bf45e08eaf7d53ed38fd1e

URL: https://github.com/llvm/llvm-project/commit/2a6d4c5d8a4c445053bf45e08eaf7d53ed38fd1e
DIFF: https://github.com/llvm/llvm-project/commit/2a6d4c5d8a4c445053bf45e08eaf7d53ed38fd1e.diff

LOG: [libc][benchmark] Fix wrong BatchSize leading to data not fitting in L1.

Differential Revision: https://reviews.llvm.org/D138111

Added: 
    

Modified: 
    libc/benchmarks/LibcMemoryBenchmark.cpp

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/LibcMemoryBenchmark.cpp b/libc/benchmarks/LibcMemoryBenchmark.cpp
index 50fb86ee774a6..3ced306584d15 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmark.cpp
@@ -72,18 +72,27 @@ static size_t getL1DataCacheSize() {
   report_fatal_error("Unable to read L1 Cache Data Size");
 }
 
+static constexpr int64_t KiB = 1024;
+static constexpr int64_t ParameterStorageBytes = 4 * KiB;
+static constexpr int64_t L1LeftAsideBytes = 1 * KiB;
+
 static size_t getAvailableBufferSize() {
-  static constexpr int64_t KiB = 1024;
-  static constexpr int64_t ParameterStorageBytes = 4 * KiB;
-  static constexpr int64_t L1LeftAsideBytes = 1 * KiB;
   return getL1DataCacheSize() - L1LeftAsideBytes - ParameterStorageBytes;
 }
 
 ParameterBatch::ParameterBatch(size_t BufferCount)
     : BufferSize(getAvailableBufferSize() / BufferCount),
-      BatchSize(BufferSize / sizeof(ParameterType)), Parameters(BatchSize) {
+      BatchSize(ParameterStorageBytes / sizeof(ParameterType)),
+      Parameters(BatchSize) {
   if (BufferSize <= 0 || BatchSize < 100)
     report_fatal_error("Not enough L1 cache");
+  const size_t ParameterBytes = Parameters.size() * sizeof(ParameterType);
+  const size_t BufferBytes = BufferSize * BufferCount;
+  if (ParameterBytes + BufferBytes + L1LeftAsideBytes > getL1DataCacheSize())
+    report_fatal_error(
+        "We're splitting a buffer of the size of the L1 cache between a data "
+        "buffer and a benchmark parameters buffer, so by construction the "
+        "total should not exceed the size of the L1 cache");
 }
 
 size_t ParameterBatch::getBatchBytes() const {


        


More information about the libc-commits mailing list