[Mlir-commits] [mlir] bafe418 - [mlir] Change test-gpu-to-cubin to derive from SerializeToBlobPass

Christian Sigg llvmlistbot at llvm.org
Thu Mar 11 01:42:28 PST 2021


Author: Christian Sigg
Date: 2021-03-11T10:42:20+01:00
New Revision: bafe418d12e9aa94fc3de210b556c5452799f6b1

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

LOG: [mlir] Change test-gpu-to-cubin to derive from SerializeToBlobPass

Clean-up after D98279, remove one call to createConvertGPUKernelToBlobPass().

Depends On D98203

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D98360

Added: 
    

Modified: 
    mlir/test/Conversion/GPUToCUDA/lower-nvvm-kernel-to-cubin.mlir
    mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp
    mlir/tools/mlir-opt/mlir-opt.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/Conversion/GPUToCUDA/lower-nvvm-kernel-to-cubin.mlir b/mlir/test/Conversion/GPUToCUDA/lower-nvvm-kernel-to-cubin.mlir
index c5c92da3cac0..6b5b9f124979 100644
--- a/mlir/test/Conversion/GPUToCUDA/lower-nvvm-kernel-to-cubin.mlir
+++ b/mlir/test/Conversion/GPUToCUDA/lower-nvvm-kernel-to-cubin.mlir
@@ -1,6 +1,6 @@
-// RUN: mlir-opt %s --test-kernel-to-cubin -split-input-file | FileCheck %s
+// RUN: mlir-opt %s --test-gpu-to-cubin | FileCheck %s
 
-// CHECK: attributes {nvvm.cubin = "CUBIN"}
+// CHECK: gpu.module @foo attributes {gpu.binary = "CUBIN"}
 gpu.module @foo {
   llvm.func @kernel(%arg0 : f32, %arg1 : !llvm.ptr<f32>)
     // CHECK: attributes  {gpu.kernel}
@@ -9,8 +9,7 @@ gpu.module @foo {
   }
 }
 
-// -----
-
+// CHECK: gpu.module @bar attributes {gpu.binary = "CUBIN"}
 gpu.module @bar {
   // CHECK: func @kernel_a
   llvm.func @kernel_a()

diff  --git a/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp
index c70538e90526..3ac572096668 100644
--- a/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp
+++ b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp
@@ -6,11 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
-#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
+#include "mlir/Dialect/GPU/Passes.h"
+
 #include "mlir/Pass/Pass.h"
-#include "mlir/Pass/PassManager.h"
-#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "llvm/Support/TargetSelect.h"
@@ -18,36 +16,53 @@
 using namespace mlir;
 
 #if MLIR_CUDA_CONVERSIONS_ENABLED
-static OwnedBlob compilePtxToCubinForTesting(const std::string &, Location,
-                                             StringRef) {
-  const char data[] = "CUBIN";
-  return std::make_unique<std::vector<char>>(data, data + sizeof(data) - 1);
+namespace {
+class TestSerializeToCubinPass
+    : public PassWrapper<TestSerializeToCubinPass, gpu::SerializeToBlobPass> {
+public:
+  TestSerializeToCubinPass();
+
+private:
+  void getDependentDialects(DialectRegistry &registry) const override;
+
+  // Serializes PTX to CUBIN.
+  std::unique_ptr<std::vector<char>>
+  serializeISA(const std::string &isa) override;
+};
+} // namespace
+
+TestSerializeToCubinPass::TestSerializeToCubinPass() {
+  this->triple = "nvptx64-nvidia-cuda";
+  this->chip = "sm_35";
+  this->features = "+ptx60";
+}
+
+void TestSerializeToCubinPass::getDependentDialects(
+    DialectRegistry &registry) const {
+  registerNVVMDialectTranslation(registry);
+  gpu::SerializeToBlobPass::getDependentDialects(registry);
 }
 
-static std::unique_ptr<llvm::Module>
-translateModuleToNVVMIR(Operation *m, llvm::LLVMContext &llvmContext,
-                        StringRef moduleName) {
-  registerLLVMDialectTranslation(*m->getContext());
-  registerNVVMDialectTranslation(*m->getContext());
-  return translateModuleToLLVMIR(m, llvmContext, moduleName);
+std::unique_ptr<std::vector<char>>
+TestSerializeToCubinPass::serializeISA(const std::string &) {
+  std::string data = "CUBIN";
+  return std::make_unique<std::vector<char>>(data.begin(), data.end());
 }
 
 namespace mlir {
 namespace test {
-void registerTestConvertGPUKernelToCubinPass() {
-  PassPipelineRegistration<>(
-      "test-kernel-to-cubin",
-      "Convert all kernel functions to CUDA cubin blobs",
-      [](OpPassManager &pm) {
+// Register test pass to serialize GPU module to a CUBIN binary annotation.
+void registerTestGpuSerializeToCubinPass() {
+  PassRegistration<TestSerializeToCubinPass> registerSerializeToCubin(
+      "test-gpu-to-cubin",
+      "Lower GPU kernel function to CUBIN binary annotations", [] {
         // Initialize LLVM NVPTX backend.
         LLVMInitializeNVPTXTarget();
         LLVMInitializeNVPTXTargetInfo();
         LLVMInitializeNVPTXTargetMC();
         LLVMInitializeNVPTXAsmPrinter();
 
-        pm.addPass(createConvertGPUKernelToBlobPass(
-            translateModuleToNVVMIR, compilePtxToCubinForTesting,
-            "nvptx64-nvidia-cuda", "sm_35", "+ptx60", "nvvm.cubin"));
+        return std::make_unique<TestSerializeToCubinPass>();
       });
 }
 } // namespace test

diff  --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index 82db6ea256d7..3b00ae61f8f3 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -64,7 +64,7 @@ void registerTestAliasAnalysisPass();
 void registerTestCallGraphPass();
 void registerTestConstantFold();
 void registerTestConvVectorization();
-void registerTestConvertGPUKernelToCubinPass();
+void registerTestGpuSerializeToCubinPass();
 void registerTestConvertGPUKernelToHsacoPass();
 void registerTestDecomposeCallGraphTypes();
 void registerTestDialect(DialectRegistry &);
@@ -136,7 +136,7 @@ void registerTestPasses() {
   test::registerTestCallGraphPass();
   test::registerTestConstantFold();
 #if MLIR_CUDA_CONVERSIONS_ENABLED
-  test::registerTestConvertGPUKernelToCubinPass();
+  test::registerTestGpuSerializeToCubinPass();
 #endif
 #if MLIR_ROCM_CONVERSIONS_ENABLED
   test::registerTestConvertGPUKernelToHsacoPass();


        


More information about the Mlir-commits mailing list