CuPy is an
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
library for GPU-accelerated computing with
Python programming language, providing support for multi-dimensional arrays, sparse matrices, and a variety of numerical algorithms implemented on top of them.
CuPy shares the same API set as
NumPy and
SciPy, allowing it to be a drop-in replacement to run NumPy/SciPy code on GPU. CuPy supports
NVIDIA CUDA GPU platform, and
AMD ROCm GPU platform starting in v9.0.
CuPy has been initially developed as a backend of
Chainer deep learning framework, and later established as an independent project in 2017.
CuPy is a part of the NumPy ecosystem array libraries and is widely adopted to utilize GPU with Python, especially in high-performance computing environments such as
Summit
A summit is a point on a surface that is higher in elevation than all points immediately adjacent to it. The topography, topographic terms acme, apex, peak (mountain peak), and zenith are synonymous.
The term (mountain top) is generally used ...
,
Perlmutter,
Eluer, and
ABCI.
CuPy is a
NumFOCUS affiliated project.
Features
CuPy implements NumPy/SciPy-compatible APIs, as well as features to write user-defined GPU kernels or access low-level APIs.
NumPy-compatible APIs
The same set of APIs defined in the NumPy package () are available under package.
* Multi-dimensional
array () for boolean, integer, float, and complex data types
* Module-level functions
*
Linear algebra functions
*
Fast Fourier transform
A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its original domain (often time or space) to a representation in th ...
*
Random number generator
SciPy-compatible APIs
The same set of APIs defined in the SciPy package () are available under package.
*
Sparse matrices () of CSR, COO, CSC, and DIA format
*
Discrete Fourier transform
* Advanced linear algebra
* Multidimensional
image processing
An image is a visual representation of something. It can be two-dimensional, three-dimensional, or somehow otherwise feed into the visual system to convey information. An image can be an artifact, such as a photograph or other two-dimensiona ...
* Sparse linear algebra
* Special functions
*
Signal processing
*
Statistical functions
User-defined GPU kernels
* Kernel templates for element-wise and reduction operations
* Raw kernel (CUDA C/C++)
* Just-in-time transpiler (JIT)
* Kernel fusion
Distributed computing
* Distributed communication package (), providing collective and peer-to-peer primitives
Low-level CUDA features
* Stream and event
* Memory pool
* Profiler
* Host API binding
* CUDA Python support
Interoperability
* DLPack
* CUDA Array Interface
* NEP 13 ()
* NEP 18 ()
* Array API Standard
Examples
Array creation
>>> import cupy as cp
>>> x = cp.array(, 2, 3
The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline o ...
>>> x
array(, 2, 3
The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline o ...
>>> y = cp.arange(10)
>>> y
array(, 1, 2, 3, 4, 5, 6, 7, 8, 9
The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline o ...
Basic operations
>>> import cupy as cp
>>> x = cp.arange(12).reshape(3, 4).astype(cp.float32)
>>> x
array( 0., 1., 2., 3.
4., 5., 6., 7.
8., 9., 10., 11., dtype=float32)
>>> x.sum(axis=1)
array( 6., 22., 38. dtype=float32)
Raw CUDA C/C++ kernel
>>> import cupy as cp
>>> kern = cp.RawKernel(r
... extern "C" __global__
... void multiply_elemwise(const float* in1, const float* in2, float* out)
... , 'multiply_elemwise')
>>> in1 = cp.arange(16, dtype=cp.float32).reshape(4, 4)
>>> in2 = cp.arange(16, dtype=cp.float32).reshape(4, 4)
>>> out = cp.zeros((4, 4), dtype=cp.float32)
>>> kern((4,), (4,), (in1, in2, out)) # grid, block and arguments
>>> out
array( 0., 1., 4., 9.
16., 25., 36., 49.
64., 81., 100., 121.
44., 169., 196., 225., dtype=float32)
Applications
*
spaCy
*
XGBoost
* turboSETI (
Berkeley SETI)
* NVIDIA RAPIDS
* einops
*
Chainer[
]
See also
*
Array programming
*
List of numerical-analysis software
*
Dask
References
External links
*
GitHub repository
{{DEFAULTSORT:CuPy
Array programming languages
Articles with example Python (programming language) code
Free mathematics software
Free science software
Numerical analysis software for Linux
Numerical analysis software for Windows
Numerical programming languages
Python (programming language) scientific libraries
Software using the MIT license