Skip to content

Commit 5f2097d

Browse files
[mlir] Expose MLIR_CUDA_CONVERSIONS_ENABLED in mlir-config.h. (#83004)
That macro was not defined in some cases and thus yielded warnings if compiled with `-Wundef`. In particular, they were not defined in the BUILD files, so the GPU targets were broken when built with Bazel. This commit exposes mentioned CMake variable through mlir-config.h and uses the macro that is introduced with the same name. This replaces the macro MLIR_CUDA_CONVERSIONS_ENABLED, which the CMake files previously defined manually.
1 parent a845ea3 commit 5f2097d

File tree

9 files changed

+29
-34
lines changed

9 files changed

+29
-34
lines changed

mlir/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
111111
else()
112112
set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
113113
endif()
114-
# TODO: we should use a config.h file like LLVM does
115-
add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})
116114

117115
# Build the ROCm conversions and run according tests if the AMDGPU backend
118116
# is available.

mlir/include/mlir/Config/mlir-config.h.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@
2929
/* If set, enables PDL usage. */
3030
#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH
3131

32+
/* If set, enables CUDA-related features in CUDA-related transforms, pipelines,
33+
and targets. */
34+
#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS
35+
3236
#endif

mlir/include/mlir/InitAllPasses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef MLIR_INITALLPASSES_H_
1515
#define MLIR_INITALLPASSES_H_
1616

17+
#include "mlir/Config/mlir-config.h"
1718
#include "mlir/Conversion/Passes.h"
1819
#include "mlir/Dialect/AMDGPU/Transforms/Passes.h"
1920
#include "mlir/Dialect/Affine/Passes.h"
@@ -96,7 +97,7 @@ inline void registerAllPasses() {
9697
bufferization::registerBufferizationPipelines();
9798
sparse_tensor::registerSparseTensorPipelines();
9899
tosa::registerTosaToLinalgPipelines();
99-
#if MLIR_CUDA_CONVERSIONS_ENABLED
100+
#if MLIR_ENABLE_CUDA_CONVERSIONS
100101
gpu::registerGPUToNVVMPipeline();
101102
#endif
102103
}

mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "mlir/Config/mlir-config.h"
1415
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
1516
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
1617
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
@@ -38,7 +39,7 @@
3839

3940
using namespace mlir;
4041

41-
#if MLIR_CUDA_CONVERSIONS_ENABLED
42+
#if MLIR_ENABLE_CUDA_CONVERSIONS
4243
namespace {
4344

4445
//===----------------------------------------------------------------------===//
@@ -127,4 +128,4 @@ void mlir::gpu::registerGPUToNVVMPipeline() {
127128
buildLowerToNVVMPassPipeline);
128129
}
129130

130-
#endif // MLIR_CUDA_CONVERSIONS_ENABLED
131+
#endif // MLIR_ENABLE_CUDA_CONVERSIONS

mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

16+
#include "mlir/Config/mlir-config.h"
1617
#include "mlir/Dialect/Func/IR/FuncOps.h"
1718
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1819
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -48,7 +49,7 @@ void GpuModuleToBinaryPass::getDependentDialects(
4849
// Register all GPU related translations.
4950
registry.insert<gpu::GPUDialect>();
5051
registry.insert<LLVM::LLVMDialect>();
51-
#if MLIR_CUDA_CONVERSIONS_ENABLED == 1
52+
#if MLIR_ENABLE_CUDA_CONVERSIONS
5253
registry.insert<NVVM::NVVMDialect>();
5354
#endif
5455
#if MLIR_ROCM_CONVERSIONS_ENABLED == 1

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

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

159-
#if MLIR_CUDA_CONVERSIONS_ENABLED == 1
160+
#if MLIR_ENABLE_CUDA_CONVERSIONS
160161
namespace {
161162
class NVPTXSerializer : public SerializeGPUModuleBase {
162163
public:
@@ -562,7 +563,7 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
562563
return compileToBinary(*serializedISA);
563564
#endif // MLIR_NVPTXCOMPILER_ENABLED == 1
564565
}
565-
#endif // MLIR_CUDA_CONVERSIONS_ENABLED == 1
566+
#endif // MLIR_ENABLE_CUDA_CONVERSIONS
566567

567568
std::optional<SmallVector<char, 0>>
568569
NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
@@ -574,15 +575,15 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
574575
module->emitError("Module must be a GPU module.");
575576
return std::nullopt;
576577
}
577-
#if MLIR_CUDA_CONVERSIONS_ENABLED == 1
578+
#if MLIR_ENABLE_CUDA_CONVERSIONS
578579
NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute), options);
579580
serializer.init();
580581
return serializer.run();
581582
#else
582583
module->emitError(
583584
"The `NVPTX` target was not built. Please enable it when building LLVM.");
584585
return std::nullopt;
585-
#endif // MLIR_CUDA_CONVERSIONS_ENABLED == 1
586+
#endif // MLIR_ENABLE_CUDA_CONVERSIONS
586587
}
587588

