Fix linalg_matmul_impl interfacing with sgemm
authorNicolas Vasilache <ntv@google.com>
Fri, 26 Jul 2019 10:33:53 +0000 (03:33 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Fri, 26 Jul 2019 10:34:21 +0000 (03:34 -0700)
This CL provides a fix that makes linal_matmul_impl compliant with the BLAS interface. Before this CL it would compute either C += A * B when called with cblas.cpp:cblas_sgemm implementation and C = A * B with other implementations.

PiperOrigin-RevId: 260117367

mlir/test/mlir-cpu-runner/cblas.cpp
mlir/test/mlir-cpu-runner/cblas_interface.cpp

index dfc3a5f..d219b7b 100644 (file)
@@ -50,7 +50,7 @@ extern "C" void cblas_sgemm(const enum CBLAS_ORDER Order,
         auto *pB = B + k * ldb;
         res += pA[k] * pB[n];
       }
-      pC[n] = (1.0f + alpha) * c + beta * res;
+      pC[n] = alpha * c + beta * res;
     }
   }
 }
index cf6a49c..1a63237 100644 (file)
@@ -57,7 +57,7 @@ extern "C" void linalg_matmul_impl(ViewType<float, 2> *A, ViewType<float, 2> *B,
   assert(A->sizes[1] == B->sizes[0]);
   cblas_sgemm(CBLAS_ORDER::CblasRowMajor, CBLAS_TRANSPOSE::CblasNoTrans,
               CBLAS_TRANSPOSE::CblasNoTrans, C->sizes[0], C->sizes[1],
-              A->sizes[1], 0.0f, A->data + A->offset, A->strides[0],
+              A->sizes[1], 1.0f, A->data + A->offset, A->strides[0],
               B->data + B->offset, B->strides[0], 1.0f, C->data + C->offset,
               C->strides[0]);
 }