美文网首页
cuBLAS Level-1 Function

cuBLAS Level-1 Function

作者: Junr_0926 | 来源:发表于2018-11-10 09:47 被阅读0次

    cuBLAS Level-1 Function

    Level-1 BLAS函数进行的是标量,向量的基本操作。仅为学习记录,具体内容请以nvidia官方文档为准:
    https://docs.nvidia.com/cuda/cublas/index.html#cublas-level-1-function-reference

    函数命名中的一些字符的含义:


    Screen Shot 2018-11-10 at 9.17.36 AM.png
    • cublasI<t>amax()
    cublasStatus_t cublasIsamax(cublasHandle_t handle, int n,
                                const float *x, int incx, int *result)
    cublasStatus_t cublasIdamax(cublasHandle_t handle, int n,
                                const double *x, int incx, int *result)
    cublasStatus_t cublasIcamax(cublasHandle_t handle, int n,
                                const cuComplex *x, int incx, int *result)
    cublasStatus_t cublasIzamax(cublasHandle_t handle, int n,
                                const cuDoubleComplex *x, int incx, int *result)
    

    这些函数寻找最大长度元素的最小索引值。也就是说找到i使得|Im(x[j])| + |Re(x[j])|最大, 其中i\in [1,...,n], j=1+(i-1) * incx
    参数以及返回值如下图:

    参数以及返回值
    • cublasI<t>amin()
    cublasStatus_t cublasIsamin(cublasHandle_t handle, int n,
                                const float *x, int incx, int *result)
    cublasStatus_t cublasIdamin(cublasHandle_t handle, int n,
                                const double *x, int incx, int *result)
    cublasStatus_t cublasIcamin(cublasHandle_t handle, int n,
                                const cuComplex *x, int incx, int *result)
    cublasStatus_t cublasIzamin(cublasHandle_t handle, int n,
                                const cuDoubleComplex *x, int incx, int *result)
    

    该函数找到拥有最小长度的元素的最小索引值。也就是说找到i使得|Im(x[j])| + |Re(x[j])|最小, 其中i\in [1,...,n], j=1+(i-1) * incx

    参数以及返回值如下图:


    参数以及返回值
    • cublas<t>asum()
    cublasStatus_t  cublasSasum(cublasHandle_t handle, int n,
                                const float           *x, int incx, float  *result)
    cublasStatus_t  cublasDasum(cublasHandle_t handle, int n,
                                const double          *x, int incx, double *result)
    cublasStatus_t cublasScasum(cublasHandle_t handle, int n,
                                const cuComplex       *x, int incx, float  *result)
    cublasStatus_t cublasDzasum(cublasHandle_t handle, int n,
                                const cuDoubleComplex *x, int incx, double *result)
    

    该函数计算向量x的元素的绝对值的和。也就是说,计算结果为\sum_{i=1}^n |Im(x[j])|+Re|(x[j])||,其中j=1+(i-1)*incx

    参数以及返回值


    参数以及返回值
    • cublas<t>axpy()
    cublasStatus_t cublasSaxpy(cublasHandle_t handle, int n,
                               const float           *alpha,
                               const float           *x, int incx,
                               float                 *y, int incy)
    cublasStatus_t cublasDaxpy(cublasHandle_t handle, int n,
                               const double          *alpha,
                               const double          *x, int incx,
                               double                *y, int incy)
    cublasStatus_t cublasCaxpy(cublasHandle_t handle, int n,
                               const cuComplex       *alpha,
                               const cuComplex       *x, int incx,
                               cuComplex             *y, int incy)
    cublasStatus_t cublasZaxpy(cublasHandle_t handle, int n,
                               const cuDoubleComplex *alpha,
                               const cuDoubleComplex *x, int incx,
                               cuDoubleComplex       *y, int incy)
    

    该函数计算向量x和标量\alpha的积,并将结果加到y上,得到的结果覆盖最后一个向量值。y[j]=\alpha * x[k]+y[j],其中i \in [1,...,n], k=1+(i-1)*incx, j=1+(i-1)*incy

    参数及返回值


    参数以及返回值
    • cublas<t>copy()
    cublasStatus_t cublasScopy(cublasHandle_t handle, int n,
                               const float           *x, int incx,
                               float                 *y, int incy)
    cublasStatus_t cublasDcopy(cublasHandle_t handle, int n,
                               const double          *x, int incx,
                               double                *y, int incy)
    cublasStatus_t cublasCcopy(cublasHandle_t handle, int n,
                               const cuComplex       *x, int incx,
                               cuComplex             *y, int incy)
    cublasStatus_t cublasZcopy(cublasHandle_t handle, int n,
                               const cuDoubleComplex *x, int incx,
                               cuDoubleComplex       *y, int incy)
    

    将向量x复制到y中,y[j]=x[k]其中i\in[1,...n], k=1+(i-1)*incx,j=1+(i-1)*incy

    • cublas<t>dot()
    cublasStatus_t cublasSdot (cublasHandle_t handle, int n,
                               const float           *x, int incx,
                               const float           *y, int incy,
                               float           *result)
    cublasStatus_t cublasDdot (cublasHandle_t handle, int n,
                               const double          *x, int incx,
                               const double          *y, int incy,
                               double          *result)
    cublasStatus_t cublasCdotu(cublasHandle_t handle, int n,
                               const cuComplex       *x, int incx,
                               const cuComplex       *y, int incy,
                               cuComplex       *result)
    cublasStatus_t cublasCdotc(cublasHandle_t handle, int n,
                               const cuComplex       *x, int incx,
                               const cuComplex       *y, int incy,
                               cuComplex       *result)
    cublasStatus_t cublasZdotu(cublasHandle_t handle, int n,
                               const cuDoubleComplex *x, int incx,
                               const cuDoubleComplex *y, int incy,
                               cuDoubleComplex *result)
    cublasStatus_t cublasZdotc(cublasHandle_t handle, int n,
                               const cuDoubleComplex *x, int incx,
                               const cuDoubleComplex *y, int incy,
                               cuDoubleComplex       *result)
    

    计算两个向量的点积。\sum_{i=1}^n(x[h]*y[j]),其中k=1+(i-1)*incx,j=1+(i-1)*incy

    Screen Shot 2018-11-10 at 9.29.13 AM.png
    • cublas<t>nrm2()
    cublasStatus_t  cublasSnrm2(cublasHandle_t handle, int n,
                                const float           *x, int incx, float  *result)
    cublasStatus_t  cublasDnrm2(cublasHandle_t handle, int n,
                                const double          *x, int incx, double *result)
    cublasStatus_t cublasScnrm2(cublasHandle_t handle, int n,
                                const cuComplex       *x, int incx, float  *result)
    cublasStatus_t cublasDznrm2(cublasHandle_t handle, int n,
                                const cuDoubleComplex *x, int incx, double *result)
    

    计算向量x的欧式长度,\sum_{i=1}^n (x[j]*x[j]) ,其中j=1+(i-1)*incx

    Screen Shot 2018-11-10 at 9.32.21 AM.png
    • cublas<t>rot()
    cublasStatus_t  cublasSrot(cublasHandle_t handle, int n,
                               float           *x, int incx,
                               float           *y, int incy,
                               const float  *c, const float           *s)
    cublasStatus_t  cublasDrot(cublasHandle_t handle, int n,
                               double          *x, int incx,
                               double          *y, int incy,
                               const double *c, const double          *s)
    cublasStatus_t  cublasCrot(cublasHandle_t handle, int n,
                               cuComplex       *x, int incx,
                               cuComplex       *y, int incy,
                               const float  *c, const cuComplex       *s)
    cublasStatus_t cublasCsrot(cublasHandle_t handle, int n,
                               cuComplex       *x, int incx,
                               cuComplex       *y, int incy,
                               const float  *c, const float           *s)
    cublasStatus_t  cublasZrot(cublasHandle_t handle, int n,
                               cuDoubleComplex *x, int incx,
                               cuDoubleComplex *y, int incy,
                               const double *c, const cuDoubleComplex *s)
    cublasStatus_t cublasZdrot(cublasHandle_t handle, int n,
                               cuDoubleComplex *x, int incx,
                               cuDoubleComplex *y, int incy,
                               const double *c, const double          *s)
    

    该函数对向量进行旋转变换,在向量x,y所处的平面内,逆时针旋转\alpha,其中cos(\alpha)=c,sin(\alpha)=s
    结果为x[k]=c*x[k]+s*y[j],y[j]=-s*x[k]+c*y[j]其中k = 1 + ( i - 1 ) * incx,j = 1 + ( i - 1 ) * incy

    Screen Shot 2018-11-10 at 9.36.37 AM.png
    • cublas<t>rotg()
    cublasStatus_t cublasSrotg(cublasHandle_t handle,
                               float           *a, float           *b,
                               float  *c, float           *s)
    cublasStatus_t cublasDrotg(cublasHandle_t handle,
                               double          *a, double          *b,
                               double *c, double          *s)
    cublasStatus_t cublasCrotg(cublasHandle_t handle,
                               cuComplex       *a, cuComplex       *b,
                               float  *c, cuComplex       *s)
    cublasStatus_t cublasZrotg(cublasHandle_t handle,
                               cuDoubleComplex *a, cuDoubleComplex *b,
                               double *c, cuDoubleComplex *s)
    

    该函数构建旋转矩阵:G = \left\{ \begin{matrix} c & s \\ -s & c \end{matrix} \right\} \tag{2}
    然后令向量(a,b)^T第二个元素为0,也就是:

    Screen Shot 2018-11-10 at 9.44.32 AM.png
    • cublas<t>rotm()
    cublasStatus_t cublasSrotm(cublasHandle_t handle, int n, float  *x, int incx,
                               float  *y, int incy, const float*  param)
    cublasStatus_t cublasDrotm(cublasHandle_t handle, int n, double *x, int incx,
                               double *y, int incy, const double* param)
    
    Screen Shot 2018-11-10 at 9.46.01 AM.png
    • cublas<t>scal()
    cublasStatus_t  cublasSscal(cublasHandle_t handle, int n,
                                const float           *alpha,
                                float           *x, int incx)
    cublasStatus_t  cublasDscal(cublasHandle_t handle, int n,
                                const double          *alpha,
                                double          *x, int incx)
    cublasStatus_t  cublasCscal(cublasHandle_t handle, int n,
                                const cuComplex       *alpha,
                                cuComplex       *x, int incx)
    cublasStatus_t cublasCsscal(cublasHandle_t handle, int n,
                                const float           *alpha,
                                cuComplex       *x, int incx)
    cublasStatus_t  cublasZscal(cublasHandle_t handle, int n,
                                const cuDoubleComplex *alpha,
                                cuDoubleComplex *x, int incx)
    cublasStatus_t cublasZdscal(cublasHandle_t handle, int n,
                                const double          *alpha,
                                cuDoubleComplex *x, int incx)
    

    标量与向量相乘

    • cublas<t>swap()
    cublasStatus_t cublasSswap(cublasHandle_t handle, int n, float           *x,
                               int incx, float           *y, int incy)
    cublasStatus_t cublasDswap(cublasHandle_t handle, int n, double          *x,
                               int incx, double          *y, int incy)
    cublasStatus_t cublasCswap(cublasHandle_t handle, int n, cuComplex       *x,
                               int incx, cuComplex       *y, int incy)
    cublasStatus_t cublasZswap(cublasHandle_t handle, int n, cuDoubleComplex *x,
                               int incx, cuDoubleComplex *y, int incy)
    

    交换两向量元素

    相关文章

      网友评论

          本文标题:cuBLAS Level-1 Function

          本文链接:https://www.haomeiwen.com/subject/batzxqtx.html