From fea8faa705b43e23508bc9fef842c62929786110 Mon Sep 17 00:00:00 2001 From: Artem Belevich Date: Fri, 17 Mar 2023 13:47:46 -0700 Subject: [PATCH] Separate SerializeToCubin from GPUTransforms. SerializeToCubin depends on CUDA at *runtime* which is undesirable for MLIR's general use case, as compilation should be doable on any host, regardless of whether it has a GPU. SerializeToCubin is needed to run some GPU tests, so when we build mlir-opt, SerializeToCubin pass is linked in directly into mlir-opt. Differential Revision: https://reviews.llvm.org/D146330 --- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel | 58 +++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index 45a75fe6..143d17a 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -5,6 +5,7 @@ # Description: # The MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure +load("@bazel_skylib//rules:write_file.bzl", "write_file") load(":tblgen.bzl", "gentbl_cc_library", "td_library") load(":linalggen.bzl", "genlinalg") load( @@ -4031,6 +4032,9 @@ cc_library( "lib/Dialect/GPU/Transforms/*.cpp", "lib/Dialect/GPU/Transforms/*.h", ], + exclude = [ + "lib/Dialect/GPU/Transforms/SerializeToCubin.cpp", + ], ), hdrs = glob(["include/mlir/Dialect/GPU/Transforms/*.h"]), includes = ["include"], @@ -4050,6 +4054,7 @@ cc_library( ":ROCDLToLLVMIRTranslation", ":SCFDialect", ":FuncDialect", + ":SerializeToCubin_stub", ":SideEffectInterfaces", ":Support", ":Transforms", @@ -4060,13 +4065,59 @@ cc_library( "//llvm:Support", "//llvm:Target", ] + if_cuda_available([ - # Dependencies for SerializeToCubin.cpp with - # -DMLIR_GPU_TO_CUBIN_PASS_ENABLE ":NVVMToLLVMIRTranslation", "//llvm:NVPTXCodeGen", + ]), +) + +cc_library( + name = "SerializeToCubin", + srcs = [ + "lib/Dialect/GPU/Transforms/SerializeToCubin.cpp", + ], + local_defines = if_cuda_available(["MLIR_GPU_TO_CUBIN_PASS_ENABLE"]), + deps = [ + ":NVVMToLLVMIRTranslation", + ":ToLLVMIRTranslation", + ":GPUDialect", + ":GPUPassIncGen", + ":GPUTransforms", + ":Pass", + ":Support", + "//llvm:Support", + ] + if_cuda_available([ "@cuda//:cuda_headers", "@cuda//:libcuda", - ]), + ]) +) + +write_file( + name = "SerializeToCubin_stub_cc", + out = "SerializeToCubin_stub.cc", + content = [ +""" +#include "mlir/Dialect/GPU/Transforms/Passes.h" + +// Provide a weak registration stub in case the real SerializeToCubin is not +// linked in. + +__attribute__((weak)) void mlir::registerGpuSerializeToCubinPass() {} +""" + ] +) + +cc_library( + name = "SerializeToCubin_stub", + srcs = [":SerializeToCubin_stub_cc"], + hdrs = glob(["include/mlir/Dialect/GPU/Transforms/*.h"]), + includes = ["include"], + deps = [ + ":GPUDialect", + ":GPUPassIncGen", + ":Pass", + ":Support", + "//llvm:Support", + ], ) td_library( @@ -7061,6 +7112,7 @@ cc_binary( ":OpenMPDialect", ":Pass", ":QuantOps", + ":SerializeToCubin", ":SCFToGPU", ":Support", ":Transforms", -- 2.7.4