35
35
#include " kernels/copy_as_contiguous.hpp"
36
36
#include " utils/memory_overlap.hpp"
37
37
#include " utils/offset_utils.hpp"
38
+ #include " utils/output_validation.hpp"
38
39
#include " utils/sycl_alloc_utils.hpp"
39
40
#include " utils/type_dispatch.hpp"
40
41
@@ -107,10 +108,16 @@ void init_copy_as_contig_dispatch_vectors(void)
107
108
namespace
108
109
{
109
110
110
- template <typename dimT> dimT get_nelems (const std::vector<dimT> &shape)
111
+ template <typename dimT> std:: size_t get_nelems (const std::vector<dimT> &shape)
111
112
{
112
- const dimT nelems = std::accumulate (std::begin (shape), std::end (shape),
113
- dimT (1 ), std::multiplies<dimT>{});
113
+ auto mult_fn = [](std::size_t prod, const dimT &term) -> std::size_t {
114
+ return prod * static_cast <std::size_t >(term);
115
+ };
116
+
117
+ constexpr std::size_t unit{1 };
118
+
119
+ const std::size_t nelems =
120
+ std::accumulate (std::begin (shape), std::end (shape), unit, mult_fn);
114
121
return nelems;
115
122
}
116
123
@@ -163,6 +170,14 @@ py_as_c_contig(const dpctl::tensor::usm_ndarray &src,
163
170
throw py::value_error (" Destination array must be C-contiguous" );
164
171
}
165
172
173
+ dpctl::tensor::validation::CheckWritable::throw_if_not_writable (dst);
174
+
175
+ // check compatibility of execution queue and allocation queue
176
+ if (!dpctl::utils::queues_are_compatible (exec_q, {src, dst})) {
177
+ throw py::value_error (
178
+ " Execution queue is not compatible with allocation queues" );
179
+ }
180
+
166
181
const auto &src_strides_vec = src.get_strides_vector ();
167
182
168
183
if (src_nd >= 2 ) {
@@ -175,7 +190,7 @@ py_as_c_contig(const dpctl::tensor::usm_ndarray &src,
175
190
}
176
191
}
177
192
178
- const py:: ssize_t nelems = get_nelems (src_shape_vec);
193
+ const std:: size_t nelems = get_nelems (src_shape_vec);
179
194
180
195
if (nelems == 0 ) {
181
196
// nothing to do
@@ -254,7 +269,7 @@ py_as_f_contig(const dpctl::tensor::usm_ndarray &src,
254
269
const std::vector<sycl::event> &depends)
255
270
{
256
271
/* Same dimensions, same shape, same data-type
257
- * dst is C -contiguous.
272
+ * dst is F -contiguous.
258
273
*/
259
274
int src_nd = src.get_ndim ();
260
275
int dst_nd = dst.get_ndim ();
@@ -288,6 +303,14 @@ py_as_f_contig(const dpctl::tensor::usm_ndarray &src,
288
303
throw py::value_error (" Destination array must be F-contiguous" );
289
304
}
290
305
306
+ dpctl::tensor::validation::CheckWritable::throw_if_not_writable (dst);
307
+
308
+ // check compatibility of execution queue and allocation queue
309
+ if (!dpctl::utils::queues_are_compatible (exec_q, {src, dst})) {
310
+ throw py::value_error (
311
+ " Execution queue is not compatible with allocation queues" );
312
+ }
313
+
291
314
const auto &src_strides_vec = src.get_strides_vector ();
292
315
293
316
if (src_nd >= 2 ) {
@@ -300,7 +323,7 @@ py_as_f_contig(const dpctl::tensor::usm_ndarray &src,
300
323
}
301
324
}
302
325
303
- const py:: ssize_t nelems = get_nelems (src_shape_vec);
326
+ const std:: size_t nelems = get_nelems (src_shape_vec);
304
327
305
328
if (nelems == 0 ) {
306
329
// nothing to do
@@ -433,6 +456,14 @@ py_as_c_contig_f2c(const dpctl::tensor::usm_ndarray &src,
433
456
throw py::value_error (" Destination array must be C-contiguous" );
434
457
}
435
458
459
+ dpctl::tensor::validation::CheckWritable::throw_if_not_writable (dst);
460
+
461
+ // check compatibility of execution queue and allocation queue
462
+ if (!dpctl::utils::queues_are_compatible (exec_q, {src, dst})) {
463
+ throw py::value_error (
464
+ " Execution queue is not compatible with allocation queues" );
465
+ }
466
+
436
467
if (nelems == 0 ) {
437
468
// nothing to do
438
469
return std::make_pair (sycl::event (), sycl::event ());
0 commit comments