[python] Flesh out more of the python parameters API. (#16957)
The existing Python parameters API was sufficient to construct parameter
indexes/archives but did not fully support introspecting them from
Python.
New APIs:
* `FileHandle`:
* Implements buffer protocol for accessing host allocations.
* `is_host_allocation -> bool` property
* `host_allocation -> memoryview`
* `__repr__`
* `ParameterIndexEntry`:
* Class added.
* Properties: `key`, `length`, `metadata`, `is_file`, `is_splat`,
`file_storage`, `file_view`, `splat_pattern`, `__repr__`
* `ParameterIndex`:
* `__getitem__` for index based iteration
* `items()` for `dict`-like access to a list of key/value tuples
* `__repr__`
Includes a version upgrade of nanobind to 1.9.2 as some new features
were needed (just bumped to current vs finding the exact version). This
requires a patch to the Linux CI to make it set up a venv and install
versions of build requirements like all of the others do (vs leaving
this to whatever was packaged in the base docker).
diff --git a/build_tools/cmake/build_and_test_byo_llvm.sh b/build_tools/cmake/build_and_test_byo_llvm.sh
index 2b96c16..043bc98 100755
--- a/build_tools/cmake/build_and_test_byo_llvm.sh
+++ b/build_tools/cmake/build_and_test_byo_llvm.sh
@@ -16,6 +16,15 @@
export IREE_BYOLLVM_BUILD_DIR="${1:-build-byo-llvm}"
export IREE_BYOLLVM_INSTALL_DIR="${IREE_BYOLLVM_BUILD_DIR}/install"
+python3 --version
+
+# We've been instructed to set up a venv.
+VENV_DIR="$IREE_BYOLLVM_BUILD_DIR/.venv"
+echo "Setting up venv at $VENV_DIR"
+python3 -m venv "$VENV_DIR"
+source "$VENV_DIR/bin/activate"
+python -m pip install -r runtime/bindings/python/iree/runtime/build_requirements.txt
+
# Note: by using the `build_llvm` action here, we are exercising byo_llvm.sh's
# ability to build LLVM... from our own third_party/llvm-project. That's not
# the most intuitive interpretation of "bring your own LLVM", since as far as
diff --git a/build_tools/cmake/setup_build.sh b/build_tools/cmake/setup_build.sh
index 02a03bf..e8b5986 100644
--- a/build_tools/cmake/setup_build.sh
+++ b/build_tools/cmake/setup_build.sh
@@ -16,7 +16,19 @@
ninja --version
python3 --version
-IREE_PYTHON3_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE:-$(which python3)}"
+if [[ ! -z "${IREE_BUILD_SETUP_PYTHON_VENV:-}" ]]; then
+ # We've been instructed to set up a venv.
+ echo "Setting up venv at $IREE_BUILD_SETUP_PYTHON_VENV"
+ python3 -m venv "$IREE_BUILD_SETUP_PYTHON_VENV"
+ source "$IREE_BUILD_SETUP_PYTHON_VENV/bin/activate"
+ IREE_PYTHON3_EXECUTABLE="$IREE_BUILD_SETUP_PYTHON_VENV/bin/python"
+ python -m pip install -r runtime/bindings/python/iree/runtime/build_requirements.txt
+else
+ # Just use the host python and yolo with what may be installed.
+ # In practice, certain callers take care of this themselves, and we trust
+ # them to do it right.
+ IREE_PYTHON3_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE:-$(which python3)}"
+fi
if [[ -d "${BUILD_DIR}" ]]; then
echo "'${BUILD_DIR}' directory already exists. Will use cached results there."