Skip to content

Commit ee628f4

Browse files
committed
implement dpnp.piecewise
1 parent 30918e4 commit ee628f4

File tree

13 files changed

+1622
-3
lines changed

13 files changed

+1622
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* Added `timeout-minutes` property to GitHub jobs [#2526](https://github.com/IntelPython/dpnp/pull/2526)
1616
* Added implementation of `dpnp.ndarray.data` and `dpnp.ndarray.data.ptr` attributes [#2521](https://github.com/IntelPython/dpnp/pull/2521)
1717
* Added `dpnp.ndarray.__contains__` method [#2534](https://github.com/IntelPython/dpnp/pull/2534)
18+
* Added implementation of `dpnp.piecewise` [#2550](https://github.com/IntelPython/dpnp/pull/2550)
1819

1920
### Changed
2021

dpnp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ endfunction()
5858
add_subdirectory(backend)
5959
add_subdirectory(backend/extensions/blas)
6060
add_subdirectory(backend/extensions/fft)
61+
add_subdirectory(backend/extensions/functional)
6162
add_subdirectory(backend/extensions/indexing)
6263
add_subdirectory(backend/extensions/lapack)
6364
add_subdirectory(backend/extensions/statistics)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2025, Intel Corporation
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# - Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# - Redistributions in binary form must reproduce the above copyright notice,
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
#
13+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
# THE POSSIBILITY OF SUCH DAMAGE.
24+
# *****************************************************************************
25+
26+
27+
set(python_module_name _functional_impl)
28+
set(_module_src
29+
${CMAKE_CURRENT_SOURCE_DIR}/piecewise.cpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/functional_py.cpp
31+
)
32+
33+
pybind11_add_module(${python_module_name} MODULE ${_module_src})
34+
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
35+
36+
if(_dpnp_sycl_targets)
37+
# make fat binary
38+
target_compile_options(
39+
${python_module_name}
40+
PRIVATE
41+
${_dpnp_sycl_target_compile_options}
42+
)
43+
target_link_options(
44+
${python_module_name}
45+
PRIVATE
46+
${_dpnp_sycl_target_link_options}
47+
)
48+
endif()
49+
50+
if (WIN32)
51+
if (${CMAKE_VERSION} VERSION_LESS "3.27")
52+
# this is a work-around for target_link_options inserting option after -link option, cause
53+
# linker to ignore it.
54+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsycl-device-code-split=per_kernel")
55+
endif()
56+
endif()
57+
58+
set_target_properties(${python_module_name} PROPERTIES CMAKE_POSITION_INDEPENDENT_CODE ON)
59+
60+
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
61+
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
62+
63+
target_include_directories(${python_module_name} PUBLIC ${Dpctl_INCLUDE_DIR})
64+
target_include_directories(${python_module_name} PUBLIC ${Dpctl_TENSOR_INCLUDE_DIR})
65+
66+
if (WIN32)
67+
target_compile_options(${python_module_name} PRIVATE
68+
/clang:-fno-approx-func
69+
/clang:-fno-finite-math-only
70+
)
71+
else()
72+
target_compile_options(${python_module_name} PRIVATE
73+
-fno-approx-func
74+
-fno-finite-math-only
75+
)
76+
endif()
77+
78+
target_link_options(${python_module_name} PUBLIC -fsycl-device-code-split=per_kernel)
79+
80+
if (DPNP_GENERATE_COVERAGE)
81+
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
82+
endif()
83+
84+
if (DPNP_WITH_REDIST)
85+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
86+
endif()
87+
88+
install(TARGETS ${python_module_name}
89+
DESTINATION "dpnp/backend/extensions/functional"
90+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//*****************************************************************************
2+
// Copyright (c) 2025, Intel Corporation
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
// - Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// - Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
// THE POSSIBILITY OF SUCH DAMAGE.
24+
//*****************************************************************************
25+
//
26+
// This file defines functions of dpnp.backend._functional_impl extensions
27+
//
28+
//*****************************************************************************
29+
30+
#include <pybind11/pybind11.h>
31+
#include <pybind11/stl.h>
32+
33+
#include "piecewise.hpp"
34+
35+
namespace functional_ns = dpnp::extensions::functional;
36+
namespace py = pybind11;
37+
38+
PYBIND11_MODULE(_functional_impl, m)
39+
{
40+
{
41+
functional_ns::init_piecewise_dispatch_vectors();
42+
43+
m.def("_piecewise", functional_ns::py_piecewise,
44+
"Call piecewise kernel", py::arg("sycl_queue"), py::arg("value"),
45+
py::arg("condition"), py::arg("result"),
46+
py::arg("depends") = py::list());
47+
}
48+
}

0 commit comments

Comments
 (0)