Layer dev paulm (#2506)

* 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
This commit is contained in:
Paul McDaniel 2019-11-27 15:04:47 -08:00 committed by GitHub
parent 2cfee5744b
commit e8e285dd97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 938 additions and 1019 deletions

View file

@ -456,7 +456,7 @@ set_target_properties(winml_dll
set_target_properties(winml_dll
PROPERTIES
LINK_FLAGS
"/DEF:${WINML_DIR}/windows.ai.machinelearning.def ${os_component_link_flags} /DELAYLOAD:d3d12.dll /DELAYLOAD:d3d11.dll /DELAYLOAD:dxgi.dll")
"/DEF:${WINML_DIR}/windows.ai.machinelearning.def ${os_component_link_flags} /DELAYLOAD:d3d12.dll /DELAYLOAD:d3d11.dll /DELAYLOAD:dxgi.dll /DELAYLOAD:directml.dll")
set_target_properties(winml_dll
PROPERTIES

View file

@ -358,7 +358,7 @@ inline Value Value::CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_
}
template <>
inline Value Value::CreateTensor<std::string>(const OrtMemoryInfo* info, std::string* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len) {
inline Value Value::CreateTensor<std::string>(const OrtMemoryInfo*, std::string* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len) {
// convert the array of std::string to an array of const char *
std::vector<const char*> string_vector;
for (int i = 0; i < p_data_element_count; ++i) {

View file

@ -91,29 +91,48 @@ class ModelInfo : public Microsoft::WRL::RuntimeClass<
Initialize(model_proto);
}
std::string& STDMETHODCALLTYPE author() override {
return author_;
const char* STDMETHODCALLTYPE author() override {
return author_.c_str();
}
std::string& STDMETHODCALLTYPE name() override {
return name_;
const char* STDMETHODCALLTYPE name() override {
return name_.c_str();
}
std::string& STDMETHODCALLTYPE domain() override {
return domain_;
const char* STDMETHODCALLTYPE domain() override {
return domain_.c_str();
}
std::string& STDMETHODCALLTYPE description() override {
return description_;
const char* STDMETHODCALLTYPE description() override {
return description_.c_str();
}
int64_t STDMETHODCALLTYPE version() override {
return version_;
}
std::unordered_map<std::string, std::string>& STDMETHODCALLTYPE model_metadata() override {
return model_metadata_;
HRESULT STDMETHODCALLTYPE GetModelMetadata(
ABI::Windows::Foundation::Collections::IMapView<HSTRING, HSTRING>** metadata) override {
*metadata = nullptr;
std::unordered_map<winrt::hstring, winrt::hstring> map_copy;
for (auto& pair : model_metadata_) {
auto key = WinML::Strings::HStringFromUTF8(pair.first);
auto map_value = WinML::Strings::HStringFromUTF8(pair.second);
map_copy.emplace(std::move(key), std::move(map_value));
}
auto out = winrt::single_threaded_map<winrt::hstring, winrt::hstring>(
std::move(map_copy));
winrt::copy_to_abi(out.GetView(), *(void**)metadata);
return S_OK;
}
wfc::IVector<winml::ILearningModelFeatureDescriptor>& STDMETHODCALLTYPE input_features() override {
return input_features_;
HRESULT STDMETHODCALLTYPE GetInputFeatures(
ABI::Windows::Foundation::Collections::IVectorView<winml::ILearningModelFeatureDescriptor>** features) override{
*features = nullptr;
winrt::copy_to_abi(input_features_.GetView(), *(void**)features);
return S_OK;
}
wfc::IVector<winml::ILearningModelFeatureDescriptor>& STDMETHODCALLTYPE output_features() override {
return output_features_;
HRESULT STDMETHODCALLTYPE GetOutputFeatures(
ABI::Windows::Foundation::Collections::IVectorView<winml::ILearningModelFeatureDescriptor>** features) override {
*features = nullptr;
winrt::copy_to_abi(output_features_.GetView(), *(void**)features);
return S_OK;
}
static std::vector<const char*>

View file

@ -10,14 +10,14 @@ TRACELOGGING_DECLARE_PROVIDER(winml_trace_logging_provider);
MIDL_INTERFACE("eaae30b5-7381-432d-9730-322136b02371") IModelInfo : IUnknown{
// model metadata
virtual std::string& STDMETHODCALLTYPE author() = 0;
virtual std::string& STDMETHODCALLTYPE name() = 0;
virtual std::string& STDMETHODCALLTYPE domain() = 0;
virtual std::string& STDMETHODCALLTYPE description() = 0;
virtual int64_t STDMETHODCALLTYPE version() = 0;
virtual std::unordered_map<std::string, std::string>& STDMETHODCALLTYPE model_metadata() = 0;
virtual wfc::IVector<winml::ILearningModelFeatureDescriptor>& STDMETHODCALLTYPE input_features() = 0;
virtual wfc::IVector<winml::ILearningModelFeatureDescriptor>& STDMETHODCALLTYPE output_features() = 0;
virtual const char* STDMETHODCALLTYPE author() = 0;
virtual const char* STDMETHODCALLTYPE name() = 0;
virtual const char* STDMETHODCALLTYPE domain() = 0;
virtual const char* STDMETHODCALLTYPE description() = 0;
virtual int64_t STDMETHODCALLTYPE version() = 0;
virtual HRESULT STDMETHODCALLTYPE GetModelMetadata(ABI::Windows::Foundation::Collections::IMapView<HSTRING, HSTRING> ** metadata) = 0;
virtual HRESULT STDMETHODCALLTYPE GetInputFeatures(ABI::Windows::Foundation::Collections::IVectorView<winml::ILearningModelFeatureDescriptor> * *features) = 0;
virtual HRESULT STDMETHODCALLTYPE GetOutputFeatures(ABI::Windows::Foundation::Collections::IVectorView<winml::ILearningModelFeatureDescriptor> * *features) = 0;
};
MIDL_INTERFACE("438e7719-554a-4058-84d9-eb6226c34887") IIOBinding : IUnknown{
@ -80,9 +80,6 @@ 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;
// factory method for creating an ortsessionbuilder from a device
virtual HRESULT STDMETHODCALLTYPE CreateOrtSessionBuilder(
ID3D12Device* device,
@ -105,6 +102,8 @@ MIDL_INTERFACE("b19385e7-d9af-441a-ba7f-3993c7b1c9db") IWinMLAdapter : IUnknown
virtual void* STDMETHODCALLTYPE CreateGPUAllocationFromD3DResource(ID3D12Resource* pResource) = 0;
virtual void STDMETHODCALLTYPE FreeGPUAllocation(void* ptr) = 0;
virtual HRESULT STDMETHODCALLTYPE CopyTensor(onnxruntime::IExecutionProvider* provider, OrtValue* src, OrtValue* dst) = 0;
// note: this returns a weak ref
virtual ID3D12Resource* STDMETHODCALLTYPE GetD3D12ResourceFromAllocation(onnxruntime::IExecutionProvider * provider, void* allocation) = 0;
// schema overrides (dml does this for us)
virtual HRESULT STDMETHODCALLTYPE OverrideSchemaInferenceFunctions() = 0;

View file

@ -3,10 +3,7 @@
#include "pch.h"
#ifdef USE_DML
#include "DirectML.h"
#endif USE_DML
#include <d3d11on12.h>
#include <wil/winrt.h>
#include "inc/DeviceHelpers.h"
@ -147,7 +144,6 @@ bool IsFloat16Supported(ID3D12Device* device) {
return false;
}
#ifdef USE_DML
winrt::com_ptr<IDMLDevice> dmlDevice;
winrt::check_hresult(DMLCreateDevice(
device,
@ -165,9 +161,6 @@ 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.

View file

@ -66,6 +66,7 @@ void LearningModel::LogCreationEvent(bool fromStream) {
break;
}
}
#ifdef LAYERING_DONE
telemetry_helper.LogModelCreation(
fromStream,
model_info_->author(),
@ -75,6 +76,7 @@ void LearningModel::LogCreationEvent(bool fromStream) {
model_info_->version(),
use_fp16,
model_info_->model_metadata());
#endif
}
void LearningModel::ModelUseFP16(
@ -140,15 +142,11 @@ WINML_CATCH_ALL
wfc::IMapView<hstring, hstring>
LearningModel::Metadata() try {
std::unordered_map<hstring, hstring> map_copy;
for (auto& pair : model_info_->model_metadata()) {
auto key = WinML::Strings::HStringFromUTF8(pair.first);
auto value = WinML::Strings::HStringFromUTF8(pair.second);
map_copy.emplace(std::move(key), std::move(value));
}
auto metadata = winrt::single_threaded_map<winrt::hstring, winrt::hstring>(
std::move(map_copy));
return metadata.GetView();
ABI::Windows::Foundation::Collections::IMapView<HSTRING,HSTRING>* metadata;
wfc::IMapView<hstring, hstring> out;
WINML_THROW_IF_FAILED(model_info_->GetModelMetadata(&metadata));
winrt::attach_abi(out, metadata);
return out;
}
WINML_CATCH_ALL
@ -169,13 +167,21 @@ LearningModel::GetOperatorRegistry() {
wfc::IVectorView<winml::ILearningModelFeatureDescriptor>
LearningModel::InputFeatures() try {
return model_info_->input_features().GetView();
ABI::Windows::Foundation::Collections::IVectorView<winml::ILearningModelFeatureDescriptor>* features;
wfc::IVectorView<winml::ILearningModelFeatureDescriptor> out;
WINML_THROW_IF_FAILED(model_info_->GetInputFeatures(&features));
winrt::attach_abi(out, features);
return out;
}
WINML_CATCH_ALL
wfc::IVectorView<winml::ILearningModelFeatureDescriptor>
LearningModel::OutputFeatures() try {
return model_info_->output_features().GetView();
ABI::Windows::Foundation::Collections::IVectorView<winml::ILearningModelFeatureDescriptor>* features;
wfc::IVectorView<winml::ILearningModelFeatureDescriptor> out;
WINML_THROW_IF_FAILED(model_info_->GetOutputFeatures(&features));
winrt::attach_abi(out, features);
return out;
}
WINML_CATCH_ALL

View file

@ -213,6 +213,8 @@ bool LearningModelBinding::HasKey(hstring const& key) {
void LearningModelBinding::Split(
Windows::Foundation::Collections::IMapView<hstring, Windows::Foundation::IInspectable>& first,
Windows::Foundation::Collections::IMapView<hstring, Windows::Foundation::IInspectable>& second) {
ORT_UNUSED_PARAMETER(first);
ORT_UNUSED_PARAMETER(second);
throw hresult_not_implemented();
}

View file

@ -160,6 +160,7 @@ struct MapBase : winrt::implements<
STDMETHOD(GetOrtValue)
(WinML::BindingContext& context, OrtValue** ort_value) {
ORT_UNUSED_PARAMETER(context);
// TODO: Tensorized data should be cached so multiple bindings work more efficiently
// TODO : we need to handle inputs. for now only handle outputs and don't pre allocate anything
@ -185,6 +186,7 @@ struct MapBase : winrt::implements<
STDMETHOD(UpdateSourceResourceData)
(BindingContext& context, OrtValue* ort_value) {
ORT_UNUSED_PARAMETER(context);
data_.Clear();
Ort::AllocatorWithDefaultOptions allocator;

View file

@ -266,6 +266,7 @@ struct SequenceBase : public winrt::implements<
STDMETHOD(UpdateSourceResourceData)(
BindingContext& context,
OrtValue* ort_value) {
ORT_UNUSED_PARAMETER(context);
auto writable_vector = data_.as<wfc::IVector<T>>();
writable_vector.Clear();

View file

@ -12,6 +12,7 @@
#include <psapi.h>
#include <string>
#include <array>
#include "core/common/common.h"
#define TIMER_SLOT_SIZE (128)
#define CONVERT_100NS_TO_SECOND(x) ((x)*0.0000001)
@ -330,6 +331,7 @@ class GpuPerfCounter : public IPerfCounter {
}
void GetValues(double (&values)[CounterType::TYPE_COUNT], double time) override {
ORT_UNUSED_PARAMETER(time);
values[CounterType::GPU_USAGE] = GetGpuUsage();
values[CounterType::GPU_DEDICATED_MEM_USAGE] = GetDedicatedMemory();
values[CounterType::GPU_SHARED_MEM_USAGE] = GetSharedMemory();

View file

@ -84,10 +84,10 @@ class WinMLTelemetryHelper {
void LogDllAttachEvent();
void LogSessionCreation(const std::string& modelname, bool isCpu, LUID adapterLuid);
void LogModelCreation(bool fromStream,
const std::string& author,
const std::string& name,
const std::string& domain,
const std::string& description,
const char* author,
const char* name,
const char* domain,
const char* description,
int64_t version,
bool bUseFP16,
const std::unordered_map<std::string, std::string>& modelMetadata);

View file

@ -51,10 +51,10 @@ void WinMLTelemetryHelper::LogSessionCreation(const std::string& modelname, bool
}
void WinMLTelemetryHelper::LogModelCreation(bool fromStream,
const std::string& author,
const std::string& name,
const std::string& domain,
const std::string& description,
const char* author,
const char* name,
const char* domain,
const char* description,
int64_t version,
bool bUseFP16,
const std::unordered_map<std::string, std::string>& modelMetadata) {
@ -87,10 +87,10 @@ void WinMLTelemetryHelper::LogModelCreation(bool fromStream,
//stream
TraceLoggingBool(fromStream, "fromStream"),
// Model Desc
TraceLoggingString(author.c_str(), "author"),
TraceLoggingString(name.c_str(), "name"),
TraceLoggingString(domain.c_str(), "domain"),
TraceLoggingString(description.c_str(), "description"),
TraceLoggingString(author, "author"),
TraceLoggingString(name, "name"),
TraceLoggingString(domain, "domain"),
TraceLoggingString(description, "description"),
TraceLoggingInt64(version, "version"),
TraceLoggingBool(bUseFP16, "usefp16"),
TraceLoggingString(BitmapPixelFormatString.c_str(), "bitmappixelformat"),

View file

@ -149,6 +149,7 @@ void ModelValidator::FnsCandy16(
bool bindInputsAsIInspectable,
float dataTolerance)
{
ORT_UNUSED_PARAMETER(dataTolerance);
WINML_PROFILING_START(g_RuntimeProfiler, WINML_RUNTIME_TEST_PERF::PREP_TEST);
// file name strings
static wchar_t* modelFileName = L"winmlperf_coreml_FNS-Candy_prerelease_fp16.onnx";

View file

@ -41,6 +41,7 @@ struct NullOperatorFactory : winrt::implements<NullOperatorFactory, IMLOperatorK
IMLOperatorKernelCreationContext* context,
IMLOperatorKernel** kernel)
{
ORT_UNUSED_PARAMETER(context);
auto op = winrt::make<NullOperator>(m_callCount);
op.copy_to(kernel);
return S_OK;
@ -48,6 +49,7 @@ struct NullOperatorFactory : winrt::implements<NullOperatorFactory, IMLOperatorK
static MLOperatorEdgeDescription CreateEdgeDescriptor(MLOperatorEdgeType type, MLOperatorTensorDataType dataType)
{
ORT_UNUSED_PARAMETER(type);
MLOperatorEdgeDescription desc;
desc.edgeType = MLOperatorEdgeType::Tensor;
desc.tensorDataType = dataType;

View file

@ -1,6 +1,7 @@
#pragma once
#include "core/providers/dml/DmlExecutionProvider/inc/MLOperatorAuthor.h"
#include "core/common//common.h"
struct NoisyReluShapeInferrer : winrt::implements<NoisyReluShapeInferrer, IMLOperatorShapeInferrer>
{
@ -144,6 +145,7 @@ struct NoisyReluOperatorFactory : winrt::implements<NoisyReluOperatorFactory, IM
static MLOperatorEdgeDescription CreateEdgeDescriptor(MLOperatorEdgeType type, MLOperatorTensorDataType dataType)
{
ORT_UNUSED_PARAMETER(type);
MLOperatorEdgeDescription desc;
desc.edgeType = MLOperatorEdgeType::Tensor;
desc.tensorDataType = dataType;

View file

@ -1,6 +1,7 @@
#pragma once
#include "core/providers/dml/DmlExecutionProvider/inc/MLOperatorAuthor.h"
#include "core/common//common.h"
struct ReluShapeInferrer : winrt::implements<ReluShapeInferrer, IMLOperatorShapeInferrer>
{
@ -104,6 +105,7 @@ struct ReluOperatorFactory : winrt::implements<ReluOperatorFactory, IMLOperatorK
IMLOperatorKernelCreationContext* context,
IMLOperatorKernel** kernel)
{
ORT_UNUSED_PARAMETER(context);
auto reluOperator = winrt::make<ReluOperator>();
reluOperator.copy_to(kernel);
return S_OK;
@ -111,6 +113,7 @@ struct ReluOperatorFactory : winrt::implements<ReluOperatorFactory, IMLOperatorK
static MLOperatorEdgeDescription CreateEdgeDescriptor(MLOperatorEdgeType type, MLOperatorTensorDataType dataType)
{
ORT_UNUSED_PARAMETER(type);
MLOperatorEdgeDescription desc;
desc.edgeType = MLOperatorEdgeType::Tensor;
desc.tensorDataType = dataType;