1 add_mlir_library(MLIRTargetLLVM
5 ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVM
20 MLIRExecutionEngineUtils
21 MLIRTargetLLVMIRExport
24 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
32 add_mlir_dialect_library(MLIRNVVMTarget
37 ADDITIONAL_HEADER_DIRS
38 ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
45 MLIRExecutionEngineUtils
49 MLIRNVVMToLLVMIRTranslation
52 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
53 # Find the CUDA toolkit.
54 find_package(CUDAToolkit)
57 # Get the CUDA toolkit path. The path is needed for detecting `libdevice.bc`.
58 # These extra steps are needed because of a bug on CMake.
59 # See: https://gitlab.kitware.com/cmake/cmake/-/issues/24858
60 # TODO: Bump the MLIR CMake version to 3.26.4 and switch to
61 # ${CUDAToolkit_LIBRARY_ROOT}
62 if(NOT DEFINED ${CUDAToolkit_LIBRARY_ROOT})
63 get_filename_component(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_BIN_DIR}
66 set(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_ROOT})
69 # Add the `nvptxcompiler` library.
70 if(MLIR_ENABLE_NVPTXCOMPILER)
71 # Find the `nvptxcompiler` library.
72 # TODO: Bump the MLIR CMake version to 3.25 and use `CUDA::nvptxcompiler_static`.
73 find_library(MLIR_NVPTXCOMPILER_LIB_PATH nvptxcompiler_static
74 PATHS ${CUDAToolkit_LIBRARY_DIR} NO_DEFAULT_PATH)
76 # Fail if `nvptxcompiler_static` couldn't be found.
77 if(MLIR_NVPTXCOMPILER_LIB_PATH STREQUAL "MLIR_NVPTXCOMPILER_LIB_PATH-NOTFOUND")
79 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
82 add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
83 # Downstream projects can modify this path and use it in CMake. For example:
84 # add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
85 # set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${...})
86 # where `...` is to be replaced with the path to the library.
87 set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${MLIR_NVPTXCOMPILER_LIB_PATH})
88 # Link against `nvptxcompiler_static`. TODO: use `CUDA::nvptxcompiler_static`.
89 target_link_libraries(MLIRNVVMTarget PRIVATE MLIR_NVPTXCOMPILER_LIB)
90 target_include_directories(obj.MLIRNVVMTarget PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
93 # Fail if `MLIR_ENABLE_NVPTXCOMPILER` is enabled and the toolkit couldn't be found.
94 if(MLIR_ENABLE_NVPTXCOMPILER)
96 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
99 message(VERBOSE "MLIR default CUDA toolkit path: ${MLIR_CUDAToolkit_ROOT}")
101 # Define the `CUDAToolkit` path.
102 target_compile_definitions(obj.MLIRNVVMTarget
104 __DEFAULT_CUDATOOLKIT_PATH__="${MLIR_CUDAToolkit_ROOT}"
108 if (MLIR_ENABLE_ROCM_CONVERSIONS)
117 add_mlir_dialect_library(MLIRROCDLTarget
130 MLIRExecutionEngineUtils
134 MLIRROCDLToLLVMIRTranslation
137 if(MLIR_ENABLE_ROCM_CONVERSIONS)
138 if (DEFINED ROCM_PATH)
139 set(DEFAULT_ROCM_PATH "${ROCM_PATH}" CACHE PATH "Fallback path to search for ROCm installs")
140 elseif(DEFINED ENV{ROCM_PATH})
141 set(DEFAULT_ROCM_PATH "$ENV{ROCM_PATH}" CACHE PATH "Fallback path to search for ROCm installs")
144 # Avoid setting an UNIX path for Windows.
145 # TODO: Eventually migrate to FindHIP once it becomes a part of CMake.
146 set(DEFAULT_ROCM_PATH "" CACHE PATH "Fallback path to search for ROCm installs")
148 set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs")
151 message(VERBOSE "MLIR Default ROCM toolkit path: ${DEFAULT_ROCM_PATH}")
153 target_compile_definitions(obj.MLIRROCDLTarget
155 __DEFAULT_ROCM_PATH__="${DEFAULT_ROCM_PATH}"