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

CPU snippets update #134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from .utils import get_image
from .utils import get_model
from .utils import get_ngraph_model
20 changes: 11 additions & 9 deletions docs/snippets/cpu/Bfloat16Inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
# SPDX-License-Identifier: Apache-2.0


from openvino.runtime import Core
import openvino as ov

from snippets import get_model

model = get_model()

#! [part0]
core = Core()
cpu_optimization_capabilities = core.get_property("CPU", "OPTIMIZATION_CAPABILITIES")
core = ov.Core()
cpu_optimization_capabilities = core.get_property("CPU", ov.properties.device.capabilities())
#! [part0]

# TODO: enable part1 when property api will be supported in python
#! [part1]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "CPU")
inference_precision = core.get_property("CPU", "INFERENCE_PRECISION_HINT")
inference_precision = core.get_property("CPU", ov.properties.hint.inference_precision())
#! [part1]

#! [part2]
core = Core()
core.set_property("CPU", {"INFERENCE_PRECISION_HINT": "f32"})
core = ov.Core()
core.set_property("CPU", {ov.properties.hint.inference_precision(): ov.Type.f32})
#! [part2]
2 changes: 2 additions & 0 deletions docs/snippets/cpu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
11 changes: 6 additions & 5 deletions docs/snippets/cpu/compile_model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from snippets import get_model

model = get_model()

#! [compile_model_default]
from openvino.runtime import Core
import openvino as ov

core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "CPU")
#! [compile_model_default]

#! [compile_model_multi]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "MULTI:CPU,GPU.0")
#! [compile_model_multi]
8 changes: 5 additions & 3 deletions docs/snippets/cpu/dynamic_shape.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from snippets import get_model

from openvino.runtime import Core
model = get_model()

#! [static_shape]
core = Core()
model = core.read_model("model.xml")
import openvino as ov

core = ov.Core()
model.reshape([10, 20, 30, 40])
#! [static_shape]
41 changes: 30 additions & 11 deletions docs/snippets/cpu/multi_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,47 @@
# SPDX-License-Identifier: Apache-2.0
#

import openvino.runtime as ov
from openvino.runtime import Core, Type, OVAny, properties
from openvino import Core, properties
from snippets import get_model

model = get_model()

device_name = "CPU"
core = Core()
core.set_property("CPU", properties.intel_cpu.sparse_weights_decompression_rate(0.8))

device_name = 'CPU'
xml_path = 'model.xml'
core = ov.Core()
core.set_property("CPU", ov.properties.intel_cpu.sparse_weights_decompression_rate(0.8))
model = core.read_model(model=xml_path)
# ! [ov:intel_cpu:multi_threading:part0]
# Use one logical processor for inference
compiled_model_1 = core.compile_model(model=model, device_name=device_name, config={properties.inference_num_threads(1)})
compiled_model_1 = core.compile_model(
model=model,
device_name=device_name,
config={properties.inference_num_threads(): 1},
)

# Use logical processors of Efficient-cores for inference on hybrid platform
compiled_model_2 = core.compile_model(model=model, device_name=device_name, config={properties.hint.scheduling_core_type(properties.hint.SchedulingCoreType.ECORE_ONLY)})
compiled_model_2 = core.compile_model(
model=model,
device_name=device_name,
config={
properties.hint.scheduling_core_type(): properties.hint.SchedulingCoreType.ECORE_ONLY,
},
)

# Use one logical processor per CPU core for inference when hyper threading is on
compiled_model_3 = core.compile_model(model=model, device_name=device_name, config={properties.hint.enable_hyper_threading(False)})
compiled_model_3 = core.compile_model(
model=model,
device_name=device_name,
config={properties.hint.enable_hyper_threading(): False},
)
# ! [ov:intel_cpu:multi_threading:part0]

# ! [ov:intel_cpu:multi_threading:part1]
# Disable CPU threads pinning for inference when system supoprt it
compiled_model_4 = core.compile_model(model=model, device_name=device_name, config={properties.hint.enable_cpu_pinning(False)})
compiled_model_4 = core.compile_model(
model=model,
device_name=device_name,
config={properties.hint.enable_cpu_pinning(): False},
)
# ! [ov:intel_cpu:multi_threading:part1]
assert compiled_model_1
assert compiled_model_2
Expand Down
16 changes: 11 additions & 5 deletions docs/snippets/cpu/ov_execution_mode.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino.runtime import Core

#! [ov:execution_mode:part0]
core = Core()
import openvino as ov

core = ov.Core()
# in case of Accuracy
core.set_property("CPU", {"EXECUTION_MODE_HINT": "ACCURACY"})
core.set_property(
"CPU",
{ov.properties.hint.execution_mode(): ov.properties.hint.ExecutionMode.ACCURACY},
)
# in case of Performance
core.set_property("CPU", {"EXECUTION_MODE_HINT": "PERFORMANCE"})
core.set_property(
"CPU",
{ov.properties.hint.execution_mode(): ov.properties.hint.ExecutionMode.PERFORMANCE},
)
#! [ov:execution_mode:part0]
10 changes: 6 additions & 4 deletions docs/snippets/cpu/ov_sparse_weights_decompression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# SPDX-License-Identifier: Apache-2.0
#

import openvino.runtime as ov
import openvino as ov
from snippets import get_model

device_name = 'CPU'
xml_path = 'model.xml'
model = get_model()

device_name = "CPU"
xml_path = "model.xml"
# ! [ov:intel_cpu:sparse_weights_decompression:part0]
core = ov.Core()
core.set_property("CPU", ov.properties.intel_cpu.sparse_weights_decompression_rate(0.8))
model = core.read_model(model=xml_path)
compiled_model = core.compile_model(model=model, device_name=device_name)
# ! [ov:intel_cpu:sparse_weights_decompression:part0]
assert compiled_model