Removing quite a bit of absl from iree/. (#6256)
The remaining usage after this is all Status/StatusOr-related.
diff --git a/bindings/python/iree/runtime/CMakeLists.txt b/bindings/python/iree/runtime/CMakeLists.txt
index 8d2f26e..0185f8c 100644
--- a/bindings/python/iree/runtime/CMakeLists.txt
+++ b/bindings/python/iree/runtime/CMakeLists.txt
@@ -27,10 +27,7 @@
iree::modules::hal
iree::vm
iree::vm::bytecode_module
- absl::inlined_vector
- absl::strings
absl::optional
- absl::span
)
iree_py_library(
diff --git a/bindings/python/iree/runtime/hal.cc b/bindings/python/iree/runtime/hal.cc
index e75cfc5..4a5994c 100644
--- a/bindings/python/iree/runtime/hal.cc
+++ b/bindings/python/iree/runtime/hal.cc
@@ -6,7 +6,6 @@
#include "bindings/python/iree/runtime/hal.h"
-#include "absl/container/inlined_vector.h"
#include "iree/hal/api.h"
namespace iree {
diff --git a/bindings/python/iree/runtime/hal.h b/bindings/python/iree/runtime/hal.h
index c42479e..d25c5a6 100644
--- a/bindings/python/iree/runtime/hal.h
+++ b/bindings/python/iree/runtime/hal.h
@@ -7,7 +7,8 @@
#ifndef IREE_BINDINGS_PYTHON_IREE_RT_HAL_H_
#define IREE_BINDINGS_PYTHON_IREE_RT_HAL_H_
-#include "absl/container/inlined_vector.h"
+#include <vector>
+
#include "bindings/python/iree/runtime/binding.h"
#include "bindings/python/iree/runtime/status_utils.h"
#include "iree/hal/api.h"
@@ -74,7 +75,7 @@
return s;
}
- absl::InlinedVector<int32_t, 6> s;
+ std::vector<int32_t> s;
};
class HalBufferView
@@ -140,18 +141,18 @@
}
py::buffer_info ToBufferInfo() {
- absl::InlinedVector<int32_t, 6> shape(iree_hal_buffer_view_shape_rank(bv_));
+ std::vector<int32_t> shape(iree_hal_buffer_view_shape_rank(bv_));
CheckApiStatus(
iree_hal_buffer_view_shape(bv_, shape.size(), shape.data(), nullptr),
"Error getting buffer view shape");
iree_hal_element_type_t element_type =
iree_hal_buffer_view_element_type(bv_);
int32_t element_size = iree_hal_element_byte_count(element_type);
- absl::InlinedVector<py::ssize_t, 6> dims(shape.size());
+ std::vector<py::ssize_t> dims(shape.size());
for (int i = 0; i < shape.size(); ++i) {
dims[i] = shape[i];
}
- absl::InlinedVector<py::ssize_t, 8> strides(shape.size());
+ std::vector<py::ssize_t> strides(shape.size());
if (!strides.empty()) {
strides[shape.size() - 1] = element_size;
for (int i = shape.size() - 2; i >= 0; --i) {
diff --git a/bindings/python/iree/runtime/status_utils.cc b/bindings/python/iree/runtime/status_utils.cc
index 545f62d..30239fb 100644
--- a/bindings/python/iree/runtime/status_utils.cc
+++ b/bindings/python/iree/runtime/status_utils.cc
@@ -6,8 +6,6 @@
#include "bindings/python/iree/runtime/status_utils.h"
-#include "absl/strings/str_cat.h"
-
namespace iree {
namespace python {
@@ -36,12 +34,12 @@
char* iree_message;
size_t iree_message_length;
if (iree_status_to_string(status, &iree_message, &iree_message_length)) {
- full_message = absl::StrCat(
- message, ": ", absl::string_view(iree_message, iree_message_length));
+ full_message = std::string(message) + ": " +
+ std::string(iree_message, iree_message_length);
iree_allocator_free(iree_allocator_system(), iree_message);
} else {
- full_message = absl::StrCat(
- message, ": ", iree_status_code_string(iree_status_code(status)));
+ full_message = std::string(message) + ": " +
+ iree_status_code_string(iree_status_code(status));
}
PyErr_SetString(ApiStatusToPyExcClass(status), full_message.c_str());
diff --git a/bindings/python/iree/runtime/vm.cc b/bindings/python/iree/runtime/vm.cc
index 325ba1f..9eb53f7 100644
--- a/bindings/python/iree/runtime/vm.cc
+++ b/bindings/python/iree/runtime/vm.cc
@@ -6,8 +6,6 @@
#include "bindings/python/iree/runtime/vm.h"
-#include "absl/strings/str_cat.h"
-#include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include "bindings/python/iree/runtime/status_utils.h"
#include "iree/base/api.h"
@@ -86,7 +84,7 @@
CheckApiStatus(status, "Error creating vm context");
} else {
// Closed set of modules.
- absl::InlinedVector<iree_vm_module_t*, 8> module_handles;
+ std::vector<iree_vm_module_t*> module_handles;
module_handles.resize(modules->size());
for (size_t i = 0, e = module_handles.size(); i < e; ++i) {
module_handles[i] = (*modules)[i]->raw_ptr();
@@ -102,7 +100,7 @@
}
void VmContext::RegisterModules(std::vector<VmModule*> modules) {
- absl::InlinedVector<iree_vm_module_t*, 8> module_handles;
+ std::vector<iree_vm_module_t*> module_handles;
module_handles.resize(modules.size());
for (size_t i = 0, e = module_handles.size(); i < e; ++i) {
module_handles[i] = modules[i]->raw_ptr();
@@ -392,6 +390,20 @@
namespace {
+static std::string ToHexString(const uint8_t* data, size_t length) {
+ static constexpr char kHexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+ std::string s(length * 2, ' ');
+ for (size_t i = 0; i < length; ++i) {
+ s[2 * i + 0] = kHexChars[(data[i] & 0xF0) >> 4];
+ s[2 * i + 1] = kHexChars[(data[i] & 0x0F) >> 0];
+ }
+ return s;
+}
+static std::string ToHexString(uint32_t value) {
+ return ToHexString((const uint8_t*)&value, sizeof(value));
+}
+
void AppendListContents(std::string& out, iree_vm_list_t* list,
std::unordered_set<iree_vm_list_t*>& visited) {
for (iree_host_size_t i = 0, e = iree_vm_list_size(list); i < e; ++i) {
@@ -405,24 +417,27 @@
if (i > 0) out.append(", ");
if (iree_vm_variant_is_value(variant)) {
- absl::StrAppend(&out, variant.i32);
+ out += std::to_string(variant.i32);
} else if (iree_vm_variant_is_ref(variant)) {
// Pretty print a subset of ABI impacting known types.
if (iree_hal_buffer_isa(variant.ref)) {
auto* hal_buffer = iree_hal_buffer_deref(variant.ref);
assert(hal_buffer);
- absl::StrAppend(&out, "HalBuffer(",
- iree_hal_buffer_byte_length(hal_buffer), ")");
+ out += std::string("HalBuffer(") +
+ std::to_string(iree_hal_buffer_byte_length(hal_buffer)) + ")";
} else if (iree_hal_buffer_view_isa(variant.ref)) {
auto hal_bv = iree_hal_buffer_view_deref(variant.ref);
- absl::StrAppend(&out, "HalBufferView(");
- absl::InlinedVector<int32_t, 5> shape(
- iree_hal_buffer_view_shape_rank(hal_bv));
+ out += "HalBufferView(";
+ std::vector<int32_t> shape(iree_hal_buffer_view_shape_rank(hal_bv));
iree_hal_buffer_view_shape(hal_bv, shape.size(), shape.data(), nullptr);
- absl::StrAppend(&out, absl::StrJoin(shape, "x"), ":0x",
- absl::Hex(static_cast<uint32_t>(
- iree_hal_buffer_view_element_type(hal_bv))),
- ")");
+ for (size_t i = 0; i < shape.size(); ++i) {
+ if (i > 0) out += 'x';
+ out += std::to_string(shape[i]);
+ }
+ out += ":0x" +
+ ToHexString(static_cast<uint32_t>(
+ iree_hal_buffer_view_element_type(hal_bv))) +
+ ")";
} else if (iree_vm_list_isa(variant.ref)) {
out.append("List[");
iree_vm_list_t* sub_list = iree_vm_list_deref(variant.ref);
@@ -433,7 +448,7 @@
}
out.append("]");
} else {
- absl::StrAppend(&out, "Unknown(", variant.type.ref_type, ")");
+ out += "Unknown(" + std::to_string(variant.type.ref_type) + ")";
}
} else {
out.append("None");
@@ -447,8 +462,8 @@
// The variant list API requires mutability, so we const cast to it internally
// so we can maintain a const DebugString() for callers.
auto mutable_this = const_cast<VmVariantList*>(this);
- std::string s;
- absl::StrAppend(&s, "<VmVariantList(", size(), "): [");
+ std::string s =
+ std::string("<VmVariantList(") + std::to_string(size()) + "): [";
iree_vm_list_t* list = mutable_this->raw_ptr();
std::unordered_set<iree_vm_list_t*> visited;
visited.insert(list);