From d738bdd968afcdbf9c1b45cfb247f6598477ad0a Mon Sep 17 00:00:00 2001 From: Brian Martin <42186431+martinb35@users.noreply.github.com> Date: Fri, 22 Nov 2019 16:13:28 -0800 Subject: [PATCH] Brianma/cpuwinml (#2466) * allow building winml cpu without dml. --- cmake/onnxruntime.cmake | 3 +- cmake/onnxruntime_providers.cmake | 2 +- cmake/winml.cmake | 21 ++- .../inc/IWinmlExecutionProvider.h | 8 +- tools/ci_build/build.py | 2 +- winml/lib/Api.Core/AbiCustomRegistryImpl.cpp | 7 +- winml/lib/Api.Core/WinMLAdapter.cpp | 146 ++++++++++++------ .../lib/Api.Core/inc/AbiCustomRegistryImpl.h | 2 + winml/lib/Api.Core/inc/WinMLAdapter.h | 7 +- winml/lib/Api.Core/pch.h | 4 + winml/lib/Api.Image/DeviceHelpers.cpp | 12 ++ winml/lib/Api/ImageFeatureValue.cpp | 8 +- winml/lib/Api/LearningModelBinding.cpp | 2 +- winml/lib/Api/LearningModelDevice.cpp | 3 +- .../Api/impl/TensorMemoryBufferReference.h | 2 +- winml/lib/Common/inc/onnx.h | 2 + 16 files changed, 157 insertions(+), 74 deletions(-) diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index ca91602aa8..107ad8e267 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -81,7 +81,8 @@ if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS) target_link_libraries(onnxruntime PRIVATE onnxruntime_language_interop onnxruntime_pyop) endif() -set_property(TARGET onnxruntime APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_SO_LINK_FLAG}) +set_property(TARGET onnxruntime APPEND_STRING PROPERTY LINK_FLAGS "${ONNXRUNTIME_SO_LINK_FLAG} ${ONNXRUNTIME_LINKER_FLAGS}") + set_target_properties(onnxruntime PROPERTIES LINK_DEPENDS ${SYMBOL_FILE}) if(onnxruntime_ENABLE_LTO) set_target_properties(onnxruntime PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 62216278d5..9ba5a30f2b 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -432,7 +432,7 @@ if (onnxruntime_USE_DML) target_link_libraries(onnxruntime_providers_dml ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) target_link_libraries(onnxruntime_providers_dml d3d12.lib dxgi.lib) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll") + list(APPEND ONNXRUNTIME_LINKER_FLAGS "/DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll") # The DML EP requires C++17 set_target_properties(onnxruntime_providers_dml PROPERTIES CXX_STANDARD 17) diff --git a/cmake/winml.cmake b/cmake/winml.cmake index f4748c8b8b..44c2a01943 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -119,27 +119,34 @@ target_link_libraries(winml_lib_telemetry PRIVATE wil) ########################### # Add static library that will be archived/linked for both static/dynamic library -add_library(winml_lib_core STATIC - ${winml_lib_api_core_dir}/inc/AbiCustomRegistryImpl.h +list(APPEND winml_lib_core_files ${winml_lib_api_core_dir}/inc/CustomRegistryHelper.h ${winml_lib_api_core_dir}/inc/LotusEnvironment.h ${winml_lib_api_core_dir}/inc/MLValueHelpers.h ${winml_lib_api_core_dir}/inc/TensorBaseHelpers.h ${winml_lib_api_core_dir}/inc/WinMLAdapter.h ${winml_lib_api_core_dir}/CpuOrtSessionBuilder.h - ${winml_lib_api_core_dir}/DmlOrtSessionBuilder.h ${winml_lib_api_core_dir}/FeatureDescriptorFactory.h ${winml_lib_api_core_dir}/FeatureDescriptorFactory.cpp ${winml_lib_api_core_dir}/ZeroCopyInputStreamWrapper.h ${winml_lib_api_core_dir}/pch.h - ${winml_lib_api_core_dir}/AbiCustomRegistryImpl.cpp ${winml_lib_api_core_dir}/CpuOrtSessionBuilder.cpp - ${winml_lib_api_core_dir}/DmlOrtSessionBuilder.cpp ${winml_lib_api_core_dir}/LotusEnvironment.cpp ${winml_lib_api_core_dir}/WinMLAdapter.cpp ${winml_lib_api_core_dir}/ZeroCopyInputStreamWrapper.cpp ) +if (onnxruntime_USE_DML) + list(APPEND winml_lib_core_files + ${winml_lib_api_core_dir}/inc/AbiCustomRegistryImpl.h + ${winml_lib_api_core_dir}/DmlOrtSessionBuilder.h + ${winml_lib_api_core_dir}/AbiCustomRegistryImpl.cpp + ${winml_lib_api_core_dir}/DmlOrtSessionBuilder.cpp + ) +endif(onnxruntime_USE_DML) + +add_library(winml_lib_core STATIC ${winml_lib_core_files}) + # Compiler options target_compile_features(winml_lib_core PRIVATE cxx_std_17) target_compile_options(winml_lib_core PRIVATE /GR- /await /wd4238) @@ -194,7 +201,9 @@ add_dependencies(winml_lib_core winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_core PRIVATE wil) -target_link_libraries(winml_lib_core PRIVATE onnxruntime_providers_dml) +if (onnxruntime_USE_DML) + target_link_libraries(winml_lib_core PRIVATE onnxruntime_providers_dml) +endif(onnxruntime_USE_DML) # add it to the onnxruntime shared library set(onnxruntime_winml windowsapp.lib -WHOLEARCHIVE:$) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h index 7fa1e21e5d..605aec43d8 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h @@ -10,6 +10,8 @@ #include "core/framework/op_kernel.h" +#include + struct AbstractOperatorDesc; interface IMLOperatorTensor; @@ -65,6 +67,8 @@ namespace Windows::AI::MachineLearning::Adapter virtual void Close() = 0; }; + using MLOperatorTensorGetter = std::function(uint32_t index)>; + struct DmlOperatorParams { Microsoft::WRL::ComPtr op; @@ -86,8 +90,6 @@ namespace Windows::AI::MachineLearning::Adapter bool allowHalfPrecisionComputation = false; }; - using MLOperatorTensorGetter = std::function(uint32_t index)>; - using GraphNodeFactory = std::function>; -} \ No newline at end of file +} // namespace Windows::AI::MachineLearning::Adapter \ No newline at end of file diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 09b19bd21c..9c3fc913b2 100755 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -373,7 +373,7 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home # enable pyop if it is nightly build "-Donnxruntime_ENABLE_LANGUAGE_INTEROP_OPS=" + ("ON" if args.enable_language_interop_ops or (args.config != 'Debug' and bool(os.getenv('NIGHTLY_BUILD') == '1')) else "OFF"), "-Donnxruntime_USE_DML=" + ("ON" if args.use_dml else "OFF"), - "-Donnxruntime_USE_WINML=" + ("ON" if args.use_winml and args.use_dml else "OFF"), + "-Donnxruntime_USE_WINML=" + ("ON" if args.use_winml else "OFF"), ] if args.use_brainslice: bs_pkg_name = args.brain_slice_package_name.split('.', 1) diff --git a/winml/lib/Api.Core/AbiCustomRegistryImpl.cpp b/winml/lib/Api.Core/AbiCustomRegistryImpl.cpp index c50395e90e..fcbc7432c0 100644 --- a/winml/lib/Api.Core/AbiCustomRegistryImpl.cpp +++ b/winml/lib/Api.Core/AbiCustomRegistryImpl.cpp @@ -2,6 +2,9 @@ // Licensed under the MIT License. #include "pch.h" + +#ifdef USE_DML + #include "inc/AbiCustomRegistryImpl.h" namespace Windows::AI::MachineLearning::Adapter { @@ -79,4 +82,6 @@ HRESULT STDMETHODCALLTYPE AbiCustomRegistryImpl::RegisterOperatorKernel( } CATCH_RETURN(); -} // namespace Windows::AI::MachineLearning::Adapter \ No newline at end of file +} // namespace Windows::AI::MachineLearning::Adapter + +#endif USE_DML diff --git a/winml/lib/Api.Core/WinMLAdapter.cpp b/winml/lib/Api.Core/WinMLAdapter.cpp index 7c0428463a..99d10f4318 100644 --- a/winml/lib/Api.Core/WinMLAdapter.cpp +++ b/winml/lib/Api.Core/WinMLAdapter.cpp @@ -7,9 +7,13 @@ #include "PheonixSingleton.h" #include "inc/LotusEnvironment.h" #include "inc/AbiCustomRegistryImpl.h" + +#ifdef USE_DML #include "core/providers/dml/DmlExecutionProvider/inc/DmlExecutionProvider.h" #include "core/providers/dml/GraphTransformers/GraphTransformerHelpers.h" #include "core/providers/dml/OperatorAuthorHelper/SchemaInferenceOverrider.h" +#include "DmlOrtSessionBuilder.h" +#endif USE_DML #include "LearningModelDevice.h" #include "TensorFeatureDescriptor.h" @@ -17,7 +21,6 @@ #include "api.image/inc/D3DDeviceCache.h" #include "Common/inc/WinMLTelemetryHelper.h" -#include "DmlOrtSessionBuilder.h" #include "CpuOrtSessionBuilder.h" #include @@ -452,11 +455,15 @@ class WinMLAdapter : public Microsoft::WRL::RuntimeClass< } ID3D12Resource* STDMETHODCALLTYPE GetD3D12ResourceFromAllocation(onnxruntime::IExecutionProvider* provider, void* allocation) override { +#ifdef USE_DML auto d3dResource = Dml::GetD3D12ResourceFromAllocation( provider->GetAllocator(0, ::OrtMemType::OrtMemTypeDefault).get(), allocation); return d3dResource; +#else + return nullptr; +#endif USE_DML } static onnxruntime::MLDataType GetType(winml::TensorKind kind) { @@ -477,10 +484,15 @@ class WinMLAdapter : public Microsoft::WRL::RuntimeClass< if (device == nullptr) { auto builder = wil::MakeOrThrow(); return builder.CopyTo(__uuidof(IOrtSessionBuilder), reinterpret_cast(session_builder)); - } else { + } +#ifdef USE_DML + else { auto builder = wil::MakeOrThrow(device, queue); return builder.CopyTo(__uuidof(IOrtSessionBuilder), reinterpret_cast(session_builder)); } +#else + return E_NOTIMPL; +#endif USE_DML } onnxruntime::MLDataType STDMETHODCALLTYPE GetTensorType() override { @@ -615,52 +627,71 @@ class WinMLAdapter : public Microsoft::WRL::RuntimeClass< } HRESULT STDMETHODCALLTYPE GetCustomRegistry(IMLOperatorRegistry** registry) override { +#ifdef USE_DML auto impl = wil::MakeOrThrow(); *registry = impl.Detach(); - return S_OK; - } + return S_OK; +#else + return E_NOTIMPL; +#endif USE_DML +} - void* STDMETHODCALLTYPE CreateGPUAllocationFromD3DResource(ID3D12Resource* pResource) override { - return Dml::CreateGPUAllocationFromD3DResource(pResource); - } +void* STDMETHODCALLTYPE CreateGPUAllocationFromD3DResource(ID3D12Resource* pResource) override { +#ifdef USE_DML + return Dml::CreateGPUAllocationFromD3DResource(pResource); +#else + return nullptr; +#endif USE_DML +} - void STDMETHODCALLTYPE FreeGPUAllocation(void* ptr) override { - Dml::FreeGPUAllocation(ptr); - } - HRESULT STDMETHODCALLTYPE CopyTensor( - onnxruntime::IExecutionProvider* provider, - ITensor* src, - ITensor* dst) override { - ORT_THROW_IF_ERROR(Dml::CopyTensor(provider, src->get(), *(dst->getMutable()))); - return S_OK; - } +void STDMETHODCALLTYPE FreeGPUAllocation(void* ptr) override { +#ifdef USE_DML + Dml::FreeGPUAllocation(ptr); +#endif USE_DML +} - HRESULT STDMETHODCALLTYPE CreateGPUMLValue( - void* execution_provider_allocated_resource, - onnxruntime::IExecutionProvider* provider, - std::vector* shape, - onnxruntime::MLDataType data_type, - IOrtValue** gpu_value) override { - THROW_HR_IF_MSG(WINML_ERR_INVALID_BINDING, - "DmlExecutionProvider" != provider->Type(), - "Cannot creat GPU tensor on CPU device"); +HRESULT STDMETHODCALLTYPE CopyTensor( + onnxruntime::IExecutionProvider* provider, + ITensor* src, + ITensor* dst) override { +#ifdef USE_DML + ORT_THROW_IF_ERROR(Dml::CopyTensor(provider, src->get(), *(dst->getMutable()))); + return S_OK; +#else + return E_NOTIMPL; +#endif USE_DML +} - onnxruntime::TensorShape tensor_shape(*shape); +HRESULT STDMETHODCALLTYPE CreateGPUMLValue( + void* execution_provider_allocated_resource, + onnxruntime::IExecutionProvider* provider, + std::vector* shape, + onnxruntime::MLDataType data_type, + IOrtValue** gpu_value) override { +#ifdef USE_DML + THROW_HR_IF_MSG(WINML_ERR_INVALID_BINDING, + "DmlExecutionProvider" != provider->Type(), + "Cannot creat GPU tensor on CPU device"); - auto tensor = new onnxruntime::Tensor( - data_type, - tensor_shape, - execution_provider_allocated_resource, - provider->GetAllocator(0, ::OrtMemType::OrtMemTypeDefault)->Info()); + onnxruntime::TensorShape tensor_shape(*shape); - auto ort_value = wil::MakeOrThrow(); - ort_value->get()->Init(tensor, - onnxruntime::DataTypeImpl::GetType(), - onnxruntime::DataTypeImpl::GetType()->GetDeleteFunc()); + auto tensor = new onnxruntime::Tensor( + data_type, + tensor_shape, + execution_provider_allocated_resource, + provider->GetAllocator(0, ::OrtMemType::OrtMemTypeDefault)->Info()); - *gpu_value = ort_value.Detach(); - return S_OK; - } + auto ort_value = wil::MakeOrThrow(); + ort_value->get()->Init(tensor, + onnxruntime::DataTypeImpl::GetType(), + onnxruntime::DataTypeImpl::GetType()->GetDeleteFunc()); + + *gpu_value = ort_value.Detach(); + return S_OK; +#else + return E_NOTIMPL; +#endif USE_DML +} HRESULT STDMETHODCALLTYPE CreateCPUMLValue( std::vector* shape, @@ -729,18 +760,23 @@ class WinMLAdapter : public Microsoft::WRL::RuntimeClass< return S_OK; } - // Override select shape inference functions which are incomplete in ONNX with versions that are complete, - // and are also used in DML kernel registrations. Doing this avoids kernel and shader creation being - // deferred until first evaluation. It also prevents a situation where inference functions in externally - // registered schema are reachable only after upstream schema have been revised in a later OS release, - // which would be a compatibility risk. - HRESULT STDMETHODCALLTYPE OverrideSchemaInferenceFunctions() override { - static std::once_flag schema_override_once_flag; - std::call_once(schema_override_once_flag, []() { - SchemaInferenceOverrider::OverrideSchemaInferenceFunctions(); - }); - return S_OK; - } +// Override select shape inference functions which are incomplete in ONNX with versions that are complete, +// and are also used in DML kernel registrations. Doing this avoids kernel and shader creation being +// deferred until first evaluation. It also prevents a situation where inference functions in externally +// registered schema are reachable only after upstream schema have been revised in a later OS release, +// which would be a compatibility risk. +HRESULT STDMETHODCALLTYPE OverrideSchemaInferenceFunctions() override { +#ifdef USE_DML + static std::once_flag schema_override_once_flag; + std::call_once(schema_override_once_flag, []() { + SchemaInferenceOverrider::OverrideSchemaInferenceFunctions(); + }); + return S_OK; +#else + return E_NOTIMPL; +#endif USE_DML +} + }; // namespace Windows::AI::MachineLearning::Adapter extern "C" HRESULT STDMETHODCALLTYPE OrtGetWinMLAdapter(IWinMLAdapter** adapter) { @@ -806,7 +842,9 @@ InferenceSession::InferenceSession(onnxruntime::InferenceSession* session) : ses } void STDMETHODCALLTYPE InferenceSession::RegisterGraphTransformers(bool registerLotusTransforms) { +#ifdef USE_DML GraphTransformerHelpers::RegisterGraphTransformers(session_.get(), registerLotusTransforms); +#endif USE_DML } HRESULT STDMETHODCALLTYPE InferenceSession::NewIOBinding(IIOBinding** io_binding) { @@ -856,15 +894,21 @@ InferenceSession::RegisterCustomRegistry( } void STDMETHODCALLTYPE InferenceSession::FlushContext(onnxruntime::IExecutionProvider* dml_provider) { +#ifdef USE_DML Dml::FlushContext(dml_provider); +#endif USE_DML } void STDMETHODCALLTYPE InferenceSession::TrimUploadHeap(onnxruntime::IExecutionProvider* dml_provider) { +#ifdef USE_DML Dml::TrimUploadHeap(dml_provider); +#endif USE_DML } void STDMETHODCALLTYPE InferenceSession::ReleaseCompletedReferences(onnxruntime::IExecutionProvider* dml_provider) { +#ifdef USE_DML Dml::ReleaseCompletedReferences(dml_provider); +#endif USE_DML } } // namespace Windows::AI::MachineLearning::Adapter \ No newline at end of file diff --git a/winml/lib/Api.Core/inc/AbiCustomRegistryImpl.h b/winml/lib/Api.Core/inc/AbiCustomRegistryImpl.h index 0d63151fa1..747dd65d5a 100644 --- a/winml/lib/Api.Core/inc/AbiCustomRegistryImpl.h +++ b/winml/lib/Api.Core/inc/AbiCustomRegistryImpl.h @@ -3,6 +3,7 @@ #pragma once +#ifdef USE_DML #include "core/providers/dml/DmlExecutionProvider/src/AbiCustomRegistry.h" namespace Windows::AI::MachineLearning::Adapter{ @@ -37,3 +38,4 @@ class AbiCustomRegistryImpl : public AbiCustomRegistry { }; } // namespace winrt::Windows::AI::MachineLearning::Adapter +#endif USE_DML diff --git a/winml/lib/Api.Core/inc/WinMLAdapter.h b/winml/lib/Api.Core/inc/WinMLAdapter.h index 2f1fd253f9..f54165b56e 100644 --- a/winml/lib/Api.Core/inc/WinMLAdapter.h +++ b/winml/lib/Api.Core/inc/WinMLAdapter.h @@ -62,13 +62,13 @@ MIDL_INTERFACE("a848faf6-5a2e-4a7f-b622-cc036f71e28a") IModelProto : IUnknown{ MIDL_INTERFACE("6ec766ef-6365-42bf-b64f-ae85c015adb8") IInferenceSession : IUnknown { virtual onnxruntime::InferenceSession* STDMETHODCALLTYPE get() = 0; virtual void STDMETHODCALLTYPE RegisterGraphTransformers(bool registerLotusTransforms) = 0; - virtual HRESULT STDMETHODCALLTYPE RegisterCustomRegistry(IMLOperatorRegistry* registry) = 0; + virtual HRESULT STDMETHODCALLTYPE RegisterCustomRegistry(IMLOperatorRegistry * registry) = 0; virtual HRESULT STDMETHODCALLTYPE LoadModel(IModelProto* model_proto) = 0; virtual HRESULT STDMETHODCALLTYPE NewIOBinding(IIOBinding** io_binding) = 0; virtual HRESULT STDMETHODCALLTYPE Run(const onnxruntime::RunOptions* run_options, IIOBinding* io_binding) = 0; virtual HRESULT STDMETHODCALLTYPE StartProfiling() = 0; virtual HRESULT STDMETHODCALLTYPE EndProfiling() = 0; - virtual void STDMETHODCALLTYPE FlushContext(onnxruntime::IExecutionProvider* dml_provider) = 0; + virtual void STDMETHODCALLTYPE FlushContext(onnxruntime::IExecutionProvider * dml_provider) = 0; virtual void STDMETHODCALLTYPE TrimUploadHeap(onnxruntime::IExecutionProvider* dml_provider) = 0; virtual void STDMETHODCALLTYPE ReleaseCompletedReferences(onnxruntime::IExecutionProvider* dml_provider) = 0; }; @@ -100,7 +100,7 @@ MIDL_INTERFACE("b19385e7-d9af-441a-ba7f-3993c7b1c9db") IWinMLAdapter : IUnknown IModelProto* p_model_proto, bool is_float16_supported) = 0; - virtual ID3D12Resource* STDMETHODCALLTYPE GetD3D12ResourceFromAllocation(onnxruntime::IExecutionProvider* provider, void* allocation) = 0; + virtual ID3D12Resource* STDMETHODCALLTYPE GetD3D12ResourceFromAllocation(onnxruntime::IExecutionProvider * provider, void* allocation) = 0; // factory method for creating an ortsessionbuilder from a device @@ -139,6 +139,7 @@ MIDL_INTERFACE("b19385e7-d9af-441a-ba7f-3993c7b1c9db") IWinMLAdapter : IUnknown std::vector* shape, onnxruntime::MLDataType data_type, IOrtValue ** gpu_value) = 0; + virtual HRESULT STDMETHODCALLTYPE CreateCPUMLValue( std::vector* shape, onnxruntime::MLDataType data_type, diff --git a/winml/lib/Api.Core/pch.h b/winml/lib/Api.Core/pch.h index 0da01cc616..8763c7e420 100644 --- a/winml/lib/Api.Core/pch.h +++ b/winml/lib/Api.Core/pch.h @@ -6,3 +6,7 @@ #include "cppwinrt_onnx.h" #include "wil/wrl.h" #include "dx.h" + +#if USE_DML +#include +#endif USE_DML diff --git a/winml/lib/Api.Image/DeviceHelpers.cpp b/winml/lib/Api.Image/DeviceHelpers.cpp index 991bd935c5..148e91d0d9 100644 --- a/winml/lib/Api.Image/DeviceHelpers.cpp +++ b/winml/lib/Api.Image/DeviceHelpers.cpp @@ -2,8 +2,12 @@ // Licensed under the MIT License. #include "pch.h" + +#ifdef USE_DML #include "DirectML.h" #include +#endif USE_DML + #include #include "inc/DeviceHelpers.h" @@ -143,6 +147,7 @@ bool IsFloat16Supported(ID3D12Device* device) { return false; } +#ifdef USE_DML winrt::com_ptr dmlDevice; winrt::check_hresult(DMLCreateDevice( device, @@ -160,6 +165,9 @@ bool IsFloat16Supported(ID3D12Device* device) { &float16Data)); return float16Data.IsSupported; +#else + return false; +#endif USE_DML } // uses Structured Exception Handling (SEH) to detect for delay load failures of target API. @@ -293,6 +301,7 @@ HRESULT GetDXCoreHardwareAdapterWithPreference(DXGI_GPU_PREFERENCE preference, I #endif HRESULT CreateD3D11On12Device(ID3D12Device* device12, ID3D11Device** device11) { +#ifdef USE_DML return DeviceHelpers::RunDelayLoadedApi( D3D11On12CreateDevice, device12, // pointer to d3d12 device @@ -305,6 +314,9 @@ HRESULT CreateD3D11On12Device(ID3D12Device* device12, ID3D11Device** device11) { device11, // d3d11 device out param nullptr, // pointer to d3d11 device context (unused) nullptr); // pointer to the returned feature level (unused) +#else + return E_NOTIMPL; +#endif USE_DML } HRESULT GetGPUPreference(winrt::Windows::AI::MachineLearning::LearningModelDeviceKind deviceKind, DXGI_GPU_PREFERENCE* preference) noexcept { diff --git a/winml/lib/Api/ImageFeatureValue.cpp b/winml/lib/Api/ImageFeatureValue.cpp index 1bc4864ce5..4b4a42296d 100644 --- a/winml/lib/Api/ImageFeatureValue.cpp +++ b/winml/lib/Api/ImageFeatureValue.cpp @@ -14,7 +14,7 @@ #include "ImageConversionTypes.h" #include "ConverterResourceStore.h" #include "ImageFeatureDescriptor.h" -#include "core/providers/dml/DmlExecutionProvider/inc/DmlExecutionProvider.h" + #include "core/session/onnxruntime_c_api.h" #include "D3DDeviceCache.h" @@ -537,7 +537,8 @@ HRESULT ImageFeatureValue::GetOrtValue(WinML::BindingContext& context, _winmla:: auto singleFrameBufferSize = bufferByteSize / m_batchSize; if (spDevice->IsCpuDevice()) { CPUTensorize(m_videoFrames, resourceMetadata.Bounds, resourceMetadata.TensorDescriptor, spSession, pAllocatedResource, static_cast(singleFrameBufferSize)); - } else { + } + else { GPUTensorize(m_videoFrames, resourceMetadata.Bounds, resourceMetadata.TensorDescriptor, spSession, pAllocatedResource, context); } } @@ -588,7 +589,8 @@ HRESULT ImageFeatureValue::UpdateSourceResourceData(BindingContext& context, _wi pooledConverter->Get()->Detensorizer->SoftwareTensorToVideoFrame(context.session, tempPAllocatedResource, resourceMetadata.TensorDescriptor, videoFrame); tempPAllocatedResource += bufferByteSize; } - } else { + } + else { descriptor.pixel_format = static_cast(DirectXPixelFormat::B8G8R8X8UIntNormalized); descriptor.luid = spDevice->GetD3DDevice()->GetAdapterLuid(); // Converted image on GPU diff --git a/winml/lib/Api/LearningModelBinding.cpp b/winml/lib/Api/LearningModelBinding.cpp index 73828af7b0..673bed57db 100644 --- a/winml/lib/Api/LearningModelBinding.cpp +++ b/winml/lib/Api/LearningModelBinding.cpp @@ -246,7 +246,7 @@ ILearningModelFeatureValue LearningModelBinding::CreateUnboundOuputFeatureValue( if (IsOfTensorType(tensorValue.get(), TensorKind::Float)) { if (descriptor.Kind() == LearningModelFeatureKind::Image) { using namespace Windows::Graphics::Imaging; - // TODO: this format for unbound ouput needs more discussion + // TODO: this format for unbound output needs more discussion BitmapPixelFormat format = descriptor.as()->BitmapPixelFormat(); uint32_t width = static_cast(tensorValue->ShapeGetDims()[3]); uint32_t height = static_cast(tensorValue->ShapeGetDims()[2]); diff --git a/winml/lib/Api/LearningModelDevice.cpp b/winml/lib/Api/LearningModelDevice.cpp index c5ad0b1c87..90d33e40ba 100644 --- a/winml/lib/Api/LearningModelDevice.cpp +++ b/winml/lib/Api/LearningModelDevice.cpp @@ -3,8 +3,7 @@ #include "pch.h" #include "LearningModelDevice.h" -#include "core/providers/dml/DmlExecutionProvider/inc/MLOperatorAuthor.h" -#include "core/providers/dml/DmlExecutionProvider/inc/DmlExecutionProvider.h" + #include #include #include "D3DDeviceCache.h" diff --git a/winml/lib/Api/impl/TensorMemoryBufferReference.h b/winml/lib/Api/impl/TensorMemoryBufferReference.h index 91f65c8a3d..c4381ed8af 100644 --- a/winml/lib/Api/impl/TensorMemoryBufferReference.h +++ b/winml/lib/Api/impl/TensorMemoryBufferReference.h @@ -5,7 +5,7 @@ #include "Tensor.h" #include -#include "core/providers/dml/DmlExecutionProvider/inc/DmlExecutionProvider.h" + #include #include "WinMLAdapter.h" diff --git a/winml/lib/Common/inc/onnx.h b/winml/lib/Common/inc/onnx.h index 0b190033fb..d537ba450b 100644 --- a/winml/lib/Common/inc/onnx.h +++ b/winml/lib/Common/inc/onnx.h @@ -16,7 +16,9 @@ // the C++ ort api #include "core/session/onnxruntime_cxx_api.h" +#ifdef USE_DML #include +#endif USE_DML #include "core/framework/customregistry.h" #include "core/framework/allocatormgr.h"