简体   繁体   English

在BLAS中使用较少的矩阵

[英]Using less matrices with BLAS

I'm quite new to BLAS (using OpenBLAS with C++ and VisualStudio) 我对BLAS相当陌生(将OpenBLAS与C ++和VisualStudio结合使用)

I know dgemm performs C <- alpha * op(A) * op(B) + beta * C 我知道dgemm执行C < -alpha * op(A)* op(B)+ beta * C

I was trying to save some allocation doing this: B <- 1 * op(A) * op(B) + 0 * B 我正在尝试为此保存一些分配: B <-1 * op(A)* op(B)+ 0 * B

In other words, putting the result in the B matrix, 换句话说,将结果放入B矩阵中

BUT making beta = 0 and repeating B in the position of C , results in a zero answer. 但是使beta = 0并在C的位置重复B会导致答案为零。

Is there a way to make it right? 有没有办法做到这一点?

The code that I'm using: 我正在使用的代码:

double* A = new double [3*3]; //3 rows x 3 columns

A[0] = 8;
A[1] = 3;
A[2] = 4;
A[3] = 1;
A[4] = 5;
A[5] = 9;
A[6] = 6;
A[7] = 7;
A[8] = 2;

double* v = new double[3]; //3 rows x 1 column

v[0] = 3;
v[1] = 5;
v[2] = 2;

double* foo = new double[3]; //3 rows x 1 column

cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans,
    3, 1, 3,
    1,
    A, 3,
    v, 3,
    0,
    foo, 3); // makes foo = [41 ; 48 ; 61], **right**

cblas_dgemm(CblasColMajor, CblasTrans, CblasTrans,
    3, 1, 3,
    1,
    A, 3,
    v, 3,
    0,
    v, 3); // makes v = [0 ; 0 ; 0], **wrong**

BLAS dgemm function documentation states that only the C matrix parameter is for both input and output, being overwritten by the operation result. BLAS dgemm功能文档指出,只有C矩阵参数同时用于输入和输出,并被运算结果覆盖。 As B is defined just for input, BLAS implementations can assume that it shouldn't be modified. 由于仅将B定义为输入,因此BLAS实现可以假定不应对其进行修改。

Setting B and C to the same data pointer could be triggering some error verification on the implementation you're using, returning the zeroed result to indicate that. 将B和C设置为相同的数据指针可能会触发您正在使用的实现的一些错误验证,并返回清零的结果来表明这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM