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

Commit

Permalink
add xrt dep (and ELFIO...)
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed May 10, 2024
1 parent b28fba1 commit db070f9
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 24 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/actions/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Setup base"

inputs:
OS:
description: 'matrix.os'
required: true
ARCH:
description: 'matrix.arch'
required: true

description: ''

outputs:
BOOST_ROOT:
description: ''
value: ${{ steps.install_boost.outputs.BOOST_ROOT }}

runs:
using: "composite"
steps:
- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
compiler: gcc
vcvarsall: ${{ contains(inputs.OS, 'windows') }}
msvc: ${{ contains(inputs.OS, 'windows') }}
cmake: true
ninja: true

- uses: makslevental/mlir-wheels/actions/setup_ccache@d77bf5dc69c46a8c2738b44528749768888eb361
id: setup_ccache
with:
MATRIX_OS: ${{ inputs.OS }}
MATRIX_ARCH: ${{ inputs.ARCH }}
WORKSPACE_ROOT: ${{ github.workspace }}

- name: Install boost for XRT
if: contains(inputs.OS, 'windows') || contains(inputs.OS, 'ubuntu')
uses: MarkusJx/install-boost@v2.4.5
id: install_boost
with:
boost_version: 1.73.0
56 changes: 45 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ on:
pull_request:
types: [assigned, opened, synchronize, reopened]

concurrency:
group: test-${{ github.event.number || github.sha }}
cancel-in-progress: true

jobs:

test-x86:

continue-on-error: true

runs-on: ${{ matrix.OS }}
strategy:
fail-fast: false
Expand All @@ -26,14 +28,11 @@ jobs:
shell: bash

steps:
- name: Setup Cpp
uses: aminya/setup-cpp@v1
- uses: ./.github/workflows/base
id: base
with:
compiler: gcc
vcvarsall: ${{ contains(matrix.os, 'windows') }}
msvc: ${{ contains(matrix.os, 'windows') }}
cmake: true
ninja: true
MATRIX_OS: ${{ matrix.OS }}
MATRIX_ARCH: ${{ matrix.ARCH }}

- uses: actions/setup-python@v4
with:
Expand All @@ -44,7 +43,23 @@ jobs:
with:
submodules: true

- name: Build and install protoc
if: ${{ contains(matrix.os, 'windows') || contains(matrix.os, 'macos') }}
run: |
PROTOBUF_ROOT=$PWD/install_protobuf
git clone -b v26.1 --recursive https://github.com/protocolbuffers/protobuf.git
cmake -G Ninja -S protobuf -B build_protobuf -DCMAKE_CXX_STANDARD=14 -Dprotobuf_WITH_ZLIB=OFF \
-Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_LIBPROTOC=ON \
-DCMAKE_INSTALL_PREFIX=$PROTOBUF_ROOT \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build build_protobuf --target install
echo "PROTOBUF_ROOT=$PROTOBUF_ROOT" | tee -a $GITHUB_ENV
- name: build wheel
env:
BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }}
BOOST_VERSION: 1.73.0
run: |
pip install -r requirements-dev.txt
Expand Down Expand Up @@ -72,8 +87,6 @@ jobs:
test-linux-aarch64:

continue-on-error: true

runs-on: ${{ matrix.OS }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -103,7 +116,28 @@ jobs:
with:
python-version: ${{ matrix.py_version }}

- uses: ./.github/workflows/base
id: base
with:
MATRIX_OS: ${{ matrix.OS }}
MATRIX_ARCH: ${{ matrix.ARCH }}

- name: Build and install protoc
run: |
PROTOBUF_ROOT=$PWD/install_protobuf
git clone -b v26.1 --recursive https://github.com/protocolbuffers/protobuf.git
cmake -G Ninja -S protobuf -B build_protobuf -DCMAKE_CXX_STANDARD=14 -Dprotobuf_WITH_ZLIB=OFF \
-Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_LIBPROTOC=ON \
-DCMAKE_INSTALL_PREFIX=$PROTOBUF_ROOT \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build build_protobuf --target install
echo "PROTOBUF_ROOT=$PROTOBUF_ROOT" | tee -a $GITHUB_ENV
- name: build wheel
env:
BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }}
BOOST_VERSION: 1.73.0
run: |
pip install -r requirements-dev.txt
Expand Down
52 changes: 42 additions & 10 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,30 @@ jobs:
with:
submodules: true

- name: Setup Cpp
uses: aminya/setup-cpp@v1
- uses: ./.github/workflows/base
id: base
with:
compiler: gcc
vcvarsall: ${{ contains(matrix.os, 'windows') }}
msvc: ${{ contains(matrix.os, 'windows') }}
cmake: true
ninja: true
MATRIX_OS: ${{ matrix.OS }}
MATRIX_ARCH: ${{ matrix.ARCH }}

- name: Build and install protoc
if: ${{ contains(matrix.os, 'windows') || contains(matrix.os, 'macos') }}
run: |
PROTOBUF_ROOT=$PWD/install_protobuf
git clone -b v26.1 --recursive https://github.com/protocolbuffers/protobuf.git
cmake -S protobuf -B build_protobuf -DCMAKE_CXX_STANDARD=14 -Dprotobuf_WITH_ZLIB=OFF \
-Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_LIBPROTOC=ON \
-DCMAKE_INSTALL_PREFIX=$PROTOBUF_ROOT
cmake --build build_protobuf --target install
echo "PROTOBUF_ROOT=$PROTOBUF_ROOT" | tee -a $GITHUB_ENV
# build

- name: cibuildwheel python bindings
env:
BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }}
BOOST_VERSION: 1.73.0
run: |
pip install cibuildwheel
Expand All @@ -77,6 +89,11 @@ jobs:
with:
submodules: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: aarch64

