[libc-commits] [PATCH] D138111: [libc][benchmark] Fix wrong BatchSize leading to data not fitting in L1.
Guillaume Chatelet via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Nov 16 03:04:54 PST 2022
gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
gchatelet requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138111
Files:
libc/benchmarks/LibcMemoryBenchmark.cpp
Index: libc/benchmarks/LibcMemoryBenchmark.cpp
===================================================================
--- libc/benchmarks/LibcMemoryBenchmark.cpp
+++ libc/benchmarks/LibcMemoryBenchmark.cpp
@@ -72,18 +72,24 @@
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("Invalid state");
}
size_t ParameterBatch::getBatchBytes() const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138111.475749.patch
Type: text/x-patch
Size: 1402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221116/bba360de/attachment.bin>
More information about the libc-commits
mailing list