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

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

在这里插入图片描述

2.5.7. 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 的欧几里得范数。 该代码使用累积的多阶段模型来避免中间下溢和上溢,结果等价于 ∑ 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<type> 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. 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)

此函数应用 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<type> vector with n elements.
incxinputstride between consecutive elements of x.
ydevicein/out<type> 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

扫地的小何尚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值