From 6783afb40d2f19e34157f02ea5fd104ad698aca2 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sat, 28 Feb 2026 01:26:36 -0800 Subject: [PATCH 01/14] move to scikit-build-core from scikit-build required vendoring Cython-finding modules from scikit-build --- .gitignore | 4 +- CMakeLists.txt | 2 +- cmake/FindCython.cmake | 88 +++ cmake/README.md | 5 + cmake/UseCython.cmake | 383 ++++++++++ conda-recipe/meta.yaml | 2 - docs/CMakeLists.txt | 2 +- dpctl/CMakeLists.txt | 8 +- dpctl/__init__.py | 8 +- dpctl/_version.py | 683 ------------------ libsyclinterface/CMakeLists.txt | 8 +- .../cmake/modules/GetLevelZeroHeaders.cmake | 14 +- pyproject.toml | 32 +- setup.py | 54 -- 14 files changed, 519 insertions(+), 774 deletions(-) create mode 100755 cmake/FindCython.cmake create mode 100644 cmake/README.md create mode 100755 cmake/UseCython.cmake delete mode 100644 dpctl/_version.py delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index f8d185c7a9..7d9138fa76 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ __pycache__/ # CMake build and local install directory build -_skbuild build_cmake install @@ -104,3 +103,6 @@ dpctl/resources/cmake # asv artifacts *.asv* + +# generated _version.py +dpctl/_version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f84348251..79593b853e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,7 @@ target_link_libraries(DpctlCAPI INTERFACE DPCTLSyclInterfaceHeaders) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include + DESTINATION dpctl/include FILES_MATCHING REGEX "\\.h(pp)?$" ) diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake new file mode 100755 index 0000000000..c8de131125 --- /dev/null +++ b/cmake/FindCython.cmake @@ -0,0 +1,88 @@ +#.rst: +# +# Find ``cython`` executable. +# +# This module will set the following variables in your project: +# +# ``CYTHON_EXECUTABLE`` +# path to the ``cython`` program +# +# ``CYTHON_VERSION`` +# version of ``cython`` +# +# ``CYTHON_FOUND`` +# true if the program was found +# +# For more information on the Cython project, see https://cython.org/. +# +# *Cython is a language that makes writing C extensions for the Python language +# as easy as Python itself.* +# +#============================================================================= +# Copyright 2011 Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +# Use the Cython executable that lives next to the Python executable +# if it is a local installation. +if(Python_EXECUTABLE) + get_filename_component(_python_path ${Python_EXECUTABLE} PATH) +elseif(Python3_EXECUTABLE) + get_filename_component(_python_path ${Python3_EXECUTABLE} PATH) +elseif(DEFINED PYTHON_EXECUTABLE) + get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH) +endif() + +if(DEFINED _python_path) + find_program(CYTHON_EXECUTABLE + NAMES cython cython.bat cython3 + HINTS ${_python_path} + DOC "path to the cython executable") +else() + find_program(CYTHON_EXECUTABLE + NAMES cython cython.bat cython3 + DOC "path to the cython executable") +endif() + +if(CYTHON_EXECUTABLE) + set(CYTHON_version_command ${CYTHON_EXECUTABLE} --version) + + execute_process(COMMAND ${CYTHON_version_command} + OUTPUT_VARIABLE CYTHON_version_output + ERROR_VARIABLE CYTHON_version_error + RESULT_VARIABLE CYTHON_version_result + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + + if(NOT ${CYTHON_version_result} EQUAL 0) + set(_error_msg "Command \"${CYTHON_version_command}\" failed with") + set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}") + message(SEND_ERROR "${_error_msg}") + else() + if("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)") + set(CYTHON_VERSION "${CMAKE_MATCH_1}") + else() + if("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)") + set(CYTHON_VERSION "${CMAKE_MATCH_1}") + endif() + endif() + endif() +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE) + +mark_as_advanced(CYTHON_EXECUTABLE) + +include(UseCython) diff --git a/cmake/README.md b/cmake/README.md new file mode 100644 index 0000000000..aac698b18e --- /dev/null +++ b/cmake/README.md @@ -0,0 +1,5 @@ +## Vendored files + +Files `FindCython.cmake` and `UseCython.cmake` were vendored from [`scikit-build`](https://github.com/scikit-build/scikit-build/tree/main/skbuild/resources/cmake) to support migration to `scikit-build-core`, which no longer includes these modules automatically + +Files are copyright 2011 Kitware, Inc. and licensed under the Apache License, Version 2.0. diff --git a/cmake/UseCython.cmake b/cmake/UseCython.cmake new file mode 100755 index 0000000000..4e0fa7907d --- /dev/null +++ b/cmake/UseCython.cmake @@ -0,0 +1,383 @@ +#.rst: +# +# The following functions are defined: +# +# .. cmake:command:: add_cython_target +# +# Create a custom rule to generate the source code for a Python extension module +# using cython. +# +# add_cython_target( [] +# [EMBED_MAIN] +# [C | CXX] +# [PY2 | PY3] +# [OUTPUT_VAR ]) +# +# ```` is the name of the new target, and ```` +# is the path to a cython source file. Note that, despite the name, no new +# targets are created by this function. Instead, see ``OUTPUT_VAR`` for +# retrieving the path to the generated source for subsequent targets. +# +# If only ```` is provided, and it ends in the ".pyx" extension, then it +# is assumed to be the ````. The name of the input without the +# extension is used as the target name. If only ```` is provided, and it +# does not end in the ".pyx" extension, then the ```` is assumed to +# be ``.pyx``. +# +# The Cython include search path is amended with any entries found in the +# ``INCLUDE_DIRECTORIES`` property of the directory containing the +# ```` file. Use ``include_directories`` to add to the Cython +# include search path. +# +# Options: +# +# ``EMBED_MAIN`` +# Embed a main() function in the generated output (for stand-alone +# applications that initialize their own Python runtime). +# +# ``C | CXX`` +# Force the generation of either a C or C++ file. By default, a C file is +# generated, unless the C language is not enabled for the project; in this +# case, a C++ file is generated by default. +# +# ``PY2 | PY3`` +# Force compilation using either Python-2 or Python-3 syntax and code +# semantics. By default, Python-2 syntax and semantics are used if the major +# version of Python found is 2. Otherwise, Python-3 syntax and semantics are +# used. +# +# ``OUTPUT_VAR `` +# Set the variable ```` in the parent scope to the path to the +# generated source file. By default, ```` is used as the output +# variable name. +# +# Defined variables: +# +# ```` +# The path of the generated source file. +# +# Cache variables that affect the behavior include: +# +# ``CYTHON_ANNOTATE`` +# Whether to create an annotated .html file when compiling. +# +# ``CYTHON_FLAGS`` +# Additional flags to pass to the Cython compiler. +# +# Example usage +# ^^^^^^^^^^^^^ +# +# .. code-block:: cmake +# +# find_package(Cython) +# +# # Note: In this case, either one of these arguments may be omitted; their +# # value would have been inferred from that of the other. +# add_cython_target(cy_code cy_code.pyx) +# +# add_library(cy_code MODULE ${cy_code}) +# target_link_libraries(cy_code ...) +# +#============================================================================= +# Copyright 2011 Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +# Configuration options. +set(CYTHON_ANNOTATE OFF + CACHE BOOL "Create an annotated .html file when compiling *.pyx.") + +set(CYTHON_FLAGS "" CACHE STRING + "Extra flags to the cython compiler.") +mark_as_advanced(CYTHON_ANNOTATE CYTHON_FLAGS) + +set(CYTHON_CXX_EXTENSION "cxx") +set(CYTHON_C_EXTENSION "c") + +get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) + +function(add_cython_target _name) + set(options EMBED_MAIN C CXX PY2 PY3) + set(options1 OUTPUT_VAR) + cmake_parse_arguments(_args "${options}" "${options1}" "" ${ARGN}) + + list(GET _args_UNPARSED_ARGUMENTS 0 _arg0) + + # if provided, use _arg0 as the input file path + if(_arg0) + set(_source_file ${_arg0}) + + # otherwise, must determine source file from name, or vice versa + else() + get_filename_component(_name_ext "${_name}" EXT) + + # if extension provided, _name is the source file + if(_name_ext) + set(_source_file ${_name}) + get_filename_component(_name "${_source_file}" NAME_WE) + + # otherwise, assume the source file is ${_name}.pyx + else() + set(_source_file ${_name}.pyx) + endif() + endif() + + set(_embed_main FALSE) + + if("C" IN_LIST languages) + set(_output_syntax "C") + elseif("CXX" IN_LIST languages) + set(_output_syntax "CXX") + else() + message(FATAL_ERROR "Either C or CXX must be enabled to use Cython") + endif() + + if(_args_EMBED_MAIN) + set(_embed_main TRUE) + endif() + + if(_args_C) + set(_output_syntax "C") + endif() + + if(_args_CXX) + set(_output_syntax "CXX") + endif() + + # Doesn't select an input syntax - Cython + # defaults to 2 for Cython 2 and 3 for Cython 3 + set(_input_syntax "default") + + if(_args_PY2) + set(_input_syntax "PY2") + endif() + + if(_args_PY3) + set(_input_syntax "PY3") + endif() + + set(embed_arg "") + if(_embed_main) + set(embed_arg "--embed") + endif() + + set(cxx_arg "") + set(extension "c") + if(_output_syntax STREQUAL "CXX") + set(cxx_arg "--cplus") + set(extension "cxx") + endif() + + set(py_version_arg "") + if(_input_syntax STREQUAL "PY2") + set(py_version_arg "-2") + elseif(_input_syntax STREQUAL "PY3") + set(py_version_arg "-3") + endif() + + set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${extension}") + set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) + + set(_output_var ${_name}) + if(_args_OUTPUT_VAR) + set(_output_var ${_args_OUTPUT_VAR}) + endif() + set(${_output_var} ${generated_file} PARENT_SCOPE) + + file(RELATIVE_PATH generated_file_relative + ${CMAKE_BINARY_DIR} ${generated_file}) + + set(comment "Generating ${_output_syntax} source ${generated_file_relative}") + set(cython_include_directories "") + set(pxd_dependencies "") + set(c_header_dependencies "") + + # Get the include directories. + get_directory_property(cmake_include_directories + DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + INCLUDE_DIRECTORIES) + list(APPEND cython_include_directories ${cmake_include_directories}) + + # Determine dependencies. + # Add the pxd file with the same basename as the given pyx file. + get_source_file_property(pyx_location ${_source_file} LOCATION) + get_filename_component(pyx_path ${pyx_location} PATH) + get_filename_component(pyx_file_basename ${_source_file} NAME_WE) + unset(corresponding_pxd_file CACHE) + find_file(corresponding_pxd_file ${pyx_file_basename}.pxd + PATHS "${pyx_path}" ${cmake_include_directories} + NO_DEFAULT_PATH) + if(corresponding_pxd_file) + list(APPEND pxd_dependencies "${corresponding_pxd_file}") + endif() + + # pxd files to check for additional dependencies + set(pxds_to_check "${_source_file}" "${pxd_dependencies}") + set(pxds_checked "") + set(number_pxds_to_check 1) + while(number_pxds_to_check GREATER 0) + foreach(pxd ${pxds_to_check}) + list(APPEND pxds_checked "${pxd}") + list(REMOVE_ITEM pxds_to_check "${pxd}") + + # look for C headers + file(STRINGS "${pxd}" extern_from_statements + REGEX "cdef[ ]+extern[ ]+from.*$") + foreach(statement ${extern_from_statements}) + # Had trouble getting the quote in the regex + string(REGEX REPLACE + "cdef[ ]+extern[ ]+from[ ]+[\"]([^\"]+)[\"].*" "\\1" + header "${statement}") + unset(header_location CACHE) + find_file(header_location ${header} PATHS ${cmake_include_directories}) + if(header_location) + list(FIND c_header_dependencies "${header_location}" header_idx) + if(${header_idx} LESS 0) + list(APPEND c_header_dependencies "${header_location}") + endif() + endif() + endforeach() + + # check for pxd dependencies + # Look for cimport statements. + set(module_dependencies "") + file(STRINGS "${pxd}" cimport_statements REGEX cimport) + foreach(statement ${cimport_statements}) + if(${statement} MATCHES from) + string(REGEX REPLACE + "from[ ]+([^ ]+).*" "\\1" + module "${statement}") + else() + string(REGEX REPLACE + "cimport[ ]+([^ ]+).*" "\\1" + module "${statement}") + endif() + list(APPEND module_dependencies ${module}) + endforeach() + + # check for pxi dependencies + # Look for include statements. + set(include_dependencies "") + file(STRINGS "${pxd}" include_statements REGEX include) + foreach(statement ${include_statements}) + string(REGEX REPLACE + "include[ ]+[\"]([^\"]+)[\"].*" "\\1" + module "${statement}") + list(APPEND include_dependencies ${module}) + endforeach() + + list(REMOVE_DUPLICATES module_dependencies) + list(REMOVE_DUPLICATES include_dependencies) + + # Add modules to the files to check, if appropriate. + foreach(module ${module_dependencies}) + unset(pxd_location CACHE) + find_file(pxd_location ${module}.pxd + PATHS "${pyx_path}" ${cmake_include_directories} + NO_DEFAULT_PATH) + if(pxd_location) + list(FIND pxds_checked ${pxd_location} pxd_idx) + if(${pxd_idx} LESS 0) + list(FIND pxds_to_check ${pxd_location} pxd_idx) + if(${pxd_idx} LESS 0) + list(APPEND pxds_to_check ${pxd_location}) + list(APPEND pxd_dependencies ${pxd_location}) + endif() # if it is not already going to be checked + endif() # if it has not already been checked + endif() # if pxd file can be found + endforeach() # for each module dependency discovered + + # Add includes to the files to check, if appropriate. + foreach(_include ${include_dependencies}) + unset(pxi_location CACHE) + find_file(pxi_location ${_include} + PATHS "${pyx_path}" ${cmake_include_directories} + NO_DEFAULT_PATH) + if(pxi_location) + list(FIND pxds_checked ${pxi_location} pxd_idx) + if(${pxd_idx} LESS 0) + list(FIND pxds_to_check ${pxi_location} pxd_idx) + if(${pxd_idx} LESS 0) + list(APPEND pxds_to_check ${pxi_location}) + list(APPEND pxd_dependencies ${pxi_location}) + endif() # if it is not already going to be checked + endif() # if it has not already been checked + endif() # if include file can be found + endforeach() # for each include dependency discovered + endforeach() # for each include file to check + + list(LENGTH pxds_to_check number_pxds_to_check) + endwhile() + + # Set additional flags. + set(annotate_arg "") + if(CYTHON_ANNOTATE) + set(annotate_arg "--annotate") + endif() + + set(cython_debug_arg "") + set(line_directives_arg "") + if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR + CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(cython_debug_arg "--gdb") + set(line_directives_arg "--line-directives") + endif() + + # Include directory arguments. + list(REMOVE_DUPLICATES cython_include_directories) + set(include_directory_arg "") + foreach(_include_dir ${cython_include_directories}) + set(include_directory_arg + ${include_directory_arg} "--include-dir" "${_include_dir}") + endforeach() + + list(REMOVE_DUPLICATES pxd_dependencies) + list(REMOVE_DUPLICATES c_header_dependencies) + + string(REGEX REPLACE " " ";" CYTHON_FLAGS_LIST "${CYTHON_FLAGS}") + + # Add the command to run the compiler. + add_custom_command(OUTPUT ${generated_file} + COMMAND ${CYTHON_EXECUTABLE} + ARGS ${cxx_arg} ${include_directory_arg} ${py_version_arg} + ${embed_arg} ${annotate_arg} ${cython_debug_arg} + ${line_directives_arg} ${CYTHON_FLAGS_LIST} ${pyx_location} + --output-file ${generated_file} + DEPENDS ${_source_file} + ${pxd_dependencies} + IMPLICIT_DEPENDS ${_output_syntax} + ${c_header_dependencies} + COMMENT ${comment}) + + # NOTE(opadron): I thought about making a proper target, but after trying it + # out, I decided that it would be far too convenient to use the same name as + # the target for the extension module (e.g.: for single-file modules): + # + # ... + # add_cython_target(_module.pyx) + # add_library(_module ${_module}) + # ... + # + # The above example would not be possible since the "_module" target name + # would already be taken by the cython target. Since I can't think of a + # reason why someone would need the custom target instead of just using the + # generated file directly, I decided to leave this commented out. + # + # add_custom_target(${_name} DEPENDS ${generated_file}) + + # Remove their visibility to the user. + set(corresponding_pxd_file "" CACHE INTERNAL "") + set(header_location "" CACHE INTERNAL "") + set(pxd_location "" CACHE INTERNAL "") +endfunction() diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 27af8f55a0..79918788d6 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -47,8 +47,6 @@ requirements: - {{ dep|replace('_','-') }} {% endif %} {% endfor %} - # versioneer dependency - - tomli # [py<311] run: - python - {{ pin_compatible('intel-sycl-rt', min_pin='x.x', max_pin='x') }} diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 0bd31e059c..e412978045 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -168,7 +168,7 @@ if (DPCTL_ENABLE_DOXYREST) endif() # Set the location where the generated docs are saved -set(DOC_OUTPUT_DIR ${CMAKE_INSTALL_PREFIX}/docs) +set(DOC_OUTPUT_DIR docs) # set(INDEX_NO_DOXYREST_IN ${CMAKE_CURRENT_SOURCE_DIR}/index_no_doxyrest.rst.in) # set(INDEX_DOXYREST_IN ${CMAKE_CURRENT_SOURCE_DIR}/index_doxyrest.rst.in) diff --git a/dpctl/CMakeLists.txt b/dpctl/CMakeLists.txt index a24c7443f9..138e70306d 100644 --- a/dpctl/CMakeLists.txt +++ b/dpctl/CMakeLists.txt @@ -1,5 +1,7 @@ find_package(Python REQUIRED COMPONENTS NumPy) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") + # -t is to only Cythonize sources with timestamps newer than existing CXX files (if present) # -w is to set working directory (and correctly set __pyx_f[] array of filenames) set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"") @@ -164,18 +166,18 @@ function(build_dpctl_ext _trgt _src _dest) LIBRARY DESTINATION ${_dest}) install(FILES ${_generated_api_h} - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include/${_dest} + DESTINATION dpctl/include/${_dest} OPTIONAL) install(FILES ${_generated_public_h} - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include/${_dest} + DESTINATION dpctl/include/${_dest} OPTIONAL) if (DPCTL_GENERATE_COVERAGE) get_filename_component(_original_src_dir ${_src} DIRECTORY) file(RELATIVE_PATH _rel_dir ${CMAKE_SOURCE_DIR} ${_original_src_dir}) install(FILES ${_generated_src} - DESTINATION ${CMAKE_INSTALL_PREFIX}/${_rel_dir} + DESTINATION ${_rel_dir} ) endif() diff --git a/dpctl/__init__.py b/dpctl/__init__.py index 5f57cdf90e..e91d716775 100644 --- a/dpctl/__init__.py +++ b/dpctl/__init__.py @@ -60,7 +60,11 @@ ) from ._sycl_queue_manager import get_device_cached_queue from ._sycl_timer import SyclTimer -from ._version import get_versions + +try: + from ._version import __version__ +except ImportError: + __version__ = "0.0.0.unknown" from .enum_types import ( backend_type, device_type, @@ -140,6 +144,4 @@ def get_include(): return os.path.join(os.path.dirname(__file__), "include") -__version__ = get_versions()["version"] -del get_versions del _init_helper diff --git a/dpctl/_version.py b/dpctl/_version.py deleted file mode 100644 index 9812b5afc6..0000000000 --- a/dpctl/_version.py +++ /dev/null @@ -1,683 +0,0 @@ - -# This file helps to compute a version number in source trees obtained from -# git-archive tarball (such as those provided by githubs download-from-tag -# feature). Distribution tarballs (built by setup.py sdist) and build -# directories (produced by setup.py build) will contain a much shorter file -# that just contains the computed version number. - -# This file is released into the public domain. -# Generated by versioneer-0.29 -# https://github.com/python-versioneer/python-versioneer - -"""Git implementation of _version.py.""" - -import errno -import os -import re -import subprocess -import sys -from typing import Any, Callable, Dict, List, Optional, Tuple -import functools - - -def get_keywords() -> Dict[str, str]: - """Get the keywords needed to look up the version information.""" - # these strings will be replaced by git during git-archive. - # setup.py/versioneer.py will grep for the variable names, so they must - # each be defined on a line of their own. _version.py will just call - # get_keywords(). - git_refnames = "$Format:%d$" - git_full = "$Format:%H$" - git_date = "$Format:%ci$" - keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} - return keywords - - -class VersioneerConfig: - """Container for Versioneer configuration parameters.""" - - VCS: str - style: str - tag_prefix: str - parentdir_prefix: str - versionfile_source: str - verbose: bool - - -def get_config() -> VersioneerConfig: - """Create, populate and return the VersioneerConfig() object.""" - # these strings are filled in when 'setup.py versioneer' creates - # _version.py - cfg = VersioneerConfig() - cfg.VCS = "git" - cfg.style = "pep440" - cfg.tag_prefix = "" - cfg.parentdir_prefix = "dpctl-" - cfg.versionfile_source = "dpctl/_version.py" - cfg.verbose = False - return cfg - - -class NotThisMethod(Exception): - """Exception raised if a method is not valid for the current scenario.""" - - -LONG_VERSION_PY: Dict[str, str] = {} -HANDLERS: Dict[str, Dict[str, Callable]] = {} - - -def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator - """Create decorator to mark a method as the handler of a VCS.""" - def decorate(f: Callable) -> Callable: - """Store f in HANDLERS[vcs][method].""" - if vcs not in HANDLERS: - HANDLERS[vcs] = {} - HANDLERS[vcs][method] = f - return f - return decorate - - -def run_command( - commands: List[str], - args: List[str], - cwd: Optional[str] = None, - verbose: bool = False, - hide_stderr: bool = False, - env: Optional[Dict[str, str]] = None, -) -> Tuple[Optional[str], Optional[int]]: - """Call the given command(s).""" - assert isinstance(commands, list) - process = None - - popen_kwargs: Dict[str, Any] = {} - if sys.platform == "win32": - # This hides the console window if pythonw.exe is used - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - popen_kwargs["startupinfo"] = startupinfo - - for command in commands: - try: - dispcmd = str([command] + args) - # remember shell=False, so use git.cmd on windows, not just git - process = subprocess.Popen([command] + args, cwd=cwd, env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr - else None), **popen_kwargs) - break - except OSError as e: - if e.errno == errno.ENOENT: - continue - if verbose: - print("unable to run %s" % dispcmd) - print(e) - return None, None - else: - if verbose: - print("unable to find command, tried %s" % (commands,)) - return None, None - stdout = process.communicate()[0].strip().decode() - if process.returncode != 0: - if verbose: - print("unable to run %s (error)" % dispcmd) - print("stdout was %s" % stdout) - return None, process.returncode - return stdout, process.returncode - - -def versions_from_parentdir( - parentdir_prefix: str, - root: str, - verbose: bool, -) -> Dict[str, Any]: - """Try to determine the version from the parent directory name. - - Source tarballs conventionally unpack into a directory that includes both - the project name and a version string. We will also support searching up - two directory levels for an appropriately named parent directory - """ - rootdirs = [] - - for _ in range(3): - dirname = os.path.basename(root) - if dirname.startswith(parentdir_prefix): - return {"version": dirname[len(parentdir_prefix):], - "full-revisionid": None, - "dirty": False, "error": None, "date": None} - rootdirs.append(root) - root = os.path.dirname(root) # up a level - - if verbose: - print("Tried directories %s but none started with prefix %s" % - (str(rootdirs), parentdir_prefix)) - raise NotThisMethod("rootdir doesn't start with parentdir_prefix") - - -@register_vcs_handler("git", "get_keywords") -def git_get_keywords(versionfile_abs: str) -> Dict[str, str]: - """Extract version information from the given file.""" - # the code embedded in _version.py can just fetch the value of these - # keywords. When used from setup.py, we don't want to import _version.py, - # so we do it with a regexp instead. This function is not used from - # _version.py. - keywords: Dict[str, str] = {} - try: - with open(versionfile_abs, "r") as fobj: - for line in fobj: - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - except OSError: - pass - return keywords - - -@register_vcs_handler("git", "keywords") -def git_versions_from_keywords( - keywords: Dict[str, str], - tag_prefix: str, - verbose: bool, -) -> Dict[str, Any]: - """Get version information from git keywords.""" - if "refnames" not in keywords: - raise NotThisMethod("Short version file found") - date = keywords.get("date") - if date is not None: - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - - # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant - # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 - # -like" string, which we must then edit to make compliant), because - # it's been around since git-1.5.3, and it's too difficult to - # discover which version we're using, or to work around using an - # older one. - date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - refnames = keywords["refnames"].strip() - if refnames.startswith("$Format"): - if verbose: - print("keywords are unexpanded, not using") - raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = {r.strip() for r in refnames.strip("()").split(",")} - # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of - # just "foo-1.0". If we see a "tag: " prefix, prefer those. - TAG = "tag: " - tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} - if not tags: - # Either we're using git < 1.8.3, or there really are no tags. We use - # a heuristic: assume all version tags have a digit. The old git %d - # expansion behaves like git log --decorate=short and strips out the - # refs/heads/ and refs/tags/ prefixes that would let us distinguish - # between branches and tags. By ignoring refnames without digits, we - # filter out many common branch names like "release" and - # "stabilization", as well as "HEAD" and "master". - tags = {r for r in refs if re.search(r'\d', r)} - if verbose: - print("discarding '%s', no digits" % ",".join(refs - tags)) - if verbose: - print("likely tags: %s" % ",".join(sorted(tags))) - for ref in sorted(tags): - # sorting will prefer e.g. "2.0" over "2.0rc1" - if ref.startswith(tag_prefix): - r = ref[len(tag_prefix):] - # Filter out refs that exactly match prefix or that don't start - # with a number once the prefix is stripped (mostly a concern - # when prefix is '') - if not re.match(r'\d', r): - continue - if verbose: - print("picking %s" % r) - return {"version": r, - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": None, - "date": date} - # no suitable tags, so version is "0+unknown", but full hex is still there - if verbose: - print("no suitable tags, using unknown + full revision id") - return {"version": "0+unknown", - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": "no suitable tags", "date": None} - - -@register_vcs_handler("git", "pieces_from_vcs") -def git_pieces_from_vcs( - tag_prefix: str, - root: str, - verbose: bool, - runner: Callable = run_command -) -> Dict[str, Any]: - """Get version from 'git describe' in the root of the source tree. - - This only gets called if the git-archive 'subst' keywords were *not* - expanded, and _version.py hasn't already been rewritten with a short - version string, meaning we're inside a checked out source tree. - """ - GITS = ["git"] - if sys.platform == "win32": - GITS = ["git.cmd", "git.exe"] - - # GIT_DIR can interfere with correct operation of Versioneer. - # It may be intended to be passed to the Versioneer-versioned project, - # but that should not change where we get our version from. - env = os.environ.copy() - env.pop("GIT_DIR", None) - runner = functools.partial(runner, env=env) - - _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, - hide_stderr=not verbose) - if rc != 0: - if verbose: - print("Directory %s not under git control" % root) - raise NotThisMethod("'git rev-parse --git-dir' returned error") - - # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] - # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = runner(GITS, [ - "describe", "--tags", "--dirty", "--always", "--long", - "--match", f"{tag_prefix}[[:digit:]]*" - ], cwd=root) - # --long was added in git-1.5.5 - if describe_out is None: - raise NotThisMethod("'git describe' failed") - describe_out = describe_out.strip() - full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root) - if full_out is None: - raise NotThisMethod("'git rev-parse' failed") - full_out = full_out.strip() - - pieces: Dict[str, Any] = {} - pieces["long"] = full_out - pieces["short"] = full_out[:7] # maybe improved later - pieces["error"] = None - - branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], - cwd=root) - # --abbrev-ref was added in git-1.6.3 - if rc != 0 or branch_name is None: - raise NotThisMethod("'git rev-parse --abbrev-ref' returned error") - branch_name = branch_name.strip() - - if branch_name == "HEAD": - # If we aren't exactly on a branch, pick a branch which represents - # the current commit. If all else fails, we are on a branchless - # commit. - branches, rc = runner(GITS, ["branch", "--contains"], cwd=root) - # --contains was added in git-1.5.4 - if rc != 0 or branches is None: - raise NotThisMethod("'git branch --contains' returned error") - branches = branches.split("\n") - - # Remove the first line if we're running detached - if "(" in branches[0]: - branches.pop(0) - - # Strip off the leading "* " from the list of branches. - branches = [branch[2:] for branch in branches] - if "master" in branches: - branch_name = "master" - elif not branches: - branch_name = None - else: - # Pick the first branch that is returned. Good or bad. - branch_name = branches[0] - - pieces["branch"] = branch_name - - # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] - # TAG might have hyphens. - git_describe = describe_out - - # look for -dirty suffix - dirty = git_describe.endswith("-dirty") - pieces["dirty"] = dirty - if dirty: - git_describe = git_describe[:git_describe.rindex("-dirty")] - - # now we have TAG-NUM-gHEX or HEX - - if "-" in git_describe: - # TAG-NUM-gHEX - mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) - if not mo: - # unparsable. Maybe git-describe is misbehaving? - pieces["error"] = ("unable to parse git-describe output: '%s'" - % describe_out) - return pieces - - # tag - full_tag = mo.group(1) - if not full_tag.startswith(tag_prefix): - if verbose: - fmt = "tag '%s' doesn't start with prefix '%s'" - print(fmt % (full_tag, tag_prefix)) - pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" - % (full_tag, tag_prefix)) - return pieces - pieces["closest-tag"] = full_tag[len(tag_prefix):] - - # distance: number of commits since tag - pieces["distance"] = int(mo.group(2)) - - # commit: short hex revision ID - pieces["short"] = mo.group(3) - - else: - # HEX: no tags - pieces["closest-tag"] = None - out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root) - pieces["distance"] = len(out.split()) # total number of commits - - # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip() - # Use only the last line. Previous lines may contain GPG signature - # information. - date = date.splitlines()[-1] - pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) - - return pieces - - -def plus_or_dot(pieces: Dict[str, Any]) -> str: - """Return a + if we don't already have one, else return a .""" - if "+" in pieces.get("closest-tag", ""): - return "." - return "+" - - -def render_pep440(pieces: Dict[str, Any]) -> str: - """Build up version string, with post-release "local version identifier". - - Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you - get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty - - Exceptions: - 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += plus_or_dot(pieces) - rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0+untagged.%d.g%s" % (pieces["distance"], - pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_branch(pieces: Dict[str, Any]) -> str: - """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] . - - The ".dev0" means not master branch. Note that .dev0 sorts backwards - (a feature branch will appear "older" than the master branch). - - Exceptions: - 1: no tags. 0[.dev0]+untagged.DISTANCE.gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0" - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+untagged.%d.g%s" % (pieces["distance"], - pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]: - """Split pep440 version string at the post-release segment. - - Returns the release segments before the post-release and the - post-release version number (or -1 if no post-release segment is present). - """ - vc = str.split(ver, ".post") - return vc[0], int(vc[1] or 0) if len(vc) == 2 else None - - -def render_pep440_pre(pieces: Dict[str, Any]) -> str: - """TAG[.postN.devDISTANCE] -- No -dirty. - - Exceptions: - 1: no tags. 0.post0.devDISTANCE - """ - if pieces["closest-tag"]: - if pieces["distance"]: - # update the post release segment - tag_version, post_version = pep440_split_post(pieces["closest-tag"]) - rendered = tag_version - if post_version is not None: - rendered += ".post%d.dev%d" % (post_version + 1, pieces["distance"]) - else: - rendered += ".post0.dev%d" % (pieces["distance"]) - else: - # no commits, use the tag as the version - rendered = pieces["closest-tag"] - else: - # exception #1 - rendered = "0.post0.dev%d" % pieces["distance"] - return rendered - - -def render_pep440_post(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX] . - - The ".dev0" means dirty. Note that .dev0 sorts backwards - (a dirty tree will appear "older" than the corresponding clean one), - but you shouldn't be releasing software with -dirty anyways. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%s" % pieces["short"] - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - rendered += "+g%s" % pieces["short"] - return rendered - - -def render_pep440_post_branch(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] . - - The ".dev0" means not master branch. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0]+gHEX[.dirty] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += plus_or_dot(pieces) - rendered += "g%s" % pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["branch"] != "master": - rendered += ".dev0" - rendered += "+g%s" % pieces["short"] - if pieces["dirty"]: - rendered += ".dirty" - return rendered - - -def render_pep440_old(pieces: Dict[str, Any]) -> str: - """TAG[.postDISTANCE[.dev0]] . - - The ".dev0" means dirty. - - Exceptions: - 1: no tags. 0.postDISTANCE[.dev0] - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: - rendered += ".post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - else: - # exception #1 - rendered = "0.post%d" % pieces["distance"] - if pieces["dirty"]: - rendered += ".dev0" - return rendered - - -def render_git_describe(pieces: Dict[str, Any]) -> str: - """TAG[-DISTANCE-gHEX][-dirty]. - - Like 'git describe --tags --dirty --always'. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - if pieces["distance"]: - rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render_git_describe_long(pieces: Dict[str, Any]) -> str: - """TAG-DISTANCE-gHEX[-dirty]. - - Like 'git describe --tags --dirty --always -long'. - The distance/hash is unconditional. - - Exceptions: - 1: no tags. HEX[-dirty] (note: no 'g' prefix) - """ - if pieces["closest-tag"]: - rendered = pieces["closest-tag"] - rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) - else: - # exception #1 - rendered = pieces["short"] - if pieces["dirty"]: - rendered += "-dirty" - return rendered - - -def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]: - """Render the given version pieces into the requested style.""" - if pieces["error"]: - return {"version": "unknown", - "full-revisionid": pieces.get("long"), - "dirty": None, - "error": pieces["error"], - "date": None} - - if not style or style == "default": - style = "pep440" # the default - - if style == "pep440": - rendered = render_pep440(pieces) - elif style == "pep440-branch": - rendered = render_pep440_branch(pieces) - elif style == "pep440-pre": - rendered = render_pep440_pre(pieces) - elif style == "pep440-post": - rendered = render_pep440_post(pieces) - elif style == "pep440-post-branch": - rendered = render_pep440_post_branch(pieces) - elif style == "pep440-old": - rendered = render_pep440_old(pieces) - elif style == "git-describe": - rendered = render_git_describe(pieces) - elif style == "git-describe-long": - rendered = render_git_describe_long(pieces) - else: - raise ValueError("unknown style '%s'" % style) - - return {"version": rendered, "full-revisionid": pieces["long"], - "dirty": pieces["dirty"], "error": None, - "date": pieces.get("date")} - - -def get_versions() -> Dict[str, Any]: - """Get version information or return default if unable to do so.""" - # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have - # __file__, we can work backwards from there to the root. Some - # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which - # case we can only use expanded keywords. - - cfg = get_config() - verbose = cfg.verbose - - try: - return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, - verbose) - except NotThisMethod: - pass - - try: - root = os.path.realpath(__file__) - # versionfile_source is the relative path from the top of the source - # tree (where the .git directory might live) to this file. Invert - # this to find the root from __file__. - for _ in cfg.versionfile_source.split('/'): - root = os.path.dirname(root) - except NameError: - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, - "error": "unable to find root of source tree", - "date": None} - - try: - pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) - return render(pieces, cfg.style) - except NotThisMethod: - pass - - try: - if cfg.parentdir_prefix: - return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) - except NotThisMethod: - pass - - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, - "error": "unable to compute version", "date": None} diff --git a/libsyclinterface/CMakeLists.txt b/libsyclinterface/CMakeLists.txt index 3ad4ae5418..aace490b84 100644 --- a/libsyclinterface/CMakeLists.txt +++ b/libsyclinterface/CMakeLists.txt @@ -376,15 +376,15 @@ endif() install(TARGETS DPCTLSyclInterface LIBRARY - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl + DESTINATION dpctl ARCHIVE - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl + DESTINATION dpctl RUNTIME - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl + DESTINATION dpctl ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include + DESTINATION dpctl/include FILES_MATCHING REGEX "\\.h(pp)?$" ) diff --git a/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake b/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake index 9e6f1b015e..52884099ff 100644 --- a/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake +++ b/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake @@ -25,14 +25,15 @@ # LEVEL_ZERO_INCLUDE_DIR function(get_level_zero_headers) + set(LZ_DIR "${CMAKE_CURRENT_BINARY_DIR}/level-zero") - if(EXISTS level-zero) + if(EXISTS ${LZ_DIR}) # Update the checkout execute_process( COMMAND ${GIT_EXECUTABLE} fetch RESULT_VARIABLE result ERROR_VARIABLE error - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/level-zero + WORKING_DIRECTORY ${LZ_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -48,6 +49,7 @@ function(get_level_zero_headers) COMMAND ${GIT_EXECUTABLE} clone https://github.com/oneapi-src/level-zero.git RESULT_VARIABLE result ERROR_VARIABLE error + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -65,7 +67,7 @@ function(get_level_zero_headers) RESULT_VARIABLE result OUTPUT_VARIABLE latest_tag ERROR_VARIABLE error - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/level-zero + WORKING_DIRECTORY ${LZ_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -81,7 +83,7 @@ function(get_level_zero_headers) COMMAND ${GIT_EXECUTABLE} checkout ${latest_tag} RESULT_VARIABLE result ERROR_VARIABLE error - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/level-zero + WORKING_DIRECTORY ${LZ_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -95,7 +97,7 @@ function(get_level_zero_headers) # Populate the path to the headers find_path(LEVEL_ZERO_INCLUDE_DIR NAMES zet_api.h - PATHS ${CMAKE_BINARY_DIR}/level-zero/include + PATHS ${LZ_DIR}/include NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH @@ -111,4 +113,6 @@ function(get_level_zero_headers) ) endif() + set(LEVEL_ZERO_INCLUDE_DIR ${LEVEL_ZERO_INCLUDE_DIR} PARENT_SCOPE) + endfunction(get_level_zero_headers) diff --git a/pyproject.toml b/pyproject.toml index b1d88ddcfc..8a7cacc14a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,11 @@ [build-system] -build-backend = "setuptools.build_meta" +build-backend = "scikit_build_core.build" requires = [ # TODO: keep in sync with [project.dependencies] - "wheel>=0.43", - "build>=1.1", - "setuptools>=63.0.0", - "scikit-build>=0.17.0", - "ninja>=1.11.1; platform_system!='Windows'", - "cmake>=3.29.0", + "scikit-build-core>=0.8.0", + "setuptools_scm>=8.0.0", "cython>=3.1.0", - "numpy >=1.26.0", - # WARNING: check with doc how to upgrade - "versioneer[toml]==0.29" + "numpy >=1.26.0" ] [project] @@ -58,7 +52,7 @@ keywords = [ license = "Apache-2.0" name = "dpctl" readme = {file = "README.md", content-type = "text/markdown"} -requires-python = ">=3.10" +requires-python = ">=3.11" [project.optional-dependencies] coverage = ["Cython>=3.1.0", "pytest", "coverage", "tomli"] @@ -149,9 +143,13 @@ norecursedirs = [ "conda-recipe" ] -[tool.versioneer] -VCS = "git" -parentdir_prefix = "dpctl-" -style = "pep440" -versionfile_build = "dpctl/_version.py" -versionfile_source = "dpctl/_version.py" +# build configuation +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["dpctl/_version.py"] +wheel.packages = ["dpctl"] + +[tool.setuptools_scm] +version_scheme = "only-version" +write_to = "dpctl/_version.py" diff --git a/setup.py b/setup.py deleted file mode 100644 index 17cb7a9492..0000000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -# Data Parallel Control Library (dpctl) -# -# Copyright 2020 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import skbuild -import skbuild.setuptools_wrap -import skbuild.utils -import versioneer - -skbuild.setup( - version=versioneer.get_version(), - cmdclass=versioneer.get_cmdclass(), - url="https://github.com/IntelPython/dpctl", - packages=[ - "dpctl", - "dpctl.memory", - "dpctl.program", - "dpctl.program.utils", - "dpctl.utils", - ], - package_data={ - "dpctl": [ - "tests/*.*", - "tests/helper/*.py", - "tests/elementwise/*.py", - "tests/*.pyx", - "tests/input_files/*", - "resources/cmake/*.cmake", - "include/*.h*", - "include/syclinterface/*.h*", - "include/syclinterface/Config/*.h", - "include/syclinterface/Support/*.h", - "include/dpctl/_sycl*.h", - "include/dpctl/memory/_memory*.h", - "include/dpctl/program/_program*.h", - "*.pxd", - "memory/*.pxd", - "program/*.pxd", - ] - }, - include_package_data=False, -) From b6bd031dc7b45a4fed829d2ea4a24e24eabcd12f Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sat, 28 Feb 2026 01:40:47 -0800 Subject: [PATCH 02/14] Update build scripts for scikit-build-core --- scripts/_build_helper.py | 59 ++++++++++++++++------------------------ scripts/build_locally.py | 30 ++++++++++---------- scripts/gen_coverage.py | 14 ++++------ scripts/gen_docs.py | 16 ++++------- 4 files changed, 51 insertions(+), 68 deletions(-) diff --git a/scripts/_build_helper.py b/scripts/_build_helper.py index d41567598b..c7ad118b11 100644 --- a/scripts/_build_helper.py +++ b/scripts/_build_helper.py @@ -109,45 +109,33 @@ def make_cmake_args( return args -def build_extension( +def build_and_install( setup_dir: str, env: dict[str, str], cmake_args: list[str], - cmake_executable: str = None, generator: str = None, build_type: str = None, + editable: bool = True, ): - cmd = [sys.executable, "setup.py", "build_ext", "--inplace"] - if cmake_executable: - cmd.append(f"--cmake-executable={cmake_executable}") + if cmake_args: + env["CMAKE_ARGS"] = " ".join(cmake_args) if generator: - cmd.append(f"--generator={generator}") + env["CMAKE_GENERATOR"] = generator if build_type: - cmd.append(f"--build-type={build_type}") - if cmake_args: - cmd.append("--") - cmd += cmake_args - run( - cmd, - env=env, - cwd=setup_dir, - ) + env["CMAKE_BUILD_TYPE"] = build_type + cmd = [ + sys.executable, + "-m", + "pip", + "install", + "--no-build-isolation", + ] + if editable: + cmd.append("-e") + cmd.append(".") -def install_editable(setup_dir: str, env: dict[str, str]): - run( - [ - sys.executable, - "-m", - "pip", - "install", - "-e", - ".", - "--no-build-isolation", - ], - env=env, - cwd=setup_dir, - ) + run(cmd, env=env, cwd=setup_dir) def clean_build_dir(setup_dir: str): @@ -157,11 +145,12 @@ def clean_build_dir(setup_dir: str): or not os.path.isdir(setup_dir) ): raise RuntimeError(f"Invalid setup directory provided: '{setup_dir}'") - target = os.path.join(setup_dir, "_skbuild") + + target = os.path.join(setup_dir, "build") if os.path.exists(target): print(f"Cleaning build directory: {target}") - try: - shutil.rmtree(target) - except Exception as e: - print(f"Failed to remove build directory: '{target}'") - raise e + try: + shutil.rmtree(target) + except Exception as e: + print(f"Failed to remove build directory: '{target}'") + raise e diff --git a/scripts/build_locally.py b/scripts/build_locally.py index 6918a429e5..7b25b00ef6 100644 --- a/scripts/build_locally.py +++ b/scripts/build_locally.py @@ -19,10 +19,9 @@ import sys from _build_helper import ( - build_extension, + build_and_install, clean_build_dir, err, - install_editable, log_cmake_args, make_cmake_args, resolve_compilers, @@ -69,12 +68,12 @@ def parse_args(): p.add_argument( "--generator", type=str, default="Ninja", help="CMake generator" ) - p.add_argument( - "--cmake-executable", - type=str, - default=None, - help="Path to CMake executable used by build", - ) + # p.add_argument( + # "--cmake-executable", + # type=str, + # default=None, + # help="Path to CMake executable used by build", + # ) p.add_argument( "--glog", @@ -170,22 +169,25 @@ def main(): log_cmake_args(cmake_args, "build_locally") - print("[build_locally] Building extensions in-place...") + print("[build_locally] Building and installing dpctl...") env = os.environ.copy() - build_extension( + do_editable = not args.skip_editable + + build_and_install( setup_dir, env, cmake_args, - cmake_executable=args.cmake_executable, generator=args.generator, build_type=args.build_type, + editable=do_editable, ) - if not args.skip_editable: - install_editable(setup_dir, env) + + if not do_editable: + print("[build_locally] Performed standard install (--skip-editable)") else: - print("[build_locally] Skipping editable install (--skip-editable)") + print("[build_locally] Performed editable install") print("[build_locally] Build complete") diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py index f7e11c4ace..47c7eeb255 100644 --- a/scripts/gen_coverage.py +++ b/scripts/gen_coverage.py @@ -22,11 +22,10 @@ import sysconfig from _build_helper import ( - build_extension, + build_and_install, capture_cmd_output, clean_build_dir, err, - install_editable, log_cmake_args, make_cmake_args, resolve_compilers, @@ -176,20 +175,17 @@ def main(): log_cmake_args(cmake_args, "gen_coverage") - build_extension( + env["SKBUILD_BUILD_DIR"] = "build/coverage" + + build_and_install( setup_dir, env, cmake_args, - cmake_executable=args.cmake_executable, generator=args.generator, build_type="Coverage", ) - install_editable(setup_dir, env) - cmake_build_dir = capture_cmd_output( - ["find", "_skbuild", "-name", "cmake-build"], - cwd=setup_dir, - ) + cmake_build_dir = os.path.join(setup_dir, "build/coverage") print(f"[gen_coverage] Found CMake build dir: {cmake_build_dir}") diff --git a/scripts/gen_docs.py b/scripts/gen_docs.py index ea29fa6bf6..93540dde58 100644 --- a/scripts/gen_docs.py +++ b/scripts/gen_docs.py @@ -20,11 +20,9 @@ import sys from _build_helper import ( - build_extension, - capture_cmd_output, + build_and_install, clean_build_dir, err, - install_editable, log_cmake_args, make_cmake_args, resolve_compilers, @@ -151,18 +149,16 @@ def main(): env = os.environ.copy() - build_extension( + env["SKBUILD_BUILD_DIR"] = "build/docs" + + build_and_install( setup_dir, env, cmake_args, - cmake_executable=args.cmake_executable, generator=args.generator, build_type="Release", ) - install_editable(setup_dir, env) - cmake_build_dir = capture_cmd_output( - ["find", "_skbuild", "-name", "cmake-build"], cwd=setup_dir - ) + cmake_build_dir = os.path.join(setup_dir, "build/docs") print(f"[gen_docs] Found CMake build dir: {cmake_build_dir}") @@ -173,7 +169,7 @@ def main(): generated_doc_dir = ( subprocess.check_output( - ["find", "_skbuild", "-name", "index.html"], cwd=setup_dir + ["find", "build/docs", "-name", "index.html"], cwd=setup_dir ) .decode("utf-8") .strip("\n") From b0d2f691a7df92265d093e0ee7fddb83db12775a Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sat, 28 Feb 2026 02:27:32 -0800 Subject: [PATCH 03/14] update conda-recipe for scikit-build-core --- conda-recipe/bld.bat | 4 ++-- conda-recipe/build.sh | 6 ++---- conda-recipe/meta.yaml | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 2ff9e6cdcc..7f2c236bc6 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -2,8 +2,6 @@ REM A workaround for activate-dpcpp.bat issue to be addressed in 2021.4 set "LIB=%BUILD_PREFIX%\Library\lib;%BUILD_PREFIX%\compiler\lib;%LIB%" set "INCLUDE=%BUILD_PREFIX%\include;%INCLUDE%" -"%PYTHON%" setup.py clean --all - REM Overriding IPO is useful for building in resources constrained VMs (public CI) if DEFINED OVERRIDE_INTEL_IPO ( set "CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=FALSE" @@ -23,6 +21,8 @@ set "CMAKE_GENERATOR=Ninja" :: Make CMake verbose set "VERBOSE=1" +set "SETUPTOOLS_SCM_PRETEND_VERSION=%PKG_VERSION%" + set "CMAKE_ARGS=%CMAKE_ARGS% -DDPCTL_LEVEL_ZERO_INCLUDE_DIR=%PREFIX:\=/%/Library/include/level_zero" %PYTHON% -m build -w -n -x diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index e892602ede..ebbb4871a8 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -13,10 +13,6 @@ export ICXCFG read -r GLIBC_MAJOR GLIBC_MINOR <<<"$(conda list '^sysroot_linux-64$' \ | tail -n 1 | awk '{print $2}' | grep -oP '\d+' | head -n 2 | tr '\n' ' ')" -if [ -e "_skbuild" ]; then - ${PYTHON} setup.py clean --all -fi - export CC=icx export CXX=icpx @@ -24,6 +20,8 @@ export CMAKE_GENERATOR=Ninja # Make CMake verbose export VERBOSE=1 +export SETUPTOOLS_SCM_PRETEND_VERSION=${PKG_VERSION} + CMAKE_ARGS="${CMAKE_ARGS} -DDPCTL_LEVEL_ZERO_INCLUDE_DIR=${PREFIX}/include/level_zero -DDPCTL_WITH_REDIST=ON" # -wnx flags mean: --wheel --no-isolation --skip-dependency-check diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 79918788d6..addfd810f6 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -35,7 +35,6 @@ requirements: - {{ pin_compatible('intel-cmplr-lib-rt', min_pin='x.x', max_pin='x') }} # Ensure we are using latest version of setuptools, since we don't need # editable environments for release. - - setuptools >=69 {% for dep in py_build_deps %} {% if dep.startswith('ninja') %} - {{ dep.split(';')[0] }} # [not win] @@ -59,7 +58,6 @@ test: - {{ compiler('cxx') }} - {{ stdlib('c') }} - cython - - setuptools - pytest about: From 3944480ac42c47d2a9dad1e48eb94aee55fc9049 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sat, 28 Feb 2026 03:23:26 -0800 Subject: [PATCH 04/14] use pyproject.toml for py_sycl_ls C example --- examples/c/py_sycl_ls/README.md | 2 +- examples/c/py_sycl_ls/pyproject.toml | 32 ++++++++++++++++++++++++++++ examples/c/py_sycl_ls/setup.py | 11 ---------- 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 examples/c/py_sycl_ls/pyproject.toml diff --git a/examples/c/py_sycl_ls/README.md b/examples/c/py_sycl_ls/README.md index f3429a534d..6965078ad6 100644 --- a/examples/c/py_sycl_ls/README.md +++ b/examples/c/py_sycl_ls/README.md @@ -3,7 +3,7 @@ ## Building ```bash -python setup.py build_ext --inplace +python -m pip install . ``` ## Testing diff --git a/examples/c/py_sycl_ls/pyproject.toml b/examples/c/py_sycl_ls/pyproject.toml new file mode 100644 index 0000000000..cc5192a7ce --- /dev/null +++ b/examples/c/py_sycl_ls/pyproject.toml @@ -0,0 +1,32 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "setuptools.build_meta" +requires = ["setuptools>=61.0.0", "dpctl"] + +[project] +authors = [{name = "Intel Corporation"}] +description = "An example of C extension calling SYCLInterface routines" +license = {text = "Apache 2.0"} +name = "py_sycl_ls" +version = "0.0.1" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.setuptools] +packages = ["py_sycl_ls"] diff --git a/examples/c/py_sycl_ls/setup.py b/examples/c/py_sycl_ls/setup.py index 21f7024c99..7a4b63c240 100644 --- a/examples/c/py_sycl_ls/setup.py +++ b/examples/c/py_sycl_ls/setup.py @@ -21,17 +21,6 @@ import dpctl setup( - name="py_sycl_ls", - version="0.0.1", - description="An example of C extension calling SYCLInterface routines", - long_description=""" - Example of using SYCLInterface. - - See README.md for more details. - """, - license="Apache 2.0", - author="Intel Corporation", - url="https://github.com/IntelPython/dpctl", ext_modules=[ Extension( name="py_sycl_ls._py_sycl_ls", From 0242383f925180901c24e1f756ed475995ae0ec8 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sat, 28 Feb 2026 04:17:07 -0800 Subject: [PATCH 05/14] update cython examples to use scikit-build-core --- examples/cython/sycl_buffer/README.md | 4 +- examples/cython/sycl_buffer/pyproject.toml | 39 ++++++++++++++++++ examples/cython/sycl_buffer/setup.py | 33 --------------- examples/cython/use_dpctl_sycl/README.md | 4 +- examples/cython/use_dpctl_sycl/pyproject.toml | 40 +++++++++++++++++++ examples/cython/use_dpctl_sycl/setup.py | 33 --------------- 6 files changed, 83 insertions(+), 70 deletions(-) create mode 100644 examples/cython/sycl_buffer/pyproject.toml delete mode 100644 examples/cython/sycl_buffer/setup.py create mode 100644 examples/cython/use_dpctl_sycl/pyproject.toml delete mode 100644 examples/cython/use_dpctl_sycl/setup.py diff --git a/examples/cython/sycl_buffer/README.md b/examples/cython/sycl_buffer/README.md index 6cda697dcf..377310adb2 100644 --- a/examples/cython/sycl_buffer/README.md +++ b/examples/cython/sycl_buffer/README.md @@ -16,12 +16,12 @@ oneMKL. To compile the example on Linux, run: ```bash -CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja +CC=icx CXX=icpx python pip install . ``` On Windows, run: ```bash -CC=icx CXX=icx python setup.py build_ext --inplace -G Ninja +CC=icx CXX=icx python pip install . ``` ## Running diff --git a/examples/cython/sycl_buffer/pyproject.toml b/examples/cython/sycl_buffer/pyproject.toml new file mode 100644 index 0000000000..0cee731c73 --- /dev/null +++ b/examples/cython/sycl_buffer/pyproject.toml @@ -0,0 +1,39 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "scikit_build_core.build" +requires = [ + "scikit-build-core>=0.8.0", + "cython>=3.0.10", + "numpy" +] + +[project] +authors = [{name = "Intel Corporation"}] +dependencies = ["dpctl", "numpy"] +description = "An example of Cython extension calling SYCL routines" +license = {text = "Apache 2.0"} +name = "syclbuffer" +requires-python = ">=3.10" +version = "0.0.0" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +wheel.packages = ["syclbuffer"] diff --git a/examples/cython/sycl_buffer/setup.py b/examples/cython/sycl_buffer/setup.py deleted file mode 100644 index cba7882e83..0000000000 --- a/examples/cython/sycl_buffer/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -# Data Parallel Control (dpctl) -# -# Copyright 2020 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from skbuild import setup - -setup( - name="syclbuffer", - version="0.0.0", - description="An example of Cython extension calling SYCL routines", - long_description=""" - Example of using SYCL to work on host allocated NumPy array using - SYCL buffers and SYCL functions. - - See README.md for more details. - """, - license="Apache 2.0", - author="Intel Corporation", - url="https://github.com/IntelPython/dpctl", - packages=["syclbuffer"], -) diff --git a/examples/cython/use_dpctl_sycl/README.md b/examples/cython/use_dpctl_sycl/README.md index e6041d12aa..43e3673aa9 100644 --- a/examples/cython/use_dpctl_sycl/README.md +++ b/examples/cython/use_dpctl_sycl/README.md @@ -11,12 +11,12 @@ written in Cython. To build the example on Linux, run: ```bash -CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja +CC=icx CXX=icpx python pip install . ``` On Windows, run: ```bash -CC=icx CXX=icx python setup.py build_ext --inplace -G Ninja +CC=icx CXX=icx python pip install . ``` ## Testing diff --git a/examples/cython/use_dpctl_sycl/pyproject.toml b/examples/cython/use_dpctl_sycl/pyproject.toml new file mode 100644 index 0000000000..f69226c7f4 --- /dev/null +++ b/examples/cython/use_dpctl_sycl/pyproject.toml @@ -0,0 +1,40 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "scikit_build_core.build" +requires = [ + "scikit-build-core>=0.8.0", + "cython>=3.0.10", + "dpctl", + "numpy" +] + +[project] +authors = [{name = "Intel Corporation"}] +dependencies = ["dpctl", "numpy"] +description = "An example of Cython extension calling SYCL Cython API" +license = {text = "Apache 2.0"} +name = "use_dpctl_sycl" +requires-python = ">=3.10" +version = "0.0.0" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +wheel.packages = ["use_dpctl_sycl"] diff --git a/examples/cython/use_dpctl_sycl/setup.py b/examples/cython/use_dpctl_sycl/setup.py deleted file mode 100644 index 559de5476e..0000000000 --- a/examples/cython/use_dpctl_sycl/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -# Data Parallel Control (dpctl) -# -# Copyright 2022 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from skbuild import setup - -setup( - name="use_dpctl_sycl", - version="0.0.0", - description="An example of Cython extension calling SYCL Cython API", - long_description=""" - Example of using SYCL to work on host allocated NumPy array using - SYCL buffers and SYCL functions. - - See README.md for more details. - """, - license="Apache 2.0", - author="Intel Corporation", - url="https://github.com/IntelPython/dpctl", - packages=["use_dpctl_sycl"], -) From ac1aa6546d6bea6c56874f36043d3713299640c4 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sat, 28 Feb 2026 15:25:05 -0800 Subject: [PATCH 06/14] update external_usm_allocation example --- .../external_usm_allocation/CMakeLists.txt | 2 +- .../external_usm_allocation/README.md | 2 +- .../external_usm_allocation/pyproject.toml | 39 +++++++++++++++++++ .../pybind11/external_usm_allocation/setup.py | 26 ------------- .../external_usm_allocation/__init__.py | 0 .../_usm_alloc_example.cpp | 0 6 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 examples/pybind11/external_usm_allocation/pyproject.toml delete mode 100644 examples/pybind11/external_usm_allocation/setup.py rename examples/pybind11/external_usm_allocation/{ => src}/external_usm_allocation/__init__.py (100%) rename examples/pybind11/external_usm_allocation/{ => src}/external_usm_allocation/_usm_alloc_example.cpp (100%) diff --git a/examples/pybind11/external_usm_allocation/CMakeLists.txt b/examples/pybind11/external_usm_allocation/CMakeLists.txt index b2462852cf..ccf64b4e72 100644 --- a/examples/pybind11/external_usm_allocation/CMakeLists.txt +++ b/examples/pybind11/external_usm_allocation/CMakeLists.txt @@ -25,7 +25,7 @@ find_package(Dpctl REQUIRED) set(py_module_name _external_usm_alloc) set(_sources - external_usm_allocation/_usm_alloc_example.cpp + src/external_usm_allocation/_usm_alloc_example.cpp ) pybind11_add_module(${py_module_name} MODULE diff --git a/examples/pybind11/external_usm_allocation/README.md b/examples/pybind11/external_usm_allocation/README.md index 71dcce3c0a..ab9f367d0e 100644 --- a/examples/pybind11/external_usm_allocation/README.md +++ b/examples/pybind11/external_usm_allocation/README.md @@ -13,7 +13,7 @@ To build the example, run: ```bash source /opt/intel/oneapi/compiler/latest/env/vars.sh -CXX=icpx CC=icx python setup.py build_ext --inplace +CXX=icpx CC=icx python -m pip install . python -m pytest tests python example.py ``` diff --git a/examples/pybind11/external_usm_allocation/pyproject.toml b/examples/pybind11/external_usm_allocation/pyproject.toml new file mode 100644 index 0000000000..9781dcd891 --- /dev/null +++ b/examples/pybind11/external_usm_allocation/pyproject.toml @@ -0,0 +1,39 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "scikit_build_core.build" +requires = [ + "scikit-build-core>=0.8.0", + "dpctl", + "numpy >=1.23" +] + +[project] +authors = [{name = "Intel Corporation"}] +dependencies = ["numpy", "dpctl"] +description = "An example of SYCL-powered Python package (with pybind11)" +license = {text = "Apache 2.0"} +name = "external_usm_allocation" +requires-python = ">=3.10" +version = "0.0.1" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +wheel.packages = ["src/external_usm_allocation"] diff --git a/examples/pybind11/external_usm_allocation/setup.py b/examples/pybind11/external_usm_allocation/setup.py deleted file mode 100644 index 92f295bb09..0000000000 --- a/examples/pybind11/external_usm_allocation/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -# Data Parallel Control (dpctl) -# -# Copyright 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from skbuild import setup - -setup( - name="external_usm_allocation", - version="0.0.1", - description="an example of SYCL-powered Python package (with pybind11)", - author="Intel Scripting", - license="Apache 2.0", - packages=["external_usm_allocation"], -) diff --git a/examples/pybind11/external_usm_allocation/external_usm_allocation/__init__.py b/examples/pybind11/external_usm_allocation/src/external_usm_allocation/__init__.py similarity index 100% rename from examples/pybind11/external_usm_allocation/external_usm_allocation/__init__.py rename to examples/pybind11/external_usm_allocation/src/external_usm_allocation/__init__.py diff --git a/examples/pybind11/external_usm_allocation/external_usm_allocation/_usm_alloc_example.cpp b/examples/pybind11/external_usm_allocation/src/external_usm_allocation/_usm_alloc_example.cpp similarity index 100% rename from examples/pybind11/external_usm_allocation/external_usm_allocation/_usm_alloc_example.cpp rename to examples/pybind11/external_usm_allocation/src/external_usm_allocation/_usm_alloc_example.cpp From 4f91866b90d48f3066d670c86d3b3ad1a6afef2c Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 11 Mar 2026 13:41:02 -0700 Subject: [PATCH 07/14] use cython-cmake in build grandfathers old scikit-build Cython CMake injections into scikit-build-core explicitly --- cmake/FindCython.cmake | 88 ---------- cmake/README.md | 5 - cmake/UseCython.cmake | 383 ----------------------------------------- pyproject.toml | 1 + 4 files changed, 1 insertion(+), 476 deletions(-) delete mode 100755 cmake/FindCython.cmake delete mode 100644 cmake/README.md delete mode 100755 cmake/UseCython.cmake diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake deleted file mode 100755 index c8de131125..0000000000 --- a/cmake/FindCython.cmake +++ /dev/null @@ -1,88 +0,0 @@ -#.rst: -# -# Find ``cython`` executable. -# -# This module will set the following variables in your project: -# -# ``CYTHON_EXECUTABLE`` -# path to the ``cython`` program -# -# ``CYTHON_VERSION`` -# version of ``cython`` -# -# ``CYTHON_FOUND`` -# true if the program was found -# -# For more information on the Cython project, see https://cython.org/. -# -# *Cython is a language that makes writing C extensions for the Python language -# as easy as Python itself.* -# -#============================================================================= -# Copyright 2011 Kitware, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= - -# Use the Cython executable that lives next to the Python executable -# if it is a local installation. -if(Python_EXECUTABLE) - get_filename_component(_python_path ${Python_EXECUTABLE} PATH) -elseif(Python3_EXECUTABLE) - get_filename_component(_python_path ${Python3_EXECUTABLE} PATH) -elseif(DEFINED PYTHON_EXECUTABLE) - get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH) -endif() - -if(DEFINED _python_path) - find_program(CYTHON_EXECUTABLE - NAMES cython cython.bat cython3 - HINTS ${_python_path} - DOC "path to the cython executable") -else() - find_program(CYTHON_EXECUTABLE - NAMES cython cython.bat cython3 - DOC "path to the cython executable") -endif() - -if(CYTHON_EXECUTABLE) - set(CYTHON_version_command ${CYTHON_EXECUTABLE} --version) - - execute_process(COMMAND ${CYTHON_version_command} - OUTPUT_VARIABLE CYTHON_version_output - ERROR_VARIABLE CYTHON_version_error - RESULT_VARIABLE CYTHON_version_result - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) - - if(NOT ${CYTHON_version_result} EQUAL 0) - set(_error_msg "Command \"${CYTHON_version_command}\" failed with") - set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}") - message(SEND_ERROR "${_error_msg}") - else() - if("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)") - set(CYTHON_VERSION "${CMAKE_MATCH_1}") - else() - if("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)") - set(CYTHON_VERSION "${CMAKE_MATCH_1}") - endif() - endif() - endif() -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE) - -mark_as_advanced(CYTHON_EXECUTABLE) - -include(UseCython) diff --git a/cmake/README.md b/cmake/README.md deleted file mode 100644 index aac698b18e..0000000000 --- a/cmake/README.md +++ /dev/null @@ -1,5 +0,0 @@ -## Vendored files - -Files `FindCython.cmake` and `UseCython.cmake` were vendored from [`scikit-build`](https://github.com/scikit-build/scikit-build/tree/main/skbuild/resources/cmake) to support migration to `scikit-build-core`, which no longer includes these modules automatically - -Files are copyright 2011 Kitware, Inc. and licensed under the Apache License, Version 2.0. diff --git a/cmake/UseCython.cmake b/cmake/UseCython.cmake deleted file mode 100755 index 4e0fa7907d..0000000000 --- a/cmake/UseCython.cmake +++ /dev/null @@ -1,383 +0,0 @@ -#.rst: -# -# The following functions are defined: -# -# .. cmake:command:: add_cython_target -# -# Create a custom rule to generate the source code for a Python extension module -# using cython. -# -# add_cython_target( [] -# [EMBED_MAIN] -# [C | CXX] -# [PY2 | PY3] -# [OUTPUT_VAR ]) -# -# ```` is the name of the new target, and ```` -# is the path to a cython source file. Note that, despite the name, no new -# targets are created by this function. Instead, see ``OUTPUT_VAR`` for -# retrieving the path to the generated source for subsequent targets. -# -# If only ```` is provided, and it ends in the ".pyx" extension, then it -# is assumed to be the ````. The name of the input without the -# extension is used as the target name. If only ```` is provided, and it -# does not end in the ".pyx" extension, then the ```` is assumed to -# be ``.pyx``. -# -# The Cython include search path is amended with any entries found in the -# ``INCLUDE_DIRECTORIES`` property of the directory containing the -# ```` file. Use ``include_directories`` to add to the Cython -# include search path. -# -# Options: -# -# ``EMBED_MAIN`` -# Embed a main() function in the generated output (for stand-alone -# applications that initialize their own Python runtime). -# -# ``C | CXX`` -# Force the generation of either a C or C++ file. By default, a C file is -# generated, unless the C language is not enabled for the project; in this -# case, a C++ file is generated by default. -# -# ``PY2 | PY3`` -# Force compilation using either Python-2 or Python-3 syntax and code -# semantics. By default, Python-2 syntax and semantics are used if the major -# version of Python found is 2. Otherwise, Python-3 syntax and semantics are -# used. -# -# ``OUTPUT_VAR `` -# Set the variable ```` in the parent scope to the path to the -# generated source file. By default, ```` is used as the output -# variable name. -# -# Defined variables: -# -# ```` -# The path of the generated source file. -# -# Cache variables that affect the behavior include: -# -# ``CYTHON_ANNOTATE`` -# Whether to create an annotated .html file when compiling. -# -# ``CYTHON_FLAGS`` -# Additional flags to pass to the Cython compiler. -# -# Example usage -# ^^^^^^^^^^^^^ -# -# .. code-block:: cmake -# -# find_package(Cython) -# -# # Note: In this case, either one of these arguments may be omitted; their -# # value would have been inferred from that of the other. -# add_cython_target(cy_code cy_code.pyx) -# -# add_library(cy_code MODULE ${cy_code}) -# target_link_libraries(cy_code ...) -# -#============================================================================= -# Copyright 2011 Kitware, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= - -# Configuration options. -set(CYTHON_ANNOTATE OFF - CACHE BOOL "Create an annotated .html file when compiling *.pyx.") - -set(CYTHON_FLAGS "" CACHE STRING - "Extra flags to the cython compiler.") -mark_as_advanced(CYTHON_ANNOTATE CYTHON_FLAGS) - -set(CYTHON_CXX_EXTENSION "cxx") -set(CYTHON_C_EXTENSION "c") - -get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) - -function(add_cython_target _name) - set(options EMBED_MAIN C CXX PY2 PY3) - set(options1 OUTPUT_VAR) - cmake_parse_arguments(_args "${options}" "${options1}" "" ${ARGN}) - - list(GET _args_UNPARSED_ARGUMENTS 0 _arg0) - - # if provided, use _arg0 as the input file path - if(_arg0) - set(_source_file ${_arg0}) - - # otherwise, must determine source file from name, or vice versa - else() - get_filename_component(_name_ext "${_name}" EXT) - - # if extension provided, _name is the source file - if(_name_ext) - set(_source_file ${_name}) - get_filename_component(_name "${_source_file}" NAME_WE) - - # otherwise, assume the source file is ${_name}.pyx - else() - set(_source_file ${_name}.pyx) - endif() - endif() - - set(_embed_main FALSE) - - if("C" IN_LIST languages) - set(_output_syntax "C") - elseif("CXX" IN_LIST languages) - set(_output_syntax "CXX") - else() - message(FATAL_ERROR "Either C or CXX must be enabled to use Cython") - endif() - - if(_args_EMBED_MAIN) - set(_embed_main TRUE) - endif() - - if(_args_C) - set(_output_syntax "C") - endif() - - if(_args_CXX) - set(_output_syntax "CXX") - endif() - - # Doesn't select an input syntax - Cython - # defaults to 2 for Cython 2 and 3 for Cython 3 - set(_input_syntax "default") - - if(_args_PY2) - set(_input_syntax "PY2") - endif() - - if(_args_PY3) - set(_input_syntax "PY3") - endif() - - set(embed_arg "") - if(_embed_main) - set(embed_arg "--embed") - endif() - - set(cxx_arg "") - set(extension "c") - if(_output_syntax STREQUAL "CXX") - set(cxx_arg "--cplus") - set(extension "cxx") - endif() - - set(py_version_arg "") - if(_input_syntax STREQUAL "PY2") - set(py_version_arg "-2") - elseif(_input_syntax STREQUAL "PY3") - set(py_version_arg "-3") - endif() - - set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${extension}") - set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) - - set(_output_var ${_name}) - if(_args_OUTPUT_VAR) - set(_output_var ${_args_OUTPUT_VAR}) - endif() - set(${_output_var} ${generated_file} PARENT_SCOPE) - - file(RELATIVE_PATH generated_file_relative - ${CMAKE_BINARY_DIR} ${generated_file}) - - set(comment "Generating ${_output_syntax} source ${generated_file_relative}") - set(cython_include_directories "") - set(pxd_dependencies "") - set(c_header_dependencies "") - - # Get the include directories. - get_directory_property(cmake_include_directories - DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - INCLUDE_DIRECTORIES) - list(APPEND cython_include_directories ${cmake_include_directories}) - - # Determine dependencies. - # Add the pxd file with the same basename as the given pyx file. - get_source_file_property(pyx_location ${_source_file} LOCATION) - get_filename_component(pyx_path ${pyx_location} PATH) - get_filename_component(pyx_file_basename ${_source_file} NAME_WE) - unset(corresponding_pxd_file CACHE) - find_file(corresponding_pxd_file ${pyx_file_basename}.pxd - PATHS "${pyx_path}" ${cmake_include_directories} - NO_DEFAULT_PATH) - if(corresponding_pxd_file) - list(APPEND pxd_dependencies "${corresponding_pxd_file}") - endif() - - # pxd files to check for additional dependencies - set(pxds_to_check "${_source_file}" "${pxd_dependencies}") - set(pxds_checked "") - set(number_pxds_to_check 1) - while(number_pxds_to_check GREATER 0) - foreach(pxd ${pxds_to_check}) - list(APPEND pxds_checked "${pxd}") - list(REMOVE_ITEM pxds_to_check "${pxd}") - - # look for C headers - file(STRINGS "${pxd}" extern_from_statements - REGEX "cdef[ ]+extern[ ]+from.*$") - foreach(statement ${extern_from_statements}) - # Had trouble getting the quote in the regex - string(REGEX REPLACE - "cdef[ ]+extern[ ]+from[ ]+[\"]([^\"]+)[\"].*" "\\1" - header "${statement}") - unset(header_location CACHE) - find_file(header_location ${header} PATHS ${cmake_include_directories}) - if(header_location) - list(FIND c_header_dependencies "${header_location}" header_idx) - if(${header_idx} LESS 0) - list(APPEND c_header_dependencies "${header_location}") - endif() - endif() - endforeach() - - # check for pxd dependencies - # Look for cimport statements. - set(module_dependencies "") - file(STRINGS "${pxd}" cimport_statements REGEX cimport) - foreach(statement ${cimport_statements}) - if(${statement} MATCHES from) - string(REGEX REPLACE - "from[ ]+([^ ]+).*" "\\1" - module "${statement}") - else() - string(REGEX REPLACE - "cimport[ ]+([^ ]+).*" "\\1" - module "${statement}") - endif() - list(APPEND module_dependencies ${module}) - endforeach() - - # check for pxi dependencies - # Look for include statements. - set(include_dependencies "") - file(STRINGS "${pxd}" include_statements REGEX include) - foreach(statement ${include_statements}) - string(REGEX REPLACE - "include[ ]+[\"]([^\"]+)[\"].*" "\\1" - module "${statement}") - list(APPEND include_dependencies ${module}) - endforeach() - - list(REMOVE_DUPLICATES module_dependencies) - list(REMOVE_DUPLICATES include_dependencies) - - # Add modules to the files to check, if appropriate. - foreach(module ${module_dependencies}) - unset(pxd_location CACHE) - find_file(pxd_location ${module}.pxd - PATHS "${pyx_path}" ${cmake_include_directories} - NO_DEFAULT_PATH) - if(pxd_location) - list(FIND pxds_checked ${pxd_location} pxd_idx) - if(${pxd_idx} LESS 0) - list(FIND pxds_to_check ${pxd_location} pxd_idx) - if(${pxd_idx} LESS 0) - list(APPEND pxds_to_check ${pxd_location}) - list(APPEND pxd_dependencies ${pxd_location}) - endif() # if it is not already going to be checked - endif() # if it has not already been checked - endif() # if pxd file can be found - endforeach() # for each module dependency discovered - - # Add includes to the files to check, if appropriate. - foreach(_include ${include_dependencies}) - unset(pxi_location CACHE) - find_file(pxi_location ${_include} - PATHS "${pyx_path}" ${cmake_include_directories} - NO_DEFAULT_PATH) - if(pxi_location) - list(FIND pxds_checked ${pxi_location} pxd_idx) - if(${pxd_idx} LESS 0) - list(FIND pxds_to_check ${pxi_location} pxd_idx) - if(${pxd_idx} LESS 0) - list(APPEND pxds_to_check ${pxi_location}) - list(APPEND pxd_dependencies ${pxi_location}) - endif() # if it is not already going to be checked - endif() # if it has not already been checked - endif() # if include file can be found - endforeach() # for each include dependency discovered - endforeach() # for each include file to check - - list(LENGTH pxds_to_check number_pxds_to_check) - endwhile() - - # Set additional flags. - set(annotate_arg "") - if(CYTHON_ANNOTATE) - set(annotate_arg "--annotate") - endif() - - set(cython_debug_arg "") - set(line_directives_arg "") - if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR - CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - set(cython_debug_arg "--gdb") - set(line_directives_arg "--line-directives") - endif() - - # Include directory arguments. - list(REMOVE_DUPLICATES cython_include_directories) - set(include_directory_arg "") - foreach(_include_dir ${cython_include_directories}) - set(include_directory_arg - ${include_directory_arg} "--include-dir" "${_include_dir}") - endforeach() - - list(REMOVE_DUPLICATES pxd_dependencies) - list(REMOVE_DUPLICATES c_header_dependencies) - - string(REGEX REPLACE " " ";" CYTHON_FLAGS_LIST "${CYTHON_FLAGS}") - - # Add the command to run the compiler. - add_custom_command(OUTPUT ${generated_file} - COMMAND ${CYTHON_EXECUTABLE} - ARGS ${cxx_arg} ${include_directory_arg} ${py_version_arg} - ${embed_arg} ${annotate_arg} ${cython_debug_arg} - ${line_directives_arg} ${CYTHON_FLAGS_LIST} ${pyx_location} - --output-file ${generated_file} - DEPENDS ${_source_file} - ${pxd_dependencies} - IMPLICIT_DEPENDS ${_output_syntax} - ${c_header_dependencies} - COMMENT ${comment}) - - # NOTE(opadron): I thought about making a proper target, but after trying it - # out, I decided that it would be far too convenient to use the same name as - # the target for the extension module (e.g.: for single-file modules): - # - # ... - # add_cython_target(_module.pyx) - # add_library(_module ${_module}) - # ... - # - # The above example would not be possible since the "_module" target name - # would already be taken by the cython target. Since I can't think of a - # reason why someone would need the custom target instead of just using the - # generated file directly, I decided to leave this commented out. - # - # add_custom_target(${_name} DEPENDS ${generated_file}) - - # Remove their visibility to the user. - set(corresponding_pxd_file "" CACHE INTERNAL "") - set(header_location "" CACHE INTERNAL "") - set(pxd_location "" CACHE INTERNAL "") -endfunction() diff --git a/pyproject.toml b/pyproject.toml index 8a7cacc14a..fca50a891a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ requires = [ "scikit-build-core>=0.8.0", "setuptools_scm>=8.0.0", "cython>=3.1.0", + "cython-cmake", "numpy >=1.26.0" ] From 1c424e656bdc193365df2b99c5f1132ca4230fd9 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 11 Mar 2026 23:24:41 -0700 Subject: [PATCH 08/14] use cython_transpile in dpctl cmake --- dpctl/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dpctl/CMakeLists.txt b/dpctl/CMakeLists.txt index 138e70306d..dac55fac40 100644 --- a/dpctl/CMakeLists.txt +++ b/dpctl/CMakeLists.txt @@ -1,11 +1,10 @@ find_package(Python REQUIRED COMPONENTS NumPy) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") - # -t is to only Cythonize sources with timestamps newer than existing CXX files (if present) # -w is to set working directory (and correctly set __pyx_f[] array of filenames) -set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"") +set(CYTHON_ARGS -t -w "${CMAKE_SOURCE_DIR}") find_package(Cython REQUIRED) +include(UseCython) if(WIN32) string(CONCAT WARNING_FLAGS @@ -108,8 +107,7 @@ set(CMAKE_INSTALL_RPATH "$ORIGIN") function(build_dpctl_ext _trgt _src _dest) set(options SYCL) cmake_parse_arguments(BUILD_DPCTL_EXT "${options}" "RELATIVE_PATH" "" ${ARGN}) - add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src) - set(_cythonize_trgt "${_trgt}_cythonize_pyx") + cython_transpile(${_src} LANGUAGE CXX OUTPUT_VARIABLE _generated_src) Python_add_library(${_trgt} MODULE WITH_SOABI ${_generated_src}) if (BUILD_DPCTL_EXT_SYCL) add_sycl_to_target(TARGET ${_trgt} SOURCES ${_generated_src}) From 2a16c1936a932fa508df500ed94d4c64561dce17 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 11 Mar 2026 23:41:59 -0700 Subject: [PATCH 09/14] update extension CMake --- examples/cython/sycl_buffer/CMakeLists.txt | 19 +++++++++---------- examples/cython/sycl_buffer/pyproject.toml | 1 + examples/cython/use_dpctl_sycl/CMakeLists.txt | 19 +++++++++---------- examples/cython/use_dpctl_sycl/pyproject.toml | 1 + 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/cython/sycl_buffer/CMakeLists.txt b/examples/cython/sycl_buffer/CMakeLists.txt index a30fbb2f35..690a4dc94c 100644 --- a/examples/cython/sycl_buffer/CMakeLists.txt +++ b/examples/cython/sycl_buffer/CMakeLists.txt @@ -19,13 +19,14 @@ find_package(Python REQUIRED COMPONENTS Development.Module NumPy) find_package(Dpctl REQUIRED) # -w is to set working directory (and correctly set __pyx_f[] array of filenames) -set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"") +set(CYTHON_ARGS -t -w "${CMAKE_SOURCE_DIR}") find_package(Cython REQUIRED) +include(UseCython) set(py_module_name _syclbuffer) set(_cy_source syclbuffer/_syclbuffer.pyx) -add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src) +cython_transpile(${_cy_source} LANGUAGE CXX OUTPUT_VARIABLE _generated_cy_src) Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src}) add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src}) target_include_directories(${py_module_name} PUBLIC src ${Dpctl_INCLUDE_DIRS}) @@ -33,14 +34,12 @@ target_link_libraries(${py_module_name} PRIVATE Python::NumPy) install(TARGETS ${py_module_name} DESTINATION syclbuffer) -foreach(_src_fn ${_sources}) - get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS) - set(_combined_options ${_compile_options} "-O3") - set_source_files_properties(${_src_fn} - PROPERTIES - COMPILE_OPTIONS "${_combined_options}" - ) -endforeach() +get_source_file_property(_compile_options ${_generated_cy_src} COMPILE_OPTIONS) +set(_combined_options ${_compile_options} "-O3") +set_source_files_properties(${_generated_cy_src} + PROPERTIES + COMPILE_OPTIONS "${_combined_options}" +) target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) set(ignoreMe "${SKBUILD}") diff --git a/examples/cython/sycl_buffer/pyproject.toml b/examples/cython/sycl_buffer/pyproject.toml index 0cee731c73..14d7d7dec9 100644 --- a/examples/cython/sycl_buffer/pyproject.toml +++ b/examples/cython/sycl_buffer/pyproject.toml @@ -19,6 +19,7 @@ build-backend = "scikit_build_core.build" requires = [ "scikit-build-core>=0.8.0", "cython>=3.0.10", + "cython-cmake", "numpy" ] diff --git a/examples/cython/use_dpctl_sycl/CMakeLists.txt b/examples/cython/use_dpctl_sycl/CMakeLists.txt index 9445ae08f3..a8f06f7cdc 100644 --- a/examples/cython/use_dpctl_sycl/CMakeLists.txt +++ b/examples/cython/use_dpctl_sycl/CMakeLists.txt @@ -19,13 +19,14 @@ find_package(Python REQUIRED COMPONENTS Development.Module NumPy) find_package(Dpctl REQUIRED) # -w is to set working directory (and correctly set __pyx_f[] array of filenames) -set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"") +set(CYTHON_ARGS -t -w "${CMAKE_SOURCE_DIR}") find_package(Cython REQUIRED) +include(UseCython) set(py_module_name _cython_api) set(_cy_source use_dpctl_sycl/_cython_api.pyx) -add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src) +cython_transpile(${_cy_source} LANGUAGE CXX OUTPUT_VARIABLE _generated_cy_src) Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src}) add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src}) target_include_directories(${py_module_name} PUBLIC include ${Dpctl_INCLUDE_DIRS}) @@ -33,14 +34,12 @@ target_link_libraries(${py_module_name} PRIVATE Python::NumPy) install(TARGETS ${py_module_name} DESTINATION use_dpctl_sycl) -foreach(_src_fn ${_sources}) - get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS) - set(_combined_options ${_compile_options} "-O3") - set_source_files_properties(${_src_fn} - PROPERTIES - COMPILE_OPTIONS "${_combined_options}" - ) -endforeach() +get_source_file_property(_compile_options ${_generated_cy_src} COMPILE_OPTIONS) +set(_combined_options ${_compile_options} "-O3") +set_source_files_properties(${_generated_cy_src} + PROPERTIES + COMPILE_OPTIONS "${_combined_options}" +) target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) set(ignoreMe "${SKBUILD}") diff --git a/examples/cython/use_dpctl_sycl/pyproject.toml b/examples/cython/use_dpctl_sycl/pyproject.toml index f69226c7f4..2861d83c7f 100644 --- a/examples/cython/use_dpctl_sycl/pyproject.toml +++ b/examples/cython/use_dpctl_sycl/pyproject.toml @@ -19,6 +19,7 @@ build-backend = "scikit_build_core.build" requires = [ "scikit-build-core>=0.8.0", "cython>=3.0.10", + "cython-cmake", "dpctl", "numpy" ] From 63e43cc21648f9aaa3e32db5a64d8369294afcf1 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 11 Mar 2026 23:42:13 -0700 Subject: [PATCH 10/14] fix cython example readmes --- examples/cython/sycl_buffer/README.md | 4 ++-- examples/cython/use_dpctl_sycl/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/cython/sycl_buffer/README.md b/examples/cython/sycl_buffer/README.md index 377310adb2..c36348c714 100644 --- a/examples/cython/sycl_buffer/README.md +++ b/examples/cython/sycl_buffer/README.md @@ -16,12 +16,12 @@ oneMKL. To compile the example on Linux, run: ```bash -CC=icx CXX=icpx python pip install . +CC=icx CXX=icpx python -m pip install . ``` On Windows, run: ```bash -CC=icx CXX=icx python pip install . +CC=icx CXX=icx python -m pip install . ``` ## Running diff --git a/examples/cython/use_dpctl_sycl/README.md b/examples/cython/use_dpctl_sycl/README.md index 43e3673aa9..368c9747ec 100644 --- a/examples/cython/use_dpctl_sycl/README.md +++ b/examples/cython/use_dpctl_sycl/README.md @@ -11,12 +11,12 @@ written in Cython. To build the example on Linux, run: ```bash -CC=icx CXX=icpx python pip install . +CC=icx CXX=icpx python -m pip install . ``` On Windows, run: ```bash -CC=icx CXX=icx python pip install . +CC=icx CXX=icx python -m pip install . ``` ## Testing From 1dbdae363d45096b92f7738c28f45d7baa942c75 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 12 Mar 2026 00:47:45 -0700 Subject: [PATCH 11/14] update oneMKL_gemv example --- examples/pybind11/onemkl_gemv/CMakeLists.txt | 8 +--- examples/pybind11/onemkl_gemv/README.md | 28 +++++++------- examples/pybind11/onemkl_gemv/pyproject.toml | 39 ++++++++++++++++++++ examples/pybind11/onemkl_gemv/setup.py | 26 ------------- 4 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 examples/pybind11/onemkl_gemv/pyproject.toml delete mode 100644 examples/pybind11/onemkl_gemv/setup.py diff --git a/examples/pybind11/onemkl_gemv/CMakeLists.txt b/examples/pybind11/onemkl_gemv/CMakeLists.txt index 08dda0b288..8eef2b3fa8 100644 --- a/examples/pybind11/onemkl_gemv/CMakeLists.txt +++ b/examples/pybind11/onemkl_gemv/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22...3.27 FATAL_ERROR) +cmake_minimum_required(VERSION 3.29 FATAL_ERROR) project(example_use_mkl_gemm VERSION 0.1 LANGUAGES CXX DESCRIPTION "Example of using Python wrapper to oneMKL function") @@ -27,12 +27,10 @@ FetchContent_MakeAvailable(pybind11) find_package(Python REQUIRED COMPONENTS Development.Module NumPy) find_package(Dpctl REQUIRED) -find_package(TBB REQUIRED) - set(MKL_ARCH "intel64") set(MKL_LINK "dynamic") set(MKL_THREADING "tbb_thread") -set(MKL_INTERFACE "ilp64") +set(MKL_INTERFACE "lp64") find_package(MKL REQUIRED) set(py_module_name _onemkl) @@ -65,5 +63,3 @@ target_compile_options(standalone_cpp ) target_include_directories(standalone_cpp PUBLIC sycl_gemm) target_link_libraries(standalone_cpp PRIVATE MKL::MKL_SYCL) - -set(ignoreMe "${SKBUILD}") diff --git a/examples/pybind11/onemkl_gemv/README.md b/examples/pybind11/onemkl_gemv/README.md index f3b1f2d2b5..a5aaa7aea9 100644 --- a/examples/pybind11/onemkl_gemv/README.md +++ b/examples/pybind11/onemkl_gemv/README.md @@ -7,24 +7,24 @@ To build on Linux, run: ```bash -python setup.py build_ext --inplace -- -G "Ninja" \ - -DCMAKE_C_COMPILER:PATH=icx \ - -DCMAKE_CXX_COMPILER:PATH=icpx \ - -DTBB_LIBRARY_DIR=$CONDA_PREFIX/lib \ - -DMKL_LIBRARY_DIR=${CONDA_PREFIX}/lib \ - -DMKL_INCLUDE_DIR=${CONDA_PREFIX}/include \ - -DTBB_INCLUDE_DIR=${CONDA_PREFIX}/include +pip install -e . \ + -Ccmake.define.CMAKE_C_COMPILER:PATH=icx \ + -Ccmake.define.CMAKE_CXX_COMPILER:PATH=icpx \ + -Ccmake.define.TBB_LIBRARY_DIR=$CONDA_PREFIX/lib \ + -Ccmake.define.MKL_LIBRARY_DIR=${CONDA_PREFIX}/lib \ + -Ccmake.define.MKL_INCLUDE_DIR=${CONDA_PREFIX}/include \ + -Ccmake.define.TBB_INCLUDE_DIR=${CONDA_PREFIX}/include ``` To build on Windows, run: ```bash -python setup.py build_ext --inplace -- -G "Ninja" \ - -DCMAKE_C_COMPILER:PATH=icx \ - -DCMAKE_CXX_COMPILER:PATH=icx \ - -DTBB_LIBRARY_DIR=$CONDA_PREFIX/lib \ - -DMKL_LIBRARY_DIR=${CONDA_PREFIX}/lib \ - -DMKL_INCLUDE_DIR=${CONDA_PREFIX}/include \ - -DTBB_INCLUDE_DIR=${CONDA_PREFIX}/include +pip install -e . \ + -Ccmake.define.CMAKE_C_COMPILER:PATH=icx \ + -Ccmake.define.CMAKE_CXX_COMPILER:PATH=icx \ + -Ccmake.define.TBB_LIBRARY_DIR=$CONDA_PREFIX/lib \ + -Ccmake.define.MKL_LIBRARY_DIR=${CONDA_PREFIX}/lib \ + -Ccmake.define.MKL_INCLUDE_DIR=${CONDA_PREFIX}/include \ + -Ccmake.define.TBB_INCLUDE_DIR=${CONDA_PREFIX}/include ``` ## Running diff --git a/examples/pybind11/onemkl_gemv/pyproject.toml b/examples/pybind11/onemkl_gemv/pyproject.toml new file mode 100644 index 0000000000..15f08096f4 --- /dev/null +++ b/examples/pybind11/onemkl_gemv/pyproject.toml @@ -0,0 +1,39 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "scikit_build_core.build" +requires = [ + "scikit-build-core>=0.8.0", + "dpctl", + "numpy >=1.23" +] + +[project] +authors = [{name = "Intel Corporation"}] +dependencies = ["numpy", "dpctl"] +description = "An example of SYCL-powered Python package (with pybind11)" +license = {text = "Apache 2.0"} +name = "sycl_gemm" +requires-python = ">=3.10" +version = "0.0.1" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +wheel.packages = ["sycl_gemm"] diff --git a/examples/pybind11/onemkl_gemv/setup.py b/examples/pybind11/onemkl_gemv/setup.py deleted file mode 100644 index 40de3b2e5b..0000000000 --- a/examples/pybind11/onemkl_gemv/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -# Data Parallel Control (dpctl) -# -# Copyright 2022 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from skbuild import setup - -setup( - name="sycl_gemm", - version="0.0.1", - description="an example of SYCL-powered Python package (with pybind11)", - author="Intel Scripting", - license="Apache 2.0", - packages=["sycl_gemm"], -) From 77e33bbfe11cfe69c8edb7a354bfa6a6ca7b9976 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 12 Mar 2026 00:48:02 -0700 Subject: [PATCH 12/14] remove unnecessary set(ignoreMe "${SKBUILD}") from CMake --- examples/cython/sycl_buffer/CMakeLists.txt | 2 -- examples/cython/use_dpctl_sycl/CMakeLists.txt | 2 -- examples/pybind11/external_usm_allocation/CMakeLists.txt | 2 -- examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt | 2 -- examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt | 2 -- 5 files changed, 10 deletions(-) diff --git a/examples/cython/sycl_buffer/CMakeLists.txt b/examples/cython/sycl_buffer/CMakeLists.txt index 690a4dc94c..d38e572848 100644 --- a/examples/cython/sycl_buffer/CMakeLists.txt +++ b/examples/cython/sycl_buffer/CMakeLists.txt @@ -41,5 +41,3 @@ set_source_files_properties(${_generated_cy_src} COMPILE_OPTIONS "${_combined_options}" ) target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) - -set(ignoreMe "${SKBUILD}") diff --git a/examples/cython/use_dpctl_sycl/CMakeLists.txt b/examples/cython/use_dpctl_sycl/CMakeLists.txt index a8f06f7cdc..f5ed5f304c 100644 --- a/examples/cython/use_dpctl_sycl/CMakeLists.txt +++ b/examples/cython/use_dpctl_sycl/CMakeLists.txt @@ -41,5 +41,3 @@ set_source_files_properties(${_generated_cy_src} COMPILE_OPTIONS "${_combined_options}" ) target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) - -set(ignoreMe "${SKBUILD}") diff --git a/examples/pybind11/external_usm_allocation/CMakeLists.txt b/examples/pybind11/external_usm_allocation/CMakeLists.txt index ccf64b4e72..155f6ab600 100644 --- a/examples/pybind11/external_usm_allocation/CMakeLists.txt +++ b/examples/pybind11/external_usm_allocation/CMakeLists.txt @@ -36,5 +36,3 @@ target_include_directories(${py_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) install(TARGETS ${py_module_name} DESTINATION external_usm_allocation ) - -set(ignoreMe "${SKBUILD}") diff --git a/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt b/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt index 5d8129581e..60a636370f 100644 --- a/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt +++ b/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt @@ -35,5 +35,3 @@ target_include_directories(${py_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) install(TARGETS ${py_module_name} DESTINATION use_kernel ) - -set(ignoreMe "${SKBUILD}") diff --git a/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt b/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt index 1534efd13e..34977542d4 100644 --- a/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt +++ b/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt @@ -34,5 +34,3 @@ target_include_directories(${py_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) install(TARGETS ${py_module_name} DESTINATION use_queue_device ) - -set(ignoreMe "${SKBUILD}") From 549a2ba177c45e8f8302d72fefec448e3ef78feb Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 12 Mar 2026 01:43:10 -0700 Subject: [PATCH 13/14] update use_dpctl_sycl_kernel example --- examples/pybind11/onemkl_gemv/README.md | 4 +- .../use_dpctl_sycl_kernel/CMakeLists.txt | 14 +++---- .../pybind11/use_dpctl_sycl_kernel/README.md | 2 +- .../pybind11/use_dpctl_sycl_kernel/example.py | 5 ++- .../use_dpctl_sycl_kernel/pyproject.toml | 39 ++++++++++++++++++ .../pybind11/use_dpctl_sycl_kernel/setup.py | 26 ------------ .../{ => src}/use_kernel/__init__.py | 0 .../{ => src}/use_kernel/_example.cpp | 0 .../{ => src/use_kernel}/resource/README.md | 0 .../use_kernel}/resource/double_it.cl | 0 .../use_kernel}/resource/double_it.spv | Bin .../tests/test_user_kernel.py | 3 +- 12 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 examples/pybind11/use_dpctl_sycl_kernel/pyproject.toml delete mode 100644 examples/pybind11/use_dpctl_sycl_kernel/setup.py rename examples/pybind11/use_dpctl_sycl_kernel/{ => src}/use_kernel/__init__.py (100%) rename examples/pybind11/use_dpctl_sycl_kernel/{ => src}/use_kernel/_example.cpp (100%) rename examples/pybind11/use_dpctl_sycl_kernel/{ => src/use_kernel}/resource/README.md (100%) rename examples/pybind11/use_dpctl_sycl_kernel/{ => src/use_kernel}/resource/double_it.cl (100%) rename examples/pybind11/use_dpctl_sycl_kernel/{ => src/use_kernel}/resource/double_it.spv (100%) diff --git a/examples/pybind11/onemkl_gemv/README.md b/examples/pybind11/onemkl_gemv/README.md index a5aaa7aea9..2a67080a3f 100644 --- a/examples/pybind11/onemkl_gemv/README.md +++ b/examples/pybind11/onemkl_gemv/README.md @@ -7,7 +7,7 @@ To build on Linux, run: ```bash -pip install -e . \ +python -m pip install -e . \ -Ccmake.define.CMAKE_C_COMPILER:PATH=icx \ -Ccmake.define.CMAKE_CXX_COMPILER:PATH=icpx \ -Ccmake.define.TBB_LIBRARY_DIR=$CONDA_PREFIX/lib \ @@ -18,7 +18,7 @@ pip install -e . \ To build on Windows, run: ```bash -pip install -e . \ +python -m pip install -e . \ -Ccmake.define.CMAKE_C_COMPILER:PATH=icx \ -Ccmake.define.CMAKE_CXX_COMPILER:PATH=icx \ -Ccmake.define.TBB_LIBRARY_DIR=$CONDA_PREFIX/lib \ diff --git a/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt b/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt index 60a636370f..4e2c40e08a 100644 --- a/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt +++ b/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt @@ -25,13 +25,11 @@ find_package(Python REQUIRED COMPONENTS Development.Module NumPy) find_package(Dpctl REQUIRED) set(py_module_name _use_kernel) -set(_sources use_kernel/_example.cpp) -pybind11_add_module(${py_module_name} - MODULE - ${_sources} -) +set(_sources src/use_kernel/_example.cpp) +pybind11_add_module(${py_module_name} MODULE ${_sources}) add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_sources}) target_include_directories(${py_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) -install(TARGETS ${py_module_name} - DESTINATION use_kernel -) +install(TARGETS ${py_module_name} DESTINATION use_kernel) + +# explicitly install the SPIR-V resources +install(DIRECTORY src/use_kernel/resource DESTINATION use_kernel) diff --git a/examples/pybind11/use_dpctl_sycl_kernel/README.md b/examples/pybind11/use_dpctl_sycl_kernel/README.md index 77aa57bf6e..e99c20cb3b 100644 --- a/examples/pybind11/use_dpctl_sycl_kernel/README.md +++ b/examples/pybind11/use_dpctl_sycl_kernel/README.md @@ -12,7 +12,7 @@ Pybind11 extensions. To build the extension, run: ``` source /opt/intel/oneapi/compiler/latest/env/vars.sh -CXX=icpx python setup.py build_ext --inplace +CXX=icpx python -m pip install . python -m pytest tests python example.py ``` diff --git a/examples/pybind11/use_dpctl_sycl_kernel/example.py b/examples/pybind11/use_dpctl_sycl_kernel/example.py index 272f32cdbf..71e2c9a166 100644 --- a/examples/pybind11/use_dpctl_sycl_kernel/example.py +++ b/examples/pybind11/use_dpctl_sycl_kernel/example.py @@ -16,6 +16,8 @@ # coding: utf-8 +import os + import numpy as np import use_kernel as eg @@ -27,7 +29,8 @@ q = dpctl.SyclQueue() # read SPIR-V: a program in Khronos standardized intermediate form -with open("resource/double_it.spv", "br") as fh: +eg_dir = os.path.dirname(os.path.abspath(eg.__file__)) +with open(os.path.join(eg_dir, "resource", "double_it.spv"), "br") as fh: il = fh.read() # Build the program for the selected device diff --git a/examples/pybind11/use_dpctl_sycl_kernel/pyproject.toml b/examples/pybind11/use_dpctl_sycl_kernel/pyproject.toml new file mode 100644 index 0000000000..cdd862f27d --- /dev/null +++ b/examples/pybind11/use_dpctl_sycl_kernel/pyproject.toml @@ -0,0 +1,39 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "scikit_build_core.build" +requires = [ + "scikit-build-core>=0.8.0", + "dpctl", + "numpy >=1.23" +] + +[project] +authors = [{name = "Intel Corporation"}] +dependencies = ["numpy", "dpctl"] +description = "An example of SYCL-powered Python package (with pybind11)" +license = {text = "Apache 2.0"} +name = "use_kernel" +requires-python = ">=3.10" +version = "0.0.1" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +wheel.packages = ["src/use_kernel"] diff --git a/examples/pybind11/use_dpctl_sycl_kernel/setup.py b/examples/pybind11/use_dpctl_sycl_kernel/setup.py deleted file mode 100644 index 3dd470e50c..0000000000 --- a/examples/pybind11/use_dpctl_sycl_kernel/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -# Data Parallel Control (dpctl) -# -# Copyright 2022 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from skbuild import setup - -setup( - name="use_kernel", - version="0.0.1", - description="an example of SYCL-powered Python package (with pybind11)", - author="Intel Scripting", - license="Apache 2.0", - packages=["use_kernel"], -) diff --git a/examples/pybind11/use_dpctl_sycl_kernel/use_kernel/__init__.py b/examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/__init__.py similarity index 100% rename from examples/pybind11/use_dpctl_sycl_kernel/use_kernel/__init__.py rename to examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/__init__.py diff --git a/examples/pybind11/use_dpctl_sycl_kernel/use_kernel/_example.cpp b/examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/_example.cpp similarity index 100% rename from examples/pybind11/use_dpctl_sycl_kernel/use_kernel/_example.cpp rename to examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/_example.cpp diff --git a/examples/pybind11/use_dpctl_sycl_kernel/resource/README.md b/examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/resource/README.md similarity index 100% rename from examples/pybind11/use_dpctl_sycl_kernel/resource/README.md rename to examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/resource/README.md diff --git a/examples/pybind11/use_dpctl_sycl_kernel/resource/double_it.cl b/examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/resource/double_it.cl similarity index 100% rename from examples/pybind11/use_dpctl_sycl_kernel/resource/double_it.cl rename to examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/resource/double_it.cl diff --git a/examples/pybind11/use_dpctl_sycl_kernel/resource/double_it.spv b/examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/resource/double_it.spv similarity index 100% rename from examples/pybind11/use_dpctl_sycl_kernel/resource/double_it.spv rename to examples/pybind11/use_dpctl_sycl_kernel/src/use_kernel/resource/double_it.spv diff --git a/examples/pybind11/use_dpctl_sycl_kernel/tests/test_user_kernel.py b/examples/pybind11/use_dpctl_sycl_kernel/tests/test_user_kernel.py index f061697442..b5bd407942 100644 --- a/examples/pybind11/use_dpctl_sycl_kernel/tests/test_user_kernel.py +++ b/examples/pybind11/use_dpctl_sycl_kernel/tests/test_user_kernel.py @@ -29,8 +29,7 @@ def _get_spv_path(): uk_dir = os.path.dirname(os.path.abspath(uk.__file__)) - proj_dir = os.path.dirname(uk_dir) - return os.path.join(proj_dir, "resource", "double_it.spv") + return os.path.join(uk_dir, "resource", "double_it.spv") def test_spv_file_exists(): From fd7a5c24d7df0c13a56e2dffd194d82dd4ad7e22 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 12 Mar 2026 01:47:11 -0700 Subject: [PATCH 14/14] update use_dpctl_sycl_queue example --- .../use_dpctl_sycl_queue/CMakeLists.txt | 11 ++---- .../pybind11/use_dpctl_sycl_queue/README.md | 10 +++-- .../use_dpctl_sycl_queue/pyproject.toml | 39 +++++++++++++++++++ .../pybind11/use_dpctl_sycl_queue/setup.py | 26 ------------- .../{ => src}/use_queue_device/__init__.py | 0 .../{ => src}/use_queue_device/_example.cpp | 0 6 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 examples/pybind11/use_dpctl_sycl_queue/pyproject.toml delete mode 100644 examples/pybind11/use_dpctl_sycl_queue/setup.py rename examples/pybind11/use_dpctl_sycl_queue/{ => src}/use_queue_device/__init__.py (100%) rename examples/pybind11/use_dpctl_sycl_queue/{ => src}/use_queue_device/_example.cpp (100%) diff --git a/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt b/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt index 34977542d4..d87da553e3 100644 --- a/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt +++ b/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt @@ -24,13 +24,8 @@ find_package(Python REQUIRED COMPONENTS Development.Module NumPy) find_package(Dpctl REQUIRED) set(py_module_name _use_queue_device) -set(_sources use_queue_device/_example.cpp) -pybind11_add_module(${py_module_name} - MODULE - ${_sources} -) +set(_sources src/use_queue_device/_example.cpp) +pybind11_add_module(${py_module_name} MODULE ${_sources}) add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_sources}) target_include_directories(${py_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) -install(TARGETS ${py_module_name} - DESTINATION use_queue_device -) +install(TARGETS ${py_module_name} DESTINATION use_queue_device) diff --git a/examples/pybind11/use_dpctl_sycl_queue/README.md b/examples/pybind11/use_dpctl_sycl_queue/README.md index 5eb8cbc1ef..b59ec9f950 100644 --- a/examples/pybind11/use_dpctl_sycl_queue/README.md +++ b/examples/pybind11/use_dpctl_sycl_queue/README.md @@ -12,7 +12,7 @@ extensions. To build the extension, run: ``` source /opt/intel/oneapi/compiler/latest/env/vars.sh -CXX=icpx python setup.py build_ext --inplace +CXX=icpx python -m pip install . python -m pytest tests python example.py ``` @@ -20,9 +20,11 @@ python example.py # Sample output ``` -(idp) [17:25:27 ansatnuc04 use_dpctl_syclqueue]$ python example.py -EU count returned by Pybind11 extension 24 -EU count computed by dpctl 24 +$ python example.py +EU count returned by Pybind11 extension 96 +EU count computed by dpctl 96 +Device's global memory size: 7445078016 bytes +Device's local memory size: 65536 bytes Computing modular reduction using SYCL on a NumPy array Offloaded result agrees with reference one computed by NumPy diff --git a/examples/pybind11/use_dpctl_sycl_queue/pyproject.toml b/examples/pybind11/use_dpctl_sycl_queue/pyproject.toml new file mode 100644 index 0000000000..a646605e51 --- /dev/null +++ b/examples/pybind11/use_dpctl_sycl_queue/pyproject.toml @@ -0,0 +1,39 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[build-system] +build-backend = "scikit_build_core.build" +requires = [ + "scikit-build-core>=0.8.0", + "dpctl", + "numpy >=1.23" +] + +[project] +authors = [{name = "Intel Corporation"}] +dependencies = ["numpy", "dpctl"] +description = "An example of SYCL-powered Python package (with pybind11)" +license = {text = "Apache 2.0"} +name = "use_queue_device" +requires-python = ">=3.10" +version = "0.0.1" + +[project.urls] +Repository = "https://github.com/IntelPython/dpctl" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +wheel.packages = ["src/use_queue_device"] diff --git a/examples/pybind11/use_dpctl_sycl_queue/setup.py b/examples/pybind11/use_dpctl_sycl_queue/setup.py deleted file mode 100644 index 1b53d74668..0000000000 --- a/examples/pybind11/use_dpctl_sycl_queue/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -# Data Parallel Control (dpctl) -# -# Copyright 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from skbuild import setup - -setup( - name="use_queue_device", - version="0.0.1", - description="an example of SYCL-powered Python package (with pybind11)", - author="Intel Scripting", - license="Apache 2.0", - packages=["use_queue_device"], -) diff --git a/examples/pybind11/use_dpctl_sycl_queue/use_queue_device/__init__.py b/examples/pybind11/use_dpctl_sycl_queue/src/use_queue_device/__init__.py similarity index 100% rename from examples/pybind11/use_dpctl_sycl_queue/use_queue_device/__init__.py rename to examples/pybind11/use_dpctl_sycl_queue/src/use_queue_device/__init__.py diff --git a/examples/pybind11/use_dpctl_sycl_queue/use_queue_device/_example.cpp b/examples/pybind11/use_dpctl_sycl_queue/src/use_queue_device/_example.cpp similarity index 100% rename from examples/pybind11/use_dpctl_sycl_queue/use_queue_device/_example.cpp rename to examples/pybind11/use_dpctl_sycl_queue/src/use_queue_device/_example.cpp