################################################################################
# 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_library(
  NAME
    libaqlprofile
  HDRS
    "libaqlprofile.h"
  SRCS
    "libaqlprofile.c"
  DEPS
    ::libhsa
    hsa_runtime::headers
    iree::base
    iree::base::internal
    iree::base::internal::dynamic_library
    iree::base::internal::path
    iree::hal::drivers::amdgpu::abi
  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_test(
  NAME
    libaqlprofile_test
  SRCS
    "libaqlprofile_test.cc"
  DEPS
    ::libaqlprofile
    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
    iree::hal
  PUBLIC
)

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

iree_cc_library(
  NAME
    hsaco_metadata
  HDRS
    "hsaco_metadata.h"
  SRCS
    "hsaco_metadata.c"
  DEPS
    iree::base
    iree::hal
  PUBLIC
)

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

iree_cc_fuzz(
  NAME
    hsaco_metadata_fuzz
  SRCS
    "hsaco_metadata_fuzz.cc"
  DEPS
    ::hsaco_metadata
    iree::base
)

iree_cc_library(
  NAME
    affinity
  HDRS
    "affinity.h"
  DEPS
    iree::base::internal
  PUBLIC
)

iree_cc_library(
  NAME
    packet
  HDRS
    "aql_emitter.h"
    "pm4_barrier.h"
    "pm4_capabilities.h"
    "pm4_emitter.h"
  DEPS
    iree::base
    iree::hal::drivers::amdgpu::abi
  PUBLIC
)

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

iree_cc_library(
  NAME
    target_id
  HDRS
    "target_id.h"
  TEXTUAL_HDRS
    "target_id_map.inl"
  SRCS
    "target_id.c"
  DEPS
    iree::base
  PUBLIC
)

iree_cc_library(
  NAME
    code_object_target
  HDRS
    "code_object_target.h"
  SRCS
    "code_object_target.c"
  DEPS
    ::target_id
    iree::base
    iree::base::core_headers
    iree::hal::utils::elf_format
  PUBLIC
)

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

iree_cc_library(
  NAME
    device_clock
  HDRS
    "device_clock.h"
  SRCS
    "device_clock.c"
  DEPS
    ::kfd
    iree::base
  PUBLIC
)

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

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

iree_cc_library(
  NAME
    pm4_dispatch
  HDRS
    "pm4_dispatch.h"
  SRCS
    "pm4_dispatch.c"
  DEPS
    ::packet
    iree::base
    iree::hal::drivers::amdgpu::abi
  PUBLIC
)

iree_cc_library(
  NAME
    queue_primitives
  HDRS
    "aql_ring.h"
    "epoch_signal_table.h"
    "error_callback.h"
    "kernarg_ring.h"
    "notification_ring.h"
    "queue_upload_ring.h"
    "signal_pool.h"
  SRCS
    "kernarg_ring.c"
    "notification_ring.c"
    "queue_upload_ring.c"
    "signal_pool.c"
  DEPS
    ::libhsa
    iree::async
    iree::base
    iree::base::internal
    iree::base::internal::arena
    iree::base::threading
    iree::hal
    iree::hal::utils::resource_set
  PUBLIC
)

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

iree_cc_library(
  NAME
    block_pool
  HDRS
    "block_pool.h"
  SRCS
    "block_pool.c"
  DEPS
    ::libhsa
    iree::base
    iree::base::threading
    iree::hal::memory::tracing
  PUBLIC
)

iree_cc_library(
  NAME
    device_library
  HDRS
    "device_library.h"
  SRCS
    "device_library.c"
  DEPS
    ::device_library_target
    ::libhsa
    ::topology
    iree::base
    iree::base::internal
    iree::hal::drivers::amdgpu::device::binaries::toc
    iree::hal::drivers::amdgpu::device::headers
  PUBLIC
)

iree_cc_library(
  NAME
    device_library_target
  HDRS
    "device_library_target.h"
  SRCS
    "device_library_target.c"
  DEPS
    ::target_id
    iree::base
  PUBLIC
)

iree_cc_library(
  NAME
    util
  DEPS
    ::affinity
    ::block_pool
    ::device_library
    ::device_library_target
    ::info
    ::kfd
    ::packet
    ::pm4_dispatch
    ::pm4_program
    ::queue_primitives
    ::target_id
    ::vmem
  PUBLIC
)

iree_cc_library(
  NAME
    benchmark_flags
  HDRS
    "benchmark_flags.h"
  SRCS
    "benchmark_flags.cc"
  DEPS
    benchmark
    iree::async
    iree::base
    iree::base::tooling::flags
  TESTONLY
  PUBLIC
)

iree_cc_library(
  NAME
    benchmark_profile
  HDRS
    "benchmark_profile.h"
  SRCS
    "benchmark_profile.cc"
  DEPS
    iree::base
    iree::hal
  TESTONLY
  PUBLIC
)

