Skip to content

Commit 8c15f5a

Browse files
author
Diptorup Deb
authored
Merge pull request #1107 from chudur-budur/refac/new-setup-skbuild
scikit-build setup.py for numba-dpex
2 parents 2f006b9 + 511c2bc commit 8c15f5a

File tree

10 files changed

+296
-64
lines changed

10 files changed

+296
-64
lines changed

CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#[=======================================================================[.rst:
2+
numba_dpex
3+
-----------
4+
5+
A cmake file to compile the ``_dpexrt_python`` Python C extension for
6+
``numba_dpex``. You can build this component locally in-place by invoking these
7+
commands:
8+
9+
.. code-block:: cmake
10+
~$ cmake .
11+
~$ cmake --build . --verbose
12+
13+
Once compiled, the _dpexrt_python library will be in ``numba_dpex/core/runtime``
14+
folder.
15+
16+
This ``CMakeLists.txt`` file will be used by ``setup.py``.
17+
#]=======================================================================]
18+
19+
cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)
20+
21+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
22+
cmake_policy(SET CMP0135 NEW)
23+
endif()
24+
25+
message(STATUS "NUMBA_DPEX_VERSION=" "${NUMBA_DPEX_VERSION}")
26+
27+
project(numba-dpex
28+
DESCRIPTION "An extension for Numba to add data-parallel offload capability"
29+
VERSION ${NUMBA_DPEX_VERSION}
30+
)
31+
32+
if(IS_INSTALL)
33+
install(DIRECTORY numba_dpex
34+
DESTINATION ${CMAKE_INSTALL_PREFIX}
35+
FILES_MATCHING PATTERN "*.py")
36+
endif()
37+
38+
add_subdirectory(numba_dpex)

MANIFEST.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
include MANIFEST.in
22
include README.md setup.py LICENSE
33

4-
recursive-include numba_dpex *.cl
5-
recursive-include numba_dpex *.spir
6-
74
include versioneer.py
85
include numba_dpex/_version.py
96

conda-recipe/meta.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ requirements:
1717
host:
1818
- python
1919
- setuptools >=63.*
20-
- numba 0.57*
20+
- scikit-build >=0.15*
21+
- cmake >=3.26*
22+
- numba >=0.57*
2123
- dpctl >=0.14*
2224
- dpnp >=0.11*
2325
- dpcpp-llvm-spirv

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies:
1616
- mkl >=2021.3.0 # for dpnp
1717
- dpcpp-llvm-spirv
1818
- packaging
19+
- scikit-build >=0.15*
20+
- cmake >=3.26*
1921
- pytest
2022
- pip
2123
- pip:

environment/coverage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ dependencies:
2020
- pytest-cov
2121
- pytest-xdist
2222
- pexpect
23+
- scikit-build>=0.15*
24+
- cmake>=3.26*

numba_dpex/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
if(IS_INSTALL)
2+
install(DIRECTORY core
3+
DESTINATION numba_dpex
4+
FILES_MATCHING PATTERN "*.py")
5+
endif()
6+
7+
add_subdirectory(core/runtime)
8+
9+
if(IS_INSTALL)
10+
install(DIRECTORY dpctl_iface
11+
DESTINATION numba_dpex
12+
FILES_MATCHING PATTERN "*.py")
13+
endif()
14+
15+
if(IS_INSTALL)
16+
install(DIRECTORY dpnp_iface
17+
DESTINATION numba_dpex
18+
FILES_MATCHING PATTERN "*.py")
19+
endif()
20+
21+
if(IS_INSTALL)
22+
install(DIRECTORY examples
23+
DESTINATION numba_dpex)
24+
endif()
25+
26+
if(IS_INSTALL)
27+
install(DIRECTORY numba_patches
28+
DESTINATION numba_dpex
29+
FILES_MATCHING PATTERN "*.py")
30+
endif()
31+
32+
if(IS_INSTALL)
33+
install(DIRECTORY ocl
34+
DESTINATION numba_dpex
35+
FILES_MATCHING PATTERN "*.py")
36+
endif()
37+
38+
if(IS_INSTALL)
39+
install(DIRECTORY tests
40+
DESTINATION numba_dpex
41+
FILES_MATCHING PATTERN "*.py")
42+
endif()
43+
44+
if(IS_INSTALL)
45+
install(DIRECTORY utils
46+
DESTINATION numba_dpex
47+
FILES_MATCHING PATTERN "*.py")
48+
endif()
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#[=======================================================================[.rst:
2+
_dpexrt_python
3+
---------------
4+
5+
A cmake file to compile the ``_dpexrt_python`` Python C extension for
6+
``numba_dpex``. You can build this component locally in-place by invoking these
7+
commands:
8+
9+
.. code-block:: cmake
10+
~$ cmake .
11+
~$ cmake --build . --verbose
12+
13+
Once compiled, the _dpexrt_python library will be in ``numba_dpex/core/runtime``
14+
folder.
15+
#]=======================================================================]
16+
17+
cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)
18+
19+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
20+
cmake_policy(SET CMP0135 NEW)
21+
endif()
22+
23+
project(_dpexrt_python
24+
DESCRIPTION "A Python C extension for numba-dpex runtime."
25+
)
26+
27+
# Get numba include path
28+
if(NOT DEFINED Numba_INCLUDE_DIRS)
29+
execute_process(
30+
COMMAND python -c "import numba; print(numba.extending.include_path());"
31+
OUTPUT_VARIABLE Numba_INCLUDE_DIRS
32+
RESULT_VARIABLE RET
33+
OUTPUT_STRIP_TRAILING_WHITESPACE
34+
)
35+
36+
if(RET EQUAL "1")
37+
message(FATAL_ERROR "Module \'numba\' not found.")
38+
endif()
39+
endif()
40+
41+
# Get dpctl library path
42+
if(NOT DEFINED DPCTL_LIBRARY_PATH)
43+
execute_process(
44+
COMMAND python -c "import dpctl; import os; print(os.path.dirname(dpctl.__file__));"
45+
OUTPUT_VARIABLE DPCTL_LIBRARY_PATH
46+
RESULT_VARIABLE RET
47+
OUTPUT_STRIP_TRAILING_WHITESPACE
48+
)
49+
50+
if(RET EQUAL "1")
51+
message(FATAL_ERROR "Module \'dpctl\' not found.")
52+
endif()
53+
endif()
54+
55+
# Update CMAKE_MODULE_PATH
56+
set(DPCTL_MODULE_PATH ${DPCTL_LIBRARY_PATH}/resources/cmake)
57+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_MODULE_PATH})
58+
59+
# Get scikit-build path
60+
if(NOT DEFINED SKBUILD_PATH)
61+
execute_process(
62+
COMMAND python -c "import skbuild; print(skbuild.__path__[0]);"
63+
OUTPUT_VARIABLE SKBUILD_PATH
64+
RESULT_VARIABLE RET
65+
OUTPUT_STRIP_TRAILING_WHITESPACE
66+
)
67+
68+
if(RET EQUAL "1")
69+
message(FATAL_ERROR "Module \'skbuild\' not found.")
70+
endif()
71+
endif()
72+
73+
# Update CMAKE_MODULE_PATH
74+
set(SKBUILD_MODULE_PATH ${SKBUILD_PATH}/resources/cmake)
75+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SKBUILD_MODULE_PATH})
76+
77+
# Check CMAKE_MODULE_PATH
78+
message(STATUS "CMAKE_MODULE_PATH=" "${CMAKE_MODULE_PATH}")
79+
80+
# Add packages
81+
find_package(PythonLibs REQUIRED)
82+
find_package(PythonExtensions REQUIRED)
83+
find_package(NumPy REQUIRED)
84+
find_package(Dpctl REQUIRED)
85+
86+
# Includes
87+
include(GNUInstallDirs)
88+
include_directories(${Python_INCLUDE_DIRS})
89+
include_directories(${NumPy_INCLUDE_DIRS})
90+
include_directories(${Numba_INCLUDE_DIRS})
91+
include_directories(${Dpctl_INCLUDE_DIRS})
92+
include_directories(.)
93+
94+
# Source files, *.c
95+
file(GLOB SOURCES "*.c")
96+
97+
# Link dpctl library path with -L
98+
link_directories(${DPCTL_LIBRARY_PATH})
99+
100+
# Output static library, *.so or *.dll
101+
add_library(${PROJECT_NAME} MODULE ${SOURCES})
102+
103+
# Link the static library to python libraries and DPCTLSyclInterface
104+
target_link_libraries(${PROJECT_NAME} ${Python_LIBRARIES})
105+
target_link_libraries(${PROJECT_NAME} DPCTLSyclInterface)
106+
107+
# Build python extension module
108+
python_extension_module(${PROJECT_NAME})
109+
110+
# If IS_DEVELOP, copy back the target into numba_dpex/core/runtime
111+
if(IS_DEVELOP)
112+
add_custom_command(
113+
TARGET ${PROJECT_NAME}
114+
POST_BUILD
115+
COMMAND ${CMAKE_COMMAND} -E copy
116+
${CMAKE_BINARY_DIR}/numba_dpex/core/runtime/*.so
117+
${CMAKE_SOURCE_DIR}/numba_dpex/core/runtime/
118+
)
119+
endif()
120+
121+
# Install
122+
install(
123+
TARGETS ${PROJECT_NAME} LIBRARY DESTINATION numba_dpex/core/runtime
124+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
from . import *

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ VCS = "git"
4444
style = "pep440"
4545
versionfile_source = "numba_dpex/_version.py"
4646
parentdir_prefix = ""
47+
48+
[build-system]
49+
requires = [
50+
"setuptools>=42",
51+
"scikit-build>=0.13",
52+
"cmake>=3.18",
53+
"ninja",
54+
"numba>=0.57",
55+
"versioneer-518"
56+
]
57+
build-backend = "setuptools.build_meta"

0 commit comments

Comments
 (0)