forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-organize the runtime python directory to be more extensible. (iree…
…-org#9071) * Native library goes from iree/runtime/_binding.so -> iree/_runtime.so * Make iree/runtime/_binding.py a trampoline to the correct runtime module. In the future, this will allow us to use a different native implementation based on environment and other packages installed (i.e. would allow an iree-runtime-instrumented and iree-runtime-debug to co-exist and be selected at runtime). * Move tests to a top-level tests directory (common convention). * Move native code to the top-level. * Adds a package_test which builds/installs the package to a venv and does some sanity checking of the modules and scripts (takes about ~12s to run on my machine, so should be hidden in the noise of bigger tests). See iree-org#9080 for updating docker images and actually enabling package_test.
- Loading branch information
1 parent
ec0dfa4
commit b17a65e
Showing
28 changed files
with
140 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2022 The IREE Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
"""Imports the native runtime library. | ||
All code in the runtime should use runtime imports via this module, which | ||
locates the actual _runtime module based on environment configuration. | ||
Currently, we only bundle a single runtime library, but in the future, this | ||
will let us dynamically switch between instrumented, debug, etc by changing | ||
the way this trampoline functions. | ||
""" | ||
|
||
import sys | ||
|
||
from iree import _runtime | ||
sys.modules[__name__] = _runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
import os | ||
import sys | ||
|
||
from . import binding as _binding | ||
from . import _binding | ||
|
||
try: | ||
import yaml | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2022 The IREE Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
"""Creates a venv and installs the runtime package, doing some smoke tests. | ||
This is not a perfect approximation of how the runtime package is built | ||
for real since it is run from the build dir and does not do a recursive | ||
invocation of CMake. However, it can detect gross errors in the installation | ||
process, including missing modules, scripts, etc. | ||
""" | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
import tempfile | ||
from typing import List | ||
|
||
SETUP_PY_DIR = sys.argv[1] | ||
if not os.path.exists(os.path.join(SETUP_PY_DIR, "setup.py")): | ||
print("ERROR: Expected directory containing setup.py as argument") | ||
print(f"Using setup.py directory: {SETUP_PY_DIR}") | ||
|
||
# Figure out where to stage output. | ||
TEMP_DIR = os.getenv("TEST_TMPDIR") | ||
if not TEMP_DIR: | ||
TEMP_DIR = tempfile.gettempdir() | ||
|
||
# Create the venv. | ||
VENV_DIR = os.path.join(TEMP_DIR, "iree_runtime_venv") | ||
print(f"Using venv directory: {VENV_DIR}") | ||
subprocess.check_call([sys.executable, "-m", "venv", VENV_DIR]) | ||
venv_python = None | ||
for venv_bin in [ | ||
os.path.join(VENV_DIR, "bin"), # Posix. | ||
os.path.join(VENV_DIR, "Scripts") # Windows. | ||
]: | ||
if os.path.exists(os.path.join(venv_bin, "activate")): | ||
venv_python = os.path.join(venv_bin, "python") | ||
if not venv_python: | ||
print("ERROR: Could not find venv python") | ||
venv_bin = os.path.dirname(venv_python) | ||
print(f"Running with python: {venv_python}") | ||
|
||
# Install the package. | ||
subprocess.check_call([ | ||
venv_python, "-m", "pip", "install", "--force-reinstall", SETUP_PY_DIR + "/" | ||
]) | ||
|
||
# Run some sanity checks. | ||
if "PYTHONPATH" in os.environ: | ||
del os.environ["PYTHONPATH"] | ||
|
||
print("***** Sanity checking that module loads...") | ||
subprocess.check_call( | ||
[venv_python, "-c", "import iree.runtime; print('Runtime loaded')"], | ||
cwd=venv_bin) | ||
|
||
|
||
# Check tools. | ||
def check_tool(tool_name: str, args: List[str]): | ||
print(f"**** Checking tool {tool_name} with args {args}") | ||
subprocess.check_call([os.path.join(venv_bin, tool_name)] + args, | ||
cwd=venv_bin) | ||
|
||
|
||
check_tool("iree-benchmark-module", ["--help"]) | ||
check_tool("iree-benchmark-trace", ["--help"]) | ||
check_tool("iree-run-module", ["--help"]) | ||
check_tool("iree-run-trace", ["--help"]) | ||
|
||
print("***** All done *****") |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
*/ | ||
|
||
{ | ||
global: PyInit_binding; | ||
global: PyInit__runtime; | ||
local: *; | ||
}; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters