From d711e54b8280f871049ee401e820ed5492d04dce Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Fri, 15 Sep 2023 13:15:10 +0000 Subject: [PATCH 01/10] fix AttributeError in __del__ on Ctrl+C for tests --- integration_tests/runner.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/integration_tests/runner.py b/integration_tests/runner.py index 966e182d4..ddeb512c6 100644 --- a/integration_tests/runner.py +++ b/integration_tests/runner.py @@ -72,9 +72,16 @@ def __init__(self, model): self._interpreter.set_model(model_content=model, secondary_memory=False) self._dets = self._interpreter.get_output_details() + # Try/except in case we cancel operation before interpreter/dir initialised def __del__(self): - self._interpreter.close() - self._temp_dir.cleanup() + try: + self._interpreter.close() + except AttributeError: + pass + try: + self._temp_dir.cleanup() + except AttributeError: + pass class BnnInterpreter(AbstractRefRunner): From a6ee2cbac0979df1fe192fa30cdc75c2b093ab4d Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 10:15:24 +0000 Subject: [PATCH 02/10] add build option for host compilation --- build.sh | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 06414322b..16544fa4f 100755 --- a/build.sh +++ b/build.sh @@ -118,13 +118,17 @@ create_zip() { cd third_party/lib_tflite_micro mkdir -p build cd build - cmake .. --toolchain=../lib_tflite_micro/submodules/xmos_cmake_toolchain/xs3a.cmake + if [ "$1" = "xcore" ]; then + cmake .. --toolchain=../lib_tflite_micro/submodules/xmos_cmake_toolchain/xs3a.cmake + else + cmake .. -DLIB_NAME=x86tflitemicro + fi make create_zip -j$NUM_PROCS cd $SCRIPT_DIR mv third_party/lib_tflite_micro/build/release_archive.zip python/xmos_ai_tools/runtime/release_archive.zip cd python/xmos_ai_tools/runtime - rm -rf lib include - unzip release_archive.zip + rm -rf include + unzip -o release_archive.zip rm release_archive.zip cd $SCRIPT_DIR } @@ -147,6 +151,10 @@ clean_xinterpreter() { make -C python/xmos_ai_tools/xinterpreters/host clean } +clean_runtime() { + rm -rf third_party/lib_tflite_micro/build +} + test_xinterpreter() { echo "Not implemented yet" exit 1 @@ -174,11 +182,12 @@ case $TARGET in case $ACTION in --build) version_check - create_zip + create_zip "xcore" build_xinterpreter ;; --clean) clean_xinterpreter + clean_runtime ;; --test) test_xinterpreter @@ -200,12 +209,27 @@ case $TARGET in ;; esac ;; + # also a mess: a shell script was a bad idea... + runtime-host) + case $ACTION in + --build) + version_check + create_zip "xcore" + clean_runtime + create_zip "x86" + clean_runtime + ;; + *) + unsupported_action + ;; + esac + ;; all) case $ACTION in --build) version_check build_xformer - create_zip + create_zip "xcore" build_xinterpreter ;; --clean) From c1cd2ec01187875888aca9dce6227cb5482478b9 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 10:17:10 +0000 Subject: [PATCH 03/10] update CMakeLists.txt --- third_party/lib_tflite_micro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/lib_tflite_micro b/third_party/lib_tflite_micro index d4d002e6d..37310d212 160000 --- a/third_party/lib_tflite_micro +++ b/third_party/lib_tflite_micro @@ -1 +1 @@ -Subproject commit d4d002e6d6047bfc1a18e1ec0de2c157b354d50e +Subproject commit 37310d21265d43fe6d838f8c5bae70e6caedd9a5 From 242a2265c03dbae3bf75906c21fa060eea65fdc6 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 10:19:02 +0000 Subject: [PATCH 04/10] update runner.py --- integration_tests/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/runner.py b/integration_tests/runner.py index ddeb512c6..b83c4bdc0 100644 --- a/integration_tests/runner.py +++ b/integration_tests/runner.py @@ -152,7 +152,7 @@ def __init__(self, model_content): f"{MAIN_CPP_PATH}", "-o", f"{self._model_exe_path}", - "-lxtflitemicro", + "-lx86tflitemicro", ] print(" ".join(cmd)) run_cmd(cmd) From fe6bac5afdc6cf43cff8cf80f1b363ba8e764436 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 11:39:03 +0000 Subject: [PATCH 05/10] clean up Jenkinsfile --- Jenkinsfile | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bf29cf2b2..73b53fd95 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,10 +37,8 @@ pipeline { stage("Setup") { steps { println "Stage running on: ${env.NODE_NAME}" - // clone checkout scm - sh 'git submodule update --init --recursive --jobs \$(nproc)' - // create venv and install pip packages + sh "./build.sh -T init" createVenv("requirements.txt") withVenv { sh "pip install -r requirements.txt" @@ -50,10 +48,6 @@ pipeline { stage("Build") { steps { withVenv { - // apply tflite-micro patch - dir("third_party/lib_tflite_micro") { - sh "make patch" - } // build dll_interpreter for python interface sh "./build.sh -T xinterpreter-nozip -b" // build xformer @@ -84,12 +78,12 @@ pipeline { steps { withVenv { dir("xformer") { - // xformer2 unit tests sh "./bazelisk-linux-amd64 --output_user_root=${env.BAZEL_USER_ROOT} test --remote_cache=${env.BAZEL_CACHE_URL} //Test:all --verbose_failures --test_output=errors --//:disable_version_check" } - // xformer2 integration tests sh "pytest integration_tests/runner.py --models_path integration_tests/models/non-bnns -n 8 --junitxml=integration_tests/integration_non_bnns_junit.xml" sh "pytest integration_tests/runner.py --models_path integration_tests/models/bnns --bnn -n 8 --junitxml=integration_tests/integration_bnns_junit.xml" + // sh "pytest integration_tests/runner.py --models_path integration_tests/models/non-bnns --compiled -n 8 --junitxml=integration_compiled_non_bnns_junit.xml" + // sh "pytest integration_tests/runner.py --models_path integration_tests/models/bnns --bnn --compiled -n 8 --junitxml=integration_compiled_bnns_junit.xml" // Any call to pytest can be given the "--junitxml SOMETHING_junit.xml" option // This step collects these files for display in Jenkins UI junit "**/*_junit.xml" From c145956c6bfcc9344bf30ef256c606c0ecbf9a1d Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 11:48:42 +0000 Subject: [PATCH 06/10] enable host building & compile testing --- Jenkinsfile | 4 ++-- build.sh | 18 +++--------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 73b53fd95..f4793e824 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,8 +82,8 @@ pipeline { } sh "pytest integration_tests/runner.py --models_path integration_tests/models/non-bnns -n 8 --junitxml=integration_tests/integration_non_bnns_junit.xml" sh "pytest integration_tests/runner.py --models_path integration_tests/models/bnns --bnn -n 8 --junitxml=integration_tests/integration_bnns_junit.xml" - // sh "pytest integration_tests/runner.py --models_path integration_tests/models/non-bnns --compiled -n 8 --junitxml=integration_compiled_non_bnns_junit.xml" - // sh "pytest integration_tests/runner.py --models_path integration_tests/models/bnns --bnn --compiled -n 8 --junitxml=integration_compiled_bnns_junit.xml" + sh "pytest integration_tests/runner.py --models_path integration_tests/models/non-bnns --compiled -n 8 --junitxml=integration_compiled_non_bnns_junit.xml" + sh "pytest integration_tests/runner.py --models_path integration_tests/models/bnns --bnn --compiled -n 8 --junitxml=integration_compiled_bnns_junit.xml" // Any call to pytest can be given the "--junitxml SOMETHING_junit.xml" option // This step collects these files for display in Jenkins UI junit "**/*_junit.xml" diff --git a/build.sh b/build.sh index 16544fa4f..4f7334c8d 100755 --- a/build.sh +++ b/build.sh @@ -183,6 +183,9 @@ case $TARGET in --build) version_check create_zip "xcore" + clean_runtime + create_zip "x86" + clean_runtime build_xinterpreter ;; --clean) @@ -209,21 +212,6 @@ case $TARGET in ;; esac ;; - # also a mess: a shell script was a bad idea... - runtime-host) - case $ACTION in - --build) - version_check - create_zip "xcore" - clean_runtime - create_zip "x86" - clean_runtime - ;; - *) - unsupported_action - ;; - esac - ;; all) case $ACTION in --build) From c6d52e05364c444a51052fe7d029162c8962bc35 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 12:08:07 +0000 Subject: [PATCH 07/10] import runtime instead of using env variable --- integration_tests/runner.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/integration_tests/runner.py b/integration_tests/runner.py index b83c4bdc0..cdc73c914 100644 --- a/integration_tests/runner.py +++ b/integration_tests/runner.py @@ -12,6 +12,7 @@ import tensorflow as tf from xmos_ai_tools.xinterpreters import xcore_tflm_host_interpreter from xmos_ai_tools import xformer +import xmos_ai_tools.runtime as rt import yaml from abc import ABC, abstractmethod, abstractproperty @@ -131,10 +132,7 @@ def input_details(self): class XFHostRuntime(AbstractXFRunner): def __init__(self, model_content): - path_var = os.getenv("XMOS_AITOOLSLIB_PATH") - if path_var is None: - LOGGER.error("XMOS_AITOOLSLIB_PATH not set properly.") - sys.exit(1) + path_var = os.path.dirname(rt.__file__) super().__init__(model_content) self._model_exe_path = self._dir_path / "a.out" cmd = [ From 14b7247b672f1a4bce0abbeed696ad7e1c7d0580 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 12:43:52 +0000 Subject: [PATCH 08/10] debug ls --- integration_tests/runner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/runner.py b/integration_tests/runner.py index cdc73c914..bb9f3a2c5 100644 --- a/integration_tests/runner.py +++ b/integration_tests/runner.py @@ -134,6 +134,7 @@ class XFHostRuntime(AbstractXFRunner): def __init__(self, model_content): path_var = os.path.dirname(rt.__file__) super().__init__(model_content) + print(os.listdir(f"{path_var}/include")) self._model_exe_path = self._dir_path / "a.out" cmd = [ CPP_COMPILER, From bd6e1a8df50222dc71da050b0a6136187d18b9a4 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 12:57:04 +0000 Subject: [PATCH 09/10] fix? --- build.sh | 2 +- integration_tests/runner.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 4f7334c8d..b3fcc2187 100755 --- a/build.sh +++ b/build.sh @@ -182,10 +182,10 @@ case $TARGET in case $ACTION in --build) version_check + clean_runtime create_zip "xcore" clean_runtime create_zip "x86" - clean_runtime build_xinterpreter ;; --clean) diff --git a/integration_tests/runner.py b/integration_tests/runner.py index bb9f3a2c5..cdc73c914 100644 --- a/integration_tests/runner.py +++ b/integration_tests/runner.py @@ -134,7 +134,6 @@ class XFHostRuntime(AbstractXFRunner): def __init__(self, model_content): path_var = os.path.dirname(rt.__file__) super().__init__(model_content) - print(os.listdir(f"{path_var}/include")) self._model_exe_path = self._dir_path / "a.out" cmd = [ CPP_COMPILER, From f6d37672a25b777157a7f2f70d0aa913f97c3a97 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Mon, 18 Sep 2023 15:46:05 +0000 Subject: [PATCH 10/10] changes --- Jenkinsfile | 1 + build.sh | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f4793e824..4675d68af 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -49,6 +49,7 @@ pipeline { steps { withVenv { // build dll_interpreter for python interface + sh "./build.sh -T runtime-host -b" sh "./build.sh -T xinterpreter-nozip -b" // build xformer dir("xformer") { diff --git a/build.sh b/build.sh index b3fcc2187..c212b7230 100755 --- a/build.sh +++ b/build.sh @@ -169,46 +169,55 @@ case $TARGET in patch ;; xformer) + build_xformer + ;; + xinterpreter) case $ACTION in --build) - build_xformer + version_check + create_zip "xcore" + build_xinterpreter + ;; + --clean) + clean_xinterpreter + clean_runtime + ;; + --test) + test_xinterpreter ;; *) unsupported_action ;; esac ;; - xinterpreter) + # this is a mess: xinterpreter-nozip only used for CI + runtime-host) case $ACTION in --build) version_check clean_runtime - create_zip "xcore" - clean_runtime create_zip "x86" - build_xinterpreter + clean_runtime ;; --clean) - clean_xinterpreter clean_runtime ;; - --test) - test_xinterpreter - ;; *) unsupported_action ;; esac ;; - # this is a mess: xinterpreter-nozip only used for CI xinterpreter-nozip) case $ACTION in --build) version_check build_xinterpreter ;; - *) - unsupported_action + --clean) + clean_xinterpreter + ;; + --test) + test_xinterpreter ;; esac ;;