Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions modules/gapi/perf/streaming/gapi_streaming_source_perf_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation


#include "../perf_precomp.hpp"
#include "../../test/common/gapi_tests_common.hpp"
#include <opencv2/gapi/streaming/onevpl/onevpl_source.hpp>
#include <opencv2/gapi/streaming/cap.hpp>

namespace opencv_test
{
using namespace perf;

const std::string files[] = {
"highgui/video/big_buck_bunny.h265",
"highgui/video/big_buck_bunny.h264",
};

const std::string codec[] = {
"MFX_CODEC_HEVC",
"MFX_CODEC_AVC"
};

using source_t = std::string;
using codec_t = std::string;
using source_description_t = std::tuple<source_t, codec_t>;

class OneVPLSourcePerfTest : public TestPerfParams<source_description_t> {};
class VideoCapSourcePerfTest : public TestPerfParams<source_t> {};

PERF_TEST_P_(OneVPLSourcePerfTest, TestPerformance)
{
using namespace cv::gapi::wip;

const auto params = GetParam();
source_t src = findDataFile(get<0>(params));
codec_t type = get<1>(params);

std::vector<oneVPL_cfg_param> cfg_params {
oneVPL_cfg_param::create<std::string>("mfxImplDescription.Impl", "MFX_IMPL_TYPE_HARDWARE"),
oneVPL_cfg_param::create("mfxImplDescription.mfxDecoderDescription.decoder.CodecID", type),
};

auto source_ptr = make_vpl_src(src, cfg_params);
Data out;
TEST_CYCLE()
{
source_ptr->pull(out);
}

SANITY_CHECK_NOTHING();
}

PERF_TEST_P_(VideoCapSourcePerfTest, TestPerformance)
{
using namespace cv::gapi::wip;

source_t src = findDataFile(GetParam());
auto source_ptr = make_src<GCaptureSource>(src);
Data out;
TEST_CYCLE()
{
source_ptr->pull(out);
}

SANITY_CHECK_NOTHING();
}

INSTANTIATE_TEST_CASE_P(Streaming, OneVPLSourcePerfTest,
Values(source_description_t(files[0], codec[0]),
source_description_t(files[1], codec[1])));

INSTANTIATE_TEST_CASE_P(Streaming, VideoCapSourcePerfTest,
Values(files[0],
files[1]));
} // namespace opencv_test
8 changes: 8 additions & 0 deletions modules/gapi/samples/infer_single_roi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,17 @@ int main(int argc, char *argv[])
pipeline.start();

cv::Mat out;
int framesCount = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did these changes get here?

cv::TickMeter t;
t.start();
while (pipeline.pull(cv::gout(out))) {
cv::imshow("Out", out);
cv::waitKey(1);
framesCount++;
}
t.stop();
std::cout << "Elapsed time: " << t.getTimeSec() << std::endl;
std::cout << "FPS: " << framesCount / t.getTimeSec() << std::endl;
std::cout << "framesCount: " << framesCount << std::endl;
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ VPLCPUAccelerationPolicy::create_surface_pool(size_t pool_size, size_t surface_s

// remember pool by key
GAPI_LOG_INFO(nullptr, "New pool allocated, key: " << preallocated_pool_memory_ptr <<
", surface count: " << pool.size() <<
", surface count: " << pool.total_size() <<
", surface size bytes: " << surface_size_bytes);
try {
if (!pool_table.emplace(preallocated_pool_memory_ptr, std::move(pool)).second) {
Expand All @@ -132,27 +132,7 @@ VPLCPUAccelerationPolicy::surface_weak_ptr_t VPLCPUAccelerationPolicy::get_free_
}

pool_t& requested_pool = pool_it->second;
#ifdef TEST_PERF

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this macro is completely gone now?

return requested_pool.find_free();
#else // TEST_PERF
auto it =
std::find_if(requested_pool.begin(), requested_pool.end(),
[](const surface_ptr_t& val) {
GAPI_DbgAssert(val && "Pool contains empty surface");
return !val->get_locks_count();
});

// Limitation realloc pool might be a future extension
if (it == requested_pool.end()) {
std::stringstream ss;
ss << "cannot get free surface from pool, key: " << key << ", size: " << requested_pool.size();
const std::string& str = ss.str();
GAPI_LOG_WARNING(nullptr, str);
throw std::runtime_error(std::string(__FUNCTION__) + " - " + str);
}

return *it;
#endif // TEST_PERF
}

size_t VPLCPUAccelerationPolicy::get_free_surface_count(pool_key_t key) const {
Expand All @@ -162,18 +142,8 @@ size_t VPLCPUAccelerationPolicy::get_free_surface_count(pool_key_t key) const {
", table size: " << pool_table.size());
return 0;
}
#ifdef TEST_PERF
return 0;
#else // TEST_PERF
const pool_t& requested_pool = pool_it->second;
size_t free_surf_count =
std::count_if(requested_pool.begin(), requested_pool.end(),
[](const surface_ptr_t& val) {
GAPI_Assert(val && "Pool contains empty surface");
return !val->get_locks_count();
});
return free_surf_count;
#endif // TEST_PERF
return requested_pool.available_size();
}

