Repository: pytorch
Issue: build pytorch from source fauled: undefined reference to `cusparseGetErrorString(cusparseStatus_t)'
Labels: module: build,triaged

## 🐛 Bug

## To Reproduce

Steps to reproduce the behavior:
follow the instruction from [](https://github.com/pytorch/pytorch)
> git clone --recursive https://github.com/pytorch/pytorch
> cd pytorch
> git submodule sync
> git submodule update --init --recursive
> export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
> python setup.py install

## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```
building pytorch failed, thus no libtorch_global_deps.so was generated and collect_env.py cannot run.

 - PyTorch Version (e.g., 1.0): latest, with commit 927c2a02b0b29a0fafcced8d65896dd417023067
 - OS (e.g., Linux): Linux
 - How you installed PyTorch (`conda`, `pip`, source): source
 - Build command you used (if compiling from source): as described above
 - Python version: 3.7.4, anaconda
 - CUDA/cuDNN version: cuda 10.1, cudnn 7.1.3
 - GPU models and configuration: Nvidia GTX 1070
 - Any other relevant information:

## Error message
The error message is listed below.
[2372/2767] Linking CXX executable bin/graph_test
FAILED: bin/graph_test 
: && /usr/bin/c++  -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3  -rdynamic -Wl,-rpath -Wl,/usr/local/lib -Wl,--enable-new-dtags -pthread caffe2/CMakeFiles/graph_test.dir/core/graph_test.cc.o  -o bin/graph_test -L/home/v-doxia/anaconda3/lib -Wl,-rpath,/home/v-doxia/anaconda3/lib:/home/v-doxia/working/pytorch/build/lib:/usr/local/cuda-10.1/lib64:/usr/local/cuda/lib64: lib/libgtest_main.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch.so -Wl,--as-needed -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cpu.so -Wl,--as-needed lib/libprotobuf.a -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread -lm /usr/lib/x86_64-linux-gnu/libdl.so lib/libmkldnn.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so -Wl,--as-needed lib/libc10_cuda.so lib/libc10.so /usr/local/cuda-10.1/lib64/libnvToolsExt.so /usr/local/cuda-10.1/lib64/libcudart.so /usr/local/cuda-10.1/lib64/libcufft.so /usr/local/cuda-10.1/lib64/libcurand.so /usr/lib/x86_64-linux-gnu/libcublas.so /usr/local/cuda/lib64/libcudnn.so lib/libgtest.a -pthread && :
/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so: undefined reference to `cusparseGetErrorString(cusparseStatus_t)'
collect2: error: ld returned 1 exit status
[2373/2767] Linking CXX executable bin/roi_align_op_gpu_test
FAILED: bin/roi_align_op_gpu_test 
: && /usr/bin/c++  -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3  -rdynamic -Wl,-rpath -Wl,/usr/local/lib -Wl,--enable-new-dtags -pthread    -rdynamic caffe2/CMakeFiles/roi_align_op_gpu_test.dir/operators/roi_align_op_gpu_test.cc.o  -o bin/roi_align_op_gpu_test -L/home/v-doxia/anaconda3/lib -Wl,-rpath,/usr/local/cuda-10.1/lib64:/home/v-doxia/anaconda3/lib:/home/v-doxia/working/pytorch/build/lib:/usr/local/cuda/lib64: /usr/local/cuda-10.1/lib64/libcudart.so lib/libgtest_main.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch.so -Wl,--as-needed -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cpu.so -Wl,--as-needed lib/libprotobuf.a -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread -lm -ldl lib/libmkldnn.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so -Wl,--as-needed lib/libc10_cuda.so lib/libc10.so /usr/local/cuda-10.1/lib64/libnvToolsExt.so /usr/local/cuda-10.1/lib64/libcudart.so /usr/local/cuda-10.1/lib64/libcufft.so /usr/local/cuda-10.1/lib64/libcurand.so -lcublas /usr/local/cuda/lib64/libcudnn.so lib/libgtest.a -pthread && :
/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so: undefined reference to `cusparseGetErrorString(cusparseStatus_t)'
collect2: error: ld returned 1 exit status
[2375/2767] Linking CXX executable bin/operator_fallback_gpu_test
FAILED: bin/operator_fallback_gpu_test 
: && /usr/bin/c++  -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3  -rdynamic -Wl,-rpath -Wl,/usr/local/lib -Wl,--enable-new-dtags -pthread    -rdynamic caffe2/CMakeFiles/operator_fallback_gpu_test.dir/operators/operator_fallback_gpu_test.cc.o  -o bin/operator_fallback_gpu_test -L/home/v-doxia/anaconda3/lib -Wl,-rpath,/usr/local/cuda-10.1/lib64:/home/v-doxia/anaconda3/lib:/home/v-doxia/working/pytorch/build/lib:/usr/local/cuda/lib64: /usr/local/cuda-10.1/lib64/libcudart.so lib/libgtest_main.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch.so -Wl,--as-needed -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cpu.so -Wl,--as-needed lib/libprotobuf.a -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread -lm -ldl lib/libmkldnn.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so -Wl,--as-needed lib/libc10_cuda.so lib/libc10.so /usr/local/cuda-10.1/lib64/libnvToolsExt.so /usr/local/cuda-10.1/lib64/libcudart.so /usr/local/cuda-10.1/lib64/libcufft.so /usr/local/cuda-10.1/lib64/libcurand.so -lcublas /usr/local/cuda/lib64/libcudnn.so lib/libgtest.a -pthread && :
/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so: undefined reference to `cusparseGetErrorString(cusparseStatus_t)'
collect2: error: ld returned 1 exit status
[2376/2767] Linking CXX executable bin/utility_ops_gpu_test
FAILED: bin/utility_ops_gpu_test 
: && /usr/bin/c++  -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3  -rdynamic -Wl,-rpath -Wl,/usr/local/lib -Wl,--enable-new-dtags -pthread    -rdynamic caffe2/CMakeFiles/utility_ops_gpu_test.dir/operators/utility_ops_gpu_test.cc.o  -o bin/utility_ops_gpu_test -L/home/v-doxia/anaconda3/lib -Wl,-rpath,/usr/local/cuda-10.1/lib64:/home/v-doxia/anaconda3/lib:/home/v-doxia/working/pytorch/build/lib:/usr/local/cuda/lib64: /usr/local/cuda-10.1/lib64/libcudart.so lib/libgtest_main.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch.so -Wl,--as-needed -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cpu.so -Wl,--as-needed lib/libprotobuf.a -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread -lm -ldl lib/libmkldnn.a -Wl,--no-as-needed,/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so -Wl,--as-needed lib/libc10_cuda.so lib/libc10.so /usr/local/cuda-10.1/lib64/libnvToolsExt.so /usr/local/cuda-10.1/lib64/libcudart.so /usr/local/cuda-10.1/lib64/libcufft.so /usr/local/cuda-10.1/lib64/libcurand.so -lcublas /usr/local/cuda/lib64/libcudnn.so lib/libgtest.a -pthread && :
/home/v-doxia/working/pytorch/build/lib/libtorch_cuda.so: undefined reference to `cusparseGetErrorString(cusparseStatus_t)'
collect2: error: ld returned 1 exit status
[2387/2767] Building CXX object test_jit/CMakeFiles/test_jit.dir/test_misc.cpp.o
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    cmake=cmake)
  File "/home/v-doxia/working/pytorch/tools/build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "/home/v-doxia/working/pytorch/tools/setup_helpers/cmake.py", line 339, in build
    self.run(build_args, my_env)
  File "/home/v-doxia/working/pytorch/tools/setup_helpers/cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/home/v-doxia/anaconda3/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)

