Skip to content

[SYCL][CUDA] Handle large Y/Z range dimensions. #7968

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

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,32 @@ int getAttribute(pi_device device, CUdevice_attribute attribute) {
// Determine local work sizes that result in uniform work groups.
// The default threadsPerBlock only require handling the first work_dim
// dimension.
void guessLocalWorkSize(size_t *threadsPerBlock, const size_t *global_work_size,
void guessLocalWorkSize(_pi_device *device, size_t *threadsPerBlock,
const size_t *global_work_size,
const size_t maxThreadsPerBlock[3], pi_kernel kernel,
pi_uint32 local_size) {
assert(threadsPerBlock != nullptr);
assert(global_work_size != nullptr);
assert(kernel != nullptr);
int recommendedBlockSize, minGrid;
int minGrid, maxBlockSize, gridDim[3];

cuDeviceGetAttribute(&gridDim[1], CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y,
device->get());
cuDeviceGetAttribute(&gridDim[2], CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z,
device->get());

threadsPerBlock[1] = ((global_work_size[1] - 1) / gridDim[1]) + 1;
threadsPerBlock[2] = ((global_work_size[2] - 1) / gridDim[2]) + 1;

PI_CHECK_ERROR(cuOccupancyMaxPotentialBlockSize(
&minGrid, &recommendedBlockSize, kernel->get(), NULL, local_size,
&minGrid, &maxBlockSize, kernel->get(), NULL, local_size,
maxThreadsPerBlock[0]));

(void)minGrid; // Not used, avoid warnings
gridDim[0] = maxBlockSize / (threadsPerBlock[1] * threadsPerBlock[2]);

threadsPerBlock[0] = std::min(
maxThreadsPerBlock[0],
std::min(global_work_size[0], static_cast<size_t>(recommendedBlockSize)));
threadsPerBlock[0] =
std::min(maxThreadsPerBlock[0],
std::min(global_work_size[0], static_cast<size_t>(gridDim[0])));

// Find a local work group size that is a divisor of the global
// work group size to produce uniform work groups.
Expand Down Expand Up @@ -3124,8 +3133,9 @@ pi_result cuda_piEnqueueKernelLaunch(
return err;
}
} else {
guessLocalWorkSize(threadsPerBlock, global_work_size,
maxThreadsPerBlock, kernel, local_size);
guessLocalWorkSize(command_queue->device_, threadsPerBlock,
global_work_size, maxThreadsPerBlock, kernel,
local_size);
}
}

Expand Down