Skip to content

Commit 978afee

Browse files
Add missing memory and queue checks
1 parent 4bf080e commit 978afee

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

0 commit comments

Comments
 (0)