提交 f9cc310b 编写于 作者: Y yanantao78

fix by clang-format

上级 4c32eb7f
...@@ -12,9 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,9 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <iostream>
#include "../test_helper.h" #include "../test_helper.h"
#include "common/log.h" #include "common/log.h"
#include "memory/t_malloc.h" #include "memory/t_malloc.h"
...@@ -26,14 +26,14 @@ limitations under the License. */ ...@@ -26,14 +26,14 @@ limitations under the License. */
#define c1(i, j) c1[(i)*ldc + (j)] #define c1(i, j) c1[(i)*ldc + (j)]
void print_matirx(int m, int n, int ldc, float *c) { void print_matirx(int m, int n, int ldc, float *c) {
for (int i = 0; i < m; ++i) { for (int i = 0; i < m; ++i) {
std::cout << c(i, 0); std::cout << c(i, 0);
for (int j = 1; j < n; ++j) { for (int j = 1; j < n; ++j) {
std::cout << " | " << c(i, j); std::cout << " | " << c(i, j);
}
std::cout << std::endl;
} }
std::cout << std::endl; std::cout << std::endl;
}
std::cout << std::endl;
} }
int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) { int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) {
...@@ -41,12 +41,18 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) { ...@@ -41,12 +41,18 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) {
int ldb = n; int ldb = n;
int ldc = n; int ldc = n;
float *a = static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m * k)); float *a =
float *b = static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * k * n)); static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m * k));
float *c = static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m * n)); float *b =
float *c1 = static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m * n)); static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * k * n));
float* scale = static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m)); float *c =
float* bias = static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m)); static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m * n));
float *c1 =
static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m * n));
float *scale =
static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m));
float *bias =
static_cast<float *>(paddle_mobile::memory::Alloc(sizeof(float) * m));
srand(unsigned(time(0))); srand(unsigned(time(0)));
for (int i = 0; i < m * k; ++i) { for (int i = 0; i < m * k; ++i) {
...@@ -77,15 +83,15 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) { ...@@ -77,15 +83,15 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) {
} }
} }
paddle_mobile::operators::math::SgemmWithBn(m, n, k, 0.9, a, lda, paddle_mobile::operators::math::SgemmWithBn(m, n, k, 0.9, a, lda, b, ldb, 0.3,
b, ldb, 0.3, c, ldc, relu, scale, bias); c, ldc, relu, scale, bias);
int eq = 0; int eq = 0;
int neq = 0; int neq = 0;
for (int i = 0; i < m * n; ++i) { for (int i = 0; i < m * n; ++i) {
if (static_cast<int>(c[i]) == static_cast<int>(c1[i])) { if (static_cast<int>(c[i]) == static_cast<int>(c1[i])) {
++eq; ++eq;
} else { } else {
++neq; ++neq;
} }
} }
...@@ -100,9 +106,8 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) { ...@@ -100,9 +106,8 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) {
print_matirx(m, n, ldc, c1); print_matirx(m, n, ldc, c1);
} }
std::cout << "mnk=" << m << " " << n << " " << k << std::cout << "mnk=" << m << " " << n << " " << k << " relu=" << relu
" relu=" << relu << << " eq=" << eq << " neq=" << neq << std::endl;
" eq=" << eq << " neq=" << neq << std::endl;
paddle_mobile::memory::Free(a); paddle_mobile::memory::Free(a);
paddle_mobile::memory::Free(b); paddle_mobile::memory::Free(b);
...@@ -115,7 +120,6 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) { ...@@ -115,7 +120,6 @@ int do_sgemm(int m, int n, int k, bool relu, int t1, int t2, int pr) {
} }
int main() { int main() {
do_sgemm(9, 9, 9, true, 10, 10, 10); do_sgemm(9, 9, 9, true, 10, 10, 10);
do_sgemm(10, 6, 12, false, 10, 10, 0); do_sgemm(10, 6, 12, false, 10, 10, 0);
do_sgemm(512, 256, 384, false, 10, 10, 0); do_sgemm(512, 256, 384, false, 10, 10, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册