From 7764648dca648b093138842b1f61c2e58dec2cbb Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Mon, 16 Dec 2019 13:00:48 +0000 Subject: [PATCH] [SYCL][CUDA] Bounds check on kernel launch Signed-off-by: Steffen Larsen --- sycl/plugins/cuda/pi_cuda.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sycl/plugins/cuda/pi_cuda.cpp b/sycl/plugins/cuda/pi_cuda.cpp index 8a44c3ff6eb56..6673503e0dcf4 100644 --- a/sycl/plugins/cuda/pi_cuda.cpp +++ b/sycl/plugins/cuda/pi_cuda.cpp @@ -1788,6 +1788,19 @@ pi_result cuda_piEnqueueKernelLaunch( } } + size_t maxThreadsPerBlock[3] = {}; + retError = cuda_piDeviceGetInfo(command_queue->device_, + PI_DEVICE_INFO_MAX_WORK_ITEM_SIZES, + sizeof(maxThreadsPerBlock), + maxThreadsPerBlock, nullptr); + assert(retError == PI_SUCCESS); + + for (size_t i = 0; i < work_dim; i++) { + if(size_t(threadsPerBlock[i]) > maxThreadsPerBlock[i]) { + return PI_INVALID_WORK_GROUP_SIZE; + } + } + int blocksPerGrid[3] = { 1, 1, 1 }; for (size_t i = 0; i < work_dim; i++) {