[Mlir-commits] [mlir] 816134b - [MLIR] Dump sass (#110227)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 27 04:52:18 PDT 2024


Author: Guray Ozen
Date: 2024-09-27T13:52:15+02:00
New Revision: 816134b3338b2cb46f4bb9e87744c67d61bf8569

URL: https://github.com/llvm/llvm-project/commit/816134b3338b2cb46f4bb9e87744c67d61bf8569
DIFF: https://github.com/llvm/llvm-project/commit/816134b3338b2cb46f4bb9e87744c67d61bf8569.diff

LOG: [MLIR] Dump sass (#110227)

This PR dump sass by using nvdiasm

Added: 
    mlir/test/Integration/GPU/CUDA/dump-sass.mlir

Modified: 
    mlir/lib/Target/LLVM/NVVM/Target.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 806c405ac17dfa..69602af8563aa0 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/raw_ostream.h"
 
 #include <cstdlib>
 
@@ -401,6 +402,26 @@ NVPTXSerializer::compileToBinary(const std::string &ptxCode) {
                                 /*MemoryLimit=*/0,
                                 /*ErrMsg=*/&message))
     return emitLogError("`ptxas`");
+#define DEBUG_TYPE "dump-sass"
+  LLVM_DEBUG({
+    std::optional<std::string> nvdisasm = findTool("nvdisasm");
+    SmallVector<StringRef> nvdisasmArgs(
+        {StringRef("nvdisasm"), StringRef(cubinFile.first)});
+    if (llvm::sys::ExecuteAndWait(nvdisasm.value(), nvdisasmArgs,
+                                  /*Env=*/std::nullopt,
+                                  /*Redirects=*/redirects,
+                                  /*SecondsToWait=*/0,
+                                  /*MemoryLimit=*/0,
+                                  /*ErrMsg=*/&message))
+      return emitLogError("`nvdisasm`");
+    llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> logBuffer =
+        llvm::MemoryBuffer::getFile(logFile->first);
+    if (logBuffer && !(*logBuffer)->getBuffer().empty()) {
+      llvm::dbgs() << "Output:\n" << (*logBuffer)->getBuffer() << "\n";
+      llvm::dbgs().flush();
+    }
+  });
+#undef DEBUG_TYPE
 
   // Invoke `fatbin`.
   message.clear();

diff  --git a/mlir/test/Integration/GPU/CUDA/dump-sass.mlir b/mlir/test/Integration/GPU/CUDA/dump-sass.mlir
new file mode 100644
index 00000000000000..d32f5efc29d58e
--- /dev/null
+++ b/mlir/test/Integration/GPU/CUDA/dump-sass.mlir
@@ -0,0 +1,18 @@
+// RUN: mlir-opt %s \
+// RUN:  | mlir-opt -gpu-lower-to-nvvm-pipeline -debug-only=dump-sass \
+// RUN:  2>&1 | FileCheck %s
+
+// CHECK: MOV
+// CHECK: STG.E 
+
+func.func @other_func(%arg0 : f32, %arg1 : memref<?xf32>) {
+  %cst = arith.constant 1 : index
+  %c0 = arith.constant 0 : index
+  %cst2 = memref.dim %arg1, %c0 : memref<?xf32>
+  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %cst, %grid_y = %cst, %grid_z = %cst)
+             threads(%tx, %ty, %tz) in (%block_x = %cst2, %block_y = %cst, %block_z = %cst) {
+    memref.store %arg0, %arg1[%tx] : memref<?xf32>
+    gpu.terminator
+  }
+  return
+}


        


More information about the Mlir-commits mailing list