Skip to content

Commit a30b573

Browse files
Merge branch 'master' into feature/dlpack-kdlcpu-support
2 parents 2bd92df + ff0d4ea commit a30b573

File tree

24 files changed

+474
-86
lines changed

24 files changed

+474
-86
lines changed

.github/workflows/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @oleksandr-pavlyk @ndgrigorian

.github/workflows/conda-package.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ jobs:
6262
$CHANNELS \
6363
conda-recipe
6464
- name: Upload artifact
65-
uses: actions/[email protected].4
65+
uses: actions/[email protected].5
6666
with:
6767
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
6868
path: /usr/share/miniconda/conda-bld/linux-64/${{ env.PACKAGE_NAME }}-*.tar.bz2
6969
- name: Upload wheels artifact
70-
uses: actions/[email protected].4
70+
uses: actions/[email protected].5
7171
with:
7272
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
7373
path: ${{ env.WHEELS_OUTPUT_FOLDER }}${{ env.PACKAGE_NAME }}-*.whl
@@ -111,12 +111,12 @@ jobs:
111111
OVERRIDE_INTEL_IPO: 1 # IPO requires more resources that GH actions VM provides
112112
run: conda build --no-test --python ${{ matrix.python }} -c dppy/label/bootstrap -c ${{ env.INTEL_CHANNEL }} -c conda-forge --override-channels conda-recipe
113113
- name: Upload artifact
114-
uses: actions/[email protected].4
114+
uses: actions/[email protected].5
115115
with:
116116
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
117117
path: ${{ env.conda-bld }}${{ env.PACKAGE_NAME }}-*.tar.bz2
118118
- name: Upload wheels artifact
119-
uses: actions/[email protected].4
119+
uses: actions/[email protected].5
120120
with:
121121
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
122122
path: ${{ env.WHEELS_OUTPUT_FOLDER }}${{ env.PACKAGE_NAME }}-*.whl

.github/workflows/generate-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
git push tokened_docs gh-pages
105105
- name: Save built docs as an artifact
106106
if: ${{ github.event.pull_request && github.event.pull_request.head.repo.fork && github.event.action != 'closed'}}
107-
uses: actions/[email protected].4
107+
uses: actions/[email protected].5
108108
with:
109109
name: ${{ env.PACKAGE_NAME }} rendered documentation
110110
path: ~/docs

.github/workflows/openssf-scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6161
# format to the repository Actions tab.
6262
- name: "Upload artifact"
63-
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
63+
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
6464
with:
6565
name: SARIF file
6666
path: results.sarif

conda-recipe/build.sh

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ CMAKE_ARGS="${CMAKE_ARGS} -DDPCTL_LEVEL_ZERO_INCLUDE_DIR=${PREFIX}/include/level
2727
# -wnx flags mean: --wheel --no-isolation --skip-dependency-check
2828
${PYTHON} -m build -w -n -x
2929

30-
pushd dist
31-
${PYTHON} -m wheel unpack -d dpctl_wheel dpctl*.whl
32-
export lib_name=libDPCTLSyclInterface
33-
export so_full_path=$(find dpctl_wheel -regextype posix-extended -regex "^.*${lib_name}\.so")
34-
export sox_full_path=$(find dpctl_wheel -regextype posix-extended -regex "^.*${lib_name}\.so\.[0-9]*$")
35-
export soxxx_full_path=$(find dpctl_wheel -regextype posix-extended -regex "^.*${lib_name}\.so\.[0-9]*\.[0-9]*$")
36-
37-
rm -rf ${so_full_path} ${soxxx_full_path}
38-
39-
export so_name=$(basename ${so_full_path})
40-
export sox_name=$(basename ${sox_full_path})
41-
export soxxx_name=$(basename ${soxxx_full_path})
42-
export wheel_path=$(dirname $(dirname ${so_full_path}))
43-
44-
# deal with hard copies
45-
${PYTHON} -m wheel pack ${wheel_path}
46-
47-
rm -rf dpctl_wheel
48-
popd
49-
5030
${PYTHON} -m wheel tags --remove --build "$GIT_DESCRIBE_NUMBER" \
5131
--platform-tag "manylinux_${GLIBC_MAJOR}_${GLIBC_MINOR}_x86_64" \
5232
dist/dpctl*.whl
@@ -59,15 +39,6 @@ ${PYTHON} -m pip install dist/dpctl*.whl \
5939
--prefix "${PREFIX}" \
6040
-vv
6141

62-
export libdir=$(find $PREFIX -name 'libDPCTLSyclInterface*' -exec dirname \{\} \;)
63-
64-
# Recover symbolic links
65-
# libDPCTLSyclInterface.so.0 -> libDPCTLSyclInterface.so.0.17
66-
# libDPCTLSyclInterface.so -> libDPCTLSyclInterface.so.0
67-
mv ${libdir}/${sox_name} ${libdir}/${soxxx_name}
68-
ln -s ${libdir}/${soxxx_name} ${libdir}/${sox_name}
69-
ln -s ${libdir}/${sox_name} ${libdir}/${so_name}
70-
7142
# Copy wheel package
7243
if [[ -d "${WHEELS_OUTPUT_FOLDER}" ]]; then
7344
cp dist/dpctl*.whl "${WHEELS_OUTPUT_FOLDER[@]}"

