Skip to content

Commit 2ba1365

Browse files
committed
[mlir] Replace MLIR_ENABLE_CUDA_CONVERSIONS with LLVM_HAS_NVPTX_TARGET
1 parent 8ccb56c commit 2ba1365

File tree

14 files changed

+32
-50
lines changed

14 files changed

+32
-50
lines changed

mlir/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ else()
110110
set(MLIR_ENABLE_EXECUTION_ENGINE 0)
111111
endif()
112112

113-
# Build the CUDA conversions and run according tests if the NVPTX backend
114-
# is available
115-
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
116-
set(MLIR_ENABLE_CUDA_CONVERSIONS 1)
117-
else()
118-
set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
119-
endif()
120-
121113
# Build the ROCm conversions and run according tests if the AMDGPU backend
122114
# is available.
123115
if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
/* If set, enables PDL usage. */
4040
#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH
4141

42-
/* If set, enables CUDA-related features in CUDA-related transforms, pipelines,
43-
and targets. */
44-
#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS
45-
4642
/* If set, enables features that depend on the NVIDIA's PTX compiler. */
4743
#cmakedefine01 MLIR_ENABLE_NVPTXCOMPILER
4844

mlir/include/mlir/InitAllPasses.h

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

17-
#include "mlir/Config/mlir-config.h"
1817
#include "mlir/Conversion/Passes.h"
1918
#include "mlir/Dialect/AMDGPU/Transforms/Passes.h"
2019
#include "mlir/Dialect/Affine/Passes.h"
@@ -99,7 +98,7 @@ inline void registerAllPasses() {
9998
bufferization::registerBufferizationPipelines();
10099
sparse_tensor::registerSparseTensorPipelines();
101100
tosa::registerTosaToLinalgPipelines();
102-
#if MLIR_ENABLE_CUDA_CONVERSIONS
101+
#if LLVM_HAS_NVPTX_TARGET
103102
gpu::registerGPUToNVVMPipeline();
104103
#endif
105104
}

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

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

14-
#include "mlir/Config/mlir-config.h"
1514
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
1615
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
1716
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
@@ -39,7 +38,7 @@
3938

4039
using namespace mlir;
4140

42-
#if MLIR_ENABLE_CUDA_CONVERSIONS
41+
#if LLVM_HAS_NVPTX_TARGET
4342
namespace {
4443

4544
//===----------------------------------------------------------------------===//
@@ -128,4 +127,4 @@ void mlir::gpu::registerGPUToNVVMPipeline() {
128127
buildLowerToNVVMPassPipeline);
129128
}
130129

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

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

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

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

16-
#include "mlir/Config/mlir-config.h"
1716
#include "mlir/Dialect/Func/IR/FuncOps.h"
1817
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1918
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -49,7 +48,7 @@ void GpuModuleToBinaryPass::getDependentDialects(
4948
// Register all GPU related translations.
5049
registry.insert<gpu::GPUDialect>();
5150
registry.insert<LLVM::LLVMDialect>();
52-
#if MLIR_ENABLE_CUDA_CONVERSIONS
51+
#if LLVM_HAS_NVPTX_TARGET
5352
registry.insert<NVVM::NVVMDialect>();
5453
#endif
5554
#if MLIR_ENABLE_ROCM_CONVERSIONS

mlir/lib/Target/LLVM/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_mlir_dialect_library(MLIRNVVMTarget
4747
MLIRNVVMToLLVMIRTranslation
4848
)
4949

50-
if(MLIR_ENABLE_CUDA_CONVERSIONS)
50+
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
5151
# Find the CUDA toolkit.
5252
find_package(CUDAToolkit)
5353

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

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

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

16-
#include "mlir/Config/mlir-config.h"
1716
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1817
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
1918
#include "mlir/Target/LLVM/NVVM/Utils.h"
@@ -158,40 +157,43 @@ SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) {
158157
return std::move(bcFiles);
159158
}
160159

