Add an option to disable CUDA constant memory dispatch; add CUPTI-based tests to check that various expected launch types are used - #9542
Conversation
Signed-off-by: Namjae Choi <Namjae.Choi@inl.gov>
Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
…guments, constant memory, or global memory according to its driver size; sizing was picked to be independent of compile-time constant memory launch support or grid constant usage. Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
…a_KernelLaunch.hpp with constexpr logic Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
…_Cuda_KernelLaunch.hpp with constexpr logic. Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
…ernelLaunch.hpp b/c it has not been updated to reflect grid constant and constant memory launch changes Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
Signed-off-by: Evan Weinberg <eweinberg@nvidia.com>
21a4380 to
0fdcdf3
Compare
|
Thank you for incorporating my change. I will close my one. |
crtrott
left a comment
There was a problem hiding this comment.
OK we need to talk about this a bit more. I am not sure that introducing an IMPL option makes too much sense. Clearly this is meant for downstream users to use, and we can't come back in the end "oh you have a problem with this, too bad this is just impl stuff".
Also KOKKOS_IMPL_CUDA_USE_GRID_CONSTANT is now unused or? Probably can be removed (that btw seems like a change we could do either way).
Ah yeah, non-impl makes more sense. I "just" copied that convention from the PR this superseded and didn't think about it too much. I'll change that up tomorrow.
It's still used here to specify launches with/without kokkos/core/src/Cuda/Kokkos_Cuda_Instance.hpp Lines 28 to 31 in 97cfb7e It's CUDA 11.7+ (so relevant for all CUDA versions supported by Kokkos), but unfortunately it's only Volta+, which is why it needs those details, and why we need 4k vs 32k values flying around, for ex, lower down in As for where all of the Disentangling the -> Put differently, I created a Creating |
|
Seeing that this PR proposes adding a test that verifies CUDA API calls, I wanted to bring ReProspect to your attention. ReProspect is a tool that @romintomasetti and I developed as part of Romin's PhD research, and that we recently published in JOSS. It's a Python package that allows the use of NVIDIA's tools for the analysis of CUDA programs to be scripted end-to-end in a concise Python script, up to programmatic test assertions. It covers CUDA API tracing through Nsight Systems, kernel profiling through Nsight Compute, and binary analysis through the CUDA binary utilities. We have used ReProspect to gain insight into various Kokkos PRs that we have worked on. In ReProspect's documentation, we have a getting started with CUDA API tracing example that is quite similar in spirit to the test in this PR. In our example, a CUDA program launches 4 kernels with a diamond dependency pattern, and ReProspect is used to verify that the CUDA API calls are as expected. We also have an example that uses ReProspect to trace the CUDA API calls that occur when Kokkos allocates a View. Looking at the test proposed in this PR, using ReProspect would lead to the test being structured as a pair of a Kokkos source file and a Python analysis script. The Kokkos source file would launch the kernels with the functors of the various sizes. The companion Python script would launch Nsight Systems on the executable, read the collected trace, and submit it to test assertions. The setup would likely involve running the test in a Docker container that provides Nsight Systems, Python, and ReProspect (as easy as I am not asking for changes on this PR. But a test that verifies CUDA API behavior is a test of a new type in Kokkos. If interest in tests of this type grows, it may be worth comparing approaches at some point, e.g., comparing using CUPTI as done here with using ReProspect. Happy to discuss! |
This PR includes and supersedes #9352 , as was discussed with @NamjaeChoi .
This PR makes CUDA constant-memory kernel launches configurable through the new
KOKKOS_ENABLE_IMPL_CUDA_CONSTANT_MEMORYoption, which is enabled by default to preserve existing behavior.This PR makes it possible to explicitly opt-out of Kokkos allocating constant memory for kernel launches across any/all compilation units. By default, no kernel launches will use constant memory anyway... unless a developer has explicitly opted in to constant memory launches via
HintHeavyWeight.The motivation for this PR is purely "don't allocate what you don't use". If "you" (the developer) know, at compile time, you'll never use
HintHeavyWeightlaunches -> never need constant memory allocated for lambdas/functors... don't bother allocating it. (Put differently, I'm not endorsing the comments on how allocating constant memory can intersects with RDC in the PR this supersedes. I just think the idea in the PR is good on the merits.)Broad features of this PR:
constexprtraits representing constant-memory and grid-constant availability, allowing launch routing to handle build configurations without duplicating preprocessor branches.HintLightWeightandHintHeavyWeightconsistently across grid-constant configurations.Cuda::print_configuration().Testing:
Adds a CUPTI-based unit test that observes CUDA runtime calls to verify the selected route:
The CMake setup uses
CUDA::cuptiwhen available and includes fallback discovery for supported older CMake versions.The test is relatively coarse grained insofar as it uses functor sizes (64 bytes, 1024 bytes, 33000 bytes) that always trigger kernel argument, (kernel argument/constant memory), global memory independent of grid constant enabled/disabled or with minimal dependence on constant memory availability enabled/disabled.
It could be made more granular---very specific to probing the values in
Kokkos_Cuda_Instance.hppand performing checks against the logic depending on if grid constant is available or constant memory is compiled in... but at some point it all becomes tautological and we're just re-implementing the logic that's already there. In any case, it could be done if requested, just ask.Related issues / PRs
#9352
Changelog Entry
Unsure if this flag justifies a changelog entry---I guess it could, since opting into this flag when applicable is a (resource) optimization.
Documentation PR
Not yet, but once I've been given a thumbs up on the conventions in this PR I'll submit a PR to kokkos-documentation to update https://github.com/kokkos/kokkos-core-wiki/blob/main/docs/source/API/core/Macros.rst .