Skip to content

[mlir] Expose MLIR_CUDA_CONVERSIONS_ENABLED in mlir-config.h. #83004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
else()
set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
endif()
# TODO: we should use a config.h file like LLVM does
add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})

# Build the ROCm conversions and run according tests if the AMDGPU backend
# is available.
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Config/mlir-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
/* If set, enables PDL usage. */
#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH

/* If set, enables CUDA-related features in CUDA-related transforms, pipelines,
and targets. */
#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS

#endif
3 changes: 2 additions & 1 deletion mlir/include/mlir/InitAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef MLIR_INITALLPASSES_H_
#define MLIR_INITALLPASSES_H_

#include "mlir/Config/mlir-config.h"
#include "mlir/Conversion/Passes.h"
#include "mlir/Dialect/AMDGPU/Transforms/Passes.h"
#include "mlir/Dialect/Affine/Passes.h"
Expand Down Expand Up @@ -96,7 +97,7 @@ inline void registerAllPasses() {
bufferization::registerBufferizationPipelines();
sparse_tensor::registerSparseTensorPipelines();
tosa::registerTosaToLinalgPipelines();
#if MLIR_CUDA_CONVERSIONS_ENABLED
#if MLIR_ENABLE_CUDA_CONVERSIONS
gpu::registerGPUToNVVMPipeline();
#endif
}
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Config/mlir-config.h"
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
Expand Down Expand Up @@ -38,7 +39,7 @@

using namespace mlir;

#if MLIR_CUDA_CONVERSIONS_ENABLED
#if MLIR_ENABLE_CUDA_CONVERSIONS
namespace {

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -127,4 +128,4 @@ void mlir::gpu::registerGPUToNVVMPipeline() {
buildLowerToNVVMPassPipeline);
}

#endif // MLIR_CUDA_CONVERSIONS_ENABLED
#endif // MLIR_ENABLE_CUDA_CONVERSIONS
3 changes: 2 additions & 1 deletion mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "mlir/Dialect/GPU/Transforms/Passes.h"

#include "mlir/Config/mlir-config.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ void GpuModuleToBinaryPass::getDependentDialects(
// Register all GPU related translations.
registry.insert<gpu::GPUDialect>();
registry.insert<LLVM::LLVMDialect>();
#if MLIR_CUDA_CONVERSIONS_ENABLED == 1
#if MLIR_ENABLE_CUDA_CONVERSIONS
registry.insert<NVVM::NVVMDialect>();
#endif
#if MLIR_ROCM_CONVERSIONS_ENABLED == 1
Expand Down
9 changes: 5 additions & 4 deletions mlir/lib/Target/LLVM/NVVM/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "mlir/Target/LLVM/NVVM/Target.h"

#include "mlir/Config/mlir-config.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/Target/LLVM/NVVM/Utils.h"
Expand Down Expand Up @@ -156,7 +157,7 @@ SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) {
return std::move(bcFiles);
}

#if MLIR_CUDA_CONVERSIONS_ENABLED == 1
#if MLIR_ENABLE_CUDA_CONVERSIONS
namespace {
class NVPTXSerializer : public SerializeGPUModuleBase {
public:
Expand Down Expand Up @@ -562,7 +563,7 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
return compileToBinary(*serializedISA);
#endif // MLIR_NVPTXCOMPILER_ENABLED == 1
}
#endif // MLIR_CUDA_CONVERSIONS_ENABLED == 1
#endif // MLIR_ENABLE_CUDA_CONVERSIONS

std::optional<SmallVector<char, 0>>
NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
Expand All @@ -574,15 +575,15 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
module->emitError("Module must be a GPU module.");
return std::nullopt;
}
#if MLIR_CUDA_CONVERSIONS_ENABLED == 1
#if MLIR_ENABLE_CUDA_CONVERSIONS
NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute), options);
serializer.init();
return serializer.run();
#else
module->emitError(
"The `NVPTX` target was not built. Please enable it when building LLVM.");
return std::nullopt;
#endif // MLIR_CUDA_CONVERSIONS_ENABLED == 1
#endif // MLIR_ENABLE_CUDA_CONVERSIONS
}

Attribute
Expand Down
7 changes: 4 additions & 3 deletions mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Config/mlir-config.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/IR/MLIRContext.h"
Expand All @@ -29,10 +30,10 @@
using namespace mlir;

// Skip the test if the NVPTX target was not built.
#if MLIR_CUDA_CONVERSIONS_ENABLED == 0
#define SKIP_WITHOUT_NVPTX(x) DISABLED_##x
#else
#if MLIR_ENABLE_CUDA_CONVERSIONS
#define SKIP_WITHOUT_NVPTX(x) x
#else
#define SKIP_WITHOUT_NVPTX(x) DISABLED_##x
#endif

class MLIRTargetLLVMNVVM : public ::testing::Test {
Expand Down
11 changes: 8 additions & 3 deletions utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# The MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load(
":build_defs.bzl",
"cc_headers_only",
Expand Down Expand Up @@ -36,7 +35,10 @@ expand_template(
"#cmakedefine01 MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS": "#define MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS 0",
"#cmakedefine MLIR_GREEDY_REWRITE_RANDOMIZER_SEED ${MLIR_GREEDY_REWRITE_RANDOMIZER_SEED}": "/* #undef MLIR_GREEDY_REWRITE_RANDOMIZER_SEED */",
"#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH": "#define MLIR_ENABLE_PDL_IN_PATTERNMATCH 1",
},
} | if_cuda_available(
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 1"},
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 0"},
),
template = "include/mlir/Config/mlir-config.h.cmake",
)

