cupy/cupy

GitHub Trending (daily) 工具

摘要

CuPy是一个GPU加速的库,可作为NumPy/SciPy的直接替代品,支持在NVIDIA CUDA和AMD ROCm平台上进行高效的数组运算。

面向GPU的NumPy与SciPy
查看原文
查看缓存全文

缓存时间: 2026/06/28 11:18

cupy/cupy 源:https://github.com/cupy/cupy

CuPy : GPU上的NumPy和SciPy

PyPI | Conda | GitHub 许可证 | Matrix | Twitter | Medium

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

CuPy 是一个兼容 NumPy/SciPy 的数组库,用于 Python 中的 GPU 加速计算。CuPy 可作为即插即用替代品(文档),在 NVIDIA CUDA 或 AMD ROCm 平台上运行已有的 NumPy/SciPy 代码。

>>> 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 功能的访问。您可以通过 RawKernels(文档)将 ndarray 传递给现有的 CUDA C/C++ 程序,使用 Streams(文档)来提升性能,甚至直接调用 CUDA 运行时 API(文档)。

安装

Pip

PyPI 上提供了适用于 Linux 和 Windows 的二进制包(轮子)。请为您的平台选择合适的包。

平台架构命令
CUDA 12.xx86_64 / aarch64pip install cupy-cuda12x
CUDA 13.xx86_64 / aarch64pip install cupy-cuda13x
ROCm 7.0(实验性文档))x86_64pip install cupy-rocm-7-0

[!注意]
要安装预发布版本,请在命令后添加 --pre -U -f https://pip.cupy.dev/pre(例如 pip install cupy-cuda12x --pre -U -f https://pip.cupy.dev/pre)。

Conda

Conda-Forge(链接)上也提供了适用于 Linux 和 Windows 的二进制包。

平台架构命令
CUDAx86_64 / aarch64 / ppc64leconda 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

[!注意]
如果您在使用通过 conda-forge 安装的 CuPy 时遇到任何问题,请前往 cupy-feedstock(链接)报告,我们将帮助调查这只是 conda-forge 配方中的打包问题,还是 CuPy 本身的问题。

Docker

使用 NVIDIA Container Toolkit(文档)运行 CuPy 容器镜像(链接)。

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

资源

1

cuSignal 自 CuPy v13.0.0 起已纳入 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"
}

相似文章

Python 中更快的物理模拟

OpenAI Blog

OpenAI 开源 mujoco-py,一个使用 MuJoCo 引擎的高性能 Python 机器人模拟库,具有无头 GPU 渲染和 VR 交互支持,性能提升约 40 倍。

CUDA-oxide:NVIDIA 官方 Rust 转 CUDA 编译器

Hacker News Top

CUDA-oxide 是由 NVIDIA 开发的实验性 Rust 转 CUDA 编译器,支持使用地道的 Rust 编写安全的 GPU 核函数,可直接编译为 PTX,无需借助领域特定语言或外部绑定。