[RFE] Support linking multiple Thrust versions: Add hooks that wrap the thrust::
namespace in a custom namespace #1401
Description
Problem
Cub allows itself to place into a namespace via CUB_NS_PREFIX
and CUB_NS_POSTFIX
, such that multiple shared libraries can each utilize their own copy of it (and thus different versions can safely coexist). Static variables used for caching could otherwise cause problems (e.g., https://github.com/NVIDIA/cub/blob/main/cub/util_device.cuh#L212).
Thrust however depends on cub and requires it to not be in another namespace, so users cannot have CUB_NS_PREFIX
defined. This means if two libraries use two different versions of thrust (or cub), issues with the caching variables inside of cub can occur.
Possible solutions
A solution would be to add THRUST_NS_PREFIX
and THRUST_NS_POSTFIX
to allow each library to place the version of thrust it's compiling against within in it's namespace, and either utilize the version of cub in the global namespace, or utilize the version of cub within the same namespace by defining CUB_NS_PREFIX
as well.
Another solution, would be to allow users to define something like THRUST_CUB_NS
, to tell thrust which namespace to look for cub in:
#define CUB_NS_PREFIX=namespace foobar {
#define CUB_NS_POSTFIX=}
...
#define THRUST_CUB_NS=foobar
#include "thrust/sort.h"