Skip to content

Commit 7b08fdf

Browse files
[SYCL][CUDA] Add bounds check on kernel launch (#1178)
Kernel launching should fail with PI_INVALID_WORK_GROUP_SIZE when the specified work-item sizes are out of bounds. Signed-off-by: Steffen Larsen <[email protected]>
1 parent c900248 commit 7b08fdf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,19 @@ pi_result cuda_piEnqueueKernelLaunch(
17881788
}
17891789
}
17901790

1791+
size_t maxThreadsPerBlock[3] = {};
1792+
retError = cuda_piDeviceGetInfo(command_queue->device_,
1793+
PI_DEVICE_INFO_MAX_WORK_ITEM_SIZES,
1794+
sizeof(maxThreadsPerBlock),
1795+
maxThreadsPerBlock, nullptr);
1796+
assert(retError == PI_SUCCESS);
1797+
1798+
for (size_t i = 0; i < work_dim; i++) {
1799+
if(size_t(threadsPerBlock[i]) > maxThreadsPerBlock[i]) {
1800+
return PI_INVALID_WORK_GROUP_SIZE;
1801+
}
1802+
}
1803+
17911804
int blocksPerGrid[3] = { 1, 1, 1 };
17921805

17931806
for (size_t i = 0; i < work_dim; i++) {

0 commit comments

Comments
 (0)