Repository: cupy/cupy

Issue:
"rocsolver" is a missing dependency for CuPy + ROCm 3.5.0
After fixing #3783 and #3788, the 3rd error I ran into is missing `librocsolver.so`:
```
$ python -c "import cupy"
Traceback (most recent call last):
  File "/home/leo/dev/cupy_rocm35/cupy/__init__.py", line 19, in <module>
    from cupy import core  # NOQA
  File "/home/leo/dev/cupy_rocm35/cupy/core/__init__.py", line 1, in <module>
    from cupy.core import core  # NOQA
ImportError: librocsolver.so.0: cannot open shared object file: No such file or directory

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/leo/dev/cupy_rocm35/cupy/__init__.py", line 40, in <module>
    raise ImportError(msg) from e
ImportError: CuPy is not correctly installed.

If you are using wheel distribution (cupy-cudaXX), make sure that the version of CuPy you installed matches with the version of CUDA on your host.
Also, confirm that only one CuPy package is installed:
  $ pip freeze

If you are building CuPy from source, please check your environment, uninstall CuPy and reinstall it with:
  $ pip install cupy --no-cache-dir -vvvv

Check the Installation Guide for details:
  https://docs.cupy.dev/en/latest/install.html

original error: librocsolver.so.0: cannot open shared object file: No such file or directory
```
which is not listed in the required ROCm packages: 
https://docs.cupy.dev/en/latest/install_rocm.html#requirements
Building `cupy.cuda.thrust` with ROCm 3.5.0 fails 
After #3786, the next error I encountered with ROCm 3.5.0 + Radeon VII is this (`error: unknown type name '__host__'`):
```    
    ************************************************************
    * CuPy Configuration Summary                               *
    ************************************************************

    Build Environment:
      Include directories: ['/home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/cub', '/home/leo/dev/cupy_rocm35/install/../cupy/core/include', '/opt/rocm/include', '/opt/rocm/rocrand/include']
      Library directories: ['/opt/rocm/lib', '/opt/rocm/rocrand/lib']
      nvcc command       : ['/usr/bin/nvcc']

    Environment Variables:
      CFLAGS          : (none)
      LDFLAGS         : (none)
      LIBRARY_PATH    : (none)
      CUDA_PATH       : (none)
      NVTOOLSEXT_PATH : (none)
      NVCC            : (none)
      ROCM_HOME       : /opt/rocm

    Modules:
      cuda      : Yes
      cusolver  : Yes
      thrust    : Yes
    ************************************************************

    building 'cupy.cuda.thrust' extension
    gcc -pthread -B /home/leo/miniconda3/envs/cupy_rocm35_dev/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -D_FORCE_INLINES=1 -DCUPY_USE_HIP=1 -D__HIP_PLATFORM_HCC__=1 -I/home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/cub -I/home/leo/dev/cupy_rocm35/install/../cupy/core/include -I/opt/rocm/include -I/opt/rocm/rocrand/include -I/home/leo/miniconda3/envs/cupy_rocm35_dev/include/python3.7m -c cupy/cuda/thrust.cpp -o build/temp.linux-x86_64-3.7/cupy/cuda/thrust.o -std=c++11
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    HIPCC options: ['-O2', '-fPIC']
    /opt/rocm/bin/hipcc -D_FORCE_INLINES=1 -DCUPY_USE_HIP=1 -D__HIP_PLATFORM_HCC__=1 -I/home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/cub -I/home/leo/dev/cupy_rocm35/install/../cupy/core/include -I/opt/rocm/include -I/opt/rocm/rocrand/include -I/home/leo/miniconda3/envs/cupy_rocm35_dev/include/python3.7m -c cupy/cuda/cupy_thrust.cu -o build/temp.linux-x86_64-3.7/cupy/cuda/cupy_thrust.o -O2 -fPIC
    HIP_PATH=/opt/rocm-3.5.0/hip
    HIP_PLATFORM=hcc
    HIP_COMPILER=clang
    HIP_RUNTIME=ROCclr
    HIP_ROCCLR_HOME=/opt/rocm-3.5.0/hip
    HIP_CLANG_PATH=/opt/rocm-3.5.0/llvm/bin
    HIP_CLANG_INCLUDE_PATH=/opt/rocm-3.5.0/llvm/lib/clang/11.0.0/include
    HIP_INCLUDE_PATH=/opt/rocm-3.5.0/hip/include
    HIP_LIB_PATH=/opt/rocm-3.5.0/hip/lib
    DEVICE_LIB_PATH=/opt/rocm-3.5.0/lib
    hipcc-args: -D_FORCE_INLINES=1 -DCUPY_USE_HIP=1 -D__HIP_PLATFORM_HCC__=1 -I/home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/cub -I/home/leo/dev/cupy_rocm35/install/../cupy/core/include -I/opt/rocm/include -I/opt/rocm/rocrand/include -I/home/leo/miniconda3/envs/cupy_rocm35_dev/include/python3.7m -c cupy/cuda/cupy_thrust.cu -o build/temp.linux-x86_64-3.7/cupy/cuda/cupy_thrust.o -O2 -fPIC
    hipcc-cmd: /opt/rocm-3.5.0/llvm/bin/clang++ -D__HIP_ROCclr__ -std=c++11 -isystem /opt/rocm-3.5.0/llvm/lib/clang/11.0.0/include/.. -isystem /opt/rocm-3.5.0/hsa/include -D__HIP_ROCclr__ -isystem /opt/rocm-3.5.0/hip/include -D__HIP_ARCH_GFX906__=1  --cuda-gpu-arch=gfx906 -mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false  --hip-device-lib-path=/opt/rocm-3.5.0/lib -fhip-new-launch-api  -D\_FORCE\_INLINES=1 -DCUPY\_USE\_HIP=1 -D\_\_HIP\_PLATFORM\_HCC\_\_=1 -I\/home\/leo\/dev\/cupy\_rocm35\/install\/..\/cupy\/core\/include\/cupy\/cub -I\/home\/leo\/dev\/cupy\_rocm35\/install\/..\/cupy\/core\/include -I\/opt\/rocm\/include -I\/opt\/rocm\/rocrand\/include -I\/home\/leo\/miniconda3\/envs\/cupy\_rocm35\_dev\/include\/python3.7m -c -x hip cupy\/cuda\/cupy\_thrust.cu -o build/temp.linux-x86_64-3.7/cupy/cuda/cupy_thrust.o -O2 -fPIC
    In file included from cupy/cuda/cupy_thrust.cu:1:
    In file included from /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/type_dispatcher.cuh:4:
    In file included from /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex.cuh:3:
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:82:10: error: unknown type name '__host__'
      inline __host__ __device__ complex(const T& re);
             ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:82:3: error: 'inline' can only appear on functions
      inline __host__ __device__ complex(const T& re);
      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:82:29: error: expected ';' at end of declaration list
      inline __host__ __device__ complex(const T& re);
                                ^
                                ;
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:89:10: error: unknown type name '__host__'
      inline __host__ __device__ complex(const T& re, const T& im);
             ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:89:3: error: 'inline' can only appear on functions
      inline __host__ __device__ complex(const T& re, const T& im);
      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:89:19: error: duplicate member '__device__'
      inline __host__ __device__ complex(const T& re, const T& im);
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:82:19: note: previous declaration is here
      inline __host__ __device__ complex(const T& re);
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:89:29: error: expected ';' at end of declaration list
      inline __host__ __device__ complex(const T& re, const T& im);
                                ^
                                ;
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:93:10: error: unknown type name '__host__'
      inline __host__ __device__ complex();
             ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:93:3: error: 'inline' can only appear on functions
      inline __host__ __device__ complex();
      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:93:19: error: duplicate member '__device__'
      inline __host__ __device__ complex();
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:82:19: note: previous declaration is here
      inline __host__ __device__ complex(const T& re);
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:93:29: error: expected ';' at end of declaration list
      inline __host__ __device__ complex();
                                ^
                                ;
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:100:10: error: unknown type name '__host__'
      inline __host__ __device__ complex(const complex<T>& z);
             ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:100:3: error: 'inline' can only appear on functions
      inline __host__ __device__ complex(const complex<T>& z);
      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:100:19: error: duplicate member '__device__'
      inline __host__ __device__ complex(const complex<T>& z);
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:82:19: note: previous declaration is here
      inline __host__ __device__ complex(const T& re);
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:100:29: error: expected ';' at end of declaration list
      inline __host__ __device__ complex(const complex<T>& z);
                                ^
                                ;
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:110:10: error: unknown type name '__host__'
      inline __host__ __device__ complex(const complex<X>& z);
             ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:110:19: error: member '__device__' declared as a template
      inline __host__ __device__ complex(const complex<X>& z);
                      ^
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:110:29: error: expected ';' at end of declaration list
      inline __host__ __device__ complex(const complex<X>& z);
                                ^
                                ;
    /home/leo/dev/cupy_rocm35/install/../cupy/core/include/cupy/complex/complex.h:119:10: error: unknown type name '__host__'
      inline __host__ __device__ complex& operator=(const T& re);
             ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated when compiling for gfx906.
    error: command '/opt/rocm/bin/hipcc' failed with exit status 1
```