588589
Attribute

mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "mlir/Config/mlir-config.h"
910
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1011
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
1112
#include "mlir/IR/MLIRContext.h"
@@ -29,10 +30,10 @@
2930
using namespace mlir;
3031

3132
// Skip the test if the NVPTX target was not built.
32-
#if MLIR_CUDA_CONVERSIONS_ENABLED == 0
33-
#define SKIP_WITHOUT_NVPTX(x) DISABLED_##x
34-
#else
33+
#if MLIR_ENABLE_CUDA_CONVERSIONS
3534
#define SKIP_WITHOUT_NVPTX(x) x
35+
#else
36+
#define SKIP_WITHOUT_NVPTX(x) DISABLED_##x
3637
#endif
3738

3839
class MLIRTargetLLVMNVVM : public ::testing::Test {

utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# The MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure
77

88
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
9-
load("@bazel_skylib//rules:write_file.bzl", "write_file")
109
load(
1110
":build_defs.bzl",
1211
"cc_headers_only",
@@ -36,7 +35,10 @@ expand_template(
3635
"#cmakedefine01 MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS": "#define MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS 0",
3736
"#cmakedefine MLIR_GREEDY_REWRITE_RANDOMIZER_SEED ${MLIR_GREEDY_REWRITE_RANDOMIZER_SEED}": "/* #undef MLIR_GREEDY_REWRITE_RANDOMIZER_SEED */",
3837
"#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH": "#define MLIR_ENABLE_PDL_IN_PATTERNMATCH 1",
39-
},
38+
} | if_cuda_available(
39+
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 1"},
40+
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 0"},
41+
),
4042
template = "include/mlir/Config/mlir-config.h.cmake",
4143
)
4244

@@ -5468,7 +5470,6 @@ cc_library(
54685470
srcs = ["lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp"],
54695471
hdrs = ["include/mlir/Dialect/GPU/Pipelines/Passes.h"],
54705472
includes = ["include"],
5471-
local_defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
54725473
deps = [
54735474
":AffineToStandard",
54745475
":ArithToLLVM",
@@ -5492,6 +5493,7 @@ cc_library(
54925493
":Transforms",
54935494
":VectorToLLVM",
54945495
":VectorToSCF",
5496+
":config",
54955497
],
54965498
)
54975499

@@ -5541,6 +5543,7 @@ cc_library(
55415543
":Transforms",
55425544
":VCIXToLLVMIRTranslation",
55435545
":VectorDialect",
5546+
":config",
55445547
"//llvm:Core",
55455548
"//llvm:MC",
55465549
"//llvm:Support",
@@ -6176,6 +6179,7 @@ cc_library(
61766179
":NVVMToLLVMIRTranslation",
61776180
":TargetLLVM",
61786181
":ToLLVMIRTranslation",
6182+
":config",
61796183
"//llvm:NVPTXCodeGen",
61806184
"//llvm:Support",
61816185
],
@@ -9131,6 +9135,7 @@ cc_library(
91319135
":VectorTransforms",
91329136
":X86VectorDialect",
91339137
":X86VectorTransforms",
9138+
":config",
91349139
],
91359140
)
91369141

utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ cc_library(
552552
cc_library(
553553
name = "TestTransforms",
554554
srcs = glob(["lib/Transforms/*.cpp"]),
555-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
556555
includes = ["lib/Dialect/Test"],
557556
deps = [
558557
":TestDialect",
@@ -579,7 +578,6 @@ cc_library(
579578
cc_library(
580579
name = "TestFuncToLLVM",
581580
srcs = glob(["lib/Conversion/FuncToLLVM/*.cpp"]),
582-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
583581
includes = ["lib/Dialect/Test"],
584582
deps = [
585583
":TestDialect",
@@ -594,7 +592,6 @@ cc_library(
594592
cc_library(
595593
name = "TestOneToNTypeConversion",
596594
srcs = glob(["lib/Conversion/OneToNTypeConversion/*.cpp"]),
597-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
598595
includes = ["lib/Dialect/Test"],
599596
deps = [
600597
":TestDialect",
@@ -653,7 +650,6 @@ cc_library(
653650
cc_library(
654651
name = "TestDLTI",
655652
srcs = glob(["lib/Dialect/DLTI/*.cpp"]),
656-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
657653
includes = ["lib/Dialect/Test"],
658654
deps = [
659655
":TestDialect",
@@ -667,7 +663,7 @@ cc_library(
667663
cc_library(
668664
name = "TestGPU",
669665
srcs = glob(["lib/Dialect/GPU/*.cpp"]),
670-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"] + if_cuda_available([
666+
defines = if_cuda_available([
671667
"MLIR_GPU_TO_CUBIN_PASS_ENABLE",
672668
]),
673669
includes = ["lib/Dialect/Test"],
@@ -714,7 +710,6 @@ cc_library(
714710
cc_library(
715711
name = "TestLinalg",
716712
srcs = glob(["lib/Dialect/Linalg/*.cpp"]),
717-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
718713
includes = ["lib/Dialect/Test"],
719714
deps = [
720715
"//llvm:Support",
@@ -748,7 +743,6 @@ cc_library(
748743
cc_library(
749744
name = "TestLLVM",
750745
srcs = glob(["lib/Dialect/LLVM/*.cpp"]),
751-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
752746
includes = ["lib/Dialect/Test"],
753747
deps = [
754748
"//mlir:AffineToStandard",
@@ -773,7 +767,6 @@ cc_library(
773767
cc_library(
774768
name = "TestMath",
775769
srcs = glob(["lib/Dialect/Math/*.cpp"]),
776-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
777770
includes = ["lib/Dialect/Test"],
778771
deps = [
779772
"//mlir:ArithDialect",
@@ -790,7 +783,6 @@ cc_library(
790783
cc_library(
791784
name = "TestMathToVCIX",
792785
srcs = glob(["lib/Conversion/MathToVCIX/*.cpp"]),
793-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
794786
includes = ["lib/Dialect/Test"],
795787
deps = [
796788
"//mlir:ArithDialect",
@@ -807,7 +799,6 @@ cc_library(
807799
cc_library(
808800
name = "TestMemRef",
809801
srcs = glob(["lib/Dialect/MemRef/*.cpp"]),
810-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
811802
includes = ["lib/Dialect/Test"],
812803
deps = [
813804
":TestDialect",
@@ -847,7 +838,6 @@ cc_library(
847838
cc_library(
848839
name = "TestNVGPU",
849840
srcs = glob(["lib/Dialect/NVGPU/*.cpp"]),
850-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
851841
includes = ["lib/Dialect/Test"],
852842
deps = [
853843
"//mlir:AffineDialect",
@@ -871,7 +861,6 @@ cc_library(
871861
cc_library(
872862
name = "TestSCF",
873863
srcs = glob(["lib/Dialect/SCF/*.cpp"]),
874-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
875864
includes = ["lib/Dialect/Test"],
876865
deps = [
877866
"//llvm:Support",
@@ -891,7 +880,6 @@ cc_library(
891880
cc_library(
892881
name = "TestArith",
893882
srcs = glob(["lib/Dialect/Arith/*.cpp"]),
894-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
895883
includes = ["lib/Dialect/Test"],
896884
deps = [
897885
"//mlir:ArithDialect",
@@ -908,7 +896,6 @@ cc_library(
908896
cc_library(
909897
name = "TestArmSME",
910898
srcs = glob(["lib/Dialect/ArmSME/*.cpp"]),
911-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
912899
includes = ["lib/Dialect/Test"],
913900
deps = [
914901
"//mlir:ArithToArmSME",
@@ -927,7 +914,6 @@ cc_library(
927914
cc_library(
928915
name = "TestBufferization",
929916
srcs = glob(["lib/Dialect/Bufferization/*.cpp"]),
930-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
931917
includes = ["lib/Dialect/Test"],
932918
deps = [
933919
"//mlir:BufferizationDialect",
@@ -989,7 +975,6 @@ cc_library(
989975
cc_library(
990976
name = "TestFunc",
991977
srcs = glob(["lib/Dialect/Func/*.cpp"]),
992-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
993978
includes = ["lib/Dialect/Test"],
994979
deps = [
995980
":TestDialect",
@@ -1005,7 +990,6 @@ cc_library(
1005990
cc_library(
1006991
name = "TestTensor",
1007992
srcs = glob(["lib/Dialect/Tensor/*.cpp"]),
1008-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
1009993
includes = ["lib/Dialect/Test"],
1010994
deps = [
1011995
"//mlir:ArithDialect",
@@ -1022,7 +1006,6 @@ cc_library(
10221006
cc_library(
10231007
name = "TestVector",
10241008
srcs = glob(["lib/Dialect/Vector/*.cpp"]),
1025-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
10261009
includes = ["lib/Dialect/Test"],
10271010
deps = [
10281011
"//mlir:AffineDialect",

0 commit comments

Comments
 (0)