Skip to content
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

CUDA Max Blocks Fix #612

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 34 additions & 2 deletions include/RAJA/policy/cuda/kernel/CudaKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,13 @@ struct CudaLaunchHelper<cuda_launch<async0, num_blocks, num_threads>,StmtList,Da
}
}

//
// actual_threads can be modified in the case where
// the requested number of theads would cause the
// max_blocks to be 0
//
inline static void max_blocks(int shmem_size,
int &max_blocks, int actual_threads)
int &max_blocks, int &actual_threads)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual_threads should not be changed at this point if num_threads was specified at compile-time.

{
auto func = internal::CudaKernelLauncher<Data, executor_t>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the fixed kernel launch function if num_threads is greater than zero.
internal::CudaKernelLauncherFixed<num_threads, Data, executor_t>
I broke this when I consolidated the CudaLaunchHelper implementation into a single code base.


Expand All @@ -314,6 +319,23 @@ struct CudaLaunchHelper<cuda_launch<async0, num_blocks, num_threads>,StmtList,Da
internal::cuda_occupancy_max_blocks<Self>(
func, shmem_size, max_blocks, actual_threads);

if(max_blocks == 0) {

//
// actual_threads is too high for the kernel to run
// successfully due to resource constraints reset to
// something that is possible
//
int min_grid_size, max_block_size;
// NOTE: min_grid_size is the minimum grid size needed
// to achieve the best potential occupancy
cudaErrchk(cudaOccupancyMaxPotentialBlockSize(
MrBurmark marked this conversation as resolved.
Show resolved Hide resolved
&min_grid_size, &max_block_size, func, shmem_size));
actual_threads = max_block_size;
max_blocks = min_grid_size;
}


} else {

//
Expand Down Expand Up @@ -477,7 +499,17 @@ struct StatementExecutor<
// Compute the MAX physical kernel blocks
//
int max_blocks;
launch_t::max_blocks(shmem, max_blocks, launch_dims.num_threads());
int adjusted_threads = launch_dims.num_threads();
launch_t::max_blocks(shmem, max_blocks, adjusted_threads);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adjusted_threads should be corrected if less than min_threads


//
// Redo fit with adjusted_threads
//
if(launch_dims.num_threads() != adjusted_threads) {
fit_threads = fitCudaDims(
adjusted_threads, launch_dims.threads, launch_dims.min_threads);
launch_dims.threads = fit_threads;
}

int use_blocks;

Expand Down