| ################################################################################ | |
| # Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from # | |
| # compiler/plugins/target/ROCM/BUILD.bazel # | |
| # # | |
| # Use iree_cmake_extra_content from iree/build_defs.oss.bzl to add arbitrary # | |
| # CMake-only content. # | |
| # # | |
| # To disable autogeneration for this file entirely, delete this header. # | |
| ################################################################################ | |
| iree_add_all_subdirs() | |
| iree_compiler_register_plugin( | |
| PLUGIN_ID | |
| hal_target_rocm | |
| TARGET | |
| ::ROCM | |
| ) | |
| iree_cc_library( | |
| NAME | |
| ROCM | |
| HDRS | |
| "ROCMTargetUtils.h" | |
| SRCS | |
| "ROCMTarget.cpp" | |
| "ROCMTargetUtils.cpp" | |
| DEPS | |
| LLVMAMDGPUCodeGen | |
| LLVMAnalysis | |
| LLVMBitWriter | |
| LLVMCore | |
| LLVMFrontendOffloading | |
| LLVMIRReader | |
| LLVMLinker | |
| LLVMMC | |
| LLVMPasses | |
| LLVMSPIRVCodeGen | |
| LLVMSupport | |
| LLVMTarget | |
| LLVMTargetParser | |
| LLVMTransformUtils | |
| LLVMipo | |
| MLIRAMDGPUDialect | |
| MLIRAMDGPUToROCDL | |
| MLIRAMDGPUTransforms | |
| MLIRBuiltinToLLVMIRTranslation | |
| MLIRIR | |
| MLIRLLVMDialect | |
| MLIRLLVMToLLVMIRTranslation | |
| MLIRPass | |
| MLIRROCDLDialect | |
| MLIRROCDLTarget | |
| MLIRROCDLToLLVMIRTranslation | |
| MLIRSupport | |
| MLIRTargetLLVMIRExport | |
| iree::compiler::Codegen::Common | |
| iree::compiler::Codegen::Dialect::Codegen::IR::IREECodegenDialect | |
| iree::compiler::Codegen::Dialect::GPU::IR::IREEGPUDialect | |
| iree::compiler::Codegen::Dialect::GPU::TargetUtils::KnownTargets | |
| iree::compiler::Codegen::Dialect::VectorExt::IR::IREEVectorExtDialect | |
| iree::compiler::Codegen::LLVMGPU | |
| iree::compiler::Codegen::Utils | |
| iree::compiler::Codegen::Utils::CodegenOptions | |
| iree::compiler::Dialect::Encoding::IR | |
| iree::compiler::Dialect::HAL::IR | |
| iree::compiler::Dialect::HAL::Target | |
| iree::compiler::Dialect::HAL::Utils::ExecutableDebugInfoUtils | |
| iree::compiler::Dialect::HAL::Utils::LLVMLinkerUtils | |
| iree::compiler::Dialect::Util::IR | |
| iree::compiler::PluginAPI | |
| iree::compiler::Utils | |
| iree::compiler::plugins::target::ROCM::Dialect::ROCM::IR::ROCMDialect | |
| iree::compiler::plugins::target::ROCM::Dialect::ROCM::Transforms | |
| iree::compiler::plugins::target::ROCM::builtins::ukernel::iree_uk_amdgpu_bitcode | |
| iree::schemas::amdgpu_executable_def_c_fbs | |
| iree::schemas::executable_debug_info_c_fbs | |
| iree::schemas::hip_executable_def_c_fbs | |
| PUBLIC | |
| ) | |
| ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ### | |
| # Use local device bitcode when requested, otherwise extract it from the | |
| # official ROCm package pinned alongside the Bazel repository's build overlay. | |
| set(_amd_required_libs "ocml.bc" "ockl.bc") | |
| set(IREE_TARGET_BACKEND_ROCM_DEVICE_BC_PATH "" CACHE PATH | |
| "Optional path to load device bitcode from (default to dynamic fetch)") | |
| set(_platform_lib_srcdir) | |
| if(IREE_TARGET_BACKEND_ROCM_DEVICE_BC_PATH) | |
| # Don't fetch: Get from local directory. | |
| set(_platform_lib_srcdir "${IREE_TARGET_BACKEND_ROCM_DEVICE_BC_PATH}") | |
| else() | |
| set(_amd_device_bc_package_file | |
| "${IREE_ROOT_DIR}/build_tools/third_party/amdgpu_device_libs/rocm_package.json") | |
| set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS | |
| "${_amd_device_bc_package_file}") | |
| file(READ "${_amd_device_bc_package_file}" _amd_device_bc_package) | |
| string(JSON _amd_device_bc_url GET "${_amd_device_bc_package}" url) | |
| string(JSON _amd_device_bc_sha256 GET "${_amd_device_bc_package}" sha256) | |
| string(JSON _amd_device_bc_payload GET "${_amd_device_bc_package}" payload) | |
| string(JSON _amd_device_bc_bitcode_path GET "${_amd_device_bc_package}" bitcode_path) | |
| # Include the archive layout in the cache key as well as the URL and hash. | |
| set(_amd_device_bc_stamp "${_amd_device_bc_package}") | |
| set(_platform_lib_archive "${CMAKE_CURRENT_BINARY_DIR}/_fetch_device_libs.deb") | |
| set(_platform_lib_extractdir "${CMAKE_CURRENT_BINARY_DIR}/_fetch_device_libs") | |
| set(_platform_lib_srcdir "${_platform_lib_extractdir}/${_amd_device_bc_bitcode_path}") | |
| set(_fetch_stamp_file "${CMAKE_CURRENT_BINARY_DIR}/_fetch_device_libs.stamp") | |
| set(_needs_fetch ON) | |
| if(EXISTS "${_fetch_stamp_file}" AND IS_DIRECTORY "${_platform_lib_srcdir}") | |
| file(READ "${_fetch_stamp_file}" _stamp_contents) | |
| if ("${_stamp_contents}" STREQUAL "${_amd_device_bc_stamp}") | |
| set(_needs_fetch OFF) | |
| endif() | |
| endif() | |
| foreach(_amd_lib_name ${_amd_required_libs}) | |
| if(NOT EXISTS "${_platform_lib_srcdir}/${_amd_lib_name}") | |
| set(_needs_fetch ON) | |
| endif() | |
| endforeach() | |
| # Download, extract, stamp. | |
| if(_needs_fetch) | |
| message(STATUS "Downloading AMD Device bitcode from ${_amd_device_bc_url} to ${_platform_lib_srcdir}") | |
| file(DOWNLOAD "${_amd_device_bc_url}" "${_platform_lib_archive}" | |
| EXPECTED_HASH SHA256=${_amd_device_bc_sha256}) | |
| # Extract the .deb container and then only the required bitcode from its | |
| # data tarball. | |
| file(REMOVE_RECURSE "${_platform_lib_extractdir}") | |
| file(ARCHIVE_EXTRACT | |
| INPUT "${_platform_lib_archive}" | |
| DESTINATION "${_platform_lib_extractdir}" | |
| PATTERNS "${_amd_device_bc_payload}" | |
| ) | |
| set(_platform_lib_patterns) | |
| foreach(_amd_lib_name ${_amd_required_libs}) | |
| list(APPEND _platform_lib_patterns "./${_amd_device_bc_bitcode_path}/${_amd_lib_name}") | |
| endforeach() | |
| file(ARCHIVE_EXTRACT | |
| INPUT "${_platform_lib_extractdir}/${_amd_device_bc_payload}" | |
| DESTINATION "${_platform_lib_extractdir}" | |
| PATTERNS ${_platform_lib_patterns} | |
| # Rebuild the compiler bundle even if package timestamps predate it. | |
| TOUCH | |
| ) | |
| foreach(_amd_lib_name ${_amd_required_libs}) | |
| if(NOT EXISTS "${_platform_lib_srcdir}/${_amd_lib_name}") | |
| message(FATAL_ERROR "ROCm package is missing required device bitcode: ${_amd_lib_name}") | |
| endif() | |
| endforeach() | |
| file(REMOVE "${_platform_lib_extractdir}/${_amd_device_bc_payload}") | |
| file(WRITE "${_fetch_stamp_file}" "${_amd_device_bc_stamp}") | |
| else() | |
| message(STATUS "Already fetched AMD Device bitcode into ${_platform_lib_srcdir}") | |
| endif() | |
| endif() | |
| # Set up copy rules. | |
| set(_platform_lib_reldir "iree_platform_libs/rocm") | |
| set(_platform_lib_absdir "${IREE_COMPILER_DYLIB_DIR}/${_platform_lib_reldir}") | |
| file(MAKE_DIRECTORY "${_platform_lib_absdir}") | |
| set(_all_device_bc_copy_commands) | |
| set(_all_device_bc_files) | |
| set(_all_device_bc_deps) | |
| foreach(_amd_lib_name ${_amd_required_libs}) | |
| # Copy to lib/ tree. | |
| set(_device_bc_srcpath "${_platform_lib_srcdir}/${_amd_lib_name}") | |
| set(_device_bc_relpath "${_platform_lib_reldir}/${_amd_lib_name}") | |
| list(APPEND _all_device_bc_files "${IREE_COMPILER_DYLIB_DIR}/${_device_bc_relpath}") | |
| list(APPEND _all_device_bc_deps "${_device_bc_srcpath}") | |
| list(APPEND _all_device_bc_copy_commands | |
| COMMAND ${CMAKE_COMMAND} -E copy | |
| "${_device_bc_srcpath}" | |
| "${IREE_COMPILER_DYLIB_DIR}/${_device_bc_relpath}" | |
| ) | |
| # Note this bc file as being part of the bundle that must be included with | |
| # the compiler dylib. | |
| set_property(GLOBAL APPEND PROPERTY IREE_COMPILER_DYLIB_RELPATHS "${_device_bc_relpath}") | |
| endforeach() | |
| # Generate a custom target with all file level dependencies and commands to | |
| # copy to our build tree locations. | |
| # Our GenDeviceLibs target depends on all of the defined device lib targets. | |
| add_custom_command( | |
| OUTPUT ${_all_device_bc_files} | |
| DEPENDS ${_all_device_bc_deps} | |
| COMMAND ${_all_device_bc_copy_commands} | |
| ) | |
| add_custom_target(iree_compiler_plugins_target_ROCM_GenDeviceLibs | |
| DEPENDS | |
| ${_all_device_bc_files} | |
| ) | |
| # Ensure that the device libs are built when the compiler dylib is built. | |
| set_property(GLOBAL APPEND PROPERTY IREE_COMPILER_DEPENDS | |
| iree_compiler_plugins_target_ROCM_GenDeviceLibs) | |
| # Install. | |
| install(FILES ${_all_device_bc_files} | |
| DESTINATION "${IREE_COMPILER_DYLIB_INSTALL_PREFIX}/${_platform_lib_reldir}") |