## Some  ideas
I search the code base and find a definition of  `cusparseGetErrorString(cusparseStatus_t)` at pytorch/aten/src/ATen/native/sparse/cuda/SparseCUDABlas.cu:
```
#if (!((CUSPARSE_VER_MAJOR >= 10) && (CUSPARSE_VER_MINOR >= 2)))
const char* cusparseGetErrorString(cusparseStatus_t status) {
  switch(status)
  {
    case CUSPARSE_STATUS_SUCCESS:
      return "success";

    case CUSPARSE_STATUS_NOT_INITIALIZED:
      return "library not initialized";

    case CUSPARSE_STATUS_ALLOC_FAILED:
      return "resource allocation failed";

    case CUSPARSE_STATUS_INVALID_VALUE:
      return "an invalid numeric value was used as an argument";

    case CUSPARSE_STATUS_ARCH_MISMATCH:
      return "an absent device architectural feature is required";

    case CUSPARSE_STATUS_MAPPING_ERROR:
      return "an access to GPU memory space failed";

    case CUSPARSE_STATUS_EXECUTION_FAILED:
      return "the GPU program failed to execute";

    case CUSPARSE_STATUS_INTERNAL_ERROR:
      return "an internal operation failed";

    case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
      return "the matrix type is not supported by this function";

    case CUSPARSE_STATUS_ZERO_PIVOT:
      return "an entry of the matrix is either structural zero or numerical zero (singular block)";

    default:
      return "unknown error";
  }
}
#endif
```
I check the version of the cusparse installed on the machine and find the code above will be be compiled due to the  `#if`. So the undefined symbol should be the function provided by Nvidia cuSPARSE, but I think I do not find '-lcusparse' in the command in the error log. Will this be the reason for this error?