Conversation
crtrott
left a comment
There was a problem hiding this comment.
I don't think I want this this way. My current thinking is that the HeavyWeight hint is what we want to reuse. Essentially if its heavy weight go back to constant launch. We also need to discuss if we want to keep the "require" mechanism, or simply add these as template parameters directly to the policy - that is an orthogonal discussion though.
|
You mean re-use the HeavyWeight hint instead of introducing a new WorkItemProperty ? I can change and reuse HeavyWeight if you prefer. |
Signed-off-by: Pierre Kestener <pierre.kestener@cea.fr>
8980a57 to
910cec6
Compare
|
The reason I want to reuse the heavy weight one are multi-fold:
Does that make sense? |
There was a problem hiding this comment.
Pull request overview
This PR restores the CUDA “constant memory” kernel launch path (cuda_parallel_launch_constant_memory) to address a reported performance regression in Kokkos >= 5 (vs 4.7.02) for certain CUDA kernels, and wires the selection so users can opt into constant-memory launch behavior via WorkItemProperty::HintHeavyWeight (including when KOKKOS_IMPL_CUDA_USE_GRID_CONSTANT is enabled).
Changes:
- Re-enables/ungates the constant-memory launch buffer and kernel entry points in
Kokkos_Cuda_KernelLaunch.hpp. - Updates CUDA launch-mechanism deduction so
HintHeavyWeightcan select constant-memory launch even under grid-constant builds. - Makes the ConstantMemory invoker/types available in grid-constant configurations (previously compiled out).
| // If KOKKOS_IMPL_CUDA_USE_GRID_CONSTANT is used we leverage implicit constant | ||
| // cache use via an argument attribute in the "local launch" mechanism. At that | ||
| // point we only need local and global launch - the latter for functors that | ||
| // exceed the kernel argument limit which is now 32kB. Local launch is always | ||
| // strictly better than global launch - which means the light weight/heavy | ||
| // weight property can be ignored - the only thing that matters is the size of | ||
| // the functor. |
| @@ -42,7 +41,6 @@ | |||
| [Kokkos::Impl::CudaTraits::ConstantMemoryUsage / sizeof(unsigned long)]; | |||
|
|
|||
| #endif | |||
There was a problem hiding this comment.
Yes, that is a good point. It's probably a bad idea to permanently allocate buffer kokkos_impl_cuda_constant_memory_buffer only for constant memory launch mechanism especially if this mechanism is not used, or only for a few kernels.
Maybe that ConstantMemoryUsage could be made configurable (from cmake) ? But this would introduce a backend specific parameter
It seems to me a bit complex; in my particular case, the kernel that benefits from the constant memory launch weights 1088 Bytes, so a buffer much smaller than 32KiB would be enough. Not sure there is a good solution here.
There was a problem hiding this comment.
yeah lets leave it like this, that was the previous behavior too.
|
|
||
| //------------------------------------------------------------------------------ | ||
| // <editor-fold desc="Constant Memory"> {{{2 | ||
| #ifndef KOKKOS_IMPL_CUDA_USE_GRID_CONSTANT | ||
| template <class DriverType, unsigned int MaxThreadsPerBlock, | ||
| unsigned int MinBlocksPerSM> | ||
| struct CudaParallelLaunchKernelFunc< |
There was a problem hiding this comment.
I didn't check whether this observation is correct (that we don't pre-populate it), but if we didn't we should.
There was a problem hiding this comment.
This observation is true. I updated the branch to address this.
| static constexpr CudaLaunchMechanism launch_mechanism = | ||
| #ifdef KOKKOS_IMPL_CUDA_USE_GRID_CONSTANT | ||
| default_launch_mechanism; | ||
| (((property & heavy_weight) == heavy_weight) and | ||
| (sizeof(DriverType) < CudaTraits::ConstantMemoryUsage)) | ||
| ? CudaLaunchMechanism::ConstantMemory | ||
| : default_launch_mechanism; |
There was a problem hiding this comment.
we do have tests for all sizes, and did decide against testing explicitly for the path back in the day.
|
If this becomes our official way of working around this Cuda issue, we should have documentation for |
…ernal constructor.
We observed situations where __grid_constant attribute for the functor does NOT result in the same optimization behavior as when the functor is stored explicitly in constant cache. We are considering that a compiler issue. This allows opting into classical constant cache launch mechanism via the HeavyWeight kernel trait. Signed-off-by: Pierre Kestener <pierre.kestener@cea.fr>
This is related to the discussion on slack about performance regression observed in kokkos >= 5 compared to 4.7.02 when using the Cuda backend.
We observed that for some cuda kernels the actual register count increased by more than 50, leading to both smaller device occupancy and reduced time to solution by about 30%. This performance regression is not due to the introduction of
__grid_constant__kernel argument annotation, but to the removal of the constant memory launch mechanism. In this PR we restore this lauch mechanism.List of modifications :
cuda_parallel_launch_constant_memorycuda_parallel_launch_constant_memoryis a user choice through the use ofa new execution policy trait canlledHintHeavyWeightImplForceConstantLaunch(introduced has a member ofWorkItemProperty)Example of use:
Changelog Entry