Expand Down Expand Up @@ -5468,7 +5470,6 @@ cc_library(
srcs = ["lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp"],
hdrs = ["include/mlir/Dialect/GPU/Pipelines/Passes.h"],
includes = ["include"],
local_defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
deps = [
":AffineToStandard",
":ArithToLLVM",
Expand All @@ -5492,6 +5493,7 @@ cc_library(
":Transforms",
":VectorToLLVM",
":VectorToSCF",
":config",
],
)

Expand Down Expand Up @@ -5541,6 +5543,7 @@ cc_library(
":Transforms",
":VCIXToLLVMIRTranslation",
":VectorDialect",
":config",
"//llvm:Core",
"//llvm:MC",
"//llvm:Support",
Expand Down Expand Up @@ -6176,6 +6179,7 @@ cc_library(
":NVVMToLLVMIRTranslation",
":TargetLLVM",
":ToLLVMIRTranslation",
":config",
"//llvm:NVPTXCodeGen",
"//llvm:Support",
],
Expand Down Expand Up @@ -9131,6 +9135,7 @@ cc_library(
":VectorTransforms",
":X86VectorDialect",
":X86VectorTransforms",
":config",
],
)

Expand Down
19 changes: 1 addition & 18 deletions utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ cc_library(
cc_library(
name = "TestTransforms",
srcs = glob(["lib/Transforms/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
":TestDialect",
Expand All @@ -579,7 +578,6 @@ cc_library(
cc_library(
name = "TestFuncToLLVM",
srcs = glob(["lib/Conversion/FuncToLLVM/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
":TestDialect",
Expand All @@ -594,7 +592,6 @@ cc_library(
cc_library(
name = "TestOneToNTypeConversion",
srcs = glob(["lib/Conversion/OneToNTypeConversion/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
":TestDialect",
Expand Down Expand Up @@ -653,7 +650,6 @@ cc_library(
cc_library(
name = "TestDLTI",
srcs = glob(["lib/Dialect/DLTI/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
":TestDialect",
Expand All @@ -667,7 +663,7 @@ cc_library(
cc_library(
name = "TestGPU",
srcs = glob(["lib/Dialect/GPU/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"] + if_cuda_available([
defines = if_cuda_available([
"MLIR_GPU_TO_CUBIN_PASS_ENABLE",
]),
includes = ["lib/Dialect/Test"],
Expand Down Expand Up @@ -714,7 +710,6 @@ cc_library(
cc_library(
name = "TestLinalg",
srcs = glob(["lib/Dialect/Linalg/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//llvm:Support",
Expand Down Expand Up @@ -748,7 +743,6 @@ cc_library(
cc_library(
name = "TestLLVM",
srcs = glob(["lib/Dialect/LLVM/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:AffineToStandard",
Expand All @@ -773,7 +767,6 @@ cc_library(
cc_library(
name = "TestMath",
srcs = glob(["lib/Dialect/Math/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:ArithDialect",
Expand All @@ -790,7 +783,6 @@ cc_library(
cc_library(
name = "TestMathToVCIX",
srcs = glob(["lib/Conversion/MathToVCIX/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:ArithDialect",
Expand All @@ -807,7 +799,6 @@ cc_library(
cc_library(
name = "TestMemRef",
srcs = glob(["lib/Dialect/MemRef/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
":TestDialect",
Expand Down Expand Up @@ -847,7 +838,6 @@ cc_library(
cc_library(
name = "TestNVGPU",
srcs = glob(["lib/Dialect/NVGPU/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:AffineDialect",
Expand All @@ -871,7 +861,6 @@ cc_library(
cc_library(
name = "TestSCF",
srcs = glob(["lib/Dialect/SCF/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//llvm:Support",
Expand All @@ -891,7 +880,6 @@ cc_library(
cc_library(
name = "TestArith",
srcs = glob(["lib/Dialect/Arith/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:ArithDialect",
Expand All @@ -908,7 +896,6 @@ cc_library(
cc_library(
name = "TestArmSME",
srcs = glob(["lib/Dialect/ArmSME/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:ArithToArmSME",
Expand All @@ -927,7 +914,6 @@ cc_library(
cc_library(
name = "TestBufferization",
srcs = glob(["lib/Dialect/Bufferization/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:BufferizationDialect",
Expand Down Expand Up @@ -989,7 +975,6 @@ cc_library(
cc_library(
name = "TestFunc",
srcs = glob(["lib/Dialect/Func/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
":TestDialect",
Expand All @@ -1005,7 +990,6 @@ cc_library(
cc_library(
name = "TestTensor",
srcs = glob(["lib/Dialect/Tensor/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:ArithDialect",
Expand All @@ -1022,7 +1006,6 @@ cc_library(
cc_library(
name = "TestVector",
srcs = glob(["lib/Dialect/Vector/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:AffineDialect",
Expand Down