Skip to content

scikit-build setup.py for numba-dpex #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#[=======================================================================[.rst:
numba_dpex
-----------

A cmake file to compile the ``_dpexrt_python`` Python C extension for
``numba_dpex``. You can build this component locally in-place by invoking these
commands:

.. code-block:: cmake
~$ cmake .
~$ cmake --build . --verbose

Once compiled, the _dpexrt_python library will be in ``numba_dpex/core/runtime``
folder.

This ``CMakeLists.txt`` file will be used by ``setup.py``.
#]=======================================================================]

cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()

message(STATUS "NUMBA_DPEX_VERSION=" "${NUMBA_DPEX_VERSION}")

project(numba-dpex
DESCRIPTION "An extension for Numba to add data-parallel offload capability"
VERSION ${NUMBA_DPEX_VERSION}
)

if(IS_INSTALL)
install(DIRECTORY numba_dpex
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
endif()

add_subdirectory(numba_dpex)
3 changes: 0 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
include MANIFEST.in
include README.md setup.py LICENSE

recursive-include numba_dpex *.cl
recursive-include numba_dpex *.spir

include versioneer.py
include numba_dpex/_version.py

Expand Down
4 changes: 3 additions & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ requirements:
host:
- python
- setuptools >=63.*
- numba 0.57*
- scikit-build >=0.15*
- cmake >=3.26*
- numba >=0.57*
- dpctl >=0.14*
- dpnp >=0.11*
- dpcpp-llvm-spirv
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies:
- mkl >=2021.3.0 # for dpnp
- dpcpp-llvm-spirv
- packaging
- scikit-build >=0.15*
- cmake >=3.26*
- pytest
- pip
- pip:
Expand Down
2 changes: 2 additions & 0 deletions environment/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ dependencies:
- pytest-cov
- pytest-xdist
- pexpect
- scikit-build>=0.15*
- cmake>=3.26*
48 changes: 48 additions & 0 deletions numba_dpex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
if(IS_INSTALL)
install(DIRECTORY core
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()

add_subdirectory(core/runtime)

if(IS_INSTALL)
install(DIRECTORY dpctl_iface
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()

if(IS_INSTALL)
install(DIRECTORY dpnp_iface
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()

if(IS_INSTALL)
install(DIRECTORY examples
DESTINATION numba_dpex)
endif()

if(IS_INSTALL)
install(DIRECTORY numba_patches
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()

if(IS_INSTALL)
install(DIRECTORY ocl
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()

if(IS_INSTALL)
install(DIRECTORY tests
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()

if(IS_INSTALL)
install(DIRECTORY utils
DESTINATION numba_dpex
FILES_MATCHING PATTERN "*.py")
endif()
124 changes: 124 additions & 0 deletions numba_dpex/core/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#[=======================================================================[.rst:
_dpexrt_python
---------------

A cmake file to compile the ``_dpexrt_python`` Python C extension for
``numba_dpex``. You can build this component locally in-place by invoking these
commands:

.. code-block:: cmake
~$ cmake .
~$ cmake --build . --verbose

Once compiled, the _dpexrt_python library will be in ``numba_dpex/core/runtime``
folder.
#]=======================================================================]

cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()

project(_dpexrt_python
DESCRIPTION "A Python C extension for numba-dpex runtime."
)

# Get numba include path
if(NOT DEFINED Numba_INCLUDE_DIRS)
execute_process(
COMMAND python -c "import numba; print(numba.extending.include_path());"
OUTPUT_VARIABLE Numba_INCLUDE_DIRS
RESULT_VARIABLE RET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(RET EQUAL "1")
message(FATAL_ERROR "Module \'numba\' not found.")
endif()
endif()

# Get dpctl library path
if(NOT DEFINED DPCTL_LIBRARY_PATH)
execute_process(
COMMAND python -c "import dpctl; import os; print(os.path.dirname(dpctl.__file__));"
OUTPUT_VARIABLE DPCTL_LIBRARY_PATH
RESULT_VARIABLE RET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(RET EQUAL "1")
message(FATAL_ERROR "Module \'dpctl\' not found.")
endif()
endif()

# Update CMAKE_MODULE_PATH
set(DPCTL_MODULE_PATH ${DPCTL_LIBRARY_PATH}/resources/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_MODULE_PATH})

# Get scikit-build path
if(NOT DEFINED SKBUILD_PATH)
execute_process(
COMMAND python -c "import skbuild; print(skbuild.__path__[0]);"
OUTPUT_VARIABLE SKBUILD_PATH
RESULT_VARIABLE RET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(RET EQUAL "1")
message(FATAL_ERROR "Module \'skbuild\' not found.")
endif()
endif()

# Update CMAKE_MODULE_PATH
set(SKBUILD_MODULE_PATH ${SKBUILD_PATH}/resources/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SKBUILD_MODULE_PATH})

# Check CMAKE_MODULE_PATH
message(STATUS "CMAKE_MODULE_PATH=" "${CMAKE_MODULE_PATH}")

# Add packages
find_package(PythonLibs REQUIRED)
find_package(PythonExtensions REQUIRED)
find_package(NumPy REQUIRED)
find_package(Dpctl REQUIRED)

# Includes
include(GNUInstallDirs)
include_directories(${Python_INCLUDE_DIRS})
include_directories(${NumPy_INCLUDE_DIRS})
include_directories(${Numba_INCLUDE_DIRS})
include_directories(${Dpctl_INCLUDE_DIRS})
include_directories(.)

# Source files, *.c
file(GLOB SOURCES "*.c")

# Link dpctl library path with -L
link_directories(${DPCTL_LIBRARY_PATH})

# Output static library, *.so or *.dll
add_library(${PROJECT_NAME} MODULE ${SOURCES})

# Link the static library to python libraries and DPCTLSyclInterface
target_link_libraries(${PROJECT_NAME} ${Python_LIBRARIES})
target_link_libraries(${PROJECT_NAME} DPCTLSyclInterface)

# Build python extension module
python_extension_module(${PROJECT_NAME})

# If IS_DEVELOP, copy back the target into numba_dpex/core/runtime
if(IS_DEVELOP)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/numba_dpex/core/runtime/*.so
${CMAKE_SOURCE_DIR}/numba_dpex/core/runtime/
)
endif()

# Install
install(
TARGETS ${PROJECT_NAME} LIBRARY DESTINATION numba_dpex/core/runtime
)
5 changes: 5 additions & 0 deletions numba_dpex/tests/core/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

from . import *
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ VCS = "git"
style = "pep440"
versionfile_source = "numba_dpex/_version.py"
parentdir_prefix = ""

[build-system]
requires = [
"setuptools>=42",
"scikit-build>=0.13",
"cmake>=3.18",
"ninja",
"numba>=0.57",
"versioneer-518"
]
build-backend = "setuptools.build_meta"
Loading