Skip to content

Commit

Permalink
Fixing executable debug info as identified in #18996. (#18997)
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik authored Nov 2, 2024
1 parent 05ec795 commit c3b1e6e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
22 changes: 10 additions & 12 deletions runtime/src/iree/hal/drivers/cuda/native_executable.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,9 @@ iree_status_t iree_hal_cuda_native_executable_create(
(CUmodule*)((uint8_t*)executable + sizeof(*executable) +
export_count * sizeof(executable->exports[0]));
executable->export_count = export_count;
IREE_TRACE(
iree_hal_debug_export_info_t* export_infos =
(iree_hal_debug_export_info_t*)((uint8_t*)executable->modules +
module_count *
sizeof(executable->modules[0])));
IREE_TRACE(uint8_t* export_info_ptr =
((uint8_t*)executable->modules +
module_count * sizeof(executable->modules[0])));

// Publish any embedded source files to the tracing infrastructure.
iree_hal_debug_publish_source_files(
Expand Down Expand Up @@ -376,13 +374,13 @@ iree_status_t iree_hal_cuda_native_executable_create(
iree_hal_cuda_BindingBits_vec_len(binding_flags_vec);

IREE_TRACE({
iree_hal_debug_copy_export_info(
iree_hal_cuda_ExportDef_debug_info_get(export_def),
&export_infos[i]);
kernel_info->debug_info.function_name = export_infos[i].function_name;
kernel_info->debug_info.source_filename =
export_infos[i].source_filename;
kernel_info->debug_info.source_line = export_infos[i].source_line;
iree_hal_debug_export_info_t* export_info =
(iree_hal_debug_export_info_t*)export_info_ptr;
export_info_ptr += iree_hal_debug_copy_export_info(
iree_hal_cuda_ExportDef_debug_info_get(export_def), export_info);
kernel_info->debug_info.function_name = export_info->function_name;
kernel_info->debug_info.source_filename = export_info->source_filename;
kernel_info->debug_info.source_line = export_info->source_line;
});
}
}
Expand Down
22 changes: 10 additions & 12 deletions runtime/src/iree/hal/drivers/hip/native_executable.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,9 @@ iree_status_t iree_hal_hip_native_executable_create(
(hipModule_t*)((uint8_t*)executable + sizeof(*executable) +
export_count * sizeof(executable->exports[0]));
executable->export_count = export_count;
IREE_TRACE(
iree_hal_debug_export_info_t* export_infos =
(iree_hal_debug_export_info_t*)((uint8_t*)executable->modules +
module_count *
sizeof(executable->modules[0])));
IREE_TRACE(uint8_t* export_info_ptr =
((uint8_t*)executable->modules +
module_count * sizeof(executable->modules[0])));

// Publish any embedded source files to the tracing infrastructure.
iree_hal_debug_publish_source_files(
Expand Down Expand Up @@ -376,13 +374,13 @@ iree_status_t iree_hal_hip_native_executable_create(
iree_hal_hip_BindingBits_vec_len(binding_flags_vec);

IREE_TRACE({
iree_hal_debug_copy_export_info(
iree_hal_hip_ExportDef_debug_info_get(export_def),
&export_infos[i]);
kernel_info->debug_info.function_name = export_infos[i].function_name;
kernel_info->debug_info.source_filename =
export_infos[i].source_filename;
kernel_info->debug_info.source_line = export_infos[i].source_line;
iree_hal_debug_export_info_t* export_info =
(iree_hal_debug_export_info_t*)export_info_ptr;
export_info_ptr += iree_hal_debug_copy_export_info(
iree_hal_hip_ExportDef_debug_info_get(export_def), export_info);
kernel_info->debug_info.function_name = export_info->function_name;
kernel_info->debug_info.source_filename = export_info->source_filename;
kernel_info->debug_info.source_line = export_info->source_line;
});
}
}
Expand Down
17 changes: 8 additions & 9 deletions runtime/src/iree/hal/drivers/metal/executable.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,8 @@ iree_status_t iree_hal_metal_executable_create(
iree_hal_resource_initialize(&iree_hal_metal_executable_vtable, &executable->resource);
executable->host_allocator = host_allocator;
executable->pipeline_count = pipeline_count;
IREE_TRACE(
iree_hal_debug_export_info_t* export_infos =
(iree_hal_debug_export_info_t*)((uint8_t*)executable->pipelines +
pipeline_count * sizeof(executable->pipelines[0])));
IREE_TRACE(uint8_t* export_info_ptr = ((uint8_t*)executable->pipelines +
pipeline_count * sizeof(executable->pipelines[0])));

// Publish any embedded source files to the tracing infrastructure.
iree_hal_debug_publish_source_files(
Expand All @@ -442,11 +440,12 @@ iree_status_t iree_hal_metal_executable_create(
if (!iree_status_is_ok(status)) break;

IREE_TRACE({
iree_hal_debug_copy_export_info(iree_hal_metal_PipelineDef_debug_info_get(pipeline_def),
&export_infos[i]);
pipeline->source_location.func_name = export_infos[i].function_name;
pipeline->source_location.file_name = export_infos[i].source_filename;
pipeline->source_location.line = export_infos[i].source_line;
iree_hal_debug_export_info_t* export_info = (iree_hal_debug_export_info_t*)export_info_ptr;
export_info_ptr += iree_hal_debug_copy_export_info(
iree_hal_metal_PipelineDef_debug_info_get(pipeline_def), export_info);
pipeline->source_location.func_name = export_info->function_name;
pipeline->source_location.file_name = export_info->source_filename;
pipeline->source_location.line = export_info->source_line;
});
}
}
Expand Down
21 changes: 11 additions & 10 deletions runtime/src/iree/hal/drivers/vulkan/native_executable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -957,20 +957,21 @@ iree_status_t iree_hal_vulkan_native_executable_create(
// Populate tracing info for each pipeline.
if (iree_status_is_ok(status)) {
IREE_TRACE({
iree_hal_debug_export_info_t* export_infos =
(iree_hal_debug_export_info_t*)((uint8_t*)executable->pipelines +
pipeline_count *
sizeof(executable->pipelines[0]));
uint8_t* export_info_ptr =
((uint8_t*)executable->pipelines +
pipeline_count * sizeof(executable->pipelines[0]));
for (iree_host_size_t i = 0; i < pipeline_count; ++i) {
iree_hal_vulkan_PipelineDef_table_t pipeline_def =
iree_hal_vulkan_PipelineDef_vec_at(pipelines_vec, i);
iree_hal_vulkan_pipeline_t* pipeline = &executable->pipelines[i];
iree_hal_debug_copy_export_info(
iree_hal_debug_export_info_t* export_info =
(iree_hal_debug_export_info_t*)export_info_ptr;
export_info_ptr += iree_hal_debug_copy_export_info(
iree_hal_vulkan_PipelineDef_debug_info_get(pipeline_def),
&export_infos[i]);
pipeline->source_location.file_name = export_infos[i].source_filename;
pipeline->source_location.line = export_infos[i].source_line;
pipeline->source_location.func_name = export_infos[i].function_name;
export_info);
iree_hal_vulkan_pipeline_t* pipeline = &executable->pipelines[i];
pipeline->source_location.file_name = export_info->source_filename;
pipeline->source_location.line = export_info->source_line;
pipeline->source_location.func_name = export_info->function_name;
}
});
}
Expand Down
9 changes: 7 additions & 2 deletions runtime/src/iree/hal/utils/executable_debug_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,19 @@ iree_host_size_t iree_hal_debug_calculate_export_info_size(
return total_size;
}

void iree_hal_debug_copy_export_info(
iree_host_size_t iree_hal_debug_copy_export_info(
iree_hal_debug_ExportDef_table_t export_def,
iree_hal_debug_export_info_t* out_info) {
memset(out_info, 0, sizeof(*out_info));
if (!export_def) return;
if (!export_def) return 0;

iree_host_size_t total_size = sizeof(iree_hal_debug_export_info_t);
char* ptr = (char*)out_info + sizeof(*out_info);

flatbuffers_string_t name = iree_hal_debug_ExportDef_name_get(export_def);
if (name) {
size_t name_length = flatbuffers_string_len(name);
total_size += name_length;
memcpy(ptr, name, name_length);
out_info->function_name = iree_make_string_view(ptr, name_length);
ptr += name_length;
Expand All @@ -110,10 +112,13 @@ void iree_hal_debug_copy_export_info(
flatbuffers_string_t filename =
iree_hal_debug_FileLineLocDef_filename_get(location_def);
size_t filename_length = flatbuffers_string_len(filename);
total_size += filename_length;
memcpy(ptr, filename, filename_length);
out_info->source_filename = iree_make_string_view(ptr, filename_length);
ptr += filename_length;
}

return total_size;
}

void iree_hal_debug_publish_source_files(
Expand Down
5 changes: 3 additions & 2 deletions runtime/src/iree/hal/utils/executable_debug_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ iree_host_size_t iree_hal_debug_calculate_export_info_size(
// Clones the given export flatbuffer data into a heap structure allocated with
// at least the size as calculated by iree_hal_debug_calculate_export_info_size.
// The storage is valid until freed by the caller and decoupled from the
// Flatbuffer storage.
void iree_hal_debug_copy_export_info(
// Flatbuffer storage. Returns the size copied (matching
// iree_hal_debug_calculate_export_info_size).
iree_host_size_t iree_hal_debug_copy_export_info(
iree_hal_debug_ExportDef_table_t export_def,
iree_hal_debug_export_info_t* out_info);

Expand Down

0 comments on commit c3b1e6e

Please sign in to comment.