cuBLAS中的Level-1函数rotg()
2.5.9. 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)
此函数构造 Givens 旋转矩阵
G = c s - s c
将 2 × 1 向量 ( a , b ) T 的第二个条目归零。
然后,对于实数,我们可以写
c s - s c a b = r 0
其中 c 2 + s 2 = 1 和 r = a 2 + b 2 。 参数 a 和 b 分别被 r 和 z 覆盖。 z 的值使得 c 和 s 可以使用以下规则恢复:
( c , s ) = ( 1 - z 2 , z ) if | z | < 1 ( 0 . 0 , 1 . 0 ) if | z | = 1 ( 1 ∕ z , 1 - z 2 ) if | z | > 1
对于复数,我们可以写
c s - s ̄ c a b = r 0
其中 c 2 + ( s ̄ × s ) = 1 and r = a | a | × || ( a , b ) T || 2 with || ( a , b ) T || 2 = | a | 2 + | b | 2 for a ≠ 0 and r = b for a = 0。 最后,参数 a 在退出时被 r 覆盖。
Param. | Memory | In/out | Meaning |
---|---|---|---|
handle | input | handle to the cuBLAS library context. | |
a | host or device | in/out | <type> scalar that is overwritten with r . |
b | host or device | in/out | <type> scalar that is overwritten with z . |
c | host or device | input | cosine element of the rotation matrix. |
s | host or device | input | sine element of the rotation matrix. |
Error Value | Meaning |
---|---|
CUBLAS_STATUS_SUCCESS | 操作成功完成 |
CUBLAS_STATUS_NOT_INITIALIZED | 库未初始化 |
CUBLAS_STATUS_EXECUTION_FAILED | 该功能无法在 GPU 上启动 |