在没有 GPU 支持的 MacOS 上安装 cupy

Posted

技术标签:

【中文标题】在没有 GPU 支持的 MacOS 上安装 cupy【英文标题】:Install cupy on MacOS without GPU support 【发布时间】:2021-10-19 07:11:54 【问题描述】:

我一直在论坛上四处寻找不同的方法来在没有 Nvidia GPU 的设备上运行的 MacOS 上安装 cupy。到目前为止,没有任何效果。我尝试了 Python 3.7 的 Homebrew 安装和 Python 3.7 的 conda 安装,并尝试了以下各项:

conda install -c conda-forge cupy conda install cupy pip install cupy
git clone https://github.com/cupy/cupy.git
cd cupy
git submodule update --init
pip install -e .

错误总是相同的......对于 conda,MacOS 存储库没有它,对于 pip,安装抱怨 CUDA 没有安装在我的系统上。根据我在网上阅读的内容,cupy 应该能够安装为仅用于开发目的的 CPU,我希望有人能阐明我可以做些什么来获得有效的安装。

这是一个错误日志示例,供pip install cupy参考:

    ERROR: Command errored out with exit status 1:
     command: /Users/nold/miniconda3/envs/SPANet/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/setup.py'"'"'; __file__='"'"'/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-pip-egg-info-2bbvs1rw
         cwd: /private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/
    Complete output (49 lines):
    Options: 'package_name': 'cupy', 'long_description': None, 'wheel_libs': [], 'wheel_includes': [], 'wheel_metadata': None, 'no_rpath': False, 'profile': False, 'linetrace': False, 'annotate': False, 'no_cuda': False, 'use_hip': False
    
    -------- Configuring Module: cuda --------
    Command "gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ajpfahnl/miniconda3/envs/SPANet/include -arch x86_64 -I/Users/ajpfahnl/miniconda3/envs/SPANet/include -arch x86_64 -D_FORCE_INLINES=1 -I/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/install/../cupy/_core/include/cupy/cub -I/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/install/../cupy/_core/include -c /var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/tmphc_ag1dw/a.cpp -o /var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/tmphc_ag1dw/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/tmphc_ag1dw/a.o" failed with exit status 1
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/setup.py", line 118, in <module>
        ext_modules = cupy_setup_build.get_ext_modules()
      File "/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/cupy_setup_build.py", line 963, in get_ext_modules
        extensions = make_extensions(arg_options, compiler, use_cython)
      File "/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/cupy_setup_build.py", line 693, in make_extensions
        raise Exception('Your CUDA environment is invalid. '
    Exception: Your CUDA environment is invalid. Please check above error log.
    **************************************************
    *** WARNING: Cannot check compute capability
    Command "gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/ajpfahnl/miniconda3/envs/SPANet/include -arch x86_64 -I/Users/ajpfahnl/miniconda3/envs/SPANet/include -arch x86_64 -I/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/install/../cupy/_core/include/cupy/cub -I/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/install/../cupy/_core/include -c /var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/tmpkdbb5_vj/a.cpp -o /var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/tmpkdbb5_vj/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/tmpkdbb5_vj/a.o" failed with exit status 1
    **************************************************
    
    ************************************************************
    * CuPy Configuration Summary                               *
    ************************************************************
    
    Build Environment:
      Include directories: ['/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/install/../cupy/_core/include/cupy/cub', '/private/var/folders/j4/nzmp4kf17z3d1z22wzwjy3m00000gn/T/pip-install-uyg_c8fb/cupy_3e5357e9d2ae4f96a8575fd2e4cc5b5e/install/../cupy/_core/include']
      Library directories: []
      nvcc command       : (not found)
      hipcc command      : (not found)
    
    Environment Variables:
      CFLAGS          : (none)
      LDFLAGS         : (none)
      LIBRARY_PATH    : (none)
      CUDA_PATH       : (none)
      NVTOOLSEXT_PATH : (none)
      NVCC            : (none)
      HIPCC           : (none)
      ROCM_HOME       : (none)
    
    Modules:
      cuda      : No
        -> Include files not found: ['cublas_v2.h', 'cuda.h', 'cuda_profiler_api.h', 'cuda_runtime.h', 'cufft.h', 'curand.h', 'cusparse.h', 'nvrtc.h']
        -> Check your CFLAGS environment variable.
    
    ERROR: CUDA could not be found on your system.
    Please refer to the Installation Guide for details:
    https://docs.cupy.dev/en/stable/install.html
    
    ************************************************************

【问题讨论】:

【参考方案1】:

由于 NVIDIA 不再支持 MacOS,CuPy 中不支持 Mac。你读的任何东西都是过时的。我知道是因为我从 CuPy 的代码库向remove the last broken bits 发送了一个 PR,并且我还在 conda-forge 上维护了 CuPy 包。

【讨论】:

以上是关于在没有 GPU 支持的 MacOS 上安装 cupy的主要内容,如果未能解决你的问题,请参考以下文章

LightGBM在MacOS上安装LightGBM的GPU版

TensorFlow的安装

在 MacOS 上使用 OpenGL 的 GPU 时序

在 MacOS 中使用 SYCL 1.2

在 MacOS 中使用 SYCL 1.2

TensorFlow 在训练期间没有使用我的 M1 MacBook GPU