1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #20119 from TolyaTalamanov:at/compile-arg-for-queue-capacity

* Support queue capacity as graph compilation argument

* Fix comments to review

* Fix comments to review

* Fix comments to review
This commit is contained in:
Anatoliy Talamanov
2021-05-24 21:48:23 +03:00
committed by GitHub
parent 1e1ddd3279
commit b67c0e5f4a
4 changed files with 94 additions and 28 deletions
@@ -67,13 +67,24 @@ std::ostream& operator<< (std::ostream &os, const KernelPackage &e)
return os;
}
struct GAPI_Streaming: public ::testing::TestWithParam<KernelPackage> {
GAPI_Streaming() { initTestDataPath(); }
struct GAPI_Streaming: public ::testing::TestWithParam<std::tuple<KernelPackage,
cv::optional<size_t>>> {
GAPI_Streaming() {
initTestDataPath();
KernelPackage pkg_kind;
std::tie(pkg_kind, cap) = GetParam();
pkg = getKernelPackage(pkg_kind);
}
cv::gapi::GKernelPackage getKernelPackage()
const cv::optional<size_t>& getQueueCapacity()
{
return cap;
}
cv::gapi::GKernelPackage getKernelPackage(KernelPackage pkg_kind)
{
using namespace cv::gapi;
switch (GetParam())
switch (pkg_kind)
{
case KernelPackage::OCV:
return cv::gapi::combine(core::cpu::kernels(),
@@ -104,6 +115,18 @@ struct GAPI_Streaming: public ::testing::TestWithParam<KernelPackage> {
}
throw std::logic_error("Unknown package");
}
cv::GCompileArgs getCompileArgs() {
using namespace cv::gapi;
auto args = cv::compile_args(use_only{pkg});
if (cap) {
args += cv::compile_args(streaming::queue_capacity{cap.value()});
}
return args;
}
cv::gapi::GKernelPackage pkg;
cv::optional<size_t> cap;
};
G_API_OP(Delay, <cv::GMat(cv::GMat, int)>, "org.opencv.test.delay") {
@@ -260,8 +283,7 @@ TEST_P(GAPI_Streaming, SmokeTest_ConstInput_GMat)
}
// Compilation & testing
auto ccomp = c.compileStreaming(cv::descr_of(in_mat),
cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
auto ccomp = c.compileStreaming(cv::descr_of(in_mat), getCompileArgs());
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
@@ -306,7 +328,7 @@ TEST_P(GAPI_Streaming, SmokeTest_VideoInput_GMat)
// Compilation & testing
auto ccomp = c.compileStreaming(cv::GMatDesc{CV_8U,3,cv::Size{768,576}},
cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
getCompileArgs());
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
@@ -356,7 +378,7 @@ TEST_P(GAPI_Streaming, Regression_CompileTimeScalar)
cv::GComputation c(cv::GIn(in), cv::GOut(tmp, tmp + 1));
auto ccomp = c.compileStreaming(cv::GMatDesc{CV_8U,3,cv::Size{768,512}},
cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
getCompileArgs());
cv::Mat in_mat = cv::imread(findDataFile("cv/edgefilter/kodim23.png"));
cv::Mat out_mat1, out_mat2;
@@ -379,7 +401,7 @@ TEST_P(GAPI_Streaming, SmokeTest_StartRestart)
cv::GComputation c(cv::GIn(in), cv::GOut(cv::gapi::copy(in), out));
auto ccomp = c.compileStreaming(cv::GMatDesc{CV_8U,3,cv::Size{768,576}},
cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
getCompileArgs());
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
@@ -424,8 +446,7 @@ TEST_P(GAPI_Streaming, SmokeTest_VideoConstSource_NoHang)
auto refc = cv::GComputation([](){
cv::GMat in;
return cv::GComputation(in, cv::gapi::copy(in));
}).compileStreaming(cv::GMatDesc{CV_8U,3,cv::Size{768,576}},
cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
}).compileStreaming(cv::GMatDesc{CV_8U,3,cv::Size{768,576}}, getCompileArgs());
auto path = findDataFile("cv/video/768x576.avi");
try {
@@ -447,7 +468,7 @@ TEST_P(GAPI_Streaming, SmokeTest_VideoConstSource_NoHang)
auto testc = cv::GComputation(cv::GIn(in, in2), cv::GOut(out))
.compileStreaming(cv::GMatDesc{CV_8U,3,cv::Size{256,256}},
cv::GMatDesc{CV_8U,3,cv::Size{768,576}},
cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
getCompileArgs());
cv::Mat in_const = cv::Mat::eye(cv::Size(256,256), CV_8UC3);
testc.setSource(cv::gin(in_const,
@@ -468,7 +489,7 @@ TEST_P(GAPI_Streaming, SmokeTest_AutoMeta)
cv::GMat out = blr - in;
auto testc = cv::GComputation(cv::GIn(in, in2), cv::GOut(out))
.compileStreaming(cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
.compileStreaming(getCompileArgs());
cv::Mat in_const = cv::Mat::eye(cv::Size(256,256), CV_8UC3);
cv::Mat tmp;
@@ -510,7 +531,7 @@ TEST_P(GAPI_Streaming, SmokeTest_AutoMeta_2xConstMat)
cv::GMat out = blr - in;
auto testc = cv::GComputation(cv::GIn(in, in2), cv::GOut(out))
.compileStreaming(cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
.compileStreaming(getCompileArgs());
cv::Mat in_const = cv::Mat::eye(cv::Size(256,256), CV_8UC3);
cv::Mat tmp;
@@ -541,7 +562,7 @@ TEST_P(GAPI_Streaming, SmokeTest_AutoMeta_VideoScalar)
cv::GMat out_m = in_m * in_s;
auto testc = cv::GComputation(cv::GIn(in_m, in_s), cv::GOut(out_m))
.compileStreaming(cv::compile_args(cv::gapi::use_only{getKernelPackage()}));
.compileStreaming(getCompileArgs());
cv::Mat tmp;
// Test with one video source and scalar
@@ -572,11 +593,13 @@ TEST_P(GAPI_Streaming, SmokeTest_AutoMeta_VideoScalar)
}
INSTANTIATE_TEST_CASE_P(TestStreaming, GAPI_Streaming,
Values( KernelPackage::OCV
//, KernelPackage::OCL // FIXME: Fails bit-exactness check, maybe relax it?
, KernelPackage::OCV_FLUID
//, KernelPackage::OCL // FIXME: Fails bit-exactness check, maybe relax it?
));
Combine(Values( KernelPackage::OCV
//, KernelPackage::OCL // FIXME: Fails bit-exactness check, maybe relax it?
, KernelPackage::OCV_FLUID
//, KernelPackage::OCL // FIXME: Fails bit-exactness check, maybe relax it?
),
Values(cv::optional<size_t>{}, 1u, 4u))
);
namespace TypesTest
{
@@ -653,8 +676,15 @@ TEST_P(GAPI_Streaming, SmokeTest_AutoMeta_VideoArray)
cv::GMat out_m = TypesTest::AddV::on(in_m, in_v) - in_m;
// Run pipeline
auto args = cv::compile_args(cv::gapi::kernels<TypesTest::OCVAddV>());
auto capacity = getQueueCapacity();
if (capacity)
{
args += cv::compile_args(
cv::gapi::streaming::queue_capacity{capacity.value()});
}
auto testc = cv::GComputation(cv::GIn(in_m, in_v), cv::GOut(out_m))
.compileStreaming(cv::compile_args(cv::gapi::kernels<TypesTest::OCVAddV>()));
.compileStreaming(std::move(args));
cv::Mat tmp;
// Test with one video source and vector