diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index 17abdf8637..ca91602aa8 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -66,7 +66,7 @@ target_link_libraries(onnxruntime PRIVATE ${PROVIDERS_NUPHAR} ${PROVIDERS_DML} ${PROVIDERS_ACL} - ${onnxruntime_winml} + ${onnxruntime_winml} onnxruntime_optimizer onnxruntime_providers onnxruntime_util diff --git a/cmake/winml.cmake b/cmake/winml.cmake index c0a370013e..f4748c8b8b 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -467,26 +467,14 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") endif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") # Link libraries -#target_link_libraries(winml_dll PRIVATE libprotobuf) -#target_link_libraries(winml_dll PRIVATE onnx) -#target_link_libraries(winml_dll PRIVATE onnxruntime_common) -#target_link_libraries(winml_dll PRIVATE onnxruntime_graph) -#target_link_libraries(winml_dll PRIVATE onnxruntime_framework) -#target_link_libraries(winml_dll PRIVATE onnxruntime_mlas) -#target_link_libraries(winml_dll PRIVATE onnxruntime_optimizer) -#target_link_libraries(winml_dll PRIVATE onnxruntime_providers) -#target_link_libraries(winml_dll PRIVATE onnxruntime_providers_dml) -#target_link_libraries(winml_dll PRIVATE onnxruntime_session) -#target_link_libraries(winml_dll PRIVATE onnxruntime_util) -#target_link_libraries(winml_dll PRIVATE onnx_proto) target_link_libraries(winml_dll PRIVATE onnxruntime) target_link_libraries(winml_dll PRIVATE re2) target_link_libraries(winml_dll PRIVATE wil) -target_link_libraries(winml_dll PRIVATE windowsapp.lib) +#target_link_libraries(winml_dll PRIVATE windowsapp.lib) target_link_libraries(winml_dll PRIVATE winml_lib_api) -#target_link_libraries(winml_dll PRIVATE winml_lib_core) target_link_libraries(winml_dll PRIVATE winml_lib_image) target_link_libraries(winml_dll PRIVATE winml_lib_telemetry) +target_link_libraries(winml_dll PRIVATE onecoreuap_apiset.lib) target_link_libraries(winml_dll PRIVATE ${DBGHELP}) # 1 of 3 projects that fail in link with 'failed to do memory mapped file I/O' (Only release) diff --git a/winml/lib/Api.Core/WinMLAdapter.cpp b/winml/lib/Api.Core/WinMLAdapter.cpp index 6bff0e6c97..8646ca314d 100644 --- a/winml/lib/Api.Core/WinMLAdapter.cpp +++ b/winml/lib/Api.Core/WinMLAdapter.cpp @@ -110,7 +110,7 @@ public: HRESULT STDMETHODCALLTYPE GetTensor(ITensor ** tensor) override { auto tensor_inner = ort_value_.GetMutable(); auto tensor_outer = wil::MakeOrThrow(tensor_inner, this); - return tensor_outer.CopyTo(__uuidof(ITensor), (void**)tensor); + return tensor_outer.CopyTo(__uuidof(ITensor), reinterpret_cast(tensor)); } }; // class AbiSafeOrtValue @@ -310,6 +310,7 @@ public: const char* path, IModelProto** model_proto) override { int file_descriptor; + _set_errno(0); // clear errno _sopen_s( &file_descriptor, path, @@ -317,6 +318,14 @@ public: _SH_DENYWR, _S_IREAD | _S_IWRITE); + errno_t err = 0; + _get_errno(&err); + THROW_HR_IF_MSG( + __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), + err == ENOENT, + "File not found: %s", + path); + THROW_HR_IF_MSG( E_FAIL, 0 > file_descriptor, @@ -332,7 +341,7 @@ public: "The stream failed to parse."); auto model_proto_outer = wil::MakeOrThrow(model_proto_inner); - return model_proto_outer.CopyTo(__uuidof(IModelProto), (void**)model_proto); + return model_proto_outer.CopyTo(__uuidof(IModelProto), reinterpret_cast(model_proto)); } // factory methods for creating an ort model from a stream @@ -349,19 +358,19 @@ public: "The stream failed to parse."); auto model_proto_outer = wil::MakeOrThrow(model_proto_inner); - return model_proto_outer.CopyTo(__uuidof(IModelProto), (void**)model_proto); + return model_proto_outer.CopyTo(__uuidof(IModelProto), reinterpret_cast(model_proto)); } // factory methods for creating an ort model from a model_proto HRESULT STDMETHODCALLTYPE CreateModelProto(IModelProto * model_proto_in, IModelProto** model_proto) override { auto model_proto_inner = new onnx::ModelProto(*model_proto_in->get()); auto model_proto_outer = wil::MakeOrThrow(model_proto_inner); - return model_proto_outer.CopyTo(__uuidof(IModelProto), (void**)model_proto); + return model_proto_outer.CopyTo(__uuidof(IModelProto), reinterpret_cast(model_proto)); } HRESULT STDMETHODCALLTYPE CreateModelInfo(IModelProto * model_proto, IModelInfo ** model_info) override { auto model_info_outer = wil::MakeOrThrow(model_proto->get()); - return model_info_outer.CopyTo(__uuidof(IModelInfo), (void**)model_info); + return model_info_outer.CopyTo(__uuidof(IModelInfo), reinterpret_cast(model_info)); } @@ -471,10 +480,10 @@ public: if (device == nullptr) { auto builder = wil::MakeOrThrow(); - return builder.CopyTo(__uuidof(IOrtSessionBuilder), (void**)session_builder); + return builder.CopyTo(__uuidof(IOrtSessionBuilder), reinterpret_cast(session_builder)); } else { auto builder = wil::MakeOrThrow(device, queue); - return builder.CopyTo(__uuidof(IOrtSessionBuilder), (void**)session_builder); + return builder.CopyTo(__uuidof(IOrtSessionBuilder), reinterpret_cast(session_builder)); } } @@ -713,7 +722,7 @@ extern "C" HRESULT STDMETHODCALLTYPE OrtGetWinMLAdapter(IWinMLAdapter** adapter) { // make an adapter instance Microsoft::WRL::ComPtr adapterptr = wil::MakeOrThrow(); - return adapterptr.CopyTo(__uuidof(IWinMLAdapter), (void **)adapter); + return adapterptr.CopyTo(__uuidof(IWinMLAdapter), reinterpret_cast(adapter)); } @@ -782,7 +791,7 @@ HRESULT STDMETHODCALLTYPE InferenceSession::NewIOBinding(IIOBinding** io_binding std::unique_ptr binding; ORT_THROW_IF_ERROR(this->session_->NewIOBinding(&binding)); auto io_binding_outer = wil::MakeOrThrow(binding.release()); - return io_binding_outer.CopyTo(__uuidof(IIOBinding), (void**)io_binding); + return io_binding_outer.CopyTo(__uuidof(IIOBinding), reinterpret_cast(io_binding)); } HRESULT STDMETHODCALLTYPE InferenceSession::Run(const onnxruntime::RunOptions* run_options, IIOBinding* io_binding) { diff --git a/winml/lib/Api/LearningModelSession.cpp b/winml/lib/Api/LearningModelSession.cpp index 21f04c2bc6..fbedef5210 100644 --- a/winml/lib/Api/LearningModelSession.cpp +++ b/winml/lib/Api/LearningModelSession.cpp @@ -29,23 +29,23 @@ static const GUID WINML_PIX_EVAL_CAPTURABLE_WORK_GUID = __uuidof(guid_details::W namespace winrt::Windows::AI::MachineLearning::implementation { LearningModelSession::LearningModelSession( - winml::LearningModel const& model) try : LearningModelSession(model, - make(LearningModelDeviceKind::Default)) {} + winml::LearningModel const& model) try : LearningModelSession(model, + make(LearningModelDeviceKind::Default)) {} WINML_CATCH_ALL LearningModelSession::LearningModelSession( - winml::LearningModel const& model, - winml::LearningModelDevice const& deviceToRunOn) try : LearningModelSession(model, - deviceToRunOn, - nullptr) {} + winml::LearningModel const& model, + winml::LearningModelDevice const& deviceToRunOn) try : LearningModelSession(model, + deviceToRunOn, + nullptr) {} WINML_CATCH_ALL LearningModelSession::LearningModelSession( - winml::LearningModel const& model, - winml::LearningModelDevice const& deviceToRunOn, - winml::LearningModelSessionOptions const& learningModelSessionOptions) try : model_(model), - device_(deviceToRunOn), - session_options_(learningModelSessionOptions) { + winml::LearningModel const& model, + winml::LearningModelDevice const& deviceToRunOn, + winml::LearningModelSessionOptions const& learningModelSessionOptions) try : model_(model), + device_(deviceToRunOn), + session_options_(learningModelSessionOptions) { Initialize(); } WINML_CATCH_ALL @@ -55,8 +55,8 @@ LearningModelSession::GetOptimizedModel() { // Get the model proto auto should_close_model = - session_options_ != nullptr && - session_options_.CloseModelOnSessionCreation(); + session_options_ != nullptr && + session_options_.CloseModelOnSessionCreation(); return GetOptimizedModel(should_close_model); } @@ -91,7 +91,7 @@ LearningModelSession::GetOptimizedModel(bool should_close_model) { void LearningModelSession::Initialize() { // Begin recording session creation telemetry _winmlt::TelemetryEvent session_creation_event( - _winmlt::EventCategory::kSessionCreation); + _winmlt::EventCategory::kSessionCreation); // Get the optimized model proto from the learning model com_ptr<_winmla::IModelProto> model_proto; @@ -105,9 +105,9 @@ void LearningModelSession::Initialize() { com_ptr<_winmla::IOrtSessionBuilder> session_builder; WINML_THROW_IF_FAILED(adapter->CreateOrtSessionBuilder( - device_impl->GetD3DDevice(), - device_impl->GetDeviceQueue(), - session_builder.put())); + device_impl->GetD3DDevice(), + device_impl->GetDeviceQueue(), + session_builder.put())); com_ptr<_winmla::ISessionOptions> options; WINML_THROW_IF_FAILED(session_builder->CreateSessionOptions(options.put())); @@ -115,7 +115,7 @@ void LearningModelSession::Initialize() { // Make onnxruntime apply the batch size override, if any if (session_options_ && session_options_.BatchSizeOverride() != 0) { - options->SetBatchOverride(session_options_.BatchSizeOverride()); + options->SetBatchOverride(session_options_.BatchSizeOverride()); } com_ptr<_winmla::IInferenceSession> session; @@ -142,9 +142,9 @@ void LearningModelSession::Initialize() { inference_session_ = session; telemetry_helper.LogSessionCreation( - WinML::Strings::UTF8FromHString(model_.Name()), - device_impl->IsCpuDevice(), - device_impl->GetDeviceLuid()); + WinML::Strings::UTF8FromHString(model_.Name()), + device_impl->IsCpuDevice(), + device_impl->GetDeviceLuid()); } wfc::IPropertySet @@ -169,8 +169,8 @@ LearningModelSession::Device() try { WINML_CATCH_ALL auto CreateBinding( - LearningModelSession& session, - wfc::IMap const features) { + LearningModelSession& session, + wfc::IMap const features) { auto binding = winrt::make(session); for (auto feature : features.GetView()) { @@ -181,8 +181,8 @@ auto CreateBinding( winml::LearningModelEvaluationResult LearningModelSession::EvaluateFeatures( - wfc::IMap const features, - hstring const correlation_id) try { + wfc::IMap const features, + hstring const correlation_id) try { auto binding = CreateBinding(*this, features); return Evaluate(binding, correlation_id); } @@ -190,53 +190,53 @@ WINML_CATCH_ALL wf::IAsyncOperation LearningModelSession::EvaluateFeaturesAsync( - wfc::IMap const features, - hstring const correlation_id) { + wfc::IMap const features, + hstring const correlation_id) { auto binding = CreateBinding(*this, features); return EvaluateAsync(binding, correlation_id); } static _winmla::IIOBinding* GetIOBinding( - winrt::com_ptr binding_impl, - winml::LearningModel& model) { + winrt::com_ptr binding_impl, + winml::LearningModel& model) { // Get the IOBinding Collection, and bound outputs - com_ptr<_winmla::IIOBinding> io_binding; - io_binding.attach(binding_impl->BindingCollection()); + com_ptr<_winmla::IIOBinding> io_binding; + io_binding.attach(binding_impl->BindingCollection()); auto& bound_output_names = io_binding->GetOutputNames(); std::unordered_set bound_output_names_set( - bound_output_names.begin(), - bound_output_names.end()); + bound_output_names.begin(), + bound_output_names.end()); // Get model output feature names auto model_impl = model.as(); auto output_features = model_impl->OutputFeatures(); std::vector output_descriptors( - begin(output_features), - end(output_features)); + begin(output_features), + end(output_features)); // Convert all output features to their feature names std::vector output_feature_names; std::transform( - std::begin(output_descriptors), - std::end(output_descriptors), - std::back_inserter(output_feature_names), - [&](auto& descriptor) { - auto descriptor_native = descriptor.as(); - const wchar_t* p_name; - uint32_t size; - WINML_THROW_IF_FAILED(descriptor_native->GetName(&p_name, &size)); - return WinML::Strings::UTF8FromUnicode(p_name, size); - }); + std::begin(output_descriptors), + std::end(output_descriptors), + std::back_inserter(output_feature_names), + [&](auto& descriptor) { + auto descriptor_native = descriptor.as(); + const wchar_t* p_name; + uint32_t size; + WINML_THROW_IF_FAILED(descriptor_native->GetName(&p_name, &size)); + return WinML::Strings::UTF8FromUnicode(p_name, size); + }); // Find the set difference to determine if there are any unbound output features std::vector unbound_output_names; std::copy_if( - std::begin(output_feature_names), std::end(output_feature_names), - std::inserter(unbound_output_names, std::begin(unbound_output_names)), - [&](const auto& outputFeatureName) { - return bound_output_names_set.find(outputFeatureName) == bound_output_names_set.end(); - }); + std::begin(output_feature_names), std::end(output_feature_names), + std::inserter(unbound_output_names, std::begin(unbound_output_names)), + [&](const auto& outputFeatureName) { + return bound_output_names_set.find(outputFeatureName) == bound_output_names_set.end(); + }); // Add all unbound outputs to the iobinding collection for (const auto& unbound_output : unbound_output_names) { @@ -274,9 +274,9 @@ LearningModelSession::Run( winml::LearningModelEvaluationResult LearningModelSession::GetResults( - winrt::com_ptr binding_impl, - hstring const& correlation_id, - uint64_t evaluation_complete_fence) { + winrt::com_ptr binding_impl, + hstring const& correlation_id, + uint64_t evaluation_complete_fence) { // First wait on the fence value for the expected frame. This is passed in so that // the fence value is added to the queue in a thread safe manor. auto device = device_.as(); @@ -418,10 +418,10 @@ LearningModelSession::CreateSessionBinding() { void LearningModelSession::ApplyEvaluationProperties() try { if (evaluation_properties_) { auto is_debug_output_enabled = evaluation_properties_.HasKey(c_enable_debug_output); - if (is_debug_output_enabled) { - com_ptr<_winmla::IWinMLAdapter> adapter; - WINML_THROW_IF_FAILED(OrtGetWinMLAdapter(adapter.put())); - adapter->EnableDebugOutput(); + if (is_debug_output_enabled) { + com_ptr<_winmla::IWinMLAdapter> adapter; + WINML_THROW_IF_FAILED(OrtGetWinMLAdapter(adapter.put())); + adapter->EnableDebugOutput(); } } }