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

Fix Thrust/CUB Linkage Issues #443

Merged
merged 17 commits into from
Sep 21, 2023

Conversation

gevtushenko
Copy link
Collaborator

@gevtushenko gevtushenko commented Sep 12, 2023

Description

closes #166

Using CUB/Thrust in shared libraries is a known source of issues. For a while, the solution to these issues consisted of wrapping CUB/Thrust namespaces in THRUST_CUB_WRAPPED_NAMESPACE macro so that different shared libraries have different symbol names. This solution has poor discoverability, since issues present themselves in forms of segmentation faults, hangs, wrong results, etc. To eliminate the symbol visibility issues on our end, the following design is proposed:

  1. Hide kernel launchers: it’s important that kernel launchers like the Thrust triple_chevron always reside in the same library as the CUB/Thrust host API using these kernel launchers.

  2. Hide all kernels: it’s important that CUB/Thrust kernels always reside in the same library as the CUB/Thrust host API using these kernels.

  3. Incorporate GPU architectures into symbol names: it’s important that kernels compiled for a given GPU architecture are always used by the CUB/Thrust host API compiled for that architecture.

Applying mentioned recommendations to the CCCL codebase involves the following changes:

  1. thrust::cuda_cub::launcher::triple_chevron is annotated with _LIBCUDACXX_HIDDEN

  2. instead of annotating kernels with __global__ we introduce {CUB,THRUST}_DETAIL_KERNEL_ATTRIBUTES macro that’s equivalent to __global__ _LIBCUDACXX_HIDDEN and annotate every CUB/Thrust kernel with it

  3. Thrust symbols are placed inside an inline namespace containing the set of GPU architectures for which the TU is being compiled when CUDA is used as the device system.

Potentially breaking changes:

  • In Linux builds, CUB/Thrust kernels used to have default visibility. This PR changes that, so direct references to CUB/Thrust kernels in shared libraries will be broken. Since CUB/Thrust kernels are considered an implementation detail, this isn't a blocker for the PR.

  • Thrust ABI is broken when the set of GPU architectures doesn’t match. If a library exposes a function taking, say, device vector and is compiled for SM80, any code compiled for different architectures won’t be able to link against that library. The behavior can be opted out by defining THRUST_DISABLE_ABI_NAMESPACE or providing wrapped namespace.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@gevtushenko gevtushenko requested review from a team as code owners September 12, 2023 19:49
@gevtushenko gevtushenko requested review from elstehle, wmaxey, jrhemstad and robertmaynard and removed request for a team September 12, 2023 19:49
@gevtushenko gevtushenko marked this pull request as draft September 12, 2023 22:24
@gevtushenko gevtushenko marked this pull request as ready for review September 19, 2023 15:03
Copy link
Collaborator

@miscco miscco left a comment

Choose a reason for hiding this comment

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

Minor nits

cub/cub/util_macro.cuh Outdated Show resolved Hide resolved
cub/cub/util_namespace.cuh Show resolved Hide resolved
thrust/thrust/detail/config/namespace.h Outdated Show resolved Hide resolved
thrust/thrust/system/cuda/detail/core/agent_launcher.h Outdated Show resolved Hide resolved
thrust/thrust/system/cuda/detail/core/agent_launcher.h Outdated Show resolved Hide resolved
Copy link
Contributor

@ahendriksen ahendriksen left a comment

Choose a reason for hiding this comment

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

This is a really clean PR with great documentation! I added some questions and one documentation suggestion.

cub/cub/util_macro.cuh Show resolved Hide resolved
cub/docs/developer_overview.rst Outdated Show resolved Hide resolved
cub/cub/util_device.cuh Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[EPIC]: Hide the visibility of Thrust/CUB symbols in shared object libraries
6 participants