From b248f2979a7622150952575b751a4d37b4791fd0 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Mon, 9 Dec 2019 12:00:57 -0800 Subject: [PATCH] Throw Winml_err_invalid_binding if binding gpu resource on cpu device (#2589) * Throw Winml_err_invalid_binding if binding gpu resource on cpu device * PR comments. No need to query executionprovider for is gpu device --- winml/lib/Api/LearningModelSession.cpp | 2 +- winml/lib/Api/impl/TensorBase.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/winml/lib/Api/LearningModelSession.cpp b/winml/lib/Api/LearningModelSession.cpp index ccfd736cec..41755e95c6 100644 --- a/winml/lib/Api/LearningModelSession.cpp +++ b/winml/lib/Api/LearningModelSession.cpp @@ -138,7 +138,7 @@ void LearningModelSession::Initialize() { model_proto = nullptr; // Initialize the session - session_builder->Initialize(session.get(), cached_execution_provider_); + WINML_THROW_IF_FAILED(session_builder->Initialize(session.get(), cached_execution_provider_)); // Cache the constructed session inference_session_ = session; diff --git a/winml/lib/Api/impl/TensorBase.h b/winml/lib/Api/impl/TensorBase.h index bfdc34e4c1..40ef0e625d 100644 --- a/winml/lib/Api/impl/TensorBase.h +++ b/winml/lib/Api/impl/TensorBase.h @@ -105,6 +105,11 @@ struct TensorBase : TBase { auto provider = session_impl->GetExecutionProvider(); WINML_THROW_IF_FAILED(adapter_->GetProviderMemoryInfo(provider, dml_memory.put())); + auto spSession = context.session.as(); + auto spDevice = spSession->Device().as(); + WINML_THROW_HR_IF_TRUE_MSG(WINML_ERR_INVALID_BINDING, + spDevice->IsCpuDevice(), + "Cannot create GPU tensor on CPU device"); // create the OrtValue as a tensor letting ort know that we own the data buffer auto value = Ort::Value::CreateTensor( dml_memory,