Skip to content
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

Fix kernel_bundle tests for multi-device systems #878

Merged
merged 4 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions tests/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "string_makers.h"
#include "value_operations.h"

#include <algorithm>
#include <cinttypes>
#include <numeric>
#include <sstream>
Expand Down Expand Up @@ -850,4 +851,24 @@ inline sycl::id<3> unlinearize(sycl::range<3> range, size_t id) {
return {id0, id1, id2};
}

/** @brief Checks that two vectors of devices have the exact same devices,
* ignoring order and repeated devices.
* @param lhs std::vector with sycl::device
* @param rhs std::vector with sycl::device
*/
inline bool have_same_devices(std::vector<sycl::device> lhs,
std::vector<sycl::device> rhs) {
auto device_order_f = [](const sycl::device& d1,
const sycl::device& d2) -> bool {
std::hash<sycl::device> h{};
return h(d1) < h(d2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we added that in the spec.
But not yet: https://gitlab.khronos.org/sycl/Specification/-/issues/586

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is this a working order?
What happens when we have 2 different devices with the same hash value?
I am afraid that while we have not solved gitlab.khronos.org/sycl/Specification/-/issues/586 we are stuck with a quadratic algorithm. :-(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, that's a good point. I've changed it to the simple, but valid, implementation.

};
std::sort(lhs.begin(), lhs.end(), device_order_f);
std::sort(rhs.begin(), rhs.end(), device_order_f);
std::vector<sycl::device> difference{};
std::set_difference(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
std::back_inserter(difference), device_order_f);
return difference.size() == 0;
}

#endif // __SYCLCTS_TESTS_COMMON_COMMON_H
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void verify_results(
if (kernel_bundle.get_context() != ctx) {
FAIL(log, "Kernel bundle's context does not equal to provided context");
}
if (kernel_bundle.get_devices() != dev_vector) {
if (!have_same_devices(kernel_bundle.get_devices(), dev_vector)) {
FAIL(log, "Devices from kernel bundle not equal to provided devices");
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ struct verify_that_bundles_are_same {
*/
void run_verification(util::logger &log, sycl::queue &q) {
auto ctx = q.get_context();
std::vector<sycl::device> dev_vector{ctx.get_devices()[0]};
std::vector<sycl::device> dev_vector{ctx.get_devices()};

const auto first_simple_kernel_id =
sycl::get_kernel_id<first_simple_kernel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ template <sycl::bundle_state State>
void run_verification(util::logger &log) {
auto queue = util::get_cts_object::queue();
const auto ctx = queue.get_context();
const auto dev = queue.get_device();

auto kb = sycl::get_kernel_bundle<State>(ctx);

// Selector that always returns false. Used to get empty kernel_bundle
auto false_selector = [](const sycl::device_image<State> &) { return false; };
auto empty_kb = sycl::get_kernel_bundle<State>(ctx, {dev}, false_selector);
auto empty_kb =
sycl::get_kernel_bundle<State>(ctx, ctx.get_devices(), false_selector);
steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved

// Check joined bundles in such order: (kernel_bundle, empty_kernel_bundle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void verify_results(
if (kernel_bundle.get_context() != ctx) {
FAIL(log, "Kernel bundle's context does not equal to provided context");
}
if (kernel_bundle.get_devices() != dev_vector) {
if (!have_same_devices(kernel_bundle.get_devices(), dev_vector)) {
FAIL(log, "Devices from kernel bundle not equal to provided devices");
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ void run_verification(util::logger &log, sycl::queue &queue) {
kb_with_first_simple_kernel_from_input, kb_with_second_simple_kernel};

std::vector<sycl::device> dev_vector{ctx.get_devices()};
std::vector<sycl::device> current_dev_vector{util::get_cts_object::device()};
std::vector<sycl::device> current_dev_vector{queue.get_device()};

log.note("Verify link(vector<kernel_bundle<>>, vector<device>) overload");
verify_results(log, current_dev_vector, ctx,
Expand Down
Loading