|
256 | 256 | }
|
257 | 257 | ],
|
258 | 258 | "source": [
|
| 259 | + "import openvino.properties as props\n", |
| 260 | + "\n", |
| 261 | + "\n", |
259 | 262 | "device = \"GPU\"\n",
|
260 | 263 | "\n",
|
261 |
| - "core.get_property(device, \"FULL_DEVICE_NAME\")" |
| 264 | + "core.get_property(device, props.device.full_name)" |
262 | 265 | ]
|
263 | 266 | },
|
264 | 267 | {
|
|
267 | 270 | "id": "aac3129a-129f-49aa-aba0-71ae1e892ada",
|
268 | 271 | "metadata": {},
|
269 | 272 | "source": [
|
270 |
| - "Each device also has a specific property called `SUPPORTED_PROPERTIES`, that enables viewing all the available properties in the device. We can check the value for each property by simply looping through the dictionary returned by `core.get_property(\"GPU\", \"SUPPORTED_PROPERTIES\")` and then querying for that property." |
| 273 | + "Each device also has a specific property called `SUPPORTED_PROPERTIES`, that enables viewing all the available properties in the device. We can check the value for each property by simply looping through the dictionary returned by `core.get_property(\"GPU\", props.supported_properties)` and then querying for that property." |
271 | 274 | ]
|
272 | 275 | },
|
273 | 276 | {
|
|
321 | 324 | ],
|
322 | 325 | "source": [
|
323 | 326 | "print(f\"{device} SUPPORTED_PROPERTIES:\\n\")\n",
|
324 |
| - "supported_properties = core.get_property(device, \"SUPPORTED_PROPERTIES\")\n", |
| 327 | + "supported_properties = core.get_property(device, props.supported_properties)\n", |
325 | 328 | "indent = len(max(supported_properties, key=len))\n",
|
326 | 329 | "\n",
|
327 | 330 | "for property_key in supported_properties:\n",
|
|
677 | 680 | "core = ov.Core()\n",
|
678 | 681 | "\n",
|
679 | 682 | "# Set cache folder\n",
|
680 |
| - "core.set_property({\"CACHE_DIR\": cache_folder})\n", |
| 683 | + "core.set_property({props.cache_dir(): cache_folder})\n", |
681 | 684 | "\n",
|
682 | 685 | "# Compile the model as before\n",
|
683 | 686 | "model = core.read_model(model=model_path)\n",
|
|
717 | 720 | "source": [
|
718 | 721 | "start = time.time()\n",
|
719 | 722 | "core = ov.Core()\n",
|
720 |
| - "core.set_property({\"CACHE_DIR\": \"cache\"})\n", |
| 723 | + "core.set_property({props.cache_dir(): \"cache\"})\n", |
721 | 724 | "model = core.read_model(model=model_path)\n",
|
722 | 725 | "compiled_model = core.compile_model(model, device)\n",
|
723 | 726 | "print(f\"Cache enabled - compile time: {time.time() - start}s\")\n",
|
|
765 | 768 | "id": "7077b662-22f3-4c52-9c80-e5ac1309c482",
|
766 | 769 | "metadata": {},
|
767 | 770 | "source": [
|
768 |
| - "To use the \"LATENCY\" performance hint, add `{\"PERFORMANCE_HINT\": \"LATENCY\"}` when compiling the model as shown below. For GPUs, this automatically minimizes the batch size and number of parallel streams such that all of the compute resources can focus on completing a single inference as fast as possible." |
| 771 | + "To use the \"LATENCY\" performance hint, add `{hints.performance_mode(): hints.PerformanceMode.LATENCY}` when compiling the model as shown below. For GPUs, this automatically minimizes the batch size and number of parallel streams such that all of the compute resources can focus on completing a single inference as fast as possible." |
769 | 772 | ]
|
770 | 773 | },
|
771 | 774 | {
|
|
780 | 783 | },
|
781 | 784 | "outputs": [],
|
782 | 785 | "source": [
|
783 |
| - "compiled_model = core.compile_model(model, device, {\"PERFORMANCE_HINT\": \"LATENCY\"})" |
| 786 | + "import openvino.properties.hint as hints\n", |
| 787 | + "\n", |
| 788 | + "\n", |
| 789 | + "compiled_model = core.compile_model(model, device, {hints.performance_mode(): hints.PerformanceMode.LATENCY})" |
784 | 790 | ]
|
785 | 791 | },
|
786 | 792 | {
|
|
789 | 795 | "id": "06589f38-ce35-457f-8395-a4a3f6327ea0",
|
790 | 796 | "metadata": {},
|
791 | 797 | "source": [
|
792 |
| - "To use the \"THROUGHPUT\" performance hint, add `{\"PERFORMANCE_HINT\": \"THROUGHPUT\"}` when compiling the model. For GPUs, this creates multiple processing streams to efficiently utilize all the execution cores and optimizes the batch size to fill the available memory." |
| 798 | + "To use the \"THROUGHPUT\" performance hint, add `{hints.performance_mode(): hints.PerformanceMode.THROUGHPUT}` when compiling the model. For GPUs, this creates multiple processing streams to efficiently utilize all the execution cores and optimizes the batch size to fill the available memory." |
793 | 799 | ]
|
794 | 800 | },
|
795 | 801 | {
|
|
804 | 810 | },
|
805 | 811 | "outputs": [],
|
806 | 812 | "source": [
|
807 |
| - "compiled_model = core.compile_model(model, device, {\"PERFORMANCE_HINT\": \"THROUGHPUT\"})" |
| 813 | + "compiled_model = core.compile_model(model, device, {hints.performance_mode(): hints.PerformanceMode.THROUGHPUT})" |
808 | 814 | ]
|
809 | 815 | },
|
810 | 816 | {
|
|
836 | 842 | "Note that we always need to explicitly specify the device list for MULTI to work, otherwise MULTI does not know which devices are available for inference. However, this is not the only way to use multiple devices in OpenVINO. There is another performance hint called \"CUMULATIVE_THROUGHPUT\" that works similar to MULTI, except it uses the devices automatically selected by AUTO. This way, we do not need to manually specify devices to use. Below is an example showing how to use \"CUMULATIVE_THROUGHPUT\", equivalent to the MULTI one:\n",
|
837 | 843 | "\n",
|
838 | 844 | "`\n",
|
839 |
| - "compiled_model = core.compile_model(model=model, device_name=\"AUTO\", config={\"PERFORMANCE_HINT\": \"CUMULATIVE_THROUGHPUT\"})\n", |
| 845 | + "\n", |
| 846 | + "\n", |
| 847 | + "compiled_model = core.compile_model(model=model, device_name=\"AUTO\", config={hints.performance_mode(): hints.PerformanceMode.CUMULATIVE_THROUGHPUT})\n", |
840 | 848 | "`\n",
|
841 | 849 | "\n",
|
842 | 850 | "> **Important**: **The “THROUGHPUT”, “MULTI”, and “CUMULATIVE_THROUGHPUT” modes are only applicable to asynchronous inferencing pipelines. The example at the end of this article shows how to set up an asynchronous pipeline that takes advantage of parallelism to increase throughput.** To learn more, see [Asynchronous Inferencing](https://docs.openvino.ai/2024/documentation/openvino-extensibility/openvino-plugin-library/asynch-inference-request.html) in OpenVINO as well as the [Asynchronous Inference notebook](../async-api/async-api.ipynb)."
|
|
1584 | 1592 | "# Read model and compile it on GPU in THROUGHPUT mode\n",
|
1585 | 1593 | "model = core.read_model(model=model_path)\n",
|
1586 | 1594 | "device_name = \"GPU\"\n",
|
1587 |
| - "compiled_model = core.compile_model(model=model, device_name=device_name, config={\"PERFORMANCE_HINT\": \"THROUGHPUT\"})\n", |
| 1595 | + "compiled_model = core.compile_model(model=model, device_name=device_name, config={hints.performance_mode(): hints.PerformanceMode.THROUGHPUT})\n", |
1588 | 1596 | "\n",
|
1589 | 1597 | "# Get the input and output nodes\n",
|
1590 | 1598 | "input_layer = compiled_model.input(0)\n",
|
|
1996 | 2004 | " )\n",
|
1997 | 2005 | " cv2.putText(\n",
|
1998 | 2006 | " frame,\n",
|
1999 |
| - " f\"hint {compiled_model.get_property('PERFORMANCE_HINT')}\",\n", |
| 2007 | + " f\"hint {compiled_model.get_property(hints.performance_mode)}\",\n", |
2000 | 2008 | " (5, 60),\n",
|
2001 | 2009 | " cv2.FONT_ITALIC,\n",
|
2002 | 2010 | " 0.6,\n",
|
|
0 commit comments