The reason is the recent introduction of native complex number support to Thrust (#3546). The solution is to make `hip_runtime.h` included (https://github.com/ROCm-Developer-Tools/HIP/issues/441). I'll send a PR to fix this.


Discussion:

Resolving patch:
diff --git a/cupy_setup_build.py b/cupy_setup_build.py
--- a/cupy_setup_build.py
+++ b/cupy_setup_build.py
@@ -883,7 +883,7 @@ def _comiple_unix_hipcc(self,
             base_opts = build.get_compiler_base_options()
             self.set_executable('compiler_so', rcom_path)
 
-            postargs = ['-O2', '-fPIC']
+            postargs = ['-O2', '-fPIC', '--include', 'hip_runtime.h']
             print('HIPCC options:', postargs)
 
             return unixccompiler.UnixCCompiler._compile(
diff --git a/install/build.py b/install/build.py
--- a/install/build.py
+++ b/install/build.py
@@ -146,6 +146,7 @@ def get_compiler_setting(use_hip):
 
     if rocm_path:
         include_dirs.append(os.path.join(rocm_path, 'include'))
+        include_dirs.append(os.path.join(rocm_path, 'include', 'hip'))
         include_dirs.append(os.path.join(rocm_path, 'rocrand', 'include'))
         library_dirs.append(os.path.join(rocm_path, 'lib'))
         library_dirs.append(os.path.join(rocm_path, 'rocrand', 'lib'))


Test patch: