Skip to content

Commit

Permalink
[EXP][Command-Buffer] Optimize L0 command buffer submission
Browse files Browse the repository at this point in the history
- Adds command buffer property to explicitly enable profiling
- Add ability to enforce use of in-order command lists
  • Loading branch information
mfrancepillois authored and Bensuo committed Mar 20, 2024
1 parent ed1f8bf commit f264346
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 145 deletions.
3 changes: 3 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7892,6 +7892,9 @@ typedef struct ur_exp_command_buffer_desc_t {
///< ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC
const void *pNext; ///< [in][optional] pointer to extension-specific structure
ur_bool_t isUpdatable; ///< [in] Commands in a finalized command-buffer can be updated.
ur_bool_t isInOrder; ///< [in] Commands in a command-buffer may be executed in-order without
///< explicit dependencies.
ur_bool_t enableProfiling; ///< [in] Command-buffer profiling is enabled.

} ur_exp_command_buffer_desc_t;

Expand Down
10 changes: 10 additions & 0 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9401,6 +9401,16 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_exp_command_bu

os << (params.isUpdatable);

os << ", ";
os << ".isInOrder = ";

os << (params.isInOrder);

os << ", ";
os << ".enableProfiling = ";

os << (params.enableProfiling);

os << "}";
return os;
}
Expand Down
7 changes: 5 additions & 2 deletions scripts/core/EXP-COMMAND-BUFFER.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ Command-Buffer Creation
Command-Buffers are tied to a specific ${x}_context_handle_t and
${x}_device_handle_t. ${x}CommandBufferCreateExp optionally takes a descriptor
to provide additional properties for how the command-buffer should be
constructed. The only unique member defined in ${x}_exp_command_buffer_desc_t
is ``isUpdatable``, which should be set to ``true`` to support :ref:`updating
constructed. The members defined in ${x}_exp_command_buffer_desc_t are:
* ``isUpdatable``, which should be set to ``true`` to support :ref:`updating
command-buffer commands`.
* ``isInOrder``, which should be set to ``true`` to enable the graph workload
to be submitted to an in-order command-list.
* ``enableProfiling``, which should be set to ``true`` to enable graph profling.

Command-buffers are reference counted and can be retained and released by
calling ${x}CommandBufferRetainExp and ${x}CommandBufferReleaseExp respectively.
Expand Down
6 changes: 6 additions & 0 deletions scripts/core/exp-command-buffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ members:
- type: $x_bool_t
name: isUpdatable
desc: "[in] Commands in a finalized command-buffer can be updated."
- type: $x_bool_t
name: isInOrder
desc: "[in] Commands in a command-buffer may be executed in-order without explicit dependencies."
- type: $x_bool_t
name: enableProfiling
desc: "[in] Command-buffer profiling is enabled."
--- #--------------------------------------------------------------------------
type: struct
desc: "Descriptor type for updating a kernel command memobj argument."
Expand Down
398 changes: 260 additions & 138 deletions source/adapters/level_zero/command_buffer.cpp

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion source/adapters/level_zero/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
ze_command_list_handle_t CommandList,
ze_command_list_handle_t CommandListResetEvents,
ZeStruct<ze_command_list_desc_t> ZeDesc,
const ur_exp_command_buffer_desc_t *Desc);
const ur_exp_command_buffer_desc_t *Desc, const bool IsInOrderCmdList);

~ur_exp_command_buffer_handle_t_();

Expand Down Expand Up @@ -82,6 +82,14 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
bool IsUpdatable = false;
// Indicates if command buffer was finalized.
bool IsFinalized = false;
// Command-buffer profiling is enabled.
bool IsProfilingEnabled = false;
// Command-buffer can be submitted to an in-order command-list.
bool IsInOrderCmdList;
// List of kernels.
// This list is needed to release all kernels retained by the
// command_buffer.
std::vector<ur_kernel_handle_t> KernelsList;
};

struct ur_exp_command_buffer_command_handle_t_ : public _ur_object {
Expand Down
8 changes: 5 additions & 3 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urExtEventCreate(
ur_event_handle_t
*Event ///< [out] pointer to the handle of the event object created.
) {
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
UR_CALL(EventCreate(Context, nullptr, false, true, false, Event));

(*Event)->RefCountExternal++;
ZE2UR_CALL(zeEventHostSignal, ((*Event)->ZeEvent));
Expand All @@ -778,7 +778,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
// we dont have urEventCreate, so use this check for now to know that
// the call comes from urEventCreate()
if (NativeEvent == nullptr) {
UR_CALL(EventCreate(Context, nullptr, false, true, Event));
UR_CALL(EventCreate(Context, nullptr, false, true, false, Event));

(*Event)->RefCountExternal++;
ZE2UR_CALL(zeEventHostSignal, ((*Event)->ZeEvent));
Expand Down Expand Up @@ -1057,9 +1057,11 @@ ur_result_t CleanupCompletedEvent(ur_event_handle_t Event, bool QueueLocked,
//
ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue,
bool IsMultiDevice, bool HostVisible,
bool ForceDisableProfiling,
ur_event_handle_t *RetEvent) {

bool ProfilingEnabled = !Queue || Queue->isProfilingEnabled();
bool ProfilingEnabled =
ForceDisableProfiling ? false : (!Queue || Queue->isProfilingEnabled());

ur_device_handle_t Device = nullptr;

Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
ur_result_t urEventReleaseInternal(ur_event_handle_t Event);
ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue,
bool IsMultiDevice, bool HostVisible,
bool ForceDisableProfiling,
ur_event_handle_t *RetEvent);
} // extern "C"

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ ur_result_t createEventAndAssociateQueue(ur_queue_handle_t Queue,

if (*Event == nullptr)
UR_CALL(EventCreate(Queue->Context, Queue, IsMultiDevice,
HostVisible.value(), Event));
HostVisible.value(), false, Event));

(*Event)->UrQueue = Queue;
(*Event)->CommandType = CommandType;
Expand Down

0 comments on commit f264346

Please sign in to comment.