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

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2023-01-09 11:08:02 +00:00
880 changed files with 83958 additions and 9368 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ cv::gapi::GBackend::Priv::compile(const ade::Graph&,
const std::vector<ade::NodeHandle> &) const
{
// ...and this method is here for the same reason!
GAPI_Assert(false);
GAPI_Error("InternalError");
return {};
}
@@ -391,7 +391,7 @@ void unbind(Mag& mag, const RcDesc &rc)
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &d) {
case MediaFormat::BGR: os << "BGR"; break;
case MediaFormat::NV12: os << "NV12"; break;
case MediaFormat::GRAY: os << "GRAY"; break;
default: GAPI_Assert(false && "Invalid media format");
default: GAPI_Error("Invalid media format");
}
os << ' ' << d.size << ']';
return os;
+1 -1
View File
@@ -313,7 +313,7 @@ std::ostream& operator<<(std::ostream& os, const cv::GMetaArg &arg)
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
return os;
+3 -3
View File
@@ -98,7 +98,7 @@ cv::GRunArgsP cv::gapi::bind(cv::GRunArgs &out_args)
outputs.emplace_back(&(cv::util::get<cv::MediaFrame>(res_obj)));
break;
default:
GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
GAPI_Error("This value type is not supported!"); // ...maybe because of STANDALONE mode.
break;
}
}
@@ -114,7 +114,7 @@ cv::GRunArg cv::gapi::bind(cv::GRunArgP &out)
{
#if !defined(GAPI_STANDALONE)
case T::index_of<cv::UMat*>() :
GAPI_Assert(false && "Please implement this!");
GAPI_Error("Please implement this!");
break;
#endif
@@ -138,7 +138,7 @@ cv::GRunArg cv::gapi::bind(cv::GRunArgP &out)
default:
// ...maybe our types were extended
GAPI_Assert(false && "This value type is UNKNOWN!");
GAPI_Error("This value type is UNKNOWN!");
break;
}
return cv::GRunArg();
@@ -37,7 +37,7 @@ cv::detail::GCompoundContext::GCompoundContext(const cv::GArgs& in_args)
// do nothing - as handled in a special way, see gcompoundkernel.hpp for details
// same applies to GMatP
break;
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
}
}
@@ -176,6 +176,13 @@ IIStream& operator>> (IIStream& is, cv::Point2f& pt) {
return is >> pt.x >> pt.y;
}
IOStream& operator<< (IOStream& os, const cv::Point3f &pt) {
return os << pt.x << pt.y << pt.z;
}
IIStream& operator>> (IIStream& is, cv::Point3f& pt) {
return is >> pt.x >> pt.y >> pt.z;
}
IOStream& operator<< (IOStream& os, const cv::Size &sz) {
return os << sz.width << sz.height;
}
@@ -283,7 +290,7 @@ IOStream& operator<< (IOStream& os, const cv::Mat &m) {
case CV_32S: write_mat_data< int32_t>(os, m); break;
case CV_32F: write_mat_data< float>(os, m); break;
case CV_64F: write_mat_data< double>(os, m); break;
default: GAPI_Assert(false && "Unsupported Mat depth");
default: GAPI_Error("Unsupported Mat depth");
}
return os;
}
@@ -299,7 +306,7 @@ IIStream& operator>> (IIStream& is, cv::Mat& m) {
case CV_32S: read_mat_data< int32_t>(is, m); break;
case CV_32F: read_mat_data< float>(is, m); break;
case CV_64F: read_mat_data< double>(is, m); break;
default: GAPI_Assert(false && "Unsupported Mat depth");
default: GAPI_Error("Unsupported Mat depth");
}
return is;
}
@@ -312,10 +319,10 @@ IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Text &t) {
}
IOStream& operator<< (IOStream&, const cv::gapi::wip::draw::FText &) {
GAPI_Assert(false && "Serialization: Unsupported << for FText");
GAPI_Error("Serialization: Unsupported << for FText");
}
IIStream& operator>> (IIStream&, cv::gapi::wip::draw::FText &) {
GAPI_Assert(false && "Serialization: Unsupported >> for FText");
GAPI_Error("Serialization: Unsupported >> for FText");
}
IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Circle &c) {
@@ -391,19 +398,19 @@ IIStream& operator>> (IIStream& is, cv::GArrayDesc &) {return is;}
#if !defined(GAPI_STANDALONE)
IOStream& operator<< (IOStream& os, const cv::UMat &)
{
GAPI_Assert(false && "Serialization: Unsupported << for UMat");
GAPI_Error("Serialization: Unsupported << for UMat");
return os;
}
IIStream& operator >> (IIStream& is, cv::UMat &)
{
GAPI_Assert(false && "Serialization: Unsupported >> for UMat");
GAPI_Error("Serialization: Unsupported >> for UMat");
return is;
}
#endif // !defined(GAPI_STANDALONE)
IOStream& operator<< (IOStream& os, const cv::gapi::wip::IStreamSource::Ptr &)
{
GAPI_Assert(false && "Serialization: Unsupported << for IStreamSource::Ptr");
GAPI_Error("Serialization: Unsupported << for IStreamSource::Ptr");
return os;
}
IIStream& operator >> (IIStream& is, cv::gapi::wip::IStreamSource::Ptr &)
@@ -422,7 +429,7 @@ struct putToStream<Ref, std::tuple<>>
{
static void put(IOStream&, const Ref &)
{
GAPI_Assert(false && "Unsupported type for GArray/GOpaque serialization");
GAPI_Error("Unsupported type for GArray/GOpaque serialization");
}
};
@@ -447,7 +454,7 @@ struct getFromStream<Ref, std::tuple<>>
{
static void get(IIStream&, Ref &, cv::detail::OpaqueKind)
{
GAPI_Assert(false && "Unsupported type for GArray/GOpaque deserialization");
GAPI_Error("Unsupported type for GArray/GOpaque deserialization");
}
};
@@ -553,7 +560,7 @@ IOStream& operator<< (IOStream& os, const cv::GArg &arg) {
case cv::detail::OpaqueKind::CV_RECT: os << arg.get<cv::Rect>(); break;
case cv::detail::OpaqueKind::CV_SCALAR: os << arg.get<cv::Scalar>(); break;
case cv::detail::OpaqueKind::CV_MAT: os << arg.get<cv::Mat>(); break;
default: GAPI_Assert(false && "GArg: Unsupported (unknown?) opaque value type");
default: GAPI_Error("GArg: Unsupported (unknown?) opaque value type");
}
}
return os;
@@ -584,12 +591,13 @@ IIStream& operator>> (IIStream& is, cv::GArg &arg) {
HANDLE_CASE(STRING , std::string);
HANDLE_CASE(POINT , cv::Point);
HANDLE_CASE(POINT2F , cv::Point2f);
HANDLE_CASE(POINT3F , cv::Point3f);
HANDLE_CASE(SIZE , cv::Size);
HANDLE_CASE(RECT , cv::Rect);
HANDLE_CASE(SCALAR , cv::Scalar);
HANDLE_CASE(MAT , cv::Mat);
#undef HANDLE_CASE
default: GAPI_Assert(false && "GArg: Unsupported (unknown?) opaque value type");
default: GAPI_Error("GArg: Unsupported (unknown?) opaque value type");
}
}
return is;
@@ -657,7 +665,7 @@ struct initCtor<Ref, std::tuple<>>
{
static void init(cv::gimpl::Data&)
{
GAPI_Assert(false && "Unsupported type for GArray/GOpaque deserialization");
GAPI_Error("Unsupported type for GArray/GOpaque deserialization");
}
};
@@ -18,7 +18,8 @@
#include "opencv2/gapi/render/render_types.hpp"
#include "opencv2/gapi/s11n.hpp" // basic interfaces
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702)
#endif
@@ -232,4 +233,8 @@ GAPI_EXPORTS std::vector<std::string> vector_of_strings_deserialize(IIStream& is
} // namespace gapi
} // namespace cv
#if defined _MSC_VER
#pragma warning(pop)
#endif
#endif // OPENCV_GAPI_COMMON_SERIALIZATION_HPP
+2 -2
View File
@@ -63,9 +63,9 @@ GAPI_OCV_KERNEL_ST(GCPUStereo, cv::gapi::calib3d::GStereo, StereoSetup)
stereoSetup.stereoBM->compute(left, right, out_mat);
break;
case cv::gapi::StereoOutputFormat::DISPARITY_FIXED16_11_5:
GAPI_Assert(false && "This case may be supported in future.");
GAPI_Error("This case may be supported in future.");
default:
GAPI_Assert(false && "Unknown output format!");
GAPI_Error("Unknown output format!");
}
}
};
@@ -313,7 +313,7 @@ static int maxLineConsumption(const cv::GFluidKernel::Kind kind, int window, int
}
} break;
case cv::GFluidKernel::Kind::YUV420toRGB: return inPort == 0 ? 2 : 1; break;
default: GAPI_Assert(false); return 0;
default: GAPI_Error("InternalError"); return 0;
}
}
@@ -325,7 +325,7 @@ static int borderSize(const cv::GFluidKernel::Kind kind, int window)
// Resize never reads from border pixels
case cv::GFluidKernel::Kind::Resize: return 0; break;
case cv::GFluidKernel::Kind::YUV420toRGB: return 0; break;
default: GAPI_Assert(false); return 0;
default: GAPI_Error("InternalError"); return 0;
}
}
@@ -685,7 +685,7 @@ void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
case 0: roi = produced; break;
case 1:
case 2: roi = cv::Rect{ produced.x/2, produced.y/2, produced.width/2, produced.height/2 }; break;
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
return roi;
};
@@ -699,7 +699,7 @@ void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
case GFluidKernel::Kind::Filter: resized = produced; break;
case GFluidKernel::Kind::Resize: resized = adjResizeRoi(produced, in_meta.size, meta.size); break;
case GFluidKernel::Kind::YUV420toRGB: resized = adj420Roi(produced, m_gm.metadata(in_edge).get<Input>().port); break;
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
// All below transformations affect roi of the writer, preserve read start position here
@@ -814,7 +814,7 @@ cv::gimpl::FluidGraphInputData cv::gimpl::fluidExtractInputDataFromGraph(const a
last_agent++;
break;
}
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
}
@@ -844,7 +844,7 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
case GFluidKernel::Kind::Filter: agent_ptr.reset(new FluidFilterAgent(g, agent_data.nh)); break;
case GFluidKernel::Kind::Resize: agent_ptr.reset(new FluidResizeAgent(g, agent_data.nh)); break;
case GFluidKernel::Kind::YUV420toRGB: agent_ptr.reset(new Fluid420toRGBAgent(g, agent_data.nh)); break;
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
std::tie(agent_ptr->in_buffer_ids, agent_ptr->out_buffer_ids) = std::tie(agent_data.in_buffer_ids, agent_data.out_buffer_ids);
return agent_ptr;
@@ -1388,7 +1388,7 @@ cv::gimpl::GParallelFluidExecutable::GParallelFluidExecutable(const ade::Graph
void cv::gimpl::GParallelFluidExecutable::reshape(ade::Graph&, const GCompileArgs& )
{
//TODO: implement ?
GAPI_Assert(false && "Not Implemented;");
GAPI_Error("Not Implemented;");
}
void cv::gimpl::GParallelFluidExecutable::run(std::vector<InObj> &&input_objs,
@@ -1474,7 +1474,7 @@ void GFluidBackendImpl::addMetaSensitiveBackendPasses(ade::ExecutionEngineSetupC
case NodeKind::EMIT:
case NodeKind::SINK:
break; // do nothing for Streaming nodes
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
} // switch
} // for (gim.nodes())
});
@@ -90,7 +90,7 @@ void fillBorderConstant(int borderSize, cv::Scalar borderValue, cv::Mat& mat)
case CV_16S: return &fillConstBorderRow< int16_t>; break;
case CV_16U: return &fillConstBorderRow<uint16_t>; break;
case CV_32F: return &fillConstBorderRow< float >; break;
default: GAPI_Assert(false); return &fillConstBorderRow<uint8_t>;
default: GAPI_Error("InternalError"); return &fillConstBorderRow<uint8_t>;
}
};
@@ -231,7 +231,7 @@ void fluid::BufferStorageWithBorder::init(int dtype, int border_size, Border bor
case cv::BORDER_REFLECT_101:
m_borderHandler.reset(new BorderHandlerT<cv::BORDER_REFLECT_101>(border_size, dtype)); break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
}
+181 -80
View File
@@ -114,7 +114,7 @@ inline IE::Precision toIE(int depth) {
case CV_32S: return IE::Precision::I32;
case CV_32F: return IE::Precision::FP32;
case CV_16F: return IE::Precision::FP16;
default: GAPI_Assert(false && "IE. Unsupported data type");
default: GAPI_Error("IE. Unsupported data type");
}
return IE::Precision::UNSPECIFIED;
}
@@ -125,7 +125,7 @@ inline int toCV(IE::Precision prec) {
case IE::Precision::I32: return CV_32S;
case IE::Precision::I64: return CV_32S;
case IE::Precision::FP16: return CV_16F;
default: GAPI_Assert(false && "IE. Unsupported data type");
default: GAPI_Error("IE. Unsupported data type");
}
return -1;
}
@@ -167,7 +167,7 @@ inline IE::Blob::Ptr wrapIE(const cv::Mat &mat, cv::gapi::ie::TraitAs hint) {
HANDLE(32S, int);
HANDLE(16F, int16_t);
#undef HANDLE
default: GAPI_Assert(false && "IE. Unsupported data type");
default: GAPI_Error("IE. Unsupported data type");
}
return IE::Blob::Ptr{};
}
@@ -190,13 +190,23 @@ inline IE::Blob::Ptr wrapIE(const cv::MediaFrame::View& view,
return wrapIE(gray, cv::gapi::ie::TraitAs::IMAGE);
}
default:
GAPI_Assert(false && "Unsupported media format for IE backend");
GAPI_Error("Unsupported media format for IE backend");
}
GAPI_Assert(false);
GAPI_Error("InternalError");
}
template<class MatType>
inline void copyFromIE(const IE::Blob::Ptr &blob, MatType &mat) {
const auto& desc = blob->getTensorDesc();
const auto ie_type = toCV(desc.getPrecision());
if (ie_type != mat.type()) {
std::stringstream ss;
ss << "Failed to copy blob from IE to OCV: "
<< "Blobs have different data types "
<< "(IE type: " << ie_type
<< " vs OCV type: " << mat.type() << ")." << std::endl;
throw std::logic_error(ss.str());
}
switch (blob->getTensorDesc().getPrecision()) {
#define HANDLE(E,T) \
case IE::Precision::E: std::copy_n(blob->buffer().as<T*>(), \
@@ -215,7 +225,7 @@ inline void copyFromIE(const IE::Blob::Ptr &blob, MatType &mat) {
mat.total());
break;
}
default: GAPI_Assert(false && "IE. Unsupported data type");
default: GAPI_Error("IE. Unsupported data type");
}
}
@@ -365,6 +375,13 @@ struct IEUnit {
cv::util::throw_error(std::logic_error("Unsupported ParamDesc::Kind"));
}
if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import &&
!cv::util::holds_alternative<cv::util::monostate>(params.output_precision)) {
cv::util::throw_error(
std::logic_error("Setting output precision isn't supported for imported network"));
}
using namespace cv::gapi::wip::onevpl;
if (params.vpl_preproc_device.has_value() && params.vpl_preproc_ctx.has_value()) {
using namespace cv::gapi::wip;
@@ -375,6 +392,12 @@ struct IEUnit {
params.vpl_preproc_ctx.value());
GAPI_LOG_INFO(nullptr, "VPP preproc created successfuly");
}
if (params.mode == cv::gapi::ie::InferMode::Sync &&
params.nireq != 1u) {
throw std::logic_error(
"Failed: cv::gapi::ie::InferMode::Sync works only with nireq equal to 1.");
}
}
// This method is [supposed to be] called at Island compilation stage
@@ -416,7 +439,7 @@ void IEUnit::InputFramesDesc::set_param(const input_name_type &input,
if (layout != InferenceEngine::NHWC && layout != InferenceEngine::NCHW) {
GAPI_LOG_WARNING(nullptr, "Unsupported layout for VPP preproc: " << layout <<
", input name: " << input);
GAPI_Assert(false && "Unsupported layout for VPP preproc");
GAPI_Error("Unsupported layout for VPP preproc");
}
GAPI_Assert(inDims.size() == 4u);
ret.size.width = static_cast<int>(inDims[3]);
@@ -731,7 +754,7 @@ inline IE::Blob::Ptr extractBlob(IECallContext& ctx,
NV12ParamType* blob_params = cv::util::any_cast<NV12ParamType>(&any_blob_params);
if (blob_params == nullptr) {
GAPI_Assert(false && "Incorrect type of blobParams:"
GAPI_Error("Incorrect type of blobParams:"
"expected std::pair<ParamType, ParamType>,"
"with ParamType std::pair<InferenceEngine::TensorDesc,"
"InferenceEngine::ParamMap >>");
@@ -759,7 +782,7 @@ inline IE::Blob::Ptr extractBlob(IECallContext& ctx,
default:
GAPI_Assert("Unsupported input shape for IE backend");
}
GAPI_Assert(false);
GAPI_Error("InternalError");
}
@@ -826,40 +849,130 @@ std::vector<InferenceEngine::InferRequest> cv::gimpl::ie::IECompiled::createInfe
return requests;
}
class cv::gimpl::ie::RequestPool {
class IInferExecutor {
public:
using RunF = std::function<void(InferenceEngine::InferRequest&)>;
using CallbackF = std::function<void(InferenceEngine::InferRequest&, InferenceEngine::StatusCode)>;
using Ptr = std::shared_ptr<IInferExecutor>;
using NotifyCallbackF = std::function<void()>;
using SetInputDataF = std::function<void(InferenceEngine::InferRequest&)>;
using ReadOutputDataF = std::function<void(InferenceEngine::InferRequest&, InferenceEngine::StatusCode)>;
// NB: The task is represented by:
// RunF - function which is set blobs and run async inference.
// CallbackF - function which is obtain output blobs and post it to output.
// SetInputDataF - function which set input data.
// ReadOutputDataF - function which read output data.
struct Task {
RunF run;
CallbackF callback;
SetInputDataF set_input_data;
ReadOutputDataF read_output_data;
};
explicit RequestPool(std::vector<InferenceEngine::InferRequest>&& requests);
IInferExecutor(IE::InferRequest request, NotifyCallbackF notify)
: m_request(std::move(request)),
m_notify(std::move(notify)) {
};
void execute(Task&& t);
void waitAll();
virtual void execute(const Task& task) = 0;
virtual ~IInferExecutor() = default;
protected:
IE::InferRequest m_request;
NotifyCallbackF m_notify;
};
class SyncInferExecutor : public IInferExecutor {
using IInferExecutor::IInferExecutor;
virtual void execute(const IInferExecutor::Task& task) override;
};
void SyncInferExecutor::execute(const IInferExecutor::Task& task) {
try {
task.set_input_data(m_request);
m_request.Infer();
task.read_output_data(m_request, IE::StatusCode::OK);
} catch (...) {
m_notify();
throw;
}
// NB: Notify pool that executor has finished.
m_notify();
}
class AsyncInferExecutor : public IInferExecutor {
public:
using IInferExecutor::IInferExecutor;
virtual void execute(const IInferExecutor::Task& task) override;
private:
void callback(Task task,
size_t id,
IE::InferRequest request,
IE::StatusCode code) noexcept;
void setup();
QueueClass<size_t> m_idle_ids;
std::vector<InferenceEngine::InferRequest> m_requests;
};
// RequestPool implementation //////////////////////////////////////////////
cv::gimpl::ie::RequestPool::RequestPool(std::vector<InferenceEngine::InferRequest>&& requests)
: m_requests(std::move(requests)) {
setup();
void AsyncInferExecutor::execute(const IInferExecutor::Task& task) {
using namespace std::placeholders;
using callback_t = std::function<void(IE::InferRequest, IE::StatusCode)>;
m_request.SetCompletionCallback(
static_cast<callback_t>(
std::bind(&AsyncInferExecutor::callback, this, task, _1, _2)));
try {
task.set_input_data(m_request);
m_request.StartAsync();
} catch (...) {
m_request.SetCompletionCallback([](){});
m_notify();
throw;
}
}
void AsyncInferExecutor::callback(IInferExecutor::Task task,
IE::InferRequest request,
IE::StatusCode code) noexcept {
task.read_output_data(request, code);
request.SetCompletionCallback([](){});
// NB: Notify pool that executor has finished.
m_notify();
}
class cv::gimpl::ie::RequestPool {
public:
explicit RequestPool(cv::gapi::ie::InferMode mode,
std::vector<InferenceEngine::InferRequest>&& requests);
IInferExecutor::Ptr getIdleRequest();
void waitAll();
private:
void setup();
void release(const size_t id);
QueueClass<size_t> m_idle_ids;
std::vector<IInferExecutor::Ptr> m_requests;
};
void cv::gimpl::ie::RequestPool::release(const size_t id) {
m_idle_ids.push(id);
}
// RequestPool implementation //////////////////////////////////////////////
cv::gimpl::ie::RequestPool::RequestPool(cv::gapi::ie::InferMode mode,
std::vector<InferenceEngine::InferRequest>&& requests) {
for (size_t i = 0; i < requests.size(); ++i) {
IInferExecutor::Ptr iexec = nullptr;
switch (mode) {
case cv::gapi::ie::InferMode::Async:
iexec = std::make_shared<AsyncInferExecutor>(std::move(requests[i]),
std::bind(&RequestPool::release, this, i));
break;
case cv::gapi::ie::InferMode::Sync:
iexec = std::make_shared<SyncInferExecutor>(std::move(requests[i]),
std::bind(&RequestPool::release, this, i));
break;
default:
GAPI_Error("Unsupported cv::gapi::ie::InferMode");
}
m_requests.emplace_back(std::move(iexec));
}
setup();
}
void cv::gimpl::ie::RequestPool::setup() {
for (size_t i = 0; i < m_requests.size(); ++i) {
@@ -867,40 +980,10 @@ void cv::gimpl::ie::RequestPool::setup() {
}
}
void cv::gimpl::ie::RequestPool::execute(cv::gimpl::ie::RequestPool::Task&& t) {
IInferExecutor::Ptr cv::gimpl::ie::RequestPool::getIdleRequest() {
size_t id = 0u;
m_idle_ids.pop(id);
auto& request = m_requests[id];
using namespace std::placeholders;
using callback_t = std::function<void(IE::InferRequest, IE::StatusCode)>;
request.SetCompletionCallback(
static_cast<callback_t>(
std::bind(&cv::gimpl::ie::RequestPool::callback, this,
t, id, _1, _2)));
// NB: InferRequest is already marked as busy
// in case of exception need to return it back to the idle.
try {
t.run(request);
} catch (...) {
request.SetCompletionCallback([](){});
m_idle_ids.push(id);
throw;
}
}
void cv::gimpl::ie::RequestPool::callback(cv::gimpl::ie::RequestPool::Task task,
size_t id,
IE::InferRequest request,
IE::StatusCode code) noexcept {
// NB: Inference is over.
// 1. Run callback
// 2. Destroy callback to free resources.
// 3. Mark InferRequest as idle.
task.callback(request, code);
request.SetCompletionCallback([](){});
m_idle_ids.push(id);
return m_requests[id];
}
// NB: Not thread-safe.
@@ -927,7 +1010,7 @@ cv::gimpl::ie::GIEExecutable::GIEExecutable(const ade::Graph &g,
if (this_nh == nullptr) {
this_nh = nh;
this_iec = iem.metadata(this_nh).get<IEUnit>().compile();
m_reqPool.reset(new RequestPool(this_iec.createInferRequests()));
m_reqPool.reset(new RequestPool(this_iec.params.mode, this_iec.createInferRequests()));
}
else
util::throw_error(std::logic_error("Multi-node inference is not supported!"));
@@ -1061,7 +1144,7 @@ static void configureInputReshapeByImage(const IE::InputInfo::Ptr& ii,
auto input_dims = ii->getTensorDesc().getDims();
const auto size = input_dims.size();
if (size <= 1) {
GAPI_Assert(false && "Unsupported number of dimensions for reshape by image");
GAPI_Error("Unsupported number of dimensions for reshape by image");
}
input_dims.at(size - 2) = static_cast<size_t>(image_sz.height);
input_dims.at(size - 1) = static_cast<size_t>(image_sz.width);
@@ -1090,7 +1173,7 @@ static void configureInputInfo(const IE::InputInfo::Ptr& ii, const cv::GMetaArg
// NB: Do nothing
break;
default:
GAPI_Assert(false && "Unsupported media format for IE backend");
GAPI_Error("Unsupported media format for IE backend");
}
ii->setPrecision(toIE(CV_8U));
break;
@@ -1122,6 +1205,28 @@ static IE::PreProcessInfo configurePreProcInfo(const IE::InputInfo::CPtr& ii,
return info;
}
using namespace cv::gapi::ie::detail;
static void configureOutputPrecision(const IE::OutputsDataMap &outputs_info,
const ParamDesc::PrecisionVariantT &output_precision) {
cv::util::visit(cv::util::overload_lambdas(
[&outputs_info](ParamDesc::PrecisionT cvdepth) {
auto precision = toIE(cvdepth);
for (auto it : outputs_info) {
it.second->setPrecision(precision);
}
},
[&outputs_info](const ParamDesc::PrecisionMapT& precision_map) {
for (auto it : precision_map) {
outputs_info.at(it.first)->setPrecision(toIE(it.second));
}
},
[&outputs_info](cv::util::monostate) {
// Do nothing.
}
), output_precision
);
}
// NB: This is a callback used by async infer
// to post outputs blobs (cv::GMat's).
static void PostOutputs(InferenceEngine::InferRequest &request,
@@ -1241,7 +1346,7 @@ struct Infer: public cv::detail::KernelTag {
GAPI_Assert(uu.params.input_names.size() == in_metas.size()
&& "Known input layers count doesn't match input meta count");
// NB: Configuring input precision and network reshape must be done
// NB: Configuring input/output precision and network reshape must be done
// only in the loadNetwork case.
using namespace cv::gapi::ie::detail;
if (uu.params.kind == ParamDesc::Kind::Load) {
@@ -1275,6 +1380,7 @@ struct Infer: public cv::detail::KernelTag {
if (!input_reshape_table.empty()) {
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
}
configureOutputPrecision(uu.net.getOutputsInfo(), uu.params.output_precision);
} else {
GAPI_Assert(uu.params.kind == ParamDesc::Kind::Import);
auto inputs = uu.this_network.GetInputsInfo();
@@ -1316,8 +1422,8 @@ struct Infer: public cv::detail::KernelTag {
static void run(std::shared_ptr<IECallContext> ctx,
cv::gimpl::ie::RequestPool &reqPool) {
using namespace std::placeholders;
reqPool.execute(
cv::gimpl::ie::RequestPool::Task {
reqPool.getIdleRequest()->execute(
IInferExecutor::Task {
[ctx](InferenceEngine::InferRequest &req) {
// non-generic version for now:
// - assumes all inputs/outputs are always Mats
@@ -1335,9 +1441,6 @@ struct Infer: public cv::detail::KernelTag {
cv::util::optional<cv::Rect>{});
setBlob(req, layer_name, this_blob, *ctx);
}
// FIXME: Should it be done by kernel ?
// What about to do that in RequestPool ?
req.StartAsync();
},
std::bind(PostOutputs, _1, _2, ctx)
}
@@ -1393,6 +1496,7 @@ struct InferROI: public cv::detail::KernelTag {
const_cast<IEUnit::InputFramesDesc &>(uu.net_input_params)
.set_param(input_name, ii->getTensorDesc());
}
configureOutputPrecision(uu.net.getOutputsInfo(), uu.params.output_precision);
} else {
GAPI_Assert(uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import);
auto inputs = uu.this_network.GetInputsInfo();
@@ -1429,8 +1533,8 @@ struct InferROI: public cv::detail::KernelTag {
static void run(std::shared_ptr<IECallContext> ctx,
cv::gimpl::ie::RequestPool &reqPool) {
using namespace std::placeholders;
reqPool.execute(
cv::gimpl::ie::RequestPool::Task {
reqPool.getIdleRequest()->execute(
IInferExecutor::Task {
[ctx](InferenceEngine::InferRequest &req) {
GAPI_Assert(ctx->uu.params.num_in == 1);
auto&& this_roi = ctx->inArg<cv::detail::OpaqueRef>(0).rref<cv::Rect>();
@@ -1455,9 +1559,6 @@ struct InferROI: public cv::detail::KernelTag {
*(ctx->uu.params.input_names.begin()),
this_blob, *ctx);
}
// FIXME: Should it be done by kernel ?
// What about to do that in RequestPool ?
req.StartAsync();
},
std::bind(PostOutputs, _1, _2, ctx)
}
@@ -1513,6 +1614,7 @@ struct InferList: public cv::detail::KernelTag {
if (!input_reshape_table.empty()) {
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
}
configureOutputPrecision(uu.net.getOutputsInfo(), uu.params.output_precision);
} else {
GAPI_Assert(uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import);
std::size_t idx = 1u;
@@ -1571,11 +1673,10 @@ struct InferList: public cv::detail::KernelTag {
for (auto&& it : ade::util::indexed(in_roi_vec)) {
auto pos = ade::util::index(it);
const auto& rc = ade::util::value(it);
reqPool.execute(
cv::gimpl::ie::RequestPool::Task {
reqPool.getIdleRequest()->execute(
IInferExecutor::Task {
[ctx, rc, this_blob](InferenceEngine::InferRequest &req) {
setROIBlob(req, ctx->uu.params.input_names[0u], this_blob, rc, *ctx);
req.StartAsync();
},
std::bind(callback, std::placeholders::_1, std::placeholders::_2, pos)
}
@@ -1667,6 +1768,7 @@ struct InferList2: public cv::detail::KernelTag {
if (!input_reshape_table.empty()) {
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
}
configureOutputPrecision(uu.net.getOutputsInfo(), uu.params.output_precision);
} else {
GAPI_Assert(uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import);
auto inputs = uu.this_network.GetInputsInfo();
@@ -1727,8 +1829,8 @@ struct InferList2: public cv::detail::KernelTag {
PostOutputsList callback(list_size, ctx, std::move(cached_dims));
for (const auto &list_idx : ade::util::iota(list_size)) {
reqPool.execute(
cv::gimpl::ie::RequestPool::Task {
reqPool.getIdleRequest()->execute(
IInferExecutor::Task {
[ctx, list_idx, list_size, blob_0](InferenceEngine::InferRequest &req) {
for (auto in_idx : ade::util::iota(ctx->uu.params.num_in)) {
const auto &this_vec = ctx->inArg<cv::detail::VectorRef>(in_idx+1u);
@@ -1748,7 +1850,6 @@ struct InferList2: public cv::detail::KernelTag {
"Only Rect and Mat types are supported for infer list 2!");
}
}
req.StartAsync();
},
std::bind(callback, std::placeholders::_1, std::placeholders::_2, list_idx)
} // task
+2 -2
View File
@@ -62,12 +62,12 @@ public:
virtual inline bool canReshape() const override { return false; }
virtual inline void reshape(ade::Graph&, const GCompileArgs&) override {
GAPI_Assert(false); // Not implemented yet
GAPI_Error("InternalError"); // Not implemented yet
}
virtual void run(std::vector<InObj> &&,
std::vector<OutObj> &&) override {
GAPI_Assert(false && "Not implemented");
GAPI_Error("Not implemented");
}
virtual void run(GIslandExecutable::IInput &in,
+9 -12
View File
@@ -39,7 +39,7 @@ class GOAKExecutable final: public GIslandExecutable {
friend class OAKKernelParams;
virtual void run(std::vector<InObj>&&,
std::vector<OutObj>&&) override {
GAPI_Assert(false && "Not implemented");
GAPI_Error("Not implemented");
}
virtual void run(GIslandExecutable::IInput &in,
@@ -121,7 +121,7 @@ public:
// FIXME: could it reshape?
virtual bool canReshape() const override { return false; }
virtual void reshape(ade::Graph&, const GCompileArgs&) override {
GAPI_Assert(false && "GOAKExecutable::reshape() is not supported");
GAPI_Error("GOAKExecutable::reshape() is not supported");
}
virtual void handleNewStream() override;
@@ -391,7 +391,7 @@ void cv::gimpl::GOAKExecutable::linkCopy(ade::NodeHandle handle) {
for (const auto& copy_next_op : copy_out.front().get()->outNodes()) {
const auto& op = m_gm.metadata(copy_next_op).get<Op>();
if (op.k.name == "org.opencv.oak.copy") {
GAPI_Assert(false && "Back-to-back Copy operations are not supported in graph");
GAPI_Error("Back-to-back Copy operations are not supported in graph");
}
}
@@ -701,14 +701,14 @@ cv::gimpl::GOAKExecutable::GOAKExecutable(const ade::Graph& g,
[](ExtractTypeHelper::InputPtr ptr) {
return ptr == nullptr;
})) {
GAPI_Assert(false && "DAI input are not set");
GAPI_Error("DAI input are not set");
}
if (std::any_of(node_info.outputs.cbegin(), node_info.outputs.cend(),
[](ExtractTypeHelper::OutputPtr ptr) {
return ptr == nullptr;
})) {
GAPI_Assert(false && "DAI outputs are not set");
GAPI_Error("DAI outputs are not set");
}
}
}
@@ -907,7 +907,7 @@ void cv::gimpl::GOAKExecutable::run(GIslandExecutable::IInput &in,
}
// FIXME: Add support for remaining types
default:
GAPI_Assert(false && "Unsupported type in OAK backend");
GAPI_Error("Unsupported type in OAK backend");
}
out.meta(out_arg, meta);
@@ -1080,7 +1080,7 @@ class GOAKBackendImpl final : public cv::gapi::GBackend::Priv {
// NB: how could we have non-OAK source in streaming mode, then OAK backend in
// streaming mode but without camera input?
if (!gm.metadata().contains<cv::gimpl::Streaming>()) {
GAPI_Assert(false && "OAK backend only supports Streaming mode for now");
GAPI_Error("OAK backend only supports Streaming mode for now");
}
return EPtr{new cv::gimpl::GOAKExecutable(graph, args, nodes, ins_data, outs_data)};
}
@@ -1118,14 +1118,11 @@ namespace gapi {
namespace oak {
cv::gapi::GKernelPackage kernels() {
GAPI_Assert(false && "Built without OAK support");
return {};
GAPI_Error("Built without OAK support");
}
cv::gapi::GBackend backend() {
GAPI_Assert(false && "Built without OAK support");
static cv::gapi::GBackend this_backend(nullptr);
return this_backend;
GAPI_Error("Built without OAK support");
}
} // namespace oak
@@ -114,7 +114,8 @@ cv::GArg cv::gimpl::GOCLExecutable::packArg(const GArg &arg)
GAPI_Assert( arg.kind != cv::detail::ArgKind::GMAT
&& arg.kind != cv::detail::ArgKind::GSCALAR
&& arg.kind != cv::detail::ArgKind::GARRAY
&& arg.kind != cv::detail::ArgKind::GOPAQUE);
&& arg.kind != cv::detail::ArgKind::GOPAQUE
&& arg.kind != cv::detail::ArgKind::GFRAME);
if (arg.kind != cv::detail::ArgKind::GOBJREF)
{
@@ -136,6 +137,7 @@ cv::GArg cv::gimpl::GOCLExecutable::packArg(const GArg &arg)
// Note: .at() is intentional for GOpaque as object MUST be already there
// (and constructed by either bindIn/Out or resetInternal)
case GShape::GOPAQUE: return GArg(m_res.slot<cv::detail::OpaqueRef>().at(ref.id));
case GShape::GFRAME: return GArg(m_res.slot<cv::MediaFrame>().at(ref.id));
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
break;
@@ -6,11 +6,32 @@
#include "precomp.hpp"
#include "logger.hpp"
#include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/ocl/core.hpp>
#include <opencv2/gapi/util/throw.hpp>
#include "backends/ocl/goclcore.hpp"
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
#pragma comment(lib,"d3d11.lib")
// get rid of generate macro max/min/etc from DX side
#define D3D11_NO_HELPERS
#define NOMINMAX
#include <d3d11.h>
#pragma comment(lib, "dxgi")
#undef NOMINMAX
#undef D3D11_NO_HELPERS
#include <opencv2/core/directx.hpp>
#endif // HAVE_D3D11
#endif // HAVE_DIRECTX
#include <opencv2/core/ocl.hpp>
#include "streaming/onevpl/accelerators/surface/dx11_frame_adapter.hpp"
GAPI_OCL_KERNEL(GOCLAdd, cv::gapi::core::GAdd)
{
static void run(const cv::UMat& a, const cv::UMat& b, int dtype, cv::UMat& out)
@@ -523,6 +544,79 @@ GAPI_OCL_KERNEL(GOCLTranspose, cv::gapi::core::GTranspose)
}
};
GAPI_OCL_KERNEL(GOCLBGR, cv::gapi::streaming::GBGR)
{
static void run(const cv::MediaFrame& in, cv::UMat& out)
{
cv::util::suppress_unused_warning(in);
cv::util::suppress_unused_warning(out);
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
#ifdef HAVE_ONEVPL
auto d = in.desc();
if (d.fmt != cv::MediaFormat::NV12)
{
GAPI_LOG_FATAL(nullptr, "Unsupported format provided: " << static_cast<int>(d.fmt) <<
". Expected cv::MediaFormat::NV12.");
cv::util::throw_error(std::logic_error("Unsupported MediaFrame format provided"));
}
// FIXME: consider a better solution.
// Current approach cannot be easily extended for other adapters (getHandle).
auto adapterPtr = in.get<cv::gapi::wip::onevpl::VPLMediaFrameDX11Adapter>();
if (adapterPtr == nullptr)
{
GAPI_LOG_FATAL(nullptr, "Unsupported adapter type. Only VPLMediaFrameDX11Adapter is supported");
cv::util::throw_error(std::logic_error("Unsupported adapter type. Only VPLMediaFrameDX11Adapter is supported"));
}
auto params = adapterPtr->getHandle();
auto handle = cv::util::any_cast<mfxHDLPair>(params);
ID3D11Texture2D* texture = reinterpret_cast<ID3D11Texture2D*>(handle.first);
if (texture == nullptr)
{
GAPI_LOG_FATAL(nullptr, "mfxHDLPair contains ID3D11Texture2D that is nullptr. Handle address" <<
reinterpret_cast<uint64_t>(handle.first));
cv::util::throw_error(std::logic_error("mfxHDLPair contains ID3D11Texture2D that is nullptr"));
}
// FIXME: Assuming here that we only have 1 device
// TODO: Textures are reusable, so to improve the peroformance here
// consider creating a hash map texture <-> device/ctx
static thread_local ID3D11Device* pD3D11Device = nullptr;
if (pD3D11Device == nullptr)
{
texture->GetDevice(&pD3D11Device);
}
if (pD3D11Device == nullptr)
{
GAPI_LOG_FATAL(nullptr, "D3D11Texture2D::GetDevice returns pD3D11Device that is nullptr");
cv::util::throw_error(std::logic_error("D3D11Texture2D::GetDevice returns pD3D11Device that is nullptr"));
}
// FIXME: assuming here that the context is always the same
// TODO: Textures are reusable, so to improve the peroformance here
// consider creating a hash map texture <-> device/ctx
static thread_local cv::ocl::Context ctx = cv::directx::ocl::initializeContextFromD3D11Device(pD3D11Device);
if (ctx.ptr() == nullptr)
{
GAPI_LOG_FATAL(nullptr, "initializeContextFromD3D11Device returned null context");
cv::util::throw_error(std::logic_error("initializeContextFromD3D11Device returned null context"));
}
cv::directx::convertFromD3D11Texture2D(texture, out);
#else
GAPI_LOG_FATAL(nullptr, "HAVE_ONEVPL is not set. Please, check your cmake flags");
cv::util::throw_error(std::logic_error("HAVE_ONEVPL is not set. Please, check your cmake flags"));
#endif // HAVE_ONEVPL
#else
GAPI_LOG_FATAL(nullptr, "HAVE_D3D11 or HAVE_DIRECTX is not set. Please, check your cmake flags");
cv::util::throw_error(std::logic_error("HAVE_D3D11 or HAVE_DIRECTX is not set. Please, check your cmake flags"));
#endif // HAVE_D3D11
#endif // HAVE_DIRECTX
}
};
cv::GKernelPackage cv::gapi::core::ocl::kernels()
{
static auto pkg = cv::gapi::kernels
@@ -587,6 +681,7 @@ cv::GKernelPackage cv::gapi::core::ocl::kernels()
, GOCLLUT
, GOCLConvertTo
, GOCLTranspose
, GOCLBGR
>();
return pkg;
}
@@ -0,0 +1,24 @@
// 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.
#include <opencv2/gapi/infer/bindings_onnx.hpp>
cv::gapi::onnx::PyParams::PyParams(const std::string& tag,
const std::string& model_path)
: m_priv(std::make_shared<Params<cv::gapi::Generic>>(tag, model_path)) {}
cv::gapi::GBackend cv::gapi::onnx::PyParams::backend() const {
return m_priv->backend();
}
std::string cv::gapi::onnx::PyParams::tag() const { return m_priv->tag(); }
cv::util::any cv::gapi::onnx::PyParams::params() const {
return m_priv->params();
}
cv::gapi::onnx::PyParams cv::gapi::onnx::params(
const std::string& tag, const std::string& model_path) {
return {tag, model_path};
}
+36 -10
View File
@@ -171,7 +171,7 @@ inline int toCV(ONNXTensorElementDataType prec) {
case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT: return CV_32F;
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32: return CV_32S;
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64: return CV_32S;
default: GAPI_Assert(false && "ONNX. Unsupported data type");
default: GAPI_Error("ONNX. Unsupported data type");
}
return -1;
}
@@ -207,7 +207,7 @@ inline void copyFromONNX(Ort::Value &v, cv::Mat& mat) {
mat.total());
break;
}
default: GAPI_Assert(false && "ONNX. Unsupported data type");
default: GAPI_Error("ONNX. Unsupported data type");
}
}
@@ -233,7 +233,7 @@ inline void preprocess(const cv::Mat& src,
"32F tensor dimensions should match with all non-dynamic NN input dimensions");
}
} else {
GAPI_Assert(false && "32F tensor size should match with NN input");
GAPI_Error("32F tensor size should match with NN input");
}
dst = src;
@@ -338,7 +338,7 @@ void preprocess(const cv::MediaFrame::View& view,
break;
}
default:
GAPI_Assert(false && "Unsupported media format for ONNX backend");
GAPI_Error("Unsupported media format for ONNX backend");
}
}
@@ -367,7 +367,7 @@ inline Ort::Value createTensor(const Ort::MemoryInfo& memory_info,
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32:
return createTensor<int32_t>(memory_info, tensor_params, data);
default:
GAPI_Assert(false && "ONNX. Unsupported data type");
GAPI_Error("ONNX. Unsupported data type");
}
return Ort::Value{nullptr};
}
@@ -735,7 +735,8 @@ void ONNXCompiled::extractMat(ONNXCallContext &ctx, const size_t in_idx, Views&
}
}
void ONNXCompiled::setOutput(int i, cv::Mat &m) {
void ONNXCompiled::setOutput(int i, cv::Mat &m)
{
// FIXME: No need in double-indexing?
out_data[i] = m;
}
@@ -857,7 +858,7 @@ static void checkInputMeta(const cv::GMetaArg mm) {
case cv::MediaFormat::NV12: break;
case cv::MediaFormat::BGR: break;
default:
GAPI_Assert(false && "Unsupported media format for ONNX backend");
GAPI_Error("Unsupported media format for ONNX backend");
} break;
} break;
default:
@@ -1100,7 +1101,7 @@ struct InferList2: public cv::detail::KernelTag {
const auto &vec = this_vec.rref<cv::Mat>();
uu.oc->setInput(in_idx, vec[list_idx]);
} else {
GAPI_Assert(false && "Only Rect and Mat types are supported for infer list 2!");
GAPI_Error("Only Rect and Mat types are supported for infer list 2!");
}
// }}} (Prepare input)
} // }}} (For every input of the net)
@@ -1133,9 +1134,34 @@ namespace {
// FIXME: Introduce a DNNBackend interface which'd specify
// the framework for this???
GONNXModel gm(gr);
const auto &np = gm.metadata(nh).get<NetworkParams>();
const auto &pp = cv::util::any_cast<cv::gapi::onnx::detail::ParamDesc>(np.opaque);
auto &np = gm.metadata(nh).get<NetworkParams>();
auto &pp = cv::util::any_cast<cv::gapi::onnx::detail::ParamDesc>(np.opaque);
const auto &ki = cv::util::any_cast<KImpl>(ii.opaque);
GModel::Graph model(gr);
auto& op = model.metadata(nh).get<Op>();
if (pp.is_generic) {
auto& info = cv::util::any_cast<cv::detail::InOutInfo>(op.params);
for (const auto& a : info.in_names)
{
pp.input_names.push_back(a);
}
// Adding const input is necessary because the definition of input_names
// includes const input.
for (const auto& a : pp.const_inputs)
{
pp.input_names.push_back(a.first);
}
pp.num_in = info.in_names.size();
for (const auto& a : info.out_names)
{
pp.output_names.push_back(a);
}
pp.num_out = info.out_names.size();
}
gm.metadata(nh).set(ONNXUnit{pp});
gm.metadata(nh).set(ONNXCallable{ki.run});
gm.metadata(nh).set(CustomMetaFunction{ki.customMetaFunc});
@@ -43,7 +43,7 @@ public:
virtual inline bool canReshape() const override { return false; }
virtual inline void reshape(ade::Graph&, const GCompileArgs&) override {
GAPI_Assert(false); // Not implemented yet
GAPI_Error("InternalError"); // Not implemented yet
}
virtual void run(std::vector<InObj> &&input_objs,
@@ -6,26 +6,25 @@
#include <ade/util/zip_range.hpp> // zip_range, indexed
#include "compiler/gmodel.hpp"
#include <opencv2/gapi/garg.hpp>
#include <opencv2/gapi/util/throw.hpp> // throw_error
#include <opencv2/gapi/python/python.hpp>
#include "api/gbackend_priv.hpp"
#include "backends/common/gbackend.hpp"
cv::gapi::python::GPythonKernel::GPythonKernel(cv::gapi::python::Impl run)
: m_run(run)
cv::gapi::python::GPythonKernel::GPythonKernel(cv::gapi::python::Impl runf,
cv::gapi::python::Setup setupf)
: run(runf), setup(setupf), is_stateful(setup != nullptr)
{
}
cv::GRunArgs cv::gapi::python::GPythonKernel::operator()(const cv::gapi::python::GPythonContext& ctx)
{
return m_run(ctx);
}
cv::gapi::python::GPythonFunctor::GPythonFunctor(const char* id,
const cv::gapi::python::GPythonFunctor::Meta &meta,
const cv::gapi::python::Impl& impl)
: gapi::GFunctor(id), impl_{GPythonKernel{impl}, meta}
const cv::gapi::python::GPythonFunctor::Meta& meta,
const cv::gapi::python::Impl& impl,
const cv::gapi::python::Setup& setup)
: gapi::GFunctor(id), impl_{GPythonKernel{impl, setup}, meta}
{
}
@@ -68,6 +67,7 @@ class GPythonExecutable final: public cv::gimpl::GIslandExecutable
virtual cv::RMat allocate(const cv::GMatDesc&) const override { return {}; }
virtual bool canReshape() const override { return true; }
virtual void handleNewStream() override;
virtual void reshape(ade::Graph&, const cv::GCompileArgs&) override {
// Do nothing here
}
@@ -80,6 +80,7 @@ public:
cv::gimpl::GModel::ConstGraph m_gm;
cv::gapi::python::GPythonKernel m_kernel;
ade::NodeHandle m_op;
cv::GArg m_node_state;
cv::GTypesInfo m_out_info;
cv::GMetaArgs m_in_metas;
@@ -149,10 +150,19 @@ static void writeBack(cv::GRunArg& arg, cv::GRunArgP& out)
break;
}
default:
GAPI_Assert(false && "Unsupported output type");
GAPI_Error("Unsupported output type");
}
}
void GPythonExecutable::handleNewStream()
{
if (!m_kernel.is_stateful)
return;
m_node_state = m_kernel.setup(cv::gimpl::GModel::collectInputMeta(m_gm, m_op),
m_gm.metadata(m_op).get<cv::gimpl::Op>().args);
}
void GPythonExecutable::run(std::vector<InObj> &&input_objs,
std::vector<OutObj> &&output_objs)
{
@@ -165,9 +175,15 @@ void GPythonExecutable::run(std::vector<InObj> &&input_objs,
std::back_inserter(inputs),
std::bind(&packArg, std::ref(m_res), _1));
cv::gapi::python::GPythonContext ctx{inputs, m_in_metas, m_out_info, /*state*/{}};
cv::gapi::python::GPythonContext ctx{inputs, m_in_metas, m_out_info};
auto outs = m_kernel(ctx);
// NB: For stateful kernel add state to its execution context
if (m_kernel.is_stateful)
{
ctx.m_state = cv::optional<cv::GArg>(m_node_state);
}
auto outs = m_kernel.run(ctx);
for (auto&& it : ade::util::zip(outs, output_objs))
{
@@ -225,6 +241,12 @@ GPythonExecutable::GPythonExecutable(const ade::Graph& g,
m_op = *it;
m_kernel = cag.metadata(m_op).get<PythonUnit>().kernel;
// If kernel is stateful then prepare storage for its state.
if (m_kernel.is_stateful)
{
m_node_state = cv::GArg{ };
}
// Ensure this the only op in the graph
if (std::any_of(it+1, nodes.end(), is_op))
{
@@ -42,7 +42,7 @@ class GStreamingIntrinExecutable final: public cv::gimpl::GIslandExecutable
{
virtual void run(std::vector<InObj> &&,
std::vector<OutObj> &&) override {
GAPI_Assert(false && "Not implemented");
GAPI_Error("Not implemented");
}
virtual void run(GIslandExecutable::IInput &in,
@@ -188,7 +188,7 @@ void Copy::Actor::run(cv::gimpl::GIslandExecutable::IInput &in,
break;
// FIXME: Add support for remaining types
default:
GAPI_Assert(false && "Copy: unsupported data type");
GAPI_Error("Copy: unsupported data type");
}
out.meta(out_arg, in_arg.meta);
out.post(std::move(out_arg));
+2 -1
View File
@@ -14,11 +14,12 @@
#include "compiler/gcompiled_priv.hpp"
#include "backends/common/gbackend.hpp"
#include "executor/gexecutor.hpp"
// GCompiled private implementation ////////////////////////////////////////////
void cv::GCompiled::Priv::setup(const GMetaArgs &_metaArgs,
const GMetaArgs &_outMetas,
std::unique_ptr<cv::gimpl::GExecutor> &&_pE)
std::unique_ptr<cv::gimpl::GAbstractExecutor> &&_pE)
{
m_metas = _metaArgs;
m_outMetas = _outMetas;
+3 -3
View File
@@ -12,7 +12,7 @@
#include "opencv2/gapi/util/optional.hpp"
#include "compiler/gmodel.hpp"
#include "executor/gexecutor.hpp"
#include "executor/gabstractexecutor.hpp"
// NB: BTW, GCompiled is the only "public API" class which
// private part (implementation) is hosted in the "compiler/" module.
@@ -36,14 +36,14 @@ class GAPI_EXPORTS GCompiled::Priv
// If we want to go autonomous, we might to do something with this.
GMetaArgs m_metas; // passed by user
GMetaArgs m_outMetas; // inferred by compiler
std::unique_ptr<cv::gimpl::GExecutor> m_exec;
std::unique_ptr<cv::gimpl::GAbstractExecutor> m_exec;
void checkArgs(const cv::gimpl::GRuntimeArgs &args) const;
public:
void setup(const GMetaArgs &metaArgs,
const GMetaArgs &outMetas,
std::unique_ptr<cv::gimpl::GExecutor> &&pE);
std::unique_ptr<cv::gimpl::GAbstractExecutor> &&pE);
bool isEmpty() const;
bool canReshape() const;
+2 -2
View File
@@ -338,7 +338,7 @@ void cv::gimpl::GCompiler::validateInputMeta()
return util::holds_alternative<cv::GOpaqueDesc>(meta);
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
return false; // should never happen
};
@@ -485,7 +485,7 @@ cv::GStreamingCompiled cv::gimpl::GCompiler::produceStreamingCompiled(GPtr &&pg)
// Otherwise, set it up with executor object only
compiled.priv().setup(std::move(pE));
}
else GAPI_Assert(false && "Impossible happened -- please report a bug");
else GAPI_Error("Impossible happened -- please report a bug");
return compiled;
}
+2 -2
View File
@@ -120,7 +120,7 @@ ade::NodeHandle GIsland::producer(const ade::Graph &g,
}
// Consistency: A GIsland requested for producer() of slot_nh should
// always had the appropriate GModel node handle in its m_out_ops vector.
GAPI_Assert(false && "Broken GIslandModel ?.");
GAPI_Error("Broken GIslandModel ?.");
}
std::string GIsland::name() const
@@ -164,7 +164,7 @@ void GIslandModel::generateInitial(GIslandModel::Graph &g,
{
case NodeType::OP: all_operations.insert(src_nh); break;
case NodeType::DATA: data_to_slot[src_nh] = mkSlotNode(g, src_nh); break;
default: GAPI_Assert(false); break;
default: GAPI_Error("InternalError"); break;
}
} // for (src_g.nodes)
+1 -1
View File
@@ -122,7 +122,7 @@ public:
virtual bool canReshape() const = 0;
virtual void reshape(ade::Graph& g, const GCompileArgs& args) = 0;
virtual bool allocatesOutputs() const { return false; }
virtual cv::RMat allocate(const cv::GMatDesc&) const { GAPI_Assert(false && "should never be called"); }
virtual cv::RMat allocate(const cv::GMatDesc&) const { GAPI_Error("should never be called"); }
// This method is called when the GStreamingCompiled gets a new
// input source to process. Normally this method is called once
+1 -1
View File
@@ -162,7 +162,7 @@ cv::gimpl::Unrolled cv::gimpl::unrollExpr(const GProtoArgs &ins,
default:
// Unsupported node shape
GAPI_Assert(false);
GAPI_Error("InternalError");
break;
}
}
+2 -2
View File
@@ -19,14 +19,14 @@
// GStreamingCompiled private implementation ///////////////////////////////////
void cv::GStreamingCompiled::Priv::setup(const GMetaArgs &_metaArgs,
const GMetaArgs &_outMetas,
std::unique_ptr<cv::gimpl::GStreamingExecutor> &&_pE)
std::unique_ptr<cv::gimpl::GAbstractStreamingExecutor> &&_pE)
{
m_metas = _metaArgs;
m_outMetas = _outMetas;
m_exec = std::move(_pE);
}
void cv::GStreamingCompiled::Priv::setup(std::unique_ptr<cv::gimpl::GStreamingExecutor> &&_pE)
void cv::GStreamingCompiled::Priv::setup(std::unique_ptr<cv::gimpl::GAbstractStreamingExecutor> &&_pE)
{
m_exec = std::move(_pE);
}
@@ -9,7 +9,7 @@
#define OPENCV_GAPI_GSTREAMING_COMPILED_PRIV_HPP
#include <memory> // unique_ptr
#include "executor/gstreamingexecutor.hpp"
#include "executor/gabstractstreamingexecutor.hpp"
namespace cv {
@@ -26,7 +26,7 @@ class GAPI_EXPORTS GStreamingCompiled::Priv
{
GMetaArgs m_metas; // passed by user
GMetaArgs m_outMetas; // inferred by compiler
std::unique_ptr<cv::gimpl::GStreamingExecutor> m_exec;
std::unique_ptr<cv::gimpl::GAbstractStreamingExecutor> m_exec;
// NB: Used by python wrapper to clarify input/output types
GTypesInfo m_out_info;
@@ -35,8 +35,8 @@ class GAPI_EXPORTS GStreamingCompiled::Priv
public:
void setup(const GMetaArgs &metaArgs,
const GMetaArgs &outMetas,
std::unique_ptr<cv::gimpl::GStreamingExecutor> &&pE);
void setup(std::unique_ptr<cv::gimpl::GStreamingExecutor> &&pE);
std::unique_ptr<cv::gimpl::GAbstractStreamingExecutor> &&pE);
void setup(std::unique_ptr<cv::gimpl::GAbstractStreamingExecutor> &&pE);
bool isEmpty() const;
const GMetaArgs& metas() const;
@@ -149,7 +149,7 @@ void dumpDot(const ade::Graph &g, std::ostream& os)
}
}
break;
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
}
@@ -209,7 +209,7 @@ void dumpDot(const ade::Graph &g, std::ostream& os)
}
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
break;
}
}
+1 -1
View File
@@ -128,7 +128,7 @@ void traceUp(cv::gimpl::GModel::Graph &g,
// this recursive process (e.g. via some other output or branch in the
// subgraph)
if (g.metadata(nh).get<DesyncPath>().index != desync_id) {
GAPI_Assert(false && "Desynchronization can't be nested!");
GAPI_Error("Desynchronization can't be nested!");
}
return; // This object belongs to the desync path - exit early.
}
@@ -371,10 +371,9 @@ cv::gimpl::findMatches(const cv::gimpl::GModel::Graph& patternGraph,
testNodeMeta,
isAlreadyVisited);
default:
GAPI_Assert(false && "Unsupported Node type!");
break;
}
return false;
GAPI_Error("Unsupported Node type!");
});
if (testIt == testOutputNodesLabeled.end()) {
+1 -1
View File
@@ -117,7 +117,7 @@ struct ChangeT
{
case Direction::In: eh = g.link(m_sibling, m_node); break;
case Direction::Out: eh = g.link(m_node, m_sibling); break;
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
GAPI_Assert(eh != nullptr);
m_meta.copyTo(g, eh);
@@ -0,0 +1,25 @@
// 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) 2022 Intel Corporation
#include "precomp.hpp"
#include <opencv2/gapi/opencv_includes.hpp>
#include "executor/gabstractexecutor.hpp"
cv::gimpl::GAbstractExecutor::GAbstractExecutor(std::unique_ptr<ade::Graph> &&g_model)
: m_orig_graph(std::move(g_model))
, m_island_graph(GModel::Graph(*m_orig_graph).metadata()
.get<IslandModel>().model)
, m_gm(*m_orig_graph)
, m_gim(*m_island_graph)
{
}
const cv::gimpl::GModel::Graph& cv::gimpl::GAbstractExecutor::model() const
{
return m_gm;
}
@@ -0,0 +1,80 @@
// 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) 2022 Intel Corporation
#ifndef OPENCV_GAPI_GABSTRACT_EXECUTOR_HPP
#define OPENCV_GAPI_GABSTRACT_EXECUTOR_HPP
#include <memory> // unique_ptr, shared_ptr
#include <utility> // tuple, required by magazine
#include <unordered_map> // required by magazine
#include <ade/graph.hpp>
#include "backends/common/gbackend.hpp"
namespace cv {
namespace gimpl {
// Graph-level executor interface.
//
// This class specifies API for a "super-executor" which orchestrates
// the overall Island graph execution.
//
// Every Island (subgraph) execution is delegated to a particular
// backend and is done opaquely to the GExecutor.
//
// Inputs to a GExecutor instance are:
// - GIslandModel - a high-level graph model which may be seen as a
// "procedure" to execute.
// - GModel - a low-level graph of operations (from which a GIslandModel
// is projected)
// - GComputation runtime arguments - vectors of input/output objects
//
// Every GExecutor is responsible for
// a. Maintaining non-island (intermediate) data objects within graph
// b. Providing GIslandExecutables with input/output data according to
// their protocols
// c. Triggering execution of GIslandExecutables when task/data dependencies
// are met.
//
// By default G-API stores all data on host, and cross-Island
// exchange happens via host buffers (and CV data objects).
//
// Today's exchange data objects are:
// - cv::Mat, cv::RMat - for image buffers
// - cv::Scalar - for single values (with up to four components inside)
// - cv::detail::VectorRef - an untyped wrapper over std::vector<T>
// - cv::detail::OpaqueRef - an untyped wrapper over T
// - cv::MediaFrame - for image textures and surfaces (e.g. in planar format)
class GAbstractExecutor
{
protected:
std::unique_ptr<ade::Graph> m_orig_graph;
std::shared_ptr<ade::Graph> m_island_graph;
cv::gimpl::GModel::Graph m_gm; // FIXME: make const?
cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const?
public:
explicit GAbstractExecutor(std::unique_ptr<ade::Graph> &&g_model);
virtual ~GAbstractExecutor() = default;
virtual void run(cv::gimpl::GRuntimeArgs &&args) = 0;
virtual bool canReshape() const = 0;
virtual void reshape(const GMetaArgs& inMetas, const GCompileArgs& args) = 0;
virtual void prepareForNewStream() = 0;
const GModel::Graph& model() const; // FIXME: make it ConstGraph?
};
} // namespace gimpl
} // namespace cv
#endif // OPENCV_GAPI_GABSTRACT_EXECUTOR_HPP
@@ -0,0 +1,23 @@
// 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) 2022 Intel Corporation
#include "precomp.hpp"
#include <opencv2/gapi/opencv_includes.hpp>
#include "executor/gabstractstreamingexecutor.hpp"
cv::gimpl::GAbstractStreamingExecutor::GAbstractStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
const GCompileArgs &comp_args)
: m_orig_graph(std::move(g_model))
, m_island_graph(GModel::Graph(*m_orig_graph).metadata()
.get<IslandModel>().model)
, m_comp_args(comp_args)
, m_gim(*m_island_graph)
, m_desync(GModel::Graph(*m_orig_graph).metadata()
.contains<Desynchronized>())
{
}
@@ -0,0 +1,49 @@
// 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) 2022 Intel Corporation
#ifndef OPENCV_GAPI_GABSTRACT_STREAMING_EXECUTOR_HPP
#define OPENCV_GAPI_GABSTRACT_STREAMING_EXECUTOR_HPP
#include <memory> // unique_ptr, shared_ptr
#include <ade/graph.hpp>
#include "backends/common/gbackend.hpp"
namespace cv {
namespace gimpl {
class GAbstractStreamingExecutor
{
protected:
std::unique_ptr<ade::Graph> m_orig_graph;
std::shared_ptr<ade::Graph> m_island_graph;
cv::GCompileArgs m_comp_args;
cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const?
const bool m_desync;
public:
explicit GAbstractStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
const cv::GCompileArgs &comp_args);
virtual ~GAbstractStreamingExecutor() = default;
virtual void setSource(GRunArgs &&args) = 0;
virtual void start() = 0;
virtual bool pull(cv::GRunArgsP &&outs) = 0;
virtual bool pull(cv::GOptRunArgsP &&outs) = 0;
using PyPullResult = std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>>;
virtual PyPullResult pull() = 0;
virtual bool try_pull(cv::GRunArgsP &&outs) = 0;
virtual void stop() = 0;
virtual bool running() const = 0;
};
} // namespace gimpl
} // namespace cv
#endif // OPENCV_GAPI_GABSTRACT_STREAMING_EXECUTOR_HPP
+3 -12
View File
@@ -16,11 +16,7 @@
#include "compiler/passes/passes.hpp"
cv::gimpl::GExecutor::GExecutor(std::unique_ptr<ade::Graph> &&g_model)
: m_orig_graph(std::move(g_model))
, m_island_graph(GModel::Graph(*m_orig_graph).metadata()
.get<IslandModel>().model)
, m_gm(*m_orig_graph)
, m_gim(*m_island_graph)
: GAbstractExecutor(std::move(g_model))
{
// NB: Right now GIslandModel is acyclic, so for a naive execution,
// simple unrolling to a list of triggers is enough
@@ -79,7 +75,7 @@ cv::gimpl::GExecutor::GExecutor(std::unique_ptr<ade::Graph> &&g_model)
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
break;
} // switch(kind)
} // for(gim nodes)
@@ -252,7 +248,7 @@ void cv::gimpl::GExecutor::initResource(const ade::NodeHandle & nh, const ade::N
break;
}
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
}
@@ -424,11 +420,6 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args)
}
}
const cv::gimpl::GModel::Graph& cv::gimpl::GExecutor::model() const
{
return m_gm;
}
bool cv::gimpl::GExecutor::canReshape() const
{
// FIXME: Introduce proper reshaping support on GExecutor level
+6 -48
View File
@@ -8,58 +8,18 @@
#ifndef OPENCV_GAPI_GEXECUTOR_HPP
#define OPENCV_GAPI_GEXECUTOR_HPP
#include <memory> // unique_ptr, shared_ptr
#include <utility> // tuple, required by magazine
#include <unordered_map> // required by magazine
#include <ade/graph.hpp>
#include "backends/common/gbackend.hpp"
#include "executor/gabstractexecutor.hpp"
namespace cv {
namespace gimpl {
// Graph-level executor interface.
//
// This class specifies API for a "super-executor" which orchestrates
// the overall Island graph execution.
//
// Every Island (subgraph) execution is delegated to a particular
// backend and is done opaquely to the GExecutor.
//
// Inputs to a GExecutor instance are:
// - GIslandModel - a high-level graph model which may be seen as a
// "procedure" to execute.
// - GModel - a low-level graph of operations (from which a GIslandModel
// is projected)
// - GComputation runtime arguments - vectors of input/output objects
//
// Every GExecutor is responsible for
// a. Maintaining non-island (intermediate) data objects within graph
// b. Providing GIslandExecutables with input/output data according to
// their protocols
// c. Triggering execution of GIslandExecutables when task/data dependencies
// are met.
//
// By default G-API stores all data on host, and cross-Island
// exchange happens via host buffers (and CV data objects).
//
// Today's exchange data objects are:
// - cv::Mat - for image buffers
// - cv::Scalar - for single values (with up to four components inside)
// - cv::detail::VectorRef - an untyped wrapper over std::vector<T>
//
class GExecutor
class GExecutor final: public GAbstractExecutor
{
protected:
Mag m_res;
std::unique_ptr<ade::Graph> m_orig_graph;
std::shared_ptr<ade::Graph> m_island_graph;
cv::gimpl::GModel::Graph m_gm; // FIXME: make const?
cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const?
// FIXME: Naive executor details are here for now
// but then it should be moved to another place
@@ -85,14 +45,12 @@ protected:
public:
explicit GExecutor(std::unique_ptr<ade::Graph> &&g_model);
void run(cv::gimpl::GRuntimeArgs &&args);
void run(cv::gimpl::GRuntimeArgs &&args) override;
bool canReshape() const;
void reshape(const GMetaArgs& inMetas, const GCompileArgs& args);
bool canReshape() const override;
void reshape(const GMetaArgs& inMetas, const GCompileArgs& args) override;
void prepareForNewStream();
const GModel::Graph& model() const; // FIXME: make it ConstGraph?
void prepareForNewStream() override;
};
} // namespace gimpl
@@ -157,7 +157,7 @@ void sync_data(cv::GRunArgs &results, cv::GRunArgsP &outputs)
*cv::util::get<cv::MediaFrame*>(out_obj) = std::move(cv::util::get<cv::MediaFrame>(res_obj));
break;
default:
GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
GAPI_Error("This value type is not supported!"); // ...maybe because of STANDALONE mode.
break;
}
}
@@ -227,7 +227,7 @@ void sync_data(cv::gimpl::stream::Result &r, cv::GOptRunArgsP &outputs)
} break;
default:
// ...maybe because of STANDALONE mode.
GAPI_Assert(false && "This value type is not supported!");
GAPI_Error("This value type is not supported!");
break;
}
}
@@ -446,7 +446,7 @@ cv::gimpl::StreamMsg QueueReader::getInputVector(std::vector<Q*> &in_queues,
break;
}
default:
GAPI_Assert(false && "Unsupported cmd type in getInputVector()");
GAPI_Error("Unsupported cmd type in getInputVector()");
}
} // for(in_queues)
@@ -920,7 +920,7 @@ class StreamingOutput final: public cv::gimpl::GIslandExecutable::IOutput
m_stops_sent++;
break;
default:
GAPI_Assert(false && "Unreachable code");
GAPI_Error("Unreachable code");
}
for (auto &&q : m_out_queues[out_idx])
@@ -1115,7 +1115,7 @@ void collectorThread(std::vector<Q*> in_queues,
out_queue.push(Cmd{cv::util::get<cv::gimpl::Exception>(result)});
break;
default:
GAPI_Assert(false && "Unreachable code");
GAPI_Error("Unreachable code");
}
}
}
@@ -1288,13 +1288,7 @@ public:
// proper graph reshape and islands recompilation
cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
const GCompileArgs &comp_args)
: m_orig_graph(std::move(g_model))
, m_island_graph(GModel::Graph(*m_orig_graph).metadata()
.get<IslandModel>().model)
, m_comp_args(comp_args)
, m_gim(*m_island_graph)
, m_desync(GModel::Graph(*m_orig_graph).metadata()
.contains<Desynchronized>())
: GAbstractStreamingExecutor(std::move(g_model), comp_args)
{
GModel::Graph gm(*m_orig_graph);
// NB: Right now GIslandModel is acyclic, and all the below code assumes that.
@@ -1485,7 +1479,7 @@ cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr<ade::Graph> &&
}
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
break;
} // switch(kind)
} // for(gim nodes)
@@ -1826,9 +1820,9 @@ bool cv::gimpl::GStreamingExecutor::pull(cv::GRunArgsP &&outs)
return true;
}
default:
GAPI_Assert(false && "Unsupported cmd type in pull");
GAPI_Error("Unsupported cmd type in pull");
}
GAPI_Assert(false && "Unreachable code");
GAPI_Error("Unreachable code");
}
bool cv::gimpl::GStreamingExecutor::pull(cv::GOptRunArgsP &&outs)
@@ -1859,10 +1853,10 @@ bool cv::gimpl::GStreamingExecutor::pull(cv::GOptRunArgsP &&outs)
return true;
}
}
GAPI_Assert(false && "Unreachable code");
GAPI_Error("Unreachable code");
}
std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>> cv::gimpl::GStreamingExecutor::pull()
cv::gimpl::GAbstractStreamingExecutor::PyPullResult cv::gimpl::GStreamingExecutor::pull()
{
using RunArgs = cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>;
bool is_over = false;
@@ -12,7 +12,6 @@
// on concurrent_bounded_queue
#endif
#include <memory> // unique_ptr, shared_ptr
#include <thread> // thread
#include <vector>
#include <unordered_map>
@@ -26,9 +25,7 @@ template<typename T> using QueueClass = cv::gapi::own::concurrent_bounded_queue<
#endif // TBB
#include "executor/last_value.hpp"
#include <ade/graph.hpp>
#include "backends/common/gbackend.hpp"
#include "executor/gabstractstreamingexecutor.hpp"
namespace cv {
namespace gimpl {
@@ -104,7 +101,7 @@ public:
// FIXME: Currently all GExecutor comments apply also
// to this one. Please document it separately in the future.
class GStreamingExecutor final
class GStreamingExecutor final: public GAbstractStreamingExecutor
{
protected:
// GStreamingExecutor is a state machine described as follows
@@ -131,15 +128,9 @@ protected:
RUNNING,
} state = State::STOPPED;
std::unique_ptr<ade::Graph> m_orig_graph;
std::shared_ptr<ade::Graph> m_island_graph;
cv::GCompileArgs m_comp_args;
cv::GMetaArgs m_last_metas;
util::optional<bool> m_reshapable;
cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const?
const bool m_desync;
// FIXME: Naive executor details are here for now
// but then it should be moved to another place
struct OpDesc
@@ -202,14 +193,14 @@ public:
explicit GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
const cv::GCompileArgs &comp_args);
~GStreamingExecutor();
void setSource(GRunArgs &&args);
void start();
bool pull(cv::GRunArgsP &&outs);
bool pull(cv::GOptRunArgsP &&outs);
std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>> pull();
bool try_pull(cv::GRunArgsP &&outs);
void stop();
bool running() const;
void setSource(GRunArgs &&args) override;
void start() override;
bool pull(cv::GRunArgsP &&outs) override;
bool pull(cv::GOptRunArgsP &&outs) override;
PyPullResult pull() override;
bool try_pull(cv::GRunArgsP &&outs) override;
void stop() override;
bool running() const override;
};
} // namespace gimpl
+1 -1
View File
@@ -12,7 +12,7 @@
#endif
#ifdef HAVE_TBB
#ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES // supress warning
#ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES
#define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
#endif
#include <tbb/tbb.h>
@@ -40,7 +40,7 @@ GStreamerMediaAdapter::GStreamerMediaAdapter(const cv::GFrameDesc& frameDesc,
break;
}
default: {
GAPI_Assert(false && "Non NV12 or GRAY Media format is not expected here");
GAPI_Error("Non NV12 or GRAY Media format is not expected here");
break;
}
}
@@ -59,7 +59,7 @@ GStreamerMediaAdapter::GStreamerMediaAdapter(const cv::GFrameDesc& frameDesc,
break;
}
default: {
GAPI_Assert(false && "Non NV12 or GRAY Media format is not expected here");
GAPI_Error("Non NV12 or GRAY Media format is not expected here");
break;
}
}
@@ -160,7 +160,7 @@ cv::MediaFrame::View GStreamerMediaAdapter::access(cv::MediaFrame::Access access
break;
}
default: {
GAPI_Assert(false && "Non NV12 or GRAY Media format is not expected here");
GAPI_Error("Non NV12 or GRAY Media format is not expected here");
break;
}
}
@@ -171,7 +171,7 @@ cv::MediaFrame::View GStreamerMediaAdapter::access(cv::MediaFrame::Access access
}
cv::util::any GStreamerMediaAdapter::blobParams() const {
GAPI_Assert(false && "No implementation for GStreamerMediaAdapter::blobParams()");
GAPI_Error("No implementation for GStreamerMediaAdapter::blobParams()");
}
} // namespace gst
@@ -69,12 +69,12 @@ GStreamerEnv::~GStreamerEnv()
const GStreamerEnv& GStreamerEnv::init()
{
GAPI_Assert(false && "Built without GStreamer support!");
GAPI_Error("Built without GStreamer support!");
}
GStreamerEnv::GStreamerEnv()
{
GAPI_Assert(false && "Built without GStreamer support!");
GAPI_Error("Built without GStreamer support!");
}
GStreamerEnv::~GStreamerEnv()
@@ -73,7 +73,7 @@ GStreamerPipeline::Priv::~Priv() { }
GStreamerPipeline::Priv::Priv(const std::string&)
{
GAPI_Assert(false && "Built without GStreamer support!");
GAPI_Error("Built without GStreamer support!");
}
IStreamSource::Ptr GStreamerPipeline::Priv::getStreamingSource(const std::string&,
@@ -205,7 +205,7 @@ void GStreamerSource::Priv::prepareVideoMeta()
break;
}
default: {
GAPI_Assert(false && "Unsupported GStreamerSource FRAME type.");
GAPI_Error("Unsupported GStreamerSource FRAME type.");
}
}
break;
@@ -317,7 +317,7 @@ bool GStreamerSource::Priv::retrieveFrame(cv::Mat& data)
break;
}
default: {
GAPI_Assert(false && "retrieveFrame - unsupported GStreamerSource FRAME type.");
GAPI_Error("retrieveFrame - unsupported GStreamerSource FRAME type.");
}
}
}
@@ -354,13 +354,13 @@ GStreamerSource::Priv::~Priv() { }
GStreamerSource::Priv::Priv(const std::string&, const GStreamerSource::OutputType)
{
GAPI_Assert(false && "Built without GStreamer support!");
GAPI_Error("Built without GStreamer support!");
}
GStreamerSource::Priv::Priv(std::shared_ptr<GStreamerPipelineFacade>, const std::string&,
const GStreamerSource::OutputType)
{
GAPI_Assert(false && "Built without GStreamer support!");
GAPI_Error("Built without GStreamer support!");
}
bool GStreamerSource::Priv::pull(cv::gapi::wip::Data&)
@@ -65,7 +65,7 @@ static surface_ptr_t create_surface_RGB4_(mfxFrameInfo frameInfo,
", offset: " << out_buf_ptr_offset <<
", W: " << surfW <<
", H: " << surfH);
GAPI_Assert(false && "Invalid offset");
GAPI_Error("Invalid offset");
}
std::unique_ptr<mfxFrameSurface1> handle(new mfxFrameSurface1);
@@ -98,7 +98,7 @@ static surface_ptr_t create_surface_other_(mfxFrameInfo frameInfo,
", offset: " << out_buf_ptr_offset <<
", W: " << surfW <<
", H: " << surfH);
GAPI_Assert(false && "Invalid offset");
GAPI_Error("Invalid offset");
}
std::unique_ptr<mfxFrameSurface1> handle(new mfxFrameSurface1);
@@ -209,7 +209,7 @@ VPLCPUAccelerationPolicy::create_surface_pool(size_t pool_size, size_t surface_s
if (!pool_table.emplace(preallocated_pool_memory_ptr, std::move(pool)).second) {
GAPI_LOG_WARNING(nullptr, "Cannot insert pool, table size: " + std::to_string(pool_table.size()) <<
", key: " << preallocated_pool_memory_ptr << " exists");
GAPI_Assert(false && "Cannot create pool in VPLCPUAccelerationPolicy");
GAPI_Error("Cannot create pool in VPLCPUAccelerationPolicy");
}
return preallocated_pool_memory_ptr;
@@ -248,7 +248,7 @@ VPLCPUAccelerationPolicy::surface_weak_ptr_t VPLCPUAccelerationPolicy::get_free_
if (pool_it == pool_table.end()) {
GAPI_LOG_WARNING(nullptr, "key is not found, table size: " <<
pool_table.size());
GAPI_Assert(false && "Invalid surface key requested in VPLCPUAccelerationPolicy");
GAPI_Error("Invalid surface key requested in VPLCPUAccelerationPolicy");
}
pool_t& requested_pool = pool_it->second;
@@ -14,7 +14,6 @@
#include "logger.hpp"
#if defined(HAVE_DIRECTX) && defined(HAVE_D3D11)
#pragma comment(lib,"d3d11.lib")
#define D3D11_NO_HELPERS
#include <d3d11.h>
@@ -153,7 +152,7 @@ VPLDX11AccelerationPolicy::surface_weak_ptr_t VPLDX11AccelerationPolicy::get_fre
}
size_t VPLDX11AccelerationPolicy::get_free_surface_count(pool_key_t) const {
GAPI_Assert(false && "get_free_surface_count() is not implemented");
GAPI_Error("get_free_surface_count() is not implemented");
}
size_t VPLDX11AccelerationPolicy::get_surface_count(pool_key_t key) const {
@@ -449,39 +448,39 @@ namespace wip {
namespace onevpl {
VPLDX11AccelerationPolicy::VPLDX11AccelerationPolicy(device_selector_ptr_t selector) :
VPLAccelerationPolicy(selector) {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
VPLDX11AccelerationPolicy::~VPLDX11AccelerationPolicy() = default;
void VPLDX11AccelerationPolicy::init(session_t ) {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
void VPLDX11AccelerationPolicy::deinit(session_t) {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
VPLDX11AccelerationPolicy::pool_key_t VPLDX11AccelerationPolicy::create_surface_pool(const mfxFrameAllocRequest&,
mfxFrameInfo&) {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
VPLDX11AccelerationPolicy::surface_weak_ptr_t VPLDX11AccelerationPolicy::get_free_surface(pool_key_t) {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
size_t VPLDX11AccelerationPolicy::get_free_surface_count(pool_key_t) const {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
size_t VPLDX11AccelerationPolicy::get_surface_count(pool_key_t) const {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
cv::MediaFrame::AdapterPtr VPLDX11AccelerationPolicy::create_frame_adapter(pool_key_t,
const FrameConstructorArgs &) {
GAPI_Assert(false && "VPLDX11AccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLDX11AccelerationPolicy unavailable in current configuration");
}
} // namespace onevpl
} // namespace wip
@@ -39,10 +39,17 @@ VPLVAAPIAccelerationPolicy::VPLVAAPIAccelerationPolicy(device_selector_ptr_t sel
va_handle = reinterpret_cast<VADisplay>(devices.begin()->second.get_ptr());
#else // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
}
#else // __linux__
VPLVAAPIAccelerationPolicy::VPLVAAPIAccelerationPolicy(device_selector_ptr_t selector) :
VPLAccelerationPolicy(selector) {
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
#endif // __linux__
#if defined(HAVE_VA) || defined(HAVE_VA_INTEL)
VPLVAAPIAccelerationPolicy::~VPLVAAPIAccelerationPolicy() {
vaTerminate(va_handle);
GAPI_LOG_INFO(nullptr, "destroyed");
@@ -90,45 +97,40 @@ cv::MediaFrame::AdapterPtr VPLVAAPIAccelerationPolicy::create_frame_adapter(pool
return cpu_dispatcher->create_frame_adapter(key, params);
}
#else // __linux__
VPLVAAPIAccelerationPolicy::VPLVAAPIAccelerationPolicy(device_selector_ptr_t selector) :
VPLAccelerationPolicy(selector) {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
#else // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
VPLVAAPIAccelerationPolicy::~VPLVAAPIAccelerationPolicy() = default;
void VPLVAAPIAccelerationPolicy::init(session_t ) {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
void VPLVAAPIAccelerationPolicy::deinit(session_t) {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
VPLVAAPIAccelerationPolicy::pool_key_t VPLVAAPIAccelerationPolicy::create_surface_pool(const mfxFrameAllocRequest&,
mfxFrameInfo&) {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
VPLVAAPIAccelerationPolicy::surface_weak_ptr_t VPLVAAPIAccelerationPolicy::get_free_surface(pool_key_t) {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
size_t VPLVAAPIAccelerationPolicy::get_free_surface_count(pool_key_t) const {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
size_t VPLVAAPIAccelerationPolicy::get_surface_count(pool_key_t) const {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
cv::MediaFrame::AdapterPtr VPLVAAPIAccelerationPolicy::create_frame_adapter(pool_key_t,
const FrameConstructorArgs &) {
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current configuration");
}
#endif // __linux__
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
} // namespace onevpl
} // namespace wip
} // namespace gapi
@@ -46,7 +46,7 @@ size_t LockAdapter::read_lock(mfxMemId mid, mfxFrameData &data) {
// adapter will throw error if VPL frame allocator fails
if (sts != MFX_ERR_NONE) {
impl->unlock_shared();
GAPI_Assert(false && "Cannot lock frame on READ using VPL allocator");
GAPI_Error("Cannot lock frame on READ using VPL allocator");
}
return prev_lock_count;
@@ -76,7 +76,7 @@ void LockAdapter::write_lock(mfxMemId mid, mfxFrameData &data) {
// adapter will throw error if VPL frame allocator fails
if (sts != MFX_ERR_NONE) {
impl->unlock();
GAPI_Assert(false && "Cannot lock frame on WRITE using VPL allocator");
GAPI_Error("Cannot lock frame on WRITE using VPL allocator");
}
}
@@ -199,13 +199,13 @@ void DX11AllocationItem::on_first_in_impl(mfxFrameData *ptr) {
err = shared_device_context->Map(get_staging_texture_ptr(), 0, mapType, mapFlags, &lockedRect);
if (S_OK != err && DXGI_ERROR_WAS_STILL_DRAWING != err) {
GAPI_LOG_WARNING(nullptr, "Cannot Map staging texture in device context, error: " << std::to_string(HRESULT_CODE(err)));
GAPI_Assert(false && "Cannot Map staging texture in device context");
GAPI_Error("Cannot Map staging texture in device context");
}
} while (DXGI_ERROR_WAS_STILL_DRAWING == err);
if (FAILED(err)) {
GAPI_LOG_WARNING(nullptr, "Cannot lock frame");
GAPI_Assert(false && "Cannot lock frame");
GAPI_Error("Cannot lock frame");
return ;
}
@@ -13,7 +13,6 @@
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
#pragma comment(lib,"d3d11.lib")
#define D3D11_NO_HELPERS
#define NOMINMAX
@@ -65,7 +65,6 @@ MediaFrame::View VPLMediaFrameCPUAdapter::access(MediaFrame::Access) {
cv::util::any VPLMediaFrameCPUAdapter::blobParams() const {
throw std::runtime_error("VPLMediaFrameCPUAdapter::blobParams() is not implemented");
return {};
}
void VPLMediaFrameCPUAdapter::serialize(cv::gapi::s11n::IOStream&) {
@@ -114,17 +114,24 @@ MediaFrame::View VPLMediaFrameDX11Adapter::access(MediaFrame::Access mode) {
}
}
cv::util::any VPLMediaFrameDX11Adapter::blobParams() const {
/*GAPI_Assert(false && "VPLMediaFrameDX11Adapter::blobParams() is not fully integrated"
"in OpenVINO InferenceEngine and would be temporary disable.");*/
#ifdef HAVE_INF_ENGINE
mfxHDLPair VPLMediaFrameDX11Adapter::getHandle() const {
auto surface_ptr_copy = get_surface();
Surface::data_t& data = surface_ptr_copy->get_data();
const Surface::info_t& info = surface_ptr_copy->get_info();
const Surface::data_t& data = surface_ptr_copy->get_data();
NativeHandleAdapter* native_handle_getter = reinterpret_cast<NativeHandleAdapter*>(data.MemId);
mfxHDLPair handle{};
native_handle_getter->get_handle(data.MemId, reinterpret_cast<mfxHDL&>(handle));
return handle;
}
cv::util::any VPLMediaFrameDX11Adapter::blobParams() const {
/*GAPI_Error("VPLMediaFrameDX11Adapter::blobParams() is not fully integrated"
"in OpenVINO InferenceEngine and would be temporary disable.");*/
#ifdef HAVE_INF_ENGINE
mfxHDLPair handle = getHandle();
auto surface_ptr_copy = get_surface();
const Surface::info_t& info = surface_ptr_copy->get_info();
GAPI_Assert(frame_desc.fmt == MediaFormat::NV12 &&
"blobParams() for VPLMediaFrameDX11Adapter supports NV12 only");
@@ -155,16 +162,16 @@ cv::util::any VPLMediaFrameDX11Adapter::blobParams() const {
return std::make_pair(std::make_pair(y_tdesc, y_params),
std::make_pair(uv_tdesc, uv_params));
#else
GAPI_Assert(false && "VPLMediaFrameDX11Adapter::blobParams() is not implemented");
GAPI_Error("VPLMediaFrameDX11Adapter::blobParams() is not implemented");
#endif // HAVE_INF_ENGINE
}
void VPLMediaFrameDX11Adapter::serialize(cv::gapi::s11n::IOStream&) {
GAPI_Assert(false && "VPLMediaFrameDX11Adapter::serialize() is not implemented");
GAPI_Error("VPLMediaFrameDX11Adapter::serialize() is not implemented");
}
void VPLMediaFrameDX11Adapter::deserialize(cv::gapi::s11n::IIStream&) {
GAPI_Assert(false && "VPLMediaFrameDX11Adapter::deserialize() is not implemented");
GAPI_Error("VPLMediaFrameDX11Adapter::deserialize() is not implemented");
}
DXGI_FORMAT VPLMediaFrameDX11Adapter::get_dx11_color_format(uint32_t mfx_fourcc) {
@@ -37,6 +37,11 @@ public:
GAPI_EXPORTS ~VPLMediaFrameDX11Adapter();
MediaFrame::View access(MediaFrame::Access) override;
// FIXME: Consider a better solution since this approach
// is not easily extendable for other adapters (oclcore.cpp)
// FIXME: Use with caution since the handle might become invalid
// due to reference counting
mfxHDLPair getHandle() const;
// The default implementation does nothing
cv::util::any blobParams() const override;
void serialize(cv::gapi::s11n::IOStream&) override;
@@ -17,26 +17,23 @@
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
#pragma comment(lib,"d3d11.lib")
// get rid of generate macro max/min/etc from DX side
#define D3D11_NO_HELPERS
#define NOMINMAX
#include <d3d11.h>
#include <d3d11_4.h>
#pragma comment(lib, "dxgi")
#undef D3D11_NO_HELPERS
#undef NOMINMAX
#endif // HAVE_D3D11
#endif // HAVE_DIRECTX
#ifdef __linux__
#include <fcntl.h>
#include <unistd.h>
#if defined(HAVE_VA) || defined(HAVE_VA_INTEL)
#include "va/va.h"
#include "va/va_drm.h"
#include <fcntl.h>
#include <unistd.h>
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
#endif // __linux__
@@ -247,10 +244,10 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(const CfgParams& cfg_params) :
suggested_device = IDeviceSelector::create<Device>(va_handle, "GPU", AccelType::VAAPI);
suggested_context = IDeviceSelector::create<Context>(nullptr, AccelType::VAAPI);
#else // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current linux configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current linux configuration");
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
#else // #ifdef __linux__
GAPI_Assert(false && "MFX_IMPL_VIA_VAAPI is supported on linux only");
GAPI_Error("MFX_IMPL_VIA_VAAPI is supported on linux only");
#endif // #ifdef __linux__
break;
}
@@ -338,10 +335,10 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(Device::Ptr device_ptr,
suggested_device = IDeviceSelector::create<Device>(device_ptr, device_id, AccelType::VAAPI);
suggested_context = IDeviceSelector::create<Context>(nullptr, AccelType::VAAPI);
#else // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current linux configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current linux configuration");
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
#else // #ifdef __linux__
GAPI_Assert(false && "MFX_IMPL_VIA_VAAPI is supported on linux only");
GAPI_Error("MFX_IMPL_VIA_VAAPI is supported on linux only");
#endif // #ifdef __linux__
break;
}
@@ -397,10 +394,10 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(const Device &device,
case AccelType::VAAPI:
#ifdef __linux__
#if !defined(HAVE_VA) || !defined(HAVE_VA_INTEL)
GAPI_Assert(false && "VPLVAAPIAccelerationPolicy unavailable in current linux configuration");
GAPI_Error("VPLVAAPIAccelerationPolicy unavailable in current linux configuration");
#endif // defined(HAVE_VA) || defined(HAVE_VA_INTEL)
#else // #ifdef __linux__
GAPI_Assert(false && "MFX_IMPL_VIA_VAAPI is supported on linux only");
GAPI_Error("MFX_IMPL_VIA_VAAPI is supported on linux only");
#endif // #ifdef __linux__
break;
case AccelType::HOST:
@@ -20,7 +20,7 @@ namespace gapi {
namespace wip {
namespace onevpl {
class PlatformSpecificParams;
struct PlatformSpecificParams;
std::vector<CfgParam> update_param_with_accel_type(std::vector<CfgParam> &&param_array, AccelType type);
struct GAPI_EXPORTS CfgParamDeviceSelector final: public IDeviceSelector {
@@ -60,7 +60,7 @@ private:
return ret;
}
mfxVariant create_impl(const std::string&, const std::string&) {
GAPI_Assert(false && "Something wrong: you should not create mfxVariant "
GAPI_Error("Something wrong: you should not create mfxVariant "
"from string directly - native type is lost in this case");
}
};
@@ -173,7 +173,7 @@ void extract_optional_param_by_name(const std::string &name,
[&out_param](int64_t value) { out_param = cv::util::make_optional(static_cast<size_t>(value)); },
[&out_param](float_t value) { out_param = cv::util::make_optional(static_cast<size_t>(value)); },
[&out_param](double_t value) { out_param = cv::util::make_optional(static_cast<size_t>(value)); },
[&out_param](void*) { GAPI_Assert(false && "`void*` is unsupported type"); },
[&out_param](void*) { GAPI_Error("`void*` is unsupported type"); },
[&out_param](const std::string& value) {
out_param = cv::util::make_optional(strtoull_or_throw(value.c_str()));
}),
@@ -189,7 +189,7 @@ unsigned long strtoul_or_throw(const char* str) {
((ret == ULONG_MAX) && errno == ERANGE)) {
// nothing parsed from the string, handle errors or exit
GAPI_LOG_WARNING(nullptr, "strtoul failed for: " << str);
GAPI_Assert(false && "strtoul_or_throw");
GAPI_Error("strtoul_or_throw");
}
return ret;
}
@@ -202,7 +202,7 @@ size_t strtoull_or_throw(const char* str) {
((ret == ULLONG_MAX) && errno == ERANGE)) {
// nothing parsed from the string, handle errors or exit
GAPI_LOG_WARNING(nullptr, "strtoull failed for: " << str);
GAPI_Assert(false && "strtoull_or_throw");
GAPI_Error("strtoull_or_throw");
}
return ret;
}
@@ -215,7 +215,7 @@ int64_t strtoll_or_throw(const char* str) {
((ret == LONG_MAX || ret == LONG_MIN) && errno == ERANGE)) {
// nothing parsed from the string, handle errors or exit
GAPI_LOG_WARNING(nullptr, "strtoll failed for: " << str);
GAPI_Assert(false && "strtoll_or_throw");
GAPI_Error("strtoll_or_throw");
}
return ret;
}
@@ -18,7 +18,7 @@ struct IDataProvider::mfx_bitstream : public mfxBitstream {};
#else // HAVE_ONEVPL
struct IDataProvider::mfx_bitstream {
mfx_bitstream() {
GAPI_Assert(false && "Reject to create `mfxBitstream` because library compiled without VPL/MFX support");
GAPI_Error("Reject to create `mfxBitstream` because library compiled without VPL/MFX support");
}
};
#endif // HAVE_ONEVPL
@@ -0,0 +1,51 @@
// 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) 2022 Intel Corporation
#include <iostream>
#include <memory>
#include <opencv2/gapi/streaming/onevpl/default.hpp>
#include <opencv2/gapi/streaming/onevpl/cfg_params.hpp>
#include <opencv2/gapi/streaming/onevpl/device_selector_interface.hpp>
#include "cfg_param_device_selector.hpp"
#ifdef HAVE_ONEVPL
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
std::shared_ptr<IDeviceSelector> getDefaultDeviceSelector(const std::vector<CfgParam>& cfg_params) {
std::shared_ptr<CfgParamDeviceSelector> default_accel_contex(new CfgParamDeviceSelector(cfg_params));
return default_accel_contex;
}
} // namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv
#else // HAVE_ONEVPL
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
std::shared_ptr<IDeviceSelector> getDefaultDeviceSelector(const std::vector<CfgParam>&) {
std::cerr << "Cannot utilize getDefaultVPLDeviceAndCtx without HAVE_ONEVPL enabled" << std::endl;
util::throw_error(std::logic_error("Cannot utilize getDefaultVPLDeviceAndCtx without HAVE_ONEVPL enabled"));
}
} // namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // HAVE_ONEVPL
@@ -5,14 +5,6 @@
// Copyright (C) 2021 Intel Corporation
#ifdef HAVE_ONEVPL
#include <errno.h>
#ifdef _WIN32
#pragma comment(lib, "Mf.lib")
#pragma comment(lib, "Mfuuid.lib")
#pragma comment(lib, "Mfplat.lib")
#pragma comment(lib, "shlwapi.lib")
#pragma comment(lib, "mfreadwrite.lib")
#endif // _WIN32
#include <opencv2/gapi/own/assert.hpp>
#include "streaming/onevpl/demux/async_mfp_demux_data_provider.hpp"
@@ -753,7 +745,7 @@ bool MFPAsyncDemuxDataProvider::fetch_bitstream_data(std::shared_ptr<mfx_bitstre
GAPI_LOG_WARNING(nullptr, "[" << this << "] " <<
"cannot find appropriate dmux buffer by key: " <<
static_cast<void*>(out_bitsream->Data));
GAPI_Assert(false && "invalid bitstream key");
GAPI_Error("invalid bitstream key");
}
if (it->second) {
it->second->Unlock();
@@ -796,20 +788,20 @@ bool MFPAsyncDemuxDataProvider::empty() const {
#else // _WIN32
MFPAsyncDemuxDataProvider::MFPAsyncDemuxDataProvider(const std::string&) {
GAPI_Assert(false && "Unsupported: Microsoft Media Foundation is not available");
GAPI_Error("Unsupported: Microsoft Media Foundation is not available");
}
IDataProvider::mfx_codec_id_type MFPAsyncDemuxDataProvider::get_mfx_codec_id() const {
GAPI_Assert(false && "Unsupported: Microsoft Media Foundation is not available");
GAPI_Error("Unsupported: Microsoft Media Foundation is not available");
return std::numeric_limits<mfx_codec_id_type>::max();
}
bool MFPAsyncDemuxDataProvider::fetch_bitstream_data(std::shared_ptr<mfx_bitstream> &) {
GAPI_Assert(false && "Unsupported: Microsoft Media Foundation is not available");
GAPI_Error("Unsupported: Microsoft Media Foundation is not available");
return false;
}
bool MFPAsyncDemuxDataProvider::empty() const {
GAPI_Assert(false && "Unsupported: Microsoft Media Foundation is not available");
GAPI_Error("Unsupported: Microsoft Media Foundation is not available");
return true;
}
#endif // _WIN32
@@ -190,7 +190,7 @@ VPLLegacyDecodeEngine::SessionParam VPLLegacyDecodeEngine::prepare_session_param
// TODO make proper direction
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
} else {
GAPI_Assert(false && "unsupported AccelType from device selector");
GAPI_Error("unsupported AccelType from device selector");
}
// try fetch & decode input data
@@ -251,7 +251,8 @@ VPLLegacyDecodeEngine::SessionParam VPLLegacyDecodeEngine::prepare_session_param
}
decRequest.Type |= MFX_MEMTYPE_EXTERNAL_FRAME | MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_FROM_VPPIN;
decRequest.Type |= MFX_MEMTYPE_EXTERNAL_FRAME | MFX_MEMTYPE_FROM_DECODE |
MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_SHARED_RESOURCE;
VPLAccelerationPolicy::pool_key_t decode_pool_key =
acceleration_policy->create_surface_pool(decRequest, mfxDecParams.mfx.FrameInfo);
@@ -66,7 +66,7 @@ pp_session VPPPreprocDispatcher::initialize_preproc(const pp_params& initial_fra
return sess;
}
}
GAPI_Assert(false && "Cannot initialize VPP preproc in dispatcher, no suitable worker");
GAPI_Error("Cannot initialize VPP preproc in dispatcher, no suitable worker");
}
cv::MediaFrame VPPPreprocDispatcher::run_sync(const pp_session &session_handle,
@@ -80,7 +80,7 @@ cv::MediaFrame VPPPreprocDispatcher::run_sync(const pp_session &session_handle,
return w->run_sync(session_handle, in_frame, opt_roi);
}
}
GAPI_Assert(false && "Cannot invoke VPP preproc in dispatcher, no suitable worker");
GAPI_Error("Cannot invoke VPP preproc in dispatcher, no suitable worker");
}
#else // HAVE_ONEVPL
@@ -90,13 +90,13 @@ cv::util::optional<pp_params> VPPPreprocDispatcher::is_applicable(const cv::Medi
pp_session VPPPreprocDispatcher::initialize_preproc(const pp_params&,
const GFrameDesc&) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
cv::MediaFrame VPPPreprocDispatcher::run_sync(const pp_session &,
const cv::MediaFrame&,
const cv::util::optional<cv::Rect> &) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
#endif // HAVE_ONEVPL
} // namespace onevpl
@@ -249,13 +249,13 @@ pp_session VPPPreprocEngine::initialize_preproc(const pp_params& initial_frame_p
sts = MFXCreateSession(mfx_handle, impl_number, &mfx_vpp_session);
if (sts != MFX_ERR_NONE) {
GAPI_LOG_WARNING(nullptr, "Cannot clone VPP session, error: " << mfxstatus_to_string(sts));
GAPI_Assert(false && "Cannot continue VPP preprocessing");
GAPI_Error("Cannot continue VPP preprocessing");
}
sts = MFXJoinSession(params.handle, mfx_vpp_session);
if (sts != MFX_ERR_NONE) {
GAPI_LOG_WARNING(nullptr, "Cannot join VPP sessions, error: " << mfxstatus_to_string(sts));
GAPI_Assert(false && "Cannot continue VPP preprocessing");
GAPI_Error("Cannot continue VPP preprocessing");
}
GAPI_LOG_INFO(nullptr, "[" << mfx_vpp_session << "] starting pool allocation");
@@ -281,7 +281,7 @@ pp_session VPPPreprocEngine::initialize_preproc(const pp_params& initial_frame_p
vppRequests[1].AllocId = std::numeric_limits<uint16_t>::max() - request_id++;
GAPI_Assert(request_id != std::numeric_limits<uint16_t>::max() && "Something wrong");
vppRequests[1].Type |= MFX_MEMTYPE_FROM_VPPIN;
vppRequests[1].Type |= MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_SHARED_RESOURCE;
vpp_out_pool_key = acceleration_policy->create_surface_pool(vppRequests[1],
mfxVPPParams.vpp.Out);
@@ -301,7 +301,7 @@ pp_session VPPPreprocEngine::initialize_preproc(const pp_params& initial_frame_p
}
} catch (const std::exception&) {
MFXClose(mfx_vpp_session);
GAPI_Assert(false && "Cannot init preproc resources");
GAPI_Error("Cannot init preproc resources");
}
// create engine session after all
@@ -28,7 +28,7 @@ cv::MediaFormat fourcc_to_MediaFormat(int value) {
default:
GAPI_LOG_WARNING(nullptr, "Unsupported FourCC format requested: " << value <<
". Cannot cast to cv::MediaFrame");
GAPI_Assert(false && "Unsupported FOURCC");
GAPI_Error("Unsupported FOURCC");
}
}
@@ -44,7 +44,7 @@ int MediaFormat_to_fourcc(cv::MediaFormat value) {
GAPI_LOG_WARNING(nullptr, "Unsupported cv::MediaFormat format requested: " <<
static_cast<typename std::underlying_type<cv::MediaFormat>::type>(value) <<
". Cannot cast to FourCC");
GAPI_Assert(false && "Unsupported cv::MediaFormat");
GAPI_Error("Unsupported cv::MediaFormat");
}
}
int MediaFormat_to_chroma(cv::MediaFormat value) {
@@ -58,7 +58,7 @@ int MediaFormat_to_chroma(cv::MediaFormat value) {
GAPI_LOG_WARNING(nullptr, "Unsupported cv::MediaFormat format requested: " <<
static_cast<typename std::underlying_type<cv::MediaFormat>::type>(value) <<
". Cannot cast to ChromaFormateIdc");
GAPI_Assert(false && "Unsupported cv::MediaFormat");
GAPI_Error("Unsupported cv::MediaFormat");
}
}
@@ -30,7 +30,7 @@ namespace wip {
template<typename SpecificPreprocEngine, typename ...PreprocEngineArgs >
std::unique_ptr<SpecificPreprocEngine>
IPreprocEngine::create_preproc_engine_impl(const PreprocEngineArgs& ...) {
GAPI_Assert(false && "Unsupported ");
GAPI_Error("Unsupported ");
}
template <>
@@ -91,7 +91,7 @@ IPreprocEngine::create_preproc_engine_impl(const onevpl::Device &device,
}
if (!pp_is_created) {
GAPI_LOG_WARNING(nullptr, "Cannot create VPP preprocessing engine: configuration unsupported");
GAPI_Assert(false && "VPP preproc unsupported");
GAPI_Error("VPP preproc unsupported");
}
#endif // HAVE_ONEVPL
return dispatcher;
@@ -404,7 +404,7 @@ void VPLLegacyTranscodeEngine::validate_vpp_param(const mfxVideoParam& mfxVPPPar
" must be less or equal to \"" <<
CfgParam::vpp_in_width_name() << "\": " <<
mfxVPPParams.vpp.In.Width);
GAPI_Assert(false && "Invalid VPP params combination: Width & Crop");
GAPI_Error("Invalid VPP params combination: Width & Crop");
}
if (mfxVPPParams.vpp.In.Height < mfxVPPParams.vpp.In.CropH + mfxVPPParams.vpp.In.CropY) {
@@ -416,7 +416,7 @@ void VPLLegacyTranscodeEngine::validate_vpp_param(const mfxVideoParam& mfxVPPPar
" must be less or equal to \"" <<
CfgParam::vpp_in_height_name() << "\": " <<
mfxVPPParams.vpp.In.Height);
GAPI_Assert(false && "Invalid VPP params combination: Height & Crop");
GAPI_Error("Invalid VPP params combination: Height & Crop");
}
if (mfxVPPParams.vpp.Out.Width < mfxVPPParams.vpp.Out.CropW + mfxVPPParams.vpp.Out.CropX) {
@@ -428,7 +428,7 @@ void VPLLegacyTranscodeEngine::validate_vpp_param(const mfxVideoParam& mfxVPPPar
" must be less or equal to \"" <<
CfgParam::vpp_out_width_name() << "\": " <<
mfxVPPParams.vpp.Out.Width);
GAPI_Assert(false && "Invalid VPP params combination: Width & Crop");
GAPI_Error("Invalid VPP params combination: Width & Crop");
}
if (mfxVPPParams.vpp.Out.Height < mfxVPPParams.vpp.Out.CropH + mfxVPPParams.vpp.Out.CropY) {
@@ -440,7 +440,7 @@ void VPLLegacyTranscodeEngine::validate_vpp_param(const mfxVideoParam& mfxVPPPar
" must be less or equal to \"" <<
CfgParam::vpp_out_height_name() << "\": " <<
mfxVPPParams.vpp.Out.Height);
GAPI_Assert(false && "Invalid VPP params combination: Height & Crop");
GAPI_Error("Invalid VPP params combination: Height & Crop");
}
GAPI_LOG_INFO(nullptr, "Finished VPP param validation");
@@ -127,26 +127,23 @@ FileDataProvider::FileDataProvider(const std::string&,
source_handle(nullptr, &fclose),
codec(std::numeric_limits<mfx_codec_id_type>::max()),
bitstream_data_size(bitstream_data_size_value) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
FileDataProvider::~FileDataProvider() = default;
IDataProvider::mfx_codec_id_type FileDataProvider::get_mfx_codec_id() const {
cv::util::suppress_unused_warning(codec);
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
return codec;
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
bool FileDataProvider::fetch_bitstream_data(std::shared_ptr<mfx_bitstream> &) {
cv::util::suppress_unused_warning(bitstream_data_size);
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
return false;
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
bool FileDataProvider::empty() const {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
return true;
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
#endif // HAVE_ONEVPL
} // namespace onevpl
+7 -7
View File
@@ -73,33 +73,33 @@ GSource::GSource(std::shared_ptr<IDataProvider> source,
#else
GSource::GSource(const std::string&, const CfgParams&) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
GSource::GSource(const std::string&, const CfgParams&, const std::string&,
void*, void*) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
GSource::GSource(const std::string&, const CfgParams&, const Device &, const Context &) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
GSource::GSource(const std::string&, const CfgParams&, std::shared_ptr<IDeviceSelector>) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
GSource::GSource(std::shared_ptr<IDataProvider>, const CfgParams&) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
GSource::GSource(std::shared_ptr<IDataProvider>, const CfgParams&,
const std::string&, void*, void*) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
GSource::GSource(std::shared_ptr<IDataProvider>, const CfgParams&, std::shared_ptr<IDeviceSelector>) {
GAPI_Assert(false && "Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
GAPI_Error("Unsupported: G-API compiled without `WITH_GAPI_ONEVPL=ON`");
}
#endif
@@ -109,7 +109,7 @@ GSource::Priv::Priv(std::shared_ptr<IDataProvider> provider,
GAPI_LOG_WARNING(nullptr, "MFXSetConfigFilterProperty failed, error: " <<
mfxstatus_to_string(sts) <<
" - for \"" << cfg_param_it->get_name() << "\"");
GAPI_Assert(false && "MFXSetConfigFilterProperty failed");
GAPI_Error("MFXSetConfigFilterProperty failed");
}
mfx_param.Type = MFX_VARIANT_TYPE_U32;
@@ -123,7 +123,7 @@ GSource::Priv::Priv(std::shared_ptr<IDataProvider> provider,
GAPI_LOG_WARNING(nullptr, "MFXSetConfigFilterProperty failed, error: " <<
mfxstatus_to_string(sts) <<
" - for \"mfxImplDescription.mfxVPPDescription.filter.FilterFourCC\"");
GAPI_Assert(false && "MFXSetConfigFilterProperty failed");
GAPI_Error("MFXSetConfigFilterProperty failed");
}
++cfg_param_it;
@@ -227,16 +227,15 @@ GSource::Priv::Priv(std::shared_ptr<IDataProvider> provider,
// TODO Add factory static method in ProcessingEngineBase
if (mfx_impl_description->ApiVersion.Major >= VPL_NEW_API_MAJOR_VERSION) {
GAPI_Assert(false &&
GAPI_LOG_WARNING(NULL,
"GSource mfx_impl_description->ApiVersion.Major >= VPL_NEW_API_MAJOR_VERSION"
" - is not implemented");
" - is not implemented. Rollback to MFX implementation");
}
const auto& transcode_params = VPLLegacyTranscodeEngine::get_vpp_params(preferred_params);
if (!transcode_params.empty()) {
engine.reset(new VPLLegacyTranscodeEngine(std::move(acceleration)));
} else {
const auto& transcode_params = VPLLegacyTranscodeEngine::get_vpp_params(preferred_params);
if (!transcode_params.empty()) {
engine.reset(new VPLLegacyTranscodeEngine(std::move(acceleration)));
} else {
engine.reset(new VPLLegacyDecodeEngine(std::move(acceleration)));
}
engine.reset(new VPLLegacyDecodeEngine(std::move(acceleration)));
}
}
@@ -318,7 +317,7 @@ std::unique_ptr<VPLAccelerationPolicy> GSource::Priv::initializeHWAccel(std::sha
GAPI_LOG_WARNING(nullptr, "Cannot initialize HW Accel: "
"invalid accelerator type: " <<
std::to_string(accel_mode.Data.U32));
GAPI_Assert(false && "Cannot initialize HW Accel");
GAPI_Error("Cannot initialize HW Accel");
}
}
@@ -429,4 +429,5 @@ std::string ext_mem_frame_type_to_cstr(int type) {
} // namespace wip
} // namespace gapi
} // namespace cv
#endif // HAVE_ONEVPL