mirror of
https://github.com/opencv/opencv.git
synced 2024-12-04 00:39:11 +08:00
0e151e3c88
G-API: Advanced device selection for ONNX DirectML Execution Provider #24060 ### Overview Extend `cv::gapi::onnx::ep::DirectML` to accept `adapter name` as `ctor` parameter in order to select execution device by `name`. E.g: ``` pp.cfgAddExecutionProvider(cv::gapi::onnx::ep::DirectML("Intel Graphics")); ``` ### 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
38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
#include <initguid.h>
|
|
|
|
#include <d3d11.h>
|
|
#include <dxgi1_2.h>
|
|
#include <dxgi1_4.h>
|
|
#include <dxgi.h>
|
|
#include <dxcore.h>
|
|
#include <dxcore_interface.h>
|
|
#include <d3d12.h>
|
|
#include <directml.h>
|
|
|
|
int main(int /*argc*/, char** /*argv*/)
|
|
{
|
|
IDXCoreAdapterFactory* factory;
|
|
DXCoreCreateAdapterFactory(__uuidof(IDXCoreAdapterFactory), (void**)&factory);
|
|
|
|
IDXCoreAdapterList* adapterList;
|
|
const GUID dxGUIDs[] = { DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE };
|
|
factory->CreateAdapterList(ARRAYSIZE(dxGUIDs), dxGUIDs, __uuidof(IDXCoreAdapterList), (void**)&adapterList);
|
|
|
|
IDXCoreAdapter* adapter;
|
|
adapterList->GetAdapter(0u, __uuidof(IDXCoreAdapter), (void**)&adapter);
|
|
|
|
D3D_FEATURE_LEVEL d3dFeatureLevel = D3D_FEATURE_LEVEL_1_0_CORE;
|
|
ID3D12Device* d3d12Device = NULL;
|
|
D3D12CreateDevice((IUnknown*)adapter, d3dFeatureLevel, __uuidof(ID3D11Device), (void**)&d3d12Device);
|
|
|
|
D3D12_COMMAND_LIST_TYPE commandQueueType = D3D12_COMMAND_LIST_TYPE_COMPUTE;
|
|
ID3D12CommandQueue* cmdQueue;
|
|
D3D12_COMMAND_QUEUE_DESC commandQueueDesc = {};
|
|
commandQueueDesc.Type = commandQueueType;
|
|
|
|
d3d12Device->CreateCommandQueue(&commandQueueDesc, __uuidof(ID3D12CommandQueue), (void**)&cmdQueue);
|
|
IDMLDevice* dmlDevice;
|
|
DMLCreateDevice(d3d12Device, DML_CREATE_DEVICE_FLAG_NONE, IID_PPV_ARGS(&dmlDevice));
|
|
|
|
return 0;
|
|
} |