[Mlir-commits] [mlir] [MLIR] Dump sass (PR #110227)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 27 02:44:48 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
@llvm/pr-subscribers-mlir-llvm
Author: Guray Ozen (grypp)
<details>
<summary>Changes</summary>
This PR dump sass by using nvdiasm
---
Full diff: https://github.com/llvm/llvm-project/pull/110227.diff
2 Files Affected:
- (modified) mlir/lib/Target/LLVM/NVVM/Target.cpp (+24-2)
- (modified) mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/dump-ptx.mlir (+1-1)
``````````diff
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 806c405ac17dfa..591074a436c4e0 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>
@@ -92,6 +93,7 @@ SerializeGPUModuleBase::SerializeGPUModuleBase(
// If `targetOptions` have an empty toolkitPath use `getCUDAToolkitPath`
if (toolkitPath.empty())
toolkitPath = getCUDAToolkitPath();
+ llvm::errs() << toolkitPath;
// Append the files in the target attribute.
if (ArrayAttr files = target.getLink())
@@ -401,6 +403,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();
@@ -532,8 +554,8 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
return SerializeGPUModuleBase::moduleToObject(llvmModule);
#if !LLVM_HAS_NVPTX_TARGET
- getOperation()->emitError(
- "The `NVPTX` target was not built. Please enable it when building LLVM.");
+ getOperation()->emitError("The `NVPTX` target was not built. Please enable "
+ "it when building LLVM.");
return std::nullopt;
#endif // LLVM_HAS_NVPTX_TARGET
diff --git a/mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/dump-ptx.mlir b/mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/dump-ptx.mlir
index 0cc5d8645bb364..2f7e00e927eca8 100644
--- a/mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/dump-ptx.mlir
+++ b/mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/dump-ptx.mlir
@@ -1,5 +1,5 @@
// RUN: mlir-opt %s \
-// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline -debug-only=serialize-to-isa \
+// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline -debug-only=serialize-to-isa -debug-only=dump-sass \
// RUN: 2>&1 | FileCheck %s
// CHECK: Generated by LLVM NVPTX Back-End
``````````
</details>
https://github.com/llvm/llvm-project/pull/110227
More information about the Mlir-commits
mailing list