Allow defining `IREE_HOST_SIZE_T` to other types. (#14040)
I tried redefining these:
```c
// iree/base/config.h
#if !defined(IREE_HOST_SIZE_T)
#define IREE_HOST_SIZE_T size_t
#define PRIhsz "zu"
#endif // !IREE_HOST_SIZE_T
```
to `uint32_t` and `PRIu32` while debugging some issues with Emscripten
builds, but many parts of the project failed to build.
`IREE_HOST_SIZE_T` should really be set to `size_t` in most/all cases,
but the project should still build if someone wants to redefine it.
Some cases were obviously using the wrong format specifier (e.g. `zu`
instead of `PRIhsz`), but other were more subtle (e.g. interop between
`std::string` with `iree_string_view_t` or using `SIZE_MAX` instead of
`IREE_HOST_SIZE_MAX`). I tried to update as many places as I could
safely.
diff --git a/experimental/webgpu/command_buffer.c b/experimental/webgpu/command_buffer.c
index b5d783d..84af3a1 100644
--- a/experimental/webgpu/command_buffer.c
+++ b/experimental/webgpu/command_buffer.c
@@ -746,7 +746,8 @@
if (IREE_UNLIKELY(offset + values_length >=
sizeof(command_buffer->state.push_constants))) {
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
- "push constant range %zu (length=%zu) out of range",
+ "push constant range %" PRIhsz " (length=%" PRIhsz
+ ") out of range",
offset, values_length);
}
diff --git a/experimental/webgpu/executable.c b/experimental/webgpu/executable.c
index 87da423..f9a0fe9 100644
--- a/experimental/webgpu/executable.c
+++ b/experimental/webgpu/executable.c
@@ -38,7 +38,8 @@
if (!flatbuffer_data.data || flatbuffer_data.data_length < 16) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
- "flatbuffer data is not present or less than 16 bytes (%zu total)",
+ "flatbuffer data is not present or less than 16 bytes (%" PRIhsz
+ " total)",
flatbuffer_data.data_length);
}
@@ -77,17 +78,17 @@
if (entry_point_count != expected_entry_point_count) {
return iree_make_status(IREE_STATUS_FAILED_PRECONDITION,
"executable provides %zu entry points but caller "
- "provided %zu; must match",
+ "provided %" PRIhsz "; must match",
entry_point_count, expected_entry_point_count);
}
for (size_t i = 0; i < entry_point_count; ++i) {
uint32_t module_ordinal = flatbuffers_uint32_vec_at(entry_points_vec, i);
if (module_ordinal >= shader_module_count) {
- return iree_make_status(
- IREE_STATUS_INVALID_ARGUMENT,
- "executable entry point %zu references an invalid shader module %d",
- i, module_ordinal);
+ return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
+ "executable entry point %zu"
+ " references an invalid shader module %d",
+ i, module_ordinal);
}
}
diff --git a/experimental/webgpu/pipeline_layout.c b/experimental/webgpu/pipeline_layout.c
index e271cfd..a5c940c 100644
--- a/experimental/webgpu/pipeline_layout.c
+++ b/experimental/webgpu/pipeline_layout.c
@@ -55,7 +55,7 @@
IREE_TRACE_ZONE_END(z0);
return iree_make_status(IREE_STATUS_OUT_OF_RANGE,
"bindings must be in the range of 0-%d; binding "
- "%zu is has ordinal %d",
+ "%" PRIhsz " is has ordinal %d",
IREE_HAL_WEBGPU_MAX_DESCRIPTOR_SET_BINDING_COUNT,
i, bindings[i].binding);
}
diff --git a/experimental/webgpu/simple_allocator.c b/experimental/webgpu/simple_allocator.c
index ddd88ea..20fabca 100644
--- a/experimental/webgpu/simple_allocator.c
+++ b/experimental/webgpu/simple_allocator.c
@@ -128,7 +128,7 @@
static iree_status_t iree_hal_webgpu_simple_allocator_allocate_buffer(
iree_hal_allocator_t* IREE_RESTRICT base_allocator,
const iree_hal_buffer_params_t* IREE_RESTRICT params,
- iree_host_size_t allocation_size, iree_const_byte_span_t initial_data,
+ iree_device_size_t allocation_size, iree_const_byte_span_t initial_data,
iree_hal_buffer_t** IREE_RESTRICT out_buffer) {
IREE_ASSERT_ARGUMENT(base_allocator);
IREE_ASSERT_ARGUMENT(params);
diff --git a/experimental/webgpu/staging_buffer.c b/experimental/webgpu/staging_buffer.c
index 36e5582..d9181e8 100644
--- a/experimental/webgpu/staging_buffer.c
+++ b/experimental/webgpu/staging_buffer.c
@@ -26,8 +26,8 @@
if ((host_buffer_capacity % limits->minUniformBufferOffsetAlignment) != 0) {
IREE_TRACE_ZONE_END(z0);
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
- "host buffer capacity (%zu) must match the buffer "
- "offset alignment (%d)",
+ "host buffer capacity (%" PRIhsz
+ ") must match the buffer offset alignment (%d)",
host_buffer_capacity,
limits->minUniformBufferOffsetAlignment);
}