Skip to content

Commit 17bba14

Browse files
authored
Giving command buffer begin_debug_group/end_debug_group status. (#18998)
1 parent fa3a144 commit 17bba14

File tree

15 files changed

+85
-59
lines changed

15 files changed

+85
-59
lines changed

experimental/webgpu/command_buffer.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -496,43 +496,37 @@ static iree_status_t iree_hal_webgpu_command_buffer_end(
496496
return iree_hal_webgpu_command_buffer_flush(command_buffer);
497497
}
498498

499-
static void iree_hal_webgpu_command_buffer_begin_debug_group(
499+
static iree_status_t iree_hal_webgpu_command_buffer_begin_debug_group(
500500
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
501501
iree_hal_label_color_t label_color,
502502
const iree_hal_label_location_t* location) {
503503
iree_hal_webgpu_command_buffer_t* command_buffer =
504504
iree_hal_webgpu_command_buffer_cast(base_command_buffer);
505505

506506
WGPUCommandEncoder command_encoder = NULL;
507-
iree_status_t status = iree_hal_webgpu_command_buffer_acquire_command_encoder(
508-
command_buffer, &command_encoder);
509-
if (!iree_status_is_ok(status)) {
510-
// TODO(benvanik): mark recording as failed.
511-
iree_status_ignore(status);
512-
return;
513-
}
507+
IREE_RETURN_IF_ERROR(iree_hal_webgpu_command_buffer_acquire_command_encoder(
508+
command_buffer, &command_encoder));
514509

515510
// TODO(benvanik): ensure this works right when in a compute pass.
516511
char label_str[128] = {0};
517512
memcpy(label_str, label.data, iree_min(sizeof(label_str) - 1, label.size));
518513
wgpuCommandEncoderPushDebugGroup(command_encoder, label_str);
514+
515+
return iree_ok_status();
519516
}
520517

521-
static void iree_hal_webgpu_command_buffer_end_debug_group(
518+
static iree_status_t iree_hal_webgpu_command_buffer_end_debug_group(
522519
iree_hal_command_buffer_t* base_command_buffer) {
523520
iree_hal_webgpu_command_buffer_t* command_buffer =
524521
iree_hal_webgpu_command_buffer_cast(base_command_buffer);
525522

526523
WGPUCommandEncoder command_encoder = NULL;
527-
iree_status_t status = iree_hal_webgpu_command_buffer_acquire_command_encoder(
528-
command_buffer, &command_encoder);
529-
if (!iree_status_is_ok(status)) {
530-
// TODO(benvanik): mark recording as failed.
531-
iree_status_ignore(status);
532-
return;
533-
}
524+
IREE_RETURN_IF_ERROR(iree_hal_webgpu_command_buffer_acquire_command_encoder(
525+
command_buffer, &command_encoder));
534526

535527
wgpuCommandEncoderPopDebugGroup(command_encoder);
528+
529+
return iree_ok_status();
536530
}
537531

538532
static iree_status_t iree_hal_webgpu_command_buffer_execution_barrier(

runtime/src/iree/hal/command_buffer.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,27 +289,28 @@ iree_hal_command_buffer_end(iree_hal_command_buffer_t* command_buffer) {
289289
return status;
290290
}
291291

292-
IREE_API_EXPORT void iree_hal_command_buffer_begin_debug_group(
292+
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_begin_debug_group(
293293
iree_hal_command_buffer_t* command_buffer, iree_string_view_t label,
294294
iree_hal_label_color_t label_color,
295295
const iree_hal_label_location_t* location) {
296296
IREE_ASSERT_ARGUMENT(command_buffer);
297-
IF_VALIDATING(command_buffer,
298-
iree_hal_command_buffer_begin_debug_group_validation(
299-
command_buffer, VALIDATION_STATE(command_buffer), label,
300-
label_color, location));
301-
_VTABLE_DISPATCH(command_buffer, begin_debug_group)
302-
(command_buffer, label, label_color, location);
297+
IF_VALIDATING(command_buffer, {
298+
IREE_RETURN_IF_ERROR(iree_hal_command_buffer_begin_debug_group_validation(
299+
command_buffer, VALIDATION_STATE(command_buffer), label, label_color,
300+
location));
301+
});
302+
return _VTABLE_DISPATCH(command_buffer, begin_debug_group)(
303+
command_buffer, label, label_color, location);
303304
}
304305

305-
IREE_API_EXPORT void iree_hal_command_buffer_end_debug_group(
306+
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_end_debug_group(
306307
iree_hal_command_buffer_t* command_buffer) {
307308
IREE_ASSERT_ARGUMENT(command_buffer);
308-
IF_VALIDATING(command_buffer,
309-
iree_hal_command_buffer_end_debug_group_validation(
310-
command_buffer, VALIDATION_STATE(command_buffer)));
311-
_VTABLE_DISPATCH(command_buffer, end_debug_group)
312-
(command_buffer);
309+
IF_VALIDATING(command_buffer, {
310+
IREE_RETURN_IF_ERROR(iree_hal_command_buffer_end_debug_group_validation(
311+
command_buffer, VALIDATION_STATE(command_buffer)));
312+
});
313+
return _VTABLE_DISPATCH(command_buffer, end_debug_group)(command_buffer);
313314
}
314315

315316
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_execution_barrier(

runtime/src/iree/hal/command_buffer.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,11 @@ IREE_API_EXPORT iree_device_size_t iree_hal_collective_element_byte_count(
422422
typedef uint64_t iree_hal_dispatch_flags_t;
423423
enum iree_hal_dispatch_flag_bits_t {
424424
IREE_HAL_DISPATCH_FLAG_NONE = 0,
425+
426+
// Indirect parameters such as workgroup count are static at the time the
427+
// command buffer is issued. This is in contrast to dynamic parameters that
428+
// may be changed by dispatches within the same command buffer.
429+
IREE_HAL_DISPATCH_FLAG_STATIC_INDIRECT_PARAMETERS = 1ull << 0,
425430
};
426431

427432
// An RGBA color.
@@ -637,13 +642,13 @@ iree_hal_command_buffer_end(iree_hal_command_buffer_t* command_buffer);
637642
// An optional RGBA color to show in the debug UI may be provided via
638643
// |label_color|; otherwise iree_hal_label_color_unspecified can be used to let
639644
// the debug tool choose.
640-
IREE_API_EXPORT void iree_hal_command_buffer_begin_debug_group(
645+
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_begin_debug_group(
641646
iree_hal_command_buffer_t* command_buffer, iree_string_view_t label,
642647
iree_hal_label_color_t label_color,
643648
const iree_hal_label_location_t* location);
644649

645650
// Pops a debug group from the stack.
646-
IREE_API_EXPORT void iree_hal_command_buffer_end_debug_group(
651+
IREE_API_EXPORT iree_status_t iree_hal_command_buffer_end_debug_group(
647652
iree_hal_command_buffer_t* command_buffer);
648653

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

869-
void(IREE_API_PTR* begin_debug_group)(
874+
iree_status_t(IREE_API_PTR* begin_debug_group)(
870875
iree_hal_command_buffer_t* command_buffer, iree_string_view_t label,
871876
iree_hal_label_color_t label_color,
872877
const iree_hal_label_location_t* location);
873-
void(IREE_API_PTR* end_debug_group)(
878+
iree_status_t(IREE_API_PTR* end_debug_group)(
874879
iree_hal_command_buffer_t* command_buffer);
875880

876881
iree_status_t(IREE_API_PTR* execution_barrier)(

runtime/src/iree/hal/command_buffer_validation.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,20 @@ iree_status_t iree_hal_command_buffer_end_validation(
258258
return iree_ok_status();
259259
}
260260

261-
void iree_hal_command_buffer_begin_debug_group_validation(
261+
iree_status_t iree_hal_command_buffer_begin_debug_group_validation(
262262
iree_hal_command_buffer_t* command_buffer,
263263
iree_hal_command_buffer_validation_state_t* validation_state,
264264
iree_string_view_t label, iree_hal_label_color_t label_color,
265265
const iree_hal_label_location_t* location) {
266266
++validation_state->debug_group_depth;
267+
return iree_ok_status();
267268
}
268269

269-
void iree_hal_command_buffer_end_debug_group_validation(
270+
iree_status_t iree_hal_command_buffer_end_debug_group_validation(
270271
iree_hal_command_buffer_t* command_buffer,
271272
iree_hal_command_buffer_validation_state_t* validation_state) {
272273
--validation_state->debug_group_depth;
274+
return iree_ok_status();
273275
}
274276

275277
iree_status_t iree_hal_command_buffer_execution_barrier_validation(

runtime/src/iree/hal/command_buffer_validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ iree_status_t iree_hal_command_buffer_end_validation(
5757
iree_hal_command_buffer_t* command_buffer,
5858
iree_hal_command_buffer_validation_state_t* validation_state);
5959

60-
void iree_hal_command_buffer_begin_debug_group_validation(
60+
iree_status_t iree_hal_command_buffer_begin_debug_group_validation(
6161
iree_hal_command_buffer_t* command_buffer,
6262
iree_hal_command_buffer_validation_state_t* validation_state,
6363
iree_string_view_t label, iree_hal_label_color_t label_color,
6464
const iree_hal_label_location_t* location);
6565

66-
void iree_hal_command_buffer_end_debug_group_validation(
66+
iree_status_t iree_hal_command_buffer_end_debug_group_validation(
6767
iree_hal_command_buffer_t* command_buffer,
6868
iree_hal_command_buffer_validation_state_t* validation_state);
6969

runtime/src/iree/hal/drivers/cuda/graph_command_buffer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static iree_status_t iree_hal_cuda_graph_command_buffer_end(
380380
return iree_ok_status();
381381
}
382382

383-
static void iree_hal_cuda_graph_command_buffer_begin_debug_group(
383+
static iree_status_t iree_hal_cuda_graph_command_buffer_begin_debug_group(
384384
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
385385
iree_hal_label_color_t label_color,
386386
const iree_hal_label_location_t* location) {
@@ -393,15 +393,18 @@ static void iree_hal_cuda_graph_command_buffer_begin_debug_group(
393393
location ? location->file.data : NULL, location ? location->file.size : 0,
394394
location ? location->line : 0,
395395
/*func_name=*/NULL, 0, label.data, label.size);
396+
397+
return iree_ok_status();
396398
}
397399

398-
static void iree_hal_cuda_graph_command_buffer_end_debug_group(
400+
static iree_status_t iree_hal_cuda_graph_command_buffer_end_debug_group(
399401
iree_hal_command_buffer_t* base_command_buffer) {
400402
iree_hal_cuda_graph_command_buffer_t* command_buffer =
401403
iree_hal_cuda_graph_command_buffer_cast(base_command_buffer);
402404
(void)command_buffer;
403405
IREE_CUDA_GRAPH_COMMAND_BUFFER_TRACE_ZONE_END(
404406
command_buffer, IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);
407+
return iree_ok_status();
405408
}
406409

407410
static iree_status_t

runtime/src/iree/hal/drivers/cuda/stream_command_buffer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static iree_status_t iree_hal_cuda_stream_command_buffer_end(
218218
return iree_ok_status();
219219
}
220220

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

236236
// TODO: pass along to CUPTI if available.
237+
238+
return iree_ok_status();
237239
}
238240

239-
static void iree_hal_cuda_stream_command_buffer_end_debug_group(
241+
static iree_status_t iree_hal_cuda_stream_command_buffer_end_debug_group(
240242
iree_hal_command_buffer_t* base_command_buffer) {
241243
iree_hal_cuda_stream_command_buffer_t* command_buffer =
242244
iree_hal_cuda_stream_command_buffer_cast(base_command_buffer);
@@ -247,6 +249,8 @@ static void iree_hal_cuda_stream_command_buffer_end_debug_group(
247249
IREE_HAL_STREAM_TRACE_ZONE_END(command_buffer->tracing_context,
248250
&command_buffer->tracing_event_list,
249251
IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);
252+
253+
return iree_ok_status();
250254
}
251255

252256
static iree_status_t iree_hal_cuda_stream_command_buffer_execution_barrier(

runtime/src/iree/hal/drivers/hip/graph_command_buffer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static iree_status_t iree_hal_hip_graph_command_buffer_end(
389389
return iree_ok_status();
390390
}
391391

392-
static void iree_hal_hip_graph_command_buffer_begin_debug_group(
392+
static iree_status_t iree_hal_hip_graph_command_buffer_begin_debug_group(
393393
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
394394
iree_hal_label_color_t label_color,
395395
const iree_hal_label_location_t* location) {
@@ -402,15 +402,18 @@ static void iree_hal_hip_graph_command_buffer_begin_debug_group(
402402
location ? location->file.data : NULL, location ? location->file.size : 0,
403403
location ? location->line : 0,
404404
/*func_name=*/NULL, 0, label.data, label.size);
405+
406+
return iree_ok_status();
405407
}
406408

407-
static void iree_hal_hip_graph_command_buffer_end_debug_group(
409+
static iree_status_t iree_hal_hip_graph_command_buffer_end_debug_group(
408410
iree_hal_command_buffer_t* base_command_buffer) {
409411
iree_hal_hip_graph_command_buffer_t* command_buffer =
410412
iree_hal_hip_graph_command_buffer_cast(base_command_buffer);
411413
(void)command_buffer;
412414
IREE_HIP_GRAPH_COMMAND_BUFFER_TRACE_ZONE_END(
413415
command_buffer, IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);
416+
return iree_ok_status();
414417
}
415418

416419
static iree_status_t

runtime/src/iree/hal/drivers/hip/stream_command_buffer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static iree_status_t iree_hal_hip_stream_command_buffer_end(
213213
return iree_ok_status();
214214
}
215215

216-
static void iree_hal_hip_stream_command_buffer_begin_debug_group(
216+
static iree_status_t iree_hal_hip_stream_command_buffer_begin_debug_group(
217217
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
218218
iree_hal_label_color_t label_color,
219219
const iree_hal_label_location_t* location) {
@@ -227,9 +227,11 @@ static void iree_hal_hip_stream_command_buffer_begin_debug_group(
227227
location ? location->file.data : NULL, location ? location->file.size : 0,
228228
location ? location->line : 0,
229229
/*func_name=*/NULL, 0, label.data, label.size);
230+
231+
return iree_ok_status();
230232
}
231233

232-
static void iree_hal_hip_stream_command_buffer_end_debug_group(
234+
static iree_status_t iree_hal_hip_stream_command_buffer_end_debug_group(
233235
iree_hal_command_buffer_t* base_command_buffer) {
234236
iree_hal_hip_stream_command_buffer_t* command_buffer =
235237
iree_hal_hip_stream_command_buffer_cast(base_command_buffer);
@@ -238,6 +240,8 @@ static void iree_hal_hip_stream_command_buffer_end_debug_group(
238240
IREE_HAL_STREAM_TRACE_ZONE_END(command_buffer->tracing_context,
239241
&command_buffer->tracing_event_list,
240242
IREE_HAL_STREAM_TRACING_VERBOSITY_COARSE);
243+
244+
return iree_ok_status();
241245
}
242246

243247
static iree_status_t iree_hal_hip_stream_command_buffer_execution_barrier(

runtime/src/iree/hal/drivers/local_task/task_command_buffer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,18 @@ iree_status_t iree_hal_task_command_buffer_issue(
380380
// iree_hal_task_command_buffer_t debug utilities
381381
//===----------------------------------------------------------------------===//
382382

383-
static void iree_hal_task_command_buffer_begin_debug_group(
383+
static iree_status_t iree_hal_task_command_buffer_begin_debug_group(
384384
iree_hal_command_buffer_t* base_command_buffer, iree_string_view_t label,
385385
iree_hal_label_color_t label_color,
386386
const iree_hal_label_location_t* location) {
387387
// TODO(benvanik): tracy event stack.
388+
return iree_ok_status();
388389
}
389390

390-
static void iree_hal_task_command_buffer_end_debug_group(
391+
static iree_status_t iree_hal_task_command_buffer_end_debug_group(
391392
iree_hal_command_buffer_t* base_command_buffer) {
392393
// TODO(benvanik): tracy event stack.
394+
return iree_ok_status();
393395
}
394396

395397
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)