iree_cc_binary_benchmark(
  NAME
    blit_benchmark
  SRCS
    "blit_benchmark.cc"
  DEPS
    ::benchmark_flags
    benchmark
    iree::async
    iree::async::util::proactor_pool
    iree::base
    iree::base::threading
    iree::base::tooling::flags
    iree::hal
    iree::hal::drivers::amdgpu::registration
  TESTONLY
  LABELS
    "benchmark"
    "driver=amdgpu"
    "nodocker"
)

iree_cc_test(
  NAME
    block_pool_test
  SRCS
    "block_pool_test.cc"
  DEPS
    ::block_pool
    ::topology
    ::vmem
    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
    ::device_library
    ::topology
    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
    device_library_target_test
  SRCS
    "device_library_target_test.cc"
  DEPS
    ::device_library_target
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

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

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

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

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

iree_cc_test(
  NAME
    device_clock_test
  SRCS
    "device_clock_test.cc"
  DEPS
    ::device_clock
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
)

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

iree_cc_test(
  NAME
    notification_ring_test
  SRCS
    "notification_ring_test.cc"
  DEPS
    ::libhsa
    ::queue_primitives
    iree::async
    iree::async::platform
    iree::base
    iree::base::internal::arena
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

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

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

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

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

iree_amdgpu_binary(
  NAME
    pm4_dispatch_test_kernels_gfx1100
  TARGET
    amdgcn-amd-amdhsa
  ARCH
    gfx1100
  SRCS
    "pm4_dispatch_test_kernels.c"
  COPTS

  LINKOPTS

)

iree_cc_test(
  NAME
    pm4_dispatch_live_test
  SRCS
    "pm4_dispatch_live_test.cc"
  DATA
    ::pm4_dispatch_test_kernels_gfx1100.so
  DEPS
    ::libhsa
    ::packet
    ::pm4_dispatch
    ::pm4_program
    ::queue_primitives
    ::topology
    ::vmem
    iree::base
    iree::base::threading
    iree::hal::drivers::amdgpu::abi
    iree::io::file_handle
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_test(
  NAME
    pm4_program_test
  SRCS
    "pm4_program_test.cc"
  DEPS
    ::packet
    ::pm4_program
    ::topology
    ::vmem
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)
if(TARGET iree::hal::drivers::amdgpu::cts::testdata_amdgpu)
add_custom_command(OUTPUT queue_benchmark_testdata_srcs.stamp
    COMMAND ${CMAKE_COMMAND} -E touch queue_benchmark_testdata_srcs.stamp
  DEPENDS
    "queue_benchmark_testdata.mlir"
)

add_custom_target(queue_benchmark_testdata_srcs
    DEPENDS queue_benchmark_testdata_srcs.stamp
)

iree_hal_cts_testdata(
  FORMAT_NAME
    amdgpu_queue_benchmark
  TARGET_DEVICE
    "amdgpu"
  IDENTIFIER
    "iree_queue_benchmark_testdata_amdgpu"
  BACKEND_NAME
    "amdgpu"
  FORMAT_STRING
    "\"amdgcn-amd-amdhsa--${IREE_ROCM_TEST_TARGET_CHIP}\""
  TESTDATA_DIR
    "${PROJECT_SOURCE_DIR}/runtime/src/iree/hal/drivers/amdgpu/util"
  FLAGS
    "--iree-rocm-target=${IREE_ROCM_TEST_TARGET_CHIP}"
)

iree_cc_binary_benchmark(
  NAME
    queue_benchmark
  SRCS
    "queue_benchmark.cc"
  DEPS
    ::benchmark_flags
    ::testdata_amdgpu_queue_benchmark
    benchmark
    iree::async
    iree::async::util::proactor_pool
    iree::base
    iree::base::threading
    iree::base::tooling::flags
    iree::hal
    iree::hal::drivers::amdgpu
    iree::hal::drivers::amdgpu::cts::testdata_amdgpu
    iree::hal::drivers::amdgpu::device::dispatch
    iree::hal::drivers::amdgpu::device::headers
    iree::hal::drivers::amdgpu::headers
    iree::hal::drivers::amdgpu::queue_affinity
    iree::hal::drivers::amdgpu::registration
    iree::hal::memory::tlsf_pool
    iree::io::file_handle
  TESTONLY
  LABELS
    "benchmark"
    "driver=amdgpu"
    "nodocker"
)
endif()
iree_cc_test(
  NAME
    signal_pool_test
  SRCS
    "signal_pool_test.cc"
  DEPS
    ::libhsa
    ::queue_primitives
    ::topology
    iree::base
    iree::testing::gtest
    iree::testing::gtest_main
  LABELS
    "driver=amdgpu"
    "nodocker"
  GROUP
    "iree-hal-drivers-amdgpu-tests"
)

iree_cc_binary_benchmark(
  NAME
    signal_pool_benchmark
  SRCS
    "signal_pool_benchmark.cc"
  DEPS
    ::libhsa
    ::queue_primitives
    ::topology
    benchmark
    iree::base
  TESTONLY
  LABELS
    "benchmark"
    "driver=amdgpu"
    "nodocker"
)

iree_cc_test(
  NAME
    vmem_test
  SRCS
    "vmem_test.cc"
  DEPS
    ::libhsa
    ::topology
    ::vmem
    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()