size_t VPLCPUAccelerationPolicy::get_surface_count(pool_key_t key) const {
Expand All @@ -183,11 +153,8 @@ size_t VPLCPUAccelerationPolicy::get_surface_count(pool_key_t key) const {
", table size: " << pool_table.size());
return 0;
}
#ifdef TEST_PERF
return 0;
#else // TEST_PERF
return pool_it->second.size();
#endif // TEST_PERF

return pool_it->second.total_size();
}

cv::MediaFrame::AdapterPtr VPLCPUAccelerationPolicy::create_frame_adapter(pool_key_t key,
Expand All @@ -202,28 +169,7 @@ cv::MediaFrame::AdapterPtr VPLCPUAccelerationPolicy::create_frame_adapter(pool_k
}

pool_t& requested_pool = pool_it->second;
#ifdef TEST_PERF
return cv::MediaFrame::AdapterPtr{new VPLMediaFrameCPUAdapter(requested_pool.find_by_handle(surface))};
#else // TEST_PERF
auto it =
std::find_if(requested_pool.begin(), requested_pool.end(),
[surface](const surface_ptr_t& val) {
GAPI_DbgAssert(val && "Pool contains empty surface");
return val->get_handle() == surface;
});

// Limitation realloc pool might be a future extension
if (it == requested_pool.end()) {
std::stringstream ss;
ss << "cannot get requested surface from pool, key: " << key << ", surf: "
<< surface << ", pool size: " << requested_pool.size();
const std::string& str = ss.str();
GAPI_LOG_WARNING(nullptr, str);
throw std::runtime_error(std::string(__FUNCTION__) + " - " + str);
}

return cv::MediaFrame::AdapterPtr{new VPLMediaFrameCPUAdapter(*it)};
#endif // TEST_PERF
}
} // namespace wip
} // namespace gapi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
#ifdef HAVE_ONEVPL
#include <vpl/mfxvideo.h>
#include "streaming/onevpl/accelerators/accel_policy_interface.hpp"
#ifdef TEST_PERF
#include "streaming/onevpl/accelerators/surface/surface_pool.hpp"
#endif // TEST_PERF

namespace cv {
namespace gapi {
Expand All @@ -28,11 +26,8 @@ struct VPLCPUAccelerationPolicy final : public VPLAccelerationPolicy
// GAPI_EXPORTS for tests
GAPI_EXPORTS VPLCPUAccelerationPolicy();
GAPI_EXPORTS ~VPLCPUAccelerationPolicy();
#ifdef TEST_PERF

using pool_t = CachedPool;
#else // TEST_PERF
using pool_t = std::vector<surface_ptr_t>;
#endif // TEST_PERF

GAPI_EXPORTS void init(session_t session) override;
GAPI_EXPORTS void deinit(session_t session) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void CachedPool::reserve(size_t size) {
surfaces.reserve(size);
}

size_t CachedPool::size() const {
size_t CachedPool::total_size() const {
return surfaces.size();
}

Expand All @@ -26,6 +26,17 @@ void CachedPool::push_back(surface_ptr_t &&surf) {
next_free_it = surfaces.begin();
}

size_t CachedPool::available_size() const {

size_t free_surf_count =
std::count_if(surfaces.begin(), surfaces.end(),
[](const surface_ptr_t& val) {
GAPI_DbgAssert(val && "Pool contains empty surface");
return !val->get_locks_count();
});
return free_surf_count;
}

CachedPool::surface_ptr_t CachedPool::find_free() {

auto it =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class CachedPool {
// GAPI_EXPORTS for tests
GAPI_EXPORTS void push_back(surface_ptr_t &&surf);
GAPI_EXPORTS void reserve(size_t size);
GAPI_EXPORTS size_t size() const;
GAPI_EXPORTS size_t total_size() const;
GAPI_EXPORTS size_t available_size() const;
GAPI_EXPORTS void clear();

GAPI_EXPORTS surface_ptr_t find_free();
GAPI_EXPORTS surface_ptr_t find_by_handle(mfxFrameSurface1* handle);
private:
Expand Down
Loading