docs/doc_sources/api_reference/dpctl/tensor.indexing_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ by either integral arrays of indices or boolean mask arrays.
1515
place
1616
put
1717
take
18+
take_along_axis

dpctl/apis/include/dpctl4pybind11.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "dpctl_capi.h"
2929
#include <complex>
30+
#include <exception>
3031
#include <memory>
3132
#include <pybind11/pybind11.h>
3233
#include <sycl/sycl.hpp>
@@ -748,6 +749,53 @@ class usm_memory : public py::object
748749
throw py::error_already_set();
749750
}
750751

752+
/*! @brief Create usm_memory object from shared pointer that manages
753+
* lifetime of the USM allocation.
754+
*/
755+
usm_memory(void *usm_ptr,
756+
size_t nbytes,
757+
const sycl::queue &q,
758+
std::shared_ptr<void> shptr)
759+
{
760+
auto const &api = ::dpctl::detail::dpctl_capi::get();
761+
DPCTLSyclUSMRef usm_ref = reinterpret_cast<DPCTLSyclUSMRef>(usm_ptr);
762+
auto q_uptr = std::make_unique<sycl::queue>(q);
763+
DPCTLSyclQueueRef QRef =
764+
reinterpret_cast<DPCTLSyclQueueRef>(q_uptr.get());
765+
766+
auto vacuous_destructor = []() {};
767+
py::capsule mock_owner(vacuous_destructor);
768+
769+
// create memory object owned by mock_owner, it is a new reference
770+
PyObject *_memory =
771+
api.Memory_Make_(usm_ref, nbytes, QRef, mock_owner.ptr());
772+
auto ref_count_decrementer = [](PyObject *o) noexcept { Py_DECREF(o); };
773+
774+
using py_uptrT =
775+
std::unique_ptr<PyObject, decltype(ref_count_decrementer)>;
776+
777+
if (!_memory) {
778+
throw py::error_already_set();
779+
}
780+
781+
auto memory_uptr = py_uptrT(_memory, ref_count_decrementer);
782+
std::shared_ptr<void> *opaque_ptr = new std::shared_ptr<void>(shptr);
783+
784+
Py_MemoryObject *memobj = reinterpret_cast<Py_MemoryObject *>(_memory);
785+
// replace mock_owner capsule as the owner
786+
memobj->refobj = Py_None;
787+
// set opaque ptr field, usm_memory now knowns that USM is managed
788+
// by smart pointer
789+
memobj->_opaque_ptr = reinterpret_cast<void *>(opaque_ptr);
790+
791+
// _memory will delete created copies of sycl::queue, and
792+
// std::shared_ptr and the deleter of the shared_ptr<void> is
793+
// supposed to free the USM allocation
794+
m_ptr = _memory;
795+
q_uptr.release();
796+
memory_uptr.release();
797+
}
798+
751799
sycl::queue get_queue() const
752800
{
753801
Py_MemoryObject *mem_obj = reinterpret_cast<Py_MemoryObject *>(m_ptr);

dpctl/memory/_opaque_smart_ptr.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "syclinterface/dpctl_sycl_types.h"
3535
#include <memory>
3636
#include <sycl/sycl.hpp>
37+
#include <utility>
3738

3839
#include <exception>
3940
#include <iostream>

dpctl/tensor/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@
6060
)
6161
from dpctl.tensor._device import Device
6262
from dpctl.tensor._dlpack import from_dlpack
63-
from dpctl.tensor._indexing_functions import extract, nonzero, place, put, take
63+
from dpctl.tensor._indexing_functions import (
64+
extract,
65+
nonzero,
66+
place,
67+
put,
68+
take,
69+
take_along_axis,
70+
)
6471
from dpctl.tensor._linear_algebra_functions import (
6572
matmul,
6673
matrix_transpose,
@@ -377,4 +384,5 @@
377384
"diff",
378385
"count_nonzero",
379386
"DLDeviceType",
387+
"take_along_axis",
380388
]

dpctl/tensor/_copy_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,18 @@ def _nonzero_impl(ary):
795795
return res
796796

797797

798-
def _take_multi_index(ary, inds, p):
798+
def _take_multi_index(ary, inds, p, mode=0):
799799
if not isinstance(ary, dpt.usm_ndarray):
800800
raise TypeError(
801801
f"Expecting type dpctl.tensor.usm_ndarray, got {type(ary)}"
802802
)
803803
ary_nd = ary.ndim
804804
p = normalize_axis_index(operator.index(p), ary_nd)
805+
mode = operator.index(mode)
806+
if mode not in [0, 1]:
807+
raise ValueError(
808+
"Invalid value for mode keyword, only 0 or 1 is supported"
809+
)
805810
queues_ = [
806811
ary.sycl_queue,
807812
]
@@ -860,7 +865,7 @@ def _take_multi_index(ary, inds, p):
860865
ind=inds,
861866
dst=res,
862867
axis_start=p,
863-
mode=0,
868+
mode=mode,
864869
sycl_queue=exec_q,
865870
depends=dep_ev,
866871
)

0 commit comments

Comments
 (0)