Skip to content

Conversation

caIicate
Copy link

No description provided.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc label Mar 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 19, 2024

@llvm/pr-subscribers-libc

Author: None (caIicate)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/85812.diff

1 Files Affected:

  • (modified) libc/benchmarks/LibcMemoryBenchmark.cpp (+70)
diff --git a/libc/benchmarks/LibcMemoryBenchmark.cpp b/libc/benchmarks/LibcMemoryBenchmark.cpp
index 3ced306584d151..455680990eeebe 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmark.cpp
@@ -40,6 +40,16 @@ getOffsetDistribution(size_t BufferSize, size_t MaxSizeValue,
   return std::uniform_int_distribution<uint32_t>(0, MaxOffset);
 }
 
+class OffsetDistribution {
+public:
+  OffsetDistribution(size_t BufferSize, size_t MaxSizeValue,
+                     MaybeAlign AccessAlignment);
+
+private:
+  std::uniform_int_distribution<uint32_t> Distribution;
+  size_t Factor;
+};
+
 OffsetDistribution::OffsetDistribution(size_t BufferSize, size_t MaxSizeValue,
                                        MaybeAlign AccessAlignment)
     : Distribution(
@@ -47,6 +57,16 @@ OffsetDistribution::OffsetDistribution(size_t BufferSize, size_t MaxSizeValue,
       Factor(AccessAlignment.valueOrOne().value()) {}
 
 // Precomputes offset where to insert mismatches between the two buffers.
+class MismatchOffsetDistribution {
+public:
+  MismatchOffsetDistribution(size_t BufferSize, size_t MaxSizeValue, size_t MismatchAt);
+
+private:
+  size_t MismatchAt;
+  std::vector<size_t> MismatchIndices;
+  std::uniform_int_distribution<size_t> MismatchIndexSelector;
+};
+
 MismatchOffsetDistribution::MismatchOffsetDistribution(size_t BufferSize,
                                                        size_t MaxSizeValue,
                                                        size_t MismatchAt)
@@ -80,6 +100,18 @@ static size_t getAvailableBufferSize() {
   return getL1DataCacheSize() - L1LeftAsideBytes - ParameterStorageBytes;
 }
 
+class ParameterBatch {
+public:
+  ParameterBatch(size_t BufferCount);
+  size_t getBatchBytes() const;
+  void checkValid(const ParameterType &P) const;
+
+private:
+  size_t BufferSize;
+  size_t BatchSize;
+  std::vector<ParameterType> Parameters;
+};
+
 ParameterBatch::ParameterBatch(size_t BufferCount)
     : BufferSize(getAvailableBufferSize() / BufferCount),
       BatchSize(ParameterStorageBytes / sizeof(ParameterType)),
@@ -113,13 +145,42 @@ void ParameterBatch::checkValid(const ParameterType &P) const {
             .concat(llvm::Twine(BufferSize)));
 }
 
+class CopySetup {
+public:
+  CopySetup();
+
+private:
+  ParameterBatch ParameterBatch;
+  AlignedBuffer SrcBuffer;
+  AlignedBuffer DstBuffer;
+};
+
 CopySetup::CopySetup()
     : ParameterBatch(2), SrcBuffer(ParameterBatch::BufferSize),
       DstBuffer(ParameterBatch::BufferSize) {}
 
+class MoveSetup {
+public:
+  MoveSetup();
+
+private:
+  ParameterBatch ParameterBatch;
+  AlignedBuffer Buffer;
+};
+
 MoveSetup::MoveSetup()
     : ParameterBatch(3), Buffer(ParameterBatch::BufferSize * 3) {}
 
+class ComparisonSetup {
+public:
+  ComparisonSetup();
+
+private:
+  ParameterBatch ParameterBatch;
+  AlignedBuffer LhsBuffer;
+  AlignedBuffer RhsBuffer;
+};
+
 ComparisonSetup::ComparisonSetup()
     : ParameterBatch(2), LhsBuffer(ParameterBatch::BufferSize),
       RhsBuffer(ParameterBatch::BufferSize) {
@@ -128,6 +189,15 @@ ComparisonSetup::ComparisonSetup()
   memset(RhsBuffer.begin(), 0xF, BufferSize);
 }
 
+class SetSetup {
+public:
+  SetSetup();
+
+private:
+  ParameterBatch ParameterBatch;
+  AlignedBuffer DstBuffer;
+};
+
 SetSetup::SetSetup()
     : ParameterBatch(1), DstBuffer(ParameterBatch::BufferSize) {}
 

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 252e2551eab9b59f7dcbf8bb79a1432884d546e4 f7999cda9853944bbb77dd380bf24c575c885537 -- libc/benchmarks/LibcMemoryBenchmark.cpp
View the diff from clang-format here.
diff --git a/libc/benchmarks/LibcMemoryBenchmark.cpp b/libc/benchmarks/LibcMemoryBenchmark.cpp
index 455680990e..fcfc427f68 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmark.cpp
@@ -59,7 +59,8 @@ OffsetDistribution::OffsetDistribution(size_t BufferSize, size_t MaxSizeValue,
 // Precomputes offset where to insert mismatches between the two buffers.
 class MismatchOffsetDistribution {
 public:
-  MismatchOffsetDistribution(size_t BufferSize, size_t MaxSizeValue, size_t MismatchAt);
+  MismatchOffsetDistribution(size_t BufferSize, size_t MaxSizeValue,
+                             size_t MismatchAt);
 
 private:
   size_t MismatchAt;

@nickdesaulniers
Copy link
Member

Thanks for the patch! Please run git clang-format HEAD~ to appease the liner gods!

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are declared in libc/benchmarks/LibcMemoryBenchmark.h. There's no point redeclaring them.

@michaelrj-google
Copy link
Contributor

Closing for now since this patch seems to be abandoned. Feel free to reopen it or open a new one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants