Skip to content

Commit 9e7deb3

Browse files
Merge move_tensor_impl_ext into move_tensor_impl_ext_part_2
2 parents 3113716 + c082224 commit 9e7deb3

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ dpnp/**/*.pyd
3333
*~
3434
core
3535

36+
# TODO: revert to `dpctl/`
37+
# when dpnp fully migrates dpctl/tensor
3638
dpctl_ext/**/*.cpython*.so

dpctl_ext/tensor/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# THE POSSIBILITY OF SUCH DAMAGE.
2828
# *****************************************************************************
2929

30-
find_package(Python COMPONENTS Development)
30+
find_package(Python COMPONENTS Development.Module)
3131

3232
if(WIN32)
3333
if(${CMAKE_VERSION} VERSION_LESS "3.27")
@@ -74,7 +74,7 @@ target_include_directories(
7474
# ${Dpctl_INCLUDE_DIR}
7575
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/include
7676
)
77-
target_link_libraries(${_static_lib_trgt} PRIVATE pybind11::headers Python::Python)
77+
target_link_libraries(${_static_lib_trgt} PRIVATE pybind11::headers Python::Module)
7878
set_target_properties(${_static_lib_trgt} PROPERTIES POSITION_INDEPENDENT_CODE ON)
7979

8080
set(_py_trgts)

dpctl_ext/tensor/libtensor/source/copy_as_contig.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ std::pair<sycl::event, sycl::event>
189189
"Execution queue is not compatible with allocation queues");
190190
}
191191

192+
// check that arrays do not overlap, and concurrent copying is safe.
193+
auto const &overlap = dpctl::tensor::overlap::MemoryOverlap();
194+
if (overlap(src, dst)) {
195+
throw py::value_error("Arrays index overlapping segments of memory");
196+
}
197+
192198
const auto &src_strides_vec = src.get_strides_vector();
193199

194200
if (src_nd >= 2) {
@@ -314,6 +320,12 @@ std::pair<sycl::event, sycl::event>
314320
"Execution queue is not compatible with allocation queues");
315321
}
316322

323+
// check that arrays do not overlap, and concurrent copying is safe.
324+
auto const &overlap = dpctl::tensor::overlap::MemoryOverlap();
325+
if (overlap(src, dst)) {
326+
throw py::value_error("Arrays index overlapping segments of memory");
327+
}
328+
317329
const auto &src_strides_vec = src.get_strides_vector();
318330

319331
if (src_nd >= 2) {
@@ -459,6 +471,12 @@ std::pair<sycl::event, sycl::event>
459471
"Execution queue is not compatible with allocation queues");
460472
}
461473

474+
// check that arrays do not overlap, and concurrent copying is safe.
475+
auto const &overlap = dpctl::tensor::overlap::MemoryOverlap();
476+
if (overlap(src, dst)) {
477+
throw py::value_error("Arrays index overlapping segments of memory");
478+
}
479+
462480
if (nelems == 0) {
463481
// nothing to do
464482
return std::make_pair(sycl::event(), sycl::event());
@@ -624,6 +642,20 @@ std::pair<sycl::event, sycl::event>
624642
throw py::value_error("Unexpected destination array layout");
625643
}
626644

645+
dpctl::tensor::validation::CheckWritable::throw_if_not_writable(dst);
646+
647+
// check compatibility of execution queue and allocation queue
648+
if (!dpctl::utils::queues_are_compatible(exec_q, {src, dst})) {
649+
throw py::value_error(
650+
"Execution queue is not compatible with allocation queues");
651+
}
652+
653+
// check that arrays do not overlap, and concurrent copying is safe.
654+
auto const &overlap = dpctl::tensor::overlap::MemoryOverlap();
655+
if (overlap(src, dst)) {
656+
throw py::value_error("Arrays index overlapping segments of memory");
657+
}
658+
627659
int src_typenum = src.get_typenum();
628660
int dst_typenum = dst.get_typenum();
629661

dpctl_ext/tensor/libtensor/source/tensor_ctors.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,15 @@
3232
/// This file defines functions of dpctl.tensor._tensor_impl extensions
3333
//===----------------------------------------------------------------------===//
3434

35-
// #include <algorithm>
36-
// #include <complex>
37-
// #include <cstdint>
38-
#include <pybind11/pybind11.h>
39-
#include <pybind11/stl.h>
40-
#include <sycl/sycl.hpp>
41-
// #include <thread>
4235
#include <optional>
4336
#include <type_traits>
4437
#include <utility>
4538
#include <vector>
4639

40+
#include <pybind11/pybind11.h>
41+
#include <pybind11/stl.h>
42+
#include <sycl/sycl.hpp>
43+
4744
#include "dpnp4pybind11.hpp"
4845

4946
// #include "accumulators.hpp"

0 commit comments

Comments
 (0)