4 "cell_type": "markdown",
7 "# Python power measurement tutorial\n",
9 "This tutorial will show how to perform a power measurement on the chip.\n",
11 "The Hailo chip supports power measurement which is done via the control protocol.\n",
13 "**Requirements:**\n",
15 "* Run the notebook inside the Python virtual environment: ```source hailo_virtualenv/bin/activate```\n",
19 "* These examples should run in a different process than the one that performs the actual inference.\n",
21 "It is recommended to use the command ``hailo tutorial`` (when inside the virtualenv) to open a Jupyter server that contains the tutorials."
26 "## Single power measurement"
28 "cell_type": "markdown",
33 "execution_count": null,
37 "%matplotlib inline\n",
40 "from hailo_platform import PcieDevice, DvmTypes, PowerMeasurementTypes, SamplingPeriod, AveragingFactor, MeasurementBufferIndex # noqa F401\n"
44 "cell_type": "markdown",
47 "Initialize the hardware object:"
52 "execution_count": null,
56 "target = PcieDevice()"
60 "cell_type": "markdown",
63 "When using the ``power_measurement()`` function with no parameters, the function tries to detect which board is connected (evaluation board, M.2 or mPCIe) and determine the DVM accordingly (at the moment only the mentioned boards are supported). \n",
65 "The parameter ``dvm`` (of type ``DvmTypes``) defines which DVM will be measured. The user can choose a specific DVM or choose the default DVM. The meaning of the default DVM changes according to the board or module in use. \n",
67 "The default for the evaluation board is the sum of three DVMs: ``DvmTypes.VDD_CORE``, ``DvmTypes.MIPI_AVDD`` and ``DvmTypes.AVDD_H``. The sum of these three DVMs approximates of the total power consumption of the chip in PCIe setups. Only power can be measured using this default option, as voltage and current can't be summed up this way. \n",
69 "The default for platforms supporting current monitoring, such as M.2 and mPCIe modules, is ``DvmTypes.OVERCURRENT_PROTECTION``, which measures the power consumption of the whole module. \n",
71 "See the API documentation for further details about the supported DVMs and measurement types.\n"
76 "execution_count": null,
80 "single_power_measurement = target.control.power_measurement()\n",
81 "print('Power from single measurement: {} W'.format(single_power_measurement))"
85 "cell_type": "markdown",
88 "## Periodic power measurement\n",
90 "In the following example, a periodic power measurement is taken.\n",
92 "A measurement index is selected. It is a member of the enum class MeasurementBufferIndex (between 0 and 3). The DVM is not given so the default DVM will be used, as explained above.\n"
97 "execution_count": null,
101 "buffer_index = MeasurementBufferIndex.MEASUREMENT_BUFFER_INDEX_0\n",
102 "target.control.set_power_measurement(buffer_index=buffer_index)"
106 "cell_type": "markdown",
109 "The following call to ``start_power_measurement()`` allows to configure the power sampling frequency. In this case we keep the default configuration. The API documentation provides more details. \n"
114 "execution_count": null,
118 "target.control.start_power_measurement()"
122 "cell_type": "markdown",
125 "Clear old samples and statistics (min, max, average) each time the measurement is taken from the chip."
130 "execution_count": null,
134 "should_clear = True"
138 "cell_type": "markdown",
141 "The power measurement is read every second, for 10 seconds.\n",
143 "The firmware calculates the min, max, and average of all the values from the sensor. Note that the average calculated by the firmware is the \"average of averages\". This is the average of all values that have already been averaged by the sensor. The host then requests these values from the firmware every second by calling the ``get_power_measurement()`` function. The host can also read the average time interval between new sensor values."
148 "execution_count": null,
154 "for _ in range(10):\n",
156 " # Get saved power measurement values from the firmware.\n",
157 " measurements = target.control.get_power_measurement(buffer_index=buffer_index, should_clear=should_clear)\n",
158 " print('Average power is {} W. Min power is {} W. Max power is {} W.\\nAverage time between power samples is {} mS\\n'.format(measurements.average_value, measurements.min_value, measurements.max_value, measurements.average_time_value_milliseconds))\n",
160 "# Stop performing periodic power measurement\n",
161 "target.control.stop_power_measurement()"
167 "display_name": "Python 3",
168 "language": "python",
176 "file_extension": ".py",
177 "mimetype": "text/x-python",
179 "nbconvert_exporter": "python",
180 "pygments_lexer": "ipython3",