[DOC][CPU] Denormals optimization doc (#12127)
This commit is contained in:
@@ -231,6 +231,7 @@ All parameters must be set before calling `ov::Core::compile_model()` in order t
|
||||
- `ov::num_streams`
|
||||
- `ov::affinity`
|
||||
- `ov::inference_num_threads`
|
||||
- `ov::intel_cpu::denormals_optimization`
|
||||
|
||||
|
||||
### Read-only properties
|
||||
@@ -266,6 +267,35 @@ For some performance-critical DL operations, the CPU plugin uses optimized imple
|
||||
* SoftMax
|
||||
@endsphinxdirective
|
||||
|
||||
## Optimization guide
|
||||
|
||||
### Denormals Optimization
|
||||
Denormal number is non-zero, finite float number that is very close to zero, i.e. the numbers in (0, 1.17549e-38) and (0, -1.17549e-38). In such case, normalized-number encoding format does not have capability to encode the number and underflow will happen. The computation involving this kind of numbers is extremly slow on many hardware.
|
||||
|
||||
As denormal number is extremly close to zero, treating denormal as zero directly is a straightforward and simple method to optimize denormals computation. As this optimization does not comply with IEEE standard 754, in case it introduce unacceptable accuracy degradation, the propery(ov::intel_cpu::denormals_optimization) is introduced to control this behavior. If there are denormal numbers in users' use case, and see no or ignorable accuracy drop, we could set this property to "YES" to improve performance, otherwise set this to "NO". If it's not set explicitly by property, this optimization is disabled by default if application program also does not perform any denormals optimization. After this property is turned on, OpenVINO will provide an cross operation-system/compiler and safe optimization on all platform when applicable.
|
||||
|
||||
There are cases that application program where OpenVINO is used also perform this low-level denormals optimization. If it's optimized by setting FTZ(Flush-To-Zero) and DAZ(Denormals-As-Zero) flag in MXCSR register in the begining of thread where OpenVINO is called, OpenVINO will inherite this setting in the same thread and sub-thread, and then no need set with property. In this case, application program users should be responsible for the effectiveness and safty of the settings.
|
||||
|
||||
It need also to be mentioned that this property should must be set before calling 'compile_model()'.
|
||||
|
||||
To enable denormals optimization, the application must set ov::denormals_optimization property to true:
|
||||
|
||||
@sphinxdirective
|
||||
|
||||
.. tab:: C++
|
||||
|
||||
.. doxygensnippet:: docs/snippets/ov_denormals.cpp
|
||||
:language: cpp
|
||||
:fragment: [ov:intel_cpu:denormals_optimization:part0]
|
||||
|
||||
.. tab:: Python
|
||||
|
||||
.. doxygensnippet:: docs/snippets/ov_denormals.py
|
||||
:language: python
|
||||
:fragment: [ov:intel_cpu:denormals_optimization:part0]
|
||||
|
||||
@endsphinxdirective
|
||||
|
||||
## See Also
|
||||
* [Supported Devices](Supported_Devices.md)
|
||||
* [Optimization guide](@ref openvino_docs_optimization_guide_dldt_optimization_guide)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include <openvino/runtime/core.hpp>
|
||||
#include "openvino/runtime/intel_cpu/properties.hpp"
|
||||
|
||||
int main() {
|
||||
try {
|
||||
std::string modelPath = "modelWithDenormals.xml";
|
||||
std::string device = "CPU";
|
||||
ov::AnyMap config;
|
||||
//! [ov:intel_cpu:denormals_optimization:part0]
|
||||
ov::Core core; // Step 1: create ov::Core object
|
||||
core.set_property(ov::intel_cpu::denormals_optimization(true)); // Step 1b: Enable denormals optimization
|
||||
auto model = core.read_model(modelPath); // Step 2: Read Model
|
||||
//... // Step 3: Prepare inputs/outputs
|
||||
//... // Step 4: Set device configuration
|
||||
auto compiled = core.compile_model(model, device, config); // Step 5: LoadNetwork
|
||||
//! [ov:intel_cpu:denormals_optimization:part0]
|
||||
if (!compiled) {
|
||||
throw std::runtime_error("error");
|
||||
}
|
||||
} catch (...) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2022 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
import openvino.runtime as ov
|
||||
|
||||
device_name = 'CPU'
|
||||
xml_path = 'modelWithDenormals.xml'
|
||||
# ! [ov:intel_cpu:denormals_optimization:part0]
|
||||
core = ov.Core()
|
||||
core.set_property("CPU", ov.properties.intel_cpu.denormals_optimization(True))
|
||||
model = core.read_model(model=xml_path)
|
||||
compiled_model = core.compile_model(model=model, device_name=device_name)
|
||||
# ! [ov:intel_cpu:denormals_optimization:part0]
|
||||
assert compiled_model
|
||||
Reference in New Issue
Block a user