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
This commit is contained in:
Ryan Lai 2019-12-09 12:00:57 -08:00 committed by GitHub
parent 09c9caab2d
commit b248f2979a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -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;

View file

@ -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<winrt::Windows::AI::MachineLearning::implementation::LearningModelSession>();
auto spDevice = spSession->Device().as<winrt::Windows::AI::MachineLearning::implementation::LearningModelDevice>();
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,