Skip to content

Commit 4c9cb9e

Browse files
[mlir] Expose MLIR_CUDA_CONVERSIONS_ENABLED in mlir-config.h.
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 c4e9463 commit 4c9cb9e

File tree

9 files changed

+43
-32
lines changed

9 files changed

+43
-32
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: 2 additions & 1 deletion
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,7 +30,7 @@
2930
using namespace mlir;
3031

3132
// Skip the test if the NVPTX target was not built.
32-
#if MLIR_CUDA_CONVERSIONS_ENABLED == 0
33+
#if MLIR_ENABLE_CUDA_CONVERSIONS == 0
3334
#define SKIP_WITHOUT_NVPTX(x) DISABLED_##x
3435
#else
3536
#define SKIP_WITHOUT_NVPTX(x) x

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

Lines changed: 7 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
],

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ cc_library(
552552
cc_library(
553553
name = "TestTransforms",
554554
srcs = glob(["lib/Transforms/*.cpp"]),
555-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
555+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
556556
includes = ["lib/Dialect/Test"],
557557
deps = [
558558
":TestDialect",
@@ -579,7 +579,7 @@ cc_library(
579579
cc_library(
580580
name = "TestFuncToLLVM",
581581
srcs = glob(["lib/Conversion/FuncToLLVM/*.cpp"]),
582-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
582+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
583583
includes = ["lib/Dialect/Test"],
584584
deps = [
585585
":TestDialect",
@@ -594,7 +594,7 @@ cc_library(
594594
cc_library(
595595
name = "TestOneToNTypeConversion",
596596
srcs = glob(["lib/Conversion/OneToNTypeConversion/*.cpp"]),
597-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
597+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
598598
includes = ["lib/Dialect/Test"],
599599
deps = [
600600
":TestDialect",
@@ -653,7 +653,7 @@ cc_library(
653653
cc_library(
654654
name = "TestDLTI",
655655
srcs = glob(["lib/Dialect/DLTI/*.cpp"]),
656-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
656+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
657657
includes = ["lib/Dialect/Test"],
658658
deps = [
659659
":TestDialect",
@@ -667,7 +667,7 @@ cc_library(
667667
cc_library(
668668
name = "TestGPU",
669669
srcs = glob(["lib/Dialect/GPU/*.cpp"]),
670-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"] + if_cuda_available([
670+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"] + if_cuda_available([
671671
"MLIR_GPU_TO_CUBIN_PASS_ENABLE",
672672
]),
673673
includes = ["lib/Dialect/Test"],
@@ -714,7 +714,7 @@ cc_library(
714714
cc_library(
715715
name = "TestLinalg",
716716
srcs = glob(["lib/Dialect/Linalg/*.cpp"]),
717-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
717+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
718718
includes = ["lib/Dialect/Test"],
719719
deps = [
720720
"//llvm:Support",
@@ -748,7 +748,7 @@ cc_library(
748748
cc_library(
749749
name = "TestLLVM",
750750
srcs = glob(["lib/Dialect/LLVM/*.cpp"]),
751-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
751+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
752752
includes = ["lib/Dialect/Test"],
753753
deps = [
754754
"//mlir:AffineToStandard",
@@ -773,7 +773,7 @@ cc_library(
773773
cc_library(
774774
name = "TestMath",
775775
srcs = glob(["lib/Dialect/Math/*.cpp"]),
776-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
776+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
777777
includes = ["lib/Dialect/Test"],
778778
deps = [
779779
"//mlir:ArithDialect",
@@ -790,7 +790,7 @@ cc_library(
790790
cc_library(
791791
name = "TestMathToVCIX",
792792
srcs = glob(["lib/Conversion/MathToVCIX/*.cpp"]),
793-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
793+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
794794
includes = ["lib/Dialect/Test"],
795795
deps = [
796796
"//mlir:ArithDialect",
@@ -807,7 +807,7 @@ cc_library(
807807
cc_library(
808808
name = "TestMemRef",
809809
srcs = glob(["lib/Dialect/MemRef/*.cpp"]),
810-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
810+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
811811
includes = ["lib/Dialect/Test"],
812812
deps = [
813813
":TestDialect",
@@ -847,7 +847,7 @@ cc_library(
847847
cc_library(
848848
name = "TestNVGPU",
849849
srcs = glob(["lib/Dialect/NVGPU/*.cpp"]),
850-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
850+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
851851
includes = ["lib/Dialect/Test"],
852852
deps = [
853853
"//mlir:AffineDialect",
@@ -871,7 +871,7 @@ cc_library(
871871
cc_library(
872872
name = "TestSCF",
873873
srcs = glob(["lib/Dialect/SCF/*.cpp"]),
874-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
874+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
875875
includes = ["lib/Dialect/Test"],
876876
deps = [
877877
"//llvm:Support",
@@ -891,7 +891,7 @@ cc_library(
891891
cc_library(
892892
name = "TestArith",
893893
srcs = glob(["lib/Dialect/Arith/*.cpp"]),
894-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
894+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
895895
includes = ["lib/Dialect/Test"],
896896
deps = [
897897
"//mlir:ArithDialect",
@@ -908,7 +908,7 @@ cc_library(
908908
cc_library(
909909
name = "TestArmSME",
910910
srcs = glob(["lib/Dialect/ArmSME/*.cpp"]),
911-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
911+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
912912
includes = ["lib/Dialect/Test"],
913913
deps = [
914914
"//mlir:ArithToArmSME",
@@ -927,7 +927,7 @@ cc_library(
927927
cc_library(
928928
name = "TestBufferization",
929929
srcs = glob(["lib/Dialect/Bufferization/*.cpp"]),
930-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
930+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
931931
includes = ["lib/Dialect/Test"],
932932
deps = [
933933
"//mlir:BufferizationDialect",
@@ -989,7 +989,7 @@ cc_library(
989989
cc_library(
990990
name = "TestFunc",
991991
srcs = glob(["lib/Dialect/Func/*.cpp"]),
992-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
992+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
993993
includes = ["lib/Dialect/Test"],
994994
deps = [
995995
":TestDialect",
@@ -1005,7 +1005,7 @@ cc_library(
10051005
cc_library(
10061006
name = "TestTensor",
10071007
srcs = glob(["lib/Dialect/Tensor/*.cpp"]),
1008-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
1008+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
10091009
includes = ["lib/Dialect/Test"],
10101010
deps = [
10111011
"//mlir:ArithDialect",
@@ -1022,7 +1022,7 @@ cc_library(
10221022
cc_library(
10231023
name = "TestVector",
10241024
srcs = glob(["lib/Dialect/Vector/*.cpp"]),
1025-
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
1025+
defines = ["MLIR_ENABLE_CUDA_CONVERSIONS"],
10261026
includes = ["lib/Dialect/Test"],
10271027
deps = [
10281028
"//mlir:AffineDialect",

0 commit comments

Comments
 (0)