forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_reduce.cpp
More file actions
76 lines (63 loc) · 2.2 KB
/
launch_reduce.cpp
File metadata and controls
76 lines (63 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// REQUIRES: aspect-usm_shared_allocations
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out
// This test checks whether the free function command launch reduce is valid.
#define __DPCPP_ENABLE_UNFINISHED_KHR_EXTENSIONS
#include <sycl/detail/core.hpp>
#include <sycl/khr/free_function_commands.hpp>
#include <sycl/reduction.hpp>
#include <sycl/usm.hpp>
#include "helpers.hpp"
int main() {
int Failed = 0;
sycl::queue Queue;
{
int Result = 0;
constexpr size_t Dim = 8;
constexpr size_t N = Dim * Dim * Dim - 1;
constexpr int ExpectedResult = N * (N + 1) / 2;
{
sycl::buffer<int> sumBuf{&Result, 1};
Queue.submit([&](sycl::handler &Handler) {
sycl::khr::launch_reduce(
Handler, sycl::range<3>(Dim, Dim, Dim),
[=](sycl::item<3> Item, auto &Sum) { Sum += Item.get_linear_id(); },
sycl::reduction(sumBuf, Handler, sycl::plus<>()));
});
}
Failed += Check(Result, ExpectedResult, "launch_reduce_with_buffer");
}
{
int *Result = sycl::malloc_shared<int>(1, Queue);
Result[0] = 0;
constexpr size_t N = 1024;
constexpr int ExpectedResult = ((N - 1) * N) / 2;
sycl::event Event =
sycl::khr::submit_tracked(Queue, [&](sycl::handler &Handler) {
sycl::khr::launch_reduce(
Handler, sycl::range<1>(N),
[=](sycl::id<1> Id, auto &Sum) {
int NegativeId = -(int)Id;
Sum += NegativeId;
},
sycl::reduction(Result, sycl::plus<>()));
});
Queue.submit([&](sycl::handler &Handler) {
Handler.depends_on(Event);
sycl::khr::launch_reduce(
Handler, sycl::range<1>(N),
[=](sycl::item<1> Item, auto &Sum) { Sum += Item.get_linear_id(); },
sycl::reduction(Result, sycl::plus<>()));
});
Queue.wait();
Failed += Check(Result[0], 0, "launch_reduce_with_usm");
sycl::khr::launch_reduce(
Queue, sycl::range<1>(N), [=](sycl::id<1> Id, auto &Sum) { Sum += Id; },
sycl::reduction(Result, sycl::plus<>()));
Queue.wait();
Failed +=
Check(Result[0], ExpectedResult, "launch_reduce_shortcut_with_usm");
sycl::free(Result, Queue);
}
return Failed;
}