Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
* Unified public API definitions in `dpnp.linalg` and `dpnp.scipy` submodules [#2663](https://github.com/IntelPython/dpnp/pull/2663)
* Aligned the signature of `dpnp.reshape` function with Python array API by making `shape` a required argument [#2673](https://github.com/IntelPython/dpnp/pull/2673)
* Unified `dpnp` public API exports by consolidating function exports in `__init__.py` and removing wildcard imports [#2665](https://github.com/IntelPython/dpnp/pull/2665) [#2666](https://github.com/IntelPython/dpnp/pull/2666)
* Changed the build scripts and documentation due to `python setup.py develop` deprecation notice [#2172](https://github.com/IntelPython/dpnp/pull/2172)

### Deprecated

Expand Down
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ set(DPNP_TARGET_CUDA
Set to a truthy value (e.g., ON, TRUE) to use default architecture (sm_50), \
or to a specific architecture like sm_80."
)
set(HIP_TARGETS "" CACHE STRING "HIP architecture for target")
set(DPNP_TARGET_HIP "" CACHE STRING "HIP architecture for target")

set(_dpnp_sycl_targets)
set(_use_onemath OFF)
Expand Down Expand Up @@ -135,18 +135,22 @@ if("x${DPNP_SYCL_TARGETS}" STREQUAL "x")
set(_use_onemath_cuda ON)
endif()

if(HIP_TARGETS)
if(HIP_TARGETS MATCHES "^gfx")
if(DPNP_TARGET_HIP)
if(DPNP_TARGET_HIP MATCHES "^gfx")
if("x${_dpnp_sycl_targets}" STREQUAL "x")
set(_dpnp_sycl_targets "amd_gpu_${HIP_TARGETS},spir64-unknown-unknown")
set(_dpnp_sycl_targets
"amd_gpu_${DPNP_TARGET_HIP},spir64-unknown-unknown"
)
else()
set(_dpnp_sycl_targets "amd_gpu_${HIP_TARGETS},${_dpnp_sycl_targets}")
set(_dpnp_sycl_targets
"amd_gpu_${DPNP_TARGET_HIP},${_dpnp_sycl_targets}"
)
endif()
set(_use_onemath_hip ON)
else()
message(
FATAL_ERROR
"Invalid value for HIP_TARGETS: \"${HIP_TARGETS}\". "
"Invalid value for DPNP_TARGET_HIP: \"${DPNP_TARGET_HIP}\". "
"Expected an architecture name starting with 'gfx', e.g. 'gfx1030'."
)
endif()
Expand All @@ -161,8 +165,11 @@ else()
if("${DPNP_SYCL_TARGETS}" MATCHES "amd_gpu_")
set(_use_onemath_hip ON)

if("x${HIP_TARGETS}" STREQUAL "x")
message(FATAL_ERROR "HIP_TARGETS must be specified when using HIP backend")
if("x${DPNP_TARGET_HIP}" STREQUAL "x")
message(
FATAL_ERROR
"DPNP_TARGET_HIP must be specified when using HIP backend"
)
endif()
endif()

Expand Down
11 changes: 0 additions & 11 deletions doc/0.builddoc.sh

This file was deleted.

6 changes: 4 additions & 2 deletions doc/quick_start_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ To build and install the package on Linux OS, run:

.. code-block:: bash

python setup.py install -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx
python setup.py build_ext --inplace -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx
python -m pip install -e .

To build and install the package on Windows OS, run:

.. code-block:: bash

python setup.py install -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx
python setup.py build_ext --inplace -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx
python -m pip install -e .

Alternatively, to develop on Linux OS, you can use the driver script:

Expand Down
243 changes: 243 additions & 0 deletions scripts/_build_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
# *****************************************************************************
# Copyright (c) 2026, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

import os
import shutil
import subprocess
import sys
import warnings


def get_dpctl_cmake_dir():
"""
If dpctl is locally built using `script/build_locally.py`, it is needed
to pass the -DDpctl_ROOT=$(python -m dpctl --cmakedir) during the build.
If dpctl is conda installed, it is optional to pass this parameter.

"""

process = subprocess.Popen(
["python", "-m", "dpctl", "--cmakedir"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
output, error = process.communicate()
if process.returncode == 0:
return output.decode("utf-8").strip()

raise RuntimeError(
"Failed to retrieve dpctl cmake directory: "
+ error.decode("utf-8").strip()
)


def resolve_compilers(
oneapi: bool,
c_compiler: str,
cxx_compiler: str,
compiler_root: str,
):
is_linux = "linux" in sys.platform

if oneapi or (
c_compiler is None and cxx_compiler is None and compiler_root is None
):
return "icx", ("icpx" if is_linux else "icx")

if (
(c_compiler is None or not os.path.isabs(c_compiler))
and (cxx_compiler is None or not os.path.isabs(cxx_compiler))
and (not compiler_root or not os.path.exists(compiler_root))
):
raise RuntimeError(
"--compiler-root option must be set when using non-default DPC++ "
"layout unless absolute paths are provided for both compilers"
)

# default values
if c_compiler is None:
c_compiler = "icx"
if cxx_compiler is None:
cxx_compiler = "icpx" if is_linux else "icx"

for name, opt_name in (
(c_compiler, "--c-compiler"),
(cxx_compiler, "--cxx-compiler"),
):
if os.path.isabs(name):
path = name
else:
path = os.path.join(compiler_root, name)
if not os.path.exists(path):
raise RuntimeError(f"{opt_name} value {name} not found")
return c_compiler, cxx_compiler


def resolve_onemath(
onemath: bool,
onemath_dir: str,
target_cuda: str = None,
target_hip: str = None,
onemkl_interfaces: bool = False,
onemkl_interfaces_dir: str = None,
):
# always enable build with oneMath i/f when oneMath path is passed
if onemath_dir:
onemath = True

# always enable build with oneMath i/f for CUDA or HIP target
if target_cuda or target_hip:
onemath = True

# TODO: onemkl_interfaces and onemkl_interfaces_dir are deprecated in
# dpnp-0.19.0 and should be removed in dpnp-0.20.0.
if onemkl_interfaces:
warnings.warn(
"Using 'onemkl_interfaces' is deprecated. Please use 'onemath' instead.",
DeprecationWarning,
stacklevel=1,
)
onemath = True
if onemkl_interfaces_dir is not None:
warnings.warn(
"Using 'onemkl_interfaces_dir' is deprecated. Please use 'onemath_dir' instead.",
DeprecationWarning,
stacklevel=1,
)
onemath_dir = onemkl_interfaces_dir
return onemath, onemath_dir


def run(cmd: list[str], env: dict[str, str] = None, cwd: str = None):
print("+", " ".join(cmd))
subprocess.check_call(
cmd, env=env or os.environ.copy(), cwd=cwd or os.getcwd()
)


def capture_cmd_output(cmd: list[str], cwd: str = None):
print("+", " ".join(cmd))
return (
subprocess.check_output(cmd, cwd=cwd or os.getcwd())
.decode("utf-8")
.strip("\n")
)


def err(msg: str, script: str):
raise RuntimeError(f"[{script}] error: {msg}")


def log_cmake_args(cmake_args: list[str], script: str):
print(f"[{script}] Using CMake args:\n{' '.join(cmake_args)}")


def make_cmake_args(
c_compiler: str = None,
cxx_compiler: str = None,
dpctl_cmake_dir: str = None,
onemath: bool = False,
onemath_dir: str = None,
verbose: bool = False,
other_opts: str = None,
):
args = [
f"-DCMAKE_C_COMPILER:PATH={c_compiler}" if c_compiler else "",
f"-DCMAKE_CXX_COMPILER:PATH={cxx_compiler}" if cxx_compiler else "",
f"-DDpctl_ROOT={dpctl_cmake_dir}" if dpctl_cmake_dir else "",
]

if onemath:
args.append("-DDPNP_USE_ONEMATH=ON")
if onemath_dir:
args.append(f"-DDPNP_ONEMATH_DIR={onemath_dir}")

if verbose:
args.append("-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
if other_opts:
args.extend(other_opts.split())

return args


def build_extension(
setup_dir: str,
env: dict[str, str],
cmake_args: list[str],
cmake_executable: str = None,
generator: str = None,
build_type: str = None,
):
cmd = [sys.executable, "setup.py", "build_ext", "--inplace"]
if cmake_executable:
cmd.append(f"--cmake-executable={cmake_executable}")
if generator:
cmd.append(f"--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,
)


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,
)


def clean_build_dir(setup_dir: str):
if (
not isinstance(setup_dir, str)
or not setup_dir
or not os.path.isdir(setup_dir)
):
raise RuntimeError(f"Invalid setup directory provided: '{setup_dir}'")
target = os.path.join(setup_dir, "_skbuild")
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
Loading
Loading