From 56cbd82c71f125de7e50377c51c869bf3acb571e Mon Sep 17 00:00:00 2001 From: Paul McDaniel Date: Thu, 5 Dec 2019 18:14:20 -0800 Subject: [PATCH] Layer dev paulm (#2567) * commetns for dml graph transformer fixed ort value passing using the allocatir info * fixed and coded maps and sequences across the abi * cleaned up w4's cleaned up the model info ABI delayload directml.dll from winml * cleaned up namepsace aliases. renamed _winmla to winmla this was good PR feedback from tiago a while back. * moved files from inc to lib\api.core cleaned up some of the cmake * staged changes * making windowsAI azure dev ops work. * code review comments. * revert changes --- .../core/session/onnxruntime_cxx_api.h | 6 +++-- .../inc/IWinmlExecutionProvider.h | 2 -- onnxruntime/core/session/IOBinding.cc | 5 ----- onnxruntime/core/session/IOBinding.h | 1 - winml/adapter/MLValueHelpers.h | 7 ------ winml/adapter/TensorBaseHelpers.h | 8 ------- winml/lib/Api/LearningModelBinding.cpp | 22 +++++++++---------- winml/lib/Api/LearningModelSession.cpp | 2 +- winml/lib/Api/impl/MapBase.h | 1 - winml/lib/Api/impl/Tensor.h | 1 - 10 files changed, 15 insertions(+), 40 deletions(-) delete mode 100644 winml/adapter/MLValueHelpers.h delete mode 100644 winml/adapter/TensorBaseHelpers.h diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h index 798459d3fc..c466b0cb8a 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h @@ -75,7 +75,9 @@ ORT_DEFINE_RELEASE(Value); // This is used internally by the C++ API. This is the common base class used by the wrapper objects. template struct Base { - Base() = default; + Base() { + p_ = nullptr; + } Base(T* p) : p_{p} { if (!p) throw Ort::Exception("Allocation failure", ORT_FAIL); } @@ -95,7 +97,7 @@ struct Base { } T** put() noexcept { - //ASSERT(p_ == nullptr); + assert(p_ == nullptr); return &p_; } diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h index 605aec43d8..86c5e8a22b 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/inc/IWinmlExecutionProvider.h @@ -10,8 +10,6 @@ #include "core/framework/op_kernel.h" -#include - struct AbstractOperatorDesc; interface IMLOperatorTensor; diff --git a/onnxruntime/core/session/IOBinding.cc b/onnxruntime/core/session/IOBinding.cc index a57927a601..878740fea2 100644 --- a/onnxruntime/core/session/IOBinding.cc +++ b/onnxruntime/core/session/IOBinding.cc @@ -8,11 +8,6 @@ #include "core/framework/utils.h" namespace onnxruntime { -IOBinding::~IOBinding() { - feeds_.clear(); - outputs_.clear(); -} - IOBinding::IOBinding(const SessionState& session_state) : session_state_(session_state) { } diff --git a/onnxruntime/core/session/IOBinding.h b/onnxruntime/core/session/IOBinding.h index 15c1d03e3b..be567b1e65 100644 --- a/onnxruntime/core/session/IOBinding.h +++ b/onnxruntime/core/session/IOBinding.h @@ -38,7 +38,6 @@ class SessionState; */ class IOBinding { public: - ~IOBinding(); /** * Call repeatedly to bind as many inputs as required. * If called again for the same name will replace an existing value. diff --git a/winml/adapter/MLValueHelpers.h b/winml/adapter/MLValueHelpers.h deleted file mode 100644 index fe9da31e8c..0000000000 --- a/winml/adapter/MLValueHelpers.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -namespace Windows::AI::MachineLearning { -} // namespace Windows::AI::MachineLearning \ No newline at end of file diff --git a/winml/adapter/TensorBaseHelpers.h b/winml/adapter/TensorBaseHelpers.h deleted file mode 100644 index 5c9b2c3388..0000000000 --- a/winml/adapter/TensorBaseHelpers.h +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -namespace Windows::AI::MachineLearning { - -} // namespace Windows::AI::MachineLearning \ No newline at end of file diff --git a/winml/lib/Api/LearningModelBinding.cpp b/winml/lib/Api/LearningModelBinding.cpp index 128d65a838..d2e7fb0156 100644 --- a/winml/lib/Api/LearningModelBinding.cpp +++ b/winml/lib/Api/LearningModelBinding.cpp @@ -15,7 +15,7 @@ using namespace WinML; namespace winrt::Windows::AI::MachineLearning::implementation { LearningModelBinding::LearningModelBinding( - Windows::AI::MachineLearning::LearningModelSession const& session) try : m_session(session) { + Windows::AI::MachineLearning::LearningModelSession const& session) try : m_session(session) { session.as()->CheckClosed(); WINML_THROW_IF_FAILED(OrtGetWinMLAdapter(adapter_.put())); } @@ -219,12 +219,12 @@ bool LearningModelBinding::HasKey(hstring const& key) { void LearningModelBinding::Split( Windows::Foundation::Collections::IMapView& first, Windows::Foundation::Collections::IMapView& second) { - ORT_UNUSED_PARAMETER(first); - ORT_UNUSED_PARAMETER(second); - throw hresult_not_implemented(); + // the winrt api guide states: + // If the IMapView instance cannot be split, then both the first and second parameters are null when the method returns. + first = nullptr; + second = nullptr; } - ONNXTensorElementDataType STDMETHODCALLTYPE GetONNXTensorElementDataType(winml::TensorKind kind) { if (kind == TensorKind::Float) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT; @@ -275,7 +275,6 @@ bool LearningModelBinding::IsOfMapType(const Ort::Value& ort_value, TensorKind k }; bool LearningModelBinding::IsOfVectorMapType(const Ort::Value& ort_value, TensorKind key_kind, TensorKind value_kind) { - if (ort_value.GetTypeInfo().GetONNXType() != ONNX_TYPE_SEQUENCE) return false; @@ -305,7 +304,7 @@ ILearningModelFeatureValue LearningModelBinding::CreateUnboundOuputFeatureValue( if (descriptor.Kind() == LearningModelFeatureKind::Image) { using namespace Windows::Graphics::Imaging; // TODO: this format for unbound output needs more discussion - BitmapPixelFormat format = descriptor.as()->BitmapPixelFormat(); + BitmapPixelFormat format = descriptor.as()->BitmapPixelFormat(); uint32_t width = static_cast(ort_value.GetTensorTypeAndShapeInfo().GetShape()[3]); uint32_t height = static_cast(ort_value.GetTensorTypeAndShapeInfo().GetShape()[2]); uint32_t batchSize = static_cast(ort_value.GetTensorTypeAndShapeInfo().GetShape()[0]); @@ -388,7 +387,7 @@ ILearningModelFeatureValue LearningModelBinding::CreateUnboundOuputFeatureValue( Windows::Foundation::IInspectable LearningModelBinding::CreateUnboundOutput( const std::string& name, - Ort::Value& ort_value) { + Ort::Value& ort_value) { // Find valid binding port auto bindingPort = FindValidBinding( m_session.Model(), @@ -539,8 +538,8 @@ HRESULT LearningModelBinding::BindInput(const std::string& name, Ort::Value& ml_ if (ml_value.IsTensor()) { Ort::Value new_mlvalue = Ort::Value(nullptr); WINML_THROW_IF_FAILED(m_session.as() - ->GetIInferenceSession() - ->CopyOneInputAcrossDevices(name.c_str(), ml_value, new_mlvalue.put())); + ->GetIInferenceSession() + ->CopyOneInputAcrossDevices(name.c_str(), ml_value, new_mlvalue.put())); add_or_replace(rc.first, rc.second, new_mlvalue); } else { add_or_replace(rc.first, rc.second, ml_value); @@ -574,8 +573,7 @@ const std::vector& LearningModelBinding::GetInputNames() const { const std::vector& LearningModelBinding::GetInputs() const { return inputs_; } -void LearningModelBinding::BindUnboundOutputs() -{ +void LearningModelBinding::BindUnboundOutputs() { auto& bound_output_names = GetOutputNames(); std::unordered_set bound_output_names_set( bound_output_names.begin(), diff --git a/winml/lib/Api/LearningModelSession.cpp b/winml/lib/Api/LearningModelSession.cpp index 190e2bd31a..ccfd736cec 100644 --- a/winml/lib/Api/LearningModelSession.cpp +++ b/winml/lib/Api/LearningModelSession.cpp @@ -109,7 +109,7 @@ void LearningModelSession::Initialize() { device_impl->GetDeviceQueue(), session_builder.put())); - Ort::SessionOptions options; + Ort::SessionOptions options(nullptr); WINML_THROW_IF_FAILED(session_builder->CreateSessionOptions(options.put())); // Make onnxruntime apply the batch size override, if any diff --git a/winml/lib/Api/impl/MapBase.h b/winml/lib/Api/impl/MapBase.h index 76ff6e3920..632ef1e677 100644 --- a/winml/lib/Api/impl/MapBase.h +++ b/winml/lib/Api/impl/MapBase.h @@ -47,7 +47,6 @@ struct MapBase : winrt::implements< using LotusKey = typename ValidLotusType::Type; using LotusValue = typename ValidLotusType::Type; - //using LotusMap = std::map; using LotusMap = std::pair, std::vector>; using ABIMap = ::winrt::Windows::Foundation::Collections::IMap; using ABIMapView = ::winrt::Windows::Foundation::Collections::IMapView; diff --git a/winml/lib/Api/impl/Tensor.h b/winml/lib/Api/impl/Tensor.h index 9d2b9dace1..69503cb42b 100644 --- a/winml/lib/Api/impl/Tensor.h +++ b/winml/lib/Api/impl/Tensor.h @@ -4,7 +4,6 @@ #pragma once #include "TensorBuffer.h" -#include "MLValueHelpers.h" // we further specialize these base types for a couple of extra tensor element types namespace Ort {