cupy numpy on GPU

cupy: numpy on GPU

Guide

CuPy: NumPy-like API accelerated with CUDA.

install

(For CUDA 8.0)
% pip install cupy-cuda80

(For CUDA 9.0)
% pip install cupy-cuda90

(For CUDA 9.1)
% pip install cupy-cuda91

(For CUDA 9.2)
% pip install cupy-cuda92

(For CUDA 10.0)
% pip install cupy-cuda100

(For CUDA 10.1)
% pip install cupy-cuda101

(Install CuPy from source)
% pip install cupy

usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
>>> 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)



>>> x = cp.arange(6, dtype='f').reshape(2, 3)
>>> y = cp.arange(3, dtype='f')
>>> kernel = cp.ElementwiseKernel(
... 'float32 x, float32 y', 'float32 z',
... '''if (x - 2 > y) {
... z = x * y;
... } else {
... z = x + y;
... }''', 'my_kernel')
>>> kernel(x, y)
array([[ 0., 2., 4.],
[ 0., 4., 10.]], dtype=float32)

Reference

History

  • 20191006: created.
赞赏