@@ -322,15 +322,16 @@ copy_usm_ndarray_into_usm_ndarray(dpctl::tensor::usm_ndarray src,
322
322
throw py::value_error (" Arrays index overlapping segments of memory" );
323
323
}
324
324
325
- int src_flags = src.get_flags ();
326
- int dst_flags = dst.get_flags ();
325
+ bool is_src_c_contig = src.is_c_contiguous ();
326
+ bool is_src_f_contig = src.is_f_contiguous ();
327
+
328
+ bool is_dst_c_contig = dst.is_c_contiguous ();
329
+ bool is_dst_f_contig = dst.is_f_contiguous ();
327
330
328
331
// check for applicability of special cases:
329
332
// (same type && (both C-contiguous || both F-contiguous)
330
- bool both_c_contig = ((src_flags & USM_ARRAY_C_CONTIGUOUS) &&
331
- (dst_flags & USM_ARRAY_C_CONTIGUOUS));
332
- bool both_f_contig = ((src_flags & USM_ARRAY_F_CONTIGUOUS) &&
333
- (dst_flags & USM_ARRAY_F_CONTIGUOUS));
333
+ bool both_c_contig = (is_src_c_contig && is_dst_c_contig);
334
+ bool both_f_contig = (is_src_f_contig && is_dst_f_contig);
334
335
if (both_c_contig || both_f_contig) {
335
336
if (src_type_id == dst_type_id) {
336
337
@@ -360,12 +361,6 @@ copy_usm_ndarray_into_usm_ndarray(dpctl::tensor::usm_ndarray src,
360
361
int nd = src_nd;
361
362
const py::ssize_t *shape = src_shape;
362
363
363
- bool is_src_c_contig = ((src_flags & USM_ARRAY_C_CONTIGUOUS) != 0 );
364
- bool is_src_f_contig = ((src_flags & USM_ARRAY_F_CONTIGUOUS) != 0 );
365
-
366
- bool is_dst_c_contig = ((dst_flags & USM_ARRAY_C_CONTIGUOUS) != 0 );
367
- bool is_dst_f_contig = ((dst_flags & USM_ARRAY_F_CONTIGUOUS) != 0 );
368
-
369
364
constexpr py::ssize_t src_itemsize = 1 ; // in elements
370
365
constexpr py::ssize_t dst_itemsize = 1 ; // in elements
371
366
@@ -576,14 +571,13 @@ copy_usm_ndarray_for_reshape(dpctl::tensor::usm_ndarray src,
576
571
577
572
const py::ssize_t *src_strides = src.get_strides_raw ();
578
573
if (src_strides == nullptr ) {
579
- int src_flags = src.get_flags ();
580
- if (src_flags & USM_ARRAY_C_CONTIGUOUS) {
574
+ if (src.is_c_contiguous ()) {
581
575
const auto &src_contig_strides =
582
576
c_contiguous_strides (src_nd, src_shape);
583
577
std::copy (src_contig_strides.begin (), src_contig_strides.end (),
584
578
packed_host_shapes_strides_shp->begin () + src_nd);
585
579
}
586
- else if (src_flags & USM_ARRAY_F_CONTIGUOUS ) {
580
+ else if (src. is_f_contiguous () ) {
587
581
const auto &src_contig_strides =
588
582
f_contiguous_strides (src_nd, src_shape);
589
583
std::copy (src_contig_strides.begin (), src_contig_strides.end (),
@@ -602,15 +596,14 @@ copy_usm_ndarray_for_reshape(dpctl::tensor::usm_ndarray src,
602
596
603
597
const py::ssize_t *dst_strides = dst.get_strides_raw ();
604
598
if (dst_strides == nullptr ) {
605
- int dst_flags = dst.get_flags ();
606
- if (dst_flags & USM_ARRAY_C_CONTIGUOUS) {
599
+ if (dst.is_c_contiguous ()) {
607
600
const auto &dst_contig_strides =
608
601
c_contiguous_strides (dst_nd, dst_shape);
609
602
std::copy (dst_contig_strides.begin (), dst_contig_strides.end (),
610
603
packed_host_shapes_strides_shp->begin () + 2 * src_nd +
611
604
dst_nd);
612
605
}
613
- else if (dst_flags & USM_ARRAY_F_CONTIGUOUS ) {
606
+ else if (dst. is_f_contiguous () ) {
614
607
const auto &dst_contig_strides =
615
608
f_contiguous_strides (dst_nd, dst_shape);
616
609
std::copy (dst_contig_strides.begin (), dst_contig_strides.end (),
@@ -744,14 +737,13 @@ void copy_numpy_ndarray_into_usm_ndarray(
744
737
char *dst_data = dst.get_data ();
745
738
746
739
int src_flags = npy_src.flags ();
747
- int dst_flags = dst.get_flags ();
748
740
749
741
// check for applicability of special cases:
750
742
// (same type && (both C-contiguous || both F-contiguous)
751
- bool both_c_contig = ((src_flags & py::array::c_style) &&
752
- (dst_flags & USM_ARRAY_C_CONTIGUOUS ));
753
- bool both_f_contig = ((src_flags & py::array::f_style) &&
754
- (dst_flags & USM_ARRAY_F_CONTIGUOUS ));
743
+ bool both_c_contig =
744
+ ((src_flags & py::array::c_style) && dst. is_c_contiguous ( ));
745
+ bool both_f_contig =
746
+ ((src_flags & py::array::f_style) && dst. is_f_contiguous ( ));
755
747
if (both_c_contig || both_f_contig) {
756
748
if (src_type_id == dst_type_id) {
757
749
int src_elem_size = npy_src.itemsize ();
@@ -791,8 +783,8 @@ void copy_numpy_ndarray_into_usm_ndarray(
791
783
bool is_src_c_contig = ((src_flags & py::array::c_style) != 0 );
792
784
bool is_src_f_contig = ((src_flags & py::array::f_style) != 0 );
793
785
794
- bool is_dst_c_contig = ((dst_flags & USM_ARRAY_C_CONTIGUOUS) != 0 );
795
- bool is_dst_f_contig = ((dst_flags & USM_ARRAY_F_CONTIGUOUS) != 0 );
786
+ bool is_dst_c_contig = dst. is_c_contiguous ( );
787
+ bool is_dst_f_contig = dst. is_f_contiguous ( );
796
788
797
789
// all args except itemsizes and is_?_contig bools can be modified by
798
790
// reference
@@ -906,16 +898,15 @@ usm_ndarray_linear_sequence_step(py::object start,
906
898
" usm_ndarray_linspace: Expecting 1D array to populate" );
907
899
}
908
900
909
- int flags = dst.get_flags ();
910
- if (!(flags & USM_ARRAY_C_CONTIGUOUS)) {
901
+ if (!dst.is_c_contiguous ()) {
911
902
throw py::value_error (
912
903
" usm_ndarray_linspace: Non-contiguous arrays are not supported" );
913
904
}
914
905
915
906
sycl::queue dst_q = dst.get_queue ();
916
- if (dst_q != exec_q && dst_q. get_context () != exec_q. get_context ( )) {
907
+ if (! dpctl::utils::queues_are_compatible ( exec_q, { dst_q} )) {
917
908
throw py::value_error (
918
- " Execution queue context is not the same as allocation context " );
909
+ " Execution queue is not compatible with the allocation queue " );
919
910
}
920
911
921
912
int dst_typenum = dst.get_typenum ();
@@ -955,14 +946,13 @@ usm_ndarray_linear_sequence_affine(py::object start,
955
946
" usm_ndarray_linspace: Expecting 1D array to populate" );
956
947
}
957
948
958
- int flags = dst.get_flags ();
959
- if (!(flags & USM_ARRAY_C_CONTIGUOUS)) {
949
+ if (!dst.is_c_contiguous ()) {
960
950
throw py::value_error (
961
951
" usm_ndarray_linspace: Non-contiguous arrays are not supported" );
962
952
}
963
953
964
954
sycl::queue dst_q = dst.get_queue ();
965
- if (dst_q != exec_q && dst_q. get_context () != exec_q. get_context ( )) {
955
+ if (! dpctl::utils::queues_are_compatible ( exec_q, { dst_q} )) {
966
956
throw py::value_error (
967
957
" Execution queue context is not the same as allocation context" );
968
958
}
@@ -1010,12 +1000,10 @@ usm_ndarray_full(py::object py_value,
1010
1000
return std::make_pair (sycl::event (), sycl::event ());
1011
1001
}
1012
1002
1013
- int dst_flags = dst.get_flags ();
1014
-
1015
1003
sycl::queue dst_q = dst.get_queue ();
1016
- if (dst_q != exec_q && dst_q. get_context () != exec_q. get_context ( )) {
1004
+ if (! dpctl::utils::queues_are_compatible ( exec_q, { dst_q} )) {
1017
1005
throw py::value_error (
1018
- " Execution queue context is not the same as allocation context " );
1006
+ " Execution queue is not compatible with the allocation queue " );
1019
1007
}
1020
1008
1021
1009
int dst_typenum = dst.get_typenum ();
@@ -1024,9 +1012,7 @@ usm_ndarray_full(py::object py_value,
1024
1012
char *dst_data = dst.get_data ();
1025
1013
sycl::event full_event;
1026
1014
1027
- if (dst_nelems == 1 || (dst_flags & USM_ARRAY_C_CONTIGUOUS) ||
1028
- (dst_flags & USM_ARRAY_F_CONTIGUOUS))
1029
- {
1015
+ if (dst_nelems == 1 || dst.is_c_contiguous () || dst.is_f_contiguous ()) {
1030
1016
auto fn = full_contig_dispatch_vector[dst_typeid];
1031
1017
1032
1018
sycl::event full_contig_event =
@@ -1079,8 +1065,8 @@ eye(py::ssize_t k,
1079
1065
return std::make_pair (sycl::event{}, sycl::event{});
1080
1066
}
1081
1067
1082
- bool is_dst_c_contig = (( dst.get_flags () & USM_ARRAY_C_CONTIGUOUS) != 0 );
1083
- bool is_dst_f_contig = (( dst.get_flags () & USM_ARRAY_F_CONTIGUOUS) != 0 );
1068
+ bool is_dst_c_contig = dst.is_c_contiguous ( );
1069
+ bool is_dst_f_contig = dst.is_f_contiguous ( );
1084
1070
if (!is_dst_c_contig && !is_dst_f_contig) {
1085
1071
throw py::value_error (" USM array is not contiguous" );
1086
1072
}
@@ -1203,9 +1189,8 @@ tri(sycl::queue &exec_q,
1203
1189
using shT = std::vector<py::ssize_t >;
1204
1190
shT src_strides (src_nd);
1205
1191
1206
- int src_flags = src.get_flags ();
1207
- bool is_src_c_contig = ((src_flags & USM_ARRAY_C_CONTIGUOUS) != 0 );
1208
- bool is_src_f_contig = ((src_flags & USM_ARRAY_F_CONTIGUOUS) != 0 );
1192
+ bool is_src_c_contig = src.is_c_contiguous ();
1193
+ bool is_src_f_contig = src.is_f_contiguous ();
1209
1194
1210
1195
const py::ssize_t *src_strides_raw = src.get_strides_raw ();
1211
1196
if (src_strides_raw == nullptr ) {
@@ -1227,9 +1212,8 @@ tri(sycl::queue &exec_q,
1227
1212
1228
1213
shT dst_strides (src_nd);
1229
1214
1230
- int dst_flags = dst.get_flags ();
1231
- bool is_dst_c_contig = ((dst_flags & USM_ARRAY_C_CONTIGUOUS) != 0 );
1232
- bool is_dst_f_contig = ((dst_flags & USM_ARRAY_F_CONTIGUOUS) != 0 );
1215
+ bool is_dst_c_contig = dst.is_c_contiguous ();
1216
+ bool is_dst_f_contig = dst.is_f_contiguous ();
1233
1217
1234
1218
const py::ssize_t *dst_strides_raw = dst.get_strides_raw ();
1235
1219
if (dst_strides_raw == nullptr ) {
0 commit comments