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

Commit

Permalink
Build libxaie and generate ctype bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed May 7, 2024
1 parent 9c3f91a commit 682ddf8
Show file tree
Hide file tree
Showing 14 changed files with 923 additions and 1 deletion.
58 changes: 58 additions & 0 deletions .github/actions/setup_base/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "Setup base"

inputs:
MATRIX_OS:
description: 'matrix.os'
required: true
MATRIX_ARCH:
description: 'matrix.arch'
required: true

description: ''

runs:
using: "composite"
steps:
- uses: ilammy/msvc-dev-cmd@v1.4.1
if: ${{ inputs.MATRIX_OS == 'windows-2019' }}

- name: Set up Visual Studio shell
if: ${{ inputs.MATRIX_OS == 'windows-2019' }}
uses: egor-tensin/vs-shell@v2
with:
arch: x64

- name: MS Build
if: ${{ inputs.MATRIX_OS == 'windows-2019' }}
uses: microsoft/setup-msbuild@v1.1

# - name: Free disk space
# if: contains(inputs.MATRIX_OS, 'ubuntu')
# uses: descriptinc/free-disk-space@main
# with:
# tool-cache: true
# android: true
# dotnet: true
# haskell: true
# large-packages: true
# swap-storage: false # This frees space on the wrong partition.

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Ninja
uses: llvm/actions/install-ninja@6a57890d0e3f9f35dfc72e7e48bc5e1e527cdd6c # Jan 17

- name: Install cross-compilation toolchain
shell: bash
if: ${{ inputs.MATRIX_OS == 'ubuntu-20.04' && inputs.MATRIX_ARCH == 'aarch64' }}
run: |
sudo apt-get update
sudo apt-get install -y binutils-aarch64-linux-gnu \
g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
- name: pip install standard tools
shell: bash
run: pip install cibuildwheel wheel auditwheel
150 changes: 150 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Wheels

on:
push:
branches:
- main
pull_request:
types: [assigned, opened, synchronize, reopened]
workflow_dispatch:

jobs:

build:

continue-on-error: true

runs-on: ${{ matrix.OS }}
strategy:
fail-fast: false
matrix:
include:
- OS: ubuntu-20.04
ARCH: x86_64

- OS: windows-2019
ARCH: AMD64

defaults:
run:
shell: bash

steps:

- name: Checkout actions
uses: actions/checkout@v3
with:
submodules: true

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

# build

- name: cibuildwheel python bindings
run: |
cibuildwheel --output-dir wheelhouse
# done

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl
name: build_artifact_python_bindings

build-linux-aarch64:

continue-on-error: true

runs-on: ${{ matrix.OS }}
strategy:
fail-fast: false
matrix:
include:
- OS: ubuntu-20.04
ARCH: aarch64
PY_VERSION: "cp38"

- OS: ubuntu-20.04
ARCH: aarch64
PY_VERSION: "cp39"

- OS: ubuntu-20.04
ARCH: aarch64
PY_VERSION: "cp310"

- OS: ubuntu-20.04
ARCH: aarch64
PY_VERSION: "cp311"

- OS: ubuntu-20.04
ARCH: aarch64
PY_VERSION: "cp312"

steps:
- name: Checkout actions
uses: actions/checkout@v3
with:
submodules: true

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

- name: Set up QEMU
if: ${{ matrix.OS == 'ubuntu-20.04' && matrix.ARCH == 'aarch64' }}
uses: docker/setup-qemu-action@v2
with:
platforms: ${{ matrix.ARCH }}

# build

- name: cibuildwheel python bindings aarch64
run: |
cibuildwheel --output-dir wheelhouse
# done

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl
name: build_artifact_python_bindings

upload_bindings_wheels:

needs: [build, build-linux-aarch64]

runs-on: ubuntu-latest

permissions:
id-token: write
contents: write

steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: build_artifact_python_bindings
path: dist

- name: Release current commit
uses: ncipollo/release-action@v1.12.0
with:
artifacts: "dist/*.whl"
token: "${{ secrets.GITHUB_TOKEN }}"
tag: "latest"
name: "latest"
removeArtifacts: false
allowUpdates: true
replacesArtifacts: true
makeLatest: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ __pycache__/

# C extensions
*.so
*.a

# Distribution / packaging
.Python
Expand Down Expand Up @@ -157,4 +158,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
cmake-build-debug
cmake-build-release
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "third_party/bootgen"]
path = third_party/bootgen
url = https://github.com/Xilinx/bootgen.git
[submodule "third_party/aie-rt"]
path = third_party/aie-rt
url = git@github.com:stephenneuendorffer/aie-rt.git
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.15)
project(xaiepy)

include(collect)

#find_package(OpenSSL REQUIRED)
#if(OPENSSL_FOUND)
# message(STATUS "OpenSSL found")
# message(STATUS "OpenSSL include directories:" ${OPENSSL_INCLUDE_DIR})
#else()
# message(FATAL_ERROR "OpenSSL Not found.")
#endif()

