scikits.cuda.cublas.cublasSaxpy

scikits.cuda.cublas.cublasSaxpy(handle, n, alpha, x, incx, y, incy)[source]

Vector addition (single-precision real).

Computes the sum of a single-precision real vector scaled by a single-precision real scalar and another single-precision real vector.

Parameters:

handle : int

CUBLAS context.

n : int

Number of elements in input vectors.

alpha : numpy.float32

Scalar.

x : ctypes.c_void_p

Pointer to single-precision input vector.

incx : int

Storage spacing between elements of x.

y : ctypes.c_void_p

Pointer to single-precision input/output vector.

incy : int

Storage spacing between elements of y.

Notes

Both x and y must contain n elements.

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> alpha = np.float32(np.random.rand())
>>> x = np.random.rand(5).astype(np.float32)
>>> y = np.random.rand(5).astype(np.float32)
>>> x_gpu = gpuarray.to_gpu(x)
>>> y_gpu = gpuarray.to_gpu(y)
>>> h = cublasCreate()
>>> cublasSaxpy(h, x_gpu.size, alpha, x_gpu.gpudata, 1, y_gpu.gpudata, 1)
>>> cublasDestroy(h)
>>> np.allclose(y_gpu.get(), alpha*x+y)
True