Skip to content

Commit

Permalink
Giving command buffer begin_debug_group/end_debug_group status. (#18998)
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik authored Nov 5, 2024
1 parent fa3a144 commit 17bba14
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 59 deletions.
26 changes: 10 additions & 16 deletions experimental/webgpu/command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,43 +496,37 @@ static iree_status_t iree_hal_webgpu_command_buffer_end(
return iree_hal_webgpu_command_buffer_flush(command_buffer);
}

static void iree_hal_webgpu_command_buffer_begin_debug_group(
static iree_status_t iree_hal_webgpu_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
iree_hal_webgpu_command_buffer_t* command_buffer =
iree_hal_webgpu_command_buffer_cast(base_command_buffer);

WGPUCommandEncoder command_encoder = NULL;
iree_status_t status = iree_hal_webgpu_command_buffer_acquire_command_encoder(
command_buffer, &command_encoder);
if (!iree_status_is_ok(status)) {
// TODO(benvanik): mark recording as failed.
iree_status_ignore(status);
return;
}
IREE_RETURN_IF_ERROR(iree_hal_webgpu_command_buffer_acquire_command_encoder(
command_buffer, &command_encoder));

// TODO(benvanik): ensure this works right when in a compute pass.
char label_str[128] = {0};
memcpy(label_str, label.data, iree_min(sizeof(label_str) - 1, label.size));
wgpuCommandEncoderPushDebugGroup(command_encoder, label_str);

return iree_ok_status();
}

static void iree_hal_webgpu_command_buffer_end_debug_group(
static iree_status_t iree_hal_webgpu_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_webgpu_command_buffer_t* command_buffer =
iree_hal_webgpu_command_buffer_cast(base_command_buffer);

WGPUCommandEncoder command_encoder = NULL;
iree_status_t status = iree_hal_webgpu_command_buffer_acquire_command_encoder(
command_buffer, &command_encoder);
if (!iree_status_is_ok(status)) {
// TODO(benvanik): mark recording as failed.
iree_status_ignore(status);
return;
}
IREE_RETURN_IF_ERROR(iree_hal_webgpu_command_buffer_acquire_command_encoder(
command_buffer, &command_encoder));

wgpuCommandEncoderPopDebugGroup(command_encoder);

return iree_ok_status();
}

static iree_status_t iree_hal_webgpu_command_buffer_execution_barrier(
Expand Down
27 changes: 14 additions & 13 deletions runtime/src/iree/hal/command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,28 @@ iree_hal_command_buffer_end(iree_hal_command_buffer_t* command_buffer) {
return status;
}

IREE_API_EXPORT void iree_hal_command_buffer_begin_debug_group(
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
IREE_ASSERT_ARGUMENT(command_buffer);
IF_VALIDATING(command_buffer,
iree_hal_command_buffer_begin_debug_group_validation(
command_buffer, VALIDATION_STATE(command_buffer), label,
label_color, location));
_VTABLE_DISPATCH(command_buffer, begin_debug_group)
(command_buffer, label, label_color, location);
IF_VALIDATING(command_buffer, {
IREE_RETURN_IF_ERROR(iree_hal_command_buffer_begin_debug_group_validation(
command_buffer, VALIDATION_STATE(command_buffer), label, label_color,
location));
});
return _VTABLE_DISPATCH(command_buffer, begin_debug_group)(
command_buffer, label, label_color, location);
}

IREE_API_EXPORT void iree_hal_command_buffer_end_debug_group(
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_end_debug_group(
iree_hal_command_buffer_t* command_buffer) {
IREE_ASSERT_ARGUMENT(command_buffer);
IF_VALIDATING(command_buffer,
iree_hal_command_buffer_end_debug_group_validation(
command_buffer, VALIDATION_STATE(command_buffer)));
_VTABLE_DISPATCH(command_buffer, end_debug_group)
(command_buffer);
IF_VALIDATING(command_buffer, {
IREE_RETURN_IF_ERROR(iree_hal_command_buffer_end_debug_group_validation(
command_buffer, VALIDATION_STATE(command_buffer)));
});
return _VTABLE_DISPATCH(command_buffer, end_debug_group)(command_buffer);
}

IREE_API_EXPORT iree_status_t iree_hal_command_buffer_execution_barrier(
Expand Down
13 changes: 9 additions & 4 deletions runtime/src/iree/hal/command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ IREE_API_EXPORT iree_device_size_t iree_hal_collective_element_byte_count(
typedef uint64_t iree_hal_dispatch_flags_t;
enum iree_hal_dispatch_flag_bits_t {
IREE_HAL_DISPATCH_FLAG_NONE = 0,

// Indirect parameters such as workgroup count are static at the time the
// command buffer is issued. This is in contrast to dynamic parameters that
// may be changed by dispatches within the same command buffer.
IREE_HAL_DISPATCH_FLAG_STATIC_INDIRECT_PARAMETERS = 1ull << 0,
};

// An RGBA color.
Expand Down Expand Up @@ -637,13 +642,13 @@ iree_hal_command_buffer_end(iree_hal_command_buffer_t* command_buffer);
// An optional RGBA color to show in the debug UI may be provided via
// |label_color|; otherwise iree_hal_label_color_unspecified can be used to let
// the debug tool choose.
IREE_API_EXPORT void iree_hal_command_buffer_begin_debug_group(
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location);

// Pops a debug group from the stack.
IREE_API_EXPORT void iree_hal_command_buffer_end_debug_group(
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_end_debug_group(
iree_hal_command_buffer_t* command_buffer);

// Defines a memory dependency between commands recorded before and after the
Expand Down Expand Up @@ -866,11 +871,11 @@ typedef struct iree_hal_command_buffer_vtable_t {
iree_status_t(IREE_API_PTR* begin)(iree_hal_command_buffer_t* command_buffer);
iree_status_t(IREE_API_PTR* end)(iree_hal_command_buffer_t* command_buffer);

void(IREE_API_PTR* begin_debug_group)(
iree_status_t(IREE_API_PTR* begin_debug_group)(
iree_hal_command_buffer_t* command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location);
void(IREE_API_PTR* end_debug_group)(
iree_status_t(IREE_API_PTR* end_debug_group)(
iree_hal_command_buffer_t* command_buffer);

iree_status_t(IREE_API_PTR* execution_barrier)(
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/iree/hal/command_buffer_validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,20 @@ iree_status_t iree_hal_command_buffer_end_validation(
return iree_ok_status();
}

void iree_hal_command_buffer_begin_debug_group_validation(
iree_status_t iree_hal_command_buffer_begin_debug_group_validation(
iree_hal_command_buffer_t* command_buffer,
iree_hal_command_buffer_validation_state_t* validation_state,
iree_string_view_t label, iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
++validation_state->debug_group_depth;
return iree_ok_status();
}

void iree_hal_command_buffer_end_debug_group_validation(
iree_status_t iree_hal_command_buffer_end_debug_group_validation(
iree_hal_command_buffer_t* command_buffer,
iree_hal_command_buffer_validation_state_t* validation_state) {
--validation_state->debug_group_depth;
return iree_ok_status();
}

iree_status_t iree_hal_command_buffer_execution_barrier_validation(
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/iree/hal/command_buffer_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ iree_status_t iree_hal_command_buffer_end_validation(
iree_hal_command_buffer_t* command_buffer,
iree_hal_command_buffer_validation_state_t* validation_state);

void iree_hal_command_buffer_begin_debug_group_validation(
iree_status_t iree_hal_command_buffer_begin_debug_group_validation(
iree_hal_command_buffer_t* command_buffer,
iree_hal_command_buffer_validation_state_t* validation_state,
iree_string_view_t label, iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location);

void iree_hal_command_buffer_end_debug_group_validation(
iree_status_t iree_hal_command_buffer_end_debug_group_validation(
iree_hal_command_buffer_t* command_buffer,
iree_hal_command_buffer_validation_state_t* validation_state);

Expand Down
7 changes: 5 additions & 2 deletions runtime/src/iree/hal/drivers/cuda/graph_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static iree_status_t iree_hal_cuda_graph_command_buffer_end(
return iree_ok_status();
}

static void iree_hal_cuda_graph_command_buffer_begin_debug_group(
static iree_status_t iree_hal_cuda_graph_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
Expand All @@ -393,15 +393,18 @@ static void iree_hal_cuda_graph_command_buffer_begin_debug_group(
location ? location->file.data : NULL, location ? location->file.size : 0,
location ? location->line : 0,
/*func_name=*/NULL, 0, label.data, label.size);

return iree_ok_status();
}

static void iree_hal_cuda_graph_command_buffer_end_debug_group(
static iree_status_t iree_hal_cuda_graph_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_cuda_graph_command_buffer_t* command_buffer =
iree_hal_cuda_graph_command_buffer_cast(base_command_buffer);
(void)command_buffer;
IREE_CUDA_GRAPH_COMMAND_BUFFER_TRACE_ZONE_END(
command_buffer, IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);
return iree_ok_status();
}

static iree_status_t
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/iree/hal/drivers/cuda/stream_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static iree_status_t iree_hal_cuda_stream_command_buffer_end(
return iree_ok_status();
}

static void iree_hal_cuda_stream_command_buffer_begin_debug_group(
static iree_status_t iree_hal_cuda_stream_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
Expand All @@ -234,9 +234,11 @@ static void iree_hal_cuda_stream_command_buffer_begin_debug_group(
/*func_name=*/NULL, 0, label.data, label.size);

// TODO: pass along to CUPTI if available.

return iree_ok_status();
}

static void iree_hal_cuda_stream_command_buffer_end_debug_group(
static iree_status_t iree_hal_cuda_stream_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_cuda_stream_command_buffer_t* command_buffer =
iree_hal_cuda_stream_command_buffer_cast(base_command_buffer);
Expand All @@ -247,6 +249,8 @@ static void iree_hal_cuda_stream_command_buffer_end_debug_group(
IREE_HAL_STREAM_TRACE_ZONE_END(command_buffer->tracing_context,
&command_buffer->tracing_event_list,
IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);

return iree_ok_status();
}

static iree_status_t iree_hal_cuda_stream_command_buffer_execution_barrier(
Expand Down
7 changes: 5 additions & 2 deletions runtime/src/iree/hal/drivers/hip/graph_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static iree_status_t iree_hal_hip_graph_command_buffer_end(
return iree_ok_status();
}

static void iree_hal_hip_graph_command_buffer_begin_debug_group(
static iree_status_t iree_hal_hip_graph_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
Expand All @@ -402,15 +402,18 @@ static void iree_hal_hip_graph_command_buffer_begin_debug_group(
location ? location->file.data : NULL, location ? location->file.size : 0,
location ? location->line : 0,
/*func_name=*/NULL, 0, label.data, label.size);

return iree_ok_status();
}

static void iree_hal_hip_graph_command_buffer_end_debug_group(
static iree_status_t iree_hal_hip_graph_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_hip_graph_command_buffer_t* command_buffer =
iree_hal_hip_graph_command_buffer_cast(base_command_buffer);
(void)command_buffer;
IREE_HIP_GRAPH_COMMAND_BUFFER_TRACE_ZONE_END(
command_buffer, IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);
return iree_ok_status();
}

static iree_status_t
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/iree/hal/drivers/hip/stream_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static iree_status_t iree_hal_hip_stream_command_buffer_end(
return iree_ok_status();
}

static void iree_hal_hip_stream_command_buffer_begin_debug_group(
static iree_status_t iree_hal_hip_stream_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
Expand All @@ -227,9 +227,11 @@ static void iree_hal_hip_stream_command_buffer_begin_debug_group(
location ? location->file.data : NULL, location ? location->file.size : 0,
location ? location->line : 0,
/*func_name=*/NULL, 0, label.data, label.size);

return iree_ok_status();
}

static void iree_hal_hip_stream_command_buffer_end_debug_group(
static iree_status_t iree_hal_hip_stream_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_hip_stream_command_buffer_t* command_buffer =
iree_hal_hip_stream_command_buffer_cast(base_command_buffer);
Expand All @@ -238,6 +240,8 @@ static void iree_hal_hip_stream_command_buffer_end_debug_group(
IREE_HAL_STREAM_TRACE_ZONE_END(command_buffer->tracing_context,
&command_buffer->tracing_event_list,
IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);

return iree_ok_status();
}

static iree_status_t iree_hal_hip_stream_command_buffer_execution_barrier(
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/iree/hal/drivers/local_task/task_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,18 @@ iree_status_t iree_hal_task_command_buffer_issue(
// iree_hal_task_command_buffer_t debug utilities
//===----------------------------------------------------------------------===//

static void iree_hal_task_command_buffer_begin_debug_group(
static iree_status_t iree_hal_task_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
// TODO(benvanik): tracy event stack.
return iree_ok_status();
}

static void iree_hal_task_command_buffer_end_debug_group(
static iree_status_t iree_hal_task_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
// TODO(benvanik): tracy event stack.
return iree_ok_status();
}

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/iree/hal/drivers/metal/direct_command_buffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,17 @@ bool iree_hal_metal_command_buffer_isa(iree_hal_command_buffer_t* command_buffer
return iree_hal_resource_is(&command_buffer->resource, &iree_hal_metal_command_buffer_vtable);
}

static void iree_hal_metal_command_buffer_begin_debug_group(
static iree_status_t iree_hal_metal_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color, const iree_hal_label_location_t* location) {
// TODO(antiagainst): implement support for debug group
return iree_ok_status();
}

static void iree_hal_metal_command_buffer_end_debug_group(
static iree_status_t iree_hal_metal_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
// TODO(antiagainst): implement support for debug group
return iree_ok_status();
}

static iree_status_t iree_hal_metal_command_buffer_prepare_barrier(
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/iree/hal/drivers/null/command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static iree_status_t iree_hal_null_command_buffer_end(
return status;
}

static void iree_hal_null_command_buffer_begin_debug_group(
static iree_status_t iree_hal_null_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
Expand All @@ -133,16 +133,20 @@ static void iree_hal_null_command_buffer_begin_debug_group(
// TODO(null): begin a nested debug group (push) if the implementation has a
// way to insert markers. This is informational and can be ignored.
(void)command_buffer;

return iree_ok_status();
}

static void iree_hal_null_command_buffer_end_debug_group(
static iree_status_t iree_hal_null_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_null_command_buffer_t* command_buffer =
iree_hal_null_command_buffer_cast(base_command_buffer);

// TODO(null): end a nested debug group (pop). Always called 1:1 in stack
// order with begin_debug_group.
(void)command_buffer;

return iree_ok_status();
}

static iree_status_t iree_hal_null_command_buffer_execution_barrier(
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/iree/hal/drivers/vulkan/direct_command_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static iree_status_t iree_hal_vulkan_direct_command_buffer_end(
return iree_ok_status();
}

static void iree_hal_vulkan_direct_command_buffer_begin_debug_group(
static iree_status_t iree_hal_vulkan_direct_command_buffer_begin_debug_group(
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
iree_hal_label_color_t label_color,
const iree_hal_label_location_t* location) {
Expand Down Expand Up @@ -255,9 +255,10 @@ static void iree_hal_vulkan_direct_command_buffer_begin_debug_group(
command_buffer->syms->vkCmdBeginDebugUtilsLabelEXT(command_buffer->handle,
&label_info);
}
return iree_ok_status();
}

static void iree_hal_vulkan_direct_command_buffer_end_debug_group(
static iree_status_t iree_hal_vulkan_direct_command_buffer_end_debug_group(
iree_hal_command_buffer_t* base_command_buffer) {
iree_hal_vulkan_direct_command_buffer_t* command_buffer =
iree_hal_vulkan_direct_command_buffer_cast(base_command_buffer);
Expand All @@ -266,6 +267,7 @@ static void iree_hal_vulkan_direct_command_buffer_end_debug_group(
}
IREE_VULKAN_TRACE_ZONE_END(command_buffer->tracing_context,
command_buffer->handle);
return iree_ok_status();
}

static VkPipelineStageFlags iree_hal_vulkan_convert_pipeline_stage_flags(
Expand Down
Loading

0 comments on commit 17bba14

Please sign in to comment.