This commit is contained in:
luoliang
2022-10-10 20:52:08 +08:00
parent e47e5f027b
commit 43c8362af7
13 changed files with 134 additions and 138 deletions

View File

@@ -174,7 +174,7 @@ aclMat &aclMat::operator*=(const aclMat &m) {
vector<aclMat> output_Mat; vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_; vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_; vector<aclDataBuffer *> outputBuffers_;
aclMat newMat{this->rows, m.cols, this->type(), this->acl_context}; aclMat newMat {this->rows, m.cols, this->type(), this->acl_context};
input_Mat.emplace_back(*this); input_Mat.emplace_back(*this);
input_Mat.emplace_back(m); input_Mat.emplace_back(m);

View File

@@ -53,7 +53,7 @@ void Convolution(const aclMat& src, const aclMat& kernel, aclMat& dest,
const vector<int64_t>& padsList, int stream_id) { const vector<int64_t>& padsList, int stream_id) {
vector<aclDataBuffer*> inputBuffers_; vector<aclDataBuffer*> inputBuffers_;
vector<aclDataBuffer*> outputBuffers_; vector<aclDataBuffer*> outputBuffers_;
vector<int64_t> dilationsList{1, 1, 1, 1}; vector<int64_t> dilationsList {1, 1, 1, 1};
string opType = "Conv2D"; string opType = "Conv2D";
int dest_rows = int dest_rows =
(src.rows + padsList[0] + padsList[1] - (1 * (kernel.rows - 1) + 1)) / (src.rows + padsList[0] + padsList[1] - (1 * (kernel.rows - 1) + 1)) /
@@ -65,9 +65,9 @@ void Convolution(const aclMat& src, const aclMat& kernel, aclMat& dest,
1; 1;
aclMat acl_dest {dest_rows, dest_cols, src.type(), src.acl_context}; aclMat acl_dest {dest_rows, dest_cols, src.type(), src.acl_context};
vector<int64_t> shape{1, 1, src.rows, src.cols}; vector<int64_t> shape {1, 1, src.rows, src.cols};
vector<int64_t> shape1{1, 1, kernel.rows, kernel.cols}; vector<int64_t> shape1 {1, 1, kernel.rows, kernel.cols};
vector<int64_t> shape2{1, 1, acl_dest.rows, acl_dest.cols}; vector<int64_t> shape2 {1, 1, acl_dest.rows, acl_dest.cols};
aclDataType dataType = type_transition(src.depth()); aclDataType dataType = type_transition(src.depth());
aclFormat format = ACL_FORMAT_NCHW; aclFormat format = ACL_FORMAT_NCHW;

View File

@@ -105,15 +105,15 @@ void transpose(const aclMat &src, aclMat &dest, int stream_id) {
OperatorDesc opDesc("Transpose"); OperatorDesc opDesc("Transpose");
aclDataType dataType = type_transition(src.depth()); aclDataType dataType = type_transition(src.depth());
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()}; vector<int64_t> inputShape1 {1, src.rows, src.cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
vector<int64_t> inputShape2{4}; vector<int64_t> inputShape2 {4};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(), opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
vector<int64_t> outputShape{-1, -1, -1, -1}; vector<int64_t> outputShape {-1, -1, -1, -1};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
@@ -198,12 +198,12 @@ void split(const aclMat &src, vector<aclMat> &mv, int stream_id) {
aclDataType dataType = type_transition(src.depth()); aclDataType dataType = type_transition(src.depth());
int cols = src.step / src.elemSize(); int cols = src.step / src.elemSize();
vector<int64_t> inputShape1{1, src.rows, cols, src.channels()}; vector<int64_t> inputShape1 {1, src.rows, cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
for (int i = 0; i < num_split; ++i) { for (int i = 0; i < num_split; ++i) {
vector<int64_t> outputShape{1, src.rows, cols, 1}; vector<int64_t> outputShape {1, src.rows, cols, 1};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
} }
@@ -239,15 +239,15 @@ static void flip_(const aclMat &src, aclMat &dest, int axis, int stream_id) {
OperatorDesc opDesc("ReverseV2"); OperatorDesc opDesc("ReverseV2");
aclDataType dataType = type_transition(src.depth()); aclDataType dataType = type_transition(src.depth());
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()}; vector<int64_t> inputShape1 {1, src.rows, src.cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
vector<int64_t> inputShape2{1}; vector<int64_t> inputShape2 {1};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(), opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);
vector<int64_t> outputShape{1, dest.rows, dest.cols, dest.channels()}; vector<int64_t> outputShape {1, dest.rows, dest.cols, dest.channels()};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_ND); ACL_FORMAT_ND);

View File

@@ -67,11 +67,11 @@ OperatorDesc CreateOpDesc(const string opType, const vector<aclMat>& input_Mat,
for (i = 0; i < input_Mat.size(); ++i) { for (i = 0; i < input_Mat.size(); ++i) {
if (config == TWO_DIMS) { if (config == TWO_DIMS) {
int cols = input_Mat[i].step / input_Mat[i].elemSize(); int cols = input_Mat[i].step / input_Mat[i].elemSize();
vector<int64_t> shape{input_Mat[i].rows, cols}; vector<int64_t> shape {input_Mat[i].rows, cols};
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format); opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
} else if (config == FOUR_DIMS) { } else if (config == FOUR_DIMS) {
int cols = input_Mat[i].step / input_Mat[i].elemSize(); int cols = input_Mat[i].step / input_Mat[i].elemSize();
vector<int64_t> shape{1, input_Mat[i].rows, cols, vector<int64_t> shape {1, input_Mat[i].rows, cols,
input_Mat[i].channels()}; input_Mat[i].channels()};
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format); opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
} }
@@ -80,11 +80,11 @@ OperatorDesc CreateOpDesc(const string opType, const vector<aclMat>& input_Mat,
for (i = 0; i < output_Mat.size(); ++i) { for (i = 0; i < output_Mat.size(); ++i) {
if (config == TWO_DIMS) { if (config == TWO_DIMS) {
int cols = output_Mat[i].step / output_Mat[i].elemSize(); int cols = output_Mat[i].step / output_Mat[i].elemSize();
vector<int64_t> shape{output_Mat[i].rows, cols}; vector<int64_t> shape {output_Mat[i].rows, cols};
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format); opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
} else if (config == FOUR_DIMS) { } else if (config == FOUR_DIMS) {
int cols = output_Mat[i].step / output_Mat[i].elemSize(); int cols = output_Mat[i].step / output_Mat[i].elemSize();
vector<int64_t> shape{1, output_Mat[i].rows, cols, vector<int64_t> shape {1, output_Mat[i].rows, cols,
output_Mat[i].channels()}; output_Mat[i].channels()};
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format); opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
} }

View File

@@ -18,7 +18,7 @@ void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context) {
constexpr int rand_data_range = 1; constexpr int rand_data_range = 1;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: operator+=()", type[i]); test.PrintLog("Perf test : Function: operator+=()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -72,7 +72,7 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context) {
constexpr int rand_data_range2 = 32; constexpr int rand_data_range2 = 32;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: operator-=()", type[i]); test.PrintLog("Perf test : Function: operator-=()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -124,7 +124,7 @@ void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context) {
constexpr int s_val4 = 4, s_val8 = 8; constexpr int s_val4 = 4, s_val8 = 8;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: operator/=()", type[i]); test.PrintLog("Perf test : Function: operator/=()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -172,7 +172,7 @@ void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context) {
constexpr int rand_data_range = 1; constexpr int rand_data_range = 1;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_32FC1}; vector<int> type {CV_32FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;

View File

@@ -3,10 +3,10 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
typedef enum TestDatatype { INT = 1, FLOAT } TestDatatype; using TestDatatype = enum TestDatatype { INT = 1, FLOAT };
class CV_EXPORTS Common_Test { class CV_EXPORTS Common_Test {
public: public:
Common_Test(); Common_Test();
~Common_Test(); ~Common_Test();
CV_EXPORTS bool Test_Diff( CV_EXPORTS bool Test_Diff(

View File

@@ -43,7 +43,7 @@
// arising in any way out of the use of this software, even if advised of the // arising in any way out of the use of this software, even if advised of the
// possibility of such damage. // possibility of such damage.
// //
// M*/ // M */
#include "test_correctness.hpp" #include "test_correctness.hpp"

View File

@@ -27,7 +27,7 @@ class CV_EXPORTS AclMat_Test {
/* test aclMat (const Mat &m, cv::acl::aclCxt* acl_context, aclrtMemMallocPolicy policy /* test aclMat (const Mat &m, cv::acl::aclCxt* acl_context, aclrtMemMallocPolicy policy
* = ACL_MEM_MALLOC_HUGE_FIRST) */ * = ACL_MEM_MALLOC_HUGE_FIRST) */
CV_EXPORTS void Test_constructor_MAT(cv::acl::aclCxt *acl_context); CV_EXPORTS void Test_constructor_MAT(cv::acl::aclCxt *acl_context);
/* test upload download*/ /* test upload download */
CV_EXPORTS void Test_DATA_TRANSFER(cv::acl::aclCxt *acl_context); CV_EXPORTS void Test_DATA_TRANSFER(cv::acl::aclCxt *acl_context);
/* test upload_2d download_2d */ /* test upload_2d download_2d */
CV_EXPORTS void Test_DATA_TRANSFERASYNC(cv::acl::aclCxt *acl_context); CV_EXPORTS void Test_DATA_TRANSFERASYNC(cv::acl::aclCxt *acl_context);

View File

@@ -13,7 +13,7 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context) {
int cycle_index = 10; // 100; int cycle_index = 10; // 100;
double begin, end, time, acltime; double begin, end, time, acltime;
Common_Test test; Common_Test test;
vector<int> type{CV_32FC1}; vector<int> type {CV_32FC1};
constexpr int base = 2; constexpr int base = 2;
constexpr int start_val = 8; constexpr int start_val = 8;
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
@@ -68,7 +68,7 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context) {
int cycle_index = 10; int cycle_index = 10;
double begin, end, time, acltime; double begin, end, time, acltime;
Common_Test test; Common_Test test;
vector<int> type{CV_32FC1}; vector<int> type {CV_32FC1};
constexpr int base = 2; constexpr int base = 2;
constexpr int start_val = 8; constexpr int start_val = 8;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
@@ -78,9 +78,9 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context) {
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
Mat mat_src(val, val, type[i], Scalar{s_val1, s_val2}); Mat mat_src(val, val, type[i], Scalar {s_val1, s_val2});
Mat mat_kernel(kernel_val, kernel_val, type[i], Scalar(s_val1, s_val4)); Mat mat_kernel(kernel_val, kernel_val, type[i], Scalar (s_val1, s_val4));
Mat mat_dest(val, val, type[i], Scalar{s_val6}); Mat mat_dest(val, val, type[i], Scalar {s_val6});
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context); aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_kernel(kernel_val, kernel_val, type[i], mat_kernel.data, acl_context); aclMat aclmat_kernel(kernel_val, kernel_val, type[i], mat_kernel.data, acl_context);
@@ -92,8 +92,8 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context) {
end = static_cast<double>(getTickCount()); end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index; time = (end - begin) / getTickFrequency() / cycle_index;
vector<int64_t> strides{1, 1, 1, 1}; vector<int64_t> strides {1, 1, 1, 1};
vector<int64_t> pads{1, 1, 1, 1}; vector<int64_t> pads {1, 1, 1, 1};
n = (cycle_index - 1); n = (cycle_index - 1);
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 0); Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 0);
wait_stream(acl_context, 0); wait_stream(acl_context, 0);

View File

@@ -18,14 +18,14 @@ void PERF_TEST::Test_Abs(aclCxt *acl_context) {
constexpr int start_val = 8; constexpr int start_val = 8;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_32FC1, CV_32SC1}; vector<int> type {CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: Abs()", type[i]); test.PrintLog("Perf test : Function: Abs()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
Mat mat_src(val, val, type[i], Scalar{s_val_2}); Mat mat_src(val, val, type[i], Scalar {s_val_2});
Mat mat_dest(val, val, type[i], Scalar{s_val_4}); Mat mat_dest(val, val, type[i], Scalar {s_val_4});
Mat mat_dest1(val, val, type[i], Scalar{s_val_6}); Mat mat_dest1(val, val, type[i], Scalar {s_val_6});
aclMat aclmat_src(val, val, type[i], mat_src.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); aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
@@ -68,7 +68,7 @@ void PERF_TEST::Test_Pow(aclCxt *acl_context) {
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: Pow()", type[i]); test.PrintLog("Perf test : Function: Pow()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -119,7 +119,7 @@ void PERF_TEST::Test_Sqrt(aclCxt *acl_context) {
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
vector<int> type{CV_32FC1, CV_64FC1}; vector<int> type {CV_32FC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
@@ -169,7 +169,7 @@ void PERF_TEST::Test_Add(aclCxt *acl_context) {
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
@@ -225,7 +225,7 @@ void PERF_TEST::Test_Divide(aclCxt *acl_context) {
constexpr int rand_data_range1 = 32; constexpr int rand_data_range1 = 32;
constexpr int rand_data_range2 = 4; constexpr int rand_data_range2 = 4;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
@@ -279,7 +279,7 @@ void PERF_TEST::Test_Exp(aclCxt *acl_context) {
constexpr int rand_data_range1 = 32; constexpr int rand_data_range1 = 32;
constexpr int rand_data_range2 = 2; constexpr int rand_data_range2 = 2;
vector<int> type{CV_32FC1, CV_64FC1}; vector<int> type {CV_32FC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
@@ -329,7 +329,7 @@ void PERF_TEST::Test_Log(aclCxt *acl_context) {
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
vector<int> type{CV_32FC1, CV_64FC1}; vector<int> type {CV_32FC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
@@ -379,7 +379,7 @@ void PERF_TEST::Test_Max(aclCxt *acl_context) {
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
vector<int> type{CV_32FC2, CV_32SC2, CV_64FC2}; vector<int> type {CV_32FC2, CV_32SC2, CV_64FC2};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;
@@ -434,7 +434,7 @@ void PERF_TEST::Test_Min(aclCxt *acl_context) {
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
vector<int> type{CV_32FC3, CV_32SC3, CV_64FC3}; vector<int> type {CV_32FC3, CV_32SC3, CV_64FC3};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
n = cycle_index; n = cycle_index;

View File

@@ -19,9 +19,9 @@ void PERF_TEST::Test_Merge(aclCxt *acl_context) {
constexpr int s_val1 = 1, s_val2 = 2, s_val3 = 3; constexpr int s_val1 = 1, s_val2 = 2, s_val3 = 3;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> srcType{CV_8UC1, CV_32FC1, CV_32SC1}; vector<int> srcType {CV_8UC1, CV_32FC1, CV_32SC1};
vector<int> destType{CV_8UC3, CV_32FC3, CV_32SC3}; vector<int> destType {CV_8UC3, CV_32FC3, CV_32SC3};
for (size_t i = 0; i < srcType.size(); ++i) { for (size_t i = 0; i < srcType.size(); ++i) {
test.PrintLog("Perf test : Function: merge()", srcType[i]); test.PrintLog("Perf test : Function: merge()", srcType[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -88,7 +88,7 @@ void PERF_TEST::Test_Transpose(aclCxt *acl_context) {
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_32FC1, CV_32SC1}; vector<int> type {CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: transpose()", type[i]); test.PrintLog("Perf test : Function: transpose()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -141,8 +141,8 @@ void PERF_TEST::Test_Split(aclCxt *acl_context) {
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
constexpr int index0 = 0, index1 = 1, index2 = 2; constexpr int index0 = 0, index1 = 1, index2 = 2;
vector<int> srcType{CV_8UC3, CV_32FC3, CV_32SC3}; vector<int> srcType {CV_8UC3, CV_32FC3, CV_32SC3};
vector<int> destType{CV_8UC1, CV_32FC1, CV_32SC1}; vector<int> destType {CV_8UC1, CV_32FC1, CV_32SC1};
for (size_t i = 0; i < srcType.size(); ++i) { for (size_t i = 0; i < srcType.size(); ++i) {
test.PrintLog("Perf test : Function: split()", srcType[i]); test.PrintLog("Perf test : Function: split()", srcType[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {
@@ -212,7 +212,7 @@ void PERF_TEST::Test_Flip(aclCxt *acl_context) {
constexpr int rand_data_range = 32; constexpr int rand_data_range = 32;
constexpr int min_format_flag = 128; constexpr int min_format_flag = 128;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1}; vector<int> type {CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) { for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: flip()", type[i]); test.PrintLog("Perf test : Function: flip()", type[i]);
for (val = start_val; val <= valmax; val *= base) { for (val = start_val; val <= valmax; val *= base) {

View File

@@ -4,7 +4,7 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
class PERF_TEST { class PERF_TEST {
public: public:
CV_EXPORTS void Test_operator_add_perf(cv::acl::aclCxt *acl_context); CV_EXPORTS void Test_operator_add_perf(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_operator_sub_perf(cv::acl::aclCxt *acl_context); CV_EXPORTS void Test_operator_sub_perf(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_operator_div_perf(cv::acl::aclCxt *acl_context); CV_EXPORTS void Test_operator_div_perf(cv::acl::aclCxt *acl_context);

View File

@@ -1,126 +1,122 @@
#include <iostream>
#include "acl/acl.h"
#include "opencv2/acl/acl.hpp"
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgcodecs.hpp" #include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/acl/acl.hpp"
#include "acl/acl.h"
#include <iostream>
using namespace cv; using namespace cv;
using namespace cv::acl; using namespace cv::acl;
using namespace std; using namespace std;
/** /**
* @brief A simple example of the split and merge functions,Using a different Stream * @brief A simple example of the split and merge functions, Using a different
* * Stream
*/ */
int test_func1(aclCxt *acl_context_0) { int test_func1(aclCxt *acl_context_0) {
Mat src = imread("../cat1.jpg"); Mat src = imread("../cat1.jpg");
if (src.empty()) { if (src.empty()) {
cerr << "could not image !" << endl; cerr << "could not image !" << endl;
return -1; return -1;
} }
// 上传数据到aclMat对象中 // 上传数据到aclMat对象中
aclMat acl_src(src, acl_context_0); aclMat acl_src (src, acl_context_0);
aclMat acl_dest1; aclMat acl_dest1;
aclMat acl_dest2; aclMat acl_dest2;
aclMat acl_dest3; aclMat acl_dest3;
vector<aclMat> mv; vector<aclMat> mv;
mv.emplace_back(acl_dest1); mv.emplace_back(acl_dest1);
mv.emplace_back(acl_dest2); mv.emplace_back(acl_dest2);
mv.emplace_back(acl_dest3); mv.emplace_back(acl_dest3);
imshow("src", src); imshow("src", src);
split(acl_src, mv, 0); split(acl_src, mv, 0);
wait_stream(acl_context_0, 0); wait_stream(acl_context_0, 0);
//下载aclMat数据到Mat类中 // 下载aclMat数据到Mat类中
Mat dest1 = mv.data()[0].operator cv::Mat(); Mat dest1 = mv.data()[0].operator cv::Mat();
Mat dest2 = mv.data()[1].operator cv::Mat(); Mat dest2 = mv.data()[1].operator cv::Mat();
Mat dest3 = mv.data()[2].operator cv::Mat(); Mat dest3 = mv.data()[2].operator cv::Mat();
imshow("dest1", dest1); imshow("dest1", dest1);
imshow("dest2", dest2); imshow("dest2", dest2);
imshow("dest3", dest3); imshow("dest3", dest3);
aclMat acl_imgdest; aclMat acl_imgdest;
merge(mv, acl_imgdest, 1); merge(mv, acl_imgdest, 1);
wait_stream(acl_context_0, 1); wait_stream(acl_context_0, 1);
Mat imgdest = acl_imgdest.operator cv::Mat(); Mat imgdest = acl_imgdest.operator cv::Mat();
imshow("imgdest", imgdest); imshow("imgdest", imgdest);
} }
/** /**
* @brief A demo of use a stream to synchronize multiple functions * @brief A demo of use a stream to synchronize multiple functions
*
*/ */
int test_func2(aclCxt *acl_context_0) { int test_func2(aclCxt *acl_context_0) {
Mat src = imread("../cat1.jpg"); Mat src = imread("../cat1.jpg");
if (src.empty()) { if (src.empty()) {
cerr << "src could not image !" << endl; cerr << "src could not image !" << endl;
return -1; return -1;
} }
Mat src1 = imread("../cat1.jpg"); Mat src1 = imread("../cat1.jpg");
if (src1.empty()) { if (src1.empty()) {
cerr << "src1 could not image !" << endl; cerr << "src1 could not image !" << endl;
return -1; return -1;
} }
// 待split操作数据上传数据到aclMat对象中
aclMat acl_src(src, acl_context_0);
aclMat acl_dest1;
aclMat acl_dest2;
aclMat acl_dest3;
vector<aclMat> mv;
mv.emplace_back(acl_dest1);
mv.emplace_back(acl_dest2);
mv.emplace_back(acl_dest3);
// 待split操作数据上传数据到aclMat对象中 // 待flip数据上传到aclMat对象中
aclMat acl_src(src, acl_context_0); aclMat acl_flip_src(src1, acl_context_0);
aclMat acl_dest1; aclMat acl_flip_dest(src1.rows, src1.cols, src1.type(), acl_context_0);
aclMat acl_dest2;
aclMat acl_dest3;
vector<aclMat> mv;
mv.emplace_back(acl_dest1);
mv.emplace_back(acl_dest2);
mv.emplace_back(acl_dest3);
// 待flip数据上传到aclMat对象中 imshow("src", src);
aclMat acl_flip_src(src1, acl_context_0); imshow("src1", src1);
aclMat acl_flip_dest(src1.rows, src1.cols, src1.type(), acl_context_0);
imshow("src", src); // 将函数挂载到1号stream上
imshow("src1", src1); split(acl_src, mv, 1);
flip(acl_flip_src, acl_flip_dest, 0, 1);
// 将函数挂载到1号stream // 等待1号stream中的任务执行完毕,stream内部按序执行任务
split(acl_src, mv, 1); wait_stream(acl_context_0, 1);
flip(acl_flip_src, acl_flip_dest, 0, 1);
// 等待1号stream中的任务执行完毕,stream内部按序执行任务 // 下载split操作完成的数据
wait_stream(acl_context_0, 1); Mat dest1 = mv.data()[0].operator cv::Mat();
Mat dest2 = mv.data()[1].operator cv::Mat();
Mat dest3 = mv.data()[2].operator cv::Mat();
// 下载split操作完成的数据 Mat flip_dest = acl_flip_dest.operator cv::Mat();
Mat dest1 = mv.data()[0].operator cv::Mat();
Mat dest2 = mv.data()[1].operator cv::Mat();
Mat dest3 = mv.data()[2].operator cv::Mat();
Mat flip_dest = acl_flip_dest.operator cv::Mat(); imshow("split_dest1", dest1);
imshow("split_dest2", dest2);
imshow("split_dest3", dest3);
imshow("split_dest1", dest1); imshow("flip_dest", flip_dest);
imshow("split_dest2", dest2);
imshow("split_dest3", dest3);
imshow("flip_dest", flip_dest);
} }
int main() int main() {
{ // 初始化
// 初始化 aclCxt *acl_context_0 = set_device("../acl.json", 1, 2);
aclCxt *acl_context_0 = set_device("../acl.json", 1, 2);
test_func2(acl_context_0); test_func2(acl_context_0);
// 去初始化 // 去初始化
release_device(acl_context_0); release_device (acl_context_0);
waitKey(0); waitKey(0);
return 0; return 0;
} }