Skip to content

Commit 65d74fd

Browse files
Use scikit-build to build cython/usm_memory
1 parent aee0a79 commit 65d74fd

File tree

3 files changed

+58
-61
lines changed

3 files changed

+58
-61
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
cmake_minimum_required(VERSION 3.22...3.27 FATAL_ERROR)
2+
3+
project(example_cython_blackscholes_usm VERSION 0.1 LANGUAGES CXX
4+
DESCRIPTION "Example of Cython extension calling SYCL routines")
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+
# -t is to only Cythonize sources with timestamps newer than existing CXX files (if present)
22+
# -w is to set working directory (and correctly set __pyx_f[] array of filenames)
23+
set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"")
24+
find_package(Cython REQUIRED)
25+
26+
find_package(TBB REQUIRED)
27+
28+
set(MKL_ARCH "intel64")
29+
set(MKL_LINK "dynamic")
30+
set(MKL_THREADING "tbb_thread")
31+
set(MKL_INTERFACE "ilp64")
32+
find_package(MKL REQUIRED)
33+
34+
set(py_module_name _blackscholes_usm)
35+
36+
set(_cy_source blackscholes/_blackscholes_usm.pyx)
37+
add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src)
38+
Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src})
39+
add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src})
40+
target_compile_definitions(${py_module_name} PRIVATE -DMKL_ILP64)
41+
target_include_directories(${py_module_name} PUBLIC src ${Dpctl_INCLUDE_DIRS})
42+
target_link_libraries(${py_module_name} PRIVATE MKL::MKL_SYCL Python::NumPy)
43+
44+
install(TARGETS ${py_module_name} DESTINATION blackscholes)
45+
46+
foreach(_src_fn ${_sources})
47+
get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS)
48+
set(_combined_options ${_compile_options} "-O3")
49+
set_source_files_properties(${_src_fn}
50+
PROPERTIES
51+
COMPILE_OPTIONS "${_combined_options}"
52+
)
53+
endforeach()
54+
target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
55+
56+
set(ignoreMe "${SKBUILD}")

examples/cython/usm_memory/setup.py

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

17-
import os.path
18-
import sysconfig
19-
20-
import numpy as np
21-
from setuptools import Extension, setup
22-
from setuptools.command.build_ext import build_ext
23-
24-
import dpctl
25-
26-
27-
class custom_build_ext(build_ext):
28-
def build_extensions(self):
29-
self.compiler.set_executable("compiler_so", "icpx -fsycl -fPIC")
30-
self.compiler.set_executable("compiler_cxx", "icpx -fsycl -fPIC")
31-
self.compiler.set_executable(
32-
"linker_so",
33-
"icpx -fsycl -shared -fpic -fsycl-device-code-split=per_kernel",
34-
)
35-
build_ext.build_extensions(self)
36-
37-
38-
ext_modules = [
39-
Extension(
40-
name="blackscholes._blackscholes_usm",
41-
sources=[
42-
"blackscholes/blackscholes.pyx",
43-
],
44-
depends=[
45-
"src/sycl_black_scholes.hpp",
46-
],
47-
include_dirs=[
48-
"./src",
49-
np.get_include(),
50-
dpctl.get_include(),
51-
os.path.join(sysconfig.get_paths()["include"], ".."),
52-
],
53-
library_dirs=[
54-
os.path.join(sysconfig.get_paths()["stdlib"], ".."),
55-
],
56-
libraries=["sycl"]
57-
+ [
58-
"mkl_sycl",
59-
"mkl_intel_ilp64",
60-
"mkl_tbb_thread",
61-
"mkl_core",
62-
"tbb",
63-
],
64-
runtime_library_dirs=[],
65-
extra_compile_args=[
66-
"-Wall",
67-
"-Wextra",
68-
"-fsycl",
69-
"-fno-fast-math",
70-
],
71-
extra_link_args=["-fPIC"],
72-
language="c++",
73-
)
74-
]
75-
17+
from skbuild import setup
7618

7719
setup(
7820
name="blackscholes_usm",
@@ -86,6 +28,5 @@ def build_extensions(self):
8628
license="Apache 2.0",
8729
author="Intel Corporation",
8830
url="https://github.com/IntelPython/dpctl",
89-
ext_modules=ext_modules,
90-
cmdclass={"build_ext": custom_build_ext},
31+
packages=["blackscholes"],
9132
)

0 commit comments

Comments
 (0)