Not using predefined marco to check EP (#22654)

### Description
We'll build CUDA EP and DML  EP in one package.
As a result, USE_DML and USE_CUDA will coexist.
We can't use predefined macros to check EP any more


### Motivation and Context
Other changes are in test code, so I make this change of core runtime
into one PR.
This commit is contained in:
Yi Zhang 2024-10-31 08:46:13 +08:00 committed by GitHub
parent 03ea5dc495
commit 5200e098aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,15 +62,16 @@ namespace {
struct DataTransfer {
std::unique_ptr<IExecutionProvider> ep;
std::unique_ptr<IDataTransfer> data_transfer;
bool is_dml = false;
Status CopyTensor(const Tensor& src, Tensor& dst) const {
return data_transfer->CopyTensor(src, dst);
}
Status Sync() const {
#if USE_DML
return ep->Sync();
#else
return Status::OK();
#endif
if (is_dml) {
return ep->Sync();
} else {
return Status::OK();
}
}
};
} // namespace
@ -94,6 +95,7 @@ static Status GetDataTransfer(const OrtMemoryInfo& mem_info, [[maybe_unused]] Da
#ifdef USE_DML
auto ep_factory = onnxruntime::DMLProviderFactoryCreator::Create(ConfigOptions{}, 0, false, false, false);
dt.ep = ep_factory->CreateProvider();
dt.is_dml = true;
dt.data_transfer = dt.ep->GetDataTransfer();
#else
status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "DML provider is not enabled in this build");