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/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 27af8f55a0..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] @@ -47,8 +46,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') }} @@ -61,7 +58,6 @@ test: - {{ compiler('cxx') }} - {{ stdlib('c') }} - cython - - setuptools - pytest about: 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..dac55fac40 100644 --- a/dpctl/CMakeLists.txt +++ b/dpctl/CMakeLists.txt @@ -2,8 +2,9 @@ find_package(Python REQUIRED COMPONENTS NumPy) # -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 @@ -106,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}) @@ -164,18 +164,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/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", diff --git a/examples/cython/sycl_buffer/CMakeLists.txt b/examples/cython/sycl_buffer/CMakeLists.txt index a30fbb2f35..d38e572848 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,10 @@ 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/README.md b/examples/cython/sycl_buffer/README.md index 6cda697dcf..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 setup.py build_ext --inplace -G Ninja +CC=icx CXX=icpx python -m pip install . ``` On Windows, run: ```bash -CC=icx CXX=icx python setup.py build_ext --inplace -G Ninja +CC=icx CXX=icx python -m 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..14d7d7dec9 --- /dev/null +++ b/examples/cython/sycl_buffer/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", + "cython-cmake", + "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/CMakeLists.txt b/examples/cython/use_dpctl_sycl/CMakeLists.txt index 9445ae08f3..f5ed5f304c 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,10 @@ 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/README.md b/examples/cython/use_dpctl_sycl/README.md index e6041d12aa..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 setup.py build_ext --inplace -G Ninja +CC=icx CXX=icpx python -m pip install . ``` On Windows, run: ```bash -CC=icx CXX=icx python setup.py build_ext --inplace -G Ninja +CC=icx CXX=icx python -m 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..2861d83c7f --- /dev/null +++ b/examples/cython/use_dpctl_sycl/pyproject.toml @@ -0,0 +1,41 @@ +# 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", + "cython-cmake", + "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"], -) diff --git a/examples/pybind11/external_usm_allocation/CMakeLists.txt b/examples/pybind11/external_usm_allocation/CMakeLists.txt index b2462852cf..155f6ab600 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 @@ -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/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 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..2a67080a3f 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 +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 \ + -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 +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 \ + -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"], -) diff --git a/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt b/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt index 5d8129581e..4e2c40e08a 100644 --- a/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt +++ b/examples/pybind11/use_dpctl_sycl_kernel/CMakeLists.txt @@ -25,15 +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) -set(ignoreMe "${SKBUILD}") +# 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(): diff --git a/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt b/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt index 1534efd13e..d87da553e3 100644 --- a/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt +++ b/examples/pybind11/use_dpctl_sycl_queue/CMakeLists.txt @@ -24,15 +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 -) - -set(ignoreMe "${SKBUILD}") +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 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..fca50a891a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,12 @@ [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" + "cython-cmake", + "numpy >=1.26.0" ] [project] @@ -58,7 +53,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 +144,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/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") 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, -)