161-
#if MLIR_ENABLE_CUDA_CONVERSIONS
160+
#if LLVM_HAS_NVPTX_TARGET
162161
namespace {
163162
class NVPTXSerializer : public SerializeGPUModuleBase {
164163
public:
165164
NVPTXSerializer(Operation &module, NVVMTargetAttr target,
166165
const gpu::TargetOptions &targetOptions);
167166

167+
/// Returns the GPU module op being serialized.
168168
gpu::GPUModuleOp getOperation();
169169

170-
// Compile PTX to cubin using `ptxas`.
170+
/// Compiles PTX to cubin using `ptxas`.
171171
std::optional<SmallVector<char, 0>>
172172
compileToBinary(const std::string &ptxCode);
173173

174-
// Compile PTX to cubin using the `nvptxcompiler` library.
174+
/// Compiles PTX to cubin using the `nvptxcompiler` library.
175175
std::optional<SmallVector<char, 0>>
176176
compileToBinaryNVPTX(const std::string &ptxCode);
177177

178+
/// Serializes the LLVM module to an object format, depending on the
179+
/// compilation target selected in target options.
178180
std::optional<SmallVector<char, 0>>
179181
moduleToObject(llvm::Module &llvmModule) override;
180182

181183
private:
182184
using TmpFile = std::pair<llvm::SmallString<128>, llvm::FileRemover>;
183185

184-
// Create a temp file.
186+
/// Creates a temp file.
185187
std::optional<TmpFile> createTemp(StringRef name, StringRef suffix);
186188

187-
// Find the `tool` path, where `tool` is the name of the binary to search,
188-
// i.e. `ptxas` or `fatbinary`. The search order is:
189-
// 1. The toolkit path in `targetOptions`.
190-
// 2. In the system PATH.
191-
// 3. The path from `getCUDAToolkitPath()`.
189+
/// Finds the `tool` path, where `tool` is the name of the binary to search,
190+
/// i.e. `ptxas` or `fatbinary`. The search order is:
191+
/// 1. The toolkit path in `targetOptions`.
192+
/// 2. In the system PATH.
193+
/// 3. The path from `getCUDAToolkitPath()`.
192194
std::optional<std::string> findTool(StringRef tool);
193195

194-
// Target options.
196+
/// Target options.
195197
gpu::TargetOptions targetOptions;
196198
};
197199
} // namespace
@@ -515,7 +517,7 @@ NVPTXSerializer::compileToBinaryNVPTX(const std::string &ptxCode) {
515517

516518
std::optional<SmallVector<char, 0>>
517519
NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
518-
// Return LLVM IR if the compilation target is offload.
520+
// Return LLVM IR if the compilation target is `offload`.
519521
#define DEBUG_TYPE "serialize-to-llvm"
520522
LLVM_DEBUG({
521523
llvm::dbgs() << "LLVM IR for module: " << getOperation().getNameAttr()
@@ -549,7 +551,7 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
549551
});
550552
#undef DEBUG_TYPE
551553

552-
// Return PTX if the compilation target is assembly.
554+
// Return PTX if the compilation target is `assembly`.
553555
if (targetOptions.getCompilationTarget() ==
554556
gpu::CompilationTarget::Assembly) {
555557
// Make sure to include the null terminator.
@@ -564,7 +566,7 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
564566
return compileToBinary(*serializedISA);
565567
#endif // MLIR_ENABLE_NVPTXCOMPILER
566568
}
567-
#endif // MLIR_ENABLE_CUDA_CONVERSIONS
569+
#endif // LLVM_HAS_NVPTX_TARGET
568570

569571
std::optional<SmallVector<char, 0>>
570572
NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
@@ -576,15 +578,15 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
576578
module->emitError("Module must be a GPU module.");
577579
return std::nullopt;
578580
}
579-
#if MLIR_ENABLE_CUDA_CONVERSIONS
581+
#if LLVM_HAS_NVPTX_TARGET
580582
NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute), options);
581583
serializer.init();
582584
return serializer.run();
583585
#else
584586
module->emitError(
585587
"The `NVPTX` target was not built. Please enable it when building LLVM.");
586588
return std::nullopt;
587-
#endif // MLIR_ENABLE_CUDA_CONVERSIONS
589+
#endif // LLVM_HAS_NVPTX_TARGET
588590
}
589591

590592
Attribute

mlir/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ endif()
6868
llvm_canonicalize_cmake_booleans(
6969
LLVM_BUILD_EXAMPLES
7070
MLIR_ENABLE_BINDINGS_PYTHON
71-
MLIR_ENABLE_CUDA_CONVERSIONS
7271
MLIR_ENABLE_CUDA_RUNNER
7372
MLIR_ENABLE_ROCM_CONVERSIONS
7473
MLIR_ENABLE_ROCM_RUNNER

mlir/test/Dialect/GPU/test-nvvm-pipeline.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ func.func @test_math(%arg0 : f32) {
2727
gpu.terminator
2828
}
2929
return
30-
}
30+
}

mlir/test/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def have_host_jit_feature_support(feature_name):
245245
if have_host_jit_feature_support("jit"):
246246
config.available_features.add("host-supports-jit")
247247

248-
if config.run_cuda_tests:
248+
if config.run_nvptx_tests:
249249
config.available_features.add("host-supports-nvptx")
250250

251251
if config.run_rocm_tests:

mlir/test/lit.site.cfg.py.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ config.mlir_cmake_dir = "@MLIR_CMAKE_DIR@"
2525
config.mlir_lib_dir = "@MLIR_LIB_DIR@"
2626

2727
config.build_examples = @LLVM_BUILD_EXAMPLES@
28-
config.run_cuda_tests = @MLIR_ENABLE_CUDA_CONVERSIONS@
28+
# We need quotes here to handle the case where LLVM_HAS_NVPTX_TARGET
29+
# is not defined (i.e. NVPTX target not built).
30+
config.run_nvptx_tests = "@LLVM_HAS_NVPTX_TARGET@"
2931
config.enable_cuda_runner = @MLIR_ENABLE_CUDA_RUNNER@
3032
config.run_rocm_tests = @MLIR_ENABLE_ROCM_CONVERSIONS@
3133
config.enable_rocm_runner = @MLIR_ENABLE_ROCM_RUNNER@

mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
using namespace mlir;
3131

3232
// Skip the test if the NVPTX target was not built.
33-
#if MLIR_ENABLE_CUDA_CONVERSIONS
33+
#if LLVM_HAS_NVPTX_TARGET
3434
#define SKIP_WITHOUT_NVPTX(x) x
3535
#else
3636
#define SKIP_WITHOUT_NVPTX(x) DISABLED_##x

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ expand_template(
5151
"#cmakedefine01 MLIR_ENABLE_NVPTXCOMPILER": "#define MLIR_ENABLE_NVPTXCOMPILER 0",
5252
"#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH": "#define MLIR_ENABLE_PDL_IN_PATTERNMATCH 1",
5353
"#cmakedefine01 MLIR_ENABLE_ROCM_CONVERSIONS": "#define MLIR_ENABLE_ROCM_CONVERSIONS 0",
54-
} | if_cuda_available(
55-
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 1"},
56-
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 0"},
57-
),
54+
},
5855
template = "include/mlir/Config/mlir-config.h.cmake",
5956
)
6057

@@ -5616,7 +5613,6 @@ cc_library(
56165613
":Transforms",
56175614
":VectorToLLVM",
56185615
":VectorToSCF",
5619-
":config",
56205616
],
56215617
)
56225618

@@ -5666,7 +5662,6 @@ cc_library(
56665662
":Transforms",
56675663
":VCIXToLLVMIRTranslation",
56685664
":VectorDialect",
5669-
":config",
56705665
"//llvm:Core",
56715666
"//llvm:MC",
56725667
"//llvm:Support",
@@ -6282,7 +6277,6 @@ cc_library(
62826277
":NVVMToLLVMIRTranslation",
62836278
":TargetLLVM",
62846279
":ToLLVMIRTranslation",
6285-
":config",
62866280
"//llvm:NVPTXCodeGen",
62876281
"//llvm:Support",
62886282
"//llvm:config",
@@ -9363,7 +9357,6 @@ cc_library(
93639357
":X86VectorTransforms",
93649358
":XeGPUDialect",
93659359
":XeGPUTransforms",
9366-
":config",
93679360
],
93689361
)
93699362

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ expand_template(
3636
"\"@MLIR_BINARY_DIR@\"": "os.environ[\"TEST_UNDECLARED_OUTPUTS_DIR\"]",
3737
# All disabled, but required to substituted because they are not in quotes.
3838
"@LLVM_BUILD_EXAMPLES@": "0",
39-
"@MLIR_ENABLE_CUDA_CONVERSIONS@": "0",
39+
# Initialized to empty string as this is already wrapped in quotes.
40+
"@LLVM_HAS_NVPTX_TARGET@": "",
4041
"@MLIR_ENABLE_CUDA_RUNNER@": "0",
4142
"@MLIR_ENABLE_ROCM_CONVERSIONS@": "0",
4243
"@MLIR_ENABLE_ROCM_RUNNER@": "0",

0 commit comments

Comments
 (0)