Skip to content

[AMDGPU] Refactor unit test. NFC #82976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2024
Merged

[AMDGPU] Refactor unit test. NFC #82976

merged 2 commits into from
Feb 26, 2024

Conversation

rovka
Copy link
Collaborator

@rovka rovka commented Feb 26, 2024

I'm about to add more tests here (downstream for now).

Change-Id: Ibd5edb398f544c90e6e8b5e49b1777a407f0594a

I'm about to add more tests here (downstream for now).

Change-Id: Ibd5edb398f544c90e6e8b5e49b1777a407f0594a
@llvmbot
Copy link
Member

llvmbot commented Feb 26, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Diana Picus (rovka)

Changes

I'm about to add more tests here (downstream for now).

Change-Id: Ibd5edb398f544c90e6e8b5e49b1777a407f0594a


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

1 Files Affected:

  • (modified) llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp (+22-13)
diff --git a/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp b/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp
index f02413376759b4..94d182b5c2ce03 100644
--- a/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp
+++ b/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp
@@ -92,9 +92,23 @@ static const std::pair<StringRef, StringRef>
   W32FS = {"+wavefrontsize32", "w32"},
   W64FS = {"+wavefrontsize64", "w64"};
 
-static void testGPRLimits(
-    const char *RegName, bool TestW32W64,
-    std::function<bool(std::stringstream &, unsigned, GCNSubtarget &)> test) {
+using TestFuncTy =
+    std::function<bool(std::stringstream &, unsigned, const GCNSubtarget &)>;
+
+static bool testAndRecord(std::stringstream &Table, const GCNSubtarget &ST,
+                          TestFuncTy test) {
+  bool Success = true;
+  unsigned MaxOcc = ST.getMaxWavesPerEU();
+  for (unsigned Occ = MaxOcc; Occ > 0; --Occ) {
+    Table << std::right << std::setw(3) << Occ << "    ";
+    Success = test(Table, Occ, ST) && Success;
+    Table << '\n';
+  }
+  return Success;
+}
+
+static void testGPRLimits(const char *RegName, bool TestW32W64,
+                          TestFuncTy test) {
   SmallVector<StringRef> CPUs;
   AMDGPU::fillValidArchListAMDGCN(CPUs);
 
@@ -117,13 +131,7 @@ static void testGPRLimits(
         FS = &W32FS;
 
       std::stringstream Table;
-      bool Success = true;
-      unsigned MaxOcc = ST.getMaxWavesPerEU();
-      for (unsigned Occ = MaxOcc; Occ > 0; --Occ) {
-        Table << std::right << std::setw(3) << Occ << "    ";
-        Success = test(Table, Occ, ST) && Success;
-        Table << '\n';
-      }
+      bool Success = testAndRecord(Table, ST, test);
       if (!Success || PrintCpuRegLimits)
         TablePerCPUs[Table.str()].push_back((CanonCPUName + FS->second).str());
 
@@ -145,13 +153,14 @@ static void testGPRLimits(
 }
 
 TEST(AMDGPU, TestVGPRLimitsPerOccupancy) {
-  testGPRLimits("VGPR", true, [](std::stringstream &OS, unsigned Occ,
-                                 GCNSubtarget &ST) {
+  auto test = [](std::stringstream &OS, unsigned Occ, const GCNSubtarget &ST) {
     unsigned MaxVGPRNum = ST.getAddressableNumVGPRs();
     return checkMinMax(
         OS, Occ, ST.getOccupancyWithNumVGPRs(MaxVGPRNum), ST.getMaxWavesPerEU(),
         [&](unsigned NumGPRs) { return ST.getOccupancyWithNumVGPRs(NumGPRs); },
         [&](unsigned Occ) { return ST.getMinNumVGPRs(Occ); },
         [&](unsigned Occ) { return ST.getMaxNumVGPRs(Occ); });
-  });
+  };
+
+  testGPRLimits("VGPR", true, test);
 }

const char *RegName, bool TestW32W64,
std::function<bool(std::stringstream &, unsigned, GCNSubtarget &)> test) {
using TestFuncTy =
std::function<bool(std::stringstream &, unsigned, const GCNSubtarget &)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

can probably be function_ref?

@rovka rovka merged commit 53697a5 into llvm:main Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants