Skip to content

Commit 2a59532

Browse files
Use skbuild to build cython/sycl_buffer example
1 parent 65d74fd commit 2a59532

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.22...3.27 FATAL_ERROR)
2+
3+
project(example_cython_syclbuffer VERSION 0.1 LANGUAGES CXX
4+
DESCRIPTION "Example of Cython extension to work on host allocated NumPy array using SYCL buffers and SYCL functions.")
5+
set(DPCTL_CMAKE_MODULES_PATH "${CMAKE_SOURCE_DIR}/../../../cmake")
6+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_CMAKE_MODULES_PATH})
7+
8+
find_package(IntelSYCL REQUIRED PATHS ${DPCTL_CMAKE_MODULES_PATH} NO_DEFAULT_PATH)
9+
10+
11+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
12+
set(CMAKE_CXX_STANDARD 17)
13+
set(CMAKE_CXX_STANDARD_REQUIRED True)
14+
15+
# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR
16+
include(GNUInstallDirs)
17+
18+
find_package(Python REQUIRED COMPONENTS Development.Module NumPy)
19+
find_package(Dpctl REQUIRED)
20+
21+
# -w is to set working directory (and correctly set __pyx_f[] array of filenames)
22+
set(CYTHON_FLAGS "-w \"${CMAKE_SOURCE_DIR}\" --module-name _syclbuffer")
23+
find_package(Cython REQUIRED)
24+
25+
set(py_module_name _syclbuffer)
26+
27+
set(_cy_source syclbuffer/_buffer_example.pyx)
28+
add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src)
29+
Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src})
30+
add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src})
31+
target_include_directories(${py_module_name} PUBLIC src ${Dpctl_INCLUDE_DIRS})
32+
target_link_libraries(${py_module_name} PRIVATE Python::NumPy)
33+
34+
install(TARGETS ${py_module_name} DESTINATION syclbuffer)
35+
36+
foreach(_src_fn ${_sources})
37+
get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS)
38+
set(_combined_options ${_compile_options} "-O3")
39+
set_source_files_properties(${_src_fn}
40+
PROPERTIES
41+
COMPILE_OPTIONS "${_combined_options}"
42+
)
43+
endforeach()
44+
target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
45+
46+
set(ignoreMe "${SKBUILD}")

examples/cython/sycl_buffer/setup.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from setuptools import Extension, setup
18-
from setuptools.command.build_ext import build_ext
19-
20-
import dpctl
21-
22-
23-
class custom_build_ext(build_ext):
24-
def build_extensions(self):
25-
self.compiler.set_executable("compiler_so", "icpx -fsycl -fPIC")
26-
self.compiler.set_executable("compiler_cxx", "icpx -fsycl -fPIC")
27-
self.compiler.set_executable(
28-
"linker_so",
29-
"icpx -fsycl -shared -fpic -fsycl-device-code-split=per_kernel",
30-
)
31-
build_ext.build_extensions(self)
32-
33-
34-
ext_modules = [
35-
Extension(
36-
name="syclbuffer._syclbuffer",
37-
sources=[
38-
"syclbuffer/_buffer_example.pyx",
39-
],
40-
depends=[
41-
"src/use_sycl_buffer.hpp",
42-
],
43-
include_dirs=[
44-
".",
45-
"./src",
46-
dpctl.get_include(),
47-
],
48-
extra_compile_args=[
49-
"-Wall",
50-
"-Wextra",
51-
"-fsycl",
52-
],
53-
extra_link_args=["-fPIC"],
54-
language="c++",
55-
)
56-
]
17+
from skbuild import setup
5718

5819
setup(
5920
name="syclbuffer",
@@ -68,6 +29,5 @@ def build_extensions(self):
6829
license="Apache 2.0",
6930
author="Intel Corporation",
7031
url="https://github.com/IntelPython/dpctl",
71-
ext_modules=ext_modules,
72-
cmdclass={"build_ext": custom_build_ext},
32+
packages=["syclbuffer"],
7333
)

0 commit comments

Comments
 (0)