1set(LLVM_OPTIONAL_SOURCES 2 rocm-runtime-wrappers.cpp 3 mlir-rocm-runner.cpp 4 ) 5 6if(MLIR_ROCM_RUNNER_ENABLED) 7 if (NOT ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)) 8 message(SEND_ERROR 9 "Building the mlir rocm runner requires the AMDGPU backend") 10 endif() 11 12 # Ensure lld is enabled. 13 if (NOT "lld" IN_LIST LLVM_ENABLE_PROJECTS) 14 message(SEND_ERROR "lld is not enabled. Please revise LLVM_ENABLE_PROJECTS") 15 endif() 16 17 # lld header files. 18 include_directories(${MLIR_SOURCE_DIR}/../lld/include) 19 20 # Configure ROCm support. 21 if (NOT DEFINED ROCM_PATH) 22 if (NOT DEFINED ENV{ROCM_PATH}) 23 set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCm has been installed") 24 else() 25 set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed") 26 endif() 27 set(HIP_PATH "${ROCM_PATH}/hip" CACHE PATH " Path to which HIP has been installed") 28 endif() 29 set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH}) 30 find_package(HIP) 31 if (NOT HIP_FOUND) 32 message(SEND_ERROR "Build the mlir rocm runner requires a working ROCm and HIP install") 33 else() 34 message(STATUS "ROCm HIP version: ${HIP_VERSION}") 35 endif() 36 37 # Set compile-time flags for ROCm path. 38 add_definitions(-D__ROCM_PATH__="${ROCM_PATH}") 39 40 # Locate HIP runtime library. 41 find_library(ROCM_RUNTIME_LIBRARY amdhip64 42 PATHS "${HIP_PATH}/lib") 43 if (NOT ROCM_RUNTIME_LIBRARY) 44 message(SEND_ERROR "Could not locate ROCm HIP runtime library") 45 else() 46 message(STATUS "ROCm HIP runtime lib: ${ROCM_RUNTIME_LIBRARY}") 47 endif() 48 49 # Set HIP compile-time flags. 50 add_definitions(-D__HIP_PLATFORM_HCC__) 51 52 add_llvm_library(rocm-runtime-wrappers SHARED 53 rocm-runtime-wrappers.cpp 54 ) 55 target_include_directories(rocm-runtime-wrappers 56 PRIVATE 57 "${HIP_PATH}/../include" 58 "${HIP_PATH}/include" 59 LLVMSupport 60 ) 61 target_link_libraries(rocm-runtime-wrappers 62 PUBLIC 63 LLVMSupport 64 ${ROCM_RUNTIME_LIBRARY} 65 ) 66 67 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 68 get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) 69 set(LIBS 70 ${dialect_libs} 71 ${conversion_libs} 72 lldCommon 73 lldDriver 74 lldELF 75 MLIRJitRunner 76 MLIRAnalysis 77 MLIREDSC 78 MLIRExecutionEngine 79 MLIRIR 80 MLIRParser 81 MLIRROCDLIR 82 MLIRSupport 83 MLIRTargetLLVMIR 84 MLIRTargetROCDLIR 85 MLIRTransforms 86 MLIRTranslation 87 ${ROCM_RUNTIME_LIBRARY} 88 ) 89 90 # Manually expand the target library, since our MLIR libraries 91 # aren't plugged into the LLVM dependency tracking. If we don't 92 # do this then we can't insert the CodeGen library after ourselves 93 llvm_expand_pseudo_components(TARGET_LIBS AllTargetsCodeGens AllTargetsAsmParsers) 94 # Prepend LLVM in front of every target, this is how the library 95 # are named with CMake 96 SET(targets_to_link) 97 FOREACH(t ${TARGET_LIBS}) 98 LIST(APPEND targets_to_link "LLVM${t}") 99 ENDFOREACH(t) 100 101 add_llvm_tool(mlir-rocm-runner 102 mlir-rocm-runner.cpp 103 104 DEPENDS 105 rocm-runtime-wrappers 106 107 LINK_COMPONENTS 108 109 Core 110 LTO 111 MC 112 MCParser 113 Option 114 Support 115 ) 116 llvm_update_compile_flags(mlir-rocm-runner) 117 target_include_directories(mlir-rocm-runner 118 PRIVATE 119 "${HIP_PATH}/../include" 120 "${HIP_PATH}/include" 121 ) 122 target_link_libraries(mlir-rocm-runner PRIVATE ${LIBS} ${targets_to_link}) 123 124endif() 125