[PATCH] D138443: [AMDGPU] Fix GCNSubtarget::getMinNumVGPRs, add unit test to check consistency between GCNSubtarget's getMinNumVGPRs, getMaxNumVGPRs and getOccupancyWithNumVGPRs.

Juan Manuel Martinez CaamaƱo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 08:14:52 PST 2022


jmmartinez added inline comments.


================
Comment at: llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp:100
+
+  std::map<std::string, SmallVector<std::string>> TablePerCPUs;
+  for (auto CPUName : CPUs) {
----------------
vpykhtin wrote:
> vpykhtin wrote:
> > vpykhtin wrote:
> > > jmmartinez wrote:
> > > > foad wrote:
> > > > > vpykhtin wrote:
> > > > > > arsenm wrote:
> > > > > > > vpykhtin wrote:
> > > > > > > > arsenm wrote:
> > > > > > > > > StringMap?
> > > > > > > > I need std::string as a key, StringMap uses StringRef but it doesn't own string data. Its not a big deal here because its only used on test fail or when printing.
> > > > > > > DenseMap
> > > > > > DenseMap doesn't work with std::string, it's not specialized for it.
> > > > > `StringMap<std:string>`?
> > > > > I need std::string as a key, StringMap uses StringRef but it doesn't own string data. Its not a big deal here because its only used on test fail or when printing.
> > > > 
> > > > @vpykhtin What do you mean that it doesn't own the string data? When creating the `StringMapEntry` (see `StringMapEntryBase::allocateWithKey`) it performs a copy of the input `StringRef` into its own internal buffer.
> > > > 
> > > > The awkward side is that you'll have to use raw_string_ostream for building the `ErrStr` as shown below (notice the call to `.first()` instead of `.first`):
> > > > 
> > > >   std::string ErrStr;
> > > >   raw_string_ostream OS(ErrStr);
> > > >   for (auto &P : TablePerCPUs) {
> > > >     for (auto &CPUName : P.second)
> > > >       OS << ' ' << CPUName;
> > > >     OS << ":\nOcc    Min" << RegName << "        Max" << RegName << '\n'
> > > >        << P.first() << '\n';
> > > >   }
> > > >   EXPECT_TRUE(ErrStr.empty()) << ErrStr;
> > > This way you specify Value type as std::string but not the key.
> > > << P.first() << '\n';
> > I don't see () in my code.
> > 
> > 
> > When creating the StringMapEntry (see StringMapEntryBase::allocateWithKey) it performs a copy of the input StringRef into its own internal buffer
> 
> Ok, but here is the final argument: strings are sorted at the map and this gives nice picture at output :)  This map is only used on error or printing, it's not used during usual llvm-check routine so there is no penalty. 
Sorry, I might have not been clear. I meant the `.first()` in my code snippet.


================
Comment at: llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp:100
+
+  std::map<std::string, SmallVector<std::string>> TablePerCPUs;
+  for (auto CPUName : CPUs) {
----------------
jmmartinez wrote:
> vpykhtin wrote:
> > vpykhtin wrote:
> > > vpykhtin wrote:
> > > > jmmartinez wrote:
> > > > > foad wrote:
> > > > > > vpykhtin wrote:
> > > > > > > arsenm wrote:
> > > > > > > > vpykhtin wrote:
> > > > > > > > > arsenm wrote:
> > > > > > > > > > StringMap?
> > > > > > > > > I need std::string as a key, StringMap uses StringRef but it doesn't own string data. Its not a big deal here because its only used on test fail or when printing.
> > > > > > > > DenseMap
> > > > > > > DenseMap doesn't work with std::string, it's not specialized for it.
> > > > > > `StringMap<std:string>`?
> > > > > > I need std::string as a key, StringMap uses StringRef but it doesn't own string data. Its not a big deal here because its only used on test fail or when printing.
> > > > > 
> > > > > @vpykhtin What do you mean that it doesn't own the string data? When creating the `StringMapEntry` (see `StringMapEntryBase::allocateWithKey`) it performs a copy of the input `StringRef` into its own internal buffer.
> > > > > 
> > > > > The awkward side is that you'll have to use raw_string_ostream for building the `ErrStr` as shown below (notice the call to `.first()` instead of `.first`):
> > > > > 
> > > > >   std::string ErrStr;
> > > > >   raw_string_ostream OS(ErrStr);
> > > > >   for (auto &P : TablePerCPUs) {
> > > > >     for (auto &CPUName : P.second)
> > > > >       OS << ' ' << CPUName;
> > > > >     OS << ":\nOcc    Min" << RegName << "        Max" << RegName << '\n'
> > > > >        << P.first() << '\n';
> > > > >   }
> > > > >   EXPECT_TRUE(ErrStr.empty()) << ErrStr;
> > > > This way you specify Value type as std::string but not the key.
> > > > << P.first() << '\n';
> > > I don't see () in my code.
> > > 
> > > 
> > > When creating the StringMapEntry (see StringMapEntryBase::allocateWithKey) it performs a copy of the input StringRef into its own internal buffer
> > 
> > Ok, but here is the final argument: strings are sorted at the map and this gives nice picture at output :)  This map is only used on error or printing, it's not used during usual llvm-check routine so there is no penalty. 
> Sorry, I might have not been clear. I meant the `.first()` in my code snippet.
Pretty-printing as an argument sounds good to me.


================
Comment at: llvm/unittests/Target/AMDGPU/CMakeLists.txt:6-9
 set(LLVM_LINK_COMPONENTS
   AMDGPUCodeGen
   AMDGPUDesc
   AMDGPUInfo
----------------
vpykhtin wrote:
> jmmartinez wrote:
> > I think `AMDGPUUtils` is missing from the list. Otherwise I get an undefined reference to `llvm::AMDGPU::IsaInfo::getMaxNumVGPRs(llvm::MCSubtargetInfo const*, unsigned int)` on my local build.
> not sure, my build is ok, I build AMDGPUTests executable. Probably should go to another patch
Are you building with `-DBUILD_SHARED_LIBS=OFF` ? If that's the case please consier reproducing the problem with `-DBUILD_SHARED_LIBS=ON` and adding the modification I suggested, to avoid breaking other peoples's builds.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138443/new/

https://reviews.llvm.org/D138443



More information about the llvm-commits mailing list