mirror of https://github.com/opencv/opencv.git
Merge pull request #24045 from TolyaTalamanov:at/add-onnx-directml-execution-provider
G-API: Support DirectML Execution Provider for ONNXRT Backend #24045 ### 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 CMakepull/24042/head
parent
a25e809da1
commit
a817813b50
9 changed files with 198 additions and 63 deletions
@ -0,0 +1,40 @@ |
||||
// 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) 2023 Intel Corporation
|
||||
|
||||
#include "backends/onnx/dml_ep.hpp" |
||||
#include "logger.hpp" |
||||
|
||||
#ifdef HAVE_ONNX |
||||
#include <onnxruntime_cxx_api.h> |
||||
|
||||
#ifdef HAVE_ONNX_DML |
||||
#include "../providers/dml/dml_provider_factory.h" |
||||
|
||||
void cv::gimpl::onnx::addDMLExecutionProvider(Ort::SessionOptions *session_options, |
||||
const cv::gapi::onnx::ep::DirectML &dml_ep) { |
||||
namespace ep = cv::gapi::onnx::ep; |
||||
GAPI_Assert(cv::util::holds_alternative<int>(dml_ep.ddesc)); |
||||
const int device_id = cv::util::get<int>(dml_ep.ddesc); |
||||
try { |
||||
OrtSessionOptionsAppendExecutionProvider_DML(*session_options, device_id); |
||||
} catch (const std::exception &e) { |
||||
std::stringstream ss; |
||||
ss << "ONNX Backend: Failed to enable DirectML" |
||||
<< " Execution Provider: " << e.what(); |
||||
cv::util::throw_error(std::runtime_error(ss.str())); |
||||
} |
||||
} |
||||
|
||||
#else // HAVE_ONNX_DML
|
||||
|
||||
void cv::gimpl::onnx::addDMLExecutionProvider(Ort::SessionOptions*, |
||||
const cv::gapi::onnx::ep::DirectML&) { |
||||
util::throw_error(std::runtime_error("G-API has been compiled with ONNXRT" |
||||
" without DirectML support")); |
||||
} |
||||
|
||||
#endif // HAVE_ONNX_DML
|
||||
#endif // HAVE_ONNX
|
@ -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) 2023 Intel Corporation
|
||||
|
||||
#ifndef OPENCV_GAPI_DML_EP_HPP |
||||
#define OPENCV_GAPI_DML_EP_HPP |
||||
|
||||
#include "opencv2/gapi/infer/onnx.hpp" |
||||
#ifdef HAVE_ONNX |
||||
|
||||
#include <onnxruntime_cxx_api.h> |
||||
|
||||
namespace cv { |
||||
namespace gimpl { |
||||
namespace onnx { |
||||
void addDMLExecutionProvider(Ort::SessionOptions *session_options, |
||||
const cv::gapi::onnx::ep::DirectML &dml_ep); |
||||
}}} |
||||
|
||||
#endif // HAVE_ONNX
|
||||
#endif // OPENCV_GAPI_DML_EP_HPP
|
Loading…
Reference in new issue