Skip to content

Add queues_are_compatible signature for list of usm_ndarray instances #1016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dpctl/apis/include/dpctl4pybind11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ sycl::event keep_args_alive(sycl::queue q,
return host_task_ev;
}

/*! @brief Check if all allocation queues are the same as the
execution queue */
template <std::size_t num>
bool queues_are_compatible(sycl::queue exec_q,
const sycl::queue (&alloc_qs)[num])
Expand All @@ -1000,6 +1002,21 @@ bool queues_are_compatible(sycl::queue exec_q,
return true;
}

/*! @brief Check if all allocation queues of usm_ndarays are the same as
the execution queue */
template <std::size_t num>
bool queues_are_compatible(sycl::queue exec_q,
const ::dpctl::tensor::usm_ndarray (&arrs)[num])
{
for (std::size_t i = 0; i < num; ++i) {

if (exec_q != arrs[i].get_queue()) {
return false;
}
}
return true;
}

} // end namespace utils

} // end namespace dpctl
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ copy_usm_ndarray_into_usm_ndarray(dpctl::tensor::usm_ndarray src,
}

// check compatibility of execution queue and allocation queue
sycl::queue src_q = src.get_queue();
sycl::queue dst_q = dst.get_queue();

if (!dpctl::utils::queues_are_compatible(exec_q, {src_q, dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {src, dst})) {
throw py::value_error(
"Execution queue is not compatible with allocation queues");
}
Expand Down
5 changes: 1 addition & 4 deletions dpctl/tensor/libtensor/source/copy_for_reshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ copy_usm_ndarray_for_reshape(dpctl::tensor::usm_ndarray src,
}

// check same contexts
sycl::queue src_q = src.get_queue();
sycl::queue dst_q = dst.get_queue();

if (!dpctl::utils::queues_are_compatible(exec_q, {src_q, dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {src, dst})) {
throw py::value_error(
"Execution queue is not compatible with allocation queues");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ void copy_numpy_ndarray_into_usm_ndarray(
}
}

sycl::queue dst_q = dst.get_queue();

if (!dpctl::utils::queues_are_compatible(exec_q, {dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {dst})) {
throw py::value_error("Execution queue is not compatible with the "
"allocation queue");
}
Expand Down
3 changes: 1 addition & 2 deletions dpctl/tensor/libtensor/source/eye_ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ usm_ndarray_eye(py::ssize_t k,
"usm_ndarray_eye: Expecting 2D array to populate");
}

sycl::queue dst_q = dst.get_queue();
if (!dpctl::utils::queues_are_compatible(exec_q, {dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {dst})) {
throw py::value_error("Execution queue is not compatible with the "
"allocation queue");
}
Expand Down
3 changes: 1 addition & 2 deletions dpctl/tensor/libtensor/source/full_ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ usm_ndarray_full(py::object py_value,
return std::make_pair(sycl::event(), sycl::event());
}

sycl::queue dst_q = dst.get_queue();
if (!dpctl::utils::queues_are_compatible(exec_q, {dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {dst})) {
throw py::value_error(
"Execution queue is not compatible with the allocation queue");
}
Expand Down
6 changes: 2 additions & 4 deletions dpctl/tensor/libtensor/source/linear_sequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ usm_ndarray_linear_sequence_step(py::object start,
"usm_ndarray_linspace: Non-contiguous arrays are not supported");
}

sycl::queue dst_q = dst.get_queue();
if (!dpctl::utils::queues_are_compatible(exec_q, {dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {dst})) {
throw py::value_error(
"Execution queue is not compatible with the allocation queue");
}
Expand Down Expand Up @@ -127,8 +126,7 @@ usm_ndarray_linear_sequence_affine(py::object start,
"usm_ndarray_linspace: Non-contiguous arrays are not supported");
}

sycl::queue dst_q = dst.get_queue();
if (!dpctl::utils::queues_are_compatible(exec_q, {dst_q})) {
if (!dpctl::utils::queues_are_compatible(exec_q, {dst})) {
throw py::value_error(
"Execution queue context is not the same as allocation context");
}
Expand Down
7 changes: 2 additions & 5 deletions dpctl/tensor/libtensor/source/triul_ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,8 @@ usm_ndarray_triul(sycl::queue exec_q,
throw py::value_error("Array dtype are not the same.");
}

// check same contexts
sycl::queue src_q = src.get_queue();
sycl::queue dst_q = dst.get_queue();

if (!dpctl::utils::queues_are_compatible(exec_q, {src_q, dst_q})) {
// check same queues
if (!dpctl::utils::queues_are_compatible(exec_q, {src, dst})) {
throw py::value_error(
"Execution queue context is not the same as allocation contexts");
}
Expand Down