[metal] Order host_allocator and const-ify various query APIs
We want to have `host_allocator` directly ahead of the `out_`
parameters.
diff --git a/experimental/metal/direct_command_buffer.h b/experimental/metal/direct_command_buffer.h
index 3c929e5..7ab8a6e 100644
--- a/experimental/metal/direct_command_buffer.h
+++ b/experimental/metal/direct_command_buffer.h
@@ -42,10 +42,10 @@
iree_host_size_t binding_capacity,
iree_hal_metal_command_buffer_resource_reference_mode_t
resource_reference_mode,
- id<MTLCommandQueue> queue, iree_allocator_t host_allocator,
- iree_arena_block_pool_t* block_pool,
+ id<MTLCommandQueue> queue, iree_arena_block_pool_t* block_pool,
iree_hal_metal_staging_buffer_t* staging_buffer,
iree_hal_metal_builtin_executable_t* builtin_executable,
+ iree_allocator_t host_allocator,
iree_hal_command_buffer_t** out_command_buffer);
// Returns true if |command_buffer| is a direct Metal command buffer.
@@ -55,7 +55,7 @@
// Returns the underlying Metal command buffer handle for the given
// |command_buffer|.
id<MTLCommandBuffer> iree_hal_metal_direct_command_buffer_handle(
- iree_hal_command_buffer_t* base_command_buffer);
+ const iree_hal_command_buffer_t* command_buffer);
#ifdef __cplusplus
} // extern "C"
diff --git a/experimental/metal/direct_command_buffer.m b/experimental/metal/direct_command_buffer.m
index 3fef89a..e937b49 100644
--- a/experimental/metal/direct_command_buffer.m
+++ b/experimental/metal/direct_command_buffer.m
@@ -232,10 +232,16 @@
return (iree_hal_metal_command_buffer_t*)base_value;
}
+static const iree_hal_metal_command_buffer_t* iree_hal_metal_command_buffer_const_cast(
+ const iree_hal_command_buffer_t* base_value) {
+ IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_metal_command_buffer_vtable);
+ return (const iree_hal_metal_command_buffer_t*)base_value;
+}
+
id<MTLCommandBuffer> iree_hal_metal_direct_command_buffer_handle(
- iree_hal_command_buffer_t* base_command_buffer) {
- iree_hal_metal_command_buffer_t* command_buffer =
- iree_hal_metal_command_buffer_cast(base_command_buffer);
+ const iree_hal_command_buffer_t* base_command_buffer) {
+ const iree_hal_metal_command_buffer_t* command_buffer =
+ iree_hal_metal_command_buffer_const_cast(base_command_buffer);
return command_buffer->command_buffer;
}
@@ -325,9 +331,9 @@
iree_hal_device_t* device, iree_hal_command_buffer_mode_t mode,
iree_hal_command_category_t command_categories, iree_host_size_t binding_capacity,
iree_hal_metal_command_buffer_resource_reference_mode_t resource_reference_mode,
- id<MTLCommandQueue> queue, iree_allocator_t host_allocator, iree_arena_block_pool_t* block_pool,
+ id<MTLCommandQueue> queue, iree_arena_block_pool_t* block_pool,
iree_hal_metal_staging_buffer_t* staging_buffer,
- iree_hal_metal_builtin_executable_t* builtin_executable,
+ iree_hal_metal_builtin_executable_t* builtin_executable, iree_allocator_t host_allocator,
iree_hal_command_buffer_t** out_command_buffer) {
IREE_ASSERT_ARGUMENT(device);
IREE_ASSERT_ARGUMENT(out_command_buffer);
@@ -842,7 +848,7 @@
}
static inline MTLResourceUsage iree_hal_metal_get_metal_resource_usage(
- iree_hal_descriptor_set_layout_binding_t* binding) {
+ const iree_hal_descriptor_set_layout_binding_t* binding) {
MTLResourceUsage usage = MTLResourceUsageRead;
if (binding->flags != IREE_HAL_DESCRIPTOR_FLAG_READ_ONLY) usage |= MTLResourceUsageWrite;
return usage;
@@ -870,7 +876,7 @@
command_buffer->state.descriptor_sets[i].active_count = 0;
}
- iree_hal_descriptor_set_layout_t* set_layout =
+ const iree_hal_descriptor_set_layout_t* set_layout =
iree_hal_metal_pipeline_layout_descriptor_set_layout(pipeline_layout, set);
iree_hal_metal_descriptor_t* descriptors = command_buffer->state.descriptor_sets[set].bindings;
@@ -884,7 +890,7 @@
descriptor->buffer = bindings[i].buffer;
descriptor->offset = bindings[i].offset;
- iree_hal_descriptor_set_layout_binding_t* binding_params =
+ const iree_hal_descriptor_set_layout_binding_t* binding_params =
iree_hal_metal_descriptor_set_layout_binding(set_layout, descriptor->binding);
descriptor->usage = iree_hal_metal_get_metal_resource_usage(binding_params);
}
diff --git a/experimental/metal/metal_device.m b/experimental/metal/metal_device.m
index 70a775f..bcbeb37 100644
--- a/experimental/metal/metal_device.m
+++ b/experimental/metal/metal_device.m
@@ -242,8 +242,9 @@
iree_status_t status = iree_hal_metal_direct_command_buffer_create(
base_device, mode, command_categories, binding_capacity,
- device->command_buffer_resource_reference_mode, device->queue, device->host_allocator,
- &device->block_pool, &device->staging_buffer, device->builtin_executable, out_command_buffer);
+ device->command_buffer_resource_reference_mode, device->queue, &device->block_pool,
+ &device->staging_buffer, device->builtin_executable, device->host_allocator,
+ out_command_buffer);
if (iree_status_is_ok(status)) {
iree_hal_metal_staging_buffer_increase_refcount(&device->staging_buffer);
}
@@ -255,8 +256,8 @@
iree_host_size_t binding_count, const iree_hal_descriptor_set_layout_binding_t* bindings,
iree_hal_descriptor_set_layout_t** out_descriptor_set_layout) {
iree_hal_metal_device_t* device = iree_hal_metal_device_cast(base_device);
- return iree_hal_metal_descriptor_set_layout_create(device->host_allocator, flags, binding_count,
- bindings, out_descriptor_set_layout);
+ return iree_hal_metal_descriptor_set_layout_create(
+ flags, binding_count, bindings, device->host_allocator, out_descriptor_set_layout);
}
static iree_status_t iree_hal_metal_device_create_event(iree_hal_device_t* base_device,
@@ -268,8 +269,8 @@
iree_hal_device_t* base_device, iree_string_view_t identifier, iree_loop_t loop,
iree_hal_executable_cache_t** out_executable_cache) {
iree_hal_metal_device_t* device = iree_hal_metal_device_cast(base_device);
- return iree_hal_metal_nop_executable_cache_create(device->device, device->host_allocator,
- identifier, out_executable_cache);
+ return iree_hal_metal_nop_executable_cache_create(device->device, identifier,
+ device->host_allocator, out_executable_cache);
}
static iree_status_t iree_hal_metal_device_create_pipeline_layout(
@@ -277,8 +278,8 @@
iree_host_size_t set_layout_count, iree_hal_descriptor_set_layout_t* const* set_layouts,
iree_hal_pipeline_layout_t** out_pipeline_layout) {
iree_hal_metal_device_t* device = iree_hal_metal_device_cast(base_device);
- return iree_hal_metal_pipeline_layout_create(device->host_allocator, set_layout_count,
- set_layouts, push_constants, out_pipeline_layout);
+ return iree_hal_metal_pipeline_layout_create(set_layout_count, set_layouts, push_constants,
+ device->host_allocator, out_pipeline_layout);
}
static iree_status_t iree_hal_metal_device_create_semaphore(iree_hal_device_t* base_device,
diff --git a/experimental/metal/metal_kernel_library.h b/experimental/metal/metal_kernel_library.h
index 635b758..4d252f7 100644
--- a/experimental/metal/metal_kernel_library.h
+++ b/experimental/metal/metal_kernel_library.h
@@ -41,13 +41,12 @@
// |out_executable| must be released by the caller (see
// iree_hal_executable_release).
iree_status_t iree_hal_metal_kernel_library_create(
- iree_allocator_t host_allocator, id<MTLDevice> device,
- const iree_hal_executable_params_t* executable_params,
- iree_hal_executable_t** out_executable);
+ id<MTLDevice> device, const iree_hal_executable_params_t* executable_params,
+ iree_allocator_t host_allocator, iree_hal_executable_t** out_executable);
// Returns the kernel launch parameters for the given |entry_point|.
iree_status_t iree_hal_metal_kernel_library_entry_point_kernel_params(
- iree_hal_executable_t* executable, int32_t entry_point,
+ const iree_hal_executable_t* executable, int32_t entry_point,
iree_hal_metal_kernel_params_t* out_params);
// Compiles the given |entry_point| in Metal |source_code| and writes the
diff --git a/experimental/metal/metal_kernel_library.m b/experimental/metal/metal_kernel_library.m
index 5f85386..44072d4 100644
--- a/experimental/metal/metal_kernel_library.m
+++ b/experimental/metal/metal_kernel_library.m
@@ -33,6 +33,12 @@
return (iree_hal_metal_kernel_library_t*)base_value;
}
+static const iree_hal_metal_kernel_library_t* iree_hal_metal_kernel_library_const_cast(
+ const iree_hal_executable_t* base_value) {
+ IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_metal_kernel_library_vtable);
+ return (const iree_hal_metal_kernel_library_t*)base_value;
+}
+
// Verifies the structure of the flatbuffer so that we can avoid doing so during runtime.
//
// There are still some conditions we must be aware of (such as omitted names on functions with
@@ -226,8 +232,8 @@
}
iree_status_t iree_hal_metal_kernel_library_create(
- iree_allocator_t host_allocator, id<MTLDevice> device,
- const iree_hal_executable_params_t* executable_params, iree_hal_executable_t** out_executable) {
+ id<MTLDevice> device, const iree_hal_executable_params_t* executable_params,
+ iree_allocator_t host_allocator, iree_hal_executable_t** out_executable) {
IREE_ASSERT_ARGUMENT(executable_params);
IREE_ASSERT_ARGUMENT(out_executable);
*out_executable = NULL;
@@ -356,9 +362,10 @@
}
iree_status_t iree_hal_metal_kernel_library_entry_point_kernel_params(
- iree_hal_executable_t* base_executable, int32_t entry_point,
+ const iree_hal_executable_t* base_executable, int32_t entry_point,
iree_hal_metal_kernel_params_t* out_params) {
- iree_hal_metal_kernel_library_t* executable = iree_hal_metal_kernel_library_cast(base_executable);
+ const iree_hal_metal_kernel_library_t* executable =
+ iree_hal_metal_kernel_library_const_cast(base_executable);
if (entry_point >= executable->entry_point_count) {
return iree_make_status(IREE_STATUS_OUT_OF_RANGE, "invalid entry point ordinal %d",
entry_point);
diff --git a/experimental/metal/metal_shared_event.h b/experimental/metal/metal_shared_event.h
index 55f627d..7961dce 100644
--- a/experimental/metal/metal_shared_event.h
+++ b/experimental/metal/metal_shared_event.h
@@ -33,7 +33,7 @@
// Returns the underlying Metal shared event handle for the given |semaphore|.
id<MTLSharedEvent> iree_hal_metal_shared_event_handle(
- iree_hal_semaphore_t* base_semaphore);
+ const iree_hal_semaphore_t* semaphore);
// Waits on the shared events in the given |semaphore_list| according to the
// |wait_mode| before |timeout|.
diff --git a/experimental/metal/metal_shared_event.m b/experimental/metal/metal_shared_event.m
index ce1f688..f49a4f4 100644
--- a/experimental/metal/metal_shared_event.m
+++ b/experimental/metal/metal_shared_event.m
@@ -39,12 +39,19 @@
return (iree_hal_metal_shared_event_t*)base_value;
}
+static const iree_hal_metal_shared_event_t* iree_hal_metal_shared_event_const_cast(
+ const iree_hal_semaphore_t* base_value) {
+ IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_metal_shared_event_vtable);
+ return (const iree_hal_metal_shared_event_t*)base_value;
+}
+
bool iree_hal_metal_shared_event_isa(iree_hal_semaphore_t* semaphore) {
return iree_hal_resource_is(semaphore, &iree_hal_metal_shared_event_vtable);
}
-id<MTLSharedEvent> iree_hal_metal_shared_event_handle(iree_hal_semaphore_t* base_semaphore) {
- iree_hal_metal_shared_event_t* semaphore = iree_hal_metal_shared_event_cast(base_semaphore);
+id<MTLSharedEvent> iree_hal_metal_shared_event_handle(const iree_hal_semaphore_t* base_semaphore) {
+ const iree_hal_metal_shared_event_t* semaphore =
+ iree_hal_metal_shared_event_const_cast(base_semaphore);
return semaphore->shared_event;
}
diff --git a/experimental/metal/nop_executable_cache.h b/experimental/metal/nop_executable_cache.h
index 214963c..a758565 100644
--- a/experimental/metal/nop_executable_cache.h
+++ b/experimental/metal/nop_executable_cache.h
@@ -23,8 +23,8 @@
// |out_executable_cache| must be released by the caller (see
// iree_hal_executable_cache_release).
iree_status_t iree_hal_metal_nop_executable_cache_create(
- id<MTLDevice> device, iree_allocator_t host_allocator,
- iree_string_view_t identifier,
+ id<MTLDevice> device, iree_string_view_t identifier,
+ iree_allocator_t host_allocator,
iree_hal_executable_cache_t** out_executable_cache);
#ifdef __cplusplus
diff --git a/experimental/metal/nop_executable_cache.m b/experimental/metal/nop_executable_cache.m
index b1e8eb1..ae6926d 100644
--- a/experimental/metal/nop_executable_cache.m
+++ b/experimental/metal/nop_executable_cache.m
@@ -32,7 +32,7 @@
}
iree_status_t iree_hal_metal_nop_executable_cache_create(
- id<MTLDevice> device, iree_allocator_t host_allocator, iree_string_view_t identifier,
+ id<MTLDevice> device, iree_string_view_t identifier, iree_allocator_t host_allocator,
iree_hal_executable_cache_t** out_executable_cache) {
IREE_ASSERT_ARGUMENT(out_executable_cache);
*out_executable_cache = NULL;
@@ -76,9 +76,8 @@
const iree_hal_executable_params_t* executable_params, iree_hal_executable_t** out_executable) {
iree_hal_metal_nop_executable_cache_t* executable_cache =
iree_hal_metal_nop_executable_cache_cast(base_executable_cache);
- return iree_hal_metal_kernel_library_create(executable_cache->host_allocator,
- executable_cache->device, executable_params,
- out_executable);
+ return iree_hal_metal_kernel_library_create(executable_cache->device, executable_params,
+ executable_cache->host_allocator, out_executable);
}
static const iree_hal_executable_cache_vtable_t iree_hal_metal_nop_executable_cache_vtable = {
diff --git a/experimental/metal/pipeline_layout.h b/experimental/metal/pipeline_layout.h
index 8d17be4..99de799 100644
--- a/experimental/metal/pipeline_layout.h
+++ b/experimental/metal/pipeline_layout.h
@@ -14,6 +14,10 @@
extern "C" {
#endif // __cplusplus
+//===----------------------------------------------------------------------===//
+// Limitations
+//===----------------------------------------------------------------------===//
+
// The max number of bindings per descriptor set allowed in the Metal HAL
// implementation.
//
@@ -51,21 +55,20 @@
// |out_descriptor_set_layout| must be released by the caller (see
// iree_hal_descriptor_set_layout_release).
iree_status_t iree_hal_metal_descriptor_set_layout_create(
- iree_allocator_t host_allocator,
iree_hal_descriptor_set_layout_flags_t flags,
iree_host_size_t binding_count,
const iree_hal_descriptor_set_layout_binding_t* bindings,
+ iree_allocator_t host_allocator,
iree_hal_descriptor_set_layout_t** out_descriptor_set_layout);
// Returns the total number of bindings in the given descriptor set.
iree_host_size_t iree_hal_metal_descriptor_set_layout_binding_count(
- iree_hal_descriptor_set_layout_t* base_descriptor_set_layout);
+ const iree_hal_descriptor_set_layout_t* descriptor_set_layout);
-// Returns the information about a given |binding| in
-// |base_descriptor_set_layout|.
-iree_hal_descriptor_set_layout_binding_t*
+// Returns the information about a given |binding| in |descriptor_set_layout|.
+const iree_hal_descriptor_set_layout_binding_t*
iree_hal_metal_descriptor_set_layout_binding(
- iree_hal_descriptor_set_layout_t* base_descriptor_set_layout,
+ const iree_hal_descriptor_set_layout_t* descriptor_set_layout,
uint32_t binding);
//===----------------------------------------------------------------------===//
@@ -78,20 +81,19 @@
// |out_pipeline_layout| must be released by the caller (see
// iree_hal_pipeline_layout_release).
iree_status_t iree_hal_metal_pipeline_layout_create(
- iree_allocator_t host_allocator, iree_host_size_t set_layout_count,
+ iree_host_size_t set_layout_count,
iree_hal_descriptor_set_layout_t* const* set_layouts,
- iree_host_size_t push_constant_count,
+ iree_host_size_t push_constant_count, iree_allocator_t host_allocator,
iree_hal_pipeline_layout_t** out_pipeline_layout);
-// Returns the descriptor set layout of the given |set| in
-// |base_pipeline_layout|.
-iree_hal_descriptor_set_layout_t*
+// Returns the descriptor set layout of the given |set| in |pipeline_layout|.
+const iree_hal_descriptor_set_layout_t*
iree_hal_metal_pipeline_layout_descriptor_set_layout(
- iree_hal_pipeline_layout_t* base_pipeline_layout, uint32_t set);
+ const iree_hal_pipeline_layout_t* pipeline_layout, uint32_t set);
// Returns the push constant count in the given |pipeline_layout|.
iree_host_size_t iree_hal_metal_pipeline_layout_push_constant_count(
- iree_hal_pipeline_layout_t* base_pipeline_layout);
+ const iree_hal_pipeline_layout_t* pipeline_layout);
#ifdef __cplusplus
} // extern "C"
diff --git a/experimental/metal/pipeline_layout.m b/experimental/metal/pipeline_layout.m
index 7f3bfaa..056804f 100644
--- a/experimental/metal/pipeline_layout.m
+++ b/experimental/metal/pipeline_layout.m
@@ -33,9 +33,16 @@
return (iree_hal_metal_descriptor_set_layout_t*)base_value;
}
+static const iree_hal_metal_descriptor_set_layout_t*
+iree_hal_metal_descriptor_set_layout_const_cast(
+ const iree_hal_descriptor_set_layout_t* base_value) {
+ IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_metal_descriptor_set_layout_vtable);
+ return (const iree_hal_metal_descriptor_set_layout_t*)base_value;
+}
+
iree_status_t iree_hal_metal_descriptor_set_layout_create(
- iree_allocator_t host_allocator, iree_hal_descriptor_set_layout_flags_t flags,
- iree_host_size_t binding_count, const iree_hal_descriptor_set_layout_binding_t* bindings,
+ iree_hal_descriptor_set_layout_flags_t flags, iree_host_size_t binding_count,
+ const iree_hal_descriptor_set_layout_binding_t* bindings, iree_allocator_t host_allocator,
iree_hal_descriptor_set_layout_t** out_descriptor_set_layout) {
IREE_ASSERT_ARGUMENT(!binding_count || bindings);
IREE_ASSERT_ARGUMENT(out_descriptor_set_layout);
@@ -70,10 +77,10 @@
IREE_TRACE_ZONE_END(z0);
}
-iree_hal_descriptor_set_layout_binding_t* iree_hal_metal_descriptor_set_layout_binding(
- iree_hal_descriptor_set_layout_t* base_descriptor_set_layout, uint32_t binding) {
- iree_hal_metal_descriptor_set_layout_t* descriptor_set_layout =
- iree_hal_metal_descriptor_set_layout_cast(base_descriptor_set_layout);
+const iree_hal_descriptor_set_layout_binding_t* iree_hal_metal_descriptor_set_layout_binding(
+ const iree_hal_descriptor_set_layout_t* base_descriptor_set_layout, uint32_t binding) {
+ const iree_hal_metal_descriptor_set_layout_t* descriptor_set_layout =
+ iree_hal_metal_descriptor_set_layout_const_cast(base_descriptor_set_layout);
for (iree_host_size_t i = 0; i < descriptor_set_layout->binding_count; ++i) {
if (descriptor_set_layout->bindings[i].binding == binding) {
return &descriptor_set_layout->bindings[i];
@@ -83,9 +90,9 @@
}
iree_host_size_t iree_hal_metal_descriptor_set_layout_binding_count(
- iree_hal_descriptor_set_layout_t* base_descriptor_set_layout) {
- iree_hal_metal_descriptor_set_layout_t* descriptor_set_layout =
- iree_hal_metal_descriptor_set_layout_cast(base_descriptor_set_layout);
+ const iree_hal_descriptor_set_layout_t* base_descriptor_set_layout) {
+ const iree_hal_metal_descriptor_set_layout_t* descriptor_set_layout =
+ iree_hal_metal_descriptor_set_layout_const_cast(base_descriptor_set_layout);
return descriptor_set_layout->binding_count;
}
@@ -117,9 +124,15 @@
return (iree_hal_metal_pipeline_layout_t*)base_value;
}
+static const iree_hal_metal_pipeline_layout_t* iree_hal_metal_pipeline_layout_const_cast(
+ const iree_hal_pipeline_layout_t* base_value) {
+ IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_metal_pipeline_layout_vtable);
+ return (const iree_hal_metal_pipeline_layout_t*)base_value;
+}
+
iree_status_t iree_hal_metal_pipeline_layout_create(
- iree_allocator_t host_allocator, iree_host_size_t set_layout_count,
- iree_hal_descriptor_set_layout_t* const* set_layouts, iree_host_size_t push_constant_count,
+ iree_host_size_t set_layout_count, iree_hal_descriptor_set_layout_t* const* set_layouts,
+ iree_host_size_t push_constant_count, iree_allocator_t host_allocator,
iree_hal_pipeline_layout_t** out_pipeline_layout) {
IREE_ASSERT_ARGUMENT(!set_layout_count || set_layouts);
IREE_ASSERT_ARGUMENT(out_pipeline_layout);
@@ -161,18 +174,18 @@
IREE_TRACE_ZONE_END(z0);
}
-iree_hal_descriptor_set_layout_t* iree_hal_metal_pipeline_layout_descriptor_set_layout(
- iree_hal_pipeline_layout_t* base_pipeline_layout, uint32_t set) {
- iree_hal_metal_pipeline_layout_t* pipeline_layout =
- iree_hal_metal_pipeline_layout_cast(base_pipeline_layout);
+const iree_hal_descriptor_set_layout_t* iree_hal_metal_pipeline_layout_descriptor_set_layout(
+ const iree_hal_pipeline_layout_t* base_pipeline_layout, uint32_t set) {
+ const iree_hal_metal_pipeline_layout_t* pipeline_layout =
+ iree_hal_metal_pipeline_layout_const_cast(base_pipeline_layout);
if (set < pipeline_layout->set_layout_count) return pipeline_layout->set_layouts[set];
return NULL;
}
iree_host_size_t iree_hal_metal_pipeline_layout_push_constant_count(
- iree_hal_pipeline_layout_t* base_pipeline_layout) {
- iree_hal_metal_pipeline_layout_t* pipeline_layout =
- iree_hal_metal_pipeline_layout_cast(base_pipeline_layout);
+ const iree_hal_pipeline_layout_t* base_pipeline_layout) {
+ const iree_hal_metal_pipeline_layout_t* pipeline_layout =
+ iree_hal_metal_pipeline_layout_const_cast(base_pipeline_layout);
return pipeline_layout->push_constant_count;
}