Skip to content

Commit 3f60607

Browse files
Change use_dpctl_sycl to use skbuild
1 parent 2a59532 commit 3f60607

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
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_use_dpctl_sycl VERSION 0.1 LANGUAGES CXX
4+
DESCRIPTION "Example of Cython extension to use Cython API to SYCL objects.")
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 "-t -w \"${CMAKE_SOURCE_DIR}\"")
23+
find_package(Cython REQUIRED)
24+
25+
set(py_module_name _cython_api)
26+
27+
set(_cy_source use_dpctl_sycl/_cython_api.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 include ${Dpctl_INCLUDE_DIRS})
32+
target_link_libraries(${py_module_name} PRIVATE Python::NumPy)
33+
34+
install(TARGETS ${py_module_name} DESTINATION use_dpctl_sycl)
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/use_dpctl_sycl/setup.py

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

17-
import Cython.Build
18-
import setuptools
19-
from setuptools.command.build_ext import build_ext as build_ext_base
17+
from skbuild import setup
2018

21-
import dpctl
22-
23-
24-
class custom_build_ext(build_ext_base):
25-
def build_extensions(self):
26-
self.compiler.set_executable("compiler_so", "icx -fsycl -fPIC")
27-
self.compiler.set_executable("compiler_cxx", "icpx -fsycl -fPIC")
28-
self.compiler.set_executable(
29-
"linker_so",
30-
"icpx -fsycl -shared -fpic -fsycl-device-code-split=per_kernel",
31-
)
32-
super().build_extensions()
33-
34-
35-
ext = setuptools.Extension(
36-
"use_dpctl_sycl._cython_api",
37-
["./use_dpctl_sycl/_cython_api.pyx"],
38-
include_dirs=[dpctl.get_include(), "./use_dpctl_sycl"],
39-
language="c++",
40-
)
41-
42-
(cythonized_ext,) = Cython.Build.cythonize(
43-
[
44-
ext,
45-
]
46-
)
47-
48-
setuptools.setup(
19+
setup(
4920
name="use_dpctl_sycl",
5021
version="0.0.0",
51-
ext_modules=[cythonized_ext],
52-
cmdclass={"build_ext": custom_build_ext},
22+
description="An example of Cython extension calling SYCL Cython API",
23+
long_description="""
24+
Example of using SYCL to work on host allocated NumPy array using
25+
SYCL buffers and SYCL functions.
26+
27+
See README.md for more details.
28+
""",
29+
license="Apache 2.0",
30+
author="Intel Corporation",
31+
url="https://github.com/IntelPython/dpctl",
32+
packages=["use_dpctl_sycl"],
5333
)

0 commit comments

Comments
 (0)