Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Refactor Thrust/CUB dispatch mechanisms to not rely on __CUDA_ARCH__ #278

Closed as not planned

Description

@brycelelbach
No description provided.

Activity

  1. added
    type: enhancement
    compiler: nvc++
    P0: must have
    on Mar 29, 2021
  2. added this to the 1.13.0 milestone on Mar 29, 2021
  3. self-assigned this
    on Mar 29, 2021
  4. seanbaxter commented on Apr 15, 2021

    @seanbaxter

    This is relevant to my interests. I been blocked by this since 2019. What's the new mechanism?

  5. alliepiper commented on Apr 15, 2021

    @alliepiper
    Contributor

    @seanbaxter There's a work-in-progress in #276.

    cub/device/dispatch/dispatch_reduce.cuh is an example of how the new mechanism is used, and the implementation is in cub/util_ptx_dispatch.cuh (For now...I'm planning to move it to cub/detail/ptx_dispatch.cuh today).

    Basically:

    • Tag each policy class with a constexpr static int ptx_arch = XXX member.
    • Add all policies to a cub::detail::type_list.
    • Use cub::detail::ptx_dispatch to invoke a functor with the best matching policy.

    I'm curious, though -- what are you doing with this? Are you using the CUB dispatch in another project?

  6. seanbaxter commented on Apr 15, 2021

    @seanbaxter

    I was compiling CUDA Toolkit samples without modification with a single translation pass in 2019:

    I ended up removing this functionality because CUDA_ARCH-based dispatch was too hard to treat robustly as the projects got more complicated. I made some requests to change this dispatch mechanism, and now it looks like it's happening. I'm looking to re-enable CUDA targets in my compiler. I want to compile CUB/Thrust with a single pass, as we all do.

    For background, I had an if-codegen statement which did operand substitution at codegen time rather than template substitution, and that appears to be exactly the same as nvc++'s if-target. There was an nvvm_arch_t enum with SM versions, which is like your sm_selector.
    https://www.circle-lang.org/saxpy.html#how-to-dispatch

    I looked over <__target_macros> closely.. Three small questions:

    1. Are __NV_PROVIDES_SM_XX and __NV_IS_EXACTLY_SM_XX not actually macros but rather implicit bool declarations that get plugged true/false at codegen depending on the target? I'm cool if they are. If not, I have no idea what's going on.
    2. Is nv::target::device also an implicit integer declaration holding the current SM target?
    3. Does [[nv::__target_bitset]] implicitly declare a target_description member function along the lines of:
    explicit operator bool () const noexcept { returns nv::target::device & targets; }
    

    ?

    Just a bit confused by the macro name style in 1 and the C++ name style in 2. Maybe they're unrelated things.

  7. alliepiper commented on Apr 15, 2021

    @alliepiper
    Contributor

    Ah ok - Everything in cub/detail/nv/ is a temporary snapshot from NVIDIA/libcudacxx#144, this PR just updates Thrust/CUB to use the libcu++ NV_IF_TARGET macros. @wmaxey, @dkolsen-pgi, and @brycelelbach wrote and designed those macros and would be better able to answer your questions about the if-target design.

  8. griwes commented on Apr 15, 2021

    @griwes
    Collaborator

    nv::target::device is just a set of targets. The actual codegen-known value does not manifest in user code at any point.

  9. seanbaxter commented on Apr 15, 2021

    @seanbaxter

    @griwes That doesn't clarify. Is nv::target::device is the bit-field of targets specified at the command line? Where is the active target manifested? It has to be somewhere.

  10. griwes commented on Apr 15, 2021

    @griwes
    Collaborator

    I'm not sure how much I can say at this point, but the short answer is that that value doesn't actually ever manifest directly in a variable, and the backend understands the bitset.

  11. seanbaxter commented on Apr 15, 2021

    @seanbaxter

    I'm just trying to compile CUB/Thrust with this new dispatch mechanic. What are the implicit declarations needed to do that?

  12. dkolsen-pgi commented on Apr 15, 2021

    @dkolsen-pgi
    Collaborator

    The value of an if target expression is a bitset that encodes all the desired targets. There is compiler magic that interprets the bitset and generates the correct code. If you want Circle to use the new if target mechanism rather than __CUDA_ARCH__, the Circle compiler will have to have the same compiler magic. This is not the right place to explain all the details of how it works; we would need to set up a meeting.

  13. wmaxey commented on Apr 16, 2021

    @wmaxey
    Member
    1. Are __NV_PROVIDES_SM_XX and __NV_IS_EXACTLY_SM_XX not actually macros but rather implicit bool declarations that get plugged true/false at codegen depending on the target? I'm cool if they are. If not, I have no idea what's going on.

    They are used for assembling the right token when preprocessing with __CUDA_ARCH__. The whole mechanism should be uninteresting as there is nothing really different or new happening with NVCC. This is just an abstraction to allow writing compiler independent code.

    In the back-end, these tokens are concatenated to obtain predefined boolean values on NVCC. It was done this way, maybe naively, because NVC++ and NVCC create the dispatch at different stages in compilation.

  14. 8 remaining items

  15. added this to the 1.17.0 milestone on Feb 7, 2022
  16. modified the milestones: 1.17.0, 2.0.0 on Apr 25, 2022
  17. modified the milestones: 2.0.0, 2.1.0 on Aug 4, 2022
  18. moved this to Needs Triage in CCCLon Aug 14, 2022
  19. moved this from Needs Triage to No status in CCCLon Aug 14, 2022
  20. moved this to In Progress in CCCLon Aug 22, 2022
  21. jrhemstad commented on Apr 26, 2023

    @jrhemstad
    Collaborator

    Closing in favor of NVIDIA/cccl#65

  22. moved this from In Progress to Done in CCCLon Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0: must havecompiler: nvc++cubtype: enhancement

Type

No type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions