Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL][CUDA] Add tests for exceeding maximum number of work groups #952

Merged
merged 3 commits into from
Apr 8, 2022
Merged
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
52 changes: 52 additions & 0 deletions SYCL/Basic/cuda_max_wgs_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -fno-sycl-id-queries-fit-in-int
// RUN: %GPU_RUN_PLACEHOLDER %t.out
//
// REQUIRES: cuda

#include <numeric>
#include <sycl/sycl.hpp>

using namespace sycl;

const size_t lsize = 32;
const std::string expected_msg =
"Number of work-groups exceed limit for dimension ";

template <int N>
void check(range<N> global, range<N> local, bool expect_fail = false) {
queue q;
try {
q.submit([&](handler &cgh) {
cgh.parallel_for(nd_range<N>(global, local), [=](nd_item<N> item) {});
});
} catch (nd_range_error e) {
if (expect_fail) {
std::string msg = e.what();
assert(msg.rfind(expected_msg, 0) == 0);
} else {
throw e;
}
}
}

int main() {
queue q;
device d = q.get_device();
id<1> max_1 = d.get_info<sycl::info::device::ext_oneapi_max_work_groups_1d>();
check(range<1>(max_1[0] * lsize), range<1>(lsize));
check(range<1>((max_1[0] + 1) * lsize), range<1>(lsize), true);

id<2> max_2 = d.get_info<sycl::info::device::ext_oneapi_max_work_groups_2d>();
check(range<2>(1, max_2[1] * lsize), range<2>(1, lsize));
check(range<2>(1, (max_2[1] + 1) * lsize), range<2>(1, lsize), true);
check(range<2>(max_2[0] * lsize, 1), range<2>(lsize, 1));
check(range<2>((max_2[0] + 1) * lsize, 1), range<2>(lsize, 1), true);

id<3> max_3 = d.get_info<sycl::info::device::ext_oneapi_max_work_groups_3d>();
check(range<3>(1, 1, max_3[2] * lsize), range<3>(1, 1, lsize));
check(range<3>(1, 1, (max_3[2] + 1) * lsize), range<3>(1, 1, lsize), true);
check(range<3>(1, max_3[1] * lsize, 1), range<3>(1, lsize, 1));
check(range<3>(1, (max_3[1] + 1) * lsize, 1), range<3>(1, lsize, 1), true);
check(range<3>(max_3[0] * lsize, 1, 1), range<3>(lsize, 1, 1));
check(range<3>((max_3[0] + 1) * lsize, 1, 1), range<3>(lsize, 1, 1), true);
}