Skip to content

Commit 259e8d6

Browse files
committed
[SYCL] Extend range rounding tests to queue shortcut
Introduce a kernel submission wrapper utility to E2E tests, and use it in the range rounding tests to increase the test coverage to the queue kernel submission shortcut function. The main motivation is to test the handler-less kernel submission path, once it is introduced (for range based submissions).
1 parent b3df18d commit 259e8d6

File tree

3 files changed

+334
-159
lines changed

3 files changed

+334
-159
lines changed

sycl/test-e2e/Basic/parallel_for_disable_range_roundup.cpp

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,62 @@
66
// RUN: %{build} -sycl-std=2020 -o %t2.out
77
// RUN: env SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE=1 %{run} %t2.out | FileCheck %s --check-prefix CHECK-ENABLED
88

9-
#include <sycl/atomic.hpp>
9+
#include <sycl/atomic_ref.hpp>
1010
#include <sycl/detail/core.hpp>
11+
#include <sycl/usm.hpp>
12+
13+
#include "../helpers.hpp"
1114

1215
#include <iostream>
1316
using namespace sycl;
1417

15-
range<1> Range1 = {0};
16-
1718
void check(const char *msg, size_t v, size_t ref) {
1819
std::cout << msg << v << std::endl;
1920
assert(v == ref);
2021
}
2122

22-
int try_rounding_off(size_t size) {
23-
range<1> Size{size};
24-
int Counter = 0;
25-
{
26-
buffer<range<1>, 1> BufRange(&Range1, 1);
27-
buffer<int, 1> BufCounter(&Counter, 1);
28-
queue myQueue;
29-
30-
std::cout << "Run parallel_for" << std::endl;
31-
myQueue.submit([&](handler &cgh) {
32-
auto AccRange = BufRange.get_access<access::mode::read_write>(cgh);
33-
auto AccCounter = BufCounter.get_access<access::mode::atomic>(cgh);
34-
cgh.parallel_for<class PF_init_item1>(Size, [=](item<1> ITEM) {
35-
AccCounter[0].fetch_add(1);
36-
AccRange[0] = ITEM.get_range(0);
37-
});
38-
});
39-
myQueue.wait();
40-
}
41-
check("Size seen by user = ", Range1.get(0), size);
42-
check("Counter = ", Counter, size);
43-
return 0;
23+
void try_rounding_off(size_t size, bool useShortcutFunction) {
24+
range<1> Range{size};
25+
queue Queue;
26+
range<1> *RangePtr = malloc_shared<range<1>>(1, Queue);
27+
int *CounterPtr = malloc_shared<int>(1, Queue);
28+
(*CounterPtr) = 0;
29+
30+
std::cout << "Run parallel_for" << std::endl;
31+
auto KernelFunc = [=](item<1> id) {
32+
auto atm = atomic_ref<int, sycl::memory_order::relaxed,
33+
sycl::memory_scope::device>(*CounterPtr);
34+
atm.fetch_add(1);
35+
(*RangePtr) = id.get_range(0);
36+
};
37+
command_submit_wrappers::parallel_for_wrapper<class TestKernel>(
38+
useShortcutFunction, Queue, Range, KernelFunc);
39+
40+
Queue.wait();
41+
42+
auto Context = Queue.get_context();
43+
44+
check("Size seen by user = ", RangePtr->get(0), size);
45+
check("Counter = ", *CounterPtr, size);
46+
47+
free(RangePtr, Context);
48+
free(CounterPtr, Context);
4449
}
4550

4651
int main() {
4752
int x;
4853

4954
x = 1500;
50-
try_rounding_off(x);
55+
try_rounding_off(x, true);
56+
try_rounding_off(x, false);
5157

5258
return 0;
5359
}
5460

61+
// CHECK-DISABLED: Run parallel_for
62+
// CHECK-DISABLED-NOT: parallel_for range adjusted at dim 0 from 1500
63+
// CHECK-DISABLED: Size seen by user = 1500
64+
// CHECK-DISABLED-NEXT: Counter = 1500
5565
// CHECK-DISABLED: Run parallel_for
5666
// CHECK-DISABLED-NOT: parallel_for range adjusted at dim 0 from 1500
5767
// CHECK-DISABLED: Size seen by user = 1500
@@ -61,3 +71,7 @@ int main() {
6171
// CHECK-ENABLED-NEXT: parallel_for range adjusted at dim 0 from 1500
6272
// CHECK-ENABLED-NEXT: Size seen by user = 1500
6373
// CHECK-ENABLED-NEXT: Counter = 1500
74+
// CHECK-ENABLED: Run parallel_for
75+
// CHECK-ENABLED-NEXT: parallel_for range adjusted at dim 0 from 1500
76+
// CHECK-ENABLED-NEXT: Size seen by user = 1500
77+
// CHECK-ENABLED-NEXT: Counter = 1500

0 commit comments

Comments
 (0)