Windows Hibernation Tutorial¶
Introduction¶
hibernation is a Windows system power states. This tutorial describes how to safely enter hibernation, while running a QNN application, and provides code snippets demonstrating the QNN API calls used to release system resources.
Steps for safe hibernation¶
Free context¶
Any contexts created in a QNN backend should be released:
1 if (QNN_CONTEXT_NO_ERROR !=
2 m_qnnFunctionPointers.qnnInterface.contextFree(context, profileBackendHandle)) {
3 QNN_ERROR("Could not free context");
4 return StatusCode::FAILURE;
5 }
Free device¶
Devices created through the QNN API should be freed next:
1 if (QNN_DEVICE_NO_ERROR !=
2 m_qnnFunctionPointers.qnnInterface.deviceFree(deviceHandle)) {
3 QNN_ERROR("Failed to free device");
4 return StatusCode::FAILURE;
5 }
Free backend¶
The application should then free any backends created:
1 if (QNN_BACKEND_NO_ERROR !=
2 m_qnnFunctionPointers.qnnInterface.backendFree(backendHandle)) {
3 QNN_ERROR("Could not free backend");
4 return StatusCode::FAILURE;
5 }
Close backend library¶
Finaly, the application should close the backend library:
Loading a backend from SampleApp as shown below:
1 if (libBackendHandle) {
2 pal::dynamicloading::dlClose(libBackendHandle);
3 }
Full SampleApp Hibernation Example¶
Now we can bring all the steps together using SampleApp as an example.
1 // Free context first
2 if (QNN_CONTEXT_NO_ERROR !=
3 m_qnnFunctionPointers.qnnInterface.contextFree(context, profileBackendHandle)) {
4 QNN_ERROR("Could not free context");
5 return StatusCode::FAILURE;
6 }
7
8 // Free device if needed
9 if (QNN_DEVICE_NO_ERROR !=
10 m_qnnFunctionPointers.qnnInterface.deviceFree(deviceHandle)) {
11 QNN_ERROR("Failed to free device");
12 return StatusCode::FAILURE;
13 }
14
15 // Free backend
16 if (QNN_BACKEND_NO_ERROR !=
17 m_qnnFunctionPointers.qnnInterface.backendFree(backendHandle)) {
18 QNN_ERROR("Could not free backend");
19 return StatusCode::FAILURE;
20 }
21
22 // Close backhandle
23 if (libBackendHandle) {
24 pal::dynamicloading::dlClose(libBackendHandle);
25 }
26
27 // This turns device into hibernation mode
28 SetSuspendState(true, true, false);
29 // Get back from hibernation
30 return EXIT_SUCCESS;