-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[µTVM] Add support for mps2_an521 board #7813
Conversation
Some boards supported by Zephyr that run emulated by default, i.e. their .yaml config file sets the field "simulation: qemu", don't have the prefix "qemu_" on their names, so µTVM can't currently recognize it as an emulated target to properly use the QEMU transporter (instead of the serial port) to open a session against it. Such a boards usually have real physical (hardware) counterparts, being specific boards and not generic or "fake" ones simply tied to a CPU type of interest. That commit allows the µTVM user to explicitly inform that µTVM needs to use the QEMU transporter to open a session against a given board by adding the suffix "-qemu" to the board name. That is necessary because for boards that don't have the name prefixed by "qemu_" and even though run emulated by default on Zephyr there is no easy way to detect them, since it's not possible to determine it by looking at any Cmake generated file or by using the `west` command to query that info. The case where the board is emulated by default but has the prefix "qemu_" in its board name is already handled by the current code. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
This commit adds a new µTVM target to support the Arm reference board MPS2-AN521, which is based upon a Cortex-m33 core. For more details about that board, please see: http://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps2 Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
This commit adds an example on how to run the Zephyr demo under apps/ using as a target the Arm mps2_an521 board, which is emulated by default on Zephyr. The example is added to the tutorial script micro_tflite.py, where other examples for other targets exist. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
@gromero Thanks for this PR! |
@gromero there is a lint issue. You can run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gromero thanks for this pr, mostly looks good! you can also use docker/lint.sh
which will use the same docker container used in regression.
python/tvm/micro/contrib/zephyr.py
Outdated
@@ -108,7 +108,18 @@ def __init__( | |||
f"project_dir supplied to ZephyrCompiler does not exist: {project_dir}" | |||
) | |||
|
|||
if "qemu" in board: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you simplify: self._is_qemu = "qemu" in board
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@areusch I can but I'm actually trimming off based on that check too. If I simplify like you suggest it would be:
diff --git a/python/tvm/micro/contrib/zephyr.py b/python/tvm/micro/contrib/zephyr.py
index ed66ce111..e772fa610 100644
--- a/python/tvm/micro/contrib/zephyr.py
+++ b/python/tvm/micro/contrib/zephyr.py
@@ -108,15 +108,14 @@ class ZephyrCompiler(tvm.micro.Compiler):
f"project_dir supplied to ZephyrCompiler does not exist: {project_dir}"
)
- if "qemu" in board:
- self._qemu = True
+ self._qemu = "qemu" in board
- # For Zephyr boards that run emulated by default, i.e. "simulation: qemu" is set in
- # the board's .yaml config file, and which their names don't have the prefix "qemu_", a
- # suffix "-qemu" is used in microTVM to inform that the QEMU transporter has to be used.
- # So the suffix needs to be trimmed off before the board name is passed to Zephyr.
- if "-qemu" in board:
- board = board.replace("-qemu", "")
+ # For Zephyr boards that run emulated by default, i.e. "simulation: qemu" is set in
+ # the board's .yaml config file, and which their names don't have the prefix "qemu_", a
+ # suffix "-qemu" is used in microTVM to inform that the QEMU transporter has to be used.
+ # So the suffix needs to be trimmed off before the board name is passed to Zephyr.
+ if "-qemu" in board:
+ board = board.replace("-qemu", "")
self._board = board
i.e. to keep the same result I would have to check for "-qemu" anyway below in order to trim off the suffix from the board name. Am I following your suggestion correctly? If so, I still prefer checking for the need of trimming off only when "qemu" is in board name, so the first version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your diff looks right to me. I think this is one of those cases where there is not much CPU time to be saved, and in particular since this is Python, the self._is_qemu
lookup could cost more time than the substring check. in these cases, I just favor the easiest code to read/debug, rather than adding e.g. if self._is_qemu and "-qemu" in board
(you would the have to explain the self._is_qemu--is this intending to capture some other criteria, which may shift over time to be more than just "qemu" in board
?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over time I think that code will be updated to take care of FVP emulation too (about to be added to Zephyr, for Cortex M-55 + Ethos U-55, i.e. for MPS3 boards which are not supported by QEMU).
That said, I was actually not thinking of saving CPU cycles (I don't think there is a difference in performance between the two forms), nor about adding FVP support in the future, rather I just think that the first form is better to read/debug because it makes explicit that the trimming off applies only for a specific case where the suffix is present in the board name :) In the second form that dependency is "weak" and one maybe need to go back to the first if
to realize that the second if
will never be taken if the first is not taken. Anyway, since the result is the same, I'm sending a new version with the change suggested. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah okay. your logic makes sense, but I guess now we have a passing PR and I think they're pretty similar. let's merge this.
@maheshambule @areusch Thanks a lot for the hint on how to check lint locally. I was not aware of them : ) |
Hi @mehrdadh ! Yes, they are different. The |
Satisfy lint about boolean expression format. Please, discard this commit message when squashing it to commit: [µTVM] Zephyr: Allow user inform if a board is emulated in the series. Thanks, Gustavo
yeah so this is why you should prefer |
Address suggestion from Andrew in the review. Also updates the comment about suffix being trimmed off. Please discard that commit message when squashing into commit: [µTVM] Zephyr: Allow user inform if a board is emulated in the patch series. Thanks, Gustavo
thanks @gromero , the PR is now merged! |
* [µTVM] Zephyr: Allow user inform if a board is emulated Some boards supported by Zephyr that run emulated by default, i.e. their .yaml config file sets the field "simulation: qemu", don't have the prefix "qemu_" on their names, so µTVM can't currently recognize it as an emulated target to properly use the QEMU transporter (instead of the serial port) to open a session against it. Such a boards usually have real physical (hardware) counterparts, being specific boards and not generic or "fake" ones simply tied to a CPU type of interest. That commit allows the µTVM user to explicitly inform that µTVM needs to use the QEMU transporter to open a session against a given board by adding the suffix "-qemu" to the board name. That is necessary because for boards that don't have the name prefixed by "qemu_" and even though run emulated by default on Zephyr there is no easy way to detect them, since it's not possible to determine it by looking at any Cmake generated file or by using the `west` command to query that info. The case where the board is emulated by default but has the prefix "qemu_" in its board name is already handled by the current code. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add new target mps2_an521 This commit adds a new µTVM target to support the Arm reference board MPS2-AN521, which is based upon a Cortex-m33 core. For more details about that board, please see: http://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps2 Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add an example for the mps2_an521 board This commit adds an example on how to run the Zephyr demo under apps/ using as a target the Arm mps2_an521 board, which is emulated by default on Zephyr. The example is added to the tutorial script micro_tflite.py, where other examples for other targets exist. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * Fix lint Fix lint accordingly to the CI error. * Satisfy lint Satisfy lint about boolean expression format. * Address suggestion from Andrew Address suggestion from Andrew in the review. Also updates the comment about suffix being trimmed off. Thanks, Gustavo
* [µTVM] Zephyr: Allow user inform if a board is emulated Some boards supported by Zephyr that run emulated by default, i.e. their .yaml config file sets the field "simulation: qemu", don't have the prefix "qemu_" on their names, so µTVM can't currently recognize it as an emulated target to properly use the QEMU transporter (instead of the serial port) to open a session against it. Such a boards usually have real physical (hardware) counterparts, being specific boards and not generic or "fake" ones simply tied to a CPU type of interest. That commit allows the µTVM user to explicitly inform that µTVM needs to use the QEMU transporter to open a session against a given board by adding the suffix "-qemu" to the board name. That is necessary because for boards that don't have the name prefixed by "qemu_" and even though run emulated by default on Zephyr there is no easy way to detect them, since it's not possible to determine it by looking at any Cmake generated file or by using the `west` command to query that info. The case where the board is emulated by default but has the prefix "qemu_" in its board name is already handled by the current code. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add new target mps2_an521 This commit adds a new µTVM target to support the Arm reference board MPS2-AN521, which is based upon a Cortex-m33 core. For more details about that board, please see: http://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps2 Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add an example for the mps2_an521 board This commit adds an example on how to run the Zephyr demo under apps/ using as a target the Arm mps2_an521 board, which is emulated by default on Zephyr. The example is added to the tutorial script micro_tflite.py, where other examples for other targets exist. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * Fix lint Fix lint accordingly to the CI error. * Satisfy lint Satisfy lint about boolean expression format. * Address suggestion from Andrew Address suggestion from Andrew in the review. Also updates the comment about suffix being trimmed off. Thanks, Gustavo
* [µTVM] Zephyr: Allow user inform if a board is emulated Some boards supported by Zephyr that run emulated by default, i.e. their .yaml config file sets the field "simulation: qemu", don't have the prefix "qemu_" on their names, so µTVM can't currently recognize it as an emulated target to properly use the QEMU transporter (instead of the serial port) to open a session against it. Such a boards usually have real physical (hardware) counterparts, being specific boards and not generic or "fake" ones simply tied to a CPU type of interest. That commit allows the µTVM user to explicitly inform that µTVM needs to use the QEMU transporter to open a session against a given board by adding the suffix "-qemu" to the board name. That is necessary because for boards that don't have the name prefixed by "qemu_" and even though run emulated by default on Zephyr there is no easy way to detect them, since it's not possible to determine it by looking at any Cmake generated file or by using the `west` command to query that info. The case where the board is emulated by default but has the prefix "qemu_" in its board name is already handled by the current code. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add new target mps2_an521 This commit adds a new µTVM target to support the Arm reference board MPS2-AN521, which is based upon a Cortex-m33 core. For more details about that board, please see: http://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps2 Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add an example for the mps2_an521 board This commit adds an example on how to run the Zephyr demo under apps/ using as a target the Arm mps2_an521 board, which is emulated by default on Zephyr. The example is added to the tutorial script micro_tflite.py, where other examples for other targets exist. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * Fix lint Fix lint accordingly to the CI error. * Satisfy lint Satisfy lint about boolean expression format. * Address suggestion from Andrew Address suggestion from Andrew in the review. Also updates the comment about suffix being trimmed off. Thanks, Gustavo
* [µTVM] Zephyr: Allow user inform if a board is emulated Some boards supported by Zephyr that run emulated by default, i.e. their .yaml config file sets the field "simulation: qemu", don't have the prefix "qemu_" on their names, so µTVM can't currently recognize it as an emulated target to properly use the QEMU transporter (instead of the serial port) to open a session against it. Such a boards usually have real physical (hardware) counterparts, being specific boards and not generic or "fake" ones simply tied to a CPU type of interest. That commit allows the µTVM user to explicitly inform that µTVM needs to use the QEMU transporter to open a session against a given board by adding the suffix "-qemu" to the board name. That is necessary because for boards that don't have the name prefixed by "qemu_" and even though run emulated by default on Zephyr there is no easy way to detect them, since it's not possible to determine it by looking at any Cmake generated file or by using the `west` command to query that info. The case where the board is emulated by default but has the prefix "qemu_" in its board name is already handled by the current code. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add new target mps2_an521 This commit adds a new µTVM target to support the Arm reference board MPS2-AN521, which is based upon a Cortex-m33 core. For more details about that board, please see: http://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps2 Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * [µTVM] Add an example for the mps2_an521 board This commit adds an example on how to run the Zephyr demo under apps/ using as a target the Arm mps2_an521 board, which is emulated by default on Zephyr. The example is added to the tutorial script micro_tflite.py, where other examples for other targets exist. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * Fix lint Fix lint accordingly to the CI error. * Satisfy lint Satisfy lint about boolean expression format. * Address suggestion from Andrew Address suggestion from Andrew in the review. Also updates the comment about suffix being trimmed off. Thanks, Gustavo
Hi,
Could the following patchset be reviewed please?
It enables the Arm MPS2-AN521 board to be used on microTVM:
TARGET = tvm.target.target.micro("mps2_an521")
BOARD = "mps2_an521-qemu"
It also adds to
micro_tflite.py
an example on how to run Zephyr demo in apps/ using that new target.To use the MPS2-AN521 target it's necessary the newest Zephyr 2.5.0 branch [0] that contains the following fixes:
drivers: uart: uart_cmsdk_apb: fix interrupt handling
zephyrproject-rtos/zephyr@ec0aa83
drivers: uart: uart_cmsdk_apb: Fix uart_irq_is_pending
zephyrproject-rtos/zephyr@bd0fe17
boards: arm: mps2-an521: Fix DT memory regions
zephyrproject-rtos/zephyr@fe3f71b
It's also necessary to have
qemu-system-arm
available in the environment (reachable from $PATH).Thanks,
Gustavo
[0] https://github.com/zephyrproject-rtos/zephyr/commits/v2.5-branch