Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/apache/tvm into tec_vm
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepapadim committed Sep 10, 2021
2 parents 03a208c + b5c4aa3 commit 5b3fb11
Show file tree
Hide file tree
Showing 47 changed files with 2,781 additions and 536 deletions.
14 changes: 14 additions & 0 deletions apps/microtvm/arduino/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,40 @@ class BoardAutodetectFailed(Exception):
"package": "arduino",
"architecture": "sam",
"board": "arduino_due_x_dbg",
"model": "sam3x8e",
},
# Due to the way the Feather S2 bootloader works, compilation
# behaves fine but uploads cannot be done automatically
"feathers2": {
"package": "esp32",
"architecture": "esp32",
"board": "feathers2",
"model": "esp32",
},
"metrom4": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_metro_m4",
"model": "atsamd51",
},
# Spresense only works as of its v2.3.0 sdk
"spresense": {
"package": "SPRESENSE",
"architecture": "spresense",
"board": "spresense",
"model": "cxd5602gg",
},
"nano33ble": {
"package": "arduino",
"architecture": "mbed_nano",
"board": "nano33ble",
"model": "nrf52840",
},
"pybadge": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_pybadge_m4",
"model": "atsamd51",
},
# The Teensy boards are listed here for completeness, but they
# won't work until https://github.com/arduino/arduino-cli/issues/700
Expand All @@ -93,16 +99,19 @@ class BoardAutodetectFailed(Exception):
"package": "teensy",
"architecture": "avr",
"board": "teensy40",
"model": "imxrt1060",
},
"teensy41": {
"package": "teensy",
"architecture": "avr",
"board": "teensy41",
"model": "imxrt1060",
},
"wioterminal": {
"package": "Seeeduino",
"architecture": "samd",
"board": "seeed_wio_terminal",
"model": "atsamd51",
},
}

Expand All @@ -114,6 +123,11 @@ class BoardAutodetectFailed(Exception):
choices=list(BOARD_PROPERTIES),
help="Name of the Arduino board to build for",
),
server.ProjectOption(
"arduino_model",
choices=[board["model"] for _, board in BOARD_PROPERTIES.items()],
help="Name of the model for each Arduino board.",
),
server.ProjectOption("arduino_cli_cmd", help="Path to the arduino-cli tool."),
server.ProjectOption("port", help="Port to use for connecting to hardware"),
server.ProjectOption(
Expand Down
6 changes: 3 additions & 3 deletions apps/microtvm/reference-vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ $ ./base-box-tool.py --provider virtualbox build zephyr

B. Run tests:
```bash
$ ./base-box-tool.py [--provider=PROVIDER] test --microtvm-platform=MICROTVM_PLATFORM [--test-device-serial=SERIAL] PLATFORM
$ ./base-box-tool.py [--provider=PROVIDER] test --microtvm-board=MICROTVM_BOARD [--test-device-serial=SERIAL] PLATFORM
```
where MICROTVM_PLATFORM is one of the options listed in the
where MICROTVM_BOARD is one of the options listed in the
PLATFORM/base-box/test-config.json file.

For example:
```base
$ ./base-box-tool.py --provider virtualbox test --microtvm-platform=stm32f746xx_disco zephyr
$ ./base-box-tool.py --provider virtualbox test --microtvm-board=stm32f746xx_disco zephyr
```

This command does the following for the specified provider:
Expand Down
14 changes: 7 additions & 7 deletions apps/microtvm/reference-vm/arduino/base-box/base_box_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
# specific language governing permissions and limitations
# under the License.
#
# Usage: base_box_test.sh <MICROTVM_PLATFORM>
# Usage: base_box_test.sh <ARDUINO_BOARD>
# Execute microTVM Arduino tests.
#

set -e
set -x

if [ "$#" -lt 1 ]; then
echo "Usage: base_box_test.sh <MICROTVM_PLATFORM>"
echo "Usage: base_box_test.sh <ARDUINO_BOARD>"
exit -1
fi

microtvm_platform=$1
board=$1

pytest tests/micro/arduino/test_arduino_workflow.py --microtvm-platforms=${microtvm_platform}
pytest tests/micro/arduino/test_arduino_workflow.py --arduino-board=${board}

if [ $microtvm_platform == "nano33ble" ]; then
if [ $board == "nano33ble" ]; then
# https://github.com/apache/tvm/issues/8730
echo "NOTE: skipped test_arduino_rpc_server.py on $microtvm_platform -- known failure"
echo "NOTE: skipped test_arduino_rpc_server.py on $board -- known failure"
else
pytest tests/micro/arduino/test_arduino_rpc_server.py --microtvm-platforms=${microtvm_platform}
pytest tests/micro/arduino/test_arduino_rpc_server.py --arduino-board=${board}
fi
57 changes: 28 additions & 29 deletions apps/microtvm/reference-vm/base-box-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import subprocess
import sys


_LOG = logging.getLogger(__name__)


Expand All @@ -48,10 +47,19 @@
"zephyr",
)

