Skip to content

Commit 31f2eb1

Browse files
committed
Silence MLIRTargetLLVMTests failures pre-ROCm6.4
COV6 was made default in 6.4, so check that the ROCm we find isn't older before assuming the tests should pass.
1 parent d3d77f7 commit 31f2eb1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

mlir/unittests/Target/LLVM/SerializeROCDLTarget.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "llvm/IRReader/IRReader.h"
2222
#include "llvm/Support/FileSystem.h"
23+
#include "llvm/Support/MemoryBuffer.h"
2324
#include "llvm/Support/MemoryBufferRef.h"
2425
#include "llvm/Support/Path.h"
2526
#include "llvm/Support/TargetSelect.h"
@@ -52,6 +53,27 @@ class MLIRTargetLLVMROCDL : public ::testing::Test {
5253
StringRef rocmPath = ROCDL::getROCMPath();
5354
if (rocmPath.empty())
5455
return false;
56+
llvm::SmallString<128> rocmVerPath(rocmPath);
57+
llvm::sys::path::append(rocmVerPath, ".info", "version");
58+
auto bufOrErr = llvm::MemoryBuffer::getFile(rocmVerPath, /*IsText=*/true);
59+
if (!bufOrErr)
60+
return false;
61+
SmallVector<StringRef, 2> majorMinorRest;
62+
bufOrErr.get()->getBuffer().split(majorMinorRest, '.', /*MaxSplit=*/2);
63+
if (majorMinorRest.size() != 3)
64+
return false;
65+
auto asInt = [](StringRef s) -> int {
66+
unsigned i;
67+
if (s.getAsInteger(/*Radix=*/10, i))
68+
return -1;
69+
return i;
70+
};
71+
int major = asInt(majorMinorRest[0]);
72+
int minor = asInt(majorMinorRest[1]);
73+
if (major < 6)
74+
return false;
75+
if (major == 6 && minor < 4)
76+
return false;
5577
llvm::SmallString<128> lldPath(rocmPath);
5678
llvm::sys::path::append(lldPath, "llvm", "bin", "ld.lld");
5779
return llvm::sys::fs::can_execute(lldPath);
@@ -185,7 +207,7 @@ TEST_F(MLIRTargetLLVMROCDL, SKIP_WITHOUT_AMDGPU(SerializeROCDLToPTX)) {
185207
// Test ROCDL serialization to Binary.
186208
TEST_F(MLIRTargetLLVMROCDL, SKIP_WITHOUT_AMDGPU(SerializeROCDLToBinary)) {
187209
if (!hasROCMTools())
188-
GTEST_SKIP() << "ROCm installation not found, skipping test.";
210+
GTEST_SKIP() << "Compatible ROCm installation not found, skipping test.";
189211

190212
MLIRContext context(registry);
191213

@@ -212,7 +234,7 @@ TEST_F(MLIRTargetLLVMROCDL, SKIP_WITHOUT_AMDGPU(SerializeROCDLToBinary)) {
212234
// Test ROCDL metadata.
213235
TEST_F(MLIRTargetLLVMROCDL, SKIP_WITHOUT_AMDGPU(GetELFMetadata)) {
214236
if (!hasROCMTools())
215-
GTEST_SKIP() << "ROCm installation not found, skipping test.";
237+
GTEST_SKIP() << "Compatible ROCm installation not found, skipping test.";
216238

217239
MLIRContext context(registry);
218240

0 commit comments

Comments
 (0)