Skip to content

Commit bab9615

Browse files
Got rid of static dpctl::tensor::detail::usm_ndarray_types array_types.
The class is already singleton. Instead create a local variable at each use site. This local variable is going to be a constant reference to the singleton.
1 parent b89de2a commit bab9615

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

dpctl/tensor/libtensor/source/tensor_py.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
namespace py = pybind11;
4444

45-
static dpctl::tensor::detail::usm_ndarray_types array_types;
46-
4745
namespace
4846
{
4947

@@ -301,6 +299,7 @@ copy_usm_ndarray_into_usm_ndarray(dpctl::tensor::usm_ndarray src,
301299
int src_typenum = src.get_typenum();
302300
int dst_typenum = dst.get_typenum();
303301

302+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
304303
int src_type_id = array_types.typenum_to_lookup_id(src_typenum);
305304
int dst_type_id = array_types.typenum_to_lookup_id(dst_typenum);
306305

@@ -545,6 +544,7 @@ copy_usm_ndarray_for_reshape(dpctl::tensor::usm_ndarray src,
545544
const py::ssize_t *src_shape = src.get_shape_raw();
546545
const py::ssize_t *dst_shape = dst.get_shape_raw();
547546

547+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
548548
int type_id = array_types.typenum_to_lookup_id(src_typenum);
549549

550550
auto fn = copy_for_reshape_generic_dispatch_vector[type_id];
@@ -729,6 +729,7 @@ void copy_numpy_ndarray_into_usm_ndarray(
729729
py::detail::array_descriptor_proxy(npy_src.dtype().ptr())->type_num;
730730
int dst_typenum = dst.get_typenum();
731731

732+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
732733
int src_type_id = array_types.typenum_to_lookup_id(src_typenum);
733734
int dst_type_id = array_types.typenum_to_lookup_id(dst_typenum);
734735

@@ -909,6 +910,7 @@ usm_ndarray_linear_sequence_step(py::object start,
909910
"Execution queue is not compatible with the allocation queue");
910911
}
911912

913+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
912914
int dst_typenum = dst.get_typenum();
913915
int dst_typeid = array_types.typenum_to_lookup_id(dst_typenum);
914916

@@ -957,6 +959,7 @@ usm_ndarray_linear_sequence_affine(py::object start,
957959
"Execution queue context is not the same as allocation context");
958960
}
959961

962+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
960963
int dst_typenum = dst.get_typenum();
961964
int dst_typeid = array_types.typenum_to_lookup_id(dst_typenum);
962965

@@ -1006,6 +1009,7 @@ usm_ndarray_full(py::object py_value,
10061009
"Execution queue is not compatible with the allocation queue");
10071010
}
10081011

1012+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
10091013
int dst_typenum = dst.get_typenum();
10101014
int dst_typeid = array_types.typenum_to_lookup_id(dst_typenum);
10111015

@@ -1054,6 +1058,7 @@ eye(py::ssize_t k,
10541058
"allocation queue");
10551059
}
10561060

1061+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
10571062
int dst_typenum = dst.get_typenum();
10581063
int dst_typeid = array_types.typenum_to_lookup_id(dst_typenum);
10591064

@@ -1168,6 +1173,8 @@ tri(sycl::queue &exec_q,
11681173
throw py::value_error("Arrays index overlapping segments of memory");
11691174
}
11701175

1176+
auto array_types = dpctl::tensor::detail::usm_ndarray_types::get();
1177+
11711178
int src_typenum = src.get_typenum();
11721179
int dst_typenum = dst.get_typenum();
11731180
int src_typeid = array_types.typenum_to_lookup_id(src_typenum);
@@ -1441,9 +1448,6 @@ PYBIND11_MODULE(_tensor_impl, m)
14411448
init_copy_for_reshape_dispatch_vector();
14421449
import_dpctl();
14431450

1444-
// populate types constants for type dispatching functions
1445-
array_types = dpctl::tensor::detail::usm_ndarray_types::get();
1446-
14471451
m.def(
14481452
"_contract_iter", &contract_iter,
14491453
"Simplifies iteration of array of given shape & stride. Returns "

0 commit comments

Comments
 (0)