OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  代码  ›  CuPy — GPU 加速 Numpy 替代库

CuPy — GPU 加速 Numpy 替代库

 
  encryption ·  2026-03-03 00:02:27 · 9 次点击  · 0 条评论  

CuPy:面向 GPU 的 NumPy 与 SciPy

pypi
Conda
GitHub license
Matrix
Twitter
Medium

官方网站
| 安装指南
| 教程
| 示例
| 文档
| API 参考
| 论坛

CuPy 是一个与 NumPy/SciPy 兼容的数组库,用于在 Python 中进行 GPU 加速计算。CuPy 可以作为现有 NumPy/SciPy 代码的直接替代品,在 NVIDIA CUDA 或 AMD ROCm 平台上运行。

>>> import cupy as cp
>>> x = cp.arange(6).reshape(2, 3).astype('f')
>>> x
array([[ 0.,  1.,  2.],
       [ 3.,  4.,  5.]], dtype=float32)
>>> x.sum(axis=1)
array([  3.,  12.], dtype=float32)

CuPy 还提供了对底层 CUDA 功能的访问。你可以通过 RawKernelsndarray 传递给现有的 CUDA C/C++ 程序,使用 Streams 提升性能,甚至直接调用 CUDA Runtime APIs

安装

Pip

适用于 Linux 和 Windows 的二进制包(wheel)可在 PyPI 获取。请根据你的平台选择正确的包。

平台 架构 命令
CUDA 12.x x86_64 / aarch64 pip install cupy-cuda12x
CUDA 13.x x86_64 / aarch64 pip install cupy-cuda13x
ROCm 7.0 (实验性支持) x86_64 pip install cupy-rocm-7-0

[!NOTE]\
如需安装预发布版本,请附加 --pre -U -f https://pip.cupy.dev/pre(例如:pip install cupy-cuda12x --pre -U -f https://pip.cupy.dev/pre)。

Conda

适用于 Linux 和 Windows 的二进制包也可在 Conda-Forge 获取。

平台 架构 命令
CUDA x86_64 / aarch64 / ppc64le conda install -c conda-forge cupy

如果你需要精简安装(不附带安装 CUDA 依赖),可以执行 conda install -c conda-forge cupy-core

如果你需要使用特定的 CUDA 版本(例如 12.0),可以使用 cuda-version 元包来选择版本,例如 conda install -c conda-forge cupy cuda-version=12.0

[!NOTE]\
如果你在使用从 conda-forge 安装的 CuPy 时遇到任何问题,请随时向 cupy-feedstock 报告,我们将协助调查这是否只是 conda-forge 配方中的打包问题,还是 CuPy 本身的实际问题。

Docker

使用 NVIDIA Container Toolkit 来运行 CuPy 容器镜像

$ docker run --gpus all -it cupy/cupy

资源

许可证

MIT 许可证(详见 LICENSE 文件)。

CuPy 的设计基于 NumPy 和 SciPy 的 API(详见 docs/source/license.rst 文件)。

CuPy 由 Preferred Networks社区贡献者 共同开发和维护。

参考文献

Ryosuke Okuta, Yuya Unno, Daisuke Nishino, Shohei Hido and Crissman Loomis.
CuPy: A NumPy-Compatible Library for NVIDIA GPU Calculations.
Proceedings of Workshop on Machine Learning Systems (LearningSys) in The Thirty-first Annual Conference on Neural Information Processing Systems (NIPS), (2017).
[PDF]

@inproceedings{cupy_learningsys2017,
  author       = "Okuta, Ryosuke and Unno, Yuya and Nishino, Daisuke and Hido, Shohei and Loomis, Crissman",
  title        = "CuPy: A NumPy-Compatible Library for NVIDIA GPU Calculations",
  booktitle    = "Proceedings of Workshop on Machine Learning Systems (LearningSys) in The Thirty-first Annual Conference on Neural Information Processing Systems (NIPS)",
  year         = "2017",
  url          = "http://learningsys.org/nips17/assets/papers/paper_16.pdf"
}

  1. 从 v13.0.0 开始,cuSignal 已成为 CuPy 的一部分。 

9 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor