mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #24059 from TolyaTalamanov:at/add-onnx-cuda-execution-provider
G-API: Support CUDA & TensoRT Execution Providers for ONNXRT Backend #24059 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [ ] I agree to contribute to the project under Apache 2 License. - [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
0883c6a913
commit
f46f7eff0c
@@ -39,6 +39,12 @@ public:
|
||||
GAPI_WRAP
|
||||
PyParams& cfgAddExecutionProvider(ep::DirectML ep);
|
||||
|
||||
GAPI_WRAP
|
||||
PyParams& cfgAddExecutionProvider(ep::CUDA ep);
|
||||
|
||||
GAPI_WRAP
|
||||
PyParams& cfgAddExecutionProvider(ep::TensorRT ep);
|
||||
|
||||
GAPI_WRAP
|
||||
PyParams& cfgDisableMemPattern();
|
||||
|
||||
|
||||
@@ -32,6 +32,56 @@ namespace onnx {
|
||||
*/
|
||||
namespace ep {
|
||||
|
||||
/**
|
||||
* @brief This structure provides functions
|
||||
* that fill inference options for CUDA Execution Provider.
|
||||
* Please follow https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#cuda-execution-provider
|
||||
*/
|
||||
struct GAPI_EXPORTS_W_SIMPLE CUDA {
|
||||
// NB: Used from python.
|
||||
/// @private -- Exclude this constructor from OpenCV documentation
|
||||
GAPI_WRAP
|
||||
CUDA() = default;
|
||||
|
||||
/** @brief Class constructor.
|
||||
|
||||
Constructs CUDA parameters based on device type information.
|
||||
|
||||
@param dev_id Target device id to use.
|
||||
*/
|
||||
GAPI_WRAP
|
||||
explicit CUDA(const int dev_id)
|
||||
: device_id(dev_id) {
|
||||
}
|
||||
|
||||
int device_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This structure provides functions
|
||||
* that fill inference options for TensorRT Execution Provider.
|
||||
* Please follow https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#tensorrt-execution-provider
|
||||
*/
|
||||
struct GAPI_EXPORTS_W_SIMPLE TensorRT {
|
||||
// NB: Used from python.
|
||||
/// @private -- Exclude this constructor from OpenCV documentation
|
||||
GAPI_WRAP
|
||||
TensorRT() = default;
|
||||
|
||||
/** @brief Class constructor.
|
||||
|
||||
Constructs TensorRT parameters based on device type information.
|
||||
|
||||
@param dev_id Target device id to use.
|
||||
*/
|
||||
GAPI_WRAP
|
||||
explicit TensorRT(const int dev_id)
|
||||
: device_id(dev_id) {
|
||||
}
|
||||
|
||||
int device_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This structure provides functions
|
||||
* that fill inference options for ONNX OpenVINO Execution Provider.
|
||||
@@ -143,7 +193,11 @@ public:
|
||||
DeviceDesc ddesc;
|
||||
};
|
||||
|
||||
using EP = cv::util::variant<cv::util::monostate, OpenVINO, DirectML>;
|
||||
using EP = cv::util::variant< cv::util::monostate
|
||||
, OpenVINO
|
||||
, DirectML
|
||||
, CUDA
|
||||
, TensorRT>;
|
||||
|
||||
} // namespace ep
|
||||
|
||||
@@ -431,6 +485,34 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** @brief Adds execution provider for runtime.
|
||||
|
||||
The function is used to add ONNX Runtime CUDA Execution Provider options.
|
||||
|
||||
@param ep CUDA Execution Provider options.
|
||||
@see cv::gapi::onnx::ep::CUDA.
|
||||
|
||||
@return the reference on modified object.
|
||||
*/
|
||||
Params<Net>& cfgAddExecutionProvider(ep::CUDA&& ep) {
|
||||
desc.execution_providers.emplace_back(std::move(ep));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** @brief Adds execution provider for runtime.
|
||||
|
||||
The function is used to add ONNX Runtime TensorRT Execution Provider options.
|
||||
|
||||
@param ep TensorRT Execution Provider options.
|
||||
@see cv::gapi::onnx::ep::TensorRT.
|
||||
|
||||
@return the reference on modified object.
|
||||
*/
|
||||
Params<Net>& cfgAddExecutionProvider(ep::TensorRT&& ep) {
|
||||
desc.execution_providers.emplace_back(std::move(ep));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** @brief Disables the memory pattern optimization.
|
||||
|
||||
@return the reference on modified object.
|
||||
@@ -491,6 +573,16 @@ public:
|
||||
desc.execution_providers.emplace_back(std::move(ep));
|
||||
}
|
||||
|
||||
/** @see onnx::Params::cfgAddExecutionProvider. */
|
||||
void cfgAddExecutionProvider(ep::CUDA&& ep) {
|
||||
desc.execution_providers.emplace_back(std::move(ep));
|
||||
}
|
||||
|
||||
/** @see onnx::Params::cfgAddExecutionProvider. */
|
||||
void cfgAddExecutionProvider(ep::TensorRT&& ep) {
|
||||
desc.execution_providers.emplace_back(std::move(ep));
|
||||
}
|
||||
|
||||
/** @see onnx::Params::cfgDisableMemPattern. */
|
||||
void cfgDisableMemPattern() {
|
||||
desc.disable_mem_pattern = true;
|
||||
|
||||
Reference in New Issue
Block a user