Repository navigation
[CUDAX] Refactor arch traits to be more structured and support arch-specific targets - #5064
Conversation
faa183a to
0b38f90
Compare
π© CI finished in 1h 01m: Pass: 100%/32 | Total: 3h 17m | Avg: 6m 10s | Max: 24m 12s | Hits: 99%/16022
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| CCCL Packaging | |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| +/- | CCCL Packaging |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
πβ Runner counts (total jobs: 32)
| # | Runner |
|---|---|
| 17 | linux-amd64-cpu16 |
| 6 | linux-amd64-gpu-rtx2080-latest-1 |
| 4 | windows-amd64-cpu16 |
| 4 | linux-arm64-cpu16 |
| 1 | linux-amd64-gpu-h100-latest-1 |
| struct traits_t | ||
| { | ||
| // Maximum number of threads per block | ||
| static constexpr int max_threads_per_block = 1024; |
There was a problem hiding this comment.
Why is this now a runtime value?
If we need that for python, we could turn this into a member function
[[nodiscard]] _CCCL_API static constexpr int max_threads_per_block() noexcept { return 1024; }This would allow this to be a plain function for python and usable at compiletime with C++
There was a problem hiding this comment.
I wanted to unify things a bit. Before I had the arch_common_traits, because there were both arch_traits_t and the arch type template and both needed the common fields. Fields in arch_common_traits were inherited by the arch type template, so they needed to be static constexpr.
Now I changed the approach and the arch types have a static constexpr member of type traits_t. Because the traits variable itself is static constexpr, I believe no fields need to be static constexpr in traits_t. I probably could keep them as static, but I don't think I want users to access those traits as statics directly as traits_t::foo_trait, I want them to do sm_XY::traits.foo_trait. So I decided to unify them all to be non-static members, I believe there is no loss of functionality apart from the mentioned usage that I don't like. But its possible that I missed something, let me know if you can think of something π
There was a problem hiding this comment.
I guess the size of the traits_t structure also changed and it might matter in some dynamic context, for example with device.arch_traits()? But I don't know if it matters unless traits are stored somewhere, which I don't think will be common.
There was a problem hiding this comment.
Still not of a fan of demoting compile time constants to runtime values. We probably want to use those in a if constexpr at some point
Note that you can always do sm_XY::traits.foo_trait for static variables too
miscco
left a comment
There was a problem hiding this comment.
Some questions regarding the shift towards runtime values
π© CI finished in 19m 37s: Pass: 100%/32 | Total: 4h 00m | Avg: 7m 31s | Max: 17m 05s | Hits: 80%/16022
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| CCCL Packaging | |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| +/- | CCCL Packaging |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
πβ Runner counts (total jobs: 32)
| # | Runner |
|---|---|
| 17 | linux-amd64-cpu16 |
| 6 | linux-amd64-gpu-rtx2080-latest-1 |
| 4 | windows-amd64-cpu16 |
| 4 | linux-arm64-cpu16 |
| 1 | linux-amd64-gpu-h100-latest-1 |
π© CI finished in 19m 04s: Pass: 100%/32 | Total: 4h 08m | Avg: 7m 45s | Max: 15m 46s | Hits: 79%/16218
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| CCCL Packaging | |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| +/- | CCCL Packaging |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
πβ Runner counts (total jobs: 32)
| # | Runner |
|---|---|
| 17 | linux-amd64-cpu16 |
| 6 | linux-amd64-gpu-rtx2080-latest-1 |
| 4 | windows-amd64-cpu16 |
| 4 | linux-arm64-cpu16 |
| 1 | linux-amd64-gpu-h100-latest-1 |
| // @brief Architecture type | ||
| // This type is a template that represents an architecture. It also contains the traits for that architecture. | ||
| template <id _Id> | ||
| struct type; |
There was a problem hiding this comment.
why do we need a type that represents an architecture? i think it would be simpler to have a variable template of type traits_t, parameterized on the arch enum.
template <id>
extern const traits_t traits;
template <>
inline constexpr traits_t traits<id::sm_60>{
.id = id::sm_60,
.compute_capability_major = 6,
.compute_capability_minor = 0,
.compute_capability = 60,
.max_shared_memory_per_multiprocessor = 64 * 1024,
.max_blocks_per_multiprocessor = 32,
.max_threads_per_multiprocessor = 2048,
.max_warps_per_multiprocessor = max_threads_per_multiprocessor / warp_size,
.reserved_shared_memory_per_block = 0,
.max_shared_memory_per_block_optin = 48 * 1024,
.cluster_supported = false,
.redux_intrinisic = false,
.elect_intrinsic = false,
.cp_async_supported = false,
.tma_supported = false
};
There was a problem hiding this comment.
Initially the main reason was that in C++17 you can't have a struct as a template argument. But I also realized that now that I added the id enum it could be used for kernel templates in C++17 instead of the type. Maybe you are right that it's no longer needed.
There was a problem hiding this comment.
I am with @ericniebler here, it would be nice to turn this into inline variables
There was a problem hiding this comment.
With the variable approach I had to add _CCCL_GLOBAL_CONSTANT to it and that resulted in a bunch of device memory that needed to hold the traits, which is probably not great.
Instead I made traits a host device function that I specialize for each enum value.
π© CI finished in 29m 12s: Pass: 100%/32 | Total: 4h 06m | Avg: 7m 41s | Max: 15m 39s | Hits: 79%/16218
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| CCCL Packaging | |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| +/- | CCCL Packaging |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
πβ Runner counts (total jobs: 32)
| # | Runner |
|---|---|
| 17 | linux-amd64-cpu16 |
| 6 | linux-amd64-gpu-rtx2080-latest-1 |
| 4 | windows-amd64-cpu16 |
| 4 | linux-arm64-cpu16 |
| 1 | linux-amd64-gpu-h100-latest-1 |
79b8475 to
d0a64c4
Compare
π© CI finished in 20m 31s: Pass: 100%/32 | Total: 4h 10m | Avg: 7m 49s | Max: 18m 14s | Hits: 79%/16246
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| CCCL Packaging | |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| +/- | CCCL Packaging |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
πβ Runner counts (total jobs: 32)
| # | Runner |
|---|---|
| 17 | linux-amd64-cpu16 |
| 6 | linux-amd64-gpu-rtx2080-latest-1 |
| 4 | windows-amd64-cpu16 |
| 4 | linux-arm64-cpu16 |
| 1 | linux-amd64-gpu-h100-latest-1 |
| // @brief Architecture type | ||
| // This type is a template that represents an architecture. It also contains the traits for that architecture. | ||
| template <id _Id> | ||
| struct type; |
There was a problem hiding this comment.
I am with @ericniebler here, it would be nice to turn this into inline variables
| struct traits_t | ||
| { | ||
| // Maximum number of threads per block | ||
| static constexpr int max_threads_per_block = 1024; |
There was a problem hiding this comment.
Still not of a fan of demoting compile time constants to runtime values. We probably want to use those in a if constexpr at some point
Note that you can always do sm_XY::traits.foo_trait for static variables too
π© CI finished in 24m 45s: Pass: 100%/32 | Total: 4h 05m | Avg: 7m 39s | Max: 15m 56s | Hits: 80%/16246
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| CCCL Packaging | |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| +/- | CCCL Packaging |
| libcu++ | |
| CUB | |
| Thrust | |
| +/- | CUDA Experimental |
| stdpar | |
| python | |
| CCCL C Parallel Library | |
| Catch2Helper |
πβ Runner counts (total jobs: 32)
| # | Runner |
|---|---|
| 17 | linux-amd64-cpu16 |
| 6 | linux-amd64-gpu-rtx2080-latest-1 |
| 4 | windows-amd64-cpu16 |
| 4 | linux-arm64-cpu16 |
| 1 | linux-amd64-gpu-h100-latest-1 |
|
I will merge to unblock some other changes, we can always adjust it slightly later |
There is a bit of redundancy in arch traits right now, where there is
arch_traits_tand thearchtemplate is also a bit of a traits type templated on__CUDA_ARCH__values. We also don't have a good way to support arch-specific targets, because we are relying on compute capability values everywhere, which makes it hard to represent something like sm_90a.This PR tries to shuffle things around and structure them better. It introduces
archnamespace to avoid repeating that prefix on the names of all introduced APIs.archnamespace has two key components:id, which is an enum meant to represent all different compilation targets, including the arch-specific targets. It is named to mimic the arch argument to nvccsm_90,sm_90aetc. We could consider some different name as well, for examplecompute_90or something completely new.traits_twhich is the type with all the static architecture traits like shared memory size, compute capability etc. This type is also released fromdevice::arch_traits()API for a given device.traitsfunction template that acceptsidas a template argument. This is how you access the traits.archnamespace there is also a concept of compute capability, which is translatable to traits withtraits_for_compute_capabilityoridwithid_for_compute_capabilityconstexpr functions. I decided to move tomajor * 10 + minorformat, because I don't want__CUDA_ARCH__macro to be used with APIs accepting compute capability. Instead we offercurrent_traitsfunction, which will return traits according to the current__CUDA_ARCH__. We could also provide an arch type alias for the current__CUDA_ARCH__, but because there is a host pass over device code, it could become problematic.To sumarize:
arch::id::sm_90is an enum value of typearch::idthat represents a given architecture.arch::traits<arch::id::sm_90>()is a constexpr function returning all traits of a given architecture.The structure selected was designed to work well for:
auto traits = device.arch_traits()auto traits = arch::traits<arch::id::sm_XY>()auto traits = arch::current_traits()This should return any architecture-specific target (like
sm_90a) traits if enabled.It allows to do other things, but might need a few steps:
idfrom the traits, becausearch::traits_thas anidmember.Finally this PR introduces
sm_90a,sm_100a,sm_103aandsm_120aid to show how it fits into the new structure. For now we don't have any trait fields that would be different for thoseaarchitectures, but it should come in the future. There are alsosm_XYffamily targets that we probably need to add as well. We could also think about member aliases to link betweensm_100,sm_100aandsm_100f, but that is also left for future changes.