Skip to content

Commit 753bc9e

Browse files
committed
[L0v2] fix unbounded memory growth of queue's submitted kernels
L0v2 avoids internally tracking each kernel submission through an event for lifetime management. Instead, when a kernel is submitted to the queue, its handle is added to a vector, to be removed at the next queue synchronization point, urQueueFinish(). This is a much more efficient way of handling kernel tracking, since it avoids taking and storing an event. However, if the application never synchronizes the queue, this vector of submitted kernels will grow unbounded. This patch forcibly synchronizes the queue once the submitted kernels vector reaches a threshold.
1 parent 7b05a8c commit 753bc9e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

unified-runtime/source/adapters/level_zero/v2/queue_immediate_in_order.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,20 @@ ur_result_t ur_queue_immediate_in_order_t::queueFinish() {
165165
return UR_RESULT_SUCCESS;
166166
}
167167

168+
// In order to avoid tracking individual events for each kernel submission on the queue,
169+
// the adapter simply keeps a vector of all handles of submitted kernels, prunning it at
170+
// queue synchronization, urQueueFinish(), knowing that all previously enqueued kernels
171+
// have finished.
172+
// However, some applications might not explicitly synchronize the queue, in which case
173+
// the submitted kernels might grow unbounded. To prevent that, we need to cap the vector's
174+
// size, and forcibly synchronize the queue once it exceeds the limit.
175+
#define MAX_QUEUE_SUBMITTED_KERNELS 1024
176+
168177
void ur_queue_immediate_in_order_t::recordSubmittedKernel(
169178
ur_kernel_handle_t hKernel) {
179+
if (submittedKernels.size() > MAX_QUEUE_SUBMITTED_KERNELS) {
180+
queueFinish();
181+
}
170182
submittedKernels.push_back(hKernel);
171183
hKernel->RefCount.increment();
172184
}

0 commit comments

Comments
 (0)