# List of identifying strings for microTVM platforms for testing.
# Must match PLATFORMS as defined in tvm/tests/micro/[platform]/conftest.py
# TODO add a way to declare supported platforms to ProjectAPI
ALL_MICROTVM_PLATFORMS = {
# Extra scripts required to execute on provisioning
# in [platform]/base-box/base_box_provision.sh
EXTRA_SCRIPTS = {
"arduino": (),
"zephyr": ("docker/install/ubuntu_init_zephyr_project.sh",),
}

PACKER_FILE_NAME = "packer.json"


# List of identifying strings for microTVM boards for testing.
# TODO add a way to declare supported boards to ProjectAPI
ALL_MICROTVM_BOARDS = {
"arduino": (
"due",
"feathers2",
Expand All @@ -64,22 +72,13 @@
"wioterminal",
),
"zephyr": (
"stm32f746xx_nucleo",
"nucleo_f746zg",
"stm32f746xx_disco",
"nrf5340dk",
"nrf5340dk_nrf5340_cpuapp",
"mps2_an521",
),
}

# Extra scripts required to execute on provisioning
# in [platform]/base-box/base_box_provision.sh
EXTRA_SCRIPTS = {
"arduino": (),
"zephyr": ("docker/install/ubuntu_init_zephyr_project.sh",),
}

PACKER_FILE_NAME = "packer.json"


def parse_virtualbox_devices():
output = subprocess.check_output(["VBoxManage", "list", "usbhost"], encoding="utf-8")
Expand Down Expand Up @@ -362,7 +361,7 @@ def _quote_cmd(cmd):
+ _quote_cmd(
[
f"apps/microtvm/reference-vm/{platform}/base-box/base_box_test.sh",
test_config["microtvm_platform"],
test_config["microtvm_board"],
]
)
)
Expand All @@ -376,22 +375,22 @@ def test_command(args):
with open(test_config_file) as f:
test_config = json.load(f)

# select microTVM test platform
microtvm_test_platform = test_config[args.microtvm_platform]
# select microTVM test config
microtvm_test_config = test_config[args.microtvm_board]

for key, expected_type in REQUIRED_TEST_CONFIG_KEYS.items():
assert key in microtvm_test_platform and isinstance(
microtvm_test_platform[key], expected_type
assert key in microtvm_test_config and isinstance(
microtvm_test_config[key], expected_type
), f"Expected key {key} of type {expected_type} in {test_config_file}: {test_config!r}"

microtvm_test_platform["vid_hex"] = microtvm_test_platform["vid_hex"].lower()
microtvm_test_platform["pid_hex"] = microtvm_test_platform["pid_hex"].lower()
microtvm_test_platform["microtvm_platform"] = args.microtvm_platform
microtvm_test_config["vid_hex"] = microtvm_test_config["vid_hex"].lower()
microtvm_test_config["pid_hex"] = microtvm_test_config["pid_hex"].lower()
microtvm_test_config["microtvm_board"] = args.microtvm_board

providers = args.provider
provider_passed = {p: False for p in providers}

release_test_dir = os.path.join(THIS_DIR, "release-test")
release_test_dir = os.path.join(THIS_DIR, f"release-test-{args.platform}")

if args.skip_build:
assert len(providers) == 1, "--skip-build was given, but >1 provider specified"
Expand All @@ -406,7 +405,7 @@ def test_command(args):
release_test_dir,
args.platform,
provider_name,
microtvm_test_platform,
microtvm_test_config,
args.test_device_serial,
)
provider_passed[provider_name] = True
Expand Down Expand Up @@ -511,10 +510,10 @@ def parse_args():
platform_specific_parser = parser_test_platform_subparsers.add_parser(platform)
platform_specific_parser.set_defaults(platform=platform)
platform_specific_parser.add_argument(
"--microtvm-platform",
choices=ALL_MICROTVM_PLATFORMS[platform],
"--microtvm-board",
choices=ALL_MICROTVM_BOARDS[platform],
required=True,
help="MicroTVM platfrom used for testing.",
help="MicroTVM board used for testing.",
)

# Options for release subcommand
Expand Down
14 changes: 7 additions & 7 deletions apps/microtvm/reference-vm/zephyr/base-box/base_box_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
# specific language governing permissions and limitations
# under the License.
#
# Usage: base_box_test.sh <MICROTVM_PLATFORM>
# Usage: base_box_test.sh <ZEPHYR_BOARD>
# Execute microTVM Zephyr tests.
#

