Skip to content

Commit

Permalink
[aot] AOT compat test in workflow (#7033)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: PENGUINLIONG <admin@penguinliong.moe>
  • Loading branch information
3 people authored Jan 11, 2023
1 parent ea0c0c4 commit ea9299c
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .github/workflows/scripts/unix_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ set -ex

export PYTHONUNBUFFERED=1

export TAICHI_AOT_FOLDER_PATH="taichi/tests"
export TI_SKIP_VERSION_CHECK=ON
export TI_CI=1
export LD_LIBRARY_PATH=$PWD/build/:$LD_LIBRARY_PATH
export TI_OFFLINE_CACHE_FILE_PATH=$PWD/.cache/taichi

setup_python

pip3 install -i https://pypi.taichi.graphics/simple/ taichi-nightly
[[ "$IN_DOCKER" == "true" ]] && cd taichi
python3 tests/generate_compat_test_modules.py
python3 -m pip uninstall taichi-nightly -y

setup_python

python3 tests/run_c_api_compat_test.py

if [ ! -z "$AMDGPU_TEST" ]; then
sudo chmod 666 /dev/kfd
Expand Down
34 changes: 34 additions & 0 deletions tests/generate_compat_test_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Generate AOT modules with Taichi nightly (which is definitely an older version
from this currently building one in development branch) for
`run_c_api_compat_test.py` to consume.
"""
import glob
import os
import pathlib
import subprocess

curr_dir = os.path.dirname(os.path.abspath(__file__))
curr_dir = os.path.dirname(curr_dir)
build_dir = os.path.join(curr_dir, 'build')
cpp_test_filename = 'taichi_cpp_tests'
capi_test_filename = 'taichi_c_api_tests'
cpp_tests_path = os.path.join(build_dir, capi_test_filename)
c_api_tests_path = os.path.join(build_dir, cpp_test_filename)


def generate():
aot_files = glob.glob("tests/cpp/aot/python_scripts/*.py")
for x in aot_files:
path_name = pathlib.Path(x).name[:-3]
os.mkdir('tests/cpp/aot/python_scripts/' + path_name)
os.environ[
"TAICHI_AOT_FOLDER_PATH"] = curr_dir + '/tests/cpp/aot/python_scripts/' + path_name
try:
subprocess.check_call(["python", x, "--arch=vulkan"])
except subprocess.CalledProcessError:
continue


if __name__ == "__main__":
generate()
75 changes: 75 additions & 0 deletions tests/run_c_api_compat_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Ensure AOT modules compiled by old versions of Taichi is compatible with the
latest Taichi Runtime.
"""
import glob
import json
import os
import pathlib
import subprocess

curr_dir = os.path.dirname(os.path.abspath(__file__))
curr_dir = os.path.dirname(curr_dir)
build_dir = os.path.join(curr_dir, 'build')
cpp_test_filename = 'taichi_cpp_tests'
capi_test_filename = 'taichi_c_api_tests'
cpp_tests_path = os.path.join(build_dir, capi_test_filename)
c_api_tests_path = os.path.join(build_dir, cpp_test_filename)

run_dict = {}


def init_dict(run_dict, aot_files):
curr_dir = os.path.dirname(os.path.abspath(__file__))
test_config_path = os.path.join(curr_dir, 'test_config.json')
with open(test_config_path, 'r') as f:
test_config = json.loads(f.read())

assert ("aot_test_cases" in test_config.keys())
assert ("capi_aot_test_cases" in test_config.keys())

for x in aot_files:
path_name = pathlib.Path(x).name[:-3]
run_dict[path_name] = []
for cpp_test_name, value in test_config["aot_test_cases"].items():
if value[1] != "--arch=vulkan":
continue
test_command = []
test_command.append(cpp_tests_path)
test_command.append(f"--gtest_filter={cpp_test_name}")
run_dict[value[0][3][:-3]].append(test_command)

for cpp_test_name, value in test_config["capi_aot_test_cases"].items():
if value[1] != "--arch=vulkan":
continue
test_command = []
test_command.append(cpp_tests_path)
test_command.append(f"--gtest_filter={cpp_test_name}")
run_dict[value[0][3][:-3]].append(test_command)


def run():
aot_files = glob.glob('tests/cpp/aot/python_scripts/*.py')
init_dict(run_dict, aot_files)
print(run_dict)
for x in aot_files:
path_name = pathlib.Path(x).name[:-3]
os.environ[
"TAICHI_AOT_FOLDER_PATH"] = curr_dir + '/tests/cpp/aot/python_scripts/' + path_name
if len(os.listdir('tests/cpp/aot/python_scripts/' + path_name)) == 0:
continue
for i in run_dict[path_name]:
print(i)
try:
subprocess.check_call(i, env=os.environ.copy(), cwd=build_dir)
except subprocess.SubprocessError:
print(os.environ["TAICHI_AOT_FOLDER_PATH"])
print(path_name)
print(os.listdir(os.environ["TAICHI_AOT_FOLDER_PATH"]))
continue
except FileNotFoundError:
continue


if __name__ == "__main__":
run()

0 comments on commit ea9299c

Please sign in to comment.