mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]

A templatized interface to the cublas library

Functions

template<typename floatT >
cublasStatus_t mx::cuda::cublasTscal (cublasHandle_t handle, int n, const floatT *alpha, floatT *x, int incx)
 Multiplies a vector by a scalar, overwriting the vector with the result. More...
 
template<typename floatT >
cublasStatus_t mx::cuda::cublasTaxpy (cublasHandle_t handle, int n, const floatT *alpha, const floatT *x, int incx, floatT *y, int incy)
 Multiplies a vector by a scalar, adding it to a second vector which is overwritten by the result. More...
 
template<typename dataT1 , typename dataT2 >
cudaError_t mx::cuda::elementwiseXxY (dataT1 *x, dataT2 *y, int size)
 Calculates the element-wise product of two vectors, storing the result in the first. More...
 
template<typename floatT >
cublasStatus_t mx::cuda::cublasTgemv (cublasHandle_t handle, cublasOperation_t trans, int m, int n, const floatT *alpha, const floatT *A, int lda, const floatT *x, int incx, const floatT *beta, floatT *y, int incy)
 Perform a matrix-vector multiplication. More...
 
template<typename floatT >
cublasStatus_t mx::cuda::cublasTgemv (cublasHandle_t handle, cublasOperation_t trans, int m, int n, const floatT *alpha, const floatT *A, const floatT *x, const floatT *beta, floatT *y)
 Perform a matrix-vector multiplication for stride-less arrays. More...
 

Function Documentation

◆ cublasTaxpy()

template<typename floatT >
cublasStatus_t mx::cuda::cublasTaxpy ( cublasHandle_t  handle,
int  n,
const floatT *  alpha,
const floatT *  x,
int  incx,
floatT *  y,
int  incy 
)

Multiplies a vector by a scalar, adding it to a second vector which is overwritten by the result.

Implements

\[ \vec{y} = \alpha \vec{x} + \vec{y} \]

Specializations are provided for float, double, complex-float, and complex-double

Template Parameters
floatTa floating-point type, either float, double, complex-float, or complex-double
Test:
Scenario: scaling and accumulating a vector with cublas [test doc]
Parameters
[in]handlehandle to the cuBLAS library context.
[in]nscalar used for multiplication.
[in]alphanumber of elements in the vector x and y
[in]xvector with n elements.
[in]incxstride between consecutive elements of x
y[in.out] vector with n elements.
[in]incystride between consecutive elements of y

Referenced by SCENARIO().

◆ cublasTgemv() [1/2]

template<typename floatT >
cublasStatus_t mx::cuda::cublasTgemv ( cublasHandle_t  handle,
cublasOperation_t  trans,
int  m,
int  n,
const floatT *  alpha,
const floatT *  A,
const floatT *  x,
const floatT *  beta,
floatT *  y 
)

Perform a matrix-vector multiplication for stride-less arrays.

Implements

\[ \vec{y} = \alpha \mathbf{A} \vec{x} + \beta \vec{y} \]

Specializations are provided for float, double, complex-float, and complex-double

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version assumes stride is 1 in all arrays.

Template Parameters
floatTa floating-point type, either float, double, complex-float, or complex-double
Parameters
[in]handlehandle to the cuBLAS library context.
[in]transoperation on a, CUBLAS_OP_N for none, and CUBLAS_OP_T for transpose
[in]mrows in matrix A.
[in]ncolumns in matrix A.
[in]alphascalar used for multiplication of A
[in]Aarray of dimension m x n. Unchanged.
[in]xvector of at least (1+(n-1)*abs(incx)) elements if transa==CUBLAS_OP_N and at least (1+(m-1)*abs(incx)) elements otherwise.
[in]betascalar used for multiplication of y, if beta==0 then y does not need to be initialized.
y[in.out] vector of at least (1+(m-1)*abs(incy)) elements if transa==CUBLAS_OP_N and at least (1+(n-1)*abs(incy)) elements otherwise.

◆ cublasTgemv() [2/2]

template<typename floatT >
cublasStatus_t mx::cuda::cublasTgemv ( cublasHandle_t  handle,
cublasOperation_t  trans,
int  m,
int  n,
const floatT *  alpha,
const floatT *  A,
int  lda,
const floatT *  x,
int  incx,
const floatT *  beta,
floatT *  y,
int  incy 
)

Perform a matrix-vector multiplication.

Implements

\[ \vec{y} = \alpha \mathbf{A} \vec{x} + \beta \vec{y} \]

Specializations are provided for float, double, complex-float, and complex-double

Template Parameters
floatTa floating-point type, either float, double, complex-float, or complex-double

\tests Scenario: multiplying a vectory by a matrix [code doc]

Parameters
[in]handlehandle to the cuBLAS library context.
[in]transoperation on a, CUBLAS_OP_N for none, and CUBLAS_OP_T for transpose
[in]mrows in matrix A.
[in]ncolumns in matrix A.
[in]alphascalar used for multiplication of A
[in]Aarray of dimension lda x n with lda >= max(1,m). The leading m by n part of the array A is multiplied by alpha and x. Unchanged.
[in]ldaleading dimension of A. lda must be at least max(1,m).
[in]xvector of at least (1+(n-1)*abs(incx)) elements if transa==CUBLAS_OP_N and at least (1+(m-1)*abs(incx)) elements otherwise.
[in]incxstride of x.
[in]betascalar used for multiplication of y, if beta==0 then y does not need to be initialized.
y[in.out] vector of at least (1+(m-1)*abs(incy)) elements if transa==CUBLAS_OP_N and at least (1+(n-1)*abs(incy)) elements otherwise.
[in]incystride of y

Referenced by SCENARIO().

◆ cublasTscal()

template<typename floatT >
cublasStatus_t mx::cuda::cublasTscal ( cublasHandle_t  handle,
int  n,
const floatT *  alpha,
floatT *  x,
int  incx 
)

Multiplies a vector by a scalar, overwriting the vector with the result.

Implements

\[ \vec{x} = \alpha \vec{x} \]

Specializations are provided for float, double, complex-float, and complex-double

Template Parameters
floatTa floating-point type, either float, double, complex-float, or complex-double
Test:
Scenario: scaling a vector with cublas [test doc]
Parameters
[in]handleThe cublas context handle
[in]nNumber of elements in the vector
[in]alphaThe scalar
x[in.out] The vector of length n
[in]incxThe stride of the vector

Referenced by SCENARIO().

◆ elementwiseXxY()

template<typename dataT1 , typename dataT2 >
cudaError_t mx::cuda::elementwiseXxY ( dataT1 *  x,
dataT2 *  y,
int  size 
)

Calculates the element-wise product of two vectors, storing the result in the first.

Calculates \( x = x * y \) element by element, a.k.a. the Hadamard product.

Specializations are provided for:

  • float,float
  • complex-float, float
  • complex-float, complex-float
  • double, double
  • complex-double, double
  • complex-double, complex-double

    Test:
    Scenario: multiplying two vectors element by element [test doc]
Parameters
x[in.out] device pointer for the 1st vector. Is replaced with the product of the two vectors
[in]ydevice pointer for the 2nd vector.
[in]sizethe number of elements in the vectors.

Referenced by SCENARIO().