可以在 google colab 上安装 cupy 吗?

Is it possible to install cupy on google colab?

我正在尝试 运行 在 google colab 上使用 GPU 链接器。这需要安装 cupy,但是我无法正确安装它,因为它在我的 colab 虚拟机中找不到 cuda 环境。

错误信息如下...

Collecting cupy Downloading cupy-2.4.0.tar.gz (1.7MB) 100% |████████████████████████████████| 1.7MB 740kB/s Complete output from command python setup.py egg_info: cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ /tmp/tmpds3ikncy/a.cpp:1:10: fatal error: cublas_v2.h: No such file or directory #include ^~~~~~~~~~~~~ compilation terminated. Options: {'profile': False, 'linetrace': False, 'annotate': False, 'no_cuda': False} ************************************************** * WARNING: nvcc not in path. * WARNING: Please set path to nvcc. ************************************************** Include directories: [] Library directories: [] command 'x86_64-linux-gnu-gcc' failed with exit status 1 ************************************************** * WARNING: Include files not found: ['cublas_v2.h', 'cuda.h', 'cuda_profiler_api.h', 'cuda_runtime.h', 'curand.h', 'cusparse.h', 'nvrtc.h', 'nvToolsExt.h'] * WARNING: Skip installing cuda support *** WARNING: Check your CFLAGS environment variable ************************************************** Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-qu5red9h/cupy/setup.py", line 32, in ext_modules = cupy_setup_build.get_ext_modules() File "/tmp/pip-build-qu5red9h/cupy/cupy_setup_build.py", line 385, in get_ext_modules extensions = make_extensions(arg_options, compiler, use_cython) File "/tmp/pip-build-qu5red9h/cupy/cupy_setup_build.py", line 275, in make_extensions raise Exception('Your CUDA environment is invalid. ' Exception: Your CUDA environment is invalid. Please check above error log.

----------------------------------------

命令 "python setup.py egg_info" 在 /tmp/pip-build-qu5red9h/cupy/

中失败,错误代码为 1

编辑: Google Colaboratory 现在默认提供了 Chainer、CuPy 和 iDeep。不再需要手动安装。


原答案:

您可以使用轮子避免在 Google Colab 上自行构建 CuPy。 Chainer官方提供snippet在Google Colab上安装Chainer/CuPy。

!curl https://colab.chainer.org/install | sh -

我们不需要在 Google colab 中手动安装 cupy。 在编辑下的笔记本设置中,我们可以选择 GPU。如果您已经安装了 chainer,您可以通过以下方式确认 cupy 的可用性:

chainer.print_runtime_info()