set(BOOTGEN_SRC_DIR ${PROJECT_SOURCE_DIR}/third_party/bootgen)
# malloc.h is deprecated and should not be used
# https://stackoverflow.com/a/56463133 If you want to use malloc, then include
# stdlib.h
file(READ ${BOOTGEN_SRC_DIR}/cdo-npi.c FILE_CONTENTS)
string(REPLACE "#include <malloc.h>" "" FILE_CONTENTS "${FILE_CONTENTS}")
file(WRITE ${BOOTGEN_SRC_DIR}/cdo-npi.c "${FILE_CONTENTS}")

file(READ ${BOOTGEN_SRC_DIR}/cdo-alloc.c FILE_CONTENTS)
string(REPLACE "#include <malloc.h>" "" FILE_CONTENTS "${FILE_CONTENTS}")
file(WRITE ${BOOTGEN_SRC_DIR}/cdo-alloc.c "${FILE_CONTENTS}")

# since we explicitly link OpenSSL::applink
file(READ ${BOOTGEN_SRC_DIR}/main.cpp FILE_CONTENTS)
string(REPLACE "#include \"openssl/ms/applink.c\"" "" FILE_CONTENTS
"${FILE_CONTENTS}")
file(WRITE ${BOOTGEN_SRC_DIR}/main.cpp "${FILE_CONTENTS}")

# objlib
file(GLOB BOOTGEN_SOURCE_SRCS ${BOOTGEN_SRC_DIR}/*.c*)
list(REMOVE_ITEM BOOTGEN_SOURCE_SRCS ${BOOTGEN_SRC_DIR}/main.cpp)
add_library(bootgen_objlib OBJECT ${BOOTGEN_SOURCE_SRCS})
set_property(TARGET bootgen_objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_definitions(bootgen_objlib PRIVATE YY_NO_UNISTD_H)
endif()
target_include_directories(bootgen_objlib PRIVATE ${BOOTGEN_SRC_DIR}
${OPENSSL_INCLUDE_DIR})
target_link_libraries(bootgen_objlib PUBLIC)

add_library(bootgen_shared SHARED $<TARGET_OBJECTS:bootgen_objlib>)
add_library(bootgen_static STATIC $<TARGET_OBJECTS:bootgen_objlib>)

#add_executable(bootgen ${BOOTGEN_SRC_DIR}/main.cpp)
#target_include_directories(
# bootgen PUBLIC ${BOOTGEN_SRC_DIR} ${OPENSSL_INCLUDE_DIR}
# ${CMAKE_CURRENT_BINARY_DIR}/include)
#target_compile_definitions(bootgen PRIVATE OPENSSL_USE_APPLINK)
#target_link_libraries(bootgen PRIVATE bootgen_static OpenSSL::SSL
# OpenSSL::applink)

add_library(cdo_driver STATIC ${BOOTGEN_SRC_DIR}/cdo-driver/cdo_driver.c)
# because primarily this will be linked into libxaie.so... if not you get
# /usr/bin/ld: libcdo_driver.a(cdo_driver.c.o): warning: relocation against
# `hdr' in read-only section `.text' /usr/bin/ld:
# libcdo_driver.a(cdo_driver.c.o): relocation R_X86_64_PC32 against symbol
# `LEfwrite' can not be used when making a shared object; recompile with -fPIC
set_property(TARGET cdo_driver PROPERTY POSITION_INDEPENDENT_CODE 1)

target_include_directories(
cdo_driver PUBLIC $<BUILD_INTERFACE:${BOOTGEN_SRC_DIR}/cdo-driver>
$<INSTALL_INTERFACE:include/cdo_driver>)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(cdo_driver PRIVATE -Wno-cast-qual -Wno-sign-compare)
endif()

set(AIERT_SRC_DIR ${PROJECT_SOURCE_DIR}/third_party/aie-rt/driver/src)
# gotta add the subdirectory so the copies to build/include/xaiengine occur...
add_subdirectory(${AIERT_SRC_DIR})

target_compile_options(aienginev2 PRIVATE -Wall -Wextra -D__AIECDO__)
get_target_property(AIERT_SRCS aienginev2 SOURCES)
list(TRANSFORM AIERT_SRCS PREPEND ${AIERT_SRC_DIR}/)
get_target_property(AIERT_INCLUDE_DIRECTORIES aienginev2 INCLUDE_DIRECTORIES)

add_library(xaie SHARED ${AIERT_SRCS})
set_target_properties(xaie PROPERTIES LINKER_LANGUAGE C)
target_compile_options(xaie PRIVATE -D__AIECDO__)
target_link_libraries(xaie cdo_driver)
target_include_directories(xaie PUBLIC ${AIERT_INCLUDE_DIRECTORIES})
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"ninja",
"cmake>=3.12",
"ctypesgen"
]
build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
build-verbosity = 3
build = "cp38-* cp39-* cp310-* cp311-* cp312-*"
skip = ["*-manylinux_i686", "*-musllinux*"]
manylinux-aarch64-image = "manylinux_2_28"
manylinux-x86_64-image = "manylinux_2_28"

[tool.cibuildwheel.linux]
before-build = [
"pip install -r requirements-dev.txt",
]

[tool.cibuildwheel.windows]
build = "cp38-* cp39-* cp310-* cp311-* cp312-*"
before-build = [
"pip install -r requirements-dev.txt",
]
7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
setuptools>=42
wheel
ninja
cmake>=3.28
ctypesgen
cmake-format
black
Loading

0 comments on commit 682ddf8

Please sign in to comment.