Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXP][Command-Buffer] Optimize L0 command-buffer submission #9

Closed
wants to merge 13 commits into from
Closed
3 changes: 3 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7813,6 +7813,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 @@ -9395,6 +9395,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
418 changes: 266 additions & 152 deletions source/adapters/level_zero/command_buffer.cpp

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion source/adapters/level_zero/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
ur_device_handle_t Device,
ze_command_list_handle_t CommandList,
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 @@ -70,4 +71,12 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
// Event which a command-buffer waits on until the wait-list dependencies
// passed to a command-buffer enqueue have been satisfied.
ur_event_handle_t WaitEvent = nullptr;
// 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;
};
8 changes: 5 additions & 3 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,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 @@ -770,7 +770,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 @@ -1049,9 +1049,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 @@ -1517,7 +1517,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