• 14.cuBLAS开发指南中文版--cuBLAS中的Level-1函数nrm2()和rot()


    cuBLAS中的Level-1函数nrm2()和rot()

    在这里插入图片描述

    2.5.7. cublasnrm2()

    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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    此函数计算向量 x 的欧几里得范数。 该代码使用累积的多阶段模型来避免中间下溢和上溢,结果等价于 ∑ i = 1 n ( x [ j ] × x [ j ] ) 其中 j = 1 + ( i - 1 ) * incx in 精确的算术。 请注意,最后一个等式反映了用于与 Fortran 兼容的基于 1 的索引。

    Param.MemoryIn/outMeaning
    handleinputhandle to the cuBLAS library context.
    ninputnumber of elements in the vector x.
    xdeviceinput vector with n elements.
    incxinputstride between consecutive elements of x.
    resulthost or deviceoutputthe resulting dot product, which is 0.0 if n<=0.

    该函数可能返回的错误值及其含义如下所列。

    Error ValueMeaning
    CUBLAS_STATUS_SUCCESS操作成功完成
    CUBLAS_STATUS_NOT_INITIALIZED库未初始化
    CUBLAS_STATUS_ALLOC_FAILED无法分配缩减缓冲区
    CUBLAS_STATUS_EXECUTION_FAILED该功能无法在 GPU 上启动

    2.5.8. cublasrot()

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

    此函数应用 Givens 旋转矩阵(即,在 x,y 平面中逆时针旋转由 cos(alpha)=c, sin(alpha)=s 定义的角度):

    G = c s - s c

    到向量 x 和 y。

    因此,结果是 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 。 请注意,最后两个等式反映了用于与 Fortran 兼容的基于 1 的索引。

    Param.MemoryIn/outMeaning
    handleinputhandle to the cuBLAS library context.
    ninputnumber of elements in the vector x.
    xdeviceinput vector with n elements.
    incxinputstride between consecutive elements of x.
    ydevicein/out vector with n elements.
    incyinputstride between consecutive elements of y.
    chost or deviceinputcosine element of the rotation matrix.
    shost or deviceinputsine element of the rotation matrix.

    该函数可能返回的错误值及其含义如下所列。

    Error ValueMeaning
    CUBLAS_STATUS_SUCCESS操作成功完成
    CUBLAS_STATUS_NOT_INITIALIZED库未初始化
    CUBLAS_STATUS_EXECUTION_FAILED该功能无法在 GPU 上启动

    请参考:
    srot, drot, crot, csrot, zrot, zdrot

  • 相关阅读:
    java语言【#87. 矩形的面积与周长】(已通过)
    Github每日精选(第40期):为 Windows 带来 macOS “快速查看”功能QuickLook
    项目管理PMP考试技巧
    设置Ollama在局域网中访问的方法(Ubuntu)
    2. Go中的常用命令
    visual studio2019怎么修改字体
    MySQL之函数
    3.JS
    Operator 开发实践 五 (多版本API)
    彻底删除vscode以及vscode的插件记录
  • 原文地址:https://blog.csdn.net/kunhe0512/article/details/126264460