mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
Improve UX: autofill cfg param with proper accel type, printout cfg params
This commit is contained in:
parent
b3b235ebc0
commit
3635b3dee7
@ -185,6 +185,8 @@ struct GAPI_EXPORTS CfgParam {
|
||||
const name_t& get_name() const;
|
||||
const value_t& get_value() const;
|
||||
bool is_major() const;
|
||||
std::string to_string() const;
|
||||
|
||||
bool operator==(const CfgParam& rhs) const;
|
||||
bool operator< (const CfgParam& rhs) const;
|
||||
bool operator!=(const CfgParam& rhs) const;
|
||||
|
@ -59,7 +59,7 @@ const std::string keys =
|
||||
"{ vpp_frames_pool_size | 0 | OneVPL source applies this parameter as preallocated frames pool size for VPP preprocessing results}"
|
||||
"{ roi | -1,-1,-1,-1 | Region of interest (ROI) to use for inference. Identified automatically when not set }"
|
||||
"{ source_device | CPU | choose device for decoding }"
|
||||
"{ preproc_device | CPU | choose device for preprocessing }";
|
||||
"{ preproc_device | | choose device for preprocessing }";
|
||||
|
||||
|
||||
namespace {
|
||||
@ -609,11 +609,6 @@ int main(int argc, char *argv[]) {
|
||||
if (is_gpu(source_device)) {
|
||||
std::cout << "enforce VPL Source deconding on device: " << source_device << std::endl;
|
||||
// use special 'Device' constructor for `onevpl::GSource`
|
||||
// put accel type description for VPL source
|
||||
source_cfgs.push_back(cfg::create_from_string(
|
||||
"mfxImplDescription.AccelerationMode"
|
||||
":"
|
||||
"MFX_ACCEL_MODE_VIA_D3D11"));
|
||||
cap = cv::gapi::wip::make_onevpl_src(file_path, source_cfgs,
|
||||
gpu_accel_device.value(),
|
||||
gpu_accel_ctx.value());
|
||||
|
@ -28,6 +28,7 @@ VPLVAAPIAccelerationPolicy::VPLVAAPIAccelerationPolicy(device_selector_ptr_t sel
|
||||
VPLAccelerationPolicy(selector),
|
||||
cpu_dispatcher(new VPLCPUAccelerationPolicy(selector)),
|
||||
va_handle() {
|
||||
GAPI_LOG_INFO(nullptr, "created - TODO dispatchered on CPU acceleration");
|
||||
#if defined(HAVE_VA) || defined(HAVE_VA_INTEL)
|
||||
// setup VAAPI device
|
||||
IDeviceSelector::DeviceScoreTable devices = get_device_selector()->select_devices();
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
struct Aux {};
|
||||
#endif
|
||||
|
||||
static std::vector<CfgParam> insertCfgparam(std::vector<CfgParam> &¶m_array, AccelType type) {
|
||||
std::vector<CfgParam> update_param_with_accel_type(std::vector<CfgParam> &¶m_array, AccelType type) {
|
||||
switch (type) {
|
||||
case AccelType::HOST:
|
||||
break;
|
||||
|
@ -21,6 +21,8 @@ namespace wip {
|
||||
namespace onevpl {
|
||||
|
||||
class Aux;
|
||||
std::vector<CfgParam> update_param_with_accel_type(std::vector<CfgParam> &¶m_array, AccelType type);
|
||||
|
||||
struct GAPI_EXPORTS CfgParamDeviceSelector final: public IDeviceSelector {
|
||||
CfgParamDeviceSelector(const CfgParams& params = {});
|
||||
CfgParamDeviceSelector(Device::Ptr device_ptr,
|
||||
|
@ -4,6 +4,7 @@
|
||||
//
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
|
||||
#include <sstream>
|
||||
#include <opencv2/gapi/util/throw.hpp>
|
||||
|
||||
#include <opencv2/gapi/streaming/onevpl/cfg_params.hpp>
|
||||
@ -25,6 +26,15 @@ struct variant_comparator : cv::util::static_visitor<bool, variant_comparator> {
|
||||
private:
|
||||
const CfgParam::value_t& rhs;
|
||||
};
|
||||
|
||||
struct variant_stringifier : cv::util::static_visitor<std::string, variant_stringifier> {
|
||||
template<typename ValueType>
|
||||
std::string visit(const ValueType& lhs) const {
|
||||
std::stringstream ss;
|
||||
ss << lhs;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
} // namespace util
|
||||
|
||||
struct CfgParam::Priv {
|
||||
@ -228,6 +238,11 @@ bool CfgParam::is_major() const {
|
||||
return m_priv->is_major_impl();
|
||||
}
|
||||
|
||||
std::string CfgParam::to_string() const {
|
||||
return get_name() + ":" + cv::util::visit(util::variant_stringifier{},
|
||||
get_value());
|
||||
}
|
||||
|
||||
bool CfgParam::operator< (const CfgParam& rhs) const {
|
||||
return *m_priv < *rhs.m_priv;
|
||||
}
|
||||
|
@ -186,6 +186,9 @@ VPLLegacyDecodeEngine::SessionParam VPLLegacyDecodeEngine::prepare_session_param
|
||||
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
|
||||
} else if (accel_type == AccelType::HOST) {
|
||||
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
|
||||
} else if (accel_type == AccelType::VAAPI) {
|
||||
// TODO make proper direction
|
||||
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
|
||||
} else {
|
||||
GAPI_Assert(false && "unsupported AccelType from device selector");
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ GSource::GSource(const std::string& filePath,
|
||||
GSource::GSource(const std::string& filePath,
|
||||
const CfgParams& cfg_params,
|
||||
const Device &device, const Context &ctx) :
|
||||
GSource(filePath, cfg_params,
|
||||
GSource(filePath, update_param_with_accel_type(CfgParams{cfg_params}, device.get_type()),
|
||||
std::make_shared<CfgParamDeviceSelector>(device, ctx, cfg_params)) {
|
||||
}
|
||||
|
||||
|
@ -94,12 +94,12 @@ GSource::Priv::Priv(std::shared_ptr<IDataProvider> provider,
|
||||
GAPI_Assert(cfg_inst && "MFXCreateConfig failed");
|
||||
|
||||
if (!cfg_param_it->is_major()) {
|
||||
GAPI_LOG_DEBUG(nullptr, "Skip not major param: " << cfg_param_it->get_name());
|
||||
GAPI_LOG_DEBUG(nullptr, "Skip not major param: " << cfg_param_it->to_string());
|
||||
++cfg_param_it;
|
||||
continue;
|
||||
}
|
||||
|
||||
GAPI_LOG_DEBUG(nullptr, "Apply major param: " << cfg_param_it->get_name());
|
||||
GAPI_LOG_DEBUG(nullptr, "Apply major param: " << cfg_param_it->to_string());
|
||||
mfxVariant mfx_param = cfg_param_to_mfx_variant(*cfg_param_it);
|
||||
mfxStatus sts = MFXSetConfigFilterProperty(cfg_inst,
|
||||
(mfxU8 *)cfg_param_it->get_name().c_str(),
|
||||
@ -189,8 +189,14 @@ GSource::Priv::Priv(std::shared_ptr<IDataProvider> provider,
|
||||
|
||||
// Extract the most suitable VPL implementation by max score
|
||||
auto max_match_it = matches_count.rbegin();
|
||||
GAPI_Assert(max_match_it != matches_count.rend() &&
|
||||
"Cannot find matched MFX implementation for requested configuration");
|
||||
if (max_match_it == matches_count.rend()) {
|
||||
std::stringstream ss;
|
||||
for (const auto &p : cfg_params) {
|
||||
ss << p.to_string() << std::endl;
|
||||
}
|
||||
GAPI_LOG_WARNING(nullptr, "No one suitable MFX implementation is found, requested params:\n" << ss.str());
|
||||
throw std::runtime_error("Cannot find any suitable MFX implementation for requested configuration");
|
||||
}
|
||||
|
||||
// TODO impl_number is global for now
|
||||
impl_number = max_match_it->second;
|
||||
|
Loading…
Reference in New Issue
Block a user