Repository: pytorch
Issue: Avoid using thrust:: directly, use THRUST_NS_QUALIFIER:: instead
Labels: module: build,module: cuda,triaged

### 🐛 Describe the bug

It throws the following error described in https://github.com/k2-fsa/k2/issues/916 when compiling [k2](https://github.com/k2-fsa/k2) against torch 1.11 using CUDA 11.6.

```
/usr/local/cuda/include/thrust/system/cuda/detail/core/util.h(534): error: namespace "thrust::cub" has no member "CacheModifiedInputIterator"
```

As k2 has [defined](https://github.com/k2-fsa/k2/blob/9e7b2a995622d06b85c090705887468d7a8833fe/k2/csrc/cub.h#L52) `CUB_NS_PREFIX` to put `cub` inside the namespace `k2`, it throws the above error for CUDA 11.6.

When we try to fix the above error by also moving `thrust` to the namespace k2 through defining `THRUST_CUB_WRAPPED_NAMESPACE`, it throws the following error:
```
/ceph-fj/fangjun/py38-1.11/lib/python3.8/site-packages/torch/include/c10/util/Half.h(492): error: class "c10::complex<double>" has no
member "imag"
``` 

It is caused by incorrect usage of the namespace `thrust` in pytorch.


There are direct usages of `thrust::` in various locations, e.g.,
https://github.com/pytorch/pytorch/blob/bf233aa049c4b479fd6cb19f9b8672bb2d42b0e2/c10/util/complex.h#L160

which makes it impossible to define `THRUST_CUB_WRAPPED_NAMESPACE` to values other than `thrust`.

`THRUST_CUB_WRAPPED_NAMESPACE` is introduced in https://github.com/NVIDIA/thrust/issues/1401#issuecomment-882805440

We should replace `thrust::` with `THRUST_NS_QUALIFIER::`, e.g., use `THRUST_NS_QUALIFIER::complex`, not `thrust::complex`.

### Versions

```
$ python3 -m torch.utils.collect_env
Collecting environment information...
PyTorch version: 1.11.0.dev20220203+cu115
Is debug build: False
CUDA used to build PyTorch: 11.5
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.18.0
Libc version: glibc-2.27

Python version: 3.8.6 (default, Dec  2 2020, 15:56:31)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.54-1.0.0.std7c.el7.2.x86_64-x86_64-with-glibc2.2.5
Is CUDA available: True
CUDA runtime version: 11.6.55
GPU models and configuration:
GPU 0: Tesla V100-PCIE-32GB
GPU 1: Tesla V100-PCIE-32GB
GPU 2: Tesla V100-PCIE-32GB
GPU 3: Tesla V100-PCIE-32GB

Nvidia driver version: 455.32.00
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.2
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.22.2
[pip3] torch==1.11.0.dev20220203+cu115
[conda] blas                      1.0                         mkl
[conda] cpuonly                   2.0                           0    pytorch
[conda] k2                        1.10.dev20211208 cpu_py3.7_torch1.8.0  [cpuonly]  <unknown>
[conda] mkl                       2020.2                      256
[conda] mkl-service               2.3.0            py38he904b0f_0
[conda] mkl_fft                   1.2.0            py38h23d657b_0
[conda] mkl_random                1.1.1            py38h0573a6f_0
[conda] numpy                     1.19.2           py38h54aff64_0
[conda] numpy-base                1.19.2           py38hfa32c7d_0
[conda] numpydoc                  1.1.0              pyhd3eb1b0_1
[conda] pytorch                   1.7.1               py3.8_cpu_0  [cpuonly]  pytorch
[conda] pytorch-mutex             1.0                         cpu    pytorch
```

cc @malfet @seemethere @ngimel