Skip to content

Commit f99e1cd

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 f99e1cd

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
169+
// the queue, the adapter simply keeps a vector of all handles of submitted
170+
// kernels, prunning it at queue synchronization, urQueueFinish(), knowing that
171+
// all previously enqueued kernels have finished. However, some applications
172+
// might not explicitly synchronize the queue, in which case the submitted
173+
// 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)