Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
rewind aie-rt
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed May 9, 2024
1 parent eacb0ab commit c33ff71
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 31 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, windows-2019 ]
os: [ ubuntu-20.04, windows-2019, macos-12 ]
py_version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]

defaults:
Expand All @@ -37,7 +37,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
python-version: ${{ matrix.py_version }}

- name: Checkout actions
uses: actions/checkout@v3
Expand All @@ -58,6 +58,13 @@ jobs:
pytest ../tests
popd
- name: Upload wheels
if: (success() || failure())
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl
name: build_artifact_python_bindings

test-linux-aarch64:

continue-on-error: true
Expand Down Expand Up @@ -89,7 +96,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
python-version: ${{ matrix.py_version }}

- name: build wheel
run: |
Expand All @@ -104,3 +111,10 @@ jobs:
pip install xaiepy -f $PWD
pytest ../tests
popd
- name: Upload wheels
if: (success() || failure())
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl
name: build_artifact_python_bindings
6 changes: 6 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
- OS: windows-2019
ARCH: AMD64

- OS: macos-12
ARCH: x86_64

- OS: macos-12
ARCH: arm64

defaults:
run:
shell: bash
Expand Down
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(AIERT_SRC_DIR ${PROJECT_SOURCE_DIR}/third_party/aie-rt/driver/src)
add_subdirectory(${AIERT_SRC_DIR})

string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
set(XAIE_DEBUG "XAIE_DEBUG")
endif()

Expand All @@ -23,3 +23,15 @@ set_target_properties(xaie PROPERTIES LINKER_LANGUAGE C)
target_compile_definitions(xaie PUBLIC ${XAIE_DEBUG} __AIECDO__)
target_include_directories(xaie PUBLIC ${AIERT_INCLUDE_DIRECTORIES})
target_include_directories(xaie PUBLIC SYSTEM ${PROJECT_SOURCE_DIR}/include)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_options(
xaie
PUBLIC
-Wl,-U,_cdo_BlockSet32
-Wl,-U,_cdo_BlockWrite32
-Wl,-U,_cdo_MaskPoll
-Wl,-U,_cdo_MaskWrite32
-Wl,-U,_cdo_Write32)
# knockout xlnx-ai-engine.h which includes <linux>
target_compile_definitions(xaie PUBLIC _UAPI_AI_ENGINE_H_)
endif()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ requires = [
"wheel",
"cmake>=3.12",
"ctypesgen",
"ninja",
"cffi"
]
build-backend = "setuptools.build_meta"
Expand Down
12 changes: 10 additions & 2 deletions scripts/gen_xaie_ctypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import sys
from argparse import Namespace
from glob import glob
Expand Down Expand Up @@ -249,21 +250,28 @@ def print_loader(self):
EXCLUDED_HEADERS = {"xaie_interrupt.h"}


def generate(xaie_build_include_dir: Path, output: Path, bootgen_include_dir: Path):
def generate(xaie_build_include_dir: Path, output: Path, elf_include_dir: Path):
headers = list(
filter(
lambda f: Path(f).name not in EXCLUDED_HEADERS,
glob(f'{xaie_build_include_dir / "xaiengine" / "*.h"}'),
)
)

if platform.system() == "Darwin":
cc = "clang"
elif platform.system() in {"Linux", "Windows"}:
cc = "gcc"
else:
raise NotImplementedError(f"unknown platform {platform.system()}")

