1 add_mlir_library(MLIRTargetLLVM
5 ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVM
20 MLIRExecutionEngineUtils
21 MLIRTargetLLVMIRExport
24 if (MLIR_ENABLE_CUDA_CONVERSIONS)
32 add_mlir_dialect_library(MLIRNVVMTarget
35 ADDITIONAL_HEADER_DIRS
36 ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
43 MLIRExecutionEngineUtils
47 MLIRNVVMToLLVMIRTranslation
50 if(MLIR_ENABLE_CUDA_CONVERSIONS)
51 # Find the CUDA toolkit.
52 find_package(CUDAToolkit)
55 # Get the CUDA toolkit path. The path is needed for detecting `libdevice.bc`.
56 # These extra steps are needed because of a bug on CMake.
57 # See: https://gitlab.kitware.com/cmake/cmake/-/issues/24858
58 # TODO: Bump the MLIR CMake version to 3.26.4 and switch to
59 # ${CUDAToolkit_LIBRARY_ROOT}
60 if(NOT DEFINED ${CUDAToolkit_LIBRARY_ROOT})
61 get_filename_component(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_BIN_DIR}
64 set(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_ROOT})
67 # Add the `nvptxcompiler` library.
68 if(MLIR_ENABLE_NVPTXCOMPILER)
69 # Find the `nvptxcompiler` library.
70 # TODO: Bump the MLIR CMake version to 3.25 and use `CUDA::nvptxcompiler_static`.
71 find_library(MLIR_NVPTXCOMPILER_LIB nvptxcompiler_static
72 PATHS ${CUDAToolkit_LIBRARY_DIR} NO_DEFAULT_PATH)
74 # Fail if `nvptxcompiler_static` couldn't be found.
75 if(MLIR_NVPTXCOMPILER_LIB STREQUAL "MLIR_NVPTXCOMPILER_LIB-NOTFOUND")
77 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
80 # Link against `nvptxcompiler_static`. TODO: use `CUDA::nvptxcompiler_static`.
81 target_link_libraries(MLIRNVVMTarget PRIVATE ${MLIR_NVPTXCOMPILER_LIB})
82 target_include_directories(obj.MLIRNVVMTarget PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
85 # Fail if `MLIR_ENABLE_NVPTXCOMPILER` is enabled and the toolkit couldn't be found.
86 if(MLIR_ENABLE_NVPTXCOMPILER)
88 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
91 message(VERBOSE "MLIR default CUDA toolkit path: ${MLIR_CUDAToolkit_ROOT}")
93 # Define the `CUDAToolkit` path.
94 target_compile_definitions(obj.MLIRNVVMTarget
96 MLIR_NVPTXCOMPILER_ENABLED=${MLIR_ENABLE_NVPTXCOMPILER}
97 __DEFAULT_CUDATOOLKIT_PATH__="${MLIR_CUDAToolkit_ROOT}"
101 if (MLIR_ENABLE_ROCM_CONVERSIONS)
110 add_mlir_dialect_library(MLIRROCDLTarget
119 MLIRExecutionEngineUtils
123 MLIRROCDLToLLVMIRTranslation
126 if(MLIR_ENABLE_ROCM_CONVERSIONS)
127 if (NOT ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD))
129 "Building mlir with ROCm support requires the AMDGPU backend")
132 if (DEFINED ROCM_PATH)
133 set(DEFAULT_ROCM_PATH "${ROCM_PATH}" CACHE PATH "Fallback path to search for ROCm installs")
134 elseif(DEFINED ENV{ROCM_PATH})
135 set(DEFAULT_ROCM_PATH "$ENV{ROCM_PATH}" CACHE PATH "Fallback path to search for ROCm installs")
137 set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs")
139 message(VERBOSE "MLIR Default ROCM toolkit path: ${DEFAULT_ROCM_PATH}")
141 target_compile_definitions(obj.MLIRROCDLTarget
143 __DEFAULT_ROCM_PATH__="${DEFAULT_ROCM_PATH}"