Removing extraneous iree/hal/drivers/utils. (#18050)
We want to keep the total number of targets reasonable and having a new
target for a single helper is not worth the cost. We also already have a
utils directory meant for HAL implementations to use and it should have
been in there. Since this method is simple it's been added to the core
HAL header (usually not preferred, but in the case of semaphore_list its
a basic utility and not a vtabled type that will have different behavior
between implementations).
diff --git a/runtime/src/iree/hal/drivers/CMakeLists.txt b/runtime/src/iree/hal/drivers/CMakeLists.txt
index 0fca062..b193b99 100644
--- a/runtime/src/iree/hal/drivers/CMakeLists.txt
+++ b/runtime/src/iree/hal/drivers/CMakeLists.txt
@@ -123,8 +123,6 @@
)
endif()
-add_subdirectory(utils)
-
set(_INIT_INTERNAL_DEPS)
if(IREE_HAL_DRIVER_CUDA)
add_subdirectory(cuda)
diff --git a/runtime/src/iree/hal/drivers/cuda/BUILD.bazel b/runtime/src/iree/hal/drivers/cuda/BUILD.bazel
index 96ebe36..89fbe0a 100644
--- a/runtime/src/iree/hal/drivers/cuda/BUILD.bazel
+++ b/runtime/src/iree/hal/drivers/cuda/BUILD.bazel
@@ -64,7 +64,6 @@
"//runtime/src/iree/base/internal:wait_handle",
"//runtime/src/iree/base/internal/flatcc:parsing",
"//runtime/src/iree/hal",
- "//runtime/src/iree/hal/drivers/utils",
"//runtime/src/iree/hal/utils:collective_batch",
"//runtime/src/iree/hal/utils:deferred_command_buffer",
"//runtime/src/iree/hal/utils:file_transfer",
diff --git a/runtime/src/iree/hal/drivers/cuda/CMakeLists.txt b/runtime/src/iree/hal/drivers/cuda/CMakeLists.txt
index 1c96849..ebf5386 100644
--- a/runtime/src/iree/hal/drivers/cuda/CMakeLists.txt
+++ b/runtime/src/iree/hal/drivers/cuda/CMakeLists.txt
@@ -61,7 +61,6 @@
iree::base::internal::threading
iree::base::internal::wait_handle
iree::hal
- iree::hal::drivers::utils
iree::hal::utils::collective_batch
iree::hal::utils::deferred_command_buffer
iree::hal::utils::file_transfer
diff --git a/runtime/src/iree/hal/drivers/cuda/pending_queue_actions.c b/runtime/src/iree/hal/drivers/cuda/pending_queue_actions.c
index b49c116..42f1f86 100644
--- a/runtime/src/iree/hal/drivers/cuda/pending_queue_actions.c
+++ b/runtime/src/iree/hal/drivers/cuda/pending_queue_actions.c
@@ -23,7 +23,6 @@
#include "iree/hal/drivers/cuda/event_semaphore.h"
#include "iree/hal/drivers/cuda/graph_command_buffer.h"
#include "iree/hal/drivers/cuda/stream_command_buffer.h"
-#include "iree/hal/drivers/utils/semaphore.h"
#include "iree/hal/utils/deferred_command_buffer.h"
#include "iree/hal/utils/resource_set.h"
@@ -867,8 +866,7 @@
if (value >= values[i]) {
// No need to wait on this timepoint as it has already occurred and
// we can remove it from the wait list.
- iree_hal_semaphore_list_remove_element(&action->wait_semaphore_list,
- i);
+ iree_hal_semaphore_list_erase(&action->wait_semaphore_list, i);
--i;
continue;
}
@@ -899,7 +897,7 @@
// Remove the wait timepoint as we have a corresponding event that we
// will wait on.
- iree_hal_semaphore_list_remove_element(&action->wait_semaphore_list, i);
+ iree_hal_semaphore_list_erase(&action->wait_semaphore_list, i);
--i;
}
}
diff --git a/runtime/src/iree/hal/drivers/hip/CMakeLists.txt b/runtime/src/iree/hal/drivers/hip/CMakeLists.txt
index 6e7b41c..d20e777 100644
--- a/runtime/src/iree/hal/drivers/hip/CMakeLists.txt
+++ b/runtime/src/iree/hal/drivers/hip/CMakeLists.txt
@@ -67,7 +67,6 @@
iree::base::internal::wait_handle
iree::base::internal::flatcc::parsing
iree::hal
- iree::hal::drivers::utils
iree::hal::utils::collective_batch
iree::hal::utils::deferred_command_buffer
iree::hal::utils::file_transfer
diff --git a/runtime/src/iree/hal/drivers/hip/pending_queue_actions.c b/runtime/src/iree/hal/drivers/hip/pending_queue_actions.c
index 33bfcd7..be52cb3 100644
--- a/runtime/src/iree/hal/drivers/hip/pending_queue_actions.c
+++ b/runtime/src/iree/hal/drivers/hip/pending_queue_actions.c
@@ -23,7 +23,6 @@
#include "iree/hal/drivers/hip/hip_device.h"
#include "iree/hal/drivers/hip/status_util.h"
#include "iree/hal/drivers/hip/stream_command_buffer.h"
-#include "iree/hal/drivers/utils/semaphore.h"
#include "iree/hal/utils/deferred_command_buffer.h"
#include "iree/hal/utils/resource_set.h"
@@ -1106,8 +1105,7 @@
if (value >= values[i]) {
// No need to wait on this timepoint as it has already occurred and
// we can remove it from the wait list.
- iree_hal_semaphore_list_remove_element(&action->wait_semaphore_list,
- i);
+ iree_hal_semaphore_list_erase(&action->wait_semaphore_list, i);
--i;
continue;
}
@@ -1138,7 +1136,7 @@
// Remove the wait timepoint as we have a corresponding event that we
// will wait on.
- iree_hal_semaphore_list_remove_element(&action->wait_semaphore_list, i);
+ iree_hal_semaphore_list_erase(&action->wait_semaphore_list, i);
--i;
}
}
diff --git a/runtime/src/iree/hal/drivers/utils/BUILD.bazel b/runtime/src/iree/hal/drivers/utils/BUILD.bazel
deleted file mode 100644
index e8b5ed9..0000000
--- a/runtime/src/iree/hal/drivers/utils/BUILD.bazel
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright 2024 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library")
-
-package(
- default_visibility = ["//visibility:public"],
- features = ["layering_check"],
- licenses = ["notice"], # Apache 2.0
-)
-
-iree_runtime_cc_library(
- name = "utils",
- hdrs = ["semaphore.h"],
- deps = [
- "//runtime/src/iree/base",
- "//runtime/src/iree/hal",
- ],
-)
diff --git a/runtime/src/iree/hal/drivers/utils/CMakeLists.txt b/runtime/src/iree/hal/drivers/utils/CMakeLists.txt
deleted file mode 100644
index fea8d66..0000000
--- a/runtime/src/iree/hal/drivers/utils/CMakeLists.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-################################################################################
-# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from #
-# runtime/src/iree/hal/drivers/utils/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
- utils
- HDRS
- "semaphore.h"
- DEPS
- iree::base
- iree::hal
- PUBLIC
-)
-
-### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
diff --git a/runtime/src/iree/hal/drivers/utils/semaphore.h b/runtime/src/iree/hal/drivers/utils/semaphore.h
deleted file mode 100644
index 797da77..0000000
--- a/runtime/src/iree/hal/drivers/utils/semaphore.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2024 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef IREE_HAL_DRIVERS_UTILS_SEMAPHORE_INTERNAL_H_
-#define IREE_HAL_DRIVERS_UTILS_SEMAPHORE_INTERNAL_H_
-
-#include "iree/base/api.h"
-#include "iree/hal/semaphore.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-static inline void iree_hal_semaphore_list_swap_elements(
- iree_hal_semaphore_list_t* semaphore_list, iree_host_size_t i,
- iree_host_size_t j) {
- IREE_ASSERT(i >= 0 && i < semaphore_list->count);
- IREE_ASSERT(j >= 0 && j < semaphore_list->count);
-
- if (IREE_UNLIKELY(i == j)) {
- return;
- }
-
- iree_hal_semaphore_t* tmp_semaphore = semaphore_list->semaphores[i];
- uint64_t tmp_payload_value = semaphore_list->payload_values[i];
-
- semaphore_list->semaphores[i] = semaphore_list->semaphores[j];
- semaphore_list->payload_values[i] = semaphore_list->payload_values[j];
-
- semaphore_list->semaphores[j] = tmp_semaphore;
- semaphore_list->payload_values[j] = tmp_payload_value;
-}
-
-// Swap i-th element with the last and then remove the last.
-static inline void iree_hal_semaphore_list_remove_element(
- iree_hal_semaphore_list_t* semaphore_list, iree_host_size_t i) {
- iree_hal_semaphore_list_swap_elements(semaphore_list, i,
- semaphore_list->count - 1);
- --semaphore_list->count;
-}
-
-#ifdef __cplusplus
-} // extern "C"
-#endif // __cplusplus
-
-#endif // IREE_HAL_DRIVERS_UTILS_SEMAPHORE_INTERNAL_H_
diff --git a/runtime/src/iree/hal/semaphore.c b/runtime/src/iree/hal/semaphore.c
index b71caa9..b34d1f2 100644
--- a/runtime/src/iree/hal/semaphore.c
+++ b/runtime/src/iree/hal/semaphore.c
@@ -206,3 +206,30 @@
IREE_TRACE_ZONE_END(z0);
return status;
}
+
+static void iree_hal_semaphore_list_swap_elements(
+ iree_hal_semaphore_list_t* semaphore_list, iree_host_size_t i,
+ iree_host_size_t j) {
+ IREE_ASSERT(i >= 0 && i < semaphore_list->count);
+ IREE_ASSERT(j >= 0 && j < semaphore_list->count);
+ if (IREE_UNLIKELY(i == j)) {
+ return;
+ }
+
+ iree_hal_semaphore_t* tmp_semaphore = semaphore_list->semaphores[i];
+ uint64_t tmp_payload_value = semaphore_list->payload_values[i];
+
+ semaphore_list->semaphores[i] = semaphore_list->semaphores[j];
+ semaphore_list->payload_values[i] = semaphore_list->payload_values[j];
+
+ semaphore_list->semaphores[j] = tmp_semaphore;
+ semaphore_list->payload_values[j] = tmp_payload_value;
+}
+
+IREE_API_EXPORT void iree_hal_semaphore_list_erase(
+ iree_hal_semaphore_list_t* semaphore_list, iree_host_size_t i) {
+ IREE_ASSERT(semaphore_list->count > 0);
+ iree_hal_semaphore_list_swap_elements(semaphore_list, i,
+ semaphore_list->count - 1);
+ --semaphore_list->count;
+}
diff --git a/runtime/src/iree/hal/semaphore.h b/runtime/src/iree/hal/semaphore.h
index b9263b2..ec0b9af 100644
--- a/runtime/src/iree/hal/semaphore.h
+++ b/runtime/src/iree/hal/semaphore.h
@@ -210,6 +210,11 @@
IREE_API_EXPORT void iree_hal_semaphore_destroy(
iree_hal_semaphore_t* semaphore);
+// Erases the i-th semaphore from the list in-place with O(1).
+// Expects that the index |i| is in bounds.
+IREE_API_EXPORT void iree_hal_semaphore_list_erase(
+ iree_hal_semaphore_list_t* semaphore_list, iree_host_size_t i);
+
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus