cupy/cupy
摘要
CuPy是一个GPU加速的库,可作为NumPy/SciPy的直接替代品,支持在NVIDIA CUDA和AMD ROCm平台上进行高效的数组运算。
查看缓存全文
缓存时间: 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.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 |
[!注意]
要安装预发布版本,请在命令后添加--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 的二进制包。
| 平台 | 架构 | 命令 |
|---|---|---|
| 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。
[!注意]
如果您在使用通过conda-forge安装的 CuPy 时遇到任何问题,请前往 cupy-feedstock(链接)报告,我们将帮助调查这只是conda-forge配方中的打包问题,还是 CuPy 本身的问题。
Docker
使用 NVIDIA Container Toolkit(文档)运行 CuPy 容器镜像(链接)。
$ docker run --gpus all -it cupy/cupy
资源
- 安装指南 - 从源码构建的说明
- 发布说明
- 使用 CuPy 的项目
- 贡献指南
- 使用 CuPy 和 Numba 进行 Python GPU 加速(GTC 2021 年 11 月技术会议)
- [使用 CuPy 和 cuSignal1 加速信号处理工作流(ICASSP’21 教程)](https://github.com/awthomp/cusignal-icassp-tutorial)
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"
}
相似文章
@charles_irl: GPU 术语表新增文章:CuTe DSL、CUTLASS 和 CuTe——用于编写一些最高性能…
GPU 术语表新增文章,涵盖 CuTe DSL、CUTLASS 和 CuTe——这些工具用于在数据中心 GPU 上编写高性能 GPU 内核,并附有 Python 示例。
Python 中更快的物理模拟
OpenAI 开源 mujoco-py,一个使用 MuJoCo 引擎的高性能 Python 机器人模拟库,具有无头 GPU 渲染和 VR 交互支持,性能提升约 40 倍。
CUDA-oxide:NVIDIA 官方 Rust 转 CUDA 编译器
CUDA-oxide 是由 NVIDIA 开发的实验性 Rust 转 CUDA 编译器,支持使用地道的 Rust 编写安全的 GPU 核函数,可直接编译为 PTX,无需借助领域特定语言或外部绑定。
cuda-oxide: 一款实验性的 Rust-to-CUDA 编译器
cuda-oxide 是 NVIDIA 发布的一款实验性 Rust-to-CUDA 编译器后端,支持纯 Rust GPU 内核开发,无需外部语言绑定。
Show HN: cuTile Rust:在Rust中编写安全、无数据竞争的GPU内核
NVIDIA Labs发布了cuTile Rust,这是一个基于瓦片的系统,用于用地道的Rust编写内存安全、无数据竞争的GPU内核。它将Rust的所有权模型扩展到GPU内核,通过JIT将Rust的AST编译为GPU代码,并实现接近原生CUDA的性能。