-
Notifications
You must be signed in to change notification settings - Fork 907
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
[BUG] libcudf must customize the Thrust/CUB namespace #11368
Comments
Yes, we should do this. It was on my list of things to investigate after I upgrade RAPIDS to Thrust 1.17. (Also I think it’s an outer namespace like |
I agree we need to find a way to ensure that two distinct libraries that have no interaction can safely use Thrust without The problem I see with proposed approach is that it makes using Thrust types harder when two projects call into each other and have Thrust types in the public API like all of RAPIDS. For example here is a super simplified example from cudf: #include <rmm/exec_policy.hpp>
#include <thrust/optional.h>
using namespace cudf;
namespace cudf {
namespace detail {
...
}
} This code fails to compile since the thrust types used in This means that at a minimum the namespace that we import thrust into has to be consistent across all of RAPIDS. To make that robust our logic should look like: #include <thrust/optional.h>
#ifdef THRUST_WRAPPED_NAMESPACE
using namespace THRUST_WRAPPED_NAMESPACE;
#endif
namespace cudf {
...
} Now that we have solved internal RAPIDS dependencies we should explore the impacts for callers of libcudf
This isn't to say I oppose this work, we just need to make sure we understand the impact. To help with this effort here are my current draft PR's for rmm and cudf: |
We should just get away from doing this. I don't know of cases where we use anything other than
I don't think we're ever concerned with ABI breaks in RAPIDS libraries. What kind of ODR issues do you foresee? If two versions of Thrust are present, each in different namespaces, then they are different symbols so far as the program is concerned and therefore distinct definitions of the symbol won't be a problem. |
If I understand correctly, every RAPIDS library would have a different definition of |
I agree. I will look at changing the offending code to not expose thrust
This doesn't stop two different versions of Thrust being compiled using the same namespace. So cudf and a consumer could use differing versions of thrust and place it in the same namespace. This might happen due to a leakage of the
The won't be interchangable. We can see that when looking at the current cudf PR. The One of the reasons I am proposing a common prefix is that interop between libraries ( cudf / raft / cuml / cugraph ) is possible when they are used within the same TU. If each project goes with a unique thrust namespace, no interop that includes thrust types will be possible, |
Excellent, the common namespace prefix seems to be essential here. However, it makes me wonder if this truly solves any problems (compared with no namespace) because some rmm types (for example) will not be compatible with non-RAPIDS libraries. It’s a slight improvement but also partially shifts the problem to require that non-RAPIDS libraries match the Thrust namespace prefix and version OR avoid using such Thrust-derived types from RAPIDS libraries. I suppose we want to remove Thrust APIs from our public interfaces so perhaps this is solved in that way. |
It does solve a real problem which is that end user programs bring RAPIDS projects together with other C++ libraries that use thrust. Since these projects are built ignorant of each other they use different thrust versions and cause weird runtime failures. To be clear the proposal for rmm won't impact the ability for non RAPIDS projects to use it. The rmm headers will adapt based on the value of |
The
It expands to
I strongly support this. The namespace macros are only robust when Thrust isn't exposed publicly. |
(Thanks for the clarification @robertmaynard / @allisonvacanti! My previous message may have sounded negative on this idea - poor writing on my part.) |
fwiw, the original impetus for this issue was due to mixing CUB versions in a C++ code using both libcudf and CUB headers. We definitely don't have any CUB types as part of any public interface, so if it's easier to just custom scope CUB and not Thrust in the short term then I think that would be valuable to do. |
As noted in #11368 we should strive towards not having thrust types in our 'public' API. This removes occurences of using `thrust::optional` from cudf/io host classes in preference of `std::optional`. Authors: - Robert Maynard (https://github.com/robertmaynard) - Bradley Dice (https://github.com/bdice) Approvers: - Nghia Truong (https://github.com/ttnghia) - Tobias Ribizel (https://github.com/upsj) - Bradley Dice (https://github.com/bdice) URL: #11455
This can be done in the current macro system by just changing I'm not sure how realistic that "CUB is not exposed" bit is, though. Thrust's headers indirectly pull in CUB headers often, so there may still be issues. |
I am working on a pr draft of cudf using cub in a namespace. |
This issue has been labeled |
With a solution to NVIDIA/cub#545 being merged, I think the best option for cudf is to patch our version of thrust. |
Can't we just use a version of Thrust that makes the same changes? NVIDIA/thrust#1788 |
No released version of Thrust currently exists have the required changes. Once Thrust 2.1 has been released ( or the patches are back ported ) we can stop patching our Thrust. |
If we're going to go through the work of making the changes locally for a patch, why not just contribute the changes to Thrust and then update our version of Thrust? |
Sounds reasonable we can use the |
@robertmaynard, @jrhemstad, mentioned PRs are merged. |
@senior-zero Will a tag be made for these changes? Our CPM configuration in cuDF relies on a tag right now. I'd use branch |
@bdice we'll create a tag soon. |
@bdice @allisonvacanti has just created 1.17.2 tag. |
Updates libcudf to use Thrust 1.17.2. This version contains a newer cub util_namespace.h with the upstream fix needed to correct ODR issues inside thrust-cub. Fixes #11368. Authors: - Robert Maynard (https://github.com/robertmaynard) - Bradley Dice (https://github.com/bdice) Approvers: - Mark Harris (https://github.com/harrism) - Bradley Dice (https://github.com/bdice) - Vyas Ramasubramani (https://github.com/vyasr) URL: #11665
Describe the bug
For header-only libraries like Thrust/CUB, it can be problematic when an application inadvertently ends up with multiple or mismatched versions of the headers.
Thrust/CUB provide a way to universally customize the namespace such that a symbol like
thrust::reduce
will instead bethrust::CUSTOM::reduce
.This prevents inadvertent symbol collisions and version mismatches by forcing libcudf to use Thrust/CUB symbols from within its custom namespace.
Solution
libcudf should set
THRUST_CUB_WRAPPED_NAMESPACE=cudf
as part of the cmake configuration step for Thrust/CUB.The text was updated successfully, but these errors were encountered: