Skip to content

Commit f3be842

Browse files
[mlir] Expose MLIR_ROCM_CONVERSIONS_ENABLED in mlir-config.h. (#83977)
This is a follow up of #83004, which made the same change for `MLIR_CUDA_CONVERSIONS_ENABLED`. As the previous PR, this PR 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_ROCM_CONVERSIONS_ENABLED`, which the CMake files previously defined manually.
1 parent b2c16e7 commit f3be842

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

mlir/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
119119
else()
120120
set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
121121
endif()
122-
add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS})
123122

124123
set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA runner")
125124
set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@
3333
and targets. */
3434
#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS
3535

36+
/* If set, enables ROCm-related features in ROCM-related transforms, pipelines,
37+
and targets. */
38+
#cmakedefine01 MLIR_ENABLE_ROCM_CONVERSIONS
39+
3640
#endif

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void GpuModuleToBinaryPass::getDependentDialects(
5252
#if MLIR_ENABLE_CUDA_CONVERSIONS
5353
registry.insert<NVVM::NVVMDialect>();
5454
#endif
55-
#if MLIR_ROCM_CONVERSIONS_ENABLED == 1
55+
#if MLIR_ENABLE_ROCM_CONVERSIONS
5656
registry.insert<ROCDL::ROCDLDialect>();
5757
#endif
5858
registry.insert<spirv::SPIRVDialect>();

mlir/lib/Target/LLVM/ROCDL/Target.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void SerializeGPUModuleBase::init() {
120120
static llvm::once_flag initializeBackendOnce;
121121
llvm::call_once(initializeBackendOnce, []() {
122122
// If the `AMDGPU` LLVM target was built, initialize it.
123-
#if MLIR_ROCM_CONVERSIONS_ENABLED == 1
123+
#if MLIR_ENABLE_ROCM_CONVERSIONS
124124
LLVMInitializeAMDGPUTarget();
125125
LLVMInitializeAMDGPUTargetInfo();
126126
LLVMInitializeAMDGPUTargetMC();
@@ -318,7 +318,7 @@ SerializeGPUModuleBase::assembleIsa(StringRef isa) {
318318
return result;
319319
}
320320

321-
#if MLIR_ROCM_CONVERSIONS_ENABLED == 1
321+
#if MLIR_ENABLE_ROCM_CONVERSIONS
322322
namespace {
323323
class AMDGPUSerializer : public SerializeGPUModuleBase {
324324
public:
@@ -450,7 +450,7 @@ AMDGPUSerializer::moduleToObject(llvm::Module &llvmModule) {
450450
// Compile to binary.
451451
return compileToBinary(*serializedISA);
452452
}
453-
#endif // MLIR_ROCM_CONVERSIONS_ENABLED
453+
#endif // MLIR_ENABLE_ROCM_CONVERSIONS
454454

455455
std::optional<SmallVector<char, 0>> ROCDLTargetAttrImpl::serializeToObject(
456456
Attribute attribute, Operation *module,
@@ -462,7 +462,7 @@ std::optional<SmallVector<char, 0>> ROCDLTargetAttrImpl::serializeToObject(
462462
module->emitError("Module must be a GPU module.");
463463
return std::nullopt;
464464
}
465-
#if MLIR_ROCM_CONVERSIONS_ENABLED == 1
465+
#if MLIR_ENABLE_ROCM_CONVERSIONS
466466
AMDGPUSerializer serializer(*module, cast<ROCDLTargetAttr>(attribute),
467467
options);
468468
serializer.init();
@@ -471,7 +471,7 @@ std::optional<SmallVector<char, 0>> ROCDLTargetAttrImpl::serializeToObject(
471471
module->emitError("The `AMDGPU` target was not built. Please enable it when "
472472
"building LLVM.");
473473
return std::nullopt;
474-
#endif // MLIR_ROCM_CONVERSIONS_ENABLED == 1
474+
#endif // MLIR_ENABLE_ROCM_CONVERSIONS
475475
}
476476

477477
Attribute

mlir/unittests/Target/LLVM/SerializeROCDLTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
using namespace mlir;
3232

3333
// Skip the test if the AMDGPU target was not built.
34-
#if MLIR_ROCM_CONVERSIONS_ENABLED == 0
35-
#define SKIP_WITHOUT_AMDGPU(x) DISABLED_##x
36-
#else
34+
#if MLIR_ENABLE_ROCM_CONVERSIONS
3735
#define SKIP_WITHOUT_AMDGPU(x) x
36+
#else
37+
#define SKIP_WITHOUT_AMDGPU(x) DISABLED_##x
3838
#endif
3939

4040
class MLIRTargetLLVMROCDL : public ::testing::Test {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ expand_template(
3535
"#cmakedefine01 MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS": "#define MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS 0",
3636
"#cmakedefine MLIR_GREEDY_REWRITE_RANDOMIZER_SEED ${MLIR_GREEDY_REWRITE_RANDOMIZER_SEED}": "/* #undef MLIR_GREEDY_REWRITE_RANDOMIZER_SEED */",
3737
"#cmakedefine01 MLIR_ENABLE_PDL_IN_PATTERNMATCH": "#define MLIR_ENABLE_PDL_IN_PATTERNMATCH 1",
38+
"#cmakedefine01 MLIR_ENABLE_ROCM_CONVERSIONS": "#define MLIR_ENABLE_ROCM_CONVERSIONS 0",
3839
} | if_cuda_available(
3940
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 1"},
4041
{"#cmakedefine01 MLIR_ENABLE_CUDA_CONVERSIONS": "#define MLIR_ENABLE_CUDA_CONVERSIONS 0"},

0 commit comments

Comments
 (0)