[Workflow] Roll back some settings since they caused more issues
[llvm-project.git] / mlir / lib / Target / LLVM / CMakeLists.txt
blobce07c259df83351f3ee6c50aa3e8af676048aef5
1 add_mlir_library(MLIRTargetLLVM
2   ModuleToObject.cpp
4   ADDITIONAL_HEADER_DIRS
5   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVM
7   DEPENDS
8   intrinsics_gen
10   LINK_COMPONENTS
11   Core
12   IPO
13   IRReader
14   Linker
15   MC
16   Passes
17   Support
18   Target
19   LINK_LIBS PUBLIC
20   MLIRExecutionEngineUtils
21   MLIRTargetLLVMIRExport
24 if (MLIR_ENABLE_CUDA_CONVERSIONS)
25   set(NVPTX_LIBS
26     NVPTXCodeGen
27     NVPTXDesc
28     NVPTXInfo
29   )
30 endif()
32 add_mlir_dialect_library(MLIRNVVMTarget
33   NVVM/Target.cpp
35   ADDITIONAL_HEADER_DIRS
36   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
38   LINK_COMPONENTS
39   ${NVPTX_LIBS}
41   LINK_LIBS PUBLIC
42   MLIRIR
43   MLIRExecutionEngineUtils
44   MLIRSupport
45   MLIRGPUDialect
46   MLIRTargetLLVM
47   MLIRNVVMToLLVMIRTranslation
48   )
50 if(MLIR_ENABLE_CUDA_CONVERSIONS)
51   # Find the CUDA toolkit.
52   find_package(CUDAToolkit)
54   if(CUDAToolkit_FOUND)
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}
62                              DIRECTORY ABSOLUTE)
63     else()
64       set(MLIR_CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_ROOT})
65     endif()
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")
76         message(FATAL_ERROR
77                 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
78       endif()
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})
83     endif()
84   else()
85     # Fail if `MLIR_ENABLE_NVPTXCOMPILER` is enabled and the toolkit couldn't be found.
86     if(MLIR_ENABLE_NVPTXCOMPILER)
87       message(FATAL_ERROR
88               "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
89     endif()
90   endif()
91   message(VERBOSE "MLIR default CUDA toolkit path: ${MLIR_CUDAToolkit_ROOT}")
93   # Define the `CUDAToolkit` path.
94   target_compile_definitions(obj.MLIRNVVMTarget
95     PRIVATE
96     MLIR_NVPTXCOMPILER_ENABLED=${MLIR_ENABLE_NVPTXCOMPILER}
97     __DEFAULT_CUDATOOLKIT_PATH__="${MLIR_CUDAToolkit_ROOT}"
98   )
99 endif()
101 if (MLIR_ENABLE_ROCM_CONVERSIONS)
102   set(AMDGPU_LIBS
103     AMDGPUAsmParser
104     AMDGPUCodeGen
105     AMDGPUDesc
106     AMDGPUInfo
107   )
108 endif()
110 add_mlir_dialect_library(MLIRROCDLTarget
111   ROCDL/Target.cpp
113   LINK_COMPONENTS
114   MCParser
115   ${AMDGPU_LIBS}
117   LINK_LIBS PUBLIC
118   MLIRIR
119   MLIRExecutionEngineUtils
120   MLIRSupport
121   MLIRGPUDialect
122   MLIRTargetLLVM
123   MLIRROCDLToLLVMIRTranslation
124   )
126 if(MLIR_ENABLE_ROCM_CONVERSIONS)
127   if (NOT ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD))
128     message(SEND_ERROR
129       "Building mlir with ROCm support requires the AMDGPU backend")
130   endif()
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")
136   else()
137     set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs")
138   endif()
139   message(VERBOSE "MLIR Default ROCM toolkit path: ${DEFAULT_ROCM_PATH}")
141   target_compile_definitions(obj.MLIRROCDLTarget
142     PRIVATE
143     __DEFAULT_ROCM_PATH__="${DEFAULT_ROCM_PATH}"
144   )
145 endif()