From bb34c4d99ddbb457c5822efb4ca13fa67a82c35e Mon Sep 17 00:00:00 2001 From: luoliang Date: Thu, 28 Jul 2022 15:52:14 +0800 Subject: [PATCH] debug --- acl/include/opencv2/acl/mat_core.hpp | 3 +- acl/src/acl_mat.cpp | 1 - acl/src/gemm.cpp | 2 - acl/src/mathfuncs.cpp | 2 +- acl/test/acl.cpp | 15 ++-- acl/test/test_acl.cpp | 8 +- acl/test/test_common.cpp | 10 +-- acl/test/test_gemm.cpp | 10 +-- acl/test/test_mathfuncs.cpp | 125 ++++++++++++++------------- acl/test/test_matrices.cpp | 13 +-- 10 files changed, 95 insertions(+), 94 deletions(-) diff --git a/acl/include/opencv2/acl/mat_core.hpp b/acl/include/opencv2/acl/mat_core.hpp index f8c741a..7100052 100644 --- a/acl/include/opencv2/acl/mat_core.hpp +++ b/acl/include/opencv2/acl/mat_core.hpp @@ -145,8 +145,9 @@ namespace cv { if (this != &m) { + if (refcount) - CV_XADD(refcount, -1); + release(); flags = m.flags; rows = m.rows; cols = m.cols; diff --git a/acl/src/acl_mat.cpp b/acl/src/acl_mat.cpp index 92e10cf..80a2395 100644 --- a/acl/src/acl_mat.cpp +++ b/acl/src/acl_mat.cpp @@ -200,7 +200,6 @@ namespace cv opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false); compileAndRunop(opDesc, inputBuffers_, outputBuffers_, this->acl_context); - newMat.data = aclGetDataBufferAddr(outputBuffers_[0]); *this = newMat; for (size_t i = 0; i < inputBuffers_.size(); i++) diff --git a/acl/src/gemm.cpp b/acl/src/gemm.cpp index 3251e7a..adfe887 100644 --- a/acl/src/gemm.cpp +++ b/acl/src/gemm.cpp @@ -31,8 +31,6 @@ namespace cv opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false); compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context); - dest.data = aclGetDataBufferAddr(outputBuffers_[0]); - for (size_t i = 0; i < inputBuffers_.size(); i++) AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i])); for (size_t i = 0; i < outputBuffers_.size(); i++) diff --git a/acl/src/mathfuncs.cpp b/acl/src/mathfuncs.cpp index 846be83..e875b45 100644 --- a/acl/src/mathfuncs.cpp +++ b/acl/src/mathfuncs.cpp @@ -8,7 +8,7 @@ namespace cv { aclMat dest(a.rows, a.cols, a.type(), a.acl_context); OneInAndOneOut(a, dest, "Abs"); - return a; + return dest; } static void *power_data(double power, aclDataType type, size_t powersize) diff --git a/acl/test/acl.cpp b/acl/test/acl.cpp index ce54ab2..7f90e20 100644 --- a/acl/test/acl.cpp +++ b/acl/test/acl.cpp @@ -204,7 +204,7 @@ namespace opencv_test test.Test_operator_mul_perf(acl_context_0); } - TEST(Mathfuncs, abs) + TEST(Mathfunction, abs) { PERF_TEST test; test.Test_Abs(acl_context_0); @@ -215,7 +215,6 @@ namespace opencv_test PERF_TEST test; test.Test_Pow(acl_context_0); } - TEST(Mathfunction, sqrt) { PERF_TEST test; @@ -263,12 +262,6 @@ namespace opencv_test PERF_TEST test; test.Test_MatMul(acl_context_0); } - - TEST(Matrices, merge) - { - PERF_TEST test; - test.Test_Merge(acl_context_0); - } TEST(Gemm, Convolution) { @@ -276,6 +269,12 @@ namespace opencv_test test.Test_Convolution(acl_context_0); } + TEST(Matrices, merge) + { + PERF_TEST test; + test.Test_Merge(acl_context_0); + } + TEST(Matrices, split) { PERF_TEST test; diff --git a/acl/test/test_acl.cpp b/acl/test/test_acl.cpp index 208f0ae..0b67320 100644 --- a/acl/test/test_acl.cpp +++ b/acl/test/test_acl.cpp @@ -57,7 +57,7 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context) double begin, end, time, acltime; Common_Test test; - vector type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1}; + vector type{CV_32FC1, CV_32SC1, CV_64FC1}; for (size_t i = 0; i < type.size(); ++i) { test.PrintLog("Perf test : Function: operator-=()", type[i]); @@ -68,8 +68,8 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context) Mat mat_dest(val, val, type[i]); Mat mat_dest1(val, val, type[i]); - test.SetDataRange(mat_src, 1); - test.SetDataRange(mat_dest, 1); + test.SetDataRange(mat_src, 4); + test.SetDataRange(mat_dest, 32); aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context); aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context); @@ -150,7 +150,7 @@ void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context) void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context) { int val, type; - int valmax = 8192; + int valmax = 4096; double begin, end, time, acltime; Common_Test test; diff --git a/acl/test/test_common.cpp b/acl/test/test_common.cpp index e4d498e..f5b3195 100644 --- a/acl/test/test_common.cpp +++ b/acl/test/test_common.cpp @@ -201,35 +201,35 @@ bool Common_Test::SetDataRange(Mat &src, int dataRange) for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels()) { for (int j = 0; j < src.channels(); ++j) - (src.data)[i+j] = RandDom_(dataRange); + (src.data)[i+j] = RandDom_(dataRange) + 1; } return true; case CV_16U: for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels()) { for (int j = 0; j < src.channels(); ++j) - ((unsigned short *)src.data)[i+j] = RandDom_(dataRange); + ((unsigned short *)src.data)[i+j] = RandDom_(dataRange) + 1; } return true; case CV_32S: for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels()) { for (int j = 0; j < src.channels(); ++j) - ((int *)src.data)[i+j] = RandDom_(dataRange); + ((int *)src.data)[i+j] = RandDom_(dataRange) + 1; } return true; case CV_32F: for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels()) { for (int j = 0; j < src.channels(); ++j) - ((float *)src.data)[i+j] = RandDom_(dataRange) / 1.0; + ((float *)src.data)[i+j] = RandDom_(dataRange) / 1.0 + 1; } return true; case CV_64F: for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels()) { for (int j = 0; j < src.channels(); ++j) - ((double *)src.data)[i+j] = RandDom_(dataRange) / 1.0; + ((double *)src.data)[i+j] = RandDom_(dataRange) / 1.0 + 1; } return true; default: diff --git a/acl/test/test_gemm.cpp b/acl/test/test_gemm.cpp index fc3fa63..6612109 100644 --- a/acl/test/test_gemm.cpp +++ b/acl/test/test_gemm.cpp @@ -4,7 +4,7 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context) { int val, type; - int valmax = 8192; + int valmax = 4096; double begin, end, time, acltime; Common_Test test; @@ -53,7 +53,7 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context) void PERF_TEST::Test_Convolution(aclCxt *acl_context) { int val, type; - int valmax = 8192; + int valmax = 4096; double begin, end, time, acltime; Common_Test test; @@ -68,7 +68,7 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context) aclMat aclmat_src(val, val, type, mat_src.data, acl_context); aclMat aclmat_kernel(3, 3, type, mat_kernel.data, acl_context); aclMat aclmat_dest(val, val, type, mat_dest.data, acl_context); - int n = 1; + int n = 100; begin = static_cast(getTickCount()); while (n--) @@ -76,7 +76,7 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context) end = static_cast(getTickCount()); time = (end - begin) / getTickFrequency(); - n = 1; + n = 100; begin = static_cast(getTickCount()); vector strides{1, 1, 1, 1}; vector pads{1, 1, 1, 1}; @@ -87,8 +87,6 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context) acltime = (end - begin) / getTickFrequency(); aclmat_dest.download(mat_dest1); - cout << mat_dest << endl; - cout << mat_dest1 << endl; /* bool ret = test.Test_Diff(mat_dest, mat_dest1); ASSERT_TRUE(ret); diff --git a/acl/test/test_mathfuncs.cpp b/acl/test/test_mathfuncs.cpp index 9c76363..39058b7 100644 --- a/acl/test/test_mathfuncs.cpp +++ b/acl/test/test_mathfuncs.cpp @@ -3,89 +3,94 @@ void PERF_TEST::Test_Abs(aclCxt *acl_context) { - int val, type; + int val; int valmax = 8192; double begin, end, time, acltime; Common_Test test; - type = CV_32FC1; - - for (val = 8; val <= valmax; val *= 2) + vector type{CV_32FC1, CV_32SC1}; + for (size_t i = 0; i < type.size(); ++i) { - int n = 100; - Mat mat_src(val, val, type, Scalar{-2}); - Mat mat_dest(val, val, type, Scalar{-4}); - Mat mat_dest1(val, val, type, Scalar{-6}); + test.PrintLog("Perf test : Function: Abs()", type[i]); + for (val = 8; val <= valmax; val *= 2) + { + int n = 100; + Mat mat_src(val, val, type[i], Scalar{-2}); + Mat mat_dest(val, val, type[i], Scalar{-4}); + Mat mat_dest1(val, val, type[i], Scalar{-6}); - aclMat aclmat_src(val, val, type, mat_src.data, acl_context); - aclMat aclmat_dest(val, val, type, mat_dest.data, acl_context); + aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context); + aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context); - begin = static_cast(getTickCount()); - while (n--) - mat_dest = abs(mat_src); - end = static_cast(getTickCount()); - time = (end - begin) / getTickFrequency(); + begin = static_cast(getTickCount()); + while (n--) + mat_dest = abs(mat_src); + end = static_cast(getTickCount()); + time = (end - begin) / getTickFrequency(); - n = 100; - begin = static_cast(getTickCount()); - while (n--) - aclmat_dest = abs(aclmat_src); - end = static_cast(getTickCount()); - acltime = (end - begin) / getTickFrequency(); + n = 100; + begin = static_cast(getTickCount()); + while (n--) + aclmat_dest = abs(aclmat_src); + end = static_cast(getTickCount()); + acltime = (end - begin) / getTickFrequency(); - aclmat_dest.download(mat_dest1); - bool ret = test.Test_Diff(mat_dest, mat_dest1); - ASSERT_TRUE(ret); - if (val < 128) - cout << "Shape: " << val << " x " << val << "\t\t"; - else - cout << "Shape: " << val << " x " << val << "\t"; - cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl; + aclmat_dest.download(mat_dest1); + bool ret = test.Test_Diff(mat_dest, mat_dest1); + ASSERT_TRUE(ret); + if (val < 128) + cout << "Shape: " << val << " x " << val << "\t\t"; + else + cout << "Shape: " << val << " x " << val << "\t"; + cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl; + } } } void PERF_TEST::Test_Pow(aclCxt *acl_context) { - int val, type; + int val; int valmax = 8192; double begin, end, time, acltime; Common_Test test; - type = CV_32FC1; - - for (val = 8; val <= valmax; val *= 2) + vector type{CV_32FC1}; + for (size_t i = 0; i < type.size(); ++i) { - int n = 100; - int power = test.RandDom_(6); - Mat mat_src(val, val, type); - Mat mat_dest(val, val, type); - Mat mat_dest1(val, val, type); + test.PrintLog("Perf test : Function: Pow()", type[i]); + for (val = 8; val <= valmax; val *= 2) + { + int n = 100; + int power = test.RandDom_(6); + Mat mat_src(val, val, type[i]); + Mat mat_dest(val, val, type[i]); + Mat mat_dest1(val, val, type[i]); - test.SetDataRange(mat_src, 32); - test.SetDataRange(mat_dest, 32); + test.SetDataRange(mat_src, 32); - aclMat aclmat_src(val, val, type, mat_src.data, acl_context); - aclMat aclmat_dest(val, val, type, mat_dest.data, acl_context); + aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context); + aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context); - begin = static_cast(getTickCount()); - while (n--) - pow(mat_src, power, mat_dest); - end = static_cast(getTickCount()); - time = (end - begin) / getTickFrequency(); + begin = static_cast(getTickCount()); + while (n--) + pow(mat_src, power, mat_dest); + end = static_cast(getTickCount()); + time = (end - begin) / getTickFrequency(); - n = 100; - begin = static_cast(getTickCount()); - while (n--) - pow(aclmat_src, power, aclmat_dest); - end = static_cast(getTickCount()); - acltime = (end - begin) / getTickFrequency(); + n = 100; + begin = static_cast(getTickCount()); + while (n--) + pow(aclmat_src, power, aclmat_dest); + end = static_cast(getTickCount()); + acltime = (end - begin) / getTickFrequency(); - aclmat_dest.download(mat_dest1); - if (val < 128) - cout << "Shape: " << val << " x " << val << "\t\t"; - else - cout << "Shape: " << val << " x " << val << "\t"; - cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl; + aclmat_dest.download(mat_dest1); + if (val < 128) + cout << "Shape: " << val << " x " << val << "\t\t"; + else + cout << "Shape: " << val << " x " << val << "\t"; + cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl; + } } } @@ -200,7 +205,7 @@ void PERF_TEST::Test_Divide(aclCxt *acl_context) Mat mat_dest1(val, val, type); test.SetDataRange(mat_src1, 32); - test.SetDataRange(mat_src2, 2); + test.SetDataRange(mat_src2, 4); test.SetDataRange(mat_dest, 32); aclMat aclmat_src1(val, val, type, mat_src1.data, acl_context); diff --git a/acl/test/test_matrices.cpp b/acl/test/test_matrices.cpp index 58a190e..c4b416a 100644 --- a/acl/test/test_matrices.cpp +++ b/acl/test/test_matrices.cpp @@ -143,7 +143,7 @@ void PERF_TEST::Test_Transpose(aclCxt *acl_context) void PERF_TEST::Test_Split(aclCxt *acl_context) { int val; - int valmax = 8; + int valmax = 8192; double begin, end, time, acltime; Common_Test test; @@ -155,7 +155,7 @@ void PERF_TEST::Test_Split(aclCxt *acl_context) test.PrintLog("Perf test : Function: split()", srcType[i]); for (val = 8; val <= valmax; val *= 2) { - int n = 1; + int n = 100; Mat mat_src(val, val, srcType[i]); Mat mat_dest1(val, val, destType[i]); Mat mat_dest2(val, val, destType[i]); @@ -164,9 +164,9 @@ void PERF_TEST::Test_Split(aclCxt *acl_context) test.SetDataRange(mat_src, 32); aclMat aclmat_src(val, val, srcType[i], mat_src.data, acl_context); - aclMat aclmat_dest1(val, val, destType[i], mat_dest1.data, acl_context); - aclMat aclmat_dest2(val, val, destType[i], mat_dest2.data, acl_context); - aclMat aclmat_dest3(val, val, destType[i], mat_dest3.data, acl_context); + aclMat aclmat_dest1; + aclMat aclmat_dest2; + aclMat aclmat_dest3; vector dest; dest.emplace_back(mat_dest1); @@ -184,7 +184,7 @@ void PERF_TEST::Test_Split(aclCxt *acl_context) end = static_cast(getTickCount()); time = (end - begin) / getTickFrequency(); - n = 1; + n = 100; begin = static_cast(getTickCount()); while (n--) split(aclmat_src, acl_dest); @@ -204,6 +204,7 @@ void PERF_TEST::Test_Split(aclCxt *acl_context) else cout << "Shape: " << val << " x " << val << "\t"; cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl; + } }