args = Namespace(
headers=headers,
all_headers=False,
allow_gnu_c=False,
builtin_symbols=False,
compile_libdirs=[str(Path(__file__).parent)],
cpp=f"gcc -E -I {bootgen_include_dir}",
cpp=f"{cc} -E -I {elf_include_dir}",
cpp_defines=[],
cpp_undefines=[],
debug_level=0,
Expand Down
32 changes: 15 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ def build_extension(self, ext: CMakeExtension) -> None:

cmake_generator = os.environ.get("CMAKE_GENERATOR", "Ninja")

RUN_TESTS = 1 if check_env("RUN_TESTS") else 0
# make windows happy
PYTHON_EXECUTABLE = str(Path(sys.executable))
CMAKE_MODULE_PATH = str(
Path(__file__).parent / "third_party" / "aie-rt" / "fal" / "cmake"
)
BOOTGEN_INCLUDE_PATH = str(Path(__file__).parent / "third_party" / "bootgen")
if platform.system() == "Windows":
PYTHON_EXECUTABLE = PYTHON_EXECUTABLE.replace("\\", "\\\\")
# i have no clue - cmake parses these at different points...?
CMAKE_MODULE_PATH = CMAKE_MODULE_PATH.replace("\\", "//")
BOOTGEN_INCLUDE_PATH = BOOTGEN_INCLUDE_PATH.replace("\\", "//")

cmake_args = [
f"-B{build_temp}",
Expand All @@ -59,6 +56,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
"-DCMAKE_CXX_COMPILER=cl",
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
"-DCMAKE_C_FLAGS=/MT",
"-DCMAKE_SHARED_LINKER_FLAGS=/FORCE:UNRESOLVED",
"-DCMAKE_CXX_FLAGS=/MT",
"-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON",
"-DCMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS=ON",
Expand Down Expand Up @@ -95,7 +93,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
if not single_config:
build_args += ["--config", cfg]

if sys.platform.startswith("darwin"):
if platform.system() == "Darwin":
osx_version = os.getenv("OSX_VERSION", "11.6")
cmake_args += [f"-DCMAKE_OSX_DEPLOYMENT_TARGET={osx_version}"]
# Cross-compile support for macOS - respect ARCHFLAGS if set
Expand All @@ -119,27 +117,27 @@ def build_extension(self, ext: CMakeExtension) -> None:
cwd=build_temp,
check=True,
)
subprocess.run(
["ls", "-lah"],
cwd=Path.cwd(),
check=True,
)
subprocess.run(
["ls", "-lah"],
cwd=Path(__file__).parent,
check=True,
)

sys.path.append(str(Path(__file__).parent))
HERE = Path(__file__).parent
sys.path.append(str(HERE))
from scripts import gen_xaie_ctypes
from scripts import gen_cdo

gen_xaie_ctypes.generate(
build_temp / "include",
extdir / PACKAGE_NAME / "__init__.py",
BOOTGEN_INCLUDE_PATH,
HERE / "include",
)
shlib_ext = "dll" if platform.system() == "Windows" else "so"

if platform.system() == "Darwin":
shlib_ext = "dylib"
elif platform.system() == "Linux":
shlib_ext = "so"
elif platform.system() == "Windows":
shlib_ext = "pyd"
else:
raise NotImplementedError(f"unknown platform {platform.system()}")

gen_cdo.build_ffi(
str(build_temp), str(extdir / PACKAGE_NAME / f"_cdo.{shlib_ext}")
)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_e2e.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
from pathlib import Path

from xaiepy import (
Expand Down Expand Up @@ -110,4 +111,5 @@ def test_transaction():
XAie_CoreEnable(devInst, tile_0_2)

txn_inst = XAie_ExportTransactionInstance(devInst)
_XAie_Txn_Submit(devInst, txn_inst)
if platform.system() != "Windows":
_XAie_Txn_Submit(devInst, txn_inst)
2 changes: 1 addition & 1 deletion third_party/aie-rt
18 changes: 12 additions & 6 deletions xaiepy/cdo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import platform
import sys
from os import RTLD_GLOBAL, RTLD_NOW

old = sys.getdlopenflags()
try:
sys.setdlopenflags(RTLD_GLOBAL | RTLD_NOW)

if platform.system() != "Windows":
from os import RTLD_GLOBAL, RTLD_NOW

old = sys.getdlopenflags()
try:
sys.setdlopenflags(RTLD_GLOBAL | RTLD_NOW)
from ._cdo import ffi
finally:
sys.setdlopenflags(old)
else:
from ._cdo import ffi
finally:
sys.setdlopenflags(old)


@ffi.def_extern()
Expand Down

0 comments on commit c33ff71

Please sign in to comment.