-
Notifications
You must be signed in to change notification settings - Fork 796
[SYCL][PI][L0] Add batching of multiple command into a command list before executing that command list. #2605
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
Changes from all commits
25ce7a7
2c7b671
579c83e
f2b8767
1293456
a7f0a65
077e040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,9 +177,13 @@ struct _pi_device : _pi_object { | |
// caller must pass a command queue to create a new fence for the new command | ||
// list if a command list/fence pair is not available. All Command Lists & | ||
// associated fences are destroyed at Device Release. | ||
// If AllowBatching is true, then the command list returned may already have | ||
// command in it, if AllowBatching is false, any open command lists that | ||
// already exist in Queue will be closed and executed. | ||
pi_result getAvailableCommandList(pi_queue Queue, | ||
ze_command_list_handle_t *ZeCommandList, | ||
ze_fence_handle_t *ZeFence); | ||
ze_fence_handle_t *ZeFence, | ||
bool AllowBatching = false); | ||
|
||
// Cache of the immutable device properties. | ||
ze_device_properties_t ZeDeviceProperties; | ||
|
@@ -268,8 +272,9 @@ struct _pi_context : _pi_object { | |
|
||
struct _pi_queue : _pi_object { | ||
_pi_queue(ze_command_queue_handle_t Queue, pi_context Context, | ||
pi_device Device) | ||
: ZeCommandQueue{Queue}, Context{Context}, Device{Device} {} | ||
pi_device Device, pi_uint32 QueueBatchSize) | ||
: ZeCommandQueue{Queue}, Context{Context}, Device{Device}, | ||
QueueBatchSize{QueueBatchSize} {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need batch size to be a member of a queue instead of just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was setting this code up for the future. By making this a field of the queue that gets set at queue creation time based on the global ZeCommandListBatchSize global variable/env var, I can allow a heuristic to change this on a queue specific basis without introducing any race/thread unsafe global var uses since fields of the queue are now all guarded in a thread safe manner. So, while not specifically necessary, I think it is an excellent way to make it easier to add heuristics for batching in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but please clarify this intention of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
|
||
// Level Zero command queue handle. | ||
ze_command_queue_handle_t ZeCommandQueue; | ||
|
@@ -291,25 +296,53 @@ struct _pi_queue : _pi_object { | |
// needed/used for the queue data structures. | ||
std::mutex PiQueueMutex; | ||
|
||
// Open command list field for batching commands into this queue. | ||
ze_command_list_handle_t ZeOpenCommandList = {nullptr}; | ||
ze_fence_handle_t ZeOpenCommandListFence = {nullptr}; | ||
pi_uint32 ZeOpenCommandListSize = {0}; | ||
|
||
// Approximate number of commands that are allowed to be batched for | ||
// this queue. | ||
// Added this member to the queue rather than using a global variable | ||
// so that future implementation could use heuristics to change this on | ||
// a queue specific basis. And by putting it in the queue itself, this | ||
// is thread safe because of the locking of the queue that occurs. | ||
pi_uint32 QueueBatchSize = {0}; | ||
|
||
// Map of all Command lists created with their associated Fence used for | ||
// tracking when the command list is available for use again. | ||
std::map<ze_command_list_handle_t, ze_fence_handle_t> ZeCommandListFenceMap; | ||
|
||
// Returns true if any commands for this queue are allowed to | ||
// be batched together. | ||
bool isBatchingAllowed(); | ||
|
||
// Resets the Command List and Associated fence in the ZeCommandListFenceMap. | ||
// If the reset command list should be made available, then MakeAvailable | ||
// needs to be set to true. The caller must verify that this command list and | ||
// fence have been signalled. | ||
pi_result resetCommandListFenceEntry(ze_command_list_handle_t ZeCommandList, | ||
bool MakeAvailable); | ||
|
||
// Attach a command list to this queue and allow it to remain open | ||
// and used for further batching. It may be executed immediately, | ||
// or it may be left open for other future command to be batched into. | ||
pi_result batchCommandList(ze_command_list_handle_t ZeCommandList, | ||
ze_fence_handle_t ZeFence); | ||
|
||
// Attach a command list to this queue, close, and execute it. | ||
// Note that this command list cannot be appended to after this. | ||
// The "is_blocking" tells if the wait for completion is requested. | ||
// The "IsBlocking" tells if the wait for completion is requested. | ||
// The "ZeFence" passed is used to track when the command list passed | ||
// has completed execution on the device and can be reused. | ||
pi_result executeCommandList(ze_command_list_handle_t ZeCommandList, | ||
ze_fence_handle_t ZeFence, | ||
bool is_blocking = false); | ||
bool IsBlocking = false); | ||
|
||
// If there is an open command list associated with this queue, | ||
// close it, exceute it, and reset ZeOpenCommandList, ZeCommandListFence, | ||
// and ZeOpenCommandListSize. | ||
pi_result executeOpenCommandList(); | ||
}; | ||
|
||
struct _pi_mem : _pi_object { | ||
|
Uh oh!
There was an error while loading. Please reload this page.