set -e
set -x

if [ "$#" -lt 1 ]; then
echo "Usage: base_box_test.sh <MICROTVM_PLATFORM>"
echo "Usage: base_box_test.sh <ZEPHYR_BOARD>"
exit -1
fi

microtvm_platform=$1
board=$1

pytest tests/micro/zephyr/test_zephyr.py --microtvm-platforms=${microtvm_platform}
pytest tests/micro/zephyr/test_zephyr.py --zephyr-board=${board}

if [ $microtvm_platform == "stm32f746xx" ]; then
echo "NOTE: skipped test_zephyr_aot.py on $microtvm_platform -- known failure"
if [ $board == "stm32f746xx" ]; then
echo "NOTE: skipped test_zephyr_aot.py on $board -- known failure"
else
pytest tests/micro/zephyr/test_zephyr_aot.py --microtvm-platforms=${microtvm_platform}
pytest tests/micro/zephyr/test_zephyr_aot.py --zephyr-board=${board}
fi
55 changes: 54 additions & 1 deletion apps/microtvm/zephyr/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,47 @@

IS_TEMPLATE = not (API_SERVER_DIR / MODEL_LIBRARY_FORMAT_RELPATH).exists()

# Data structure to hold the information microtvm_api_server.py needs
# to communicate with each of these boards.
BOARD_PROPERTIES = {
"qemu_x86": {
"board": "qemu_x86",
"model": "host",
},
"qemu_riscv32": {
"board": "qemu_riscv32",
"model": "host",
},
"qemu_riscv64": {
"board": "qemu_riscv64",
"model": "host",
},
"mps2_an521": {
"board": "mps2_an521",
"model": "mps2_an521",
},
"nrf5340dk_nrf5340_cpuapp": {
"board": "nrf5340dk_nrf5340_cpuapp",
"model": "nrf5340dk",
},
"stm32f746xx_disco": {
"board": "stm32f746xx_disco",
"model": "stm32f746xx",
},
"nucleo_f746zg": {
"board": "nucleo_f746zg",
"model": "stm32f746xx",
},
"nucleo_l4r5zi": {
"board": "nucleo_l4r5zi",
"model": "stm32l4r5zi",
},
"qemu_cortex_r5": {
"board": "qemu_cortex_r5",
"model": "zynq_mp_r5",
},
}


def check_call(cmd_args, *args, **kwargs):
cwd_str = "" if "cwd" not in kwargs else f" (in cwd: {kwargs['cwd']})"
Expand Down Expand Up @@ -243,7 +284,16 @@ def _get_nrf_device_args(options):
),
),
server.ProjectOption("zephyr_base", help="Path to the zephyr base directory."),
server.ProjectOption("zephyr_board", help="Name of the Zephyr board to build for."),
server.ProjectOption(
"zephyr_board",
choices=list(BOARD_PROPERTIES),
help="Name of the Zephyr board to build for.",
),
server.ProjectOption(
"zephyr_model",
choices=[board["model"] for _, board in BOARD_PROPERTIES.items()],
help="Name of the model for each Zephyr board.",
),
]


Expand Down Expand Up @@ -397,6 +447,9 @@ def build(self, options):
if options.get("zephyr_base"):
cmake_args.append(f"-DZEPHYR_BASE:STRING={options['zephyr_base']}")

if options.get("west_cmd"):
cmake_args.append(f"-DWEST={options['west_cmd']}")

cmake_args.append(f"-DBOARD:STRING={options['zephyr_board']}")

check_call(cmake_args, cwd=BUILD_DIR)
Expand Down
11 changes: 9 additions & 2 deletions include/tvm/arith/int_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,24 @@ class IntSet : public ObjectRef {
* \return The result set containing the indices in the vector.
*/
static IntSet Vector(PrimExpr vec);
/*!
* \brief Construct a set representing a range [min, min + extent).
* \param min The minimum of the range range
* \param extent The extent of the range.
* \return The constructed set.
*/
static IntSet FromMinExtent(PrimExpr min, PrimExpr extent);
/*!
* \brief Construct a set representing a range.
* \param r The range
* \return constructed set.
* \return The constructed set.
*/
static IntSet FromRange(tvm::Range r);
/*!
* \brief Construct a set representing a interval.
* \param min The minimum value of the interval.
* \param max The maximum value of the interval.
* \return constructed set.
* \return The constructed set.
*/
static IntSet Interval(PrimExpr min, PrimExpr max);

Expand Down
Loading

0 comments on commit 5b3fb11

Please sign in to comment.