Avoid variable size C array in CUDA hal (#6130)
This fix MSVC build break.
diff --git a/iree/hal/cuda/graph_command_buffer.c b/iree/hal/cuda/graph_command_buffer.c
index 7d86ccb..9b7fdc9 100644
--- a/iree/hal/cuda/graph_command_buffer.c
+++ b/iree/hal/cuda/graph_command_buffer.c
@@ -35,7 +35,7 @@
void* current_descriptor[];
} iree_hal_cuda_graph_command_buffer_t;
-static const size_t max_binding_count = 64;
+#define IREE_HAL_CUDA_MAX_BINDING_COUNT 64
extern const iree_hal_command_buffer_vtable_t
iree_hal_cuda_graph_command_buffer_vtable;
@@ -61,8 +61,8 @@
"cuGraphCreate");
iree_hal_cuda_graph_command_buffer_t* command_buffer = NULL;
size_t total_size = sizeof(*command_buffer) +
- max_binding_count * sizeof(void*) +
- max_binding_count * sizeof(CUdeviceptr);
+ IREE_HAL_CUDA_MAX_BINDING_COUNT * sizeof(void*) +
+ IREE_HAL_CUDA_MAX_BINDING_COUNT * sizeof(CUdeviceptr);
iree_status_t status = iree_allocator_malloc(
context->host_allocator, total_size, (void**)&command_buffer);
if (iree_status_is_ok(status)) {
@@ -77,8 +77,9 @@
command_buffer->last_node = NULL;
CUdeviceptr* device_ptrs =
- (CUdeviceptr*)(command_buffer->current_descriptor + max_binding_count);
- for (size_t i = 0; i < max_binding_count; i++) {
+ (CUdeviceptr*)(command_buffer->current_descriptor +
+ IREE_HAL_CUDA_MAX_BINDING_COUNT);
+ for (size_t i = 0; i < IREE_HAL_CUDA_MAX_BINDING_COUNT; i++) {
command_buffer->current_descriptor[i] = &device_ptrs[i];
}
@@ -347,14 +348,14 @@
// based on the binding index.
// Sort the binding based on the binding index and map the array index to the
// argument index.
- iree_hal_cuda_binding_mapping_t binding_used[max_binding_count];
+ iree_hal_cuda_binding_mapping_t binding_used[IREE_HAL_CUDA_MAX_BINDING_COUNT];
for (iree_host_size_t i = 0; i < binding_count; i++) {
iree_hal_cuda_binding_mapping_t buffer = {i, bindings[i].binding};
binding_used[i] = buffer;
}
qsort(binding_used, binding_count, sizeof(iree_hal_cuda_binding_mapping_t),
compare_binding_index);
- assert(binding_count < max_binding_count &&
+ assert(binding_count < IREE_HAL_CUDA_MAX_BINDING_COUNT &&
"binding count larger than the max expected.");
for (iree_host_size_t i = 0; i < binding_count; i++) {
iree_hal_descriptor_set_binding_t binding = bindings[binding_used[i].index];