forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel_for_indexers.cpp
More file actions
142 lines (137 loc) · 4.33 KB
/
Copy pathparallel_for_indexers.cpp
File metadata and controls
142 lines (137 loc) · 4.33 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// RUN: %clangxx %s -o %t1.out -lsycl -I %sycl_include -Wno-sycl-strict -Xclang -verify-ignore-unexpected=note,warning
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t2.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t2.out
// RUN: %CPU_RUN_PLACEHOLDER %t2.out
// RUN: %GPU_RUN_PLACEHOLDER %t2.out
// RUN: %ACC_RUN_PLACEHOLDER %t2.out
// TODO: Unexpected result
// TODO: _indexers.cpp:37: int main(): Assertion `id == -1' failed.
// XFAIL: cuda
#include <CL/sycl.hpp>
#include <cassert>
#include <memory>
using namespace cl::sycl;
// TODO add cases with dimensions more than 1
int main() {
// Id indexer
{
vector_class<int> data(10, -1);
const range<1> globalRange(6);
{
buffer<int, 1> b(data.data(), range<1>(10),
{property::buffer::use_host_ptr()});
queue myQueue;
myQueue.submit([&](handler &cgh) {
auto B = b.get_access<access::mode::read_write>(cgh);
cgh.parallel_for<class id1>(globalRange,
[=](id<1> index) { B[index] = index[0]; });
});
}
for (int i = 0; i < data.size(); i++) {
const int id = data[i];
if (i < globalRange[0]) {
assert(id == i);
} else {
assert(id == -1);
}
}
}
// Item indexer without offset
{
vector_class<int2> data(10, int2{-1});
const range<1> globalRange(6);
{
buffer<int2, 1> b(data.data(), range<1>(10),
{property::buffer::use_host_ptr()});
queue myQueue;
myQueue.submit([&](handler &cgh) {
auto B = b.get_access<access::mode::read_write>(cgh);
cgh.parallel_for<class item1_nooffset>(
globalRange, [=](item<1, false> index) {
B[index.get_id()] = int2{index.get_id()[0], index.get_range()[0]};
});
});
}
for (int i = 0; i < data.size(); i++) {
const int id = data[i].s0();
const int range = data[i].s1();
if (i < globalRange[0]) {
assert(id == i);
assert(range == globalRange[0]);
} else {
assert(id == -1);
assert(range == -1);
}
}
}
// Item indexer with offset
{
vector_class<int3> data(10, int3{-1});
const range<1> globalRange(6);
const id<1> globalOffset(4);
{
buffer<int3, 1> b(data.data(), range<1>(10),
{property::buffer::use_host_ptr()});
queue myQueue;
myQueue.submit([&](handler &cgh) {
auto B = b.get_access<access::mode::read_write>(cgh);
cgh.parallel_for<class item1_offset>(
globalRange, globalOffset, [=](item<1> index) {
B[index.get_id()] = int3{index.get_id()[0], index.get_range()[0],
index.get_offset()[0]};
});
});
}
for (int i = 0; i < data.size(); i++) {
const int id = data[i].s0();
const int range = data[i].s1();
const int offset = data[i].s2();
if (i < globalOffset[0]) {
assert(id == -1);
assert(range == -1);
assert(offset == -1);
} else {
assert(id == i);
assert(range == globalRange[0]);
assert(offset == globalOffset[0]);
}
}
}
// ND_Item indexer
{
vector_class<int3> data(10, int3{-1});
const range<1> globalRange(6);
const range<1> localRange(3);
const id<1> globalOffset(4);
const nd_range<1> ndRange(globalRange, localRange, globalOffset);
{
buffer<int3, 1> b(data.data(), range<1>(10),
{property::buffer::use_host_ptr()});
queue myQueue;
myQueue.submit([&](handler &cgh) {
auto B = b.get_access<access::mode::read_write>(cgh);
cgh.parallel_for<class item1_nd_range>(ndRange, [=](nd_item<1> index) {
B[index.get_global_id()] =
int3{index.get_global_id()[0], index.get_global_range()[0],
index.get_offset()[0]};
});
});
}
for (int i = 0; i < data.size(); i++) {
const int id = data[i].s0();
const int range = data[i].s1();
const int offset = data[i].s2();
if (i < globalOffset[0]) {
assert(id == -1);
assert(range == -1);
assert(offset == -1);
} else {
assert(id == i);
assert(range == globalRange[0]);
assert(offset == globalOffset[0]);
}
}
}
return 0;
}