################################################################################
# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from           #
# runtime/src/iree/hal/drivers/amdgpu/util/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_cc_library(
  NAME
    libhsa
  HDRS
    "libhsa.h"
  TEXTUAL_HDRS
    "libhsa_tables.h"
  SRCS
    "libhsa.c"
  DEPS
    hsa_runtime::headers
    iree::base
    iree::base::internal
    iree::base::internal::dynamic_library
    iree::base::internal::path
  PUBLIC
)

iree_cc_test(
  NAME
    libhsa_test
  SRCS
    "libhsa_test.cc"
  DEPS
    ::libhsa
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_library(
  NAME
    topology
  HDRS
    "topology.h"
  SRCS
    "topology.c"
  DEPS
    ::libhsa
    iree::base
  PUBLIC
)

iree_cc_test(
  NAME
    topology_test
  SRCS
    "topology_test.cc"
  DEPS
    ::libhsa
    ::topology
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_library(
  NAME
    util
  HDRS
    "affinity.h"
    "block_pool.h"
    "device_library.h"
    "error_callback.h"
    "info.h"
    "kfd.h"
    "vmem.h"
  SRCS
    "block_pool.c"
    "device_library.c"
    "info.c"
    "kfd.c"
    "vmem.c"
  DEPS
    ::libhsa
    ::topology
    iree::base
    iree::base::internal
    iree::base::threading
    iree::base::threading::thread
    iree::hal::drivers::amdgpu::device::binaries
    iree::hal::drivers::amdgpu::device::headers
  PUBLIC
)

iree_cc_test(
  NAME
    block_pool_test
  SRCS
    "block_pool_test.cc"
  DEPS
    ::topology
    ::util
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_test(
  NAME
    device_library_test
  SRCS
    "device_library_test.cc"
  DEPS
    ::topology
    ::util
    iree::base
    iree::hal::drivers::amdgpu::device::headers
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_test(
  NAME
    kfd_test
  SRCS
    "kfd_test.cc"
  DEPS
    ::libhsa
    ::topology
    ::util
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_test(
  NAME
    vmem_test
  SRCS
    "vmem_test.cc"
  DEPS
    ::libhsa
    ::topology
    ::util
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###

# Enable statically linking against ROCR-Runtime.
# The resulting application binary will initialize the runtime at startup and
# may fail to work on any machine without a modern ROCM driver. Avoid using this
# unless it is known that the deployment is always on an up-to-date AMDGPU
# device.
option(IREE_HAL_AMDGPU_LIBHSA_STATIC
       "Statically link against the installed hsa-runtime64 package."
       OFF)

if(IREE_HAL_AMDGPU_LIBHSA_STATIC)
  find_package(hsa-runtime64 1.0 REQUIRED)
  target_compile_options(iree_hal_drivers_amdgpu_util_libhsa
    PUBLIC
      "-DIREE_HAL_AMDGPU_LIBHSA_STATIC=1"
  )
  target_link_libraries(iree_hal_drivers_amdgpu_util_libhsa
    PRIVATE
      hsa-runtime64::hsa-runtime64
  )
endif()
