Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Intel NPU on DirectML_ESRGAN #670

Open
bonihaniboni opened this issue Nov 26, 2024 · 0 comments
Open

Using Intel NPU on DirectML_ESRGAN #670

bonihaniboni opened this issue Nov 26, 2024 · 0 comments

Comments

@bonihaniboni
Copy link

Hello, Thank you for your Hard Work

I have a question about using Intel NPU in DirectML_ESRGAN samples.

Since only QC NPU can run that sample, i try to change code to run that sample in Intel NPU.

So, I refer to DirectMLNpuInference sample, which works well on Intel NPU.

/* Original Code
// DML execution provider prefers these session options.
Ort::SessionOptions sessionOptions;
sessionOptions.DisableMemPattern();
sessionOptions.SetExecutionMode(ExecutionMode::ORT_SEQUENTIAL);
// sessionOptions.DisablePerSessionThreads();

// By passing in an explicitly created DML device & queue, the DML execution provider sends work
// to the desired device. If not used, the DML execution provider will create its own device & queue.
const OrtApi& ortApi = Ort::GetApi();
const OrtDmlApi* ortDmlApi = nullptr;
Ort::ThrowOnError(ortApi.GetExecutionProviderApi("DML", ORT_API_VERSION, reinterpret_cast<const void**>(&ortDmlApi)));
Ort::ThrowOnError(ortDmlApi->SessionOptionsAppendExecutionProvider_DML1(
sessionOptions,
dmlDevice,
d3dQueue
));

// Load ONNX model into a session.
Ort::Env env(OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, "DirectML_CV");
// .exe failed from here (under line)
Ort::Session ortSession(env, modelPath.wstring().c_str(), sessionOptions);

*/
// Changed Code from DirectMLNpuInference
 const OrtApi& ortApi = Ort::GetApi();
 static Ort::Env env{ nullptr };
 env = Ort::Env(Ort::ThreadingOptions{});
 env.DisableTelemetryEvents();

 auto sessionOptions = Ort::SessionOptions{};
 sessionOptions.DisableMemPattern();
 sessionOptions.DisablePerSessionThreads();
 sessionOptions.SetExecutionMode(ExecutionMode::ORT_SEQUENTIAL);
 const OrtDmlApi* ortDmlApi = nullptr;
 Ort::ThrowOnError(ortApi.GetExecutionProviderApi("DML", ORT_API_VERSION, reinterpret_cast<const void**>(&ortDmlApi)));
 Ort::ThrowOnError(ortDmlApi->SessionOptionsAppendExecutionProvider_DML1(sessionOptions, dmlDevice, d3dQueue));

 // Create the session
 auto ortSession = Ort::Session(env, L"esrgan.onnx", sessionOptions);
'''

But it still shows "2024-11-26 17:11:56.2608680 [E:onnxruntime:, inference_session.cc:2045 onnxruntime::InferenceSession::Initialize::<lambda_deb1d9a98dc3fb814563870e4f4b9f20>::operator ()] Exception during initialization:" Error. 
If anyone knows the reasons, please tell me... I will be very very appreciated....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant