Skip to content

Commit 5e56e8e

Browse files
Changed building to use scikit-build and cmake to build dpctl
The change to _dlpack was to fix incorrect path to includes (relative to current dir).
1 parent a2b6a9c commit 5e56e8e

File tree

12 files changed

+164
-468
lines changed

12 files changed

+164
-468
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __pycache__/
1313

1414
# CMake build and local install directory
1515
build
16+
_skbuild
1617
build_cmake
1718
install
1819

CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
2+
3+
project(dpctl
4+
LANGUAGES CXX
5+
DESCRIPTION "Python interface for XPU programming"
6+
)
7+
8+
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD_REQUIRED True)
10+
11+
find_package(IntelDPCPP REQUIRED)
12+
13+
add_subdirectory(libsyclinterface)
14+
15+
file(GLOB _dpctl_capi_headers dpctl/apis/include/*.h*)
16+
install(FILES ${_dpctl_capi_headers}
17+
DESTINATION dpctl/include
18+
COMPONENT DpctlCAPIHeaders
19+
)
20+
21+
add_subdirectory(dpctl)
22+
23+
if (DPCTL_GENERATE_DOCS)
24+
add_subdirectory(docs)
25+
endif()

dpctl/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
find_package(PythonExtensions REQUIRED)
3+
find_package(NumPy REQUIRED)
4+
find_package(Cython REQUIRED)
5+
6+
# at build time create include/ directory and copy header files over
7+
set(DPCTL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
8+
add_custom_target(_build_time_create_dpctl_include ALL
9+
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}
10+
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface
11+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/libsyclinterface/include/* ${DPCTL_INCLUDE_DIR}/syclinterface
12+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/* ${DPCTL_INCLUDE_DIR}
13+
DEPENDS DPCTLSyclInterface
14+
)
15+
16+
set(CMAKE_INSTALL_RPATH "$ORIGIN")
17+
18+
function(build_dpctl_ext _trgt _src _dest)
19+
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
20+
add_library(${_trgt} MODULE ${_generated_src})
21+
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR})
22+
add_dependencies(${_trgt} _build_time_create_dpctl_include)
23+
target_link_libraries(${_trgt} DPCTLSyclInterface)
24+
python_extension_module(${_trgt})
25+
get_filename_component(_name_wle ${_generated_src} NAME_WLE)
26+
get_filename_component(_generated_src_dir ${_generated_src} DIRECTORY)
27+
set(_generated_public_h "${_generated_src_dir}/${_name_wle}.h")
28+
set(_generated_api_h "${_generated_src_dir}/${_name_wle}_api.h")
29+
set(_copy_trgt "${_trgt}_copy_capi_include")
30+
add_custom_target(
31+
${_copy_trgt} ALL
32+
COMMAND ${CMAKE_COMMAND}
33+
-DSOURCE_FILE=${_generated_public_h}
34+
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
35+
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_generated_headers.cmake
36+
COMMAND ${CMAKE_COMMAND}
37+
-DSOURCE_FILE=${_generated_api_h}
38+
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
39+
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_generated_headers.cmake
40+
DEPENDS ${_trgt}
41+
VERBATIM
42+
COMMENT "Copying Cython-generated headers to destination"
43+
)
44+
install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest})
45+
endfunction()
46+
47+
file(GLOB _cython_sources *.pyx)
48+
foreach(_cy_file ${_cython_sources})
49+
get_filename_component(_trgt ${_cy_file} NAME_WLE)
50+
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl")
51+
endforeach()
52+
53+
add_subdirectory(program)
54+
add_subdirectory(memory)
55+
add_subdirectory(tensor)
56+
add_subdirectory(utils)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (EXISTS ${SOURCE_FILE})
2+
configure_file(${SOURCE_FILE} ${DEST} COPYONLY)
3+
endif()

dpctl/memory/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
file(GLOB _cython_sources *.pyx)
3+
foreach(_cy_file ${_cython_sources})
4+
get_filename_component(_trgt ${_cy_file} NAME_WLE)
5+
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/memory")
6+
endforeach()

dpctl/program/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
file(GLOB _cython_sources *.pyx)
3+
foreach(_cy_file ${_cython_sources})
4+
get_filename_component(_trgt ${_cy_file} NAME_WLE)
5+
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/program")
6+
endforeach()

dpctl/tensor/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
file(GLOB _cython_sources *.pyx)
2+
foreach(_cy_file ${_cython_sources})
3+
get_filename_component(_trgt ${_cy_file} NAME_WLE)
4+
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/tensor")
5+
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
6+
endforeach()

dpctl/tensor/_dlpack.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from ._usmarray cimport usm_ndarray
2222

2323

24-
cdef extern from './include/dlpack/dlpack.h' nogil:
24+
cdef extern from 'dlpack/dlpack.h' nogil:
2525
int device_CPU 'kDLCPU'
2626
int device_oneAPI 'kDLOneAPI'
2727
int device_OpenCL 'kDLOpenCL'

dpctl/tensor/_dlpack.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import dpctl
3939
import dpctl.memory as dpmem
4040

4141

42-
cdef extern from './include/dlpack/dlpack.h' nogil:
42+
cdef extern from 'dlpack/dlpack.h' nogil:
4343
cdef int DLPACK_VERSION
4444

4545
cdef enum DLDeviceType:

dpctl/utils/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
file(GLOB _cython_sources *.pyx)
3+
foreach(_cy_file ${_cython_sources})
4+
get_filename_component(_trgt ${_cy_file} NAME_WLE)
5+
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/utils")
6+
endforeach()

0 commit comments

Comments
 (0)