Skip to content

Commit

Permalink
wrapper update to CLIc 0.6 (#23)
Browse files Browse the repository at this point in the history
* wrapper update to CLIc 0.6
  • Loading branch information
StRigaud authored Nov 21, 2022
1 parent 5d18333 commit 54767f9
Show file tree
Hide file tree
Showing 53 changed files with 3,279 additions and 2,926 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
max-parallel: 8
max-parallel: 3
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]
platform: [ubuntu-latest] #, windows-latest, macos-latest]

steps:
Expand Down Expand Up @@ -49,12 +49,5 @@ jobs:
- name: Compile
shell: bash -l {0}
run: pip install -e .
run: pip install -e . -vvv

# Issue to link with ICD-loader and ICDs coming from python
# - name: Test
# shell: bash -l {0}
# run: oclgrind python -m pytest .

# - name: Coverage
# uses: codecov/codecov-action@v1
69 changes: 69 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build & Deploy

# Build on every branch push, tag push, and pull request change:
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: x86_64 arm64

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

upload_all:
name: Upload if release
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')

steps:
- uses: actions/setup-python@v4
with:
python-version: "3.x"

- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# skip_existing: true
verbose: true
2 changes: 1 addition & 1 deletion CLIc
Submodule CLIc updated from 443eef to 61daa9
112 changes: 69 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,86 @@
cmake_minimum_required(VERSION 3.20)

# Set project name and version
project(pyClesperanto VERSION "0.4.0")
# - package version is managed in file `version.py`
project(pyClesperanto)

# Compilation tag for CLIc library linking
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_BUILD_TYPE Release)

# find required package
set(Python_FIND_VIRTUALENV "FIRST") # look for python in virtual env or conda first before checking the system.
find_package(Python COMPONENTS Interpreter Development REQUIRED)
string(TOLOWER ${PROJECT_NAME} PY_PACKAGE_NAME)
set(CY_PACKAGE_NAME _${PY_PACKAGE_NAME})

# find opencl icd-loader in virtual environment
file(GLOB PYTHON_OpenCL_LIBRARY ${Python_LIBRARY_DIRS}/libOpenCL.so)
if(PYTHON_OpenCL_LIBRARY STREQUAL "")
message(STATUS "WARNING: No ICD found in virtual environment.")
else()
message(STATUS ${PYTHON_OpenCL_LIBRARY})
set(OpenCL_LIBRARIES ${PYTHON_OpenCL_LIBRARY})
set(OpenCL_LIBRARY ${PYTHON_OpenCL_LIBRARY})
set(OpenCL_FOUND TRUE)
message(STATUS "Package: ${PY_PACKAGE_NAME}")
message(STATUS "C++ Module: ${CY_PACKAGE_NAME}")

# Compilation tag for CLIc library linking for UNIX
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()
# set(CMAKE_CXX_STANDARD 17) # Use C++17
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Require (at least) it

# Compile CLIc Back-end library
add_subdirectory(CLIc)
# find python dev library
# look for python in virtual env or conda first before checking the system.
set(Python_FIND_VIRTUALENV "FIRST")
find_package(Python3 COMPONENTS Interpreter Development.Embed Development.Module)

if(Python3_Development.Module_FOUND)
message(STATUS "Python Developement Module found")
endif()

if(Python3_Development.Embed_FOUND)
message(STATUS "Python Developement Embed found")
endif()

message(STATUS "OpenCL_FOUND: ${OpenCL_FOUND}")
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
message(STATUS "OpenCL_LIBRARIES: ${OpenCL_LIBRARIES}")

# CMake Warning:
# Manually-specified variables were not used by the project:
# PYTHON_INCLUDE_DIR
# PYTHON_LIBRARY
# PYTHON_VERSION_STRING
# Python_EXECUTABLE
# Python_INCLUDE_DIR
# Python_LIBRARY

# split c++ stand-alone build from python wrapper build with scikit-build
if(DEFINED SKBUILD)
# Define CLIc Backend library
option(BUILD_TESTING OFF)
add_subdirectory(CLIc)

set(ignoreMe "${SKBUILD}")
set(PACKAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pyclesperanto)
set(WRAPPER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wrapper)
if(SKBUILD)
# Scikit-Build does not add your site-packages to the search path
# automatically, so we need to add it _or_ the pybind11 specific directory
# here.
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "import pybind11; print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE _tmp_dir
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
endif()

file(GLOB_RECURSE WRAPPER_SOURCES_FILES ${WRAPPER_DIR}/*.cpp)
set(PACKAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${PY_PACKAGE_NAME})
set(WRAPPER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wrapper)
file(GLOB_RECURSE WRAPPER_SOURCES_FILES ${WRAPPER_DIR}/*.cpp)

# call pybind11-config to obtain the root of the cmake package
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11 --cmakedir
OUTPUT_VARIABLE pybind11_ROOT_RAW)
string(STRIP ${pybind11_ROOT_RAW} pybind11_ROOT)
find_package(pybind11)
find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(_pyclic MODULE ${WRAPPER_SOURCES_FILES})
target_link_libraries(_pyclic PRIVATE CLIc::CLIc)
add_dependencies(_pyclic CLIc)
target_include_directories(_pyclic PUBLIC "$<BUILD_INTERFACE:${WRAPPER_DIR}>")
target_compile_definitions(_pyclic PRIVATE VERSION_INFO=${PROJECT_VERSION})
pybind11_add_module(${CY_PACKAGE_NAME} MODULE ${WRAPPER_SOURCES_FILES})

# Installing the extension module to the root of the package
install(TARGETS _pyclic DESTINATION .)
target_link_libraries(${CY_PACKAGE_NAME} PRIVATE CLIc::CLIc)
add_dependencies(${CY_PACKAGE_NAME} CLIc)
target_include_directories(${CY_PACKAGE_NAME} PUBLIC "$<BUILD_INTERFACE:${WRAPPER_DIR}>")
target_compile_features(${CY_PACKAGE_NAME} PRIVATE cxx_std_17)

if(APPLE)
set_target_properties(
_pyclic PROPERTIES INSTALL_RPATH "@loader_path/${CMAKE_INSTALL_LIBDIR}")
else()
set_target_properties(_pyclic PROPERTIES INSTALL_RPATH
"$ORIGIN/${CMAKE_INSTALL_LIBDIR}")
endif()
# Installing the extension module to the root of the package
install(TARGETS ${CY_PACKAGE_NAME} DESTINATION .)

if(APPLE)
set_target_properties(
${CY_PACKAGE_NAME} PROPERTIES INSTALL_RPATH "@loader_path/${CMAKE_INSTALL_LIBDIR}")
else()
set_target_properties(${CY_PACKAGE_NAME} PROPERTIES INSTALL_RPATH
"$ORIGIN/${CMAKE_INSTALL_LIBDIR}")
endif()
Loading

0 comments on commit 54767f9

Please sign in to comment.