- name: Install cross-compilation toolchain
shell: bash
run: |
Expand All @@ -85,14 +102,29 @@ jobs:
sudo apt-get install -y binutils-aarch64-linux-gnu \
g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- uses: ./.github/workflows/base
id: base
with:
platforms: aarch64
MATRIX_OS: ${{ matrix.OS }}
MATRIX_ARCH: ${{ matrix.ARCH }}

- name: Build and install protoc
run: |
PROTOBUF_ROOT=$PWD/install_protobuf
git clone -b v26.1 --recursive https://github.com/protocolbuffers/protobuf.git
cmake -S protobuf -B build_protobuf -DCMAKE_CXX_STANDARD=14 -Dprotobuf_WITH_ZLIB=OFF \
-Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_LIBPROTOC=ON \
-DCMAKE_INSTALL_PREFIX=$PROTOBUF_ROOT
cmake --build build_protobuf --target install
echo "PROTOBUF_ROOT=$PROTOBUF_ROOT" | tee -a $GITHUB_ENV
# build

- name: cibuildwheel python bindings aarch64
env:
BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }}
BOOST_VERSION: 1.73.0
run: |
pip install cibuildwheel
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "third_party/aie-rt"]
path = third_party/aie-rt
url = git@github.com:stephenneuendorffer/aie-rt.git
[submodule "third_party/XRT"]
path = third_party/XRT
url = git@github.com:Xilinx/XRT.git
[submodule "third_party/ELFIO"]
path = third_party/ELFIO
url = git@github.com:serge1/ELFIO.git
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.15)
project(xaiepy)
set(CMAKE_CXX_STANDARD 17)

include(collect)

Expand Down Expand Up @@ -33,3 +34,25 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-Wl,-U,_cdo_MaskWrite32
-Wl,-U,_cdo_Write32)
endif()

if(POLICY CMP0144)
# respect all caps <PACKAGENAME>_ROOT environment variable
# to search for package stuff
cmake_policy(SET CMP0144 NEW)
endif()

option(BUILD_PYXRT "Build XRT" ON)
if(BUILD_PYXRT)
include(scripts/stuff.cmake)
detect_pybind11_install()
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
"suffix = '${PYTHON_MODULE_SUFFIX}', "
"extension = '${PYTHON_MODULE_EXTENSION}")
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third_party/ELFIO)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/XRT/src)
add_dependencies(xaie pyxrt)
endif()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ before-build = [
"rm -rf {project}/build",
"rm -rf *egg*",
"pip install -r requirements-dev.txt",
"yum install -y epel-release && yum install -y ninja-build cmake openssl openssl-devel"
"yum install -y epel-release && yum install -y ninja-build cmake openssl openssl-devel boost-devel protobuf-devel"
]

[tool.cibuildwheel.macos]
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ ctypesgen
cmake-format
black
pytest
cffi
cffi
pybind11[global]
27 changes: 27 additions & 0 deletions scripts/stuff.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,30 @@ function(print_target_properties target)
endif()
endforeach()
endfunction()


# from https://github.com/llvm/llvm-project/blob/427beff2ad274f38f9de682f48f550cdcf5fc505/mlir/cmake/modules/MLIRDetectPythonEnv.cmake#L35C1-L58C14
# Detects a pybind11 package installed in the current python environment
# and sets variables to allow it to be found. This allows pybind11 to be
# installed via pip, which typically yields a much more recent version than
# the OS install, which will be available otherwise.
function(detect_pybind11_install)
if(pybind11_DIR)
message(STATUS "Using explicit pybind11 cmake directory: ${pybind11_DIR} (-Dpybind11_DIR to change)")
else()
message(STATUS "Checking for pybind11 in python path...")
execute_process(
COMMAND "${Python3_EXECUTABLE}"
-c "import pybind11;print(pybind11.get_cmake_dir(), end='')"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE STATUS
OUTPUT_VARIABLE PACKAGE_DIR
ERROR_QUIET)
if(NOT STATUS EQUAL "0")
message(STATUS "not found (install via 'pip install pybind11' or set pybind11_DIR)")
return()
endif()
message(STATUS "found (${PACKAGE_DIR})")
set(pybind11_DIR "${PACKAGE_DIR}" PARENT_SCOPE)
endif()
endfunction()
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
"-DCMAKE_C_VISIBILITY_PRESET=default",
]

if platform.system() == "Windows":
cmake_args += [
"-DCMAKE_C_COMPILER=cl",
Expand Down Expand Up @@ -96,6 +97,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
build_args += ["--config", cfg]

if platform.system() == "Darwin":
cmake_args += ["-DBUILD_PYXRT=OFF"]
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 @@ -108,16 +110,19 @@ def build_extension(self, ext: CMakeExtension) -> None:
else:
build_args += [f"-j{os.environ.get('PARALLEL_LEVEL')}"]

env = os.environ.copy()
env["XRT_NATIVE_BUILD"] = "no"
print("ENV", pprint(os.environ), file=sys.stderr)
print("CMAKE_ARGS", cmake_args, file=sys.stderr)

subprocess.run(
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True, env=env
)
subprocess.run(
["cmake", "--build", ".", "--target", "xaie", *build_args],
cwd=build_temp,
check=True,
env=env,
)

sys.path.append(str(HERE))
Expand Down
1 change: 1 addition & 0 deletions third_party/ELFIO
Submodule ELFIO added at 45af83
1 change: 1 addition & 0 deletions third_party/XRT
Submodule XRT added at 7ae1da

0 comments on commit db070f9

Please sign in to comment.